mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
Correcting index detection to not include the fields from a previous index, where several mult-field indexes
exist git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7827 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
ea30a48c5a
commit
2a9b8643db
2 changed files with 83 additions and 20 deletions
|
@ -513,6 +513,7 @@ class DboMysql extends DboSource {
|
||||||
$keys = Set::extract($indexes, '{n}.STATISTICS');
|
$keys = Set::extract($indexes, '{n}.STATISTICS');
|
||||||
foreach ($keys as $i => $key) {
|
foreach ($keys as $i => $key) {
|
||||||
if (!isset($index[$key['Key_name']])) {
|
if (!isset($index[$key['Key_name']])) {
|
||||||
|
$col = array();
|
||||||
$index[$key['Key_name']]['column'] = $key['Column_name'];
|
$index[$key['Key_name']]['column'] = $key['Column_name'];
|
||||||
$index[$key['Key_name']]['unique'] = intval($key['Non_unique'] == 0);
|
$index[$key['Key_name']]['unique'] = intval($key['Non_unique'] == 0);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -287,6 +287,68 @@ class DboMysqlTest extends CakeTestCase {
|
||||||
|
|
||||||
$this->db->query('DROP TABLE ' . $this->db->fullTableName('tinyint'));
|
$this->db->query('DROP TABLE ' . $this->db->fullTableName('tinyint'));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* testIndexDetection method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @access public
|
||||||
|
*/
|
||||||
|
function testIndexDetection() {
|
||||||
|
$this->db->cacheSources = $this->db->testing = false;
|
||||||
|
|
||||||
|
$name = $this->db->fullTableName('simple');
|
||||||
|
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id));');
|
||||||
|
$expected = array('PRIMARY' => array('column' => 'id', 'unique' => 1));
|
||||||
|
$result = $this->db->index($name, false);
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
$this->db->query('DROP TABLE ' . $name);
|
||||||
|
|
||||||
|
$name = $this->db->fullTableName('with_a_key');
|
||||||
|
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ));');
|
||||||
|
$expected = array(
|
||||||
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
||||||
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
||||||
|
);
|
||||||
|
$result = $this->db->index($name, false);
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
$this->db->query('DROP TABLE ' . $name);
|
||||||
|
|
||||||
|
$name = $this->db->fullTableName('with_two_keys');
|
||||||
|
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ));');
|
||||||
|
$expected = array(
|
||||||
|
'PRIMARY' => array('column' => 'id', 'unique' => 1),
|
||||||
|
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
|
||||||
|
'pointless_small_int' => array('column' => 'small_int', 'unique' => 0),
|
||||||
|
);
|
||||||
|
$result = $this->db->index($name, false);
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
$this->db->query('DROP TABLE ' . $name);
|
||||||
|
|
||||||
|
$name = $this->db->fullTableName('with_compound_keys');
|
||||||
|
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ));');
|
||||||
|
$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),
|
||||||
|
);
|
||||||
|
$result = $this->db->index($name, false);
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
$this->db->query('DROP TABLE ' . $name);
|
||||||
|
|
||||||
|
$name = $this->db->fullTableName('with_multiple_compound_keys');
|
||||||
|
$this->db->query('CREATE TABLE ' . $name . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id), KEY `pointless_bool` ( `bool` ), KEY `pointless_small_int` ( `small_int` ), KEY `one_way` ( `bool`, `small_int` ), KEY `other_way` ( `small_int`, `bool` ));');
|
||||||
|
$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),
|
||||||
|
'other_way' => array('column' => array('small_int', 'bool'), 'unique' => 0),
|
||||||
|
);
|
||||||
|
$result = $this->db->index($name, false);
|
||||||
|
$this->assertEqual($expected, $result);
|
||||||
|
$this->db->query('DROP TABLE ' . $name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Add table
Reference in a new issue