Skip to content

Commit ef3ba1f

Browse files
Added support for Json ID values.
1 parent dcf67f2 commit ef3ba1f

File tree

13 files changed

+81
-13
lines changed

13 files changed

+81
-13
lines changed

doc/src/api_manual/module.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,17 @@ Oracledb Methods
18671867
(number of seconds since the epoch; see the documentation of the standard
18681868
Python time module for details).
18691869

1870+
1871+
.. _jsonid:
1872+
1873+
oracledb.JsonId Class
1874+
=====================
1875+
1876+
Objects of this class are returned by SODA in Oracle Database 23.4 and higher
1877+
in the ``_id`` attribute of documents stored in native collections. It is a
1878+
subclass of the ``bytes`` class.
1879+
1880+
18701881
.. _futureobj:
18711882

18721883
Oracledb.__future__ Object

doc/src/release_notes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Common Changes
6767
columns which have the check constraint ``IS JSON FORMAT OSON`` enabled.
6868
#) Added boolean property :data:`FetchInfo.is_oson` which is set when a column
6969
has the check constraint "IS JSON FORMAT OSON" enabled.
70+
#) Added class :ref:`oracledb.JsonId <jsonid>` to represent JSON ID values
71+
returned by SODA in Oracle Database 23.4 and higher in the ``_id``
72+
attribute of documents stored in native collections.
7073
#) Added support for columns of type vector (currently requires access to a
7174
limited availability release of the database).
7275
#) Errors raised when calling :meth:`Cursor.executemany()` with PL/SQL now

src/oracledb/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2024, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -270,6 +270,11 @@
270270
future as __future__, # noqa: F401
271271
)
272272

273+
274+
class JsonId(bytes):
275+
pass
276+
277+
273278
package = sys.modules[__name__]
274279
base_impl.init_base_impl(package)
275280
thick_impl.init_thick_impl(package)

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ cdef enum:
4545

4646
cdef enum:
4747
DB_TYPE_NUM_MIN = 2000
48-
DB_TYPE_NUM_MAX = 2033
48+
DB_TYPE_NUM_MAX = 2034
4949

5050
DB_TYPE_NUM_BFILE = 2020
5151
DB_TYPE_NUM_BINARY_DOUBLE = 2008

src/oracledb/base_impl.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ cdef type PY_TYPE_DATETIME = datetime.datetime
6969
cdef type PY_TYPE_DECIMAL = decimal.Decimal
7070
cdef type PY_TYPE_DB_OBJECT
7171
cdef type PY_TYPE_DB_OBJECT_TYPE
72+
cdef type PY_TYPE_JSON_ID
7273
cdef type PY_TYPE_LOB
7374
cdef type PY_TYPE_TIMEDELTA = datetime.timedelta
7475
cdef type PY_TYPE_VAR

src/oracledb/impl/base/oson.pyx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ cdef class OsonDecoder(Buffer):
163163
elif node_type == TNS_JSON_TYPE_ID:
164164
self.read_ub1(&temp8)
165165
ptr = self._get_raw(temp8)
166-
return ptr[:temp8]
166+
return PY_TYPE_JSON_ID(ptr[:temp8])
167167
elif node_type == TNS_JSON_TYPE_BINARY_LENGTH_UINT16:
168168
self.read_uint16(&temp16)
169169
ptr = self._get_raw(temp16)
@@ -611,7 +611,10 @@ cdef class OsonTreeSegment(GrowableBuffer):
611611
# handle bytes
612612
elif isinstance(value, bytes):
613613
value_len = len(<bytes> value)
614-
if value_len < 65536:
614+
if isinstance(value, PY_TYPE_JSON_ID):
615+
self.write_uint8(TNS_JSON_TYPE_ID)
616+
self.write_uint8(<uint8_t> value_len)
617+
elif value_len < 65536:
615618
self.write_uint8(TNS_JSON_TYPE_BINARY_LENGTH_UINT16)
616619
self.write_uint16(<uint16_t> value_len)
617620
else:

src/oracledb/impl/base/utils.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ def init_base_impl(package):
201201
"""
202202
global PY_TYPE_ASYNC_CURSOR, PY_TYPE_ASYNC_LOB, PY_TYPE_CURSOR
203203
global PY_TYPE_DB_OBJECT, PY_TYPE_DB_OBJECT_TYPE, PY_TYPE_LOB, PY_TYPE_VAR
204-
global PY_TYPE_FETCHINFO
204+
global PY_TYPE_FETCHINFO, PY_TYPE_JSON_ID
205205
PY_TYPE_ASYNC_CURSOR = package.AsyncCursor
206206
PY_TYPE_ASYNC_LOB = package.AsyncLOB
207207
PY_TYPE_CURSOR = package.Cursor
208208
PY_TYPE_DB_OBJECT = package.DbObject
209209
PY_TYPE_DB_OBJECT_TYPE = package.DbObjectType
210+
PY_TYPE_JSON_ID = package.JsonId
210211
PY_TYPE_FETCHINFO = package.FetchInfo
211212
PY_TYPE_LOB = package.LOB
212213
PY_TYPE_VAR = package.Var

src/oracledb/impl/thick/buffer.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#------------------------------------------------------------------------------
2-
# Copyright (c) 2020, 2022, Oracle and/or its affiliates.
2+
# Copyright (c) 2020, 2024, Oracle and/or its affiliates.
33
#
44
# This software is dual-licensed to you under the Universal Permissive License
55
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
@@ -48,7 +48,7 @@ cdef class StringBuffer:
4848
self.obj = (<str> value).encode()
4949
self.size_in_chars = <uint32_t> len(<str> value)
5050
elif isinstance(value, bytes):
51-
self.obj = value
51+
self.obj = <bytes> value
5252
self.size_in_chars = <uint32_t> len(<bytes> value)
5353
else:
5454
raise TypeError("expecting string or bytes")

src/oracledb/impl/thick/json.pyx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ cdef class JsonBuffer:
108108
self._add_buf(value, &node.value.asBytes.ptr,
109109
&node.value.asBytes.length)
110110
elif isinstance(value, bytes):
111-
node.oracleTypeNum = DPI_ORACLE_TYPE_RAW
111+
node.oracleTypeNum = DPI_ORACLE_TYPE_JSON_ID \
112+
if isinstance(value, PY_TYPE_JSON_ID) \
113+
else DPI_ORACLE_TYPE_RAW
112114
node.nativeTypeNum = DPI_NATIVE_TYPE_BYTES
113115
self._add_buf(value, &node.value.asBytes.ptr,
114116
&node.value.asBytes.length)

src/oracledb/impl/thick/odpi.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ cdef extern from "impl/thick/odpi/embed/dpi.c":
111111
DPI_ORACLE_TYPE_INTERVAL_YM
112112
DPI_ORACLE_TYPE_JSON
113113
DPI_ORACLE_TYPE_JSON_ARRAY
114+
DPI_ORACLE_TYPE_JSON_ID
114115
DPI_ORACLE_TYPE_JSON_OBJECT
115116
DPI_ORACLE_TYPE_LONG_NVARCHAR
116117
DPI_ORACLE_TYPE_LONG_RAW
@@ -342,6 +343,7 @@ cdef extern from "impl/thick/odpi/embed/dpi.c":
342343
const char *oracleClientLibDir
343344
const char *oracleClientConfigDir
344345
bint sodaUseJsonDesc
346+
bint useJsonId
345347

346348
ctypedef union dpiDataBuffer:
347349
bint asBoolean

0 commit comments

Comments
 (0)