使用 Android SQL,我尝试从空的 SQL 表中获取列的列表。
这是我迄今为止尝试过的:
SQLiteDatabase db = getReadableDatabase();
ArrayList<String> output = new ArrayList<String>();
Cursor ti = db.rawQuery("PRAGMA table_info("+myTable+")", null);
if ( ti.moveToFirst() ) {
do {
output.add(ti.getString(1));
} while (ti.moveToNext());
}
ti.close();
db.close();
return output;
结果列表只出现单词 INTEGER,而数据库有很多列。我怎样才能做到这一点?
最佳答案
这是我用来检索字符串中的列名称:
SQLiteDatabase mDataBase;
(some code here...)
mDataBase = getReadableDatabase();
Cursor dbCursor = mDataBase.query(TABLE_NAME, null, null, null, null, null, null);
String[] columnNames = dbCursor.getColumnNames();
或者这个:
Cursor c = db.rawQuery("SELECT * FROM table WHERE 0", null);
try {
String[] columnNames = c.columnNames();
} finally {
c.close();
}
关于java - Android SQLite 从空表中获取列列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37686947/