From 99874c60d99ab2d498fe76179c8684e1168117e8 Mon Sep 17 00:00:00 2001 From: gwoo Date: Tue, 13 May 2008 18:03:44 +0000 Subject: [PATCH] fixes #4238, Mysqli working with the test suite. git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6849 3807eeeb-6ff5-0310-8944-8be069107fe0 --- cake/libs/model/datasources/dbo/dbo_mysql.php | 27 ---------- .../libs/model/datasources/dbo/dbo_mysqli.php | 10 ++++ cake/libs/model/datasources/dbo_source.php | 51 ++++++++++++------- cake/tests/lib/cake_test_fixture.php | 23 +++++++-- 4 files changed, 63 insertions(+), 48 deletions(-) diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index caca7fa5d..4644db106 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -599,32 +599,5 @@ class DboMysql extends DboSource { } return $out; } -/** - * Format indexes for create table - * - * @param array $indexes - * @return string - */ - function buildIndex($indexes) { - $join = array(); - foreach ($indexes as $name => $value) { - $out = ''; - if ($name == 'PRIMARY') { - $out .= 'PRIMARY '; - $name = null; - } else { - if (!empty($value['unique'])) { - $out .= 'UNIQUE '; - } - } - if (is_array($value['column'])) { - $out .= 'KEY '. $name .' (' . join(', ', array_map(array(&$this, 'name'), $value['column'])) . ')'; - } else { - $out .= 'KEY '. $name .' (' . $this->name($value['column']) . ')'; - } - $join[] = $out; - } - return join(",\n\t", $join); - } } ?> \ No newline at end of file diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index 2c1e8e15d..0a2e86de5 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -54,6 +54,13 @@ class DboMysqli extends DboSource { * @var unknown_type */ var $endQuote = "`"; +/** + * index definition, standard cake, primary, index, unique + * + * @var array + */ + var $index = array('PRI' => 'primary', 'MUL' => 'index', 'UNI' => 'unique'); + /** * Base configuration settings for Mysqli driver * @@ -199,6 +206,9 @@ class DboMysqli extends DboSource { 'default' => $column[0]['Default'], 'length' => $this->length($column[0]['Type']) ); + if(!empty($column[0]['Key']) && isset($this->index[$column[0]['Key']])) { + $fields[$column[0]['Field']]['key'] = $this->index[$column[0]['Key']]; + } } } diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 6c0e6b68b..59cc33dc9 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -181,7 +181,7 @@ class DboSource extends DataSource { $limit = null; $page = null; $recursive = null; - + if (count($args) == 1) { return $this->fetchAll($args[0]); @@ -979,17 +979,19 @@ class DboSource extends DataSource { unset($assocFields, $passedFields); } - // $tmpModel =& $model; - // - // if ($linkModel != null) { - // $tmpModel =& $linkModel; - // } - // foreach ($tmpModel->schema() as $field => $info) { - // if ($info['type'] == 'boolean') { - // $this->_booleans[$tmpModel->alias][] = $field; - // } - // } - // unset($tmpModel); + /* Saving for later refactor + $tmpModel =& $model; + + if ($linkModel != null) { + $tmpModel =& $linkModel; + } + foreach ($tmpModel->schema() as $field => $info) { + if ($info['type'] == 'boolean') { + $this->_booleans[$tmpModel->alias][] = $field; + } + } + unset($tmpModel); + */ if ($linkModel == null) { return $this->buildStatement( @@ -1984,9 +1986,7 @@ class DboSource extends DataSource { * @access protected */ function insertMulti($table, $fields, $values) { - if (is_object($table)) { - $table = $this->fullTableName($table); - } + $table = $this->fullTableName($table); if (is_array($fields)) { $fields = join(', ', array_map(array(&$this, 'name'), $fields)); } @@ -2139,8 +2139,25 @@ class DboSource extends DataSource { * @return string */ function buildIndex($indexes) { - return false; + $join = array(); + foreach ($indexes as $name => $value) { + $out = ''; + if ($name == 'PRIMARY') { + $out .= 'PRIMARY '; + $name = null; + } else { + if (!empty($value['unique'])) { + $out .= 'UNIQUE '; + } + } + if (is_array($value['column'])) { + $out .= 'KEY '. $name .' (' . join(', ', array_map(array(&$this, 'name'), $value['column'])) . ')'; + } else { + $out .= 'KEY '. $name .' (' . $this->name($value['column']) . ')'; + } + $join[] = $out; + } + return join(",\n\t", $join); } } - ?> \ No newline at end of file diff --git a/cake/tests/lib/cake_test_fixture.php b/cake/tests/lib/cake_test_fixture.php index ba6ce2b4c..47a6d827a 100644 --- a/cake/tests/lib/cake_test_fixture.php +++ b/cake/tests/lib/cake_test_fixture.php @@ -33,7 +33,19 @@ * @subpackage cake.cake.tests.lib */ class CakeTestFixture extends Object { +/** + * Cake's DBO driver (e.g: DboMysql). + * + * @access public + */ var $db = null; +/** + * Full Table Name + * + * @access public + */ + var $table = null; + /** * Instantiate the fixture. * @@ -42,15 +54,17 @@ class CakeTestFixture extends Object { * @access public */ function __construct(&$db) { - $this->init(); - if(!class_exists('cakeschema')) { - uses('model' . DS .'schema'); - } + App::import('Model', 'Schema'); $this->Schema = new CakeSchema(array('name'=>'TestSuite', 'connection'=>'test_suite')); + + $this->init(); } /** * Initialize the fixture. * + * @param object Cake's DBO driver (e.g: DboMysql). + * @access public + * */ function init() { if (isset($this->import) && (is_string($this->import) || is_array($this->import))) { @@ -105,6 +119,7 @@ class CakeTestFixture extends Object { if (!isset($this->table)) { $this->table = Inflector::underscore(Inflector::pluralize($this->name)); } + if (!isset($this->primaryKey) && isset($this->fields['id'])) { $this->primaryKey = 'id'; }