HI, All
How to get String or Int values from SQLite for sure and null-error-free ?
I have done such subs for DBUtils, are they correct or maybe there is more clear solution ?
How to get String or Int values from SQLite for sure and null-error-free ?
I have done such subs for DBUtils, are they correct or maybe there is more clear solution ?
B4X:
'return "", if no string data
Sub GetStringFromSQL (SQL As SQL, req As String) As String
Dim a As String
Try
a = SQL.ExecQuerySingleResult(req)
Catch
Return ""
End Try
If a = Null Then
Return ""
Else If a.ToLowerCase = "null" Then
Return ""
Else If a = "" Then
Return ""
Else
Return a
End If
End Sub
'return -1, if no number data
Sub GetIntFromSQL (SQL As SQL, req As String) As Int
Dim a As String
Dim Const NegativeRes As Int = -1
Try
a = SQL.ExecQuerySingleResult(req)
Catch
Return NegativeRes
End Try
If a = Null Then
Return NegativeRes
Else If a.ToLowerCase = "null" Then
Return NegativeRes
Else If IsNumber(a) = False Then
Return NegativeRes
Else
Dim res As Int = a
Return res
End If
End Sub