Sub Activity_Create(FirstTime As Boolean)
Dim bDBDeleted As Boolean
Dim bStringPassword As Boolean = False
Activity.LoadLayout("Layout")
Dim key As String = "Hello world"
Dim c As B4XCipher
'if you don't delete the DB that was created with a different password method (string or byte array)
'then there will be an error:
'android.database.sqlite.SQLiteException: file is not a database: , while compiling:
'select count(*) from sqlite_master;
'----------------------------------------------------------------------------------------------------
bDBDeleted = File.Delete(File.DirInternal, "db3.db")
Log("bDBDeleted: " & bDBDeleted)
If bStringPassword Then
sqlci.initializeCipher("SQL", File.DirInternal & "/db3.db", "12345678", 1)
Else
Dim b() As Byte = c.Encrypt(key.GetBytes("UTF8"), "12345678")
sqlci.initializeCipher2("SQL", File.DirInternal & "/db3.db", b, 1)
End If
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
'as the DB was deleted on app start we don't really need the: if not exists anymore
sqlci.ExecNonQuery("CREATE TABLE if not exists table1 (col1 TEXT, col2 INTEGER, col3 INTEGER)")
For i = 0 To 10
sqlci.ExecNonQuery2("INSERT INTO table1 VALUES (?, ?, ?)", Array As Object("some text" & i, i, i * 2))
Next
End Sub
Private Sub Button2_Click
Dim RS As ResultSet
RS = sqlci.ExecQuery("SELECT col1, col2 FROM table1")
Do While RS.NextRow
Log(RS.GetString2(0))
Log(RS.GetInt2(1))
Loop
Log("------------------------------------------")
End Sub