Ticket #7171 (assigned enhancement)

Opened 2 months ago

Last modified 2 months ago

wpdb::insert() & wpdb::update() need to allow typecasting of params.

Reported by: DD32 Assigned to: westi (accepted)
Priority: normal Milestone: 2.7
Component: Administration Version: 2.6
Severity: normal Keywords: dev-feedback
Cc:

Description

As a follow up to: http://trac.wordpress.org/ticket/6836#comment:8

insert() and update() should prepare the values before inserting/updating

I see 2 options;

  1. 3rd param to insert() & update() which specifies the field types; Eg: http://trac.wordpress.org/ticket/6836#comment:9
    The downside to that is it'll require the type to be specified on each insert/update statement
  1. defining the field-types in an array to check against eg:
    $wpdb->fields = array( $wpdb->posts => array('ID' => '%d', 'post_content' => '%s') );
    
    ..
    in insert():
    foreach( (array)$data as $key => $value )
       if( isset($this->fields[ $table ][ $key ]) )
           $data[$key] = sprintf($this->fields[ $table ][ $key ], $value);
    

The downside of this approach, Is that it'll require the list to be kept updated, However, it has the advantage of being kept updated in a single location.

If theres a preference for either method, I'm happy to roll up a patch for it.

Change History

07/12/08 10:16:32 changed by westi

  • owner changed from anonymous to westi.
  • status changed from new to assigned.