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 D92046EC55; Fri, 27 Aug 2021 11:48:02 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org D92046EC55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630054083; bh=6Wu7fakZcy5wvo/IpQ+u5zNS9SZnZxjTwGHBU7K3/aA=; h=Date:To:Cc:References:In-Reply-To:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=kxZHa1nTgLGe0n96rvbEFdmj1KPycQnOr2s2T9wcEHhxcjW51pGJkPKbiU3l4MLaf hEGLmzyNi7JDgV52szV1g8XA7lbgWA2wvsb1Tz7yPTl2B9439Nfq3A6hpQidIuuaHo aq5wgmj6t5dUoqkQdCGz65llbIpn495q9dUsqqwc= Received: from smtpng2.i.mail.ru (smtpng2.i.mail.ru [94.100.179.3]) (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 649116EC55 for ; Fri, 27 Aug 2021 11:48:01 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 649116EC55 Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mJXWq-0005ZJ-G2; Fri, 27 Aug 2021 11:48:00 +0300 Date: Fri, 27 Aug 2021 11:47:59 +0300 To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org Message-ID: <20210827084759.GA98711@tarantool.org> References: <1d3ddbfe02f20123aada9b0e252368310f742bf0.1629989915.git.imeevma@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-4EC0790: 10 X-7564579A: B8F34718100C35BD X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F6525B29142351271182A05F538085040A2F379E720552951C7F897A23675B04C85B18D35EC3FF663FD783A76751E1390 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE7A3589DC202DD7369EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F7900637ABBE65DF69007335EA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F27A3F54806B33F53B92B40456B7EBBBF3CC7F00164DA146DAFE8445B8C89999728AA50765F7900637F924B32C592EA89F389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC8A9FF340AA05FB58CF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8B9F5955FECEF5819E75ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 0D63561A33F958A58A29C7D5A7AD4EA54EB297D3D2F8AAA3185AEE1DA20A78F3D59269BC5F550898D99A6476B3ADF6B47008B74DF8BB9EF7333BD3B22AA88B938A852937E12ACA756665624D6DDF07B5410CA545F18667F91A7EA1CDA0B5A7A0 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34C02783DDD5A45DEF80ECE3680D7D108EC54BC4243BEE33189A5A2486A301A5537504AAFE41EBE1601D7E09C32AA3244C6B9E1578C044951CE37A6E7701F6625697FE24653F78E668729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj+bzRAXO2P1TwMZe3z0WkLA== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5D222F901B7BF0552A0DB3BF7437B711BB83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B 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: Mergen Imeev via Tarantool-patches Reply-To: Mergen Imeev Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Thank you for the review! My answers, diff and new patch below. On Thu, Aug 26, 2021 at 10:51:07PM +0200, Vladislav Shpilevoy wrote: > Thanks for the patch! > > See 3 comments below. > > > 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..9ffd64272 > > --- /dev/null > > +++ b/changelogs/unreleased/gh-4717-binding-for-decimal.md > > @@ -0,0 +1,4 @@ > > +## feature/sql > > + > > +* Now DECIMAL values can be binded in SQL (gh-4717). > > 1. binded -> bound. > Fixed. > > diff --git a/src/box/bind.h b/src/box/bind.h > > index 143f010ce..a88cc105b 100644 > > --- a/src/box/bind.h > > +++ b/src/box/bind.h > > @@ -40,6 +40,7 @@ extern "C" { > > #include > > > > #include "msgpuck.h" > > +#include "lua/decimal.h" > > 2. Why do you need Lua in the non-Lua folder? > Replaced by "decimal.h". > > #include "uuid/tt_uuid.h" > > #include "mp_extension_types.h" > > > > diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h > > index d78076868..5d622bfad 100644 > > --- a/src/box/sql/sqlInt.h > > +++ b/src/box/sql/sqlInt.h > > @@ -75,6 +75,7 @@ > > #include "box/sql.h" > > #include "box/txn.h" > > #include "trivia/util.h" > > +#include "lua/decimal.h" > > 3. Ditto. Same. Diff: diff --git a/changelogs/unreleased/gh-4717-binding-for-decimal.md b/changelogs/unreleased/gh-4717-binding-for-decimal.md index 9ffd64272..3612e287d 100644 --- a/changelogs/unreleased/gh-4717-binding-for-decimal.md +++ b/changelogs/unreleased/gh-4717-binding-for-decimal.md @@ -1,4 +1,3 @@ ## feature/sql -* Now DECIMAL values can be binded in SQL (gh-4717). - +* Now DECIMAL values can be bound in SQL (gh-4717). diff --git a/src/box/bind.h b/src/box/bind.h index a88cc105b..1ab8ea72d 100644 --- a/src/box/bind.h +++ b/src/box/bind.h @@ -40,7 +40,7 @@ extern "C" { #include #include "msgpuck.h" -#include "lua/decimal.h" +#include "decimal.h" #include "uuid/tt_uuid.h" #include "mp_extension_types.h" diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 5d622bfad..2e250dc29 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -75,7 +75,8 @@ #include "box/sql.h" #include "box/txn.h" #include "trivia/util.h" -#include "lua/decimal.h" + +#include "decimal.h" /* * These #defines should enable >2GB file support on POSIX if the diff --git a/test/sql-tap/decimal.test.lua b/test/sql-tap/decimal.test.lua index 2455bab61..d422533d6 100755 --- a/test/sql-tap/decimal.test.lua +++ b/test/sql-tap/decimal.test.lua @@ -938,7 +938,7 @@ test:do_catchsql_test( 1, "Inconsistent types: expected string or varbinary got decimal(111)" }) --- Make sure that DECIMAL value can be binded. +-- Make sure that DECIMAL value can be bound. test:do_test( "dec-16-1", function() New patch: commit 2ec28c37f9431e3fb2fbb2a8772e4eac26c1ace9 Author: Mergen Imeev Date: Thu Aug 26 15:52:13 2021 +0300 sql: allow to bind DECIMAL values After this patch, DECIMAL values can be bound like any other supported by SQL values. Closes #4717 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 0aca76112..2bf78e625 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;