save/load boolean seems failing on 2.1

On r2.1, saving a booleanValue, to a SQLite table on disk. , seems that always is re-loaded as false
for example: the saving line looks like:

row.Column("multiplayer").BooleanValue = globals.multiplayer

globals.multiplayer is true at saving time.

When loading the line looks like

globals.Multiplayer = rs.Column("Multiplayer").BooleanValue

is always loaded as false.

Reinstalled and tested on r2 where the code for saving was

and the load

the boolean is loaded as true if saved as true.

Any suggestion to go on with 2.1 and saving the day.

can you check what actually is written to the SQLite DB (e.g. using the commandline interface sqlite3)? The documentation states

I may try, but never used the commandline interface sqlite3, could you give an idea?
But with the Xojo debbuger the rowset shows all booleans as nil

that would indicate that the problem occurs when writing the data. How did you accomplish this using a DatabaseRow?

My test failed with another bug way earlier when writing using a DatabaseRow, the remaining seem to work fine:

[code]
//intit
Dim db As New SQLiteDatabase
db.Connect
db.ExecuteSQL(“CREATE TABLE t (id INT PRIMARY KEY, b1 BOOLEAN, b2 BOOLEAN);”)

//insert
Dim row As New DatabaseRow
row.Column(“b1”).BooleanValue = True
row.Column(“b2”).BooleanValue = False
//oh my! the following gives ‘near “)”: syntax error’
'db.AddRow(“t”, row)
db.ExecuteSQL(“INSERT INTO t(b1, b2) VALUES(‘True’, ‘False’);”) //this does not test writing

//read
Dim rs As RowSet
rs = db.SelectSQL(“SELECT * FROM t;”)
//…using RowSet
System.DebugLog rs.Column(“b1”).NativeValue + rs.Column(“b2”).NativeValue
System.DebugLog Str(rs.Column(“b1”).BooleanValue) + Str(rs.Column(“b2”).BooleanValue)
//…using DatabaseRow
For Each r As DatabaseRow In rs
System.DebugLog r.Column(“b1”).NativeValue + r.Column(“b2”).NativeValue
System.DebugLog Str(r.Column(“b1”).BooleanValue) + Str(r.Column(“b2”).BooleanValue)
Break //look in debugger
Next r

//edit
rs.MoveToFirstRow
rs.EditRow
rs.Column(“b1”).BooleanValue = True
rs.Column(“b2”).BooleanValue = False
rs.SaveRow

//read again
rs = db.SelectSQL(“SELECT * FROM t;”)
//…using RowSet
System.DebugLog rs.Column(“b1”).NativeValue + rs.Column(“b2”).NativeValue
System.DebugLog Str(rs.Column(“b1”).BooleanValue) + Str(rs.Column(“b2”).BooleanValue)
//…using DatabaseRow
For Each r As DatabaseRow In rs
System.DebugLog r.Column(“b1”).NativeValue + r.Column(“b2”).NativeValue
System.DebugLog Str(r.Column(“b1”).BooleanValue) + Str(r.Column(“b2”).BooleanValue)
Break //look in debugger
Next r[/code]

I posted a Feedback and they already answered:

[quote]
This issue has been reproduced based on the information provided.
A workaround might be to use an Integer field instead and use 0 to represent False and 1 to represent True.
This is pretty much how SQLite implements its Boolean data type.[/quote]

So, the solution for now, is changing all booleans to integers.

thanks. If you file issues discussed in the Forum in Feedback, please also post a link to it: <https://xojo.com/issue/58470>

this bug was already found by @Dale Arends and filed as <https://xojo.com/issue/58403>

Change

row.Column("multiplayer").BooleanValue = globals.multiplayer

to

row.Column("multiplayer").IntegerValue = if(globals.multiplayer,1,0)

Edit: from my tests, pulling the information from the Database with BooleanValue works ok

[quote=465364:@Alberto DePoo]Change

row.Column("multiplayer").BooleanValue = globals.multiplayer

to

row.Column("multiplayer").IntegerValue = if(globals.multiplayer,1,0)

Edit: from my tests, pulling the information from the Database with BooleanValue works ok[/quote]

Thanks Alberto, this morning I realize that this was the workaround but I decided to take day off.

By the way, Alberto, [quote]Edit: from my tests, pulling the information from the Database with BooleanValue works ok[/quote]

I tested and it not works on me.

when saving must change

// row.Column("IsDead").BooleanValue= u.isDead

to

row.Column("IsDead").IntegerValue = if(u.isDead,1,0)

when loading change

// u.isDead = rs.Column("IsDead").BooleanValue

to

u.isDead = if (rs.Column("IsDead").IntegerValue=1,true,false)

x Tables x booleans in each table

Did you get an error or always False too?

I downloaded Robin’s example from your Feedback case.
Only changed this:

'row.Column("Flag").BooleanValue = flag row.Column("Flag").IntegerValue = if(flag, 1, 0)
and it works too (this is another test from what I did before), in other words I didn’t change the ShowData method that includes:

str(row.Column("Flag").BooleanValue))

[quote=465343:@Enric Herrera]I posted a Feedback and they already answered:

So, the solution for now, is changing all booleans to integers.[/quote]
Another bug for a dot release 2019r2.2

No Alberto this do not work.
If you save to disk

row.Column("IsDead").BooleanValue= u.isDead // where u.isDead is true

and then load from disk as

u.isDead = if (rs.Column("IsDead").IntegerValue=1,true,false)

the bool is loaded always as false.
You need to save it as

row.Column("IsDead").IntegerValue = if(u.isDead,1,0)

Robin’s exemple do not save to disk file and reload from disk.

unlikely they’ll do a 2.2
check the betas channel :slight_smile:

edited : to clarify

[quote=465406:@Norman Palardy]unlikely they’ll do a 2.2
check the betas channel :)[/quote]
How?

Usually just the wrong value on the boolean, several times Xojo crashed in the debbuger checking the rowset contents

sorry I meant that for Martin who is a member of the pre-release group as well

[quote=465405:@Enric Herrera]No Alberto this do not work.
If you save to disk

row.Column("IsDead").BooleanValue= u.isDead // where u.isDead is true

and then load from disk as

u.isDead = if (rs.Column("IsDead").IntegerValue=1,true,false)

the bool is loaded always as false.
You need to save it as

row.Column("IsDead").IntegerValue = if(u.isDead,1,0)

Robin’s exemple do not save to disk file and reload from disk.[/quote]
Sorry, I think I was not clear enough. The save to database (BooleanValue) is broken, so you need:

row.Column("IsDead").IntegerValue = if(u.isDead,1,0)

to save to database, once is there (you can open the sqlite file with another program and see 1 or 0 as expected, but with the original code you will see that nothing was written to the boolean column.
When you load from the sqlite database you can use:

u.isDead = rs.Column(ïsDead").BooleanValue

and will get the correct value.

Robin’s example does create and save the information into Desktop/example.sqlite and pulls the information from that file to show the values on the listbox.

Yes, only the save is broken, this simplify the workaround at 50%

This bug can silently break things (and damage data in databases) so it is a priority to fix this. And also check the behavior of row.Column(name).BooleanValue in the other supported databases.