From 32a0aad7204837fd51d28f43cbb4477afe77449a Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 23 Jan 2019 13:50:32 +1300 Subject: [PATCH 1/2] =?UTF-8?q?FIX:=20Boolean=20=E2=80=99t=E2=80=99/?= =?UTF-8?q?=E2=80=98f=E2=80=99=20strings=20need=20to=20be=20coerced=20to?= =?UTF-8?q?=20int=20properly.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/PostgreSQLQuery.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/code/PostgreSQLQuery.php b/code/PostgreSQLQuery.php index d372d3c..9d658b0 100644 --- a/code/PostgreSQLQuery.php +++ b/code/PostgreSQLQuery.php @@ -80,7 +80,11 @@ class PostgreSQLQuery extends Query $record[$k] = $v; $type = pg_field_type($this->handle, $i); if (isset(self::$typeMapping[$type])) { - settype($record[$k], self::$typeMapping[$type]); + if ($type === 'bool' && $record[$k] === 't') { + $record[$k] = 1; + } else { + settype($record[$k], self::$typeMapping[$type]); + } } } From fd27c17a80025f1048a231aac01ae8a8d37801cb Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Wed, 23 Jan 2019 22:19:26 +1300 Subject: [PATCH 2/2] =?UTF-8?q?MINOR:=20Add=20comment=20to=20explain=20?= =?UTF-8?q?=E2=80=98f=E2=80=99=20coercion.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to https://github.com/silverstripe/silverstripe-postgresql/pull/93 --- code/PostgreSQLQuery.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/code/PostgreSQLQuery.php b/code/PostgreSQLQuery.php index 9d658b0..0b96c61 100644 --- a/code/PostgreSQLQuery.php +++ b/code/PostgreSQLQuery.php @@ -82,6 +82,8 @@ class PostgreSQLQuery extends Query if (isset(self::$typeMapping[$type])) { if ($type === 'bool' && $record[$k] === 't') { $record[$k] = 1; + + // Note that boolean 'f' will be converted to 0 by this } else { settype($record[$k], self::$typeMapping[$type]); }