code
stringlengths 17
247k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
private function quoteValueInternal($value, $type)
{
if(mb_stripos($this->connectionString, 'odbc:')===false)
{
if(($quoted=$this->_pdo->quote($value, $type))!==false)
return $quoted;
}
// fallback for drivers that don't support quote (e.g. oci and odbc)
return "'" . addcslashes(str_replace("'", "''", $value), "\000\n\r\\\032") . "'";
} | Quotes a value for use in a query using a given type. This method is internally used.
@param mixed $value
@param int $type
@return string | quoteValueInternal | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function quoteTableName($name)
{
return $this->getSchema()->quoteTableName($name);
} | Quotes a table name for use in a query.
If the table name contains schema prefix, the prefix will also be properly quoted.
@param string $name table name
@return string the properly quoted table name | quoteTableName | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function quoteColumnName($name)
{
return $this->getSchema()->quoteColumnName($name);
} | Quotes a column name for use in a query.
If the column name contains prefix, the prefix will also be properly quoted.
@param string $name column name
@return string the properly quoted column name | quoteColumnName | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getPdoType($type)
{
static $map=array
(
'boolean'=>PDO::PARAM_BOOL,
'integer'=>PDO::PARAM_INT,
'string'=>PDO::PARAM_STR,
'resource'=>PDO::PARAM_LOB,
'NULL'=>PDO::PARAM_NULL,
);
return isset($map[$type]) ? $map[$type] : PDO::PARAM_STR;
} | Determines the PDO type for the specified PHP type.
@param string $type The PHP type (obtained by gettype() call).
@return integer the corresponding PDO type | getPdoType | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getColumnCase()
{
return $this->getAttribute(PDO::ATTR_CASE);
} | Returns the case of the column names
@return mixed the case of the column names
@see https://www.php.net/manual/en/pdo.setattribute.php | getColumnCase | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setColumnCase($value)
{
$this->setAttribute(PDO::ATTR_CASE,$value);
} | Sets the case of the column names.
@param mixed $value the case of the column names
@see https://www.php.net/manual/en/pdo.setattribute.php | setColumnCase | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getNullConversion()
{
return $this->getAttribute(PDO::ATTR_ORACLE_NULLS);
} | Returns how the null and empty strings are converted.
@return mixed how the null and empty strings are converted
@see https://www.php.net/manual/en/pdo.setattribute.php | getNullConversion | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setNullConversion($value)
{
$this->setAttribute(PDO::ATTR_ORACLE_NULLS,$value);
} | Sets how the null and empty strings are converted.
@param mixed $value how the null and empty strings are converted
@see https://www.php.net/manual/en/pdo.setattribute.php | setNullConversion | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getAutoCommit()
{
return $this->getAttribute(PDO::ATTR_AUTOCOMMIT);
} | Returns whether creating or updating a DB record will be automatically committed.
Some DBMS (such as sqlite) may not support this feature.
@return boolean whether creating or updating a DB record will be automatically committed. | getAutoCommit | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setAutoCommit($value)
{
$this->setAttribute(PDO::ATTR_AUTOCOMMIT,$value);
} | Sets whether creating or updating a DB record will be automatically committed.
Some DBMS (such as sqlite) may not support this feature.
@param boolean $value whether creating or updating a DB record will be automatically committed. | setAutoCommit | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getPersistent()
{
return $this->getAttribute(PDO::ATTR_PERSISTENT);
} | Returns whether the connection is persistent or not.
Some DBMS (such as sqlite) may not support this feature.
@return boolean whether the connection is persistent or not | getPersistent | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setPersistent($value)
{
return $this->setAttribute(PDO::ATTR_PERSISTENT,$value);
} | Sets whether the connection is persistent or not.
Some DBMS (such as sqlite) may not support this feature.
@param boolean $value whether the connection is persistent or not | setPersistent | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getDriverName()
{
if($this->_driverName!==null)
return $this->_driverName;
elseif(($pos=strpos($this->connectionString,':'))!==false)
return $this->_driverName=strtolower(substr($this->connectionString,0,$pos));
//return $this->getAttribute(PDO::ATTR_DRIVER_NAME);
} | Returns the name of the DB driver.
@return string name of the DB driver. | getDriverName | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setDriverName($driverName)
{
$this->_driverName=strtolower($driverName);
} | Changes the name of the DB driver. Overrides value extracted from the {@link connectionString},
which is behavior by default.
@param string $driverName to be set. Valid values are the keys from the {@link driverMap} property.
@see getDriverName
@see driverName
@since 1.1.16 | setDriverName | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getClientVersion()
{
return $this->getAttribute(PDO::ATTR_CLIENT_VERSION);
} | Returns the version information of the DB driver.
@return string the version information of the DB driver | getClientVersion | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getConnectionStatus()
{
return $this->getAttribute(PDO::ATTR_CONNECTION_STATUS);
} | Returns the status of the connection.
Some DBMS (such as sqlite) may not support this feature.
@return string the status of the connection | getConnectionStatus | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getPrefetch()
{
return $this->getAttribute(PDO::ATTR_PREFETCH);
} | Returns whether the connection performs data prefetching.
@return boolean whether the connection performs data prefetching | getPrefetch | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getServerInfo()
{
return $this->getAttribute(PDO::ATTR_SERVER_INFO);
} | Returns the information of DBMS server.
@return string the information of DBMS server | getServerInfo | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getServerVersion()
{
return $this->getAttribute(PDO::ATTR_SERVER_VERSION);
} | Returns the version information of DBMS server.
@return string the version information of DBMS server | getServerVersion | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getTimeout()
{
return $this->getAttribute(PDO::ATTR_TIMEOUT);
} | Returns the timeout settings for the connection.
@return integer timeout settings for the connection | getTimeout | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getAttribute($name)
{
$this->setActive(true);
return $this->_pdo->getAttribute($name);
} | Obtains a specific DB connection attribute information.
@param integer $name the attribute to be queried
@return mixed the corresponding attribute information
@see https://www.php.net/manual/en/function.PDO-getAttribute.php | getAttribute | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setAttribute($name,$value)
{
if($this->_pdo instanceof PDO)
$this->_pdo->setAttribute($name,$value);
else
$this->_attributes[$name]=$value;
} | Sets an attribute on the database connection.
@param integer $name the attribute to be set
@param mixed $value the attribute value
@see https://www.php.net/manual/en/function.PDO-setAttribute.php | setAttribute | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getAttributes()
{
return $this->_attributes;
} | Returns the attributes that are previously explicitly set for the DB connection.
@return array attributes (name=>value) that are previously explicitly set for the DB connection.
@see setAttributes
@since 1.1.7 | getAttributes | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setAttributes($values)
{
foreach($values as $name=>$value)
$this->_attributes[$name]=$value;
} | Sets a set of attributes on the database connection.
@param array $values attributes (name=>value) to be set.
@see setAttribute
@since 1.1.7 | setAttributes | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getStats()
{
$logger=Yii::getLogger();
$timings=$logger->getProfilingResults(null,'system.db.CDbCommand.query');
$count=count($timings);
$time=array_sum($timings);
$timings=$logger->getProfilingResults(null,'system.db.CDbCommand.execute');
$count+=count($timings);
$time+=array_sum($timings);
return array($count,$time);
} | Returns the statistical results of SQL executions.
The results returned include the number of SQL statements executed and
the total time spent.
In order to use this method, {@link enableProfiling} has to be set true.
@return array the first element indicates the number of SQL statements executed,
and the second element the total time spent in SQL execution. | getStats | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getColumn($name)
{
return isset($this->columns[$name]) ? $this->columns[$name] : null;
} | Gets the named column metadata.
This is a convenient method for retrieving a named column even if it does not exist.
@param string $name column name
@return CDbColumnSchema metadata of the named column. Null if the named column does not exist. | getColumn | php | yiisoft/yii | framework/db/schema/CDbTableSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbTableSchema.php | BSD-3-Clause |
public function getTable($name,$refresh=false)
{
if($refresh===false && isset($this->_tables[$name]))
return $this->_tables[$name];
else
{
if($this->_connection->tablePrefix!==null && strpos($name,'{{')!==false)
$realName=preg_replace('/\{\{(.*?)\}\}/',$this->_connection->tablePrefix.'$1',$name);
else
$realName=$name;
// temporarily disable query caching
if($this->_connection->queryCachingDuration>0)
{
$qcDuration=$this->_connection->queryCachingDuration;
$this->_connection->queryCachingDuration=0;
}
if(!isset($this->_cacheExclude[$name]) && ($duration=$this->_connection->schemaCachingDuration)>0 && $this->_connection->schemaCacheID!==false && ($cache=Yii::app()->getComponent($this->_connection->schemaCacheID))!==null)
{
$key='yii:dbschema'.$this->_connection->connectionString.':'.$this->_connection->username.':'.$name;
$table=$cache->get($key);
if($refresh===true || $table===false)
{
$table=$this->loadTable($realName);
if($table!==null)
$cache->set($key,$table,$duration);
}
$this->_tables[$name]=$table;
}
else
$this->_tables[$name]=$table=$this->loadTable($realName);
if(isset($qcDuration)) // re-enable query caching
$this->_connection->queryCachingDuration=$qcDuration;
return $table;
}
} | Obtains the metadata for the named table.
@param string $name table name
@param boolean $refresh if we need to refresh schema cache for a table.
Parameter available since 1.1.9
@return CDbTableSchema table metadata. Null if the named table does not exist. | getTable | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function getTables($schema='')
{
$tables=array();
foreach($this->getTableNames($schema) as $name)
{
if(($table=$this->getTable($name))!==null)
$tables[$name]=$table;
}
return $tables;
} | Returns the metadata for all tables in the database.
@param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
@return array the metadata for all tables in the database.
Each array element is an instance of {@link CDbTableSchema} (or its child class).
The array keys are table names. | getTables | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function getTableNames($schema='')
{
if(!isset($this->_tableNames[$schema]))
$this->_tableNames[$schema]=$this->findTableNames($schema);
return $this->_tableNames[$schema];
} | Returns all table names in the database.
@param string $schema 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. | getTableNames | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function refresh()
{
if(($duration=$this->_connection->schemaCachingDuration)>0 && $this->_connection->schemaCacheID!==false && ($cache=Yii::app()->getComponent($this->_connection->schemaCacheID))!==null)
{
foreach(array_keys($this->_tables) as $name)
{
if(!isset($this->_cacheExclude[$name]))
{
$key='yii:dbschema'.$this->_connection->connectionString.':'.$this->_connection->username.':'.$name;
$cache->delete($key);
}
}
}
$this->_tables=array();
$this->_tableNames=array();
$this->_builder=null;
} | Refreshes the schema.
This method resets the loaded table metadata and command builder
so that they can be recreated to reflect the change of schema. | refresh | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function quoteTableName($name)
{
if(strpos($name,'.')===false)
return $this->quoteSimpleTableName($name);
$parts=explode('.',$name);
foreach($parts as $i=>$part)
$parts[$i]=$this->quoteSimpleTableName($part);
return implode('.',$parts);
} | Quotes a table name for use in a query.
If the table name contains schema prefix, the prefix will also be properly quoted.
@param string $name table name
@return string the properly quoted table name
@see quoteSimpleTableName | quoteTableName | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function quoteSimpleTableName($name)
{
return "'".$name."'";
} | Quotes a simple table name for use in a query.
A simple table name does not schema prefix.
@param string $name table name
@return string the properly quoted table name
@since 1.1.6 | quoteSimpleTableName | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function quoteSimpleColumnName($name)
{
return '"'.$name.'"';
} | Quotes a simple column name for use in a query.
A simple column name does not contain prefix.
@param string $name column name
@return string the properly quoted column name
@since 1.1.6 | quoteSimpleColumnName | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function compareTableNames($name1,$name2)
{
$name1=str_replace(array('"','`',"'"),'',$name1);
$name2=str_replace(array('"','`',"'"),'',$name2);
if(($pos=strrpos($name1,'.'))!==false)
$name1=substr($name1,$pos+1);
if(($pos=strrpos($name2,'.'))!==false)
$name2=substr($name2,$pos+1);
if($this->_connection->tablePrefix!==null)
{
if(strpos($name1,'{')!==false)
$name1=$this->_connection->tablePrefix.str_replace(array('{','}'),'',$name1);
if(strpos($name2,'{')!==false)
$name2=$this->_connection->tablePrefix.str_replace(array('{','}'),'',$name2);
}
return $name1===$name2;
} | Compares two table names.
The table names can be either quoted or unquoted. This method
will consider both cases.
@param string $name1 table name 1
@param string $name2 table name 2
@return boolean whether the two table names refer to the same table. | compareTableNames | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function resetSequence($table,$value=null)
{
} | 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 max value of a primary key plus one (i.e. sequence trimming).
@param CDbTableSchema $table the table schema whose primary key sequence will be reset
@param integer|null $value 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 the max value of a primary
key plus one (i.e. sequence trimming).
@since 1.1 | resetSequence | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function checkIntegrity($check=true,$schema='')
{
} | Enables or disables integrity check.
@param boolean $check whether to turn on or off the integrity check.
@param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
@since 1.1 | checkIntegrity | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
protected function createCommandBuilder()
{
return new CDbCommandBuilder($this);
} | Creates a command builder for the database.
This method may be overridden by child classes to create a DBMS-specific command builder.
@return CDbCommandBuilder command builder instance | createCommandBuilder | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
protected function findTableNames($schema='')
{
throw new CDbException(Yii::t('yii','{class} does not support fetching all table names.',
array('{class}'=>get_class($this))));
} | Returns all table names in the database.
This method should be overridden by child classes in order to support this feature
because the default implementation simply throws an exception.
@param string $schema 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.
@throws CDbException if current schema does not support fetching all table names
@return array all table names in the database. | findTableNames | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function renameTable($table,$newName)
{
return 'RENAME TABLE ' . $this->quoteTableName($table) . ' TO ' . $this->quoteTableName($newName);
} | Builds a SQL statement for renaming a DB table.
@param string $table the table to be renamed. The name will be properly quoted by the method.
@param string $newName the new table name. The name will be properly quoted by the method.
@return string the SQL statement for renaming a DB table.
@since 1.1.6 | renameTable | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function dropTable($table)
{
return "DROP TABLE ".$this->quoteTableName($table);
} | Builds a SQL statement for dropping a DB table.
@param string $table the table to be dropped. The name will be properly quoted by the method.
@return string the SQL statement for dropping a DB table.
@since 1.1.6 | dropTable | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function truncateTable($table)
{
return "TRUNCATE TABLE ".$this->quoteTableName($table);
} | Builds a SQL statement for truncating a DB table.
@param string $table the table to be truncated. The name will be properly quoted by the method.
@return string the SQL statement for truncating a DB table.
@since 1.1.6 | truncateTable | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function addColumn($table,$column,$type)
{
return 'ALTER TABLE ' . $this->quoteTableName($table)
. ' ADD ' . $this->quoteColumnName($column) . ' '
. $this->getColumnType($type);
} | Builds a SQL statement for adding a new DB column.
@param string $table the table that the new column will be added to. The table name will be properly quoted by the method.
@param string $column the name of the new column. The name will be properly quoted by the method.
@param string $type the column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any)
into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL.
For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
@return string the SQL statement for adding a new column.
@since 1.1.6 | addColumn | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function dropColumn($table,$column)
{
return "ALTER TABLE ".$this->quoteTableName($table)
." DROP COLUMN ".$this->quoteColumnName($column);
} | Builds a SQL statement for dropping a DB column.
@param string $table the table whose column is to be dropped. The name will be properly quoted by the method.
@param string $column the name of the column to be dropped. The name will be properly quoted by the method.
@return string the SQL statement for dropping a DB column.
@since 1.1.6 | dropColumn | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function renameColumn($table,$name,$newName)
{
return "ALTER TABLE ".$this->quoteTableName($table)
. " RENAME COLUMN ".$this->quoteColumnName($name)
. " TO ".$this->quoteColumnName($newName);
} | Builds a SQL statement for renaming a column.
@param string $table the table whose column is to be renamed. The name will be properly quoted by the method.
@param string $name the old name of the column. The name will be properly quoted by the method.
@param string $newName the new name of the column. The name will be properly quoted by the method.
@return string the SQL statement for renaming a DB column.
@since 1.1.6 | renameColumn | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function alterColumn($table,$column,$type)
{
return 'ALTER TABLE ' . $this->quoteTableName($table) . ' CHANGE '
. $this->quoteColumnName($column) . ' '
. $this->quoteColumnName($column) . ' '
. $this->getColumnType($type);
} | Builds a SQL statement for changing the definition of a column.
@param string $table the table whose column is to be changed. The table name will be properly quoted by the method.
@param string $column the name of the column to be changed. The name will be properly quoted by the method.
@param string $type the new column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any)
into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL.
For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
@return string the SQL statement for changing the definition of a column.
@since 1.1.6 | alterColumn | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function addForeignKey($name,$table,$columns,$refTable,$refColumns,$delete=null,$update=null)
{
if(is_string($columns))
$columns=preg_split('/\s*,\s*/',$columns,-1,PREG_SPLIT_NO_EMPTY);
foreach($columns as $i=>$col)
$columns[$i]=$this->quoteColumnName($col);
if(is_string($refColumns))
$refColumns=preg_split('/\s*,\s*/',$refColumns,-1,PREG_SPLIT_NO_EMPTY);
foreach($refColumns as $i=>$col)
$refColumns[$i]=$this->quoteColumnName($col);
$sql='ALTER TABLE '.$this->quoteTableName($table)
.' ADD CONSTRAINT '.$this->quoteColumnName($name)
.' FOREIGN KEY ('.implode(', ',$columns).')'
.' REFERENCES '.$this->quoteTableName($refTable)
.' ('.implode(', ',$refColumns).')';
if($delete!==null)
$sql.=' ON DELETE '.$delete;
if($update!==null)
$sql.=' ON UPDATE '.$update;
return $sql;
} | Builds a SQL statement for adding a foreign key constraint to an existing table.
The method will properly quote the table and column names.
@param string $name the name of the foreign key constraint.
@param string $table the table that the foreign key constraint will be added to.
@param string|array $columns the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or pass as an array of column names.
@param string $refTable the table that the foreign key references to.
@param string|array $refColumns the name of the column that the foreign key references to. If there are multiple columns, separate them with commas or pass as an array of column names.
@param string $delete the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
@param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
@return string the SQL statement for adding a foreign key constraint to an existing table.
@since 1.1.6 | addForeignKey | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function dropForeignKey($name,$table)
{
return 'ALTER TABLE '.$this->quoteTableName($table)
.' DROP CONSTRAINT '.$this->quoteColumnName($name);
} | Builds a SQL statement for dropping a foreign key constraint.
@param string $name the name of the foreign key constraint to be dropped. The name will be properly quoted by the method.
@param string $table the table whose foreign is to be dropped. The name will be properly quoted by the method.
@return string the SQL statement for dropping a foreign key constraint.
@since 1.1.6 | dropForeignKey | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function dropIndex($name,$table)
{
return 'DROP INDEX '.$this->quoteTableName($name).' ON '.$this->quoteTableName($table);
} | Builds a SQL statement for dropping an index.
@param string $name the name of the index to be dropped. The name will be properly quoted by the method.
@param string $table the table whose index is to be dropped. The name will be properly quoted by the method.
@return string the SQL statement for dropping an index.
@since 1.1.6 | dropIndex | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function addPrimaryKey($name,$table,$columns)
{
if(is_string($columns))
$columns=preg_split('/\s*,\s*/',$columns,-1,PREG_SPLIT_NO_EMPTY);
foreach($columns as $i=>$col)
$columns[$i]=$this->quoteColumnName($col);
return 'ALTER TABLE ' . $this->quoteTableName($table) . ' ADD CONSTRAINT '
. $this->quoteColumnName($name) . ' PRIMARY KEY ('
. implode(', ',$columns). ' )';
} | Builds a SQL statement for adding a primary key constraint to an existing table.
@param string $name the name of the primary key constraint.
@param string $table the table that the primary key constraint will be added to.
@param string|array $columns comma separated string or array of columns that the primary key will consist of.
Array value can be passed since 1.1.14.
@return string the SQL statement for adding a primary key constraint to an existing table.
@since 1.1.13 | addPrimaryKey | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function dropPrimaryKey($name,$table)
{
return 'ALTER TABLE ' . $this->quoteTableName($table) . ' DROP CONSTRAINT '
. $this->quoteColumnName($name);
} | Builds a SQL statement for removing a primary key constraint to an existing table.
@param string $name the name of the primary key constraint to be removed.
@param string $table the table that the primary key constraint will be removed from.
@return string the SQL statement for removing a primary key constraint from an existing table.
@since 1.1.13 | dropPrimaryKey | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function addCondition($condition,$operator='AND')
{
if(is_array($condition))
{
if($condition===array())
return $this;
$condition='('.implode(') '.$operator.' (',$condition).')';
}
if($this->condition==='')
$this->condition=$condition;
else
$this->condition='('.$this->condition.') '.$operator.' ('.$condition.')';
return $this;
} | Appends a condition to the existing {@link condition}.
The new condition and the existing condition will be concatenated via the specified operator
which defaults to 'AND'.
The new condition can also be an array. In this case, all elements in the array
will be concatenated together via the operator.
This method handles the case when the existing condition is empty.
After calling this method, the {@link condition} property will be modified.
@param mixed $condition the new condition. It can be either a string or an array of strings.
@param string $operator the operator to join different conditions. Defaults to 'AND'.
@return static the criteria object itself | addCondition | php | yiisoft/yii | framework/db/schema/CDbCriteria.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCriteria.php | BSD-3-Clause |
public function addNotInCondition($column,$values,$operator='AND')
{
if(($n=count($values))<1)
return $this;
if($n===1)
{
$value=reset($values);
if($value===null)
$condition=$column.' IS NOT NULL';
else
{
$condition=$column.'!='.self::PARAM_PREFIX.self::$paramCount;
$this->params[self::PARAM_PREFIX.self::$paramCount++]=$value;
}
}
else
{
$params=array();
foreach($values as $value)
{
$params[]=self::PARAM_PREFIX.self::$paramCount;
$this->params[self::PARAM_PREFIX.self::$paramCount++]=$value;
}
$condition=$column.' NOT IN ('.implode(', ',$params).')';
}
return $this->addCondition($condition,$operator);
} | Appends an NOT IN condition to the existing {@link condition}.
The NOT IN condition and the existing condition will be concatenated via the specified operator
which defaults to 'AND'.
The NOT IN condition is generated by using the SQL NOT IN operator which requires the specified
column value to be among the given list of values.
@param string $column the column name (or a valid SQL expression)
@param array $values list of values that the column value should not be in
@param string $operator the operator used to concatenate the new condition with the existing one.
Defaults to 'AND'.
@return static the criteria object itself
@since 1.1.1 | addNotInCondition | php | yiisoft/yii | framework/db/schema/CDbCriteria.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCriteria.php | BSD-3-Clause |
public function compare($column, $value, $partialMatch=false, $operator='AND', $escape=true)
{
if(is_array($value))
{
if($value===array())
return $this;
return $this->addInCondition($column,$value,$operator);
}
else
$value="$value";
if(preg_match('/^(?:\s*(<>|<=|>=|<|>|=))?(.*)$/',$value,$matches))
{
$value=$matches[2];
$op=$matches[1];
}
else
$op='';
if($value==='')
return $this;
if($partialMatch)
{
if($op==='')
return $this->addSearchCondition($column,$value,$escape,$operator);
if($op==='<>')
return $this->addSearchCondition($column,$value,$escape,$operator,'NOT LIKE');
}
elseif($op==='')
$op='=';
$this->addCondition($column.$op.self::PARAM_PREFIX.self::$paramCount,$operator);
$this->params[self::PARAM_PREFIX.self::$paramCount++]=$value;
return $this;
} | Adds a comparison expression to the {@link condition} property.
This method is a helper that appends to the {@link condition} property
with a new comparison expression. The comparison is done by comparing a column
with the given value using some comparison operator.
The comparison operator is intelligently determined based on the first few
characters in the given value. In particular, it recognizes the following operators
if they appear as the leading characters in the given value:
<ul>
<li><code><</code>: the column must be less than the given value.</li>
<li><code>></code>: the column must be greater than the given value.</li>
<li><code><=</code>: the column must be less than or equal to the given value.</li>
<li><code>>=</code>: the column must be greater than or equal to the given value.</li>
<li><code><></code>: the column must not be the same as the given value.
Note that when $partialMatch is true, this would mean the value must not be a substring
of the column.</li>
<li><code>=</code>: the column must be equal to the given value.</li>
<li>none of the above: the column must be equal to the given value. Note that when $partialMatch
is true, this would mean the value must be the same as the given value or be a substring of it.</li>
</ul>
Note that any surrounding white spaces will be removed from the value before comparison.
When the value is empty, no comparison expression will be added to the search condition.
@param string $column the name of the column to be searched
@param mixed $value the column value to be compared with. If the value is a string, the aforementioned
intelligent comparison will be conducted. If the value is an array, the comparison is done
by exact match of any of the value in the array. If the string or the array is empty,
the existing search condition will not be modified.
@param boolean $partialMatch whether the value should consider partial text match (using LIKE and NOT LIKE operators).
Defaults to false, meaning exact comparison.
@param string $operator the operator used to concatenate the new condition with the existing one.
Defaults to 'AND'.
@param boolean $escape whether the value should be escaped if $partialMatch is true and
the value contains characters % or _. When this parameter is true (default),
the special characters % (matches 0 or more characters)
and _ (matches a single character) will be escaped, and the value will be surrounded with a %
character on both ends. When this parameter is false, the value will be directly used for
matching without any change.
@return static the criteria object itself
@since 1.1.1 | compare | php | yiisoft/yii | framework/db/schema/CDbCriteria.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCriteria.php | BSD-3-Clause |
public function addBetweenCondition($column,$valueStart,$valueEnd,$operator='AND')
{
if($valueStart==='' || $valueEnd==='')
return $this;
$paramStart=self::PARAM_PREFIX.self::$paramCount++;
$paramEnd=self::PARAM_PREFIX.self::$paramCount++;
$this->params[$paramStart]=$valueStart;
$this->params[$paramEnd]=$valueEnd;
$condition="$column BETWEEN $paramStart AND $paramEnd";
return $this->addCondition($condition,$operator);
} | Adds a between condition to the {@link condition} property.
The new between condition and the existing condition will be concatenated via
the specified operator which defaults to 'AND'.
If one or both values are empty then the condition is not added to the existing condition.
This method handles the case when the existing condition is empty.
After calling this method, the {@link condition} property will be modified.
@param string $column the name of the column to search between.
@param string $valueStart the beginning value to start the between search.
@param string $valueEnd the ending value to end the between search.
@param string $operator the operator used to concatenate the new condition with the existing one.
Defaults to 'AND'.
@return static the criteria object itself
@since 1.1.2 | addBetweenCondition | php | yiisoft/yii | framework/db/schema/CDbCriteria.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCriteria.php | BSD-3-Clause |
public function getLastInsertID($table)
{
$this->ensureTable($table);
if($table->sequenceName!==null)
return $this->_connection->getLastInsertID($table->sequenceName);
else
return null;
} | Returns the last insertion ID for the specified table.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@return mixed last insertion id. Null is returned if no sequence name. | getLastInsertID | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function createFindCommand($table,$criteria,$alias='t')
{
$this->ensureTable($table);
$select=is_array($criteria->select) ? implode(', ',$criteria->select) : $criteria->select;
if($criteria->alias!='')
$alias=$criteria->alias;
$alias=$this->_schema->quoteTableName($alias);
// issue 1432: need to expand * when SQL has JOIN
if($select==='*' && !empty($criteria->join))
{
$prefix=$alias.'.';
$select=array();
foreach($table->getColumnNames() as $name)
$select[]=$prefix.$this->_schema->quoteColumnName($name);
$select=implode(', ',$select);
}
$sql=($criteria->distinct ? 'SELECT DISTINCT':'SELECT')." {$select} FROM {$table->rawName} $alias";
$sql=$this->applyJoin($sql,$criteria->join);
$sql=$this->applyCondition($sql,$criteria->condition);
$sql=$this->applyGroup($sql,$criteria->group);
$sql=$this->applyHaving($sql,$criteria->having);
$sql=$this->applyOrder($sql,$criteria->order);
$sql=$this->applyLimit($sql,$criteria->limit,$criteria->offset);
$command=$this->_connection->createCommand($sql);
$this->bindValues($command,$criteria->params);
return $command;
} | Creates a SELECT command for a single table.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param CDbCriteria $criteria the query criteria
@param string $alias the alias name of the primary table. Defaults to 't'.
@return CDbCommand query command. | createFindCommand | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function createMultipleInsertCommand($table,array $data)
{
return $this->composeMultipleInsertCommand($table,$data);
} | Creates a multiple INSERT command.
This method could be used to achieve better performance during insertion of the large
amount of data into the database tables.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param array[] $data list data to be inserted, each value should be an array in format (column name=>column value).
If a key is not a valid column name, the corresponding value will be ignored.
@return CDbCommand multiple insert command
@since 1.1.14 | createMultipleInsertCommand | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function createUpdateCounterCommand($table,$counters,$criteria)
{
$this->ensureTable($table);
$fields=array();
foreach($counters as $name=>$value)
{
if(($column=$table->getColumn($name))!==null)
{
$value=(float)$value;
if($value<0)
$fields[]="{$column->rawName}={$column->rawName}-".(-$value);
else
$fields[]="{$column->rawName}={$column->rawName}+".$value;
}
} | Creates an UPDATE command that increments/decrements certain columns.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param array $counters counters to be updated (counter increments/decrements indexed by column names.)
@param CDbCriteria $criteria the query criteria
@throws CDbException if no columns are being updated for the given table
@return CDbCommand the created command | createUpdateCounterCommand | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function applyJoin($sql,$join)
{
if($join!='')
return $sql.' '.$join;
else
return $sql;
} | Alters the SQL to apply JOIN clause.
@param string $sql the SQL statement to be altered
@param string $join the JOIN clause (starting with join type, such as INNER JOIN)
@return string the altered SQL statement | applyJoin | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function applyCondition($sql,$condition)
{
if($condition!='')
return $sql.' WHERE '.$condition;
else
return $sql;
} | Alters the SQL to apply WHERE clause.
@param string $sql the SQL statement without WHERE clause
@param string $condition the WHERE clause (without WHERE keyword)
@return string the altered SQL statement | applyCondition | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function applyOrder($sql,$orderBy)
{
if($orderBy!='')
return $sql.' ORDER BY '.$orderBy;
else
return $sql;
} | Alters the SQL to apply ORDER BY.
@param string $sql SQL statement without ORDER BY.
@param string $orderBy column ordering
@return string modified SQL applied with ORDER BY. | applyOrder | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function applyGroup($sql,$group)
{
if($group!='')
return $sql.' GROUP BY '.$group;
else
return $sql;
} | Alters the SQL to apply GROUP BY.
@param string $sql SQL query string without GROUP BY.
@param string $group GROUP BY
@return string SQL with GROUP BY. | applyGroup | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function applyHaving($sql,$having)
{
if($having!='')
return $sql.' HAVING '.$having;
else
return $sql;
} | Alters the SQL to apply HAVING.
@param string $sql SQL query string without HAVING
@param string $having HAVING
@return string SQL with HAVING | applyHaving | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function createPkCondition($table,$values,$prefix=null)
{
$this->ensureTable($table);
return $this->createInCondition($table,$table->primaryKey,$values,$prefix);
} | Generates the expression for selecting rows of specified primary key values.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param array $values list of primary key values to be selected within
@param string $prefix column prefix (ended with dot). If null, it will be the table name
@return string the expression for selection | createPkCondition | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
protected function createCompositeInCondition($table,$values,$prefix)
{
$keyNames=array();
foreach(array_keys($values[0]) as $name)
$keyNames[]=$prefix.$table->columns[$name]->rawName;
$vs=array();
foreach($values as $value)
$vs[]='('.implode(', ',$value).')';
return '('.implode(', ',$keyNames).') IN ('.implode(', ',$vs).')';
} | Generates the expression for selecting rows with specified composite key values.
@param CDbTableSchema $table the table schema
@param array $values list of primary key values to be selected within
@param string $prefix column prefix (ended with dot)
@return string the expression for selection | createCompositeInCondition | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
protected function ensureTable(&$table)
{
if(is_string($table) && ($table=$this->_schema->getTable($tableName=$table))===null)
throw new CDbException(Yii::t('yii','Table "{table}" does not exist.',
array('{table}'=>$tableName)));
} | Checks if the parameter is a valid table schema.
If it is a string, the corresponding table schema will be retrieved.
@param mixed $table table schema ({@link CDbTableSchema}) or table name (string).
If this refers to a valid table name, this parameter will be returned with the corresponding table schema.
@throws CDbException if the table name is not valid | ensureTable | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
protected function getIntegerPrimaryKeyDefaultValue()
{
return 'NULL';
} | Returns default value of the integer/serial primary key. Default value means that the next
autoincrement/sequence value would be used.
@return string default value of the integer/serial primary key.
@since 1.1.14 | getIntegerPrimaryKeyDefaultValue | php | yiisoft/yii | framework/db/schema/CDbCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbCommandBuilder.php | BSD-3-Clause |
public function init($dbType, $defaultValue)
{
$this->dbType=$dbType;
$this->extractType($dbType);
$this->extractLimit($dbType);
if($defaultValue!==null)
$this->extractDefault($defaultValue);
} | Initializes the column with its DB type and default value.
This sets up the column's PHP type, size, precision, scale as well as default value.
@param string $dbType the column's DB type
@param mixed $defaultValue the default value | init | php | yiisoft/yii | framework/db/schema/CDbColumnSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbColumnSchema.php | BSD-3-Clause |
protected function extractType($dbType)
{
if(stripos($dbType,'int')!==false && stripos($dbType,'unsigned int')===false)
$this->type='integer';
elseif(stripos($dbType,'bool')!==false)
$this->type='boolean';
elseif(preg_match('/(real|floa|doub)/i',$dbType))
$this->type='double';
else
$this->type='string';
} | Extracts the PHP type from DB type.
@param string $dbType DB type | extractType | php | yiisoft/yii | framework/db/schema/CDbColumnSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbColumnSchema.php | BSD-3-Clause |
protected function extractLimit($dbType)
{
if(strpos($dbType,'(') && preg_match('/\((.*)\)/',$dbType,$matches))
{
$values=explode(',',$matches[1]);
$this->size=$this->precision=(int)$values[0];
if(isset($values[1]))
$this->scale=(int)$values[1];
}
} | Extracts size, precision and scale information from column's DB type.
@param string $dbType the column's DB type | extractLimit | php | yiisoft/yii | framework/db/schema/CDbColumnSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbColumnSchema.php | BSD-3-Clause |
protected function extractDefault($defaultValue)
{
$this->defaultValue=$this->typecast($defaultValue);
} | Extracts the default value for the column.
The value is typecasted to correct PHP type.
@param mixed $defaultValue the default value obtained from metadata | extractDefault | php | yiisoft/yii | framework/db/schema/CDbColumnSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbColumnSchema.php | BSD-3-Clause |
public function typecast($value)
{
if(gettype($value)===$this->type || $value===null || $value instanceof CDbExpression)
return $value;
if($value==='' && $this->allowNull)
return $this->type==='string' ? '' : null;
switch($this->type)
{
case 'string': return (string)$value;
case 'integer': return (integer)$value;
case 'boolean': return (boolean)$value;
case 'double':
default: return $value;
}
} | Converts the input value to the type that this column is of.
@param mixed $value input value
@return mixed converted value | typecast | php | yiisoft/yii | framework/db/schema/CDbColumnSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbColumnSchema.php | BSD-3-Clause |
public function applyLimit($sql,$limit,$offset)
{
// Ugly, but this is how MySQL recommends doing it: https://dev.mysql.com/doc/refman/5.0/en/select.html
if($limit<=0 && $offset>0)
$limit=PHP_INT_MAX;
return parent::applyLimit($sql,$limit,$offset);
} | Alters the SQL to apply LIMIT and OFFSET.
@param string $sql SQL query string without LIMIT and OFFSET.
@param integer $limit maximum number of rows, -1 to ignore limit.
@param integer $offset row offset, -1 to ignore offset.
@return string SQL with LIMIT and OFFSET | applyLimit | php | yiisoft/yii | framework/db/schema/mysql/CMysqlCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/mysql/CMysqlCommandBuilder.php | BSD-3-Clause |
public function quoteSimpleTableName($name)
{
return '`'.$name.'`';
} | Quotes a table name for use in a query.
A simple table name does not schema prefix.
@param string $name table name
@return string the properly quoted table name
@since 1.1.6 | quoteSimpleTableName | php | yiisoft/yii | framework/db/schema/mysql/CMysqlSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/mysql/CMysqlSchema.php | BSD-3-Clause |
public function quoteSimpleColumnName($name)
{
return '`'.$name.'`';
} | Quotes a column name for use in a query.
A simple column name does not contain prefix.
@param string $name column name
@return string the properly quoted column name
@since 1.1.6 | quoteSimpleColumnName | php | yiisoft/yii | framework/db/schema/mysql/CMysqlSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/mysql/CMysqlSchema.php | BSD-3-Clause |
protected function loadTable($name)
{
$table=new CMysqlTableSchema;
$this->resolveTableNames($table,$name);
if($this->findColumns($table))
{
$this->findConstraints($table);
return $table;
}
else
return null;
} | Loads the metadata for the specified table.
@param string $name table name
@return CMysqlTableSchema driver dependent table metadata. Null if the table does not exist. | loadTable | php | yiisoft/yii | framework/db/schema/mysql/CMysqlSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/mysql/CMysqlSchema.php | BSD-3-Clause |
protected function resolveTableNames($table,$name)
{
$parts=explode('.',str_replace(array('`','"'),'',$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.
@param CMysqlTableSchema $table the table instance
@param string $name the unquoted table name | resolveTableNames | php | yiisoft/yii | framework/db/schema/mysql/CMysqlSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/mysql/CMysqlSchema.php | BSD-3-Clause |
protected function createCommandBuilder()
{
return new CMysqlCommandBuilder($this);
} | Creates a command builder for the database.
This method overrides parent implementation in order to create a MySQL specific command builder
@return CDbCommandBuilder command builder instance
@since 1.1.13 | createCommandBuilder | php | yiisoft/yii | framework/db/schema/mysql/CMysqlSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/mysql/CMysqlSchema.php | BSD-3-Clause |
public function addPrimaryKey($name,$table,$columns)
{
if(is_string($columns))
$columns=preg_split('/\s*,\s*/',$columns,-1,PREG_SPLIT_NO_EMPTY);
foreach($columns as $i=>$col)
$columns[$i]=$this->quoteColumnName($col);
return 'ALTER TABLE ' . $this->quoteTableName($table) . ' ADD PRIMARY KEY ('
. implode(', ', $columns). ' )';
} | Builds a SQL statement for adding a primary key constraint to a table.
@param string $name not used in the MySQL syntax, the primary key is always called PRIMARY and is reserved.
@param string $table the table that the primary key constraint will be added to.
@param string|array $columns comma separated string or array of columns that the primary key will consist of.
@return string the SQL statement for adding a primary key constraint to an existing table.
@since 1.1.14 | addPrimaryKey | php | yiisoft/yii | framework/db/schema/mysql/CMysqlSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/mysql/CMysqlSchema.php | BSD-3-Clause |
protected function extractOraType($dbType){
if(strpos($dbType,'FLOAT')!==false) return 'double';
if (strpos($dbType,'NUMBER')!==false || strpos($dbType,'INTEGER')!==false)
{
if(strpos($dbType,'(') && preg_match('/\((.*)\)/',$dbType,$matches))
{
$values=explode(',',$matches[1]);
if(isset($values[1]) and (((int)$values[1]) > 0))
return 'double';
else
return 'integer';
}
else
return 'double';
}
else
return 'string';
} | Extracts the PHP type from DB type.
@param string $dbType DB type
@return string | extractOraType | php | yiisoft/yii | framework/db/schema/oci/COciColumnSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/oci/COciColumnSchema.php | BSD-3-Clause |
protected function loadTable($name)
{
$table=new COciTableSchema;
$this->resolveTableNames($table,$name);
if(!$this->findColumns($table))
return null;
$this->findConstraints($table);
return $table;
} | Loads the metadata for the specified table.
@param string $name table name
@return CDbTableSchema driver dependent table metadata. | loadTable | php | yiisoft/yii | framework/db/schema/oci/COciSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/oci/COciSchema.php | BSD-3-Clause |
protected function resolveTableNames($table,$name)
{
$parts=explode('.',str_replace('"','',$name));
if(isset($parts[1]))
{
$schemaName=$parts[0];
$tableName=$parts[1];
}
else
{
$schemaName=$this->getDefaultSchema();
$tableName=$parts[0];
}
$table->name=$tableName;
$table->schemaName=$schemaName;
if($schemaName===$this->getDefaultSchema())
$table->rawName=$this->quoteTableName($tableName);
else
$table->rawName=$this->quoteTableName($schemaName).'.'.$this->quoteTableName($tableName);
} | Generates various kinds of table names.
@param COciTableSchema $table the table instance
@param string $name the unquoted table name | resolveTableNames | php | yiisoft/yii | framework/db/schema/oci/COciSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/oci/COciSchema.php | BSD-3-Clause |
protected function findConstraints($table)
{
$sql=<<<EOD
SELECT D.constraint_type as CONSTRAINT_TYPE, C.COLUMN_NAME, C.position, D.r_constraint_name,
E.table_name as table_ref, f.column_name as column_ref,
C.table_name
FROM ALL_CONS_COLUMNS C
inner join ALL_constraints D on D.OWNER = C.OWNER and D.constraint_name = C.constraint_name
left join ALL_constraints E on E.OWNER = D.r_OWNER and E.constraint_name = D.r_constraint_name
left join ALL_cons_columns F on F.OWNER = E.OWNER and F.constraint_name = E.constraint_name and F.position = c.position
WHERE C.OWNER = '{$table->schemaName}'
and C.table_name = '{$table->name}'
and D.constraint_type <> 'P'
order by d.constraint_name, c.position
EOD;
$command=$this->getDbConnection()->createCommand($sql);
foreach($command->queryAll() as $row)
{
if($row['CONSTRAINT_TYPE']==='R') // foreign key
{
$name = $row["COLUMN_NAME"];
$table->foreignKeys[$name]=array($row["TABLE_REF"], $row["COLUMN_REF"]);
if(isset($table->columns[$name]))
$table->columns[$name]->isForeignKey=true;
}
}
} | Collects the primary and foreign key column details for the given table.
@param COciTableSchema $table the table metadata | findConstraints | php | yiisoft/yii | framework/db/schema/oci/COciSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/oci/COciSchema.php | BSD-3-Clause |
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.
@param string $schema the schema of the tables. This is not used for sqlite database.
@return array all table names in the database. | findTableNames | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
protected function createCommandBuilder()
{
return new CSqliteCommandBuilder($this);
} | Creates a command builder for the database.
@return CSqliteCommandBuilder command builder instance | createCommandBuilder | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
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;
} | Loads the metadata for the specified table.
@param string $name table name
@return CDbTableSchema driver dependent table metadata. Null if the table does not exist. | loadTable | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
public function renameTable($table, $newName)
{
return 'ALTER TABLE ' . $this->quoteTableName($table) . ' RENAME TO ' . $this->quoteTableName($newName);
} | Builds a SQL statement for renaming a DB table.
@param string $table the table to be renamed. The name will be properly quoted by the method.
@param string $newName the new table name. The name will be properly quoted by the method.
@return string the SQL statement for renaming a DB table.
@since 1.1.13 | renameTable | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
public function dropColumn($table, $column)
{
throw new CDbException(Yii::t('yii', 'Dropping DB column is not supported by SQLite.'));
} | Builds a SQL statement for dropping a DB column.
Because SQLite does not support dropping a DB column, calling this method will throw an exception.
@param string $table the table whose column is to be dropped. The name will be properly quoted by the method.
@param string $column the name of the column to be dropped. The name will be properly quoted by the method.
@return string the SQL statement for dropping a DB column.
@since 1.1.6
@throws CDbException | dropColumn | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
public function renameColumn($table, $name, $newName)
{
throw new CDbException(Yii::t('yii', 'Renaming a DB column is not supported by SQLite.'));
} | Builds a SQL statement for renaming a column.
Because SQLite does not support renaming a DB column, calling this method will throw an exception.
@param string $table the table whose column is to be renamed. The name will be properly quoted by the method.
@param string $name the old name of the column. The name will be properly quoted by the method.
@param string $newName the new name of the column. The name will be properly quoted by the method.
@return string the SQL statement for renaming a DB column.
@since 1.1.6
@throws CDbException | renameColumn | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
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.'));
} | Builds a SQL statement for adding a foreign key constraint to an existing table.
Because SQLite does not support adding foreign key to an existing table, calling this method will throw an exception.
@param string $name the name of the foreign key constraint.
@param string $table the table that the foreign key constraint will be added to.
@param string $columns the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas.
@param string $refTable the table that the foreign key references to.
@param string $refColumns the name of the column that the foreign key references to. If there are multiple columns, separate them with commas.
@param string $delete the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
@param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
@return string the SQL statement for adding a foreign key constraint to an existing table.
@since 1.1.6
@throws CDbException | addForeignKey | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
public function dropForeignKey($name, $table)
{
throw new CDbException(Yii::t('yii', 'Dropping a foreign key constraint is not supported by SQLite.'));
} | Builds a SQL statement for dropping a foreign key constraint.
Because SQLite does not support dropping a foreign key constraint, calling this method will throw an exception.
@param string $name the name of the foreign key constraint to be dropped. The name will be properly quoted by the method.
@param string $table the table whose foreign is to be dropped. The name will be properly quoted by the method.
@return string the SQL statement for dropping a foreign key constraint.
@since 1.1.6
@throws CDbException | dropForeignKey | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
public function alterColumn($table, $column, $type)
{
throw new CDbException(Yii::t('yii', 'Altering a DB column is not supported by SQLite.'));
} | Builds a SQL statement for changing the definition of a column.
Because SQLite does not support altering a DB column, calling this method will throw an exception.
@param string $table the table whose column is to be changed. The table name will be properly quoted by the method.
@param string $column the name of the column to be changed. The name will be properly quoted by the method.
@param string $type the new column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any)
into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL.
For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
@return string the SQL statement for changing the definition of a column.
@since 1.1.6
@throws CDbException | alterColumn | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
public function addPrimaryKey($name,$table,$columns)
{
throw new CDbException(Yii::t('yii', 'Adding a primary key after table has been created is not supported by SQLite.'));
} | Builds a SQL statement for adding a primary key constraint to an existing table.
Because SQLite does not support adding a primary key on an existing table this method will throw an exception.
@param string $name the name of the primary key constraint.
@param string $table the table that the primary key constraint will be added to.
@param string|array $columns comma separated string or array of columns that the primary key will consist of.
@return string the SQL statement for adding a primary key constraint to an existing table.
@since 1.1.13
@throws CDbException | addPrimaryKey | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
public function dropPrimaryKey($name,$table)
{
throw new CDbException(Yii::t('yii', 'Removing a primary key after table has been created is not supported by SQLite.'));
} | Builds a SQL statement for removing a primary key constraint to an existing table.
Because SQLite does not support dropping a primary key from an existing table this method will throw an exception
@param string $name the name of the primary key constraint to be removed.
@param string $table the table that the primary key constraint will be removed from.
@return string the SQL statement for removing a primary key constraint from an existing table.
@since 1.1.13
@throws CDbException | dropPrimaryKey | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteSchema.php | BSD-3-Clause |
protected function createCompositeInCondition($table,$values,$prefix)
{
$keyNames=array();
foreach(array_keys($values[0]) as $name)
$keyNames[]=$prefix.$table->columns[$name]->rawName;
$vs=array();
foreach($values as $value)
$vs[]=implode("||','||",$value);
return implode("||','||",$keyNames).' IN ('.implode(', ',$vs).')';
} | Generates the expression for selecting rows with specified composite key values.
This method is overridden because SQLite does not support the default
IN expression with composite columns.
@param CDbTableSchema $table the table schema
@param array $values list of primary key values to be selected within
@param string $prefix column prefix (ended with dot)
@return string the expression for selection | createCompositeInCondition | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteCommandBuilder.php | BSD-3-Clause |
public function createMultipleInsertCommand($table,array $data)
{
$templates=array(
'main'=>'INSERT INTO {{tableName}} ({{columnInsertNames}}) {{rowInsertValues}}',
'columnInsertValue'=>'{{value}} AS {{column}}',
'columnInsertValueGlue'=>', ',
'rowInsertValue'=>'SELECT {{columnInsertValues}}',
'rowInsertValueGlue'=>' UNION ',
'columnInsertNameGlue'=>', ',
);
return $this->composeMultipleInsertCommand($table,$data,$templates);
} | Creates a multiple INSERT command.
This method could be used to achieve better performance during insertion of the large
amount of data into the database tables.
Note that SQLite does not keep original order of the inserted rows.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param array[] $data list data to be inserted, each value should be an array in format (column name=>column value).
If a key is not a valid column name, the corresponding value will be ignored.
@return CDbCommand multiple insert command
@since 1.1.14 | createMultipleInsertCommand | php | yiisoft/yii | framework/db/schema/sqlite/CSqliteCommandBuilder.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/sqlite/CSqliteCommandBuilder.php | BSD-3-Clause |
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.
@param CDbTableSchema $table the table schema whose primary key sequence will be reset
@param mixed $value 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. | resetSequence | php | yiisoft/yii | framework/db/schema/cubrid/CCubridSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/cubrid/CCubridSchema.php | BSD-3-Clause |
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.
@param string $name table name
@return CCubridTableSchema driver dependent table metadata. Null if the table does not exist. | loadTable | php | yiisoft/yii | framework/db/schema/cubrid/CCubridSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/cubrid/CCubridSchema.php | BSD-3-Clause |
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.
@param CCubridTableSchema $table the table instance
@param string $name the unquoted table name | resolveTableNames | php | yiisoft/yii | framework/db/schema/cubrid/CCubridSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/cubrid/CCubridSchema.php | BSD-3-Clause |
protected function resolveTableNames($table,$name)
{
$parts=explode('.',str_replace('"','',$name));
if(isset($parts[1]))
{
$schemaName=$parts[0];
$tableName=$parts[1];
}
else
{
$schemaName=self::DEFAULT_SCHEMA;
$tableName=$parts[0];
}
$table->name=$tableName;
$table->schemaName=$schemaName;
if($schemaName===self::DEFAULT_SCHEMA)
$table->rawName=$this->quoteTableName($tableName);
else
$table->rawName=$this->quoteTableName($schemaName).'.'.$this->quoteTableName($tableName);
} | Generates various kinds of table names.
@param CPgsqlTableSchema $table the table instance
@param string $name the unquoted table name | resolveTableNames | php | yiisoft/yii | framework/db/schema/pgsql/CPgsqlSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/pgsql/CPgsqlSchema.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.