QueryBuilder is the query builder for Oracle databases.
Defined in: yii\base\BaseObject::__call()
Calls the named method which is not a class method.
Do not call this method directly as it is a PHP magic method that will be implicitly called when an unknown method is being invoked.
public function __call($name, $params)
{
throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}
public void __construct ( $connection, $config = [] ) $connection yii\db\Connection
The database connection.
$config arrayName-value pairs that will be used to initialize the object properties
public function __construct($connection, $config = [])
{
$this->db = $connection;
parent::__construct($config);
}
Defined in: yii\base\BaseObject::__get()
Returns the value of an object property.
Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $object->property;
.
See also __set().
public function __get($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter();
} elseif (method_exists($this, 'set' . $name)) {
throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
}
throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}
public boolean __isset ( $name ) $name string
The property name or the event name
return booleanWhether the named property is set (not null).
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
}
return false;
}
Defined in: yii\base\BaseObject::__set()
Sets value of an object property.
Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $object->property = $value;
.
See also __get().
public function __set($name, $value)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
} else {
throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}
}
Defined in: yii\base\BaseObject::__unset()
Sets an object property to null.
Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($object->property)
.
Note that if the property is not defined, this method will do nothing. If the property is read-only, it will throw an exception.
See also https://www.php.net/manual/en/function.unset.php.
public function __unset($name)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter(null);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
}
}
public string addCheck ( $name, $table, $expression ) $name string
The name of the check constraint. The name will be properly quoted by the method.
$table stringThe table that the check constraint will be added to. The name will be properly quoted by the method.
$expression stringThe SQL of the CHECK
constraint.
The SQL statement for adding a check constraint to an existing table.
public function addCheck($name, $table, $expression)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' ADD CONSTRAINT '
. $this->db->quoteColumnName($name) . ' CHECK (' . $this->db->quoteSql($expression) . ')';
}
public string addColumn ( $table, $column, $type ) $table string
The table that the new column will be added to. The table name will be properly quoted by the method.
$column stringThe name of the new column. The name will be properly quoted by the method.
$type stringThe column type. The 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 stringThe SQL statement for adding a new column.
public function addColumn($table, $column, $type)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' ADD ' . $this->db->quoteColumnName($column) . ' '
. $this->getColumnType($type);
}
public string addDefaultValue ( $name, $table, $column, $value ) $name string
The name of the default value constraint. The name will be properly quoted by the method.
$table stringThe table that the default value constraint will be added to. The name will be properly quoted by the method.
$column stringThe name of the column to that the constraint will be added on. The name will be properly quoted by the method.
$value mixedDefault value.
return stringThe SQL statement for adding a default value constraint to an existing table.
throws yii\base\NotSupportedExceptionif this is not supported by the underlying DBMS.
public function addDefaultValue($name, $table, $column, $value)
{
throw new NotSupportedException($this->db->getDriverName() . ' does not support adding default value constraints.');
}
Builds a SQL statement for adding a foreign key constraint to an existing table.
The method will properly quote the table and column names.
public string addForeignKey ( $name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null ) $name stringThe name of the foreign key constraint.
$table stringThe table that the foreign key constraint will be added to.
$columns string|arrayThe name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or use an array to represent them.
$refTable stringThe table that the foreign key references to.
$refColumns string|arrayThe name of the column that the foreign key references to. If there are multiple columns, separate them with commas or use an array to represent them.
$delete string|nullThe ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
$update string|nullThe ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
return stringThe SQL statement for adding a foreign key constraint to an existing table.
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
{
$sql = 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' ADD CONSTRAINT ' . $this->db->quoteColumnName($name)
. ' FOREIGN KEY (' . $this->buildColumns($columns) . ')'
. ' REFERENCES ' . $this->db->quoteTableName($refTable)
. ' (' . $this->buildColumns($refColumns) . ')';
if ($delete !== null) {
$sql .= ' ON DELETE ' . $delete;
}
if ($update !== null) {
throw new Exception('Oracle does not support ON UPDATE clause.');
}
return $sql;
}
public string addPrimaryKey ( $name, $table, $columns ) $name string
The name of the primary key constraint.
$table stringThe table that the primary key constraint will be added to.
$columns string|arrayComma separated string or array of columns that the primary key will consist of.
return stringThe SQL statement for adding a primary key constraint to an existing table.
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->db->quoteColumnName($col);
}
return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' ADD CONSTRAINT '
. $this->db->quoteColumnName($name) . ' PRIMARY KEY ('
. implode(', ', $columns) . ')';
}
public string addUnique ( $name, $table, $columns ) $name string
The name of the unique constraint. The name will be properly quoted by the method.
$table stringThe table that the unique constraint will be added to. The name will be properly quoted by the method.
$columns string|arrayThe name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas. The name will be properly quoted by the method.
return stringThe SQL statement for adding an unique constraint to an existing table.
public function addUnique($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->db->quoteColumnName($col);
}
return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' ADD CONSTRAINT '
. $this->db->quoteColumnName($name) . ' UNIQUE ('
. implode(', ', $columns) . ')';
}
Builds a SQL statement for changing the definition of a column.
public string alterColumn ( $table, $column, $type ) $table stringThe table whose column is to be changed. The table name will be properly quoted by the method.
$column stringThe name of the column to be changed. The name will be properly quoted by the method.
$type stringThe new column type. The 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 stringThe SQL statement for changing the definition of a column.
public function alterColumn($table, $column, $type)
{
$type = $this->getColumnType($type);
return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' MODIFY ' . $this->db->quoteColumnName($column) . ' ' . $this->getColumnType($type);
}
Generates a batch INSERT SQL statement.
For example,
$sql = $queryBuilder->batchInsert('user', ['name', 'age'], [
['Tom', 30],
['Jane', 20],
['Linda', 25],
]);
Note that the values in each row must match the corresponding column names.
public string batchInsert ( $table, $columns, $rows, &$params = [] ) $table stringThe table that new rows will be inserted into.
$columns arrayThe column names
$rows array|GeneratorThe rows to be batch inserted into the table
$params return stringThe batch INSERT SQL statement
public function batchInsert($table, $columns, $rows, &$params = [])
{
if (empty($rows)) {
return '';
}
$schema = $this->db->getSchema();
if (($tableSchema = $schema->getTableSchema($table)) !== null) {
$columnSchemas = $tableSchema->columns;
} else {
$columnSchemas = [];
}
$values = [];
foreach ($rows as $row) {
$vs = [];
foreach ($row as $i => $value) {
if (isset($columns[$i], $columnSchemas[$columns[$i]])) {
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
}
if (is_string($value)) {
$value = $schema->quoteValue($value);
} elseif (is_float($value)) {
$value = StringHelper::floatToString($value);
} elseif ($value === false) {
$value = 0;
} elseif ($value === null) {
$value = 'NULL';
} elseif ($value instanceof ExpressionInterface) {
$value = $this->buildExpression($value, $params);
}
$vs[] = $value;
}
$values[] = '(' . implode(', ', $vs) . ')';
}
if (empty($values)) {
return '';
}
foreach ($columns as $i => $name) {
$columns[$i] = $schema->quoteColumnName($name);
}
$tableAndColumns = ' INTO ' . $schema->quoteTableName($table)
. ' (' . implode(', ', $columns) . ') VALUES ';
return 'INSERT ALL ' . $tableAndColumns . implode($tableAndColumns, $values) . ' SELECT 1 FROM SYS.DUAL';
}
public function bindParam($value, &$params)
{
$phName = self::PARAM_PREFIX . count($params);
$params[$phName] = $value;
return $phName;
}
public array build ( $query, $params = [] ) $query yii\db\Query
The yii\db\Query object from which the SQL statement will be generated.
$params arrayThe parameters to be bound to the generated SQL statement. These parameters will be included in the result with the additional parameters generated during the query building process.
return arrayThe generated SQL statement (the first array element) and the corresponding parameters to be bound to the SQL statement (the second array element). The parameters returned include those provided in $params
.
public function build($query, $params = [])
{
$query = $query->prepare($this);
$params = empty($params) ? $query->params : array_merge($params, $query->params);
$clauses = [
$this->buildSelect($query->select, $params, $query->distinct, $query->selectOption),
$this->buildFrom($query->from, $params),
$this->buildJoin($query->join, $params),
$this->buildWhere($query->where, $params),
$this->buildGroupBy($query->groupBy),
$this->buildHaving($query->having, $params),
];
$sql = implode($this->separator, array_filter($clauses));
$sql = $this->buildOrderByAndLimit($sql, $query->orderBy, $query->limit, $query->offset);
if (!empty($query->orderBy)) {
foreach ($query->orderBy as $expression) {
if ($expression instanceof ExpressionInterface) {
$this->buildExpression($expression, $params);
}
}
}
if (!empty($query->groupBy)) {
foreach ($query->groupBy as $expression) {
if ($expression instanceof ExpressionInterface) {
$this->buildExpression($expression, $params);
}
}
}
$union = $this->buildUnion($query->union, $params);
if ($union !== '') {
$sql = "($sql){$this->separator}$union";
}
$with = $this->buildWithQueries($query->withQueries, $params);
if ($with !== '') {
$sql = "$with{$this->separator}$sql";
}
return [$sql, $params];
}
Deprecated since 2.0.14. Use buildCondition()
instead.
The operator to use for connecting the given operands
$operands arrayThe SQL expressions to connect.
$params arrayThe binding parameters to be populated
return stringThe generated SQL expression
public function buildAndCondition($operator, $operands, &$params)
{
array_unshift($operands, $operator);
return $this->buildCondition($operands, $params);
}
Deprecated since 2.0.14. Use buildCondition()
instead.
The operator to use (e.g. BETWEEN
or NOT BETWEEN
)
The first operand is the column name. The second and third operands describe the interval that column value should be in.
$params arrayThe binding parameters to be populated
return stringThe generated SQL expression
throws yii\base\InvalidArgumentExceptionif wrong number of operands have been given.
public function buildBetweenCondition($operator, $operands, &$params)
{
array_unshift($operands, $operator);
return $this->buildCondition($operands, $params);
}
public function buildColumns($columns)
{
if (!is_array($columns)) {
if (strpos($columns, '(') !== false) {
return $columns;
}
$rawColumns = $columns;
$columns = preg_split('/\s*,\s*/', $columns, -1, PREG_SPLIT_NO_EMPTY);
if ($columns === false) {
throw new InvalidArgumentException("$rawColumns is not valid columns.");
}
}
foreach ($columns as $i => $column) {
if ($column instanceof ExpressionInterface) {
$columns[$i] = $this->buildExpression($column);
} elseif (strpos($column, '(') === false) {
$columns[$i] = $this->db->quoteColumnName($column);
}
}
return implode(', ', $columns);
}
public function buildCondition($condition, &$params)
{
if (is_array($condition)) {
if (empty($condition)) {
return '';
}
$condition = $this->createConditionFromArray($condition);
}
if ($condition instanceof ExpressionInterface) {
return $this->buildExpression($condition, $params);
}
return (string)$condition;
}
Deprecated since 2.0.14. Use buildCondition()
instead.
public function buildExistsCondition($operator, $operands, &$params)
{
array_unshift($operands, $operator);
return $this->buildCondition($operands, $params);
}
public function buildExpression(ExpressionInterface $expression, &$params = [])
{
$builder = $this->getExpressionBuilder($expression);
return $builder->build($expression, $params);
}
public function buildFrom($tables, &$params)
{
if (empty($tables)) {
return '';
}
$tables = $this->quoteTableNames($tables, $params);
return 'FROM ' . implode(', ', $tables);
}
public function buildGroupBy($columns)
{
if (empty($columns)) {
return '';
}
foreach ($columns as $i => $column) {
if ($column instanceof ExpressionInterface) {
$columns[$i] = $this->buildExpression($column);
} elseif (strpos($column, '(') === false) {
$columns[$i] = $this->db->quoteColumnName($column);
}
}
return 'GROUP BY ' . implode(', ', $columns);
}
Deprecated since 2.0.14. Use buildCondition()
instead.
public function buildHashCondition($condition, &$params)
{
return $this->buildCondition(new HashCondition($condition), $params);
}
public function buildHaving($condition, &$params)
{
$having = $this->buildCondition($condition, $params);
return $having === '' ? '' : 'HAVING ' . $having;
}
Deprecated since 2.0.14. Use buildCondition()
instead.
The operator to use (e.g. IN
or NOT IN
)
The first operand is the column name. If it is an array a composite IN condition will be generated. The second operand is an array of values that column value should be among. If it is an empty array the generated expression will be a false
value if operator is IN
and empty if operator is NOT IN
.
The binding parameters to be populated
return stringThe generated SQL expression
throws yii\db\Exceptionif wrong number of operands have been given.
public function buildInCondition($operator, $operands, &$params)
{
array_unshift($operands, $operator);
return $this->buildCondition($operands, $params);
}
public function buildJoin($joins, &$params)
{
if (empty($joins)) {
return '';
}
foreach ($joins as $i => $join) {
if (!is_array($join) || !isset($join[0], $join[1])) {
throw new Exception('A join clause must be specified as an array of join type, join table, and optionally join condition.');
}
list($joinType, $table) = $join;
$tables = $this->quoteTableNames((array)$table, $params);
$table = reset($tables);
$joins[$i] = "$joinType $table";
if (isset($join[2])) {
$condition = $this->buildCondition($join[2], $params);
if ($condition !== '') {
$joins[$i] .= ' ON ' . $condition;
}
}
}
return implode($this->separator, $joins);
}
Deprecated since 2.0.14. Use buildCondition()
instead.
The operator to use (e.g. LIKE
, NOT LIKE
, OR LIKE
or OR NOT LIKE
)
An array of two or three operands
false
value if operator is LIKE
or OR LIKE
, and empty if operator is NOT LIKE
or OR NOT LIKE
.false
or an empty array to indicate the values are already escaped and no escape should be applied. Note that when using an escape mapping (or the third operand is not provided), the values will be automatically enclosed within a pair of percentage characters.The binding parameters to be populated
return stringThe generated SQL expression
throws yii\base\InvalidArgumentExceptionif wrong number of operands have been given.
public function buildLikeCondition($operator, $operands, &$params)
{
array_unshift($operands, $operator);
return $this->buildCondition($operands, $params);
}
public function buildLimit($limit, $offset)
{
$sql = '';
if ($this->hasLimit($limit)) {
$sql = 'LIMIT ' . $limit;
}
if ($this->hasOffset($offset)) {
$sql .= ' OFFSET ' . $offset;
}
return ltrim($sql);
}
Deprecated since 2.0.14. Use buildCondition()
instead.
public function buildNotCondition($operator, $operands, &$params)
{
array_unshift($operands, $operator);
return $this->buildCondition($operands, $params);
}
public function buildOrderBy($columns)
{
if (empty($columns)) {
return '';
}
$orders = [];
foreach ($columns as $name => $direction) {
if ($direction instanceof ExpressionInterface) {
$orders[] = $this->buildExpression($direction);
} else {
$orders[] = $this->db->quoteColumnName($name) . ($direction === SORT_DESC ? ' DESC' : '');
}
}
return 'ORDER BY ' . implode(', ', $orders);
}
Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.
public function buildOrderByAndLimit($sql, $orderBy, $limit, $offset)
{
$orderBy = $this->buildOrderBy($orderBy);
if ($orderBy !== '') {
$sql .= $this->separator . $orderBy;
}
$filters = [];
if ($this->hasOffset($offset)) {
$filters[] = 'rowNumId > ' . $offset;
}
if ($this->hasLimit($limit)) {
$filters[] = 'rownum <= ' . $limit;
}
if (empty($filters)) {
return $sql;
}
$filter = implode(' AND ', $filters);
return <<<EOD
USER_SQL AS ($sql),
PAGINATION AS (SELECT USER_SQL.*, rownum as rowNumId FROM USER_SQL)
CT *
PAGINATION
E $filter
}
public function buildSelect($columns, &$params, $distinct = false, $selectOption = null)
{
$select = $distinct ? 'SELECT DISTINCT' : 'SELECT';
if ($selectOption !== null) {
$select .= ' ' . $selectOption;
}
if (empty($columns)) {
return $select . ' *';
}
foreach ($columns as $i => $column) {
if ($column instanceof ExpressionInterface) {
if (is_int($i)) {
$columns[$i] = $this->buildExpression($column, $params);
} else {
$columns[$i] = $this->buildExpression($column, $params) . ' AS ' . $this->db->quoteColumnName($i);
}
} elseif ($column instanceof Query) {
list($sql, $params) = $this->build($column, $params);
$columns[$i] = "($sql) AS " . $this->db->quoteColumnName($i);
} elseif (is_string($i) && $i !== $column) {
if (strpos($column, '(') === false) {
$column = $this->db->quoteColumnName($column);
}
$columns[$i] = "$column AS " . $this->db->quoteColumnName($i);
} elseif (strpos($column, '(') === false) {
if (preg_match('/^(.*?)(?i:\s+as\s+|\s+)([\w\-_\.]+)$/', $column, $matches)) {
$columns[$i] = $this->db->quoteColumnName($matches[1]) . ' AS ' . $this->db->quoteColumnName($matches[2]);
} else {
$columns[$i] = $this->db->quoteColumnName($column);
}
}
}
return $select . ' ' . implode(', ', $columns);
}
Deprecated since 2.0.14. Use buildCondition()
instead.
public function buildSimpleCondition($operator, $operands, &$params)
{
array_unshift($operands, $operator);
return $this->buildCondition($operands, $params);
}
public function buildUnion($unions, &$params)
{
if (empty($unions)) {
return '';
}
$result = '';
foreach ($unions as $i => $union) {
$query = $union['query'];
if ($query instanceof Query) {
list($unions[$i]['query'], $params) = $this->build($query, $params);
}
$result .= 'UNION ' . ($union['all'] ? 'ALL ' : '') . '( ' . $unions[$i]['query'] . ' ) ';
}
return trim($result);
}
public function buildWhere($condition, &$params)
{
$where = $this->buildCondition($condition, $params);
return $where === '' ? '' : 'WHERE ' . $where;
}
public string buildWithQueries ( $withs, &$params ) $withs array
Of configurations for each WITH query
$params arrayThe binding parameters to be populated
return stringCompiled WITH prefix of query including nested queries
public function buildWithQueries($withs, &$params)
{
if (empty($withs)) {
return '';
}
$recursive = false;
$result = [];
foreach ($withs as $i => $with) {
if ($with['recursive']) {
$recursive = true;
}
$query = $with['query'];
if ($query instanceof Query) {
list($with['query'], $params) = $this->build($query, $params);
}
$result[] = $with['alias'] . ' AS (' . $with['query'] . ')';
}
return 'WITH ' . ($recursive ? 'RECURSIVE ' : '') . implode(', ', $result);
}
Defined in: yii\base\BaseObject::canGetProperty()
Returns a value indicating whether a property can be read.
A property is readable if:
$checkVars
is true);See also canSetProperty().
public function canGetProperty($name, $checkVars = true)
{
return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}
Defined in: yii\base\BaseObject::canSetProperty()
Returns a value indicating whether a property can be set.
A property is writable if:
$checkVars
is true);See also canGetProperty().
public boolean canSetProperty ( $name, $checkVars = true ) $name stringThe property name
$checkVars booleanWhether to treat member variables as properties
return booleanWhether the property can be written
public function canSetProperty($name, $checkVars = true)
{
return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}
public string checkIntegrity ( $check = true, $schema = '', $table = '' ) $check boolean
Whether to turn on or off the integrity check.
$schema stringThe schema of the tables. Defaults to empty string, meaning the current or default schema.
$table stringThe table name. Defaults to empty string, meaning that no table will be changed.
return stringThe SQL statement for checking integrity
throws yii\base\NotSupportedExceptionif this is not supported by the underlying DBMS
public function checkIntegrity($check = true, $schema = '', $table = '')
{
throw new NotSupportedException($this->db->getDriverName() . ' does not support enabling/disabling integrity check.');
}
Deprecated since 2.0.14. On PHP >=5.5, use ::class
instead.
public static function className()
{
return get_called_class();
}
public function createConditionFromArray($condition)
{
if (isset($condition[0])) {
$operator = strtoupper(array_shift($condition));
if (isset($this->conditionClasses[$operator])) {
$className = $this->conditionClasses[$operator];
} else {
$className = 'yii\db\conditions\SimpleCondition';
}
return $className::fromArrayDefinition($operator, $condition);
}
return new HashCondition($condition);
}
public string createIndex ( $name, $table, $columns, $unique = false ) $name string
The name of the index. The name will be properly quoted by the method.
$table stringThe table that the new index will be created for. The table name will be properly quoted by the method.
$columns string|arrayThe column(s) that should be included in the index. If there are multiple columns, separate them with commas or use an array to represent them. Each column name will be properly quoted by the method, unless a parenthesis is found in the name.
$unique booleanWhether to add UNIQUE constraint on the created index.
return stringThe SQL statement for creating a new index.
public function createIndex($name, $table, $columns, $unique = false)
{
return ($unique ? 'CREATE UNIQUE INDEX ' : 'CREATE INDEX ')
. $this->db->quoteTableName($name) . ' ON '
. $this->db->quoteTableName($table)
. ' (' . $this->buildColumns($columns) . ')';
}
Defined in: yii\db\QueryBuilder::createTable()
Builds a SQL statement for creating a new DB table.
The columns in the new table should be specified as name-definition pairs (e.g. 'name' => 'string'), where name stands for a column name which will be properly quoted by the method, and definition stands for the column type which must contain an abstract DB type. The getColumnType() method will be invoked to convert any abstract type into a physical one.
If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly inserted into the generated SQL.
For example,
$sql = $queryBuilder->createTable('user', [
'id' => 'pk',
'name' => 'string',
'age' => 'integer',
'column_name double precision null default null',
]);
public string createTable ( $table, $columns, $options = null ) $table string
The name of the table to be created. The name will be properly quoted by the method.
$columns arrayThe columns (name => definition) in the new table.
$options string|nullAdditional SQL fragment that will be appended to the generated SQL.
return stringThe SQL statement for creating a new DB table.
public function createTable($table, $columns, $options = null)
{
$cols = [];
foreach ($columns as $name => $type) {
if (is_string($name)) {
$cols[] = "\t" . $this->db->quoteColumnName($name) . ' ' . $this->getColumnType($type);
} else {
$cols[] = "\t" . $type;
}
}
$sql = 'CREATE TABLE ' . $this->db->quoteTableName($table) . " (\n" . implode(",\n", $cols) . "\n)";
return $options === null ? $sql : $sql . ' ' . $options;
}
public function createView($viewName, $subQuery)
{
if ($subQuery instanceof Query) {
list($rawQuery, $params) = $this->build($subQuery);
array_walk(
$params,
function (&$param) {
$param = $this->db->quoteValue($param);
}
);
$subQuery = strtr($rawQuery, $params);
}
return 'CREATE VIEW ' . $this->db->quoteTableName($viewName) . ' AS ' . $subQuery;
}
protected function defaultConditionClasses()
{
return [
'NOT' => 'yii\db\conditions\NotCondition',
'AND' => 'yii\db\conditions\AndCondition',
'OR' => 'yii\db\conditions\OrCondition',
'BETWEEN' => 'yii\db\conditions\BetweenCondition',
'NOT BETWEEN' => 'yii\db\conditions\BetweenCondition',
'IN' => 'yii\db\conditions\InCondition',
'NOT IN' => 'yii\db\conditions\InCondition',
'LIKE' => 'yii\db\conditions\LikeCondition',
'NOT LIKE' => 'yii\db\conditions\LikeCondition',
'OR LIKE' => 'yii\db\conditions\LikeCondition',
'OR NOT LIKE' => 'yii\db\conditions\LikeCondition',
'EXISTS' => 'yii\db\conditions\ExistsCondition',
'NOT EXISTS' => 'yii\db\conditions\ExistsCondition',
];
}
Contains array of default expression builders. Extend this method and override it, if you want to change default expression builders for this query builder. See $expressionBuilders docs for details.
protected function defaultExpressionBuilders()
{
return array_merge(parent::defaultExpressionBuilders(), [
'yii\db\conditions\InCondition' => 'yii\db\oci\conditions\InConditionBuilder',
'yii\db\conditions\LikeCondition' => 'yii\db\oci\conditions\LikeConditionBuilder',
]);
}
Defined in: yii\db\QueryBuilder::delete()
Creates a DELETE SQL statement.
For example,
$sql = $queryBuilder->delete('user', 'status = 0');
The method will properly escape the table and column names.
public string delete ( $table, $condition, &$params ) $table stringThe table where the data will be deleted from.
$condition array|stringThe condition that will be put in the WHERE part. Please refer to yii\db\Query::where() on how to specify condition.
$params arrayThe binding parameters that will be modified by this method so that they can be bound to the DB command later.
return stringThe DELETE SQL
public function delete($table, $condition, &$params)
{
$sql = 'DELETE FROM ' . $this->db->quoteTableName($table);
$where = $this->buildWhere($condition, $params);
return $where === '' ? $sql : $sql . ' ' . $where;
}
public string dropCheck ( $name, $table ) $name string
The name of the check constraint to be dropped. The name will be properly quoted by the method.
$table stringThe table whose check constraint is to be dropped. The name will be properly quoted by the method.
return stringThe SQL statement for dropping a check constraint.
public function dropCheck($name, $table)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
}
public string dropColumn ( $table, $column ) $table string
The table whose column is to be dropped. The name will be properly quoted by the method.
$column stringThe name of the column to be dropped. The name will be properly quoted by the method.
return stringThe SQL statement for dropping a DB column.
public function dropColumn($table, $column)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP COLUMN ' . $this->db->quoteColumnName($column);
}
public string dropDefaultValue ( $name, $table ) $name string
The name of the default value constraint to be dropped. The name will be properly quoted by the method.
$table stringThe table whose default value constraint is to be dropped. The name will be properly quoted by the method.
return stringThe SQL statement for dropping a default value constraint.
throws yii\base\NotSupportedExceptionif this is not supported by the underlying DBMS.
public function dropDefaultValue($name, $table)
{
throw new NotSupportedException($this->db->getDriverName() . ' does not support dropping default value constraints.');
}
public string dropForeignKey ( $name, $table ) $name string
The name of the foreign key constraint to be dropped. The name will be properly quoted by the method.
$table stringThe table whose foreign is to be dropped. The name will be properly quoted by the method.
return stringThe SQL statement for dropping a foreign key constraint.
public function dropForeignKey($name, $table)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
}
Builds a SQL statement for dropping an index.
public string dropIndex ( $name, $table ) $name stringThe name of the index to be dropped. The name will be properly quoted by the method.
$table stringThe table whose index is to be dropped. The name will be properly quoted by the method.
return stringThe SQL statement for dropping an index.
public function dropIndex($name, $table)
{
return 'DROP INDEX ' . $this->db->quoteTableName($name);
}
public string dropPrimaryKey ( $name, $table ) $name string
The name of the primary key constraint to be removed.
$table stringThe table that the primary key constraint will be removed from.
return stringThe SQL statement for removing a primary key constraint from an existing table.
public function dropPrimaryKey($name, $table)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
}
public string dropTable ( $table ) $table string
The table to be dropped. The name will be properly quoted by the method.
return stringThe SQL statement for dropping a DB table.
public function dropTable($table)
{
return 'DROP TABLE ' . $this->db->quoteTableName($table);
}
public string dropUnique ( $name, $table ) $name string
The name of the unique constraint to be dropped. The name will be properly quoted by the method.
$table stringThe table whose unique constraint is to be dropped. The name will be properly quoted by the method.
return stringThe SQL statement for dropping an unique constraint.
public function dropUnique($name, $table)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);
}
public string dropView ( $viewName ) $viewName string
The name of the view to be dropped.
return stringThe DROP VIEW
SQL statement.
public function dropView($viewName)
{
return 'DROP VIEW ' . $this->db->quoteTableName($viewName);
}
Execute a SQL statement for resetting the sequence value of a table's primary key.
Reason for execute is that some databases (Oracle) need several queries to do so. The sequence is reset such that the primary key of the next new row inserted will have the specified value or the maximum existing value +1.
public void executeResetSequence ( $table, $value = null ) $table stringThe name of the table whose primary key sequence is reset
$value array|string|nullThe 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 maximum existing value +1.
throws yii\base\NotSupportedExceptionif this is not supported by the underlying DBMS
public function executeResetSequence($table, $value = null)
{
$tableSchema = $this->db->getTableSchema($table);
if ($tableSchema === null) {
throw new InvalidArgumentException("Unknown table: $table");
}
if ($tableSchema->sequenceName === null) {
throw new InvalidArgumentException("There is no sequence associated with table: $table");
}
if ($value !== null) {
$value = (int) $value;
} else {
if (count($tableSchema->primaryKey) > 1) {
throw new InvalidArgumentException("Can't reset sequence for composite primary key in table: $table");
}
$value = $this->db->useMaster(function (Connection $db) use ($tableSchema) {
return $db->createCommand(
'SELECT MAX("' . $tableSchema->primaryKey[0] . '") FROM "' . $tableSchema->name . '"'
)->queryScalar();
}) + 1;
}
$this->db->createCommand('DROP SEQUENCE "' . $tableSchema->sequenceName . '"')->execute();
$this->db->createCommand('CREATE SEQUENCE "' . $tableSchema->sequenceName . '" START WITH ' . $value
. ' INCREMENT BY 1 NOMAXVALUE NOCACHE')->execute();
}
Defined in: yii\db\QueryBuilder::getColumnType()
Converts an abstract column type into a physical column type.
The conversion is done using the type map specified in $typeMap. The following abstract column types are supported (using MySQL as an example to explain the corresponding physical types):
pk
: an auto-incremental primary key type, will be converted into "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY"bigpk
: an auto-incremental primary key type, will be converted into "bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY"upk
: an unsigned auto-incremental primary key type, will be converted into "int(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY"char
: char type, will be converted into "char(1)"string
: string type, will be converted into "varchar(255)"text
: a long string type, will be converted into "text"smallint
: a small integer type, will be converted into "smallint(6)"integer
: integer type, will be converted into "int(11)"bigint
: a big integer type, will be converted into "bigint(20)"boolean
: boolean type, will be converted into "tinyint(1)"float
`: float number type, will be converted into "float"decimal
: decimal number type, will be converted into "decimal"datetime
: datetime type, will be converted into "datetime"timestamp
: timestamp type, will be converted into "timestamp"time
: time type, will be converted into "time"date
: date type, will be converted into "date"money
: money type, will be converted into "decimal(19,4)"binary
: binary data type, will be converted into "blob"If the abstract type contains two or more parts separated by spaces (e.g. "string NOT NULL"), then only the first part will be converted, and the rest of the parts will be appended to the converted result. For example, 'string NOT NULL' is converted to 'varchar(255) NOT NULL'.
For some of the abstract types you can also specify a length or precision constraint by appending it in round brackets directly to the type. For example string(32)
will be converted into "varchar(32)" on a MySQL database. If the underlying DBMS does not support these kind of constraints for a type it will be ignored.
If a type cannot be found in $typeMap, it will be returned without any change.
public function getColumnType($type)
{
if ($type instanceof ColumnSchemaBuilder) {
$type = $type->__toString();
}
if (isset($this->typeMap[$type])) {
return $this->typeMap[$type];
} elseif (preg_match('/^(\w+)\((.+?)\)(.*)$/', $type, $matches)) {
if (isset($this->typeMap[$matches[1]])) {
return preg_replace('/\(.+\)/', '(' . $matches[2] . ')', $this->typeMap[$matches[1]]) . $matches[3];
}
} elseif (preg_match('/^(\w+)\s+/', $type, $matches)) {
if (isset($this->typeMap[$matches[1]])) {
return preg_replace('/^\w+/', $this->typeMap[$matches[1]], $type);
}
}
return $type;
}
public function getExpressionBuilder(ExpressionInterface $expression)
{
$className = get_class($expression);
if (!isset($this->expressionBuilders[$className])) {
foreach (array_reverse($this->expressionBuilders) as $expressionClass => $builderClass) {
if (is_subclass_of($expression, $expressionClass)) {
$this->expressionBuilders[$className] = $builderClass;
break;
}
}
if (!isset($this->expressionBuilders[$className])) {
throw new InvalidArgumentException('Expression of class ' . $className . ' can not be built in ' . get_class($this));
}
}
if ($this->expressionBuilders[$className] === __CLASS__) {
return $this;
}
if (!is_object($this->expressionBuilders[$className])) {
$this->expressionBuilders[$className] = new $this->expressionBuilders[$className]($this);
}
return $this->expressionBuilders[$className];
}
protected boolean hasLimit ( $limit ) $limit mixed
The given limit
return booleanWhether the limit is effective
protected function hasLimit($limit)
{
return ($limit instanceof ExpressionInterface) || ctype_digit((string)$limit);
}
Defined in: yii\base\BaseObject::hasMethod()
Returns a value indicating whether a method is defined.
The default implementation is a call to php function method_exists()
. You may override this method when you implemented the php magic method __call()
.
public function hasMethod($name)
{
return method_exists($this, $name);
}
protected boolean hasOffset ( $offset ) $offset mixed
The given offset
return booleanWhether the offset is effective
protected function hasOffset($offset)
{
return ($offset instanceof ExpressionInterface) || ctype_digit((string)$offset) && (string)$offset !== '0';
}
Defined in: yii\base\BaseObject::hasProperty()
Returns a value indicating whether a property is defined.
A property is defined if:
$checkVars
is true);See also:
public boolean hasProperty ( $name, $checkVars = true ) $name stringThe property name
$checkVars booleanWhether to treat member variables as properties
return booleanWhether the property is defined
public function hasProperty($name, $checkVars = true)
{
return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}
Defined in: yii\db\QueryBuilder::init()
Initializes the object.
This method is invoked at the end of the constructor after the object is initialized with the given configuration.
public function init()
{
parent::init();
$this->expressionBuilders = array_merge($this->defaultExpressionBuilders(), $this->expressionBuilders);
$this->conditionClasses = array_merge($this->defaultConditionClasses(), $this->conditionClasses);
}
Defined in: yii\db\QueryBuilder::insert()
Creates an INSERT SQL statement.
For example, `
php $sql = $queryBuilder->insert('user', [
'name' => 'Sam',
'age' => 30,
], $params); `
The method will properly escape the table and column names.
The table that new rows will be inserted into.
$columns array|yii\db\QueryThe column data (name => value) to be inserted into the table or instance of Query to perform INSERT INTO ... SELECT SQL statement. Passing of Query is available since version 2.0.11.
$params arrayThe binding parameters that will be generated by this method. They should be bound to the DB command later.
return stringThe INSERT SQL
public function insert($table, $columns, &$params)
{
list($names, $placeholders, $values, $params) = $this->prepareInsertValues($table, $columns, $params);
return 'INSERT INTO ' . $this->db->quoteTableName($table)
. (!empty($names) ? ' (' . implode(', ', $names) . ')' : '')
. (!empty($placeholders) ? ' VALUES (' . implode(', ', $placeholders) . ')' : $values);
}
protected array prepareInsertSelectSubQuery ( $columns, $schema, $params = [] ) $columns yii\db\Query
Object, which represents select query.
$schema yii\db\SchemaSchema object to quote column name.
$params arrayThe parameters to be bound to the generated SQL statement. These parameters will be included in the result with the additional parameters generated during the query building process.
return arrayArray of column names, values and params.
throws yii\base\InvalidArgumentExceptionif query's select does not contain named parameters only.
protected function prepareInsertSelectSubQuery($columns, $schema, $params = [])
{
if (!is_array($columns->select) || empty($columns->select) || in_array('*', $columns->select)) {
throw new InvalidArgumentException('Expected select query object with enumerated (named) parameters');
}
list($values, $params) = $this->build($columns, $params);
$names = [];
$values = ' ' . $values;
foreach ($columns->select as $title => $field) {
if (is_string($title)) {
$names[] = $schema->quoteColumnName($title);
} elseif (preg_match('/^(.*?)(?i:\s+as\s+|\s+)([\w\-_\.]+)$/', $field, $matches)) {
$names[] = $schema->quoteColumnName($matches[2]);
} else {
$names[] = $schema->quoteColumnName($field);
}
}
return [$names, $values, $params];
}
Prepares a VALUES
part for an INSERT
SQL statement.
The table that new rows will be inserted into.
$columns array|yii\db\QueryThe column data (name => value) to be inserted into the table or instance of Query to perform INSERT INTO ... SELECT SQL statement.
$params arrayThe binding parameters that will be generated by this method. They should be bound to the DB command later.
return arrayArray of column names, placeholders, values and params.
protected function prepareInsertValues($table, $columns, $params = [])
{
list($names, $placeholders, $values, $params) = parent::prepareInsertValues($table, $columns, $params);
if (!$columns instanceof Query && empty($names)) {
$tableSchema = $this->db->getSchema()->getTableSchema($table);
if ($tableSchema !== null) {
$columns = !empty($tableSchema->primaryKey) ? $tableSchema->primaryKey : [reset($tableSchema->columns)->name];
foreach ($columns as $name) {
$names[] = $this->db->quoteColumnName($name);
$placeholders[] = 'DEFAULT';
}
}
}
return [$names, $placeholders, $values, $params];
}
protected array prepareUpdateSets ( $table, $columns, $params = [] ) $table string
The table to be updated.
$columns arrayThe column data (name => value) to be updated.
$params arrayThe binding parameters that will be modified by this method so that they can be bound to the DB command later.
return arrayAn array SET
parts for an UPDATE
SQL statement (the first array element) and params (the second array element).
protected function prepareUpdateSets($table, $columns, $params = [])
{
$tableSchema = $this->db->getTableSchema($table);
$columnSchemas = $tableSchema !== null ? $tableSchema->columns : [];
$sets = [];
foreach ($columns as $name => $value) {
$value = isset($columnSchemas[$name]) ? $columnSchemas[$name]->dbTypecast($value) : $value;
if ($value instanceof ExpressionInterface) {
$placeholder = $this->buildExpression($value, $params);
} else {
$placeholder = $this->bindParam($value, $params);
}
$sets[] = $this->db->quoteColumnName($name) . '=' . $placeholder;
}
return [$sets, $params];
}
protected function prepareUpsertColumns($table, $insertColumns, $updateColumns, &$constraints = [])
{
if ($insertColumns instanceof Query) {
list($insertNames) = $this->prepareInsertSelectSubQuery($insertColumns, $this->db->getSchema());
} else {
$insertNames = array_map([$this->db, 'quoteColumnName'], array_keys($insertColumns));
}
$uniqueNames = $this->getTableUniqueColumnNames($table, $insertNames, $constraints);
$uniqueNames = array_map([$this->db, 'quoteColumnName'], $uniqueNames);
if ($updateColumns !== true) {
return [$uniqueNames, $insertNames, null];
}
return [$uniqueNames, $insertNames, array_diff($insertNames, $uniqueNames)];
}
public string renameColumn ( $table, $oldName, $newName ) $table string
The table whose column is to be renamed. The name will be properly quoted by the method.
$oldName stringThe old name of the column. The name will be properly quoted by the method.
$newName stringThe new name of the column. The name will be properly quoted by the method.
return stringThe SQL statement for renaming a DB column.
public function renameColumn($table, $oldName, $newName)
{
return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' RENAME COLUMN ' . $this->db->quoteColumnName($oldName)
. ' TO ' . $this->db->quoteColumnName($newName);
}
Defined in: yii\db\QueryBuilder::resetSequence()
Creates a SQL statement for resetting 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 the maximum existing value +1.
public string resetSequence ( $table, $value = null ) $table stringThe name of the table whose primary key sequence will be reset
$value array|string|nullThe 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 maximum existing value +1.
return stringThe SQL statement for resetting sequence
throws yii\base\NotSupportedExceptionif this is not supported by the underlying DBMS
public function resetSequence($table, $value = null)
{
throw new NotSupportedException($this->db->getDriverName() . ' does not support resetting sequence.');
}
Creates a SELECT EXISTS() SQL statement.
public function selectExists($rawSql)
{
return 'SELECT CASE WHEN EXISTS(' . $rawSql . ') THEN 1 ELSE 0 END FROM DUAL';
}
public void setConditionClasses ( $classes ) $classes string[]
Map of condition aliases to condition classes. For example:
['LIKE' => yii\db\condition\LikeCondition::class]
public function setConditionClasses($classes)
{
$this->conditionClasses = array_merge($this->conditionClasses, $classes);
}
public function setExpressionBuilders($builders)
{
$this->expressionBuilders = array_merge($this->expressionBuilders, $builders);
}
public string truncateTable ( $table ) $table string
The table to be truncated. The name will be properly quoted by the method.
return stringThe SQL statement for truncating a DB table.
public function truncateTable($table)
{
return 'TRUNCATE TABLE ' . $this->db->quoteTableName($table);
}
Defined in: yii\db\QueryBuilder::update()
Creates an UPDATE SQL statement.
For example,
$params = [];
$sql = $queryBuilder->update('user', ['status' => 1], 'age > 30', $params);
The method will properly escape the table and column names.
public string update ( $table, $columns, $condition, &$params ) $table stringThe table to be updated.
$columns arrayThe column data (name => value) to be updated.
$condition array|stringThe condition that will be put in the WHERE part. Please refer to yii\db\Query::where() on how to specify condition.
$params arrayThe binding parameters that will be modified by this method so that they can be bound to the DB command later.
return stringThe UPDATE SQL
public function update($table, $columns, $condition, &$params)
{
list($lines, $params) = $this->prepareUpdateSets($table, $columns, $params);
$sql = 'UPDATE ' . $this->db->quoteTableName($table) . ' SET ' . implode(', ', $lines);
$where = $this->buildWhere($condition, $params);
return $where === '' ? $sql : $sql . ' ' . $where;
}
Creates an SQL statement to insert rows into a database table if they do not already exist (matching unique constraints), or update them if they do.
For example,
$sql = $queryBuilder->upsert('pages', [
'name' => 'Front page',
'url' => 'https://example.com/',
'visits' => 0,
], [
'visits' => new \yii\db\Expression('visits + 1'),
], $params);
The method will properly escape the table and column names.
See also https://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606.
public string upsert ( $table, $insertColumns, $updateColumns, &$params ) $table stringThe table that new rows will be inserted into/updated in.
$insertColumns array|yii\db\QueryThe column data (name => value) to be inserted into the table or instance of yii\db\Query to perform INSERT INTO ... SELECT
SQL statement.
The column data (name => value) to be updated if they already exist. If true
is passed, the column data will be updated to match the insert column data. If false
is passed, no update will be performed if the column data already exists.
The binding parameters that will be generated by this method. They should be bound to the DB command later.
return stringThe resulting SQL.
throws yii\base\NotSupportedExceptionif this is not supported by the underlying DBMS.
public function upsert($table, $insertColumns, $updateColumns, &$params)
{
list($uniqueNames, $insertNames, $updateNames) = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns, $constraints);
if (empty($uniqueNames)) {
return $this->insert($table, $insertColumns, $params);
}
if ($updateNames === []) {
$updateColumns = false;
}
$onCondition = ['or'];
$quotedTableName = $this->db->quoteTableName($table);
foreach ($constraints as $constraint) {
$constraintCondition = ['and'];
foreach ($constraint->columnNames as $name) {
$quotedName = $this->db->quoteColumnName($name);
$constraintCondition[] = "$quotedTableName.$quotedName=\"EXCLUDED\".$quotedName";
}
$onCondition[] = $constraintCondition;
}
$on = $this->buildCondition($onCondition, $params);
list(, $placeholders, $values, $params) = $this->prepareInsertValues($table, $insertColumns, $params);
if (!empty($placeholders)) {
$usingSelectValues = [];
foreach ($insertNames as $index => $name) {
$usingSelectValues[$name] = new Expression($placeholders[$index]);
}
$usingSubQuery = (new Query())
->select($usingSelectValues)
->from('DUAL');
list($usingValues, $params) = $this->build($usingSubQuery, $params);
}
$mergeSql = 'MERGE INTO ' . $this->db->quoteTableName($table) . ' '
. 'USING (' . (isset($usingValues) ? $usingValues : ltrim($values, ' ')) . ') "EXCLUDED" '
. "ON ($on)";
$insertValues = [];
foreach ($insertNames as $name) {
$quotedName = $this->db->quoteColumnName($name);
if (strrpos($quotedName, '.') === false) {
$quotedName = '"EXCLUDED".' . $quotedName;
}
$insertValues[] = $quotedName;
}
$insertSql = 'INSERT (' . implode(', ', $insertNames) . ')'
. ' VALUES (' . implode(', ', $insertValues) . ')';
if ($updateColumns === false) {
return "$mergeSql WHEN NOT MATCHED THEN $insertSql";
}
if ($updateColumns === true) {
$updateColumns = [];
foreach ($updateNames as $name) {
$quotedName = $this->db->quoteColumnName($name);
if (strrpos($quotedName, '.') === false) {
$quotedName = '"EXCLUDED".' . $quotedName;
}
$updateColumns[$name] = new Expression($quotedName);
}
}
list($updates, $params) = $this->prepareUpdateSets($table, $updateColumns, $params);
$updateSql = 'UPDATE SET ' . implode(', ', $updates);
return "$mergeSql WHEN MATCHED THEN $updateSql WHEN NOT MATCHED THEN $insertSql";
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4