Skip to content

Commit a4c13ab

Browse files
Added parameter "data" to connection.createlob() to allow data to be
written at LOB creation time.
1 parent 8211232 commit a4c13ab

File tree

7 files changed

+62
-23
lines changed

7 files changed

+62
-23
lines changed

doc/src/api_manual/connection.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,20 @@ Connection Methods
9191

9292
Commits any pending transactions to the database.
9393

94-
.. method:: Connection.createlob(lob_type)
94+
.. method:: Connection.createlob(lob_type, data=None)
9595

9696
Creates and returns a new temporary :ref:`LOB object <lobobj>` of the
9797
specified type. The ``lob_type`` parameter should be one of
9898
:data:`oracledb.DB_TYPE_CLOB`, :data:`oracledb.DB_TYPE_BLOB`, or
9999
:data:`oracledb.DB_TYPE_NCLOB`.
100100

101+
If data is supplied, it will be written to the temporary LOB before it is
102+
returned.
103+
104+
.. versionchanged:: 2.0
105+
106+
The parameter ``data`` was added.
107+
101108
.. note::
102109

103110
This method is an extension to the DB API definition.

doc/src/api_manual/deprecations.rst

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if applicable. The most recent deprecations are listed first.
1111
.. list-table-with-summary:: Desupported in python-oracledb 2.0
1212
:header-rows: 1
1313
:class: wy-table-responsive
14-
:summary: The first column, Name, displays the desupported API name. The second column, Comments, includes information about when the API desupported and what API to use, if applicable.
14+
:summary: The first column, Name, displays the desupported feature. The second column, Comments, includes information about the desupport and what replacement to make, if applicable.
1515
:name: _desupported_2_0
1616

1717
* - Name
@@ -49,10 +49,29 @@ if applicable. The most recent deprecations are listed first.
4949
* - ``SessionPool.tnsentry``
5050
- Replace with :attr:`ConnectionPool.dsn`
5151

52+
.. list-table-with-summary:: Deprecated in python-oracledb 2.0
53+
:header-rows: 1
54+
:class: wy-table-responsive
55+
:summary: The first column, Name, displays the deprecated feature. The second column, Comments, includes information about the deprecatation and what replacement to use, if applicable.
56+
:name: _deprecations_2_0
57+
58+
* - Name
59+
- Comments
60+
* - Calling :meth:`Variable.setvalue()` with a string value when the
61+
variable type is one of :data:`oracledb.DB_TYPE_BLOB`,
62+
:data:`oracledb.DB_TYPE_CLOB` or :data:`oracledb.DB_TYPE_NCLOB`.
63+
- Call :meth:`Connection.createlob()` with the value instead and pass the
64+
result to :meth:`Variable.setvalue()`.
65+
* - Setting an attribute of type :data:`oracledb.DB_TYPE_BLOB`,
66+
:data:`oracledb.DB_TYPE_CLOB` or :data:`oracledb.DB_TYPE_NCLOB` on a
67+
database object to a string value.
68+
- Call :meth:`Connection.createlob()` with the value instead and set the
69+
attribute with the result.
70+
5271
.. list-table-with-summary:: Deprecated in python-oracledb 1.4
5372
:header-rows: 1
5473
:class: wy-table-responsive
55-
:summary: The first column, Name, displays the deprecated API name. The second column, Comments, includes information about when the API was deprecated and what API to use, if applicable.
74+
:summary: The first column, Name, displays the deprecated feature. The second column, Comments, includes information about the deprecatation and what replacement to use, if applicable.
5675
:name: _deprecations_1_4
5776

5877
* - Name
@@ -163,9 +182,7 @@ python-oracledb are listed below:
163182
.. list-table-with-summary:: Deprecated in cx_Oracle 8.2
164183
:header-rows: 1
165184
:class: wy-table-responsive
166-
:summary: The first column, Name, displays the deprecated API name. The second column,
167-
Comments, includes information about when the API was deprecated and what API to use,
168-
if applicable.
185+
:summary: The first column, Name, displays the deprecated feature. The second column, Comments, includes information about the deprecatation and what replacement to use, if applicable.
169186
:name: _deprecations_8_2
170187

171188
* - Name
@@ -261,7 +278,7 @@ python-oracledb are listed below:
261278
.. list-table-with-summary:: Deprecated in cx_Oracle 8.0
262279
:header-rows: 1
263280
:class: wy-table-responsive
264-
:summary: The first column, Name, displays the deprecated API name. The second column, Comments, includes information about when the API was deprecated and what API to use, if applicable.
281+
:summary: The first column, Name, displays the deprecated feature. The second column, Comments, includes information about the deprecatation and what replacement to use, if applicable.
265282
:name: _deprecations_8_0
266283

267284
* - Name
@@ -303,7 +320,7 @@ python-oracledb are listed below:
303320
.. list-table-with-summary:: Deprecated in cx_Oracle 7.2
304321
:header-rows: 1
305322
:class: wy-table-responsive
306-
:summary: The first column, Name, displays the deprecated API name. The second column, Comments, includes information about when the API was deprecated and what API to use, if applicable.
323+
:summary: The first column, Name, displays the deprecated feature. The second column, Comments, includes information about the deprecatation and what replacement to use, if applicable.
307324
:name: _deprecations_7_2
308325

309326
* - Name
@@ -321,7 +338,7 @@ python-oracledb are listed below:
321338
.. list-table-with-summary:: Deprecated in cx_Oracle 6.4
322339
:header-rows: 1
323340
:class: wy-table-responsive
324-
:summary: The first column, Name, displays the deprecated API name. The second column, Comments, includes information about when the API was deprecated and what API to use, if applicable.
341+
:summary: The first column, Name, displays the deprecated feature. The second column, Comments, includes information about the deprecatation and what replacement to use, if applicable.
325342
:name: _deprecations_6_4
326343

327344
* - Name

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ Common Changes
7474
associated with columns that are being fetched. SQL domains and annotations
7575
require Oracle Database 23c. If using python-oracledb Thick mode, Oracle
7676
Client 23c is also required.
77+
#) Added parameter ``data`` to :meth:`Connection.createlob()` to allow data to
78+
be written at LOB creation time.
7779
#) Added type :data:`~oracledb.DB_TYPE_XMLTYPE` to represent data of type
7880
``SYS.XMLTYPE`` in the database. Previously the value of
7981
:data:`FetchInfo.type_code` for data of this type was

src/oracledb/connection.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,9 @@ def commit(self) -> None:
619619
self._verify_connected()
620620
self._impl.commit()
621621

622-
def createlob(self, lob_type: DbType) -> LOB:
622+
def createlob(
623+
self, lob_type: DbType, data: Union[str, bytes] = None
624+
) -> LOB:
623625
"""
624626
Create and return a new temporary LOB of the specified type.
625627
"""
@@ -631,6 +633,8 @@ def createlob(self, lob_type: DbType) -> LOB:
631633
)
632634
raise TypeError(message)
633635
impl = self._impl.create_temp_lob_impl(lob_type)
636+
if data:
637+
impl.write(data, 1)
634638
return LOB._from_impl(impl)
635639

636640
def cursor(self, scrollable: bool = False) -> Cursor:
@@ -1518,7 +1522,9 @@ async def commit(self) -> None:
15181522
self._verify_connected()
15191523
await self._impl.commit()
15201524

1521-
async def createlob(self, lob_type: DbType) -> LOB:
1525+
async def createlob(
1526+
self, lob_type: DbType, data: Union[str, bytes] = None
1527+
) -> AsyncLOB:
15221528
"""
15231529
Create and return a new temporary LOB of the specified type.
15241530
"""
@@ -1530,6 +1536,8 @@ async def createlob(self, lob_type: DbType) -> LOB:
15301536
)
15311537
raise TypeError(message)
15321538
impl = await self._impl.create_temp_lob_impl(lob_type)
1539+
if data:
1540+
await impl.write(data, 1)
15331541
return AsyncLOB._from_impl(impl)
15341542

15351543
def cursor(self, scrollable: bool = False) -> AsyncCursor:

tests/test_1900_lob_var.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ def __test_pickle(self, lob_type):
211211
if lob_type == "BLOB":
212212
value = value.encode("ascii")
213213
db_type = getattr(oracledb, "DB_TYPE_" + lob_type)
214-
lob = self.conn.createlob(db_type)
215-
lob.write(value)
214+
lob = self.conn.createlob(db_type, value)
216215
pickled_data = pickle.dumps(lob)
217216
unpickled_value = pickle.loads(pickled_data)
218217
self.assertEqual(unpickled_value, value)
@@ -224,8 +223,7 @@ def __test_temporary_lob(self, lob_type):
224223
if lob_type == "BLOB":
225224
value = value.encode("ascii")
226225
db_type = getattr(oracledb, f"DB_TYPE_{lob_type}")
227-
lob = self.conn.createlob(db_type)
228-
lob.write(value)
226+
lob = self.conn.createlob(db_type, value)
229227
self.cursor.execute(
230228
f"""
231229
insert into Test{lob_type}s (IntCol, {lob_type}Col)
@@ -435,8 +433,7 @@ def test_1920_supplemental_characters(self):
435433
"𢵌 𢵧 𢺳 𣲷 𤓓 𤶸 𤷪 𥄫 𦉘 𦟌 𦧲 𦧺 𧨾 𨅝 𨈇 𨋢 𨳊 𨳍 𨳒 𩶘"
436434
)
437435
self.cursor.execute("delete from TestCLOBs")
438-
lob = self.conn.createlob(oracledb.DB_TYPE_CLOB)
439-
lob.write(supplemental_chars)
436+
lob = self.conn.createlob(oracledb.DB_TYPE_CLOB, supplemental_chars)
440437
self.cursor.execute(
441438
"""
442439
insert into TestCLOBs

tests/test_5700_lob_var_async.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,7 @@ async def __test_temporary_lob(self, lob_type):
203203
if lob_type == "BLOB":
204204
value = value.encode("ascii")
205205
db_type = getattr(oracledb, f"DB_TYPE_{lob_type}")
206-
lob = await self.conn.createlob(db_type)
207-
await lob.write(value)
206+
lob = await self.conn.createlob(db_type, value)
208207
await self.cursor.execute(
209208
f"""
210209
insert into Test{lob_type}s (IntCol, {lob_type}Col)
@@ -399,8 +398,9 @@ async def test_5716_supplemental_characters(self):
399398
"𢵌 𢵧 𢺳 𣲷 𤓓 𤶸 𤷪 𥄫 𦉘 𦟌 𦧲 𦧺 𧨾 𨅝 𨈇 𨋢 𨳊 𨳍 𨳒 𩶘"
400399
)
401400
await self.cursor.execute("delete from TestCLOBs")
402-
lob = await self.conn.createlob(oracledb.DB_TYPE_CLOB)
403-
await lob.write(supplemental_chars)
401+
lob = await self.conn.createlob(
402+
oracledb.DB_TYPE_CLOB, supplemental_chars
403+
)
404404
await self.cursor.execute(
405405
"""
406406
insert into TestCLOBs

utils/templates/connection.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ def commit(self) -> None:
617617
self._verify_connected()
618618
self._impl.commit()
619619

620-
def createlob(self, lob_type: DbType) -> LOB:
620+
def createlob(
621+
self, lob_type: DbType, data: Union[str, bytes] = None
622+
) -> LOB:
621623
"""
622624
Create and return a new temporary LOB of the specified type.
623625
"""
@@ -629,6 +631,8 @@ def createlob(self, lob_type: DbType) -> LOB:
629631
)
630632
raise TypeError(message)
631633
impl = self._impl.create_temp_lob_impl(lob_type)
634+
if data:
635+
impl.write(data, 1)
632636
return LOB._from_impl(impl)
633637

634638
def cursor(self, scrollable: bool = False) -> Cursor:
@@ -1325,7 +1329,9 @@ async def commit(self) -> None:
13251329
self._verify_connected()
13261330
await self._impl.commit()
13271331

1328-
async def createlob(self, lob_type: DbType) -> LOB:
1332+
async def createlob(
1333+
self, lob_type: DbType, data: Union[str, bytes] = None
1334+
) -> AsyncLOB:
13291335
"""
13301336
Create and return a new temporary LOB of the specified type.
13311337
"""
@@ -1337,6 +1343,8 @@ async def createlob(self, lob_type: DbType) -> LOB:
13371343
)
13381344
raise TypeError(message)
13391345
impl = await self._impl.create_temp_lob_impl(lob_type)
1346+
if data:
1347+
await impl.write(data, 1)
13401348
return AsyncLOB._from_impl(impl)
13411349

13421350
def cursor(self, scrollable: bool = False) -> AsyncCursor:

0 commit comments

Comments
 (0)