77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.3 1996/07/19 07:00:56 scrappy Exp $
10+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.4 1996/07/23 03:35:12 scrappy Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -70,12 +70,12 @@ PQsetdb(char *pghost, char* pgport, char* pgoptions, char* pgtty, char* dbName)
7070 char * tmp ;
7171
7272 conn = (PGconn * )malloc (sizeof (PGconn ));
73-
73+
7474 if (!conn ) {
75- fprintf (stderr ,"FATAL: pqsetdb () -- unable to allocate memory for a PGconn" );
76- return (PGconn * )NULL ;
75+ fprintf (stderr ,"FATAL: PQsetdb () -- unable to allocate memory for a PGconn" );
76+ return (PGconn * )NULL ;
7777 }
78-
78+
7979 conn -> Pfout = NULL ;
8080 conn -> Pfin = NULL ;
8181 conn -> Pfdebug = NULL ;
@@ -90,45 +90,58 @@ PQsetdb(char *pghost, char* pgport, char* pgoptions, char* pgtty, char* dbName)
9090 } else
9191 conn -> pghost = strdup (pghost );
9292
93- if (!pgport || pgport == '\0' ) {
93+ if (!pgport || pgport [ 0 ] == '\0' ) {
9494 if (!(tmp = getenv ("PGPORT" ))) {
9595 tmp = POSTPORT ;
9696 }
9797 conn -> pgport = strdup (tmp );
9898 } else
9999 conn -> pgport = strdup (pgport );
100100
101- if (!pgtty || pgtty == '\0' ) {
101+ if (!pgtty || pgtty [ 0 ] == '\0' ) {
102102 if (!(tmp = getenv ("PGTTY" ))) {
103103 tmp = DefaultTty ;
104104 }
105105 conn -> pgtty = strdup (tmp );
106106 } else
107107 conn -> pgtty = strdup (pgtty );
108108
109- if (!pgoptions || pgoptions == '\0' ) {
109+ if (!pgoptions || pgoptions [ 0 ] == '\0' ) {
110110 if (!(tmp = getenv ("PGOPTIONS" ))) {
111111 tmp = DefaultOption ;
112112 }
113113 conn -> pgoptions = strdup (tmp );
114114 } else
115115 conn -> pgoptions = strdup (pgoptions );
116-
117- if (((tmp = dbName ) && (dbName [0 ] != '\0' )) ||
118- ((tmp = getenv ("PGDATABASE" ))))
116+ #if 0
117+ if (!dbName || dbName [0 ] == '\0' ) {
118+ char errorMessage [ERROR_MSG_LENGTH ];
119+ if (!(tmp = getenv ("PGDATABASE" )) &&
120+ !(tmp = fe_getauthname (errorMessage ))) {
121+ sprintf (conn -> errorMessage ,
122+ "FATAL: PQsetdb: Unable to determine a database name!\n" );
123+ /* pqdebug("%s", conn->errorMessage); */
124+ conn -> dbName = NULL ;
125+ return conn ;
126+ }
119127 conn -> dbName = strdup (tmp );
120- else {
128+ } else
129+ conn -> dbName = strdup (dbName );
130+ #endif
131+ if (((tmp = dbName ) && (dbName [0 ] != '\0' )) ||
132+ ((tmp = getenv ("PGDATABASE" )))) {
133+ conn -> dbName = strdup (tmp );
134+ } else {
121135 char errorMessage [ERROR_MSG_LENGTH ];
122136 if (tmp = fe_getauthname (errorMessage )) {
123- conn -> dbName = strdup (tmp );
124- free (tmp );
125- }
126- else {
127- sprintf (conn -> errorMessage ,
128- "FATAL: PQsetdb: Unable to determine a database name!\n" );
129- /* pqdebug("%s", conn->errorMessage); */
130- conn -> dbName = NULL ;
131- return conn ;
137+ conn -> dbName = strdup (tmp );
138+ free (tmp );
139+ } else {
140+ sprintf (conn -> errorMessage ,
141+ "FATAL: PQsetdb: Unable to determine a database name!\n" );
142+ /* pqdebug("%s", conn->errorMessage); */
143+ conn -> dbName = NULL ;
144+ return conn ;
132145 }
133146 }
134147 conn -> status = connectDB (conn );
@@ -320,7 +333,7 @@ PQfinish(PGconn *conn)
320333 fprintf (stderr ,"PQfinish() -- pointer to PGconn is null" );
321334 } else {
322335 if (conn -> status == CONNECTION_OK )
323- closePGconn (conn );
336+ closePGconn (conn );
324337 freePGconn (conn );
325338 }
326339}
@@ -404,10 +417,8 @@ startup2PacketBuf(StartupInfo* s, PacketBuf* res)
404417 strncpy (tmp , s -> execFile , sizeof (s -> execFile ));
405418 tmp += sizeof (s -> execFile );
406419 strncpy (tmp , s -> tty , sizeof (s -> execFile ));
407-
408420}
409421
410-
411422/* =========== accessor functions for PGconn ========= */
412423char *
413424PQdb (PGconn * conn )
@@ -416,7 +427,6 @@ PQdb(PGconn* conn)
416427 fprintf (stderr ,"PQdb() -- pointer to PGconn is null" );
417428 return (char * )NULL ;
418429 }
419-
420430 return conn -> dbName ;
421431}
422432
@@ -438,7 +448,6 @@ PQoptions(PGconn* conn)
438448 fprintf (stderr ,"PQoptions() -- pointer to PGconn is null" );
439449 return (char * )NULL ;
440450 }
441-
442451 return conn -> pgoptions ;
443452}
444453
@@ -449,7 +458,6 @@ PQtty(PGconn* conn)
449458 fprintf (stderr ,"PQtty() -- pointer to PGconn is null" );
450459 return (char * )NULL ;
451460 }
452-
453461 return conn -> pgtty ;
454462}
455463
@@ -460,7 +468,6 @@ PQport(PGconn* conn)
460468 fprintf (stderr ,"PQport() -- pointer to PGconn is null" );
461469 return (char * )NULL ;
462470 }
463-
464471 return conn -> pgport ;
465472}
466473
@@ -471,7 +478,6 @@ PQstatus(PGconn* conn)
471478 fprintf (stderr ,"PQstatus() -- pointer to PGconn is null" );
472479 return CONNECTION_BAD ;
473480 }
474-
475481 return conn -> status ;
476482}
477483
@@ -482,7 +488,6 @@ PQerrorMessage(PGconn* conn)
482488 fprintf (stderr ,"PQerrorMessage() -- pointer to PGconn is null" );
483489 return (char * )NULL ;
484490 }
485-
486491 return conn -> errorMessage ;
487492}
488493
0 commit comments