Android Question Error with SQLite

mrjaw

Active Member
Licensed User
Longtime User
Hi!
I am having a weird problem with SQLite, the database is in my device but when I try to do any SQL to this I get always NULL and I get this error:

android.database.sqlite.SQLiteException: no such table: t_ganadores: DELETE FROM t_ganadores

But if I check my database with a SQLiteBrowser all my tables there are.
B4a tell me there is no tables in my DB

av = SQL.ExecQuerySingleResult("Select count(*) from sqlite_master where Type = 'table' and name='t_ganadores';")

Av has the value of 0

Thinks B4a doesnt understand the tables into DB
 

mrjaw

Active Member
Licensed User
Longtime User
This is my code to open the database
<code>

If File.Exists(File.DirDefaultExternal, "lototouch.db") = False Then
Log("Copiando la base de datos")
File.Copy(File.DirAssets, "lototouch.db", File.DirInternal, "lototouch.db")
Else
Log("La bas e de datos existe..")
End If
'
If File.Exists(File.DirInternal, "lototouch.db") = True Then
Log("La base de datos existe////..")
Else
Log("La base de datos NO existe..")
End If

Log("Dir Assets:" & File.DirAssets)
Log("Dir External:" & File.DirInternal)
Log("Dir External:" & File.DirDefaultExternal)
'
SQL.Initialize(File.DirDefaultExternal,"lototouch.db", True)
'
Dim av As String
av = SQL.ExecQuerySingleResult("Select count(*) from sqlite_master where Type = 'table' and name='t_ganadores';")
Log("AV::::" & av)
'
SQL.ExecNonQuery("DELETE FROM t_ganadores")
'
SQL.ExecNonQuery("DELETE FROM t_jugadas")
</code>
 
Upvote 0

edgar_ortiz

Active Member
Licensed User
Longtime User
Change:
File.Copy(File.DirAssets, "lototouch.db", File.DirInternal, "lototouch.db")

TO
File.Copy(File.DirAssets, "lototouch.db", File.DirDefaultExternal, "lototouch.db")

Regards,

Edgar
 
Upvote 0

mrjaw

Active Member
Licensed User
Longtime User
Edgar, it works! but really I dont know how!! I dont understand because the database was in the other location , can you explain me how ?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Edgar, it works! but really I dont know how!! I dont understand because the database was in the other location , can you explain me how ?
In your code you copy the database to Internal: File.Copy(File.DirAssets, "lototouch.db", File.DirInternal, "lototouch.db")
But you try to open it somewhere else: SQL.Initialize(File.DirDefaultExternal,"lototouch.db", True)
If you want to copy the database to internal, you need to initialize it in internal like this:
SQL.Initialize(File.DirInternal,"lototouch.db", True)
 
Upvote 0
Top