1 /*
2  *	common.h
3  *		Common support routines for bin/scripts/
4  *
5  *	Copyright (c) 2003-2016, 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 
17 enum trivalue
18 {
19 	TRI_DEFAULT,
20 	TRI_NO,
21 	TRI_YES
22 };
23 
24 extern bool CancelRequested;
25 
26 /* Parameters needed by connectDatabase/connectMaintenanceDatabase */
27 typedef struct _connParams
28 {
29 	/* These fields record the actual command line parameters */
30 	const char *dbname;			/* this may be a connstring! */
31 	const char *pghost;
32 	const char *pgport;
33 	const char *pguser;
34 	enum trivalue prompt_password;
35 	/* If not NULL, this overrides the dbname obtained from command line */
36 	/* (but *only* the DB name, not anything else in the connstring) */
37 	const char *override_dbname;
38 } ConnParams;
39 
40 typedef void (*help_handler) (const char *progname);
41 
42 extern void handle_help_version_opts(int argc, char *argv[],
43 						 const char *fixed_progname,
44 						 help_handler hlp);
45 
46 extern PGconn *connectDatabase(const ConnParams *cparams,
47 							   const char *progname,
48 							   bool echo, bool fail_ok,
49 							   bool allow_password_reuse);
50 
51 extern PGconn *connectMaintenanceDatabase(ConnParams *cparams,
52 						   const char *progname, bool echo);
53 
54 extern PGresult *executeQuery(PGconn *conn, const char *query,
55 			 const char *progname, bool echo);
56 
57 extern void executeCommand(PGconn *conn, const char *query,
58 			   const char *progname, bool echo);
59 
60 extern bool executeMaintenanceCommand(PGconn *conn, const char *query,
61 						  bool echo);
62 
63 extern void appendQualifiedRelation(PQExpBuffer buf, const char *name,
64 						PGconn *conn, const char *progname, bool echo);
65 
66 extern bool yesno_prompt(const char *question);
67 
68 extern void setup_cancel_handler(void);
69 
70 extern void SetCancelConn(PGconn *conn);
71 extern void ResetCancelConn(void);
72 
73 
74 #endif   /* COMMON_H */
75