I had a problem using KeyValueStore2 and, "investigating", saw it uses "INSERT OR REPLACE".
This doesn't work well in SQLite (almost certainly due to the rowid field).
The problem I had was that I couldn't preserve the order of the data by using Put (actually PutEncrypted but it doesn't matter) to change a value of an existing key.
Testing "INSERT OR REPLACE" with a tool:
CREATE TABLE main(key TEXT PRIMARY KEY, value NONE);
INSERT OR REPLACE INTO main VALUES('Site 0', 'AAA');
INSERT OR REPLACE INTO main VALUES('Site 1', 'BBB');
INSERT OR REPLACE INTO main VALUES('Site 2', 'CCC');
... then...
INSERT OR REPLACE INTO main VALUES('Site 1', '111');
Next, reading all the data using:
i got the data in that order, instead of the original order (note: the key value may not be done that way, not sortable like that).
At that point I modified KVS2 to be able to keep the order of the data as if it were a Map. Added also:
- Replace (so that you can change a key)
- ReplaceEncrypted
- Changed PutMapAsync (not tested) because of the same reason. Note that a "PutEncryptedMap" and "PutEncryptedMapAsync" would needed.
I believe my version is fully compatible with the original. I am attaching only the bas file, instead of the B4Xlib. I would like Erel to examine it, test it and use it in his KeyValueStore2, without me being forced to unnecessarily create my own lmKeyValueStore(2).
I kept the original routines, commenting on them and written my routines with the comment: ' LucaMs 04/15/2021
This doesn't work well in SQLite (almost certainly due to the rowid field).
The problem I had was that I couldn't preserve the order of the data by using Put (actually PutEncrypted but it doesn't matter) to change a value of an existing key.
Testing "INSERT OR REPLACE" with a tool:
CREATE TABLE main(key TEXT PRIMARY KEY, value NONE);
INSERT OR REPLACE INTO main VALUES('Site 0', 'AAA');
INSERT OR REPLACE INTO main VALUES('Site 1', 'BBB');
INSERT OR REPLACE INTO main VALUES('Site 2', 'CCC');
... then...
INSERT OR REPLACE INTO main VALUES('Site 1', '111');
Next, reading all the data using:
B4X:
For Each Key As String In mKVS2.ListKeys
At that point I modified KVS2 to be able to keep the order of the data as if it were a Map. Added also:
- Replace (so that you can change a key)
- ReplaceEncrypted
- Changed PutMapAsync (not tested) because of the same reason. Note that a "PutEncryptedMap" and "PutEncryptedMapAsync" would needed.
I believe my version is fully compatible with the original. I am attaching only the bas file, instead of the B4Xlib. I would like Erel to examine it, test it and use it in his KeyValueStore2, without me being forced to unnecessarily create my own lmKeyValueStore(2).
I kept the original routines, commenting on them and written my routines with the comment: ' LucaMs 04/15/2021
Attachments
Last edited: