Fixing quoting of numeric literals in DboSource::order(), closes #5360

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7537 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2008-08-29 20:40:15 +00:00
parent 7b8e69f120
commit 26e2747180
2 changed files with 10 additions and 4 deletions

View file

@ -2026,17 +2026,19 @@ class DboSource extends DataSource {
if (strpos($keys, '.')) {
preg_match_all('/([a-zA-Z0-9_]{1,})\\.([a-zA-Z0-9_]{1,})/', $keys, $result, PREG_PATTERN_ORDER);
$pregCount = count($result['0']);
$pregCount = count($result[0]);
for ($i = 0; $i < $pregCount; $i++) {
$keys = preg_replace('/' . $result['0'][$i] . '/', $this->name($result['0'][$i]), $keys);
if (!is_numeric($result[0][$i])) {
$keys = preg_replace('/' . $result[0][$i] . '/', $this->name($result[0][$i]), $keys);
}
}
$result = ' ORDER BY ' . $keys;
return $result . (!preg_match('/\\x20ASC|\\x20DESC/i', $keys) ? ' ' . $direction : '');
} elseif (preg_match('/(\\x20ASC|\\x20DESC)/i', $keys, $match)) {
$direction = $match['1'];
return ' ORDER BY ' . preg_replace('/' . $match['1'] . '/', '', $keys) . $direction;
$direction = $match[1];
return ' ORDER BY ' . preg_replace('/' . $match[1] . '/', '', $keys) . $direction;
}
return ' ORDER BY ' . $keys . ' ' . $direction;
}

View file

@ -3188,6 +3188,10 @@ class DboSourceTest extends CakeTestCase {
$result = $this->testDb->order("Anuncio.destaque & 2 DESC");
$expected = ' ORDER BY `Anuncio`.`destaque` & 2 DESC';
$this->assertEqual($result, $expected);
$result = $this->testDb->order("3963.191 * id");
$expected = ' ORDER BY 3963.191 * id ASC';
$this->assertEqual($result, $expected);
}
/**
* testComplexSortExpression method