'Python Oracle_cx How to check what is being inserted
sql_insert=""" Insert into DIRECTOR (name,secondName) values (:1,:2) """
name='Tom'
second_name='Musk'
data=[name,second_name]
try:
cur.execute(sql_insert,data)
except Exception as err:
print('Error DIRECTOR',err)
else:
conn.commit()
I want to print what is inserted into my database. Like in this case I want to see:
Insert into DIRECTOR (name,secondName) values ('Tom','Musk')
I tried to print it like this print(cur.fetchall()) and any different methods but no one is working.
Solution 1:[1]
To get the data, look at cx_Oracle examples and documentation.
You need to execute a SELECT statement. You can use various methods including:
cur = conn.cursor()
for row in cur.execute("select * from DIRECTOR"):
print(row)
To do tracing of statements you can do your own printing before execution. Or read the cx_Oracle documentation on Tracing SQL and PL/SQL Statements which shows how to subclass the execute() call so it always prints what is being executed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
