Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfc211f8

Browse files
author
Michael Meskes
committed
Applied Peter's patch to PQconnectdbParams in ecpglib instead of the old
PQconectdb.
1 parent39909d1 commitfc211f8

File tree

1 file changed

+43
-32
lines changed

1 file changed

+43
-32
lines changed

‎src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,6 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
260260
ecpg_log("raising sqlcode %d\n",sqlcode);
261261
}
262262

263-
staticint
264-
strlen_or_null(constchar*string)
265-
{
266-
if (!string)
267-
return0;
268-
return (strlen(string));
269-
}
270-
271263
/* this contains some quick hacks, needs to be cleaned up, but it works */
272264
bool
273265
ECPGconnect(intlineno,intc,constchar*name,constchar*user,constchar*passwd,constchar*connection_name,intautocommit)
@@ -281,8 +273,9 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
281273
*tmp,
282274
*port=NULL,
283275
*realname=NULL,
284-
*options=NULL,
285-
*connect_string=NULL;
276+
*options=NULL;
277+
constchar*conn_keywords[6];
278+
constchar*conn_values[6];
286279

287280
ecpg_init_sqlca(sqlca);
288281

@@ -482,34 +475,52 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
482475
options ?"with options " :"",options ?options :"",
483476
(user&&strlen(user)>0) ?"for user " :"",user ?user :"");
484477

485-
connect_string=ecpg_alloc(strlen_or_null(host)
486-
+strlen_or_null(port)
487-
+strlen_or_null(options)
488-
+strlen_or_null(realname)
489-
+strlen_or_null(user)
490-
+strlen_or_null(passwd)
491-
+sizeof(" host = port = dbname = user = password ="),lineno);
492-
493-
if (options)/* replace '&' if tehre are any */
478+
if (options)/* replace '&' if there are any */
494479
for (i=0;options[i];i++)
495480
if (options[i]=='&')
496481
options[i]=' ';
497482

498-
sprintf(connect_string,"%s%s %s%s %s%s %s%s %s%s %s",
499-
realname ?"dbname=" :"",realname ?realname :"",
500-
host ?"host=" :"",host ?host :"",
501-
port ?"port=" :"",port ?port :"",
502-
(user&&strlen(user)>0) ?"user=" :"",user ?user :"",
503-
(passwd&&strlen(passwd)>0) ?"password=" :"",passwd ?passwd :"",
504-
options ?options :"");
483+
i=0;
484+
if (realname)
485+
{
486+
conn_keywords[i]="dbname";
487+
conn_values[i]=realname;
488+
i++;
489+
}
490+
if (host)
491+
{
492+
conn_keywords[i]="host";
493+
conn_values[i]=host;
494+
i++;
495+
}
496+
if (port)
497+
{
498+
conn_keywords[i]="port";
499+
conn_values[i]=port;
500+
i++;
501+
}
502+
if (user&&strlen(user)>0)
503+
{
504+
conn_keywords[i]="user";
505+
conn_values[i]=user;
506+
i++;
507+
}
508+
if (passwd&&strlen(passwd)>0)
509+
{
510+
conn_keywords[i]="password";
511+
conn_values[i]=passwd;
512+
i++;
513+
}
514+
if (options)
515+
{
516+
conn_keywords[i]="options";
517+
conn_values[i]=options;
518+
i++;
519+
}
520+
conn_keywords[i]=NULL;/* terminator */
505521

506-
/*
507-
* this is deprecated this->connection = PQsetdbLogin(host, port, options,
508-
* NULL, realname, user, passwd);
509-
*/
510-
this->connection=PQconnectdb(connect_string);
522+
this->connection=PQconnectdbParams(conn_keywords,conn_values,0);
511523

512-
ecpg_free(connect_string);
513524
if (host)
514525
ecpg_free(host);
515526
if (port)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp