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)
7070char * tmp ;
7171
7272conn = (PGconn * )malloc (sizeof (PGconn ));
73-
73+
7474if (!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+
7979conn -> Pfout = NULL ;
8080conn -> Pfin = NULL ;
8181conn -> Pfdebug = NULL ;
@@ -90,45 +90,58 @@ PQsetdb(char *pghost, char* pgport, char* pgoptions, char* pgtty, char* dbName)
9090 }else
9191conn -> pghost = strdup (pghost );
9292
93- if (!pgport || pgport == '\0' ) {
93+ if (!pgport || pgport [ 0 ] == '\0' ) {
9494if (!(tmp = getenv ("PGPORT" ))) {
9595tmp = POSTPORT ;
9696}
9797conn -> pgport = strdup (tmp );
9898 }else
9999conn -> pgport = strdup (pgport );
100100
101- if (!pgtty || pgtty == '\0' ) {
101+ if (!pgtty || pgtty [ 0 ] == '\0' ) {
102102if (!(tmp = getenv ("PGTTY" ))) {
103103tmp = DefaultTty ;
104104}
105105conn -> pgtty = strdup (tmp );
106106 }else
107107conn -> pgtty = strdup (pgtty );
108108
109- if (!pgoptions || pgoptions == '\0' ) {
109+ if (!pgoptions || pgoptions [ 0 ] == '\0' ) {
110110if (!(tmp = getenv ("PGOPTIONS" ))) {
111111tmp = DefaultOption ;
112112}
113113conn -> pgoptions = strdup (tmp );
114114 }else
115115conn -> 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+ }
119127conn -> 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 {
121135char errorMessage [ERROR_MSG_LENGTH ];
122136if (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 }
134147conn -> status = connectDB (conn );
@@ -320,7 +333,7 @@ PQfinish(PGconn *conn)
320333fprintf (stderr ,"PQfinish() -- pointer to PGconn is null" );
321334 }else {
322335if (conn -> status == CONNECTION_OK )
323- closePGconn (conn );
336+ closePGconn (conn );
324337freePGconn (conn );
325338 }
326339}
@@ -404,10 +417,8 @@ startup2PacketBuf(StartupInfo* s, PacketBuf* res)
404417strncpy (tmp ,s -> execFile ,sizeof (s -> execFile ));
405418tmp += sizeof (s -> execFile );
406419strncpy (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)
416427fprintf (stderr ,"PQdb() -- pointer to PGconn is null" );
417428return (char * )NULL ;
418429 }
419-
420430return conn -> dbName ;
421431}
422432
@@ -438,7 +448,6 @@ PQoptions(PGconn* conn)
438448fprintf (stderr ,"PQoptions() -- pointer to PGconn is null" );
439449return (char * )NULL ;
440450 }
441-
442451return conn -> pgoptions ;
443452}
444453
@@ -449,7 +458,6 @@ PQtty(PGconn* conn)
449458fprintf (stderr ,"PQtty() -- pointer to PGconn is null" );
450459return (char * )NULL ;
451460 }
452-
453461return conn -> pgtty ;
454462}
455463
@@ -460,7 +468,6 @@ PQport(PGconn* conn)
460468fprintf (stderr ,"PQport() -- pointer to PGconn is null" );
461469return (char * )NULL ;
462470 }
463-
464471return conn -> pgport ;
465472}
466473
@@ -471,7 +478,6 @@ PQstatus(PGconn* conn)
471478fprintf (stderr ,"PQstatus() -- pointer to PGconn is null" );
472479return CONNECTION_BAD ;
473480 }
474-
475481return conn -> status ;
476482}
477483
@@ -482,7 +488,6 @@ PQerrorMessage(PGconn* conn)
482488fprintf (stderr ,"PQerrorMessage() -- pointer to PGconn is null" );
483489return (char * )NULL ;
484490 }
485-
486491return conn -> errorMessage ;
487492}
488493