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
a0cc581b
Commit
a0cc581b
authored
Sep 15, 2017
by
Marco Pivetta
Committed by
GitHub
Sep 15, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2718 from jenkoian/efficient-iterating
Add iterators for non pdo drivers.
parents
373ae9ed
078d32ea
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
81 additions
and
15 deletions
+81
-15
DB2Statement.php
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
+2
-3
MysqliStatement.php
lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
+2
-3
OCI8Connection.php
lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
+0
-1
OCI8Statement.php
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
+4
-4
SQLAnywhereStatement.php
...Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php
+2
-1
SQLSrvStatement.php
lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
+2
-3
StatementIterator.php
lib/Doctrine/DBAL/Driver/StatementIterator.php
+29
-0
StatementIteratorTest.php
tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php
+40
-0
No files found.
lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php
View file @
a0cc581b
...
...
@@ -20,6 +20,7 @@
namespace
Doctrine\DBAL\Driver\IBMDB2
;
use
Doctrine\DBAL\Driver\Statement
;
use
Doctrine\DBAL\Driver\StatementIterator
;
class
DB2Statement
implements
\IteratorAggregate
,
Statement
{
...
...
@@ -199,9 +200,7 @@ class DB2Statement implements \IteratorAggregate, Statement
*/
public
function
getIterator
()
{
$data
=
$this
->
fetchAll
();
return
new
\ArrayIterator
(
$data
);
return
new
StatementIterator
(
$this
);
}
/**
...
...
lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
View file @
a0cc581b
...
...
@@ -20,6 +20,7 @@
namespace
Doctrine\DBAL\Driver\Mysqli
;
use
Doctrine\DBAL\Driver\Statement
;
use
Doctrine\DBAL\Driver\StatementIterator
;
use
PDO
;
/**
...
...
@@ -406,8 +407,6 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/
public
function
getIterator
()
{
$data
=
$this
->
fetchAll
();
return
new
\ArrayIterator
(
$data
);
return
new
StatementIterator
(
$this
);
}
}
lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php
View file @
a0cc581b
...
...
@@ -21,7 +21,6 @@ namespace Doctrine\DBAL\Driver\OCI8;
use
Doctrine\DBAL\Driver\Connection
;
use
Doctrine\DBAL\Driver\ServerInfoAwareConnection
;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
/**
* OCI8 implementation of the Connection interface.
...
...
lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php
View file @
a0cc581b
...
...
@@ -20,6 +20,8 @@
namespace
Doctrine\DBAL\Driver\OCI8
;
use
Doctrine\DBAL\Driver\Statement
;
use
Doctrine\DBAL\Driver\StatementIterator
;
use
IteratorAggregate
;
use
PDO
;
/**
...
...
@@ -28,7 +30,7 @@ use PDO;
* @since 2.0
* @author Roman Borschel <roman@code-factory.org>
*/
class
OCI8Statement
implements
\
IteratorAggregate
,
Statement
class
OCI8Statement
implements
IteratorAggregate
,
Statement
{
/**
* @var resource
...
...
@@ -369,9 +371,7 @@ class OCI8Statement implements \IteratorAggregate, Statement
*/
public
function
getIterator
()
{
$data
=
$this
->
fetchAll
();
return
new
\ArrayIterator
(
$data
);
return
new
StatementIterator
(
$this
);
}
/**
...
...
lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php
View file @
a0cc581b
...
...
@@ -19,6 +19,7 @@
namespace
Doctrine\DBAL\Driver\SQLAnywhere
;
use
Doctrine\DBAL\Driver\StatementIterator
;
use
IteratorAggregate
;
use
PDO
;
use
Doctrine\DBAL\Driver\Statement
;
...
...
@@ -278,7 +279,7 @@ class SQLAnywhereStatement implements IteratorAggregate, Statement
*/
public
function
getIterator
()
{
return
new
\ArrayIterator
(
$this
->
fetchAll
()
);
return
new
StatementIterator
(
$this
);
}
/**
...
...
lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php
View file @
a0cc581b
...
...
@@ -19,6 +19,7 @@
namespace
Doctrine\DBAL\Driver\SQLSrv
;
use
Doctrine\DBAL\Driver\StatementIterator
;
use
PDO
;
use
IteratorAggregate
;
use
Doctrine\DBAL\Driver\Statement
;
...
...
@@ -295,9 +296,7 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/
public
function
getIterator
()
{
$data
=
$this
->
fetchAll
();
return
new
\ArrayIterator
(
$data
);
return
new
StatementIterator
(
$this
);
}
/**
...
...
lib/Doctrine/DBAL/Driver/StatementIterator.php
0 → 100644
View file @
a0cc581b
<?php
namespace
Doctrine\DBAL\Driver
;
class
StatementIterator
implements
\IteratorAggregate
{
/**
* @var Statement
*/
private
$statement
;
/**
* @param Statement $statement
*/
public
function
__construct
(
Statement
$statement
)
{
$this
->
statement
=
$statement
;
}
/**
* {@inheritdoc}
*/
public
function
getIterator
()
{
while
(
false
!==
(
$result
=
$this
->
statement
->
fetch
()))
{
yield
$result
;
}
}
}
tests/Doctrine/Tests/DBAL/Driver/StatementIteratorTest.php
0 → 100644
View file @
a0cc581b
<?php
namespace
Doctrine\Tests\DBAL\Driver
;
use
Doctrine\DBAL\Driver\Statement
;
use
Doctrine\DBAL\Driver\StatementIterator
;
class
StatementIteratorTest
extends
\Doctrine\Tests\DbalTestCase
{
public
function
testGettingIteratorDoesNotCallFetch
()
{
$stmt
=
$this
->
createMock
(
Statement
::
class
);
$stmt
->
expects
(
$this
->
never
())
->
method
(
'fetch'
);
$stmt
->
expects
(
$this
->
never
())
->
method
(
'fetchAll'
);
$stmt
->
expects
(
$this
->
never
())
->
method
(
'fetchColumn'
);
$stmtIterator
=
new
StatementIterator
(
$stmt
);
$stmtIterator
->
getIterator
();
}
public
function
testIterationCallsFetchOncePerStep
()
{
$values
=
[
'foo'
,
''
,
'bar'
,
'0'
,
'baz'
,
0
,
'qux'
,
null
,
'quz'
,
false
,
'impossible'
];
$calls
=
0
;
$stmt
=
$this
->
createMock
(
Statement
::
class
);
$stmt
->
expects
(
$this
->
exactly
(
10
))
->
method
(
'fetch'
)
->
willReturnCallback
(
function
()
use
(
$values
,
&
$calls
)
{
$value
=
$values
[
$calls
];
$calls
++
;
return
$value
;
});
$stmtIterator
=
new
StatementIterator
(
$stmt
);
foreach
(
$stmtIterator
as
$i
=>
$_
)
{
$this
->
assertEquals
(
$i
+
1
,
$calls
);
}
}
}
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