From 5018dd610974ec3a732b0573961138a14f086b04 Mon Sep 17 00:00:00 2001 From: Adriano dos Santos Fernandes Date: Mon, 3 May 2021 11:19:14 -0300 Subject: [PATCH] Improvement #6786 - Add session time zone to system context. --- doc/sql.extensions/README.context_variables2 | 2 ++ doc/sql.extensions/README.time_zone.md | 15 +++++++++++++++ src/jrd/SysFunction.cpp | 7 +++++++ 3 files changed, 24 insertions(+) diff --git a/doc/sql.extensions/README.context_variables2 b/doc/sql.extensions/README.context_variables2 index 1421baa370..5ef0fff719 100644 --- a/doc/sql.extensions/README.context_variables2 +++ b/doc/sql.extensions/README.context_variables2 @@ -131,6 +131,8 @@ Usage: EXT_CONN_POOL_ACTIVE_COUNT | Count of active connections, associated with pool | EXT_CONN_POOL_LIFETIME | Idle connection lifetime, in seconds + | + SESSION_TIMEZONE | Current session time zone. Notes: To prevent DoS attacks against Firebird Server you are not allowed to have diff --git a/doc/sql.extensions/README.time_zone.md b/doc/sql.extensions/README.time_zone.md index ed6f7927ff..5480cb1536 100644 --- a/doc/sql.extensions/README.time_zone.md +++ b/doc/sql.extensions/README.time_zone.md @@ -329,6 +329,21 @@ select localtimestamp from rdb$database; ``` +### `SESSION_TIMEZONE` context variable + +`RDB$GET_CONTEXT('SYSTEM', 'SESSION_TIMEZONE')` could be used to obtain the session current time zone. + +#### Examples + +``` +set time zone 'america/sao_paulo'; +select rdb$get_context('SYSTEM', 'SESSION_TIMEZONE') from rdb$database; +-- Result: America/Sao_Paulo + +set time zone '-3:00'; +-- Result: -03:00 +``` + # Changes in `CURRENT_TIME` and `CURRENT_TIMESTAMP` In version 4.0, `CURRENT_TIME` and `CURRENT_TIMESTAMP` are changed to return `TIME WITH TIME ZONE` and `TIMESTAMP WITH TIME ZONE` (with time zone set to the session time zone), different than previous versions, that returned the types without time zone. diff --git a/src/jrd/SysFunction.cpp b/src/jrd/SysFunction.cpp index a2f93bc48f..1edfc45383 100644 --- a/src/jrd/SysFunction.cpp +++ b/src/jrd/SysFunction.cpp @@ -384,6 +384,7 @@ const char SESSION_IDLE_TIMEOUT[] = "SESSION_IDLE_TIMEOUT", STATEMENT_TIMEOUT[] = "STATEMENT_TIMEOUT", EFFECTIVE_USER_NAME[] = "EFFECTIVE_USER", + SESSION_TIMEZONE[] = "SESSION_TIMEZONE", // SYSTEM namespace: transaction wise items TRANSACTION_ID_NAME[] = "TRANSACTION_ID", ISOLATION_LEVEL_NAME[] = "ISOLATION_LEVEL", @@ -4331,6 +4332,12 @@ dsc* evlGetContext(thread_db* tdbb, const SysFunction*, const NestValueArray& ar return NULL; resultStr = user.c_str(); } + else if (nameStr == SESSION_TIMEZONE) + { + char timeZoneBuffer[TimeZoneUtil::MAX_SIZE]; + TimeZoneUtil::format(timeZoneBuffer, sizeof(timeZoneBuffer), attachment->att_current_timezone); + resultStr = timeZoneBuffer; + } else { // "Context variable %s is not found in namespace %s"