Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 658d22d054b65d72fa19b282eb273585537ff118 1 parent f2208f3
ryan authored
Showing with 30 additions and 16 deletions.
  1. +20 −10 wp-includes/wp-db.php
  2. +10 −6 wp-settings.php
View
30 wp-includes/wp-db.php
@@ -255,6 +255,20 @@ class wpdb {
'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
*
* @since 2.2.0
@@ -703,16 +717,14 @@ function query($query) {
* @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 @@ function insert($table, $data, $format = null) {
* @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 @@ function update($table, $data, $where, $format = null, $where_format = null) {
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 @@ function update($table, $data, $where, $format = null, $where_format = null) {
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
16 wp-settings.php
@@ -247,20 +247,24 @@ function timer_stop($display = 0, $precision = 3) { //if called like timer_stop(
require (ABSPATH . WPINC . '/functions.php');
require (ABSPATH . WPINC . '/classes.php');
+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()
*/
-$db_field_types = array( 'post_author' => '%d', 'post_parent' => '%d', 'menu_order' => '%d', 'term_id' => '%d', 'term_group' => '%d', 'term_taxonomy_id' => '%d',
+$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');
-require_wp_db();
-
-if ( !empty($wpdb->error) )
- dead_db();
-
$prefix = $wpdb->set_prefix($table_prefix);
if ( is_wp_error($prefix) )
Please sign in to comment.
Something went wrong with that request. Please try again.