Skip to content

Commit

Permalink
Detect the time zone on the OS and set the session timezone using this
Browse files Browse the repository at this point in the history
value to be consistent with thick mode (#144).
  • Loading branch information
anthony-tuininga committed Mar 29, 2023
1 parent c1417d1 commit 279d2dd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Thin Mode Changes
collections.
#) Removed internally set fixed size for database collections. Collections of
any size supported by the database can now be created.
#) Detect the time zone on the OS and set the session timezone using this
value to be consistent with thick mode
(`issue 144 <https://github.com/oracle/python-oracledb/issues/144>`__).
#) Improved BOOLEAN handling.
#) Error ``DPY-6005: cannot connect to database`` is now raised for all
failures to connect to the database and the phrase ``cannot connect to
Expand Down
21 changes: 20 additions & 1 deletion src/oracledb/impl/thin/messages.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,23 @@ cdef class AuthMessage(Message):
# use of AES encryption
self.encoded_jdwp_data = encrypted_jdwp_data.hex().upper() + "01"

cdef str _get_alter_timezone_statement(self):
"""
Returns the statement required to change the session time zone to match
the time zone in use by the Python interpreter.
"""
cdef:
int tz_hour, tz_minute, timezone
str sign, tz_repr
timezone = -time.altzone if time.daylight else -time.timezone
tz_hour = timezone // 3600
tz_minute = (timezone - (tz_hour * 3600)) // 60
if tz_hour < 0:
sign = "-"
tz_hour = -tz_hour
tz_repr = f"{sign}{tz_hour:02}:{tz_minute:02}"
return f"ALTER SESSION SET TIME_ZONE='{tz_repr}'\x00"

cdef tuple _get_version_tuple(self, ReadBuffer buf):
"""
Return the 5-tuple for the database version. Note that the format
Expand Down Expand Up @@ -1528,7 +1545,7 @@ cdef class AuthMessage(Message):
self._encrypt_passwords()
num_pairs = 2
else:
num_pairs = 3
num_pairs = 4

# token authentication
if self.token is not None:
Expand Down Expand Up @@ -1610,6 +1627,8 @@ cdef class AuthMessage(Message):
driver_name)
self._write_key_value(buf, "SESSION_CLIENT_VERSION",
str(_connect_constants.full_version_num))
self._write_key_value(buf, "AUTH_ALTER_SESSION",
self._get_alter_timezone_statement(), 1)
if self.conn_impl._cclass is not None:
self._write_key_value(buf, "AUTH_KPPL_CONN_CLASS",
self.conn_impl._cclass)
Expand Down

0 comments on commit 279d2dd

Please sign in to comment.