sqlite - Manually executing sql query in Android -
i have database in app using 3rd party library. library doesn't seem have drop table functionality. thinking directly change using sqliteopenhelper api. possible?
i have created class extends sqliteopenhelper , give same db name 1 used in library.
public class sqlitedatabasehelper extends sqliteopenhelper { // database info private static final string database_name = "mydatabase"; private static final int database_version = 1; private context context; public sqlitedatabasehelper(context context) { super(context, database_name, null, database_version); this.context = context; } @override public void oncreate(sqlitedatabase db) { } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { l.w("old: " + oldversion + ", " + "new: " + newversion); if (oldversion != newversion) { db.execsql("drop table if exists " + "deals_latest"); oncreate(db); l.w("drop it's hot"); } } }
and initialize in application class, see if reflects db class created.
sqlitedatabase db = new sqlitedatabasehelper(this).getreadabledatabase(); l.w("version: " + db.getversion()); l.w("path: " + db.getpath()); sqlitedatabasehelper helper = new sqlitedatabasehelper(this); helper.onupgrade(db, 1, 2); // line suppose invoke drop table query
when running app, onupgrade()
method doesn't seem called.
mind you, have never had experience in using native sqlite helper, have no idea going on here. objective see if query in onupgrade executed or not. table still exists in database.
how around this?
the sqliteopenhelper
class helps manage versions of own database.
it not make sense use database managed third-party code.
just open database directly opendatabase()
.
Comments
Post a Comment