Skip to content

Fix JSON Binding Logic for Thin and Thick Modes in python-oracledb #509

Open
@xkazuma

Description

@xkazuma

Isn't the following code the opposite of what is in the if and else blocks?

if connection.thin or client_version >= 21:
# Take advantage of direct binding
cursor.setinputsizes(None, oracledb.DB_TYPE_JSON)
cursor.execute(inssql, [1, data])
else:
# Insert the data as a JSON string
cursor.execute(inssql, [1, json.dumps(data)])

So, I think the below code is preferred:

 if connection.thin or client_version >= 21: 
     # Thin mode
     cursor.execute(inssql, [1, json.dumps(data)]) 
 else: 
     # Thick mode
     cursor.setinputsizes(None, oracledb.DB_TYPE_JSON) 
     cursor.execute(inssql, [1, data]) 

In my environment, softwares' version are:

  • Oracle Database Server: Oracle Database 23ai,
  • Database Client: instantclient-basic-linux.x64-23.4.0.24.05.zip ,
  • Python: Python 3.12.4, python-oracledb==2.2.1.

If I use direct binding in Thin mode, clients can't display rows including a JSON column, or the column's value shows "java.lang.UnsupportedOperationException".

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions