Skip to content

Commit 279d2dd

Browse files
Detect the time zone on the OS and set the session timezone using this
value to be consistent with thick mode (#144).
1 parent c1417d1 commit 279d2dd

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Thin Mode Changes
2323
collections.
2424
#) Removed internally set fixed size for database collections. Collections of
2525
any size supported by the database can now be created.
26+
#) Detect the time zone on the OS and set the session timezone using this
27+
value to be consistent with thick mode
28+
(`issue 144 <https://github.com/oracle/python-oracledb/issues/144>`__).
2629
#) Improved BOOLEAN handling.
2730
#) Error ``DPY-6005: cannot connect to database`` is now raised for all
2831
failures to connect to the database and the phrase ``cannot connect to

src/oracledb/impl/thin/messages.pyx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,23 @@ cdef class AuthMessage(Message):
13861386
# use of AES encryption
13871387
self.encoded_jdwp_data = encrypted_jdwp_data.hex().upper() + "01"
13881388

1389+
cdef str _get_alter_timezone_statement(self):
1390+
"""
1391+
Returns the statement required to change the session time zone to match
1392+
the time zone in use by the Python interpreter.
1393+
"""
1394+
cdef:
1395+
int tz_hour, tz_minute, timezone
1396+
str sign, tz_repr
1397+
timezone = -time.altzone if time.daylight else -time.timezone
1398+
tz_hour = timezone // 3600
1399+
tz_minute = (timezone - (tz_hour * 3600)) // 60
1400+
if tz_hour < 0:
1401+
sign = "-"
1402+
tz_hour = -tz_hour
1403+
tz_repr = f"{sign}{tz_hour:02}:{tz_minute:02}"
1404+
return f"ALTER SESSION SET TIME_ZONE='{tz_repr}'\x00"
1405+
13891406
cdef tuple _get_version_tuple(self, ReadBuffer buf):
13901407
"""
13911408
Return the 5-tuple for the database version. Note that the format
@@ -1528,7 +1545,7 @@ cdef class AuthMessage(Message):
15281545
self._encrypt_passwords()
15291546
num_pairs = 2
15301547
else:
1531-
num_pairs = 3
1548+
num_pairs = 4
15321549

15331550
# token authentication
15341551
if self.token is not None:
@@ -1610,6 +1627,8 @@ cdef class AuthMessage(Message):
16101627
driver_name)
16111628
self._write_key_value(buf, "SESSION_CLIENT_VERSION",
16121629
str(_connect_constants.full_version_num))
1630+
self._write_key_value(buf, "AUTH_ALTER_SESSION",
1631+
self._get_alter_timezone_statement(), 1)
16131632
if self.conn_impl._cclass is not None:
16141633
self._write_key_value(buf, "AUTH_KPPL_CONN_CLASS",
16151634
self.conn_impl._cclass)

0 commit comments

Comments
 (0)