Yii Framework v1.1.10 绫诲弬鑰

CPgsqlSchema

system.db.schema.pgsql
缁ф壙 class CPgsqlSchema » CDbSchema » CComponent
婧愯嚜 1.0
鐗堟湰 $Id: CPgsqlSchema.php 3515 2011-12-28 12:29:24Z mdomba $
婧愮爜 framework/db/schema/pgsql/CPgsqlSchema.php
CPgsqlSchema鏄粠PostgreSQL鏁版嵁搴撴绱㈠厓鏁版嵁淇℃伅鐨勭被銆

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
columnTypes array 鏄犲皠鍒板疄浣撳垪绫诲瀷鐨勬娊璞″垪绫诲瀷銆 CPgsqlSchema
commandBuilder CDbCommandBuilder the SQL command builder for this connection. CDbSchema
dbConnection CDbConnection database connection. CDbSchema
tableNames array Returns all table names in the database. CDbSchema
tables array Returns the metadata for all tables in the database. CDbSchema

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 濡傛灉绫讳腑娌℃湁璋冪殑鏂规硶鍚嶏紝鍒欒皟鐢ㄨ繖涓柟娉曘 CComponent
__construct() Constructor. CDbSchema
__get() 杩斿洖涓涓睘鎬у笺佷竴涓簨浠跺鐞嗙▼搴忓垪琛ㄦ垨涓涓涓哄悕绉般 CComponent
__isset() 妫鏌ヤ竴涓睘鎬ф槸鍚︿负null銆 CComponent
__set() 璁剧疆涓涓粍浠剁殑灞炴у笺 CComponent
__unset() 璁剧疆涓涓粍浠剁殑灞炴т负null銆 CComponent
addColumn() 鏋勯犳坊鍔犳柊鍒楃殑SQL璇彞銆 CPgsqlSchema
addForeignKey() Builds a SQL statement for adding a foreign key constraint to an existing table. CDbSchema
alterColumn() 鏋勯犳敼鍙樺垪瀹氫箟鐨凷QL璇彞銆 CPgsqlSchema
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
checkIntegrity() 鍚敤鎴栫鐢ㄥ畬鏁存ф鏌ャ CPgsqlSchema
compareTableNames() Compares two table names. CDbSchema
createIndex() Builds a SQL statement for creating a new index. CDbSchema
createTable() Builds a SQL statement for creating a new DB table. CDbSchema
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
dropColumn() Builds a SQL statement for dropping a DB column. CDbSchema
dropForeignKey() Builds a SQL statement for dropping a foreign key constraint. CDbSchema
dropIndex() 鏋勯犲垹闄ょ储寮曠殑SQL璇彞銆 CPgsqlSchema
dropTable() Builds a SQL statement for dropping a DB table. CDbSchema
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
getColumnType() Converts an abstract column type into a physical column type. CDbSchema
getCommandBuilder() 杩斿洖the SQL command builder for this connection. CDbSchema
getDbConnection() 杩斿洖database connection. The connection is active. CDbSchema
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getTable() Obtains the metadata for the named table. CDbSchema
getTableNames() Returns all table names in the database. CDbSchema
getTables() Returns the metadata for all tables in the database. CDbSchema
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
quoteColumnName() Quotes a column name for use in a query. CDbSchema
quoteSimpleColumnName() Quotes a simple column name for use in a query. CDbSchema
quoteSimpleTableName() 鐢ㄥ紩鍙峰紩鐢ㄨ〃鍚嶄互渚挎煡璇㈡椂浣跨敤銆 CPgsqlSchema
quoteTableName() Quotes a table name for use in a query. CDbSchema
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
refresh() Refreshes the schema. CDbSchema
renameColumn() Builds a SQL statement for renaming a column. CDbSchema
renameTable() 鏋勯犻噸鍛藉悕鏁版嵁琛ㄧ殑SQL璇彞銆 CPgsqlSchema
resetSequence() 閲嶇疆琛ㄧ殑涓婚敭鐨勫簭鍒楀笺 CPgsqlSchema
truncateTable() Builds a SQL statement for truncating a DB table. CDbSchema

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
createColumn() 鍒涘缓涓涓垪銆 CPgsqlSchema
createCommandBuilder() Creates a command builder for the database. CDbSchema
findColumns() 鏀堕泦鍒楃殑鍏冩暟鎹 CPgsqlSchema
findConstraints() 鏀堕泦缁欏畾琛ㄤ富閿垪鍜屽閿垪鐨勮缁嗕俊鎭 CPgsqlSchema
findForeignKey() 鏀堕泦澶栭敭淇℃伅銆 CPgsqlSchema
findPrimaryKey() 鏀堕泦涓婚敭淇℃伅銆 CPgsqlSchema
findTableNames() 杩斿洖鎵鏈夋暟鎹簱閲岀殑琛ㄥ悕銆 CPgsqlSchema
loadTable() 涓烘寚瀹氳〃杞藉叆鍏冩暟鎹 CPgsqlSchema
resolveTableNames() 鐢熸垚鍚勭琛ㄥ悕銆 CPgsqlSchema

灞炴ц缁

columnTypes 灞炴 锛堝彲鐢ㄨ嚜 v1.1.6锛
public array $columnTypes;

鏄犲皠鍒板疄浣撳垪绫诲瀷鐨勬娊璞″垪绫诲瀷銆

鏂规硶璇︾粏

addColumn() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string addColumn(string $table, string $column, string $type)
$table string 瑕佹坊鍔犳柊鍒楃殑琛ㄣ傝琛ㄥ悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
$column string 鏂板垪鍚嶃傝鍒楀悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
$type string 鍒楃被鍨嬨getColumnType鏂规硶浼氳璋冪敤鏉ュ皢铏氭嫙鍒楃被鍨嬶紙鑻ュ瓨鍦級 杞崲涓哄搴旂殑瀹炰綋鍒楃被鍨嬨備换浣曟湭琚瘑鍒负铏氭嫙绫诲瀷鐨勭被鍨嬩細琚繚鐣欏湪鐢熸垚鐨凷QL涓 渚嬪锛屸榮tring鈥欎細琚浆涓衡榲archar(255)鈥欙紝鑰屸榮tring not null鈥欎細琚浆涓衡榲archar(255) not null鈥欍
{return} string 鏀瑰彉鍒楀畾涔夌殑SQL璇彞銆
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#386 (鏄剧ず)
public function addColumn($table$column$type)
{
    
$type=$this->getColumnType($type);
    
$sql='ALTER TABLE ' $this->quoteTableName($table)
        . 
' ADD COLUMN ' $this->quoteColumnName($column) . ' '
        
$this->getColumnType($type);
    return 
$sql;
}

鏋勯犳坊鍔犳柊鍒楃殑SQL璇彞銆

alterColumn() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string alterColumn(string $table, string $column, string $type)
$table string 瑕佹敼鍙樼殑鍒楁墍鍦ㄨ〃銆傝琛ㄥ悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
$column string 瑕佹敼鍙樼殑鍒楀悕銆傝鍒楀悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
$type string 鏂扮殑鍒楃被鍨嬨getColumnType鏂规硶浼氳璋冪敤鏉ュ皢铏氭嫙鍒楃被鍨嬶紙鑻ュ瓨鍦級 杞崲涓哄搴旂殑瀹炰綋鍒楃被鍨嬨備换浣曟湭琚瘑鍒负铏氭嫙绫诲瀷鐨勭被鍨嬩細琚繚鐣欏湪鐢熸垚鐨凷QL涓 渚嬪锛屸榮tring鈥欎細琚浆涓衡榲archar(255)鈥欙紝鑰屸榮tring not null鈥欎細琚浆涓衡榲archar(255) not null鈥欍
{return} string 鏀瑰彉鍒楀畾涔夌殑SQL璇彞銆
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#405 (鏄剧ず)
public function alterColumn($table$column$type)
{
    
$type=$this->getColumnType($type);
    
$sql='ALTER TABLE ' $this->quoteTableName($table) . ' ALTER COLUMN '
        
$this->quoteColumnName($column) . ' TYPE ' $this->getColumnType($type);
    return 
$sql;
}

鏋勯犳敼鍙樺垪瀹氫箟鐨凷QL璇彞銆

checkIntegrity() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1锛
public void checkIntegrity(boolean $check=true, string $schema='')
$check boolean 鏄惁寮鍚畬鏁存ф鏌ャ
$schema string 鍚勮〃schema銆傞粯璁や负绌哄瓧绗︿覆锛屾剰鍛崇潃褰撳墠鎴栭粯璁chema銆
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#87 (鏄剧ず)
public function checkIntegrity($check=true,$schema='')
{
    
$enable=$check 'ENABLE' 'DISABLE';
    
$tableNames=$this->getTableNames($schema);
    
$db=$this->getDbConnection();
    foreach(
$tableNames as $tableName)
    {
        
$tableName='"'.$tableName.'"';
        if(
strpos($tableName,'.')!==false)
            
$tableName=str_replace('.','"."',$tableName);
        
$db->createCommand("ALTER TABLE $tableName $enable TRIGGER ALL")->execute();
    }
}

鍚敤鎴栫鐢ㄥ畬鏁存ф鏌ャ

createColumn() 鏂规硶
protected CDbColumnSchema createColumn(array $column)
$column array 鍒楀厓鏁版嵁
{return} CDbColumnSchema 瑙勮寖鐨勫垪鍏冩暟鎹
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#202 (鏄剧ず)
protected function createColumn($column)
{
    
$c=new CPgsqlColumnSchema;
    
$c->name=$column['attname'];
    
$c->rawName=$this->quoteColumnName($c->name);
    
$c->allowNull=!$column['attnotnull'];
    
$c->isPrimaryKey=false;
    
$c->isForeignKey=false;

    
$c->init($column['type'],$column['atthasdef'] ? $column['adsrc'] : null);

    return 
$c;
}

鍒涘缓涓涓垪銆

dropIndex() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string dropIndex(string $name, string $table)
$name string 瑕佸垹闄ょ殑绱㈠紩鍚嶃傝绱㈠紩鍚嶄細琚寚瀹氭柟娉曟纭紩鐢ㄣ
$table string 瑕佸垹闄ょ殑绱㈠紩鎵鍦ㄨ〃銆傝琛ㄥ悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
{return} string 鍒犻櫎绱㈠紩鐨凷QL璇彞銆
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#420 (鏄剧ず)
public function dropIndex($name$table)
{
    return 
'DROP INDEX '.$this->quoteTableName($name);
}

鏋勯犲垹闄ょ储寮曠殑SQL璇彞銆

findColumns() 鏂规硶
protected boolean findColumns(CPgsqlTableSchema $table)
$table CPgsqlTableSchema 琛ㄥ厓鏁版嵁
{return} boolean 琛ㄦ槸鍚﹀瓨鍦ㄤ簬鏁版嵁搴撻噷
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#163 (鏄剧ず)
protected function findColumns($table)
{
    
$sql=<<<EOD
SELECT a.attname, LOWER(format_type(a.atttypid, a.atttypmod)) AS type, d.adsrc, a.attnotnull, a.atthasdef
FROM pg_attribute a LEFT JOIN pg_attrdef d ON a.attrelid = d.adrelid AND a.attnum = d.adnum
WHERE a.attnum > 0 AND NOT a.attisdropped
AND a.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname=:table
    AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname = :schema))
ORDER BY a.attnum
EOD;
    
$command=$this->getDbConnection()->createCommand($sql);
    
$command->bindValue(':table',$table->name);
    
$command->bindValue(':schema',$table->schemaName);

    if((
$columns=$command->queryAll())===array())
        return 
false;

    foreach(
$columns as $column)
    {
        
$c=$this->createColumn($column);
        
$table->columns[$c->name]=$c;

        if(
stripos($column['adsrc'],'nextval')===&& preg_match('/nextval\([^\']*\'([^\']+)\'[^\)]*\)/i',$column['adsrc'],$matches))
        {
            if(
strpos($matches[1],'.')!==false || $table->schemaName===self::DEFAULT_SCHEMA)
                
$this->_sequences[$table->rawName.'.'.$c->name]=$matches[1];
            else
                
$this->_sequences[$table->rawName.'.'.$c->name]=$table->schemaName.'.'.$matches[1];
            
$c->autoIncrement=true;
        }
    }
    return 
true;
}

鏀堕泦鍒楃殑鍏冩暟鎹

findConstraints() 鏂规硶
protected void findConstraints(CPgsqlTableSchema $table)
$table CPgsqlTableSchema 琛ㄥ厓鏁版嵁
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#220 (鏄剧ず)
protected function findConstraints($table)
{
    
$sql=<<<EOD
SELECT conname, consrc, contype, indkey FROM (
SELECT
    conname,
    CASE WHEN contype='f' THEN
        pg_catalog.pg_get_constraintdef(oid)
    ELSE
        'CHECK (' || consrc || ')'
    END AS consrc,
    contype,
    conrelid AS relid,
    NULL AS indkey
FROM
    pg_catalog.pg_constraint
WHERE
    contype IN ('f', 'c')
UNION ALL
SELECT
    pc.relname,
    NULL,
    CASE WHEN indisprimary THEN
            'p'
    ELSE
            'u'
    END,
    pi.indrelid,
    indkey
FROM
    pg_catalog.pg_class pc,
    pg_catalog.pg_index pi
WHERE
    pc.oid=pi.indexrelid
    AND EXISTS (
        SELECT 1 FROM pg_catalog.pg_depend d JOIN pg_catalog.pg_constraint c
        ON (d.refclassid = c.tableoid AND d.refobjid = c.oid)
        WHERE d.classid = pc.tableoid AND d.objid = pc.oid AND d.deptype = 'i' AND c.contype IN ('u', 'p')
)
) AS sub
WHERE relid = (SELECT oid FROM pg_catalog.pg_class WHERE relname=:table
AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace
WHERE nspname=:schema))
EOD;
    
$command=$this->getDbConnection()->createCommand($sql);
    
$command->bindValue(':table',$table->name);
    
$command->bindValue(':schema',$table->schemaName);
    foreach(
$command->queryAll() as $row)
    {
        if(
$row['contype']==='p'// primary key
            
$this->findPrimaryKey($table,$row['indkey']);
        else if(
$row['contype']==='f'// foreign key
            
$this->findForeignKey($table,$row['consrc']);
    }
}

鏀堕泦缁欏畾琛ㄤ富閿垪鍜屽閿垪鐨勮缁嗕俊鎭

findForeignKey() 鏂规硶
protected void findForeignKey(CPgsqlTableSchema $table, string $src)
$table CPgsqlTableSchema 琛ㄥ厓鏁版嵁
$src string pgsql澶栭敭瀹氫箟
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#317 (鏄剧ず)
protected function findForeignKey($table,$src)
{
    
$matches=array();
    
$brackets='\(([^\)]+)\)';
    
$pattern="/FOREIGN\s+KEY\s+{$brackets}\s+REFERENCES\s+([^\(]+){$brackets}/i";
    if(
preg_match($pattern,str_replace('"','',$src),$matches))
    {
        
$keys=preg_split('/,\s+/'$matches[1]);
        
$tableName=$matches[2];
        
$fkeys=preg_split('/,\s+/'$matches[3]);
        foreach(
$keys as $i=>$key)
        {
            
$table->foreignKeys[$key]=array($tableName,$fkeys[$i]);
            if(isset(
$table->columns[$key]))
                
$table->columns[$key]->isForeignKey=true;
        }
    }
}

鏀堕泦澶栭敭淇℃伅銆

findPrimaryKey() 鏂规硶
protected void findPrimaryKey(CPgsqlTableSchema $table, string $indices)
$table CPgsqlTableSchema 琛ㄥ厓鏁版嵁
$indices string pgsql涓婚敭绱㈠紩鍒楄〃
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#281 (鏄剧ず)
protected function findPrimaryKey($table,$indices)
{
    
$indices=implode(', ',preg_split('/\s+/',$indices));
    
$sql=<<<EOD
SELECT attnum, attname FROM pg_catalog.pg_attribute WHERE
attrelid=(
    SELECT oid FROM pg_catalog.pg_class WHERE relname=:table AND relnamespace=(
        SELECT oid FROM pg_catalog.pg_namespace WHERE nspname=:schema
    )
)
AND attnum IN (
{$indices})
EOD;
    
$command=$this->getDbConnection()->createCommand($sql);
    
$command->bindValue(':table',$table->name);
    
$command->bindValue(':schema',$table->schemaName);
    foreach(
$command->queryAll() as $row)
    {
        
$name=$row['attname'];
        if(isset(
$table->columns[$name]))
        {
            
$table->columns[$name]->isPrimaryKey=true;
            if(
$table->primaryKey===null)
                
$table->primaryKey=$name;
            else if(
is_string($table->primaryKey))
                
$table->primaryKey=array($table->primaryKey,$name);
            else
                
$table->primaryKey[]=$name;
        }
    }
}

鏀堕泦涓婚敭淇℃伅銆

findTableNames() 鏂规硶
protected array findTableNames(string $schema='')
$schema string 琛╯chema銆傞粯璁ゆ槸绌哄瓧绗︿覆锛屾剰鍛崇潃褰撳墠鎴栭粯璁chema銆 鑻ヤ负绌猴紝鍒欒繑鍥炵殑琛ㄥ悕浼氳鍔犱笂schema鍚嶅墠缂銆
{return} array 鏁版嵁搴撻噷鐨勬墍鏈夎〃鍚嶃
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#342 (鏄剧ず)
protected function findTableNames($schema='')
{
    if(
$schema==='')
        
$schema=self::DEFAULT_SCHEMA;
    
$sql=<<<EOD
SELECT table_name, table_schema FROM information_schema.tables
WHERE table_schema=:schema AND table_type='BASE TABLE'
EOD;
    
$command=$this->getDbConnection()->createCommand($sql);
    
$command->bindParam(':schema',$schema);
    
$rows=$command->queryAll();
    
$names=array();
    foreach(
$rows as $row)
    {
        if(
$schema===self::DEFAULT_SCHEMA)
            
$names[]=$row['table_name'];
        else
            
$names[]=$row['table_schema'].'.'.$row['table_name'];
    }
    return 
$names;
}

杩斿洖鎵鏈夋暟鎹簱閲岀殑琛ㄥ悕銆

loadTable() 鏂规硶
protected CDbTableSchema loadTable(string $name)
$name string 琛ㄥ悕
{return} CDbTableSchema 鍙栧喅浜庤〃鍏冩暟鎹殑椹卞姩銆
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#106 (鏄剧ず)
protected function loadTable($name)
{
    
$table=new CPgsqlTableSchema;
    
$this->resolveTableNames($table,$name);
    if(!
$this->findColumns($table))
        return 
null;
    
$this->findConstraints($table);

    if(
is_string($table->primaryKey) && isset($this->_sequences[$table->rawName.'.'.$table->primaryKey]))
        
$table->sequenceName=$this->_sequences[$table->rawName.'.'.$table->primaryKey];
    else if(
is_array($table->primaryKey))
    {
        foreach(
$table->primaryKey as $pk)
        {
            if(isset(
$this->_sequences[$table->rawName.'.'.$pk]))
            {
                
$table->sequenceName=$this->_sequences[$table->rawName.'.'.$pk];
                break;
            }
        }
    }

    return 
$table;
}

涓烘寚瀹氳〃杞藉叆鍏冩暟鎹

quoteSimpleTableName() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string quoteSimpleTableName(string $name)
$name string 琛ㄥ悕
{return} string 姝g‘寮曠敤鐨勮〃鍚
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#52 (鏄剧ず)
public function quoteSimpleTableName($name)
{
    return 
'"'.$name.'"';
}

鐢ㄥ紩鍙峰紩鐢ㄨ〃鍚嶄互渚挎煡璇㈡椂浣跨敤銆 涓涓笉鍖呮嫭鍓嶇紑鐨勭畝鍗曡〃鍚嶃

renameTable() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string renameTable(string $table, string $newName)
$table string 瑕侀噸鍛藉悕鐨勮〃銆傝琛ㄥ悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
$newName string 鏂拌〃鍚嶃 璇ヨ〃鍚嶄細琚寚瀹氭柟娉曟纭紩鐢ㄣ
{return} string 閲嶅懡鍚嶆暟鎹〃鐨凷QL璇彞銆
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#371 (鏄剧ず)
public function renameTable($table$newName)
{
    return 
'ALTER TABLE ' $this->quoteTableName($table) . ' RENAME TO ' $this->quoteTableName($newName);
}

鏋勯犻噸鍛藉悕鏁版嵁琛ㄧ殑SQL璇彞銆

resetSequence() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1锛
public void resetSequence(CDbTableSchema $table, mixed $value=NULL)
$table CDbTableSchema 瑕侀噸缃富閿簭鍒楃殑琛╯chema
$value mixed 鏂版彃鍏ヨ鐨勪富閿笺傚鏋滄湭璁剧疆锛 鍒欐柊琛屼富閿间负1銆
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#66 (鏄剧ず)
public function resetSequence($table,$value=null)
{
    if(
$table->sequenceName!==null)
    {
        
$seq='"'.$table->sequenceName.'"';
        if(
strpos($seq,'.')!==false)
            
$seq=str_replace('.','"."',$seq);
        if(
$value===null)
            
$value="(SELECT COALESCE(MAX(\"{$table->primaryKey}\"),0) FROM {$table->rawName}) + 1";
        else
            
$value=(int)$value;
        
$this->getDbConnection()->createCommand("SELECT SETVAL('$seq', $value, false)")->execute();
    }
}

閲嶇疆琛ㄧ殑涓婚敭鐨勫簭鍒楀笺 搴忓垪浼氳鍏呭硷紝杩欐牱涓鏉ワ紝鏂版彃鍏ヨ鐨勪富閿 灏嗕細鏄寚瀹氬兼垨鑰1銆

resolveTableNames() 鏂规硶
protected void resolveTableNames(CPgsqlTableSchema $table, string $name)
$table CPgsqlTableSchema 琛ㄥ厓鏁版嵁
$name string 鏈紩鐢ㄧ殑琛ㄥ悕
婧愮爜锛 framework/db/schema/pgsql/CPgsqlSchema.php#136 (鏄剧ず)
protected function resolveTableNames($table,$name)
{
    
$parts=explode('.',str_replace('"','',$name));
    if(isset(
$parts[1]))
    {
        
$schemaName=$parts[0];
        
$tableName=$parts[1];
    }
    else
    {
        
$schemaName=self::DEFAULT_SCHEMA;
        
$tableName=$parts[0];
    }

    
$table->name=$tableName;
    
$table->schemaName=$schemaName;
    if(
$schemaName===self::DEFAULT_SCHEMA)
        
$table->rawName=$this->quoteTableName($tableName);
    else
        
$table->rawName=$this->quoteTableName($schemaName).'.'.$this->quoteTableName($tableName);
}

鐢熸垚鍚勭琛ㄥ悕銆

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.