Minor optimizations in DboMysql.

This commit is contained in:
Juan Basso 2011-02-25 17:22:15 -03:00
parent 73b3b65a53
commit fea2b5798c
2 changed files with 20 additions and 22 deletions

View file

@ -209,21 +209,19 @@ class DboMysql extends DboSource {
$this->map = array();
$numFields = $results->columnCount();
$index = 0;
$j = 0;
while ($j < $numFields) {
$column = $results->getColumnMeta($j);
if (!empty($column['native_type'])) {
$type = $column['native_type'];
} else {
while ($numFields-- > 0) {
$column = $results->getColumnMeta($index);
if (empty($column['native_type'])) {
$type = ($column['len'] == 1) ? 'boolean' : 'string';
} else {
$type = $column['native_type'];
}
if (!empty($column['table']) && strpos($column['name'], $this->virtualFieldSeparator) === false) {
$this->map[$index++] = array($column['table'], $column['name'], $type);
} else {
$this->map[$index++] = array(0, $column['name'], $type);
}
$j++;
}
}
@ -238,7 +236,7 @@ class DboMysql extends DboSource {
foreach ($this->map as $col => $meta) {
list($table, $column, $type) = $meta;
$resultRow[$table][$column] = $row[$col];
if ($type == 'boolean' && !is_null($row[$col])) {
if ($type === 'boolean' && !is_null($row[$col])) {
$resultRow[$table][$column] = $this->boolean($resultRow[$table][$column]);
}
}
@ -304,7 +302,7 @@ class DboMysql extends DboSource {
foreach ($cols as $column) {
$fields[$column->Field] = array(
'type' => $this->column($column->Type),
'null' => ($column->Null == 'YES' ? true : false),
'null' => ($column->Null === 'YES' ? true : false),
'default' => $column->Default,
'length' => $this->length($column->Type),
);
@ -365,7 +363,7 @@ class DboMysql extends DboSource {
return false;
}
if (!$this->execute($this->renderStatement('update', compact('table', 'alias', 'joins', 'fields', 'conditions')))) {
if ($this->execute($this->renderStatement('update', compact('table', 'alias', 'joins', 'fields', 'conditions'))) === false) {
$model->onError();
return false;
}
@ -409,7 +407,7 @@ class DboMysql extends DboSource {
* @param string $enc Database encoding
*/
function setEncoding($enc) {
return $this->_execute('SET NAMES ' . $enc) != false;
return $this->_execute('SET NAMES ' . $enc) !== false;
}
/**
@ -499,7 +497,7 @@ class DboMysql extends DboSource {
}
$colList = array_merge($colList, $this->_alterIndexes($curTable, $indexes));
$colList = array_merge($colList, $this->_alterTableParameters($curTable, $tableParameters));
$out .= "\t" . join(",\n\t", $colList) . ";\n\n";
$out .= "\t" . implode(",\n\t", $colList) . ";\n\n";
}
}
return $out;
@ -516,7 +514,7 @@ class DboMysql extends DboSource {
function dropSchema(CakeSchema $schema, $table = null) {
$out = '';
foreach ($schema->tables as $curTable => $columns) {
if (!$table || $table == $curTable) {
if (!$table || $table === $curTable) {
$out .= 'DROP TABLE IF EXISTS ' . $this->fullTableName($curTable) . ";\n";
}
}
@ -583,7 +581,7 @@ class DboMysql extends DboSource {
/**
* Returns an detailed array of sources (tables) in the database.
*
* @param string $name Table name to get parameters
* @param string $name Table name to get parameters
* @return array Array of tablenames in the database
*/
function listDetailedSources($name = null) {
@ -628,7 +626,7 @@ class DboMysql extends DboSource {
if (is_array($real)) {
$col = $real['name'];
if (isset($real['limit'])) {
$col .= '('.$real['limit'].')';
$col .= '(' . $real['limit'] . ')';
}
return $col;
}
@ -642,19 +640,19 @@ class DboMysql extends DboSource {
if (in_array($col, array('date', 'time', 'datetime', 'timestamp'))) {
return $col;
}
if (($col == 'tinyint' && $limit == 1) || $col == 'boolean') {
if (($col === 'tinyint' && $limit == 1) || $col === 'boolean') {
return 'boolean';
}
if (strpos($col, 'int') !== false) {
return 'integer';
}
if (strpos($col, 'char') !== false || $col == 'tinytext') {
if (strpos($col, 'char') !== false || $col === 'tinytext') {
return 'string';
}
if (strpos($col, 'text') !== false) {
return 'text';
}
if (strpos($col, 'blob') !== false || $col == 'binary') {
if (strpos($col, 'blob') !== false || $col === 'binary') {
return 'binary';
}
if (strpos($col, 'float') !== false || strpos($col, 'double') !== false || strpos($col, 'decimal') !== false) {

View file

@ -2744,7 +2744,7 @@ class DboSource extends DataSource {
if (strpos($col, '(') !== false) {
list($col, $limit) = explode('(', $col);
}
if ($limit != null) {
if ($limit !== null) {
return intval($limit);
}
return null;
@ -2762,10 +2762,10 @@ class DboSource extends DataSource {
$isFloat = in_array($type, array('dec', 'decimal', 'float', 'numeric', 'double'));
if ($isFloat && $offset) {
return $length.','.$offset;
return $length . ',' . $offset;
}
if (($real[0] == $type) && (count($real) == 1)) {
if (($real[0] == $type) && (count($real) === 1)) {
return null;
}
@ -2777,7 +2777,7 @@ class DboSource extends DataSource {
} elseif (in_array($type, array('enum', 'set'))) {
$length = 0;
foreach ($typeArr as $key => $enumValue) {
if ($key == 0) {
if ($key === 0) {
continue;
}
$tmpLength = strlen($enumValue);