Index: wp-includes/load.php
===================================================================
--- wp-includes/load.php	(revision 21358)
+++ wp-includes/load.php	(working copy)
@@ -354,9 +354,14 @@
 	global $wpdb, $table_prefix;
 	if ( !empty( $wpdb->error ) )
 		dead_db();
-
+	/**
+	 * List all columns in WP tables that should be formatted as %d 
+	 * These columns will be matched against the master list of tables in $wpdb->tables 
+	 * - so "parent" won't indiscrimately be cast to INT in a user-defined table where its type is VARCHAR or TEXT, etc
+	 *  
+	 */
 	$wpdb->field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
-		'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'commment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
+		'parent' => '%d', 'count' => '%d','object_id' => '%d', 'term_order' => '%d', 'ID' => '%d', 'comment_ID' => '%d', 'comment_post_ID' => '%d', 'comment_parent' => '%d',
 		'user_id' => '%d', 'link_id' => '%d', 'link_owner' => '%d', 'link_rating' => '%d', 'option_id' => '%d', 'blog_id' => '%d', 'meta_id' => '%d', 'post_id' => '%d',
 		'user_status' => '%d', 'umeta_id' => '%d', 'comment_karma' => '%d', 'comment_count' => '%d',
 		// multisite:
Index: wp-includes/wp-db.php
===================================================================
--- wp-includes/wp-db.php	(revision 21358)
+++ wp-includes/wp-db.php	(working copy)
@@ -1186,6 +1186,40 @@
 	}
 
 	/**
+	 * Helper function for resolving form field formats
+	 *
+	 * @access protected
+	 * @since 3.5.0
+	 * @see wpdb::prepare()
+	 * @see wpdb::$field_types
+	 * @see wp_set_wpdb_vars()
+	 *
+	 * @param string $table table name
+	 * @param string $field the column to format
+	 * @param array|string $format Optional. An array of formats, the first item will be returned.
+	 *		If string, that format will be used.
+	 *		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.
+	 *		$format is passed by-reference so that array_shift() will move the cursor to the next item in $format on subsequent calls
+	 *		
+	 * @return string format of value.
+	 */
+	protected function field_format( $table, $field, &$format = null ) {
+		if ( ! empty( $format ) ) {
+			if ( is_string( $format ) )
+				$form = $format;
+			elseif ( is_array( $format ) )
+				$form = array_shift( $format );
+		} elseif ( in_array( $table, array_keys( $this->tables ) ) && isset( $this->field_types[$field] ) ) {
+			$form = $this->field_types[$field];
+		} else {
+			$form = '%s';
+		}
+			
+		return $form;
+	}
+	
+	/**
 	 * Helper function for insert and replace.
 	 *
 	 * Runs an insert or replace query based on $type argument.
@@ -1198,7 +1232,7 @@
 	 *
 	 * @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.
@@ -1206,23 +1240,40 @@
 	function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) {
 		if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) )
 			return false;
-		$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;
-		}
+		foreach ( $fields as $field )
+			$formatted_fields[] = $this->field_format( $table, $field, $format );
+
 		$sql = "{$type} INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES (" . implode( ",", $formatted_fields ) . ")";
 		return $this->query( $this->prepare( $sql, $data ) );
 	}
 
 	/**
+	 * Helper function for format of WHERE clauses
+	 *
+	 * @access protected
+	 * @since 3.5.0
+	 * @see wpdb::prepare()
+	 * @see wpdb::$field_types
+	 * @see wp_set_wpdb_vars()
+	 *
+	 * @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.
+	 * @return array of formatted field => $value
+	 */
+	protected function where_clauses( $table, $where, $where_format = null ) {
+		$wheres = array();
+		foreach ( (array) array_keys( $where ) as $field ) {
+			$form = $this->field_format( $table, $field, $where_format );
+			$wheres[] = "`$field` = {$form}";
+		}
+		
+		return $wheres;
+	}
+	
+	/**
 	 * Update a row in the table
 	 *
 	 * <code>
@@ -1247,28 +1298,13 @@
 		if ( ! is_array( $data ) || ! is_array( $where ) )
 			return false;
 
-		$formats = $format = (array) $format;
-		$bits = $wheres = array();
+		$bits = 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';
+			$form = $this->field_format( $table, $field, $format );
 			$bits[] = "`$field` = {$form}";
 		}
 
-		$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}";
-		}
+		$wheres = $this->where_clauses( $table, $where, $where_format );
 
 		$sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres );
 		return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) );
@@ -1296,22 +1332,8 @@
 		if ( ! is_array( $where ) )
 			return false;
 
-		$bits = $wheres = array();
+		$wheres = $this->where_clauses( $table, $where, $where_format );
 
-		$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 );
 		return $this->query( $this->prepare( $sql, $where ) );
 	}
