Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 4/5] sql: make built-ins raise errors for varbin args
Date: Wed, 24 Jul 2019 14:42:46 +0300	[thread overview]
Message-ID: <61adf9b0d2ce82a927f318c386dd0a004eb3ca45.1563967510.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1563967510.git.korablev@tarantool.org>
In-Reply-To: <cover.1563967510.git.korablev@tarantool.org>

Since values of type 'varbinary' can't be cast to any other type, let's
patch built-in functions which are not assumed to accept arguments of
this type to raise an error in case argument turn out to be of type
varbinary.

Part of #4206
---
 src/box/sql/func.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 4ec591eee..5fd1496fd 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -196,9 +196,10 @@ absFunc(sql_context * context, int argc, sql_value ** argv)
 			sql_result_null(context);
 			break;
 		}
-	case MP_BOOL: {
+	case MP_BOOL:
+	case MP_BIN: {
 		diag_set(ClientError, ER_INCONSISTENT_TYPES, "number",
-			 "boolean");
+			 mem_type_to_str(argv[0]));
 		context->is_aborted = true;
 		return;
 	}
@@ -506,6 +507,12 @@ roundFunc(sql_context * context, int argc, sql_value ** argv)
 	}
 	if (sql_value_is_null(argv[0]))
 		return;
+	if (sql_value_type(argv[0]) == MP_BIN) {
+		diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
+			 sql_value_text(argv[0]), "numeric");
+		context->is_aborted = true;
+		return;
+	}
 	r = sql_value_double(argv[0]);
 	/* If Y==0 and X will fit in a 64-bit int,
 	 * handle the rounding directly,
@@ -560,6 +567,13 @@ case_type##ICUFunc(sql_context *context, int argc, sql_value **argv)   \
 	const char *z2;                                                        \
 	int n;                                                                 \
 	UNUSED_PARAMETER(argc);                                                \
+	int arg_type = sql_value_type(argv[0]);                                \
+	if (arg_type == MP_BIN) {                                              \
+		diag_set(ClientError, ER_INCONSISTENT_TYPES, "TEXT",           \
+			 "VARBINARY");                                         \
+		context->is_aborted = true;                                    \
+		return;                                                        \
+	}                                                                      \
 	z2 = (char *)sql_value_text(argv[0]);                              \
 	n = sql_value_bytes(argv[0]);                                      \
 	/*                                                                     \
@@ -646,6 +660,12 @@ randomBlob(sql_context * context, int argc, sql_value ** argv)
 	unsigned char *p;
 	assert(argc == 1);
 	UNUSED_PARAMETER(argc);
+	if (sql_value_type(argv[0]) == MP_BIN) {
+		diag_set(ClientError, ER_SQL_TYPE_MISMATCH,
+			 sql_value_text(argv[0]), "numeric");
+		context->is_aborted = true;
+		return;
+	}
 	n = sql_value_int(argv[0]);
 	if (n < 1)
 		return;
-- 
2.15.1

  parent reply	other threads:[~2019-07-24 11:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24 11:42 [tarantool-patches] [PATCH 0/5] Introduce VARBINARY in SQL Nikita Pettik
2019-07-24 11:42 ` [tarantool-patches] [PATCH 1/5] sql: always erase numeric flag after stringifying Nikita Pettik
2019-07-24 11:42 ` [tarantool-patches] [PATCH 2/5] sql: fix resulting type calculation for CASE-WHEN stmt Nikita Pettik
2019-07-25 22:12   ` [tarantool-patches] " Vladislav Shpilevoy
     [not found]   ` <a061e845-eeb1-00d1-9141-3b9bb87768f5@tarantool.org>
2019-07-28 23:56     ` n.pettik
2019-07-24 11:42 ` [tarantool-patches] [PATCH 3/5] sql: use 'varbinary' as a name of type instead of 'blob' Nikita Pettik
2019-07-25 22:11   ` [tarantool-patches] " Vladislav Shpilevoy
     [not found]   ` <2e655514-0fec-8baf-20a8-d49e5586b047@tarantool.org>
2019-07-28 23:56     ` n.pettik
2019-07-29 21:03       ` Vladislav Shpilevoy
2019-07-30 13:43         ` n.pettik
2019-07-24 11:42 ` Nikita Pettik [this message]
2019-07-25 22:11   ` [tarantool-patches] Re: [PATCH 4/5] sql: make built-ins raise errors for varbin args Vladislav Shpilevoy
     [not found]   ` <05d15035-2552-1f05-b7ce-facfbbc3a520@tarantool.org>
2019-07-28 23:59     ` n.pettik
2019-07-24 11:42 ` [tarantool-patches] [PATCH 5/5] sql: introduce VARBINARY column type Nikita Pettik
2019-07-25 22:12   ` [tarantool-patches] " Vladislav Shpilevoy
     [not found]   ` <49a188eb-dafe-44e7-a0fd-e9244b68e721@tarantool.org>
2019-07-29  0:03     ` n.pettik
2019-07-29 20:55       ` Vladislav Shpilevoy
2019-07-30 13:44         ` n.pettik
2019-07-30 19:41           ` Vladislav Shpilevoy
2019-07-30 19:52             ` Vladislav Shpilevoy
2019-07-31 14:51               ` n.pettik
2019-08-01  8:42 ` [tarantool-patches] Re: [PATCH 0/5] Introduce VARBINARY in SQL Kirill Yukhin

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=61adf9b0d2ce82a927f318c386dd0a004eb3ca45.1563967510.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 4/5] sql: make built-ins raise errors for varbin args' \
    /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