Android Question SQL Database Update Issue

brianwiz12

Active Member
Licensed User
Longtime User
Hello,

So i add a table to my database. I delete the copy from file folders. Put the new copy same name in it.

Then i run my program and it does not recorgnize the new table that was created

B4X:
Kind of night
ham
tuna
steak
1

** Activity (abbyfull) Pause, UserClosed = true **
** Activity (trivia) Create, isFirst = false **
** Activity (trivia) Resume **
** Activity (trivia) Pause, UserClosed = true **
** Activity (bents1) Create, isFirst = true **
** Activity (bents1) Resume **
bents1_episode1_click (java line: 1362)
android.database.sqlite.SQLiteException: no such table: Bent (code 1): , while compiling: SELECT * FROM Bent Where Episode='1'
    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
    at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
    at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
    at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1318)
    at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1257)
    at anywheresoftware.b4a.sql.SQL.ExecQuery2(SQL.java:223)
    at anywheresoftware.b4a.sql.SQL.ExecQuery(SQL.java:211)
    at bw.ultimatefreetvtrivia.bents1._episode1_click(bents1.java:1362)
    at bw.ultimatefreetvtrivia.bents1._button1_click(bents1.java:1179)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5610)
    at android.view.View$PerformClick.run(View.java:22265)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

Checked the database and the table is their like every other table i have for shows

Only way i have found for a work around is to rename the databse. Which i really dont want to do for every monthly update

any ideas?

Same issue on emulators and phones/tablets. Testing in release mode
 

hatzisn

Well-Known Member
Licensed User
Longtime User
Initialize again the connection
(Sql.Initialize(folder, file, createifnecessary)
 
Upvote 0

mcqueccu

Well-Known Member
Licensed User
Longtime User
The new database will not be updated automatically on your phone, I believe its an external database... which means you will have to recopy it to the phones storage before you can be able to access the new tables.

EDIT: You have to device a way of pushing new database update to your users - one way is tracking your database version.
Example if the old Database is 1 and the updated database is 2, then you know whether you have to copy the new one.
 
Upvote 0

Alex_197

Well-Known Member
Licensed User
Longtime User
What if you add a new table into existing database on your phone?
B4X:
Dim SQL1 As SQLCipher

Dim tblSymptoms As String

    tblSymptoms="CREATE TABLE  IF NOT EXISTS tblSymptoms ( "
    tblSymptoms=tblSymptoms & "ID INTEGER Not Null PRIMARY KEY AUTOINCREMENT, "
    tblSymptoms=tblSymptoms & "SymptomID INTEGER , "
    tblSymptoms=tblSymptoms & "Symptom Text "   
    tblSymptoms=tblSymptoms & ");"
    
SQL1.Initialize(DBFileDir, DBFileName, True,PWD,"")

SQL1.ExecNonQuery(tblSymptoms)

In this case you don't need to copy a database every time you do the update.
 
Upvote 0

brianwiz12

Active Member
Licensed User
Longtime User
I greatly appreciate the replies. I should clarify one aspect.

This is a trivia based app. I do monthly updates to add content. Shows/Questions.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
any ideas?
remember that you need to copy the database from Filesfolder (Assets) to another place to use it.
Did you overwrite the database on the device with the new one?

Also remember that you should do the changes (new table, new fields) by code with a already existent database on the device to not loose the data stored in the DB.
 
Upvote 0
Top