mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-09 20:12:14 +09:00
Fix inconsistent handling of empty string in INSERT/UPDATE queries
This commit is contained in:
parent
54375d16ad
commit
945c09059a
4 changed files with 43 additions and 6 deletions
14
common/framework/parsers/dbquery/emptystring.php
Normal file
14
common/framework/parsers/dbquery/emptystring.php
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rhymix\Framework\Parsers\DBQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty string class.
|
||||||
|
*/
|
||||||
|
class EmptyString
|
||||||
|
{
|
||||||
|
public function __toString(): string
|
||||||
|
{
|
||||||
|
return "''";
|
||||||
|
}
|
||||||
|
}
|
||||||
14
common/framework/parsers/dbquery/nullvalue.php
Normal file
14
common/framework/parsers/dbquery/nullvalue.php
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Rhymix\Framework\Parsers\DBQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Null value class.
|
||||||
|
*/
|
||||||
|
class NullValue
|
||||||
|
{
|
||||||
|
public function __toString(): string
|
||||||
|
{
|
||||||
|
return 'NULL';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -603,11 +603,12 @@ class Query extends VariableBase
|
||||||
* Check if a variable is considered valid for XE compatibility.
|
* Check if a variable is considered valid for XE compatibility.
|
||||||
*
|
*
|
||||||
* @param mixed $var
|
* @param mixed $var
|
||||||
|
* @param bool $allow_empty_string
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function isValidVariable($var): bool
|
public static function isValidVariable($var, $allow_empty_string = true): bool
|
||||||
{
|
{
|
||||||
if ($var === null || $var === '')
|
if ($var === null || ($var === '' && !$allow_empty_string))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,11 +39,19 @@ class VariableBase
|
||||||
$value = '(' . $this->getQueryString($prefix, $args) . ')';
|
$value = '(' . $this->getQueryString($prefix, $args) . ')';
|
||||||
$params = $this->getQueryParams();
|
$params = $this->getQueryParams();
|
||||||
}
|
}
|
||||||
elseif ($this->var && Query::isValidVariable($args[$this->var]))
|
elseif ($this->var && Query::isValidVariable($args[$this->var], $this instanceof ColumnWrite))
|
||||||
{
|
{
|
||||||
$this->filterValue($args[$this->var]);
|
$this->filterValue($args[$this->var]);
|
||||||
$is_expression = false;
|
if ($args[$this->var] instanceof EmptyString || $args[$this->var] instanceof NullValue)
|
||||||
$value = $args[$this->var];
|
{
|
||||||
|
$value = strval($args[$this->var]);
|
||||||
|
$is_expression = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$value = $args[$this->var];
|
||||||
|
$is_expression = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elseif ($this->default !== null)
|
elseif ($this->default !== null)
|
||||||
{
|
{
|
||||||
|
|
@ -257,7 +265,7 @@ class VariableBase
|
||||||
*/
|
*/
|
||||||
public function getValue(array $args)
|
public function getValue(array $args)
|
||||||
{
|
{
|
||||||
if ($this->var && Query::isValidVariable($args[$this->var]))
|
if ($this->var && Query::isValidVariable($args[$this->var], $this instanceof ColumnWrite))
|
||||||
{
|
{
|
||||||
$is_expression = false;
|
$is_expression = false;
|
||||||
$value = $args[$this->var];
|
$value = $args[$this->var];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue