Changeset 32313 for branches/4.0/src/wp-includes/wp-db.php
- Timestamp:
- 04/27/2015 05:16:29 PM (11 years ago)
- File:
-
- 1 edited
-
branches/4.0/src/wp-includes/wp-db.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/4.0/src/wp-includes/wp-db.php
r32272 r32313 1929 1929 protected function process_fields( $table, $data, $format ) { 1930 1930 $data = $this->process_field_formats( $data, $format ); 1931 if ( false === $data ) { 1932 return false; 1933 } 1934 1931 1935 $data = $this->process_field_charsets( $data, $table ); 1936 if ( false === $data ) { 1937 return false; 1938 } 1939 1940 $data = $this->process_field_lengths( $data, $table ); 1932 1941 if ( false === $data ) { 1933 1942 return false; … … 2006 2015 // This isn't ASCII. Don't have strip_invalid_text() re-check. 2007 2016 $value['ascii'] = false; 2017 } 2018 2019 $data[ $field ] = $value; 2020 } 2021 2022 return $data; 2023 } 2024 2025 /** 2026 * For string fields, record the maximum string length that field can safely save. 2027 * 2028 * @since 4.2.1 2029 * @access protected 2030 * 2031 * @param array $data As it comes from the wpdb::process_field_charsets() method. 2032 * @param string $table Table name. 2033 * @return array|False The same array as $data with additional 'length' keys, or false if 2034 * any of the values were too long for their corresponding field. 2035 */ 2036 protected function process_field_lengths( $data, $table ) { 2037 foreach ( $data as $field => $value ) { 2038 if ( '%d' === $value['format'] || '%f' === $value['format'] ) { 2039 // We can skip this field if we know it isn't a string. 2040 // This checks %d/%f versus ! %s because it's sprintf() could take more. 2041 $value['length'] = false; 2042 } else { 2043 $value['length'] = $this->get_col_length( $table, $field ); 2044 if ( is_wp_error( $value['length'] ) ) { 2045 return false; 2046 } 2047 } 2048 2049 if ( false !== $value['length'] && strlen( $value['value'] ) > $value['length'] ) { 2050 return false; 2008 2051 } 2009 2052 … … 2336 2379 2337 2380 /** 2381 * Retrieve the maximum string length allowed in a given column. 2382 * 2383 * @since 4.2.1 2384 * @access public 2385 * 2386 * @param string $table Table name. 2387 * @param string $column Column name. 2388 * @return mixed Max column length as an int. False if the column has no 2389 * length. WP_Error object if there was an error. 2390 */ 2391 public function get_col_length( $table, $column ) { 2392 $tablekey = strtolower( $table ); 2393 $columnkey = strtolower( $column ); 2394 2395 // Skip this entirely if this isn't a MySQL database. 2396 if ( false === $this->is_mysql ) { 2397 return false; 2398 } 2399 2400 if ( empty( $this->col_meta[ $tablekey ] ) ) { 2401 // This primes column information for us. 2402 $table_charset = $this->get_table_charset( $table ); 2403 if ( is_wp_error( $table_charset ) ) { 2404 return $table_charset; 2405 } 2406 } 2407 2408 if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) { 2409 return false; 2410 } 2411 2412 $typeinfo = explode( '(', $this->col_meta[ $tablekey ][ $columnkey ]->Type ); 2413 2414 $type = strtolower( $typeinfo[0] ); 2415 if ( ! empty( $typeinfo[1] ) ) { 2416 $length = trim( $typeinfo[1], ')' ); 2417 } else { 2418 $length = false; 2419 } 2420 2421 switch( $type ) { 2422 case 'binary': 2423 case 'char': 2424 case 'varbinary': 2425 case 'varchar': 2426 return $length; 2427 break; 2428 case 'tinyblob': 2429 case 'tinytext': 2430 return 255; // 2^8 - 1 2431 break; 2432 case 'blob': 2433 case 'text': 2434 return 65535; // 2^16 - 1 2435 break; 2436 case 'mediumblob': 2437 case 'mediumtext': 2438 return 16777215; // 2^24 - 1 2439 break; 2440 case 'longblob': 2441 case 'longtext': 2442 return 4294967295; // 2^32 - 1 2443 break; 2444 default: 2445 return false; 2446 } 2447 2448 return false; 2449 } 2450 2451 /** 2338 2452 * Check if a string is ASCII. 2339 2453 *
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)