问题
I have a simple, single table sqlite3 database file that has exactly one table. There are no keys, foreign or domestic. There are no triggers. I have the following workflow:
If the database file exixts open it.
- Start exclusive transaction
- Select all rows from the table in order.
- Operate on each row.
- Delete each operated-on row.
- When done, count the number of remaining rows in the table, if 0 then DROP the table then unlink the database file
- Commit or Rollback the transaction
The drop-table always fails with the message that the table is locked. I've seen a couple of other posts that suggest that there could be open statement handles or other cruft lying around. Since I am using "sqlite_exec()"s for all of this I do not have any open DB anything except the DB handle itself.
Is drop table not allowed in transactions?
回答1:
When dropping a table, you get the "table is locked" message when there is still some active cursor on the table, i.e., when you did not finalize a statement (or did not close a query object in whatever language you're using).
来源:https://stackoverflow.com/questions/17733419/sqlite-dropping-a-table-in-a-transaction