Android Question KeyvalueStore2 writes row but incomplete data

Rusty

Well-Known Member
Licensed User
Longtime User
I am creating a KVS2 database. It gets created and when I add rows with a PUT
B4X:
Sub Class_Globals
    Type cntnts(Room As String, ItemType As String, ItemList As List)
    Dim Contents As cntnts
    Dim ItemNo As Int
End Sub
… 
ItemNo = ItemNo + 1
Contents.Room = "RoomA"
Contents.ItemType = "normal"
Contents.ItemList.add("item1")
Contents.ItemList.add("item2")
Contents.ItemList.add("item3")
Contents.ItemList.add("item4")
kvs.Put(ItemNo, Contents)
...

The value of Contents is almost always empty in the database. Sometimes (randomly), there will be a valid value.
I've converted to the KeyvalueStore2 class so I could trace the INSERT or REPLACE command and the data is there. I've used TRY/CATCH around the INSERT
B4X:
Try
        sql1.ExecNonQuery2("INSERT OR REPLACE INTO main VALUES(?, ?)", Array (Key, ser.ConvertObjectToBytes(Value)))     
    Catch
        Log(LastException)
    End Try
and NO ERROR occurs. The Value is correct and contains all 4 items at the point of the ExecNonQuery2.
The write to the table seems to go ok, but when I view the database, the Keys are all there (thus a row per key) but the VALUES are mostly empty...

This works the same way with both the LIBRARY and the CLASS...
Can the ser.convertobjecttobytes(Value) accept a list?
Any ideas or suggestions?
Thanks,
Rusty
 

Rusty

Well-Known Member
Licensed User
Longtime User
Hi Erel,
I created a small program that writes the KVS and can't make it fail...
Obviously, it's my code or a combination of events.
I will convert it to SQLite (Open/Write/Close...etc.) I had it done with SQLite originally but decided it was more conducive for KVS and tried to convert it to KVS. It worked as SQLite and due (thankfully) to the B4a automatic backups :):):) I can restore to the SQLite version and move on.
Thanks for your great development environment(s) and support!
Rusty
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
I just bumped into the same issue. One key only recorded the value, otherwise the others simply contain null :(

Erel advised to put declaration and initialization in Starter, I tried in both main and starter with exactly the same result.

Here is a log :

EtMemo_Left,65
EtMemo_Top,null
EtSignature_Left,null
EtSignature_Top,null
EtWordAmount_Left,null
EtWordAmount_Top,null
zut,null


I will switch to Map in hope not to get the same issue.
 
Upvote 0

MitchBu

Well-Known Member
Licensed User
Longtime User
There must be something else.

I tried to create a small test project based on your tutorial, and the issue does not manifest.

My project works now perfectly and does not exhibit the same issue with Map Collection. So for the moment I have my solution. Case closed for me.
 
Upvote 0
Top