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

View source

Public Properties

PropertyDescription
$dbyii\db\Connection – The database connection.
$separatorstring – The separator between different fragments of a SQL statement.
$typeMaparray – The abstract column types mapped to physical column types.

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 \craft\db\pgsql\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()
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 \craft\db\pgsql\Query::where() to instance of \craft\db\pgsql\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.
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.
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 \craft\db\pgsql\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.

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.

Signature

public string dropTableIfExists ( \craft\db\pgsql\string $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.

Signature

public string fixedOrder ( \craft\db\pgsql\string $column, array $values )

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.

Signature

public string renameSequence ( \craft\db\pgsql\string $oldName, \craft\db\pgsql\string $newName )

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 \craft\db\pgsql\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.

Signature

public string replace ( \craft\db\pgsql\string $table, \craft\db\pgsql\string $column, \craft\db\pgsql\string $find, \craft\db\pgsql\string $replace, $condition, array &$params )

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