# QueryBuilder

> QueryBuilder is the query builder for SQLite databases.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › [sqlite](/docs/api/yii/db/sqlite/index.md) › QueryBuilder

| class | `yii\db\sqlite\QueryBuilder` |
| --- | --- |
| Extends | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) » [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| Implements | [`yii\base\Configurable`](/docs/api/yii/base/configurable/index.md) |
| Since | 2.0 |
| Source | [`framework/db/sqlite/QueryBuilder.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/sqlite/QueryBuilder.php#L28) |

QueryBuilder is the query builder for SQLite databases.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-db"></span>[`$db`](/docs/api/yii/db/querybuilder/index.md#property-db) | [`yii\db\Connection`](/docs/api/yii/db/connection/index.md) | The database connection. Default: `null`. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="property-separator"></span>[`$separator`](/docs/api/yii/db/querybuilder/index.md#property-separator) | `string` | The separator between different fragments of a SQL statement. Default: `' '`. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="property-typeMap"></span>`$typeMap` | `array` | Mapping from abstract column types (keys) to physical column types (values). Default: `[\yii\db\sqlite\Schema::TYPE_PK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', \yii\db\sqlite\Schema::TYPE_UPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', \yii\db\sqlite\Schema::TYPE_BIGPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', \yii\db\sqlite\Schema::TYPE_UBIGPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', \yii\db\sqlite\Schema::TYPE_CHAR => 'char(1)', \yii\db\sqlite\Schema::TYPE_STRING => 'varchar(255)', \yii\db\sqlite\Schema::TYPE_TEXT => 'text', \yii\db\sqlite\Schema::TYPE_TINYINT => 'tinyint', \yii\db\sqlite\Schema::TYPE_SMALLINT => 'smallint', \yii\db\sqlite\Schema::TYPE_INTEGER => 'integer', \yii\db\sqlite\Schema::TYPE_BIGINT => 'bigint', \yii\db\sqlite\Schema::TYPE_FLOAT => 'float', \yii\db\sqlite\Schema::TYPE_DOUBLE => 'double', \yii\db\sqlite\Schema::TYPE_DECIMAL => 'decimal(10,0)', \yii\db\sqlite\Schema::TYPE_DATETIME => 'datetime', \yii\db\sqlite\Schema::TYPE_TIMESTAMP => 'timestamp', \yii\db\sqlite\Schema::TYPE_TIME => 'time', \yii\db\sqlite\Schema::TYPE_DATE => 'date', \yii\db\sqlite\Schema::TYPE_BINARY => 'blob', \yii\db\sqlite\Schema::TYPE_BOOLEAN => 'boolean', \yii\db\sqlite\Schema::TYPE_MONEY => 'decimal(19,4)']`. | `QueryBuilder` |
| <span id="property-conditionClasses"></span>[`$conditionClasses`](/docs/api/yii/db/querybuilder/index.md#property-conditionClasses) protected | `array` | Map of condition aliases to condition classes. Default: `[]`. Available since 2.0.14. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="property-expressionBuilders"></span>[`$expressionBuilders`](/docs/api/yii/db/querybuilder/index.md#property-expressionBuilders) protected | `string[]\|`[`yii\db\ExpressionBuilderInterface`](/docs/api/yii/db/expressionbuilderinterface/index.md)`[]` | Maps expression class to expression builder class. Default: `[]`. Available since 2.0.14. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| <span id="method-__construct"></span>[`__construct()`](/docs/api/yii/db/querybuilder/index.md#method-__construct) | Constructor. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-__call"></span>[`__call()`](/docs/api/yii/base/baseobject/index.md#method-__call) | Calls the named method which is not a class method. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__get"></span>[`__get()`](/docs/api/yii/base/baseobject/index.md#method-__get) | Returns the value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__isset"></span>[`__isset()`](/docs/api/yii/base/baseobject/index.md#method-__isset) | Checks if a property is set, i.e. defined and not null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__set"></span>[`__set()`](/docs/api/yii/base/baseobject/index.md#method-__set) | Sets value of an object property. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-__unset"></span>[`__unset()`](/docs/api/yii/base/baseobject/index.md#method-__unset) | Sets an object property to null. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`addCheck()`](#method-addCheck) | Creates a SQL command for adding a check constraint to an existing table. | `QueryBuilder` |
| <span id="method-addColumn"></span>[`addColumn()`](/docs/api/yii/db/querybuilder/index.md#method-addColumn) | Builds a SQL statement for adding a new DB column. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`addCommentOnColumn()`](#method-addCommentOnColumn) | Builds a SQL command for adding comment to column. | `QueryBuilder` |
| [`addCommentOnTable()`](#method-addCommentOnTable) | Builds a SQL command for adding comment to table. | `QueryBuilder` |
| [`addDefaultValue()`](#method-addDefaultValue) | Creates a SQL command for adding a default value constraint to an existing table. | `QueryBuilder` |
| [`addForeignKey()`](#method-addForeignKey) | Builds a SQL statement for adding a foreign key constraint to an existing table. | `QueryBuilder` |
| [`addPrimaryKey()`](#method-addPrimaryKey) | Builds a SQL statement for adding a primary key constraint to an existing table. | `QueryBuilder` |
| [`addUnique()`](#method-addUnique) | Creates a SQL command for adding an unique constraint to an existing table. | `QueryBuilder` |
| [`alterColumn()`](#method-alterColumn) | Builds a SQL statement for changing the definition of a column. | `QueryBuilder` |
| <span id="method-batchInsert"></span>[`batchInsert()`](/docs/api/yii/db/querybuilder/index.md#method-batchInsert) | Generates a batch INSERT SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-bindParam"></span>[`bindParam()`](/docs/api/yii/db/querybuilder/index.md#method-bindParam) | Helper method to add $value to $params array using [`PARAM_PREFIX`](/docs/api/yii/db/querybuilder/index.md#const-PARAM_PREFIX). | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-build"></span>[`build()`](/docs/api/yii/db/querybuilder/index.md#method-build) | Generates a SELECT SQL statement from a [`Query`](/docs/api/yii/db/query/index.md) object. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildColumns"></span>[`buildColumns()`](/docs/api/yii/db/querybuilder/index.md#method-buildColumns) | Processes columns and properly quotes them if necessary. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildCondition"></span>[`buildCondition()`](/docs/api/yii/db/querybuilder/index.md#method-buildCondition) | Parses the condition specification and generates the corresponding SQL expression. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildExpression"></span>[`buildExpression()`](/docs/api/yii/db/querybuilder/index.md#method-buildExpression) | Builds given $expression | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildFrom"></span>[`buildFrom()`](/docs/api/yii/db/querybuilder/index.md#method-buildFrom) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildGroupBy"></span>[`buildGroupBy()`](/docs/api/yii/db/querybuilder/index.md#method-buildGroupBy) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildHaving"></span>[`buildHaving()`](/docs/api/yii/db/querybuilder/index.md#method-buildHaving) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildJoin"></span>[`buildJoin()`](/docs/api/yii/db/querybuilder/index.md#method-buildJoin) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`buildLimit()`](#method-buildLimit) |  | `QueryBuilder` |
| <span id="method-buildOrderBy"></span>[`buildOrderBy()`](/docs/api/yii/db/querybuilder/index.md#method-buildOrderBy) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildOrderByAndLimit"></span>[`buildOrderByAndLimit()`](/docs/api/yii/db/querybuilder/index.md#method-buildOrderByAndLimit) | Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildSelect"></span>[`buildSelect()`](/docs/api/yii/db/querybuilder/index.md#method-buildSelect) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`buildUnion()`](#method-buildUnion) |  | `QueryBuilder` |
| <span id="method-buildUnionOrderByAndLimit"></span>[`buildUnionOrderByAndLimit()`](/docs/api/yii/db/querybuilder/index.md#method-buildUnionOrderByAndLimit) | Builds the global ORDER BY and LIMIT/OFFSET clauses for a UNION query. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildWhere"></span>[`buildWhere()`](/docs/api/yii/db/querybuilder/index.md#method-buildWhere) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-buildWithQueries"></span>[`buildWithQueries()`](/docs/api/yii/db/querybuilder/index.md#method-buildWithQueries) |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-canGetProperty"></span>[`canGetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canGetProperty) | Returns a value indicating whether a property can be read. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-canSetProperty"></span>[`canSetProperty()`](/docs/api/yii/base/baseobject/index.md#method-canSetProperty) | Returns a value indicating whether a property can be set. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| [`checkIntegrity()`](#method-checkIntegrity) | Enables or disables integrity check. | `QueryBuilder` |
| <span id="method-className"></span>[`className()`](/docs/api/yii/base/baseobject/index.md#method-className) static | Returns the fully qualified name of this class. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-createConditionFromArray"></span>[`createConditionFromArray()`](/docs/api/yii/db/querybuilder/index.md#method-createConditionFromArray) | Transforms $condition defined in array format (as described in [`Query::where()`](/docs/api/yii/db/query/index.md#method-where) to instance of ConditionInterface according to [`$conditionClasses`](/docs/api/yii/db/querybuilder/index.md#property-conditionClasses) map. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`createIndex()`](#method-createIndex) | Builds a SQL statement for creating a new index. | `QueryBuilder` |
| <span id="method-createTable"></span>[`createTable()`](/docs/api/yii/db/querybuilder/index.md#method-createTable) | Builds a SQL statement for creating a new DB table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-createView"></span>[`createView()`](/docs/api/yii/db/querybuilder/index.md#method-createView) | Creates a SQL View. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-delete"></span>[`delete()`](/docs/api/yii/db/querybuilder/index.md#method-delete) | Creates a DELETE SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`dropCheck()`](#method-dropCheck) | Creates a SQL command for dropping a check constraint. | `QueryBuilder` |
| [`dropColumn()`](#method-dropColumn) | Builds a SQL statement for dropping a DB column. | `QueryBuilder` |
| [`dropCommentFromColumn()`](#method-dropCommentFromColumn) | Builds a SQL command for adding comment to column. | `QueryBuilder` |
| [`dropCommentFromTable()`](#method-dropCommentFromTable) | Builds a SQL command for adding comment to table. | `QueryBuilder` |
| [`dropDefaultValue()`](#method-dropDefaultValue) | Creates a SQL command for dropping a default value constraint. | `QueryBuilder` |
| [`dropForeignKey()`](#method-dropForeignKey) | Builds a SQL statement for dropping a foreign key constraint. | `QueryBuilder` |
| [`dropIndex()`](#method-dropIndex) | Builds a SQL statement for dropping an index. | `QueryBuilder` |
| [`dropPrimaryKey()`](#method-dropPrimaryKey) | Builds a SQL statement for removing a primary key constraint to an existing table. | `QueryBuilder` |
| <span id="method-dropTable"></span>[`dropTable()`](/docs/api/yii/db/querybuilder/index.md#method-dropTable) | Builds a SQL statement for dropping a DB table. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`dropUnique()`](#method-dropUnique) | Creates a SQL command for dropping an unique constraint. | `QueryBuilder` |
| <span id="method-dropView"></span>[`dropView()`](/docs/api/yii/db/querybuilder/index.md#method-dropView) | Drops a SQL View. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-executeResetSequence"></span>[`executeResetSequence()`](/docs/api/yii/db/querybuilder/index.md#method-executeResetSequence) | Execute a SQL statement for resetting the sequence value of a table's primary key. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-getColumnType"></span>[`getColumnType()`](/docs/api/yii/db/querybuilder/index.md#method-getColumnType) | Converts an abstract column type into a physical column type. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-getExpressionBuilder"></span>[`getExpressionBuilder()`](/docs/api/yii/db/querybuilder/index.md#method-getExpressionBuilder) | Gets object of [`ExpressionBuilderInterface`](/docs/api/yii/db/expressionbuilderinterface/index.md) that is suitable for $expression. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-hasMethod"></span>[`hasMethod()`](/docs/api/yii/base/baseobject/index.md#method-hasMethod) | Returns a value indicating whether a method is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-hasProperty"></span>[`hasProperty()`](/docs/api/yii/base/baseobject/index.md#method-hasProperty) | Returns a value indicating whether a property is defined. | [`yii\base\BaseObject`](/docs/api/yii/base/baseobject/index.md) |
| <span id="method-init"></span>[`init()`](/docs/api/yii/db/querybuilder/index.md#method-init) | Initializes the object. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-insert"></span>[`insert()`](/docs/api/yii/db/querybuilder/index.md#method-insert) | Creates an INSERT SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`renameColumn()`](#method-renameColumn) | Builds a SQL statement for renaming a column. | `QueryBuilder` |
| [`renameTable()`](#method-renameTable) | Builds a SQL statement for renaming a DB table. | `QueryBuilder` |
| [`resetSequence()`](#method-resetSequence) | Creates a SQL statement for resetting the sequence value of a table's primary key. | `QueryBuilder` |
| <span id="method-selectExists"></span>[`selectExists()`](/docs/api/yii/db/querybuilder/index.md#method-selectExists) | Creates a SELECT EXISTS() SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-setConditionClasses"></span>[`setConditionClasses()`](/docs/api/yii/db/querybuilder/index.md#method-setConditionClasses) | Setter for [`$conditionClasses`](/docs/api/yii/db/querybuilder/index.md#property-conditionClasses) property. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-setExpressionBuilders"></span>[`setExpressionBuilders()`](/docs/api/yii/db/querybuilder/index.md#method-setExpressionBuilders) | Setter for [`$expressionBuilders`](/docs/api/yii/db/querybuilder/index.md#property-expressionBuilders) property. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`truncateTable()`](#method-truncateTable) | Builds a SQL statement for truncating a DB table. | `QueryBuilder` |
| <span id="method-update"></span>[`update()`](/docs/api/yii/db/querybuilder/index.md#method-update) | Creates an UPDATE SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`upsert()`](#method-upsert) | 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. | `QueryBuilder` |
| [`concatUnionSql()`](#method-concatUnionSql) protected | Concatenates the first `SELECT` statement with the UNION clauses built by [`buildUnion()`](/docs/api/yii/db/sqlite/querybuilder/index.md#method-buildUnion). | `QueryBuilder` |
| <span id="method-defaultConditionClasses"></span>[`defaultConditionClasses()`](/docs/api/yii/db/querybuilder/index.md#method-defaultConditionClasses) protected | Contains array of default condition classes. Extend this method, if you want to change default condition classes for the query builder. See [`$conditionClasses`](/docs/api/yii/db/querybuilder/index.md#property-conditionClasses) docs for details. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| [`defaultExpressionBuilders()`](#method-defaultExpressionBuilders) protected | 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/api/yii/db/querybuilder/index.md#property-expressionBuilders) docs for details. | `QueryBuilder` |
| <span id="method-extractAlias"></span>[`extractAlias()`](/docs/api/yii/db/querybuilder/index.md#method-extractAlias) protected | Extracts table alias if there is one or returns false | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-hasLimit"></span>[`hasLimit()`](/docs/api/yii/db/querybuilder/index.md#method-hasLimit) protected | Checks to see if the given limit is effective. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-hasOffset"></span>[`hasOffset()`](/docs/api/yii/db/querybuilder/index.md#method-hasOffset) protected | Checks to see if the given offset is effective. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareInsertSelectSubQuery"></span>[`prepareInsertSelectSubQuery()`](/docs/api/yii/db/querybuilder/index.md#method-prepareInsertSelectSubQuery) protected | Prepare select-subquery and field names for INSERT INTO ... SELECT SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareInsertValues"></span>[`prepareInsertValues()`](/docs/api/yii/db/querybuilder/index.md#method-prepareInsertValues) protected | Prepares a `VALUES` part for an `INSERT` SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareSelectQuery"></span>[`prepareSelectQuery()`](/docs/api/yii/db/querybuilder/index.md#method-prepareSelectQuery) protected | Performs driver-specific preparation after [`Query::prepare()`](/docs/api/yii/db/query/index.md#method-prepare). | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareUpdateSets"></span>[`prepareUpdateSets()`](/docs/api/yii/db/querybuilder/index.md#method-prepareUpdateSets) protected | Prepares a `SET` parts for an `UPDATE` SQL statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareUpsertColumns"></span>[`prepareUpsertColumns()`](/docs/api/yii/db/querybuilder/index.md#method-prepareUpsertColumns) protected |  | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |
| <span id="method-prepareUpsertSets"></span>[`prepareUpsertSets()`](/docs/api/yii/db/querybuilder/index.md#method-prepareUpsertSets) protected | Prepares the `SET` assignments for the update branch of an upsert statement. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |

## Constants

| Constant | Value | Description | Defined by |
| --- | --- | --- | --- |
| <span id="const-PARAM_PREFIX"></span>[`PARAM_PREFIX`](/docs/api/yii/db/querybuilder/index.md#const-PARAM_PREFIX) | `':qp'` | The prefix for automatically generated query binding parameters. | [`yii\db\QueryBuilder`](/docs/api/yii/db/querybuilder/index.md) |

## Method details

### addCheck() <span id="method-addCheck"></span>

```php
public function addCheck(mixed $name, mixed $table, mixed $expression): string
```

Creates a SQL command for adding a check constraint to an existing table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the check constraint. The name will be properly quoted by the method. |
| `$table` | `mixed` | The table that the check constraint will be added to. The name will be properly quoted by the method. |
| `$expression` | `mixed` | The SQL of the `CHECK` constraint. |

**Returns**

`string`: The SQL statement for adding a check constraint to an existing table.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite.

**Since**

2.0.13

### addCommentOnColumn() <span id="method-addCommentOnColumn"></span>

```php
public function addCommentOnColumn(mixed $table, mixed $column, mixed $comment): string
```

Builds a SQL command for adding comment to column.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table whose column is to be commented. The table name will be properly quoted by the method. |
| `$column` | `mixed` | The name of the column to be commented. The column name will be properly quoted by the method. |
| `$comment` | `mixed` | The text of the comment to be added. The comment will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for adding comment on column

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md)

**Since**

2.0.8

### addCommentOnTable() <span id="method-addCommentOnTable"></span>

```php
public function addCommentOnTable(mixed $table, mixed $comment): string
```

Builds a SQL command for adding comment to table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table whose column is to be commented. The table name will be properly quoted by the method. |
| `$comment` | `mixed` | The text of the comment to be added. The comment will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for adding comment on table

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md)

**Since**

2.0.8

### addDefaultValue() <span id="method-addDefaultValue"></span>

```php
public function addDefaultValue(mixed $name, mixed $table, mixed $column, mixed $value): string
```

Creates a SQL command for adding a default value constraint to an existing table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the default value constraint. The name will be properly quoted by the method. |
| `$table` | `mixed` | The table that the default value constraint will be added to. The name will be properly quoted by the method. |
| `$column` | `mixed` | The name of the column to that the constraint will be added on. The name will be properly quoted by the method. |
| `$value` | `mixed` | Default value. |

**Returns**

`string`: The SQL statement for adding a default value constraint to an existing table.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite.

**Since**

2.0.13

### addForeignKey() <span id="method-addForeignKey"></span>

```php
public function addForeignKey(string $name, string $table, string|array $columns, string $refTable, string|array $refColumns, string|null $delete = null, string|null $update = null): string
```

Builds a SQL statement for adding a foreign key constraint to an existing table.

The method will properly quote the table and column names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the foreign key constraint. |
| `$table` | `string` | The table that the foreign key constraint will be added to. |
| `$columns` | `string\|array` | The 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` | `string` | The table that the foreign key references to. |
| `$refColumns` | `string\|array` | The 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\|null` | The ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL |
| `$update` | `string\|null` | The ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL |

**Returns**

`string`: The SQL statement for adding a foreign key constraint to an existing table.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite

### addPrimaryKey() <span id="method-addPrimaryKey"></span>

```php
public function addPrimaryKey(string $name, string $table, string|array $columns): string
```

Builds a SQL statement for adding a primary key constraint to an existing table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the primary key constraint. |
| `$table` | `string` | The table that the primary key constraint will be added to. |
| `$columns` | `string\|array` | Comma separated string or array of columns that the primary key will consist of. |

**Returns**

`string`: The SQL statement for adding a primary key constraint to an existing table.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite

### addUnique() <span id="method-addUnique"></span>

```php
public function addUnique(mixed $name, mixed $table, mixed $columns): string
```

Creates a SQL command for adding an unique constraint to an existing table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the unique constraint. The name will be properly quoted by the method. |
| `$table` | `mixed` | The table that the unique constraint will be added to. The name will be properly quoted by the method. |
| `$columns` | `mixed` | The 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. |

**Returns**

`string`: The SQL statement for adding an unique constraint to an existing table.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite.

**Since**

2.0.13

### alterColumn() <span id="method-alterColumn"></span>

```php
public function alterColumn(string $table, string $column, string $type): string
```

Builds a SQL statement for changing the definition of a column.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `string` | The table whose column is to be changed. The table name will be properly quoted by the method. |
| `$column` | `string` | The name of the column to be changed. The name will be properly quoted by the method. |
| `$type` | `string` | The new column type. The [`getColumnType()`](/docs/api/yii/db/querybuilder/index.md#method-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'. |

**Returns**

`string`: The SQL statement for changing the definition of a column.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite

### buildLimit() <span id="method-buildLimit"></span>

```php
public function buildLimit(mixed $limit, mixed $offset): string
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$limit` | `mixed` |  |
| `$offset` | `mixed` |  |

**Returns**

`string`: The LIMIT and OFFSET clauses

### buildUnion() <span id="method-buildUnion"></span>

```php
public function buildUnion(mixed $unions, mixed &$params): string
```

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$unions` | `mixed` |  |
| `$params` | `mixed` | The binding parameters to be populated |

**Returns**

`string`: The UNION clause built from [`Query::$union`](/docs/api/yii/db/query/index.md#property-union).

### checkIntegrity() <span id="method-checkIntegrity"></span>

```php
public function checkIntegrity(bool $check = true, string $schema = '', string $table = ''): string
```

Enables or disables integrity check.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$check` | `bool` | Whether to turn on or off the integrity check. |
| `$schema` | `string` | The schema of the tables. Meaningless for SQLite. |
| `$table` | `string` | The table name. Meaningless for SQLite. |

**Returns**

`string`: The SQL statement for checking integrity.

### createIndex() <span id="method-createIndex"></span>

```php
public function createIndex(mixed $name, mixed $table, mixed $columns, mixed $unique = false): string
```

Builds a SQL statement for creating a new index.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the index. The name will be properly quoted by the method. |
| `$table` | `mixed` | The table that the new index will be created for. The table name will be properly quoted by the method. |
| `$columns` | `mixed` | The 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` | `mixed` | Whether to add UNIQUE constraint on the created index. |

**Returns**

`string`: The SQL statement for creating a new index.

### dropCheck() <span id="method-dropCheck"></span>

```php
public function dropCheck(mixed $name, mixed $table): string
```

Creates a SQL command for dropping a check constraint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the check constraint to be dropped. The name will be properly quoted by the method. |
| `$table` | `mixed` | The table whose check constraint is to be dropped. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for dropping a check constraint.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite.

**Since**

2.0.13

### dropColumn() <span id="method-dropColumn"></span>

```php
public function dropColumn(string $table, string $column): string
```

Builds a SQL statement for dropping a DB column.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `string` | The table whose column is to be dropped. The name will be properly quoted by the method. |
| `$column` | `string` | The name of the column to be dropped. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for dropping a DB column.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite

### dropCommentFromColumn() <span id="method-dropCommentFromColumn"></span>

```php
public function dropCommentFromColumn(mixed $table, mixed $column): string
```

Builds a SQL command for adding comment to column.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table whose column is to be commented. The table name will be properly quoted by the method. |
| `$column` | `mixed` | The name of the column to be commented. The column name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for adding comment on column

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md)

**Since**

2.0.8

### dropCommentFromTable() <span id="method-dropCommentFromTable"></span>

```php
public function dropCommentFromTable(mixed $table): string
```

Builds a SQL command for adding comment to table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table whose column is to be commented. The table name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for adding comment on column

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md)

**Since**

2.0.8

### dropDefaultValue() <span id="method-dropDefaultValue"></span>

```php
public function dropDefaultValue(mixed $name, mixed $table): string
```

Creates a SQL command for dropping a default value constraint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the default value constraint to be dropped. The name will be properly quoted by the method. |
| `$table` | `mixed` | The table whose default value constraint is to be dropped. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for dropping a default value constraint.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite.

**Since**

2.0.13

### dropForeignKey() <span id="method-dropForeignKey"></span>

```php
public function dropForeignKey(string $name, string $table): string
```

Builds a SQL statement for dropping a foreign key constraint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the foreign key constraint to be dropped. The name will be properly quoted by the method. |
| `$table` | `string` | The table whose foreign is to be dropped. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for dropping a foreign key constraint.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite

### dropIndex() <span id="method-dropIndex"></span>

```php
public function dropIndex(string $name, string $table): string
```

Builds a SQL statement for dropping an index.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the index to be dropped. The name will be properly quoted by the method. |
| `$table` | `string` | The table whose index is to be dropped. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for dropping an index.

### dropPrimaryKey() <span id="method-dropPrimaryKey"></span>

```php
public function dropPrimaryKey(string $name, string $table): string
```

Builds a SQL statement for removing a primary key constraint to an existing table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `string` | The name of the primary key constraint to be removed. |
| `$table` | `string` | The table that the primary key constraint will be removed from. |

**Returns**

`string`: The SQL statement for removing a primary key constraint from an existing table.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite

### dropUnique() <span id="method-dropUnique"></span>

```php
public function dropUnique(mixed $name, mixed $table): string
```

Creates a SQL command for dropping an unique constraint.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$name` | `mixed` | The name of the unique constraint to be dropped. The name will be properly quoted by the method. |
| `$table` | `mixed` | The table whose unique constraint is to be dropped. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for dropping an unique constraint.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite.

**Since**

2.0.13

### renameColumn() <span id="method-renameColumn"></span>

```php
public function renameColumn(string $table, string $oldName, string $newName): string
```

Builds a SQL statement for renaming a column.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `string` | The table whose column is to be renamed. The name will be properly quoted by the method. |
| `$oldName` | `string` | The old name of the column. The name will be properly quoted by the method. |
| `$newName` | `string` | The new name of the column. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for renaming a DB column.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): this is not supported by SQLite

### renameTable() <span id="method-renameTable"></span>

```php
public function renameTable(string $table, string $newName): string
```

Builds a SQL statement for renaming a DB table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `string` | The table to be renamed. The name will be properly quoted by the method. |
| `$newName` | `string` | The new table name. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for renaming a DB table.

### resetSequence() <span id="method-resetSequence"></span>

```php
public function resetSequence(string $tableName, int|null $value = null): string
```

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 `1`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$tableName` | `string` | The name of the table whose primary key sequence will be reset. |
| `$value` | `int\|null` | The integer 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`. |

**Returns**

`string`: The SQL statement for resetting sequence.

**Throws**

- [`yii\base\InvalidArgumentException`](/docs/api/yii/base/invalidargumentexception/index.md): if the table does not exist or there is no sequence associated with the table.

### truncateTable() <span id="method-truncateTable"></span>

```php
public function truncateTable(string $table): string
```

Builds a SQL statement for truncating a DB table.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `string` | The table to be truncated. The name will be properly quoted by the method. |

**Returns**

`string`: The SQL statement for truncating a DB table.

### upsert() <span id="method-upsert"></span>

```php
public function upsert(mixed $table, mixed $insertColumns, mixed $updateColumns, mixed &$params): string
```

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/', // url is unique
    'visits' => 0,
], [
    'visits' => new \yii\db\Expression('visits + 1'),
], $params);
```

The method will properly escape the table and column names.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$table` | `mixed` | The table that new rows will be inserted into/updated in. |
| `$insertColumns` | `mixed` | The column data (name => value) to be inserted into the table or instance of [`Query`](/docs/api/yii/db/query/index.md) to perform `INSERT INTO ... SELECT` SQL statement. |
| `$updateColumns` | `mixed` | 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. |
| `$params` | `mixed` | The binding parameters that will be generated by this method. They should be bound to the DB command later. |

**Returns**

`string`: The resulting SQL.

**Throws**

- [`yii\base\NotSupportedException`](/docs/api/yii/base/notsupportedexception/index.md): if this is not supported by the underlying DBMS.

**Since**

2.0.14

**See also**

- <https://www.sqlite.org/lang_upsert.html>

### concatUnionSql() <span id="method-concatUnionSql"></span>

```php
protected function concatUnionSql(string $sql, string $union): string
```

Concatenates the first `SELECT` statement with the UNION clauses built by [`buildUnion()`](/docs/api/yii/db/sqlite/querybuilder/index.md#method-buildUnion).

SQLite does not support parenthesized UNION operands, so the first `SELECT` statement is left unwrapped.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$sql` | `string` | The SQL of the first `SELECT` statement. |
| `$union` | `string` | The UNION clauses. |

**Returns**

`string`: The compound SQL with the first statement parenthesized.

**Since**

22.0

### defaultExpressionBuilders() <span id="method-defaultExpressionBuilders"></span>

```php
protected function defaultExpressionBuilders(): array
```

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/api/yii/db/querybuilder/index.md#property-expressionBuilders) docs for details.

**Returns**

`array`

**Since**

2.0.14