Skip to content

Commit 9a4801a

Browse files
Added support for application context in thin mode; tweak documentation
for edition as well since they are closely related enhancements.
1 parent d9d4bee commit 9a4801a

File tree

14 files changed

+89
-55
lines changed

14 files changed

+89
-55
lines changed

doc/src/api_manual/async_connection.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,8 @@ AsyncConnection Attributes
485485

486486
.. attribute:: AsyncConnection.edition
487487

488-
This read-only attribute gets the session edition and is only available in
489-
Oracle Database 11.2 (the server must be at this level or higher for this
490-
to work). This attribute is ignored in python-oracledb Thin mode.
488+
This read-only attribute gets the session edition and is only available
489+
with Oracle Database 11.2, or later.
491490

492491
.. attribute:: AsyncConnection.external_name
493492

doc/src/api_manual/connect_params.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ ConnectParams Attributes
100100
used by the connection. It is a list of 3-tuples that includes the
101101
namespace, name, and value. Each entry in the tuple is a string.
102102

103-
This attribute is only supported in python-oracledb Thick mode.
103+
This attribute is supported in both python-oracledb Thin and Thick modes.
104104

105105
.. attribute:: ConnectParams.cclass
106106

doc/src/api_manual/connection.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -677,9 +677,8 @@ Connection Attributes
677677

678678
.. attribute:: Connection.edition
679679

680-
This read-only attribute gets the session edition and is only available in
681-
Oracle Database 11.2 (both client and server must be at this level or
682-
higher for this to work).
680+
This read-only attribute gets the session edition and is only available
681+
with Oracle Database 11.2, or later.
683682

684683
.. note::
685684

doc/src/api_manual/module.rst

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,9 @@ Oracledb Methods
253253
:attr:`defaults.stmtcachesize`.
254254

255255
The ``edition`` parameter is expected to be a string that indicates the
256-
edition to use for the connection. This parameter cannot be used
257-
simultaneously with the ``cclass`` parameter. This value is only used in
258-
the python-oracledb Thick mode and is ignored in the Thin mode.
256+
edition to use for the connection. It requires Oracle Database 11.2, or
257+
later. This parameter cannot be used simultaneously with the ``cclass``
258+
parameter.
259259

260260
The ``tag`` parameter is expected to be a string that identifies the type
261261
of connection that should be returned from a pool. This value is only used
@@ -276,8 +276,7 @@ Oracledb Methods
276276
The ``appcontext`` parameter is expected to be a list of 3-tuples that
277277
identifies the application context used by the connection. This parameter
278278
should contain namespace, name, and value and each entry in the tuple
279-
should be a string. This value is only used in the python-oracledb Thick
280-
mode and is ignored in the Thin mode.
279+
should be a string.
281280

282281
The ``shardingkey`` parameter and ``supershardingkey`` parameters, if
283282
specified, are expected to be a sequence of values which identifies the
@@ -389,7 +388,8 @@ Oracledb Methods
389388
.. versionchanged:: 2.5.0
390389

391390
The ``program``, ``machine``, ``terminal``, ``osuser``, and
392-
``driver_name`` parameters were added.
391+
``driver_name`` parameters were added. Support for ``edition`` and
392+
``appcontext`` was added to python-oracledb Thin mode.
393393

394394
.. versionchanged:: 2.3.0
395395

@@ -434,6 +434,8 @@ Oracledb Methods
434434
and can be specified as keyword parameters. See
435435
:ref:`standaloneconnection` information about connections.
436436

437+
This method can only be used in python-oracledb Thin mode.
438+
437439
.. versionadded:: 2.0.0
438440

439441
Some values, such as the database host name, can be specified as
@@ -584,8 +586,6 @@ Oracledb Methods
584586
specifies the initial size of the statement cache. The default is the
585587
value of :attr:`defaults.stmtcachesize`.
586588

587-
The ``edition`` parameter is ignored in the python-oracledb Thin mode.
588-
589589
The ``tag`` parameter is ignored in the python-oracledb Thin mode.
590590

591591
The ``matchanytag`` parameter is ignored in the python-oracledb Thin mode.
@@ -594,7 +594,10 @@ Oracledb Methods
594594
directory in which configuration files (tnsnames.ora) are found. The
595595
default is the value of :attr:`defaults.config_dir`.
596596

597-
The ``appcontext`` parameter is ignored in the python-oracledb Thin mode.
597+
The ``appcontext`` parameter is expected to be a list of 3-tuples that
598+
identifies the application context used by the connection. This parameter
599+
should contain namespace, name, and value and each entry in the tuple
600+
should be a string.
598601

599602
The ``shardingkey`` parameter and ``supershardingkey`` parameters are
600603
ignored in the python-oracledb Thin mode.
@@ -689,7 +692,8 @@ Oracledb Methods
689692
.. versionchanged:: 2.5.0
690693

691694
The ``program``, ``machine``, ``terminal``, ``osuser``, and
692-
``driver_name`` parameters were added.
695+
``driver_name`` parameters were added. Support for ``edition`` and
696+
``appcontext`` was added.
693697

694698
.. versionchanged:: 2.3.0
695699

@@ -891,9 +895,9 @@ Oracledb Methods
891895
:attr:`defaults.stmtcachesize`.
892896

893897
The ``edition`` parameter is expected to be a string that indicates the
894-
edition to use for the connection. This parameter cannot be used
895-
simultaneously with the ``cclass`` parameter. This value is used in the
896-
python-oracledb Thick mode.
898+
edition to use for the connection. It requires Oracle Database 11.2, or
899+
later. This parameter cannot be used simultaneously with the ``cclass``
900+
parameter.
897901

898902
The ``tag`` parameter is expected to be a string that identifies the type of
899903
connection that should be returned from a pool. This value is only used
@@ -913,8 +917,7 @@ Oracledb Methods
913917
The ``appcontext`` parameter is expected to be a list of 3-tuples that
914918
identifies the application context used by the connection. This parameter
915919
should contain namespace, name, and value and each entry in the tuple
916-
should be a string. This value is only used inthe python-oracledb Thick
917-
mode.
920+
should be a string.
918921

919922
The ``shardingkey`` parameter and ``supershardingkey`` parameters, if
920923
specified, are expected to be a sequence of values which identifies the
@@ -1352,9 +1355,9 @@ Oracledb Methods
13521355
:attr:`defaults.stmtcachesize`.
13531356

13541357
The ``edition`` parameter is expected to be a string that indicates the
1355-
edition to use for the connection. This parameter cannot be used
1356-
simultaneously with the ``cclass`` parameter. This value is used in the
1357-
python-oracledb Thick mode and is ignored in the Thin mode.
1358+
edition to use for the connection. It requires Oracle Database 11.2, or
1359+
later. This parameter cannot be used simultaneously with the ``cclass``
1360+
parameter.
13581361

13591362
The ``tag`` parameter is expected to be a string that identifies the type
13601363
of connection that should be returned from a pool. This value is only used
@@ -1488,7 +1491,8 @@ Oracledb Methods
14881491
.. versionchanged:: 2.5.0
14891492

14901493
The ``program``, ``machine``, ``terminal``, ``osuser``, and
1491-
``driver_name`` parameters were added.
1494+
``driver_name`` parameters were added. Support for ``edition`` and
1495+
``appcontext`` was added to python-oracledb Thin mode.
14921496

14931497
.. versionchanged:: 2.3.0
14941498

@@ -1538,6 +1542,8 @@ Oracledb Methods
15381542
``create_pool_async()`` is a synchronous method. See
15391543
:ref:`Connection pooling <asyncconnpool>` for more information.
15401544

1545+
This method can only be used in python-oracledb Thin mode.
1546+
15411547
.. versionadded:: 2.0.0
15421548

15431549
Some values, such as the database host name, can be specified as
@@ -1744,8 +1750,6 @@ Oracledb Methods
17441750
specifies the initial size of the statement cache. The default is the
17451751
value of :attr:`defaults.stmtcachesize`.
17461752

1747-
The ``edition`` parameter is ignored in the python-oracledb Thin mode.
1748-
17491753
The ``tag`` parameter is ignored in the python-oracledb Thin mode.
17501754

17511755
The ``matchanytag`` parameter is ignored in the python-oracledb Thin mode.
@@ -1754,7 +1758,10 @@ Oracledb Methods
17541758
directory in which configuration files (tnsnames.ora) are found. The
17551759
default is the value of :attr:`defaults.config_dir`.
17561760

1757-
The ``appcontext`` parameter is ignored in the python-oracledb Thin mode.
1761+
The ``appcontext`` parameter is expected to be a list of 3-tuples that
1762+
identifies the application context used by the connection. This parameter
1763+
should contain namespace, name, and value and each entry in the tuple
1764+
should be a string.
17581765

17591766
The ``shardingkey`` parameter and ``supershardingkey`` parameters are
17601767
ignored in the python-oracledb Thin mode.
@@ -1849,7 +1856,8 @@ Oracledb Methods
18491856
.. versionchanged:: 2.5.0
18501857

18511858
The ``program``, ``machine``, ``terminal``, ``osuser``, and
1852-
``driver_name`` parameters were added.
1859+
``driver_name`` parameters were added. Support for ``edition`` and
1860+
``appcontext`` was added.
18531861

18541862
.. versionchanged:: 2.3.0
18551863

@@ -2271,9 +2279,9 @@ Oracledb Methods
22712279
:attr:`defaults.stmtcachesize`.
22722280

22732281
The ``edition`` parameter is expected to be a string that indicates the
2274-
edition to use for the connection. This parameter cannot be used
2275-
simultaneously with the ``cclass`` parameter. This value is used in the
2276-
python-oracledb Thick mode.
2282+
edition to use for the connection. It requires Oracle Database 11.2, or
2283+
later. This parameter cannot be used simultaneously with the ``cclass``
2284+
parameter.
22772285

22782286
The ``tag`` parameter is expected to be a string that identifies the type
22792287
of connection that should be returned from a pool. This value is only used

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Thin Mode Changes
4848
about any query column metadata returned from a pipeline operation.
4949
#) Added support for setting the :ref:`edition <ebr>` when connecting to
5050
Oracle Database.
51+
#) Added support for Application Contexts, i.e. the ``appcontext`` parameter
52+
is supported when connecting.
5153
#) Fixed bug causing some pooled connections to be permanently marked as busy
5254
and unavailable for reuse
5355
(`issue 392 <https://github.com/oracle/python-oracledb/issues/392>`__).

doc/src/user_guide/appendix_a.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ see :ref:`driverdiff` and :ref:`compatibility`.
331331
- Yes
332332
- Yes
333333
* - Application Contexts
334-
- No
334+
- Yes
335335
- Yes
336336
- Yes
337337
* - Persistent and Temporary LOBs

doc/src/user_guide/appendix_b.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,13 @@ the recommended way to create a connection pool. The use of the equivalent
234234
The :func:`~oracledb.create_pool()` method in the python-oracledb Thin mode
235235
differs from the python-oracledb Thick mode in the following ways:
236236

237-
* Not all the parameters of the :func:`oracledb.create_pool()` method are applicable
238-
to both python-oracledb modes. Each mode ignores unrecognized parameters.
239-
The parameters that are ignored in Thin mode include ``events``, ``tag``,
240-
``matchanytag``, ``appcontext``, ``shardingkey``, ``supershardingkey``, and
241-
``handle`` parameters. The parameters that are ignored in the Thick mode include
242-
``wallet_password``, ``disable_oob``, ``config_dir``, and ``debug_jdwp`` parameters.
237+
* Not all the parameters of the :func:`oracledb.create_pool()` method are
238+
applicable to both python-oracledb modes. Each mode ignores unrecognized
239+
parameters. The parameters that are ignored in Thin mode include ``events``,
240+
``tag``, ``matchanytag``, ``shardingkey``, ``supershardingkey``, and
241+
``handle`` parameters. The parameters that are ignored in the Thick mode
242+
include ``wallet_password``, ``disable_oob``, ``config_dir``, and
243+
``debug_jdwp`` parameters.
243244

244245
* The python-oracledb Thin mode only suppports :ref:`homogeneous
245246
<connpooltypes>` pools.

samples/app_context.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -----------------------------------------------------------------------------
2-
# Copyright (c) 2016, 2023, Oracle and/or its affiliates.
2+
# Copyright (c) 2016, 2024, Oracle and/or its affiliates.
33
#
44
# Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
55
#
@@ -38,8 +38,9 @@
3838
import oracledb
3939
import sample_env
4040

41-
# this script is currently only supported in python-oracledb thick mode
42-
oracledb.init_oracle_client(lib_dir=sample_env.get_oracle_client())
41+
# determine whether to use python-oracledb thin mode or thick mode
42+
if not sample_env.get_is_thin():
43+
oracledb.init_oracle_client(lib_dir=sample_env.get_oracle_client())
4344

4445
# client context attributes to be set
4546
APP_CTX_NAMESPACE = "CLIENTCONTEXT"

src/oracledb/impl/base/connect_params.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ cdef class ConnectParamsImpl:
9393
_set_obj_param(args, "ssl_context", self)
9494
_set_str_param(args, "debug_jdwp", self)
9595
_set_str_param(args, "config_dir", self)
96-
_set_obj_param(args, "appcontext", self)
96+
_set_app_context_param(args, "appcontext", self)
9797
_set_obj_param(args, "shardingkey", self)
9898
_set_obj_param(args, "supershardingkey", self)
9999
_set_bool_param(args, "externalauth", &self.externalauth)

src/oracledb/impl/base/utils.pyx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@
2828
# Cython file defining utility methods (embedded in base_impl.pyx).
2929
#------------------------------------------------------------------------------
3030

31+
cdef int _set_app_context_param(dict args, str name, object target) except -1:
32+
"""
33+
Sets an application context parameter to the value provided in the
34+
dictionary, if a value is provided. This value is then set directly on the
35+
target.
36+
"""
37+
in_val = args.get(name)
38+
if in_val is not None:
39+
message = (
40+
"appcontext should be a list of 3-tuples and each 3-tuple should "
41+
"contain three strings"
42+
)
43+
if not isinstance(in_val, list):
44+
raise TypeError(message)
45+
for entry in in_val:
46+
if not isinstance(entry, tuple) or len(entry) != 3:
47+
raise TypeError(message)
48+
for value in entry:
49+
if not isinstance(value, str):
50+
raise TypeError(message)
51+
setattr(target, name, in_val)
52+
53+
3154
cdef int _set_bool_param(dict args, str name, bint *out_val) except -1:
3255
"""
3356
Sets a boolean parameter to the value provided in the dictionary. This can

src/oracledb/impl/thick/connection.pyx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,6 @@ cdef class ConnectionParams:
157157
num_bytes = self.num_app_context * sizeof(dpiAppContext)
158158
self.app_context = <dpiAppContext*> cpython.PyMem_Malloc(num_bytes)
159159
for i in range(self.num_app_context):
160-
if not isinstance(entries[i], tuple) or len(entries[i]) != 3:
161-
raise TypeError("appcontext should be a list of 3-tuples")
162160
namespace, name, value = entries[i]
163161
entry = &self.app_context[i]
164162
self._process_context_str(namespace, &entry.namespaceName,

src/oracledb/impl/thin/messages.pyx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,7 @@ cdef class AuthMessage(Message):
14591459
str osuser
14601460
str driver_name
14611461
str edition
1462+
list appcontext
14621463

14631464
cdef int _encrypt_passwords(self) except -1:
14641465
"""
@@ -1667,6 +1668,7 @@ cdef class AuthMessage(Message):
16671668
if self.driver_name is None:
16681669
self.driver_name = f"{DRIVER_NAME} thn : {DRIVER_VERSION}"
16691670
self.edition = params.edition
1671+
self.appcontext = params.appcontext
16701672

16711673
# if drcp is used, use purity = NEW as the default purity for
16721674
# standalone connections and purity = SELF for connections that belong
@@ -1770,6 +1772,8 @@ cdef class AuthMessage(Message):
17701772
num_pairs += 1
17711773
if self.edition is not None:
17721774
num_pairs += 1
1775+
if self.appcontext is not None:
1776+
num_pairs += len(self.appcontext) * 3
17731777

17741778
# write basic data to packet
17751779
self._write_function_code(buf)
@@ -1836,6 +1840,13 @@ cdef class AuthMessage(Message):
18361840
self.encoded_jdwp_data)
18371841
if self.edition is not None:
18381842
self._write_key_value(buf, "AUTH_ORA_EDITION", self.edition)
1843+
if self.appcontext is not None:
1844+
# NOTE: these keys require a trailing null character as the
1845+
# server expects it!
1846+
for entry in self.appcontext:
1847+
self._write_key_value(buf, "AUTH_APPCTX_NSPACE\0", entry[0])
1848+
self._write_key_value(buf, "AUTH_APPCTX_ATTR\0", entry[1])
1849+
self._write_key_value(buf, "AUTH_APPCTX_VALUE\0", entry[2])
18391850

18401851

18411852
@cython.final

tests/test_1100_connection.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ def test_1100(self):
8585
self.assertEqual(conn.thin, test_env.get_is_thin())
8686

8787
@unittest.skipIf(test_env.get_is_drcp(), "not supported with DRCP")
88-
@unittest.skipIf(
89-
test_env.get_is_thin(),
90-
"thin mode doesn't support application context yet",
91-
)
9288
def test_1101(self):
9389
"1101 - test use of application context"
9490
namespace = "CLIENTCONTEXT"
@@ -106,10 +102,6 @@ def test_1101(self):
106102
(actual_value,) = cursor.fetchone()
107103
self.assertEqual(actual_value, value)
108104

109-
@unittest.skipIf(
110-
test_env.get_is_thin(),
111-
"thin mode doesn't support application context yet",
112-
)
113105
def test_1102(self):
114106
"1102 - test invalid use of application context"
115107
self.assertRaises(

tests/test_4500_connect_params.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ def test_4539(self):
721721
("tag", "tag_new"),
722722
("matchanytag", False),
723723
("config_dir", "config_dir_new"),
724-
("appcontext", [("a", "b", "c", "new")]),
724+
("appcontext", [("a", "b", "c"), ("d", "e", "f")]),
725725
("shardingkey", [1, 2, 3, 4]),
726726
("supershardingkey", [6]),
727727
("debug_jdwp", "host=host;port=4638"),

0 commit comments

Comments
 (0)