Android Question [SOLVED] Multiple tables in sqlite database

AymanA

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

mc73

Well-Known Member
Licensed 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.
 

AymanA

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!
 

klaus

Expert
Licensed 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:

AymanA

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?
 

Computersmith64

Well-Known 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?
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.
 

Erel

Administrator
Staff member
Licensed 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")
 

Computersmith64

Well-Known Member
Licensed 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.
 

AymanA

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 :)
 
Top