diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index 07772d9b5affd0a854ce9ff36297fbe5f0ba02b8..2e60f7cf61cc516f4c8eb5a93da1fdfaa7322b64 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -77,7 +77,6 @@ set(sql_sources sql/alter.c sql/cursor.c sql/build.c - sql/callback.c sql/delete.c sql/expr.c sql/func.c diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 68de7e2c0d31255f2cf9bfd1bd42901e6b826071..7bab28b51cc95e84e0730c2528a9e25f9607b690 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -2449,9 +2449,12 @@ index_fill_def(struct Parse *parse, struct index *index, uint32_t fieldno = column_expr->iColumn; uint32_t coll_id; if (expr->op == TK_COLLATE) { - if (sql_get_coll_seq(parse, expr->u.zToken, - &coll_id) == NULL) + coll_id = sql_coll_id_by_expr(expr); + if (coll_id == UINT32_MAX) { + diag_set(ClientError, ER_NO_SUCH_COLLATION, + expr->u.zToken); goto tnt_error; + } } else { sql_column_collation(space_def, fieldno, &coll_id); } diff --git a/src/box/sql/callback.c b/src/box/sql/callback.c deleted file mode 100644 index 290363db60b14c5850931e36d48715ba18591bb0..0000000000000000000000000000000000000000 --- a/src/box/sql/callback.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * 1. Redistributions of source code must retain the above - * copyright notice, this list of conditions and the - * following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * - * This file contains functions used to access the internal hash tables - * of user defined functions and collation sequences. - */ - -#include "box/coll_id_cache.h" -#include "sqlInt.h" -#include "box/session.h" - -struct coll * -sql_get_coll_seq(Parse *parser, const char *name, uint32_t *coll_id) -{ - if (name == NULL) { - *coll_id = COLL_NONE; - return coll_by_id(COLL_NONE)->coll; - } - struct coll_id *p = coll_by_name(name, strlen(name)); - if (p == NULL) { - diag_set(ClientError, ER_NO_SUCH_COLLATION, name); - parser->is_aborted = true; - return NULL; - } else { - *coll_id = p->id; - return p->coll; - } -} diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index 0850b388ef842eaf966441c6ac53aac1cedea43d..7e394e6888bf5bc989d9618f5f487e5aa65ec68c 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -291,9 +291,15 @@ sql_expr_coll(Parse *parse, Expr *p, bool *is_explicit_coll, uint32_t *coll_id, } if (op == TK_COLLATE || (op == TK_REGISTER && p->op2 == TK_COLLATE)) { - *coll = sql_get_coll_seq(parse, p->u.zToken, coll_id); - if (*coll == NULL) + uint32_t id = sql_coll_id_by_expr(p); + if (id == UINT32_MAX) { + diag_set(ClientError, ER_NO_SUCH_COLLATION, + p->u.zToken); + parse->is_aborted = true; return -1; + } + *coll_id = id; + *coll = coll_by_id(id)->coll; *is_explicit_coll = true; break; } @@ -5448,3 +5454,14 @@ sql_fieldno_by_item(const struct space *space, const struct ExprList_item *item) { return sql_space_fieldno(space, item->zName); } + +uint32_t +sql_coll_id_by_expr(const struct Expr *expr) +{ + assert(expr->op == TK_COLLATE); + const char *name = expr->u.zToken; + struct coll_id *coll_id = coll_by_name(name, strlen(name)); + if (coll_id != NULL) + return coll_id->id; + return UINT32_MAX; +} diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index c9bfc713e80d05f07c23915c6ce14efee9ac1e11..d890c43ff2f838388116b2698a5e5e13407a66d0 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -3174,6 +3174,13 @@ sql_fieldno_by_item(const struct space *space, const struct ExprList_item *it); uint32_t sql_coll_id_by_token(const struct Token *name); +/** + * Return the ID of the collation with the name defined by the expression. + * Return UINT32_MAX if the field was not found. + */ +uint32_t +sql_coll_id_by_expr(const struct Expr *expr); + /** * Return the tuple foreign key constraint with the name defined by the token. * Return NULL if the tuple foreign key constraint was not found. @@ -4091,17 +4098,6 @@ int sqlResolveOrderGroupBy(Parse *, Select *, ExprList *, const char *); char * rename_trigger(char const *sql_stmt, char const *table_name, bool *is_quoted); -/** - * Find a collation by name. Set error in @a parser if not found. - * @param parser Parser. - * @param name Collation name. - * @param[out] Collation identifier. - * - * @retval Collation object. NULL on error or not found. - */ -struct coll * -sql_get_coll_seq(Parse *parser, const char *name, uint32_t *coll_id); - /** * This function returns average size of tuple in given index. * Currently, all indexes from one space feature the same size,