diff options
Diffstat (limited to 'test/it_dbi.t')
-rwxr-xr-x | test/it_dbi.t | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/test/it_dbi.t b/test/it_dbi.t index 2b5b0c5..2a601b6 100755 --- a/test/it_dbi.t +++ b/test/it_dbi.t @@ -27,6 +27,7 @@ $dbi->query("create temporary table it_dbi_test ( $autoid, x int, y float, + z bigint, foo varchar(42), flag boolean, $dyncols, @@ -44,9 +45,9 @@ try { is(it::match('syntax', $e->getMessage()), 'syntax', "Syntax error triggers error"); } -$record->insert(['x' => 42, 'y' => 0.0001, 'foo' => null, 'flag' => 1]); -$record->insert(['foo' => "bar", 'y' => 1e-10, 'flag' => 0]); -$record->insert(['x' => 64738, 'y' => 1, 'foo' => "q'uux"]); +$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( $record->ID, @@ -192,6 +193,22 @@ is( "update with function" ); +$value = pow(2, 24) + 1; +$record->update(['x' => $value]); +is($record->x, $value, "update 32bit integer without float representation"); +is($record->select(['x' => $value]), 1, "select 32bit integer without float representation"); + +$value = pow(2, 53) + 1; +$record->update(['z' => $value]); +is($record->z, $value, "update 64bit integer without double representation"); +is($record->select(['z' => $value]), 1, "select 64bit integer without double representation"); + +$record->update(['foo' => "10", 'x' => 10]); +is($record->select(['x <' => 9]), 0, "always use integer comparision for int field"); +is($record->select(['x <' => '9']), 0, "always use integer comparision for int field"); +is($record->select(['foo <' => 9]), 1, "always use string comparision for varchar field"); +is($record->select(['foo <' => '9']), 1, "always use string comparision for varchar field"); + $record->update(['foo' => "00"]); $rand = $record->x; is ( @@ -253,6 +270,14 @@ foreach (new it_dbi_test as $id => $record) is($count, 3, "Iterator without select"); $count = 0; +foreach (new it_dbi($db + ['table' => 'it_dbi_test']) as $id => $record) +{ + $count++; + is($record->_key, $id, "Iterator id $id (it_dbi object)"); +} +is($count, 3, "Iterator without select (it_dbi_object)"); + +$count = 0; foreach (new it_dbi_test(['foo <>' => ""]) as $id => $record) { $count++; @@ -489,14 +514,14 @@ $record->delete(['WHERE TRUE' ]); $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, 'foo' => '{"value":"a"}', 'flag' => 0], '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, 'foo' => '{"value":"a"}', 'flag' => 0], '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, 'foo' => '{"value":"b"}', 'flag' => 0], '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'); |