Android Question Display of Sqlite null values

dlfallen

Active Member
Licensed User
Longtime User
When I display a table in Sqlite (using DBUtils, for example) records containing a null value in a field will display as "null". Is there any option to display a blank field instead?
 

dlfallen

Active Member
Licensed User
Longtime User
Yes, that cleans the table up nicely -- but the column header now reads ifnull(col1,'') instead of just col1. Nice table, but ugly column titles.
 
Upvote 0

DouglasNYoung

Active Member
Licensed User
Longtime User
Obviously, next alternatives are to:
a) rename the column titles by
Select ifnull(col1, '' ") as Column1 , etc....
or
b) do the ifnull comparison/replacement where you ouput the results.

Douglas
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Erel, why not simply adding an if to reading with dbUtils? After all, an empty string is what user expects to view if a null appears.
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Erel, why not simply adding an if to reading with dbUtils? After all, an empty string is what user expects to view if a null appears.

Er no..! This is the way all DBs work, changing this behaviour could lead to other problems.

If the DB is under user control you should indicate that they should nulls should be empty strings.

Something like this : http://stackoverflow.com/questions/6598881/how-to-make-a-column-of-text-empty-instead-of-null

Although you may have to recreate the table from scratch which could be a pita.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Upvote 0

dlfallen

Active Member
Licensed User
Longtime User
OK, the answer was quite simple, really. My program contained these two lines of code (taken from SQLite Viewer):
B4X:
h = DBUtils.ExecuteHtml(Main.SQL, Query , Null, RecLimit, False)
WebView1.LoadHtml(h)

I just inserted a replacement function in between these two lines, so now it reads:
B4X:
h = DBUtils.ExecuteHtml(Main.SQL, Query , Null, RecLimit, False)
h = h.Replace(Null,"")
WebView1.LoadHtml(h)

And Bob's your Uncle!
 
  • Like
Reactions: eps
Upvote 0
Top