From 4ea34933f0c6d632f1e45f6783e8d29f525241e5 Mon Sep 17 00:00:00 2001 From: Adriano dos Santos Fernandes Date: Mon, 21 May 2018 12:48:37 -0300 Subject: [PATCH] Added isc_dpb_session_time_zone. --- doc/sql.extensions/README.time_zone.md | 2 +- src/include/consts_pub.h | 1 + src/jrd/extds/ExtDS.cpp | 4 ++++ src/jrd/jrd.cpp | 17 +++++++++++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/sql.extensions/README.time_zone.md b/doc/sql.extensions/README.time_zone.md index 174beb077a..599f5f4b49 100644 --- a/doc/sql.extensions/README.time_zone.md +++ b/doc/sql.extensions/README.time_zone.md @@ -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. By default it starts 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 same time zone used by the Firebird database OS 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`. diff --git a/src/include/consts_pub.h b/src/include/consts_pub.h index 1ddfc8bddd..13e05830f0 100644 --- a/src/include/consts_pub.h +++ b/src/include/consts_pub.h @@ -123,6 +123,7 @@ #define isc_dpb_nolinger 88 #define isc_dpb_reset_icu 89 #define isc_dpb_map_attach 90 +#define isc_dpb_session_time_zone 91 /**************************************************/ /* clumplet tags used inside isc_dpb_address_path */ diff --git a/src/jrd/extds/ExtDS.cpp b/src/jrd/extds/ExtDS.cpp index 01e7ce3ad0..263fadbcae 100644 --- a/src/jrd/extds/ExtDS.cpp +++ b/src/jrd/extds/ExtDS.cpp @@ -319,6 +319,10 @@ void Provider::generateDPB(thread_db* tdbb, ClumpletWriter& dpb, dpb.insertString(isc_dpb_lc_ctype, cs->getName()); } + char timeZoneBuffer[TimeZoneUtil::MAX_SIZE]; + TimeZoneUtil::format(timeZoneBuffer, sizeof(timeZoneBuffer), attachment->att_current_timezone); + dpb.insertString(isc_dpb_session_time_zone, timeZoneBuffer); + // remote network address??? } diff --git a/src/jrd/jrd.cpp b/src/jrd/jrd.cpp index 43a1b27675..9e8eecedec 100644 --- a/src/jrd/jrd.cpp +++ b/src/jrd/jrd.cpp @@ -997,6 +997,7 @@ public: PathName dpb_remote_process; PathName dpb_org_filename; string dpb_config; + string dpb_session_tz; public: static const ULONG DPB_FLAGS_MASK = DBB_damaged; @@ -1800,6 +1801,12 @@ JAttachment* JProvider::internalAttach(CheckStatusWrapper* user_status, const ch find_intl_charset(tdbb, attachment, &options); + if (!options.dpb_session_tz.isEmpty()) + { + attachment->att_current_timezone = TimeZoneUtil::parse( + options.dpb_session_tz.c_str(), options.dpb_session_tz.length()); + } + // if the attachment is through gbak and this attachment is not by owner // or sysdba then return error. This has been added here to allow for the // GBAK security feature of only allowing the owner or sysdba to backup a @@ -2833,6 +2840,12 @@ JAttachment* JProvider::createDatabase(CheckStatusWrapper* user_status, const ch find_intl_charset(tdbb, attachment, &options); + if (!options.dpb_session_tz.isEmpty()) + { + attachment->att_current_timezone = TimeZoneUtil::parse( + options.dpb_session_tz.c_str(), options.dpb_session_tz.length()); + } + CCH_flush(tdbb, FLUSH_FINI, 0); if (!options.dpb_set_force_write) @@ -6628,6 +6641,10 @@ void DatabaseOptions::get(const UCHAR* dpb, USHORT dpb_length, bool& invalid_cli getString(rdr, dpb_config); break; + case isc_dpb_session_time_zone: + rdr.getString(dpb_session_tz); + break; + default: break; }