Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: korablev@tarantool.org, tsafin@tarantool.org
Cc: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v5 5/6] sql: fix implicit cast in opcode MustBeInt
Date: Fri, 21 Aug 2020 12:19:56 +0300	[thread overview]
Message-ID: <660af07f4a4cf50567ee5ca845cfa538f316e9f4.1598000242.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1598000242.git.imeevma@gmail.com>

This patch removes implicit casting from STRING to number and vice
versa from MustBeInt opcode.

Part of #4230
---
 src/box/sql/vdbe.c | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index b326c4ba4..a0ddbaf60 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2352,16 +2352,20 @@ case OP_AddImm: {            /* in1 */
  */
 case OP_MustBeInt: {            /* jump, in1 */
 	pIn1 = &aMem[pOp->p1];
-	if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) {
-		mem_apply_type(pIn1, FIELD_TYPE_INTEGER);
-		if ((pIn1->flags & (MEM_Int | MEM_UInt)) == 0) {
-			if (pOp->p2==0) {
-				diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
-					 sql_value_to_diag_str(pIn1), "integer");
-				goto abort_due_to_error;
-			} else {
-				goto jump_to_p2;
-			}
+	if (mem_is_type_compatible(pIn1, FIELD_TYPE_INTEGER))
+		break;
+	if ((pIn1->flags & MEM_Real) != 0) {
+		double d = pIn1->u.r;
+		if (d == (double)(int64_t)d || d == (double)(uint64_t)d)
+			mem_convert_to_integer(pIn1);
+	}
+	if (!mem_is_type_compatible(pIn1, FIELD_TYPE_INTEGER)) {
+		if (pOp->p2==0) {
+			diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
+				 sql_value_to_diag_str(pIn1), "integer");
+			goto abort_due_to_error;
+		} else {
+			goto jump_to_p2;
 		}
 	}
 	break;
-- 
2.25.1

  parent reply	other threads:[~2020-08-21  9:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21  9:19 [Tarantool-patches] [PATCH v5 0/6] sql; remove implicit cast for comparison imeevma
2020-08-21  9:19 ` [Tarantool-patches] [PATCH v5 1/6] sql: remove unused DOUBLE to INTEGER conversion imeevma
2020-09-17 14:48   ` Nikita Pettik
2020-09-28 15:50     ` Mergen Imeev
2020-08-21  9:19 ` [Tarantool-patches] [PATCH v5 2/6] sql: add implicit cast between numbers in OP_Seek* imeevma
2020-09-17 15:34   ` Nikita Pettik
2020-09-28 15:55     ` Mergen Imeev
2020-08-21  9:19 ` [Tarantool-patches] [PATCH v5 3/6] sql: change comparison between numbers using index imeevma
2020-09-18  8:08   ` Nikita Pettik
2020-09-28 16:10     ` Mergen Imeev
2020-08-21  9:19 ` [Tarantool-patches] [PATCH v5 4/6] sql: remove implicit cast from comparison opcodes imeevma
2020-08-21  9:19 ` imeevma [this message]
2020-08-21  9:19 ` [Tarantool-patches] [PATCH v5 6/6] sql: remove implicit cast from MakeRecord opcode imeevma
2020-09-18 12:28   ` Nikita Pettik
2020-09-28 16:19     ` Mergen Imeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=660af07f4a4cf50567ee5ca845cfa538f316e9f4.1598000242.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=tsafin@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH v5 5/6] sql: fix implicit cast in opcode MustBeInt' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox