1947
1947
protected function process_fields( $table, $data, $format ) {
1948
1948
$data = $this->process_field_formats( $data, $format );
1949
if ( false === $data ) {
1949
1953
$data = $this->process_field_charsets( $data, $table );
1950
1954
if ( false === $data ) {
1958
$data = $this->process_field_lengths( $data, $table );
1959
if ( false === $data ) {
1954
1963
$converted_data = $this->strip_invalid_text( $data );
1956
1965
if ( $data !== $converted_data ) {
2044
* For string fields, record the maximum string length that field can safely save.
2049
* @param array $data As it comes from the wpdb::process_field_charsets() method.
2050
* @param string $table Table name.
2051
* @return array|False The same array as $data with additional 'length' keys, or false if
2052
* any of the values were too long for their corresponding field.
2054
protected function process_field_lengths( $data, $table ) {
2055
foreach ( $data as $field => $value ) {
2056
if ( '%d' === $value['format'] || '%f' === $value['format'] ) {
2057
// We can skip this field if we know it isn't a string.
2058
// This checks %d/%f versus ! %s because it's sprintf() could take more.
2059
$value['length'] = false;
2061
$value['length'] = $this->get_col_length( $table, $field );
2062
if ( is_wp_error( $value['length'] ) ) {
2067
if ( false !== $value['length'] && mb_strlen( $value['value'] ) > $value['length'] ) {
2071
$data[ $field ] = $value;
2035
2078
* Retrieve one variable from the database.
2037
2080
* Executes a SQL query and returns the value from the SQL result.
2408
* Retrieve the maximum string length allowed in a given column.
2413
* @param string $table Table name.
2414
* @param string $column Column name.
2415
* @return mixed Max column length as an int. False if the column has no
2416
* length. WP_Error object if there was an error.
2418
public function get_col_length( $table, $column ) {
2419
$tablekey = strtolower( $table );
2420
$columnkey = strtolower( $column );
2422
// Skip this entirely if this isn't a MySQL database.
2423
if ( false === $this->is_mysql ) {
2427
if ( empty( $this->col_meta[ $tablekey ] ) ) {
2428
// This primes column information for us.
2429
$table_charset = $this->get_table_charset( $table );
2430
if ( is_wp_error( $table_charset ) ) {
2431
return $table_charset;
2435
if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) {
2439
$typeinfo = explode( '(', $this->col_meta[ $tablekey ][ $columnkey ]->Type );
2441
$type = strtolower( $typeinfo[0] );
2442
if ( ! empty( $typeinfo[1] ) ) {
2443
$length = trim( $typeinfo[1], ')' );
2457
return 255; // 2^8 - 1
2461
return 65535; // 2^16 - 1
2465
return 16777215; // 2^24 - 1
2469
return 4294967295; // 2^32 - 1
2365
2479
* Check if a string is ASCII.
2367
2481
* The negative regex is faster for non-ASCII strings, as it allows