55namespace daos \pgsql ;
66
77use daos \DatabaseInterface ;
8+ use Generator ;
89
910/**
1011 * PostgreSQL specific statements
@@ -74,17 +75,15 @@ public static function csvRowMatches(string $column, string $value): string {
7475 }
7576
7677 /**
77- * Ensure row values have the appropriate PHP type. This assumes we are
78- * using buffered queries (sql results are in PHP memory).
78+ * Ensure row values have the appropriate PHP type.
7979 *
80- * @param array $rows array of associative array representing row results
80+ * @param iterable $rows array of associative array representing row results
8181 * @param array $expectedRowTypes associative array mapping columns to PDO types
8282 *
83- * @return array of associative array representing row results having
84- * expected types
83+ * @return Generator<int, array, void, void> of associative array representing row results having expected types
8584 */
86- public static function ensureRowTypes (array $ rows , array $ expectedRowTypes ): array {
87- foreach ($ rows as $ rowIndex => $ row ) {
85+ public static function ensureRowTypes (iterable $ rows , array $ expectedRowTypes ): Generator {
86+ foreach ($ rows as $ row ) {
8887 foreach ($ expectedRowTypes as $ columnIndex => $ type ) {
8988 if (array_key_exists ($ columnIndex , $ row )) {
9089 if ($ type & DatabaseInterface::PARAM_NULL ) {
@@ -110,13 +109,13 @@ public static function ensureRowTypes(array $rows, array $expectedRowTypes): arr
110109 $ value = null ;
111110 }
112111 if ($ value !== null ) {
113- $ rows [ $ rowIndex ] [$ columnIndex ] = $ value ;
112+ $ row [$ columnIndex ] = $ value ;
114113 }
115114 }
116115 }
117- }
118116
119- return $ rows ;
117+ yield $ row ;
118+ }
120119 }
121120
122121 /**
0 commit comments