Android Question keyvaluestore question

tufanv

Expert
Licensed User
Longtime User
Hello,

Let's say for the key "x" I have value "y". If I want to change the value from y to z , I use kvs.put(x,z) but this add the key to last position on kvs. For example if i use kvs.listykeys previous to this , x key is at second position but after this it changes to last position. Is there anyway to to avoid this ? like editing the key instead of removing and adding again without changing the list sequence ?

like adding a edit public sup to keyvalue store as it is in put :
B4X:
Public Sub Put(Key As String, Value As Object)
    sql1.ExecNonQuery2("INSERT OR REPLACE INTO main VALUES(?, ?)", Array As Object(Key, ser.ConvertObjectToBytes(Value)))
End Sub

and use update ?

I am trying to add this to kvs :

B4X:
Public Sub Edit(Key As String, Value As Object)
    sql1.ExecNonQuery2("UPDATE main SET(?, ?)", Array As Object(Key, ser.ConvertObjectToBytes(Value)))
End Sub

I dont understand how to use question marks here. What I want to do is Execute :
Update main set key=value where key=key

TY
 
Last edited:

derez

Expert
Licensed User
Longtime User
If Key and Value are the names of the columns in the DB then:
B4X:
Public Sub Edit(Key As String, Value As Object)
    sql1.ExecNonQuery2("UPDATE main SET Value=? WHERE Key=?", Array As Object( ser.ConvertObjectToBytes(Value), Key))
End Sub
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User
If Key and Value are the names of the columns in the DB then:
B4X:
Public Sub Edit(Key As String, Value As Object)
    sql1.ExecNonQuery2("UPDATE main SET Value=? WHERE Key=?", Array As Object( ser.ConvertObjectToBytes(Value), Key))
End Sub
YEs thanks ! I mistyped the code value for key so it wasnt working :)

B4X:
Public Sub Edit(Key As String, Value As Object)
    sql1.ExecNonQuery2("UPDATE main SET Key=? WHERE Key=?", Array As Object( ser.ConvertObjectToBytes(Value), Key))
End Sub
 
Upvote 0
Top