Yii Framework v1.1.10 绫诲弬鑰

CSqliteSchema

system.db.schema.sqlite
缁ф壙 class CSqliteSchema » CDbSchema » CComponent
婧愯嚜 1.0
鐗堟湰 $Id: CSqliteSchema.php 3515 2011-12-28 12:29:24Z mdomba $
婧愮爜 framework/db/schema/sqlite/CSqliteSchema.php
CSqliteSchema鏄粠SQLite锛2/3锛夋暟鎹簱妫绱㈠厓鏁版嵁淇℃伅鐨勭被銆

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
columnTypes array 鏄犲皠鍒板疄浣撳垪绫诲瀷鐨勬娊璞″垪绫诲瀷銆 CSqliteSchema
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() Builds a SQL statement for adding a new DB column. CDbSchema
addForeignKey() 鏋勯犲線鏌愪釜瀛樺湪鐨勮〃娣诲姞澶栭敭绾︽潫鐨凷QL璇彞銆 CSqliteSchema
alterColumn() 鏋勯犳敼鍙樺垪瀹氫箟鐨凷QL璇彞銆 CSqliteSchema
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
checkIntegrity() 鍚敤鎴栫鐢ㄥ畬鏁存ф鏌ャ CSqliteSchema
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() 鏋勯犲垹闄ゅ垪鐨凷QL璇彞銆 CSqliteSchema
dropForeignKey() 鏋勯犲垹闄ゅ閿害鏉熺殑SQL璇彞銆 CSqliteSchema
dropIndex() 鏋勯犲垹闄ょ储寮曠殑SQL璇彞銆 CSqliteSchema
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() Quotes a simple table name for use in a query. CDbSchema
quoteTableName() Quotes a table name for use in a query. CDbSchema
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
refresh() Refreshes the schema. CDbSchema
renameColumn() 鏋勯犻噸鍛藉悕鍒楃殑SQL璇彞銆 CSqliteSchema
renameTable() Builds a SQL statement for renaming a DB table. CDbSchema
resetSequence() 閲嶇疆琛ㄧ殑涓婚敭鐨勫簭鍒楀笺 CSqliteSchema
truncateTable() 鏋勯犳竻绌烘暟鎹〃鐨凷QL璇彞銆 CSqliteSchema

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
createColumn() 鍒涘缓涓涓垪銆 CSqliteSchema
createCommandBuilder() 涓烘暟鎹簱鍒涘缓鍛戒护鏋勯犲櫒銆 CSqliteSchema
findColumns() 鏀堕泦鍒楃殑鍏冩暟鎹 CSqliteSchema
findConstraints() 鏀堕泦缁欏畾琛ㄤ富閿垪鍜屽閿垪鐨勮缁嗕俊鎭 CSqliteSchema
findTableNames() 杩斿洖鎵鏈夋暟鎹簱閲岀殑琛ㄥ悕銆 CSqliteSchema
loadTable() 涓烘寚瀹氳〃杞藉叆鍏冩暟鎹 CSqliteSchema

灞炴ц缁

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

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

鏂规硶璇︾粏

addForeignKey() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string addForeignKey(string $name, string $table, string $columns, string $refTable, string $refColumns, string $delete=NULL, string $update=NULL)
$name string 澶栭敭绾︽潫鍚嶃
$table string 瑕佹坊鍔犲閿害鏉熺殑琛ㄣ
$columns string 瑕佹坊鍔犵害鏉熺殑鍒楀悕銆傝嫢鏈夊涓垪锛屽垯浠ラ楀彿鍒嗛殧銆
$refTable string 澶栭敭娑夊強鐨勮〃銆
$refColumns string 澶栭敭娑夊強鐨勫垪鍚嶃傝嫢鏈夊涓垪锛屽垯浠ラ楀彿鍒嗛殧銆
$delete string ON DELETE閫夐」銆傚ぇ閮ㄥ垎DBMS鏀寔濡備笅閫夐」锛歊ESTRICT銆丆ASCADE銆丯O ACTION銆丼ET DEFAULT銆丼ET NULL銆
$update string ON UPDATE閫夐」銆傚ぇ閮ㄥ垎DBMS鏀寔濡備笅閫夐」锛歊ESTRICT銆丆ASCADE銆丯O ACTION銆丼ET DEFAULT銆丼ET NULL銆
{return} string 寰鏌愪釜瀛樺湪鐨勮〃娣诲姞澶栭敭绾︽潫鐨凷QL璇彞銆
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#242 (鏄剧ず)
public function addForeignKey($name$table$columns$refTable$refColumns$delete=null$update=null)
{
    throw new 
CDbException(Yii::t('yii''Adding a foreign key constraint to an existing table is not supported by SQLite.'));
}

鏋勯犲線鏌愪釜瀛樺湪鐨勮〃娣诲姞澶栭敭绾︽潫鐨凷QL璇彞銆 璋冪敤姝ゆ柟娉曚細鎶涘嚭寮傚父鍥犱负SQLite涓嶆敮鎸佹坊鍔犲閿害鏉熴

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/sqlite/CSqliteSchema.php#271 (鏄剧ず)
public function alterColumn($table$column$type)
{
    throw new 
CDbException(Yii::t('yii''Altering a DB column is not supported by SQLite.'));
}

鏋勯犳敼鍙樺垪瀹氫箟鐨凷QL璇彞銆 璋冪敤姝ゆ柟娉曚細鎶涘嚭寮傚父鍥犱负SQLite涓嶆敮鎸佹敼鍙樺垪銆

checkIntegrity() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1锛
public void checkIntegrity(boolean $check=true, string $schema='')
$check boolean 鏄惁寮鍚畬鏁存ф鏌ャ
$schema string 鍚勮〃schema銆傞粯璁や负绌哄瓧绗︿覆锛屾剰鍛崇潃褰撳墠鎴栭粯璁chema銆
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#75 (鏄剧ず)
public function checkIntegrity($check=true,$schema='')
{
    
// SQLite doesn't enforce integrity
    
return;
}

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

createColumn() 鏂规硶
protected CDbColumnSchema createColumn(array $column)
$column array 鍒楀厓鏁版嵁
{return} CDbColumnSchema 瑙勮寖鐨勫垪鍏冩暟鎹
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#179 (鏄剧ず)
protected function createColumn($column)
{
    
$c=new CSqliteColumnSchema;
    
$c->name=$column['name'];
    
$c->rawName=$this->quoteColumnName($c->name);
    
$c->allowNull=!$column['notnull'];
    
$c->isPrimaryKey=$column['pk']!=0;
    
$c->isForeignKey=false;
    
$c->init(strtolower($column['type']),$column['dflt_value']);
    return 
$c;
}

鍒涘缓涓涓垪銆

createCommandBuilder() 鏂规硶
protected CSqliteCommandBuilder createCommandBuilder()
{return} CSqliteCommandBuilder 鍛戒护鏋勯犲櫒瀹炰緥
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#96 (鏄剧ず)
protected function createCommandBuilder()
{
    return new 
CSqliteCommandBuilder($this);
}

涓烘暟鎹簱鍒涘缓鍛戒护鏋勯犲櫒銆

dropColumn() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string dropColumn(string $table, string $column)
$table string 瑕佸垹闄ょ殑鍒楁墍鍦ㄨ〃銆傝琛ㄥ悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
$column string 瑕佸垹闄ょ殑鍒椼傝鍒楀悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
{return} string 鍒犻櫎鍒楃殑SQL璇彞銆
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#210 (鏄剧ず)
public function dropColumn($table$column)
{
    throw new 
CDbException(Yii::t('yii''Dropping DB column is not supported by SQLite.'));
}

鏋勯犲垹闄ゅ垪鐨凷QL璇彞銆 璋冪敤姝ゆ柟娉曚細鎶涘嚭寮傚父鍥犱负SQLite涓嶆敮鎸佸垹闄ゅ垪銆

dropForeignKey() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string dropForeignKey(string $name, string $table)
$name string 瑕佸垹闄ょ殑澶栭敭绾︽潫鍚嶃傝閿悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
$table string 瑕佸垹闄ょ殑澶栭敭绾︽潫鎵鍦ㄨ〃銆傝琛ㄥ悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
{return} string 鍒犻櫎澶栭敭绾︽潫鐨凷QL璇彞銆
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#255 (鏄剧ず)
public function dropForeignKey($name$table)
{
    throw new 
CDbException(Yii::t('yii''Dropping a foreign key constraint is not supported by SQLite.'));
}

鏋勯犲垹闄ゅ閿害鏉熺殑SQL璇彞銆 璋冪敤姝ゆ柟娉曚細鎶涘嚭寮傚父鍥犱负SQLite涓嶆敮鎸佸垹闄ゅ閿害鏉熴

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

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

findColumns() 鏂规硶
protected boolean findColumns(CDbTableSchema $table)
$table CDbTableSchema 琛ㄥ厓鏁版嵁
{return} boolean 琛ㄦ槸鍚﹀瓨鍦ㄤ簬鏁版嵁搴撻噷
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#126 (鏄剧ず)
protected function findColumns($table)
{
    
$sql="PRAGMA table_info({$table->rawName})";
    
$columns=$this->getDbConnection()->createCommand($sql)->queryAll();
    if(empty(
$columns))
        return 
false;

    foreach(
$columns as $column)
    {
        
$c=$this->createColumn($column);
        
$table->columns[$c->name]=$c;
        if(
$c->isPrimaryKey)
        {
            if(
$table->primaryKey===null)
                
$table->primaryKey=$c->name;
            else if(
is_string($table->primaryKey))
                
$table->primaryKey=array($table->primaryKey,$c->name);
            else
                
$table->primaryKey[]=$c->name;
        }
    }
    if(
is_string($table->primaryKey) && !strncasecmp($table->columns[$table->primaryKey]->dbType,'int',3))
    {
        
$table->sequenceName='';
        
$table->columns[$table->primaryKey]->autoIncrement=true;
    }

    return 
true;
}

鏀堕泦鍒楃殑鍏冩暟鎹

findConstraints() 鏂规硶
protected void findConstraints(CDbTableSchema $table)
$table CDbTableSchema 琛ㄥ厓鏁版嵁
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#160 (鏄剧ず)
protected function findConstraints($table)
{
    
$foreignKeys=array();
    
$sql="PRAGMA foreign_key_list({$table->rawName})";
    
$keys=$this->getDbConnection()->createCommand($sql)->queryAll();
    foreach(
$keys as $key)
    {
        
$column=$table->columns[$key['from']];
        
$column->isForeignKey=true;
        
$foreignKeys[$key['from']]=array($key['table'],$key['to']);
    }
    
$table->foreignKeys=$foreignKeys;
}

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

findTableNames() 鏂规硶
protected array findTableNames(string $schema='')
$schema string 琛╯chema銆傝繖骞朵笉琚玈QLite鏁版嵁搴撲娇鐢ㄣ
{return} array 鏁版嵁搴撻噷鐨勬墍鏈夎〃鍚嶃
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#86 (鏄剧ず)
protected function findTableNames($schema='')
{
    
$sql="SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'";
    return 
$this->getDbConnection()->createCommand($sql)->queryColumn();
}

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

loadTable() 鏂规硶
protected CDbTableSchema loadTable(string $name)
$name string 琛ㄥ悕
{return} CDbTableSchema 鍙栧喅浜庤〃鍏冩暟鎹殑椹卞姩銆傝嫢琛ㄤ笉瀛樺湪鍒欒繑鍥瀗ull銆
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#106 (鏄剧ず)
protected function loadTable($name)
{
    
$table=new CDbTableSchema;
    
$table->name=$name;
    
$table->rawName=$this->quoteTableName($name);

    if(
$this->findColumns($table))
    {
        
$this->findConstraints($table);
        return 
$table;
    }
    else
        return 
null;
}

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

renameColumn() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string renameColumn(string $table, string $name, string $newName)
$table string 瑕侀噸鍛藉悕鐨勫垪鎵鍦ㄨ〃銆傝琛ㄥ悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
$name string 鍘熸湁鍒楀悕銆傝鍒楀悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
$newName string 鏂板垪鍚嶃傝鍒楀悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
{return} string 閲嶅懡鍚嶅垪鐨凷QL璇彞銆
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#224 (鏄剧ず)
public function renameColumn($table$name$newName)
{
    throw new 
CDbException(Yii::t('yii''Renaming a DB column is not supported by SQLite.'));
}

鏋勯犻噸鍛藉悕鍒楃殑SQL璇彞銆 璋冪敤姝ゆ柟娉曚細鎶涘嚭寮傚父鍥犱负SQLite涓嶆敮鎸侀噸鍛藉悕鍒椼

resetSequence() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1锛
public void resetSequence(CDbTableSchema $table, mixed $value=NULL)
$table CDbTableSchema 瑕侀噸缃富閿簭鍒楃殑琛╯chema
$value mixed 鏂版彃鍏ヨ鐨勪富閿笺傚鏋滄湭璁剧疆锛 鍒欐柊琛屼富閿间负1銆
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#50 (鏄剧ず)
public function resetSequence($table,$value=null)
{
    if(
$table->sequenceName!==null)
    {
        if(
$value===null)
            
$value=$this->getDbConnection()->createCommand("SELECT MAX(`{$table->primaryKey}`) FROM {$table->rawName}")->queryScalar();
        else
            
$value=(int)$value-1;
        try
        {
            
// it's possible sqlite_sequence does not exist
            
$this->getDbConnection()->createCommand("UPDATE sqlite_sequence SET seq='$value' WHERE name='{$table->name}'")->execute();
        }
        catch(
Exception $e)
        {
        }
    }
}

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

truncateTable() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.6锛
public string truncateTable(string $table)
$table string 瑕佹竻绌虹殑琛ㄣ傝琛ㄥ悕浼氳鎸囧畾鏂规硶姝g‘寮曠敤銆
{return} string 娓呯┖鏁版嵁琛ㄧ殑SQL璇彞銆
婧愮爜锛 framework/db/schema/sqlite/CSqliteSchema.php#197 (鏄剧ず)
public function truncateTable($table)
{
    return 
"DELETE FROM ".$this->quoteTableName($table);
}

鏋勯犳竻绌烘暟鎹〃鐨凷QL璇彞銆

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