From 29ddffa2d37d55f0a6d1903bd07feef5e7ed6746 Mon Sep 17 00:00:00 2001 From: mark_story Date: Mon, 9 Aug 2010 23:25:32 -0400 Subject: [PATCH] Fixing regression in DboMysqlBase where describe() was no longer pulling out fieldParameters. A test case has been added to catch any future regressions. Fixes #991 --- cake/libs/model/datasources/dbo/dbo_mysql.php | 14 +++++++- .../model/datasources/dbo/dbo_mysql.test.php | 36 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 731e14e70..3e6681d9d 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -122,7 +122,7 @@ class DboMysqlBase extends DboSource { return $cache; } $fields = false; - $cols = $this->query('DESCRIBE ' . $this->fullTableName($model)); + $cols = $this->query('SHOW FULL COLUMNS FROM ' . $this->fullTableName($model)); foreach ($cols as $column) { $colKey = array_keys($column); @@ -139,11 +139,23 @@ class DboMysqlBase extends DboSource { if (!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) { $fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']]; } + foreach ($this->fieldParameters as $name => $value) { + if (!empty($column[0][$value['column']])) { + $fields[$column[0]['Field']][$name] = $column[0][$value['column']]; + } + } + if (isset($fields[$column[0]['Field']]['collate'])) { + $charset = $this->getCharsetName($fields[$column[0]['Field']]['collate']); + if ($charset) { + $fields[$column[0]['Field']]['charset'] = $charset; + } + } } } $this->__cacheDescription($this->fullTableName($model, false), $fields); return $fields; } + /** * Generates and executes an SQL UPDATE statement for given model, fields, and values. * diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index f79b84298..7c2def568 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -774,7 +774,41 @@ class DboMysqlTest extends CakeTestCase { $result = $this->db->fields($model, null, array('data', 'other__field')); $expected = array('`BinaryTest`.`data`', '(SUM(id)) AS BinaryTest_$_other__field'); $this->assertEqual($result, $expected); - + } + +/** + * test that a describe() gets additional fieldParameters + * + * @return void + */ + function testDescribeGettingFieldParameters() { + $schema =& new CakeSchema(array( + 'connection' => 'test_suite', + 'testdescribes' => array( + 'id' => array('type' => 'integer', 'key' => 'primary'), + 'stringy' => array( + 'type' => 'string', + 'null' => true, + 'charset' => 'cp1250', + 'collate' => 'cp1250_general_ci', + ), + 'other_col' => array( + 'type' => 'string', + 'null' => false, + 'charset' => 'latin1', + 'comment' => 'Test Comment' + ) + ) + )); + $this->db->execute($this->db->createSchema($schema)); + + $model =& new CakeTestModel(array('table' => 'testdescribes', 'name' => 'Testdescribes')); + $result = $this->db->describe($model); + $this->assertEqual($result['stringy']['collate'], 'cp1250_general_ci'); + $this->assertEqual($result['stringy']['charset'], 'cp1250'); + $this->assertEqual($result['other_col']['comment'], 'Test Comment'); + + $this->db->execute($this->db->dropSchema($schema)); } }