Android Question ExecQuerySingleResult generates Invalid double: "null"

Gary Milne

Active Member
Licensed User
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.
 

mc73

Well-Known Member
Licensed User
An alternative to Erel's code, in the particular query, could be
B4X:
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
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
Thanks all, that did the trick.
 
Top