Skip to content

Commit 3b6232c

Browse files
Throw error DPY-2037: no object type specified for object variable when
attempting to create a variable of type DB_TYPE_OBJECT without specifying a type name.
1 parent 93c3786 commit 3b6232c

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/oracledb/cursor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from . import connection as connection_module
3737
from .defaults import defaults
3838
from .var import Var
39-
from .base_impl import DbType
39+
from .base_impl import DbType, DB_TYPE_OBJECT
4040
from .dbobject import DbObjectType
4141

4242
class Cursor:
@@ -793,6 +793,8 @@ def var(self,
793793
self._verify_open()
794794
if typename is not None:
795795
typ = self.connection.gettype(typename)
796+
elif typ is DB_TYPE_OBJECT:
797+
errors._raise_err(errors.ERR_MISSING_TYPE_NAME_FOR_OBJECT_VAR)
796798
if encodingErrors is not None:
797799
if encoding_errors is not None:
798800
errors._raise_err(errors.ERR_DUPLICATED_PARAMETER,

src/oracledb/errors.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def _raise_from_string(exc_type: Exception, message: str) -> None:
168168
ERR_ACCESS_TOKEN_REQUIRES_TCPS = 2034
169169
ERR_INVALID_OBJECT_TYPE_NAME = 2035
170170
ERR_OBJECT_IS_NOT_A_COLLECTION = 2036
171+
ERR_MISSING_TYPE_NAME_FOR_OBJECT_VAR = 2037
171172

172173
# error numbers that result in NotSupportedError
173174
ERR_TIME_NOT_SUPPORTED = 3000
@@ -390,6 +391,8 @@ def _raise_from_string(exc_type: Exception, message: str) -> None:
390391
ERR_MISSING_BIND_VALUE:
391392
'a bind variable replacement value for placeholder ":{name}" was '
392393
'not provided',
394+
ERR_MISSING_TYPE_NAME_FOR_OBJECT_VAR:
395+
'no object type specified for object variable',
393396
ERR_MIXED_ELEMENT_TYPES:
394397
'element {element} is not the same data type as previous elements',
395398
ERR_MIXED_POSITIONAL_AND_NAMED_BINDS:

tests/test_2300_object_var.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,5 +487,10 @@ def test_2317_plsql_type_metadata(self):
487487
self.assertEqual(typ.package_name, "PKG_TESTSTRINGARRAYS")
488488
self.assertEqual(typ.element_type, oracledb.DB_TYPE_VARCHAR)
489489

490+
def test_2318_negative_create_object_var_no_type_name(self):
491+
"2318 - test creating an object variable without a type name"
492+
self.assertRaisesRegex(oracledb.DatabaseError, "^DPY-2037:",
493+
self.cursor.var, oracledb.DB_TYPE_OBJECT)
494+
490495
if __name__ == "__main__":
491496
test_env.run_test_cases()

0 commit comments

Comments
 (0)