Widget Well-Known Member Licensed User Longtime User Jun 28, 2016 #1 SQLite has a boolean data type. Why doesn't B4A have a Cursor.GetBoolean("ColName") method?
Eme Fibonacci Well-Known Member Licensed User Longtime User Jun 29, 2016 #2 "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 Upvote 0
"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
Widget Well-Known Member Licensed User Longtime User Jun 29, 2016 #3 Eme Fibonacci said: "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 Click to expand... 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. Code: 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 Code: 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. Code: 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 said: "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 Click to expand... 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. Code: 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 Code: 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. Code: if Cursor.GetBoolean("Active") then 'This code is much easier to read and more compatible with other databases ... end if TIA
Erel B4X founder Staff member Licensed User Longtime User Jun 29, 2016 #4 There is no "getBoolean" in the native Cursor API. Upvote 0
Eme Fibonacci Well-Known Member Licensed User Longtime User Jun 29, 2016 #5 Thank you for your explanation. I understood. Then it would be nice Code: Cursor.GetBooleanFromInt("Field") Would make automatic conversion: 1 for true and 0 for false Upvote 0
Thank you for your explanation. I understood. Then it would be nice Code: Cursor.GetBooleanFromInt("Field") Would make automatic conversion: 1 for true and 0 for false
Widget Well-Known Member Licensed User Longtime User Jun 29, 2016 #6 Erel said: There is no "getBoolean" in the native Cursor API. Click to expand... 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
Erel said: There is no "getBoolean" in the native Cursor API. Click to expand... 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.
Eme Fibonacci Well-Known Member Licensed User Longtime User Jun 29, 2016 #7 I Agree. Widget said: 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. Click to expand... I Agree. Upvote 0
I Agree. Widget said: 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. Click to expand... I Agree.