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 A6B976F3FD; Tue, 31 Aug 2021 11:24:57 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org A6B976F3FD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1630398297; bh=IdaB4CXVO7zs6fbMH5aHn8wOtF5hWJdTLcTGI+fPI2c=; h=To:Cc:Date:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=REmwE+KzQ65U0fcPR/BGIey4aiAlSBgu+RRfqTk6RgWyXOpo5vbjPg82TI7j5pwVY fjjbeVNnucgQoVJ3oXnadcZkrAiR+TQP6u/RHmPXLr/tMyGhLbcrDiStIkLjgZspNI w897rsRL/E9IPyRbgDAgIN0o2gdx4rixQPx4Qg6c= 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 8B3626F3FD for ; Tue, 31 Aug 2021 11:24:55 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 8B3626F3FD Received: by smtpng2.m.smailru.net with esmtpa (envelope-from ) id 1mKz4g-0000pH-Pp; Tue, 31 Aug 2021 11:24:55 +0300 To: tsafin@tarantool.org Cc: tarantool-patches@dev.tarantool.org Date: Tue, 31 Aug 2021 11:24:54 +0300 Message-Id: <75936763d4e7b280b4bf4f3ed94d1bcf812f0b18.1630398245.git.imeevma@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-174C08C4: 5188C02AEC42908C481ED7ADC579193296BBA28369E3F2D2713F3D5F7D406D31BCF678C7329BA986 X-7564579A: 78E4E2B564C1792B X-77F55803: 4F1203BC0FB41BD92087353F0EC44DD9ECFD080E047A606F56291F8739A291D6182A05F53808504021BF9051A3B971283AFDD4BFB41CA68C3E3369765E1F3A2F94A93A6EB8F004DF X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE70EEC24FFE855BCBBC2099A533E45F2D0395957E7521B51C2CFCAF695D4D8E9FCEA1F7E6F0F101C6778DA827A17800CE77F5852B248C7AFEDEA1F7E6F0F101C6723150C8DA25C47586E58E00D9D99D84E1BDDB23E98D2D38BBCA57AF85F7723F20B5347EE131BC7CB7FFE5928A85B1143CC7F00164DA146DAFE8445B8C89999728AA50765F79006370277CA7F994D7EF5389733CBF5DBD5E9C8A9BA7A39EFB766F5D81C698A659EA7CC7F00164DA146DA9985D098DBDEAEC89E541A154B51D14BF6B57BC7E6449061A352F6E88A58FB86F5D81C698A659EA7E827F84554CEF5019E625A9149C048EE9ECD01F8117BC8BEE2021AF6380DFAD18AA50765F790063735872C767BF85DA227C277FBC8AE2E8BDAE3FA6833AEA0C275ECD9A6C639B01B4E70A05D1297E1BBCB5012B2E24CD356 X-C1DE0DAB: 8BD88D57C5CADBC8B2710865C38675103DEB35D4F4140487A3B1A56EE2B804F6B226C914C996894645FD9D8A29397D6EFF55FE49A3C2BFCFC8C84E951CD0BE2F296C473AB1E14218EA052B563B0B06C67866D6147AF826D830634C7FE324091928F999F0341B5B18F972CCD2F8FE1EF1CFC4036BBF6A4EA9ED2E935B6230FB13CB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34351729636A02D1DED48C99F9FEBA5DC2C7356FD58E9A870B5CC8D62B807EA895F1AFB556B96BA4941D7E09C32AA3244CF2713307163E45E5A2A14A38B00C04768894E9C85370243E729B2BEF169E0186 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2bioj4DnN7V8kJ6sBPQpPrq/70A== X-Mailru-Sender: 689FA8AB762F7393C37E3C1AEC41BA5DE8D4963FEEB0CD3CB5FCB19C7457EB2F83D72C36FC87018B9F80AB2734326CD2FB559BB5D741EB96352A0ABBE4FDA4210A04DAD6CC59E33667EA787935ED9F1B X-Mras: Ok Subject: [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: imeevma@tarantool.org Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" 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