summaryrefslogtreecommitdiff
path: root/tests/it_dbi.t
diff options
context:
space:
mode:
authorChristian Schneider2012-05-21 23:09:40 +0000
committerChristian Schneider2012-05-21 23:09:40 +0000
commit8b2713167a7dbc6979458a835fa1eb3b0ee43d0b (patch)
tree642bf53fe4eabee6c3634273eabdf237d9e8c4bf /tests/it_dbi.t
parent70889fde2ffa8c747b0a11d2712c4642b6c19b83 (diff)
downloaditools-8b2713167a7dbc6979458a835fa1eb3b0ee43d0b.tar.gz
itools-8b2713167a7dbc6979458a835fa1eb3b0ee43d0b.tar.bz2
itools-8b2713167a7dbc6979458a835fa1eb3b0ee43d0b.zip
More tests for it_dbi::store() behaviour
Diffstat (limited to 'tests/it_dbi.t')
-rwxr-xr-xtests/it_dbi.t31
1 files changed, 26 insertions, 5 deletions
diff --git a/tests/it_dbi.t b/tests/it_dbi.t
index 1ae479f..e988fa8 100755
--- a/tests/it_dbi.t
+++ b/tests/it_dbi.t
@@ -13,7 +13,7 @@ $dbi->query('create temporary table it_dbi_test (
primary key(ID)
);');
-$record = new it_dbi($db + array('table' => "it_dbi_test"));
+$record = new it_dbi($db + array('table' => "it_dbi_test"));
$record->insert(array('x' => 42, 'foo' => null));
$record->insert(array('foo' => "bar"));
@@ -236,24 +236,45 @@ foreach ($record as $dummy_rec)
$count++;
is($count, 2, "Iterator reused");
-$record->store(array('ID' => 5, 'x' => 6));
+$GLOBALS['debug_sqllog'] = true;
+@$record->store(array('ID' => 5, 'x' => 6));
+like(
+ $record->_sqllog[1]['query'],
+ "REPLACE",
+ "store => REPLACE for new entries"
+);
$record->clear();
-$record->read(5);
+@$record->read(5);
is(
$record->x,
6,
"saving with store"
);
-$record->store(array('ID' => 5, 'x' => 7));
+$record->_sqllog = array();
+@$record->store(array('ID' => 5, 'x' => 7));
+like(
+ $record->_sqllog[1]['query'],
+ "UPDATE",
+ "store => UPDATE for existing entries"
+);
$record->clear();
-$record->read(5);
+@$record->read(5);
is(
$record->x,
7,
"updating with store"
);
+$record->_sqllog = array();
+@$record->store(array('ID' => 5, 'x' => 7));
+is(
+ $record->_sqllog[1]['query'],
+ null, # Only SELECT, no UPDATE
+ "Optimized away UPDATE with same values"
+);
+$GLOBALS['debug_sqllog'] = false;
+
# Test field localization feature
$dbi->query('create temporary table it_dbi_testlocalized (