スキーマを知らないテーブルのダンプ
Cursor c = db.rawQuery("SELECT * FROM ...", null); Log.d("行数", ""+c.getCount()); Log.d("列数", ""+c.getColumnCount()); if(!c.moveToFirst()) return; for(int col=0; col<c.getColumnCount(); ++col) { Log.d("列番号:" + col, c.getColumnName(col)); } for(int row=0; row<c.getCount(); ++row) { Log.d("行番号", ""+row); for(int col=0; col<c.getColumnCount(); ++col) { switch(c.getType(col)) { case Cursor.FIELD_TYPE_FLOAT: Log.d("列番号:" + col + "(f)", ""+c.getFloat(col)); break; case Cursor.FIELD_TYPE_INTEGER: Log.d("列番号:" + col + "(i)", ""+c.getInt(col)); break; case Cursor.FIELD_TYPE_NULL: Log.d("列番号:" + col, "null"); break; case Cursor.FIELD_TYPE_STRING: Log.d("列番号:" + col + "(s)", ""+c.getString(col)); break; case Cursor.FIELD_TYPE_BLOB: Log.d("列番号:" + col + "(b)", "blob"); break; } } c.moveToNext(); } c.close();
上記を使用して、今自分のアプリで存在する全テーブルスキーマを取得するには、以下のSQLを実行すればよい。
Cursor c = db.rawQuery("SELECT * FROM sqlite_master WHERE type='table' ", null);
ちなみにsqlite_masterテーブルは以下のような定義となっている
CREATE TABLE sqlite_master( type text, name text, tbl_name text, rootpage integer, sql text );