0

我在一个 android 应用程序中工作,我想在我的应用程序本地数据库中获取详细信息。我正在使用的查询具有内连接,因此它不返回值。但是,如果我使用没有内连接的查询,则以相同的方法返回值。请帮我

public boolean isAvailableTransitionFile(String MenuName) {

    String query = "select * from Transition_File_Table inner join item_sync on Transition_File_Table.Menuitem_id=item_sync.id where item_sync.itemName=?";
    Cursor cursor = this.db.rawQuery(query,
            new String[] { String.valueOf(MenuName) });
    Log.e("Count", cursor.getCount() + "");
    if (cursor.moveToFirst()) {
        return true;
    } else {
        return false;
    }
}
4

4 回答 4

1

将您的选择查询更改为:

String query = "SELECT * FROM Transition_File_Table 
a INNER JOIN Transition_File_Table b 
ON a.Menuitem_id=b.id WHERE b.itemName=?";
于 2012-07-05T11:54:57.383 回答
0

我建议你,不要使用rawQuery。你会找到有用的替代方法来完成你的工作。检查android的记事本示例以获得一个好主意。

于 2012-07-05T11:53:38.837 回答
0

看着查询

select *
from Transition_File_Table 
inner join item_sync 
    on Transition_File_Table.Menuitem_id=item_sync.id 
where item_sync.itemName=?

这会将 Transition_File_Table 的行连接到 item_sync 的行,其中 Transition_File_Table 的 Menuitem_id 列与 item_sync 表中的 id 列匹配。

如果连接没有返回结果,这意味着可以连接 n 行,这意味着没有 item_sync id 的值与 Transition_File_Table 的 Menuitem_id 列中的值匹配。

于 2012-07-05T11:54:07.567 回答
0

SQL 问题通常是由于 SQL 中的语法使用错误造成的,请务必在程序中使用它们之前对其进行测试。我在这里找到了一个类似的帖子:

如何在我的 Android 应用程序中加入两个 SQLite 表?

你应该试试这段代码:

String query = "select * from Transition_File_Table TF inner join item_sync IS on
TF.Menuitem_id=IS.id where IS.itemName=?";

Cursor cursor = this.db.rawQuery(query,new String[]{String.valueOf(MenuName)});
于 2012-07-05T11:59:50.153 回答