[wp-trac] [WordPress Trac] #7171: wpdb::insert() & wpdb::update()
need to allow typecasting of params.
WordPress Trac
wp-trac at lists.automattic.com
Tue Jun 24 05:03:57 GMT 2008
#7171: wpdb::insert() & wpdb::update() need to allow typecasting of params.
----------------------------+-----------------------------------------------
Reporter: DD32 | Owner: anonymous
Type: enhancement | Status: new
Priority: normal | Milestone: 2.7
Component: Administration | Version: 2.6
Severity: normal | Keywords: dev-feedback
----------------------------+-----------------------------------------------
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 [[BR]]The downside to that
is it'll require the type to be specified on each insert/update statement
2. 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.
--
Ticket URL: <http://trac.wordpress.org/ticket/7171>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list