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}";