From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 7888D6F800; Tue, 31 Aug 2021 22:52:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 7888D6F800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630439569; bh=wlvUKbBS84u3O6l+xxNLoaiEt0m+OTexDUj3fuuc8WI=; h=To:Cc:References:In-Reply-To:Date:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=wc16GKeqcCIQHq17uOVep8Nyo5H7YKVpp+c18UuzaOnrebjR4OTVMCAtZCNz87tTW pv7au+DTUthySCrrNBDU4TYxsL59lBuZ3GVoMnrcuXQ3ErzJHo0N1rVNKO3/lRihKj 5dmjdxQVS5Zo6wOECCImxjc7GrkhsZaXtt6y5gxw= Received: from smtp59.i.mail.ru (smtp59.i.mail.ru [217.69.128.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 21CB56F800 for ; Tue, 31 Aug 2021 22:52:49 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 21CB56F800 Received: by smtp59.i.mail.ru with esmtpa (envelope-from ) id 1mL9oO-0001N6-CV; Tue, 31 Aug 2021 22:52:48 +0300 To: Cc: References: <75936763d4e7b280b4bf4f3ed94d1bcf812f0b18.1630398245.git.imeevma@gmail.com> In-Reply-To: <75936763d4e7b280b4bf4f3ed94d1bcf812f0b18.1630398245.git.imeevma@gmail.com> Date: Tue, 31 Aug 2021 22:52:27 +0300 Message-ID: <017501d79ea1$b9c99c80$2d5cd580$@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQFyJm1OORuT7S5NF8fTuY3VQfG1S6xY9mpQ Content-Language: ru X-4EC0790: 10 X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD9EE8D69D3379D80C4782614AD4D168F39C00BD28B7DDE0949182A05F538085040C852D8A8AA49B5C6C7DF739C54443DF8AFFA33C051C47CB47BED754B9D3728A4 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE78E88BD1CA827EF00C2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE7818460412E3A2163EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F2D68FF0CB733BEFB5C9954CAFCF766D74CC7F00164DA146DAFE8445B8C89999728AA50765F7900637BA939FD1B3BAB99B389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC886A7C529F68B8E5CF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA73AA81AA40904B5D9A18204E546F3947C241FAFF9BB01F7E72D242C3BD2E3F4C64AD6D5ED66289B52698AB9A7B718F8C46E0066C2D8992A16725E5C173C3A84C3CE3755A3954A2D0DBA3038C0950A5D36B5C8C57E37DE458B0BC6067A898B09E46D1867E19FE14079C09775C1D3CA48CF3D321E7403792E342EB15956EA79C166A417C69337E82CC275ECD9A6C639B01B78DA827A17800CE70BB89B22BF4660DC731C566533BA786AA5CC5B56E945C8DA X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A213B5FB47DCBC3458F0AFF96BAACF4158235E5A14AD4A4A4625E192CAD1D9E79DB8BF922E402C092CB53C0F8080663ADD X-C1DE0DAB: 0D63561A33F958A54E787E35C595FBD99AE9B36B936E59FB49B7CD1B617798F8D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA752546FE575EB473F1410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D349FD10E01B3CDC9E26744DADE59FD842EC3EABD55AEF36A1976380457021B846A60C4800FE9F113311D7E09C32AA3244C84FCF57829CD96D2586DDD9FABAC2878F2F5F14F68F1805B729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojKvNUqyKacB1O++qVOrTMnw== X-Mailru-Sender: B5B6A6EBBD94DAD88AE996DFA43B41791A6D6719AA4029D8A3FA78FDC6D116E6995597C26086C0995C2808D6142752370A8ED71B308007E3DC85537438B7E1A423D748DE48713E689437F6177E88F7363CDA0F3B3F5B9367 X-Mras: Ok Subject: Re: [Tarantool-patches] [PATCH v1 1/1] sql: allow to bind DECIMAL values X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Timur Safin via Tarantool-patches Reply-To: Timur Safin Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" LGTM, thanks! Timur > -----Original Message----- > From: imeevma@tarantool.org > Sent: Tuesday, August 31, 2021 11:25 AM > To: tsafin@tarantool.org > Cc: tarantool-patches@dev.tarantool.org > Subject: [PATCH v1 1/1] sql: allow to bind DECIMAL values > > After this patch, DECIMAL values can be bound like any other > supported > by SQL values. > > Closes #4717 > --- > https://github.com/tarantool/tarantool/issues/4717 > https://github.com/tarantool/tarantool/tree/imeevma/gh-4717-binding- > for-decimal > > .../unreleased/gh-4717-binding-for-decimal.md | 3 +++ > src/box/bind.c | 6 +++-- > src/box/bind.h | 2 ++ > src/box/lua/execute.c | 4 ++++ > src/box/sql/mem.c | 2 +- > src/box/sql/mem.h | 2 +- > src/box/sql/sqlInt.h | 5 ++++ > src/box/sql/vdbeapi.c | 10 ++++++++ > test/sql-tap/decimal.test.lua | 23 > ++++++++++++++++++- > 9 files changed, 52 insertions(+), 5 deletions(-) > create mode 100644 changelogs/unreleased/gh-4717-binding-for- > decimal.md > > diff --git a/changelogs/unreleased/gh-4717-binding-for-decimal.md > b/changelogs/unreleased/gh-4717-binding-for-decimal.md > new file mode 100644 > index 000000000..3612e287d > --- /dev/null > +++ b/changelogs/unreleased/gh-4717-binding-for-decimal.md > @@ -0,0 +1,3 @@ > +## feature/sql > + > +* Now DECIMAL values can be bound in SQL (gh-4717). > diff --git a/src/box/bind.c b/src/box/bind.c > index 734f65186..58fff0b98 100644 > --- a/src/box/bind.c > +++ b/src/box/bind.c > @@ -192,8 +192,10 @@ sql_bind_column(struct sql_stmt *stmt, const > struct sql_bind *p, > return sql_bind_blob64(stmt, pos, (const void *) p->s, p- > >bytes, > SQL_STATIC); > case MP_EXT: > - assert(p->ext_type == MP_UUID); > - return sql_bind_uuid(stmt, pos, &p->uuid); > + assert(p->ext_type == MP_UUID || p->ext_type == > MP_DECIMAL); > + if (p->ext_type == MP_UUID) > + return sql_bind_uuid(stmt, pos, &p->uuid); > + return sql_bind_dec(stmt, pos, &p->dec); > default: > unreachable(); > } > diff --git a/src/box/bind.h b/src/box/bind.h > index 143f010ce..1ab8ea72d 100644 > --- a/src/box/bind.h > +++ b/src/box/bind.h > @@ -40,6 +40,7 @@ extern "C" { > #include > > #include "msgpuck.h" > +#include "decimal.h" > #include "uuid/tt_uuid.h" > #include "mp_extension_types.h" > > @@ -72,6 +73,7 @@ struct sql_bind { > /** For string or blob. */ > const char *s; > struct tt_uuid uuid; > + decimal_t dec; > }; > }; > > diff --git a/src/box/lua/execute.c b/src/box/lua/execute.c > index 62ccaf3f1..777db82cb 100644 > --- a/src/box/lua/execute.c > +++ b/src/box/lua/execute.c > @@ -375,6 +375,10 @@ lua_sql_bind_decode(struct lua_State *L, struct > sql_bind *bind, int idx, int i) > bind->uuid = *field.uuidval; > break; > } > + if (field.ext_type == MP_DECIMAL) { > + bind->dec = *field.decval; > + break; > + } > diag_set(ClientError, ER_SQL_BIND_TYPE, "USERDATA", > sql_bind_name(bind)); > return -1; > diff --git a/src/box/sql/mem.c b/src/box/sql/mem.c > index 4c40f15dc..24de26548 100644 > --- a/src/box/sql/mem.c > +++ b/src/box/sql/mem.c > @@ -293,7 +293,7 @@ mem_set_double(struct Mem *mem, double value) > } > > void > -mem_set_dec(struct Mem *mem, decimal_t *d) > +mem_set_dec(struct Mem *mem, const decimal_t *d) > { > mem_clear(mem); > mem->u.d = *d; > diff --git a/src/box/sql/mem.h b/src/box/sql/mem.h > index 543944b80..0da45b8af 100644 > --- a/src/box/sql/mem.h > +++ b/src/box/sql/mem.h > @@ -312,7 +312,7 @@ mem_set_uuid(struct Mem *mem, const struct > tt_uuid *uuid); > > /** Clear MEM and set it to DECIMAL. */ > void > -mem_set_dec(struct Mem *mem, decimal_t *dec); > +mem_set_dec(struct Mem *mem, const decimal_t *dec); > > /** Clear MEM and set it to STRING. The string belongs to another > object. */ > void > diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h > index d78076868..2e250dc29 100644 > --- a/src/box/sql/sqlInt.h > +++ b/src/box/sql/sqlInt.h > @@ -76,6 +76,8 @@ > #include "box/txn.h" > #include "trivia/util.h" > > +#include "decimal.h" > + > /* > * These #defines should enable >2GB file support on POSIX if the > * underlying operating system supports it. If the OS lacks > @@ -639,6 +641,9 @@ sql_bind_zeroblob64(sql_stmt *, int, > int > sql_bind_uuid(struct sql_stmt *stmt, int i, const struct tt_uuid > *uuid); > > +int > +sql_bind_dec(struct sql_stmt *stmt, int i, const decimal_t *dec); > + > /** > * Return the number of wildcards that should be bound to. > */ > diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c > index 8031ee0dc..77df0e4cc 100644 > --- a/src/box/sql/vdbeapi.c > +++ b/src/box/sql/vdbeapi.c > @@ -850,6 +850,16 @@ sql_bind_uuid(struct sql_stmt *stmt, int i, > const struct tt_uuid *uuid) > return 0; > } > > +int > +sql_bind_dec(struct sql_stmt *stmt, int i, const decimal_t *dec) > +{ > + struct Vdbe *p = (struct Vdbe *)stmt; > + if (vdbeUnbind(p, i) != 0 || sql_bind_type(p, i, "decimal") != > 0) > + return -1; > + mem_set_dec(&p->aVar[i - 1], dec); > + return 0; > +} > + > int > sql_bind_parameter_count(const struct sql_stmt *stmt) > { > diff --git a/test/sql-tap/decimal.test.lua b/test/sql- > tap/decimal.test.lua > index 69288d696..d422533d6 100755 > --- a/test/sql-tap/decimal.test.lua > +++ b/test/sql-tap/decimal.test.lua > @@ -3,7 +3,7 @@ local build_path = os.getenv("BUILDDIR") > package.cpath = build_path..'/test/sql- > tap/?.so;'..build_path..'/test/sql-tap/?.dylib;'..package.cpath > > local test = require("sqltester") > -test:plan(101) > +test:plan(104) > > local dec = require("decimal") > local dec1 = dec.new("111") > @@ -938,6 +938,27 @@ test:do_catchsql_test( > 1, "Inconsistent types: expected string or varbinary got > decimal(111)" > }) > > +-- Make sure that DECIMAL value can be bound. > +test:do_test( > + "dec-16-1", > + function() > + return box.execute([[SELECT ?;]], {dec1}).rows[1][1] > + end, > + dec1) > +test:do_test( > + "dec-16-2", > + function() > + return box.execute([[SELECT $2;]], {123, dec2}).rows[1][1] > + end, > + dec2) > + > +test:do_test( > + "dec-16-3", > + function() > + return box.execute([[SELECT :two;]], {{[":two"] = > dec3}}).rows[1][1] > + end, > + dec3) > + > test:execsql([[ > DROP TRIGGER t; > DROP VIEW v; > -- > 2.25.1