Commit fc211f82 authored by Michael Meskes's avatar Michael Meskes

Applied Peter's patch to PQconnectdbParams in ecpglib instead of the old

PQconectdb.
parent 39909d1d
...@@ -260,14 +260,6 @@ ECPGnoticeReceiver(void *arg, const PGresult *result) ...@@ -260,14 +260,6 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
ecpg_log("raising sqlcode %d\n", sqlcode); ecpg_log("raising sqlcode %d\n", sqlcode);
} }
static int
strlen_or_null(const char *string)
{
if (!string)
return 0;
return (strlen(string));
}
/* this contains some quick hacks, needs to be cleaned up, but it works */ /* this contains some quick hacks, needs to be cleaned up, but it works */
bool bool
ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit) ECPGconnect(int lineno, int c, const char *name, const char *user, const char *passwd, const char *connection_name, int autocommit)
...@@ -281,8 +273,9 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p ...@@ -281,8 +273,9 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
*tmp, *tmp,
*port = NULL, *port = NULL,
*realname = NULL, *realname = NULL,
*options = NULL, *options = NULL;
*connect_string = NULL; const char *conn_keywords[6];
const char *conn_values[6];
ecpg_init_sqlca(sqlca); ecpg_init_sqlca(sqlca);
...@@ -482,34 +475,52 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p ...@@ -482,34 +475,52 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
options ? "with options " : "", options ? options : "", options ? "with options " : "", options ? options : "",
(user && strlen(user) > 0) ? "for user " : "", user ? user : ""); (user && strlen(user) > 0) ? "for user " : "", user ? user : "");
connect_string = ecpg_alloc(strlen_or_null(host) if (options) /* replace '&' if there are any */
+ strlen_or_null(port)
+ strlen_or_null(options)
+ strlen_or_null(realname)
+ strlen_or_null(user)
+ strlen_or_null(passwd)
+ sizeof(" host = port = dbname = user = password ="), lineno);
if (options) /* replace '&' if tehre are any */
for (i = 0; options[i]; i++) for (i = 0; options[i]; i++)
if (options[i] == '&') if (options[i] == '&')
options[i] = ' '; options[i] = ' ';
sprintf(connect_string, "%s%s %s%s %s%s %s%s %s%s %s", i = 0;
realname ? "dbname=" : "", realname ? realname : "", if (realname)
host ? "host=" : "", host ? host : "", {
port ? "port=" : "", port ? port : "", conn_keywords[i] = "dbname";
(user && strlen(user) > 0) ? "user=" : "", user ? user : "", conn_values[i] = realname;
(passwd && strlen(passwd) > 0) ? "password=" : "", passwd ? passwd : "", i++;
options ? options : ""); }
if (host)
{
conn_keywords[i] = "host";
conn_values[i] = host;
i++;
}
if (port)
{
conn_keywords[i] = "port";
conn_values[i] = port;
i++;
}
if (user && strlen(user) > 0)
{
conn_keywords[i] = "user";
conn_values[i] = user;
i++;
}
if (passwd && strlen(passwd) > 0)
{
conn_keywords[i] = "password";
conn_values[i] = passwd;
i++;
}
if (options)
{
conn_keywords[i] = "options";
conn_values[i] = options;
i++;
}
conn_keywords[i] = NULL; /* terminator */
/* this->connection = PQconnectdbParams(conn_keywords, conn_values, 0);
* this is deprecated this->connection = PQsetdbLogin(host, port, options,
* NULL, realname, user, passwd);
*/
this->connection = PQconnectdb(connect_string);
ecpg_free(connect_string);
if (host) if (host)
ecpg_free(host); ecpg_free(host);
if (port) if (port)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment