Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
7cd0589f
Commit
7cd0589f
authored
Oct 27, 2016
by
Sergei Morozov
Committed by
Marco Pivetta
Feb 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DBAL-2546] Reworked implementation of closeCursor() for mysqli, ibm_db2 and oci drivers
parent
fc376f7a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
8 deletions
+71
-8
DB2Statement.php
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
+1
-4
OCI8Statement.php
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
+7
-1
SQLSrvStatement.php
lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
+7
-3
StatementTest.php
tests/Doctrine/Tests/DBAL/Functional/StatementTest.php
+56
-0
No files found.
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
View file @
7cd0589f
...
...
@@ -104,11 +104,8 @@ class DB2Statement implements \IteratorAggregate, Statement
}
$this
->
_bindParam
=
array
();
db2_free_result
(
$this
->
_stmt
);
$ret
=
db2_free_stmt
(
$this
->
_stmt
);
$this
->
_stmt
=
false
;
return
$ret
;
return
db2_free_result
(
$this
->
_stmt
)
;
}
/**
...
...
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
View file @
7cd0589f
...
...
@@ -176,7 +176,13 @@ class OCI8Statement implements \IteratorAggregate, Statement
*/
public
function
closeCursor
()
{
return
oci_free_statement
(
$this
->
_sth
);
// emulate it by fetching and discarding rows, similarly to what PDO does in this case
// @link http://php.net/manual/en/pdostatement.closecursor.php
// @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
// deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
while
(
oci_fetch
(
$this
->
_sth
));
return
true
;
}
/**
...
...
lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
View file @
7cd0589f
...
...
@@ -150,9 +150,13 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/
public
function
closeCursor
()
{
if
(
$this
->
stmt
)
{
sqlsrv_free_stmt
(
$this
->
stmt
);
}
// emulate it by fetching and discarding rows, similarly to what PDO does in this case
// @link http://php.net/manual/en/pdostatement.closecursor.php
// @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075
// deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them
while
(
sqlsrv_fetch
(
$this
->
stmt
));
return
true
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/StatementTest.php
0 → 100644
View file @
7cd0589f
<?php
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Schema\Table
;
class
StatementTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
public
function
testStatementIsReusableAfterClosingCursor
()
{
$sm
=
$this
->
_conn
->
getSchemaManager
();
$table
=
new
Table
(
'stmt_test_reusable'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$sm
->
createTable
(
$table
);
$this
->
_conn
->
insert
(
'stmt_test_reusable'
,
array
(
'id'
=>
1
));
$this
->
_conn
->
insert
(
'stmt_test_reusable'
,
array
(
'id'
=>
2
));
$stmt
=
$this
->
_conn
->
prepare
(
'SELECT id FROM stmt_test_reusable ORDER BY id'
);
$stmt
->
execute
();
$id
=
$stmt
->
fetchColumn
();
$this
->
assertEquals
(
1
,
$id
);
$stmt
->
closeCursor
();
$stmt
->
execute
();
$id
=
$stmt
->
fetchColumn
();
$this
->
assertEquals
(
1
,
$id
);
$id
=
$stmt
->
fetchColumn
();
$this
->
assertEquals
(
2
,
$id
);
}
public
function
testClosedCursorDoesNotContainResults
()
{
$sm
=
$this
->
_conn
->
getSchemaManager
();
$table
=
new
Table
(
'stmt_test_no_results'
);
$table
->
addColumn
(
'id'
,
'integer'
);
$sm
->
createTable
(
$table
);
$this
->
_conn
->
insert
(
'stmt_test_no_results'
,
array
(
'id'
=>
1
));
$stmt
=
$this
->
_conn
->
prepare
(
'SELECT id FROM stmt_test_no_results'
);
$stmt
->
execute
();
$stmt
->
closeCursor
();
try
{
$value
=
$stmt
->
fetchColumn
();
}
catch
(
\Exception
$e
)
{
// some adapters trigger PHP error or throw adapter-specific exception in case of fetching
// from a closed cursor, which still proves that it has been closed
return
;
}
$this
->
assertFalse
(
$value
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment