Android Sqlite Database record deleted after updating the apk version -


i have tried implement persistence layer of application after updating apk via google play, database record can maintained. when comes ti implementation, erases data after updating apk version. please tell me way , restore sqlite records?

the below code

 private static final string database_name = "hkgadddlden.sqlite";      private static final int database_version = 6;      private dao<history, integer> hdao = null;     private dao<favourite, integer> fdao = null;     private dao<lm, integer> ldao = null;     private dao<iconplus, integer> idao = null;       public databasehelper(context context)     {         super(context, database_name, null, database_version);     }      @override     public void oncreate(sqlitedatabase database,connectionsource connectionsource)     { //      database.execsql("create table history(t_id integer, topic text, page integer, primary key(t_id));"); //      database.execsql("create table lm(t_id integer, primary key(t_id));"); //      database.execsql("create table favourites(t_id integer, primary key(t_id));");          try         {             tableutils.createtable(connectionsource, history.class);             tableutils.createtable(connectionsource, favourite.class);             tableutils.createtable(connectionsource, lm.class);              tableutils.createtable(connectionsource, iconplus.class);                     }         catch (sqlexception e)         {             log.e(databasehelper.class.getname(), "can't create database", e);             throw new runtimeexception(e);         }         catch (java.sql.sqlexception e)         {             e.printstacktrace();         }     }      @override     public void onupgrade(sqlitedatabase db,connectionsource connectionsource, int oldversion, int newversion)     {         db.execsql("drop table if exists history"); //刪除舊有的資料表         db.execsql("drop table if exists lm");         db.execsql("drop table if exists favourite");         db.execsql("drop table if exists iconplus");                 oncreate(db, connectionsource);          try         {             list<string> allsql = new arraylist<string>();             (string sql : allsql)             {                 db.execsql(sql);             }         }         catch (sqlexception e)         {             log.e(databasehelper.class.getname(), "exception during onupgrade", e);             throw new runtimeexception(e);         }      } 

your onupgrade function dropping tables. means you'll drop data. if want not drop them, have write alter statements each possible upgrade instead.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -