如何清除ActiveAndroid中的所有表?

如何清除ActiveAndroid中的所有表?,第1张

概述我的Active Android数据库中有大约20-30个表.当我按logoutButton时,我想清除所有表格.我怎么能在ActiveAndroid中做到这一点? public void logOut() { //clear all tables } SQLiteDatabase db = ActiveAndroid.getDatabase(); List<Strin 我的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);        }
总结

以上是内存溢出为你收集整理的如何清除ActiveAndroid中的所有表?全部内容,希望文章能够帮你解决如何清除ActiveAndroid中的所有表?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1134869.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存