Why does the sql eliminates the previous zero in the following example, if the value is a numer (0201 =201)? Is it possible to hold the previous zero to save telephonenumbers etc.?
B4X:
Sub Process_Globals
Private sql1 As SQL
End Sub
Private Sub Application_Start (Nav As NavigationController)
Initialize
PutSimple("Wert1", "0201")
Log(GetString("Wert1"))
PutSimple("Wert2", "0hallo")
Log(GetString("Wert2"))
End Sub
Public Sub Initialize
If sql1.IsInitialized Then sql1.Close
sql1.Initialize(File.DirLibrary, "pm.dat", True)
CreateTable
End Sub
Public Sub SetString(key As String, value As String)
PutSimple(key, value)
End Sub
Public Sub GetString(key As String) As String
Return GetSimpleString(key)
End Sub
Private Sub CreateTable
sql1.ExecNonQuery("CREATE TABLE IF NOT EXISTS main(key TEXT PRIMARY KEY, value NONE)")
End Sub
Private Sub getCursor(Key As String) As ResultSet
Return sql1.ExecQuery2("SELECT value FROM main WHERE key = ?", Array As String(Key))
End Sub
Private Sub GetSimpleString(Key As String) As String
Dim c As ResultSet = getCursor(Key)
If c.NextRow = False Then
c.Close
Return ""
End If
Dim res As String = c.GetString2(0)
c.Close
Return res
End Sub
Private Sub PutSimple(Key As String, Value As Object) As Boolean
Try
start(Key)
insertQuery(Key, Value)
Return complete(True)
Catch
Return complete(False)
End Try
End Sub
Private Sub start (Key As String)
sql1.BeginTransaction
sql1.ExecNonQuery2("DELETE FROM main WHERE key = ?", Array As Object(Key))
End Sub
Private Sub insertQuery(Key As String, Value As Object)
sql1.ExecNonQuery2("INSERT INTO main VALUES(?, ?)", Array As Object(Key, Value))
End Sub
Private Sub complete(success As Boolean) As Boolean
If success Then
sql1.TransactionSuccessful
Else
sql1.Rollback
End If
Return success
End Sub
Public Sub Close
sql1.Close
End Sub