CCubridSchema
Package | system.db.schema.cubrid |
---|---|
Inheritance | class CCubridSchema » CDbSchema » CComponent |
Since | 1.1.16 |
Source Code | framework/db/schema/cubrid/CCubridSchema.php |
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
columnTypes | CCubridSchema | ||
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 |
Protected Properties
Property | Type | Description | Defined By |
---|---|---|---|
serverVersion | float | server version. | CCubridSchema |
Public Methods
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 |
addColumn() | Builds a SQL statement for adding a new DB column. | CDbSchema |
addForeignKey() | Builds a SQL statement for adding a foreign key constraint to an existing table. | CDbSchema |
addPrimaryKey() | Builds a SQL statement for adding a primary key constraint to an existing table. | CDbSchema |
alterColumn() | Builds a SQL statement for changing the definition of a column. | CDbSchema |
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 |
checkIntegrity() | Enables or disables integrity check. | CDbSchema |
compareTableNames() | Compares two table names. | CCubridSchema |
createIndex() | Builds a SQL statement for creating a new index. | CDbSchema |
createTable() | Builds a SQL statement for creating a new DB table. | 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 |
dropColumn() | Builds a SQL statement for dropping a DB column. | CDbSchema |
dropForeignKey() | Builds a SQL statement for dropping a foreign key constraint. | CDbSchema |
dropIndex() | Builds a SQL statement for dropping an index. | CDbSchema |
dropPrimaryKey() | Builds a SQL statement for removing a primary key constraint to an existing table. | CDbSchema |
dropTable() | Builds a SQL statement for dropping a DB table. | CDbSchema |
enableBehavior() | Enables an attached behavior. | CComponent |
enableBehaviors() | Enables all behaviors attached to this component. | CComponent |
evaluateExpression() | Evaluates a PHP expression or callback under the context of this component. | CComponent |
getColumnType() | Converts an abstract column type into a physical column type. | CDbSchema |
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 |
quoteSimpleColumnName() | Quotes a column name for use in a query. | CCubridSchema |
quoteSimpleTableName() | Quotes a table name for use in a query. | CCubridSchema |
quoteTableName() | Quotes a table name for use in a query. | CDbSchema |
raiseEvent() | Raises an event. | CComponent |
refresh() | Refreshes the schema. | CDbSchema |
renameColumn() | Builds a SQL statement for renaming a column. | CDbSchema |
renameTable() | Builds a SQL statement for renaming a DB table. | CDbSchema |
resetSequence() | Resets the sequence value of a table's primary key. | CCubridSchema |
truncateTable() | Builds a SQL statement for truncating a DB table. | CDbSchema |
Protected Methods
Method | Description | Defined By |
---|---|---|
createColumn() | Creates a table column. | CCubridSchema |
createCommandBuilder() | Creates a command builder for the database. | CDbSchema |
findColumns() | Collects the table column metadata. | CCubridSchema |
findConstraints() | Collects the foreign key column details for the given table. | CCubridSchema |
findPrimaryKeys() | Collects the primary key column details for the given table. | CCubridSchema |
findTableNames() | Returns all table names in the database. | CCubridSchema |
getServerVersion() | Returns server version. | CCubridSchema |
loadTable() | Creates a table instance representing the metadata for the named table. | CCubridSchema |
resolveTableNames() | Generates various kinds of table names. | CCubridSchema |
Property Details
columnTypes property
public $columnTypes;
serverVersion property read-only
protected float getServerVersion()
server version.
Method Details
compareTableNames() method
public boolean compareTableNames(string $name1, string $name2) | ||
$name1 | string | table name 1 |
$name2 | string | table name 2 |
{return} | boolean | whether the two table names refer to the same table. |
public function compareTableNames($name1,$name2)
{
return parent::compareTableNames(strtolower($name1),strtolower($name2));
}
Compares two table names. The table names can be either quoted or unquoted. This method will consider both cases.
createColumn() method
protected CDbColumnSchema createColumn(array $column) | ||
$column | array | column metadata |
{return} | CDbColumnSchema | normalized column metadata |
protected function createColumn($column)
{
$c=new CCubridColumnSchema;
$c->name=$column['Field'];
$c->rawName=$this->quoteColumnName($c->name);
$c->allowNull=$column['Null']==='YES';
$c->isPrimaryKey=strpos($column['Key'],'PRI')!==false;
$c->isForeignKey=false;
$c->init($column['Type'],$column['Default']);
$c->autoIncrement=strpos(strtolower($column['Extra']),'auto_increment')!==false;
return $c;
}
Creates a table column.
findColumns() method
protected boolean findColumns(CCubridTableSchema $table) | ||
$table | CCubridTableSchema | the table metadata |
{return} | boolean | whether the table exists in the database |
protected function findColumns($table)
{
// it may be good to use CUBRID PHP API to retrieve column info.
$sql='SHOW COLUMNS FROM '.$table->rawName;
try
{
$columns=$this->getDbConnection()->createCommand($sql)->queryAll();
}
catch(Exception $e)
{
return false;
}
foreach($columns as $column)
{
$c=$this->createColumn($column);
$table->columns[$c->name]=$c;
}
return true;
}
Collects the table column metadata.
findConstraints() method
protected void findConstraints(CCubridTableSchema $table) | ||
$table | CCubridTableSchema | the table metadata |
protected function findConstraints($table)
{
$schemas=$this->getDbConnection()->getPdoInstance()->cubrid_schema(PDO::CUBRID_SCH_IMPORTED_KEYS,$table->name);
foreach($schemas as $schema)
{
$table->foreignKeys[$schema["FKCOLUMN_NAME"]]=array($schema["PKTABLE_NAME"],$schema["PKCOLUMN_NAME"]);
if(isset($table->columns[$schema["FKCOLUMN_NAME"]]))
$table->columns[$schema["FKCOLUMN_NAME"]]->isForeignKey=true;
}
}
Collects the foreign key column details for the given table.
findPrimaryKeys() method
protected void findPrimaryKeys(CCubridTableSchema $table) | ||
$table | CCubridTableSchema | the table metadata |
protected function findPrimaryKeys($table)
{
$pks=$this->getDbConnection()->getPdoInstance()->cubrid_schema(PDO::CUBRID_SCH_PRIMARY_KEY,$table->name);
foreach($pks as $pk)
{
$c = $table->columns[$pk['ATTR_NAME']];
$c->isPrimaryKey = true;
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($c->autoIncrement)
$table->sequenceName='';
}
}
Collects the primary key column details for the given table.
findTableNames() method
protected array findTableNames(string $schema='') | ||
$schema | string | the schema of the tables. Defaults to empty string, meaning the current or default schema. If not empty, the returned table names will be prefixed with the schema name. |
{return} | array | all table names in the database. |
protected function findTableNames($schema='')
{
// CUBRID does not allow to look into another database from within another connection.
// If necessary user has to establish a connection to that particular database and
// query to show all tables. For this reason if a user executes this funtion
// we will return all table names of the currently connected database.
return $this->getDbConnection()->createCommand('SHOW TABLES')->queryColumn();
}
Returns all table names in the database.
getServerVersion() method
protected float getServerVersion() | ||
{return} | float | server version. |
protected function getServerVersion()
{
$version=$this->getDbConnection()->getAttribute(PDO::ATTR_SERVER_VERSION);
$digits=array();
preg_match('/(\d+)\.(\d+)\.(\d+).(\d+)/', $version, $digits);
return floatval($digits[1].'.'.$digits[2].$digits[3].'.'.$digits[4]);
}
loadTable() method
protected CCubridTableSchema loadTable(string $name) | ||
$name | string | table name |
{return} | CCubridTableSchema | driver dependent table metadata. Null if the table does not exist. |
protected function loadTable($name)
{
$table=new CCubridTableSchema;
$this->resolveTableNames($table,$name);
if($this->findColumns($table))
{
$this->findPrimaryKeys($table);
$this->findConstraints($table);
return $table;
}
else
return null;
}
Creates a table instance representing the metadata for the named table.
quoteSimpleColumnName() method
public string quoteSimpleColumnName(string $name) | ||
$name | string | column name |
{return} | string | the properly quoted column name |
public function quoteSimpleColumnName($name)
{
return '`'.$name.'`';
}
Quotes a column name for use in a query. A simple column name does not contain prefix.
quoteSimpleTableName() method
public string quoteSimpleTableName(string $name) | ||
$name | string | table name |
{return} | string | the properly quoted table name |
public function quoteSimpleTableName($name)
{
return '`'.$name.'`';
}
Quotes a table name for use in a query. A simple table name does not schema prefix.
resetSequence() method
public void resetSequence(CDbTableSchema $table, mixed $value=NULL) | ||
$table | CDbTableSchema | the table schema whose primary key sequence will be reset |
$value | mixed | the value for the primary key of the next new row inserted. If this is not set, the next new row's primary key will have a value 1. |
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()+1;
else
$value=(int)$value;
$this->getDbConnection()->createCommand("ALTER TABLE {$table->rawName} AUTO_INCREMENT=$value")->execute();
}
}
Resets the sequence value of a table's primary key. The sequence will be reset such that the primary key of the next new row inserted will have the specified value or 1.
resolveTableNames() method
protected void resolveTableNames(CCubridTableSchema $table, string $name) | ||
$table | CCubridTableSchema | the table instance |
$name | string | the unquoted table name |
protected function resolveTableNames($table,$name)
{
$parts=explode('.',str_replace('`','',$name));
if(isset($parts[1]))
{
$table->schemaName=$parts[0];
$table->name=$parts[1];
$table->rawName=$this->quoteTableName($table->schemaName).'.'.$this->quoteTableName($table->name);
}
else
{
$table->name=$parts[0];
$table->rawName=$this->quoteTableName($table->name);
}
}
Generates various kinds of table names.
© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc/api/1.1/CCubridSchema