CSqliteSchema

优质
小牛编辑
127浏览
2023-12-01
所有包 | 属性 | 方法
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)数据库检索元数据信息的类。

公共属性

隐藏继承属性

属性类型描述定义在
columnTypesarray映射到实体列类型的抽象列类型。CSqliteSchema
commandBuilderCDbCommandBuilderthe SQL command builder for this connection.CDbSchema
dbConnectionCDbConnectiondatabase connection.CDbSchema
tableNamesarrayReturns all table names in the database.CDbSchema
tablesarrayReturns 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()构造往某个存在的表添加外键约束的SQL语句。CSqliteSchema
alterColumn()构造改变列定义的SQL语句。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()构造删除列的SQL语句。CSqliteSchema
dropForeignKey()构造删除外键约束的SQL语句。CSqliteSchema
dropIndex()构造删除索引的SQL语句。CSqliteSchema
dropTable()Builds a SQL statement for dropping a DB table.CDbSchema
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。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()构造清空数据表的SQL语句。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)
$namestring外键约束名。
$tablestring要添加外键约束的表。
$columnsstring要添加约束的列名。若有多个列,则以逗号分隔。
$refTablestring外键涉及的表。
$refColumnsstring外键涉及的列名。若有多个列,则以逗号分隔。
$deletestringON DELETE选项。大部分DBMS支持如下选项:RESTRICT、CASCADE、NO ACTION、SET DEFAULT、SET NULL。
$updatestringON UPDATE选项。大部分DBMS支持如下选项:RESTRICT、CASCADE、NO ACTION、SET DEFAULT、SET NULL。
{return}string往某个存在的表添加外键约束的SQL语句。
源码: framework/db/schema/sqlite/CSqliteSchema.php#242 (显示) publicfunctionaddForeignKey($name,$table,$columns,$refTable,$refColumns,$delete=null,$update=null)
{
thrownewCDbException(Yii::t('yii','AddingaforeignkeyconstrainttoanexistingtableisnotsupportedbySQLite.'));
}

构造往某个存在的表添加外键约束的SQL语句。 调用此方法会抛出异常因为SQLite不支持添加外键约束。

alterColumn() 方法 (可用自 v1.1.6)
public string alterColumn(string $table, string $column, string $type)
$tablestring要改变的列所在表。该表名会被指定方法正确引用。
$columnstring要改变的列名。该列名会被指定方法正确引用。
$typestring新的列类型。getColumnType方法会被调用来将虚拟列类型(若存在) 转换为对应的实体列类型。任何未被识别为虚拟类型的类型会被保留在生成的SQL中。 例如,‘string’会被转为‘varchar(255)’,而‘string not null’会被转为‘varchar(255) not null’。
{return}string改变列定义的SQL语句。
源码: framework/db/schema/sqlite/CSqliteSchema.php#271 (显示) publicfunctionalterColumn($table,$column,$type)
{
thrownewCDbException(Yii::t('yii','AlteringaDBcolumnisnotsupportedbySQLite.'));
}

构造改变列定义的SQL语句。 调用此方法会抛出异常因为SQLite不支持改变列。

checkIntegrity() 方法 (可用自 v1.1)
public void checkIntegrity(boolean $check=true, string $schema='')
$checkboolean是否开启完整性检查。
$schemastring各表schema。默认为空字符串,意味着当前或默认schema。
源码: framework/db/schema/sqlite/CSqliteSchema.php#75 (显示) publicfunctioncheckIntegrity($check=true,$schema='')
{
//SQLitedoesn'tenforceintegrity
return;
}

启用或禁用完整性检查。

createColumn() 方法
protected CDbColumnSchema createColumn(array $column)
$columnarray列元数据
{return}CDbColumnSchema规范的列元数据
源码: framework/db/schema/sqlite/CSqliteSchema.php#179 (显示) protectedfunctioncreateColumn($column)
{
$c=newCSqliteColumnSchema;
$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 (显示) protectedfunctioncreateCommandBuilder()
{
returnnewCSqliteCommandBuilder($this);
}

为数据库创建命令构造器。

dropColumn() 方法 (可用自 v1.1.6)
public string dropColumn(string $table, string $column)
$tablestring要删除的列所在表。该表名会被指定方法正确引用。
$columnstring要删除的列。该列名会被指定方法正确引用。
{return}string删除列的SQL语句。
源码: framework/db/schema/sqlite/CSqliteSchema.php#210 (显示) publicfunctiondropColumn($table,$column)
{
thrownewCDbException(Yii::t('yii','DroppingDBcolumnisnotsupportedbySQLite.'));
}

构造删除列的SQL语句。 调用此方法会抛出异常因为SQLite不支持删除列。

dropForeignKey() 方法 (可用自 v1.1.6)
public string dropForeignKey(string $name, string $table)
$namestring要删除的外键约束名。该键名会被指定方法正确引用。
$tablestring要删除的外键约束所在表。该表名会被指定方法正确引用。
{return}string删除外键约束的SQL语句。
源码: framework/db/schema/sqlite/CSqliteSchema.php#255 (显示) publicfunctiondropForeignKey($name,$table)
{
thrownewCDbException(Yii::t('yii','DroppingaforeignkeyconstraintisnotsupportedbySQLite.'));
}

构造删除外键约束的SQL语句。 调用此方法会抛出异常因为SQLite不支持删除外键约束。

dropIndex() 方法 (可用自 v1.1.6)
public string dropIndex(string $name, string $table)
$namestring要删除的索引名。该索引名会被指定方法正确引用。
$tablestring要删除的索引所在表。该表名会被指定方法正确引用。
{return}string删除索引的SQL语句。
源码: framework/db/schema/sqlite/CSqliteSchema.php#283 (显示) publicfunctiondropIndex($name,$table)
{
return'DROPINDEX'.$this->quoteTableName($name);
}

构造删除索引的SQL语句。

findColumns() 方法
protected boolean findColumns(CDbTableSchema $table)
$tableCDbTableSchema表元数据
{return}boolean表是否存在于数据库里
源码: framework/db/schema/sqlite/CSqliteSchema.php#126 (显示) protectedfunctionfindColumns($table)
{
$sql="PRAGMAtable_info({$table->rawName})";
$columns=$this->getDbConnection()->createCommand($sql)->queryAll();
if(empty($columns))
returnfalse;

foreach($columnsas$column)
{
$c=$this->createColumn($column);
$table->columns[$c->name]=$c;
if($c->isPrimaryKey)
{
if($table->primaryKey===null)
$table->primaryKey=$c->name;
elseif(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;
}

returntrue;
}

收集列的元数据。

findConstraints() 方法
protected void findConstraints(CDbTableSchema $table)
$tableCDbTableSchema表元数据
源码: framework/db/schema/sqlite/CSqliteSchema.php#160 (显示) protectedfunctionfindConstraints($table)
{
$foreignKeys=array();
$sql="PRAGMAforeign_key_list({$table->rawName})";
$keys=$this->getDbConnection()->createCommand($sql)->queryAll();
foreach($keysas$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='')
$schemastring表schema。这并不被SQLite数据库使用。
{return}array数据库里的所有表名。
源码: framework/db/schema/sqlite/CSqliteSchema.php#86 (显示) protectedfunctionfindTableNames($schema='')
{
$sql="SELECTDISTINCTtbl_nameFROMsqlite_masterWHEREtbl_name<>'sqlite_sequence'";
return$this->getDbConnection()->createCommand($sql)->queryColumn();
}

返回所有数据库里的表名。

loadTable() 方法
protected CDbTableSchema loadTable(string $name)
$namestring表名
{return}CDbTableSchema取决于表元数据的驱动。若表不存在则返回null。
源码: framework/db/schema/sqlite/CSqliteSchema.php#106 (显示) protectedfunctionloadTable($name)
{
$table=newCDbTableSchema;
$table->name=$name;
$table->rawName=$this->quoteTableName($name);

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

为指定表载入元数据。

renameColumn() 方法 (可用自 v1.1.6)
public string renameColumn(string $table, string $name, string $newName)
$tablestring要重命名的列所在表。该表名会被指定方法正确引用。
$namestring原有列名。该列名会被指定方法正确引用。
$newNamestring新列名。该列名会被指定方法正确引用。
{return}string重命名列的SQL语句。
源码: framework/db/schema/sqlite/CSqliteSchema.php#224 (显示) publicfunctionrenameColumn($table,$name,$newName)
{
thrownewCDbException(Yii::t('yii','RenamingaDBcolumnisnotsupportedbySQLite.'));
}

构造重命名列的SQL语句。 调用此方法会抛出异常因为SQLite不支持重命名列。

resetSequence() 方法 (可用自 v1.1)
public void resetSequence(CDbTableSchema $table, mixed $value=NULL)
$tableCDbTableSchema要重置主键序列的表schema
$valuemixed新插入行的主键值。如果未设置, 则新行主键值为1。
源码: framework/db/schema/sqlite/CSqliteSchema.php#50 (显示) publicfunctionresetSequence($table,$value=null)
{
if($table->sequenceName!==null)
{
if($value===null)
$value=$this->getDbConnection()->createCommand("SELECTMAX(`{$table->primaryKey}`)FROM{$table->rawName}")->queryScalar();
else
$value=(int)$value-1;
try
{
//it'spossiblesqlite_sequencedoesnotexist
$this->getDbConnection()->createCommand("UPDATEsqlite_sequenceSETseq='$value'WHEREname='{$table->name}'")->execute();
}
catch(Exception$e)
{
}
}
}

重置表的主键的序列值。 序列会被充值,这样一来,新插入行的主键值 将会是指定值或者1。

truncateTable() 方法 (可用自 v1.1.6)
public string truncateTable(string $table)
$tablestring要清空的表。该表名会被指定方法正确引用。
{return}string清空数据表的SQL语句。
源码: framework/db/schema/sqlite/CSqliteSchema.php#197 (显示) publicfunctiontruncateTable($table)
{
return"DELETEFROM".$this->quoteTableName($table);
}

构造清空数据表的SQL语句。