'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim SQL1 As SQL
'initialize the database ..Create new file if does not exist
SQL1.Initialize (File.DirDefaultExternal,"MyDataBase.db",True)
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("layout1")
'remove table if needed
SQL1.ExecNonQuery("DROP TABLE IF EXISTS stock")
'create table
SQL1.ExecNonQuery("CREATE TABLE IF NOT EXIST mytable (Firstname TEXT , LastName TEXT, age INTEGER)")
End Sub
Sub FillTable
SQL1.ExecNonQuery ("INSERT INTO mytable VALUES ('John', 'Smith', 21)")
End Sub
Hi Fabio .. Just learning myself so this might get you started
I seriously suggest you read this .. SQL Tutorial
You can also build ,view and test your database with this program .... SQLite Database Browser
B4X:'Activity module Sub Process_Globals 'These global variables will be declared once when the application starts. 'These variables can be accessed from all modules. Dim SQL1 As SQL 'initialize the database ..Create new file if does not exist SQL1.Initialize (File.DirDefaultExternal,"MyDataBase.db",True) End Sub Sub Activity_Create(FirstTime As Boolean) 'Do not forget to load the layout file created with the visual designer. For example: Activity.LoadLayout("layout1") 'remove table if needed SQL1.ExecNonQuery("DROP TABLE IF EXISTS stock") 'create table SQL1.ExecNonQuery("CREATE TABLE IF NOT EXIST mytable (Firstname TEXT , LastName TEXT, age INTEGER)") End Sub Sub FillTable SQL1.ExecNonQuery ("INSERT INTO mytable VALUES ('John', 'Smith', 21)") End Sub
Cheers mj
I'm little confused .... does not this work with SQLite3 anyway ?
Cheers mj
are you sure this is also compatible with sqlite3?
SQL library work with SQLite3 databases.
Can you post the code that opens the database?
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim SQL1 As SQL
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Main")
SQL1.Initialize ("/sdcard/","contacts.db",False)
End Sub
Sub ButtonClearCall_Click
ProgressDialogShow("Wait...")
SQL1.ExecNonQuery("delete from data_usage_stat;")
ProgressDialogHide
End Sub
Can you post the exact error message?
You should use SQL1.Initialize(File.DirRootExternal, "contacts.db", False) instead.
This issue is not related to the databases. This folder is not accessible to non-system applications.
Do you plan to run your app on rooted devices only?
As far as I know, there is no way to run your application with root access. You can run a shell script with the Shell command (search the forum) that will copy the database to an accessible folder.
As I wrote above you will need to copy the database and then open it from your application.