Android SQLite - 更改journal_mode
我正在尝试通过代码更改数据库的journal_mode。我尝试了 SQLiteDatabase.execSQL("PRAGMAjournal_mode=OFF") 但它失败了,因为表达式"PRAGMAjournal_mode=OFF"返回一个结果(我从终端验证了这一点),所以 Android 认为这是一个查询并抱怨我应该使用 execQuery 代替。但我试图执行的不是查询。
我还尝试将 pragma 表达式编译为 SQLiteStatement 并调用执行方法,但结果相同。
有人可以建议任何替代方案来通过代码实现这项工作吗?
谢谢, 兰吉特
I am trying to alter the journal_mode for my database, through code. I tried SQLiteDatabase.execSQL("PRAGMA journal_mode=OFF") but it fails because, the expression "PRAGMA journal_mode=OFF" returns a result (I verified this from the terminal), and so Android thinks this is a query and complains that I should be using execQuery instead. But what I am trying to execute isn't a query.
I also tried compiling the pragma expression to a SQLiteStatement and invoked the execute method, but same result.
Can someone suggest any alternatives to make this work through code?
Thanks,
Ranjit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许您正遭受这个问题 execSQL 文档谈论:
检查您是否没有使用预写日志记录,然后它可能会起作用。
更新:正如 Ranjit 在评论中所说,这应该有效:
Perhaps you are suffering from this problem that the execSQL docs talk about:
Check that you are not using write ahead logging and then it might work.
Update: As Ranjit said in the comments, this should work:
可以使用下一个命令来完成:(
无需创建
Cursor
,因为 罗伯特的回答)It can be done with the next command:
(No need to create a
Cursor
as it is suggested in one of the comments to Robert's answer)