could anyone help with how to update blob data in oracle
so, i'm trying like:
file = open ('picture.jpg','rb')
ext = 'jpg'
content = file.read ()
file.close ()
db = cx_Oracle.connect('user', 'pwd', dsn_tns)
db=db.cursor()
sqlStr = "update table_name set column1=:blobData, column2=" + str(ext) + " where id = 1"
db.setinputsizes (blobData = cx_Oracle.BLOB)
db.execute (sqlStr, {'blobData': content})
db.execute ('commit')
db.close()
finally, I got such error:
cx_Oracle.DatabaseError: ORA-00904: "JPG": invalid identifier
file = open ('picture.jpg','rb')
ext = 'jpg'
content = file.read ()
file.close ()
db = cx_Oracle.connect('user', 'pwd', dsn_tns)
db=db.cursor()
blobvar = db.var(cx_Oracle.BLOB)
blobvar.setvalue(0,content)
sqlStr = "update table_name set column1=:blobData, column2="jpg" where id = 1"
db.setinputsizes (blobData = cx_Oracle.BLOB)
db.execute (sqlStr, {'blobData': blobvar})
db.execute ('commit')
db.close()
cx_Oracle 6.0 does not allow you to close a connection whilst a BLOB is open leading to a DPI-1054 error.
cx_Oracle.DatabaseError: DPI-1054: connection cannot be closed when open statements or LOBs exist
Adding to Leo's answer, this can be resolved by deleting the BLOB variable.
file = open ('picture.jpg','rb')
ext = 'jpg'
content = file.read ()
file.close ()
con = cx_Oracle.connect('user', 'pwd', dsn_tns)
db = con.cursor()
blobvar = db.var(cx_Oracle.BLOB)
blobvar.setvalue(0,content)
sqlStr = "update table_name set column1=:blobData, column2="jpg" where id = 1"
db.setinputsizes (blobData = cx_Oracle.BLOB)
db.execute (sqlStr, {'blobData': blobvar})
del blobvar # <--------
db.execute ('commit')
db.close()
con.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With