@@ -3033,13 +3033,13 @@ public function testTranslatesUtf8SELECT() {
30333033 $ this ->assertQuery ( 'DELETE FROM _options ' );
30343034 }
30353035
3036- public function testTranslateLikeBinaryAndGlob () {
3036+ public function testTranslateLikeBinary () {
30373037 // Create a temporary table for testing
30383038 $ this ->assertQuery (
3039- "CREATE TABLE _tmp_table (
3039+ "CREATE TABLE _tmp_table (
30403040 ID INTEGER PRIMARY KEY AUTO_INCREMENT NOT NULL,
3041- name varchar(20) NOT NULL default ''
3042- ); "
3041+ name varchar(20)
3042+ ) "
30433043 );
30443044
30453045 // Insert data into the table
@@ -3052,70 +3052,110 @@ public function testTranslateLikeBinaryAndGlob() {
30523052 $ this ->assertQuery ( "INSERT INTO _tmp_table (name) VALUES ('special%chars'); " );
30533053 $ this ->assertQuery ( "INSERT INTO _tmp_table (name) VALUES ('special_chars'); " );
30543054 $ 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'); " );
30553057
3056- // Test case-sensitive LIKE BINARY
3058+ // Test exact string
30573059 $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'first' " );
30583060 $ this ->assertCount ( 1 , $ result );
30593061 $ this ->assertEquals ( 'first ' , $ result [0 ]->name );
30603062
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
30623072 $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'f%' " );
30633073 $ this ->assertCount ( 1 , $ result );
30643074 $ this ->assertEquals ( 'first ' , $ result [0 ]->name );
30653075
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
30673086 $ result = $ this ->assertQuery ( "SELECT * FROM _tmp_table WHERE name LIKE BINARY 'f_rst' " );
30683087 $ this ->assertCount ( 1 , $ result );
30693088 $ this ->assertEquals ( 'first ' , $ result [0 ]->name );
30703089
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 );
30743093
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 );
30783098
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 );
30823103
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 );
30873107
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 );
30963112
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 );
31003116
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 );
31033120
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 );
31113124
31123125 // 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%' " );
31143127 $ this ->assertCount ( 4 , $ result );
31153128 $ this ->assertEquals ( '%special% ' , $ result [0 ]->name );
31163129 $ this ->assertEquals ( 'special%chars ' , $ result [1 ]->name );
31173130 $ 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'
31193159 }
31203160
31213161 public function testOnConflictReplace () {
0 commit comments