mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-12 13:44:21 +01:00
WPDB: Remove some of the complexities in ::strip_invalid_text()
associated with switching character sets between queries. Instead of trying to dynamically change connection character sets, we now rely on the value of ::charset
. This also fixes the case where queries were being blocked when DB_CHARSET
was utf8
, but the column character set was non-utf8
.
Fixes #32165. Built from https://develop.svn.wordpress.org/trunk@33308 git-svn-id: http://core.svn.wordpress.org/trunk@33280 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
f9980c793c
commit
6759a210ca
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.3-beta3-33300';
|
||||
$wp_version = '4.3-beta3-33308';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
@ -2710,55 +2710,37 @@ class wpdb {
|
||||
$queries = array();
|
||||
foreach ( $data as $col => $value ) {
|
||||
if ( ! empty( $value['db'] ) ) {
|
||||
if ( ! isset( $queries[ $value['charset'] ] ) ) {
|
||||
$queries[ $value['charset'] ] = array();
|
||||
}
|
||||
|
||||
// We're going to need to truncate by characters or bytes, depending on the length value we have.
|
||||
if ( 'byte' === $value['length']['type'] ) {
|
||||
// Split the CONVERT() calls by charset, so we can make sure the connection is right
|
||||
$queries[ $value['charset'] ][ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING binary ), %.0f ) USING {$value['charset']} )", $value['value'], $value['length']['length'] );
|
||||
// Using binary causes LEFT() to truncate by bytes.
|
||||
$charset = 'binary';
|
||||
} else {
|
||||
$queries[ $value['charset'] ][ $col ] = $this->prepare( "LEFT( CONVERT( %s USING {$value['charset']} ), %.0f )", $value['value'], $value['length']['length'] );
|
||||
$charset = $value['charset'];
|
||||
}
|
||||
|
||||
$queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING {$this->charset} )", $value['value'], $value['length']['length'] );
|
||||
|
||||
unset( $data[ $col ]['db'] );
|
||||
}
|
||||
}
|
||||
|
||||
$connection_charset = $this->charset;
|
||||
foreach ( $queries as $charset => $query ) {
|
||||
$sql = array();
|
||||
foreach ( $queries as $column => $query ) {
|
||||
if ( ! $query ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Change the charset to match the string(s) we're converting
|
||||
if ( $charset !== $connection_charset ) {
|
||||
$connection_charset = $charset;
|
||||
$this->set_charset( $this->dbh, $charset );
|
||||
}
|
||||
|
||||
$this->check_current_query = false;
|
||||
|
||||
$sql = array();
|
||||
foreach ( $query as $column => $column_query ) {
|
||||
$sql[] = $column_query . " AS x_$column";
|
||||
}
|
||||
|
||||
$row = $this->get_row( "SELECT " . implode( ', ', $sql ), ARRAY_A );
|
||||
if ( ! $row ) {
|
||||
$this->set_charset( $this->dbh, $connection_charset );
|
||||
return new WP_Error( 'wpdb_strip_invalid_text_failure' );
|
||||
}
|
||||
|
||||
foreach ( array_keys( $query ) as $column ) {
|
||||
$data[ $column ]['value'] = $row["x_$column"];
|
||||
}
|
||||
$sql[] = $query . " AS x_$column";
|
||||
}
|
||||
|
||||
// Don't forget to change the charset back!
|
||||
if ( $connection_charset !== $this->charset ) {
|
||||
$this->set_charset( $this->dbh );
|
||||
$this->check_current_query = false;
|
||||
$row = $this->get_row( "SELECT " . implode( ', ', $sql ), ARRAY_A );
|
||||
if ( ! $row ) {
|
||||
return new WP_Error( 'wpdb_strip_invalid_text_failure' );
|
||||
}
|
||||
|
||||
foreach ( array_keys( $data ) as $column ) {
|
||||
$data[ $column ]['value'] = $row["x_$column"];
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user