Req #69592 [NoF->Csd]: allow 0-column rowsets to be skipped automatically

From: Date: Tue, 17 Oct 2017 18:23:19 +0000
Subject: Req #69592 [NoF->Csd]: allow 0-column rowsets to be skipped automatically
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211764@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69592&edit=1 ID: 69592 Updated by: adambaratz@php.net Reported by: martinpop83 at gmail dot com Summary: allow 0-column rowsets to be skipped automatically -Status: No Feedback +Status: Closed Type: Feature/Change Request Package: PDO DBlib Operating System: Linux PHP Version: Irrelevant -Assigned To: +Assigned To: adambaratz Block user comment: N Private report: N New Comment: Fixed for PHP 7.3. Previous Comments: ------------------------------------------------------------------------ [2017-10-10 08:29:26] fandrieu at gmail dot com Related To: Bug #75201 ------------------------------------------------------------------------ [2016-09-14 16:00:02] adambaratz@php.net I think there's a misunderstanding about how SET NOCOUNT works. According to the docs[1], it works specifically on row count. The mssql extension suppressed the rowsets you're referring to by skipping any with a column count of 0[2]. The posted PR replicates this behavior. It can be merged once it's cleaned up for PHP7. In the meantime, you can workaround this issue in userland by calling \PDOStatement::columnCount(): $rowsets = []; do { if ($statement->columnCount()) { $rowsets[] = $statement->fetchAll(); } } while ($statement->nextRowset()); Generally speaking, functionality that can be implemented cleanly in userland should be kept there, but this is a meaningful convenience for people migrating from mssql. --- [1] https://msdn.microsoft.com/en-us/library/ms189837.aspx [2] https://github.com/php/php-src/blob/PHP-5.6/ext/mssql/php_mssql.c#L1363 ------------------------------------------------------------------------ [2016-07-07 12:18:42] mark dot blackman at db dot com Is this PR likely to get merged anytime soon? ------------------------------------------------------------------------ [2015-05-07 09:19:38] martinpop83 at gmail dot com Description: ------------ MS SQL usually return results for every query. For INSERT/UPDATE/DELETE return empty results and number of affected rows. It can be turn off by SET NOCOUNT ON and results will be returned only after SELECT queries. pdo_dblib ignore SET NOCOUNT ON and still creating empty result sets (rowsets). With pdo_sqlsrv (Windows server) and mssql (Linux server, FreeTDS) is everything ok. Test script: --------------- $pdo = new PDO("dblib:host=<host>;dbname=<dbname>", "username", "password"); $stmt = $pdo->query(" SET NOCOUNT ON DECLARE @tempTable TABLE(value VARCHAR(20), find BIT) INSERT INTO @tempTable(value, find) VALUES('textA', 1) INSERT INTO @tempTable(value, find) VALUES('textB', 0) SELECT * FROM @tempTable "); do { print_r($stmt->fetchAll(PDO::FETCH_ASSOC)); } while ($stmt->nextRowset()); Expected result: ---------------- Array ( [0] => Array ( [value] => textA [find] => 1 ) [1] => Array ( [value] => textB [find] => 0 ) ) Actual result: -------------- Array ( ) Array ( [0] => Array ( [value] => textA [find] => 1 ) [1] => Array ( [value] => textB [find] => 0 ) ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=69592&edit=1

« previous php.bugs (#211764) next »