mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
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
This commit is contained in:
parent
ccfb1d179a
commit
29ddffa2d3
2 changed files with 48 additions and 2 deletions
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue