1/*
2 * common.h
3 * Common support routines for bin/scripts/
4 *
5 * Copyright (c) 2003-2019, 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 "libpq-fe.h"
14#include "getopt_long.h" /* pgrminclude ignore */
15#include "pqexpbuffer.h" /* pgrminclude ignore */
16
17enum trivalue
18{
19 TRI_DEFAULT,
20 TRI_NO,
21 TRI_YES
22};
23
24extern bool CancelRequested;
25
26typedef void (*help_handler) (const char *progname);
27
28extern void handle_help_version_opts(int argc, char *argv[],
29 const char *fixed_progname,
30 help_handler hlp);
31
32extern PGconn *connectDatabase(const char *dbname, const char *pghost,
33 const char *pgport, const char *pguser,
34 enum trivalue prompt_password, const char *progname,
35 bool echo, bool fail_ok, bool allow_password_reuse);
36
37extern PGconn *connectMaintenanceDatabase(const char *maintenance_db,
38 const char *pghost, const char *pgport,
39 const char *pguser, enum trivalue prompt_password,
40 const char *progname, bool echo);
41
42extern PGresult *executeQuery(PGconn *conn, const char *query,
43 const char *progname, bool echo);
44
45extern void executeCommand(PGconn *conn, const char *query,
46 const char *progname, bool echo);
47
48extern bool executeMaintenanceCommand(PGconn *conn, const char *query,
49 bool echo);
50
51extern void splitTableColumnsSpec(const char *spec, int encoding,
52 char **table, const char **columns);
53
54extern void appendQualifiedRelation(PQExpBuffer buf, const char *name,
55 PGconn *conn, const char *progname, bool echo);
56
57extern bool yesno_prompt(const char *question);
58
59extern void setup_cancel_handler(void);
60
61extern void SetCancelConn(PGconn *conn);
62extern void ResetCancelConn(void);
63
64
65#endif /* COMMON_H */
66