Commit a1824852 authored by Tim Schoondergang's avatar Tim Schoondergang
Browse files

Merge branch '24-maak-collection-en-param-itterable' into 'milestone-v6'

bugfix voor sql query's an inSql nu inQuery

See merge request !43
parents d10f9454 e75f35c2
Pipeline #7320 passed with stage
in 19 seconds
......@@ -590,8 +590,8 @@ class DB
public static function getWhereFromParam($param = false, string $table = ''): string
{
self::addToStats(__FUNCTION__);
if (is_object($param) && ($param instanceof Collection || $param instanceof Param)) {
$where = (string)$param;
if (is_object($param) && ($param instanceof Collection)) {
$where = self::getWhereFromCollection($param);
} elseif (is_array($param) && !empty($param)) {
$where = "(";
$divider_operator = 'AND';
......@@ -665,6 +665,18 @@ class DB
return $where;
}
/**
* Make where statement from Collection
* @param Collection $collection paramater
*
* @return string
*/
public static function getWhereFromCollection(Collection $collection): string
{
self::addToStats(__FUNCTION__);
return (string)$collection;
}
/**
* dbDelta on DB
* @param string|array $queries
......
......@@ -215,30 +215,30 @@ class Param implements Stringable
}
/**
* in sql
* in query
*
* @param string $value
*
* @return Param
*/
public function inSql(string $value): Param
public function inQuery(string $value): Param
{
$this->value = $value;
$this->operator = 'IN SQL';
$this->operator = 'IN QUERY';
return $this;
}
/**
* not in sql
* not in query
*
* @param string $value
*
* @return Param
*/
public function notSql(string $value): Param
public function notInQuery(string $value): Param
{
$this->value = $value;
$this->operator = 'NOT IN SQL';
$this->operator = 'NOT IN QUERY';
return $this;
}
......@@ -274,10 +274,11 @@ class Param implements Stringable
return "NULL";
case 'string':
// if IN or NOT IN, don't escape string because it is SQL
switch (substr($this->operator, -3)) {
case 'SQL':
$this->operator = substr($this->operator, 0, -4);
return $this->value;
switch (substr($this->operator, -5)) {
case 'QUERY':
$this->operator = substr($this->operator, 0, -6);
return "(" . rtrim($this->value, ";") . ")";
default:
$value = DB::clean4DB($value);
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment