Android Question Download and update sqlite db

Hamied Abou Hulaikah

Well-Known Member
Licensed User
There are a lot of approach here in B4X to do it.
To exactly fit your app needs you should specify what db update type you mean: insert records, update/delete records, change schema or mix of them? also your db size matter.
You have a lot of choice in b4x such as okhttp, mqtt, etc .....
 
Upvote 0

DeclanOK

Member
Licensed User
Size of db is less than 5 MB
I think it would update about 100 each time some new and some update but in reality easiest to replace one db file with the other
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
I think it would update about 100 each time some new and some update but in reality easiest to replace one db file with the other
Here Dr. Declan:
In this case use okhttp library as the following:
1- Check OkHttpUtils2 library
2- Use this example to download your x.db file.
3- replace your old.db with your new.db using file functions.
 
Upvote 0

DeclanOK

Member
Licensed User
I am so grateful. Thank you for your kindness. The app is very popular and this saves me time in having to do updates.
 
Upvote 0

Hamied Abou Hulaikah

Well-Known Member
Licensed User
I'm happy to assist you Dr. Declan, I downloaded your app , it is amazing & has a lot of medical info suitable for almost of doctors in any level of medical study or practice.
By the way I'm MBBS in medicine, I'm glade to assist you in your app if you need adjustment, improvement or any thing. I can help.

Thank you
 
Upvote 0

behnam_tr

Active Member
Licensed User
I'm using this way in our app

1-if new field or new table is added to db :
you can add that with code to old database.you must put codes in new Update apk.
example :

B4X:
Try
        ' Add new columns to the database if they don't already exist
        Main.Sql1.ExecNonQuery("ALTER TABLE [tablename] ADD [fieldname] integer default 1")
       
    Catch
        Log(LastException)
    End Try

B4X:
  'creat New table in old db
    Try
        Main.Sql1.ExecNonQuery("CREATE TABLE Tablename (id integer NOT NULL PRIMARY KEY AUTOINCREMENT,name text)")
   
    Catch
        Log(LastException)
    End Try

2-if new data added to you database
you can download data from server with okhttputils and insert to olddatabase.
===================================
also you can download new db and replace with old db
 
Last edited:
Upvote 0
Top