MediaWiki
master
|
Build UPDATE queries with a fluent interface. More...
Public Member Functions | |
__construct (IDatabase $db) | |
Only for use in subclasses. More... | |
andSet ( $set) | |
Add set values to the query. More... | |
andWhere ( $conds) | |
Add conditions to the query. More... | |
caller ( $fname) | |
Set the method name to be included in an SQL comment. More... | |
conds ( $conds) | |
Add conditions to the query. More... | |
connection (IDatabase $db) | |
Change the IDatabase object the query builder is bound to. More... | |
execute () | |
Run the constructed UPDATE query and return the result. More... | |
getQueryInfo () | |
Get an associative array describing the query in terms of its raw parameters to Database::update(). More... | |
ignore () | |
Enable the IGNORE option. More... | |
option ( $name, $value=null) | |
Manually set an option in the $options array to be passed to IDatabase::update() More... | |
options (array $options) | |
Manually set multiple options in the $options array to be passed to IDatabase::update(). More... | |
queryInfo ( $info) | |
Set the query parameters to the given values, appending to the values which were already set. More... | |
set ( $set) | |
Add conditions to the query. More... | |
table ( $table) | |
Manually set the table name to be passed to IDatabase::update() More... | |
update (string $table) | |
Set table for the query. More... | |
where ( $conds) | |
Add conditions to the query. More... | |
Protected Attributes | |
IDatabase | $db |
array | $options = [] |
The options to be passed to IDatabase::update() More... | |
Build UPDATE queries with a fluent interface.
Each query builder object must be used for a single database query only, and not be reused afterwards. To run multiple similar queries, you can create a query builder to set up most of your query, which you can use as a "template" to clone. You can then modify the cloned object for each individual query.
Definition at line 21 of file UpdateQueryBuilder.php.
Wikimedia\Rdbms\UpdateQueryBuilder::__construct | ( | IDatabase | $db | ) |
Only for use in subclasses.
To create a SelectQueryBuilder instance, use $db->newUpdateQueryBuilder()
instead.
IDatabase | $db |
Definition at line 56 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\$db.
Wikimedia\Rdbms\UpdateQueryBuilder::andSet | ( | $set | ) |
Add set values to the query.
Alias for set().
string | array | $set |
Definition at line 276 of file UpdateQueryBuilder.php.
Wikimedia\Rdbms\UpdateQueryBuilder::andWhere | ( | $conds | ) |
Add conditions to the query.
Alias for where().
string | array | $conds |
Definition at line 220 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\where().
Wikimedia\Rdbms\UpdateQueryBuilder::caller | ( | $fname | ) |
Set the method name to be included in an SQL comment.
string | $fname |
Definition at line 299 of file UpdateQueryBuilder.php.
Referenced by Wikimedia\Rdbms\UpdateQueryBuilder\execute().
Wikimedia\Rdbms\UpdateQueryBuilder::conds | ( | $conds | ) |
Add conditions to the query.
Alias for where().
string | array | $conds |
Definition at line 230 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\where().
Referenced by Wikimedia\Rdbms\UpdateQueryBuilder\execute(), and Wikimedia\Rdbms\UpdateQueryBuilder\where().
Wikimedia\Rdbms\UpdateQueryBuilder::connection | ( | IDatabase | $db | ) |
Change the IDatabase object the query builder is bound to.
The specified IDatabase will subsequently be used to execute the query.
IDatabase | $db |
Definition at line 67 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\$db, and Wikimedia\Rdbms\IReadableDatabase\getType().
Wikimedia\Rdbms\UpdateQueryBuilder::execute | ( | ) |
Run the constructed UPDATE query and return the result.
Definition at line 309 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\caller(), Wikimedia\Rdbms\UpdateQueryBuilder\conds(), Wikimedia\Rdbms\UpdateQueryBuilder\options(), and Wikimedia\Rdbms\UpdateQueryBuilder\table().
Wikimedia\Rdbms\UpdateQueryBuilder::getQueryInfo | ( | ) |
Get an associative array describing the query in terms of its raw parameters to Database::update().
This can be used to interface with legacy code.
Definition at line 335 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\$options.
Wikimedia\Rdbms\UpdateQueryBuilder::ignore | ( | ) |
Enable the IGNORE option.
Skip update of rows that would cause unique key conflicts. IDatabase::affectedRows() can be used to determine how many rows were updated.
Definition at line 288 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\options().
Wikimedia\Rdbms\UpdateQueryBuilder::option | ( | $name, | |
$value = null |
|||
) |
Manually set an option in the $options array to be passed to IDatabase::update()
string | $name | The option name |
mixed | $value | The option value, or null for a boolean option |
Definition at line 137 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\options().
Wikimedia\Rdbms\UpdateQueryBuilder::options | ( | array | $options | ) |
Manually set multiple options in the $options array to be passed to IDatabase::update().
array | $options |
Definition at line 153 of file UpdateQueryBuilder.php.
Referenced by Wikimedia\Rdbms\UpdateQueryBuilder\execute(), Wikimedia\Rdbms\UpdateQueryBuilder\ignore(), Wikimedia\Rdbms\UpdateQueryBuilder\option(), and Wikimedia\Rdbms\UpdateQueryBuilder\queryInfo().
Wikimedia\Rdbms\UpdateQueryBuilder::queryInfo | ( | $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::update.
array | $info | Associative array of query info, with keys:
|
Definition at line 92 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\options(), Wikimedia\Rdbms\UpdateQueryBuilder\table(), and Wikimedia\Rdbms\UpdateQueryBuilder\where().
Wikimedia\Rdbms\UpdateQueryBuilder::set | ( | $set | ) |
Add conditions to the query.
The supplied conditions will be appended to the existing conditions, separated by AND.
string | array | $set | Combination map/list where each string-keyed entry maps a column to a literal assigned value and each integer-keyed value is a SQL expression in the format of a column assignment within UPDATE...SET. The (column => value) entries are convenient due to automatic value quoting and conversion of null to NULL. The SQL assignment format is useful for updates like "column = column + X". All assignments have no defined execution order, so they should not depend on each other. Do not modify AUTOINCREMENT or UUID columns in assignments. |
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()
Definition at line 255 of file UpdateQueryBuilder.php.
Wikimedia\Rdbms\UpdateQueryBuilder::table | ( | $table | ) |
Manually set the table name to be passed to IDatabase::update()
string | $table | The table name |
Definition at line 114 of file UpdateQueryBuilder.php.
Referenced by Wikimedia\Rdbms\UpdateQueryBuilder\execute(), Wikimedia\Rdbms\UpdateQueryBuilder\queryInfo(), and Wikimedia\Rdbms\UpdateQueryBuilder\update().
Wikimedia\Rdbms\UpdateQueryBuilder::update | ( | string | $table | ) |
Set table for the query.
Alias for table().
string | $table | The table name |
Definition at line 125 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\table().
Wikimedia\Rdbms\UpdateQueryBuilder::where | ( | $conds | ) |
Add conditions to the query.
The supplied conditions will be appended to the existing conditions, separated by AND.
string | array | $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:
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:
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()
Definition at line 194 of file UpdateQueryBuilder.php.
References Wikimedia\Rdbms\UpdateQueryBuilder\conds(), and LIST_AND.
Referenced by Wikimedia\Rdbms\UpdateQueryBuilder\andWhere(), Wikimedia\Rdbms\UpdateQueryBuilder\conds(), and Wikimedia\Rdbms\UpdateQueryBuilder\queryInfo().
|
protected |
Definition at line 48 of file UpdateQueryBuilder.php.
Referenced by Wikimedia\Rdbms\UpdateQueryBuilder\__construct(), and Wikimedia\Rdbms\UpdateQueryBuilder\connection().
|
protected |
The options to be passed to IDatabase::update()
Definition at line 45 of file UpdateQueryBuilder.php.
Referenced by Wikimedia\Rdbms\UpdateQueryBuilder\getQueryInfo().