mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Added conditional check for compatibility with MySQL 4.x result sets to DboMySqlBase::index(). Tests added. Thanks to 'teknoid' for the help. Closes #4503
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@8020 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b71457f332
commit
d3ee6b31f1
2 changed files with 99 additions and 1 deletions
|
@ -177,7 +177,11 @@ class DboMysqlBase extends DboSource {
|
|||
$table = $this->fullTableName($model);
|
||||
if ($table) {
|
||||
$indexes = $this->query('SHOW INDEX FROM ' . $table);
|
||||
$keys = Set::extract($indexes, '{n}.STATISTICS');
|
||||
if (isset($indexes[0]['STATISTICS'])) {
|
||||
$keys = Set::extract($indexes, '{n}.STATISTICS');
|
||||
} else {
|
||||
$keys = Set::extract($indexes, '{n}.0');
|
||||
}
|
||||
foreach ($keys as $i => $key) {
|
||||
if (!isset($index[$key['Key_name']])) {
|
||||
$col = array();
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
App::import('Core', array('Model', 'DataSource', 'DboSource', 'DboMysql'));
|
||||
|
||||
Mock::generatePartial('DboMysql', 'QueryMockDboMysql', array('query'));
|
||||
/**
|
||||
* Short description for class.
|
||||
*
|
||||
|
@ -361,6 +362,99 @@ class DboMysqlTest extends CakeTestCase {
|
|||
$this->assertEqual($expected, $result);
|
||||
$this->db->query('DROP TABLE ' . $name);
|
||||
}
|
||||
/**
|
||||
* MySQL 4.x returns index data in a different format,
|
||||
* Using a mock ensure that MySQL 4.x output is properly parsed.
|
||||
*
|
||||
* @return void
|
||||
**/
|
||||
function testIndexOnMySQL4Output() {
|
||||
$name = $this->db->fullTableName('simple');
|
||||
|
||||
$mockDbo =& new QueryMockDboMysql($this);
|
||||
$columnData = array(
|
||||
array('0' => array(
|
||||
'Table' => 'with_compound_keys',
|
||||
'Non_unique' => '0',
|
||||
'Key_name' => 'PRIMARY',
|
||||
'Seq_in_index' => '1',
|
||||
'Column_name' => 'id',
|
||||
'Collation' => 'A',
|
||||
'Cardinality' => '0',
|
||||
'Sub_part' => NULL,
|
||||
'Packed' => NULL,
|
||||
'Null' => '',
|
||||
'Index_type' => 'BTREE',
|
||||
'Comment' => ''
|
||||
)),
|
||||
array('0' => array(
|
||||
'Table' => 'with_compound_keys',
|
||||
'Non_unique' => '1',
|
||||
'Key_name' => 'pointless_bool',
|
||||
'Seq_in_index' => '1',
|
||||
'Column_name' => 'bool',
|
||||
'Collation' => 'A',
|
||||
'Cardinality' => NULL,
|
||||
'Sub_part' => NULL,
|
||||
'Packed' => NULL,
|
||||
'Null' => 'YES',
|
||||
'Index_type' => 'BTREE',
|
||||
'Comment' => ''
|
||||
)),
|
||||
array('0' => array(
|
||||
'Table' => 'with_compound_keys',
|
||||
'Non_unique' => '1',
|
||||
'Key_name' => 'pointless_small_int',
|
||||
'Seq_in_index' => '1',
|
||||
'Column_name' => 'small_int',
|
||||
'Collation' => 'A',
|
||||
'Cardinality' => NULL,
|
||||
'Sub_part' => NULL,
|
||||
'Packed' => NULL,
|
||||
'Null' => 'YES',
|
||||
'Index_type' => 'BTREE',
|
||||
'Comment' => ''
|
||||
)),
|
||||
array('0' => array(
|
||||
'Table' => 'with_compound_keys',
|
||||
'Non_unique' => '1',
|
||||
'Key_name' => 'one_way',
|
||||
'Seq_in_index' => '1',
|
||||
'Column_name' => 'bool',
|
||||
'Collation' => 'A',
|
||||
'Cardinality' => NULL,
|
||||
'Sub_part' => NULL,
|
||||
'Packed' => NULL,
|
||||
'Null' => 'YES',
|
||||
'Index_type' => 'BTREE',
|
||||
'Comment' => ''
|
||||
)),
|
||||
array('0' => array(
|
||||
'Table' => 'with_compound_keys',
|
||||
'Non_unique' => '1',
|
||||
'Key_name' => 'one_way',
|
||||
'Seq_in_index' => '2',
|
||||
'Column_name' => 'small_int',
|
||||
'Collation' => 'A',
|
||||
'Cardinality' => NULL,
|
||||
'Sub_part' => NULL,
|
||||
'Packed' => NULL,
|
||||
'Null' => 'YES',
|
||||
'Index_type' => 'BTREE',
|
||||
'Comment' => ''
|
||||
))
|
||||
);
|
||||
$mockDbo->setReturnValue('query', $columnData, array('SHOW INDEX FROM ' . $name));
|
||||
|
||||
$result = $mockDbo->index($name, false);
|
||||
$expected = array(
|
||||
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
||||
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
||||
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
||||
'one_way' => array('column' => array('bool', 'small_int'), 'unique' => 0),
|
||||
);
|
||||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
/**
|
||||
* testColumn method
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue