-1

I am developing an app that using sq-lite database. in my app when user tap on backup my sq-lite db file save on another place. i now write a new version of my app and in new version my sq-lite db has some more fields. how can i check sq-lite database file and get user-version of that file to open it with true fields avoiding force-close? in new version off my app the db version is 2:

private final static String DB_NAME="cDb";
private final static String DB_TABLE="_table";
private final static int DB_VERSION=2;

But in old version my db version is 1. How can i check if my db file is for version 1 or 2?

Furqan Safdar
  • 16,260
  • 13
  • 59
  • 93
aTa
  • 641
  • 2
  • 8
  • 20

3 Answers3

2

Use getVersion to get database version , but anyway just to let you know as soon as you open your database if its an old one onUpgrade should be triggered.

idanakav
  • 1,466
  • 1
  • 13
  • 23
  • how can i get my db file version in onUpgrade? when i use getVersion() it returns the new version to me that i defined before on my SQLiteOpenHelper constractor: – aTa Oct 08 '12 at 09:24
  • take a look at onUpgrade parameters , you have oldVersion and newVersion – idanakav Oct 08 '12 at 09:26
2

Use PRAGMA user_version sql to get database version

Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
yepeng820
  • 21
  • 1
  • @aTa , you must be connected to the device using adb, this link has it all http://stackoverflow.com/questions/18370219/how-to-use-adb-in-android-studio-to-view-an-sqlite-db – john-salib Jun 02 '16 at 07:54
0

In phonegap sqlite (cordova-sqlite-storage plugin), you can get user_version as :

db.executeSql('PRAGMA user_version', [], migrate, function(){console.log('unable to fetch user_version');});

function migrate(db, resultSet {console.log(resultSet.rows.item(0).user_version);}
Fawaz
  • 3,404
  • 3
  • 17
  • 22