Bug? SQL null on ExecQueryAsync

EnriqueGonzalez

Expert
Licensed User
Longtime User
hello!

An strage error happens when the below code is executed, the error is when you pass a Null value in params. when you pass an empty array it goes okey, i do not have any problem with that but in the tooltip for execQueryAsync there is an example passing a Null value.


Code: Copy
public Sub fillCmb(query As String,params() As String,cmb As ComboBox)
    Dim sf As Object = sql.ExecQueryAsync("SQL",query,params) 'here line 16

    wait for (sf) SQL_QueryComplete (Success As Boolean, rs As ResultSet)

this happens with:
JSQL: 1.5
DB: SQL SERVER 2014
B4J: 6.01

SQL is initialized correctly.


Error:

Waiting for debugger to connect...
Program started.
Error occurred on line: 16
java.lang.NullPointerException
at anywheresoftware.b4a.keywords.Common.ArrayToList(Common.java:648)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:228)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:61)
at b4j.example.clscomprobantesimple$ResumableSub_fillForm.resume(clscomprobantesimple.java:192)
at b4j.example.clscomprobantesimple._fillform(clscomprobantesimple.java:177)
at b4j.example.clscomprobantesimple._initialize(clscomprobantesimple.java:74)
at b4j.example.main._btnfacturas_click(main.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:613)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA$1.run(BA.java:215)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Thread.java:748)[/CODE]
 
Thank you Erel! indeed was not a bug.

but it raises a question!

in the official JRDC2 project the type
Code: Copy
    Type DBCommand (Name As String, Parameters() As Object)
uses an array os strings

and the execQuery is waiting for a list
Code: Copy
    Dim rs As ResultSet = con.ExecQuery2(Main.rdcConnector1.GetCommand(cmd.Name), cmd.Parameters)

This means that it will fail if it receives an instruction wihout parameters.

correct?
 
This means that it will fail if it receives an instruction wihout parameters.
At least according to my notes, it will. Here are the notes I made for modifying jRDC2:
'Modified ExecuteQuery2 and ExecuteBatch2 to check cmd.Parameters for Null. This removed a
' Null pointer exception error message in case cmd.Parameters was Null. Also call
' ExecQuery/ExecNonQuery when no cmd.Parameters are given.
 
thank you OliverA, mine JRDC failed too, had to check for null,

Code: Copy
    If cmd.Parameters = Null Then
        Dim rs As ResultSet = con.ExecQuery(Main.rdcConnector1.GetCommand(cmd.Name))
    Else
        Dim rs As ResultSet = con.ExecQuery2(Main.rdcConnector1.GetCommand(cmd.Name), cmd.Parameters)
    End If
 
I do one additional check
Code: Copy
' Call correct Query function based on cmd.Parameters setting
If cmd.Parameters = Null Or cmd.Parameters.Length = 0 Then
    rs = con.ExecQuery(Main.rdcConnector1.GetCommand(cmd.Name))
Else
    rs = con.ExecQuery2(Main.rdcConnector1.GetCommand(cmd.Name), cmd.Parameters)
End If

even tough ExecQuery2 works with a parameter with 0 length. That was/is just me being weird. The kicker is that in the source of the SQL library (https://github.com/AnywhereSoftware/B4J_SQL/blob/master/src/anywheresoftware/b4j/objects/SQL.java), ExecQuery just calls ExecQuery2 via
Code: Copy
ExecQuery2(Query, null)
. I guess B4A/B4J null in this case <> Java null. Looking at it now, I might as well take the length check out and call ExecQuery2 directly (instead of indirectly via ExecQuery).
 
lol you are right!

return ExecQuery2(Query, null);

all the queries are executed from here and it uses null... i thought i was calling some wrapped especial methods from java.
 
Back
Top