The android 2.3 and Xiaomi System of your own machine have been successfully executed once, and the versions passed before and after are correct. If it is not executed, it is indeed the getWritableDatabase () called (), no exception was found after reading the Android source code.
Think twice! I switched to a testing machine of the company.
Therefore, it is determined that this onUpgrade is unreliable and you have written a set of logic for upgrading the sqlite database.
Create an update. SQL file under assets, read the file, and execute SQL statements in one row. If the upgrade succeeds, write a mark in the database.
Note: In update. SQL, a complete operation includes a sentence that needs to be merged into a row.
Code ):
Private void updateDB () {SqliteHelper sqliteHelper = SqliteHelper. getInstance (this); if (! ("" + Config. SQLITE_DB_VERSION ). equals (sqliteHelper. getValue (Configuration. DB_VERSION) {LogUtil. I (TAG, "===== Database Upgrade start ===="); // sqliteHelper. beginTransaction (); try {InputStream in = this. getAssets (). open ("update. SQL "); BufferedReader bufferedReader = new BufferedReader (new InputStreamReader (in); String tmpStr = null; StringBuffer SQL = new StringBuffer (); while (tmpStr = bufferedReader. read Line ())! = Null) {SQL. append (tmpStr); SQL. append ("\ n"); if (tmpStr. trim (). endsWith (";") {sqliteHelper.exe cSQL (SQL. toString (); SQL = new StringBuffer () ;}} bufferedReader. close (); in. close (); // sqliteHelper. setTransactionSuccessful (); sqliteHelper. setValue (Configuration. DB_VERSION, "" + Config. SQLITE_DB_VERSION); LogUtil. I (TAG, "===== Database Upgrade successful! ==== ");} Catch (Exception e) {LogUtil. e (TAG, e. getMessage ();} finally {// sqliteHelper. endTransaction ();}}}