Skip to content

Commit

Permalink
(Fixes issue 1995)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiang.xue committed Jan 14, 2011
1 parent 93ccfb7 commit 8d7f150
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -40,6 +40,7 @@ Version 1.1.6 to be released
- Enh #1929: Improved CActiveForm so that it can be used multiple times on the same page for the same type of data model (Qiang)
- Enh #1931: CDbConnection.tablePrefix can now use an empty string as table prefix (Qiang)
- Enh #1962: Added submenuOptions option to CMenu::items (Qiang)
- Enh #1995: Added CDbConnection::driverMap to allow more easily customizing schema classes (Qiang)
- Enh: Allowed passing multiple forms or choice format quantity parameter without wrapping it with array (Sam Dark)
- Enh: CDbConnection::quoteColumnName and quoteTableName will properly quote table prefix and schema prefix. (Qiang)
- Enh: Added CConsoleCommand::init() (Qiang)
Expand Down
44 changes: 22 additions & 22 deletions framework/db/CDbConnection.php
Expand Up @@ -164,6 +164,22 @@ class CDbConnection extends CApplicationComponent
* @since 1.1.1
*/
public $initSQLs;
/**
* @var array mapping between PDO driver and schema class name.
* A schema class can be specified using path alias.
* @since 1.1.6
*/
public $driverMap=array(
'pgsql'=>'CPgsqlSchema', // PostgreSQL
'mysqli'=>'CMysqlSchema', // MySQL
'mysql'=>'CMysqlSchema', // MySQL
'sqlite'=>'CSqliteSchema', // sqlite 3
'sqlite2'=>'CSqliteSchema', // sqlite 2
'mssql'=>'CMssqlSchema', // Mssql driver on windows hosts
'dblib'=>'CMssqlSchema', // dblib drivers on linux (and maybe others os) hosts
'sqlsrv'=>'CMssqlSchema', // Mssql
'oci'=>'CMssqlSchema', // Oracle driver
);

private $_attributes=array();
private $_active=false;
Expand Down Expand Up @@ -405,28 +421,12 @@ public function getSchema()
{
if(!$this->getActive())
throw new CDbException(Yii::t('yii','CDbConnection is inactive and cannot perform any DB operations.'));
$driver=$this->getDriverName();
switch(strtolower($driver))
{
case 'pgsql': // PostgreSQL
return $this->_schema=new CPgsqlSchema($this);
case 'mysqli': // MySQL
case 'mysql':
return $this->_schema=new CMysqlSchema($this);
case 'sqlite': // sqlite 3
case 'sqlite2': // sqlite 2
return $this->_schema=new CSqliteSchema($this);
case 'mssql': // Mssql driver on windows hosts
case 'dblib': // dblib drivers on linux (and maybe others os) hosts
case 'sqlsrv':
return $this->_schema=new CMssqlSchema($this);
case 'oci': // Oracle driver
return $this->_schema=new COciSchema($this);
case 'ibm':
default:
throw new CDbException(Yii::t('yii','CDbConnection does not support reading schema for {driver} database.',
array('{driver}'=>$driver)));
}
$driver=strtolower($this->getDriverName());
if(isset($this->driverMap[$driver]))
return $this->_schema=Yii::createComponent($this->driverMap[$driver], $this);
else
throw new CDbException(Yii::t('yii','CDbConnection does not support reading schema for {driver} database.',
array('{driver}'=>$driver)));
}
}

Expand Down

0 comments on commit 8d7f150

Please sign in to comment.