Android Question Why is there no Cursor.GetBoolean("ColName")?

Widget

Well-Known Member
Licensed User
Longtime User
SQLite has a boolean data type.
Why doesn't B4A have a Cursor.GetBoolean("ColName") method?
 

Widget

Well-Known Member
Licensed User
Longtime User
"SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true)."

From

https://www.sqlite.org/datatype3.html#section_2_1

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

TIA
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Thank you for your explanation.
I understood.

Then it would be nice
B4X:
Cursor.GetBooleanFromInt("Field")

Would make automatic conversion: 1 for true and 0 for false
 
Upvote 0

Widget

Well-Known Member
Licensed User
Longtime User
There is no "getBoolean" in the native Cursor API.

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.

Thanks.
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
I Agree.
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.

Thanks.
I Agree.
 
Upvote 0
Top