1010namespace Nette \Database ;
1111
1212use Nette ;
13- use PDO ;
1413
1514
1615/**
1716 * Represents a result set.
1817 */
1918class ResultSet implements \Iterator, IRowContainer
2019{
21- private ?\ PDOStatement $ pdoStatement = null ;
20+ private ?ResultDriver $ result = null ;
2221
2322 /** @var callable(array, ResultSet): array */
2423 private $ normalizer ;
@@ -44,7 +43,7 @@ public function __construct(
4443 if (str_starts_with ($ queryString , ':: ' )) {
4544 $ driver ->{substr ($ queryString , 2 )}();
4645 } else {
47- $ this ->pdoStatement = $ driver ->query ($ queryString , $ params );
46+ $ this ->result = $ driver ->query ($ queryString , $ params );
4847 }
4948
5049 $ this ->time = microtime (true ) - $ time ;
@@ -63,7 +62,7 @@ public function getConnection(): Connection
6362 */
6463 public function getPdoStatement (): ?\PDOStatement
6564 {
66- return $ this ->pdoStatement ;
65+ return $ this ->result -> getPDOStatement () ;
6766 }
6867
6968
@@ -81,19 +80,19 @@ public function getParameters(): array
8180
8281 public function getColumnCount (): ?int
8382 {
84- return $ this ->pdoStatement ? $ this -> pdoStatement -> columnCount () : null ;
83+ return $ this ->result ?->getColumnCount() ;
8584 }
8685
8786
8887 public function getRowCount (): ?int
8988 {
90- return $ this ->pdoStatement ? $ this -> pdoStatement -> rowCount () : null ;
89+ return $ this ->result ?->getRowCount() ;
9190 }
9291
9392
9493 public function getColumnTypes (): array
9594 {
96- $ this ->types ??= $ this ->connection -> getDriver ()-> getColumnTypes ($ this -> pdoStatement );
95+ $ this ->types ??= $ this ->result -> getColumnTypes ();
9796 return $ this ->types ;
9897 }
9998
@@ -169,13 +168,12 @@ public function valid(): bool
169168 */
170169 public function fetch (): ?Row
171170 {
172- $ data = $ this ->pdoStatement ? $ this ->pdoStatement ->fetch () : null ;
173- if (!$ data ) {
174- $ this ->pdoStatement ->closeCursor ();
171+ $ data = $ this ->result ?->fetch();
172+ if ($ data === null ) {
175173 return null ;
176174
177- } elseif ($ this ->lastRow === null && count ($ data ) !== $ this ->pdoStatement -> columnCount ()) {
178- $ duplicates = Helpers::findDuplicates ($ this ->pdoStatement );
175+ } elseif ($ this ->lastRow === null && count ($ data ) !== $ this ->result -> getColumnCount ()) {
176+ $ duplicates = Helpers::findDuplicates ($ this ->result );
179177 trigger_error ("Found duplicate columns in database result set: $ duplicates. " );
180178 }
181179
@@ -191,6 +189,13 @@ public function fetch(): ?Row
191189 }
192190
193191
192+ /** @internal */
193+ public function fetchArray (): ?array
194+ {
195+ return $ this ->result ?->fetch();
196+ }
197+
198+
194199 /**
195200 * Fetches single field.
196201 */
0 commit comments