没有命名空间的类 yii yii\base yii\behaviors yii\caching yii\captcha yii\console yii\console\controllers yii\console\widgets yii\data yii\db yii\db\conditions yii\db\cubrid yii\db\cubrid\conditions yii\db\mssql yii\db\mssql\conditions yii\db\mysql yii\db\oci yii\db\oci\conditions yii\db\pgsql yii\db\sqlite yii\db\sqlite\conditions yii\di yii\filters yii\filters\auth yii\grid yii\helpers yii\i18n yii\log yii\mail yii\mutex yii\rbac yii\rest yii\test yii\validators yii\web yii\widgets

Class yii\db\oci\QueryBuilder

继承yii\db\oci\QueryBuilder » yii\db\QueryBuilder » yii\base\BaseObject
实现yii\base\Configurable
可用版本自2.0
源码 https://github.com/yiichina/yii2/blob/api/framework/db/oci/QueryBuilder.php

QueryBuilder 类是 Oracle 数据库的查询构建器。

公共属性

隐藏继承的属性

属性类型描述被定义在
$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\oci\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\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\QueryBuilder
addCommentOnTable() Builds a SQL command for adding comment to table. yii\db\QueryBuilder
addDefaultValue() Creates a SQL command for adding a default value constraint to an existing table. yii\db\QueryBuilder
addForeignKey() Builds a SQL statement for adding a foreign key constraint to an existing table. yii\db\oci\QueryBuilder
addPrimaryKey() Builds a SQL statement for adding a primary key constraint to an existing table. yii\db\QueryBuilder
addUnique() Creates a SQL command for adding an unique constraint to an existing table. yii\db\QueryBuilder
alterColumn() 构建用于更改列定义的 SQL 语句。 yii\db\oci\QueryBuilder
batchInsert() 生成批量插入的 SQL 语句, yii\db\oci\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\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\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\oci\QueryBuilder
buildSelect() yii\db\QueryBuilder
buildSimpleCondition() Creates an SQL expressions like "column" operator value. yii\db\QueryBuilder
buildUnion() yii\db\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() Builds a SQL statement for enabling or disabling integrity check. yii\db\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\QueryBuilder
dropColumn() Builds a SQL statement for dropping a DB column. yii\db\QueryBuilder
dropCommentFromColumn() Builds a SQL command for adding comment to column. yii\db\oci\QueryBuilder
dropCommentFromTable() Builds a SQL command for adding comment to table. yii\db\oci\QueryBuilder
dropDefaultValue() Creates a SQL command for dropping a default value constraint. yii\db\QueryBuilder
dropForeignKey() Builds a SQL statement for dropping a foreign key constraint. yii\db\QueryBuilder
dropIndex() 构建用于删除索引的 SQL 语句。 yii\db\oci\QueryBuilder
dropPrimaryKey() Builds a SQL statement for removing a primary key constraint to an existing table. yii\db\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\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\oci\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\QueryBuilder
renameTable() 构建用于重命名数据库表的 SQL 语句。 yii\db\oci\QueryBuilder
resetSequence() Creates a SQL statement for resetting the sequence value of a table's primary key. yii\db\QueryBuilder
selectExists() Creates a SELECT EXISTS() SQL statement. yii\db\oci\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\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\oci\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\oci\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\oci\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

属性详情

$typeMap 公共 属性

从抽象列类型(键)到物理列类型(值)的映射。

public array $typeMap = [\yii\db\oci\Schema::TYPE_PK => 'NUMBER(10) NOT NULL PRIMARY KEY', \yii\db\oci\Schema::TYPE_UPK => 'NUMBER(10) UNSIGNED NOT NULL PRIMARY KEY', \yii\db\oci\Schema::TYPE_BIGPK => 'NUMBER(20) NOT NULL PRIMARY KEY', \yii\db\oci\Schema::TYPE_UBIGPK => 'NUMBER(20) UNSIGNED NOT NULL PRIMARY KEY', \yii\db\oci\Schema::TYPE_CHAR => 'CHAR(1)', \yii\db\oci\Schema::TYPE_STRING => 'VARCHAR2(255)', \yii\db\oci\Schema::TYPE_TEXT => 'CLOB', \yii\db\oci\Schema::TYPE_TINYINT => 'NUMBER(3)', \yii\db\oci\Schema::TYPE_SMALLINT => 'NUMBER(5)', \yii\db\oci\Schema::TYPE_INTEGER => 'NUMBER(10)', \yii\db\oci\Schema::TYPE_BIGINT => 'NUMBER(20)', \yii\db\oci\Schema::TYPE_FLOAT => 'NUMBER', \yii\db\oci\Schema::TYPE_DOUBLE => 'NUMBER', \yii\db\oci\Schema::TYPE_DECIMAL => 'NUMBER', \yii\db\oci\Schema::TYPE_DATETIME => 'TIMESTAMP', \yii\db\oci\Schema::TYPE_TIMESTAMP => 'TIMESTAMP', \yii\db\oci\Schema::TYPE_TIME => 'TIMESTAMP', \yii\db\oci\Schema::TYPE_DATE => 'DATE', \yii\db\oci\Schema::TYPE_BINARY => 'BLOB', \yii\db\oci\Schema::TYPE_BOOLEAN => 'NUMBER(1)', \yii\db\oci\Schema::TYPE_MONEY => 'NUMBER(19,4)']

方法详情

addForeignKey() 公共 方法

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.

alterColumn() 公共 方法

构建用于更改列定义的 SQL 语句。

public string alterColumn($table, $column, $type)
$table string

要更改其列的表。该方法将正确引用表名。

$column string

要更改的列的名称。该方法将正确引用该名称。

$type string

新的列类型。将调用 getColumnType() 方法转换抽象列类型(如果有)转换为物理列类型, 任何为被识别为抽象列类型的内容都将保留在生成的 SQL 语句中。 例如,string 被转换成 varchar(255),而 string not null 会被转换成 varchar(255) not null

return string

用于更改列定义的 SQL 语句。

batchInsert() 公共 方法

生成批量插入的 SQL 语句,

举个例子,

$sql = $queryBuilder->batchInsert('user', ['name', 'age'], [
    ['Tom', 30],
    ['Jane', 20],
    ['Linda', 25],
]);

请注意,每行中的值必须与相应的列名匹配。

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

要插入新行的表。

$columns array

列名

$rows array|Generator

要批量插入到表中的行

$params
return string

批量插入的 SQL 语句

buildOrderByAndLimit() 公共 方法

Builds the ORDER BY and LIMIT/OFFSET clauses and appends them to the given SQL.

public string buildOrderByAndLimit($sql, $orderBy, $limit, $offset)
$sql string

The existing SQL (without ORDER BY/LIMIT/OFFSET)

$orderBy array

The order by columns. See yii\db\Query::orderBy() for more details on how to specify this parameter.

$limit integer

The limit number. See yii\db\Query::limit() for more details.

$offset integer

The offset number. See yii\db\Query::offset() for more details.

return string

The SQL completed with ORDER BY/LIMIT/OFFSET (if any)

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.

protected array defaultExpressionBuilders()
dropCommentFromColumn() 公共 方法 (自版本 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

dropCommentFromTable() 公共 方法 (自版本 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

dropIndex() 公共 方法

构建用于删除索引的 SQL 语句。

public string dropIndex($name, $table)
$name string

要删除的索引的名称。该方法将正确引用该名称。

$table string

要删除其索引的表。该方法将正确引用该名称。

return string

用于删除索引的 SQL 语句。

executeResetSequence() 公共 方法

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 string

The name of the table whose primary key sequence is reset

$value array|string

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

throws yii\base\NotSupportedException

if this is not supported by the underlying DBMS

prepareInsertValues() 受保护 方法

Prepares a VALUES part for an INSERT SQL statement.

protected array prepareInsertValues($table, $columns, $params = [])
$table string

The table that new rows will be inserted into.

$columns array|yii\db\Query

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

$params array

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

return array

Array of column names, placeholders, values and params.

renameTable() 公共 方法

构建用于重命名数据库表的 SQL 语句。

public string renameTable($table, $newName)
$table string

要重命名的表。该方法将正确引用该名称。

$newName string

新的表名。该方法将正确引用该名称。

return string

用于重命名数据库表的 SQL 语句。

selectExists() 公共 方法 (自版本 2.0.8 可用)

Creates a SELECT EXISTS() SQL statement.

public string selectExists($rawSql)
$rawSql string

The subquery in a raw form to select from.

return string

The SELECT EXISTS() SQL statement.

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.

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://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm#SQLRF01606.

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.