|
7 | 7 | *
|
8 | 8 | *
|
9 | 9 | * IDENTIFICATION
|
10 |
| - * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.2 1996/07/12 04:53:57 scrappy Exp $ |
| 10 | + * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.3 1996/07/19 07:00:56 scrappy Exp $ |
11 | 11 | *
|
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
@@ -114,20 +114,23 @@ PQsetdb(char *pghost, char* pgport, char* pgoptions, char* pgtty, char* dbName)
|
114 | 114 | }else
|
115 | 115 | conn->pgoptions=strdup(pgoptions);
|
116 | 116 |
|
117 |
| -if (!dbName||dbName[0]=='\0') { |
118 |
| -charerrorMessage[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 |
| -returnconn; |
126 |
| -} |
| 117 | +if (((tmp=dbName)&& (dbName[0]!='\0'))|| |
| 118 | +((tmp=getenv("PGDATABASE")))) |
127 | 119 | conn->dbName=strdup(tmp);
|
128 |
| - }else |
129 |
| -conn->dbName=strdup(dbName); |
130 |
| - |
| 120 | +else { |
| 121 | +charerrorMessage[ERROR_MSG_LENGTH]; |
| 122 | +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 | +returnconn; |
| 132 | + } |
| 133 | + } |
131 | 134 | conn->status=connectDB(conn);
|
132 | 135 | returnconn;
|
133 | 136 | }
|
@@ -164,8 +167,9 @@ connectDB(PGconn *conn)
|
164 | 167 | user=fe_getauthname(conn->errorMessage);
|
165 | 168 | if (!user)
|
166 | 169 | gotoconnect_errReturn;
|
167 |
| -strncpy(startup.database,conn->dbName,sizeof(startup.database)); |
168 | 170 | strncpy(startup.user,user,sizeof(startup.user));
|
| 171 | +free(user); |
| 172 | +strncpy(startup.database,conn->dbName,sizeof(startup.database)); |
169 | 173 | strncpy(startup.tty,conn->pgtty,sizeof(startup.tty));
|
170 | 174 | if (conn->pgoptions) {
|
171 | 175 | strncpy(startup.options,conn->pgoptions,sizeof(startup.options));
|
|