I created a database with a table (table1) with Sqlite expert, but with the following code tells me the table1 does not exist, if I open the database with Sqlite is okay.
Please if you can help me.
thanks
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("culturilla")
SQL1.Initialize(File.DirInternal, "base.db", True)
la1=SQL1.ExecQuery("SELECT pregunta FROM table1 WHERE id=1")
Label1.Text=la1
End Sub
You must be careful:
How many results are you expecting.
- SQL.ExecQuery returns a Cursor object with multiple results
- SQL.ExecQuerySingleResult returns a single value
I think in your case you should use SQL.ExecQuerySingleResult.
I haven't looked at your project but did you add the file to your project in the b4a ide? and you must, in your code, copy the database to a writeable location.
Search the forum for DBUtils, this helps simplify the process a bit.
barx is right, you didn't copy the database to the File.DirInternal folder.
This code works having the database file in the Files folder of the project:
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("culturilla")
If FirstTime = True AND File.Exists(File.DirInternal, "base.db") = False Then
File.Copy(File.DirAssets, "base.db", File.DirInternal, "base.db")
End If
SQL1.Initialize(File.DirInternal, "base.db", True)
la1=SQL1.ExecQuerySingleResult("SELECT pregunta FROM table1 WHERE id=1")
Label1.Text=la1
End Sub