Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Откровениями в понимании «почему так» можно делится в комментариях..
/*
** <sqlite3_unicode>
** The built-in collating sequence: NOCASE is extended to accomodate the
** unicode case folding mapping tables to normalize characters to their
** fold equivalents and test them for equality.
**
** Both UTF-8 and UTF-16 implementations are supported.
*/
/*
** <sqlite3_unicode>
** Implementation of the FOLD(), UPPER(), LOWER(), TITLE() SQL functions.
** This function case folds each character in the supplied string to its
** single character equivalent.
**
** The conversion to be made depends on the contents of (sqlite3_context *)context
** where a pointer to a specific case conversion function is stored.
*/
/*
** <sqlite3_unicode>
** Implementation of the UNACCENT() SQL function.
** This function decomposes each character in the supplied string
** to its components and strips any accents present in the string.
**
** This function may result to a longer output string compared
** to the original input string. Memory has been properly reallocated
** to accomodate for the extra memory length required.
*/
% package require sqlite3
## откроем БД :
% sqlite3 db test.sqlite
## стандартный NOCASE collation вернет здесь "none", потому что
## действует ASCII only ...
% db onecolumn {select 'ok' where 'абвгд' == 'АБВГД' collate NOCASE union all select 'none'}
none
## регистрируем NOCASE collation, используя tcl функцию (utf-8 safe)
% proc NOCASE_compare {a b} {
string compare -nocase $a $b
}
% db collate NOCASE NOCASE_compare
## теперь снова пробуем, NOCASE collation вернет здесь уже "ок"
% db onecolumn {select 'ok' where 'абвгд' == 'АБВГД' collate NOCASE union all select 'none'}
ok
## регистрируем собственную функцию для "nocase like" :
% db function NCLIKE {string match -nocase}
## test it ...
% db onecolumn {select 'ok' where NCLIKE('Te?t - аб*', 'TEST - АБВГД') union all select 'none'}
ok
## test it in table ...
% set search {Te?t - аб*}
% db onecolum {select field1 from tab1 where NCLIKE($search, field1)}
TEST - АБВГД
In SQLite, the datatype of a value is associated with the value itself, not with its container.То есть (если подытожить то, что там по ссылке ещё понаписано), то что указано для колонки при создании таблицы, и то, что будет хранится собственно в полях записей — вещи связанные ОООЧЕНЬ косвенно. И никто не скажет вам, что хранится не то, что вы декларировали при создании таблицы. Если не спросите.
BLOB. The value is a blob of data, stored exactly as it was input.В частности, если вы все строки биндите как блобы, например ради того чтоб не конвертить любимый Windows-1251 в эти их UTF-ы, то в полях записей так и будут хранится блобы. Собственно, этого-то тут и хотелось. Чтоб хранились.
A TEXT value is less than a BLOB value.Воот. Если вдруг вздумали сравнивать с литералом каким-нибудь, то будьте готовы обломаться.
When two BLOB values are compared, the result is determined using memcmp().А если сравнивать блоб с бинденным блобом — то тоже может быть всякое, если блоб вдруг почему-то не байт в байт прям совпадает.
SQLite и UNICODE