Class yii\db\sqlite\QueryBuilder

Inheritanceyii\db\sqlite\QueryBuilder » yii\db\QueryBuilder » yii\base\BaseObject
Implementsyii\base\Configurable
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/db/sqlite/QueryBuilder.php

QueryBuilder is the query builder for SQLite databases.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$db yii\db\Connection The database connection. yii\db\QueryBuilder
$separator string The separator between different fragments of a SQL statement. yii\db\QueryBuilder
$typeMap array Mapping from abstract column types (keys) to physical column types (values). yii\db\sqlite\QueryBuilder

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$conditionBuilders array Map of query condition to builder methods. yii\db\QueryBuilder
$conditionClasses array Map of condition aliases to condition classes. yii\db\QueryBuilder
$expressionBuilders string[]|yii\db\ExpressionBuilderInterface[] Maps expression class to expression builder class. yii\db\QueryBuilder

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\db\QueryBuilder
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__unset() Sets an object property to null. yii\base\BaseObject
addCheck() Creates a SQL command for adding a check constraint to an existing table. yii\db\sqlite\QueryBuilder
addColumn() Builds a SQL statement for adding a new DB column. yii\db\QueryBuilder
addCommentOnColumn() Builds a SQL command for adding comment to column. yii\db\sqlite\QueryBuilder
addCommentOnTable() Builds a SQL command for adding comment to table. yii\db\sqlite\QueryBuilder
addDefaultValue() Creates a SQL command for adding a default value constraint to an existing table. yii\db\sqlite\QueryBuilder
addForeignKey() Builds a SQL statement for adding a foreign key constraint to an existing table. yii\db\sqlite\QueryBuilder
addPrimaryKey() Builds a SQL statement for adding a primary key constraint to an existing table. yii\db\sqlite\QueryBuilder
addUnique() Creates a SQL command for adding an unique constraint to an existing table. yii\db\sqlite\QueryBuilder
alterColumn() Builds a SQL statement for changing the definition of a column. yii\db\sqlite\QueryBuilder
batchInsert() Generates a batch INSERT SQL statement. yii\db\sqlite\QueryBuilder
bindParam() Helper method to add $value to $params array using PARAM_PREFIX. yii\db\QueryBuilder
build() Generates a SELECT SQL statement from a yii\db\Query object. yii\db\sqlite\QueryBuilder
buildAndCondition() Connects two or more SQL expressions with the AND or OR operator. yii\db\QueryBuilder
buildBetweenCondition() Creates an SQL expressions with the BETWEEN operator. yii\db\QueryBuilder
buildColumns() Processes columns and properly quotes them if necessary. yii\db\QueryBuilder
buildCondition() Parses the condition specification and generates the corresponding SQL expression. yii\db\QueryBuilder
buildExistsCondition() Creates an SQL expressions with the EXISTS operator. yii\db\QueryBuilder
buildExpression() Builds given $expression yii\db\QueryBuilder
buildFrom() yii\db\QueryBuilder
buildGroupBy() yii\db\QueryBuilder
buildHashCondition() Creates a condition based on column-value pairs. yii\db\QueryBuilder
buildHaving() yii\db\QueryBuilder
buildInCondition() Creates an SQL expressions with the IN operator. yii\db\QueryBuilder
buildJoin() yii\db\QueryBuilder
buildLikeCondition() Creates an SQL expressions with the LIKE operator. yii\db\QueryBuilder
buildLimit() yii\db\sqlite\QueryBuilder
buildNotCondition() Inverts an SQL expressions with NOT operator. yii\db\QueryBuilder
buildOrderBy() yii\db\QueryBuilder
buildOrderByAndLimit() Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL. yii\db\QueryBuilder
buildSelect() yii\db\QueryBuilder
buildSimpleCondition() Creates an SQL expressions like "column" operator value. yii\db\QueryBuilder
buildUnion() yii\db\sqlite\QueryBuilder
buildWhere() yii\db\QueryBuilder
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
checkIntegrity() Enables or disables integrity check. yii\db\sqlite\QueryBuilder
className() Returns the fully qualified name of this class. yii\base\BaseObject
createConditionFromArray() Transforms $condition defined in array format (as described in yii\db\Query::where() to instance of \yii\db\yii\db\condition\ConditionInterface according to $conditionClasses map. yii\db\QueryBuilder
createIndex() Builds a SQL statement for creating a new index. yii\db\QueryBuilder
createTable() Builds a SQL statement for creating a new DB table. yii\db\QueryBuilder
createView() Creates a SQL View. yii\db\QueryBuilder
delete() Creates a DELETE SQL statement. yii\db\QueryBuilder
dropCheck() Creates a SQL command for dropping a check constraint. yii\db\sqlite\QueryBuilder
dropColumn() Builds a SQL statement for dropping a DB column. yii\db\sqlite\QueryBuilder
dropCommentFromColumn() Builds a SQL command for adding comment to column. yii\db\sqlite\QueryBuilder
dropCommentFromTable() Builds a SQL command for adding comment to table. yii\db\sqlite\QueryBuilder
dropDefaultValue() Creates a SQL command for dropping a default value constraint. yii\db\sqlite\QueryBuilder
dropForeignKey() Builds a SQL statement for dropping a foreign key constraint. yii\db\sqlite\QueryBuilder
dropIndex() Builds a SQL statement for dropping an index. yii\db\sqlite\QueryBuilder
dropPrimaryKey() Builds a SQL statement for removing a primary key constraint to an existing table. yii\db\sqlite\QueryBuilder
dropTable() Builds a SQL statement for dropping a DB table. yii\db\QueryBuilder
dropUnique() Creates a SQL command for dropping an unique constraint. yii\db\sqlite\QueryBuilder
dropView() Drops a SQL View. yii\db\QueryBuilder
executeResetSequence() Execute a SQL statement for resetting the sequence value of a table's primary key. yii\db\QueryBuilder
getColumnType() Converts an abstract column type into a physical column type. yii\db\QueryBuilder
getExpressionBuilder() Gets object of yii\db\ExpressionBuilderInterface that is suitable for $expression. yii\db\QueryBuilder
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\db\QueryBuilder
insert() Creates an INSERT SQL statement. yii\db\QueryBuilder
renameColumn() Builds a SQL statement for renaming a column. yii\db\sqlite\QueryBuilder
renameTable() Builds a SQL statement for renaming a DB table. yii\db\sqlite\QueryBuilder
resetSequence() Creates a SQL statement for resetting the sequence value of a table's primary key. yii\db\sqlite\QueryBuilder
selectExists() Creates a SELECT EXISTS() SQL statement. yii\db\QueryBuilder
setConditionClasses() Setter for $conditionClasses property. yii\db\QueryBuilder
setExpressionBuilders() Setter for $expressionBuilders property. yii\db\QueryBuilder
truncateTable() Builds a SQL statement for truncating a DB table. yii\db\sqlite\QueryBuilder
update() Creates an UPDATE SQL statement. yii\db\QueryBuilder
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. yii\db\sqlite\QueryBuilder

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
defaultConditionClasses() Contains array of default condition classes. Extend this method, if you want to change default condition classes for the query builder. See $conditionClasses docs for details. yii\db\QueryBuilder
defaultExpressionBuilders() 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. yii\db\sqlite\QueryBuilder
hasLimit() Checks to see if the given limit is effective. yii\db\QueryBuilder
hasOffset() Checks to see if the given offset is effective. yii\db\QueryBuilder
prepareInsertSelectSubQuery() Prepare select-subquery and field names for INSERT INTO . yii\db\QueryBuilder
prepareInsertValues() Prepares a VALUES part for an INSERT SQL statement. yii\db\QueryBuilder
prepareUpdateSets() Prepares a SET parts for an UPDATE SQL statement. yii\db\QueryBuilder
prepareUpsertColumns() yii\db\QueryBuilder

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
PARAM_PREFIX ':qp' The prefix for automatically generated query binding parameters. yii\db\QueryBuilder

Property Details

$typeMap public property

Mapping from abstract column types (keys) to physical column types (values).

public array $typeMap = [\yii\db\sqlite\Schema::TYPE_PK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', \yii\db\sqlite\Schema::TYPE_UPK => 'integer UNSIGNED PRIMARY KEY AUTOINCREMENT NOT NULL', \yii\db\sqlite\Schema::TYPE_BIGPK => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', \yii\db\sqlite\Schema::TYPE_UBIGPK => 'integer UNSIGNED 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)']

Method Details

addCheck() public method

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

public string addCheck ( $name, $table, $expression )
$name string

The name of the check constraint. The name will be properly quoted by the method.

$table string

The table that the check constraint will be added to. The name will be properly quoted by the method.

$expression string

The SQL of the CHECK constraint.

return string

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

throws yii\base\NotSupportedException

this is not supported by SQLite.

addCommentOnColumn() public method (available since version 2.0.8)

Builds a SQL command for adding comment to column.

public string addCommentOnColumn ( $table, $column, $comment )
$table string

The table whose column is to be commented. The table name will be properly quoted by the method.

$column string

The name of the column to be commented. The column name will be properly quoted by the method.

$comment string

The text of the comment to be added. The comment will be properly quoted by the method.

return string

The SQL statement for adding comment on column

throws yii\base\NotSupportedException
addCommentOnTable() public method (available since version 2.0.8)

Builds a SQL command for adding comment to table.

public string addCommentOnTable ( $table, $comment )
$table string

The table whose column is to be commented. The table name will be properly quoted by the method.

$comment string

The text of the comment to be added. The comment will be properly quoted by the method.

return string

The SQL statement for adding comment on table

throws yii\base\NotSupportedException
addDefaultValue() public method

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

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 string

The table that the default value constraint will be added to. The name will be properly quoted by the method.

$column string

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.

return string

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

throws yii\base\NotSupportedException

this is not supported by SQLite.

addForeignKey() public method

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 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

The ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL

$update string

The ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL

return string

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

throws yii\base\NotSupportedException

this is not supported by SQLite

addPrimaryKey() public method

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

public string addPrimaryKey ( $name, $table, $columns )
$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.

return string

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

throws yii\base\NotSupportedException

this is not supported by SQLite

addUnique() public method

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

public string addUnique ( $name, $table, $columns )
$name string

The name of the unique constraint. The name will be properly quoted by the method.

$table string

The table that the unique constraint will be added to. The name will be properly quoted by the method.

$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. The name will be properly quoted by the method.

return string

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

throws yii\base\NotSupportedException

this is not supported by SQLite.

alterColumn() public method

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

public string alterColumn ( $table, $column, $type )
$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() method will be invoked to convert abstract column type (if any) into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.

return string

The SQL statement for changing the definition of a column.

throws yii\base\NotSupportedException

this is not supported by SQLite

batchInsert() public method

Generates a batch INSERT SQL statement.

For example,

$connection->createCommand()->batchInsert('user', ['name', 'age'], [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
])->execute();

Note that the values in each row must match the corresponding column names.

public string batchInsert ( $table, $columns, $rows, &$params = [] )
$table string

The table that new rows will be inserted into.

$columns array

The column names

$rows array|Generator

The rows to be batch inserted into the table

$params
return string

The batch INSERT SQL statement

build() public method

Generates a SELECT SQL statement from a yii\db\Query object.

public array build ( $query, $params = [] )
$query yii\db\Query

The yii\db\Query object from which the SQL statement will be generated.

$params array

The 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 array

The 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.

buildLimit() public method

public string buildLimit ( $limit, $offset )
$limit integer
$offset integer
return string

The LIMIT and OFFSET clauses

buildUnion() public method

public string buildUnion ( $unions, &$params )
$unions array
$params array

The binding parameters to be populated

return string

The UNION clause built from yii\db\Query::$union.

checkIntegrity() public method

Enables or disables integrity check.

public string checkIntegrity ( $check true, $schema '', $table '' )
$check boolean

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.

return string

The SQL statement for checking integrity

throws yii\base\NotSupportedException

this is not supported by SQLite

defaultExpressionBuilders() protected method

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 array defaultExpressionBuilders ( )
dropCheck() public method

Creates a SQL command for dropping a check constraint.

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 string

The table whose check constraint is to be dropped. The name will be properly quoted by the method.

return string

The SQL statement for dropping a check constraint.

throws yii\base\NotSupportedException

this is not supported by SQLite.

dropColumn() public method

Builds a SQL statement for dropping a DB column.

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 string

The name of the column to be dropped. The name will be properly quoted by the method.

return string

The SQL statement for dropping a DB column.

throws yii\base\NotSupportedException

this is not supported by SQLite

dropCommentFromColumn() public method (available since version 2.0.8)

Builds a SQL command for adding comment to column.

public string dropCommentFromColumn ( $table, $column )
$table string

The table whose column is to be commented. The table name will be properly quoted by the method.

$column string

The name of the column to be commented. The column name will be properly quoted by the method.

return string

The SQL statement for adding comment on column

throws yii\base\NotSupportedException
dropCommentFromTable() public method (available since version 2.0.8)

Builds a SQL command for adding comment to table.

public string dropCommentFromTable ( $table )
$table string

The table whose column is to be commented. The table name will be properly quoted by the method.

return string

The SQL statement for adding comment on column

throws yii\base\NotSupportedException
dropDefaultValue() public method

Creates a SQL command for dropping a default value constraint.

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 string

The table whose default value constraint is to be dropped. The name will be properly quoted by the method.

return string

The SQL statement for dropping a default value constraint.

throws yii\base\NotSupportedException

this is not supported by SQLite.

dropForeignKey() public method

Builds a SQL statement for dropping a foreign key constraint.

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 string

The table whose foreign is to be dropped. The name will be properly quoted by the method.

return string

The SQL statement for dropping a foreign key constraint.

throws yii\base\NotSupportedException

this is not supported by SQLite

dropIndex() public method

Builds a SQL statement for dropping an index.

public string dropIndex ( $name, $table )
$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.

return string

The SQL statement for dropping an index.

dropPrimaryKey() public method

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

public string dropPrimaryKey ( $name, $table )
$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.

return string

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

throws yii\base\NotSupportedException

this is not supported by SQLite

dropUnique() public method

Creates a SQL command for dropping an unique constraint.

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 string

The table whose unique constraint is to be dropped. The name will be properly quoted by the method.

return string

The SQL statement for dropping an unique constraint.

throws yii\base\NotSupportedException

this is not supported by SQLite.

renameColumn() public method

Builds a SQL statement for renaming a column.

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

return string

The SQL statement for renaming a DB column.

throws yii\base\NotSupportedException

this is not supported by SQLite

renameTable() public method

Builds a SQL statement for renaming a DB table.

public string renameTable ( $table, $newName )
$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.

return string

The SQL statement for renaming a DB table.

resetSequence() public method

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.

public string resetSequence ( $tableName, $value null )
$tableName string

The name of the table whose primary key sequence will be reset

$value mixed

The value for the primary key of the next new row inserted. If this is not set, the next new row's primary key will have a value 1.

return string

The SQL statement for resetting sequence

throws yii\base\InvalidArgumentException

if the table does not exist or there is no sequence associated with the table.

truncateTable() public method

Builds a SQL statement for truncating a DB table.

public string truncateTable ( $table )
$table string

The table to be truncated. The name will be properly quoted by the method.

return string

The SQL statement for truncating a DB table.

upsert() public method

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' => 'http://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.

See also https://stackoverflow.com/questions/15277373/sqlite-upsert-update-or-insert/15277374#15277374.

public string upsert ( $table, $insertColumns, $updateColumns, &$params )
$table string

The table that new rows will be inserted into/updated in.

$insertColumns array|yii\db\Query

The column data (name => value) to be inserted into the table or instance of yii\db\Query to perform INSERT INTO ... SELECT SQL statement.

$updateColumns array|boolean

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 array

The binding parameters that will be generated by this method. They should be bound to the DB command later.

return string

The resulting SQL.

throws yii\base\NotSupportedException

if this is not supported by the underlying DBMS.