sqlite: dropping a table in a transaction?

浪尽此生 提交于 2020-01-15 11:05:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!