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