B4X:
Dim l_sSimpleValue As String = Null
Log($"l_sSimpleValue = ${l_sSimpleValue}"$)
If l_sSimpleValue <> Null Then
Log($"l_sSimpleValue <> Null"$)
Else
Log($"l_sSimpleValue = Null"$)
End If
If l_sSimpleValue.CompareTo(Null) = 0 Then
Log($"l_sSimpleValue.CompareTo(Null) = 0"$)
Else
Log($"l_sSimpleValue.CompareTo(Null) <> 0"$)
End If
Log output:
l_sSimpleValue = null
l_sSimpleValue <> Null
l_sSimpleValue.CompareTo(Null) = 0
P.S. The same in B4A and B4J.
Note 1: Really I discovered the problem when ported code from B4A to B4i.
l_sSimpleValue = ExecQuerySingleResult2, ExecQuerySingleResult ' return null
In B4A, B4J
If l_sSimpleValue <> Null Then ...
with null returned from ExecQuerySingleResult2, ExecQuerySingleResult to l_sSimpleValue gives true.
In B4i
If l_sSimpleValue <> Null Then ...
with null returned from ExecQuerySingleResult2, ExecQuerySingleResultto l_sSimpleValue gives false.
but if we assign Null to string value directly, the behavior in B4A, B4J, B4i the same (see. code and results above).
Note 2: According the documentation:
B4A, B4J: ExecQuerySingleResult2, ExecQuerySingleResult Returns Null if no results were found.
B4i: Returns an empty string if no value was found.
But really in B4i ExecQuerySingleResult2, ExecQuerySingleResult return null instead of empty string.
l_sSimpleValue = ExecQuerySingleResult2, ExecQuerySingleResult
Log($"l_sSimpleValue = ${l_sSimpleValue}"$)
Log output:
l_sSimpleValue = null
As a workaround I will try to use l_sSimpleValue.CompareTo(Null) = 0 instead of If l_sSimpleValue <> Null Then, but it will force me do a lot of changes to the code .
It would great to make behaviour of l_sSimpleValue <> Null and l_sSimpleValue.CompareTo(Null) = 0 equal, fix documentation for iSQL "Returns an empty string if no value was found." => "Returns Null if no results were found." or understand why ExecQuerySingleResult2, ExecQuerySingleResult return null (instead of empty string) and why this "null" is compared to Null in different way in B4A, B4J and B4i.