#4503: DboMysqli needs index function so that console can generate proper indexes ------------------------------------------------------------+--------------- Reporter: simian187 | Owner: Type: Enhancement | Status: reopened Priority: Low | Milestone: 1.2.x.x Component: MySQLi | Version: RC1 Severity: Normal | Resolution: Keywords: dbomysqli mysqli index bake schema generate | Php_version: n/a Cake_version: | ------------------------------------------------------------+--------------- Changes (by stv):
* status: closed => reopened * resolution: fixed => Comment: I did the tests described below using cake trunk [source:trunk/cake/1.2....@8004 HEAD revision] (rev. 8004). I still have problems to generate proper indexes using `cake schema`. The problem seems to reside in MySQL version. Index generation works fine with MySQL 5.0.51a, but doesn't work with MySQL 4.1.16. I have the following table: {{{ CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `username` varchar(32) NOT NULL default '', `password` varchar(32) NOT NULL default '', `created` datetime default NULL, PRIMARY KEY (`id`) ) }}} On MySQL 4.1.16, the following command: {{{ cake schema generate }}} produces this `schema.php` file: {{{ <?php /* SVN FILE: $Id$ */ /* App schema generated on: 2009-01-29 12:01:04 : 1233224464*/ class AppSchema extends CakeSchema { var $name = 'App'; function before($event = array()) { return true; } function after($event = array()) { } var $users = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'username' => array('type' => 'string', 'null' => false, 'length' => 32), 'password' => array('type' => 'string', 'null' => false, 'length' => 32), 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'indexes' => array('' => array('column' => NULL, 'unique' => 1)) ); } ?> }}} Notice the line {{{ 'indexes' => array('' => array('column' => NULL, 'unique' => 1)) }}} which is obviously wrong. The `schema.php` file, produced by the same command using MySQL 5.0.51a is: {{{ <?php /* SVN FILE: $Id$ */ /* App schema generated on: 2009-01-29 15:01:09 : 1233234669*/ class AppSchema extends CakeSchema { var $name = 'App'; function before($event = array()) { return true; } function after($event = array()) { } var $users = array( 'id' => array('type' => 'integer', 'null' => false, 'default' => NULL, 'key' => 'primary'), 'username' => array('type' => 'string', 'null' => false, 'length' => 32), 'password' => array('type' => 'string', 'null' => false, 'length' => 32), 'created' => array('type' => 'datetime', 'null' => true, 'default' => NULL), 'indexes' => array('PRIMARY' => array('column' => 'id', 'unique' => 1)) ); } ?> }}} I agree with simian187 that the problem is in method [source:trunk/cake/1.2.x.x/cake/libs/model/datasources/dbo/dbo_mysql....@7945#l175 DboMysqlBase::index()] and particularly in line 180 {{{ $keys = Set::extract($indexes, '{n}.STATISTICS'); }}} The solution of replacing `STATISTICS` with `0` (as suggested above) is wrong, because it will fix the problem with MySQL 4.1 but will break the otherwise working case when using MySQL 5.x. I was able to fix this by replacing the line above with: {{{ $keys = array_values(reset($indexes)); }}} I don't know how adequate is that solution, it just works for me. -- Ticket URL: <https://trac.cakephp.org/ticket/4503#comment:5> CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/> Cake is a rapid development framework for PHP which uses commonly known design patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC. Our primary goal is to provide a structured framework that enables PHP users at all levels to rapidly develop robust web applications, without any loss to flexibility. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "tickets cakephp" group. To post to this group, send email to tickets-cakephp@googlegroups.com To unsubscribe from this group, send email to tickets-cakephp+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/tickets-cakephp?hl=en -~----------~----~----~----~------~----~------~--~---