1

Topic: Saving given in SQLite at application update in PlayMarket

Hello, respected! smile
My application uses standard basis SQLite from many examples on programming on Android
Actually there is a class DbHelper
[spoiler DbHelper]

import android.content. Context;
import android.database.sqlite. SQLiteDatabase;
import android.database.sqlite. SQLiteOpenHelper;
import android.util.Log;
public class DbHelper extends SQLiteOpenHelper {
//database File name
private static final String DATABASE_NAME = "spline.db";
//the database Version.
private static final int DATABASE_VERSION = 20;
//the Designer
public DbHelper (Context context) {
super (context, DATABASE_NAME, null, DATABASE_VERSION);
}
//It is caused at database creation
@Override
public void onCreate (SQLiteDatabase db) {
String sSQL;
//the Table of the list of the new data
sSQL = "CREATE TABLE tblNewDataInfo ("
+ " )";
db.execSQL (sSQL);
//the Table of the loaded data
sSQL = "CREATE TABLE tblNewData ("
+ " )";
db.execSQL (sSQL);
}
//It is caused at database scheme update
@Override
public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion) {
//we Write down in log
Log.w ("SQLite", "We are updated from the version" + oldVersion + "on the version" + newVersion);
//It is deleted the old table and we create the new
db.execSQL ("DROP TABLE IF EXISTS tblNewDataInfo");
db.execSQL ("DROP TABLE IF EXISTS tblNewData");
//we Create the new table
onCreate (db);
}
}

[/spoiler] Well and reversal to basis happens as that so:

DbHelper mDbHelper = new DbHelper (this);
SQLiteDatabase SplineDB = mDbHelper.getReadableDatabase ();
String query = "SELECT * FROM tblNewDataInfo";
Cursor cursor = SplineDB.rawQuery (query, null);

And so, if application to update, the data entered by the user of application - disappears... This normal behavior if the application version exchanged, but the basis version remained former?

//the database Version.
private static final int DATABASE_VERSION = 20;

2

Re: Saving given in SQLite at application update in PlayMarket

Whether it will be caused onUpgrade if DATABASE_VERSION as remains = 20? smile

3

Re: Saving given in SQLite at application update in PlayMarket

AndroidNeedHelp wrote:

Log.w ("SQLite", "We are updated from the version" + oldVersion + "on the version" + newVersion);

In a broad gull there is something?

AndroidNeedHelp wrote:

from many examples on programming on Android

In examples too at once with 20th version begin?

4

Re: Saving given in SQLite at application update in PlayMarket

And a question on a charge: in examples too at update of basis there is no check with what on what version??? smile))

5

Re: Saving given in SQLite at application update in PlayMarket

wadman ;
Unfortunately, I do not know as to look a broad gull already on operating application without AndroidStudio
And on phone which is connected to studio for  it is impossible to install application from a plej-market. Speaks, it already is, even if it before it to delete

wadman wrote:

And a question on a charge: in examples too at update of basis there is no check with what on what version???

There such check was not, and consequently I thought that onUpgrade is caused only if changes DATABASE_VERSION

6

Re: Saving given in SQLite at application update in PlayMarket

AndroidNeedHelp wrote:

There such check was not

In that case it is very strange source. Because the user can pass some versions of application and deliver at once though through 10 versions. And in onUpgrade should understand it. For this purpose also current and necessary versions of basis are transferred.
That is though with 1st on 5th, though about 2nd... Approximately thus:
[spoiler]

@Override
public void onUpgrade (SQLiteDatabase db, int oldVersion, int newVersion) {
ContentValues cv = new ContentValues ();
if (newVersion == 2) {
cv.put ("allow",-1);
db.update (rule_table, cv, "allow = 0", null);
}
cv.clear ();
if (newVersion == 3) {
db.execSQL ("alter table" +message_table + "add column sended integer");
db.execSQL ("update" +message_table + "set sended = eventstamp");
}
}

[/spoiler]

7

Re: Saving given in SQLite at application update in PlayMarket

wadman ;
Thanks big!
Made check of versions, laid out in PlayMarket, it was updated - the data remained!
Hurrah! smile