@@ -165,6 +165,10 @@ protected function buildCriteria(array $statements, bool $bindValues = true): ar
165165
166166 $ value = $ statement ['value ' ];
167167
168+ if ($ value instanceof Raw) {
169+ $ bindings [] = $ value ->getBindings ();
170+ }
171+
168172 if ($ value === null && $ key instanceof \Closure) {
169173
170174 /**
@@ -290,11 +294,12 @@ protected function buildCriteriaWithType(array $statements, $key, $type, $bindVa
290294 * Build join string
291295 *
292296 * @param array $statements
297+ * @param array $bindings
293298 *
294299 * @return string
295300 * @throws Exception
296301 */
297- protected function buildJoin (array $ statements ): string
302+ protected function buildJoin (array $ statements, array & $ bindings ): string
298303 {
299304 $ sql = '' ;
300305
@@ -313,12 +318,20 @@ protected function buildJoin(array $statements): string
313318 /* @var $joinBuilder QueryBuilderHandler */
314319 $ joinBuilder = $ joinArr ['joinBuilder ' ];
315320
321+ $ valueSql = '' ;
322+
323+ if ($ joinBuilder instanceof QueryBuilderHandler) {
324+ $ valueQuery = $ joinBuilder ->getQuery ('criteriaOnly ' , false );
325+ $ valueSql = $ valueQuery ->getSql ();
326+ $ bindings += $ valueQuery ->getBindings ();
327+ }
328+
316329 $ sqlArr = [
317330 $ sql ,
318331 strtoupper ($ joinArr ['type ' ]),
319332 'JOIN ' ,
320333 $ table ,
321- $ joinBuilder instanceof QueryBuilderHandler ? $ joinBuilder -> getQuery ( ' criteriaOnly ' , false )-> getSql () : '' ,
334+ $ valueSql ,
322335 ];
323336
324337 $ sql = $ this ->concatenateQuery ($ sqlArr );
@@ -387,21 +400,20 @@ public function delete(array $statements, array $columns = null): array
387400 }
388401
389402 // WHERE
390- [$ whereCriteria , $ whereBindings ] = $ this ->buildCriteriaWithType ($ statements , 'wheres ' , 'WHERE ' );
403+ [$ whereCriteria , $ bindings ] = $ this ->buildCriteriaWithType ($ statements , 'wheres ' , 'WHERE ' );
391404
392405 $ sql = $ this ->concatenateQuery ([
393406 'DELETE ' ,
394407 $ columnsQuery ,
395408 ' FROM ' ,
396409 $ this ->wrapSanitizer ($ table ),
397- $ this ->buildQueryPart (static ::QUERY_PART_JOIN , $ statements ),
410+ $ this ->buildQueryPart (static ::QUERY_PART_JOIN , $ statements, $ bindings ),
398411 $ whereCriteria ,
399- $ this ->buildQueryPart (static ::QUERY_PART_GROUPBY , $ statements ),
400- $ this ->buildQueryPart (static ::QUERY_PART_ORDERBY , $ statements ),
401- $ this ->buildQueryPart (static ::QUERY_PART_LIMIT , $ statements ),
402- $ this ->buildQueryPart (static ::QUERY_PART_OFFSET , $ statements ),
412+ $ this ->buildQueryPart (static ::QUERY_PART_GROUPBY , $ statements, $ bindings ),
413+ $ this ->buildQueryPart (static ::QUERY_PART_ORDERBY , $ statements, $ bindings ),
414+ $ this ->buildQueryPart (static ::QUERY_PART_LIMIT , $ statements, $ bindings ),
415+ $ this ->buildQueryPart (static ::QUERY_PART_OFFSET , $ statements, $ bindings ),
403416 ]);
404- $ bindings = $ whereBindings ;
405417
406418 return compact ('sql ' , 'bindings ' );
407419 }
@@ -610,14 +622,14 @@ public function select(array $statements): array
610622 $ this ->arrayStr ($ statements ['selects ' ], ', ' ),
611623 $ fromEnabled ? 'FROM ' : '' ,
612624 $ tables ,
613- $ this ->buildQueryPart (static ::QUERY_PART_JOIN , $ statements ),
625+ $ this ->buildQueryPart (static ::QUERY_PART_JOIN , $ statements, $ bindings ),
614626 $ whereCriteria ,
615- $ this ->buildQueryPart (static ::QUERY_PART_GROUPBY , $ statements ),
627+ $ this ->buildQueryPart (static ::QUERY_PART_GROUPBY , $ statements, $ bindings ),
616628 $ havingCriteria ,
617- $ this ->buildQueryPart (static ::QUERY_PART_ORDERBY , $ statements ),
618- $ this ->buildQueryPart (static ::QUERY_PART_LIMIT , $ statements ),
619- $ this ->buildQueryPart (static ::QUERY_PART_OFFSET , $ statements ),
620- $ this ->buildQueryPart (static ::QUERY_PART_FOR , $ statements ),
629+ $ this ->buildQueryPart (static ::QUERY_PART_ORDERBY , $ statements, $ bindings ),
630+ $ this ->buildQueryPart (static ::QUERY_PART_LIMIT , $ statements, $ bindings ),
631+ $ this ->buildQueryPart (static ::QUERY_PART_OFFSET , $ statements, $ bindings ),
632+ $ this ->buildQueryPart (static ::QUERY_PART_FOR , $ statements, $ bindings ),
621633 ]);
622634
623635 $ sql = $ this ->buildUnion ($ statements , $ sql );
@@ -636,14 +648,15 @@ public function select(array $statements): array
636648 *
637649 * @param string $section
638650 * @param array $statements
651+ * @param array $bindings
639652 * @return string
640653 * @throws Exception
641654 */
642- protected function buildQueryPart (string $ section , array $ statements ): string
655+ protected function buildQueryPart (string $ section , array $ statements, array & $ bindings ): string
643656 {
644657 switch ($ section ) {
645658 case static ::QUERY_PART_JOIN :
646- return $ this ->buildJoin ($ statements );
659+ return $ this ->buildJoin ($ statements, $ bindings );
647660 case static ::QUERY_PART_TOP :
648661 return isset ($ statements ['limit ' ]) ? 'TOP ' . $ statements ['limit ' ] : '' ;
649662 case static ::QUERY_PART_LIMIT :
@@ -733,13 +746,13 @@ public function update(array $statements, array $data): array
733746 $ sqlArray = [
734747 'UPDATE ' ,
735748 $ this ->buildAliasedTableName ($ table , $ statements ),
736- $ this ->buildQueryPart (static ::QUERY_PART_JOIN , $ statements ),
749+ $ this ->buildQueryPart (static ::QUERY_PART_JOIN , $ statements, $ bindings ),
737750 'SET ' . $ updateStatement ,
738751 $ whereCriteria ,
739- $ this ->buildQueryPart (static ::QUERY_PART_GROUPBY , $ statements ),
740- $ this ->buildQueryPart (static ::QUERY_PART_ORDERBY , $ statements ),
741- $ this ->buildQueryPart (static ::QUERY_PART_LIMIT , $ statements ),
742- $ this ->buildQueryPart (static ::QUERY_PART_OFFSET , $ statements ),
752+ $ this ->buildQueryPart (static ::QUERY_PART_GROUPBY , $ statements, $ bindings ),
753+ $ this ->buildQueryPart (static ::QUERY_PART_ORDERBY , $ statements, $ bindings ),
754+ $ this ->buildQueryPart (static ::QUERY_PART_LIMIT , $ statements, $ bindings ),
755+ $ this ->buildQueryPart (static ::QUERY_PART_OFFSET , $ statements, $ bindings ),
743756 ];
744757
745758 $ sql = $ this ->concatenateQuery ($ sqlArray );
0 commit comments