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 }
@@ -73,7 +72,7 @@ public function getConnection(): Connection
7372 */
7473 public function getPdoStatement (): ?\PDOStatement
7574 {
76- return $ this ->pdoStatement ;
75+ return $ this ->result -> getPDOStatement () ;
7776 }
7877
7978
@@ -91,20 +90,20 @@ public function getParameters(): array
9190
9291 public function getColumnCount (): ?int
9392 {
94- return $ this ->pdoStatement ? $ this -> pdoStatement -> columnCount () : null ;
93+ return $ this ->result ?->getColumnCount() ;
9594 }
9695
9796
9897 public function getRowCount (): ?int
9998 {
100- return $ this ->pdoStatement ? $ this -> pdoStatement -> rowCount () : null ;
99+ return $ this ->result ?->getRowCount() ;
101100 }
102101
103102
104103 public function getColumnTypes (): array
105104 {
106105 if (!isset ($ this ->types )) {
107- $ this ->types = $ this ->connection -> getDriver ()-> getColumnTypes ($ this -> pdoStatement );
106+ $ this ->types = $ this ->result -> getColumnTypes ();
108107 }
109108 return $ this ->types ;
110109 }
@@ -181,13 +180,12 @@ public function valid(): bool
181180 */
182181 public function fetch (): ?Row
183182 {
184- $ data = $ this ->pdoStatement ? $ this ->pdoStatement ->fetch () : null ;
185- if (!$ data ) {
186- $ this ->pdoStatement ->closeCursor ();
183+ $ data = $ this ->result ?->fetch();
184+ if ($ data === null ) {
187185 return null ;
188186
189- } elseif (!isset ($ this ->lastRow ) && count ($ data ) !== $ this ->pdoStatement -> columnCount ()) {
190- $ duplicates = Helpers::findDuplicates ($ this ->pdoStatement );
187+ } elseif (!isset ($ this ->lastRow ) && count ($ data ) !== $ this ->result -> getColumnCount ()) {
188+ $ duplicates = Helpers::findDuplicates ($ this ->result );
191189 trigger_error ("Found duplicate columns in database result set: $ duplicates. " , E_USER_NOTICE );
192190 }
193191
@@ -203,6 +201,13 @@ public function fetch(): ?Row
203201 }
204202
205203
204+ /** @internal */
205+ public function fetchArray (): ?array
206+ {
207+ return $ this ->result ?->fetch();
208+ }
209+
210+
206211 /**
207212 * Fetches single field.
208213 */
0 commit comments