Skip to content

Commit

Permalink
Fixed CORE-6034 - The original time zone should be set to the current…
Browse files Browse the repository at this point in the history
… time zone at routine invocation.
  • Loading branch information
asfernandes committed Mar 26, 2019
1 parent c2fe37d commit a64b202
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions doc/sql.extensions/README.time_zone.md
Expand Up @@ -8,6 +8,8 @@ The session time zone, as the name implies, can be a different one for each data

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`.

The original time zone value is initially defined equal to the current time zone in session initialization and cannot be changed manually. But the original time zone is internally changed when a routine (function, procedure or trigger) is called to the value of the current time zone and restored to its previous value at routine exit. That means that a routine that changes the current time zone and later run `SET TIME ZONE LOCAL` will restore the current time zone to its initially received value.

A time zone may be a string with a time zone region (for example, `America/Sao_Paulo`) or a hours:minutes displacement (for example, `-03:00`) from GMT.

A time/timestamp with time zone is considered equal to another time/timestamp with time zone if their conversion to UTC are equal, for example, `time '10:00 -02' = time '09:00 -03'`, since both are the same as `time '12:00 GMT'`. This is also valid in the context of `UNIQUE` constraints and for sorting purposes.
Expand Down
4 changes: 4 additions & 0 deletions src/dsql/ExprNodes.cpp
Expand Up @@ -12712,6 +12712,10 @@ dsc* UdfCallNode::execute(thread_db* tdbb, jrd_req* request) const
Arg::Gds(isc_modnotfound));
}

AutoSetRestore<USHORT> autoOriginalTimeZone(
&tdbb->getAttachment()->att_original_timezone,
tdbb->getAttachment()->att_current_timezone);

// Evaluate the function.

if (function->fun_entrypoint)
Expand Down
4 changes: 4 additions & 0 deletions src/dsql/StmtNodes.cpp
Expand Up @@ -3203,6 +3203,10 @@ void ExecProcedureNode::executeProcedure(thread_db* tdbb, jrd_req* request) cons

try
{
AutoSetRestore<USHORT> autoOriginalTimeZone(
&tdbb->getAttachment()->att_original_timezone,
tdbb->getAttachment()->att_current_timezone);

procRequest->req_gmt_timestamp = request->req_gmt_timestamp;

EXE_start(tdbb, procRequest, transaction);
Expand Down
4 changes: 4 additions & 0 deletions src/jrd/exe.cpp
Expand Up @@ -1163,6 +1163,10 @@ void EXE_execute_triggers(thread_db* tdbb,
UserId* invoker = s->triggerInvoker ? s->triggerInvoker : tdbb->getAttachment()->att_ss_user;
AutoSetRestore<UserId*> userIdHolder(&tdbb->getAttachment()->att_ss_user, invoker);

AutoSetRestore<USHORT> autoOriginalTimeZone(
&tdbb->getAttachment()->att_original_timezone,
tdbb->getAttachment()->att_current_timezone);

EXE_start(tdbb, trigger, transaction);
}

Expand Down
8 changes: 8 additions & 0 deletions src/jrd/recsrc/ProcedureScan.cpp
Expand Up @@ -110,6 +110,10 @@ void ProcedureScan::open(thread_db* tdbb) const

TraceProcExecute trace(tdbb, proc_request, request, m_targetList);

AutoSetRestore<USHORT> autoOriginalTimeZone(
&tdbb->getAttachment()->att_original_timezone,
tdbb->getAttachment()->att_current_timezone);

EXE_start(tdbb, proc_request, request->req_transaction);

if (iml)
Expand Down Expand Up @@ -184,6 +188,10 @@ bool ProcedureScan::getRecord(thread_db* tdbb) const

TraceProcFetch trace(tdbb, proc_request);

AutoSetRestore<USHORT> autoOriginalTimeZone(
&tdbb->getAttachment()->att_original_timezone,
tdbb->getAttachment()->att_current_timezone);

try
{
EXE_receive(tdbb, proc_request, 1, oml, om);
Expand Down

0 comments on commit a64b202

Please sign in to comment.