Annotation of embedaddon/php/ext/pdo_mysql/tests/pdo_mysql_commit.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: MySQL PDO->commit()
3: --SKIPIF--
4: <?php
5: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7: MySQLPDOTest::skip();
8: $db = MySQLPDOTest::factory();
9: if (false == MySQLPDOTest::detect_transactional_mysql_engine($db))
10: die("skip Transactional engine not found");
11: ?>
12: --FILE--
13: <?php
14: require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
15: $db = MySQLPDOTest::factory();
16: MySQLPDOTest::createTestTable($db, MySQLPDOTest::detect_transactional_mysql_engine($db));
17:
18: try {
19: if (true !== ($tmp = $db->beginTransaction())) {
20: printf("[001] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
21: }
22:
23: // DDL will issue an implicit commit
24: $db->exec(sprintf('DROP TABLE IF EXISTS test_commit'));
25: $db->exec(sprintf('CREATE TABLE test_commit(id INT) ENGINE=%s', MySQLPDOTest::detect_transactional_mysql_engine($db)));
26: if (true !== ($tmp = $db->commit())) {
27: printf("[002] No commit allowed? [%s] %s\n",
28: $db->errorCode(), implode(' ', $db->errorInfo()));
29: }
30:
31: // pdo_transaction_transitions should check this as well...
32: // ... just to be sure the most basic stuff really works we check it again...
33: if (1 !== ($tmp = $db->getAttribute(PDO::ATTR_AUTOCOMMIT)))
34: printf("[003] According to the manual we should be back to autocommit mode, got %s/%s\n",
35: gettype($tmp), var_export($tmp, true));
36:
37: if (true !== ($tmp = $db->beginTransaction()))
38: printf("[004] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
39:
40: $db->exec("INSERT INTO test(id, label) VALUES (100, 'z')");
41:
42: if (true !== ($tmp = $db->commit()))
43: printf("[005] No commit allowed? [%s] %s\n",
44: $db->errorCode(), implode(' ', $db->errorInfo()));
45:
46: // a weak test without unicode etc. - lets leave that to dedicated tests
47: $stmt = $db->query('SELECT id, label FROM test WHERE id = 100');
48: $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
49: if (!isset($rows[0]['label']) || ($rows[0]['label'] != 'z')) {
50: printf("[006] Record data is strange, dumping rows\n");
51: var_dump($rows);
52: }
53:
54: // Ok, lets check MyISAM resp. any other non-transactional engine
55: // pdo_mysql_begin_transaction has more on this, quick check only
56: $db = MySQLPDOTest::factory();
57: MySQLPDOTest::createTestTable($db, 'MyISAM');
58:
59: if (true !== ($tmp = $db->beginTransaction()))
60: printf("[007] Expecting true, got %s/%s\n", gettype($tmp), $tmp);
61:
62: $db->exec("INSERT INTO test(id, label) VALUES (100, 'z')");
63: if (true !== ($tmp = $db->commit()))
64: printf("[008] No commit allowed? [%s] %s\n",
65: $db->errorCode(), implode(' ', $db->errorInfo()));
66:
67: // a weak test without unicode etc. - lets leave that to dedicated tests
68: $stmt = $db->query('SELECT id, label FROM test WHERE id = 100');
69: $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
70: if (!isset($rows[0]['label']) || ($rows[0]['label'] != 'z')) {
71: printf("[009] Record data is strange, dumping rows\n");
72: var_dump($rows);
73: }
74:
75: } catch (PDOException $e) {
76: printf("[002] %s, [%s] %s\n",
77: $e->getMessage(),
78: $db->errorCode(), implode(' ', $db->errorInfo()));
79: }
80:
81: print "done!";
82: --CLEAN--
83: <?php
84: require dirname(__FILE__) . '/mysql_pdo_test.inc';
85: $db = MySQLPDOTest::factory();
86: $db->exec('DROP TABLE IF EXISTS test_commit');
87: MySQLPDOTest::dropTestTable($db);
88: ?>
89: --EXPECT--
90: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>