]> granicus.if.org Git - php/commitdiff
for the transactions test case, detect working transactions before attempting to...
authorWez Furlong <wez@php.net>
Sat, 9 Jul 2005 04:28:45 +0000 (04:28 +0000)
committerWez Furlong <wez@php.net>
Sat, 9 Jul 2005 04:28:45 +0000 (04:28 +0000)
Additional ugliness required because mysql does stupid stuff like this:

mysql> CREATE TABLE foo (id int) TYPE=innodb;
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> SHOW CREATE TABLE foo;
CREATE TABLE `foo` (
  `id` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

In addition, BEGIN, COMMIT and ROLLBACK all succeed, even when no tables
support transactions.

ext/pdo/tests/pdo_017.phpt
ext/pdo/tests/pdo_test.inc

index 36bdb029c8fa3acc4dd7541f02b3dd26ca89ecdc..def132e5692e38eaf0d1eb6e843bf998fda63a49 100644 (file)
@@ -7,15 +7,19 @@ $dir = getenv('REDIR_TEST_DIR');
 if (false == $dir) die('skip no driver');
 require_once $dir . 'pdo_test.inc';
 PDOTest::skip();
-/* TODO:
+
 $db = PDOTest::factory();
 try {
   $db->beginTransaction();
 } catch (PDOException $e) {
-  # check sqlstate to see if transactions
-  # are not implemented; if so, skip
+  die('skip no working transactions: ' . $e->getMessage());
+}
+
+if ($db->getAttribute(PDO_ATTR_DRIVER_NAME) == 'mysql') {
+       if (false === PDOTest::detect_transactional_mysql_engine($db)) {
+               die('skip your mysql configuration does not support working transactions');
+       }
 }
-*/
 ?>
 --FILE--
 <?php
@@ -23,7 +27,7 @@ require getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
 $db = PDOTest::factory();
 
 if ($db->getAttribute(PDO_ATTR_DRIVER_NAME) == 'mysql') {
-       $suf = ' Type=InnoDB';
+       $suf = ' Type=' . PDOTest::detect_transactional_mysql_engine($db);
 } else {
        $suf = '';
 }
index 13ab1c1d5f0cf0979d3dc050b735d86ecf7fc94f..79b2a9d168faf5ccf480024160b08a4ae48854ce 100644 (file)
@@ -43,6 +43,15 @@ class PDOTest {
                        die("skip " . $e->getMessage());
                }
        }
+
+       static function detect_transactional_mysql_engine($db) {
+               foreach ($db->query('show engines') as $row) {
+                       if ($row[1] == 'YES' && ($row[0] == 'INNOBASE' || $row[0] == 'BDB')) {
+                               return $row[0];
+                       }
+               }
+               return false;
+       }
 }