The application uses a ready SQLite database. There was an empty column in the table from the database, but now I have added the string value "0" to all entries in this column. On the phone I tried to work with the application, I threw it out, apparently because after reinstalling the application, the changes did not automatically occur in the database. Tell me how I can make it so that other users who download the application do not have errors and the database is updated? DB version need to be changed? How to update this column from other users?
- Will it be correct if you change the database version and in the onUpgrade () method it is stupid to update the required column via update? or how to do? - Sergey
- From general considerations, it is necessary to check wherever a problem may arise. And this means that at least at the start of the application - request this field for random writing, and if you get a Null, then execute the UPDATE table SET field = '0' WHERE field IS NULL; This will help both for non-converted DB, and in case of failures / errors. - Akina
- oneI try to do so. changed the database version to 2 and write this: public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion) {if (oldVersion == 1 && newVersion == 2) {String s = "0"; database.beginTransaction (); try {database.execSQL ("update tbl set favorites =" + "\" "+ s +" \ ""); database.setTransactionSuccessful (); } finally {database.endTransaction (); }}} The column does not update. What was my mistake? - Sergey
- And what for this hemorrhoids with variable s? And why are double quotes placed in the query string? why not just database.execSQL ("update tbl set favorites = '0'"); ? - Akina
- The first time I try to update the database .. can be your way. But after that the column was not updated. Generally, am I trying to update this column in the table correctly? - Sergey
|