58 if (!fname || fname[0] ==
'\0')
63 else if (*fname ==
'|')
218 pg_log_error(
"cannot escape without active connection");
259 pg_log_error(
"shell command argument contains a newline or carriage return: \"%s\"",
367 fprintf(
stderr,
_(
"The connection to the server was lost. Attempting reset: "));
621 printf(
_(
"Time: %.3f ms (%02d:%06.3f)\n"),
630 printf(
_(
"Time: %.3f ms (%02d:%02d:%06.3f)\n"),
637 printf(
_(
"Time: %.3f ms (%.0f d %02d:%02d:%06.3f)\n"),
661 pg_log_error(
"You are currently not connected to a database.");
667 printf(
_(
"/******** QUERY *********/\n"
669 "/************************/\n\n"), query);
674 _(
"/******** QUERY *********/\n"
676 "/************************/\n\n"), query);
718 pg_log_error(
"You are currently not connected to a database.");
749 fprintf(
pset.
queryFout,
_(
"Asynchronous notification \"%s\" with payload \"%s\" received from server process with PID %d.\n"),
752 fprintf(
pset.
queryFout,
_(
"Asynchronous notification \"%s\" received from server process with PID %d.\n"),
826 pg_log_warning(
"attempt to \\gset into specially treated variable \"%s\" ignored",
874 for (r = 0; r < nrows; r++)
876 for (
c = 0;
c < ncolumns;
c++)
1130 pg_log_error(
"You are currently not connected to a database.");
1139 printf(
_(
"/**(Single step mode: verify command)******************************************/\n"
1141 "/**(press return to proceed or enter x and return to cancel)*******************/\n"),
1159 _(
"/******** QUERY *********/\n"
1161 "/************************/\n\n"), query);
1193 result =
PQexec(
pset.
db,
"SAVEPOINT pg_psql_temporary_savepoint");
1229 svptcmd =
"ROLLBACK TO pg_psql_temporary_savepoint";
1243 svptcmd =
"RELEASE pg_psql_temporary_savepoint";
1396 "SELECT name AS \"%s\", pg_catalog.format_type(tp, tpm) AS \"%s\"\n"
1448 _(
"The command has no result, or the result has no columns.\n"));
1498 else if (res ==
NULL)
1769 while (result !=
NULL)
1797 pg_log_info(
"Pipeline aborted, command did not run");
1856 strcmp(cmd,
"SAVEPOINT") == 0 ||
1857 strcmp(cmd,
"RELEASE") == 0 ||
1858 strcmp(cmd,
"ROLLBACK") == 0);
1893 pg_log_info(
"COPY in a pipeline is not supported, aborting connection");
1942 int64 total_tuples = 0;
1948 my_popt.topt.stop_table =
false;
1949 my_popt.topt.prior_records = 0;
1981 my_popt.topt.start_table =
false;
2003 my_popt.topt.stop_table =
true;
2217 if (
isspace((
unsigned char) *query))
2219 else if (query[0] ==
'/' && query[1] ==
'*')
2224 else if (
cnestlevel > 0 && query[0] ==
'*' && query[1] ==
'/')
2229 else if (
cnestlevel == 0 && query[0] ==
'-' && query[1] ==
'-')
2278 while (
isalpha((
unsigned char) query[wordlen]))
2309 while (
isalpha((
unsigned char) query[wordlen]))
2312 if (wordlen == 11 &&
pg_strncasecmp(query,
"transaction", 11) == 0)
2331 if (
isalpha((
unsigned char) query[0]))
2343 while (
isalpha((
unsigned char) query[wordlen]))
2348 if (wordlen == 10 &&
pg_strncasecmp(query,
"tablespace", 10) == 0)
2359 while (
isalpha((
unsigned char) query[wordlen]))
2370 while (
isalpha((
unsigned char) query[wordlen]))
2373 if (wordlen == 12 &&
pg_strncasecmp(query,
"concurrently", 12) == 0)
2387 while (
isalpha((
unsigned char) query[wordlen]))
2410 while (
isalpha((
unsigned char) query[wordlen]))
2417 if (wordlen == 10 &&
pg_strncasecmp(query,
"tablespace", 10) == 0)
2425 while (
isalpha((
unsigned char) query[wordlen]))
2432 if (wordlen == 12 &&
pg_strncasecmp(query,
"concurrently", 12) == 0)
2444 while (
isalpha((
unsigned char) query[wordlen]))
2447 if (wordlen == 12 &&
pg_strncasecmp(query,
"concurrently", 12) == 0)
2464 while (
isalpha((
unsigned char) query[wordlen]))
2555 if (
strcmp(opt->keyword, keyword) == 0)
2601 while (*p !=
'/' && *p !=
'\0')
2607 if (*(
fn + 1) ==
'\0')
void expand_tilde(char **filename)
PGresult * PSQLexec(const char *query)
void psql_setup_cancel_handler(void)
volatile sig_atomic_t sigint_interrupt_enabled
static bool PrintQueryResult(PGresult *result, bool last, const printQueryOpt *opt, FILE *printQueryFout, FILE *printStatusFout)
static bool CheckConnection(void)
const char * session_username(void)
static void PrintQueryStatus(PGresult *result, FILE *printQueryFout)
static int uri_prefix_length(const char *connstr)
static bool DescribeQuery(const char *query, double *elapsed_msec)
static void ClearOrSaveAllResults(void)
static PGresult * discardAbortedPipelineResults(void)
char * get_conninfo_value(const char *keyword)
static bool ExecQueryTuples(const PGresult *result)
static void PrintNotifications(void)
static void SetResultVariables(PGresult *result, bool success)
char * psql_get_variable(const char *varname, PsqlScanQuoteType quote, void *passthrough)
sigjmp_buf sigint_interrupt_jmp
static void ClearOrSaveResult(PGresult *result)
static bool SetupGOutput(FILE **gfile_fout, bool *is_pipe)
static void psql_cancel_callback(void)
static bool AcceptResult(const PGresult *result, bool show_error)
static bool HandleCopyResult(PGresult **resultp, FILE *copystream)
int PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE *printQueryFout, int min_rows)
void SetShellResultVariables(int wait_result)
void NoticeProcessor(void *arg, const char *message)
void clean_extended_state(void)
static bool StoreQueryTuple(const PGresult *result)
static void CloseGOutput(FILE *gfile_fout, bool is_pipe)
static const char * skip_white_space(const char *query)
bool standard_strings(void)
static void SetPipelineVariables(void)
static bool PrintQueryTuples(const PGresult *result, const printQueryOpt *opt, FILE *printQueryFout)
static void pipelineReset(void)
static bool ConnectionUp(void)
bool setQFout(const char *fname)
static int ExecQueryAndProcessResults(const char *query, double *elapsed_msec, bool *svpt_gone_p, bool is_watch, int min_rows, const printQueryOpt *opt, FILE *printQueryFout)
bool openQueryOutputFile(const char *fname, FILE **fout, bool *is_pipe)
bool recognized_connection_string(const char *connstr)
static void PrintTiming(double elapsed_msec)
bool SendQuery(const char *query)
static bool command_no_begin(const char *query)
bool handleCopyOut(PGconn *conn, FILE *copystream, PGresult **res)
bool handleCopyIn(PGconn *conn, FILE *copystream, bool isbinary, PGresult **res)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
void ResetCancelConn(void)
void SetCancelConn(PGconn *conn)
void setup_cancel_handler(void(*query_cancel_callback)(void))
void restorePsetInfo(printQueryOpt *popt, printQueryOpt *save)
void UnsyncVariables(void)
void connection_warnings(bool in_startup)
bool conditional_active(ConditionalStack cstack)
bool PrintResultInCrosstab(const PGresult *res)
#define fprintf(file, fmt, msg)
void PQreset(PGconn *conn)
static const char short_uri_designator[]
PGTransactionStatusType PQtransactionStatus(const PGconn *conn)
PQconninfoOption * PQconninfo(PGconn *conn)
void PQconninfoFree(PQconninfoOption *connOptions)
static const char uri_designator[]
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
ConnStatusType PQstatus(const PGconn *conn)
int PQclientEncoding(const PGconn *conn)
void PQfinish(PGconn *conn)
char * PQuser(const PGconn *conn)
PGpipelineStatus PQpipelineStatus(const PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
int PQsendQueryParams(PGconn *conn, const char *command, int nParams, const Oid *paramTypes, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
int PQbinaryTuples(const PGresult *res)
int PQflush(PGconn *conn)
void PQfreemem(void *ptr)
Oid PQftype(const PGresult *res, int field_num)
PGresult * PQdescribePrepared(PGconn *conn, const char *stmt)
int PQexitPipelineMode(PGconn *conn)
int PQenterPipelineMode(PGconn *conn)
int PQsendClosePrepared(PGconn *conn, const char *stmt)
int PQsendPipelineSync(PGconn *conn)
PGresult * PQprepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)
int PQconsumeInput(PGconn *conn)
char * PQescapeLiteral(PGconn *conn, const char *str, size_t len)
int PQsendPrepare(PGconn *conn, const char *stmtName, const char *query, int nParams, const Oid *paramTypes)
int PQfmod(const PGresult *res, int field_num)
int PQsetChunkedRowsMode(PGconn *conn, int chunkSize)
int PQsendQuery(PGconn *conn, const char *query)
int PQpipelineSync(PGconn *conn)
PGresult * PQexec(PGconn *conn, const char *query)
int PQsendQueryPrepared(PGconn *conn, const char *stmtName, int nParams, const char *const *paramValues, const int *paramLengths, const int *paramFormats, int resultFormat)
char * PQescapeIdentifier(PGconn *conn, const char *str, size_t len)
int PQsendFlushRequest(PGconn *conn)
Oid PQoidValue(const PGresult *res)
PGnotify * PQnotifies(PGconn *conn)
int PQmblenBounded(const char *s, int encoding)
char * pg_strdup(const char *in)
void restore_sigpipe_trap(void)
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
FILE * PageOutput(int lines, const printTableOpt *topt)
void ClosePager(FILE *pagerpipe)
void disable_sigpipe_trap(void)
void html_escaped_print(const char *in, FILE *fout)
void set_sigpipe_trap_state(bool ignore)
volatile sig_atomic_t cancel_pressed
#define INSTR_TIME_SET_CURRENT(t)
#define INSTR_TIME_SUBTRACT(x, y)
#define INSTR_TIME_GET_MILLISEC(t)
#define INSTR_TIME_SET_ZERO(t)
#define PQresultErrorMessage
#define PQresultErrorField
#define pg_log_error(...)
static AmcheckOptions opts
static const char * connstr
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define pg_encoding_to_char
#define pg_log_warning(...)
bool get_home_path(char *ret_path)
size_t strlcpy(char *dst, const char *src, size_t siz)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
#define PG_DIAG_MESSAGE_PRIMARY
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * psprintf(const char *fmt,...)
static int before(chr x, chr y)
@ PSQL_ERROR_ROLLBACK_OFF
@ PSQL_ECHO_HIDDEN_NOEXEC
@ PSQL_SEND_PIPELINE_SYNC
@ PSQL_SEND_FLUSH_REQUEST
@ PSQL_SEND_START_PIPELINE_MODE
@ PSQL_SEND_EXTENDED_QUERY_PARAMS
@ PSQL_SEND_EXTENDED_PARSE
@ PSQL_SEND_END_PIPELINE_MODE
@ PSQL_SEND_EXTENDED_CLOSE
@ PSQL_SEND_EXTENDED_QUERY_PREPARED
bool appendShellStringNoError(PQExpBuffer buf, const char *str)
PSQL_ERROR_ROLLBACK on_error_rollback
PGresult * last_error_result
PSQL_ECHO_HIDDEN echo_hidden
printQueryOpt * gsavepopt
static void * fn(void *arg)
bool VariableHasHook(VariableSpace space, const char *name)
bool SetVariable(VariableSpace space, const char *name, const char *value)
const char * GetVariable(VariableSpace space, const char *name)
int wait_result_to_exit_code(int exit_status)