mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Fixing quoting of boolean values in DboPostgres (Ticket #2594)
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5416 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
79147c297f
commit
629c0a9d63
2 changed files with 101 additions and 108 deletions
|
@ -241,14 +241,12 @@ class DboPostgres extends DboSource {
|
|||
|
||||
break;
|
||||
case 'boolean':
|
||||
$data = $this->boolean((bool)$data, false);
|
||||
if ($data === true) {
|
||||
$data = '1';
|
||||
} elseif ($data === false) {
|
||||
$data = '0';
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ($data === true) {
|
||||
return 'TRUE';
|
||||
} elseif ($data === false) {
|
||||
return 'FALSE';
|
||||
}
|
||||
$data = pg_escape_string($data);
|
||||
break;
|
||||
}
|
||||
|
@ -558,7 +556,7 @@ class DboPostgres extends DboSource {
|
|||
if ($data === true || $data === false) {
|
||||
$result = $data;
|
||||
} elseif (is_string($data) && !is_numeric($data)) {
|
||||
if (strpos($data, 't') !== false) {
|
||||
if (strpos(low($data), 't') !== false) {
|
||||
$result = true;
|
||||
} else {
|
||||
$result = false;
|
||||
|
@ -566,11 +564,6 @@ class DboPostgres extends DboSource {
|
|||
} else {
|
||||
$result = (bool)$data;
|
||||
}
|
||||
|
||||
if ($quote) {
|
||||
$result = "'" . $result . "'";
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -216,7 +216,7 @@ class DboSource extends DataSource {
|
|||
$c = 0;
|
||||
$query = array();
|
||||
foreach ($field as $f) {
|
||||
if (!is_array($params[$c]) && !empty($params[$c])) {
|
||||
if (!is_array($params[$c]) && !empty($params[$c]) && $params[$c] !== true && $params[$c] !== false) {
|
||||
$query[$args[2]->name . '.' . $f] = '= ' . $params[$c];
|
||||
} else {
|
||||
$query[$args[2]->name . '.' . $f] = $params[$c];
|
||||
|
@ -1494,115 +1494,115 @@ class DboSource extends DataSource {
|
|||
* @param array $conditions Array or string of conditions
|
||||
* @return string SQL fragment
|
||||
*/
|
||||
function conditionKeysToString($conditions, $quoteValues = true) {
|
||||
$c = 0;
|
||||
$data = $not = null;
|
||||
$out = array();
|
||||
$bool = array('and', 'or', 'not', 'and not', 'or not', 'xor', '||', '&&');
|
||||
$join = ' AND ';
|
||||
function conditionKeysToString($conditions, $quoteValues = true) {
|
||||
$c = 0;
|
||||
$data = $not = null;
|
||||
$out = array();
|
||||
$bool = array('and', 'or', 'not', 'and not', 'or not', 'xor', '||', '&&');
|
||||
$join = ' AND ';
|
||||
|
||||
foreach ($conditions as $key => $value) {
|
||||
if (is_numeric($key) && empty($value)) {
|
||||
continue;
|
||||
} elseif (is_numeric($key) && is_string($value)) {
|
||||
$out[] = $not . $this->__quoteFields($value);
|
||||
} elseif (in_array(strtolower(trim($key)), $bool)) {
|
||||
$join = ' ' . strtoupper($key) . ' ';
|
||||
$value = $this->conditionKeysToString($value, $quoteValues);
|
||||
if (strpos($join, 'NOT') !== false) {
|
||||
if (up(trim($key)) == 'NOT') {
|
||||
$key = 'AND ' . $key;
|
||||
foreach ($conditions as $key => $value) {
|
||||
if (is_numeric($key) && empty($value)) {
|
||||
continue;
|
||||
} elseif (is_numeric($key) && is_string($value)) {
|
||||
$out[] = $not . $this->__quoteFields($value);
|
||||
} elseif (in_array(strtolower(trim($key)), $bool)) {
|
||||
$join = ' ' . strtoupper($key) . ' ';
|
||||
$value = $this->conditionKeysToString($value, $quoteValues);
|
||||
if (strpos($join, 'NOT') !== false) {
|
||||
if (up(trim($key)) == 'NOT') {
|
||||
$key = 'AND ' . $key;
|
||||
}
|
||||
$not = 'NOT ';
|
||||
} else {
|
||||
$not = null;
|
||||
}
|
||||
$not = 'NOT ';
|
||||
$out[] = $not . '((' . join(') ' . strtoupper($key) . ' (', $value) . '))';
|
||||
} else {
|
||||
$not = null;
|
||||
}
|
||||
$out[] = $not . '((' . join(') ' . strtoupper($key) . ' (', $value) . '))';
|
||||
} else {
|
||||
if (is_string($value) && preg_match('/^\{\$__cakeIdentifier\[(.*)\]__\$}$/', $value, $identifier) && isset($identifier[1])) {
|
||||
$data .= $this->name($key) . ' = ' . $this->name($identifier[1]);
|
||||
} elseif (is_array($value) && !empty($value)) {
|
||||
$keys = array_keys($value);
|
||||
if ($keys[0] === 0) {
|
||||
$data = $this->name($key) . ' IN (';
|
||||
if (strpos($value[0], '-!') === 0) {
|
||||
$value[0] = str_replace('-!', '', $value[0]);
|
||||
$data .= $value[0];
|
||||
$data .= ')';
|
||||
} else {
|
||||
if ($quoteValues) {
|
||||
foreach ($value as $valElement) {
|
||||
$data .= $this->value($valElement) . ', ';
|
||||
if (is_string($value) && preg_match('/^\{\$__cakeIdentifier\[(.*)\]__\$}$/', $value, $identifier) && isset($identifier[1])) {
|
||||
$data .= $this->name($key) . ' = ' . $this->name($identifier[1]);
|
||||
} elseif (is_array($value) && !empty($value)) {
|
||||
$keys = array_keys($value);
|
||||
if ($keys[0] === 0) {
|
||||
$data = $this->name($key) . ' IN (';
|
||||
if (strpos($value[0], '-!') === 0) {
|
||||
$value[0] = str_replace('-!', '', $value[0]);
|
||||
$data .= $value[0];
|
||||
$data .= ')';
|
||||
} else {
|
||||
if ($quoteValues) {
|
||||
foreach ($value as $valElement) {
|
||||
$data .= $this->value($valElement) . ', ';
|
||||
}
|
||||
}
|
||||
$data[strlen($data) - 2] = ')';
|
||||
}
|
||||
$data[strlen($data) - 2] = ')';
|
||||
}
|
||||
} else {
|
||||
$ret = $this->conditionKeysToString($value, $quoteValues);
|
||||
if (count($ret) > 1) {
|
||||
$out[] = '(' . join(') AND (', $ret) . ')';
|
||||
} elseif (isset($ret[0])) {
|
||||
$out[] = $ret[0];
|
||||
}
|
||||
}
|
||||
} elseif (is_numeric($key) && !empty($value)) {
|
||||
$data = $this->__quoteFields($value);
|
||||
} elseif ($value === null || (is_array($value) && empty($value))) {
|
||||
$data = $this->name($key) . ' IS NULL';
|
||||
} elseif ($value === false || $value === true) {
|
||||
$data = $this->name($key) . " = " . $this->boolean($value);
|
||||
} elseif ($value === '') {
|
||||
$data = $this->name($key) . " = ''";
|
||||
} elseif (preg_match('/^([a-z]+\\([a-z0-9]*\\)\\x20+|(?:' . join('\\x20)|(?:', $this->__sqlOps) . '\\x20)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)?(.*)/i', $value, $match)) {
|
||||
if (preg_match('/(\\x20[\\w]*\\x20)/', $key, $regs)) {
|
||||
$clause = $regs['1'];
|
||||
$key = preg_replace('/' . $regs['1'] . '/', '', $key);
|
||||
}
|
||||
|
||||
$not = false;
|
||||
$mValue = trim($match['1']);
|
||||
if (empty($match['1'])) {
|
||||
$match['1'] = ' = ';
|
||||
} elseif (empty($mValue)) {
|
||||
$match['1'] = ' = ';
|
||||
$match['2'] = $match['0'];
|
||||
} elseif (!isset($match['2'])) {
|
||||
$match['1'] = ' = ';
|
||||
$match['2'] = $match['0'];
|
||||
} else if(low($mValue) == 'not') {
|
||||
$not = $this->conditionKeysToString(array($mValue => array($key => $match[2])), $quoteValues);
|
||||
}
|
||||
|
||||
if($not) {
|
||||
$data = $not[0];
|
||||
} elseif (strpos($match['2'], '-!') === 0) {
|
||||
$match['2'] = str_replace('-!', '', $match['2']);
|
||||
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
|
||||
} else {
|
||||
if (!empty($match['2']) && $quoteValues) {
|
||||
if (!preg_match('/[A-Za-z]+\\([a-z0-9]*\\),?\\x20+/', $match['2'])) {
|
||||
$match['2'] = $this->value($match['2']);
|
||||
} else {
|
||||
$ret = $this->conditionKeysToString($value, $quoteValues);
|
||||
if (count($ret) > 1) {
|
||||
$out[] = '(' . join(') AND (', $ret) . ')';
|
||||
} elseif (isset($ret[0])) {
|
||||
$out[] = $ret[0];
|
||||
}
|
||||
$match['2'] = str_replace(' AND ', "' AND '", $match['2']);
|
||||
}
|
||||
$data = $this->__quoteFields($key);
|
||||
if ($data === $key) {
|
||||
} elseif (is_numeric($key) && !empty($value)) {
|
||||
$data = $this->__quoteFields($value);
|
||||
} elseif ($value === null || (is_array($value) && empty($value))) {
|
||||
$data = $this->name($key) . ' IS NULL';
|
||||
} elseif ($value === false || $value === true) {
|
||||
$data = $this->name($key) . " = " . $this->value($value, 'boolean');
|
||||
} elseif ($value === '') {
|
||||
$data = $this->name($key) . " = ''";
|
||||
} elseif (preg_match('/^([a-z]+\\([a-z0-9]*\\)\\x20+|(?:' . join('\\x20)|(?:', $this->__sqlOps) . '\\x20)|<[>=]?(?![^>]+>)\\x20?|[>=!]{1,3}(?!<)\\x20?)?(.*)/i', $value, $match)) {
|
||||
if (preg_match('/(\\x20[\\w]*\\x20)/', $key, $regs)) {
|
||||
$clause = $regs['1'];
|
||||
$key = preg_replace('/' . $regs['1'] . '/', '', $key);
|
||||
}
|
||||
|
||||
$not = false;
|
||||
$mValue = trim($match['1']);
|
||||
if (empty($match['1'])) {
|
||||
$match['1'] = ' = ';
|
||||
} elseif (empty($mValue)) {
|
||||
$match['1'] = ' = ';
|
||||
$match['2'] = $match['0'];
|
||||
} elseif (!isset($match['2'])) {
|
||||
$match['1'] = ' = ';
|
||||
$match['2'] = $match['0'];
|
||||
} else if(low($mValue) == 'not') {
|
||||
$not = $this->conditionKeysToString(array($mValue => array($key => $match[2])), $quoteValues);
|
||||
}
|
||||
|
||||
if($not) {
|
||||
$data = $not[0];
|
||||
} elseif (strpos($match['2'], '-!') === 0) {
|
||||
$match['2'] = str_replace('-!', '', $match['2']);
|
||||
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
|
||||
} else {
|
||||
$data = $data . ' ' . $match['1'] . ' ' . $match['2'];
|
||||
if (!empty($match['2']) && $quoteValues) {
|
||||
if (!preg_match('/[A-Za-z]+\\([a-z0-9]*\\),?\\x20+/', $match['2'])) {
|
||||
$match['2'] = $this->value($match['2']);
|
||||
}
|
||||
$match['2'] = str_replace(' AND ', "' AND '", $match['2']);
|
||||
}
|
||||
$data = $this->__quoteFields($key);
|
||||
if ($data === $key) {
|
||||
$data = $this->name($key) . ' ' . $match['1'] . ' ' . $match['2'];
|
||||
} else {
|
||||
$data = $data . ' ' . $match['1'] . ' ' . $match['2'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($data != null) {
|
||||
$out[] = $data;
|
||||
$data = null;
|
||||
if ($data != null) {
|
||||
$out[] = $data;
|
||||
$data = null;
|
||||
}
|
||||
}
|
||||
$c++;
|
||||
}
|
||||
$c++;
|
||||
return $out;
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
/**
|
||||
* Quotes Model.fields
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue