Changeset 35655
- Timestamp:
- 11/17/2015 06:12:08 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
src/wp-includes/wp-db.php (modified) (1 diff)
-
tests/phpunit/tests/db/charset.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/wp-db.php
r35544 r35655 2812 2812 } 2813 2813 2814 if ( $this->charset ) { 2815 $connection_charset = $this->charset; 2816 } else { 2817 if ( $this->use_mysqli ) { 2818 $connection_charset = mysqli_character_set_name( $this->dbh ); 2819 } else { 2820 $connection_charset = mysql_client_encoding(); 2821 } 2822 } 2823 2814 2824 if ( is_array( $value['length'] ) ) { 2815 $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING {$this->charset})", $value['value'], $value['length']['length'] );2825 $queries[ $col ] = $this->prepare( "CONVERT( LEFT( CONVERT( %s USING $charset ), %.0f ) USING $connection_charset )", $value['value'], $value['length']['length'] ); 2816 2826 } else if ( 'binary' !== $charset ) { 2817 2827 // If we don't have a length, there's no need to convert binary - it will always return the same result. 2818 $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING {$this->charset})", $value['value'] );2828 $queries[ $col ] = $this->prepare( "CONVERT( CONVERT( %s USING $charset ) USING $connection_charset )", $value['value'] ); 2819 2829 } 2820 2830 -
trunk/tests/phpunit/tests/db/charset.php
r35186 r35655 866 866 $this->assertEquals( $safe_query, $stripped_query ); 867 867 } 868 869 /** 870 * @ticket 34708 871 */ 872 function test_no_db_charset_defined() { 873 $tablename = 'test_cp1251_query_' . rand_str( 5 ); 874 if ( ! self::$_wpdb->query( "CREATE TABLE $tablename ( a VARCHAR(50) ) DEFAULT CHARSET 'cp1251'" ) ) { 875 $this->markTestSkipped( "Test requires the 'cp1251' charset" ); 876 } 877 878 $charset = self::$_wpdb->charset; 879 self::$_wpdb->charset = ''; 880 881 $safe_query = "INSERT INTO $tablename( `a` ) VALUES( 'safe data' )"; 882 $stripped_query = self::$_wpdb->strip_invalid_text_from_query( $safe_query ); 883 884 self::$_wpdb->query( "DROP TABLE $tablename" ); 885 886 self::$_wpdb->charset = $charset; 887 888 $this->assertEquals( $safe_query, $stripped_query ); 889 } 868 890 }
Note: See TracChangeset
for help on using the changeset viewer.