PostgreSQL Source Code  git master
common.h
Go to the documentation of this file.
1 /*
2  * common.h
3  * Common support routines for bin/scripts/
4  *
5  * Copyright (c) 2003-2021, PostgreSQL Global Development Group
6  *
7  * src/bin/scripts/common.h
8  */
9 #ifndef COMMON_H
10 #define COMMON_H
11 
12 #include "common/username.h"
13 #include "getopt_long.h" /* pgrminclude ignore */
14 #include "libpq-fe.h"
15 #include "pqexpbuffer.h" /* pgrminclude ignore */
16 
18 {
22 };
23 
24 /* Parameters needed by connectDatabase/connectMaintenanceDatabase */
25 typedef struct _connParams
26 {
27  /* These fields record the actual command line parameters */
28  const char *dbname; /* this may be a connstring! */
29  const char *pghost;
30  const char *pgport;
31  const char *pguser;
33  /* If not NULL, this overrides the dbname obtained from command line */
34  /* (but *only* the DB name, not anything else in the connstring) */
35  const char *override_dbname;
36 } ConnParams;
37 
38 typedef void (*help_handler) (const char *progname);
39 
40 extern void handle_help_version_opts(int argc, char *argv[],
41  const char *fixed_progname,
42  help_handler hlp);
43 
44 extern PGconn *connectDatabase(const ConnParams *cparams,
45  const char *progname,
46  bool echo, bool fail_ok,
47  bool allow_password_reuse);
48 
50  const char *progname, bool echo);
51 
52 extern void disconnectDatabase(PGconn *conn);
53 
54 extern PGresult *executeQuery(PGconn *conn, const char *query, bool echo);
55 
56 extern void executeCommand(PGconn *conn, const char *query, bool echo);
57 
58 extern bool executeMaintenanceCommand(PGconn *conn, const char *query,
59  bool echo);
60 
61 extern bool consumeQueryResult(PGconn *conn);
62 
63 extern bool processQueryResult(PGconn *conn, PGresult *result);
64 
65 extern void splitTableColumnsSpec(const char *spec, int encoding,
66  char **table, const char **columns);
67 
68 extern void appendQualifiedRelation(PQExpBuffer buf, const char *name,
69  PGconn *conn, bool echo);
70 
71 extern bool yesno_prompt(const char *question);
72 
73 #endif /* COMMON_H */
PGconn * connectDatabase(const ConnParams *cparams, const char *progname, bool echo, bool fail_ok, bool allow_password_reuse)
Definition: common.c:65
void splitTableColumnsSpec(const char *spec, int encoding, char **table, const char **columns)
Definition: common.c:351
Definition: common.h:20
bool yesno_prompt(const char *question)
Definition: common.c:453
void handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp)
Definition: common.c:34
const char * progname
Definition: pg_standby.c:36
bool consumeQueryResult(PGconn *conn)
Definition: common.c:299
bool processQueryResult(PGconn *conn, PGresult *result)
Definition: common.c:320
bool executeMaintenanceCommand(PGconn *conn, const char *query, bool echo)
Definition: common.c:273
PGconn * conn
Definition: streamutil.c:54
PGresult * executeQuery(PGconn *conn, const char *query, bool echo)
Definition: common.c:221
static char * buf
Definition: pg_test_fsync.c:68
Definition: common.h:21
enum trivalue prompt_password
Definition: common.h:32
PGconn * connectMaintenanceDatabase(ConnParams *cparams, const char *progname, bool echo)
Definition: common.c:173
trivalue
Definition: vacuumlo.c:34
const char * dbname
Definition: common.h:28
void(* help_handler)(const char *progname)
Definition: common.h:38
void disconnectDatabase(PGconn *conn)
Definition: common.c:197
int32 encoding
Definition: pg_database.h:41
const char * name
Definition: encode.c:515
const char * pghost
Definition: common.h:29
const char * pgport
Definition: common.h:30
const char * override_dbname
Definition: common.h:35
void appendQualifiedRelation(PQExpBuffer buf, const char *name, PGconn *conn, bool echo)
Definition: common.c:386
void executeCommand(PGconn *conn, const char *query, bool echo)
Definition: common.c:246
struct _connParams ConnParams
const char * pguser
Definition: common.h:31