Store field types in wpdb object. Props mdawaffe. see #7171

git-svn-id: http://svn.automattic.com/wordpress/trunk@10910 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-04-10 21:56:30 +00:00
parent f2208f3c91
commit 658d22d054
2 changed files with 33 additions and 19 deletions

View File

@ -254,6 +254,20 @@ class wpdb {
var $tables = array('users', 'usermeta', 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options',
'postmeta', 'terms', 'term_taxonomy', 'term_relationships');
/**
* Format specifiers for DB columns. Columns not listed here default to %s. Initialized in wp-settings.php.
*
* Keys are colmn names, values are format types: 'ID' => '%d'
*
* @since 2.8.0
* @see wpdb:prepare()
* @see wpdb:insert()
* @see wpdb:update()
* @access public
* @war array
*/
var $field_type = array();
/**
* Database table columns charset
*
@ -703,16 +717,14 @@ class wpdb {
* @return mixed Results of $this->query()
*/
function insert($table, $data, $format = null) {
global $db_field_types;
$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($db_field_types[$field]) )
$form = $db_field_types[$field];
elseif ( isset($this->field_types[$field]) )
$form = $this->field_types[$field];
else
$form = '%s';
$formatted_fields[] = $form;
@ -734,8 +746,6 @@ class wpdb {
* @return mixed Results of $this->query()
*/
function update($table, $data, $where, $format = null, $where_format = null) {
global $db_field_types;
if ( !is_array( $where ) )
return false;
@ -744,8 +754,8 @@ class wpdb {
foreach ( (array) array_keys($data) as $field ) {
if ( !empty($format) )
$form = ( $form = array_shift($formats) ) ? $form : $format[0];
elseif ( isset($db_field_types[$field]) )
$form = $db_field_types[$field];
elseif ( isset($this->field_types[$field]) )
$form = $this->field_types[$field];
else
$form = '%s';
$bits[] = "`$field` = {$form}";
@ -755,8 +765,8 @@ class wpdb {
foreach ( (array) array_keys($where) as $field ) {
if ( !empty($where_format) )
$form = ( $form = array_shift($where_formats) ) ? $form : $where_format[0];
elseif ( isset($db_field_types[$field]) )
$form = $db_field_types[$field];
elseif ( isset($this->field_types[$field]) )
$form = $this->field_types[$field];
else
$form = '%s';
$wheres[] = "`$field` = {$form}";

View File

@ -247,20 +247,24 @@ require (ABSPATH . WPINC . '/compat.php');
require (ABSPATH . WPINC . '/functions.php');
require (ABSPATH . WPINC . '/classes.php');
/**
* Format specifiers for DB columns. Columns not listed here default to %s.
* @since 2.8.0
*/
$db_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',
'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');
require_wp_db();
if ( !empty($wpdb->error) )
dead_db();
/**
* Format specifiers for DB columns. Columns not listed here default to %s.
* @since 2.8.0
* @see wpdb:$field_types
* @see wpdb:prepare()
* @see wpdb:insert()
* @see wpdb:update()
*/
$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',
'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');
$prefix = $wpdb->set_prefix($table_prefix);
if ( is_wp_error($prefix) )