Skip to content

Commit dcf67f2

Browse files
The error "DPY-2047: LOB amount must be greater than zero" is now raised
when the amount parameter to LOB.read() is zero or negative.
1 parent 5732c5b commit dcf67f2

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Common Changes
9797
parameters if they were not included in the parameters. This also affected
9898
calls to :meth:`oracledb.connect()` and :meth:`oracledb.create_pool()` that
9999
made use of the DSN with credentials format.
100+
#) The error ``DPY-2047: LOB amount must be greater than zero`` is now raised
101+
when the amount parameter to :meth:`LOB.read()` is zero or negative.
100102
#) Fixed bug in the calculation of :data:`Cursor.rowcount` under some
101103
circumstances.
102104
#) Connection parameters that are strings now treat an empty string in the

src/oracledb/errors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def _raise_err(
240240
ERR_DBOBJECT_ELEMENT_MAX_SIZE_VIOLATED = 2044
241241
ERR_INVALID_ARRAYSIZE = 2045
242242
ERR_CURSOR_HAS_BEEN_CLOSED = 2046
243+
ERR_INVALID_LOB_AMOUNT = 2047
243244

244245
# error numbers that result in NotSupportedError
245246
ERR_TIME_NOT_SUPPORTED = 3000
@@ -520,6 +521,7 @@ def _raise_err(
520521
"given index {index} must be in the range of {min_index} to "
521522
"{max_index}"
522523
),
524+
ERR_INVALID_LOB_AMOUNT: "LOB amount must be greater than zero",
523525
ERR_INVALID_LOB_OFFSET: "LOB offset must be greater than zero",
524526
ERR_INVALID_MAKEDSN_ARG: '"{name}" argument contains invalid values',
525527
ERR_INVALID_NUMBER: "invalid number",

src/oracledb/lob.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ def read(self, offset: int = 1, amount: int = None) -> Union[str, bytes]:
145145
amount = amount - offset + 1
146146
else:
147147
amount = 1
148+
elif amount <= 0:
149+
errors._raise_err(errors.ERR_INVALID_LOB_AMOUNT)
148150
if offset <= 0:
149151
errors._raise_err(errors.ERR_INVALID_LOB_OFFSET)
150152
return self._impl.read(offset, amount)

tests/test_1900_lob_var.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ def __test_lob_operations(self, lob_type):
181181
lob.read(0)
182182
with self.assertRaisesFullCode("DPY-2030"):
183183
lob.read(-25)
184+
with self.assertRaisesFullCode("DPY-2047"):
185+
lob.read(amount=0)
186+
with self.assertRaisesFullCode("DPY-2047"):
187+
lob.read(amount=-5)
184188
self.assertEqual(lob.read(), long_string + write_value)
185189
lob.write(write_value, 1)
186190
self.assertEqual(

0 commit comments

Comments
 (0)