Finish the SELECT query generator

This commit is contained in:
Kijin Sung 2020-06-26 21:56:25 +09:00
parent bc287b0e0f
commit 6d251dfbe1
2 changed files with 135 additions and 12 deletions

View file

@ -33,7 +33,7 @@ class VariableBase
$params = array();
// Process the variable or default value.
if ($this->var && isset($args[$this->var]) && (!is_array($args[$this->var]) || count($args[$this->var]) > 1 || $args[$this->var] !== ['']))
if ($this->var && Query::isValidVariable($args[$this->var]))
{
$this->filterValue($args[$this->var]);
$is_expression = false;
@ -223,6 +223,27 @@ class VariableBase
return [$where, $params];
}
/**
* Get the current value, falling back to the default value if necessary.
*
* @param array $args
* @return array
*/
public function getValue(array $args)
{
if ($this->var && Query::isValidVariable($args[$this->var]))
{
$is_expression = false;
$value = $args[$this->var];
}
elseif ($this->default !== null)
{
list($is_expression, $value) = $this->getDefaultValue();
}
return [$is_expression, $value];
}
/**
* Get the default value of this variable.
*
@ -231,7 +252,7 @@ class VariableBase
public function getDefaultValue()
{
// If the default value is a column name, escape it.
if (preg_match('/^[a-z0-9_]+(?:\.[a-z0-9_]+)+$/', $this->default))
if (strpos($this->default, '.') !== false && Query::isValidColumnName($this->default))
{
return [true, Query::quoteName($this->default)];
}