Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c9bc657

Browse filesBrowse files
authored
Update ssql.php
Added four more methods to advanced conditions: in, begins, ends and contains
1 parent 669eb16 commit c9bc657
Copy full SHA for c9bc657

File tree

Expand file treeCollapse file tree

1 file changed

+62
-0
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+62
-0
lines changed

‎ssql.php

Copy file name to clipboardExpand all lines: ssql.php
+62Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,68 @@ public function between($k, $a, $b, $flags = 128) {
994994
$this->cond = ($append ? ("({$this->cond}) " . ($flags & SQ::COND_OR ? "OR" : "AND") . " (") : "") . ("`" . $this->c->escape($k) . "` BETWEEN `" . $this->c->escape($a) . "` AND `" . $this->c->escape($b) . "`") . ($append ? ")" : "");
995995
return $this;
996996
}
997+
public function in($k, $v, $flags = 128) {
998+
$append = !empty($this->cond);
999+
if(!is_array($v))
1000+
throw new SmysqlException("\$v expected to be an array, " . gettxpe($v) . " received");
1001+
if(count($v) < 1)
1002+
return false;
1003+
$values = array_map(function($n) {
1004+
if(is_int($n) || is_float($n))
1005+
return strval($n);
1006+
if(is_array($n))
1007+
return implode(", ", array_map(function($n2) {
1008+
if(is_int($n2) || is_float($n2))
1009+
return strval($n2);
1010+
return "\"" . $this->c->escape($n2) . "\"";
1011+
}, $n));
1012+
return "`" . $this->c->escape($n) . "`";
1013+
}, $v);
1014+
$this->cond = ($append ? ("({$this->cond}) " . ($flags & SQ::COND_OR ? "OR" : "AND") . " (") : "") . ("`" . $this->c->escape($k) . "` IN (" . implode(", ", $values) . ")") . ($append ? ")" : "");
1015+
return $this;
1016+
}
1017+
public function begins($k, $v, $flags = 128) {
1018+
$append = !empty($this->cond);
1019+
if(is_int($v) || is_float($v)) {
1020+
$v = [$v];
1021+
$quotes = "";
1022+
};
1023+
if(is_array($v) && count($v) < 1)
1024+
return false;
1025+
if(is_array($v))
1026+
$this->cond = ($append ? ("({$this->cond}) " . ($flags & SQ::COND_OR ? "OR" : "AND") . " (") : "") . ((count($v) < 2) ? ("`" . $this->c->escape($k) . "` LIKE \"" . $this->c->escape($v[0]) . "%\"") : ("(`" . $this->c->escape($k) . "` LIKE \"" . $this->c->escape(array_shift($v)) . "%\") OR (" . $this->c->cond()->like($k, $v) . ")")) . ($append ? ")" : "");
1027+
else
1028+
$this->cond = ($append ? ("({$this->cond}) " . ($flags & SQ::COND_OR ? "OR" : "AND") . " (") : "") . ("`" . $this->c->escape($k) . "` LIKE CONCAT(`" . $this->c->escape($v) . "`, \"%\")") . ($append ? ")" : "");
1029+
return $this;
1030+
}
1031+
public function ends($k, $v, $flags = 128) {
1032+
$append = !empty($this->cond);
1033+
if(is_int($v) || is_float($v)) {
1034+
$v = [$v];
1035+
$quotes = "";
1036+
};
1037+
if(is_array($v) && count($v) < 1)
1038+
return false;
1039+
if(is_array($v))
1040+
$this->cond = ($append ? ("({$this->cond}) " . ($flags & SQ::COND_OR ? "OR" : "AND") . " (") : "") . ((count($v) < 2) ? ("`" . $this->c->escape($k) . "` LIKE \"%" . $this->c->escape($v[0]) . "\"") : ("(`" . $this->c->escape($k) . "` LIKE \"%" . $this->c->escape(array_shift($v)) . "\") OR (" . $this->c->cond()->like($k, $v) . ")")) . ($append ? ")" : "");
1041+
else
1042+
$this->cond = ($append ? ("({$this->cond}) " . ($flags & SQ::COND_OR ? "OR" : "AND") . " (") : "") . ("`" . $this->c->escape($k) . "` LIKE CONCAT(\"%\", `" . $this->c->escape($v) . "`)") . ($append ? ")" : "");
1043+
return $this;
1044+
}
1045+
public function contains($k, $v, $flags = 128) {
1046+
$append = !empty($this->cond);
1047+
if(is_int($v) || is_float($v)) {
1048+
$v = [$v];
1049+
$quotes = "";
1050+
};
1051+
if(is_array($v) && count($v) < 1)
1052+
return false;
1053+
if(is_array($v))
1054+
$this->cond = ($append ? ("({$this->cond}) " . ($flags & SQ::COND_OR ? "OR" : "AND") . " (") : "") . ((count($v) < 2) ? ("`" . $this->c->escape($k) . "` LIKE \"%" . $this->c->escape($v[0]) . "%\"") : ("(`" . $this->c->escape($k) . "` LIKE \"%" . $this->c->escape(array_shift($v)) . "%\") OR (" . $this->c->cond()->like($k, $v) . ")")) . ($append ? ")" : "");
1055+
else
1056+
$this->cond = ($append ? ("({$this->cond}) " . ($flags & SQ::COND_OR ? "OR" : "AND") . " (") : "") . ("`" . $this->c->escape($k) . "` LIKE CONCAT(\"%\", `" . $this->c->escape($v) . "`, \"%\")") . ($append ? ")" : "");
1057+
return $this;
1058+
}
9971059

9981060
public function not($cond = "", $flags = 128) {
9991061
if(!empty($cond) && empty($this->cond))

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.