def blob(bid, bname, path): db = cx_Oracle.connect(config['USER'] + '/' + config['PASSWORD']) cur = db.cursor() f1 = open(path, 'rb') data = f1.read() bphoto = cx_Oracle.Binary(data) sql = "INSERT INTO coder.book VALUES ('%s','%s',:blobData)" % (bid, bname) cur.setinputsizes(blobData=cx_Oracle.BLOB) try: cur.execute(sql, {'blobData': bphoto}) db.commit() print('update success') # print('update success') except: # print('update loss') db.rollback() cur.close() db.close()
connection = pool.acquire() cursor = connection.cursor() cursor.execute(""" delete from TestTempTable where IntCol = 1""") cursor.execute(""" insert into TestTempTable values (1, null)""") input("Please kill %s session now. Press ENTER when complete." % \ SampleEnv.MAIN_USER) try: connection.commit() # this should fail sys.exit("Session was not killed. Terminating.") except cx_Oracle.DatabaseError as e: errorObj, = e.args if not errorObj.isrecoverable: sys.exit("Session is not recoverable. Terminating.") ltxid = connection.ltxid if not ltxid: sys.exit("Logical transaction not available. Terminating.") pool.drop(connection) # check if previous transaction completed connection = pool.acquire() cursor = connection.cursor() _, committed, completed = cursor.callproc( "dbms_app_cont.get_ltxid_outcome", (cx_Oracle.Binary(ltxid), cursor.var(bool), cursor.var(bool))) print("Failed transaction was committed:", committed) print("Failed call was completed:", completed)
connection = pool.acquire() cursor = connection.cursor() cursor.execute(""" delete from TestTempTable where IntCol = 1""") cursor.execute(""" insert into TestTempTable values (1, null)""") input("Please kill %s session now. Press ENTER when complete." % \ sample_env.get_main_user()) try: connection.commit() # this should fail sys.exit("Session was not killed. Terminating.") except oracledb.DatabaseError as e: error_obj, = e.args if not error_obj.isrecoverable: sys.exit("Session is not recoverable. Terminating.") ltxid = connection.ltxid if not ltxid: sys.exit("Logical transaction not available. Terminating.") pool.drop(connection) # check if previous transaction completed connection = pool.acquire() cursor = connection.cursor() args = (oracledb.Binary(ltxid), cursor.var(bool), cursor.var(bool)) _, committed, completed = cursor.callproc("dbms_app_cont.get_ltxid_outcome", args) print("Failed transaction was committed:", committed) print("Failed call was completed:", completed)