From 050d94ccba2bd16f15f156b4d629ae7d23306cd4 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Fri, 27 Aug 2010 17:35:07 +0000 Subject: [PATCH] Revert insertOrUpdate work Will mark relevant revisions as reverted on CR as appropriate --- includes/db/Database.php | 56 ----------------------------------- includes/db/DatabaseMysql.php | 56 ----------------------------------- 2 files changed, 112 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index 46971d0757..642b4b6a45 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -1038,62 +1038,6 @@ abstract class DatabaseBase implements DatabaseType { return (bool)$this->query( $sql, $fname ); } - /** - * INSERT ... ON DUPLICATE KEY UPDATE wrapper, inserts an array into a - * table, optionally updating if duplicate primary key found - * - * $rows may be a single associative array, or an array of these with - * numeric keys, for multi-row insert. - * - * Usually aborts on failure. If errors are explicitly ignored, returns success. - * - * @param $table String: table name (prefix auto-added) - * @param $rows Array: Array of rows to insert - * @param $fname String: Calling function name (use __METHOD__) for logs/profiling - * @param $onDupeUpdate Array: Associative array of fields to update on duplicate - * - * @return bool - */ - function insertOrUpdate( $table, $rows, $fname = 'DatabaseBase::insertOrUpdate', $onDupeUpdate = array() ) { - if ( isset( $rows[0] ) && is_array( $rows[0] ) ) { - $keys = array_keys( $rows[0] ); - } else { - $keys = array_keys( $rows ); - } - - // Get what is only to be set if inserted - $where = array_diff( $rows, $onDupeUpdate ); - - $res = $this->select( - $table, - $keys, - $where, - __METHOD__ - ); - - if ( $res ) { - // Where there is a different value to set if this is being - // "updated", use the $onDupeUpdate value for that to replace the - // original option (if it was an insert), and replace the column - // name with the value read from the existing row - foreach ( $where as $key => $unused ) { - if ( isset( $onDupeUpdate[$key] ) ) { - $options[$key] = str_replace( $key, $res[0]->{$key}, $onDupeUpdate[$key] ); - } - } - } else { - // No results, it's just an insert - $update = $where; - } - - return (bool)$this->replace( - $table, - $update, - array(), - __METHOD__ - ); - } - /** * Make UPDATE options for the DatabaseBase::update function * diff --git a/includes/db/DatabaseMysql.php b/includes/db/DatabaseMysql.php index 3e731a5a6c..afcaa2cd44 100644 --- a/includes/db/DatabaseMysql.php +++ b/includes/db/DatabaseMysql.php @@ -350,62 +350,6 @@ class DatabaseMysql extends DatabaseBase { return false; } - /** - * INSERT ... ON DUPE UPDATE wrapper, inserts an array into a table, optionally updating if - * duplicate primary key found - * - * $a may be a single associative array, or an array of these with numeric keys, for - * multi-row insert. - * - * Usually aborts on failure - * If errors are explicitly ignored, returns success - * - * @param $table String: table name (prefix auto-added) - * @param $a Array: Array of rows to insert - * @param $fname String: Calling function name (use __METHOD__) for logs/profiling - * @param $onDupeUpdate Array: Associative array of fields to update on duplicate - * - * @return bool - */ - function insertOrUpdate( $table, $a, $fname = 'DatabaseBase::insertOrUpdate', $onDupeUpdate = array() ) { - # No rows to insert, easy just return now - if ( !count( $a ) ) { - return true; - } - - $table = $this->tableName( $table ); - - if ( isset( $a[0] ) && is_array( $a[0] ) ) { - $multi = true; - $keys = array_keys( $a[0] ); - } else { - $multi = false; - $keys = array_keys( $a ); - } - - $sql = "INSERT INTO $table (" . implode( ',', $keys ) . ') VALUES '; - - if ( $multi ) { - $first = true; - foreach ( $a as $row ) { - if ( $first ) { - $first = false; - } else { - $sql .= ','; - } - $sql .= '(' . $this->makeList( $row ) . ')'; - } - } else { - $sql .= '(' . $this->makeList( $a ) . ')'; - } - - if ( count( $onDupeUpdate ) ) { - $sql .= ' ON DUPLICATE KEY UPDATE ' . $this->makeList( $onDupeUpdate, LIST_SET ); - } - - return (bool)$this->query( $sql, $fname ); - } - function getServerVersion() { return mysql_get_server_info( $this->mConn ); } -- 2.20.1