From fea2b5798ca4b8aeaf7958f74b2694518e4fe226 Mon Sep 17 00:00:00 2001 From: Juan Basso Date: Fri, 25 Feb 2011 17:22:15 -0300 Subject: [PATCH] Minor optimizations in DboMysql. --- cake/libs/model/datasources/dbo/dbo_mysql.php | 34 +++++++++---------- cake/libs/model/datasources/dbo_source.php | 8 ++--- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 055964dc4..0ac24e123 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -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) { diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 3fac20ea8..7fd298c8d 100755 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -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);