diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 9b0c2cff2..af2d6ebee 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -707,6 +707,7 @@ class DboMysql extends DboSource { $values = implode(', ', $values); $this->query("INSERT INTO {$table} ({$fields}) VALUES {$values}"); } + /** * Returns an detailed array of sources (tables) in the database. * @@ -715,20 +716,24 @@ class DboMysql extends DboSource { */ function listDetailedSources($name = null) { $condition = ''; + $params = array(); if (is_string($name)) { - $condition = ' LIKE ' . $this->value($name); + $condition = ' WHERE name = ?' ; + $params = array($name); } - $result = $this->query('SHOW TABLE STATUS FROM ' . $this->name($this->config['database']) . $condition . ';'); + $result = $this->_execute('SHOW TABLE STATUS ' . $condition, $params); + if (!$result) { return array(); } else { $tables = array(); - foreach ($result as $row) { - $tables[$row['TABLES']['Name']] = $row['TABLES']; - if (!empty($row['TABLES']['Collation'])) { - $charset = $this->getCharsetName($row['TABLES']['Collation']); + while ($row = $result->fetch()) { + $tables[$row->Name] = (array) $row; + unset($tables[$row->Name]['queryString']); + if (!empty($row->Collation)) { + $charset = $this->getCharsetName($row->Collation); if ($charset) { - $tables[$row['TABLES']['Name']]['charset'] = $charset; + $tables[$row->Name]['charset'] = $charset; } } } diff --git a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php index 76d294d7e..32471c21f 100644 --- a/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php +++ b/cake/tests/cases/libs/model/datasources/dbo/dbo_mysql.test.php @@ -705,7 +705,7 @@ class DboMysqlTest extends CakeTestCase { ) ) )); - $this->Dbo->query($this->Dbo->createSchema($schema1)); + $this->Dbo->rawQuery($this->Dbo->createSchema($schema1)); $schema2 = new CakeSchema(array( 'name' => 'AlterTest1', 'connection' => 'test', @@ -720,17 +720,17 @@ class DboMysqlTest extends CakeTestCase { ) )); $result = $this->Dbo->alterSchema($schema2->compare($schema1)); - $this->assertPattern('/DEFAULT CHARSET=utf8/', $result); - $this->assertPattern('/ENGINE=InnoDB/', $result); - $this->assertPattern('/COLLATE=utf8_general_ci/', $result); + $this->assertContains('DEFAULT CHARSET=utf8', $result); + $this->assertContains('ENGINE=InnoDB', $result); + $this->assertContains('COLLATE=utf8_general_ci', $result); - $this->Dbo->query($result); + $this->Dbo->rawQuery($result); $result = $this->Dbo->listDetailedSources('altertest'); $this->assertEqual($result['Collation'], 'utf8_general_ci'); $this->assertEqual($result['Engine'], 'InnoDB'); $this->assertEqual($result['charset'], 'utf8'); - $this->Dbo->query($this->Dbo->dropSchema($schema1)); + $this->Dbo->rawQuery($this->Dbo->dropSchema($schema1)); } /** @@ -739,7 +739,7 @@ class DboMysqlTest extends CakeTestCase { * @return void */ function testAlteringTwoTables() { - $schema1 =& new CakeSchema(array( + $schema1 = new CakeSchema(array( 'name' => 'AlterTest1', 'connection' => 'test', 'altertest' => array( @@ -751,7 +751,7 @@ class DboMysqlTest extends CakeTestCase { 'name' => array('type' => 'string', 'null' => false, 'length' => 50), ) )); - $schema2 =& new CakeSchema(array( + $schema2 = new CakeSchema(array( 'name' => 'AlterTest1', 'connection' => 'test', 'altertest' => array( @@ -776,23 +776,23 @@ class DboMysqlTest extends CakeTestCase { function testReadTableParameters() { $this->Dbo->cacheSources = $this->Dbo->testing = false; $tableName = 'tinyint_' . uniqid(); - $this->Dbo->query('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'); + $this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'); $result = $this->Dbo->readTableParameters($tableName); + $this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); $expected = array( 'charset' => 'utf8', 'collate' => 'utf8_unicode_ci', 'engine' => 'InnoDB'); $this->assertEqual($result, $expected); - $this->Dbo->query('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); - $this->Dbo->query('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;'); + $this->Dbo->rawQuery('CREATE TABLE ' . $this->Dbo->fullTableName($tableName) . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;'); $result = $this->Dbo->readTableParameters($tableName); + $this->Dbo->rawQuery('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); $expected = array( 'charset' => 'cp1250', 'collate' => 'cp1250_general_ci', 'engine' => 'MyISAM'); $this->assertEqual($result, $expected); - $this->Dbo->query('DROP TABLE ' . $this->Dbo->fullTableName($tableName)); } /**