-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added empty result set check to nextRowset() #520
Changes from 2 commits
83631cd
f4117a8
8666ea6
7046086
0d06dea
2c28d0b
f11c208
be2be4b
270f2b4
1045ea4
68bb42b
66a12d3
a749010
d039cf6
7713b70
d56446c
3acab1a
257b1cd
7315d44
494527d
0728a1d
dc6e2a3
9e92867
4674f58
4151f8f
95f7675
cc0d71d
6aa062f
4349a3c
70b20a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
--TEST-- | ||
Test that calling nextRowset() on an empty result set produces the correct error message. Fix for Github 507. | ||
--SKIPIF-- | ||
<?php require('skipif.inc'); ?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please try to limit the length of test title. If you have more please put it in --DESCRIPTION-- instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do drop them at the end, but I kept the drop functions at the beginning too just in case... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ahhh... I see! In the beginning you use DropTable and DropProc but later you simply use queries. |
||
--FILE-- | ||
<?php | ||
require_once("MsSetup.inc"); | ||
|
||
$conn = new PDO( "sqlsrv:Server = $server; Database = $databaseName; ", $uid, $pwd ); | ||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); | ||
|
||
$stmt = $conn->query("IF OBJECT_ID('TestEmptySetTable', 'U') IS NOT NULL DROP TABLE TestEmptySetTable"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There a DropTable and DropProc function you can use in MsCommon |
||
$stmt = $conn->query("CREATE TABLE TestEmptySetTable ([c1] nvarchar(10),[c2] nvarchar(10))"); | ||
|
||
$stmt = $conn->query("INSERT INTO TestEmptySetTable (c1, c2) VALUES ('a', 'b')"); | ||
$stmt = $conn->query("IF OBJECT_ID('TestEmptySetProc', 'P') IS NOT NULL DROP PROCEDURE TestEmptySetProc"); | ||
$stmt = $conn->query("CREATE PROCEDURE TestEmptySetProc @a nvarchar(10), @b nvarchar(10) | ||
AS SET NOCOUNT ON | ||
BEGIN | ||
IF @b='b' | ||
BEGIN | ||
SELECT 'a' as testValue | ||
END | ||
ELSE | ||
BEGIN | ||
UPDATE TestEmptySetTable SET c2 = 'c' WHERE c1 = @a | ||
END | ||
END"); | ||
|
||
// errors out when reaching the second nextRowset() call | ||
// returned error indicates there are no more results | ||
echo "Return a nonempty result set:\n"; | ||
try | ||
{ | ||
$stmt = $conn->query("TestEmptySetProc @a='a', @b='b'"); | ||
$result = $stmt->fetchAll(); | ||
print_r($result); | ||
$stmt->nextRowset(); | ||
$result = $stmt->fetchAll(); | ||
print_r($result); | ||
$stmt->nextRowset(); | ||
} | ||
catch(Exception $e) | ||
{ | ||
echo $e->getMessage()."\n"; | ||
} | ||
|
||
// errors out indicating the result set contains no fields | ||
echo "Return an empty result set, call nextRowset on it before fetching anything:\n"; | ||
try | ||
{ | ||
$stmt = $conn->query("TestEmptySetProc @a='a', @b='c'"); | ||
$stmt->nextRowset(); | ||
} | ||
catch(Exception $e) | ||
{ | ||
echo $e->getMessage()."\n"; | ||
} | ||
|
||
// errors out indicating the result set contains no fields | ||
echo "Return an empty result set, call fetch on it:\n"; | ||
try | ||
{ | ||
$stmt = $conn->query("TestEmptySetProc @a='a', @b='c'"); | ||
$result = $stmt->fetchAll(); | ||
print_r($result); | ||
} | ||
catch(Exception $e) | ||
{ | ||
echo $e->getMessage()."\n"; | ||
} | ||
|
||
$stmt = $conn->query("DROP TABLE TestEmptySetTable"); | ||
$stmt = $conn->query("DROP PROCEDURE TestEmptySetProc"); | ||
|
||
$conn = null; | ||
?> | ||
--EXPECT-- | ||
Return a nonempty result set: | ||
Array | ||
( | ||
[0] => Array | ||
( | ||
[testValue] => a | ||
[0] => a | ||
) | ||
|
||
) | ||
Array | ||
( | ||
) | ||
SQLSTATE[IMSSP]: There are no more results returned by the query. | ||
Return an empty result set, call nextRowset on it before fetching anything: | ||
SQLSTATE[IMSSP]: The active result for the query contains no fields. | ||
Return an empty result set, call fetch on it: | ||
SQLSTATE[IMSSP]: The active result for the query contains no fields. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From this page it seems valid and accurate to call this without making another trip to the server. Please confirm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since a statement has to be executed for the user to call nextRowset, there is no trip to the server made here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an equivalent scenario in the sqlsrv side?
Based on your comment it seems that fetch() also invokes SQLNumResultCols(), right? Would that be a duplicate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I've verified the same problem exists on the sqlsrv side. But I think core_sqlsrv_fetch is never called if nextRowset is called before fetch, which is why we're catching the error here. I'll add a fix and test for sqlsrv.