Ticket #27272: 27272.diff
File 27272.diff, 3.0 KB (added by , 11 years ago) |
---|
-
src/wp-includes/meta.php
833 833 $meta_value = trim( $meta_value ); 834 834 } 835 835 836 if ( in_array( $meta_type, array( 'SIGNED', 'UNSIGNED' ) ) ) { 837 $cast_string = "CAST(%s AS $meta_type)"; 838 } else { 839 $cast_string = '%s'; 840 } 841 $meta_compare_string = $cast_string; 842 836 843 if ( 'IN' == substr( $meta_compare, -2) ) { 837 $meta_compare_string = '(' . substr( str_repeat( ',%s', count( $meta_value ) ), 1 ) . ')';844 $meta_compare_string = '(' . substr( str_repeat( ", $cast_string", count( $meta_value ) ), 1 ) . ')'; 838 845 } elseif ( 'BETWEEN' == substr( $meta_compare, -7) ) { 839 846 $meta_value = array_slice( $meta_value, 0, 2 ); 840 $meta_compare_string = '%s AND %s';847 $meta_compare_string = "$cast_string AND $cast_string"; 841 848 } elseif ( 'LIKE' == substr( $meta_compare, -4 ) ) { 842 849 $meta_value = '%' . like_escape( $meta_value ) . '%'; 843 $meta_compare_string = '%s';844 } else {845 $meta_compare_string = '%s';846 850 } 847 851 848 852 if ( ! empty( $where[$k] ) ) -
tests/phpunit/tests/meta/query.php
117 117 ) ); 118 118 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 119 119 120 $this->assertEquals( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = '' )" ) );120 $this->assertEquals( 1, substr_count( $sql['where'], "CAST($wpdb->postmeta.meta_value AS CHAR) = ''" ) ); 121 121 } 122 122 123 123 /** … … 194 194 $this->assertContains( "{$wpdb->postmeta}.meta_key = 'exclude'\nOR", $sql['where'] ); 195 195 $this->assertNotContains( "{$wpdb->postmeta}.post_id IS NULL", $sql['where'] ); 196 196 } 197 198 function test_cast_both_sides() { 199 global $wpdb; 200 201 $query = new WP_Meta_Query( array( 202 array( 203 'key' => 'number_string', 204 'value' => '1000000', 205 'compare' => '<=', 206 'type' => 'NUMERIC', 207 ), 208 ) ); 209 210 $sql = $query->get_sql( 'post', $wpdb->posts, 'ID', $this ); 211 $this->assertNotContains( "CAST({$wpdb->postmeta}.meta_value AS SIGNED) <= '1000000'", $sql['where'] ); 212 $this->assertContains( "CAST({$wpdb->postmeta}.meta_value AS SIGNED) <= CAST('1000000' AS SIGNED)", $sql['where'] ); 213 } 197 214 } -
tests/phpunit/tests/meta.php
180 180 ) ); 181 181 182 182 $this->assertEquals( array( $post_id2, $post_id1 ), $posts->posts ); 183 $this->assertEquals( 2, substr_count( $posts->request, 'CAST(' ) ); 183 $this->assertNotContains( "> '0'", $posts->request ); 184 $this->assertContains( "> CAST('0' AS UNSIGNED)", $posts->request ); 185 $this->assertEquals( 3, substr_count( $posts->request, 'CAST(' ) ); 184 186 } 185 187 186 188 function test_meta_cache_order_asc() {