Class yii\db\oci\QueryBuilder

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

QueryBuilder is the query builder for Oracle 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\oci\QueryBuilder

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$conditionBuilders array Map of query condition to builder methods. yii\db\QueryBuilder
$likeEscapeCharacter string|null Character used to escape special characters in LIKE conditions. yii\db\oci\QueryBuilder
$likeEscapingReplacements array \ is initialized in buildLikeCondition() method since we need to choose replacement value based on yii\db\Schema::quoteValue(). yii\db\oci\QueryBuilder

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Object
__construct() Constructor. yii\db\QueryBuilder
__get() Returns the value of an object property. yii\base\Object
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Object
__set() Sets value of an object property. yii\base\Object
__unset() Sets an object property to null. yii\base\Object
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
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
alterColumn() Builds a SQL statement for changing the definition of a column. yii\db\oci\QueryBuilder
batchInsert() Generates a batch INSERT SQL statement. yii\db\oci\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
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\oci\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\Object
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Object
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\Object
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
delete() Creates a DELETE SQL statement. 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
dropForeignKey() Builds a SQL statement for dropping a foreign key constraint. yii\db\QueryBuilder
dropIndex() Builds a SQL statement for dropping an index. 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
getColumnType() Converts an abstract column type into a physical column type. yii\db\QueryBuilder
hasMethod() Returns a value indicating whether a method is defined. yii\base\Object
hasProperty() Returns a value indicating whether a property is defined. yii\base\Object
init() Initializes the object. yii\base\Object
insert() Creates an INSERT SQL statement. yii\db\oci\QueryBuilder
renameColumn() Builds a SQL statement for renaming a column. yii\db\QueryBuilder
renameTable() Builds a SQL statement for renaming a DB table. yii\db\oci\QueryBuilder
resetSequence() Creates a SQL statement for resetting the sequence value of a table's primary key. yii\db\oci\QueryBuilder
selectExists() Creates a SELECT EXISTS() SQL statement. yii\db\oci\QueryBuilder
truncateTable() Builds a SQL statement for truncating a DB table. yii\db\QueryBuilder
update() Creates an UPDATE SQL statement. yii\db\QueryBuilder

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
buildCompositeInCondition() Builds SQL for IN condition yii\db\QueryBuilder
buildSubqueryInCondition() Builds SQL for IN condition yii\db\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

Constants

Hide inherited constants

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

Property Details

$likeEscapeCharacter protected property

Character used to escape special characters in LIKE conditions. By default it's assumed to be \.

$likeEscapingReplacements protected property

Map of chars to their replacements in LIKE conditions. By default it's configured to escape %, _ and \ with \.

protected array $likeEscapingReplacements = ['%' => '!%''_' => '!_''!' => '!!']
$typeMap public property

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

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_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)']

Method Details

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.

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.

batchInsert() public method

Generates a batch INSERT SQL statement.

For example,

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

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

public string batchInsert ( $table, $columns, $rows )
$table string

The table that new rows will be inserted into.

$columns array

The column names

$rows array

The rows to be batch inserted into the table

return string

The batch INSERT SQL statement

buildLikeCondition() public method

Creates an SQL expressions with the LIKE operator.

public string buildLikeCondition ( $operator, $operands, &$params )
$operator string

The operator to use (e.g. LIKE, NOT LIKE, OR LIKE or OR NOT LIKE)

$operands array

An array of two or three operands

  • The first operand is the column name.
  • The second operand is a single value or an array of values that column value should be compared with. If it is an empty array the generated expression will be a false value if operator is LIKE or OR LIKE, and empty if operator is NOT LIKE or OR NOT LIKE.
  • An optional third operand can also be provided to specify how to escape special characters in the value(s). The operand should be an array of mappings from the special characters to their escaped counterparts. If this operand is not provided, a default escape mapping will be used. You may use false or an empty array to indicate the values are already escaped and no escape should be applied. Note that when using an escape mapping (or the third operand is not provided), the values will be automatically enclosed within a pair of percentage characters.
$params array

The binding parameters to be populated

return string

The generated SQL expression

throws yii\base\InvalidParamException

if wrong number of operands have been given.

buildOrderByAndLimit() public method

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\oci\Query::orderBy for more details on how to specify this parameter.

$limit integer

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

$offset integer

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

return string

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

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

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

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.

insert() public method

Creates an INSERT SQL statement.

For example,

$sql = $queryBuilder->insert('user', [
    'name' => 'Sam',
    'age' => 30,
], $params);

The method will properly escape the table and column names.

public string insert ( $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. Passing of \yii\db\oci\yii\db\Query is available since version 2.0.11.

$params array

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

return string

The INSERT SQL

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 ( $table, $value null )
$table string

The name of the table whose primary key sequence will be 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 a value 1.

return string

The SQL statement for resetting sequence

throws yii\base\NotSupportedException

if this is not supported by the underlying DBMS

selectExists() public method (available since version 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.