Android Question [SOLVED] Multiple tables in sqlite database

AymanA

Active Member
Licensed User
Hi Helpers :)

I have a sqlite db with multiple tables, I am not sure why but I no matter what I do, I can not read from all the tables in my DB, I have searched in sqlite documentation and saw some examples which are not different than what I have, but for some reason it fails, when I try the code below it returns an error:

B4X:
Sub subGroupRetrieve()
    grouplist.Initialize()
    Starter.myCUR = Starter.mySQL.ExecQuery("SELECT distinct topicsplit.groupname FROM topicsplit")
    For i= 0 To Starter.myCUR.RowCount - 1
        Starter.myCUR.Position = i
grouplist.Add(Starter.myCUR.GetString("groupname"))
Next
end sub

Error in log:

B4X:
android.database.sqlite.SQLiteException: no such table: topicsplit (code 1 SQLITE_ERROR[1]): , while compiling: SELECT distinct topicsplit.groupname FROM topicsplit

There is topicsplit as you can see from the compressed sample attached.

I really appreciate your help on this!
 

Attachments

  • sqlite_multi_tbl.zip
    9.7 KB · Views: 342

mc73

Well-Known Member
Licensed User
Longtime User
Possibly, you have an old db at dir.internal from which this table is missing. Try deleting this db and reload your new one from assets.
 
Upvote 0

AymanA

Active Member
Licensed User
@mc73 @klaus thank you so much for confirming that it is working for you!! Appreciate your help! I have been scratching my head for a very long time thinking I was doing something wrong!

I am sorry I didn't get the part of dir.internal I think you mean to remove the app on the mobile which will remove the db file right? If no then can you explain more to learn from this.

Thank you so much for your help guys!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
In the Starter Service, in the SaveDB routine add the line to delete the file from File.DirInternal.
B4X:
Sub SaveDB()
    File.Delete(DBDir, DBName)
    If File.Exists(DBDir, DBName) = False Then
        File.Copy(File.DirAssets, DBName, DBDir, DBName)
    End If
End Sub
And when it works don't forget to comment this line.
 
Last edited:
Upvote 0

AymanA

Active Member
Licensed User
It worked!!, I really appreciate your help on this and the time you have spent to help me out! thank you so much!

Just to understand, the File.DirInternal is the directory that is created with the application, and it it is specific for the app running, so removing the app and reinstall it (through the B4A Bridge / Debug mode) in my assumption deletes the directory, or this is an incorrect assumption?
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
It worked!!, I really appreciate your help on this and the time you have spent to help me out! thank you so much!

Just to understand, the File.DirInternal is the directory that is created with the application, and it it is specific for the app running, so removing the app and reinstall it (through the B4A Bridge / Debug mode) in my assumption deletes the directory, or this is an incorrect assumption?
If you are just rebuilding the app & running it in debug mode, then no - the app is not removed, nor is Dir.Internal. If you actually uninstall the app, then compile, install & run it, then Dir.Internal will be removed with the uninstall & recreated with the new install.

- Colin.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you are just rebuilding the app & running it in debug mode, then no - the app is not removed, nor is Dir.Internal. If you actually uninstall the app, then compile, install & run it, then Dir.Internal will be removed with the uninstall & recreated with the new install.
This is not 100% correct. On newer versions of Android, the app might be backed up automatically and then the previous files will be restored.

You can disable it with:
B4X:
'manifest editor
SetApplicationAttribute(android:allowBackup, "false")
 
Upvote 0

Computersmith64

Well-Known Member
Licensed User
Longtime User
This is not 100% correct. On newer versions of Android, the app might be backed up automatically and then the previous files will be restored.

You can disable it with:
B4X:
'manifest editor
SetApplicationAttribute(android:allowBackup, "false")
True - I forgot about that... You can also disable cloud backup in the device settings.

- Colin.
 
Upvote 0

AymanA

Active Member
Licensed User
Perfect! now I understand the cause of this :) thank you for your help! it is really great to have awesome people that tends to help, without this invaluable forum I could have struggled in so many ways :)
 
Upvote 0
Top