Index: src/wp-includes/wp-db.php
===================================================================
--- src/wp-includes/wp-db.php	(revision 25437)
+++ src/wp-includes/wp-db.php	(working copy)
@@ -1243,7 +1243,43 @@
 
 		return $return_val;
 	}
+	
+	/**
+	 * Helper function for format of name value pairs joined by =
+	 *
+	 * @access protected
+	 * @since 3.5.0
+	 * @see wpdb::prepare()
+	 * @see wpdb::$field_types
+	 * @see wp_set_wpdb_vars()
+	 *
+	 * @param array $data A named array of clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $data columns and $data values should be "raw".
+	 * @param array|string $formats Optional. An array of formats to be mapped to each of the values in $where. 
+	 *	If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). 
+	 *	If omitted, all values in $where will be treated as strings.
+	 * @param boolean $values If set to true, only returns an array of formats
+	 * @return array of formatted field => $value
+	 */
+	protected function format_clauses( $data, $formats = null, $values = false ) {
+		$wheres = array();
+		foreach ( (array) array_keys( $data ) as $field ) {
+			$format = $formats;
+			
+			if ( isset( $this->field_types[$field] ) )
+				$format = $this->field_types[$field];					
+			
+			if ( is_array( $formats ) )
+				$format = empty( $formats ) ? '%s' : array_shift( $formats );
 
+			if ( empty( $format ) )
+				$format = '%s';
+			
+			$wheres[] = $values ? $format : "`$field` = {$format}";
+		}
+
+		return $wheres;
+	}	
+	
 	/**
 	 * Insert a row into a table.
 	 *
@@ -1259,12 +1295,12 @@
 	 *
 	 * @param string $table table name
 	 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
-	 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
+	 * @param array|string $formats Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
 	 * 	A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
 	 * @return int|false The number of rows inserted, or false on error.
 	 */
-	function insert( $table, $data, $format = null ) {
-		return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' );
+	function insert( $table, $data, $formats = null ) {
+		return $this->_insert_replace_helper( $table, $data, $formats, 'INSERT' );
 	}
 
 	/**
@@ -1282,12 +1318,12 @@
 	 *
 	 * @param string $table table name
 	 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
-	 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
+	 * @param array|string $formats Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
 	 * 	A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
 	 * @return int|false The number of rows affected, or false on error.
 	 */
-	function replace( $table, $data, $format = null ) {
-		return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' );
+	function replace( $table, $data, $formats = null ) {
+		return $this->_insert_replace_helper( $table, $data, $formats, 'REPLACE' );
 	}
 
 	/**
@@ -1303,28 +1339,20 @@
 	 *
 	 * @param string $table table name
 	 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
-	 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
+	 * @param array|string $formats Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
 	 * 	A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
 	 * @param string $type Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT.
 	 * @return int|false The number of rows affected, or false on error.
 	 */
-	function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) {
+	function _insert_replace_helper( $table, $data, $formats = null, $type = 'INSERT' ) {
 		if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) )
 			return false;
 		$this->insert_id = 0;
-		$formats = $format = (array) $format;
-		$fields = array_keys( $data );
-		$formatted_fields = array();
-		foreach ( $fields as $field ) {
-			if ( !empty( $format ) )
-				$form = ( $form = array_shift( $formats ) ) ? $form : $format[0];
-			elseif ( isset( $this->field_types[$field] ) )
-				$form = $this->field_types[$field];
-			else
-				$form = '%s';
-			$formatted_fields[] = $form;
-		}
-		$sql = "{$type} INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES (" . implode( ",", $formatted_fields ) . ")";
+		
+		$fields = implode( '`,`', array_keys( $data ) );
+		$formatted_fields = implode( ",", $this->format_clauses( $data, $formats, true ) );
+
+		$sql = "{$type} INTO `$table` (`$fields`) VALUES ($formatted_fields)";
 		return $this->query( $this->prepare( $sql, $data ) );
 	}
 
@@ -1344,39 +1372,19 @@
 	 * @param string $table table name
 	 * @param array $data Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
 	 * @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
-	 * @param array|string $format Optional. An array of formats to be mapped to each of the values in $data. If string, that format will be used for all of the values in $data.
+	 * @param array|string $formats Optional. An array of formats to be mapped to each of the values in $data. If string, that format will be used for all of the values in $data.
 	 * 	A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
-	 * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings.
+	 * @param array|string $where_formats Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings.
 	 * @return int|false The number of rows updated, or false on error.
 	 */
-	function update( $table, $data, $where, $format = null, $where_format = null ) {
+	function update( $table, $data, $where, $formats = null, $where_formats = null ) {
 		if ( ! is_array( $data ) || ! is_array( $where ) )
 			return false;
 
-		$formats = $format = (array) $format;
-		$bits = $wheres = array();
-		foreach ( (array) array_keys( $data ) as $field ) {
-			if ( !empty( $format ) )
-				$form = ( $form = array_shift( $formats ) ) ? $form : $format[0];
-			elseif ( isset($this->field_types[$field]) )
-				$form = $this->field_types[$field];
-			else
-				$form = '%s';
-			$bits[] = "`$field` = {$form}";
-		}
+		$bits = implode( ', ', $this->format_clauses( $data, $formats ) );
+		$wheres = implode( ' AND ', $this->format_clauses( $where, $where_formats ) );
 
-		$where_formats = $where_format = (array) $where_format;
-		foreach ( (array) array_keys( $where ) as $field ) {
-			if ( !empty( $where_format ) )
-				$form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0];
-			elseif ( isset( $this->field_types[$field] ) )
-				$form = $this->field_types[$field];
-			else
-				$form = '%s';
-			$wheres[] = "`$field` = {$form}";
-		}
-
-		$sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres );
+		$sql = "UPDATE `$table` SET $bits WHERE $wheres";
 		return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) );
 	}
 
@@ -1395,34 +1403,19 @@
 	 *
 	 * @param string $table table name
 	 * @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
-	 * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types.
+	 * @param array|string $where_formats Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types.
 	 * @return int|false The number of rows updated, or false on error.
 	 */
-	function delete( $table, $where, $where_format = null ) {
+	function delete( $table, $where, $where_formats = null ) {
 		if ( ! is_array( $where ) )
 			return false;
 
-		$bits = $wheres = array();
+		$wheres = implode( ' AND ', $this->format_clauses( $where, $where_formats ) );
 
-		$where_formats = $where_format = (array) $where_format;
-
-		foreach ( array_keys( $where ) as $field ) {
-			if ( !empty( $where_format ) ) {
-				$form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0];
-			} elseif ( isset( $this->field_types[ $field ] ) ) {
-				$form = $this->field_types[ $field ];
-			} else {
-				$form = '%s';
-			}
-
-			$wheres[] = "$field = $form";
-		}
-
-		$sql = "DELETE FROM $table WHERE " . implode( ' AND ', $wheres );
+		$sql = "DELETE FROM `$table` WHERE $wheres";
 		return $this->query( $this->prepare( $sql, $where ) );
 	}
 
-
 	/**
 	 * Retrieve one variable from the database.
 	 *
