Android Question Externally created database

casher2

Member
Licensed User
Longtime User
I created small DB with independent utility program. 'Enteral.db'. The DB has two tables: 'Company': ID, CompanyName and 'Products': ID, CompanyID, ProductName. Both tables contain data.
Question: How do I read the existing data from my app? I copied DB to app Files folder and then copied files from ASSETS within my app (DBUTILS). I still cannot reference tables.
Everything I have read tells me I must recreate the tables and fill them with data on start-up. If that's true, why have an existing DB with data?
I've read help files extensively to no avail. I think I'm missing something very basic.
 

barx

Well-Known Member
Licensed User
Longtime User
Is it a SQLite DB?

Did you copy the DB from assets to a writable location?
 
Upvote 0

casher2

Member
Licensed User
Longtime User
Yes, It's SQLite DB.

Public Sub CopyDBFromAssets (FileName As String) As String
Dim TargetDir As String
If File.ExternalWritable Then TargetDir = File.DirDefaultExternal Else TargetDir = File.DirInternal
If File.Exists(TargetDir, FileName) = False Then
File.Copy(File.DirAssets, FileName, TargetDir, FileName)
End If
Return TargetDir
End Sub

I used this Sub from DBUTILS. Rethinking, I then tried to reference tables in File.DirInternal and File.DirExternal. Should I have used 'TargetDir' instead? (Eril's DBUTILS has the sub for copying files from ASSETS but doesn't use it in his sample program. He rebuilds tables instead...hence the confusion.
 
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Should I have used 'TargetDir' instead?
After you copied the database to TargetDir you should use (initialize) the database in TargetDir. Correct.
 
Upvote 0

casher2

Member
Licensed User
Longtime User
Will try 'TargetDir'. Suspect this was my error and if it resolves issue, will save me tons of time and coding. Thanks!!
 
Upvote 0
Top