Store boolean values as integers with SQLite
authorJackmcbarn <jackmcbarn@gmail.com>
Tue, 17 Sep 2013 22:54:59 +0000 (18:54 -0400)
committerJackmcbarn <jackmcbarn@gmail.com>
Wed, 18 Sep 2013 00:03:22 +0000 (20:03 -0400)
Since SQLite doesn't have a boolean type, and doesn't enforce types, make
sure booleans get stored as integers, to prevent undesirable behavior,
such as false values being stored as empty strings.

Change-Id: I2a96065826412fa25f98ec298d806e73ebe155ba

includes/db/DatabaseSqlite.php

index 6692fa4..a8270bf 100644 (file)
@@ -709,6 +709,8 @@ class DatabaseSqlite extends DatabaseBase {
        function addQuotes( $s ) {
                if ( $s instanceof Blob ) {
                        return "x'" . bin2hex( $s->fetch() ) . "'";
+               } elseif ( is_bool( $s ) ) {
+                       return (int)$s;
                } elseif ( strpos( $s, "\0" ) !== false ) {
                        // SQLite doesn't support \0 in strings, so use the hex representation as a workaround.
                        // This is a known limitation of SQLite's mprintf function which PDO should work around,