Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
b3e5b0e
or operator
fogelito Feb 6, 2023
f5416e4
Merge branch 'between' of github.com:utopia-php/database into test-or
fogelito Feb 6, 2023
50a6a0e
bind param error
fogelito Feb 6, 2023
c309434
Nested conditions
fogelito Feb 7, 2023
2d3e8ea
remove nesting entry
fogelito Feb 7, 2023
95b6e53
Merge branch 'main' of github.com:utopia-php/database into test-or
fogelito Feb 8, 2023
111c30d
Merge branch 'main' of github.com:utopia-php/database into test-or
fogelito Oct 15, 2023
58fe422
Query OR
fogelito Oct 15, 2023
fe25d3c
Query OR
fogelito Oct 17, 2023
252321d
Some changes
fogelito Oct 23, 2023
2829975
cleanFilters tests
fogelito Oct 24, 2023
110da1f
mongo blocker
fogelito Oct 24, 2023
b818706
Second try
fogelito Oct 24, 2023
0da0dce
Fix Mongo tests
fogelito Oct 29, 2023
46b252a
Merge branch 'main' of github.com:utopia-php/database into query-or
fogelito Oct 29, 2023
c13cba0
Merge main
fogelito Oct 29, 2023
800cf82
Remove first check
fogelito Oct 29, 2023
5f9cb97
Remove comments
fogelito Oct 29, 2023
71f7950
implode $conditions
fogelito Oct 29, 2023
2948863
Format
fogelito Oct 30, 2023
88b5f48
composer check
fogelito Oct 30, 2023
af7c5c3
remove line
fogelito Oct 30, 2023
b90da4e
Parsing Tests
fogelito Oct 30, 2023
fc3369c
Mongo mount
fogelito Oct 30, 2023
cb86bbb
Mongo mount
fogelito Oct 30, 2023
9eabf48
revert or parse
fogelito Dec 4, 2023
36c07bf
allow test
fogelito Dec 4, 2023
80ca44e
Merge branch 'main' of github.com:utopia-php/database into query-or
fogelito Dec 5, 2023
458bcf7
composer.lock
fogelito Dec 5, 2023
f64fec2
and Nested operator
fogelito Dec 5, 2023
df713f7
Formatting
fogelito Dec 5, 2023
7c27898
check formatting
fogelito Dec 5, 2023
19715d9
check formatting
fogelito Dec 5, 2023
a5bb36f
Remove commented test
fogelito Dec 5, 2023
bdd651c
getValues getValue
fogelito Dec 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
- ./src:/usr/src/code/src
- ./tests:/usr/src/code/tests
- ./phpunit.xml:/usr/src/code/phpunit.xml
#- ./vendor/utopia-php/mongo:/usr/src/code/vendor/utopia-php/mongo
ports:
- "8708:8708"

Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
Expand Down
30 changes: 19 additions & 11 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -1471,14 +1471,11 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
}
}

foreach ($queries as $query) {
if ($query->getMethod() === Query::TYPE_SELECT) {
continue;
}
$where[] = $this->getSQLCondition($query);
$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
$where[] = $conditions;
}


if (Authorization::$status) {
$where[] = $this->getSQLPermissionsCondition($name, $roles);
}
Expand Down Expand Up @@ -1588,8 +1585,9 @@ public function count(string $collection, array $queries = [], ?int $max = null)
$where = [];
$limit = \is_null($max) ? '' : 'LIMIT :max';

foreach ($queries as $query) {
$where[] = $this->getSQLCondition($query);
$conditions = $this->getSQLConditions($queries);
if(!empty($conditions)) {
$where[] = $conditions;
}

if (Authorization::$status) {
Expand Down Expand Up @@ -1743,7 +1741,7 @@ protected function getAttributeProjection(array $selections, string $prefix = ''
return \implode(', ', $selections);
}

/*
/**
* Get SQL Condition
*
* @param Query $query
Expand All @@ -1764,6 +1762,17 @@ protected function getSQLCondition(Query $query): string
$placeholder = $this->getSQLPlaceholder($query);

switch ($query->getMethod()) {
case Query::TYPE_OR:
case Query::TYPE_AND:
$conditions = [];
/* @var $q Query */
foreach ($query->getValue() as $q) {
$conditions[] = $this->getSQLCondition($q);
}

$method = strtoupper($query->getMethod());
return empty($conditions) ? '' : ' '. $method .' (' . implode(' AND ', $conditions) . ')';

case Query::TYPE_SEARCH:
return "MATCH(table_main.{$attribute}) AGAINST (:{$placeholder}_0 IN BOOLEAN MODE)";

Expand All @@ -1779,8 +1788,7 @@ protected function getSQLCondition(Query $query): string
foreach ($query->getValues() as $key => $value) {
$conditions[] = $attribute . ' ' . $this->getSQLOperator($query->getMethod()) . ' :' . $placeholder . '_' . $key;
}
$condition = implode(' OR ', $conditions);
return empty($condition) ? '' : '(' . $condition . ')';
return empty($conditions) ? '' : '(' . implode(' OR ', $conditions) . ')';
}
}

Expand Down
Loading