CCubridSchema
CCubridSchema is the class for retrieving metadata information from a CUBRID database (version 8.4.0 and later).
Protected Properties
Property |
Type |
Description |
Defined By |
serverVersion | float | server version. | CCubridSchema |
Property Details
columnTypes
public $columnTypes;
protected float getServerVersion()
server version.
Method Details
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. |
Compares two table names. The table names can be either quoted or unquoted. This method will consider both cases.
createColumn()
Source Code: framework/db/schema/cubrid/CCubridSchema.php#165 (
show)
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()
Source Code: framework/db/schema/cubrid/CCubridSchema.php#140 (
show)
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.
Source Code: framework/db/schema/cubrid/CCubridSchema.php#194 (
show)
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.
Source Code: framework/db/schema/cubrid/CCubridSchema.php#210 (
show)
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.
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. |
Source Code: framework/db/schema/cubrid/CCubridSchema.php#236 (
show)
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.
protected float getServerVersion() |
{return} | float | server version. |
Source Code: framework/db/schema/cubrid/CCubridSchema.php#182 (
show)
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]);
}
Source Code: framework/db/schema/cubrid/CCubridSchema.php#99 (
show)
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()
public string quoteSimpleColumnName(string $name) |
$name | string | column name |
{return} | string | the properly quoted column name |
Quotes a column name for use in a query. A simple column name does not contain prefix.
public string quoteSimpleTableName(string $name) |
$name | string | table name |
{return} | string | the properly quoted table name |
Quotes a table name for use in a query. A simple table name does not schema prefix.
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. |
Source Code: framework/db/schema/cubrid/CCubridSchema.php#82 (
show)
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.
Source Code: framework/db/schema/cubrid/CCubridSchema.php#119 (
show)
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.