Permalink
Browse files

Moving DboMysqli::describe() and DboMysql::describe() into DboMysqlBa…

…se. Removes duplicated method code.
  • Loading branch information...
1 parent d25497c commit c6999aea7f66bad6bd98e460351e045a0a6d4374 @markstory markstory committed Oct 24, 2009
Showing with 34 additions and 71 deletions.
  1. +34 −34 cake/libs/model/datasources/dbo/dbo_mysql.php
  2. +0 −37 cake/libs/model/datasources/dbo/dbo_mysqli.php
@@ -86,6 +86,40 @@ class DboMysqlBase extends DboSource {
'boolean' => array('name' => 'tinyint', 'limit' => '1')
);
/**
+ * Returns an array of the fields in given table name.
+ *
+ * @param string $tableName Name of database table to inspect
+ * @return array Fields in table. Keys are name and type
+ */
+ function describe(&$model) {
+ $cache = parent::describe($model);
+ if ($cache != null) {
+ return $cache;
+ }
+ $fields = false;
+ $cols = $this->query('DESCRIBE ' . $this->fullTableName($model));
+
+ foreach ($cols as $column) {
+ $colKey = array_keys($column);
+ if (isset($column[$colKey[0]]) && !isset($column[0])) {
+ $column[0] = $column[$colKey[0]];
+ }
+ if (isset($column[0])) {
+ $fields[$column[0]['Field']] = array(
+ 'type' => $this->column($column[0]['Type']),
+ 'null' => ($column[0]['Null'] == 'YES' ? true : false),
+ 'default' => $column[0]['Default'],
+ 'length' => $this->length($column[0]['Type']),
+ );
+ if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) {
+ $fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']];
+ }
+ }
+ }
+ $this->__cacheDescription($this->fullTableName($model, false), $fields);
+ return $fields;
+ }
+/**
* Generates and executes an SQL UPDATE statement for given model, fields, and values.
*
* @param Model $model
@@ -443,40 +477,6 @@ function listSources() {
}
}
/**
- * Returns an array of the fields in given table name.
- *
- * @param string $tableName Name of database table to inspect
- * @return array Fields in table. Keys are name and type
- */
- function describe(&$model) {
- $cache = parent::describe($model);
- if ($cache != null) {
- return $cache;
- }
- $fields = false;
- $cols = $this->query('DESCRIBE ' . $this->fullTableName($model));
-
- foreach ($cols as $column) {
- $colKey = array_keys($column);
- if (isset($column[$colKey[0]]) && !isset($column[0])) {
- $column[0] = $column[$colKey[0]];
- }
- if (isset($column[0])) {
- $fields[$column[0]['Field']] = array(
- 'type' => $this->column($column[0]['Type']),
- 'null' => ($column[0]['Null'] == 'YES' ? true : false),
- 'default' => $column[0]['Default'],
- 'length' => $this->length($column[0]['Type']),
- );
- if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) {
- $fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']];
- }
- }
- }
- $this->__cacheDescription($this->fullTableName($model, false), $fields);
- return $fields;
- }
-/**
* Returns a quoted and escaped string of $data for use in an SQL statement.
*
* @param string $data String to be prepared for use in an SQL statement
@@ -158,43 +158,6 @@ function listSources() {
return $tables;
}
/**
- * Returns an array of the fields in given table name.
- *
- * @param string $tableName Name of database table to inspect
- * @return array Fields in table. Keys are name and type
- */
- function describe(&$model) {
-
- $cache = parent::describe($model);
- if ($cache != null) {
- return $cache;
- }
-
- $fields = false;
- $cols = $this->query('DESCRIBE ' . $this->fullTableName($model));
-
- foreach ($cols as $column) {
- $colKey = array_keys($column);
- if (isset($column[$colKey[0]]) && !isset($column[0])) {
- $column[0] = $column[$colKey[0]];
- }
- if (isset($column[0])) {
- $fields[$column[0]['Field']] = array(
- 'type' => $this->column($column[0]['Type']),
- 'null' => ($column[0]['Null'] == 'YES' ? true : false),
- 'default' => $column[0]['Default'],
- 'length' => $this->length($column[0]['Type'])
- );
- if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) {
- $fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']];
- }
- }
- }
-
- $this->__cacheDescription($this->fullTableName($model, false), $fields);
- return $fields;
- }
-/**
* Returns a quoted and escaped string of $data for use in an SQL statement.
*
* @param string $data String to be prepared for use in an SQL statement

0 comments on commit c6999ae

Please sign in to comment.