From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id DD87328BE5 for ; Sat, 2 Mar 2019 08:07:57 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 76ZoGQ4AdnfX for ; Sat, 2 Mar 2019 08:07:57 -0500 (EST) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 4999028BD9 for ; Sat, 2 Mar 2019 08:07:57 -0500 (EST) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v3 4/9] sql: remove field rc of struct Parse Date: Sat, 2 Mar 2019 16:07:55 +0300 Message-Id: <50846f935fdc69a4ff17958b8307bc9dc245fe70.1551530224.git.imeevma@gmail.com> In-Reply-To: References: Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: korablev@tarantool.org Cc: tarantool-patches@freelists.org Currently, the field rc of the struct Parse can have only two values: SQL_OK or SQL_TARANTOOL_ERROR. Therefore, it is logical to replace it with a new boolean field. This patche replaces field rc by new field is_aborted. Part of #3965 --- src/box/sql.c | 10 ++---- src/box/sql/alter.c | 2 +- src/box/sql/analyze.c | 4 +-- src/box/sql/build.c | 76 ++++++++++++++++++++++----------------------- src/box/sql/callback.c | 2 +- src/box/sql/delete.c | 8 ++--- src/box/sql/expr.c | 22 ++++++------- src/box/sql/insert.c | 4 +-- src/box/sql/parse.y | 16 +++++----- src/box/sql/pragma.c | 8 ++--- src/box/sql/prepare.c | 8 ++--- src/box/sql/resolve.c | 14 ++++----- src/box/sql/select.c | 33 ++++++++++---------- src/box/sql/sqlInt.h | 11 ++----- src/box/sql/tokenize.c | 42 +++++++++---------------- src/box/sql/trigger.c | 14 ++++----- src/box/sql/update.c | 4 +-- src/box/sql/util.c | 8 +---- src/box/sql/vdbemem.c | 4 +-- src/box/sql/where.c | 4 +-- src/box/sql/wherecode.c | 3 +- test/sql-tap/check.test.lua | 4 +-- test/sql/checks.result | 12 +++---- 23 files changed, 139 insertions(+), 174 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index cb0facf..1004bb7 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -1275,7 +1275,7 @@ sql_ephemeral_space_def_new(struct Parse *parser, const char *name) if (def == NULL) { diag_set(OutOfMemory, size, "region_alloc", "sql_ephemeral_space_def_new"); - parser->rc = SQL_TARANTOOL_ERROR; + parser->is_aborted = true; return NULL; } @@ -1293,7 +1293,7 @@ sql_ephemeral_space_new(Parse *parser, const char *name) struct space *space = (struct space *) region_alloc(&parser->region, sz); if (space == NULL) { diag_set(OutOfMemory, sz, "region", "space"); - parser->rc = SQL_TARANTOOL_ERROR; + parser->is_aborted = true; return NULL; } @@ -1361,12 +1361,8 @@ sql_checks_resolve_space_def_reference(ExprList *expr_list, sql_resolve_self_reference(&parser, def, NC_IsCheck, NULL, expr_list); int rc = 0; - if (parser.rc != SQL_OK) { - /* Tarantool error may be already set with diag. */ - if (parser.rc != SQL_TARANTOOL_ERROR) - diag_set(ClientError, ER_SQL, parser.zErrMsg); + if (parser.is_aborted) rc = -1; - } sql_parser_destroy(&parser); return rc; } diff --git a/src/box/sql/alter.c b/src/box/sql/alter.c index 214e0f8..bd9b034 100644 --- a/src/box/sql/alter.c +++ b/src/box/sql/alter.c @@ -72,7 +72,7 @@ exit_rename_table: return; tnt_error: sqlDbFree(db, new_name); - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; goto exit_rename_table; } diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index 96e5e4c..9bcbe49 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -907,7 +907,7 @@ vdbe_emit_analyze_space(struct Parse *parse, struct space *space) if (jump_addrs == NULL) { diag_set(OutOfMemory, sizeof(int) * part_count, "region", "jump_addrs"); - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; return; } /* @@ -1129,7 +1129,7 @@ sqlAnalyze(Parse * pParse, Token * pName) } } else { diag_set(ClientError, ER_NO_SUCH_SPACE, z); - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; } sqlDbFree(db, z); } diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 7d6c1c9..a1f4b1b 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -91,7 +91,7 @@ save_record(struct Parse *parser, uint32_t space_id, int reg_key, if (record == NULL) { diag_set(OutOfMemory, sizeof(*record), "region_alloc", "record"); - parser->rc = SQL_TARANTOOL_ERROR; + parser->is_aborted = true; return; } record->space_id = space_id; @@ -144,11 +144,11 @@ sql_finish_coding(struct Parse *parse_context) "Exit with an error if CREATE statement fails")); } - if (parse_context->rc == SQL_TARANTOOL_ERROR) + if (parse_context->is_aborted) return; if (db->mallocFailed) { diag_set(OutOfMemory, 0, "SQL", "db"); - parse_context->rc = SQL_TARANTOOL_ERROR; + parse_context->is_aborted = true; return; } /* @@ -190,12 +190,12 @@ sql_finish_coding(struct Parse *parse_context) sqlVdbeGoto(v, 1); } /* Get the VDBE program ready for execution. */ - if (parse_context->rc == SQL_OK && !db->mallocFailed) { + if (!parse_context->is_aborted && !db->mallocFailed) { assert(parse_context->iCacheLevel == 0); sqlVdbeMakeReady(v, parse_context); - } else if (parse_context->rc != SQL_TARANTOOL_ERROR){ + } else if (!parse_context->is_aborted){ diag_set(OutOfMemory, 0, "SQL", "db"); - parse_context->rc = SQL_TARANTOOL_ERROR; + parse_context->is_aborted = true; } } /** @@ -345,7 +345,7 @@ sqlStartTable(Parse *pParse, Token *pName, int noErr) if (space != NULL) { if (!noErr) { diag_set(ClientError, ER_SPACE_EXISTS, zName); - sql_parser_error(pParse); + pParse->is_aborted = true; } else { assert(!db->init.busy || CORRUPT_DB); } @@ -397,7 +397,7 @@ sql_field_retrieve(Parse *parser, struct space_def *space_def, uint32_t id) diag_set(OutOfMemory, columns_new * sizeof(space_def->fields[0]), "region_alloc", "sql_field_retrieve"); - parser->rc = SQL_TARANTOOL_ERROR; + parser->is_aborted = true; return NULL; } @@ -452,7 +452,7 @@ sqlAddColumn(Parse * pParse, Token * pName, struct type_def *type_def) if (z == NULL) { diag_set(OutOfMemory, pName->n + 1, "region_alloc", "z"); - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; return; } memcpy(z, pName->z, pName->n); @@ -461,7 +461,7 @@ sqlAddColumn(Parse * pParse, Token * pName, struct type_def *type_def) for (uint32_t i = 0; i < def->field_count; i++) { if (strcmp(z, def->fields[i].name) == 0) { diag_set(ClientError, ER_SPACE_FIELD_IS_DUPLICATE, z); - sql_parser_error(pParse); + pParse->is_aborted = true; return; } } @@ -499,7 +499,7 @@ sql_column_add_nullable_action(struct Parse *parser, on_conflict_action_strs[field-> nullable_action]); diag_set(ClientError, ER_SQL, err_msg); - parser->rc = SQL_TARANTOOL_ERROR; + parser->is_aborted = true; return; } field->nullable_action = nullable_action; @@ -540,7 +540,7 @@ sqlAddDefaultValue(Parse * pParse, ExprSpan * pSpan) diag_set(OutOfMemory, default_length + 1, "region_alloc", "field->default_value"); - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; return; } strncpy(field->default_value, pSpan->zStart, @@ -558,7 +558,7 @@ field_def_create_for_pk(struct Parse *parser, struct field_def *field, if (field->nullable_action != ON_CONFLICT_ACTION_ABORT && field->nullable_action != ON_CONFLICT_ACTION_DEFAULT) { diag_set(ClientError, ER_NULLABLE_PRIMARY, space_name); - parser->rc = SQL_TARANTOOL_ERROR; + parser->is_aborted = true; return -1; } else if (field->nullable_action == ON_CONFLICT_ACTION_DEFAULT) { field->nullable_action = ON_CONFLICT_ACTION_ABORT; @@ -647,7 +647,7 @@ sqlAddPrimaryKey(Parse * pParse, /* Parsing context */ sql_create_index(pParse, 0, 0, pList, 0, sortOrder, false, SQL_INDEX_TYPE_CONSTRAINT_PK); pList = 0; - if (pParse->rc == SQL_TARANTOOL_ERROR) + if (pParse->is_aborted) goto primary_key_exit; } @@ -846,7 +846,7 @@ vdbe_emit_create_index(struct Parse *parse, struct space_def *def, save_record(parse, BOX_INDEX_ID, entry_reg, 2, v->nOp - 1); return; error: - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; } /* @@ -904,7 +904,7 @@ createSpace(Parse * pParse, int iSpaceId, char *zStmt) save_record(pParse, BOX_SPACE_ID, iFirstCol, 1, v->nOp - 1); return; error: - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; } int @@ -1084,7 +1084,7 @@ vdbe_emit_fk_constraint_create(struct Parse *parse_context, sqlReleaseTempRange(parse_context, constr_tuple_reg, 10); return; error: - parse_context->rc = SQL_TARANTOOL_ERROR; + parse_context->is_aborted = true; } /** @@ -1112,7 +1112,7 @@ resolve_link(struct Parse *parse_context, const struct space_def *def, diag_set(ClientError, ER_CREATE_FK_CONSTRAINT, fk_name, tt_sprintf("unknown column %s in foreign key definition", field_name)); - parse_context->rc = SQL_TARANTOOL_ERROR; + parse_context->is_aborted = true; return -1; } @@ -1243,7 +1243,7 @@ sqlEndTable(Parse * pParse, /* Parse context */ "foreign key does not match the "\ "number of columns in the primary "\ "index of referenced table"); - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; return; } for (uint32_t i = 0; i < fk_def->field_count; ++i) { @@ -1273,7 +1273,7 @@ sql_create_view(struct Parse *parse_context, struct Token *begin, } sqlStartTable(parse_context, name, if_exists); struct space *space = parse_context->new_space; - if (space == NULL || parse_context->rc == SQL_TARANTOOL_ERROR) + if (space == NULL || parse_context->is_aborted) goto create_view_fail; struct space *select_res_space = @@ -1318,7 +1318,7 @@ sql_create_view(struct Parse *parse_context, struct Token *begin, space->def->opts.sql = strndup(begin->z, n); if (space->def->opts.sql == NULL) { diag_set(OutOfMemory, n, "strndup", "opts.sql"); - parse_context->rc = SQL_TARANTOOL_ERROR; + parse_context->is_aborted = true; goto create_view_fail; } @@ -1591,14 +1591,14 @@ sql_drop_table(struct Parse *parse_context, struct SrcList *table_name_list, goto exit_drop_table; } sqlVdbeCountChanges(v); - assert(parse_context->rc != SQL_TARANTOOL_ERROR); + assert(!parse_context->is_aborted); assert(table_name_list->nSrc == 1); const char *space_name = table_name_list->a[0].zName; struct space *space = space_by_name(space_name); if (space == NULL) { if (!if_exists) { diag_set(ClientError, ER_NO_SUCH_SPACE, space_name); - sql_parser_error(parse_context); + parse_context->is_aborted = true; } goto exit_drop_table; } @@ -1637,7 +1637,7 @@ sql_drop_table(struct Parse *parse_context, struct SrcList *table_name_list, if (! fk_constraint_is_self_referenced(fk->def)) { diag_set(ClientError, ER_DROP_SPACE, space_name, "other objects depend on it"); - parse_context->rc = SQL_TARANTOOL_ERROR; + parse_context->is_aborted = true; goto exit_drop_table; } } @@ -1672,7 +1672,7 @@ columnno_by_name(struct Parse *parse_context, const struct space *space, diag_set(ClientError, ER_CREATE_FK_CONSTRAINT, fk_name, tt_sprintf("foreign key refers to nonexistent field %s", column_name)); - parse_context->rc = SQL_TARANTOOL_ERROR; + parse_context->is_aborted = true; return -1; } return 0; @@ -1881,7 +1881,7 @@ exit_create_fk: sqlDbFree(db, constraint_name); return; tnt_error: - parse_context->rc = SQL_TARANTOOL_ERROR; + parse_context->is_aborted = true; goto exit_create_fk; } @@ -1905,7 +1905,7 @@ sql_drop_foreign_key(struct Parse *parse_context, struct SrcList *table, struct space *child = space_by_name(table_name); if (child == NULL) { diag_set(ClientError, ER_NO_SUCH_SPACE, table_name); - parse_context->rc = SQL_TARANTOOL_ERROR; + parse_context->is_aborted = true; return; } char *constraint_name = sqlNameFromToken(parse_context->db, @@ -2032,7 +2032,7 @@ index_fill_def(struct Parse *parse, struct index *index, struct Expr *expr = expr_list->a[i].pExpr; sql_resolve_self_reference(parse, space_def, NC_IdxExpr, expr, 0); - if (parse->rc == SQL_TARANTOOL_ERROR) + if (parse->is_aborted) goto cleanup; struct Expr *column_expr = sqlExprSkipCollate(expr); @@ -2083,7 +2083,7 @@ cleanup: key_def_delete(key_def); return rc; tnt_error: - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; goto cleanup; } @@ -2111,7 +2111,7 @@ sql_create_index(struct Parse *parse, struct Token *token, struct sql *db = parse->db; assert(!db->init.busy); - if (db->mallocFailed || parse->rc == SQL_TARANTOOL_ERROR) + if (db->mallocFailed || parse->is_aborted) goto exit_create_index; if (idx_type == SQL_INDEX_TYPE_UNIQUE || idx_type == SQL_INDEX_TYPE_NON_UNIQUE) { @@ -2133,7 +2133,7 @@ sql_create_index(struct Parse *parse, struct Token *token, if (space == NULL) { if (! if_not_exist) { diag_set(ClientError, ER_NO_SUCH_SPACE, name); - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; } goto exit_create_index; } @@ -2179,7 +2179,7 @@ sql_create_index(struct Parse *parse, struct Token *token, if (!if_not_exist) { diag_set(ClientError, ER_INDEX_EXISTS_IN_SPACE, name, def->name); - sql_parser_error(parse); + parse->is_aborted = true; } goto exit_create_index; } @@ -2226,7 +2226,7 @@ sql_create_index(struct Parse *parse, struct Token *token, if (tbl_name != NULL && space_is_system(space)) { diag_set(ClientError, ER_MODIFY_INDEX, name, def->name, "can't create index on system space"); - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; goto exit_create_index; } @@ -2254,7 +2254,7 @@ sql_create_index(struct Parse *parse, struct Token *token, index = (struct index *) region_alloc(&parse->region, sizeof(*index)); if (index == NULL) { diag_set(OutOfMemory, sizeof(*index), "region", "index"); - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; goto exit_create_index; } memset(index, 0, sizeof(*index)); @@ -2424,7 +2424,7 @@ sql_drop_index(struct Parse *parse_context, struct SrcList *index_name_list, assert(v != NULL); struct sql *db = parse_context->db; /* Never called with prior errors. */ - assert(parse_context->rc != SQL_TARANTOOL_ERROR); + assert(!parse_context->is_aborted); assert(table_token != NULL); const char *table_name = sqlNameFromToken(db, table_token); if (db->mallocFailed) { @@ -2437,7 +2437,7 @@ sql_drop_index(struct Parse *parse_context, struct SrcList *index_name_list, if (space == NULL) { if (!if_exists) { diag_set(ClientError, ER_NO_SUCH_SPACE, table_name); - sql_parser_error(parse_context); + parse_context->is_aborted = true; } goto exit_drop_index; } @@ -2448,7 +2448,7 @@ sql_drop_index(struct Parse *parse_context, struct SrcList *index_name_list, if (!if_exists) { diag_set(ClientError, ER_NO_SUCH_INDEX_NAME, index_name, table_name); - sql_parser_error(parse_context); + parse_context->is_aborted = true; } goto exit_drop_index; } @@ -2806,7 +2806,7 @@ sqlSrcListAppendFromTerm(Parse * pParse, /* Parsing context */ if (!p && (pOn || pUsing)) { diag_set(ClientError, ER_SQL_SYNTAX, "FROM clause", "a JOIN clause is required before ON and USING"); - sql_parser_error(pParse); + pParse->is_aborted = true; goto append_from_error; } p = sqlSrcListAppend(db, p, pTable); diff --git a/src/box/sql/callback.c b/src/box/sql/callback.c index 6c26402..4919753 100644 --- a/src/box/sql/callback.c +++ b/src/box/sql/callback.c @@ -49,7 +49,7 @@ sql_get_coll_seq(Parse *parser, const char *name, uint32_t *coll_id) struct coll_id *p = coll_by_name(name, strlen(name)); if (p == NULL) { diag_set(ClientError, ER_NO_SUCH_COLLATION, name); - parser->rc = SQL_TARANTOOL_ERROR; + parser->is_aborted = true; return NULL; } else { *coll_id = p->id; diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c index fba07a9..87d4ed4 100644 --- a/src/box/sql/delete.c +++ b/src/box/sql/delete.c @@ -43,14 +43,14 @@ sql_lookup_space(struct Parse *parse, struct SrcList_item *space_name) struct space *space = space_by_name(space_name->zName); if (space == NULL) { diag_set(ClientError, ER_NO_SUCH_SPACE, space_name->zName); - sql_parser_error(parse); + parse->is_aborted = true; return NULL; } assert(space != NULL); if (space->def->field_count == 0) { diag_set(ClientError, ER_UNSUPPORTED, "SQL", "space without format"); - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; return NULL; } space_name->space = space; @@ -115,7 +115,7 @@ cleanup: return; tarantool_error: - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; goto cleanup; } @@ -124,7 +124,7 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list, struct Expr *where) { struct sql *db = parse->db; - if (parse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) + if (parse->is_aborted || db->mallocFailed) goto delete_from_cleanup; assert(tab_list->nSrc == 1); diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index 0911eee..7ea344b 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -254,10 +254,10 @@ sql_expr_coll(Parse *parse, Expr *p, bool *is_explicit_coll, uint32_t *coll_id, * several times: this * function is recursive. */ - if (parse->rc != SQL_TARANTOOL_ERROR) { + if (!parse->is_aborted) { diag_set(ClientError, ER_ILLEGAL_COLLATION_MIX); - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; } return -1; } @@ -409,7 +409,7 @@ sql_binary_compare_coll_seq(Parse *parser, Expr *left, Expr *right, return -1; if (collations_check_compatibility(lhs_coll_id, is_lhs_forced, rhs_coll_id, is_rhs_forced, id) != 0) { - parser->rc = SQL_TARANTOOL_ERROR; + parser->is_aborted = true; return -1; } return 0; @@ -819,7 +819,7 @@ exprSetHeight(Expr * p) void sqlExprSetHeightAndFlags(Parse * pParse, Expr * p) { - if (pParse->rc == SQL_TARANTOOL_ERROR) + if (pParse->is_aborted) return; exprSetHeight(p); sqlExprCheckHeight(pParse, p->nHeight); @@ -1003,7 +1003,7 @@ sqlPExpr(Parse * pParse, /* Parsing context */ ) { Expr *p; - if (op == TK_AND && pParse->rc != SQL_TARANTOOL_ERROR) { + if (op == TK_AND && !pParse->is_aborted) { /* Take advantage of short-circuit false optimization for AND */ p = sqlExprAnd(pParse->db, pLeft, pRight); } else { @@ -2405,8 +2405,7 @@ sqlFindInIndex(Parse * pParse, /* Parsing context */ * satisfy the query. This is preferable to generating a new * ephemeral table. */ - if (pParse->rc != SQL_TARANTOOL_ERROR && - (p = isCandidateForInOpt(pX)) != 0) { + if (!pParse->is_aborted && (p = isCandidateForInOpt(pX)) != 0) { sql *db = pParse->db; /* Database connection */ ExprList *pEList = p->pEList; int nExpr = pEList->nExpr; @@ -3040,7 +3039,7 @@ sqlExprCodeIN(Parse * pParse, /* Parsing and code generating context */ destIfFalse == destIfNull ? 0 : &rRhsHasNull, aiMap, 0); - assert(pParse->rc == SQL_TARANTOOL_ERROR || nVector == 1 || + assert(pParse->is_aborted || nVector == 1 || eType == IN_INDEX_EPH || eType == IN_INDEX_INDEX_ASC || eType == IN_INDEX_INDEX_DESC); #ifdef SQL_DEBUG @@ -3364,7 +3363,7 @@ sqlExprCacheStore(Parse * pParse, int iTab, int iCol, int iReg) struct yColCache *p; /* Unless an error has occurred, register numbers are always positive. */ - assert(iReg > 0 || pParse->rc == SQL_TARANTOOL_ERROR || + assert(iReg > 0 || pParse->is_aborted || pParse->db->mallocFailed); assert(iCol >= -1 && iCol < 32768); /* Finite column numbers */ @@ -3998,7 +3997,7 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) if (pDef == 0 || pDef->xFinalize != 0) { diag_set(ClientError, ER_NO_SUCH_FUNCTION, zId); - sql_parser_error(pParse); + pParse->is_aborted = true; break; } @@ -4342,8 +4341,7 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) } else { sqlVdbeAddOp2(v, OP_Null, 0, target); } - assert(pParse->db->mallocFailed || - pParse->rc == SQL_TARANTOOL_ERROR || + assert(pParse->db->mallocFailed || pParse->is_aborted || pParse->iCacheLevel == iCacheLevel); sqlVdbeResolveLabel(v, endLabel); break; diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index e8cdd39..6f7f020 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -277,7 +277,7 @@ sqlInsert(Parse * pParse, /* Parser context */ db = pParse->db; memset(&dest, 0, sizeof(dest)); - if (pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) { + if (pParse->is_aborted || db->mallocFailed) { goto insert_cleanup; } @@ -426,7 +426,7 @@ sqlInsert(Parse * pParse, /* Parser context */ dest.nSdst = space_def->field_count; rc = sqlSelect(pParse, pSelect, &dest); regFromSelect = dest.iSdst; - if (rc || db->mallocFailed || pParse->rc == SQL_TARANTOOL_ERROR) + if (rc || db->mallocFailed || pParse->is_aborted) goto insert_cleanup; sqlVdbeEndCoroutine(v, regYield); sqlVdbeJumpHere(v, addrTop - 1); /* label B: */ diff --git a/src/box/sql/parse.y b/src/box/sql/parse.y index f980945..b8c0515 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -38,11 +38,11 @@ } else { diag_set(ClientError, ER_SQL_UNRECOGNIZED_SYNTAX, TOKEN.n, TOKEN.z); } - sql_parser_error(pParse); + pParse->is_aborted = true; } %stack_overflow { diag_set(ClientError, ER_SQL_STACK_OVERFLOW); - sql_parser_error(pParse); + pParse->is_aborted = true; } // The name of the generated procedure that implements the parser @@ -118,7 +118,7 @@ ecmd ::= explain cmdx SEMI. { } ecmd ::= SEMI. { diag_set(ClientError, ER_SQL_STATEMENT_EMPTY); - sql_parser_error(pParse); + pParse->is_aborted = true; } explain ::= . explain ::= EXPLAIN. { pParse->explain = 1; } @@ -232,7 +232,7 @@ columnname(A) ::= nm(A) typedef(Y). {sqlAddColumn(pParse,&A,&Y);} nm(A) ::= id(A). { if(A.isReserved) { diag_set(ClientError, ER_SQL_KEYWORD_IS_RESERVED, A.n, A.z, A.n, A.z); - sql_parser_error(pParse); + pParse->is_aborted = true; } } @@ -904,7 +904,7 @@ expr(A) ::= VARIABLE(X). { spanExpr(&A, pParse, TK_VARIABLE, X); if (A.pExpr->u.zToken[0] == '?' && n > 1) { diag_set(ClientError, ER_SQL_UNRECOGNIZED_SYNTAX, t.n, t.z); - sql_parser_error(pParse); + pParse->is_aborted = true; } else { sqlExprAssignVarNumber(pParse, A.pExpr, n); } @@ -912,7 +912,7 @@ expr(A) ::= VARIABLE(X). { assert( t.n>=2 ); spanSet(&A, &t, &t); diag_set(ClientError, ER_SQL_UNRECOGNIZED_SYNTAX, t.n, t.z); - sql_parser_error(pParse); + pParse->is_aborted = true; A.pExpr = NULL; } } @@ -1384,13 +1384,13 @@ tridxby ::= . tridxby ::= INDEXED BY nm. { diag_set(ClientError, ER_SQL_SYNTAX, "trigger body", "the INDEXED BY clause "\ "is not allowed on UPDATE or DELETE statements within triggers"); - sql_parser_error(pParse); + pParse->is_aborted = true; } tridxby ::= NOT INDEXED. { diag_set(ClientError, ER_SQL_SYNTAX, "trigger body", "the NOT INDEXED "\ "clause is not allowed on UPDATE or DELETE statements within "\ "triggers"); - sql_parser_error(pParse); + pParse->is_aborted = true; } diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c index 6dc41a3..2b9c9b4 100644 --- a/src/box/sql/pragma.c +++ b/src/box/sql/pragma.c @@ -440,7 +440,7 @@ sqlPragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ pPragma = pragmaLocate(zLeft); if (pPragma == 0) { diag_set(ClientError, ER_SQL_NO_SUCH_PRAGMA, zLeft); - sql_parser_error(pParse); + pParse->is_aborted = true; goto pragma_out; } /* Register the result column names for pragmas that return results */ @@ -506,7 +506,7 @@ sqlPragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ box_iterator_t* iter; iter = box_index_iterator(space->def->id, 0,ITER_ALL, key_buf, key_end); if (iter == NULL) { - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; goto pragma_out; } int rc = box_iterator_next(iter, &tuple); @@ -564,7 +564,7 @@ sqlPragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ if (!token_is_string(pValue)) { diag_set(ClientError, ER_ILLEGAL_PARAMS, "string value is expected"); - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; goto pragma_out; } if (zRight == NULL) { @@ -575,7 +575,7 @@ sqlPragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ sqlVdbeAddOp2(v, OP_ResultRow, 1, 1); } else { if (sql_default_engine_set(zRight) != 0) { - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; goto pragma_out; } sqlVdbeAddOp0(v, OP_Expire); diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c index 0c6296d..42737ff 100644 --- a/src/box/sql/prepare.c +++ b/src/box/sql/prepare.c @@ -100,15 +100,15 @@ sqlPrepare(sql * db, /* Database handle. */ } assert(0 == sParse.nQueryLoop); - if (sParse.rc == SQL_DONE) - sParse.rc = SQL_OK; if (db->mallocFailed) { - sParse.rc = SQL_NOMEM; + diag_set(OutOfMemory, 0, "SQL", "db"); + sParse.is_aborted = true; } if (pzTail) { *pzTail = sParse.zTail; } - rc = sParse.rc; + if (sParse.is_aborted) + rc = SQL_TARANTOOL_ERROR; if (rc == SQL_OK && sParse.pVdbe && sParse.explain) { static const char *const azColName[] = { diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c index dfb6238..3215db3 100644 --- a/src/box/sql/resolve.c +++ b/src/box/sql/resolve.c @@ -441,7 +441,7 @@ lookupName(Parse * pParse, /* The parsing context */ diag_set(ClientError, ER_NO_SUCH_FIELD_NAME, zCol, zTab); } - sql_parser_error(pParse); + pParse->is_aborted = true; pTopNC->nErr++; } @@ -707,7 +707,7 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) #endif ) { diag_set(ClientError, ER_NO_SUCH_FUNCTION, zId); - sql_parser_error(pParse); + pParse->is_aborted = true; pNC->nErr++; } else if (wrong_num_args) { sqlErrorMsg(pParse, @@ -809,7 +809,7 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) break; } } - return (pParse->rc == SQL_TARANTOOL_ERROR + return (pParse->is_aborted || pParse->db->mallocFailed) ? WRC_Abort : WRC_Continue; } @@ -1195,7 +1195,7 @@ resolveSelectStep(Walker * pWalker, Select * p) */ if ((p->selFlags & SF_Expanded) == 0) { sqlSelectPrep(pParse, p, pOuterNC); - return (pParse->rc == SQL_TARANTOOL_ERROR + return (pParse->is_aborted || db->mallocFailed) ? WRC_Abort : WRC_Prune; } @@ -1252,7 +1252,7 @@ resolveSelectStep(Walker * pWalker, Select * p) sqlResolveSelectNames(pParse, pItem->pSelect, pOuterNC); - if (pParse->rc == SQL_TARANTOOL_ERROR || + if (pParse->is_aborted || db->mallocFailed) return WRC_Abort; @@ -1337,7 +1337,7 @@ resolveSelectStep(Walker * pWalker, Select * p) "argument must appear in the GROUP BY " "clause or be used in an aggregate " "function"); - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; return WRC_Abort; } /* @@ -1532,7 +1532,7 @@ sqlResolveExprNames(NameContext * pNC, /* Namespace to resolve expressions in. * #if SQL_MAX_EXPR_DEPTH>0 pNC->pParse->nHeight -= pExpr->nHeight; #endif - if (pNC->nErr > 0 || w.pParse->rc == SQL_TARANTOOL_ERROR) { + if (pNC->nErr > 0 || w.pParse->is_aborted) { ExprSetProperty(pExpr, EP_Error); } if (pNC->ncFlags & NC_HasAgg) { diff --git a/src/box/sql/select.c b/src/box/sql/select.c index 4698bb4..cfac553 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -196,13 +196,13 @@ sqlSelectNew(Parse * pParse, /* Parsing context */ pNew->pLimit = pLimit; pNew->pOffset = pOffset; pNew->pWith = 0; - assert(pOffset == 0 || pLimit != 0 || pParse->rc == SQL_TARANTOOL_ERROR + assert(pOffset == 0 || pLimit != 0 || pParse->is_aborted || db->mallocFailed != 0); if (db->mallocFailed) { clearSelect(db, pNew, pNew != &standin); pNew = 0; } else { - assert(pNew->pSrc != 0 || pParse->rc == SQL_TARANTOOL_ERROR); + assert(pNew->pSrc != 0 || pParse->is_aborted); } assert(pNew != &standin); return pNew; @@ -2003,7 +2003,7 @@ sqlResultSetOfSelect(Parse * pParse, Select * pSelect) user_session->sql_flags |= ~SQL_FullColNames; user_session->sql_flags &= SQL_ShortColNames; sqlSelectPrep(pParse, pSelect, 0); - if (pParse->rc == SQL_TARANTOOL_ERROR) + if (pParse->is_aborted) return NULL; while (pSelect->pPrior) pSelect = pSelect->pPrior; @@ -2094,7 +2094,7 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak) (p->pOffset->flags & EP_Collate) != 0)) { diag_set(ClientError, ER_SQL_UNRECOGNIZED_SYNTAX, sizeof("COLLATE"), "COLLATE"); - sql_parser_error(pParse); + pParse->is_aborted = true; return; } p->iLimit = iLimit = ++pParse->nMem; @@ -2235,7 +2235,7 @@ multi_select_coll_seq_r(struct Parse *parser, struct Select *p, int n, if (collations_check_compatibility(prior_coll_id, is_prior_forced, current_coll_id, is_current_forced, &res_coll_id) != 0) { - parser->rc = SQL_TARANTOOL_ERROR; + parser->is_aborted = true; return 0; } *is_forced_coll = (is_prior_forced || is_current_forced); @@ -3115,7 +3115,7 @@ generateOutputSubroutine(struct Parse *parse, struct Select *p, */ case SRT_Mem:{ assert(in->nSdst == 1 || - parse->rc == SQL_TARANTOOL_ERROR); + parse->is_aborted); testcase(in->nSdst != 1); sqlExprCodeMove(parse, in->iSdst, dest->iSDParm, 1); @@ -3585,7 +3585,7 @@ multiSelectOrderBy(Parse * pParse, /* Parsing context */ *** subqueries *** */ explainComposite(pParse, p->op, iSub1, iSub2, 0); - return pParse->rc == SQL_TARANTOOL_ERROR; + return pParse->is_aborted; } #endif @@ -4428,7 +4428,7 @@ sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom) if (idx == NULL) { diag_set(ClientError, ER_NO_SUCH_INDEX_NAME, zIndexedBy, space->def->name); - sql_parser_error(pParse); + pParse->is_aborted = true; return SQL_ERROR; } pFrom->pIBIndex = idx->def; @@ -5054,7 +5054,7 @@ selectExpander(Walker * pWalker, Select * p) diag_set(ClientError, ER_SQL_SELECT_WILDCARD); } - sql_parser_error(pParse); + pParse->is_aborted = true; } } } @@ -5095,9 +5095,8 @@ sqlExprWalkNoop(Walker * NotUsed, Expr * NotUsed2) * SELECT statement. The SELECT statement must be expanded before * name resolution is performed. * - * If anything goes wrong, an error message is written into pParse. - * The calling function can detect the problem by looking at pParse->rc - * and/or pParse->db->mallocFailed. + * The calling function can detect the problem by looking at + * pParse->is_aborted and/or pParse->db->mallocFailed. */ static void sqlSelectExpand(Parse * pParse, Select * pSelect) @@ -5205,10 +5204,10 @@ sqlSelectPrep(Parse * pParse, /* The parser context */ if (p->selFlags & SF_HasTypeInfo) return; sqlSelectExpand(pParse, p); - if (pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) + if (pParse->is_aborted || db->mallocFailed) return; sqlResolveSelectNames(pParse, p, pOuterNC); - if (pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) + if (pParse->is_aborted || db->mallocFailed) return; sqlSelectAddTypeInfo(pParse, p); } @@ -5463,7 +5462,7 @@ sqlSelect(Parse * pParse, /* The parser context */ pParse->iSelectId = pParse->iNextSelectId++; db = pParse->db; - if (p == 0 || db->mallocFailed || pParse->rc == SQL_TARANTOOL_ERROR) { + if (p == 0 || db->mallocFailed || pParse->is_aborted) { return 1; } memset(&sAggInfo, 0, sizeof(sAggInfo)); @@ -5498,7 +5497,7 @@ sqlSelect(Parse * pParse, /* The parser context */ memset(&sSort, 0, sizeof(sSort)); sSort.pOrderBy = p->pOrderBy; pTabList = p->pSrc; - if (pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) { + if (pParse->is_aborted || db->mallocFailed) { goto select_end; } assert(p->pEList != 0); @@ -6392,7 +6391,7 @@ sqlSelect(Parse * pParse, /* The parser context */ /* The SELECT has been coded. If there is an error in the Parse structure, * set the return code to 1. Otherwise 0. */ - rc = (pParse->rc == SQL_TARANTOOL_ERROR); + rc = pParse->is_aborted; /* Control jumps to here if an error is encountered above, or upon * successful coding of the SELECT. diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 719b85e..42ff4b8 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2643,7 +2643,6 @@ struct Parse { sql *db; /* The main database structure */ char *zErrMsg; /* An error message */ Vdbe *pVdbe; /* An engine for executing database bytecode */ - int rc; /* Return code from execution */ u8 colNamesSet; /* TRUE after OP_ColumnName has been issued to pVdbe */ u8 nTempReg; /* Number of temporary registers in aTempReg[] */ u8 isMultiWrite; /* True if statement may modify/insert multiple rows */ @@ -2677,6 +2676,8 @@ struct Parse { u8 eOrconf; /* Default ON CONFLICT policy for trigger steps */ /** Region to make SQL temp allocations. */ struct region region; + /** Flag to show that parsing should be aborted. */ + bool is_aborted; /************************************************************************** * Fields above must be initialized to zero. The fields that follow, @@ -3190,14 +3191,6 @@ int sqlKeywordCode(const unsigned char *, int); int sqlRunParser(Parse *, const char *, char **); /** - * Increment error counter. - * - * @param parse_context Current parsing context. - */ -void -sql_parser_error(struct Parse *parse_context); - -/** * This routine is called after a single SQL statement has been * parsed and a VDBE program to execute that statement has been * prepared. This routine puts the finishing touches on the diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c index fac2781..4ca3c2e 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -460,7 +460,6 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg) if (db->nVdbeActive == 0) { db->u1.isInterrupted = 0; } - pParse->rc = SQL_OK; pParse->zTail = zSql; i = 0; assert(pzErrMsg != 0); @@ -485,7 +484,7 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg) if (i > mxSqlLen) { diag_set(ClientError, ER_SQL_PARSER_GENERIC, "string or blob too big"); - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; break; } } else { @@ -506,21 +505,21 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg) if (db->u1.isInterrupted) { diag_set(ClientError, ER_SQL_PARSER_GENERIC, "interrupted"); - pParse->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; break; } if (tokenType == TK_ILLEGAL) { diag_set(ClientError, ER_SQL_UNKNOWN_TOKEN, pParse->sLastToken.n, pParse->sLastToken.z); - sql_parser_error(pParse); + pParse->is_aborted = true; break; } } else { sqlParser(pEngine, tokenType, pParse->sLastToken, pParse); lastTokenParsed = tokenType; - if (pParse->rc != SQL_OK || db->mallocFailed) + if (pParse->is_aborted || db->mallocFailed) break; } } @@ -534,25 +533,17 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg) sqlParserFree(pEngine, sql_free); if (db->mallocFailed) { diag_set(OutOfMemory, 0, "SQL", "db"); - pParse->rc = SQL_TARANTOOL_ERROR; - } - if (pParse->rc != SQL_OK && pParse->rc != SQL_DONE - && pParse->zErrMsg == 0) { - const char *error; - if (is_tarantool_error(pParse->rc) && - tarantoolErrorMessage() != NULL) - error = tarantoolErrorMessage(); - else - error = sqlErrStr(pParse->rc); - pParse->zErrMsg = sqlMPrintf(db, "%s", error); + pParse->is_aborted = true; } + if (pParse->is_aborted && pParse->zErrMsg == 0) + pParse->zErrMsg = sqlMPrintf(db, "%s", tarantoolErrorMessage()); assert(pzErrMsg != 0); if (pParse->zErrMsg) { *pzErrMsg = pParse->zErrMsg; - sql_log(pParse->rc, "%s", *pzErrMsg); + sql_log(SQL_TARANTOOL_ERROR, "%s", *pzErrMsg); nErr++; } - if (pParse->pVdbe != NULL && pParse->rc == SQL_TARANTOOL_ERROR) { + if (pParse->pVdbe != NULL && pParse->is_aborted) { sqlVdbeDelete(pParse->pVdbe); pParse->pVdbe = 0; } @@ -560,7 +551,7 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg) if (pParse->pWithToFree) sqlWithDelete(db, pParse->pWithToFree); sqlDbFree(db, pParse->pVList); - assert(nErr == 0 || pParse->rc != SQL_OK); + assert(nErr == 0 || pParse->is_aborted); return nErr; } @@ -583,10 +574,8 @@ sql_expr_compile(sql *db, const char *expr, int expr_len) sprintf(stmt, "%s%.*s", outer, expr_len, expr); char *sql_error = NULL; - if (sqlRunParser(&parser, stmt, &sql_error) != SQL_OK || - parser.parsed_ast_type != AST_TYPE_EXPR) { - diag_set(ClientError, ER_SQL, sql_error); - } else { + if (sqlRunParser(&parser, stmt, &sql_error) == SQL_OK && + parser.parsed_ast_type == AST_TYPE_EXPR) { expression = parser.parsed_ast.expr; parser.parsed_ast.expr = NULL; } @@ -625,11 +614,8 @@ sql_trigger_compile(struct sql *db, const char *sql) parser.parse_only = true; char *sql_error = NULL; struct sql_trigger *trigger = NULL; - if (sqlRunParser(&parser, sql, &sql_error) != SQL_OK || - parser.parsed_ast_type != AST_TYPE_TRIGGER) { - if (parser.rc != SQL_TARANTOOL_ERROR) - diag_set(ClientError, ER_SQL, sql_error); - } else { + if (sqlRunParser(&parser, sql, &sql_error) == SQL_OK && + parser.parsed_ast_type == AST_TYPE_TRIGGER) { trigger = parser.parsed_ast.trigger; parser.parsed_ast.trigger = NULL; } diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c index 6816028..7eacd33 100644 --- a/src/box/sql/trigger.c +++ b/src/box/sql/trigger.c @@ -154,7 +154,7 @@ sql_trigger_begin(struct Parse *parse, struct Token *name, int tr_tm, return; set_tarantool_error_and_cleanup: - parse->rc = SQL_TARANTOOL_ERROR; + parse->is_aborted = true; goto trigger_cleanup; } @@ -168,7 +168,7 @@ sql_trigger_finish(struct Parse *parse, struct TriggerStep *step_list, struct sql *db = parse->db; parse->parsed_ast.trigger = NULL; - if (NEVER(parse->rc == SQL_TARANTOOL_ERROR) || trigger == NULL) + if (NEVER(parse->is_aborted) || trigger == NULL) goto cleanup; char *trigger_name = trigger->zName; trigger->step_list = step_list; @@ -729,11 +729,11 @@ onErrorText(int onError) static void transferParseError(Parse * pTo, Parse * pFrom) { - assert(pFrom->zErrMsg == 0 || pFrom->rc == SQL_TARANTOOL_ERROR); - assert(pTo->zErrMsg == 0 || pTo->rc == SQL_TARANTOOL_ERROR); - if (pTo->rc != SQL_TARANTOOL_ERROR) { + assert(pFrom->zErrMsg == 0 || pFrom->is_aborted); + assert(pTo->zErrMsg == 0 || pTo->is_aborted); + if (!pTo->is_aborted) { pTo->zErrMsg = pFrom->zErrMsg; - pTo->rc = pFrom->rc; + pTo->is_aborted = pFrom->is_aborted; } else { sqlDbFree(pFrom->db, pFrom->zErrMsg); } @@ -922,7 +922,7 @@ vdbe_code_row_trigger_direct(struct Parse *parser, struct sql_trigger *trigger, struct Vdbe *v = sqlGetVdbe(parser); TriggerPrg *pPrg = sql_row_trigger(parser, trigger, space, orconf); - assert(pPrg != NULL || parser->rc == SQL_TARANTOOL_ERROR || + assert(pPrg != NULL || parser->is_aborted || parser->db->mallocFailed != 0); /* diff --git a/src/box/sql/update.c b/src/box/sql/update.c index caf7911..05ceeb4 100644 --- a/src/box/sql/update.c +++ b/src/box/sql/update.c @@ -116,7 +116,7 @@ sqlUpdate(Parse * pParse, /* The parser context */ int upd_cols_cnt = 0; db = pParse->db; - if (pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) { + if (pParse->is_aborted || db->mallocFailed) { goto update_cleanup; } assert(pTabList->nSrc == 1); @@ -192,7 +192,7 @@ sqlUpdate(Parse * pParse, /* The parser context */ if (j >= (int)def->field_count) { diag_set(ClientError, ER_NO_SUCH_FIELD_NAME, pChanges->a[i].zName, def->name); - sql_parser_error(pParse); + pParse->is_aborted = true; goto update_cleanup; } } diff --git a/src/box/sql/util.c b/src/box/sql/util.c index 502d7ab..6129d5b 100644 --- a/src/box/sql/util.c +++ b/src/box/sql/util.c @@ -238,13 +238,7 @@ sqlErrorMsg(Parse * pParse, const char *zFormat, ...) va_end(ap); diag_set(ClientError, ER_SQL_PARSER_GENERIC, zMsg); sqlDbFree(db, zMsg); - pParse->rc = SQL_TARANTOOL_ERROR; -} - -void -sql_parser_error(struct Parse *parse_context) -{ - parse_context->rc = SQL_TARANTOOL_ERROR; + pParse->is_aborted = true; } /* diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index a42e872..9957f3a 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -1215,7 +1215,7 @@ valueFromFunction(sql * db, /* The database connection */ goto value_from_function_out; } - assert(pCtx->pParse->rc == SQL_OK); + assert(!pCtx->pParse->is_aborted); memset(&ctx, 0, sizeof(ctx)); ctx.pOut = pVal; ctx.pFunc = pFunc; @@ -1228,7 +1228,7 @@ valueFromFunction(sql * db, /* The database connection */ assert(rc == SQL_OK); } if (rc != SQL_OK) - pCtx->pParse->rc = SQL_TARANTOOL_ERROR; + pCtx->pParse->is_aborted = true; value_from_function_out: if (rc != SQL_OK) { diff --git a/src/box/sql/where.c b/src/box/sql/where.c index d86b608..cf70e06 100644 --- a/src/box/sql/where.c +++ b/src/box/sql/where.c @@ -2799,7 +2799,7 @@ whereLoopAddBtree(WhereLoopBuilder * pBuilder, /* WHERE clause information */ struct key_def *key_def = key_def_new(&part, 1); if (key_def == NULL) { tnt_error: - pWInfo->pParse->rc = SQL_TARANTOOL_ERROR; + pWInfo->pParse->is_aborted = true; return SQL_TARANTOOL_ERROR; } @@ -4457,7 +4457,7 @@ sqlWhereBegin(Parse * pParse, /* The parser context */ (user_session->sql_flags & SQL_ReverseOrder) != 0) { pWInfo->revMask = ALLBITS; } - if (pParse->rc == SQL_TARANTOOL_ERROR || NEVER(db->mallocFailed)) { + if (pParse->is_aborted || NEVER(db->mallocFailed)) { goto whereBeginError; } #ifdef SQL_DEBUG diff --git a/src/box/sql/wherecode.c b/src/box/sql/wherecode.c index bcb10a5..e1c3366 100644 --- a/src/box/sql/wherecode.c +++ b/src/box/sql/wherecode.c @@ -1472,8 +1472,7 @@ sqlWhereCodeOneLoopStart(WhereInfo * pWInfo, /* Complete information about the W sqlWhereBegin(pParse, pOrTab, pOrExpr, 0, 0, wctrlFlags, iCovCur); - assert(pSubWInfo || - pParse->rc == SQL_TARANTOOL_ERROR + assert(pSubWInfo || pParse->is_aborted || db->mallocFailed); if (pSubWInfo) { WhereLoop *pSubLoop; diff --git a/test/sql-tap/check.test.lua b/test/sql-tap/check.test.lua index bab6493..0d8bf15 100755 --- a/test/sql-tap/check.test.lua +++ b/test/sql-tap/check.test.lua @@ -516,7 +516,7 @@ test:do_catchsql_test( ); ]], { -- - 1, "Wrong space options (field 5): invalid expression specified (SQL error: bindings are not allowed in DDL)" + 1, "Wrong space options (field 5): invalid expression specified (bindings are not allowed in DDL)" -- }) @@ -528,7 +528,7 @@ test:do_catchsql_test( ); ]], { -- - 1, "Wrong space options (field 5): invalid expression specified (SQL error: bindings are not allowed in DDL)" + 1, "Wrong space options (field 5): invalid expression specified (bindings are not allowed in DDL)" -- }) diff --git a/test/sql/checks.result b/test/sql/checks.result index e31964c..42df657 100644 --- a/test/sql/checks.result +++ b/test/sql/checks.result @@ -29,8 +29,8 @@ t = {513, 1, 'test', 'memtx', 0, opts, format} ... s = box.space._space:insert(t) --- -- error: 'Wrong space options (field 5): invalid expression specified (SQL error: - Syntax error near ''<'')' +- error: 'Wrong space options (field 5): invalid expression specified (Syntax error + near ''<'')' ... opts = {checks = {{expr = 'X>5'}}} --- @@ -122,8 +122,8 @@ box.sql.execute("DROP TABLE w2;") -- box.sql.execute("CREATE TABLE t5(x INT PRIMARY KEY, y INT, CHECK( x*y < ? ));") --- -- error: 'Wrong space options (field 5): invalid expression specified (SQL error: - bindings are not allowed in DDL)' +- error: 'Wrong space options (field 5): invalid expression specified (bindings are + not allowed in DDL)' ... opts = {checks = {{expr = '?>5', name = 'ONE'}}} --- @@ -136,8 +136,8 @@ t = {513, 1, 'test', 'memtx', 0, opts, format} ... s = box.space._space:insert(t) --- -- error: 'Wrong space options (field 5): invalid expression specified (SQL error: - bindings are not allowed in DDL)' +- error: 'Wrong space options (field 5): invalid expression specified (bindings are + not allowed in DDL)' ... test_run:cmd("clear filter") --- -- 2.7.4