Skip to content

Commit

Permalink
Implemented support for NOT IN
Browse files Browse the repository at this point in the history
  • Loading branch information
LionelLaffineur committed Apr 4, 2024
1 parent 3f958da commit 31b1e45
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/Skeleton/Pager/Sql/Condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ public function get_comparison() {
*/
public function __toString() {
$db = Database::get();
if ($this->comparison == 'IN') {
if ($this->comparison == 'IN' || $this->comparison == 'NOT IN') {
$not = '';
if ($this->comparison == 'NOT IN') {
$not = 'NOT ';
}
if (!is_array($this->value)) {
throw new \Exception('Error in condition: the IN value specified for ' . $this->local_field . ' must be an array');
throw new \Exception('Error in condition: the ' . $not . 'IN value specified for ' . $this->local_field . ' must be an array');
}

if (empty($this->value) === true) {
return $db->quote_identifier($this->local_field) . ' IN (NULL)';
return $db->quote_identifier($this->local_field) . ' ' . $not . 'IN (NULL)';
}

/**
Expand All @@ -120,10 +124,10 @@ public function __toString() {
$condition = '( ';
if (count($non_null) > 0 ) {
$list = implode(', ', $db->quote($non_null));
$condition .= $db->quote_identifier($this->local_field) . ' IN (' . $list . ')';
$condition .= $db->quote_identifier($this->local_field) . ' ' . $not . 'IN (' . $list . ')';
}
if (count($null) > 0) {
$condition .= ' OR ' . $db->quote_identifier($this->local_field) . ' IS NULL )';
$condition .= ' OR ' . $db->quote_identifier($this->local_field) . ' IS ' . $not . 'NULL )';
}
$condition .= ') ';

Expand Down

0 comments on commit 31b1e45

Please sign in to comment.