Changeset 32316 for branches/3.9/src/wp-includes/wp-db.php
- Timestamp:
- 04/27/2015 06:29:08 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.9/src/wp-includes/wp-db.php
r32273 r32316 1894 1894 protected function process_fields( $table, $data, $format ) { 1895 1895 $data = $this->process_field_formats( $data, $format ); 1896 if ( false === $data ) { 1897 return false; 1898 } 1899 1896 1900 $data = $this->process_field_charsets( $data, $table ); 1901 if ( false === $data ) { 1902 return false; 1903 } 1904 1905 $data = $this->process_field_lengths( $data, $table ); 1897 1906 if ( false === $data ) { 1898 1907 return false; … … 1971 1980 // This isn't ASCII. Don't have strip_invalid_text() re-check. 1972 1981 $value['ascii'] = false; 1982 } 1983 1984 $data[ $field ] = $value; 1985 } 1986 1987 return $data; 1988 } 1989 1990 /** 1991 * For string fields, record the maximum string length that field can safely save. 1992 * 1993 * @since 4.2.1 1994 * @access protected 1995 * 1996 * @param array $data As it comes from the wpdb::process_field_charsets() method. 1997 * @param string $table Table name. 1998 * @return array|False The same array as $data with additional 'length' keys, or false if 1999 * any of the values were too long for their corresponding field. 2000 */ 2001 protected function process_field_lengths( $data, $table ) { 2002 foreach ( $data as $field => $value ) { 2003 if ( '%d' === $value['format'] || '%f' === $value['format'] ) { 2004 // We can skip this field if we know it isn't a string. 2005 // This checks %d/%f versus ! %s because it's sprintf() could take more. 2006 $value['length'] = false; 2007 } else { 2008 $value['length'] = $this->get_col_length( $table, $field ); 2009 if ( is_wp_error( $value['length'] ) ) { 2010 return false; 2011 } 2012 } 2013 2014 if ( false !== $value['length'] && strlen( $value['value'] ) > $value['length'] ) { 2015 return false; 1973 2016 } 1974 2017 … … 2300 2343 2301 2344 /** 2345 * Retrieve the maximum string length allowed in a given column. 2346 * 2347 * @since 4.2.1 2348 * @access public 2349 * 2350 * @param string $table Table name. 2351 * @param string $column Column name. 2352 * @return mixed Max column length as an int. False if the column has no 2353 * length. WP_Error object if there was an error. 2354 */ 2355 public function get_col_length( $table, $column ) { 2356 $tablekey = strtolower( $table ); 2357 $columnkey = strtolower( $column ); 2358 2359 // Skip this entirely if this isn't a MySQL database. 2360 if ( false === $this->is_mysql ) { 2361 return false; 2362 } 2363 2364 if ( empty( $this->col_meta[ $tablekey ] ) ) { 2365 // This primes column information for us. 2366 $table_charset = $this->get_table_charset( $table ); 2367 if ( is_wp_error( $table_charset ) ) { 2368 return $table_charset; 2369 } 2370 } 2371 2372 if ( empty( $this->col_meta[ $tablekey ][ $columnkey ] ) ) { 2373 return false; 2374 } 2375 2376 $typeinfo = explode( '(', $this->col_meta[ $tablekey ][ $columnkey ]->Type ); 2377 2378 $type = strtolower( $typeinfo[0] ); 2379 if ( ! empty( $typeinfo[1] ) ) { 2380 $length = trim( $typeinfo[1], ')' ); 2381 } else { 2382 $length = false; 2383 } 2384 2385 switch( $type ) { 2386 case 'binary': 2387 case 'char': 2388 case 'varbinary': 2389 case 'varchar': 2390 return $length; 2391 break; 2392 case 'tinyblob': 2393 case 'tinytext': 2394 return 255; // 2^8 - 1 2395 break; 2396 case 'blob': 2397 case 'text': 2398 return 65535; // 2^16 - 1 2399 break; 2400 case 'mediumblob': 2401 case 'mediumtext': 2402 return 16777215; // 2^24 - 1 2403 break; 2404 case 'longblob': 2405 case 'longtext': 2406 return 4294967295; // 2^32 - 1 2407 break; 2408 default: 2409 return false; 2410 } 2411 2412 return false; 2413 } 2414 2415 /** 2302 2416 * Check if a string is ASCII. 2303 2417 *
Note: See TracChangeset
for help on using the changeset viewer.