Class yii\db\sqlite\QueryBuilder
继承 | yii\db\sqlite\QueryBuilder » yii\db\QueryBuilder » yii\base\BaseObject |
---|---|
实现 | yii\base\Configurable |
可用版本自 | 2.0 |
源码 | https://github.com/yiichina/yii2/blob/api/framework/db/sqlite/QueryBuilder.php |
QueryBuilder 是 SQLite 数据库的查询构建器。
公共属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
$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 | 从抽象列类型(键)到物理列类型(值)的映射。 | yii\db\sqlite\QueryBuilder |
受保护的属性
属性 | 类型 | 描述 | 被定义在 |
---|---|---|---|
$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 |
公共方法
方法 | 描述 | 被定义在 |
---|---|---|
__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() | 构建用于将外键约束添加到已知的表的 SQL 语句。 该方法将确保正确引用表名和列名。 | yii\db\sqlite\QueryBuilder |
addPrimaryKey() | 构建用于将主键约束添加到现有表的 SQL 语句。 | yii\db\sqlite\QueryBuilder |
addUnique() | Creates a SQL command for adding an unique constraint to an existing table. | yii\db\sqlite\QueryBuilder |
alterColumn() | 构建用于更改列定义的 SQL 语句。 | yii\db\sqlite\QueryBuilder |
batchInsert() | 生成批量插入的 SQL 语句。 | 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() | 启用或禁用完整性检查。 | 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() | 构建用于删除 DB 列的 SQL 语句。 | 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() | 构建用于删除外键约束的 SQL 语句。 | yii\db\sqlite\QueryBuilder |
dropIndex() | 构建用于删除索引的 SQL 语句。 | yii\db\sqlite\QueryBuilder |
dropPrimaryKey() | 构建一个将主键约束从现有表移除的 SQL 语句。 | 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() | 构建用于重命名列的 SQL 语句。 | yii\db\sqlite\QueryBuilder |
renameTable() | 构建用于重命名 DB 表名的 SQL 语句。 | yii\db\sqlite\QueryBuilder |
resetSequence() | 创建用于重置表的主键序列的 SQL 语句。 序列将被重置, 以便插入的下一个新行的主键具有指定的值或其值为 1 。 | 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() | 构建用于截断数据库表的 SQL 语句。 | 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 |
受保护的方法
方法 | 描述 | 被定义在 |
---|---|---|
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 |
常量
常量 | 值 | 描述 | 被定义在 |
---|---|---|---|
PARAM_PREFIX | ':qp' | The prefix for automatically generated query binding parameters. | yii\db\QueryBuilder |
属性详情
从抽象列类型(键)到物理列类型(值)的映射。
方法详情
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 |
return | string | The SQL statement for adding a check constraint to an existing table. |
---|---|---|
throws | yii\base\NotSupportedException | SQLite 不支持这一点时抛出异常。 |
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 |
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 |
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 | SQLite 不支持这一点时抛出异常。 |
构建用于将外键约束添加到已知的表的 SQL 语句。 该方法将确保正确引用表名和列名。
public string addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null) | ||
$name | string | 外键约束名称。 |
$table | string | 要添加外键约束的表名。 |
$columns | string|array | 要添加约束的列名。 如果有多个列,请使用英文逗号分割它们或使用数组来表示它们。 |
$refTable | string | 外键引用的表。 |
$refColumns | string|array | 外键引用的列名。 如果有多个列,请使用英文逗号分隔它们或使用数组来表示它们。 |
$delete | string | ON DELETE 选项。大多数 DBMS 支持这些选项:RESTRICT,CASCADE,NO ACTION,SET DEFAULT,SET NULL |
$update | string | ON UPDATE 选项。大多数 DBMS 支持这些选项:RESTRICT,CASCADE,NO ACTION,SET DEFAULT,SET NULL |
return | string | 用于将外键约束添加到已知的表的 SQL 语句。 |
---|---|---|
throws | yii\base\NotSupportedException | SQLite 不支持这一点时抛出异常 |
构建用于将主键约束添加到现有表的 SQL 语句。
public string addPrimaryKey($name, $table, $columns) | ||
$name | string | 主键约束名称。 |
$table | string | 将主键约束添加到其中的表的表名。 |
$columns | string|array | 英文逗号分隔的字符串或主键所包含的l列数组。 |
return | string | 将主键约束添加到现有表的 SQL 语句。 |
---|---|---|
throws | yii\base\NotSupportedException | SQLite 不支持这一点时抛出异常 |
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 | SQLite 不支持这一点时抛出异常。 |
构建用于更改列定义的 SQL 语句。
public string alterColumn($table, $column, $type) | ||
$table | string | 要更改其列的表。表名将由该方法正确引用。 |
$column | string | 要更改的列的名称。该方法将正确引用该名称。 |
$type | string | 新的列类型。将调用 getColumnType() 方法将抽象列类型(如果有)转换为物理列类型。
任何未被识别为抽象类型的内容都将保存在生成的 SQL 语句中。
例如, |
return | string | 用于更改列定义的 SQL 语句。 |
---|---|---|
throws | yii\base\NotSupportedException | SQLite 不支持这一点时抛出异常 |
生成批量插入的 SQL 语句。
例如,
$connection->createCommand()->batchInsert('user', ['name', 'age'], [
['Tom', 30],
['Jane', 20],
['Linda', 25],
])->execute();
注意,每行中的值必须与相对应的列名称匹配。
public string batchInsert($table, $columns, $rows, &$params = []) | ||
$table | string | 将插入新行的表。 |
$columns | array | 列名 |
$rows | array|Generator | 要批量插入表中的行 |
$params | ||
return | string | 用于批量插入的 SQL 语句 |
---|
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 |
---|
public string buildLimit($limit, $offset) | ||
$limit | integer | |
$offset | integer | |
return | string | The LIMIT and OFFSET clauses |
---|
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. |
---|
启用或禁用完整性检查。
public string checkIntegrity($check = true, $schema = '', $table = '') | ||
$check | boolean | 是否开打或关闭完整性检查。 |
$schema | string | 表的数据库结构。对 SQLite 毫无意义。 |
$table | string | 表名。对 SQLite 毫无意义。 |
return | string | 用于完整性检查的 SQL 语句 |
---|---|---|
throws | yii\base\NotSupportedException | 如果 SQLite 不支持完整性检查,则抛出异常。 |
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() |
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 | SQLite 不支持这一点时抛出异常。 |
构建用于删除 DB 列的 SQL 语句。
public string dropColumn($table, $column) | ||
$table | string | 要删除其列的表名。该方法将正确引用该名称。 |
$column | string | 要删除的列的名称。该方法将正确引用该名称。 |
return | string | 用于删除 DB 列的 SQL 语句。 |
---|---|---|
throws | yii\base\NotSupportedException | 当 SQLite 不支持时抛出异常 |
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 |
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 |
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 | SQLite 不支持这一点时抛出异常。 |
构建用于删除外键约束的 SQL 语句。
public string dropForeignKey($name, $table) | ||
$name | string | 要被删除的外键约束的名称。该方法将正确引用该名称。 |
$table | string | 外删除其外键约束的表的表名。该方法将正确引用该名称。 |
return | string | 构建用于删除外键约束的 SQL 语句。 |
---|---|---|
throws | yii\base\NotSupportedException | SQLite 不支持这一点时抛出异常 |
构建用于删除索引的 SQL 语句。
public string dropIndex($name, $table) | ||
$name | string | 要删除的索引的名称。该方法将正确引用该名称。 |
$table | string | 要删除其索引的表的名称。该方法将正确引用该名称。 |
return | string | 用于删除索引的 SQL 语句。 |
---|
构建一个将主键约束从现有表移除的 SQL 语句。
public string dropPrimaryKey($name, $table) | ||
$name | string | 要被移除的主键约束的名称。 |
$table | string | 从中要移除主键约束的表的名称。 |
return | string | 将主键约束从现有表移除的 SQL 语句。 |
---|---|---|
throws | yii\base\NotSupportedException | SQLite 不支持这一点时抛出异常 |
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 | SQLite 不支持这一点时抛出异常。 |
构建用于重命名列的 SQL 语句。
public string renameColumn($table, $oldName, $newName) | ||
$table | string | 要重命名其列的表名。该方法将正确引用该名称。 |
$oldName | string | 要重命名的列的名称。该方法将正确引用该名称。 |
$newName | string | 要重命名的列的新的名称。该方法将正确引用该名称。 |
return | string | 用于重命名 DB 列的 SQL 语句。 |
---|---|---|
throws | yii\base\NotSupportedException | 当 SQLite 不支持时抛出异常 |
构建用于重命名 DB 表名的 SQL 语句。
public string renameTable($table, $newName) | ||
$table | string | 要重命名的表的名称。该方法将正确引用该名称。 |
$newName | string | 新的表名称。该方法将正确引用该名称。 |
return | string | 用于重命名 DB 表名的 SQL 语句。 |
---|
创建用于重置表的主键序列的 SQL 语句。 序列将被重置, 以便插入的下一个新行的主键具有指定的值或其值为 1 。
public string resetSequence($tableName, $value = null) | ||
$tableName | string | 将被重置主键序列的表名 |
$value | mixed | 插入下一新行的主键的值。如果 $value 未设置, 则插入下一新行的主键序列值将指定为 1 。 |
return | string | 用于重置序列的 SQL 语句 |
---|---|---|
throws | yii\base\InvalidArgumentException | 如果表不存在,或没有与表关联的序列,则抛出异常。 |
构建用于截断数据库表的 SQL 语句。
public string truncateTable($table) | ||
$table | string | 要截断的表。该方法将正确引用该名称。 |
return | string | 用于截断数据库表的 SQL 语句。 |
---|
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.
参见 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 |
$updateColumns | array|boolean | The column data (name => value) to be updated if they already exist.
If |
$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. |