1010namespace Nette \Database ;
1111
1212use Nette ;
13- use PDO ;
1413
1514
1615/**
@@ -22,7 +21,7 @@ class ResultSet implements \Iterator, IRowContainer
2221
2322 private Connection $ connection ;
2423
25- private ?\ PDOStatement $ pdoStatement ;
24+ private ?ResultDriver $ result ;
2625
2726 /** @var callable(array, ResultSet): array */
2827 private $ normalizer ;
@@ -55,7 +54,7 @@ public function __construct(Connection $connection, string $queryString, array $
5554 if (str_starts_with ($ queryString , ':: ' )) {
5655 $ driver ->{substr ($ queryString , 2 )}();
5756 } elseif ($ queryString !== null ) {
58- $ this ->pdoStatement = $ driver ->query ($ queryString , $ params );
57+ $ this ->result = $ driver ->query ($ queryString , $ params );
5958 }
6059 $ this ->time = microtime (true ) - $ time ;
6160 }
@@ -64,7 +63,7 @@ public function __construct(Connection $connection, string $queryString, array $
6463 /** @deprecated */
6564 public function getPdoStatement (): ?\PDOStatement
6665 {
67- return $ this ->pdoStatement ;
66+ return $ this ->result -> getPDOStatement () ;
6867 }
6968
7069
@@ -82,20 +81,20 @@ public function getParameters(): array
8281
8382 public function getColumnCount (): ?int
8483 {
85- return $ this ->pdoStatement ? $ this -> pdoStatement -> columnCount () : null ;
84+ return $ this ->result ?->getColumnCount() ;
8685 }
8786
8887
8988 public function getRowCount (): ?int
9089 {
91- return $ this ->pdoStatement ? $ this -> pdoStatement -> rowCount () : null ;
90+ return $ this ->result ?->getRowCount() ;
9291 }
9392
9493
9594 public function getColumnTypes (): array
9695 {
9796 if (!isset ($ this ->types )) {
98- $ this ->types = $ this ->connection -> getDriver ()-> getColumnTypes ($ this -> pdoStatement );
97+ $ this ->types = $ this ->result -> getColumnTypes ();
9998 }
10099 return $ this ->types ;
101100 }
@@ -172,13 +171,12 @@ public function valid(): bool
172171 */
173172 public function fetch (): ?Row
174173 {
175- $ data = $ this ->pdoStatement ? $ this ->pdoStatement ->fetch () : null ;
176- if (!$ data ) {
177- $ this ->pdoStatement ->closeCursor ();
174+ $ data = $ this ->result ?->fetch();
175+ if ($ data === null ) {
178176 return null ;
179177
180- } elseif (!isset ($ this ->lastRow ) && count ($ data ) !== $ this ->pdoStatement -> columnCount ()) {
181- $ duplicates = Helpers::findDuplicates ($ this ->pdoStatement );
178+ } elseif (!isset ($ this ->lastRow ) && count ($ data ) !== $ this ->result -> getColumnCount ()) {
179+ $ duplicates = Helpers::findDuplicates ($ this ->result );
182180 trigger_error ("Found duplicate columns in database result set: $ duplicates. " , E_USER_NOTICE );
183181 }
184182
@@ -194,6 +192,13 @@ public function fetch(): ?Row
194192 }
195193
196194
195+ /** @internal */
196+ public function fetchArray (): ?array
197+ {
198+ return $ this ->result ?->fetch();
199+ }
200+
201+
197202 /**
198203 * Fetches single field.
199204 */
0 commit comments