From 2ec25ce270003854867a57b7862a4e47eccbd6db Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 2 Aug 2024 02:58:11 +0500 Subject: [PATCH] text: do not override built-in case functions --- src/text/extension.c | 6 +----- test/text.sql | 17 ++++++++--------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/text/extension.c b/src/text/extension.c index 95a67e3..c7dbd3d 100644 --- a/src/text/extension.c +++ b/src/text/extension.c @@ -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); @@ -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); @@ -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); @@ -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; } diff --git a/test/text.sql b/test/text.sql index a67961b..b0cbe03 100644 --- a/test/text.sql +++ b/test/text.sql @@ -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;