Android Question [Closed] Any change to SQL library recently?

aeric

Expert
Licensed User
Longtime User
From what I can remember, ExecuteQuery2 worked with Array As Object parameters.
Now it throws out error unless I use Array As String.

EDIT: It works fine in B4J.

B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=SQL.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Dim DB As SQL
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
    #If B4J
    xui.SetDataFolder("SQL")
    #End If
    
    If File.Exists(xui.DefaultFolder, "data.db") = False Then
        #If B4J
        DB.InitializeSQLite(xui.DefaultFolder, "data.db", True)
        #Else
        DB.Initialize(xui.DefaultFolder, "data.db", True)
        #End If
        DB.ExecNonQuery("CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)")
        DB.ExecNonQuery2("INSERT INTO test (name) SELECT ?", Array As Object("Test Value 1"))
        DB.ExecNonQuery2("INSERT INTO test (name) SELECT ?", Array As Object("Test Value 2"))
        DB.ExecNonQuery2("INSERT INTO test (name) SELECT ?", Array As Object("Test Value 3"))
    Else
        #If B4J
        DB.InitializeSQLite(xui.DefaultFolder, "data.db", False)
        #Else
        DB.Initialize(xui.DefaultFolder, "data.db", False)
        #End If
    End If
    ' This line cause error in B4A but not B4J
    Dim res As ResultSet = DB.ExecQuery2("SELECT id FROM test WHERE name = ?", Array As Object("Test Value 2"))
    ' This line is working fine
    'Dim res As ResultSet = DB.ExecQuery2("SELECT id FROM test WHERE name = ?", Array As String("Test Value 2"))
    Do While res.NextRow
        xui.MsgboxAsync($"id=${res.GetInt("id")}"$, "FOUND")
    Loop
    res.Close
End Sub

*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
anywheresoftware.b4a.sql.SQL:ExecQuery2, [SELECT id FROM test WHERE name = ?, [Ljava.lang.Object;@575c04d]
Error occurred on line: 33 (B4XMainPage)
java.lang.IllegalArgumentException: method anywheresoftware.b4a.sql.SQL.ExecQuery2 argument 2 has type java.lang.String[], got java.lang.Object[]
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:144)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
at b4a.example.sql.b4xmainpage._b4xpage_created(b4xmainpage.java:45)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1055)
at b4a.example.sql.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1060)
at b4a.example.sql.b4xpagesmanager._showpage(b4xpagesmanager.java:417)
at b4a.example.sql.b4xpagesmanager._addpage(b4xpagesmanager.java:245)
at b4a.example.sql.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:259)
at b4a.example.sql.b4xpagesmanager._initialize(b4xpagesmanager.java:165)
at b4a.example.sql.main._activity_create(main.java:415)
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:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at b4a.example.sql.main.afterFirstLayout(main.java:105)
at b4a.example.sql.main.access$000(main.java:17)
at b4a.example.sql.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:794)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
 

Attachments

  • SQL.zip
    13.2 KB · Views: 230
Last edited:

aeric

Expert
Licensed User
Longtime User
I think I just confused with B4J or I never aware that all the while it is actually not allowed to use Array As Object for ExecuteQuery2.

 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…