1/*-------------------------------------------------------------------------
4 * Common support routines for bin/scripts/
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/bin/scripts/common.c
12 *-------------------------------------------------------------------------
28 * Split TABLE[(COLUMNS)] into TABLE and [(COLUMNS)] portions. When you
29 * finish using them, pg_free(*table). *columns is a pointer into "spec",
30 * possibly to its NUL terminator.
34 char **
table,
const char **columns)
36 bool inquotes =
false;
37 const char *cp = spec;
40 * Find the first '(' not identifier-quoted. Based on
41 * dequote_downcase_identifier().
43 while (*cp && (*cp !=
'(' || inquotes))
47 if (inquotes && cp[1] ==
'"')
48 cp++;
/* pair does not affect quoting */
61 * Break apart TABLE[(COLUMNS)] of "spec". With the reset_val of search_path
62 * in effect, have regclassin() interpret the TABLE portion. Append to "buf"
63 * the qualified name of TABLE, followed by any (COLUMNS). Exit on failure.
64 * We use this to interpret --table=foo under the search path psql would get,
65 * in advance of "ANALYZE public.foo" under the always-secure search path.
80 * Query must remain ABSOLUTELY devoid of unqualified names. This would
81 * be unnecessary given a regclassin() variant taking a search_path
86 "SELECT c.relname, ns.nspname\n"
87 " FROM pg_catalog.pg_class c,"
88 " pg_catalog.pg_namespace ns\n"
89 " WHERE c.relnamespace OPERATOR(pg_catalog.=) ns.oid\n"
90 " AND c.oid OPERATOR(pg_catalog.=) ");
97 * One row is a typical result, as is a nonexistent relation ERROR.
98 * regclassin() unconditionally accepts all-digits input as an OID; if no
99 * relation has that OID; this query returns no rows. Catalog corruption
100 * might elicit other row counts.
107 "query returned %d rows instead of one: %s",
127 * Check yes/no answer in a localized way. 1=yes, 0=no, -1=neither.
130/* translator: abbreviation for "yes" */
131 #define PG_YESLETTER gettext_noop("y")
132/* translator: abbreviation for "no" */
133 #define PG_NOLETTER gettext_noop("n")
141 translator: This is a question followed by the translated options for
143 snprintf(prompt,
sizeof(prompt),
_(
"%s (%s/%s) "),
164 printf(
_(
"Please answer \"%s\" or \"%s\".\n"),
bool yesno_prompt(const char *question)
void splitTableColumnsSpec(const char *spec, int encoding, char **table, const char **columns)
void appendQualifiedRelation(PQExpBuffer buf, const char *spec, PGconn *conn, bool echo)
#define ngettext(s, p, n)
#define ALWAYS_SECURE_SEARCH_PATH_SQL
PGresult * executeQuery(PGconn *conn, const char *query)
int PQclientEncoding(const PGconn *conn)
void PQfinish(PGconn *conn)
int PQmblenBounded(const char *s, int encoding)
#define pg_log_error(...)
char * pnstrdup(const char *in, Size len)
static void executeCommand(PGconn *conn, const char *query)
static const struct lconv_member_info table[]
void initPQExpBuffer(PQExpBuffer str)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * simple_prompt(const char *prompt, bool echo)
const char * fmtQualifiedIdEnc(const char *schema, const char *id, int encoding)
void appendStringLiteralConn(PQExpBuffer buf, const char *str, PGconn *conn)