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 E807D276DF for ; Mon, 25 Feb 2019 12:14:31 -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 sU7Dg4wFEW6m for ; Mon, 25 Feb 2019 12:14:31 -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 4C88627725 for ; Mon, 25 Feb 2019 12:14:31 -0500 (EST) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v2 5/5] sql: remove field nErr of struct Parse Date: Mon, 25 Feb 2019 20:14:29 +0300 Message-Id: <4189982e3c44b8dcdd1fe3358c1b42f30fa6d6d2.1551114402.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 At the moment, the only purpose of the field nErr of struct Parse is to show whether the field rc of the same struct is SQL_TARANTOOL_ERROR RC or not. Let's remove it. Part of #3965 --- src/box/sql.c | 2 -- src/box/sql/alter.c | 1 - src/box/sql/analyze.c | 2 -- src/box/sql/build.c | 62 ++++++++++++++++++------------------------------- src/box/sql/callback.c | 1 - src/box/sql/delete.c | 7 +++--- src/box/sql/expr.c | 26 +++++++++++---------- src/box/sql/insert.c | 4 ++-- src/box/sql/parse.y | 16 ++++++------- src/box/sql/pragma.c | 5 +--- src/box/sql/resolve.c | 13 ++++++----- src/box/sql/select.c | 30 ++++++++++++------------ src/box/sql/sqlInt.h | 9 ------- src/box/sql/tokenize.c | 4 ++-- src/box/sql/trigger.c | 21 +++-------------- src/box/sql/update.c | 4 ++-- src/box/sql/util.c | 8 ------- src/box/sql/where.c | 3 +-- src/box/sql/wherecode.c | 5 ++-- 19 files changed, 83 insertions(+), 140 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index 116e3e8..6402673 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -1276,7 +1276,6 @@ sql_ephemeral_space_def_new(struct Parse *parser, const char *name) diag_set(OutOfMemory, size, "region_alloc", "sql_ephemeral_space_def_new"); parser->rc = SQL_TARANTOOL_ERROR; - parser->nErr++; return NULL; } @@ -1295,7 +1294,6 @@ sql_ephemeral_space_new(Parse *parser, const char *name) if (space == NULL) { diag_set(OutOfMemory, sz, "region", "space"); parser->rc = SQL_TARANTOOL_ERROR; - parser->nErr++; return NULL; } diff --git a/src/box/sql/alter.c b/src/box/sql/alter.c index d49ebb8..214e0f8 100644 --- a/src/box/sql/alter.c +++ b/src/box/sql/alter.c @@ -73,7 +73,6 @@ exit_rename_table: tnt_error: sqlDbFree(db, new_name); parse->rc = SQL_TARANTOOL_ERROR; - parse->nErr++; goto exit_rename_table; } diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index 8c83288..96e5e4c 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -908,7 +908,6 @@ vdbe_emit_analyze_space(struct Parse *parse, struct space *space) diag_set(OutOfMemory, sizeof(int) * part_count, "region", "jump_addrs"); parse->rc = SQL_TARANTOOL_ERROR; - parse->nErr++; return; } /* @@ -1131,7 +1130,6 @@ sqlAnalyze(Parse * pParse, Token * pName) } else { diag_set(ClientError, ER_NO_SUCH_SPACE, z); pParse->rc = SQL_TARANTOOL_ERROR; - pParse->nErr++; } sqlDbFree(db, z); } diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 6afca4a..6621af4 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -92,7 +92,6 @@ save_record(struct Parse *parser, uint32_t space_id, int reg_key, diag_set(OutOfMemory, sizeof(*record), "region_alloc", "record"); parser->rc = SQL_TARANTOOL_ERROR; - parser->nErr++; return; } record->space_id = space_id; @@ -145,9 +144,11 @@ sql_finish_coding(struct Parse *parse_context) "Exit with an error if CREATE statement fails")); } - if (db->mallocFailed || parse_context->nErr != 0) { - if (parse_context->rc == SQL_OK) - parse_context->rc = SQL_ERROR; + if (parse_context->rc == SQL_TARANTOOL_ERROR) + return; + if (db->mallocFailed) { + diag_set(ClientError, ER_SQL_PARSER_GENERIC, "Out of memory"); + parse_context->rc = SQL_TARANTOOL_ERROR; return; } /* @@ -189,13 +190,13 @@ sql_finish_coding(struct Parse *parse_context) sqlVdbeGoto(v, 1); } /* Get the VDBE program ready for execution. */ - if (parse_context->nErr == 0 && !db->mallocFailed) { + if (parse_context->rc != SQL_TARANTOOL_ERROR && !db->mallocFailed) { assert(parse_context->iCacheLevel == 0); sqlVdbeMakeReady(v, parse_context); parse_context->rc = SQL_DONE; - } else { - if (parse_context->rc != SQL_TARANTOOL_ERROR) - parse_context->rc = SQL_ERROR; + } else if (parse_context->rc != SQL_TARANTOOL_ERROR) { + diag_set(ClientError, ER_SQL_PARSER_GENERIC, "Out of memory"); + parse_context->rc = SQL_TARANTOOL_ERROR; } } /** @@ -345,7 +346,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->rc = SQL_TARANTOOL_ERROR; } else { assert(!db->init.busy || CORRUPT_DB); } @@ -398,7 +399,6 @@ sql_field_retrieve(Parse *parser, struct space_def *space_def, uint32_t id) sizeof(space_def->fields[0]), "region_alloc", "sql_field_retrieve"); parser->rc = SQL_TARANTOOL_ERROR; - parser->nErr++; return NULL; } @@ -454,7 +454,6 @@ sqlAddColumn(Parse * pParse, Token * pName, struct type_def *type_def) diag_set(OutOfMemory, pName->n + 1, "region_alloc", "z"); pParse->rc = SQL_TARANTOOL_ERROR; - pParse->nErr++; return; } memcpy(z, pName->z, pName->n); @@ -463,7 +462,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->rc = SQL_TARANTOOL_ERROR; return; } } @@ -538,7 +537,6 @@ sqlAddDefaultValue(Parse * pParse, ExprSpan * pSpan) "region_alloc", "field->default_value"); pParse->rc = SQL_TARANTOOL_ERROR; - pParse->nErr++; return; } strncpy(field->default_value, pSpan->zStart, @@ -557,7 +555,6 @@ field_def_create_for_pk(struct Parse *parser, struct field_def *field, field->nullable_action != ON_CONFLICT_ACTION_DEFAULT) { diag_set(ClientError, ER_NULLABLE_PRIMARY, space_name); parser->rc = SQL_TARANTOOL_ERROR; - parser->nErr++; return -1; } else if (field->nullable_action == ON_CONFLICT_ACTION_DEFAULT) { field->nullable_action = ON_CONFLICT_ACTION_ABORT; @@ -646,7 +643,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->nErr > 0) + if (pParse->rc == SQL_TARANTOOL_ERROR) goto primary_key_exit; } @@ -846,8 +843,6 @@ vdbe_emit_create_index(struct Parse *parse, struct space_def *def, return; error: parse->rc = SQL_TARANTOOL_ERROR; - parse->nErr++; - } /* @@ -905,7 +900,6 @@ createSpace(Parse * pParse, int iSpaceId, char *zStmt) save_record(pParse, BOX_SPACE_ID, iFirstCol, 1, v->nOp - 1); return; error: - pParse->nErr++; pParse->rc = SQL_TARANTOOL_ERROR; } @@ -1086,7 +1080,6 @@ vdbe_emit_fk_constraint_create(struct Parse *parse_context, sqlReleaseTempRange(parse_context, constr_tuple_reg, 10); return; error: - parse_context->nErr++; parse_context->rc = SQL_TARANTOOL_ERROR; } @@ -1116,7 +1109,6 @@ resolve_link(struct Parse *parse_context, const struct space_def *def, tt_sprintf("unknown column %s in foreign key definition", field_name)); parse_context->rc = SQL_TARANTOOL_ERROR; - parse_context->nErr++; return -1; } @@ -1248,7 +1240,6 @@ sqlEndTable(Parse * pParse, /* Parse context */ "number of columns in the primary "\ "index of referenced table"); pParse->rc = SQL_TARANTOOL_ERROR; - pParse->nErr++; return; } for (uint32_t i = 0; i < fk_def->field_count; ++i) { @@ -1278,7 +1269,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->nErr != 0) + if (space == NULL || parse_context->rc == SQL_TARANTOOL_ERROR) goto create_view_fail; struct space *select_res_space = @@ -1324,7 +1315,6 @@ sql_create_view(struct Parse *parse_context, struct Token *begin, if (space->def->opts.sql == NULL) { diag_set(OutOfMemory, n, "strndup", "opts.sql"); parse_context->rc = SQL_TARANTOOL_ERROR; - parse_context->nErr++; goto create_view_fail; } @@ -1597,14 +1587,14 @@ sql_drop_table(struct Parse *parse_context, struct SrcList *table_name_list, goto exit_drop_table; } sqlVdbeCountChanges(v); - assert(parse_context->nErr == 0); + assert(parse_context->rc != SQL_TARANTOOL_ERROR); 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->rc = SQL_TARANTOOL_ERROR; } goto exit_drop_table; } @@ -1644,7 +1634,6 @@ sql_drop_table(struct Parse *parse_context, struct SrcList *table_name_list, diag_set(ClientError, ER_DROP_SPACE, space_name, "other objects depend on it"); parse_context->rc = SQL_TARANTOOL_ERROR; - parse_context->nErr++; goto exit_drop_table; } } @@ -1680,7 +1669,6 @@ columnno_by_name(struct Parse *parse_context, const struct space *space, tt_sprintf("foreign key refers to nonexistent field %s", column_name)); parse_context->rc = SQL_TARANTOOL_ERROR; - parse_context->nErr++; return -1; } return 0; @@ -1890,7 +1878,6 @@ exit_create_fk: return; tnt_error: parse_context->rc = SQL_TARANTOOL_ERROR; - parse_context->nErr++; goto exit_create_fk; } @@ -1915,7 +1902,6 @@ sql_drop_foreign_key(struct Parse *parse_context, struct SrcList *table, if (child == NULL) { diag_set(ClientError, ER_NO_SUCH_SPACE, table_name); parse_context->rc = SQL_TARANTOOL_ERROR; - parse_context->nErr++; return; } char *constraint_name = sqlNameFromToken(parse_context->db, @@ -2042,7 +2028,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->nErr > 0) + if (parse->rc == SQL_TARANTOOL_ERROR) goto cleanup; struct Expr *column_expr = sqlExprSkipCollate(expr); @@ -2094,7 +2080,6 @@ cleanup: return rc; tnt_error: parse->rc = SQL_TARANTOOL_ERROR; - ++parse->nErr; goto cleanup; } @@ -2122,7 +2107,7 @@ sql_create_index(struct Parse *parse, struct Token *token, struct sql *db = parse->db; assert(!db->init.busy); - if (db->mallocFailed || parse->nErr > 0) + if (db->mallocFailed || parse->rc == SQL_TARANTOOL_ERROR) goto exit_create_index; if (idx_type == SQL_INDEX_TYPE_UNIQUE || idx_type == SQL_INDEX_TYPE_NON_UNIQUE) { @@ -2145,7 +2130,6 @@ sql_create_index(struct Parse *parse, struct Token *token, if (! if_not_exist) { diag_set(ClientError, ER_NO_SUCH_SPACE, name); parse->rc = SQL_TARANTOOL_ERROR; - parse->nErr++; } goto exit_create_index; } @@ -2191,7 +2175,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->rc = SQL_TARANTOOL_ERROR; } goto exit_create_index; } @@ -2238,7 +2222,6 @@ 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->nErr++; parse->rc = SQL_TARANTOOL_ERROR; goto exit_create_index; } @@ -2268,7 +2251,6 @@ sql_create_index(struct Parse *parse, struct Token *token, if (index == NULL) { diag_set(OutOfMemory, sizeof(*index), "region", "index"); parse->rc = SQL_TARANTOOL_ERROR; - parse->nErr++; goto exit_create_index; } memset(index, 0, sizeof(*index)); @@ -2438,7 +2420,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->nErr == 0); + assert(parse_context->rc != SQL_TARANTOOL_ERROR); assert(table_token != NULL); const char *table_name = sqlNameFromToken(db, table_token); if (db->mallocFailed) { @@ -2451,7 +2433,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->rc = SQL_TARANTOOL_ERROR; } goto exit_drop_index; } @@ -2462,7 +2444,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->rc = SQL_TARANTOOL_ERROR; } goto exit_drop_index; } @@ -2820,7 +2802,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->rc = SQL_TARANTOOL_ERROR; goto append_from_error; } p = sqlSrcListAppend(db, p, pTable); diff --git a/src/box/sql/callback.c b/src/box/sql/callback.c index 4594cac..6c26402 100644 --- a/src/box/sql/callback.c +++ b/src/box/sql/callback.c @@ -50,7 +50,6 @@ sql_get_coll_seq(Parse *parser, const char *name, uint32_t *coll_id) if (p == NULL) { diag_set(ClientError, ER_NO_SUCH_COLLATION, name); parser->rc = SQL_TARANTOOL_ERROR; - parser->nErr++; return NULL; } else { *coll_id = p->id; diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c index a7bf3b3..c582a10 100644 --- a/src/box/sql/delete.c +++ b/src/box/sql/delete.c @@ -43,7 +43,7 @@ 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->rc = SQL_TARANTOOL_ERROR; return NULL; } assert(space != NULL); @@ -51,7 +51,6 @@ sql_lookup_space(struct Parse *parse, struct SrcList_item *space_name) diag_set(ClientError, ER_UNSUPPORTED, "SQL", "space without format"); parse->rc = SQL_TARANTOOL_ERROR; - parse->nErr++; return NULL; } space_name->space = space; @@ -94,7 +93,7 @@ sql_table_truncate(struct Parse *parse, struct SrcList *tab_list) struct space *space = space_by_name(tab_name); if (space == NULL) { diag_set(ClientError, ER_NO_SUCH_SPACE, tab_name); - sql_parser_error(parse); + parse->rc = SQL_TARANTOOL_ERROR; } if (! rlist_empty(&space->parent_fk_constraint)) { sqlErrorMsg(parse, "can not truncate space '%s' because other " @@ -117,7 +116,7 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list, struct Expr *where) { struct sql *db = parse->db; - if (parse->nErr || db->mallocFailed) + if (parse->rc == SQL_TARANTOOL_ERROR || 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 c914cfb..e4924ac 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -254,10 +254,9 @@ sql_expr_coll(Parse *parse, Expr *p, bool *is_explicit_coll, uint32_t *coll_id, * several times: this * function is recursive. */ - if (parse->nErr == 0) { + if (parse->rc != SQL_TARANTOOL_ERROR) { diag_set(ClientError, ER_ILLEGAL_COLLATION_MIX); - parse->nErr++; parse->rc = SQL_TARANTOOL_ERROR; } return -1; @@ -411,7 +410,6 @@ sql_binary_compare_coll_seq(Parse *parser, Expr *left, Expr *right, if (collations_check_compatibility(lhs_coll_id, is_lhs_forced, rhs_coll_id, is_rhs_forced, id) != 0) { parser->rc = SQL_TARANTOOL_ERROR; - parser->nErr++; return -1; } return 0; @@ -821,7 +819,7 @@ exprSetHeight(Expr * p) void sqlExprSetHeightAndFlags(Parse * pParse, Expr * p) { - if (pParse->nErr) + if (pParse->rc == SQL_TARANTOOL_ERROR) return; exprSetHeight(p); sqlExprCheckHeight(pParse, p->nHeight); @@ -1005,7 +1003,7 @@ sqlPExpr(Parse * pParse, /* Parsing context */ ) { Expr *p; - if (op == TK_AND && pParse->nErr == 0) { + if (op == TK_AND && pParse->rc != SQL_TARANTOOL_ERROR) { /* Take advantage of short-circuit false optimization for AND */ p = sqlExprAnd(pParse->db, pLeft, pRight); } else { @@ -2407,7 +2405,8 @@ sqlFindInIndex(Parse * pParse, /* Parsing context */ * satisfy the query. This is preferable to generating a new * ephemeral table. */ - if (pParse->nErr == 0 && (p = isCandidateForInOpt(pX)) != 0) { + if (pParse->rc != SQL_TARANTOOL_ERROR && + (p = isCandidateForInOpt(pX)) != 0) { sql *db = pParse->db; /* Database connection */ ExprList *pEList = p->pEList; int nExpr = pEList->nExpr; @@ -3041,8 +3040,9 @@ sqlExprCodeIN(Parse * pParse, /* Parsing and code generating context */ destIfFalse == destIfNull ? 0 : &rRhsHasNull, aiMap, 0); - assert(pParse->nErr || nVector == 1 || eType == IN_INDEX_EPH - || eType == IN_INDEX_INDEX_ASC || eType == IN_INDEX_INDEX_DESC); + assert(pParse->rc == SQL_TARANTOOL_ERROR || nVector == 1 || + eType == IN_INDEX_EPH || eType == IN_INDEX_INDEX_ASC || + eType == IN_INDEX_INDEX_DESC); #ifdef SQL_DEBUG /* Confirm that aiMap[] contains nVector integer values between 0 and * nVector-1. @@ -3364,7 +3364,8 @@ 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->nErr || pParse->db->mallocFailed); + assert(iReg > 0 || pParse->rc == SQL_TARANTOOL_ERROR || + pParse->db->mallocFailed); assert(iCol >= -1 && iCol < 32768); /* Finite column numbers */ /* The SQL_ColumnCache flag disables the column cache. This is used @@ -3997,7 +3998,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->rc = SQL_TARANTOOL_ERROR; break; } @@ -4341,8 +4342,9 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) } else { sqlVdbeAddOp2(v, OP_Null, 0, target); } - assert(pParse->db->mallocFailed || pParse->nErr > 0 - || pParse->iCacheLevel == iCacheLevel); + assert(pParse->db->mallocFailed || + pParse->rc == SQL_TARANTOOL_ERROR || + pParse->iCacheLevel == iCacheLevel); sqlVdbeResolveLabel(v, endLabel); break; } diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index 17fbdec..e8cdd39 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->nErr || db->mallocFailed) { + if (pParse->rc == SQL_TARANTOOL_ERROR || 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->nErr) + if (rc || db->mallocFailed || pParse->rc == SQL_TARANTOOL_ERROR) 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 67a7a57..ac50731 100644 --- a/src/box/sql/parse.y +++ b/src/box/sql/parse.y @@ -38,11 +38,11 @@ } else { diag_set(ClientError, ER_SQL_SYNTAX_NEAR, TOKEN.n, TOKEN.z); } - sql_parser_error(pParse); + pParse->rc = SQL_TARANTOOL_ERROR; } %stack_overflow { diag_set(ClientError, ER_SQL_STACK_OVERFLOW); - sql_parser_error(pParse); + pParse->rc = SQL_TARANTOOL_ERROR; } // 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->rc = SQL_TARANTOOL_ERROR; } 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->rc = SQL_TARANTOOL_ERROR; } } @@ -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_SYNTAX_NEAR, t.n, t.z); - sql_parser_error(pParse); + pParse->rc = SQL_TARANTOOL_ERROR; } 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_SYNTAX_NEAR, t.n, t.z); - sql_parser_error(pParse); + pParse->rc = SQL_TARANTOOL_ERROR; 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->rc = SQL_TARANTOOL_ERROR; } 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->rc = SQL_TARANTOOL_ERROR; } diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c index a7224f5..b555c06 100644 --- a/src/box/sql/pragma.c +++ b/src/box/sql/pragma.c @@ -469,7 +469,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->rc = SQL_TARANTOOL_ERROR; goto pragma_out; } /* Register the result column names for pragmas that return results */ @@ -537,7 +537,6 @@ sqlPragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ iter = box_index_iterator(space->def->id, 0,ITER_ALL, key_buf, key_end); if (iter == NULL) { pParse->rc = SQL_TARANTOOL_ERROR; - pParse->nErr++; goto pragma_out; } int rc = box_iterator_next(iter, &tuple); @@ -623,12 +622,10 @@ sqlPragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ diag_set(ClientError, ER_ILLEGAL_PARAMS, "string value is expected"); pParse->rc = SQL_TARANTOOL_ERROR; - pParse->nErr++; goto pragma_out; } if (sql_default_engine_set(zRight) != 0) { pParse->rc = SQL_TARANTOOL_ERROR; - pParse->nErr++; goto pragma_out; } sqlVdbeAddOp0(v, OP_Expire); diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c index 1339157..0b3d876 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->rc = SQL_TARANTOOL_ERROR; 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->rc = SQL_TARANTOOL_ERROR; pNC->nErr++; } else if (wrong_num_args) { sqlErrorMsg(pParse, @@ -809,7 +809,7 @@ resolveExprStep(Walker * pWalker, Expr * pExpr) break; } } - return (pParse->nErr + return (pParse->rc == SQL_TARANTOOL_ERROR || 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->nErr + return (pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) ? WRC_Abort : WRC_Prune; } @@ -1252,7 +1252,8 @@ resolveSelectStep(Walker * pWalker, Select * p) sqlResolveSelectNames(pParse, pItem->pSelect, pOuterNC); - if (pParse->nErr || db->mallocFailed) + if (pParse->rc == SQL_TARANTOOL_ERROR || + db->mallocFailed) return WRC_Abort; for (pNC = pOuterNC; pNC; pNC = pNC->pNext) @@ -1529,7 +1530,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->nErr > 0) { + if (pNC->nErr > 0 || w.pParse->rc == SQL_TARANTOOL_ERROR) { ExprSetProperty(pExpr, EP_Error); } if (pNC->ncFlags & NC_HasAgg) { diff --git a/src/box/sql/select.c b/src/box/sql/select.c index 7eea90e..3249db6 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->nErr > 0 + assert(pOffset == 0 || pLimit != 0 || pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed != 0); if (db->mallocFailed) { clearSelect(db, pNew, pNew != &standin); pNew = 0; } else { - assert(pNew->pSrc != 0 || pParse->nErr > 0); + assert(pNew->pSrc != 0 || pParse->rc == SQL_TARANTOOL_ERROR); } 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->nErr) + if (pParse->rc == SQL_TARANTOOL_ERROR) 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_SYNTAX_NEAR, sizeof("COLLATE"), "COLLATE"); - sql_parser_error(pParse); + pParse->rc = SQL_TARANTOOL_ERROR; return; } p->iLimit = iLimit = ++pParse->nMem; @@ -2236,7 +2236,6 @@ multi_select_coll_seq_r(struct Parse *parser, struct Select *p, int n, current_coll_id, is_current_forced, &res_coll_id) != 0) { parser->rc = SQL_TARANTOOL_ERROR; - parser->nErr++; return 0; } *is_forced_coll = (is_prior_forced || is_current_forced); @@ -3115,7 +3114,8 @@ generateOutputSubroutine(struct Parse *parse, struct Select *p, * of the scan loop. */ case SRT_Mem:{ - assert(in->nSdst == 1 || parse->nErr > 0); + assert(in->nSdst == 1 || + parse->rc == SQL_TARANTOOL_ERROR); 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->nErr != 0; + return pParse->rc == SQL_TARANTOOL_ERROR; } #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->rc = SQL_TARANTOOL_ERROR; return SQL_ERROR; } pFrom->pIBIndex = idx->def; @@ -5055,7 +5055,7 @@ selectExpander(Walker * pWalker, Select * p) diag_set(ClientError, ER_SQL_SELECT_WILDCARD); } - sql_parser_error(pParse); + pParse->rc = SQL_TARANTOOL_ERROR; } } } @@ -5097,7 +5097,7 @@ sqlExprWalkNoop(Walker * NotUsed, Expr * NotUsed2) * 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->nErr + * The calling function can detect the problem by looking at pParse->rc * and/or pParse->db->mallocFailed. */ static void @@ -5206,10 +5206,10 @@ sqlSelectPrep(Parse * pParse, /* The parser context */ if (p->selFlags & SF_HasTypeInfo) return; sqlSelectExpand(pParse, p); - if (pParse->nErr || db->mallocFailed) + if (pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) return; sqlResolveSelectNames(pParse, p, pOuterNC); - if (pParse->nErr || db->mallocFailed) + if (pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) return; sqlSelectAddTypeInfo(pParse, p); } @@ -5464,7 +5464,7 @@ sqlSelect(Parse * pParse, /* The parser context */ pParse->iSelectId = pParse->iNextSelectId++; db = pParse->db; - if (p == 0 || db->mallocFailed || pParse->nErr) { + if (p == 0 || db->mallocFailed || pParse->rc == SQL_TARANTOOL_ERROR) { return 1; } memset(&sAggInfo, 0, sizeof(sAggInfo)); @@ -5499,7 +5499,7 @@ sqlSelect(Parse * pParse, /* The parser context */ memset(&sSort, 0, sizeof(sSort)); sSort.pOrderBy = p->pOrderBy; pTabList = p->pSrc; - if (pParse->nErr || db->mallocFailed) { + if (pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed) { goto select_end; } assert(p->pEList != 0); @@ -6393,7 +6393,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->nErr > 0); + rc = (pParse->rc == SQL_TARANTOOL_ERROR); /* 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 1a28f1a..be0e94e 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2665,7 +2665,6 @@ struct Parse { u8 nColCache; /* Number of entries in aColCache[] */ int nRangeReg; /* Size of the temporary register block */ int iRangeReg; /* First register in temporary register block */ - int nErr; /* Number of errors seen */ int nTab; /* Number of previously allocated VDBE cursors */ int nMem; /* Number of memory cells used so far */ int nOpAlloc; /* Number of slots allocated for Vdbe.aOp[] */ @@ -3223,14 +3222,6 @@ int sqlKeywordCode(const unsigned char *, int); int sqlRunParser(Parse *, const 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 5ea0ea5..fe2c0ab 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -508,7 +508,7 @@ sqlRunParser(Parse * pParse, const char *zSql) diag_set(ClientError, ER_SQL_UNKNOWN_TOKEN, pParse->sLastToken.n, pParse->sLastToken.z); - sql_parser_error(pParse); + pParse->rc = SQL_TARANTOOL_ERROR; break; } } else { @@ -532,7 +532,7 @@ sqlRunParser(Parse * pParse, const char *zSql) } if (pParse->rc != SQL_OK && pParse->rc != SQL_DONE) nErr++; - if (pParse->pVdbe != NULL && pParse->nErr > 0) { + if (pParse->pVdbe != NULL && pParse->rc == SQL_TARANTOOL_ERROR) { sqlVdbeDelete(pParse->pVdbe); pParse->pVdbe = 0; } diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c index 4c7ab8a..89d42d1 100644 --- a/src/box/sql/trigger.c +++ b/src/box/sql/trigger.c @@ -155,7 +155,6 @@ sql_trigger_begin(struct Parse *parse, struct Token *name, int tr_tm, set_tarantool_error_and_cleanup: parse->rc = SQL_TARANTOOL_ERROR; - parse->nErr++; goto trigger_cleanup; } @@ -169,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->nErr) || trigger == NULL) + if (NEVER(parse->rc == SQL_TARANTOOL_ERROR) || trigger == NULL) goto cleanup; char *trigger_name = trigger->zName; trigger->step_list = step_list; @@ -722,20 +721,6 @@ onErrorText(int onError) } #endif -/* - * Parse context structure pFrom has just been used to create a sub-vdbe - * (trigger program). If an error has occurred, transfer error information - * from pFrom to pTo. - */ -static void -transferParseError(Parse * pTo, Parse * pFrom) -{ - if (pTo->nErr == 0) { - pTo->nErr = pFrom->nErr; - pTo->rc = pFrom->rc; - } -} - /** * Create and populate a new TriggerPrg object with a sub-program * implementing trigger pTrigger with ON CONFLICT policy orconf. @@ -844,7 +829,7 @@ sql_row_trigger_program(struct Parse *parser, struct sql_trigger *trigger, VdbeComment((v, "End: %s.%s", trigger->zName, onErrorText(orconf))); - transferParseError(parser, pSubParse); + parser->rc = pSubParse->rc; if (db->mallocFailed == 0) { pProgram->aOp = sqlVdbeTakeOpArray(v, &pProgram->nOp, @@ -918,7 +903,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->nErr != 0 || + assert(pPrg != NULL || parser->rc == SQL_TARANTOOL_ERROR || parser->db->mallocFailed != 0); /* diff --git a/src/box/sql/update.c b/src/box/sql/update.c index 670e547..40d16ac 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->nErr || db->mallocFailed) { + if (pParse->rc == SQL_TARANTOOL_ERROR || 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->rc = SQL_TARANTOOL_ERROR; goto update_cleanup; } } diff --git a/src/box/sql/util.c b/src/box/sql/util.c index e4c93cb..4f7e36a 100644 --- a/src/box/sql/util.c +++ b/src/box/sql/util.c @@ -238,17 +238,9 @@ sqlErrorMsg(Parse * pParse, const char *zFormat, ...) va_end(ap); diag_set(ClientError, ER_SQL_PARSER_GENERIC, zMsg); sqlDbFree(db, zMsg); - pParse->nErr++; pParse->rc = SQL_TARANTOOL_ERROR; } -void -sql_parser_error(struct Parse *parse_context) -{ - parse_context->nErr++; - parse_context->rc = SQL_TARANTOOL_ERROR; -} - /* * Convert an SQL-style quoted string into a normal string by removing * the quote characters. The conversion is done in-place. If the diff --git a/src/box/sql/where.c b/src/box/sql/where.c index 1bba9d6..28a19f0 100644 --- a/src/box/sql/where.c +++ b/src/box/sql/where.c @@ -2805,7 +2805,6 @@ whereLoopAddBtree(WhereLoopBuilder * pBuilder, /* WHERE clause information */ struct key_def *key_def = key_def_new(&part, 1); if (key_def == NULL) { tnt_error: - pWInfo->pParse->nErr++; pWInfo->pParse->rc = SQL_TARANTOOL_ERROR; return SQL_TARANTOOL_ERROR; } @@ -4464,7 +4463,7 @@ sqlWhereBegin(Parse * pParse, /* The parser context */ (user_session->sql_flags & SQL_ReverseOrder) != 0) { pWInfo->revMask = ALLBITS; } - if (pParse->nErr || NEVER(db->mallocFailed)) { + if (pParse->rc == SQL_TARANTOOL_ERROR || NEVER(db->mallocFailed)) { goto whereBeginError; } #ifdef WHERETRACE_ENABLED diff --git a/src/box/sql/wherecode.c b/src/box/sql/wherecode.c index 04b79ab..0360f40 100644 --- a/src/box/sql/wherecode.c +++ b/src/box/sql/wherecode.c @@ -1473,8 +1473,9 @@ sqlWhereCodeOneLoopStart(WhereInfo * pWInfo, /* Complete information about the W sqlWhereBegin(pParse, pOrTab, pOrExpr, 0, 0, wctrlFlags, iCovCur); - assert(pSubWInfo || pParse->nErr - || db->mallocFailed); + assert(pSubWInfo || + pParse->rc == SQL_TARANTOOL_ERROR || + db->mallocFailed); if (pSubWInfo) { WhereLoop *pSubLoop; int addrExplain = -- 2.7.4