@@ -260,14 +260,6 @@ ECPGnoticeReceiver(void *arg, const PGresult *result)
260
260
ecpg_log ("raising sqlcode %d\n" , sqlcode );
261
261
}
262
262
263
- static int
264
- strlen_or_null (const char * string )
265
- {
266
- if (!string )
267
- return 0 ;
268
- return (strlen (string ));
269
- }
270
-
271
263
/* this contains some quick hacks, needs to be cleaned up, but it works */
272
264
bool
273
265
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
273
* tmp ,
282
274
* port = NULL ,
283
275
* realname = NULL ,
284
- * options = NULL ,
285
- * connect_string = NULL ;
276
+ * options = NULL ;
277
+ const char * conn_keywords [6 ];
278
+ const char * conn_values [6 ];
286
279
287
280
ecpg_init_sqlca (sqlca );
288
281
@@ -482,34 +475,52 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
482
475
options ? "with options " : "" , options ? options : "" ,
483
476
(user && strlen (user ) > 0 ) ? "for user " : "" , user ? user : "" );
484
477
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 */
494
479
for (i = 0 ; options [i ]; i ++ )
495
480
if (options [i ] == '&' )
496
481
options [i ] = ' ' ;
497
482
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 */
505
521
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 );
511
523
512
- ecpg_free (connect_string );
513
524
if (host )
514
525
ecpg_free (host );
515
526
if (port )
0 commit comments