|
9 | 9 | *
|
10 | 10 | *
|
11 | 11 | * IDENTIFICATION
|
12 |
| - * $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.105 2004/12/31 21:59:42 pgsql Exp $ |
| 12 | + * $PostgreSQL: pgsql/src/backend/commands/variable.c,v 1.106 2005/04/19 03:13:58 momjian Exp $ |
13 | 13 | *
|
14 | 14 | *-------------------------------------------------------------------------
|
15 | 15 | */
|
@@ -315,104 +315,50 @@ assign_timezone(const char *value, bool doit, GucSource source)
|
315 | 315 | * UNKNOWN as the canonical spelling.
|
316 | 316 | *
|
317 | 317 | * During GUC initialization, since the timezone library isn't
|
318 |
| - * set up yet, pg_get_current_timezone will return NULL and we |
| 318 | + * set up yet, pg_get_timezone_name will return NULL and we |
319 | 319 | * will leave the setting as UNKNOWN. If this isn't
|
320 | 320 | * overridden from the config file then
|
321 | 321 | * pg_timezone_initialize() will eventually select a default
|
322 | 322 | * value from the environment.
|
323 | 323 | */
|
324 |
| - const char *curzone = pg_get_current_timezone(); |
| 324 | + const char *curzone = pg_get_timezone_name(global_timezone); |
325 | 325 |
|
326 | 326 | if (curzone)
|
327 | 327 | value = curzone;
|
328 | 328 | }
|
329 | 329 | else
|
330 | 330 | {
|
331 | 331 | /*
|
332 |
| - * Otherwise assume it is a timezone name. |
333 |
| - * |
334 |
| - * We have to actually apply the change before we can have any |
335 |
| - * hope of checking it. So, save the old value in case we |
336 |
| - * have to back out. We have to copy since |
337 |
| - * pg_get_current_timezone returns a pointer to its static |
338 |
| - * state. |
339 |
| - * |
340 |
| - * This would all get a lot simpler if the TZ library had a |
341 |
| - * better API that would let us look up and test a timezone |
342 |
| - * name without making it the default. |
| 332 | + * Otherwise assume it is a timezone name, and try to load it. |
343 | 333 | */
|
344 |
| - const char *cur_tz; |
345 |
| - char *save_tz; |
346 |
| - bool known, |
347 |
| - acceptable; |
| 334 | + pg_tz *new_tz; |
348 | 335 |
|
349 |
| - cur_tz = pg_get_current_timezone(); |
350 |
| - if (cur_tz) |
351 |
| - save_tz = pstrdup(cur_tz); |
352 |
| - else |
353 |
| - save_tz = NULL; |
| 336 | + new_tz = pg_tzset(value); |
354 | 337 |
|
355 |
| - known = pg_tzset(value); |
356 |
| - acceptable = known ? tz_acceptable() : false; |
| 338 | + if (!new_tz) |
| 339 | + { |
| 340 | + ereport((source >= PGC_S_INTERACTIVE) ? ERROR : LOG, |
| 341 | + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 342 | + errmsg("unrecognized time zone name: \"%s\"", |
| 343 | + value))); |
| 344 | + return NULL; |
| 345 | + } |
357 | 346 |
|
358 |
| - if (doit && known && acceptable) |
| 347 | + if (!tz_acceptable(new_tz)) |
359 | 348 | {
|
360 |
| - /* Keep the changed TZ */ |
361 |
| - HasCTZSet = false; |
| 349 | + ereport((source >= PGC_S_INTERACTIVE) ? ERROR : LOG, |
| 350 | + (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 351 | + errmsg("time zone \"%s\" appears to use leap seconds", |
| 352 | + value), |
| 353 | + errdetail("PostgreSQL does not support leap seconds."))); |
| 354 | + return NULL; |
362 | 355 | }
|
363 |
| - else |
| 356 | + |
| 357 | + if (doit) |
364 | 358 | {
|
365 |
| - /* |
366 |
| - * Revert to prior TZ setting; note we haven't changed |
367 |
| - * HasCTZSet in this path, so if we were previously using |
368 |
| - * a fixed offset, we still are. |
369 |
| - */ |
370 |
| - if (save_tz) |
371 |
| - pg_tzset(save_tz); |
372 |
| - else |
373 |
| - { |
374 |
| - /* |
375 |
| - * TZ library wasn't initialized yet. Annoyingly, we |
376 |
| - * will come here during startup because guc-file.l |
377 |
| - * checks the value with doit = false before actually |
378 |
| - * applying. The best approach seems to be as follows: |
379 |
| - * |
380 |
| - * 1. known && acceptable: leave the setting in place, |
381 |
| - * since we'll apply it soon anyway. This is mainly |
382 |
| - * so that any log messages printed during this |
383 |
| - * interval are timestamped with the user's requested |
384 |
| - * timezone. |
385 |
| - * |
386 |
| - * 2. known && !acceptable: revert to GMT for lack of any |
387 |
| - * better idea. (select_default_timezone() may get |
388 |
| - * called later to undo this.) |
389 |
| - * |
390 |
| - * 3. !known: no need to do anything since TZ library did |
391 |
| - * not change its state. |
392 |
| - * |
393 |
| - * Again, this should all go away sometime soon. |
394 |
| - */ |
395 |
| - if (known && !acceptable) |
396 |
| - pg_tzset("GMT"); |
397 |
| - } |
398 |
| - /* Complain if it was bad */ |
399 |
| - if (!known) |
400 |
| - { |
401 |
| - ereport((source >= PGC_S_INTERACTIVE) ? ERROR : LOG, |
402 |
| - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
403 |
| - errmsg("unrecognized time zone name: \"%s\"", |
404 |
| - value))); |
405 |
| - return NULL; |
406 |
| - } |
407 |
| - if (!acceptable) |
408 |
| - { |
409 |
| - ereport((source >= PGC_S_INTERACTIVE) ? ERROR : LOG, |
410 |
| - (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
411 |
| - errmsg("time zone \"%s\" appears to use leap seconds", |
412 |
| - value), |
413 |
| - errdetail("PostgreSQL does not support leap seconds."))); |
414 |
| - return NULL; |
415 |
| - } |
| 359 | + /* Save the changed TZ */ |
| 360 | + global_timezone = new_tz; |
| 361 | + HasCTZSet = false; |
416 | 362 | }
|
417 | 363 | }
|
418 | 364 | }
|
@@ -459,7 +405,7 @@ show_timezone(void)
|
459 | 405 | IntervalPGetDatum(&interval)));
|
460 | 406 | }
|
461 | 407 | else
|
462 |
| - tzn = pg_get_current_timezone(); |
| 408 | + tzn = pg_get_timezone_name(global_timezone); |
463 | 409 |
|
464 | 410 | if (tzn != NULL)
|
465 | 411 | return tzn;
|
|
0 commit comments