5
5
namespace daos \pgsql ;
6
6
7
7
use daos \DatabaseInterface ;
8
+ use Generator ;
8
9
9
10
/**
10
11
* PostgreSQL specific statements
@@ -74,17 +75,15 @@ public static function csvRowMatches(string $column, string $value): string {
74
75
}
75
76
76
77
/**
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.
79
79
*
80
- * @param array $rows array of associative array representing row results
80
+ * @param iterable $rows array of associative array representing row results
81
81
* @param array $expectedRowTypes associative array mapping columns to PDO types
82
82
*
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
85
84
*/
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 ) {
88
87
foreach ($ expectedRowTypes as $ columnIndex => $ type ) {
89
88
if (array_key_exists ($ columnIndex , $ row )) {
90
89
if ($ type & DatabaseInterface::PARAM_NULL ) {
@@ -110,13 +109,13 @@ public static function ensureRowTypes(array $rows, array $expectedRowTypes): arr
110
109
$ value = null ;
111
110
}
112
111
if ($ value !== null ) {
113
- $ rows [ $ rowIndex ] [$ columnIndex ] = $ value ;
112
+ $ row [$ columnIndex ] = $ value ;
114
113
}
115
114
}
116
115
}
117
- }
118
116
119
- return $ rows ;
117
+ yield $ row ;
118
+ }
120
119
}
121
120
122
121
/**
0 commit comments