]> granicus.if.org Git - php/commitdiff
Test PDO::beginTransaction and PDO::rollBack.
authorDan Scott <dbs@php.net>
Sat, 5 Mar 2005 21:03:12 +0000 (21:03 +0000)
committerDan Scott <dbs@php.net>
Sat, 5 Mar 2005 21:03:12 +0000 (21:03 +0000)
ext/pdo/tests/pdo_017.inc [new file with mode: 0755]
ext/pdo_odbc/tests/pdo_017.phpt [new file with mode: 0755]

diff --git a/ext/pdo/tests/pdo_017.inc b/ext/pdo/tests/pdo_017.inc
new file mode 100755 (executable)
index 0000000..7c198a4
--- /dev/null
@@ -0,0 +1,32 @@
+<?php # vim:ft=php
+
+require_once('pdo.inc');
+
+set_sql('create',  'CREATE TABLE test(id INT NOT NULL PRIMARY KEY, val VARCHAR(10))');
+set_sql('insert1', "INSERT INTO test VALUES(1, 'A')"); 
+set_sql('insert2', "INSERT INTO test VALUES(2, 'B')"); 
+set_sql('insert3', "INSERT INTO test VALUES(3, 'C')");
+set_sql('select',  'SELECT COUNT(*) FROM test');
+set_sql('delete',  'DELETE FROM test');
+
+function countRows($DB, $action) {
+    global $SQL;
+    $stmt = $DB->query($SQL['select']);
+    $res = $stmt->fetchSingle();
+    return "Counted $res rows after $action.\n";
+}
+
+$DB->exec($SQL['create']);
+$DB->exec($SQL['insert1']); 
+$DB->exec($SQL['insert2']); 
+$DB->exec($SQL['insert3']); 
+
+echo countRows($DB, 'insert');
+
+$DB->beginTransaction();
+$DB->exec($SQL['delete']); 
+echo countRows($DB, 'delete');
+$DB->rollBack();
+
+echo countRows($DB, 'rollback');
+?>
diff --git a/ext/pdo_odbc/tests/pdo_017.phpt b/ext/pdo_odbc/tests/pdo_017.phpt
new file mode 100755 (executable)
index 0000000..5221c3d
--- /dev/null
@@ -0,0 +1,21 @@
+--TEST--
+PDO_ODBC: PDO::beginTransaction / PDO::rollBack
+--SKIPIF--
+<?php # vim:ft=php
+require_once('skipif.inc'); ?>
+--FILE--
+<?php
+
+require_once('connection.inc');
+require_once('prepare.inc');
+
+require_once($PDO_TESTS . 'pdo_017.inc');
+
+?>
+===DONE===
+<?php exit(0); ?>
+--EXPECT--
+Counted 3 rows after insert.
+Counted 0 rows after delete.
+Counted 3 rows after rollback.
+===DONE===