@@ -64,6 +64,142 @@ private function getRows(string $configKey): array {
6464 ->where ($ qb ->expr ()->eq ('appid ' , $ qb ->createNamedParameter ($ this ->appId )))
6565 ->andWhere ($ qb ->expr ()->eq ('configkey ' , $ qb ->createNamedParameter ($ configKey )))
6666 ->executeQuery ()
67- ->fetchAll ();
67+ ->fetchAllAssociative ();
68+ }
69+
70+ public function fetchAssociative (): void {
71+ $ insert = $ this ->connection ->getQueryBuilder ();
72+ $ insert ->insert ('appconfig ' )
73+ ->values ([
74+ 'appid ' => $ this ->appId ,
75+ 'configkey ' => 'test ' ,
76+ 'configvalue ' => '1 ' ,
77+ ])
78+ ->executeStatement ();
79+
80+ // fetch all associative
81+ $ qb = $ this ->connection ->getQueryBuilder ();
82+ $ result = $ qb ->select (['configkey ' , 'configvalue ' , 'appid ' ])
83+ ->from ('appconfig ' )
84+ ->executeQuery ();
85+
86+ $ rows = $ result ->fetchAllAssociative ();
87+ $ this ->assertEquals ([
88+ [
89+ 'appid ' => $ this ->appId ,
90+ 'configkey ' => 'test ' ,
91+ 'configvalue ' => '1 ' ,
92+ ]
93+ ], $ rows );
94+
95+ // fetch associative
96+ $ qb = $ this ->connection ->getQueryBuilder ();
97+ $ result = $ qb ->select (['configkey ' , 'configvalue ' , 'appid ' ])
98+ ->from ('appconfig ' )
99+ ->executeQuery ();
100+ $ row = $ result ->fetchAssociative ();
101+ $ this ->assertEquals ([
102+ 'appid ' => $ this ->appId ,
103+ 'configkey ' => 'test ' ,
104+ 'configvalue ' => '1 ' ,
105+ ], $ row );
106+
107+ // iterate associative
108+ $ qb = $ this ->connection ->getQueryBuilder ();
109+ $ result = $ qb ->select (['configkey ' , 'configvalue ' , 'appid ' ])
110+ ->from ('appconfig ' )
111+ ->executeQuery ();
112+ $ row = iterator_to_array ($ result ->iterateAssociative ());
113+ $ this ->assertEquals ([
114+ 'appid ' => $ this ->appId ,
115+ 'configkey ' => 'test ' ,
116+ 'configvalue ' => '1 ' ,
117+ ], $ row );
118+ }
119+
120+ public function fetchNumeric (): void {
121+ $ insert = $ this ->connection ->getQueryBuilder ();
122+ $ insert ->insert ('appconfig ' )
123+ ->values ([
124+ 'appid ' => $ this ->appId ,
125+ 'configkey ' => 'test ' ,
126+ 'configvalue ' => '1 ' ,
127+ ])
128+ ->executeStatement ();
129+
130+ // fetch all associative
131+ $ qb = $ this ->connection ->getQueryBuilder ();
132+ $ result = $ qb ->select (['configkey ' , 'configvalue ' , 'appid ' ])
133+ ->from ('appconfig ' )
134+ ->executeQuery ();
135+
136+ $ rows = $ result ->fetchAllNumeric ();
137+ $ this ->assertEquals ([
138+ [
139+ 0 => $ this ->appId ,
140+ 1 => 'test ' ,
141+ 2 => '1 ' ,
142+ ]
143+ ], $ rows );
144+
145+ // fetch associative
146+ $ qb = $ this ->connection ->getQueryBuilder ();
147+ $ result = $ qb ->select (['configkey ' , 'configvalue ' , 'appid ' ])
148+ ->from ('appconfig ' )
149+ ->executeQuery ();
150+ $ row = $ result ->fetchNumeric ();
151+ $ this ->assertEquals ([
152+ 0 => $ this ->appId ,
153+ 1 => 'test ' ,
154+ 2 => '1 ' ,
155+ ], $ row );
156+
157+ // iterate associative
158+ $ qb = $ this ->connection ->getQueryBuilder ();
159+ $ result = $ qb ->select (['configkey ' , 'configvalue ' , 'appid ' ])
160+ ->from ('appconfig ' )
161+ ->executeQuery ();
162+ $ row = iterator_to_array ($ result ->iterateNumeric ());
163+ $ this ->assertEquals ([
164+ 0 => $ this ->appId ,
165+ 1 => 'test ' ,
166+ 2 => '1 ' ,
167+ ], $ row );
168+ }
169+
170+ public function fetchOne (): void {
171+ $ insert = $ this ->connection ->getQueryBuilder ();
172+ $ insert ->insert ('appconfig ' )
173+ ->values ([
174+ 'appid ' => $ this ->appId ,
175+ 'configkey ' => 'test ' ,
176+ 'configvalue ' => '1 ' ,
177+ ])
178+ ->executeStatement ();
179+
180+ // fetch all associative
181+ $ qb = $ this ->connection ->getQueryBuilder ();
182+ $ result = $ qb ->select (['configkey ' , 'configvalue ' , 'appid ' ])
183+ ->from ('appconfig ' )
184+ ->executeQuery ();
185+
186+ $ rows = $ result ->fetchFirstColumn ();
187+ $ this ->assertEquals ($ this ->appId , $ rows );
188+
189+ // fetch associative
190+ $ qb = $ this ->connection ->getQueryBuilder ();
191+ $ result = $ qb ->select (['configkey ' , 'configvalue ' , 'appid ' ])
192+ ->from ('appconfig ' )
193+ ->executeQuery ();
194+ $ row = $ result ->fetchFirstColumn ();
195+ $ this ->assertEquals ($ this ->appId , $ row );
196+
197+ // iterate associative
198+ $ qb = $ this ->connection ->getQueryBuilder ();
199+ $ result = $ qb ->select (['configkey ' , 'configvalue ' , 'appid ' ])
200+ ->from ('appconfig ' )
201+ ->executeQuery ();
202+ $ rows = iterator_to_array ($ result ->iterateNumeric ());
203+ $ this ->assertEquals ([$ this ->appId ], $ rows );
68204 }
69205}
0 commit comments