我使用Cursor
检索数据库中特定值的表名。问题是我不知道如何使用它。
通常,我会这样做:
Cursor c = myDbHelper.getSelectedData(value);
int id = c.getColumnIndex("ENGLISH_NAME");
但是,此代码会遍历列调用“ENGLISH_NAME”的记录
如何使用它来检索表的名称?
以下是Cursor
public Cursor selectTablesFromSearch(String value){
String selectQuery = " SELECT TableName" +
" , ENGLISH_NAME " +
" FROM (" +
" SELECT \'BABY_FOODS\' AS TableName" +
" , ENGLISH_NAME " +
" FROM BABY_FOODS " +
" UNION ALL " +
" SELECT \'BAKED_PRODUCTS_AND_CORN_TORTILLAS\'" +
" , ENGLISH_NAME " +
" FROM BAKED_PRODUCTS_AND_CORN_TORTILLAS" +
" UNION ALL " +
" SELECT \'BEEF_PRODUCTS\'" +
" , ENGLISH_NAME " +
" FROM BEEF_PRODUCTS" +
" ) AS SubQueryAlias " +
" WHERE ENGLISH_NAME IN (\'" + value + "\')";
return myDataBase.rawQuery(selectQuery, null);
}
答案 0 :(得分:2)
试试这个
if (c.moveFirst()) {
do {
String value = c.getString(0);
} while (c.moveNext());
}