From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 01808265BE for ; Mon, 30 Jul 2018 06:35:41 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ng2Ia7RUfjpY for ; Mon, 30 Jul 2018 06:35:40 -0400 (EDT) Received: from smtp16.mail.ru (smtp16.mail.ru [94.100.176.153]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 37B761FCE1 for ; Mon, 30 Jul 2018 06:35:39 -0400 (EDT) Received: from [185.6.245.156] (port=54500 helo=msk-wire-v_shpilevoy-v.shpilevoy.mail.msk) by smtp16.mail.ru with esmtpa (envelope-from ) id 1fk5Wb-00078m-K4 for tarantool-patches@freelists.org; Mon, 30 Jul 2018 13:35:37 +0300 Subject: [tarantool-patches] Re: [PATCH v1 1/1] sql: UPPER and LOWER support COLLATE References: <76c1c2215de0e9d35e9501158efb1eea8ecfa52b.1532705640.git.imeevma@gmail.com> From: Vladislav Shpilevoy Message-ID: <5e91ab73-cebc-5e81-813b-317bfb484a76@tarantool.org> Date: Mon, 30 Jul 2018 13:35:35 +0300 MIME-Version: 1.0 In-Reply-To: <76c1c2215de0e9d35e9501158efb1eea8ecfa52b.1532705640.git.imeevma@gmail.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Hi! Thanks for the patch! Please, write me in 'Copy' when sending a patch on review. See 3 comments below. On 27/07/2018 18:40, imeevma@tarantool.org wrote: > SQL functions UPPER and LOWER now works > with COLLATE as they should according to > ANSI Standart. > > Closes #3052. > --- > Branch: https://github.com/tarantool/tarantool/tree/imeevma/gh-3052-collate-for-upper-lower > Issue: https://github.com/tarantool/tarantool/issues/3052 > > src/box/sql/func.c | 18 ++++++++++----- > test/sql/collation.result | 53 +++++++++++++++++++++++++++++++++++++++++++++ > test/sql/collation.test.lua | 20 +++++++++++++++++ > 3 files changed, 86 insertions(+), 5 deletions(-) > > diff --git a/src/box/sql/func.c b/src/box/sql/func.c > index e211de1..637121c 100644 > --- a/src/box/sql/func.c > +++ b/src/box/sql/func.c > @@ -503,6 +504,14 @@ case_type##ICUFunc(sqlite3_context *context, int argc, sqlite3_value **argv) \ > return; \ > } \ > UErrorCode status = U_ZERO_ERROR; \ > + struct coll *pColl = sqlite3GetFuncCollSeq(context); \ 1. Please, use Tarantool style for new code. > + const char *locale = NULL; \ > + if (pColl != NULL) { \ > + locale = ucol_getLocaleByType(pColl->collator, \ > + ULOC_VALID_LOCALE, &status); \ > + } \ > + UCaseMap *pUCaseMap = ucasemap_open(locale, 0, &status); \ > + assert(pUCaseMap); \ > int len = ucasemap_utf8To##case_type(pUCaseMap, z1, n, z2, n, &status);\ > if (len > n) { \ > status = U_ZERO_ERROR; \ > diff --git a/test/sql/collation.result b/test/sql/collation.result > index 7fec96d..e057bb6 100644 > --- a/test/sql/collation.result > +++ b/test/sql/collation.result > @@ -32,6 +32,59 @@ box.sql.execute("SELECT 1 LIMIT 1 COLLATE BINARY, 1;") > --- > - error: 'near "COLLATE": syntax error' > ... > +-- gh-3052: sql: upper/lower support only default locale 2. I do not think that in /test/sql directory it is necessary to specify 'sql:' subsystem. > +-- For tr-TR result depends on collation > +box.internal.collation.create('TURKISH', 'ICU', 'tr-TR', {strength='primary'}); > +--- > +... > +box.sql.execute([[CREATE TABLE tu (descriptor CHAR(50) PRIMARY KEY, letter CHAR)]]); > +--- > +... > +box.sql.execute([[INSERT INTO tu VALUES ('Latin Capital Letter I U+0049','I');]]) > +--- > +... > +box.sql.execute([[INSERT INTO tu VALUES ('Latin Small Letter I U+0069','i');]]) > +--- > +... > +box.sql.execute([[INSERT INTO tu VALUES ('Latin Capital Letter I With Dot Above U+0130','İ');]]) > +--- > +... > +box.sql.execute([[INSERT INTO tu VALUES ('Latin Small Letter Dotless I U+0131','ı');]]) > +--- > +... > +-- Without collation > +box.sql.execute([[SELECT descriptor, upper(letter) AS upper,lower(letter) AS lower FROM tu;]]) > +--- > +- - ['Latin Capital Letter I U+0049', 'I', 'i'] > + - ['Latin Capital Letter I With Dot Above U+0130', 'İ', 'i̇'] > + - ['Latin Small Letter Dotless I U+0131', 'I', 'ı'] > + - ['Latin Small Letter I U+0069', 'I', 'i'] > +... > +-- With collation > +box.sql.execute([[SELECT descriptor, upper(letter COLLATE "TURKISH") AS upper,lower(letter COLLATE "TURKISH") AS lower FROM tu;]]) > +--- > +- - ['Latin Capital Letter I U+0049', 'I', 'ı'] > + - ['Latin Capital Letter I With Dot Above U+0130', 'İ', 'i'] > + - ['Latin Small Letter Dotless I U+0131', 'I', 'ı'] > + - ['Latin Small Letter I U+0069', 'İ', 'i'] > +... > +-- For de-DE result is actually the same > +box.internal.collation.create('GERMAN', 'ICU', 'de-DE', {strength='primary'}); > +--- > +... > +box.sql.execute([[INSERT INTO tu VALUES ('German Small Letter Sharp S U+00DF','ß');]]) > +--- > +... > +-- Without collation > +box.sql.execute([[SELECT descriptor, upper(letter), letter FROM tu where UPPER(letter) = 'SS';]]) > +--- > +- - ['German Small Letter Sharp S U+00DF', 'SS', 'ß'] > +... > +-- With collation > +box.sql.execute([[SELECT descriptor, upper(letter COLLATE "GERMAN"), letter FROM tu where UPPER(letter COLLATE "GERMAN") = 'SS';]]) > +--- > +- - ['German Small Letter Sharp S U+00DF', 'SS', 'ß'] > +... > box.schema.user.grant('guest','read,write,execute', 'universe') > --- > ... 3. Cleanup the test: drop tables, collations.