DBUtils - not seeing an existing table

gawie007

Member
Licensed User
Longtime User
Hi,
I hope someone could assist me with this!

I have made an SQLite (3) database called ESR.db
One of my table names is "Customers".

In the ActivityCreate Sub I have the following line:
DBUtils.ExecuteSpinner(SQL, "SELECT CustomerID FROM Customers", Null, 0, spnrCustomers)

This gives an error in the DBUtils Module line 138:
android.database.sqlite.SQLiteException: no such table : Customers:.

When I cut and paste this Query into Sqlite 3, it returns the ID's 1,2,3,4 ... as expected.

The only difference on my PK (ID) is that mine are Integers and the DBUtils example uses Strings.

Your help will be greatly appreciated!

Kind regards
Gavin
 

gawie007

Member
Licensed User
Longtime User
My Project as requested

Hi Erel,

I had to remove the apk files to reduce the size of the zip file.

I hope that you aren't going to tell me I am an idiot after missing something simple in my code.

Thanks in advance!

Kind regards

Gavin
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
The answer is simple, you are NOT copying the DB from your assets to the device.

Something like:

B4X:
If FirstTime Then

   If File.Exists(File.DirDefaultExternal, "ESR.db") = False Then
            
      File.Copy(File.DirAssets, "ESR.db", File.DirDefaultExternal, "ESR.db")
                     
   End If

End If

SQL.Initialize(File.DirRootExternal, "ESR.db", True)

If it doesn't work maybe something wrong with DBUtils?, not sure because I don't use it.
 
Last edited:
Upvote 0

gawie007

Member
Licensed User
Longtime User
Thanks NJDude

Hi, you pointed me in the right direction.
I havent got it completely right yet but this was the solution to it:

If FirstTime Then

Dim TargetDir As String
TargetDir = DBUtils.CopyDBFromAssets("ESR.db")
SQL.Initialize(TargetDir,"ESR.db", True)

End If

It did what you suggested then returned a string of the actual Directory which I put into TargetDir.

Your help was appreciated.
Thank you!
Regards
Gavin
 
Upvote 0
Top