Gary Milne Active Member Licensed User Longtime User Nov 21, 2014 #1 I'm running a query against SQL to see if a record exists (so it can be updated). The query is quite simple and looks like "SELECT MAX (ShotNumber) FROM SESSION WHERE SessionNumber = 3 AND RallyNumber = 25" When it does not exist (which is quite common) then I get a java.lang.NumberFormatException: Invalid double: "null" Other B4A SQL routines will usually say something like "this is a sql exception not an error", but this error does not, so it concerns me. I have it in a Try Catch loop but if there is a better way I'd like to know what it is. Thanks for any responses.
I'm running a query against SQL to see if a record exists (so it can be updated). The query is quite simple and looks like "SELECT MAX (ShotNumber) FROM SESSION WHERE SessionNumber = 3 AND RallyNumber = 25" When it does not exist (which is quite common) then I get a java.lang.NumberFormatException: Invalid double: "null" Other B4A SQL routines will usually say something like "this is a sql exception not an error", but this error does not, so it concerns me. I have it in a Try Catch loop but if there is a better way I'd like to know what it is. Thanks for any responses.
DonManfred Expert Licensed User Longtime User Nov 21, 2014 #2 without seeing a code it is hard to help. i would suggest that you first try to check the amount of resulting rows (Recordcount >0) . And only if >0 then you assign the 0th element. To double-check you can check if cursor(0) <> null Upvote 0
without seeing a code it is hard to help. i would suggest that you first try to check the amount of resulting rows (Recordcount >0) . And only if >0 then you assign the 0th element. To double-check you can check if cursor(0) <> null
Erel B4X founder Staff member Licensed User Longtime User Nov 21, 2014 #3 Your code should be: Code: Dim res As String = SQL1.ExecQuerySingleResult(...) If res <> Null Then Dim value As Int = res ... End If Upvote 0
Your code should be: Code: Dim res As String = SQL1.ExecQuerySingleResult(...) If res <> Null Then Dim value As Int = res ... End If
mc73 Well-Known Member Licensed User Longtime User Nov 21, 2014 #4 An alternative to Erel's code, in the particular query, could be Code: SELECT ifnull(MAX (ShotNumber),0) FROM SESSION WHERE SessionNumber = 3 AND RallyNumber = 25 . This will return 0, if the field's value is null. Upvote 0
An alternative to Erel's code, in the particular query, could be Code: SELECT ifnull(MAX (ShotNumber),0) FROM SESSION WHERE SessionNumber = 3 AND RallyNumber = 25 . This will return 0, if the field's value is null.
Gary Milne Active Member Licensed User Longtime User Nov 22, 2014 #5 Thanks for those responses. I'm using an Int to capture the response but it makes sense that the response would be a string which can be converted to a different type. I'll try that tomorrow. Many thanks everyone who took the time. Upvote 0
Thanks for those responses. I'm using an Int to capture the response but it makes sense that the response would be a string which can be converted to a different type. I'll try that tomorrow. Many thanks everyone who took the time.
Gary Milne Active Member Licensed User Longtime User Nov 22, 2014 #6 Thanks all, that did the trick. Upvote 0