Package | system.db.schema.sqlite |
---|---|
Inheritance | class CSqliteSchema » CDbSchema » CComponent |
Since | 1.0 |
Version | $Id$ |
Source Code | framework/db/schema/sqlite/CSqliteSchema.php |
Property | Type | Description | Defined By |
---|---|---|---|
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 |
Method | Description | Defined By |
---|---|---|
__call() | Calls the named method which is not a class method. | CComponent |
__construct() | Constructor. | CDbSchema |
__get() | Returns a property value, an event handler list or a behavior based on its name. | CComponent |
__isset() | Checks if a property value is null. | CComponent |
__set() | Sets value of a component property. | CComponent |
__unset() | Sets a component property to be null. | CComponent |
asa() | Returns the named behavior object. | CComponent |
attachBehavior() | Attaches a behavior to this component. | CComponent |
attachBehaviors() | Attaches a list of behaviors to the component. | CComponent |
attachEventHandler() | Attaches an event handler to an event. | CComponent |
canGetProperty() | Determines whether a property can be read. | CComponent |
canSetProperty() | Determines whether a property can be set. | CComponent |
compareTableNames() | Compares two table names. | CDbSchema |
detachBehavior() | Detaches a behavior from the component. | CComponent |
detachBehaviors() | Detaches all behaviors from the component. | CComponent |
detachEventHandler() | Detaches an existing event handler. | CComponent |
disableBehavior() | Disables an attached behavior. | CComponent |
disableBehaviors() | Disables all behaviors attached to this component. | CComponent |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
getCommandBuilder() | Returns the SQL command builder for this connection. | CDbSchema |
getDbConnection() | Returns database connection. The connection is active. | CDbSchema |
getEventHandlers() | Returns the list of attached event handlers for an event. | 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() | Determines whether an event is defined. | CComponent |
hasEventHandler() | Checks whether the named event has attached handlers. | CComponent |
hasProperty() | Determines whether a property is defined. | CComponent |
quoteColumnName() | Quotes a column name for use in a query. | CDbSchema |
quoteTableName() | Quotes a table name for use in a query. | CDbSchema |
raiseEvent() | Raises an event. | CComponent |
refresh() | Refreshes the schema. | CDbSchema |
Method | Description | Defined By |
---|---|---|
createColumn() | Creates a table column. | CSqliteSchema |
createCommandBuilder() | Creates a command builder for the database. | CSqliteSchema |
createTable() | Creates a table instance representing the metadata for the named table. | CSqliteSchema |
findColumns() | Collects the table column metadata. | CSqliteSchema |
findConstraints() | Collects the foreign key column details for the given table. | CSqliteSchema |
findTableNames() | Returns all table names in the database. | CSqliteSchema |
protected CDbColumnSchema createColumn(array $column)
| ||
$column | array | column metadata |
{return} | CDbColumnSchema | normalized column metadata |
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;
}
Creates a table column.
protected CSqliteCommandBuilder createCommandBuilder()
| ||
{return} | CSqliteCommandBuilder | command builder instance |
protected function createCommandBuilder()
{
return new CSqliteCommandBuilder($this);
}
Creates a command builder for the database.
protected CDbTableSchema createTable($name)
| ||
$name | ||
{return} | CDbTableSchema | driver dependent table metadata. Null if the table does not exist. |
protected function createTable($name)
{
$db=$this->getDbConnection();
$table=new CDbTableSchema;
$table->name=$name;
$table->rawName=$this->quoteTableName($name);
if($this->findColumns($table))
{
$this->findConstraints($table);
return $table;
}
else
return null;
}
Creates a table instance representing the metadata for the named table.
protected boolean findColumns(CDbTableSchema $table)
| ||
$table | CDbTableSchema | the table metadata |
{return} | boolean | whether the table exists in the database |
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='';
return true;
}
Collects the table column metadata.
protected void findConstraints(CDbTableSchema $table)
| ||
$table | CDbTableSchema | the table metadata |
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;
}
Collects the foreign key column details for the given table.
protected array findTableNames(string $schema='')
| ||
$schema | string | the schema of the tables. This is not used for sqlite database. |
{return} | array | all table names in the database. |
protected function findTableNames($schema='')
{
$sql="SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence'";
return $this->getDbConnection()->createCommand($sql)->queryColumn();
}
Returns all table names in the database.
Signup or Login in order to comment.