Skip to content

Commit 367089b

Browse files
author
Thomas G. Lockhart
committed
Add PGTZ environment variable to initialization code.
Rename PG_DATESTYLE to PGDATESTYLE environment variable. Move environment variable code to a different place so it now works! Note that regression tests can now run with "setenv PGTZ PST8PDT" at the frontend rather than requiring the backend to have TZ set.
1 parent 4ebc4e3 commit 367089b

File tree

1 file changed

+41
-29
lines changed

1 file changed

+41
-29
lines changed

src/interfaces/libpq/fe-connect.c

Lines changed: 41 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.44 1997/11/10 05:10:45 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.45 1997/11/10 15:41:58 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -47,6 +47,7 @@ static void closePGconn(PGconn *conn);
4747
static int conninfo_parse(const char *conninfo, char *errorMessage);
4848
static char *conninfo_getval(char *keyword);
4949
static void conninfo_free(void);
50+
void PQsetenv(PGconn *conn);
5051

5152
#define NOTIFYLIST_INITIAL_SIZE 10
5253
#define NOTIFYLIST_GROWBY 10
@@ -109,18 +110,15 @@ struct EnvironmentOptions
109110
} EnvironmentOptions[] =
110111

111112
{
112-
{
113-
"PG_DATESTYLE", "datestyle"
114-
},
115-
{
116-
NULL
117-
}
113+
{ "PGDATESTYLE", "datestyle" },
114+
{ "PGTZ", "timezone" },
115+
{ NULL }
118116
};
119117

120118
/* ----------------
121119
* PQconnectdb
122120
*
123-
* establishes a connectin to a postgres backend through the postmaster
121+
* establishes a connection to a postgres backend through the postmaster
124122
* using connection information in a string.
125123
*
126124
* The conninfo string is a list of
@@ -136,7 +134,7 @@ struct EnvironmentOptions
136134
* then some fields may be null'ed out instead of having valid values
137135
* ----------------
138136
*/
139-
PGconn *
137+
PGconn *
140138
PQconnectdb(const char *conninfo)
141139
{
142140
PGconn *conn;
@@ -255,6 +253,8 @@ PQconnectdb(const char *conninfo)
255253
PQclear(res);
256254
}
257255

256+
PQsetenv(conn);
257+
258258
return conn;
259259
}
260260

@@ -309,6 +309,11 @@ PQconndefaults(void)
309309
*
310310
* None of the above need be defined. There are defaults for all of them.
311311
*
312+
* To support "delimited identifiers" for database names, only convert
313+
* the database name to lower case if it is not surrounded by double quotes.
314+
* Otherwise, strip the double quotes but leave the reset of the string intact.
315+
* - thomas 1997-11-08
316+
*
312317
* ----------------
313318
*/
314319
PGconn *
@@ -419,8 +424,8 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
419424
conn->dbName = strdup(conn->pguser);
420425

421426
/*
422-
* if the table name is surrounded by double-quotes, then
423-
* don't convert case
427+
* if the database name is surrounded by double-quotes,
428+
* then don't convert case
424429
*/
425430
if (*conn->dbName == '"')
426431
{
@@ -457,6 +462,7 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
457462
}
458463
PQclear(res);
459464
}
465+
PQsetenv(conn);
460466
}
461467
}
462468
return conn;
@@ -625,24 +631,6 @@ connectDB(PGconn *conn)
625631

626632
conn->port = port;
627633

628-
{
629-
struct EnvironmentOptions *eo;
630-
char setQuery[80]; /* mjl: size okay? XXX */
631-
632-
for (eo = EnvironmentOptions; eo->envName; eo++)
633-
{
634-
const char *val;
635-
636-
if ((val = getenv(eo->envName)))
637-
{
638-
PGresult *res;
639-
640-
sprintf(setQuery, "SET %s TO '%.60s'", eo->pgName, val);
641-
res = PQexec(conn, setQuery);
642-
PQclear(res); /* Don't care? */
643-
}
644-
}
645-
}
646634
return CONNECTION_OK;
647635

648636
connect_errReturn:
@@ -658,6 +646,30 @@ connectDB(PGconn *conn)
658646

659647
}
660648

649+
void
650+
PQsetenv(PGconn *conn)
651+
{
652+
struct EnvironmentOptions *eo;
653+
char setQuery[80]; /* mjl: size okay? XXX */
654+
655+
for (eo = EnvironmentOptions; eo->envName; eo++)
656+
{
657+
const char *val;
658+
659+
if ((val = getenv(eo->envName)))
660+
{
661+
PGresult *res;
662+
663+
sprintf(setQuery, "SET %s TO '%.60s'", eo->pgName, val);
664+
#ifdef CONNECTDEBUG
665+
printf("Use environment variable %s to send %s\n", eo->envName, setQuery);
666+
#endif
667+
res = PQexec(conn, setQuery);
668+
PQclear(res); /* Don't care? */
669+
}
670+
}
671+
} /* PQsetenv() */
672+
661673
/*
662674
* freePGconn
663675
* - free the PGconn data structure

0 commit comments

Comments
 (0)