Android - 从android的游标中获取子查询的结果?

时间:2015-08-17 06:26:01

标签: android sqlite android-sqlite android-cursor

我有subquery sqlite

SELECT BookDB.ArticleID,BookDB.Title, subquery.Title FROM BookDB, (SELECT 
MetaDataID,Title  FROM MetaDataDB  order by OrderView) subquery WHERE 
subquery.MetaDataID = BookDB.ArticleID;

这个query让我得到了结果(在编辑sqlite中),但我无法在cursor的android中看到任何结果。

cursor = sql.rawQuery("SELECT BookDB.ArticleID,BookDB.Title, subquery.Title FROM BookDB, (SELECT 
MetaDataID,Title  FROM MetaDataDB  order by OrderView) subquery WHERE 
subquery.MetaDataID = BookDB.ArticleID;", null);
                    if (cursor != null) {
                        do {
                            cursor.moveToFirst();
                            String C = cursor.getString(cursor.getColumnIndex("BookDB.Title"));
                            Log.i("results",C);
                        } while (cursor.moveToNext());
                    }

注意:我如何从这一行获得结果?

String C = cursor.getString(cursor.getColumnIndex("BookDB.Title"));

1 个答案:

答案 0 :(得分:1)

我改变了我的Query并且它有效:

cursor = sql.rawQuery("SELECT BookDB.ArticleID as ID,BookDB.Title as TITLE, subquery.Title as COMM FROM BookDB, (SELECT 
MetaDataID,Title  FROM MetaDataDB  order by OrderView) subquery WHERE 
subquery.MetaDataID = BookDB.ArticleID;", null);
                    if (cursor != null) {
                        do {
                            cursor.moveToFirst();
                            String C = cursor.getString(cursor.getColumnIndex("TITLE"));
                            Log.i("results",C);
                        } while (cursor.moveToNext());
                    }

立即获取结果。