Skip to content

Commit

Permalink
text: do not override built-in case functions
Browse files Browse the repository at this point in the history
  • Loading branch information
nalgeon committed Aug 1, 2024
1 parent 18c0842 commit 2ec25ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/text/extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,6 @@ static int collate_nocase(void* unused, int n1, const void* s1, int n2, const vo

int text_init(sqlite3* db) {
static const int flags = SQLITE_UTF8 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC;
static const int flags16 = SQLITE_UTF16 | SQLITE_INNOCUOUS | SQLITE_DETERMINISTIC;

// substrings
sqlite3_create_function(db, "text_substring", 2, flags, 0, text_substring2, 0, 0);
Expand All @@ -935,7 +934,6 @@ int text_init(sqlite3* db) {
sqlite3_create_function(db, "text_has_suffix", 2, flags, 0, text_has_suffix, 0, 0);
sqlite3_create_function(db, "text_count", 2, flags, 0, text_count, 0, 0);
sqlite3_create_function(db, "text_like", 2, flags, 0, text_like, 0, 0);
sqlite3_create_function(db, "like", 2, flags16, 0, text_like, 0, 0);

// split and join
sqlite3_create_function(db, "text_split", 3, flags, 0, text_split, 0, 0);
Expand All @@ -961,9 +959,7 @@ int text_init(sqlite3* db) {

// change case
sqlite3_create_function(db, "text_upper", 1, flags, utf8_toupper, text_change_case, 0, 0);
sqlite3_create_function(db, "upper", 1, flags16, utf8_toupper, text_change_case, 0, 0);
sqlite3_create_function(db, "text_lower", 1, flags, utf8_tolower, text_change_case, 0, 0);
sqlite3_create_function(db, "lower", 1, flags16, utf8_tolower, text_change_case, 0, 0);
sqlite3_create_function(db, "text_title", 1, flags, utf8_totitle, text_change_case, 0, 0);
sqlite3_create_function(db, "text_casefold", 1, flags, utf8_casefold, text_change_case, 0, 0);

Expand All @@ -985,7 +981,7 @@ int text_init(sqlite3* db) {
sqlite3_create_function(db, "bit_length", 1, flags, 0, text_bit_size, 0, 0);

// collation
sqlite3_create_collation(db, "nocase", SQLITE_UTF8, NULL, collate_nocase);
sqlite3_create_collation(db, "text_nocase", SQLITE_UTF8, NULL, collate_nocase);

return SQLITE_OK;
}
17 changes: 8 additions & 9 deletions test/text.sql
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,13 @@ select '29_01', text_like(null, 'hello') is null;
select '29_02', text_like('hello', null) is null;
select '29_03', text_like('hello', 'hello') = 1;
select '29_04', text_like('h%', 'hello') = 1;
select '29_05', like('Hel_o, w__ld!', 'hello, world!') = 1;
select '29_06', like('H%l_, w%ld!', 'hello, world!') = 1;
select '29_07', like('H%l_, w%ld.', 'hello, world!') = 0;
select '29_08', like('c_mo est_s', 'cómo estás') = 1;
select '29_09', like('прив_т', 'пРиВеТ') = 1;
select '29_10', ('пРиВеТ' like 'прив_т') = 1;
select '29_05', text_like('Hel_o, w__ld!', 'hello, world!') = 1;
select '29_06', text_like('H%l_, w%ld!', 'hello, world!') = 1;
select '29_07', text_like('H%l_, w%ld.', 'hello, world!') = 0;
select '29_08', text_like('c_mo est_s', 'cómo estás') = 1;
select '29_09', text_like('прив_т', 'пРиВеТ') = 1;
-- nocase collation
select '31_01', (select 1 where 'hello' = 'hello' collate nocase) = 1;
select '31_02', (select 1 where 'hell0' = 'hello' collate nocase) is null;
select '31_03', (select 1 where 'привет' = 'ПРИВЕТ' collate nocase) = 1;
select '31_01', (select 1 where 'hello' = 'hello' collate text_nocase) = 1;
select '31_02', (select 1 where 'hell0' = 'hello' collate text_nocase) is null;
select '31_03', (select 1 where 'привет' = 'ПРИВЕТ' collate text_nocase) = 1;

0 comments on commit 2ec25ce

Please sign in to comment.