Thanks for the reference.
Yes SQLite stores Boolean data type as NUMERIC, 0 or 1. But you can still use "Boolean" as a data type for a column when creating a table as shown in the example below.
B4X:
CREATE TABLE t1(
Active Boolean,
t TEXT, -- text affinity by rule 2
nu NUMERIC, -- numeric affinity by rule 5
i INTEGER, -- integer affinity by rule 1
r REAL, -- real affinity by rule 4
no BLOB -- no affinity by rule 3
);
If there was no Boolean data type, then I'd agree with you. We would have to test for True/False using
B4X:
if Cursor.GetInt("Active")=1 then
...
end if
But since there is a Boolean data type in SQLite, why can't we have a Cursor.GetBoolean("Active") that returns True or False depending on whether the "Active" column value is 1 or 0? This would make changing from one database to another much easier since other databases have a logical Boolean data type and we wouldn't have to change all references of "=1" or "=0" etc to True or False when switching databases.
B4X:
if Cursor.GetBoolean("Active") then 'This code is much easier to read and more compatible with other databases
...
end if
Then it seems to me Google was cutting corners when writing the API and relied on the programmer to sort things out in code by referencing 1 and 0 instead of True/False. Most programmers would expect a Boolean to return True/False and not 1/0.
Maybe you could consider adding Cursor.GetBoolean() in some future version of B4A? (no rush)
In the mean time I will write my own Sub GetBoolean(Cursor, ColName) to return True/False for the column name so my code is easier to read and not dependent on idiosyncrasies of the underlying database.
Then it seems to me Google was cutting corners when writing the API and relied on the programmer to sort things out in code by referencing 1 and 0 instead of True/False. Most programmers would expect a Boolean to return True/False and not 1/0.
Maybe you could consider adding Cursor.GetBoolean() in some future version of B4A? (no rush)
In the mean time I will write my own Sub GetBoolean(Cursor, ColName) to return True/False for the column name so my code is easier to read and not dependent on idiosyncrasies of the underlying database.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.