a boolean question on sqlite

Ricky D

Well-Known Member
Licensed User
Longtime User
How do we handle saving & retrieving boolean values from an sqlite database?

I am assuming I have to declare the type as DB_INTEGER

What does sqlite expect for true and false?

Is there any code I can see?

regards, Ricky
 

Ricky D

Well-Known Member
Licensed User
Longtime User
sqlite on android doesn't have that

sqlite on android only has

BLOB, INTEGER, REAL & TEXT according to dbutils

I created my db using dbutils.

I couldn't create one outside B4A that would work.

regards, Ricky
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I've done this by using a column with an INTEGER data type.
I store a 0 for False and a 1 for True.

Then in my B4A code i do something like this:

B4X:
Dim IntegerToBoolean() As Boolean
IntegerToBoolean=Array As Boolean(False, True)

' to get a Boolean value from the query:
MyBoolean=IntegerToBoolean(Cursor1.GetInt("TheIntegerColumnName"))

Martin.
 
Upvote 0

Ricky D

Well-Known Member
Licensed User
Longtime User
That should work!

:sign0142:

Thanks Martin.

cheers, Ricky
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi,

Is there also an easy way to convert a Boolean to an Int for saving in SQLite or do I have to build If...Then for every Checkbox?

Best regards,
André
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I already figure it out. I use:
B4X:
Sub BooleanToInt(Check As Boolean) As Int
    If (Check) Then
        Return 1
    Else
        Return 0
    End If
End Sub

Best regards,
André
 
Upvote 0
Top