Cristian Accino
Cristian Accino

Reputation: 11

How to check if LOB data is empty using cx_Oracle in Python?

Every time a cx_Oracle cursor attempts to access an empty LOB data record, it gets stuck and freezes the script just like when accessing a non-existing table column.

I need to find a way to check if the LOB data is empty so as to bypass this issue.

cursor = db.cursor()
cursor.execute(SQL_QUERY)
for row in cursor:
    lob_data = row[1].read()

So far, I have tried getting the cursor row length, but it returns the actual length even though the LOB data is empty.

I have also tried using the .fileexists() method of a LOB object, albeit it also freezes the script execution.

Any ideas?

Thanks a lot.

Upvotes: 0

Views: 1060

Answers (1)

Cristian Accino
Cristian Accino

Reputation: 11

I finally found a solution. It turns out that the cursor returns NoneType reference when LOB data is empty. So checking the type to avoid accessing NoneType references did the trick.

for row in cursor:
  if type(row[1]) is cx_Oracle.BLOB:
    lob_data = row[1].read()

Upvotes: 1

Related Questions