@@ -116,7 +116,7 @@ protected function getDoctrineDriver()
116116 }
117117
118118 /**
119- * Compile for select.
119+ * Compile the bindings for select.
120120 *
121121 * @param \Illuminate\Database\Query\Builder $builder
122122 * @param array $bindings
@@ -148,15 +148,13 @@ private function compileForSelect(Builder $builder, $bindings) {
148148 $ tables = $ alias ['table ' ];
149149 }
150150
151+ // TODO: cache this query
151152 $ queryString = $ this ->queryStringForSelect ($ tables );
152-
153153 $ queryRes = $ this ->getPdo ()->query ($ queryString );
154-
155154 $ types [$ tables ] = $ queryRes ->fetchAll (PDO ::FETCH_NAMED );
156155
157156 foreach ($ types [$ tables ] as &$ row ) {
158157 $ tipos [strtolower ($ row ['name ' ])] = $ row ['type ' ];
159-
160158 $ tipos [strtolower ($ tables . '. ' . $ row ['name ' ])] = $ row ['type ' ];
161159
162160 if (!empty ($ alias ['alias ' ])) {
@@ -170,7 +168,7 @@ private function compileForSelect(Builder $builder, $bindings) {
170168
171169 foreach ($ builder ->wheres as $ w ) {
172170 switch ($ w ['type ' ]) {
173- case ' Nested ' :
171+ case " Nested " :
174172 $ wheres += $ w ['query ' ]->wheres ;
175173 break ;
176174 default :
@@ -180,11 +178,13 @@ private function compileForSelect(Builder $builder, $bindings) {
180178 }
181179
182180 $ i = 0 ;
183-
184181 $ wheresCount = count ($ wheres );
185182
186183 for ($ ind = 0 ; $ ind < $ wheresCount ; $ ind ++) {
187- if (
184+ if ($ wheres [$ ind ]['type ' ] == 'raw ' ) {
185+ $ newBinds [] = $ bindings [$ i ];
186+ $ i ++;
187+ } else if (
188188 isset ($ wheres [$ ind ]['value ' ]) &&
189189 isset ($ tipos [strtolower ($ wheres [$ ind ]['column ' ])])
190190 ) {
@@ -205,7 +205,6 @@ private function compileForSelect(Builder $builder, $bindings) {
205205 } else {
206206 $ newBinds [$ i ] = (string ) $ bindings [$ i ];
207207 }
208-
209208 $ i ++;
210209 }
211210 }
@@ -214,14 +213,22 @@ private function compileForSelect(Builder $builder, $bindings) {
214213 $ newFormat [$ tables ] = [];
215214 }
216215
217- $ wheres = (array ) $ builder ->wheres ;
218216
217+ /**
218+ * Is this block duplicated? Need more tests will keep it
219+ * commented to remember that a possible error could be related to
220+ * this
221+ */
222+ /**
223+ $wheres = (array) $builder->wheres;
219224 $i = 0;
220-
221225 $wheresCount = count($wheres);
222226
223227 for ($ind = 0; $ind < $wheresCount; $ind++) {
224- if (isset ($ wheres [$ ind ]['value ' ])) {
228+ if ($wheres[$ind]['type'] == 'raw') {
229+ $newBinds[] = $bindings[$i];
230+ $i++;
231+ } else if (isset($wheres[$ind]['value'])) {
225232 if (is_object($wheres[$ind]['value']) === false) {
226233 if (
227234 in_array(
@@ -239,11 +246,11 @@ private function compileForSelect(Builder $builder, $bindings) {
239246 } else {
240247 $newBinds[$i] = (string) $bindings[$i];
241248 }
242-
243249 $i++;
244250 }
245251 }
246252 }
253+ */
247254
248255 return $ newBinds ;
249256 }
0 commit comments