[wp-trac] [WordPress Trac] #15158: wpdb insert & update with null values
WordPress Trac
noreply at wordpress.org
Fri Dec 28 17:24:08 UTC 2012
#15158: wpdb insert & update with null values
-------------------------+-----------------------------
Reporter: westi | Owner: sorich87
Type: enhancement | Status: accepted
Priority: normal | Milestone: Future Release
Component: Database | Version: 3.0.1
Severity: normal | Resolution:
Keywords: has-patch |
-------------------------+-----------------------------
Changes (by jbutkus):
* keywords: needs-patch => has-patch
Comment:
Please find my patch attached.
I have tested it to work with such cases:
Test1:
{{{$wpdb->prepare( 'INSERT INTO foo ( val1, val2, val3 ) VALUES (
x\'%2$s\', %3$d, \'%1$s\' ) ON DUPLICATE KEY UPDATE SET val1 = %3$d, val2
= %3$d', 'foo-\'bar\'-baz', 'ae4f', NULL );}}}
gives:
{{{INSERT INTO foo ( val1, val2, val3 ) VALUES ( x'ae4f', NULL ,
'foo-\'bar\'-baz' ) ON DUPLICATE KEY UPDATE SET val1 = NULL , val2 =
NULL}}}
----
Test2:
{{{$wpdb->prepare( 'UPDATE foo SET val1 = %s, val2 = %d, val3 = %f, val4 =
%s', 'foo-\'bar\'-baz', NULL, 2013.12, 'Happy Holidays' );}}}
gives:
{{{UPDATE foo SET val1 = 'foo-\'bar\'-baz', val2 = NULL , val3 =
2013.120000, val4 = 'Happy Holidays'}}}
----
Test3:
{{{$wpdb->prepare( 'INSERT INTO foo ( val1, val2, val3, val4 ) VALUES (
%s, %d, %s, %s ) ', 'My First WP post', '1010', NULL, 'Hello, World!'
);}}}
gives:
{{{INSERT INTO foo ( val1, val2, val3, val4 ) VALUES ( 'My First WP post',
1010, NULL , 'Hello, World!' )}}}
I see this as one of the possibilities.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/15158#comment:22>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list