B4J Library [B4X] KVS2 / KeyValueStore 2 - Simple & Powerful Local Datastore

Status
Not open for further replies.

leitor79

Active Member
Licensed User
Longtime User
Hi,

I have a question: how is that v2 is faster than 1.01, being the case that 1.01 uses sql1.2 and v2 uses sql 1.3, which uses resulsets, that aren't more powerful than cursors? It would be true to say that v1.01 is better for certain type of data? (for example, if I only store text and numbers and not other type of objects)

Regards,
 

jaraiza

Active Member
Licensed User
Longtime User
Sorry if I ask something obvious, but I haven't find anything related. The "string" should be unique between applications, or the name can conflict with another app?

I mean, can I use 'Starter.kvs.Put("time", DateTime.Now)' in all my apps, or should I use 'Starter.kvs.Put("app1_time", DateTime.Now)' and 'app2_Starter.kvs.Put("time", DateTime.Now)' in another app?

Thanks!
 

vk7krj

Member
Licensed User
Hi, a rank beginner here. I downloaded the KeyValueStore zip file for B4A from the link on the first page of this thread, unzipped it and copied AndroidManifest.xml to the libraries folder, but the help says to copy the .jar file as well- but there isn't one in the zip file. When I try to refresh the libraries, it says it can't find the jar file- reasonable, as there isn't one- where can I find the associated .jar file for this library please?

Thanks, Ken.
 

vk7krj

Member
Licensed User
Thanks for the prompt reply Manfred, I have done that & B4A now sees it ok.

Ken.
 

vk7krj

Member
Licensed User
Hi Again, yet more stuff I don't understand- it seems I have a lot of trouble with the concepts of Object Oriented programming.

I am now getting the error-

Error description: Array expected.
Occurred on line: 49
Fuel_datastore.Initialize(File.DirApp, "Fuel_datastore")
Word: (

The code is here-

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    If StateManager.RestoreState(Activity, "Main", 0) = False Then
        Fuel_datastore.Initialize(File.DirApp, "Fuel_datastore")
        current_fuel = 0
        odo = 0
        old_odo = 0
        total_fuel = 0
        total_odo = 0
        start_odo = 0
        oa_consumption = 0
        current_consumption = 0
        Fuel_datastore.PutSimple("oa_consumption", oa_consumption)
        Fuel_datastore.PutSimple("current_consumption", current_consumption)
        Fuel_datastore.PutSimple("total_fuel", total_fuel)
        Fuel_datastore.PutSimple("start_odo", start_odo)
        Fuel_datastore.PutSimple("old_odo", old_odo)
    End If
    Activity.LoadLayout("fuellayout")
        OdometerEntry.Text = "0"
        FuelEntry.Text = "0"
    Calculate_click

I have also declared Fuel_datastore As KeyValueStore in Process_Globals and have searched the forum & read the tutorials and cannot find a solution (or perhaps didn't recognise it?) - please, what am I doing wrong?

Without the KeyValueStore class, the app does exactly what I want it to, I just don't have persistent data storage.

Thanks, Ken.
 

panagiotisden2

Active Member
Licensed User
Longtime User
Hello, I just received this log from a user
It seems that kvs caused a force close
I don't have problems in a lot of devices I tested my app. Any help here?

B4X:
Java.lang.RuntimeException: Unable to start service com.orionapps.zerodot.bglistener@420c0cf0 with Intent { cmp=com.orionapps.zerodot/.bglistener }: java.lang.RuntimeException: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2885)
    at android.app.ActivityThread.access$2100(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1418)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5299)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:206)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at com.orionapps.zerodot.bglistener.handleStart(bglistener.java:101)
    at com.orionapps.zerodot.bglistener.onStartCommand(bglistener.java:69)
    at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2868)
    ... 10 more
Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
    at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
    at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
    at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
    at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
    at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:829)
    at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:814)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:709)
    at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:684)
    at anywheresoftware.b4a.sql.SQL.Initialize(SQL.java:37)
    at com.orionapps.zerodot.keyvaluestore._initialize(keyvaluestore.java:156)
    at com.orionapps.zerodot.bglistener._service_start(bglistener.java:519)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
    ... 14 more
 

ilan

Expert
Licensed User
Longtime User
Umm default kvs location? I did not change anything I just used the example

cloudkvs? https://www.b4x.com:51041/cloudkvs?

 

Mahares

Expert
Licensed User
Longtime User
No, its a local db, kvs2 not cloudkvs
The below line located in most likely your Starter service module tells you where the kvs file is saved:
kvs.Initialize(File.DirDefaultExternal, "datastore2")
If you want it where you can more easily see it, you can save it here:
kvs.Initialize(File.DirRootExternal, "datastore2")
 

Wolfgang Trageiser

Member
Licensed User
Longtime User
can i use 3 or more KVS2-objects like:

Sub Process_Globals
Public kvs_systemdata As KeyValueStore
Public kvs_userdata As KeyValueStore
Public kvs_defaultdata As KeyValueStore
End Sub
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…