'return -2147483648, if no valid number data
Sub GetIntFromSQL (SQL As SQL, table As String, req As String) As Int
Dim Const NegativeRes As Int = -2147483648
If TableExists(SQL, table) = False Then
Log("GetIntFromSQL(" & table & ") does not exist")
Return NegativeRes
End If
Dim q As Int = SQL.ExecQuerySingleResult("SELECT count(*) FROM " & table)
If q = 0 Then
Return NegativeRes
End If
Dim a As String
Try
'req may be wrong syntax, dangerous
a = SQL.ExecQuerySingleResult(req)
Catch
Log("GetIntFromSQL(" & req & ").error = " & LastException)
Return NegativeRes
End Try
If a.ToLowerCase = "null" Then
Return NegativeRes
Else If a = Null Then
Return NegativeRes
Else If IsNumber(a) = False Then
Return NegativeRes
Else
Dim res As Int = a
Return res
End If
End Sub