Skip to content

Commit

Permalink
Merge pull request #3559 from yiisoft/revert-3551-master
Browse files Browse the repository at this point in the history
Revert "Fixed caching for table schema with prefix"
  • Loading branch information
samdark committed Sep 29, 2014
2 parents ad6642e + 09eb303 commit 8575b22
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 72 deletions.
1 change: 0 additions & 1 deletion CHANGELOG
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion framework/db/schema/CDbSchema.php
Expand Up @@ -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)
{
Expand Down
12 changes: 0 additions & 12 deletions tests/framework/db/data/mysql.sql
Expand Up @@ -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;
69 changes: 11 additions & 58 deletions tests/framework/db/schema/CMysqlTest.php
Expand Up @@ -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'))
Expand All @@ -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();

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 8575b22

Please sign in to comment.