2

This question is related to one of my earlier questions posted here.

I have this code:

dsn = cx_Oracle.makedsn(hostname, port, sid)
orcl = cx_Oracle.connect(username + '/' + password + '@' + dsn)
curs = orcl.cursor()
sql = "select TEMPLATE from my_table where id ='6'"
curs.execute(sql)
rows = curs.fetchall()
print rows
template = rows[0][0]
orcl.close()
template.read()

When I do print rows, I get this:

[(<cx_Oracle.LOB object at 0x0000000001D49990>,)]

However, when I get to template.read(), I get this error:

cx_Oracle.DatabaseError: Invalid handle!

Now when I swap orcl.close() and template.read() like so:

template.read()
orcl.close()

I don't get any error at all.

Additionally, this ONLY happens when the data type is LOB. If the data I'm retrieving is a string or integer or any other non-LOB data, print rows prints all my data and template.read() does not throw an error regardless of it being before or after the orcl.close(). My question is, why does this happen?

Community
  • 1
  • 1
Di Zou
  • 4,469
  • 13
  • 59
  • 88
  • 1
    The docs on LOBs say that Oracle optimizes queries against them by returning only handles to the LOBs, not the LOB data itself. My guess is `cx_Oracale` follows this convention and that the `cx_Oracle.LOB` object is just a proxy to the remote data. Given that, closing the connection to the server will kill the proxy as well. – Silas Ray Sep 26 '12 at 14:13
  • @sr2222 Ah, ok. That makes sense. Do you think you could point me to the docs that say this? – Di Zou Sep 26 '12 at 14:30
  • 1
    Was trying to find something straight from Oracle, but have this http://www.idevelopment.info/data/Oracle/DBA_tips/LOBs/LOBS_1.shtml – Silas Ray Sep 26 '12 at 15:20

0 Answers0