Annotation of embedaddon/php/ext/pdo_mysql/tests/bug_44454.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Bug #44454 (Unexpected exception thrown in foreach() statement)
3: --SKIPIF--
4: <?php
5: if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
6: require dirname(__FILE__) . '/config.inc';
7: require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8: PDOTest::skip();
9: ?>
10: --FILE--
11: <?php
12: require dirname(__FILE__) . '/config.inc';
13: require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
14: $db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
15:
16: function bug_44454($db) {
17:
18: try {
19:
20: $db->exec('DROP TABLE IF EXISTS test');
21: $db->exec('CREATE TABLE test(a INT, b INT, UNIQUE KEY idx_ab (a, b))');
22: $db->exec('INSERT INTO test(a, b) VALUES (1, 1)');
23:
24: $stmt = $db->query('SELECT a, b FROM test');
25: printf("... SELECT has returned %d row...\n", $stmt->rowCount());
26: while ($row = $stmt->fetch()) {
27: try {
28: printf("... INSERT should fail...\n");
29: $db->exec('INSERT INTO test(a, b) VALUES (1, 1)');
30: } catch (Exception $e) {
31: printf("... STMT - %s\n", var_export($stmt->errorCode(), true));
32: printf("... PDO - %s\n", var_export($db->errorInfo(), true));
33: }
34: }
35:
36: $db->exec('DROP TABLE IF EXISTS test');
37: $db->exec('CREATE TABLE test(a INT, b INT, UNIQUE KEY idx_ab (a, b))');
38: $db->exec('INSERT INTO test(a, b) VALUES (1, 1)');
39:
40: } catch (Exception $e) {
41: printf("... While error %s\n", $e->getMessage()); ;
42: }
43:
44: $stmt = $db->query('SELECT a, b FROM test');
45: printf("... SELECT has returned %d row...\n", $stmt->rowCount());
46: foreach ($stmt as $row) {
47: try {
48: printf("... INSERT should fail...\n");
49: $db->exec('INSERT INTO test(a, b) VALUES (1, 1)');
50: } catch (Exception $e) {
51: printf("... STMT - %s\n", var_export($stmt->errorCode(), true));
52: printf("... PDO - %s\n", var_export($db->errorInfo(), true));
53: }
54: }
55:
56: }
57:
58: $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
59:
60: print "Native Prepared Statements\n";
61: $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0);
62: bug_44454($db);
63:
64: print "\nEmulated Prepared Statements\n";
65: $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
66: bug_44454($db);
67:
68: print "done!";
69: ?>
70: --CLEAN--
71: <?php
72: require dirname(__FILE__) . '/mysql_pdo_test.inc';
73: $db = MySQLPDOTest::factory();
74: $db->exec('DROP TABLE IF EXISTS test');
75: ?>
76: --XFAIL--
77: For some reason the exception gets thrown at the wrong place
78: --EXPECTF--
79: Native Prepared Statements
80: ... SELECT has returned 1 row...
81: ... INSERT should fail...
82: ... STMT - '00000'
83: ... PDO - array (
84: 0 => '23000',
85: 1 => 1062,
86: 2 => 'Duplicate entry \'1-1\' for key %s',
87: )
88: ... SELECT has returned 1 row...
89: ... INSERT should fail...
90: ... STMT - '00000'
91: ... PDO - array (
92: 0 => '23000',
93: 1 => 1062,
94: 2 => 'Duplicate entry \'1-1\' for key %s',
95: )
96:
97: Emulated Prepared Statements
98: ... SELECT has returned 1 row...
99: ... INSERT should fail...
100: ... STMT - '00000'
101: ... PDO - array (
102: 0 => '23000',
103: 1 => 1062,
104: 2 => 'Duplicate entry \'1-1\' for key %s',
105: )
106: ... SELECT has returned 1 row...
107: ... INSERT should fail...
108: ... STMT - '00000'
109: ... PDO - array (
110: 0 => '23000',
111: 1 => 1062,
112: 2 => 'Duplicate entry \'1-1\' for key %s',
113: )
114: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>