Skip to content

Commit 7c6bd6c

Browse files
Ensure that a proper error messsage is raised for unsigned integers in
addition to signed integers; add appropriate tests.
1 parent 0ac1c65 commit 7c6bd6c

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

src/oracledb/impl/arrow/array.pyx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,15 @@ cdef class ArrowArrayImpl:
266266
"""
267267
Append an unsigned integer to the array.
268268
"""
269-
_check_nanoarrow(ArrowArrayAppendUInt(self.arrow_array, value))
269+
cdef:
270+
str arrow_type
271+
int result
272+
result = ArrowArrayAppendUInt(self.arrow_array, value)
273+
if result == EINVAL:
274+
arrow_type = ArrowTypeString(self.schema_impl.arrow_type).decode()
275+
errors._raise_err(errors.ERR_INVALID_INTEGER, value=value,
276+
arrow_type=arrow_type)
277+
_check_nanoarrow(result)
270278

271279
cdef int append_vector(self, array.array value) except -1:
272280
"""

tests/test_9300_dataframe_requested_schema.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,3 +719,29 @@ def test_9325(db_type_name, dtype, conn):
719719
assert tab.field("STRING_COL").type == dtype
720720
for fetched_value in tab["STRING_COL"]:
721721
assert fetched_value.as_py() == value
722+
723+
724+
@pytest.mark.parametrize(
725+
"dtype,value",
726+
[
727+
(pyarrow.int8(), -129),
728+
(pyarrow.int8(), 128),
729+
(pyarrow.int16(), -32769),
730+
(pyarrow.int16(), 32768),
731+
(pyarrow.int32(), -2147483649),
732+
(pyarrow.int32(), 2147483648),
733+
(pyarrow.uint8(), -1),
734+
(pyarrow.uint8(), 256),
735+
(pyarrow.uint16(), -1),
736+
(pyarrow.uint16(), 65536),
737+
(pyarrow.uint32(), -1),
738+
(pyarrow.uint32(), 4294967296),
739+
],
740+
)
741+
def test_9326(dtype, value, conn, test_env):
742+
"9326 - fetch_df_all() for out of range integer values"
743+
requested_schema = pyarrow.schema([("VALUE", dtype)])
744+
with test_env.assert_raises_full_code("DPY-4038"):
745+
conn.fetch_df_all(
746+
"select :1 from dual", [value], requested_schema=requested_schema
747+
)

tests/test_9400_dataframe_requested_schema_async.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,3 +742,29 @@ async def test_9425(db_type_name, dtype, async_conn):
742742
assert tab.field("STRING_COL").type == dtype
743743
for fetched_value in tab["STRING_COL"]:
744744
assert fetched_value.as_py() == value
745+
746+
747+
@pytest.mark.parametrize(
748+
"dtype,value",
749+
[
750+
(pyarrow.int8(), -129),
751+
(pyarrow.int8(), 128),
752+
(pyarrow.int16(), -32769),
753+
(pyarrow.int16(), 32768),
754+
(pyarrow.int32(), -2147483649),
755+
(pyarrow.int32(), 2147483648),
756+
(pyarrow.uint8(), -1),
757+
(pyarrow.uint8(), 256),
758+
(pyarrow.uint16(), -1),
759+
(pyarrow.uint16(), 65536),
760+
(pyarrow.uint32(), -1),
761+
(pyarrow.uint32(), 4294967296),
762+
],
763+
)
764+
async def test_9426(dtype, value, async_conn, test_env):
765+
"9426 - fetch_df_all() for out of range integer values"
766+
requested_schema = pyarrow.schema([("VALUE", dtype)])
767+
with test_env.assert_raises_full_code("DPY-4038"):
768+
await async_conn.fetch_df_all(
769+
"select :1 from dual", [value], requested_schema=requested_schema
770+
)

0 commit comments

Comments
 (0)