Android Question Strange behavior of null value returned from database

MrKim

Well-Known Member
Licensed User
Longtime User
I am trying to figure out how to get consistent results from Null. jtds database driver returns something "sort of like" null - but different. I just need to consistently test for null.
See results below:

ActiveEmp.PassWord has been initialized:
upload_2019-5-11_0-18-2.png

Set to B4A Null:
upload_2019-5-11_0-19-36.png


Set to Null returned by database/driver:
upload_2019-5-11_0-22-25.png
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
I am trying to figure out how to get consistent results from Null. jtds database driver returns something "sort of like" null - but different. I just need to consistently test for null.
See results below:

ActiveEmp.PassWord has been initialized:
View attachment 80291
Set to B4A Null:
View attachment 80292

Set to Null returned by database/driver:
View attachment 80293

Can you show the SQL that gets the data into Crsr?
Are you aware of the coalesce function?

RBS
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You can probably use the ifnull function:
B4X:
ActiveEmp.Password =Starter.SQL1.ExecQuerySingleResult2("SELECT ifnull(Emp_BadgeNum,'') FROM mytable WHERE user LIKE ?", _
    Array As String("%MrKim%"))  'note 2 single quotes after Emp_BadgeNum,
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Can you show the SQL that gets the data into Crsr?
Are you aware of the coalesce function?

RBS
Good Idea. Out of habit I try to keep server side processing to a minimum and do busy work like this on the WS/tablet where there is plenty of spare CPU power but in this case probably not.

You can probably use the ifnull function:
B4X:
ActiveEmp.Password =Starter.SQL1.ExecQuerySingleResult2("SELECT ifnull(Emp_BadgeNum,'') FROM mytable WHERE user LIKE ?", _
    Array As String("%MrKim%"))  'note 2 single quotes after Emp_BadgeNum,
in TSQL it is IsNull, not IfNull but as with Coalesce, also a good idea, thanks.
 
Last edited:
Upvote 0
Top