Skip to content

QueryBuilder ​

Type
Class
Namespace
craft\db\pgsql
Inherits
craft\db\pgsql\QueryBuilder » yii\db\pgsql\QueryBuilder » yii\db\QueryBuilder » yii\base\BaseObject
Implements
yii\base\Configurable
Since
3.0.0

View source

Public Properties ​

PropertyDescription
dbcraft\db\Connection – Connection the DB connection that this command is associated with.
separatorstring – The separator between different fragments of a SQL statement.
typeMaparray – Mapping from abstract column types (keys) to physical column types (values).

db ​

Type
craft\db\Connection
Default value
null

Connection the DB connection that this command is associated with.

View source

Protected Properties ​

PropertyDescription
conditionBuildersarray – Map of query condition to builder methods.
conditionClassesarray – Map of condition aliases to condition classes.
expressionBuildersstring[], yii\db\ExpressionBuilderInterface – Maps expression class to expression builder class.

Public Methods ​

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

deleteDuplicates() ​

Since
3.5.2

Builds the SQL expression used to delete duplicate rows from a table.

View source

Arguments ​

  • $table (string) – The table where the data will be deleted from
  • $columns (string[]) – The column names that contain duplicate data
  • $pk (string) – The primary key column name

Returns ​

string – The SQL expression

dropTableIfExists() ​

Builds a SQL statement for dropping a DB table if it exists.

View source

Arguments ​

  • $table (string) – The table to be dropped. The name will be properly quoted by the method.

Returns ​

string – The SQL statement for dropping a DB table.

fixedOrder() ​

Builds the SQL expression used to return a DB result in a fixed order.

http://stackoverflow.com/a/1310188/684

View source

Arguments ​

  • $column (string) – The column name that contains the values.
  • $values (array) – The column values, in the order in which the rows should be returned in.

Returns ​

string – The SQL expression.

renameSequence() ​

Builds a SQL statement for renaming a DB sequence.

View source

Arguments ​

  • $oldName (string) – The sequence to be renamed. The name will be properly quoted by the method.
  • $newName (string) – The new sequence name. The name will be properly quoted by the method.

Returns ​

string – The SQL statement for renaming a DB table.

replace() ​

Builds a SQL statement for replacing some text with other text in a given table column.

View source

Arguments ​

  • $table (string) – The table to be updated.
  • $column (string) – The column to be searched.
  • $find (string) – The text to be searched for.
  • $replace (string) – The replacement text.
  • $condition (array, string) – The condition that will be put in the WHERE part. Please refer to yii\db\Query::where() on how to specify condition.
  • $params (array) – The binding parameters that will be generated by this method. They should be bound to the DB command later.

Returns ​

string – The SQL statement for replacing some text in a given table.

Protected Methods ​

MethodDescription
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.
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.
extractAlias()Extracts table alias if there is one or returns false
hasLimit()Checks to see if the given limit is effective.
hasOffset()Checks to see if the given offset is effective.
prepareInsertSelectSubQuery()Prepare select-subquery and field names for INSERT INTO ... SELECT SQL statement.
prepareInsertValues()Prepares a VALUES part for an INSERT SQL statement.
prepareUpdateSets()Prepares a SET parts for an UPDATE SQL statement.
prepareUpsertColumns()

Constants ​

ConstantDescription
INDEX_B_TREEDefines a B-tree index for createIndex().
INDEX_GINDefines a GIN index for createIndex().
INDEX_GISTDefines a GiST index for createIndex().
INDEX_HASHDefines a hash index for createIndex().
INDEX_UNIQUEDefines a UNIQUE index for createIndex().
PARAM_PREFIXThe prefix for automatically generated query binding parameters.