From 305fa5f80db7691597abc607020622e7c065eaed Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Tue, 28 Feb 2023 14:46:49 +0100 Subject: Revert "special handling of boolean columns (accept false as value without warning)" This reverts commit efeb9c4a97668672f8aaa263e4937461f0b1b725. --- it_dbi.class | 5 ----- test/it_dbi.t | 16 ++++++++-------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/it_dbi.class b/it_dbi.class index 6e34002..c9cef54 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -956,11 +956,6 @@ function _get_field_info() $this->_convertfunc[$name] = $field['_convertfunc']; $this->_escapefunc[$name] = $field['_escapefunc']; } - else if ($field['Type'] == 'tinyint(1)') - { - $this->_convertfunc[$name] = 'boolval'; - $this->_escapefunc[$name] = 'it_dbi::escape_bool'; - } else if (preg_match('/^(tiny|small|medium|)int|^float|^double$/', $field['Type'])) $this->_convertfunc[$name] = it::match('int', $field['Type']) ? "intval" : "floatval"; } diff --git a/test/it_dbi.t b/test/it_dbi.t index 0305166..ff0303a 100755 --- a/test/it_dbi.t +++ b/test/it_dbi.t @@ -45,8 +45,8 @@ try { is(it::match('syntax', $e->getMessage()), 'syntax', "Syntax error triggers error"); } -$record->insert(['x' => 42, 'y' => 0.0001, 'z' => 0, 'foo' => null, 'flag' => true]); -$record->insert(['foo' => "bar", 'y' => 1e-10, 'z' => 0, 'flag' => false]); +$record->insert(['x' => 42, 'y' => 0.0001, 'z' => 0, 'foo' => null, 'flag' => 1]); +$record->insert(['foo' => "bar", 'y' => 1e-10, 'z' => 0, 'flag' => 0]); $record->insert(['x' => 64738, 'y' => 1, 'z' => 0, 'foo' => "q'uux"]); is( @@ -67,9 +67,9 @@ is( [1, 42, 0.0001, null], "read" ); -is($record->flag, true, "read true boolean"); +ok(!!$record->flag, "read true boolean"); $record->read(2); -is($record->flag, false, "read false boolean"); +ok(!$record->flag, "read false boolean"); is( $record->select(), @@ -517,17 +517,17 @@ static function _write_preprocess($data) $record = new my_dbi_test; $record->delete(['WHERE TRUE' ]); -$record->upsert(['ID' => 1, 'x' => 42, 'y' => 2.5, 'foo' => ['value' => "a"], 'flag' => false]); +$record->upsert(['ID' => 1, 'x' => 42, 'y' => 2.5, 'foo' => ['value' => "a"], 'flag' => 0]); $record->read(1); is($record->x, 42, 'value of x after reading with _read_postprocess'); -is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'z' => NULL, 'foo' => '{"value":"a"}', 'flag' => false], 'data after reading with _read_postprocess'); +is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'z' => NULL, 'foo' => '{"value":"a"}', 'flag' => 0], 'data after reading with _read_postprocess'); is($record->foo, ['value' => "a"], 'field after reading with _read_postprocess'); $record2 = new it_dbi_test; $record2->read(1); is($record2->x, 43, 'raw value of x after writing with _write_preprocess'); -is($record2->_data, ["ID" => 1, "x" => 43, 'y' => 2.5, 'z' => NULL, 'foo' => '{"value":"a"}', 'flag' => false], 'raw data after writing with _write_preprocess'); +is($record2->_data, ["ID" => 1, "x" => 43, 'y' => 2.5, 'z' => NULL, 'foo' => '{"value":"a"}', 'flag' => 0], 'raw data after writing with _write_preprocess'); $record->update(['foo' => ['value' => "b"]]); -is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'z' => NULL, 'foo' => '{"value":"b"}', 'flag' => false], 'raw data after updating with _write_preprocess'); +is($record->_data, ["ID" => 1, "x" => 42, 'y' => 2.5, 'z' => NULL, 'foo' => '{"value":"b"}', 'flag' => 0], 'raw data after updating with _write_preprocess'); is($record->foo, ['value' => "b"], 'field data after updating with _write_preprocess'); -- cgit v1.2.3