'KeyValueStore: v2.00
Sub Class_Globals
Private sql1 As SQL
''''Private ser As B4XSerializator '<<<<< removed
End Sub
'Initializes the store and sets the store file.
Public Sub Initialize (Dir As String, FileName As String)
If sql1.IsInitialized Then sql1.Close
#if B4J
sql1.InitializeSQLite(Dir, FileName, True)
#else
sql1.Initialize(Dir, FileName, True)
#end if
CreateTable
sql1.ExecNonQuery("PRAGMA journal_mode = wal") '<<<<< added line
End Sub
Public Sub Put(Key As String, Value As Object)
Dim ser As B4XSerializator '<<<<< added line
sql1.ExecNonQuery2("INSERT OR REPLACE INTO main VALUES(?, ?)", Array As Object(Key, ser.ConvertObjectToBytes(Value)))
End Sub
Public Sub Get(Key As String) As Object
Dim rs As ResultSet = sql1.ExecQuery2("SELECT value FROM main WHERE key = ?", Array As String(Key))
Dim result As Object = Null
If rs.NextRow Then
Dim ser As B4XSerializator '<<<<< added line
result = ser.ConvertBytesToObject(rs.GetBlob2(0))
End If
rs.Close
Return result
End Sub