Skip to content

Commit

Permalink
Fixed bug with ordering of binds in SQL when the database version is
Browse files Browse the repository at this point in the history
12.1 (#135).
  • Loading branch information
anthony-tuininga committed Mar 22, 2023
1 parent ee07e83 commit 40caed2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Thin Mode Changes
#) Fixed bug with SQL containing multibyte characters with certain database
character sets
(`issue 133 <https://github.com/oracle/python-oracledb/issues/133>`__).
#) Fixed bug with ordering of binds in SQL when the database version is 12.1
(`issue 135 <https://github.com/oracle/python-oracledb/issues/135>`__).
#) Fixed bug with ordering of binds in PL/SQL when the bind variable may
potentially exceed the 32767 byte limit but the actual value bound does not
(`issue 146 <https://github.com/oracle/python-oracledb/issues/146>`__).
Expand Down
3 changes: 2 additions & 1 deletion src/oracledb/impl/thin/buffer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ cdef class Buffer:
cdef ssize_t chunk_len
if num_bytes <= TNS_MAX_SHORT_LENGTH:
self.write_uint8(<uint8_t> num_bytes)
self.write_raw(ptr, num_bytes)
if num_bytes > 0:
self.write_raw(ptr, num_bytes)
else:
self.write_uint8(TNS_LONG_LENGTH_INDICATOR)
while num_bytes > 0:
Expand Down
6 changes: 5 additions & 1 deletion src/oracledb/impl/thin/capabilities.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ cdef class Capabilities:
uint16_t ncharset_id
bytearray compile_caps
bytearray runtime_caps
uint32_t max_string_size
bint supports_oob

def __init__(self):
Expand All @@ -57,7 +58,10 @@ cdef class Capabilities:

@cython.boundscheck(False)
cdef void _adjust_for_server_runtime_caps(self, bytearray server_caps):
pass
if server_caps[TNS_RCAP_TTC] & TNS_RCAP_TTC_32K:
self.max_string_size = 32767
else:
self.max_string_size = 4000

cdef int _check_ncharset_id(self) except -1:
"""
Expand Down
1 change: 0 additions & 1 deletion src/oracledb/impl/thin/constants.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,6 @@ DEF TNS_MAX_ROWID_LENGTH = 18
DEF TNS_DURATION_MID = 0x80000000
DEF TNS_DURATION_OFFSET = 60
DEF TNS_DURATION_SESSION = 10
DEF TNS_MIN_LONG_LENGTH = 0x8000
DEF TNS_MAX_LONG_LENGTH = 0x7fffffff
DEF TNS_SDU = 8192
DEF TNS_TDU = 65535
Expand Down
6 changes: 3 additions & 3 deletions src/oracledb/impl/thin/messages.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ cdef class MessageWithData(Message):
# expects that and complains if any other value is sent!
buf.write_uint8(0)
buf.write_uint8(0)
if buffer_size >= TNS_MIN_LONG_LENGTH:
if buffer_size > buf._caps.max_string_size:
buf.write_ub4(TNS_MAX_LONG_LENGTH)
else:
buf.write_ub4(buffer_size)
Expand Down Expand Up @@ -1062,7 +1062,7 @@ cdef class MessageWithData(Message):
self._write_bind_params_column(buf, var_impl, value)
else:
if not self.cursor_impl._statement._is_plsql \
and var_impl.buffer_size >= TNS_MIN_LONG_LENGTH:
and var_impl.buffer_size > buf._caps.max_string_size:
found_long = True
continue
self._write_bind_params_column(buf, var_impl,
Expand All @@ -1072,7 +1072,7 @@ cdef class MessageWithData(Message):
if bind_info._is_return_bind:
continue
var_impl = bind_info._bind_var_impl
if var_impl.buffer_size < TNS_MIN_LONG_LENGTH:
if var_impl.buffer_size <= buf._caps.max_string_size:
continue
self._write_bind_params_column(buf, var_impl,
var_impl._values[pos + offset])
Expand Down

0 comments on commit 40caed2

Please sign in to comment.