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:
AD7six 2008-11-05 13:44:05 +00:00
parent ea30a48c5a
commit 2a9b8643db
2 changed files with 83 additions and 20 deletions

View file

@ -513,6 +513,7 @@ class DboMysql extends DboSource {
$keys = Set::extract($indexes, '{n}.STATISTICS');
foreach ($keys as $i => $key) {
if (!isset($index[$key['Key_name']])) {
$col = array();
$index[$key['Key_name']]['column'] = $key['Column_name'];
$index[$key['Key_name']]['unique'] = intval($key['Non_unique'] == 0);
} else {

View file

@ -38,22 +38,22 @@ App::import('Core', array('Model', 'DataSource', 'DboSource', 'DboMysql'));
class DboMysqlTestDb extends DboMysql {
/**
* simulated property
*
*
* @var array
* @access public
*/
var $simulated = array();
/**
* testing property
*
*
* @var bool true
* @access public
*/
var $testing = true;
/**
* execute method
*
* @param mixed $sql
*
* @param mixed $sql
* @access protected
* @return void
*/
@ -66,7 +66,7 @@ class DboMysqlTestDb extends DboMysql {
}
/**
* getLastQuery method
*
*
* @access public
* @return void
*/
@ -83,25 +83,25 @@ class DboMysqlTestDb extends DboMysql {
class MysqlTestModel extends Model {
/**
* name property
*
*
* @var string 'MysqlTestModel'
* @access public
*/
var $name = 'MysqlTestModel';
/**
* useTable property
*
*
* @var bool false
* @access public
*/
var $useTable = false;
/**
* find method
*
* @param mixed $conditions
* @param mixed $fields
* @param mixed $order
* @param mixed $recursive
*
* @param mixed $conditions
* @param mixed $fields
* @param mixed $order
* @param mixed $recursive
* @access public
* @return void
*/
@ -110,11 +110,11 @@ class MysqlTestModel extends Model {
}
/**
* findAll method
*
* @param mixed $conditions
* @param mixed $fields
* @param mixed $order
* @param mixed $recursive
*
* @param mixed $conditions
* @param mixed $fields
* @param mixed $order
* @param mixed $recursive
* @access public
* @return void
*/
@ -123,7 +123,7 @@ class MysqlTestModel extends Model {
}
/**
* schema method
*
*
* @access public
* @return void
*/
@ -236,7 +236,7 @@ class DboMysqlTest extends CakeTestCase {
$expected = 'NULL';
$result = $this->db->value('', 'integer');
$this->assertEqual($expected, $result);
$expected = 'NULL';
$result = $this->db->value('', 'boolean');
$this->assertEqual($expected, $result);
@ -251,7 +251,7 @@ class DboMysqlTest extends CakeTestCase {
}
/**
* testTinyintCasting method
*
*
* @access public
* @return void
*/
@ -287,6 +287,68 @@ class DboMysqlTest extends CakeTestCase {
$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);
}
}
?>