From: ahristov Date: March 13 2007 8:36am Subject: PHP mysqlnd svn commit: r110 - in trunk/ext/mysqli: mysqlnd tests List-Archive: http://lists.mysql.com/commits/21778 Message-Id: <200703130836.l2D8aRNn011000@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: ahristov Date: 2007-03-13 09:36:26 +0100 (Tue, 13 Mar 2007) New Revision: 110 Modified: trunk/ext/mysqli/mysqlnd/mysqlnd.c trunk/ext/mysqli/mysqlnd/mysqlnd_ps.c trunk/ext/mysqli/tests/057.phpt trunk/ext/mysqli/tests/mysqli_fetch_all_oo.phpt trunk/ext/mysqli/tests/mysqli_prepare.phpt Log: Fix two issues which were affecting test 057.phpt - The user was calling stmt_close() directly after stmt_execute() and we have to clean the line before being able to close the statement. - libmysql's documentation states that mysql_stmt_affected_rows() should return mysql_stmt_num_rows() for SELECT statements. The same is stated for non-prepared statements too. In addition fix similar problem which was affecting mysqlnd_stmt_reset(). Added a test case for it. Modified: trunk/ext/mysqli/mysqlnd/mysqlnd.c =================================================================== --- trunk/ext/mysqli/mysqlnd/mysqlnd.c 2007-03-12 22:51:02 UTC (rev 109) +++ trunk/ext/mysqli/mysqlnd/mysqlnd.c 2007-03-13 08:36:26 UTC (rev 110) @@ -1396,7 +1396,9 @@ if (PASS == ret) { /* Position at the first row */ result->data_cursor = result->data; - /* No multithreading issues as we don't share the connection :) */ + + /* libmysql's documentation says it should be so for SELECT statements */ + conn->upsert_status.affected_rows = result->row_count; } else { mysqlnd_internal_free_result_contents(result); efree(result); Modified: trunk/ext/mysqli/mysqlnd/mysqlnd_ps.c =================================================================== --- trunk/ext/mysqli/mysqlnd/mysqlnd_ps.c 2007-03-12 22:51:02 UTC (rev 109) +++ trunk/ext/mysqli/mysqlnd/mysqlnd_ps.c 2007-03-13 08:36:26 UTC (rev 110) @@ -162,7 +162,11 @@ /* Position at the first row */ result->data_cursor = result->data; stmt->state = MYSQLND_STMT_USE_OR_STORE_CALLED; - /* No multithreading issues as we don't share the connection :) */ + + /* libmysql API docs say it should be so for SELECT statements */ + stmt->upsert_status.affected_rows = + stmt->conn->upsert_status.affected_rows = + stmt->result->row_count; } else { mysqlnd_internal_free_result_contents(stmt->result); efree(stmt->result); @@ -444,6 +448,12 @@ stmt->result->lengths = NULL; if (stmt->field_count) { stmt->state = MYSQLND_STMT_WAITING_USE_OR_STORE; + /* + We need to set this because the user might not call + use_result() or store_result() and we should be able to scrap the + data on the line, if he just decides to close the statement. + */ + if (stmt->upsert_status.server_status & SERVER_STATUS_CURSOR_EXISTS) { stmt->cursor_exists = TRUE; conn->state = CONN_READY; @@ -815,6 +825,16 @@ } } + /* + If the user decided to close the statement right after execute() + We have to call the appropriate use_result() or store_result() and + clean. + */ + if (stmt->state == MYSQLND_STMT_WAITING_USE_OR_STORE) { + stmt->default_rset_handler(stmt TSRMLS_CC); + stmt->state = MYSQLND_STMT_USER_FETCHING; + } + if (stmt->result) { stmt->result->m.skip_result(stmt->result TSRMLS_CC); } @@ -1369,6 +1389,16 @@ MYSQLND * conn = stmt->conn; zend_uchar cmd_buf[STMT_ID_LENGTH /* statement id */]; + /* + If the user decided to close the statement right after execute() + We have to call the appropriate use_result() or store_result() and + clean. + */ + if (stmt->state == MYSQLND_STMT_WAITING_USE_OR_STORE) { + stmt->default_rset_handler(stmt TSRMLS_CC); + stmt->state = MYSQLND_STMT_USER_FETCHING; + } + /* unbuffered set not fetched to the end ? Clean the line */ if (stmt->result) { stmt->result->m.skip_result(stmt->result TSRMLS_CC); Modified: trunk/ext/mysqli/tests/057.phpt =================================================================== --- trunk/ext/mysqli/tests/057.phpt 2007-03-12 22:51:02 UTC (rev 109) +++ trunk/ext/mysqli/tests/057.phpt 2007-03-13 08:36:26 UTC (rev 110) @@ -26,7 +26,16 @@ } mysqli_stmt_close($stmt); + /* now we should try mysqli_stmt_reset() */ $stmt = mysqli_prepare($link, "SELECT * FROM test_store_result"); + var_dump(mysqli_execute($stmt)); + var_dump(mysqli_stmt_reset($stmt)); + var_dump($stmt = mysqli_prepare($link, "SELECT * FROM test_store_result")); + var_dump(mysqli_execute($stmt)); + var_dump($stmt = mysqli_prepare($link, "SELECT * FROM test_store_result")); + var_dump(mysqli_stmt_reset($stmt)); + + $stmt = mysqli_prepare($link, "SELECT * FROM test_store_result"); mysqli_execute($stmt); $result1 = mysqli_get_metadata($stmt); mysqli_stmt_store_result($stmt); @@ -47,6 +56,14 @@ mysqli_close($link); ?> --EXPECTF-- +bool(true) +bool(true) +object(mysqli_stmt)#%d (%d) { +} +bool(true) +object(mysqli_stmt)#%d (%d) { +} +bool(true) Rows: 3 array(1) { [0]=> Modified: trunk/ext/mysqli/tests/mysqli_fetch_all_oo.phpt =================================================================== --- trunk/ext/mysqli/tests/mysqli_fetch_all_oo.phpt 2007-03-12 22:51:02 UTC (rev 109) +++ trunk/ext/mysqli/tests/mysqli_fetch_all_oo.phpt 2007-03-13 08:36:26 UTC (rev 110) @@ -3,7 +3,6 @@ --SKIPIF-- - --FILE-- - --FILE-- --EXPECTF-- -done! \ No newline at end of file +done!