Android Tutorial [B4X] CloudKVS - synchronized key / value store

pesquera

Active Member
Licensed User
Longtime User
You can see in the code that all the messages sent are first serialized with B4XSerializator.
Sorry if this post is not related..
Why this serialization is needed?
How can I do to see the "Value" data into the SQLite DB with any db tool editor? (in some kind of legible way)
Where can I read about the B4XSerializator logic? I've never used it and trying to find info without luck, may be my brain is not compiling at this time
Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Why this serialization is needed?
You can only send bytes over the network. Serialization is the process of converting data or objects to bytes. B4XSerializator is very useful as it makes it easy to convert complex objects to bytes (and later convert the bytes back to objects).
Using B4XSerializator also allows us to store (almost) any type of value in the data store. For example the value can be a list of custom types.

For more information about B4XSerializator please start a new thread.

You can open the database with any SQL editor you like. The value field is a serialized blob.
 

pesquera

Active Member
Licensed User
Longtime User
Ok. I understand now.. thanks
I just expected to update some simple text value with my sql editor.. because I need to edit all records from serverdb.db, filtering in the user field
As I can see, I should do some B4J UI for that.. correct?
Is there any way to do the server side with B4A?
 

pesquera

Active Member
Licensed User
Longtime User
Do you plan to add encryption methods on the future? (like KeyValueStore 2)
 

pesquera

Active Member
Licensed User
Longtime User
Yes. You can use PutBitmap and GetBitmap.
Thank you Erel, copied them from KeyValueStore 2 and it's working perfect

Now, I must put/get a SQLite data file.. Could you please recommend me how to do that?
Should I handle the whole .db file? (if possible)
or, Should I handle each record into a List?
db has less than 1000 records

Thanks
 

luke2012

Well-Known Member
Licensed User
Longtime User
I have a couple of questions about KVS Cloud.

1) Can I use array of bytes to store (put) audio file within the KVS store?
2) Is it possibile to set an auto-refresh interval like 0.5 or 1 sec ?
 
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
Hi @Erel.
Regarding your example:

B4X:
ckvs.Put("User1", "Key1", 100)
Log(ckvs.Get("User1", "Key1")) '100
Log(ckvs.GetDefault("User2", "Key1", 0)) '0 because User2/Key1 is different than User1/Key1

How I can get a list of all values "putted" (for example) by "User1" ?
I mean with "Get" method I can get always one value (putted by the User1), because the key is a unique value within the KVS.
 

LucaMs

Expert
Licensed User
Longtime User
There is a GetAll method which returns a map:
B4X:
'Returns a map with the keys and values of the given user.
Public Sub GetAll(user As String) As Map
    Dim res As Map
    res.Initialize
    Dim ser As B4XSerializator
    Dim rs As ResultSet = sql.ExecQuery2("SELECT key, value FROM data WHERE user = ? AND value IS NOT NULL", Array As String(user))
    Do While rs.NextRow
        res.Put(rs.GetString("key"), ser.ConvertBytesToObject(rs.GetBlob("value")))
    Loop
    rs.Close
    Return res
End Sub
 

luke2012

Well-Known Member
Licensed User
Longtime User

Thank you very much @LucaMs
 

luke2012

Well-Known Member
Licensed User
Longtime User
The method GetAll is simple to use and works very well
Now I can put a value, get a value, replace a value and get all values for a gived user but how to delete a value or delete all values for a given user?
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…