1010namespace Nette \Database ;
1111
1212use Nette ;
13- use PDO ;
1413
1514
1615/**
@@ -21,7 +20,7 @@ class ResultSet implements \Iterator, IRowContainer
2120 use Nette \SmartObject;
2221
2322 private Connection $ connection ;
24- private ?\ PDOStatement $ pdoStatement ;
23+ private ?ResultDriver $ result ;
2524
2625 /** @var callable(array, ResultSet): array */
2726 private $ normalizer ;
@@ -50,7 +49,7 @@ public function __construct(Connection $connection, string $queryString, array $
5049 if (str_starts_with ($ queryString , ':: ' )) {
5150 $ driver ->{substr ($ queryString , 2 )}();
5251 } elseif ($ queryString !== null ) {
53- $ this ->pdoStatement = $ driver ->query ($ queryString , $ params );
52+ $ this ->result = $ driver ->query ($ queryString , $ params );
5453 }
5554 $ this ->time = microtime (true ) - $ time ;
5655 }
@@ -68,7 +67,7 @@ public function getConnection(): Connection
6867 */
6968 public function getPdoStatement (): ?\PDOStatement
7069 {
71- return $ this ->pdoStatement ;
70+ return $ this ->result -> getPDOStatement () ;
7271 }
7372
7473
@@ -86,20 +85,20 @@ public function getParameters(): array
8685
8786 public function getColumnCount (): ?int
8887 {
89- return $ this ->pdoStatement ? $ this -> pdoStatement -> columnCount () : null ;
88+ return $ this ->result ?->getColumnCount() ;
9089 }
9190
9291
9392 public function getRowCount (): ?int
9493 {
95- return $ this ->pdoStatement ? $ this -> pdoStatement -> rowCount () : null ;
94+ return $ this ->result ?->getRowCount() ;
9695 }
9796
9897
9998 public function getColumnTypes (): array
10099 {
101100 if (!isset ($ this ->types )) {
102- $ this ->types = $ this ->connection -> getDriver ()-> getColumnTypes ($ this -> pdoStatement );
101+ $ this ->types = $ this ->result -> getColumnTypes ();
103102 }
104103 return $ this ->types ;
105104 }
@@ -176,13 +175,12 @@ public function valid(): bool
176175 */
177176 public function fetch (): ?Row
178177 {
179- $ data = $ this ->pdoStatement ? $ this ->pdoStatement ->fetch () : null ;
180- if (!$ data ) {
181- $ this ->pdoStatement ->closeCursor ();
178+ $ data = $ this ->result ?->fetch();
179+ if ($ data === null ) {
182180 return null ;
183181
184- } elseif (!isset ($ this ->lastRow ) && count ($ data ) !== $ this ->pdoStatement -> columnCount ()) {
185- $ duplicates = Helpers::findDuplicates ($ this ->pdoStatement );
182+ } elseif (!isset ($ this ->lastRow ) && count ($ data ) !== $ this ->result -> getColumnCount ()) {
183+ $ duplicates = Helpers::findDuplicates ($ this ->result );
186184 trigger_error ("Found duplicate columns in database result set: $ duplicates. " , E_USER_NOTICE );
187185 }
188186
@@ -198,6 +196,13 @@ public function fetch(): ?Row
198196 }
199197
200198
199+ /** @internal */
200+ public function fetchArray (): ?array
201+ {
202+ return $ this ->result ?->fetch();
203+ }
204+
205+
201206 /**
202207 * Fetches single field.
203208 */
0 commit comments