Changes from branches/4.2/src/wp-includes/wp-db.php at r32307 to trunk/src/wp-includes/wp-db.php at r32261
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/wp-db.php
r32307 r32261 1947 1947 protected function process_fields( $table, $data, $format ) { 1948 1948 $data = $this->process_field_formats( $data, $format ); 1949 if ( false === $data ) {1950 return false;1951 }1952 1953 1949 $data = $this->process_field_charsets( $data, $table ); 1954 if ( false === $data ) {1955 return false;1956 }1957 1958 $data = $this->process_field_lengths( $data, $table );1959 1950 if ( false === $data ) { 1960 1951 return false; … … 2033 2024 // This isn't ASCII. Don't have strip_invalid_text() re-check. 2034 2025 $value['ascii'] = false; 2035 }2036 2037 $data[ $field ] = $value;2038 }2039 2040 return $data;2041 }2042 2043 /**2044 * For string fields, record the maximum string length that field can safely save.2045 *2046 * @since 4.2.12047 * @access protected2048 *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 if2052 * any of the values were too long for their corresponding field.2053 */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;2060 } else {2061 $value['length'] = $this->get_col_length( $table, $field );2062 if ( is_wp_error( $value['length'] ) ) {2063 return false;2064 }2065 }2066 2067 if ( false !== $value['length'] && mb_strlen( $value['value'] ) > $value['length'] ) {2068 return false;2069 2026 } 2070 2027 … … 2406 2363 2407 2364 /** 2408 * Retrieve the maximum string length allowed in a given column.2409 *2410 * @since 4.2.12411 * @access public2412 *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 no2416 * length. WP_Error object if there was an error.2417 */2418 public function get_col_length( $table, $column ) {2419 $tablekey = strtolower( $table );2420 $columnkey = strtolower( $column );2421 2422 // Skip this entirely if this isn't a MySQL database.2423 if ( false === $this->is_mysql ) {2424 return false;2425 }2426 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;2432 }2433 }2434 2435 if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) {2436 return false;2437 }2438 2439 $typeinfo = explode( '(', $this->col_meta[ $tablekey ][ $columnkey ]->Type );2440 2441 $type = strtolower( $typeinfo[0] );2442 if ( ! empty( $typeinfo[1] ) ) {2443 $length = trim( $typeinfo[1], ')' );2444 } else {2445 $length = false;2446 }2447 2448 switch( $type ) {2449 case 'binary':2450 case 'char':2451 case 'varbinary':2452 case 'varchar':2453 return $length;2454 break;2455 case 'tinyblob':2456 case 'tinytext':2457 return 255; // 2^8 - 12458 break;2459 case 'blob':2460 case 'text':2461 return 65535; // 2^16 - 12462 break;2463 case 'mediumblob':2464 case 'mediumtext':2465 return 16777215; // 2^24 - 12466 break;2467 case 'longblob':2468 case 'longtext':2469 return 4294967295; // 2^32 - 12470 break;2471 default:2472 return false;2473 }2474 2475 return false;2476 }2477 2478 /**2479 2365 * Check if a string is ASCII. 2480 2366 *
Note: See TracChangeset
for help on using the changeset viewer.