From 415f600478bce82a13c5932c6f1ca78cf947dcdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Tue, 8 Jun 2021 00:54:57 +0200 Subject: [PATCH] Fixed Raw not working correctly for join statements, for example: `->join('hostnames', 'host', '=', $this->raw('?', [$host]))` - Changed references for SqlServer class. --- .phpunit.result.cache | 2 +- .../QueryBuilder/Adapters/BaseAdapter.php | 82 +++++++++++-------- .../Pixie/QueryBuilder/Adapters/Sqlserver.php | 28 +++---- .../Pecee/Pixie/QueryBuilderBehaviorTest.php | 12 +++ tests/TestCase.php | 2 +- 5 files changed, 76 insertions(+), 50 deletions(-) diff --git a/.phpunit.result.cache b/.phpunit.result.cache index 08e6d59..365efb7 100644 --- a/.phpunit.result.cache +++ b/.phpunit.result.cache @@ -1 +1 @@ -C:37:"PHPUnit\Runner\DefaultTestResultCache":7914:{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;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.001;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.001;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;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:42:"Pecee\Pixie\ConnectionTest::testConnection";d:0.023;s:47:"Pecee\Pixie\ConnectionTest::testMultiConnection";d:0.001;s:57:"Pecee\Pixie\CustomExceptionsTest::testConnectionException";d:0.004;s:60:"Pecee\Pixie\CustomExceptionsTest::testTableNotFoundException";d:0.041;s:61:"Pecee\Pixie\CustomExceptionsTest::testColumnNotFoundException";d:0.043;s:61:"Pecee\Pixie\CustomExceptionsTest::testDuplicateEntryException";d:0.039;s:75:"Pecee\Pixie\CustomExceptionsTest::testQueryAggregateColumnNotFoundException";d:0.047;s:57:"Pecee\Pixie\CustomExceptionsTest::testForeignKeyException";d:0.045;s:54:"Pecee\Pixie\CustomExceptionsTest::testNotNullException";d:0.043;s:45:"Pecee\Pixie\NoTableSubQueryTest::testRawQuery";d:0.001;s:53:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryCount";d:0.037;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.001;s:55:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryAverage";d:0.04;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.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;s:40:"Pecee\Pixie\QueryBuilder::testGetColumns";d:0;s:42:"Pecee\Pixie\QueryBuilder::testQueryPartFor";d:0;s:41:"Pecee\Pixie\QueryBuilder::testRemoveQuery";d:0;s:50:"Pecee\Pixie\TransactionTest::testTransactionResult";d:0.047;s:51:"Pecee\Pixie\TransactionTest::testNestedTransactions";d:0.048;s:58:"Pecee\Pixie\TransactionTest::testTransactionMultipleInsert";d:0.042;s:42:"Pecee\Pixie\TransactionTest::testLastQuery";d:0.039;s:47:"Pecee\Pixie\QueryBuilderTest::testRawExpression";d:0;}}} \ No newline at end of file +C:37:"PHPUnit\Runner\DefaultTestResultCache":8248:{a:2:{s:7:"defects";a:59:{s:39:"Pecee\Pixie\QueryBuilderTest::testAlias";i:4;s:45:"Pecee\Pixie\QueryBuilderTest::testDeleteQuery";i:4;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:4;s:73:"Pecee\Pixie\QueryBuilderTest::testIsPossibleToUseSubqueryInWhereNotClause";i:4;s:52:"Pecee\Pixie\QueryBuilderTest::testOrderByFlexibility";i:4;s:61:"Pecee\Pixie\QueryBuilderTest::testRawStatementsWithinCriteria";i:4;s:61:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinStatement";i:3;s:58:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinSelect";i:4;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:4;s:55:"Pecee\Pixie\QueryBuilderTest::testSelectWithQueryEvents";i:4;s:52:"Pecee\Pixie\QueryBuilderTest::testStandaloneWhereNot";i:4;s:45:"Pecee\Pixie\QueryBuilderTest::testUpdateQuery";i:3;s:53:"Pecee\Pixie\QueryBuilderTest::testDeleteAdvancedQuery";i:4;s:53:"Pecee\Pixie\QueryBuilderTest::testUpdateAdvancedQuery";i:3;s:46:"Pecee\Pixie\QueryBuilderTest::testFromSubQuery";i:4;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:4;s:47:"Pecee\Pixie\QueryBuilderTest::testRawExpression";i:4;s:44:"Pecee\Pixie\QueryBuilder::testFalseBoolWhere";i:4;s:43:"Pecee\Pixie\QueryBuilder::testNullableWhere";i:4;s:42:"Pecee\Pixie\QueryBuilder::testWhereBetween";i:4;s:35:"Pecee\Pixie\QueryBuilder::testUnion";i:4;s:43:"Pecee\Pixie\QueryBuilder::testUnionSubQuery";i:4;s:44:"Pecee\Pixie\QueryBuilder::testQueryOverwrite";i:4;s:41:"Pecee\Pixie\QueryBuilder::testRemoveQuery";i:4;s:56:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinJoin";i:3;s:45:"Pecee\Pixie\NoTableSubQueryTest::testRawQuery";i:4;s:38:"Pecee\Pixie\QueryBuilder::testRawQuery";i:4;s:42:"Pecee\Pixie\QueryBuilder::testQueryPartFor";i:4;}s:5:"times";a:66:{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.002;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.001;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.001;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.002;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.001;s:53:"Pecee\Pixie\QueryBuilderTest::testUpdateAdvancedQuery";d:0.001;s:46:"Pecee\Pixie\QueryBuilderTest::testFromSubQuery";d:0.001;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.059;s:47:"Pecee\Pixie\ConnectionTest::testMultiConnection";d:0.001;s:57:"Pecee\Pixie\CustomExceptionsTest::testConnectionException";d:0.006;s:60:"Pecee\Pixie\CustomExceptionsTest::testTableNotFoundException";d:0.086;s:61:"Pecee\Pixie\CustomExceptionsTest::testColumnNotFoundException";d:0.059;s:61:"Pecee\Pixie\CustomExceptionsTest::testDuplicateEntryException";d:0.056;s:75:"Pecee\Pixie\CustomExceptionsTest::testQueryAggregateColumnNotFoundException";d:0.053;s:57:"Pecee\Pixie\CustomExceptionsTest::testForeignKeyException";d:0.045;s:54:"Pecee\Pixie\CustomExceptionsTest::testNotNullException";d:0.057;s:45:"Pecee\Pixie\NoTableSubQueryTest::testRawQuery";d:0.001;s:53:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryCount";d:0.044;s:59:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQueryCount";d:0.001;s:51:"Pecee\Pixie\QueryBuilderAggregateTest::testQuerySum";d:0.045;s:57:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQuerySum";d:0.001;s:55:"Pecee\Pixie\QueryBuilderAggregateTest::testQueryAverage";d:0.041;s:61:"Pecee\Pixie\QueryBuilderAggregateTest::testSqliteQueryAverage";d:0.001;s:44:"Pecee\Pixie\QueryBuilder::testFalseBoolWhere";d:0.001;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;s:38:"Pecee\Pixie\QueryBuilder::testRawQuery";d:0.001;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;s:40:"Pecee\Pixie\QueryBuilder::testGetColumns";d:0;s:42:"Pecee\Pixie\QueryBuilder::testQueryPartFor";d:0;s:41:"Pecee\Pixie\QueryBuilder::testRemoveQuery";d:0;s:50:"Pecee\Pixie\TransactionTest::testTransactionResult";d:0.055;s:51:"Pecee\Pixie\TransactionTest::testNestedTransactions";d:0.066;s:58:"Pecee\Pixie\TransactionTest::testTransactionMultipleInsert";d:0.048;s:42:"Pecee\Pixie\TransactionTest::testLastQuery";d:0.045;s:47:"Pecee\Pixie\QueryBuilderTest::testRawExpression";d:0;s:56:"Pecee\Pixie\QueryBuilderTest::testRawStatementWithinJoin";d:0.001;}}} \ 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 c694a91..7829811 100644 --- a/src/Pecee/Pixie/QueryBuilder/Adapters/BaseAdapter.php +++ b/src/Pecee/Pixie/QueryBuilder/Adapters/BaseAdapter.php @@ -127,8 +127,8 @@ protected function arrayStr(array $pieces, string $glue = ', ', bool $wrapSaniti * @param array $statements * @param bool $bindValues * - * @throws Exception * @return array + * @throws Exception */ protected function buildCriteria(array $statements, bool $bindValues = true): array { @@ -154,11 +154,11 @@ protected function buildCriteria(array $statements, bool $bindValues = true): ar $key = $statement['key']; - if($key instanceof Raw === false) { + if ($key instanceof Raw === false) { $key = $this->wrapSanitizer($key); // Add alias non-existing - if(is_string($key) && $this->aliasPrefix !== null && strpos($key, '.') === false) { + if (is_string($key) && $this->aliasPrefix !== null && strpos($key, '.') === false) { $key = $this->aliasPrefix . '.' . $key; } } @@ -169,6 +169,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) { /** @@ -239,7 +243,7 @@ protected function buildCriteria(array $statements, bool $bindValues = true): ar } // Check for objects that implement the __toString() magic method - if(\is_object($value) === true && \method_exists($value, '__toString') === true) { + if (\is_object($value) === true && \method_exists($value, '__toString') === true) { $value = $value->__toString(); } @@ -288,11 +292,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 = ''; @@ -311,12 +316,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); @@ -330,7 +343,7 @@ protected function buildJoin(array $statements): string * eg. foo as f * * @param string $table - * @param array $statements + * @param array $statements * * @return string */ @@ -380,26 +393,25 @@ public function delete(array $statements, array $columns = null): array $columnsQuery = ''; - if($columns !== null) { + if ($columns !== null) { $columnsQuery = $this->arrayStr($columns); } // 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'); } @@ -477,7 +489,7 @@ private function getUpdateStatement(array $data): array $bindings += $value->getBindings(); } else { $statements[] = $statement . '?'; - $bindings[] = $value; + $bindings[] = $value; } } @@ -548,11 +560,12 @@ protected function setSelectStatement(array &$statements, array &$bindings): boo $statements['selects'] = $statements['distincts']; } - } else if (isset($statements['selects']) === false) { - $statements['selects'] = ['*']; + } else { + if (isset($statements['selects']) === false) { + $statements['selects'] = ['*']; + } } - foreach ((array)$statements['selects'] as $select) { if ($select instanceof Raw) { $bindings += $select->getBindings(); @@ -567,8 +580,8 @@ protected function setSelectStatement(array &$statements, array &$bindings): boo * * @param array $statements * - * @throws Exception * @return array + * @throws Exception */ public function select(array $statements): array { @@ -607,14 +620,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); @@ -633,14 +646,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: @@ -729,14 +743,14 @@ public function update(array $statements, array $data): array $sqlArray = [ 'UPDATE', - $this->buildAliasedTableName($table,$statements), - $this->buildQueryPart(static::QUERY_PART_JOIN, $statements), + $this->buildAliasedTableName($table, $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') diff --git a/tests/TestCase.php b/tests/TestCase.php index b7c1e93..0318447 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -116,7 +116,7 @@ public function getLiveConnection() { 'host' => '127.0.0.1', 'database' => 'test', 'username' => 'root', - 'password' => '', + 'password' => 'root', 'charset' => 'utf8mb4', // Optional 'collation' => 'utf8mb4_unicode_ci', // Optional 'prefix' => '', // Table prefix, optional