0

我需要从表中选择一些列,其中某个列(在我的情况下为 pos_report_id)为空,而不是 null。我在 SQLiteDatabaseBrowser 中尝试了这段代码(对于 user_id='23'),它工作正常:

"SELECT information_action.target_type, information_action.message_type,"
                + "information_action.start_date, information_action.end_date, information_action.content, information_action.status "
                + "FROM information_action INNER JOIN information_to_user ON "
                + "information_to_user.information_action_id = information_action.id_information_action "
                + "WHERE information_action.pos_report_id ='' AND information_to_user.user_id ='"
                + user_id + "'";

但在代码中,当我运行应用程序时出现此错误:

ERROR   AndroidRuntime  Caused by: android.database.sqlite.SQLiteException: near "": syntax error: , while compiling: SELECT information_action.target_type, information_action.message_type,information_action.start_date, information_action.end_date, information_action.content, information_action.status FROM information_action INNER JOIN information_to_user ON information_to_user.information_action_id = information_action.id_information_action WHERE information_action.pos_report_id ='' AND information_to_user.user_id ='23'

知道如何解决这个问题吗?为什么''不行?

4

2 回答 2

0

在您的查询中,您同时使用了WHEREandON子句。试试这个只是小的改变,而不是在哪里使用 AND:

"SELECT information_action.target_type, information_action.message_type,"
                + "information_action.start_date, information_action.end_date, information_action.content, information_action.status "
                + "FROM information_action INNER JOIN information_to_user ON "
                + "information_to_user.information_action_id = information_action.id_information_action "
                + "AND information_action.pos_report_id ='' AND information_to_user.user_id ='"
                + user_id + "'";
于 2012-10-08T09:10:55.270 回答
0

user_id 是数据库中的 char 字段吗?似乎是一个整数。如果这项权利从 23 中删除 ''。

于 2012-10-08T08:59:25.330 回答