Permalink
Browse files

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
  • Loading branch information...
1 parent f9ff43b commit fefbe772087a91360316a94d924c180f4e851003 @tim-kos tim-kos committed Jul 21, 2009
@@ -481,9 +481,11 @@ function value($data, $column = null, $safe = false) {
if ($parent != null) {
return $parent;
- } elseif ($data === null || (is_array($data) && empty($data))) {
+ }
+ if ($data === null || (is_array($data) && empty($data))) {
return 'NULL';
- } elseif ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
+ }
+ if ($data === '' && $column !== 'integer' && $column !== 'float' && $column !== 'boolean') {
return "''";
}
if (empty($column)) {
@@ -200,9 +200,8 @@ function execute($sql, $options = array()) {
if ($this->error) {
$this->showQuery($sql);
return false;
- } else {
- return $this->_result;
}
+ return $this->_result;
}
/**
* DataSource Query abstraction
@@ -1515,12 +1514,12 @@ function _getJoins($model) {
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 string $func Lowercase name of SQL function, i.e. 'count' or 'max'
* @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
*/
function calculate(&$model, $func, $params = array()) {
@@ -1908,7 +1907,9 @@ function __parseKey($model, $key, $value) {
}
}
+
$type = (is_object($model) ? $model->getColumnType($key) : null);
+
$null = ($value === null || (is_array($value) && empty($value)));
if (strtolower($operator) === 'not') {
@@ -1917,6 +1918,7 @@ function __parseKey($model, $key, $value) {
);
return $data[0];
}
+
$value = $this->value($value, $type);
if ($key !== '?') {
@@ -1957,6 +1959,7 @@ function __parseKey($model, $key, $value) {
break;
}
}
+
return "{$key} {$operator} {$value}";
}
/**
@@ -277,17 +277,20 @@ function excerpt($text, $phrase, $radius = 100, $ending = "...") {
}
$pos = strpos(strtolower($text), strtolower($phrase));
+
$startPos = 0;
if ($pos > $radius) {
$startPos = $pos - $radius;
}
+
$textLen = strlen($text);
+
$endPos = $pos + $phraseLen + $radius;
if ($endPos >= $textLen) {
$endPos = $textLen;
}
- $excerpt = substr($text, $startPos, $endPos - $startPos);
+ $excerpt = substr($text, $startPos, $endPos - $startPos);
if ($startPos != 0) {
$excerpt = substr_replace($excerpt, $ending, 0, $phraseLen);
}

0 comments on commit fefbe77

Please sign in to comment.