Error when using ExecuteMemoryTable

WiLey2000

Member
Licensed User
Longtime User
When i try to run the code below, I get an error that - cur = SQL.ExecQuery(Query), from DBUtils Module needs to be Initialized first.

Heres my code:
B4X:
Sub InitializeCurrentWeek()
   Dim values() As String

   Activity.LoadLayout("AddTime")
   DisplayWeek.Initialize(Me, "DisplayWeek", 0)
   DisplayWeek.AddToActivity(pnlAddTime, 0, 10%y, 100%x, 22%y)
   DisplayWeek = DBUtils.ExecuteMemoryTable(sqlCWeek, "SELECT * FROM tblCurrentWeek", Null, 0)
      
      values = DisplayWeek.Get(0)
         Log(values(0))
   'DisplayWeek.LoadTableFromCSV(File.DirAssets, "tblCurrentWeekJobs.csv", True)
   
   DisplayWeek.SetColumnsWidths(Array As Int(130dip, 130dip, 130dip, 130dip, 130dip, 130dip, 130dip, 130dip))
   
   lblDisplayedWeek.Text = "Current Week"
   lblSelectedName.Text = sSelectedName
   lblEmployeeID.Text = sEmployeeID
   ChangeHeaders
End Sub


Here is error log:
B4X:
dbutils_executememorytable (B4A line: 138)
cur = SQL.ExecQuery(Query)
java.lang.RuntimeException: Object should first be initialized.
   at anywheresoftware.b4a.sql.SQL.checkNull(SQL.java:40)
   at anywheresoftware.b4a.sql.SQL.ExecQuery(SQL.java:94)
   at mcdal.timeclock.dbutils._executememorytable(dbutils.java:625)
   at mcdal.timeclock.main._initializecurrentweek(main.java:1075)
   at mcdal.timeclock.main._btnaddtime_click(main.java:405)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:158)
   at anywheresoftware.b4a.BA.raiseEvent(BA.java:154)
   at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:54)
   at android.view.View.performClick(View.java:3538)
   at android.view.View$PerformClick.run(View.java:14330)
   at android.os.Handler.handleCallback(Handler.java:608)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:154)
   at android.app.ActivityThread.main(ActivityThread.java:4977)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Object should first be initialized.

Thanks,

John
 

klaus

Expert
Licensed User
Longtime User
This post answers also a question from this post.

You have several problems:
- SQL not initialized as Erel already reported.

- You are misunderstanding the DBUtils.ExecutMemoryTable function.
ExecutMemoryTable load a database into a table in memory (a list of string arrays) and not into a Table class object.
There is no predefined routine to load a database into a Table class object you need to do it on your own.

You need to define where you want to save the database.
A database file cannot be accessed in the DirAssets folder you must copy your original database in another folder DirInternal, DirRootExternal etc.
The choice depends if you need access to it from outsides the program.

Then your database is somewhat special.
In the cvs file you have column headers like : 4/26/2012 0:00, 4/23/2012 0:00
In the database the column names are F1, F2 etc
and the first entry in the database are the headers like in the cvs file.
And then the next entries are the 'real' database entries.
You must take this into account when you manage the database data.

I think you should think about your data structure.
How many entries will your database have ?
Will the headers (cvs like) change with time ?
Depending on the data structure you should define the most suitable saving method. I'm not sure that a database is the best one but this depends on the answers to the above questions.

Best regards.
 
Upvote 0
Top