com php-src: Handle mysqli errors in more cases: ext/mysqli/mys qli_api.c ext/mysqli/tests/mysqli_report.phpt ext/m ysqlnd/mysqlnd_ps.c

From: Date: Wed, 28 Oct 2020 10:33:50 +0000
Subject: com php-src: Handle mysqli errors in more cases: ext/mysqli/mys qli_api.c ext/mysqli/tests/mysqli_report.phpt ext/m ysqlnd/mysqlnd_ps.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-113961@lists.php.net to get a copy of this message
Commit: 990bb34891c83d12c5129fd781893704f948f2f4 Author: Dharman <tekiela246@gmail.com> Thu, 17 Sep 2020 23:45:17 +0100 Committer: Nikita Popov <nikita.ppv@gmail.com> Wed, 28 Oct 2020 11:33:50 +0100 Parents: fe55fe1f54958edf273ea37b580c04f0c85903e3 Branches: PHP-7.4 PHP-8.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=990bb34891c83d12c5129fd781893704f948f2f4 Log: Handle mysqli errors in more cases Report errors autocommit, commit, rollback and mysqli_stmt_attr_set. Additionally, copy the error from conn to stmt when preparing fails, so these errors are also handled by mysqli_stmt_prepare. Closes GH-6157. Changed paths: M ext/mysqli/mysqli_api.c M ext/mysqli/tests/mysqli_report.phpt M ext/mysqlnd/mysqlnd_ps.c Diff: diff --git a/ext/mysqli/mysqli_api.c b/ext/mysqli/mysqli_api.c index e164e701b42..9a54171b307 100644 --- a/ext/mysqli/mysqli_api.c +++ b/ext/mysqli/mysqli_api.c @@ -171,6 +171,7 @@ PHP_FUNCTION(mysqli_autocommit) MYSQLI_FETCH_RESOURCE_CONN(mysql, mysql_link, MYSQLI_STATUS_VALID); if (mysql_autocommit(mysql->mysql, (my_bool)automode)) { + MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql); RETURN_FALSE; } RETURN_TRUE; @@ -754,6 +755,7 @@ PHP_FUNCTION(mysqli_commit) #else if (FAIL == mysqlnd_commit(mysql->mysql, flags, name)) { #endif + MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql); RETURN_FALSE; } RETURN_TRUE; @@ -1989,6 +1991,7 @@ PHP_FUNCTION(mysqli_rollback) #else if (FAIL == mysqlnd_rollback(mysql->mysql, flags, name)) { #endif + MYSQLI_REPORT_MYSQL_ERROR(mysql->mysql); RETURN_FALSE; } RETURN_TRUE; @@ -2350,6 +2353,7 @@ PHP_FUNCTION(mysqli_stmt_attr_set) #else if (FAIL == mysql_stmt_attr_set(stmt->stmt, attr, mode_p)) { #endif + MYSQLI_REPORT_STMT_ERROR(stmt->stmt); RETURN_FALSE; } RETURN_TRUE; diff --git a/ext/mysqli/tests/mysqli_report.phpt b/ext/mysqli/tests/mysqli_report.phpt index 86fb45bc87c..33730976976 100644 --- a/ext/mysqli/tests/mysqli_report.phpt +++ b/ext/mysqli/tests/mysqli_report.phpt @@ -49,6 +49,20 @@ require_once('skipifconnectfailure.inc'); printf("[009] select_db should have failed\n"); // 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 + mysqli_multi_query($link, "SELECT 1; FOO;"); + mysqli_autocommit($link, true); + mysqli_commit($link); + mysqli_rollback($link); + $stmt = mysqli_stmt_init($link); + mysqli_stmt_prepare($stmt, "SELECT id FROM test WHERE id > ?"); + while(mysqli_more_results($link)) { + mysqli_next_result($link); + $res = mysqli_store_result($link); + } + mysqli_next_result($link); + + $stmt = mysqli_prepare($link, "SELECT 1"); + mysqli_stmt_attr_set($stmt, MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_FOR_UPDATE); // Check that none of the above would have caused any error messages if MYSQL_REPORT_ERROR would // not have been set. If that would be the case, the test would be broken. @@ -65,6 +79,21 @@ require_once('skipifconnectfailure.inc'); mysqli_real_query($link, "FOO"); mysqli_select_db($link, "Oh lord, let this be an unknown database name"); + mysqli_multi_query($link, "SELECT 1; FOO;"); + mysqli_autocommit($link, true); + mysqli_commit($link); + mysqli_rollback($link); + $stmt = mysqli_stmt_init($link); + mysqli_stmt_prepare($stmt, "SELECT id FROM test WHERE id > ?"); + while(mysqli_more_results($link)) { + mysqli_next_result($link); + $res = mysqli_store_result($link); + } + mysqli_next_result($link); + + $stmt = mysqli_prepare($link, "SELECT 1"); + mysqli_stmt_attr_set($stmt, MYSQLI_STMT_ATTR_CURSOR_TYPE, MYSQLI_CURSOR_TYPE_FOR_UPDATE); + /* Internal macro MYSQL_REPORT_STMT_ERROR */ @@ -294,6 +323,18 @@ Warning: mysqli_prepare(): (%d/%d): You have an error in your SQL syntax; check 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 +Warning: mysqli_autocommit(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d + +Warning: mysqli_commit(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d + +Warning: mysqli_rollback(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d + +Warning: mysqli_stmt_prepare(): (%s/%d): Commands out of sync; you can't run this command now in %s on line %d + +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 + +Warning: mysqli_stmt_attr_set(): (%s/%d): Not implemented in %s on line %d + Warning: mysqli_kill(): processid should have positive value in %s on line %d 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 diff --git a/ext/mysqlnd/mysqlnd_ps.c b/ext/mysqlnd/mysqlnd_ps.c index d4d34ee500e..010a7bbb413 100644 --- a/ext/mysqlnd/mysqlnd_ps.c +++ b/ext/mysqlnd/mysqlnd_ps.c @@ -411,6 +411,7 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const ret = conn->command->stmt_prepare(conn, query_string); if (FAIL == ret) { + COPY_CLIENT_ERROR(stmt->error_info, *conn->error_info); goto fail; } }

« previous php.cvs (#113961) next »