Android Question DBUtils DBversion doesnt return user version set in Sqlite

mcqueccu

Well-Known Member
Licensed User
Longtime User
How to I set and Get correct DBVersion in SQL Browser and my application.

From the sample code below, I get result as 1 meanwhile, in building the database, I set user version as 15. Screenshot below

What am i doing wrong. Also included example project

B4X:
If File.Exists(File.DirInternal,"db.db") = False Then
        File.Copy(File.DirAssets,"db.db",File.DirInternal,"db.db")
        Log("DB Copied")
    End If
   
    sql.Initialize(File.DirInternal,"db.db",True)

    Log(DBUtils.GetDBVersion(sql))


xq4uPAw.png
 

Attachments

  • dbversion.zip
    11.4 KB · Views: 307

eurojam

Well-Known Member
Licensed User
Longtime User
you can use
PRAGMA user_version;
to get the user_version
and
PRAGMA user_version=5;
to set the userversion
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
you can use
PRAGMA user_version;
to get the user_version
and
PRAGMA user_version=5;
to set the userversion

PRAGMA user_version gives 15 as i have set in the Sqlite Database
but I get different result in the app ( 1 ) when I use dbversion from DBUtils Class..

How come there is difference and how can i merge the two?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but I get different result in the app ( 1 ) when I use dbversion from DBUtils Class..
you only copy the DB from your asset to somewhere when the file DOES NOT EXISTS.

So, updating your app you already HAVE a version copied. The old one. But you are not copying a new databasefile.

You need to update your local DB first with the changes needed to make it version 15.....
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
you only copy the DB from your asset to somewhere when the file DOES NOT EXISTS.

So, updating your app you already HAVE a version copied. The old one. But you are not copying a new databasefile.

You need to update your local DB first with the changes needed to make it version 15.....

This happened with a fresh database running for first time. The 15 was set in the new database outside the application.

Can you help me with a sample code on how to update the localDB
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
This happened with a fresh database running for first time
so the one in your assets IS the most up to date database-file?
If yes, then you should get the 15 as result as the database was not existent at the first run.

Or not?

The point is that you DID MADE some changes to the databasestructure (ony your pc probably).
You need to remember all these changes.

Updated table x and adding field y.
removing field z.
whatever.....

In you app you then check the db.

If it is V1 then you need to run the changes on the device database too....

Update table x and adding field y.
removing field z.
whatever.....

You then set the version to V2 after all changes are done.
 
Upvote 0
Top