45{
47 bool new_pass;
48 const char *remoteversion_str;
49 int my_version;
51 const char **
values = NULL;
53 int server_version_temp;
54
57
58 /*
59 * Start the connection. Loop until we have a password if requested by
60 * backend.
61 */
62 do
63 {
64 int argcount = 8;
66 char *err_msg = NULL;
68
72
73 /*
74 * Merge the connection info inputs given in form of connection string
75 * and other options. Explicitly discard any dbname value in the
76 * connection string; otherwise, PQconnectdbParams() would interpret
77 * that value as being itself a connection string.
78 */
80 {
82 if (conn_opts == NULL)
84
85 for (conn_opt = conn_opts; conn_opt->
keyword != NULL; conn_opt++)
86 {
87 if (conn_opt->
val != NULL && conn_opt->
val[0] !=
'0円' &&
88 strcmp(conn_opt->
keyword,
"dbname") != 0)
89 argcount++;
90 }
91
94
95 for (conn_opt = conn_opts; conn_opt->
keyword != NULL; conn_opt++)
96 {
97 if (conn_opt->
val != NULL && conn_opt->
val[0] !=
'0円' &&
98 strcmp(conn_opt->
keyword,
"dbname") != 0)
99 {
103 }
104 }
105 }
106 else
107 {
110 }
111
113 {
117 }
119 {
123 }
124 if (pguser)
125 {
129 }
131 {
135 }
137 {
141 }
142 if (override_dbname)
143 {
147 }
148
149 keywords[
i] =
"fallback_application_name";
152
153 new_pass = false;
155
158
162 prompt_password !=
TRI_NO)
163 {
166 new_pass = true;
167 }
168 } while (new_pass);
169
170 /* check to see that the backend connection was successfully made */
172 {
173 if (fail_on_error)
175 else
176 {
178
182
183 return NULL;
184 }
185 }
186
187 /*
188 * Ok, connected successfully. If requested, remember the options used, in
189 * the form of a connection string.
190 */
193
197
198 /* Check version */
200 if (!remoteversion_str)
201 pg_fatal(
"could not get server version");
202
204 if (server_version_temp == 0)
205 pg_fatal(
"could not parse server version \"%s\"",
206 remoteversion_str);
207
208 /* If requested, then copy server version to out variable. */
211
212 my_version = PG_VERSION_NUM;
213
214 /*
215 * We allow the server to be back to 9.2, and up to any minor release of
216 * our own major version. (See also version check in pg_dump.c.)
217 */
218 if (my_version != server_version_temp
219 && (server_version_temp < 90200 ||
220 (server_version_temp / 100) > (my_version / 100)))
221 {
222 pg_log_error(
"aborting because of server version mismatch");
224 remoteversion_str,
progname, PG_VERSION);
226 }
227
229
231}
static Datum values[MAXATTR]
#define ALWAYS_SECURE_SEARCH_PATH_SQL
static char * constructConnStr(const char **keywords, const char **values)
PGresult * executeQuery(PGconn *conn, const char *query)
int PQserverVersion(const PGconn *conn)
void PQconninfoFree(PQconninfoOption *connOptions)
PQconninfoOption * PQconninfoParse(const char *conninfo, char **errmsg)
const char * PQparameterStatus(const PGconn *conn, const char *paramName)
int PQconnectionNeedsPassword(const PGconn *conn)
ConnStatusType PQstatus(const PGconn *conn)
void PQfinish(PGconn *conn)
char * PQerrorMessage(const PGconn *conn)
PGconn * PQconnectdbParams(const char *const *keywords, const char *const *values, int expand_dbname)
void * pg_malloc0(size_t size)
static const JsonPathKeyword keywords[]
#define pg_log_error(...)
#define pg_log_error_detail(...)
void exit_nicely(int code)
static const char * connstr
static int server_version
static const char * pghost
static const char * pgport
char * simple_prompt(const char *prompt, bool echo)