Question

I have question about python and sqlite3. I want to drop a table from within Python. The command

cur.execute('drop table if exists tab1')

Does not work.

cur.executescript('drop table if exists tab1;')

does the job.

The execute method allows the creation of tables. However, it won't drop them? Is there a reason for this?

Was it helpful?

Solution

The cur.executescript command issues a COMMIT before running the provided script. Additionally a CREATE executes a COMMIT intrinsically. Perhaps you have an open transaction that needs committed before your changes take place.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top