In closeCursor check if statement has been executed before moving to next result.
This commit is contained in:
parent
451f84c416
commit
887857eaf2
|
@ -401,10 +401,14 @@ int pdo_sqlsrv_stmt_close_cursor(pdo_stmt_t *stmt TSRMLS_DC)
|
|||
|
||||
// to "close the cursor" means we make the statement ready for execution again. To do this, we
|
||||
// skip all the result sets on the current statement.
|
||||
while( driver_stmt->past_next_result_end == false ) {
|
||||
// If the statement has not been executed there are no next results to iterate over.
|
||||
if ( driver_stmt->executed == true )
|
||||
{
|
||||
while( driver_stmt->past_next_result_end == false ) {
|
||||
|
||||
core_sqlsrv_next_result( driver_stmt TSRMLS_CC );
|
||||
}
|
||||
core_sqlsrv_next_result( driver_stmt TSRMLS_CC );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( core::CoreException& ) {
|
||||
|
||||
|
|
71
test/pdo_sqlsrv/pdo_267_closeCursor.phpt
Normal file
71
test/pdo_sqlsrv/pdo_267_closeCursor.phpt
Normal file
|
@ -0,0 +1,71 @@
|
|||
--TEST--
|
||||
Test closeCursor with a stmt before/after execute and fetch.
|
||||
--SKIPIF--
|
||||
--FILE--
|
||||
<?php
|
||||
require_once("autonomous_setup.php");
|
||||
|
||||
try
|
||||
{
|
||||
/* Connect */
|
||||
$conn = new PDO("sqlsrv:server=$serverName", $username, $password);
|
||||
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
|
||||
|
||||
// prepare a stmt but don't execute, then closeCursor.
|
||||
$stmt = $conn->prepare("select 123 as 'IntCol'");
|
||||
$ret = $stmt->closeCursor();
|
||||
var_dump($ret);
|
||||
$ret = $stmt->closeCursor();
|
||||
var_dump($ret);
|
||||
|
||||
// prepare a stmt and execute, then closeCursor.
|
||||
$stmt = $conn->prepare("select 123 as 'IntCol'");
|
||||
$stmt->execute();
|
||||
$ret = $stmt->closeCursor();
|
||||
var_dump($ret);
|
||||
$ret = $stmt->closeCursor();
|
||||
var_dump($ret);
|
||||
|
||||
|
||||
// prepare two stmt, execute, and fetch, then closeCursor.
|
||||
// use one with client side buffering.
|
||||
$stmt1 = $conn->prepare("select 123 as 'IntCol'");
|
||||
$stmt2 = $conn->prepare("select 'abc' as 'Charcol'", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));
|
||||
$stmt1->execute();
|
||||
$result = $stmt1->fetch(PDO::FETCH_NUM);
|
||||
print_r($result[0]);
|
||||
echo "\n";
|
||||
$ret = $stmt1->closeCursor();
|
||||
var_dump($ret);
|
||||
$stmt2->execute();
|
||||
$result = $stmt2->fetch(PDO::FETCH_NUM);
|
||||
print_r($result[0]);
|
||||
echo "\n";
|
||||
$ret = $stmt2->closeCursor();
|
||||
var_dump($ret);
|
||||
|
||||
$stmt1 = null;
|
||||
$stmt2 = null;
|
||||
$stmt = null;
|
||||
$conn = null;
|
||||
|
||||
}
|
||||
|
||||
catch( PDOException $e ) {
|
||||
var_dump($e);
|
||||
exit;
|
||||
}
|
||||
|
||||
print "Done";
|
||||
?>
|
||||
|
||||
--EXPECT--
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
bool(true)
|
||||
123
|
||||
bool(true)
|
||||
abc
|
||||
bool(true)
|
||||
Done
|
Loading…
Reference in a new issue