Android Question Update SQLite table with WhereFields

Declan

Well-Known Member
Licensed User
Longtime User
I am trying to UPDATE records in a SQLite table.
I need to update all the records in table "user" where the field "IDNo" is equal to "MyIDNo".
This code creates an error - I think there is a syntax problem with "WhereFields"?
B4X:
Dim ListOfMaps As List
    ListOfMaps.Initialize
        Dim m As Map
        m.Initialize
        m.Put("ID", MyID)
        m.Put("FirstName", MyFirstName)
        m.Put("LastName", MyLastName)
        m.Put("IDNo", MyIDNo)
        m.Put("School", MySchool)
        m.Put("StudentNo", MyStudentNo)
        m.Put("Grade", MyGrade)
        m.Put("Add1", MyAdd1)
        m.Put("Add2", MyAdd2)
        m.Put("Town", MyTown)
        m.Put("Province", MyProvince)
        m.Put("PhoneNo", MyPhoneNo)
        m.Put("Email", MyEmail)
        m.Put("parentphone", ParentPhone)
        m.Put("parentemail", ParentEmail)
        m.Put("parenteid", ParentID)
        m.Put("DateRegsitered", DateReg)
        ListOfMaps.Add(m)

    Dim WhereFields As Map
    WhereFields.Initialize
    WhereFields.Put("IDNo", MyIDNo)
    DBUtils.UpdateRecord2(SQL0, "user", ListOfMaps, WhereFields)
    ListOfMaps.Clear
 

Declan

Well-Known Member
Licensed User
Longtime User
You should post the error you get.

Maybe ID is declared as auto increment or you have "constraints exceptions" (fields IDno, parenteid?)
This is the error:
B4X:
Error occurred on line: 140 (DBUtils)
java.lang.ClassCastException: java.util.ArrayList cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
    at anywheresoftware.b4a.objects.collections.Map.getSize(Map.java:112)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:337)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:4848)
    at android.view.View$PerformClick.run(View.java:20262)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:194)
    at android.app.ActivityThread.main(ActivityThread.java:5637)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
ops, sorry, I don't use DBUtils...

java.lang.ClassCastException: java.util.ArrayList cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap

the command (UpdateRecord2) requires a Map as parameter, not a List.
DBUtils.UpdateRecord2(SQL0, "user", ListOfMaps, WhereFields)
should be:
DBUtils.UpdateRecord2(SQL0, "user", m, WhereFields)
 
Upvote 0
Top