From 279d2dd85f3b622be9af61b4316efcdee68f9eb7 Mon Sep 17 00:00:00 2001 From: Anthony Tuininga Date: Tue, 28 Mar 2023 21:54:47 -0600 Subject: [PATCH] Detect the time zone on the OS and set the session timezone using this value to be consistent with thick mode (#144). --- doc/src/release_notes.rst | 3 +++ src/oracledb/impl/thin/messages.pyx | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/src/release_notes.rst b/doc/src/release_notes.rst index 2c30ddd..c8829cd 100644 --- a/doc/src/release_notes.rst +++ b/doc/src/release_notes.rst @@ -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 `__). #) 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 diff --git a/src/oracledb/impl/thin/messages.pyx b/src/oracledb/impl/thin/messages.pyx index 6ec1779..77fa39f 100644 --- a/src/oracledb/impl/thin/messages.pyx +++ b/src/oracledb/impl/thin/messages.pyx @@ -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 @@ -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: @@ -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)