Bug->Req #69592 [Opn]: allow 0-column rowsets to be skipped automatically
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: PDO_DBLIB MSSQL ignore SET NOCOUNT ON
+Summary: allow 0-column rowsets to be skipped automatically
Status: Open
-Type: Bug
+Type: Feature/Change Request
Package: PDO DBlib
Operating System: Linux
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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
Thread (5 messages)