1919 */
2020class Result implements \Iterator
2121{
22- private ?\ PDOStatement $ pdoStatement = null ;
22+ private ?Drivers \ Result $ result = null ;
2323 private Row |false |null $ lastRow = null ;
2424 private int $ lastRowKey = -1 ;
2525
@@ -41,7 +41,7 @@ public function __construct(
4141 if (str_starts_with ($ queryString , ':: ' )) {
4242 $ connection ->getConnection ()->{substr ($ queryString , 2 )}();
4343 } else {
44- $ this ->pdoStatement = $ connection ->getConnection ()->query ($ queryString , $ params );
44+ $ this ->result = $ connection ->getConnection ()->query ($ queryString , $ params );
4545 }
4646 } catch (\PDOException $ e ) {
4747 $ e = $ connection ->getDatabaseEngine ()->convertException ($ e );
@@ -62,13 +62,6 @@ public function getConnection(): Connection
6262 }
6363
6464
65- /** @internal */
66- public function getPdoStatement (): ?\PDOStatement
67- {
68- return $ this ->pdoStatement ;
69- }
70-
71-
7265 public function getQueryString (): string
7366 {
7467 return $ this ->queryString ;
@@ -83,13 +76,13 @@ public function getParameters(): array
8376
8477 public function getColumnCount (): ?int
8578 {
86- return $ this ->pdoStatement ? $ this -> pdoStatement -> columnCount () : null ;
79+ return $ this ->result ?->getColumnCount() ;
8780 }
8881
8982
9083 public function getRowCount (): ?int
9184 {
92- return $ this ->pdoStatement ? $ this -> pdoStatement -> rowCount () : null ;
85+ return $ this ->result ?->getRowCount() ;
9386 }
9487
9588
@@ -162,14 +155,13 @@ public function fetchAssoc(?string $path = null): ?array
162155 return Arrays::associate ($ this ->fetchAll (), $ path );
163156 }
164157
165- $ data = $ this ->pdoStatement ? $ this ->pdoStatement ->fetch () : null ;
166- if (!$ data ) {
167- $ this ->pdoStatement ->closeCursor ();
158+ $ data = $ this ->result ?->fetch();
159+ if ($ data === null ) {
168160 return null ;
169161
170- } elseif ($ this ->lastRow === null && count ($ data ) !== $ this ->pdoStatement -> columnCount ()) {
171- $ duplicates = Helpers:: findDuplicates ( $ this ->pdoStatement );
172- trigger_error ("Found duplicate columns in database result set: $ duplicates. " );
162+ } elseif ($ this ->lastRow === null && count ($ data ) !== $ this ->result -> getColumnCount ()) {
163+ $ duplicates = array_filter ( array_count_values ( array_column ( $ this ->result -> getColumnsInfo (), ' name ' )), fn ( $ val ) => $ val > 1 );
164+ trigger_error ("Found duplicate columns in database result set: ' " . implode ( " ', ' " , array_keys ( $ duplicates)) . " ' . " );
173165 }
174166
175167 return $ this ->normalizeRow ($ data );
@@ -259,17 +251,8 @@ private function normalizeRow(array $row): array
259251 private function getColumnsMeta (): array
260252 {
261253 $ res = [];
262- $ metaTypeKey = $ this ->connection ->getConnection ()->metaTypeKey ;
263- $ count = $ this ->pdoStatement ->columnCount ();
264- for ($ i = 0 ; $ i < $ count ; $ i ++) {
265- $ meta = $ this ->pdoStatement ->getColumnMeta ($ i );
266- if (isset ($ meta [$ metaTypeKey ])) {
267- $ res [$ meta ['name ' ]] = [
268- 'nativeType ' => $ meta [$ metaTypeKey ],
269- 'size ' => $ meta ['len ' ],
270- 'scale ' => $ meta ['precision ' ],
271- ];
272- }
254+ foreach ($ this ->result ->getColumnsInfo () as $ meta ) {
255+ $ res [$ meta ['name ' ]] = $ meta ;
273256 }
274257 return $ res ;
275258 }
0 commit comments