-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
greg(a)svn.wikimedia.org wrote:
Force inserted bools to be ints, per Tim's
suggestion on bug 15148.
This should be fine for now as Postgres uses SMALLINTs for BOOLs, to
match MySQLs BOOL/TINYINT aliasing and subsequent MW coding assumptions.
It's possible this will cause bad effects if inserted values are called
in a boolean context when they are going into a non-SMALLINT column, but we can handle
those as they come up.
[snip]
function addQuotes( $s ) {
if ( is_null( $s ) ) {
return 'NULL';
+ } else if ( is_bool( $s ) ) {
+ return intval( $s );
It probably wouldn't hurt to do this on general principle in the base
class. Some quick background:
PHP's boolean type interpolates to string as:
true -> "1"
false -> ""
MySQL's "bool" column type is an alias to "tinyint" (which we use,
as
"bool" didn't exist in earlier MySQL versions), where you generally
store 1 or 0. However if you stick '' in there it gets automatically
interpreted as 0... (does this happen in MySQL's strict mode, though?)
PostgreSQL has a "bool" data type also, which seems to accept a variety
of values:
http://www.postgresql.org/docs/8.1/static/datatype-boolean.html
none of which are "". ;)
It's also much whingier about its numeric types, and won't let us insert
an empty string, which is what a boolean false interpolates to.
Now, most of the time we explicitly use 1 and 0 when storing boolean
values in MediaWiki, like:
'page_is_new' => ($lastRevision === 0) ? 1 : 0,
'page_is_redirect' => $rt !== NULL ? 1 : 0,
But it'd be nice not to break if people forget and use a genuine bool...
for that matter it'd be nice to be able to do that as a matter of course. ;)
- -- brion
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla -
http://enigmail.mozdev.org
iEYEARECAAYFAkit6J0ACgkQwRnhpk1wk45XUgCgy2BL/ggyfKmHMXbauzXGPq3Q
pwAAoI2tKNJKhuU7o90pbFG9w5S/IEfR
=NrDM
-----END PGP SIGNATURE-----