PHP  
 PHP_7_3
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

Test Failure Report for ext/pdo_mysql/tests/pdo_mysql_exec.phpt ('MySQL PDO->exec(), affected rows')

Script

1: <?php
2:     
function exec_and_count($offset, &$db$sql$exp NULL) {
3:
4:         try {
5:
6:             
$ret $db->exec($sql);
7:             if (!
is_null($exp) && ($ret !== $exp)) {
8:                 
printf("[%03d] Expecting '%s'/%s got '%s'/%s when running '%s', [%s] %s\n",
9:                     
$offset$expgettype($exp), $retgettype($ret), $sql,
10:                     
$db->errorCode(), implode(' '$db->errorInfo()));
11:                 return 
false;
12:             }
13:
14:         } catch (
PDOException $e) {
15:             
printf("[%03d] '%s' has failed, [%s] %s\n",
16:                 
$offset$sql$db->errorCode(), implode(' '$db->errorInfo()));
17:             return 
false;
18:         }
19:
20:         return 
true;
21:     }
22:
23:     require_once(
dirname(__FILE__) . DIRECTORY_SEPARATOR 'mysql_pdo_test.inc');
24:     
$db MySQLPDOTest::factory();
25:     
MySQLPDOTest::createTestTable($dbMySQLPDOTest::detect_transactional_mysql_engine($db));
26:
27:     
/* affected rows related */
28:     
try {
29:
30:         
exec_and_count(2$db'DROP TABLE IF EXISTS test'0);
31:         
exec_and_count(3$dbsprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s'PDO_MYSQL_TEST_ENGINE), 0);
32:         
exec_and_count(4$db"INSERT INTO test(id, col1) VALUES (1, 'a')"1);
33:         
exec_and_count(5$db"INSERT INTO test(id, col1) VALUES (2, 'b'), (3, 'c')"2);
34:         
exec_and_count(6$db"UPDATE test SET id = 4 WHERE id = 3"1);
35:         
exec_and_count(7$db"INSERT INTO test(id, col1) VALUES (1, 'd') ON DUPLICATE KEY UPDATE id = 3"2);
36:         
exec_and_count(8$db"UPDATE test SET id = 5 WHERE id = 5"0);
37:         
exec_and_count(9$db"INSERT INTO test(id, col1) VALUES (5, 'e') ON DUPLICATE KEY UPDATE id = 6"1);
38:         
exec_and_count(10$db"REPLACE INTO test(id, col1) VALUES (5, 'f')"2);
39:         
exec_and_count(11$db"REPLACE INTO test(id, col1) VALUES (6, 'g')"1);
40:         
exec_and_count(12$db'DELETE FROM test WHERE id > 2'4);
41:         
exec_and_count(13$db'DROP TABLE test'0);
42:         
exec_and_count(14$db'SET @myvar = 1'0);
43:
44:         
exec_and_count(15$db'THIS IS NOT VALID SQL, I HOPE'false);
45:         
printf("[016] [%s] %s\n"$db->errorCode(), implode(' '$db->errorInfo()));
46:
47:         
exec_and_count(36$dbsprintf('CREATE TABLE test(id INT NOT NULL PRIMARY KEY, col1 CHAR(10)) ENGINE=%s'PDO_MYSQL_TEST_ENGINE), 0);
48:         
exec_and_count(37$db"INSERT INTO test(id, col1) VALUES (1, 'a')"1);
49:         
// Results may vary. Typically you will get 1. But the MySQL 5.1 manual states: Truncation operations do not return the number of deleted rows.
50:         // Don't rely on any return value!
51:         
exec_and_count(38$db'TRUNCATE TABLE test'NULL);
52:
53:     } catch (
PDOException $e) {
54:         
printf("[001] %s, [%s] %s\n",
55:             
$e->getMessage(),
56:             
$db->errorCode(), implode(' '$db->errorInfo()));
57:     }
58:
59:
60:     
/* CREATE, DROP, CALL SP and SF */
61:     
if (MySQLPDOTest::getServerVersion($db) > 50000) {
62:         
// let's try to play with stored procedures
63:         
try {
64:             
$ignore_exception true;
65:             
exec_and_count(18$db'DROP PROCEDURE IF EXISTS p'0);
66:             
exec_and_count(19$db'CREATE PROCEDURE p(OUT ver_param VARCHAR(255)) BEGIN SELECT VERSION() INTO ver_param; END;'0);
67:             
// we got this far without problems. If there's an issue from now on, its a failure
68:             
$ignore_exception false;
69:             
exec_and_count(20$db'CALL p(@version)'1);
70:             
$stmt $db->query('SELECT @version AS p_version');
71:             
$tmp $stmt->fetchAll(PDO::FETCH_ASSOC);
72:             if (
count($tmp) > || !isset($tmp[0]['p_version'])) {
73:                 
printf("[022] Data seems wrong, dumping\n");
74:                 
var_dump($tmp);
75:             } else {
76:                 
$p_version $tmp[0]['p_version'];
77:             }
78:
79:             
$stmt $db->query('SELECT VERSION() AS _version');
80:             
$tmp  $stmt->fetchAll(PDO::FETCH_ASSOC);
81:             if (
count($tmp) > || !isset($tmp[0]['_version'])) {
82:                 
printf("[023] Data seems wrong, dumping\n");
83:                 
var_dump($tmp);
84:             } else {
85:                 if (
$p_version !== $tmp[0]['_version']) {
86:                     
printf("[024] Found different version strings, SP returned '%s'/%s, SELECT returned '%s'/%s\n",
87:                         
$p_versiongettype($p_version),
88:                         
$tmp[0]['_version'], gettype($tmp[0]['_version']));
89:                 }
90:             }
91:             
exec_and_count(25$db'DROP PROCEDURE IF EXISTS p'0);
92:
93:         } catch (
PDOException $e) {
94:             
// ignore it, we might not have sufficient permissions
95:             
if (!$ignore_exception)
96:                 
printf("[021] %s, [%s] %s\n",
97:                     
$e->getMessage(),
98:                     
$db->errorCode(), implode(' '$db->errorInfo()));
99:         }
100:
101:         
// stored function
102:         
try {
103:             
$ignore_exception true;
104:             
exec_and_count(27$db'DROP FUNCTION IF EXISTS f'0);
105:             
exec_and_count(28$db'CREATE FUNCTION f( ver_param VARCHAR(255)) RETURNS VARCHAR(255) DETERMINISTIC RETURN ver_param;'0);
106:             
// we got this far without problems. If there's an issue from now on, its a failure
107:             
$ignore_exception false;
108:             
$stmt $db->query('SELECT f(VERSION()) AS f_version');
109:             
$tmp $stmt->fetchAll(PDO::FETCH_ASSOC);
110:             if (
count($tmp) > || !isset($tmp[0]['f_version'])) {
111:                 
printf("[029] Data seems wrong, dumping\n");
112:                 
var_dump($tmp);
113:             } else {
114:                 
$f_version $tmp[0]['f_version'];
115:             }
116:             
$stmt $db->query('SELECT VERSION() AS _version');
117:             
$tmp  $stmt->fetchAll(PDO::FETCH_ASSOC);
118:             if (
count($tmp) > || !isset($tmp[0]['_version'])) {
119:                 
printf("[030] Data seems wrong, dumping\n");
120:                 
var_dump($tmp);
121:             } else {
122:                 if (
$f_version !== $tmp[0]['_version']) {
123:                     
printf("[031] Found different version strings, SF returned '%s'/%s, SELECT returned '%s'/%s\n",
124:                         
$f_versiongettype($f_version),
125:                         
$tmp[0]['_version'], gettype($tmp[0]['_version']));
126:                 }
127:             }
128:             
exec_and_count(32$db'DROP FUNCTION IF EXISTS f'0);
129:
130:         } catch (
PDOException $e) {
131:             
// ignore it, we might not have sufficient permissions
132:             
if (!$ignore_exception)
133:                 
printf("[026] %s, [%s] %s\n",
134:                     
$e->getMessage(),
135:                     
$db->errorCode(), implode(' '$db->errorInfo()));
136:         }
137:     }
138:
139:     
// multi query
140:     
try {
141:
142:         
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES1);
143:         
$exp 0;
144:
145:         
$tmp = @$db->exec(sprintf('DROP TABLE IF EXISTS test; CREATE TABLE test(id INT) ENGINE=%s'PDO_MYSQL_TEST_ENGINE));
146:         if (
$exp !== $tmp)
147:             
printf("[034] Expecting %s/%s got %s/%s, [%s] %s\n",
148:                 
$expgettype($exp),
149:                 
$tmpgettype($tmp),
150:                 
$db->errorCode(), var_export($db->errorInfo(), true));
151:
152:         
// this is interesting: if we get sort of affected rows, what will happen now?
153:         
$tmp = @$db->exec('INSERT INTO test(id) VALUES (1); INSERT INTO test(id) VALUES (2)');
154:         
printf("[035] With emulated PS it works but makes no sense given that exec() returns sort of affected rows...\n");
155:
156:
157:     } catch (
PDOException $e) {
158:         
printf("[033] %s, [%s] %s\n",
159:             
$e->getMessage(),
160:             
$db->errorCode(), implode(' '$db->errorInfo()));
161:     }
162:     
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES0);
163:
164:     print 
"done!";
165:
?>
166:

Expected

Warning: PDO::exec(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'THIS IS NOT VALID SQL, I HOPE' at line 1 in %s on line %d
[016] [42000] 42000 1064 You have an error in your SQL syntax; check the manual that corresponds to your %s server version for the right syntax to use near 'THIS IS NOT VALID SQL, I HOPE' at line %d
[035] With emulated PS it works but makes no sense given that exec() returns sort of affected rows...
done!

Output

Warning: PDO::exec(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'THIS IS NOT VALID SQL, I HOPE' at line 1 in /var/php_gcov/PHP_7_3/ext/pdo_mysql/tests/pdo_mysql_exec.php on line 6
[016] [42000] 42000 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'THIS IS NOT VALID SQL, I HOPE' at line 1
[020] Expecting '1'/integer got '0'/integer when running 'CALL p(@version)', [00000] 00000  
[035] With emulated PS it works but makes no sense given that exec() returns sort of affected rows...
done!

Diff

003+ [020] Expecting '1'/integer got '0'/integer when running 'CALL p(@version)', [00000] 00000  

 

Generated at Thu, 14 Nov 2019 02:24:20 +0000 (11 hours ago)

Copyright © 2005-2019 The PHP Group
All rights reserved.