我的Active
Android数据库中有大约20-30个表.当我按logoutButton时,我想清除所有表格.我怎么能在ActiveAndroid中做到这一点?
public void logout() { //clear all tables }
解决方法
sqliteDatabase db = ActiveAndroid.getDatabase(); List<String> tables = new ArrayList<>(); Cursor cursor = db.rawQuery("SELECT * FROM sqlite_master WHERE type='table';",null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { String tableName = cursor.getString(1); if (!tableName.equals("android_Metadata") && !tableName.equals("sqlite_sequence")) { tables.add(tableName); } cursor.moveToNext(); } cursor.close(); for (String tableName : tables) { db.execsql("DELETE FROM " + tableName); }