14

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?

1 Answer 1

15

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.

Sign up to request clarification or add additional context in comments.

1 Comment

What if drop table by sqlite3.connect('disk_sqlite3').cursor().execute() works while sqlite3.connect(':memory:').cursor().execute() does not?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.