35 #define SYSPSQLRC "psqlrc" 36 #define PSQLRC ".psqlrc" 38 #define SYSPSQLRC "psqlrc" 39 #define PSQLRC "psqlrc.conf" 133 if ((strcmp(argv[1],
"-?") == 0) || (argc == 2 && (strcmp(argv[1],
"--help") == 0)))
138 if (strcmp(argv[1],
"--version") == 0 || strcmp(argv[1],
"-V") == 0)
179 pset.
notty = (!isatty(fileno(stdin)) || !isatty(fileno(
stdout)));
213 pg_log_fatal(
"-1 can only be used in non-interactive mode");
243 #define PARAMS_ARRAY_SIZE 8 247 keywords[0] =
"host";
248 values[0] = options.
host;
249 keywords[1] =
"port";
250 values[1] = options.
port;
251 keywords[2] =
"user";
253 keywords[3] =
"password";
255 keywords[4] =
"dbname";
257 "postgres" : options.
dbname;
258 keywords[5] =
"fallback_application_name";
260 keywords[6] =
"client_encoding";
261 values[6] = (pset.
notty || getenv(
"PGCLIENTENCODING")) ? NULL :
"auto";
280 const char *realusername =
PQuser(pset.
db);
281 char *password_prompt;
283 if (realusername && realusername[0])
284 password_prompt =
psprintf(
_(
"Password for user %s: "),
291 free(password_prompt);
348 if ((res =
PSQLexec(
"BEGIN")) == NULL)
384 cell->
val, strlen(cell->
val),
414 if ((res =
PSQLexec(
"COMMIT")) == NULL)
438 printf(
_(
"Type \"help\" for help.\n\n"));
452 return successResult;
463 static struct option long_options[] =
507 memset(options, 0,
sizeof *options);
509 while ((c =
getopt_long(argc, argv,
"aAbc:d:eEf:F:h:HlL:no:p:P:qR:sStT:U:v:VwWxXz?01",
510 long_options, &optindex)) != -1)
580 equal_loc = strchr(value,
'=');
586 result =
do_pset(value, equal_loc + 1, &pset.
popt,
true);
591 pg_log_fatal(
"could not set printing parameter \"%s\"", value);
626 equal_loc = strchr(value,
'=');
668 strcmp(argv[
optind - 1],
"-?") == 0)
699 fprintf(stderr,
_(
"Try \"%s --help\" for more information.\n"),
709 while (argc -
optind >= 1)
715 else if (!pset.
quiet)
761 char *envrc = getenv(
"PSQLRC");
774 if (envrc != NULL && strlen(envrc) > 0)
777 char *envrc_alloc =
pstrdup(envrc);
797 #if defined(WIN32) && (!defined(__MINGW32__)) 801 psqlrc_minor =
psprintf(
"%s-%s", filename, PG_VERSION);
802 psqlrc_major =
psprintf(
"%s-%s", filename, PG_MAJORVERSION);
805 if (access(psqlrc_minor, R_OK) == 0)
807 else if (access(psqlrc_major, R_OK) == 0)
809 else if (access(filename, R_OK) == 0)
825 puts(
"psql (PostgreSQL) " PG_VERSION);
849 else if (newval[0] ==
'\0')
1046 "lower, upper, preserve-lower, preserve-upper");
1075 "none, ignorespace, ignoredups, ignoreboth");
1124 PsqlVarEnumError(
"VERBOSITY", newval,
"default, verbose, terse, sqlstate");
static void parse_psql_options(int argc, char *argv[], struct adhoc_opts *options)
bool ParseVariableNum(const char *value, const char *name, int *result)
static void process_psqlrc(char *argv0)
char * PQerrorMessage(const PGconn *conn)
static char * verbosity_substitute_hook(char *newval)
static void log_pre_callback(void)
PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn, PQnoticeProcessor proc, void *arg)
static void EstablishVariableSpace(void)
void * pg_malloc(size_t size)
const char * get_progname(const char *argv0)
#define pg_log_error(...)
PsqlScanState psql_scan_create(const PsqlScanCallbacks *callbacks)
int getopt_long(int argc, char *const argv[], const char *optstring, const struct option *longopts, int *longindex)
static bool on_error_stop_hook(const char *newval)
char * pstrdup(const char *in)
void pg_logging_init(const char *argv0)
char * psprintf(const char *fmt,...)
void PsqlVarEnumError(const char *name, const char *value, const char *suggestions)
static bool echo_hook(const char *newval)
void pg_logging_set_pre_callback(void(*cb)(void))
unicode_linestyle unicode_header_linestyle
void PQfinish(PGconn *conn)
static bool quiet_hook(const char *newval)
bool SetVariableBool(VariableSpace space, const char *name)
char * simple_prompt(const char *prompt, bool echo)
int pg_strcasecmp(const char *s1, const char *s2)
static void simple_action_list_append(SimpleActionList *list, enum _actions action, const char *val)
static void log_locus_callback(const char **filename, uint64 *lineno)
PSQL_ERROR_ROLLBACK on_error_rollback
unicode_linestyle unicode_border_linestyle
static void showVersion(void)
static void process_file(const char *filename, int weight)
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
static bool histcontrol_hook(const char *newval)
char * PQuser(const PGconn *conn)
static char * bool_substitute_hook(char *newval)
int main(int argc, char *argv[])
VariableSpace CreateVariableSpace(void)
unsigned short int border
static bool prompt2_hook(const char *newval)
static bool hide_tableam_hook(const char *newval)
#define required_argument
unsigned short int expanded
SimpleActionListCell * head
PSQL_ECHO_HIDDEN echo_hidden
SimpleActionListCell * tail
void expand_tilde(char **filename)
unicode_linestyle unicode_column_linestyle
bool DeleteVariable(VariableSpace space, const char *name)
static bool singleline_hook(const char *newval)
int find_my_exec(const char *argv0, char *retpath)
static char * echo_substitute_hook(char *newval)
const PsqlScanCallbacks psqlscan_callbacks
#define DEFAULT_RECORD_SEP
static bool autocommit_hook(const char *newval)
char * pg_strdup(const char *in)
bool do_pset(const char *param, const char *value, printQueryOpt *popt, bool quiet)
static char * comp_keyword_case_substitute_hook(char *newval)
static bool fetch_count_hook(const char *newval)
void pg_logging_set_locus_callback(void(*cb)(const char **filename, uint64 *lineno))
static bool singlestep_hook(const char *newval)
static bool show_context_hook(const char *newval)
struct SimpleActionListCell * next
static bool on_error_rollback_hook(const char *newval)
static char * show_context_substitute_hook(char *newval)
static bool histsize_hook(const char *newval)
char my_exec_path[MAXPGPATH]
#define PG_TEXTDOMAIN(domain)
ConditionalStack conditional_stack_create(void)
PGContextVisibility show_context
void helpVariables(unsigned short int pager)
static void process_psqlrc_file(char *filename)
#define DEFAULT_CSV_FIELD_SEP
bool setQFout(const char *fname)
void psql_scan_destroy(PsqlScanState state)
PGresult * last_error_result
PGContextVisibility PQsetErrorContextVisibility(PGconn *conn, PGContextVisibility show_context)
static char * histsize_substitute_hook(char *newval)
void get_etc_path(const char *my_exec_path, char *ret_path)
void SetVariableHooks(VariableSpace space, const char *name, VariableSubstituteHook shook, VariableAssignHook ahook)
struct SimpleActionList SimpleActionList
void PQclear(PGresult *res)
bool standard_strings(void)
struct separator fieldSep
void NoticeProcessor(void *arg, const char *message)
struct SimpleActionListCell SimpleActionListCell
#define Assert(condition)
bool SetVariable(VariableSpace space, const char *name, const char *value)
#define PARAMS_ARRAY_SIZE
int MainLoop(FILE *source)
static bool comp_keyword_case_hook(const char *newval)
void pg_logging_config(int new_flags)
enum trivalue getPassword
void setDecimalLocale(void)
static char * histcontrol_substitute_hook(char *newval)
#define optional_argument
static bool ignoreeof_hook(const char *newval)
static char * ignoreeof_substitute_hook(char *newval)
void conditional_stack_destroy(ConditionalStack cstack)
static bool prompt1_hook(const char *newval)
bool ParseVariableBool(const char *value, const char *name, bool *result)
static Datum values[MAXATTR]
int PQconnectionNeedsPassword(const PGconn *conn)
#define PG_LOG_FLAG_TERSE
void set_pglocale_pgservice(const char *argv0, const char *app)
void psql_scan_set_passthrough(PsqlScanState state, void *passthrough)
void psql_setup_cancel_handler(void)
static bool histfile_hook(const char *newval)
void refresh_utf8format(const printTableOpt *opt)
void psql_scan_setup(PsqlScanState state, const char *line, int line_len, int encoding, bool std_strings)
bool SendQuery(const char *query)
void connection_warnings(bool in_startup)
static bool verbosity_hook(const char *newval)
static char * fetch_count_substitute_hook(char *newval)
static bool prompt3_hook(const char *newval)
struct separator recordSep
#define pg_log_warning(...)
backslashResult HandleSlashCmds(PsqlScanState scan_state, ConditionalStack cstack, PQExpBuffer query_buf, PQExpBuffer previous_buf)
static bool echo_hidden_hook(const char *newval)
ConnStatusType PQstatus(const PGconn *conn)
#define DEFAULT_FIELD_SEP
PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity)
void slashUsage(unsigned short int pager)
bool listAllDbs(const char *pattern, bool verbose)
bool get_home_path(char *ret_path)
PGresult * PSQLexec(const char *query)
#define pg_log_fatal(...)