8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:03:02 +01:00

Add config. parameter DefaultTimeZone.

This commit is contained in:
Adriano dos Santos Fernandes 2018-12-28 15:38:50 -02:00
parent 86081d3264
commit 3ca18c540c
5 changed files with 37 additions and 3 deletions

View File

@ -706,6 +706,17 @@
#
#DummyPacketInterval = 0
#
# Default session or client time zone.
#
# If empty, the default is the OS time zone.
# When set in the server, it defines the default session time zone for attachments.
# When set in the client, it defines the default time zone used with client-side API functions.
#
# Type: string
#
#DefaultTimeZone =
# ----------------------------
# TCP Protocol Settings

View File

@ -4,7 +4,7 @@ Time zone support consists of `TIME WITH TIME ZONE` and `TIMESTAMP WITH TIME ZON
The first important thing to understand is that `TIME WITHOUT TIME ZONE`, `TIMESTAMP WITHOUT TIME ZONE` and `DATE` data types are defined to use the session time zone when converting from or to a `TIME WITH TIME ZONE` or `TIMESTAMP WITH TIME ZONE`. `TIME` and `TIMESTAMP` are synonymous to theirs respectively `WITHOUT TIME ZONE` data types.
The session time zone, as the name implies, can be a different one for each database attachment. It can be set with the isc_dpb_session_time_zone DPB, and if not, it starts by default defined to be the same time zone used by the Firebird database OS process.
The session time zone, as the name implies, can be a different one for each database attachment. It can be set with the isc_dpb_session_time_zone DPB, and if not, it starts by default defined to be the `firebird.conf` parameter `DefaultTimeZone` or the same time zone used by the Firebird OS process when the parameter is not defined. A change in `DefaultTimeZone` configuration or the OS time zone does not changes the default of a running Firebird process.
It can then be changed with `SET TIME ZONE` statement to a given time zone or reset to its original value with `SET TIME ZONE LOCAL`.

View File

@ -33,6 +33,7 @@
#include "../common/classes/rwlock.h"
#include "../common/classes/timestamp.h"
#include "../common/classes/GenericMap.h"
#include "../common/config/config.h"
#include "unicode/ucal.h"
#ifdef TZ_UPDATE
@ -195,6 +196,7 @@ USHORT TimeZoneUtil::getSystemTimeZone()
static volatile USHORT cachedTimeZoneId = TimeZoneUtil::GMT_ZONE;
static volatile int32_t cachedTimeZoneNameLen = -1;
static UChar cachedTimeZoneName[TimeZoneUtil::MAX_SIZE];
static GlobalPtr<RWLock> lock;
if (cachedError)
return cachedTimeZoneId;
@ -203,9 +205,21 @@ USHORT TimeZoneUtil::getSystemTimeZone()
Jrd::UnicodeUtil::ConversionICU& icuLib = Jrd::UnicodeUtil::getConversionICU();
UChar buffer[TimeZoneUtil::MAX_SIZE];
int32_t len = icuLib.ucalGetDefaultTimeZone(buffer, FB_NELEM(buffer), &icuErrorCode);
int32_t len;
const char* configDefault = Config::getDefaultTimeZone();
static GlobalPtr<RWLock> lock;
if (configDefault && configDefault[0])
{
UChar* dst = buffer;
for (const char* src = configDefault; src - configDefault < TimeZoneUtil::MAX_SIZE && *src; ++src, ++dst)
*dst = *src;
*dst = 0;
len = dst - buffer;
}
else
len = icuLib.ucalGetDefaultTimeZone(buffer, FB_NELEM(buffer), &icuErrorCode);
ReadLockGuard readGuard(lock, "TimeZoneUtil::getSystemTimeZone");

View File

@ -151,6 +151,7 @@ const Config::ConfigEntry Config::entries[MAX_CONFIG_KEY] =
{TYPE_INTEGER, "DefaultDbCachePages", (ConfigValue) -1}, // pages
{TYPE_INTEGER, "ConnectionTimeout", (ConfigValue) 180}, // seconds
{TYPE_INTEGER, "DummyPacketInterval", (ConfigValue) 0}, // seconds
{TYPE_STRING, "DefaultTimeZone", (ConfigValue) ""},
{TYPE_INTEGER, "LockMemSize", (ConfigValue) 1048576}, // bytes
{TYPE_INTEGER, "LockHashSlots", (ConfigValue) 8191}, // slots
{TYPE_INTEGER, "LockAcquireSpins", (ConfigValue) 0},
@ -517,6 +518,11 @@ int Config::getDummyPacketInterval() const
return get<int>(KEY_DUMMY_PACKET_INTERVAL);
}
const char* Config::getDefaultTimeZone()
{
return getDefaultConfig()->get<const char*>(KEY_DEFAULT_TIME_ZONE);
}
int Config::getLockMemSize() const
{
int size = get<int>(KEY_LOCK_MEM_SIZE);

View File

@ -98,6 +98,7 @@ public:
KEY_DEFAULT_DB_CACHE_PAGES,
KEY_CONNECTION_TIMEOUT,
KEY_DUMMY_PACKET_INTERVAL,
KEY_DEFAULT_TIME_ZONE,
KEY_LOCK_MEM_SIZE,
KEY_LOCK_HASH_SLOTS,
KEY_LOCK_ACQUIRE_SPINS,
@ -263,6 +264,8 @@ public:
// Dummy packet interval
int getDummyPacketInterval() const;
static const char* getDefaultTimeZone();
// Lock manager memory size
int getLockMemSize() const;