@@ -3033,13 +3033,13 @@ public function testTranslatesUtf8SELECT() {
3033
3033
$ this ->assertQuery ( 'DELETE FROM _options ' );
3034
3034
}
3035
3035
3036
- public function testTranslateLikeBinaryAndGlob () {
3036
+ public function testTranslateLikeBinary () {
3037
3037
// Create a temporary table for testing
3038
3038
$ this ->assertQuery (
3039
- "CREATE TABLE _tmp_table (
3039
+ "CREATE TABLE _tmp_table (
3040
3040
ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
3041
- name varchar(20) NOT NULL default ''
3042
- ); "
3041
+ name varchar(20)
3042
+ ) "
3043
3043
);
3044
3044
3045
3045
// Insert data into the table
@@ -3052,70 +3052,110 @@ public function testTranslateLikeBinaryAndGlob() {
3052
3052
$ this ->assertQuery ( "INSERT INTO _tmp_table (name) VALUES ('special%chars'); " );
3053
3053
$ this ->assertQuery ( "INSERT INTO _tmp_table (name) VALUES ('special_chars'); " );
3054
3054
$ this ->assertQuery ( "INSERT INTO _tmp_table (name) VALUES ('special \\chars'); " );
3055
+ $ this ->assertQuery ( "INSERT INTO _tmp_table (name) VALUES ('aste*risk'); " );
3056
+ $ this ->assertQuery ( "INSERT INTO _tmp_table (name) VALUES ('question?mark'); " );
3055
3057
3056
- // Test case-sensitive LIKE BINARY
3058
+ // Test exact string
3057
3059
$ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'first' " );
3058
3060
$ this ->assertCount ( 1 , $ result );
3059
3061
$ this ->assertEquals ( 'first ' , $ result [0 ]->name );
3060
3062
3061
- // Test case-sensitive LIKE BINARY with wildcard %
3063
+ // Test exact string with no matches
3064
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'third' " );
3065
+ $ this ->assertCount ( 0 , $ result );
3066
+
3067
+ // Test mixed case
3068
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'First' " );
3069
+ $ this ->assertCount ( 0 , $ result );
3070
+
3071
+ // Test % wildcard
3062
3072
$ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'f%' " );
3063
3073
$ this ->assertCount ( 1 , $ result );
3064
3074
$ this ->assertEquals ( 'first ' , $ result [0 ]->name );
3065
3075
3066
- // Test case-sensitive LIKE BINARY with wildcard _
3076
+ // Test % wildcard with no matches
3077
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'x%' " );
3078
+ $ this ->assertCount ( 0 , $ result );
3079
+
3080
+ // Test "%" character (not a wildcard)
3081
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'special \\%chars' " );
3082
+ $ this ->assertCount ( 1 , $ result );
3083
+ $ this ->assertEquals ( 'special%chars ' , $ result [0 ]->name );
3084
+
3085
+ // Test _ wildcard
3067
3086
$ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'f_rst' " );
3068
3087
$ this ->assertCount ( 1 , $ result );
3069
3088
$ this ->assertEquals ( 'first ' , $ result [0 ]->name );
3070
3089
3071
- // Test case-insensitive LIKE
3072
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE 'FIRST ' " );
3073
- $ this ->assertCount ( 2 , $ result ); // Should match both 'first' and 'FIRST'
3090
+ // Test _ wildcard with no matches
3091
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'x_yz ' " );
3092
+ $ this ->assertCount ( 0 , $ result );
3074
3093
3075
- // Test mixed case with LIKE BINARY
3076
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'First' " );
3077
- $ this ->assertCount ( 0 , $ result );
3094
+ // Test "_" character (not a wildcard)
3095
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'special \\_chars' " );
3096
+ $ this ->assertCount ( 1 , $ result );
3097
+ $ this ->assertEquals ( 'special_chars ' , $ result [0 ]->name );
3078
3098
3079
- // Test no matches with LIKE BINARY
3080
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'third' " );
3081
- $ this ->assertCount ( 0 , $ result );
3099
+ // Test escaping of "*"
3100
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'aste*risk' " );
3101
+ $ this ->assertCount ( 1 , $ result );
3102
+ $ this ->assertEquals ( 'aste*risk ' , $ result [0 ]->name );
3082
3103
3083
- // Test GLOB equivalent for case-sensitive matching with wildcard
3084
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name GLOB 'f*' " );
3085
- $ this ->assertCount ( 1 , $ result );
3086
- $ this ->assertEquals ( 'first ' , $ result [0 ]->name );
3104
+ // Test escaping of "*" with no matches
3105
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'f*' " );
3106
+ $ this ->assertCount ( 0 , $ result );
3087
3107
3088
- // Test GLOB with single character wildcard
3089
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name GLOB 'f?rst' " );
3090
- $ this ->assertCount ( 1 , $ result );
3091
- $ this ->assertEquals ( 'first ' , $ result [0 ]->name );
3092
-
3093
- // Test GLOB with no matches
3094
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name GLOB 'S*' " );
3095
- $ this ->assertCount ( 0 , $ result );
3108
+ // Test escaping of "?"
3109
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'question?mark' " );
3110
+ $ this ->assertCount ( 1 , $ result );
3111
+ $ this ->assertEquals ( 'question?mark ' , $ result [0 ]->name );
3096
3112
3097
- // Test GLOB case sensitivity with LIKE and GLOB
3098
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name GLOB 'first'; " );
3099
- $ this ->assertCount ( 1 , $ result ); // Should only match 'first'
3113
+ // Test escaping of "?" with no matches
3114
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'f?rst' " );
3115
+ $ this ->assertCount ( 0 , $ result );
3100
3116
3101
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name GLOB 'FIRST'; " );
3102
- $ this ->assertCount ( 1 , $ result ); // Should only match 'FIRST'
3117
+ // Test escaping of character class
3118
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY '[f]irst' " );
3119
+ $ this ->assertCount ( 0 , $ result );
3103
3120
3104
- // Test NULL comparison with LIKE BINARY
3105
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'first'; " );
3106
- $ this ->assertCount ( 1 , $ result );
3107
- $ this ->assertEquals ( 'first ' , $ result [0 ]->name );
3108
-
3109
- $ result = $ this ->assertQuery ( 'SELECT * FROM _tmp_table WHERE name LIKE BINARY NULL; ' );
3110
- $ this ->assertCount ( 0 , $ result ); // NULL comparison should return no results
3121
+ // Test NULL
3122
+ $ result = $ this ->assertQuery ( 'SELECT * FROM _tmp_table WHERE name LIKE BINARY NULL ' );
3123
+ $ this ->assertCount ( 0 , $ result );
3111
3124
3112
3125
// Test pattern with special characters using LIKE BINARY
3113
- $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY '%special%'; " );
3126
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY '%special%' " );
3114
3127
$ this ->assertCount ( 4 , $ result );
3115
3128
$ this ->assertEquals ( '%special% ' , $ result [0 ]->name );
3116
3129
$ this ->assertEquals ( 'special%chars ' , $ result [1 ]->name );
3117
3130
$ this ->assertEquals ( 'special_chars ' , $ result [2 ]->name );
3118
- $ this ->assertEquals ( 'specialchars ' , $ result [3 ]->name );
3131
+ $ this ->assertEquals ( 'special\chars ' , $ result [3 ]->name );
3132
+
3133
+ // Test escaping - "\t" is a tab character
3134
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'firs \\t' " );
3135
+ $ this ->assertCount ( 0 , $ result );
3136
+
3137
+ // Test escaping - "\\t" is "t" (input resolves to "\t", which LIKE resolves to "t")
3138
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'firs \\\\t' " );
3139
+ $ this ->assertCount ( 1 , $ result );
3140
+ $ this ->assertEquals ( 'first ' , $ result [0 ]->name );
3141
+
3142
+ // Test escaping - "\%" is a "%" literal
3143
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'special \\%chars' " );
3144
+ $ this ->assertCount ( 1 , $ result );
3145
+ $ this ->assertEquals ( 'special%chars ' , $ result [0 ]->name );
3146
+
3147
+ // Test escaping - "\\%" is also a "%" literal
3148
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'special \\\\%chars' " );
3149
+ $ this ->assertCount ( 1 , $ result );
3150
+ $ this ->assertEquals ( 'special%chars ' , $ result [0 ]->name );
3151
+
3152
+ // Test escaping - "\\\%" is "\" and a wildcard
3153
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'special \\\\\\%chars' " );
3154
+ $ this ->assertCount ( 0 , $ result );
3155
+
3156
+ // Test LIKE without BINARY
3157
+ $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE 'FIRST' " );
3158
+ $ this ->assertCount ( 2 , $ result ); // Should match both 'first' and 'FIRST'
3119
3159
}
3120
3160
3121
3161
public function testOnConflictReplace () {
0 commit comments