cvs: php-src(PHP_5_3) /ext/mysqli/tests mysqli_stmt_affected_rows.phpt /ext/mysqlnd mysqlnd_result.c
| From: | Andrey Hristov | Date: | Wed, 06 Feb 2008 14:12:32 +0000 |
| Subject: | cvs: php-src(PHP_5_3) /ext/mysqli/tests mysqli_stmt_affected_rows.phpt /ext/mysqlnd mysqlnd_result.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-48380@lists.php.net to get a copy of this message | ||
andrey Wed Feb 6 14:12:32 2008 UTC
Modified files: (Branch: PHP_5_3)
/php-src/ext/mysqli/tests mysqli_stmt_affected_rows.phpt
/php-src/ext/mysqlnd mysqlnd_result.c
Log:
MFH: Fix a compatibility bug and a failing test
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqli/tests/mysqli_stmt_affected_rows.phpt?r1=1.2.2.2&r2=1.2.2.3&diff_format=u
Index: php-src/ext/mysqli/tests/mysqli_stmt_affected_rows.phpt
diff -u php-src/ext/mysqli/tests/mysqli_stmt_affected_rows.phpt:1.2.2.2
php-src/ext/mysqli/tests/mysqli_stmt_affected_rows.phpt:1.2.2.3
--- php-src/ext/mysqli/tests/mysqli_stmt_affected_rows.phpt:1.2.2.2 Wed Oct 10 10:18:50 2007
+++ php-src/ext/mysqli/tests/mysqli_stmt_affected_rows.phpt Wed Feb 6 14:12:32 2008
@@ -160,17 +160,77 @@
if (1 !== ($tmp = mysqli_stmt_affected_rows($stmt)))
printf("[029] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
+ if (!mysqli_stmt_prepare($stmt, 'SELECT label FROM test WHERE id = 100') ||
+ !mysqli_stmt_execute($stmt))
+ printf("[030] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+
+ /* use it like num_rows */
+ /* PS are unbuffered, num_rows cannot determine the row count before all rows have been fetched
and/or buffered */
+ if (-1 !== ($tmp = mysqli_stmt_affected_rows($stmt)))
+ printf("[031] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);
+
+ if (0 !== ($tmp = mysqli_stmt_num_rows($stmt)))
+ printf("[032] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
+
+ if (!mysqli_stmt_store_result($stmt))
+ printf("[033] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+
+ if (1 !== ($tmp = mysqli_stmt_affected_rows($stmt)))
+ printf("[034] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
+
+ if (1 !== ($tmp = mysqli_stmt_num_rows($stmt)))
+ printf("[035] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
+
+ mysqli_stmt_free_result($stmt);
+ mysqli_stmt_close($stmt);
+ $stmt = mysqli_stmt_init($link);
+
+ if (!mysqli_stmt_prepare($stmt, 'SELECT label FROM test WHERE 1 = 2') ||
+ !mysqli_stmt_execute($stmt))
+ printf("[036] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+
+ /* use it like num_rows */
+ if (-1 !== ($tmp = mysqli_stmt_affected_rows($stmt)))
+ printf("[037] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);
+
+ if (true !== ($tmp = mysqli_stmt_store_result($stmt)))
+ printf("[038] Expecting boolean/true, got %s\%s\n", gettype($tmp), $tmp);
+
+ if (0 !== ($tmp = mysqli_stmt_num_rows($stmt)))
+ printf("[039] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
+
+ if (0 !== ($tmp = mysqli_stmt_affected_rows($stmt)))
+ printf("[040] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
+
+ /* try to use stmt_affected_rows like stmt_num_rows */
+ /* stmt_affected_rows is not really meant for SELECT! */
+ if (mysqli_stmt_prepare($stmt, 'SELECT unknown_column FROM this_table_does_not_exist')
||
+ mysqli_stmt_execute($stmt))
+ printf("[041] The invalid SELECT statement is issued on purpose\n");
+
+ if (-1 !== ($tmp = mysqli_stmt_affected_rows($stmt)))
+ printf("[042] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);
+
+ if (false !== ($tmp = mysqli_stmt_store_result($stmt)))
+ printf("[043] Expecting boolean/false, got %s\%s\n", gettype($tmp), $tmp);
+
+ if (0 !== ($tmp = mysqli_stmt_num_rows($stmt)))
+ printf("[044] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
+
+ if (-1 !== ($tmp = mysqli_stmt_affected_rows($stmt)))
+ printf("[045] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);
+
mysqli_stmt_close($stmt);
$stmt = mysqli_stmt_init($link);
if (!mysqli_stmt_prepare($stmt, "DROP TABLE IF EXISTS test") ||
!mysqli_stmt_execute($stmt))
- printf("[030] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
+ printf("[046] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
mysqli_stmt_close($stmt);
if (!is_null($tmp = mysqli_stmt_affected_rows($stmt)))
- printf("[031] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
+ printf("[047] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
mysqli_close($link);
@@ -180,4 +240,4 @@
[009] [%d] (error message varies with the MySQL Server version, check the error code)
Warning: mysqli_stmt_affected_rows(): Couldn't fetch mysqli_stmt in %s on line %d
-done!
\ No newline at end of file
+done!
http://cvs.php.net/viewvc.cgi/php-src/ext/mysqlnd/mysqlnd_result.c?r1=1.4.2.13&r2=1.4.2.14&diff_format=u
Index: php-src/ext/mysqlnd/mysqlnd_result.c
diff -u php-src/ext/mysqlnd/mysqlnd_result.c:1.4.2.13 php-src/ext/mysqlnd/mysqlnd_result.c:1.4.2.14
--- php-src/ext/mysqlnd/mysqlnd_result.c:1.4.2.13 Wed Feb 6 11:34:44 2008
+++ php-src/ext/mysqlnd/mysqlnd_result.c Wed Feb 6 14:12:32 2008
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: mysqlnd_result.c,v 1.4.2.13 2008/02/06 11:34:44 andrey Exp $ */
+/* $Id: mysqlnd_result.c,v 1.4.2.14 2008/02/06 14:12:32 andrey Exp $ */
#include "php.h"
#include "mysqlnd.h"
#include "mysqlnd_wireprotocol.h"
@@ -438,6 +438,7 @@
ret = FAIL;
PACKET_INIT_ALLOCA(rset_header, PROT_RSET_HEADER_PACKET);
do {
+ SET_ERROR_AFF_ROWS(conn);
if (FAIL == (ret = PACKET_READ_ALLOCA(rset_header, conn))) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Error reading result set's header");
break;
@@ -454,7 +455,6 @@
safe to unconditionally turn off the flag here.
*/
conn->upsert_status.server_status &= ~SERVER_MORE_RESULTS_EXISTS;
- conn->upsert_status.affected_rows = -1;
/*
This will copy the error code and the messages, as they
are buffers in the struct
@@ -506,6 +506,9 @@
MYSQLND_INC_CONN_STATISTIC(&conn->stats, STAT_RSET_QUERY);
memset(&conn->upsert_status, 0, sizeof(conn->upsert_status));
+ /* restore after zeroing */
+ SET_ERROR_AFF_ROWS(conn);
+
conn->last_query_type = QUERY_SELECT;
CONN_SET_STATE(conn, CONN_FETCHING_DATA);
/* PS has already allocated it */