diff --git a/.phpunit.result.cache b/.phpunit.result.cache index e6d3699..54576f7 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":7966:{a:2:{s:7:"defects";a:55:{s:39:"Pecee\Pixie\QueryBuilderTest::testAlias";i:3;s:45:"Pecee\Pixie\QueryBuilderTest::testDeleteQuery";i:3;s:50:"Pecee\Pixie\QueryBuilderTest::testEventPropagation";i:4;s:51:"Pecee\Pixie\QueryBuilderTest::testInsertIgnoreQuery";i:4;s:65:"Pecee\Pixie\QueryBuilderTest::testInsertOnDuplicateKeyUpdateQuery";i:4;s:45:"Pecee\Pixie\QueryBuilderTest::testInsertQuery";i:4;s:70:"Pecee\Pixie\QueryBuilderTest::testIsPossibleToUseSubqueryInWhereClause";i:3;s:73:"Pecee\Pixie\QueryBuilderTest::testIsPossibleToUseSubqueryInWhereNotClause";i:3;s:52:"Pecee\Pixie\QueryBuilderTest::testOrderByFlexibility";i:4;s:61:"Pecee\Pixie\QueryBuilderTest::testRawStatementsWithinCriteria";i:3;s:61:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinStatement";i:3;s:58:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinSelect";i:3;s:46:"Pecee\Pixie\QueryBuilderTest::testReplaceQuery";i:4;s:47:"Pecee\Pixie\QueryBuilderTest::testSelectAliases";i:4;s:48:"Pecee\Pixie\QueryBuilderTest::testSelectDistinct";i:4;s:62:"Pecee\Pixie\QueryBuilderTest::testSelectDistinctAndSelectCalls";i:4;s:64:"Pecee\Pixie\QueryBuilderTest::testSelectDistinctWithSingleColumn";i:4;s:51:"Pecee\Pixie\QueryBuilderTest::testSelectFlexibility";i:4;s:45:"Pecee\Pixie\QueryBuilderTest::testSelectQuery";i:3;s:71:"Pecee\Pixie\QueryBuilderTest::testSelectQueryWithNestedCriteriaAndJoins";i:3;s:53:"Pecee\Pixie\QueryBuilderTest::testSelectQueryWithNull";i:3;s:55:"Pecee\Pixie\QueryBuilderTest::testSelectWithQueryEvents";i:3;s:52:"Pecee\Pixie\QueryBuilderTest::testStandaloneWhereNot";i:3;s:45:"Pecee\Pixie\QueryBuilderTest::testUpdateQuery";i:3;s:53:"Pecee\Pixie\QueryBuilderTest::testDeleteAdvancedQuery";i:3;s:53:"Pecee\Pixie\QueryBuilderTest::testUpdateAdvancedQuery";i:3;s:46:"Pecee\Pixie\QueryBuilderTest::testFromSubQuery";i:3;s:44:"Pecee\Pixie\QueryBuilderTest::testTableAlias";i:4;s:54:"Pecee\Pixie\QueryBuilderTest::testWhereNotNullSubQuery";i:4;s:43:"Pecee\Pixie\QueryBuilderTest::testJoinUsing";i:3;s:55:"Pecee\Pixie\QueryBuilderTest::testJoinQueryBuilderUsing";i:3;s:60:"Pecee\Pixie\CustomExceptionsTest::testTableNotFoundException";i:4;s:61:"Pecee\Pixie\CustomExceptionsTest::testColumnNotFoundException";i:4;s:61:"Pecee\Pixie\CustomExceptionsTest::testDuplicateEntryException";i:4;s:75:"Pecee\Pixie\CustomExceptionsTest::testQueryAggregateColumnNotFoundException";i:4;s:57:"Pecee\Pixie\CustomExceptionsTest::testForeignKeyException";i:4;s:54:"Pecee\Pixie\CustomExceptionsTest::testNotNullException";i:4;s:53:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryCount";i:4;s:59:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQueryCount";i:4;s:51:"Pecee\Pixie\QueryBuilderAggregateTest::testQuerySum";i:4;s:57:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQuerySum";i:4;s:55:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryAverage";i:4;s:61:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQueryAverage";i:4;s:50:"Pecee\Pixie\TransactionTest::testTransactionResult";i:4;s:51:"Pecee\Pixie\TransactionTest::testNestedTransactions";i:4;s:58:"Pecee\Pixie\TransactionTest::testTransactionMultipleInsert";i:4;s:42:"Pecee\Pixie\TransactionTest::testLastQuery";i:3;s:47:"Pecee\Pixie\QueryBuilderTest::testRawExpression";i:3;s:44:"Pecee\Pixie\QueryBuilder::testFalseBoolWhere";i:3;s:43:"Pecee\Pixie\QueryBuilder::testNullableWhere";i:3;s:42:"Pecee\Pixie\QueryBuilder::testWhereBetween";i:3;s:35:"Pecee\Pixie\QueryBuilder::testUnion";i:3;s:43:"Pecee\Pixie\QueryBuilder::testUnionSubQuery";i:3;s:44:"Pecee\Pixie\QueryBuilder::testQueryOverwrite";i:3;s:41:"Pecee\Pixie\QueryBuilder::testRemoveQuery";i:3;}s:5:"times";a:65:{s:39:"Pecee\Pixie\QueryBuilderTest::testAlias";d:0.001;s:45:"Pecee\Pixie\QueryBuilderTest::testDeleteQuery";d:0.001;s:50:"Pecee\Pixie\QueryBuilderTest::testEventPropagation";d:0.001;s:51:"Pecee\Pixie\QueryBuilderTest::testInsertIgnoreQuery";d:0.001;s:65:"Pecee\Pixie\QueryBuilderTest::testInsertOnDuplicateKeyUpdateQuery";d:0;s:45:"Pecee\Pixie\QueryBuilderTest::testInsertQuery";d:0;s:70:"Pecee\Pixie\QueryBuilderTest::testIsPossibleToUseSubqueryInWhereClause";d:0;s:73:"Pecee\Pixie\QueryBuilderTest::testIsPossibleToUseSubqueryInWhereNotClause";d:0;s:52:"Pecee\Pixie\QueryBuilderTest::testOrderByFlexibility";d:0;s:61:"Pecee\Pixie\QueryBuilderTest::testRawStatementsWithinCriteria";d:0;s:61:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinStatement";d:0;s:58:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinSelect";d:0.001;s:46:"Pecee\Pixie\QueryBuilderTest::testReplaceQuery";d:0;s:47:"Pecee\Pixie\QueryBuilderTest::testSelectAliases";d:0;s:48:"Pecee\Pixie\QueryBuilderTest::testSelectDistinct";d:0;s:62:"Pecee\Pixie\QueryBuilderTest::testSelectDistinctAndSelectCalls";d:0;s:64:"Pecee\Pixie\QueryBuilderTest::testSelectDistinctWithSingleColumn";d:0;s:51:"Pecee\Pixie\QueryBuilderTest::testSelectFlexibility";d:0;s:45:"Pecee\Pixie\QueryBuilderTest::testSelectQuery";d:0.001;s:71:"Pecee\Pixie\QueryBuilderTest::testSelectQueryWithNestedCriteriaAndJoins";d:0.001;s:53:"Pecee\Pixie\QueryBuilderTest::testSelectQueryWithNull";d:0;s:55:"Pecee\Pixie\QueryBuilderTest::testSelectWithQueryEvents";d:0.001;s:52:"Pecee\Pixie\QueryBuilderTest::testStandaloneWhereNot";d:0;s:45:"Pecee\Pixie\QueryBuilderTest::testUpdateQuery";d:0;s:53:"Pecee\Pixie\QueryBuilderTest::testDeleteAdvancedQuery";d:0.001;s:53:"Pecee\Pixie\QueryBuilderTest::testUpdateAdvancedQuery";d:0.001;s:46:"Pecee\Pixie\QueryBuilderTest::testFromSubQuery";d:0;s:44:"Pecee\Pixie\QueryBuilderTest::testTableAlias";d:0;s:54:"Pecee\Pixie\QueryBuilderTest::testWhereNotNullSubQuery";d:0.001;s:43:"Pecee\Pixie\QueryBuilderTest::testJoinUsing";d:0.001;s:55:"Pecee\Pixie\QueryBuilderTest::testJoinQueryBuilderUsing";d:0.001;s:42:"Pecee\Pixie\ConnectionTest::testConnection";d:0.048;s:47:"Pecee\Pixie\ConnectionTest::testMultiConnection";d:0.001;s:57:"Pecee\Pixie\CustomExceptionsTest::testConnectionException";d:0.007;s:60:"Pecee\Pixie\CustomExceptionsTest::testTableNotFoundException";d:0.059;s:61:"Pecee\Pixie\CustomExceptionsTest::testColumnNotFoundException";d:0.053;s:61:"Pecee\Pixie\CustomExceptionsTest::testDuplicateEntryException";d:0.059;s:75:"Pecee\Pixie\CustomExceptionsTest::testQueryAggregateColumnNotFoundException";d:0.045;s:57:"Pecee\Pixie\CustomExceptionsTest::testForeignKeyException";d:0.044;s:54:"Pecee\Pixie\CustomExceptionsTest::testNotNullException";d:0.046;s:45:"Pecee\Pixie\NoTableSubQueryTest::testRawQuery";d:0.001;s:53:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryCount";d:0.048;s:59:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQueryCount";d:0.002;s:51:"Pecee\Pixie\QueryBuilderAggregateTest::testQuerySum";d:0.039;s:57:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQuerySum";d:0.002;s:55:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryAverage";d:0.037;s:61:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQueryAverage";d:0.001;s:44:"Pecee\Pixie\QueryBuilder::testFalseBoolWhere";d:0;s:59:"Pecee\Pixie\QueryBuilder::testInsertQueryReturnsIdForInsert";d:0.002;s:65:"Pecee\Pixie\QueryBuilder::testInsertQueryReturnsIdForInsertIgnore";d:0.001;s:68:"Pecee\Pixie\QueryBuilder::testInsertQueryReturnsNullForIgnoredInsert";d:0.001;s:38:"Pecee\Pixie\QueryBuilder::testRawQuery";d:0.001;s:43:"Pecee\Pixie\QueryBuilder::testNullableWhere";d:0.001;s:42:"Pecee\Pixie\QueryBuilder::testWhereBetween";d:0.001;s:35:"Pecee\Pixie\QueryBuilder::testUnion";d:0.001;s:43:"Pecee\Pixie\QueryBuilder::testUnionSubQuery";d:0.001;s:44:"Pecee\Pixie\QueryBuilder::testQueryOverwrite";d:0.001;s:40:"Pecee\Pixie\QueryBuilder::testGetColumns";d:0.001;s:42:"Pecee\Pixie\QueryBuilder::testQueryPartFor";d:0;s:41:"Pecee\Pixie\QueryBuilder::testRemoveQuery";d:0.001;s:50:"Pecee\Pixie\TransactionTest::testTransactionResult";d:0.043;s:51:"Pecee\Pixie\TransactionTest::testNestedTransactions";d:0.05;s:58:"Pecee\Pixie\TransactionTest::testTransactionMultipleInsert";d:0.043;s:42:"Pecee\Pixie\TransactionTest::testLastQuery";d:0.038;s:47:"Pecee\Pixie\QueryBuilderTest::testRawExpression";d:0;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":4437:{a:2:{s:7:"defects";a:0:{}s:5:"times";a:66:{s:42:"Pecee\Pixie\ConnectionTest::testConnection";d:0.059;s:47:"Pecee\Pixie\ConnectionTest::testMultiConnection";d:0.001;s:57:"Pecee\Pixie\CustomExceptionsTest::testConnectionException";d:0.121;s:60:"Pecee\Pixie\CustomExceptionsTest::testTableNotFoundException";d:0.467;s:61:"Pecee\Pixie\CustomExceptionsTest::testColumnNotFoundException";d:0.053;s:61:"Pecee\Pixie\CustomExceptionsTest::testDuplicateEntryException";d:0.052;s:75:"Pecee\Pixie\CustomExceptionsTest::testQueryAggregateColumnNotFoundException";d:0.048;s:57:"Pecee\Pixie\CustomExceptionsTest::testForeignKeyException";d:0.044;s:54:"Pecee\Pixie\CustomExceptionsTest::testNotNullException";d:0.041;s:45:"Pecee\Pixie\NoTableSubQueryTest::testRawQuery";d:0.001;s:53:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryCount";d:0.039;s:59:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQueryCount";d:0.001;s:51:"Pecee\Pixie\QueryBuilderAggregateTest::testQuerySum";d:0.041;s:57:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQuerySum";d:0.001;s:55:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryAverage";d:0.039;s:61:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQueryAverage";d:0.002;s:39:"Pecee\Pixie\QueryBuilderTest::testAlias";d:0.001;s:45:"Pecee\Pixie\QueryBuilderTest::testDeleteQuery";d:0.001;s:50:"Pecee\Pixie\QueryBuilderTest::testEventPropagation";d:0.001;s:51:"Pecee\Pixie\QueryBuilderTest::testInsertIgnoreQuery";d:0;s:65:"Pecee\Pixie\QueryBuilderTest::testInsertOnDuplicateKeyUpdateQuery";d:0;s:45:"Pecee\Pixie\QueryBuilderTest::testInsertQuery";d:0;s:70:"Pecee\Pixie\QueryBuilderTest::testIsPossibleToUseSubqueryInWhereClause";d:0;s:73:"Pecee\Pixie\QueryBuilderTest::testIsPossibleToUseSubqueryInWhereNotClause";d:0;s:52:"Pecee\Pixie\QueryBuilderTest::testOrderByFlexibility";d:0;s:61:"Pecee\Pixie\QueryBuilderTest::testRawStatementsWithinCriteria";d:0.001;s:61:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinStatement";d:0;s:58:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinSelect";d:0.001;s:56:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinJoin";d:0.001;s:47:"Pecee\Pixie\QueryBuilderTest::testRawExpression";d:0.001;s:46:"Pecee\Pixie\QueryBuilderTest::testReplaceQuery";d:0.001;s:47:"Pecee\Pixie\QueryBuilderTest::testSelectAliases";d:0.001;s:48:"Pecee\Pixie\QueryBuilderTest::testSelectDistinct";d:0;s:62:"Pecee\Pixie\QueryBuilderTest::testSelectDistinctAndSelectCalls";d:0;s:64:"Pecee\Pixie\QueryBuilderTest::testSelectDistinctWithSingleColumn";d:0;s:51:"Pecee\Pixie\QueryBuilderTest::testSelectFlexibility";d:0;s:45:"Pecee\Pixie\QueryBuilderTest::testSelectQuery";d:0.001;s:71:"Pecee\Pixie\QueryBuilderTest::testSelectQueryWithNestedCriteriaAndJoins";d:0.001;s:53:"Pecee\Pixie\QueryBuilderTest::testSelectQueryWithNull";d:0;s:55:"Pecee\Pixie\QueryBuilderTest::testSelectWithQueryEvents";d:0;s:52:"Pecee\Pixie\QueryBuilderTest::testStandaloneWhereNot";d:0;s:45:"Pecee\Pixie\QueryBuilderTest::testUpdateQuery";d:0;s:53:"Pecee\Pixie\QueryBuilderTest::testDeleteAdvancedQuery";d:0;s:53:"Pecee\Pixie\QueryBuilderTest::testUpdateAdvancedQuery";d:0;s:46:"Pecee\Pixie\QueryBuilderTest::testFromSubQuery";d:0;s:44:"Pecee\Pixie\QueryBuilderTest::testTableAlias";d:0;s:54:"Pecee\Pixie\QueryBuilderTest::testWhereNotNullSubQuery";d:0;s:43:"Pecee\Pixie\QueryBuilderTest::testJoinUsing";d:0;s:55:"Pecee\Pixie\QueryBuilderTest::testJoinQueryBuilderUsing";d:0;s:44:"Pecee\Pixie\QueryBuilder::testFalseBoolWhere";d:0;s:59:"Pecee\Pixie\QueryBuilder::testInsertQueryReturnsIdForInsert";d:0.001;s:65:"Pecee\Pixie\QueryBuilder::testInsertQueryReturnsIdForInsertIgnore";d:0;s:68:"Pecee\Pixie\QueryBuilder::testInsertQueryReturnsNullForIgnoredInsert";d:0;s:38:"Pecee\Pixie\QueryBuilder::testRawQuery";d:0;s:43:"Pecee\Pixie\QueryBuilder::testNullableWhere";d:0;s:42:"Pecee\Pixie\QueryBuilder::testWhereBetween";d:0;s:35:"Pecee\Pixie\QueryBuilder::testUnion";d:0;s:43:"Pecee\Pixie\QueryBuilder::testUnionSubQuery";d:0;s:44:"Pecee\Pixie\QueryBuilder::testQueryOverwrite";d:0.001;s:40:"Pecee\Pixie\QueryBuilder::testGetColumns";d:0.001;s:42:"Pecee\Pixie\QueryBuilder::testQueryPartFor";d:0;s:41:"Pecee\Pixie\QueryBuilder::testRemoveQuery";d:0.001;s:50:"Pecee\Pixie\TransactionTest::testTransactionResult";d:0.044;s:51:"Pecee\Pixie\TransactionTest::testNestedTransactions";d:0.049;s:58:"Pecee\Pixie\TransactionTest::testTransactionMultipleInsert";d:0.039;s:42:"Pecee\Pixie\TransactionTest::testLastQuery";d:0.041;}}} \ No newline at end of file diff --git a/src/Pecee/Pixie/QueryBuilder/Adapters/BaseAdapter.php b/src/Pecee/Pixie/QueryBuilder/Adapters/BaseAdapter.php index f3d2831..54ebbaa 100644 --- a/src/Pecee/Pixie/QueryBuilder/Adapters/BaseAdapter.php +++ b/src/Pecee/Pixie/QueryBuilder/Adapters/BaseAdapter.php @@ -165,6 +165,10 @@ protected function buildCriteria(array $statements, bool $bindValues = true): ar $value = $statement['value']; + if ($value instanceof Raw) { + $bindings[] = $value->getBindings(); + } + if ($value === null && $key instanceof \Closure) { /** @@ -290,11 +294,12 @@ protected function buildCriteriaWithType(array $statements, $key, $type, $bindVa * Build join string * * @param array $statements + * @param array $bindings * * @return string * @throws Exception */ - protected function buildJoin(array $statements): string + protected function buildJoin(array $statements, array &$bindings): string { $sql = ''; @@ -313,12 +318,20 @@ protected function buildJoin(array $statements): string /* @var $joinBuilder QueryBuilderHandler */ $joinBuilder = $joinArr['joinBuilder']; + $valueSql = ''; + + if ($joinBuilder instanceof QueryBuilderHandler) { + $valueQuery = $joinBuilder->getQuery('criteriaOnly', false); + $valueSql = $valueQuery->getSql(); + $bindings += $valueQuery->getBindings(); + } + $sqlArr = [ $sql, strtoupper($joinArr['type']), 'JOIN', $table, - $joinBuilder instanceof QueryBuilderHandler ? $joinBuilder->getQuery('criteriaOnly', false)->getSql() : '', + $valueSql, ]; $sql = $this->concatenateQuery($sqlArr); @@ -387,21 +400,20 @@ public function delete(array $statements, array $columns = null): array } // WHERE - [$whereCriteria, $whereBindings] = $this->buildCriteriaWithType($statements, 'wheres', 'WHERE'); + [$whereCriteria, $bindings] = $this->buildCriteriaWithType($statements, 'wheres', 'WHERE'); $sql = $this->concatenateQuery([ 'DELETE ', $columnsQuery, ' FROM', $this->wrapSanitizer($table), - $this->buildQueryPart(static::QUERY_PART_JOIN, $statements), + $this->buildQueryPart(static::QUERY_PART_JOIN, $statements, $bindings), $whereCriteria, - $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements), - $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements), - $this->buildQueryPart(static::QUERY_PART_LIMIT, $statements), - $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements), + $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_LIMIT, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements, $bindings), ]); - $bindings = $whereBindings; return compact('sql', 'bindings'); } @@ -610,14 +622,14 @@ public function select(array $statements): array $this->arrayStr($statements['selects'], ', '), $fromEnabled ? 'FROM' : '', $tables, - $this->buildQueryPart(static::QUERY_PART_JOIN, $statements), + $this->buildQueryPart(static::QUERY_PART_JOIN, $statements, $bindings), $whereCriteria, - $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements), + $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements, $bindings), $havingCriteria, - $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements), - $this->buildQueryPart(static::QUERY_PART_LIMIT, $statements), - $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements), - $this->buildQueryPart(static::QUERY_PART_FOR, $statements), + $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_LIMIT, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_FOR, $statements, $bindings), ]); $sql = $this->buildUnion($statements, $sql); @@ -636,14 +648,15 @@ public function select(array $statements): array * * @param string $section * @param array $statements + * @param array $bindings * @return string * @throws Exception */ - protected function buildQueryPart(string $section, array $statements): string + protected function buildQueryPart(string $section, array $statements, array &$bindings): string { switch ($section) { case static::QUERY_PART_JOIN: - return $this->buildJoin($statements); + return $this->buildJoin($statements, $bindings); case static::QUERY_PART_TOP: return isset($statements['limit']) ? 'TOP ' . $statements['limit'] : ''; case static::QUERY_PART_LIMIT: @@ -733,13 +746,13 @@ public function update(array $statements, array $data): array $sqlArray = [ 'UPDATE', $this->buildAliasedTableName($table, $statements), - $this->buildQueryPart(static::QUERY_PART_JOIN, $statements), + $this->buildQueryPart(static::QUERY_PART_JOIN, $statements, $bindings), 'SET ' . $updateStatement, $whereCriteria, - $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements), - $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements), - $this->buildQueryPart(static::QUERY_PART_LIMIT, $statements), - $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements), + $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_LIMIT, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements, $bindings), ]; $sql = $this->concatenateQuery($sqlArray); diff --git a/src/Pecee/Pixie/QueryBuilder/Adapters/Sqlserver.php b/src/Pecee/Pixie/QueryBuilder/Adapters/Sqlserver.php index a754aaa..2d35e5e 100644 --- a/src/Pecee/Pixie/QueryBuilder/Adapters/Sqlserver.php +++ b/src/Pecee/Pixie/QueryBuilder/Adapters/Sqlserver.php @@ -30,10 +30,11 @@ class Sqlserver extends BaseAdapter * Overridden method for SQL SERVER correct usage of: OFFSET x ROWS FETCH NEXT y ROWS ONLY * @param string $section * @param array $statements + * @param array $bindings * @return string * @throws Exception */ - protected function buildQueryPart(string $section, array $statements): string + protected function buildQueryPart(string $section, array $statements, array &$bindings): string { switch ($section) { case static::QUERY_PART_TOP: @@ -43,7 +44,7 @@ protected function buildQueryPart(string $section, array $statements): string case static::QUERY_PART_FETCH_NEXT: return isset($statements['fetch_next']) ? 'FETCH NEXT '.$statements['fetch_next'].' ROWS ONLY' : ''; default: - return parent::buildQueryPart($section, $statements); + return parent::buildQueryPart($section, $statements, $bindings); } } @@ -95,17 +96,17 @@ public function select(array $statements): array $sql = $this->concatenateQuery([ 'SELECT' . ($hasDistincts === true ? ' DISTINCT' : ''), - $this->buildQueryPart(static::QUERY_PART_TOP, $statements), + $this->buildQueryPart(static::QUERY_PART_TOP, $statements, $bindings), $this->arrayStr($statements['selects'], ', '), $fromEnabled ? 'FROM' : '', $tables, - $this->buildQueryPart(static::QUERY_PART_JOIN, $statements), + $this->buildQueryPart(static::QUERY_PART_JOIN, $statements, $bindings), $whereCriteria, - $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements), + $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements, $bindings), $havingCriteria, - $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements), - $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements), - $this->buildQueryPart(static::QUERY_PART_FETCH_NEXT, $statements), + $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_FETCH_NEXT, $statements, $bindings), ]); $sql = $this->buildUnion($statements, $sql); @@ -139,20 +140,19 @@ public function delete(array $statements, array $columns = null): array } // WHERE - [$whereCriteria, $whereBindings] = $this->buildCriteriaWithType($statements, 'wheres', 'WHERE'); + [$whereCriteria, $bindings] = $this->buildCriteriaWithType($statements, 'wheres', 'WHERE'); $sql = $this->concatenateQuery([ 'DELETE ', $columnsQuery, ' FROM', $this->wrapSanitizer($table), - $this->buildQueryPart(static::QUERY_PART_JOIN, $statements), + $this->buildQueryPart(static::QUERY_PART_JOIN, $statements, $bindings), $whereCriteria, - $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements), - $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements), - $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements), + $this->buildQueryPart(static::QUERY_PART_GROUPBY, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_ORDERBY, $statements, $bindings), + $this->buildQueryPart(static::QUERY_PART_OFFSET, $statements, $bindings), ]); - $bindings = $whereBindings; return compact('sql', 'bindings'); } diff --git a/tests/Pecee/Pixie/QueryBuilderBehaviorTest.php b/tests/Pecee/Pixie/QueryBuilderBehaviorTest.php index 8d7ec5a..32f2846 100644 --- a/tests/Pecee/Pixie/QueryBuilderBehaviorTest.php +++ b/tests/Pecee/Pixie/QueryBuilderBehaviorTest.php @@ -188,6 +188,18 @@ public function testRawStatementWithinSelect() { ); } + public function testRawStatementWithinJoin() { + $this->builder->from('my_table') + ->join('people', 'id', '=', $this->builder->raw("CONCAT('hej', ?)", ['shemales'])) + ->where('simple', '=', 'criteria') + ->first(); + + $this->assertEquals( + "SELECT * FROM `cb_my_table` JOIN `cb_people` ON `id` = CONCAT('hej', 'shemales') WHERE `simple` = 'criteria' LIMIT 1", + $this->builder->getLastQuery()->getRawSql() + ); + } + public function testRawExpression() { $query = $this->builder ->table('my_table')