Android - 从 android 的游标中的子查询获取结果?
Android - Get results from subquery in cursor of android?
我有一个 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
中)但是我在 android 的 cursor
中看不到任何结果。
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"));
我更改了我的 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());
}
立即获取结果。
我有一个 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
中)但是我在 android 的 cursor
中看不到任何结果。
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"));
我更改了我的 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());
}
立即获取结果。