I don't think it's necessary. The same query, with 2 numeric parameters, works fine about 25500 times, then crashes, for no reason (I checked the query and the values, everything is fine).Post relevant code?
Yes.Before I testdoes it happen in release mode as well?
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
#AdditionalJar: sqlite-jdbc-3.39.3.0
Sub Process_Globals
Dim DB As SQL
End Sub
Sub AppStart (Args() As String)
Log("** Test Begin **")
RunStressTest
StartMessageLoop
End Sub
Sub RunStressTest
If File.Exists(File.DirApp, "Data.db") = False Then
DB.InitializeSQLite(File.DirApp, "Data.db", True)
Else
DB.InitializeSQLite(File.DirApp, "Data.db", False)
End If
Dim Query As String = "SELECT ? + ?"
For i = 0 To 30000
Dim Result As Long
Result = DB.ExecQuerySingleResult2(Query, Array As Int(0, i))
Log(Result)
Next
DB.Close
Log("** Test End **")
End Sub
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
#AdditionalJar: sqlite-jdbc-3.39.3.0
Sub Process_Globals
Dim DB As SQL
End Sub
Sub AppStart (Args() As String)
Log("** Test Begin **")
RunStressTest
StartMessageLoop
End Sub
Sub RunStressTest
If File.Exists(File.DirApp, "Data.db") = False Then
DB.InitializeSQLite(File.DirApp, "Data.db", True)
Dim Query As String = "CREATE TABLE Test (id INTEGER)"
DB.ExecNonQuery(Query)
Dim Query As String = "INSERT INTO Test (id) VALUES (100)"
DB.ExecNonQuery(Query)
Else
DB.InitializeSQLite(File.DirApp, "Data.db", False)
End If
Dim Query As String = "SELECT id + ? + ? FROM Test"
For i = 0 To 100000
Dim Result As Long
Result = DB.ExecQuerySingleResult2(Query, Array As Int(1000, i))
Log(i & " -> " & Result)
Next
DB.Close
Log("** Test End **")
End Sub
'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
#AdditionalJar: sqlite-jdbc-3.39.3.0
Sub Process_Globals
Dim DB As SQL
End Sub
Sub AppStart (Args() As String)
Log("** Test Begin **")
RunStressTest
StartMessageLoop
End Sub
Sub RunStressTest
If File.Exists(File.DirApp, "Data.db") = False Then
DB.InitializeSQLite(File.DirApp, "Data.db", True)
Dim Query As String = "CREATE TABLE Test (id INTEGER)"
DB.ExecNonQuery(Query)
Dim Query As String = "INSERT INTO Test (id) VALUES (100)"
DB.ExecNonQuery(Query)
Else
DB.InitializeSQLite(File.DirApp, "Data.db", False)
End If
Dim Query As String = "SELECT id + ? + ? FROM Test"
For i = 0 To 100000
Dim Result As Long
If i = 10 Then
Result = DB.ExecQuerySingleResult2(Query, Array As Int(1000))
Else
Result = DB.ExecQuerySingleResult2(Query, Array As Int(1000, i))
End If
Log(i & " -> " & Result)
Next
DB.Close
Log("** Test End **")
End Sub
Result = DB.ExecQuerySingleResult2(Query, Array As Int(1000))
Waiting for debugger to connect...
Program started.
** Test Begin **
0 -> 1100
1 -> 1101
2 -> 1102
3 -> 1103
4 -> 1104
5 -> 1105
6 -> 1106
7 -> 1107
8 -> 1108
9 -> 1109
Error occurred on line: 32 (Main)
java.lang.NullPointerException
at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.base/java.lang.Double.parseDouble(Double.java:543)
at b4j.example.main._runstresstest(main.java:121)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:629)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:234)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:167)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:111)
at anywheresoftware.b4a.shell.ShellBA.raiseEvent2(ShellBA.java:100)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:98)
at b4j.example.main.main(main.java:29)
Very strange.I made some tests and wasn't able to reproduce. It looks like a bug on your side Luca...
'This crashes only after about 25500 times.
Result = DB.ExecQuerySingleResult(Query)
'No crashes (same query, of course, consecutive lines of code)
' Dim RS As ResultSet
' RS = DB.ExecQuery(Query)
' Do While RS.NextRow
' Result = RS.GetInt2(0)
' Loop
' RS.Close
#AdditionalJar: sqlite-jdbc-3.39.3.0
Using ExecQuery, the Do While loop is not executed and the function returns the default value of Result.Result = DB.ExecQuerySingleResult(Query)
You still did not explain why it did not return a result. What did you find in your data that made it failExecQuerySingleResult did not return any results
There are no records whose fields contain the values requested in the query.You still did not explain why it did not return a result. What did you find in your data that made it fail
In this case I thought there was all ?I think Luca has explained the golden rule of databases, do not assume a query will return a result, check if it does before using the returned value.
Now, you are cooking. Your post #10 does not show a parameterized query. That is why I asked the question. It is settled now.SELECT * FROM MyTable WHERE Field1 = 10 AND Field2 = 20
Based on your statement, we should try to avoid the use of ExecSingleResultdo not assume a query will return a result, check if it does before using the returned value.
Now, you are cooking. Your post #10 does not show a parameterized query. That is why I asked the question. It is settled now.
I don't think it's necessary. The same query, with 2 numeric parameters, works fine about 25500 times, then crashes, for no reason (I checked the query and the values, everything is fine).
I solved using ExecQuery, which I think takes longer.
Yes, unless you are very sure about your data.Based on your statement, we should try to avoid the use of ExecSingleResult
Where is the code for the SQL library located. Maybe we can look at it and see if the ExecSingleResult can be modified to prevent such error without knowing the content of your data in the table.n this case I thought there was all
I don't think it's necessary.Where is the code for the SQL library located. Maybe we can look at it and see if the ExecSingleResult can be modified to prevent such error without knowing the content of your data in the table.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?