[wp-trac] [WordPress Trac] #32315: $wpdb->insert fails without error msg
WordPress Trac
noreply at wordpress.org
Tue Nov 1 00:31:04 UTC 2016
#32315: $wpdb->insert fails without error msg
------------------------------------------+------------------------------
Reporter: dlt101 | Owner:
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: Database | Version:
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+------------------------------
Comment (by procodewp):
I`ve been looking into this over the weekend and found the following:
When you call the insert() or update() routine in wpdb, it's calling
process_fields().
Inside of process_fields(), it calls strip_invalid_text() which removes
invalid characters, and also truncates the data to the field length.
When strip_invalid_text() returns the amended $data, the following code is
run:
{{{
if ( $data !== $converted_data ) {
return false;
}
}}}
This compares the original $data with the $converted_data returned from
the strip_invalid_text() function, and if anything has been changed it
returns false.
This stops the operation from occuring, without an error message. So if
any invalid characters are removed, or the field is truncated, everything
stops.
The problem from the error side is that the existing error variables are
set up to log errors returned by MySQL. But in this case, the query is
never sent to the database, it's an internal error rather than a database
error, so it doesn't get logged anywhere.
>>You realize how much extra code an insert would require if you error?
Every insert var would have to be checked for length prior to insert.
This is already happening, each insert var string passes through
process_field_lengths which gets the size of the database field.
strip_invalid_text() then uses this to truncate the field if necessary.
I`m not not sure of the best way to handle this. It would be possible to
run through the $data array and compare it to the $converted_data array
returned from strip_invalid_text(), which would allow a list of any fields
with data thats been changed. But what would be the best way to display
this information to the user?
Would it be worth creating a variable to hold internal errors, for errors
in functions that occur before a database operation?
--
Ticket URL: <https://core.trac.wordpress.org/ticket/32315#comment:17>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list