MediaWiki master
Wikimedia\Rdbms\DeleteQueryBuilder Class Reference

A query builder for DELETE queries with a fluent interface. More...

Collaboration diagram for Wikimedia\Rdbms\DeleteQueryBuilder:

Public Member Functions

 __construct (IDatabase $db)
 Only for use in subclasses and Database::newDeleteQueryBuilder.
 
 andWhere ( $conds)
 Add conditions to the query.
 
 caller (string $fname)
 Set the method name to be included in an SQL comment.
 
 conds ( $conds)
 Add conditions to the query.
 
 connection (IDatabase $db)
 Change the IDatabase object the query builder is bound to.
 
 delete (string $table)
 Set table for the query.
 
 deleteFrom (string $table)
 Set table for the query.
 
 execute ()
 Run the constructed DELETE query.
 
 getQueryInfo ()
 Get an associative array describing the query in terms of its raw parameters to IDatabase::delete().
 
 queryInfo (array $info)
 Set the query parameters to the given values, appending to the values which were already set.
 
 table (string $table)
 Manually set the table name to be passed to IDatabase::delete()
 
 where ( $conds)
 Add conditions to the query.
 

Protected Attributes

IDatabase $db
 

Detailed Description

A query builder for DELETE queries with a fluent interface.

Any particular query builder object should only be used for a single database query, and not be reused afterwards. However, to run multiple similar queries, you can create a “template” query builder to set up most of the query, and then clone the object (and potentially modify the clone) for each individual query.

Stability: stable
to extend
Since
1.41

Definition at line 23 of file DeleteQueryBuilder.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\DeleteQueryBuilder::__construct ( IDatabase $db)

Only for use in subclasses and Database::newDeleteQueryBuilder.

To create a DeleteQueryBuilder instance, use $db->newDeleteQueryBuilder() instead.

Parameters
IDatabase$db

Definition at line 47 of file DeleteQueryBuilder.php.

References Wikimedia\Rdbms\DeleteQueryBuilder\$db.

Member Function Documentation

◆ andWhere()

Wikimedia\Rdbms\DeleteQueryBuilder::andWhere ( $conds)

Add conditions to the query.

Alias for where().

Parameters
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>|RawSQLValue>|array<int,string|IExpression>$conds
Returns
$this

Definition at line 193 of file DeleteQueryBuilder.php.

◆ caller()

Wikimedia\Rdbms\DeleteQueryBuilder::caller ( string $fname)

Set the method name to be included in an SQL comment.

Parameters
string$fname
Returns
$this

Definition at line 215 of file DeleteQueryBuilder.php.

◆ conds()

Wikimedia\Rdbms\DeleteQueryBuilder::conds ( $conds)

Add conditions to the query.

Alias for where().

Parameters
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>|RawSQLValue>|array<int,string|IExpression>$conds
Returns
$this

Definition at line 204 of file DeleteQueryBuilder.php.

◆ connection()

Wikimedia\Rdbms\DeleteQueryBuilder::connection ( IDatabase $db)

Change the IDatabase object the query builder is bound to.

The specified IDatabase will subsequently be used to execute the query.

Parameters
IDatabase$db
Returns
$this

Definition at line 58 of file DeleteQueryBuilder.php.

◆ delete()

Wikimedia\Rdbms\DeleteQueryBuilder::delete ( string $table)

Set table for the query.

Alias for table().

Parameters
string$tableThe unqualified name of a table
Returns
$this

Definition at line 125 of file DeleteQueryBuilder.php.

◆ deleteFrom()

Wikimedia\Rdbms\DeleteQueryBuilder::deleteFrom ( string $table)

Set table for the query.

Alias for table().

Parameters
string$tableThe unqualified name of a table
Returns
$this

Definition at line 114 of file DeleteQueryBuilder.php.

◆ execute()

Wikimedia\Rdbms\DeleteQueryBuilder::execute ( )

Run the constructed DELETE query.

Definition at line 223 of file DeleteQueryBuilder.php.

◆ getQueryInfo()

Wikimedia\Rdbms\DeleteQueryBuilder::getQueryInfo ( )

Get an associative array describing the query in terms of its raw parameters to IDatabase::delete().

This can be used to interface with legacy code.

Returns
array The query info array, with keys:
  • table: The table name
  • conds: The conditions
  • caller: The caller signature

Definition at line 244 of file DeleteQueryBuilder.php.

◆ queryInfo()

Wikimedia\Rdbms\DeleteQueryBuilder::queryInfo ( array $info)

Set the query parameters to the given values, appending to the values which were already set.

This can be used to interface with legacy code. If a key is omitted, the previous value will be retained.

The parameters must be formatted as required by Database::delete.

Parameters
array$infoAssociative array of query info, with keys:
  • table: The table name to be passed to IDatabase::delete()
  • conds: The conditions
  • caller: The caller signature
Returns
$this

Definition at line 82 of file DeleteQueryBuilder.php.

◆ table()

Wikimedia\Rdbms\DeleteQueryBuilder::table ( string $table)

Manually set the table name to be passed to IDatabase::delete()

Parameters
string$tableThe unqualified name of a table
Returns
$this

Definition at line 102 of file DeleteQueryBuilder.php.

◆ where()

Wikimedia\Rdbms\DeleteQueryBuilder::where ( $conds)

Add conditions to the query.

The supplied conditions will be appended to the existing conditions, separated by AND.

Parameters
string|IExpression|array<string,?scalar|non-empty-array<int,?scalar>|RawSQLValue>|array<int,string|IExpression>$conds

May be either a string containing a single condition, or an array of conditions. If an array is given, the conditions constructed from each element are combined with AND.

Array elements may take one of two forms:

  • Elements with a numeric key are interpreted as raw SQL fragments.
  • Elements with a string key are interpreted as equality conditions, where the key is the field name.
    • If the value of such an array element is a scalar (such as a string), it will be treated as data and thus quoted appropriately. If it is null, an IS NULL clause will be added.
    • If the value is an array, an IN (...) clause will be constructed from its non-null elements, and an IS NULL clause will be added if null is present, such that the field may match any of the elements in the array. The non-null elements will be quoted.

Note that expressions are often DBMS-dependent in their syntax. DBMS-independent wrappers are provided for constructing several types of expression commonly used in condition queries. See:

  • IDatabase::buildLike()
  • IDatabase::conditional()

Untrusted user input is safe in the values of string keys, however untrusted input must not be used in the array key names or in the values of numeric keys. Escaping of untrusted input used in values of numeric keys should be done via IDatabase::addQuotes()

Returns
$this

Definition at line 166 of file DeleteQueryBuilder.php.

Member Data Documentation

◆ $db

IDatabase Wikimedia\Rdbms\DeleteQueryBuilder::$db
protected

The documentation for this class was generated from the following file: