mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 11:06:15 +00:00
Fixing column quoting for array-based conditions when columns are wrapped in SQL functions
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4330 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
f9a00da02b
commit
dbbfa5b837
2 changed files with 27 additions and 2 deletions
|
@ -208,6 +208,11 @@ class DboMysql extends DboSource {
|
||||||
* @return string Quoted for MySQL
|
* @return string Quoted for MySQL
|
||||||
*/
|
*/
|
||||||
function name($data) {
|
function name($data) {
|
||||||
|
$tmp = parent::name($data);
|
||||||
|
if (!empty($tmp)) {
|
||||||
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
if ($data == '*') {
|
if ($data == '*') {
|
||||||
return '*';
|
return '*';
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
* @lastmodified $Date$
|
* @lastmodified $Date$
|
||||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||||
*/
|
*/
|
||||||
|
uses('set');
|
||||||
/**
|
/**
|
||||||
* DboSource
|
* DboSource
|
||||||
*
|
*
|
||||||
|
@ -362,6 +363,21 @@ class DboSource extends DataSource {
|
||||||
return $data[$name];
|
return $data[$name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Strips fields out of SQL functions before quoting.
|
||||||
|
*
|
||||||
|
* @param string $data
|
||||||
|
* @return string SQL field
|
||||||
|
*/
|
||||||
|
function name($data) {
|
||||||
|
if (preg_match_all('/(.*)\((.*)\)/', $data, $fields)) {
|
||||||
|
$fields = Set::extract($fields, '{n}.0');
|
||||||
|
if (isset($fields[1]) && isset($fields[2])) {
|
||||||
|
return $fields[1] . '(' . $this->name($fields[2]) . ')';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Checks if it's connected to the database
|
* Checks if it's connected to the database
|
||||||
*
|
*
|
||||||
|
@ -1343,7 +1359,12 @@ class DboSource extends DataSource {
|
||||||
return $clause . ' (' . join(') AND (', $out) . ')';
|
return $clause . ' (' . join(') AND (', $out) . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Creates a WHERE clause by parsing given conditions array. Used by DboSource::conditions().
|
||||||
|
*
|
||||||
|
* @param array $conditions Array or string of conditions
|
||||||
|
* @return string SQL fragment
|
||||||
|
*/
|
||||||
function conditionKeysToString($conditions) {
|
function conditionKeysToString($conditions) {
|
||||||
|
|
||||||
$c = 0;
|
$c = 0;
|
||||||
|
@ -1363,7 +1384,6 @@ class DboSource extends DataSource {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (is_array($value) && !empty($value)) {
|
if (is_array($value) && !empty($value)) {
|
||||||
|
|
||||||
$keys = array_keys($value);
|
$keys = array_keys($value);
|
||||||
if ($keys[0] === 0) {
|
if ($keys[0] === 0) {
|
||||||
$data = $this->name($key) . ' IN (';
|
$data = $this->name($key) . ' IN (';
|
||||||
|
|
Loading…
Add table
Reference in a new issue