Android Question KeyValueStore

Sergey_New

Well-Known Member
Licensed User
Longtime User
I fill in kvs:
B4X:
Starter.kvs.Initialize(Starter.myFolder, "Thumbnails")
For i=0 To db.media.Size-1
    Starter.kvs.PutBitmap(id,bmp) 'id=@O01@,id=@O02@...id=@O129@
Next
I get:
B4X:
Starter.kvs.Initialize(Starter.myFolder, "Thumbnails")
Dim tempList As List
tempList = Starter.kvs.ListKeys
For i=0 To tempList.Size-1
    Dim id As String=tempList.Get(i)
    Log(id )
Next
'id=@O100@,@O101@,@O102@,@O103@,@O104@,@O105@
This does not correspond to the input order.
How can I sort kvs?
And the second question:
Two files appear in the Starter.myFolder folder - Thumbnails of 2 MB and Thumbnails-journal of 0B.
That is, the last file does not contain information. Is it necessary?
 

LucaMs

Expert
Licensed User
Longtime User
How can I sort kvs?
Sort your tempList, tempList.Sort(True). Next, you can get the values like:

B4X:
For i = 0 to tempList.Size - 1
   Bmp = Starter.kvs.Get(tempList.Get(i))
Next
Two files appear in the Starter.myFolder folder - Thumbnails of 2 MB and Thumbnails-journal of 0B.
That is, the last file does not contain information. Is it necessary?
It looks like some DB operation is still using it. Normally that second file is automatically deleted.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Sort your tempList, tempList.Sort(True)
Thank you, but the output order of the values was not changed. If you use tempList.Sort(False), the output order will be reversed. In both cases, it does not match the input order of the data.
Normally that second file is automatically deleted.
The Thumbnails-journal file is not deleted even after the application is closed.
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
Starter.kvs.Close
If you close after entering or outputting data, an error occurs:
Error occurred on line: 22 (KeyValueStore)
java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /storage/emulated/0/Поколения/Thumbnails
at android.database.sqlite.SQLiteClosable.acquireReference(SQLiteClosable.java:58)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1708)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1651)
at anywheresoftware.b4a.sql.SQL.ExecQuery2(SQL.java:223)
at sv.bystrovzorov.keyvaluestore._get(keyvaluestore.java:295)
at sv.bystrovzorov.keyvaluestore._getbitmap(keyvaluestore.java:196)
at sv.bystrovzorov.table._showrow(table.java:1697)
at sv.bystrovzorov.table._addrow(table.java:688)
at sv.bystrovzorov.function._filltablemedias(function.java:1118)
at sv.bystrovzorov.listmedia._setmedias(listmedia.java:565)
at sv.bystrovzorov.listmedia._activity_resume(listmedia.java:552)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at sv.bystrovzorov.listmedia.afterFirstLayout(listmedia.java:111)
at sv.bystrovzorov.listmedia.access$000(listmedia.java:17)
at sv.bystrovzorov.listmedia$WaitForLayout.run(listmedia.java:83)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7884)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
If you do this when closing the application, the error does not occur, but Thumbnails-journal is not deleted
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
If you also want to know what changes to make, just pay me $10,000 and I'll do it right away
I was kidding, of course; $3000 should be enough for me

I think what you can add is a function that returns the rowids of the SQlite DB. It is not the optimal solution, because if you later change a key, the rowid will be the same as before, but it is a good alternative
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
If you want I can do it. Just know that you will have to change the name of the library afterwards
Joke accepted
Thanks, this is not required. I just wanted to study the library in more detail. Unfortunately, its description is very sparse.
Thanks for participating in the discussion!
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Joke accepted
Thanks, this is not required. I just wanted to study the library in more detail. Unfortunately, its description is very sparse.
Thanks for participating in the discussion!
Before lunch, I wanted to try.
I added two functions:


Public Sub GetMapByRowids As Map

Public Sub GetValuesByRowids As List

If you are interested and/or have any other functions in mind, let me know.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I also have created MinimaList b4xlib which work similarly to KeyValueStore but with many extra methods such as sorting.
 
Upvote 0