Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: korablev@tarantool.org, tsafin@tarantool.org,
	tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH v4 2/5] sql: move diag setting to sql_func_by_signature()
Date: Mon, 13 Jul 2020 08:33:01 +0300	[thread overview]
Message-ID: <9ceb258869506f3068f6aae6f0c02ac1338ee29e.1594618005.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1594618005.git.imeevma@gmail.com>

After this patch, the sql_func_by_signature() function will check the
found function and set diag if something is wrong.

Needed for #4159
---
 src/box/sql/expr.c    |  2 --
 src/box/sql/func.c    | 18 +++++++++++++++---
 src/box/sql/resolve.c | 23 ++---------------------
 src/box/sql/sqlInt.h  |  7 +++++--
 4 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index bc2182446..d0620b98c 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -3978,8 +3978,6 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target)
 			zId = pExpr->u.zToken;
 			struct func *func = sql_func_by_signature(zId, nFarg);
 			if (func == NULL) {
-				diag_set(ClientError, ER_NO_SUCH_FUNCTION,
-					 zId);
 				pParse->is_aborted = true;
 				break;
 			}
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 487cdafe1..4bbe4d4b7 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -2185,11 +2185,23 @@ struct func *
 sql_func_by_signature(const char *name, int argc)
 {
 	struct func *base = func_by_name(name, strlen(name));
-	if (base == NULL || !base->def->exports.sql)
+	if (base == NULL) {
+		diag_set(ClientError, ER_NO_SUCH_FUNCTION, name);
 		return NULL;
-
-	if (base->def->param_count != -1 && base->def->param_count != argc)
+	}
+	if (!base->def->exports.sql) {
+		diag_set(ClientError, ER_SQL_PARSER_GENERIC,
+			 tt_sprintf("function %s() is not available in SQL",
+				     name));
+		return NULL;
+	}
+	int param_count = base->def->param_count;
+	if (param_count != -1 && param_count != argc) {
+		const char *err = tt_sprintf("%d", param_count);
+		diag_set(ClientError, ER_FUNC_WRONG_ARG_COUNT,
+			 base->def->name, err, argc);
 		return NULL;
+	}
 	return base;
 }
 
diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c
index 6f625dc18..10c77c491 100644
--- a/src/box/sql/resolve.c
+++ b/src/box/sql/resolve.c
@@ -598,32 +598,13 @@ resolveExprStep(Walker * pWalker, Expr * pExpr)
 			assert(!ExprHasProperty(pExpr, EP_xIsSelect));
 			zId = pExpr->u.zToken;
 			nId = sqlStrlen30(zId);
-			struct func *func = func_by_name(zId, nId);
+			struct func *func = sql_func_by_signature(zId, n);
 			if (func == NULL) {
-				diag_set(ClientError, ER_NO_SUCH_FUNCTION, zId);
-				pParse->is_aborted = true;
-				pNC->nErr++;
-				return WRC_Abort;
-			}
-			if (!func->def->exports.sql) {
-				diag_set(ClientError, ER_SQL_PARSER_GENERIC,
-					 tt_sprintf("function %.*s() is not "
-						    "available in SQL",
-						     nId, zId));
-				pParse->is_aborted = true;
-				pNC->nErr++;
-				return WRC_Abort;
-			}
-			if (func->def->param_count != -1 &&
-			    func->def->param_count != n) {
-				uint32_t argc = func->def->param_count;
-				const char *err = tt_sprintf("%d", argc);
-				diag_set(ClientError, ER_FUNC_WRONG_ARG_COUNT,
-					 func->def->name, err, n);
 				pParse->is_aborted = true;
 				pNC->nErr++;
 				return WRC_Abort;
 			}
+			assert(func->def->exports.sql);
 			bool is_agg = func->def->aggregate ==
 				      FUNC_AGGREGATE_GROUP;
 			assert(!is_agg || func->def->language ==
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 37283e506..58a65acc1 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -4441,8 +4441,11 @@ sql_func_flag_is_set(struct func *func, uint16_t flag)
  * export field set true and have exactly the same signature
  * are returned.
  *
- * Returns not NULL function pointer when a valid and exported
- * to SQL engine function is found and NULL otherwise.
+ * @param name Name of the function to find.
+ * @param argc Number of arguments of the function.
+ *
+ * @retval not NULL function pointer when a function is found.
+ * @retval NULL on error and sets a diag.
  */
 struct func *
 sql_func_by_signature(const char *name, int argc);
-- 
2.25.1

  parent reply	other threads:[~2020-07-13  5:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-13  5:32 [Tarantool-patches] [PATCH v4 0/5] Change implicit cast for assignment imeevma
2020-07-13  5:32 ` [Tarantool-patches] [PATCH v4 1/5] sql: set field_type in mem_set_*() functions imeevma
2020-07-13 10:36   ` Nikita Pettik
2020-07-13  5:33 ` imeevma [this message]
2020-07-13 10:58   ` [Tarantool-patches] [PATCH v4 2/5] sql: move diag setting to sql_func_by_signature() Nikita Pettik
2020-07-13  5:33 ` [Tarantool-patches] [PATCH v4 3/5] sql: check number of arguments in sql_func_by_signature() imeevma
2020-07-13 12:21   ` Nikita Pettik
2020-07-13  5:33 ` [Tarantool-patches] [PATCH v4 4/5] sql: change implicit cast for assignment imeevma
2020-07-13 14:42   ` Nikita Pettik
2020-07-13  5:33 ` [Tarantool-patches] [PATCH v4 5/5] sql: properly check arguments of functions imeevma
2020-07-13 14:56   ` Nikita Pettik

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=9ceb258869506f3068f6aae6f0c02ac1338ee29e.1594618005.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 v4 2/5] sql: move diag setting to sql_func_by_signature()' \
    /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