Skip to content

Commit a3a0f37

Browse files
committed
Trigger exceptions for autocommit, commit, rollback and mysqli_stmt_attr_set
mysqli_report test cases for autocommit, commit, rollback and mysqli_stmt_attr_set Updated test case with no warning control case
1 parent 54435c9 commit a3a0f37

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

ext/mysqli/mysqli_api.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ PHP_FUNCTION(mysqli_autocommit)
169169
MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID);
170170

171171
if (mysql_autocommit(mysql->mysql, (my_bool)automode)) {
172+
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
172173
RETURN_FALSE;
173174
}
174175
RETURN_TRUE;
@@ -708,6 +709,7 @@ PHP_FUNCTION(mysqli_commit)
708709
#else
709710
if (FAIL == mysqlnd_commit(mysql->mysql, flags, name)) {
710711
#endif
712+
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
711713
RETURN_FALSE;
712714
}
713715
RETURN_TRUE;
@@ -1927,6 +1929,7 @@ PHP_FUNCTION(mysqli_rollback)
19271929
#else
19281930
if (FAIL == mysqlnd_rollback(mysql->mysql, flags, name)) {
19291931
#endif
1932+
MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql);
19301933
RETURN_FALSE;
19311934
}
19321935
RETURN_TRUE;
@@ -2297,6 +2300,7 @@ PHP_FUNCTION(mysqli_stmt_attr_set)
22972300
#else
22982301
if (FAIL == mysql_stmt_attr_set(stmt->stmt, attr, mode_p)) {
22992302
#endif
2303+
MYSQLI_REPORT_STMT_ERROR(stmt->stmt);
23002304
RETURN_FALSE;
23012305
}
23022306
RETURN_TRUE;

ext/mysqli/tests/mysqli_report.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ require_once('skipifconnectfailure.inc');
4949
printf("[009] select_db should have failed\n");
5050
// mysqli_store_result() and mysqli_use_result() cannot be tested, because one would need to cause an error inside the C function to test it
5151

52+
mysqli_multi_query($link, "SELECT 1; FOO;");
53+
mysqli_autocommit($link, true);
54+
mysqli_commit($link);
55+
mysqli_rollback($link);
56+
while(mysqli_more_results($link)) {
57+
mysqli_next_result($link);
58+
$res = mysqli_store_result($link);
59+
}
60+
mysqli_next_result($link);
61+
62+
$stmt = mysqli_prepare($link, "SELECT 1");
63+
mysqli_stmt_attr_set($stmt, MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_FOR_UPDATE);
5264

5365
// Check that none of the above would have caused any error messages if MYSQL_REPORT_ERROR would
5466
// not have been set. If that would be the case, the test would be broken.
@@ -65,6 +77,19 @@ require_once('skipifconnectfailure.inc');
6577
mysqli_real_query($link, "FOO");
6678
mysqli_select_db($link, "Oh lord, let this be an unknown database name");
6779

80+
mysqli_multi_query($link, "SELECT 1; FOO;");
81+
mysqli_autocommit($link, true);
82+
mysqli_commit($link);
83+
mysqli_rollback($link);
84+
while(mysqli_more_results($link)) {
85+
mysqli_next_result($link);
86+
$res = mysqli_store_result($link);
87+
}
88+
mysqli_next_result($link);
89+
90+
$stmt = mysqli_prepare($link, "SELECT 1");
91+
mysqli_stmt_attr_set($stmt, MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_FOR_UPDATE);
92+
6893
/*
6994
Internal macro MYSQL_REPORT_STMT_ERROR
7095
*/
@@ -292,6 +317,16 @@ mysqli_kill(): Argument #2 ($process_id) must be greater than 0
292317
Warning: mysqli_prepare(): (%d/%d): 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 'FOO' at line 1 in %s on line %d
293318

294319
Warning: mysqli_real_query(): (%d/%d): 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 'FOO' at line 1 in %s on line %d
320+
321+
Warning: mysqli_autocommit(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d
322+
323+
Warning: mysqli_commit(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d
324+
325+
Warning: mysqli_rollback(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d
326+
327+
Warning: mysqli_store_result(): (%s/%d): 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 'FOO' at line 1 in %s on line %d
328+
329+
Warning: mysqli_stmt_attr_set(): (%s/%d): Not implemented in %s on line %d
295330
mysqli_kill(): Argument #2 ($process_id) must be greater than 0
296331

297332
Warning: mysqli_stmt_prepare(): (%d/%d): 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 'FOO' at line 1 in %s on line %d

0 commit comments

Comments
 (0)