[wp-trac] [WordPress Trac] #24581: Database IN() operators + array are broken
WordPress Trac
noreply at wordpress.org
Sat Jun 15 12:52:40 UTC 2013
#24581: Database IN() operators + array are broken
--------------------------+-----------------------------
Reporter: Ninos Ego | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version: 3.5.1
Severity: normal | Keywords: has-patch
--------------------------+-----------------------------
I found the ticket #11100 after I searched for a solution with escaping in
IN operators. I think the solution in [12156] is very nice. But if you
have nothing in your array, you get a database error. So here's my
solution :)
{{{
$in = count($postmetaids) ? implode( ',', array_fill(1,
count($postmetaids), '%d')) : 'NULL';
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE meta_id
IN($in)", $postmetaids ));
}}}
This codesnippet is for #11100 and should work like a charm. But I think
there are another places with the solution like in [12156]...
PS: Maybe it would be also nice to include a solution for arrays in the
$wpdb->prepare() function like %as (string array), %ad (decimal array) %af
(float array)
Thanks
--
Ticket URL: <http://core.trac.wordpress.org/ticket/24581>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list