SQLite Forum

Bug when converting string to boolean?
Login
Please don't compare a string to a boolean.  It doesn't mean anything and anyone reading your code won't understand it.  The fact you can do it at all is a nasty hack.  Figure out what you really mean, and write code to do that.

In terms of what SQLite actually does, it tries to turn the string you give it into a number, working character by character from the left, and it stops when it reaches any character which can't be part of that number.  So, starting with the value <code>0</code> ...

* <code>'123'</code> multiplies by 10 and adds 1, multiplies by 10 and adds 2, multiplies by 10 and adds 3.
* <code>'1x'</code>  multiplies by 10 and adds 1, then stops because <code>'x'</code> can't be part of a number
* <code>'x1'</code> stops because <code>'x'</code> can't be part of a number

Once SQLite has the number it then evaluates it as boolean, either <code>FALSE</code> or <code>TRUE</code>.