Minor refactorings for DboMysql, DboSource and TextHelper

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8241 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
DarkAngelBGE 2009-07-21 20:57:39 +00:00
parent f9ff43b352
commit fefbe77208
3 changed files with 15 additions and 7 deletions

View file

@ -481,9 +481,11 @@ class DboMysql extends DboMysqlBase {
if ($parent != null) { if ($parent != null) {
return $parent; return $parent;
} elseif ($data === null || (is_array($data) && empty($data))) { }
if ($data === null || (is_array($data) && empty($data))) {
return 'NULL'; return 'NULL';
} elseif ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') { }
if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return "''"; return "''";
} }
if (empty($column)) { if (empty($column)) {

View file

@ -200,9 +200,8 @@ class DboSource extends DataSource {
if ($this->error) { if ($this->error) {
$this->showQuery($sql); $this->showQuery($sql);
return false; return false;
} else {
return $this->_result;
} }
return $this->_result;
} }
/** /**
* DataSource Query abstraction * DataSource Query abstraction
@ -1515,12 +1514,12 @@ class DboSource extends DataSource {
return $join; return $join;
} }
/** /**
* Returns the an SQL calculation, i.e. COUNT() or MAX() * Returns an SQL calculation, i.e. COUNT() or MAX()
* *
* @param model $model * @param model $model
* @param string $func Lowercase name of SQL function, i.e. 'count' or 'max' * @param string $func Lowercase name of SQL function, i.e. 'count' or 'max'
* @param array $params Function parameters (any values must be quoted manually) * @param array $params Function parameters (any values must be quoted manually)
* @return string An SQL calculation function * @return string An SQL calculation function
* @access public * @access public
*/ */
function calculate(&$model, $func, $params = array()) { function calculate(&$model, $func, $params = array()) {
@ -1908,7 +1907,9 @@ class DboSource extends DataSource {
} }
} }
$type = (is_object($model) ? $model->getColumnType($key) : null); $type = (is_object($model) ? $model->getColumnType($key) : null);
$null = ($value === null || (is_array($value) && empty($value))); $null = ($value === null || (is_array($value) && empty($value)));
if (strtolower($operator) === 'not') { if (strtolower($operator) === 'not') {
@ -1917,6 +1918,7 @@ class DboSource extends DataSource {
); );
return $data[0]; return $data[0];
} }
$value = $this->value($value, $type); $value = $this->value($value, $type);
if ($key !== '?') { if ($key !== '?') {
@ -1957,6 +1959,7 @@ class DboSource extends DataSource {
break; break;
} }
} }
return "{$key} {$operator} {$value}"; return "{$key} {$operator} {$value}";
} }
/** /**

View file

@ -277,17 +277,20 @@ class TextHelper extends AppHelper {
} }
$pos = strpos(strtolower($text), strtolower($phrase)); $pos = strpos(strtolower($text), strtolower($phrase));
$startPos = 0; $startPos = 0;
if ($pos > $radius) { if ($pos > $radius) {
$startPos = $pos - $radius; $startPos = $pos - $radius;
} }
$textLen = strlen($text); $textLen = strlen($text);
$endPos = $pos + $phraseLen + $radius; $endPos = $pos + $phraseLen + $radius;
if ($endPos >= $textLen) { if ($endPos >= $textLen) {
$endPos = $textLen; $endPos = $textLen;
} }
$excerpt = substr($text, $startPos, $endPos - $startPos);
$excerpt = substr($text, $startPos, $endPos - $startPos);
if ($startPos != 0) { if ($startPos != 0) {
$excerpt = substr_replace($excerpt, $ending, 0, $phraseLen); $excerpt = substr_replace($excerpt, $ending, 0, $phraseLen);
} }