PostgreSQL Source Code
git master
|
#include "postgres_fe.h"
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <pwd.h>
#include <signal.h>
#include <unistd.h>
#include "command.h"
#include "common.h"
#include "common/logging.h"
#include "copy.h"
#include "crosstabview.h"
#include "fe_utils/cancel.h"
#include "fe_utils/mbprint.h"
#include "fe_utils/string_utils.h"
#include "portability/instr_time.h"
#include "settings.h"
Go to the source code of this file.
Functions | |
static bool | DescribeQuery (const char *query, double *elapsed_msec) |
static int | ExecQueryAndProcessResults (const char *query, double *elapsed_msec, bool *svpt_gone_p, bool is_watch, int min_rows, const printQueryOpt *opt, FILE *printQueryFout) |
static bool | command_no_begin (const char *query) |
bool | openQueryOutputFile (const char *fname, FILE **fout, bool *is_pipe) |
static bool | SetupGOutput (FILE **gfile_fout, bool *is_pipe) |
static void | CloseGOutput (FILE *gfile_fout, bool is_pipe) |
bool | setQFout (const char *fname) |
char * | psql_get_variable (const char *varname, PsqlScanQuoteType quote, void *passthrough) |
void | NoticeProcessor (void *arg, const char *message) |
static void | psql_cancel_callback (void) |
void | psql_setup_cancel_handler (void) |
static bool | ConnectionUp (void) |
static bool | CheckConnection (void) |
static bool | AcceptResult (const PGresult *result, bool show_error) |
static void | SetResultVariables (PGresult *result, bool success) |
void | SetShellResultVariables (int wait_result) |
static void | ClearOrSaveResult (PGresult *result) |
static void | ClearOrSaveAllResults (void) |
static void | PrintTiming (double elapsed_msec) |
PGresult * | PSQLexec (const char *query) |
int | PSQLexecWatch (const char *query, const printQueryOpt *opt, FILE *printQueryFout, int min_rows) |
static void | PrintNotifications (void) |
static bool | PrintQueryTuples (const PGresult *result, const printQueryOpt *opt, FILE *printQueryFout) |
static bool | StoreQueryTuple (const PGresult *result) |
static bool | ExecQueryTuples (const PGresult *result) |
static bool | HandleCopyResult (PGresult **resultp, FILE *copystream) |
static void | PrintQueryStatus (PGresult *result, FILE *printQueryFout) |
static bool | PrintQueryResult (PGresult *result, bool last, const printQueryOpt *opt, FILE *printQueryFout, FILE *printStatusFout) |
bool | SendQuery (const char *query) |
static const char * | skip_white_space (const char *query) |
bool | is_superuser (void) |
bool | standard_strings (void) |
const char * | session_username (void) |
void | expand_tilde (char **filename) |
static int | uri_prefix_length (const char *connstr) |
void | clean_extended_state (void) |
bool | recognized_connection_string (const char *connstr) |
Variables | |
volatile sig_atomic_t | sigint_interrupt_enabled = false |
sigjmp_buf | sigint_interrupt_jmp |
|
static |
Definition at line 403 of file common.c.
References CheckConnection(), _psqlSettings::db, error(), pg_log_error, pg_log_info, PGRES_BAD_RESPONSE, PGRES_COMMAND_OK, PGRES_COPY_IN, PGRES_COPY_OUT, PGRES_EMPTY_QUERY, PGRES_FATAL_ERROR, PGRES_NONFATAL_ERROR, PGRES_TUPLES_CHUNK, PGRES_TUPLES_OK, PQerrorMessage(), PQresultStatus(), and pset.
Referenced by DescribeQuery(), ExecQueryAndProcessResults(), and PSQLexec().
|
static |
Definition at line 342 of file common.c.
References _, connection_warnings(), ConnectionUp(), _psqlSettings::cur_cmd_interactive, _psqlSettings::db, _psqlSettings::dead_conn, exit(), EXIT_BADCONN, fprintf, pg_log_error, PQfinish(), PQreset(), pset, ResetCancelConn(), SyncVariables(), and UnsyncVariables().
Referenced by AcceptResult(), and ExecQueryAndProcessResults().
void clean_extended_state | ( | void | ) |
Definition at line 2279 of file common.c.
References _psqlSettings::bind_nparams, _psqlSettings::bind_params, free, i, pset, PSQL_SEND_EXTENDED_CLOSE, PSQL_SEND_EXTENDED_PARSE, PSQL_SEND_EXTENDED_QUERY_PARAMS, PSQL_SEND_EXTENDED_QUERY_PREPARED, PSQL_SEND_QUERY, _psqlSettings::send_mode, and _psqlSettings::stmtName.
Referenced by exec_command_bind(), exec_command_bind_named(), exec_command_close(), exec_command_parse(), and SendQuery().
|
static |
Definition at line 547 of file common.c.
References ClearOrSaveResult(), _psqlSettings::db, PQgetResult(), and pset.
Referenced by ExecQueryAndProcessResults().
|
static |
Definition at line 523 of file common.c.
References _psqlSettings::last_error_result, PGRES_FATAL_ERROR, PGRES_NONFATAL_ERROR, PQclear(), PQresultStatus(), and pset.
Referenced by ClearOrSaveAllResults(), DescribeQuery(), ExecQueryAndProcessResults(), PSQLexec(), and SendQuery().
|
static |
Definition at line 110 of file common.c.
References restore_sigpipe_trap(), and SetShellResultVariables().
Referenced by ExecQueryAndProcessResults().
|
static |
Definition at line 1919 of file common.c.
References _psqlSettings::encoding, pg_strncasecmp(), PQmblenBounded(), pset, and skip_white_space().
Referenced by SendQuery().
|
static |
Definition at line 324 of file common.c.
References CONNECTION_BAD, _psqlSettings::db, PQstatus(), and pset.
Referenced by CheckConnection(), and SendQuery().
|
static |
Definition at line 1314 of file common.c.
References _, AcceptResult(), appendPQExpBuffer(), appendPQExpBufferStr(), before(), buf, ClearOrSaveResult(), _psqlSettings::db, fprintf, gettext_noop, i, initPQExpBuffer(), INSTR_TIME_GET_MILLISEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SET_ZERO, INSTR_TIME_SUBTRACT, name, pg_log_info, PGRES_COMMAND_OK, PQclear(), PQdescribePrepared(), PQerrorMessage(), PQescapeLiteral(), PQexec(), PQfmod(), PQfname(), PQfreemem(), PQftype(), PQnfields(), PQprepare(), PQresultStatus(), printfPQExpBuffer(), PrintQueryResult(), pset, _psqlSettings::queryFout, SetResultVariables(), termPQExpBuffer(), and _psqlSettings::timing.
Referenced by SendQuery().
|
static |
Definition at line 1446 of file common.c.
References AcceptResult(), Assert, before(), _psqlSettings::bind_nparams, _psqlSettings::bind_params, buf, cancel_pressed, CheckConnection(), ClearOrSaveAllResults(), ClearOrSaveResult(), CloseGOutput(), ClosePager(), _psqlSettings::copyStream, _psqlSettings::crosstab_flag, _psqlSettings::db, error(), _psqlSettings::fetch_count, fflush(), _psqlSettings::gexec_flag, _psqlSettings::gfname, _psqlSettings::gset_prefix, HandleCopyResult(), INSTR_TIME_GET_MILLISEC, INSTR_TIME_SET_CURRENT, INSTR_TIME_SET_ZERO, INSTR_TIME_SUBTRACT, INT64_FORMAT, _psqlSettings::logfile, PageOutput(), pg_log_info, pg_log_warning, PGRES_COPY_BOTH, PGRES_COPY_IN, PGRES_COPY_OUT, PGRES_TUPLES_CHUNK, PGRES_TUPLES_OK, _psqlSettings::popt, PQcmdStatus(), PQerrorMessage(), PQgetResult(), PQntuples(), PQresultErrorMessage(), PQresultStatus(), PQsendClosePrepared(), PQsendPrepare(), PQsendQuery(), PQsendQueryParams(), PQsendQueryPrepared(), PQsetChunkedRowsMode(), printQuery(), PrintQueryResult(), PrintQueryStatus(), printTableOpt::prior_records, pset, PSQL_SEND_EXTENDED_CLOSE, PSQL_SEND_EXTENDED_PARSE, PSQL_SEND_EXTENDED_QUERY_PARAMS, PSQL_SEND_EXTENDED_QUERY_PREPARED, PSQL_SEND_QUERY, _psqlSettings::queryFout, _psqlSettings::send_mode, SetResultVariables(), SetupGOutput(), SetVariable(), _psqlSettings::show_all_results, snprintf, printTableOpt::start_table, generate_unaccent_rules::stdout, _psqlSettings::stmtName, printTableOpt::stop_table, success, _psqlSettings::timing, printQueryOpt::topt, and _psqlSettings::vars.
Referenced by PSQLexecWatch(), and SendQuery().
|
static |
Definition at line 826 of file common.c.
References cancel_pressed, _psqlSettings::echo, fflush(), _psqlSettings::gexec_flag, _psqlSettings::on_error_stop, PQgetisnull(), PQgetvalue(), PQnfields(), PQntuples(), pset, PSQL_ECHO_ALL, SendQuery(), _psqlSettings::singlestep, generate_unaccent_rules::stdout, and success.
Referenced by PrintQueryResult().
void expand_tilde | ( | char ** | filename | ) |
Definition at line 2195 of file common.c.
References filename, fn(), free, get_home_path(), MAXPGPATH, psprintf(), and strlcpy().
Referenced by exec_command_edit(), exec_command_g(), exec_command_include(), exec_command_lo(), exec_command_out(), exec_command_s(), exec_command_write(), initializeInput(), parse_slash_copy(), and process_psqlrc().
|
static |
Definition at line 902 of file common.c.
References Assert, _psqlSettings::copyStream, _psqlSettings::cur_cmd_source, _psqlSettings::db, handleCopyIn(), handleCopyOut(), PGRES_COPY_IN, PGRES_COPY_OUT, PQbinaryTuples(), PQclear(), PQresultStatus(), pset, _psqlSettings::queryFout, ResetCancelConn(), SetCancelConn(), and success.
Referenced by ExecQueryAndProcessResults().
bool is_superuser | ( | void | ) |
Definition at line 2134 of file common.c.
References _psqlSettings::db, PQparameterStatus(), pset, and val.
void NoticeProcessor | ( | void * | arg, |
const char * | message | ||
) |
Definition at line 267 of file common.c.
References arg, and pg_log_info.
Referenced by do_connect(), and main().
bool openQueryOutputFile | ( | const char * | fname, |
FILE ** | fout, | ||
bool * | is_pipe | ||
) |
Definition at line 56 of file common.c.
References fflush(), pg_log_error, and generate_unaccent_rules::stdout.
Referenced by setQFout(), and SetupGOutput().
|
static |
Definition at line 705 of file common.c.
References _, pgNotify::be_pid, _psqlSettings::db, pgNotify::extra, fflush(), fprintf, PQconsumeInput(), PQfreemem(), PQnotifies(), pset, _psqlSettings::queryFout, and pgNotify::relname.
Referenced by SendQuery().
|
static |
Definition at line 1004 of file common.c.
References _psqlSettings::crosstab_flag, ExecQueryTuples(), _psqlSettings::gexec_flag, _psqlSettings::gset_prefix, pg_log_error, PGRES_BAD_RESPONSE, PGRES_COMMAND_OK, PGRES_COPY_IN, PGRES_COPY_OUT, PGRES_EMPTY_QUERY, PGRES_FATAL_ERROR, PGRES_NONFATAL_ERROR, PGRES_TUPLES_OK, PQresultStatus(), PrintQueryStatus(), PrintQueryTuples(), PrintResultInCrosstab(), pset, _psqlSettings::show_all_results, StoreQueryTuple(), and success.
Referenced by DescribeQuery(), and ExecQueryAndProcessResults().
|
static |
Definition at line 957 of file common.c.
References buf, fflush(), printTableOpt::format, fprintf, html_escaped_print(), _psqlSettings::logfile, PGRES_TUPLES_OK, _psqlSettings::popt, PQcmdStatus(), PQoidValue(), PQresultStatus(), PRINT_HTML, pset, _psqlSettings::queryFout, _psqlSettings::quiet, SetVariable(), snprintf, printQueryOpt::topt, and _psqlSettings::vars.
Referenced by ExecQueryAndProcessResults(), and PrintQueryResult().
|
static |
Definition at line 738 of file common.c.
References fflush(), _psqlSettings::logfile, pg_log_error, _psqlSettings::popt, printQuery(), pset, and _psqlSettings::queryFout.
Referenced by PrintQueryResult().
|
static |
Definition at line 561 of file common.c.
References _, days, and printf.
Referenced by PSQLexecWatch(), and SendQuery().
|
static |
Definition at line 297 of file common.c.
References cancel_pressed, sigint_interrupt_enabled, and sigint_interrupt_jmp.
Referenced by psql_setup_cancel_handler().
char* psql_get_variable | ( | const char * | varname, |
PsqlScanQuoteType | quote, | ||
void * | passthrough | ||
) |
Definition at line 176 of file common.c.
References appendShellStringNoError(), buf, conditional_active(), _psqlSettings::db, error(), free, GetVariable(), initPQExpBuffer(), pg_log_error, pg_log_info, pg_strdup(), PQerrorMessage(), PQescapeIdentifier(), PQescapeLiteral(), PQfreemem(), PQUOTE_PLAIN, PQUOTE_SHELL_ARG, PQUOTE_SQL_IDENT, PQUOTE_SQL_LITERAL, pset, value, and _psqlSettings::vars.
void psql_setup_cancel_handler | ( | void | ) |
Definition at line 313 of file common.c.
References psql_cancel_callback(), and setup_cancel_handler().
Referenced by main().
PGresult* PSQLexec | ( | const char * | query | ) |
Definition at line 620 of file common.c.
References _, AcceptResult(), ClearOrSaveResult(), _psqlSettings::db, _psqlSettings::echo_hidden, fflush(), fprintf, _psqlSettings::logfile, pg_log_error, PQexec(), printf, pset, PSQL_ECHO_HIDDEN_NOEXEC, PSQL_ECHO_HIDDEN_OFF, res, ResetCancelConn(), SetCancelConn(), and generate_unaccent_rules::stdout.
Referenced by add_tablespace_footer(), addFooterToPublicationDesc(), describeAccessMethods(), describeAggregates(), describeConfigurationParameters(), describeFunctions(), describeOneTableDetails(), describeOneTSConfig(), describeOneTSParser(), describeOperators(), describePublications(), describeRoleGrants(), describeRoles(), describeSubscriptions(), describeTableDetails(), describeTablespaces(), describeTypes(), do_lo_import(), exec_command_password(), fail_lo_xact(), finish_lo_xact(), listAllDbs(), listCasts(), listCollations(), listConversions(), listDbRoleSettings(), listDefaultACLs(), listDomains(), listEventTriggers(), listExtendedStats(), listExtensionContents(), listExtensions(), listForeignDataWrappers(), listForeignServers(), listForeignTables(), listLanguages(), listLargeObjects(), listOneExtensionContents(), listOperatorClasses(), listOperatorFamilies(), listOpFamilyFunctions(), listOpFamilyOperators(), listPartitionedTables(), listPublications(), listSchemas(), listTables(), listTSConfigs(), listTSConfigsVerbose(), listTSDictionaries(), listTSParsers(), listTSParsersVerbose(), listTSTemplates(), listUserMappings(), main(), objectDescription(), permissionsList(), and start_lo_xact().
int PSQLexecWatch | ( | const char * | query, |
const printQueryOpt * | opt, | ||
FILE * | printQueryFout, | ||
int | min_rows | ||
) |
Definition at line 675 of file common.c.
References _psqlSettings::db, ExecQueryAndProcessResults(), pg_log_error, PrintTiming(), pset, res, ResetCancelConn(), SetCancelConn(), and _psqlSettings::timing.
Referenced by do_watch().
static bool recognized_connection_string | ( | const char * | connstr | ) |
Definition at line 2317 of file common.c.
References connstr, and uri_prefix_length().
Referenced by do_connect().
bool SendQuery | ( | const char * | query | ) |
Definition at line 1082 of file common.c.
References _, _psqlSettings::autocommit, buf, cancel_pressed, clean_extended_state(), ClearOrSaveResult(), command_no_begin(), ConnectionUp(), _psqlSettings::crosstab_flag, _psqlSettings::ctv_args, _psqlSettings::cur_cmd_interactive, _psqlSettings::db, DescribeQuery(), _psqlSettings::echo, _psqlSettings::encoding, printTableOpt::encoding, ExecQueryAndProcessResults(), fflush(), fprintf, free, _psqlSettings::gdesc_flag, _psqlSettings::gexec_flag, _psqlSettings::gfname, _psqlSettings::gsavepopt, _psqlSettings::gset_prefix, i, lengthof, _psqlSettings::logfile, _psqlSettings::on_error_rollback, pg_encoding_to_char, pg_free(), pg_log_error, pg_log_info, PGRES_COMMAND_OK, _psqlSettings::popt, PQclear(), PQclientEncoding(), PQerrorMessage(), PQexec(), PQresultStatus(), PQTRANS_ACTIVE, PQTRANS_IDLE, PQTRANS_INERROR, PQTRANS_INTRANS, PQTRANS_UNKNOWN, PQtransactionStatus(), printf, PrintNotifications(), PrintTiming(), pset, PSQL_ECHO_ERRORS, PSQL_ECHO_QUERIES, PSQL_ERROR_ROLLBACK_OFF, PSQL_ERROR_ROLLBACK_ON, ResetCancelConn(), restorePsetInfo(), SetCancelConn(), SetVariable(), _psqlSettings::singlestep, generate_unaccent_rules::stdout, _psqlSettings::timing, printQueryOpt::topt, and _psqlSettings::vars.
Referenced by do_copy(), ExecQueryTuples(), main(), and MainLoop().
const char* session_username | ( | void | ) |
Definition at line 2174 of file common.c.
References _psqlSettings::db, PQparameterStatus(), PQuser(), pset, and val.
Referenced by get_prompt().
bool setQFout | ( | const char * | fname | ) |
Definition at line 132 of file common.c.
References openQueryOutputFile(), pset, _psqlSettings::queryFout, _psqlSettings::queryFoutPipe, restore_sigpipe_trap(), set_sigpipe_trap_state(), SetShellResultVariables(), and generate_unaccent_rules::stdout.
Referenced by exec_command_out(), main(), and parse_psql_options().
|
static |
Definition at line 461 of file common.c.
References PG_DIAG_MESSAGE_PRIMARY, PG_DIAG_SQLSTATE, PQcmdTuples(), PQresultErrorField(), pset, SetVariable(), success, and _psqlSettings::vars.
Referenced by DescribeQuery(), and ExecQueryAndProcessResults().
void SetShellResultVariables | ( | int | wait_result | ) |
Definition at line 501 of file common.c.
References buf, pset, SetVariable(), snprintf, _psqlSettings::vars, and wait_result_to_exit_code().
Referenced by CloseGOutput(), do_copy(), do_shell(), exec_command_write(), and setQFout().
|
static |
Definition at line 90 of file common.c.
References disable_sigpipe_trap(), _psqlSettings::gfname, openQueryOutputFile(), and pset.
Referenced by ExecQueryAndProcessResults().
|
static |
Definition at line 1855 of file common.c.
References _psqlSettings::encoding, PQmblenBounded(), and pset.
Referenced by command_no_begin().
bool standard_strings | ( | void | ) |
Definition at line 2154 of file common.c.
References _psqlSettings::db, PQparameterStatus(), pset, and val.
Referenced by get_create_object_cmd(), main(), MainLoop(), and parse_slash_copy().
|
static |
Definition at line 762 of file common.c.
References free, _psqlSettings::gset_prefix, i, pg_log_error, pg_log_warning, PQfname(), PQgetisnull(), PQgetvalue(), PQnfields(), PQntuples(), pset, psprintf(), SetVariable(), success, value, VariableHasHook(), and _psqlSettings::vars.
Referenced by PrintQueryResult().
|
static |
Definition at line 2253 of file common.c.
References connstr, short_uri_designator, and uri_designator.
Referenced by recognized_connection_string().
volatile sig_atomic_t sigint_interrupt_enabled = false |
Definition at line 292 of file common.c.
Referenced by exec_command_password(), exec_command_prompt(), gets_fromFile(), gets_interactive(), handleCopyIn(), MainLoop(), prompt_for_password(), and psql_cancel_callback().
sigjmp_buf sigint_interrupt_jmp |
Definition at line 294 of file common.c.
Referenced by exec_command_password(), exec_command_prompt(), handleCopyIn(), MainLoop(), prompt_for_password(), and psql_cancel_callback().