Sergey_New Well-Known Member Licensed User Longtime User Feb 1, 2025 #1 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=@[email protected]=@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?
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=@[email protected]=@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 Feb 1, 2025 #2 Sergey_New said: How can I sort kvs? Click to expand... 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 Sergey_New said: 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? Click to expand... It looks like some DB operation is still using it. Normally that second file is automatically deleted. Upvote 0
Sergey_New said: How can I sort kvs? Click to expand... 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 Sergey_New said: 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? Click to expand... It looks like some DB operation is still using it. Normally that second file is automatically deleted.
Sergey_New Well-Known Member Licensed User Longtime User Feb 2, 2025 #3 LucaMs said: Sort your tempList, tempList.Sort(True) Click to expand... 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. LucaMs said: Normally that second file is automatically deleted. Click to expand... The Thumbnails-journal file is not deleted even after the application is closed. Upvote 0
LucaMs said: Sort your tempList, tempList.Sort(True) Click to expand... 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. LucaMs said: Normally that second file is automatically deleted. Click to expand... The Thumbnails-journal file is not deleted even after the application is closed.
LucaMs Expert Licensed User Longtime User Feb 2, 2025 #4 Your question was: Sergey_New said: How can I sort kvs? Click to expand... To preserve the input order it would be necessary to modify KVS. Sergey_New said: The Thumbnails-journal file is not deleted even after the application is closed. Click to expand... Did you close KVS in your source? Upvote 0
Your question was: Sergey_New said: How can I sort kvs? Click to expand... To preserve the input order it would be necessary to modify KVS. Sergey_New said: The Thumbnails-journal file is not deleted even after the application is closed. Click to expand... Did you close KVS in your source?
Sergey_New Well-Known Member Licensed User Longtime User Feb 2, 2025 #5 LucaMs said: Did you close KVS in your source? Click to expand... How can this be done? Upvote 0
LucaMs Expert Licensed User Longtime User Feb 2, 2025 #6 Sergey_New said: How can this be done? Click to expand... Just: Starter.kvs.Close Upvote 0
Sergey_New Well-Known Member Licensed User Longtime User Feb 2, 2025 #7 LucaMs said: Starter.kvs.Close Click to expand... If you close after entering or outputting data, an error occurs: Spoiler 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 said: Starter.kvs.Close Click to expand... If you close after entering or outputting data, an error occurs: Spoiler 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
LucaMs Expert Licensed User Longtime User Feb 2, 2025 #8 Sergey_New said: If you do this when closing the application, the error does not occur, but Thumbnails-journal is not deleted Click to expand... Don't worry about this (and save the KVS in DirInternal) Upvote 0
Sergey_New said: If you do this when closing the application, the error does not occur, but Thumbnails-journal is not deleted Click to expand... Don't worry about this (and save the KVS in DirInternal)
Sergey_New Well-Known Member Licensed User Longtime User Feb 2, 2025 #9 LucaMs said: Don't worry about this (and save the KVS in DirInternal) Click to expand... In this case the file is still not deleted. Why? Upvote 0
LucaMs said: Don't worry about this (and save the KVS in DirInternal) Click to expand... In this case the file is still not deleted. Why?
LucaMs Expert Licensed User Longtime User Feb 2, 2025 #10 Sergey_New said: In this case the file is still not deleted. Why? Click to expand... I don't know. When you close the KVS (in which the DB is almost certainly closed) the file should be deleted automatically. Upvote 0
Sergey_New said: In this case the file is still not deleted. Why? Click to expand... I don't know. When you close the KVS (in which the DB is almost certainly closed) the file should be deleted automatically.
Sergey_New Well-Known Member Licensed User Longtime User Feb 2, 2025 #11 LucaMs said: To preserve the input order it would be necessary to modify KVS. Click to expand... Please tell me how this can be done? Upvote 0
LucaMs said: To preserve the input order it would be necessary to modify KVS. Click to expand... Please tell me how this can be done?
LucaMs Expert Licensed User Longtime User Feb 2, 2025 #12 Sergey_New said: Please tell me how this can be done? Click to expand... KeyValueStore is a b4xlib, a simple zip file. Unzip it and edit the source code. If you also want to know what changes to make, just pay me $10,000 and I'll do it right away Upvote 0
Sergey_New said: Please tell me how this can be done? Click to expand... KeyValueStore is a b4xlib, a simple zip file. Unzip it and edit the source code. If you also want to know what changes to make, just pay me $10,000 and I'll do it right away
LucaMs Expert Licensed User Longtime User Feb 2, 2025 #13 LucaMs said: If you also want to know what changes to make, just pay me $10,000 and I'll do it right away Click to expand... 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
LucaMs said: If you also want to know what changes to make, just pay me $10,000 and I'll do it right away Click to expand... 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
LucaMs Expert Licensed User Longtime User Feb 2, 2025 #14 Sergey_New said: Please tell me how this can be done? Click to expand... If you want I can do it. Just know that you will have to change the name of the library afterwards; a good name could be lmKeyValueStore Upvote 0
Sergey_New said: Please tell me how this can be done? Click to expand... If you want I can do it. Just know that you will have to change the name of the library afterwards; a good name could be lmKeyValueStore
Sergey_New Well-Known Member Licensed User Longtime User Feb 2, 2025 #15 LucaMs said: If you want I can do it. Just know that you will have to change the name of the library afterwards Click to expand... 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 said: If you want I can do it. Just know that you will have to change the name of the library afterwards Click to expand... 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!
LucaMs Expert Licensed User Longtime User Feb 2, 2025 #16 Sergey_New said: 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! Click to expand... 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
Sergey_New said: 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! Click to expand... 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.
LucaMs Expert Licensed User Longtime User Feb 2, 2025 #17 LucaMs said: 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. Click to expand... Attachments lmKeyValueStore.b4xlib lmKeyValueStore.b4xlib 2.4 KB · Views: 361 Upvote 0
LucaMs said: 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. Click to expand...
aeric Expert Licensed User Longtime User Feb 2, 2025 #18 I also have created MinimaList b4xlib which work similarly to KeyValueStore but with many extra methods such as sorting. [B4X] MinimaListUtils Version : 3.00 A utility class to manipulate a simple List of Map to do basic CRUD. Treat it as some kind of a NoSQL for key-value pairs. It is suitable for small demo if you don't want to use SQL database. Depends on: RandomAccessFile Note: You can use File.ReadBytes and File.WriteBytes to... www.b4x.com Upvote 0
I also have created MinimaList b4xlib which work similarly to KeyValueStore but with many extra methods such as sorting. [B4X] MinimaListUtils Version : 3.00 A utility class to manipulate a simple List of Map to do basic CRUD. Treat it as some kind of a NoSQL for key-value pairs. It is suitable for small demo if you don't want to use SQL database. Depends on: RandomAccessFile Note: You can use File.ReadBytes and File.WriteBytes to... www.b4x.com