From 66b32fa01763bfc8cee2a29e089a106e3094f178 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Mon, 18 Jul 2005 02:30:04 +0000 Subject: [PATCH] * Modified the update function to take another argument, $options, it now supports queries like $dbr->update( 'user', array( 'user_name' => 'foo' ), array( 'user_name => 'bar' ), '', array('IGNORE') to make UPDATE IGNORE .. * Documented Database::update() --- includes/Database.php | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/includes/Database.php b/includes/Database.php index 98bf45eddf..ea61683f38 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -930,11 +930,36 @@ class Database { } /** - * UPDATE wrapper, takes a condition array and a SET array + * Make UPDATE options for the Database::update function + * + * @access private + * @param array $options The options passed to Database::update + * @return string */ - function update( $table, $values, $conds, $fname = 'Database::update' ) { + function makeUpdateOptions( $options ) { + $opts = array(); + if ( in_array( 'LOW_PRIORITY', $options ) ) + $opts[] = 'LOW_PRIORITY'; + if ( in_array( 'IGNORE', $options ) ) + $opts[] = 'IGNORE'; + return implode(' ', $opts); + } + + /** + * UPDATE wrapper, takes a condition array and a SET array + * + * @param string $table The table to UPDATE + * @param array $values An array of values to SET + * @param array $conds An array of conditions (WHERE) + * @param string $fname The Class::Function calling this function + * (for the log) + * @param array $options An array of UPDATE options, can be one or + * more of IGNORE, LOW_PRIORITY + */ + function update( $table, $values, $conds, $fname = 'Database::update', $options = array() ) { $table = $this->tableName( $table ); - $sql = "UPDATE $table SET " . $this->makeList( $values, LIST_SET ); + $opts = $this->makeUpdateOptions( $options ); + $sql = "UPDATE $opts $table SET " . $this->makeList( $values, LIST_SET ); if ( $conds != '*' ) { $sql .= " WHERE " . $this->makeList( $conds, LIST_AND ); } -- 2.20.1