Sub Process_Globals
Dim SQL1 As SQL
End Sub
Sub Globals
Private EditTextKey As EditText
Private EditTextValue As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
InitializeDatabase
End If
' Créer l'interface utilisateur ici
End Sub
Sub InitializeDatabase
If File.Exists(File.DirInternal, "mapdata.db") = False Then
SQL1.Initialize(File.DirInternal, "mapdata.db", True)
CreateTable
Else
SQL1.Initialize(File.DirInternal, "mapdata.db", False)
End If
End Sub
Sub CreateTable
SQL1.ExecNonQuery("CREATE TABLE IF NOT EXISTS MapData (id INTEGER PRIMARY KEY AUTOINCREMENT, key TEXT UNIQUE, value TEXT)")
End Sub
Sub AddEntry
Dim key As String = EditTextKey.Text
Dim value As String = EditTextValue.Text
SQL1.ExecNonQuery2("INSERT OR REPLACE INTO MapData (key, value) VALUES (?, ?)", Array As String(key, value))
ToastMessageShow("Entrée ajoutée/mise à jour avec succès", False)
End Sub
Sub UpdateEntry
Dim key As String = EditTextKey.Text
Dim value As String = EditTextValue.Text
SQL1.ExecNonQuery2("UPDATE MapData SET value = ? WHERE key = ?", Array As String(value, key))
ToastMessageShow("Entrée mise à jour avec succès", False)
End Sub
Sub DeleteEntry
Dim key As String = EditTextKey.Text
SQL1.ExecNonQuery2("DELETE FROM MapData WHERE key = ?", Array As String(key))
ToastMessageShow("Entrée supprimée avec succès", False)
End Sub
Sub RetrieveEntry
Dim key As String = EditTextKey.Text
Dim cursor As Cursor
cursor = SQL1.ExecQuery2("SELECT value FROM MapData WHERE key = ?", Array As String(key))
If cursor.RowCount > 0 Then
cursor.Position = 0
EditTextValue.Text = cursor.GetString("value")
Else
EditTextValue.Text = ""
ToastMessageShow("Clé non trouvée", False)
End If
cursor.Close
End Sub