From 09eb3038d610d87f2450852187a02d88b53f8f2f Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Mon, 29 Sep 2014 14:45:16 +0400 Subject: [PATCH] Revert "Fixed caching for table schema with prefix" --- CHANGELOG | 1 - framework/db/schema/CDbSchema.php | 2 +- tests/framework/db/data/mysql.sql | 12 ----- tests/framework/db/schema/CMysqlTest.php | 69 ++++-------------------- 4 files changed, 12 insertions(+), 72 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 65ce050b72..553f07aea9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -58,7 +58,6 @@ Version 1.1.16 under development - Bug: Fixed an issue with CFilehelper and not accessable directories which resulted in endless loop (cebe) - Bug #3305: COciSchema column comment reading from another schema (gureedo) - Bug #3406: Fixed Object of class Imagick could not be converted to string (eXprojects) -- Bug #3551: CDbSchema::getTable() fixed caching for table schema with prefix (maxsh) - Enh: Public method CFileHelper::createDirectory() has been added (klimov-paul) - Enh: Added proper handling and support of the symlinked directories in CFileHelper::removeDirectory(), added $options parameter in CFileHelper::removeDirectory() (resurtm) - Enh #89: Support for SOAP headers in WSDL generator (nineinchnick) diff --git a/framework/db/schema/CDbSchema.php b/framework/db/schema/CDbSchema.php index 66c75c15d3..18d3f0e932 100644 --- a/framework/db/schema/CDbSchema.php +++ b/framework/db/schema/CDbSchema.php @@ -89,7 +89,7 @@ public function getTable($name,$refresh=false) if(!isset($this->_cacheExclude[$name]) && ($duration=$this->_connection->schemaCachingDuration)>0 && $this->_connection->schemaCacheID!==false && ($cache=Yii::app()->getComponent($this->_connection->schemaCacheID))!==null) { - $key='yii:dbschema'.$this->_connection->connectionString.':'.$this->_connection->username.':'.$realName; + $key='yii:dbschema'.$this->_connection->connectionString.':'.$this->_connection->username.':'.$name; $table=$cache->get($key); if($refresh===true || $table===false) { diff --git a/tests/framework/db/data/mysql.sql b/tests/framework/db/data/mysql.sql index f776f31d53..8a85621290 100644 --- a/tests/framework/db/data/mysql.sql +++ b/tests/framework/db/data/mysql.sql @@ -149,16 +149,4 @@ CREATE TABLE types bool_col2 BOOLEAN DEFAULT 1, bit_col1 BIT, bit_col2 BIT(32) DEFAULT b'101010' -) ENGINE=InnoDB; - -CREATE TABLE p1_state -( - id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, - name VARCHAR(128) -) ENGINE=InnoDB; - -CREATE TABLE p2_state -( - id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, - name VARCHAR(128) ) ENGINE=InnoDB; \ No newline at end of file diff --git a/tests/framework/db/schema/CMysqlTest.php b/tests/framework/db/schema/CMysqlTest.php index 4944534cf4..5829411fc2 100644 --- a/tests/framework/db/schema/CMysqlTest.php +++ b/tests/framework/db/schema/CMysqlTest.php @@ -8,22 +8,6 @@ class CMysqlTest extends CTestCase { private $db; - private $_appConfig=array( - 'id'=>'testApp', - 'components'=>array( - 'cache'=>array( - 'class'=>'CFileCache', - ), - 'db'=>array( - 'connectionString'=>'mysql:host=127.0.0.1;dbname=yii', - 'username'=>'root', - 'password'=>'root', - 'charset'=>'UTF8', - 'schemaCachingDuration'=>300, - ), - ), - ); - public function setUp() { if(!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) @@ -41,7 +25,7 @@ public function setUp() $this->markTestSkipped("Please read $schemaFile for details on setting up the test environment for MySQL test case."); } - $tables=array('comments','post_category','posts','categories','profiles','users','items','orders','types','p1_state','p2_state'); + $tables=array('comments','post_category','posts','categories','profiles','users','items','orders','types'); foreach($tables as $table) $this->db->createCommand("DROP TABLE IF EXISTS $table CASCADE")->execute(); @@ -70,37 +54,6 @@ public function testSchema() $this->assertNull($schema->getTable('foo')); } - public function testTableSchemaWithTablePrefix() - { - $schema=$this->db->schema; - $this->db->tablePrefix = 'p1_'; - $table=$schema->getTable('{{state}}'); - $this->assertEquals('p1_state',$table->name); - $this->db->tablePrefix = 'p2_'; - $table=$schema->getTable('{{state}}'); - $this->assertEquals('p1_state',$table->name); - } - - public function testTableSchemaWithTablePrefixAndEnabledCache() - { - $app=new TestApplication($this->_appConfig); - $app->reset(); - $app->cache->flush(); - $schema=$app->db->schema; - $app->db->tablePrefix = 'p1_'; - $table=$schema->getTable('{{state}}'); - $this->assertEquals('p1_state',$table->name); - } - - public function testTableSchemaWithTablePrefixAndEnabledCacheForCachedSchema() - { - $app=new TestApplication($this->_appConfig); - $schema=$app->db->schema; - $app->db->tablePrefix = 'p2_'; - $table=$schema->getTable('{{state}}'); - $this->assertEquals('p2_state',$table->name); - } - public function testTable() { $table=$this->db->schema->getTable('posts'); @@ -248,16 +201,16 @@ public function testCommandBuilder() $c=$builder->createSqlCommand('SELECT author_id FROM posts WHERE id=5'); $this->assertEquals(2,$c->queryScalar()); - // test for updates with joins - $c=$builder->createUpdateCommand($table,array('title'=>'new post 1'),new CDbCriteria(array( - 'condition'=>'u.`username`=:username', - 'join'=>'JOIN `users` u ON `author_id`=u.`id`', - 'params'=>array(':username'=>'user1')))); - $c->execute(); - $c=$builder->createFindCommand($table,new CDbCriteria(array( - 'select'=>'title', - 'condition'=>'id=:id', - 'params'=>array('id'=>1)))); + // test for updates with joins + $c=$builder->createUpdateCommand($table,array('title'=>'new post 1'),new CDbCriteria(array( + 'condition'=>'u.`username`=:username', + 'join'=>'JOIN `users` u ON `author_id`=u.`id`', + 'params'=>array(':username'=>'user1')))); + $c->execute(); + $c=$builder->createFindCommand($table,new CDbCriteria(array( + 'select'=>'title', + 'condition'=>'id=:id', + 'params'=>array('id'=>1)))); $this->assertEquals('new post 1',$c->queryScalar()); $c=$builder->createUpdateCounterCommand($table,array('author_id'=>-1),new CDbCriteria(array(