错误
android.database.sqlite.SQLiteException: near ",": syntax error (code 1): , while compiling: DELETE FROM messages_table WHERE (time,recepient_id,sender_id) IN (("1469945224502","8c79c7d4bf2c11e38867e83935244df8","0a0897ceed5a11e38867e83935244df8"),("1466672473543","8c79c7d4bf2c11e38867e83935244df8","0a0897ceed5a11e38867e83935244df8"))
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:887)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.delete(SQLiteDatabase.java:1496)
at $JUST_MY_CLAS_NAME$6.run(BasicDAO.java:136)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)
可能是什么原因造成的?
它在服务器数据库上执行时没有错误,但在Android上失败。
问题:我需要从数据库中删除大量数据。 我以POJO列表的形式获取数据。所以我需要动态创建查询。这只是证明问题的简单案例。
可能这不是最佳方式,任何建议,尤其是文档都将受到赞赏。
答案 0 :(得分:2)
IN和NOT IN运算符在左侧采用单个标量操作数,在右侧采用向量操作数。
所以你必须写出比较:
DELETE FROM messages_table
WHERE (time = '1469945224502' AND
recepient_id = '8c79c7d4bf2c11e38867e83935244df8' AND
sender_id = '0a0897ceed5a11e38867e83935244df8')
OR
(time = '1466672473543' AND
recepient_id = '8c79c7d4bf2c11e38867e83935244df8' AND
sender_id = '0a0897ceed5a11e38867e83935244df8');