Bug #65693 [Com]: mssql_fetch_batch does not fetch next batch
Edit report at https://bugs.php.net/bug.php?id=65693edit=1 ID: 65693 Comment by: ken-phpbugs at norganna dot com Reported by:ken-phpbugs at norganna dot com Summary:mssql_fetch_batch does not fetch next batch Status: Open Type: Bug Package:MSSQL related Operating System: Linux PHP Version:5.5.3 Block user comment: N Private report: N New Comment: Actually, the patch I provided does not help if you are running multiple queries. It seems that the dbcancel() for any query on the link cancels all queries on the link, so that if another query decides to free a result, your completely separate batch result is nuked at the same time. The only way I can work out to make it multi-query safe is to comment out the dbcancel() line altogether. Previous Comments: [2013-09-18 05:47:05] ken-phpbugs at norganna dot com I made a minor copy/paste fail with the test script: $remain = mssql_fetch_batch($res); $res should be $result. Bug is still valid. [2013-09-18 05:09:20] ken-phpbugs at norganna dot com Description: When sending batch requests to the mssql server, the mssql result is having dbcancel() called prematurely on the handle (via the _free_mssql_result function). Because we are processing batches of the result set we need the query to stay open until we are finished fetching all the rows (not just the first batch). In a non-batch scenario, it is fine to cancel the query after the first batch is called, because all rows have been fetched. I have attached a patch, which fixes the problem, but probably not in the right way. I have no clue what the right way actually would be or what the repercussions of applying the patch are. It is meant for illustrative purposes only. Test script: --- ?php // Connect to MSSQL and select the database $link = mssql_connect('hostpath', 'user', 'pass'); mssql_select_db('db', $link); // Send a query to a table that has 12 rows print Given a table with 12 rows:\n; $result = mssql_query('SELECT * FROM tablename', $link, 5); do { while ($row = mssql_fetch_assoc($result)) { print Row found\n; } $remain = mssql_fetch_batch($res); print Remainder $remain\n; } while ($remain 0); Expected result: Given a table with 12 rows: Row found Row found Row found Row found Row found Remainder 5 Row found Row found Row found Row found Row found Remainder 2 Row found Row found Remainder 0 Actual result: -- Given a table with 12 rows: Row found Row found Row found Row found Row found Remainder 1 Row found Remainder 0 -- Edit this bug report at https://bugs.php.net/bug.php?id=65693edit=1
[PHP-BUG] Bug #65693 [NEW]: mssql_fetch_batch does not fetch next batch
From: ken-phpbugs at norganna dot com Operating system: Linux PHP version: 5.5.3 Package: MSSQL related Bug Type: Bug Bug description:mssql_fetch_batch does not fetch next batch Description: When sending batch requests to the mssql server, the mssql result is having dbcancel() called prematurely on the handle (via the _free_mssql_result function). Because we are processing batches of the result set we need the query to stay open until we are finished fetching all the rows (not just the first batch). In a non-batch scenario, it is fine to cancel the query after the first batch is called, because all rows have been fetched. I have attached a patch, which fixes the problem, but probably not in the right way. I have no clue what the right way actually would be or what the repercussions of applying the patch are. It is meant for illustrative purposes only. Test script: --- ?php // Connect to MSSQL and select the database $link = mssql_connect('hostpath', 'user', 'pass'); mssql_select_db('db', $link); // Send a query to a table that has 12 rows print Given a table with 12 rows:\n; $result = mssql_query('SELECT * FROM tablename', $link, 5); do { while ($row = mssql_fetch_assoc($result)) { print Row found\n; } $remain = mssql_fetch_batch($res); print Remainder $remain\n; } while ($remain 0); Expected result: Given a table with 12 rows: Row found Row found Row found Row found Row found Remainder 5 Row found Row found Row found Row found Row found Remainder 2 Row found Row found Remainder 0 Actual result: -- Given a table with 12 rows: Row found Row found Row found Row found Row found Remainder 1 Row found Remainder 0 -- Edit bug report at https://bugs.php.net/bug.php?id=65693edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=65693r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=65693r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=65693r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=65693r=fixed Fixed in release: https://bugs.php.net/fix.php?id=65693r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=65693r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=65693r=needscript Try newer version: https://bugs.php.net/fix.php?id=65693r=oldversion Not developer issue:https://bugs.php.net/fix.php?id=65693r=support Expected behavior: https://bugs.php.net/fix.php?id=65693r=notwrong Not enough info: https://bugs.php.net/fix.php?id=65693r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=65693r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=65693r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=65693r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=65693r=dst IIS Stability: https://bugs.php.net/fix.php?id=65693r=isapi Install GNU Sed:https://bugs.php.net/fix.php?id=65693r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=65693r=float No Zend Extensions: https://bugs.php.net/fix.php?id=65693r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=65693r=mysqlcfg
Bug #65693 [Opn]: mssql_fetch_batch does not fetch next batch
Edit report at https://bugs.php.net/bug.php?id=65693edit=1 ID: 65693 User updated by:ken-phpbugs at norganna dot com Reported by:ken-phpbugs at norganna dot com Summary:mssql_fetch_batch does not fetch next batch Status: Open Type: Bug Package:MSSQL related Operating System: Linux PHP Version:5.5.3 Block user comment: N Private report: N New Comment: I made a minor copy/paste fail with the test script: $remain = mssql_fetch_batch($res); $res should be $result. Bug is still valid. Previous Comments: [2013-09-18 05:09:20] ken-phpbugs at norganna dot com Description: When sending batch requests to the mssql server, the mssql result is having dbcancel() called prematurely on the handle (via the _free_mssql_result function). Because we are processing batches of the result set we need the query to stay open until we are finished fetching all the rows (not just the first batch). In a non-batch scenario, it is fine to cancel the query after the first batch is called, because all rows have been fetched. I have attached a patch, which fixes the problem, but probably not in the right way. I have no clue what the right way actually would be or what the repercussions of applying the patch are. It is meant for illustrative purposes only. Test script: --- ?php // Connect to MSSQL and select the database $link = mssql_connect('hostpath', 'user', 'pass'); mssql_select_db('db', $link); // Send a query to a table that has 12 rows print Given a table with 12 rows:\n; $result = mssql_query('SELECT * FROM tablename', $link, 5); do { while ($row = mssql_fetch_assoc($result)) { print Row found\n; } $remain = mssql_fetch_batch($res); print Remainder $remain\n; } while ($remain 0); Expected result: Given a table with 12 rows: Row found Row found Row found Row found Row found Remainder 5 Row found Row found Row found Row found Row found Remainder 2 Row found Row found Remainder 0 Actual result: -- Given a table with 12 rows: Row found Row found Row found Row found Row found Remainder 1 Row found Remainder 0 -- Edit this bug report at https://bugs.php.net/bug.php?id=65693edit=1