It would be great if B4X supported ternary operators so we could do inline if statements. Consider this scenario:
I have a SQLite database table that I want to store a boolean value in. SQLite doesn't support booleans, so I have to use an integer type for the field, then convert int values pulled from the database to boolean & vis-a-vis when saving values to the table. So one way to do this is:
However it would be much easier & more efficient if I could just write:
- Colin.
I have a SQLite database table that I want to store a boolean value in. SQLite doesn't support booleans, so I have to use an integer type for the field, then convert int values pulled from the database to boolean & vis-a-vis when saving values to the table. So one way to do this is:
B4X:
Private Sub dbStuff
...
Private boolVal = toBool(Cursor.GetInt("boolasint"))
....
SQL1.ExecNonQuery($"UPDATE table SET boolasint=${fromBool(boolVal)} WHERE..."$
End Sub
Private Sub toBool(val as Int) as Boolean
If val = 0 Then Return False Else Return True
End Sub
Private Sub fromBool(val as Boolean) as Int
If val Then Return 1 Else Return 0
End Sub
However it would be much easier & more efficient if I could just write:
B4X:
Private Sub sbStuff
...
Private boolVal = Cursor.GetInt("boolasint") = 0 ? False : True
....
SQL1.ExecNonQuery($"UPDATE table SET boolasint=${boolval = True ? 1 : 0} WHERE..."$
'(or even better)
SQL1.ExecNonQuery($"UPDATE table SET boolasint=${boolval ? 1 : 0} WHERE..."$
End Sub
- Colin.