@@ -260,14 +260,6 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
260260 ecpg_log ("raising sqlcode %d\n" , sqlcode );
261261}
262262
263- static int
264- strlen_or_null (const char * string )
265- {
266- if (!string )
267- return 0 ;
268- return (strlen (string ));
269- }
270-
271263/* this contains some quick hacks, needs to be cleaned up, but it works */
272264bool
273265ECPGconnect (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
281273 * tmp ,
282274 * port = NULL ,
283275 * realname = NULL ,
284- * options = NULL ,
285- * connect_string = NULL ;
276+ * options = NULL ;
277+ const char * conn_keywords [6 ];
278+ const char * 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