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 93F3F2779E for ; Sat, 2 Mar 2019 08:07:56 -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 3S5zRsmirU4Z for ; Sat, 2 Mar 2019 08:07:56 -0500 (EST) Received: from smtpng2.m.smailru.net (smtpng2.m.smailru.net [94.100.179.3]) (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 F407D26208 for ; Sat, 2 Mar 2019 08:07:55 -0500 (EST) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v3 3/9] sql: remove field nErr of struct Parse Date: Sat, 2 Mar 2019 16:07:53 +0300 Message-Id: <0448cc416f3401eeecbad1883fea7193399a72aa.1551530224.git.imeevma@gmail.com> MIME-Version: 1.0 In-Reply-To: References: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit 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 Hi! Thank you for review. My answers and new version below. There won't be diff between versions as I completely rewritten this patch to place it before removing of nErr and zErrMsg. On 2/26/19 5:48 PM, n.pettik wrote: > >> 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) > > rc == 0 / ! abort > Fixed in next patch. >> + return; >> + if (db->mallocFailed) { >> + diag_set(ClientError, ER_SQL_PARSER_GENERIC, "Out of memoryā€¯); > > Why generic when it is OOM error? > I fixed this, but not sure that I wrote right error description. >> + parse_context->rc = SQL_TARANTOOL_ERROR; > > rc = -1 / abort = true > Fixed in next patch. >> 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; > > The same is here and in other places . > If it is about flag than it was fixed in next patch. If this is about OOM error than anvwer is the same as for second comment. New version: commit 0448cc416f3401eeecbad1883fea7193399a72aa Author: Mergen Imeev Date: Tue Feb 26 22:22:26 2019 +0300 sql: remove field nErr of struct Parse 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_OK or SQL_TARANTOOL_ERROR. Let's remove it. Part of #3965 diff --git a/src/box/sql.c b/src/box/sql.c index a2937a0..cb0facf 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 deb5b89..7d6c1c9 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(OutOfMemory, 0, "SQL", "db"); + parse_context->rc = SQL_TARANTOOL_ERROR; return; } /* @@ -189,13 +190,12 @@ 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_OK && !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(OutOfMemory, 0, "SQL", "db"); + parse_context->rc = SQL_TARANTOOL_ERROR; } } /** @@ -398,7 +398,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 +453,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); @@ -502,7 +500,6 @@ sql_column_add_nullable_action(struct Parse *parser, nullable_action]); diag_set(ClientError, ER_SQL, err_msg); parser->rc = SQL_TARANTOOL_ERROR; - parser->nErr++; return; } field->nullable_action = nullable_action; @@ -544,7 +541,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, @@ -563,7 +559,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; @@ -652,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->nErr > 0) + if (pParse->rc == SQL_TARANTOOL_ERROR) goto primary_key_exit; } @@ -852,8 +847,6 @@ vdbe_emit_create_index(struct Parse *parse, struct space_def *def, return; error: parse->rc = SQL_TARANTOOL_ERROR; - parse->nErr++; - } /* @@ -911,7 +904,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; } @@ -1092,7 +1084,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; } @@ -1122,7 +1113,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; } @@ -1254,7 +1244,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) { @@ -1284,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->nErr != 0) + if (space == NULL || parse_context->rc == SQL_TARANTOOL_ERROR) goto create_view_fail; struct space *select_res_space = @@ -1330,7 +1319,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; } @@ -1603,7 +1591,7 @@ 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); @@ -1650,7 +1638,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; } } @@ -1686,7 +1673,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; @@ -1896,7 +1882,6 @@ exit_create_fk: return; tnt_error: parse_context->rc = SQL_TARANTOOL_ERROR; - parse_context->nErr++; goto exit_create_fk; } @@ -1921,7 +1906,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, @@ -2048,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->nErr > 0) + if (parse->rc == SQL_TARANTOOL_ERROR) goto cleanup; struct Expr *column_expr = sqlExprSkipCollate(expr); @@ -2100,7 +2084,6 @@ cleanup: return rc; tnt_error: parse->rc = SQL_TARANTOOL_ERROR; - ++parse->nErr; goto cleanup; } @@ -2128,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->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) { @@ -2151,7 +2134,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; } @@ -2244,7 +2226,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; } @@ -2274,7 +2255,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)); @@ -2444,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->nErr == 0); + assert(parse_context->rc != SQL_TARANTOOL_ERROR); assert(table_token != NULL); const char *table_name = sqlNameFromToken(db, table_token); if (db->mallocFailed) { 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 5170c7f..fba07a9 100644 --- a/src/box/sql/delete.c +++ b/src/box/sql/delete.c @@ -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; @@ -117,7 +116,6 @@ cleanup: tarantool_error: parse->rc = SQL_TARANTOOL_ERROR; - parse->nErr++; goto cleanup; } @@ -126,7 +124,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 a75f237..0911eee 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 @@ -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/pragma.c b/src/box/sql/pragma.c index 8b909f2..6dc41a3 100644 --- a/src/box/sql/pragma.c +++ b/src/box/sql/pragma.c @@ -507,7 +507,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); @@ -566,7 +565,6 @@ 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 (zRight == NULL) { @@ -578,7 +576,6 @@ sqlPragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ } else { 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 aed9e26..dfb6238 100644 --- a/src/box/sql/resolve.c +++ b/src/box/sql/resolve.c @@ -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) @@ -1336,7 +1337,6 @@ resolveSelectStep(Walker * pWalker, Select * p) "argument must appear in the GROUP BY " "clause or be used in an aggregate " "function"); - pParse->nErr++; pParse->rc = SQL_TARANTOOL_ERROR; 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->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 ef24760..4698bb4 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; @@ -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 @@ -5096,7 +5096,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 @@ -5205,10 +5205,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); } @@ -5463,7 +5463,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)); @@ -5498,7 +5498,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); @@ -6392,7 +6392,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 387cfa9..719b85e 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2654,7 +2654,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[] */ diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c index 58685c4..fac2781 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -483,7 +483,9 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg) &pParse->sLastToken.isReserved); i += pParse->sLastToken.n; if (i > mxSqlLen) { - pParse->rc = SQL_TOOBIG; + diag_set(ClientError, ER_SQL_PARSER_GENERIC, + "string or blob too big"); + pParse->rc = SQL_TARANTOOL_ERROR; break; } } else { @@ -502,7 +504,9 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg) assert(tokenType == TK_SPACE || tokenType == TK_ILLEGAL); if (db->u1.isInterrupted) { - pParse->rc = SQL_INTERRUPT; + diag_set(ClientError, ER_SQL_PARSER_GENERIC, + "interrupted"); + pParse->rc = SQL_TARANTOOL_ERROR; break; } if (tokenType == TK_ILLEGAL) { @@ -529,7 +533,8 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg) #endif /* YYDEBUG */ sqlParserFree(pEngine, sql_free); if (db->mallocFailed) { - pParse->rc = SQL_NOMEM; + diag_set(OutOfMemory, 0, "SQL", "db"); + pParse->rc = SQL_TARANTOOL_ERROR; } if (pParse->rc != SQL_OK && pParse->rc != SQL_DONE && pParse->zErrMsg == 0) { @@ -547,7 +552,7 @@ sqlRunParser(Parse * pParse, const char *zSql, char **pzErrMsg) sql_log(pParse->rc, "%s", *pzErrMsg); 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 f7e6189..6816028 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; @@ -730,11 +729,10 @@ onErrorText(int onError) static void transferParseError(Parse * pTo, Parse * pFrom) { - assert(pFrom->zErrMsg == 0 || pFrom->nErr); - assert(pTo->zErrMsg == 0 || pTo->nErr); - if (pTo->nErr == 0) { + assert(pFrom->zErrMsg == 0 || pFrom->rc == SQL_TARANTOOL_ERROR); + assert(pTo->zErrMsg == 0 || pTo->rc == SQL_TARANTOOL_ERROR); + if (pTo->rc != SQL_TARANTOOL_ERROR) { pTo->zErrMsg = pFrom->zErrMsg; - pTo->nErr = pFrom->nErr; pTo->rc = pFrom->rc; } else { sqlDbFree(pFrom->db, pFrom->zErrMsg); @@ -924,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->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..caf7911 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); diff --git a/src/box/sql/util.c b/src/box/sql/util.c index e4c93cb..502d7ab 100644 --- a/src/box/sql/util.c +++ b/src/box/sql/util.c @@ -211,7 +211,7 @@ sqlErrorWithMsg(sql * db, int err_code, const char *zFormat, ...) } /* - * Add an error message to pParse->zErrMsg and increment pParse->nErr. + * Add an error message to pParse->zErrMsg. * The following formatting characters are allowed: * * %s Insert a string @@ -238,14 +238,12 @@ 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; } diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index f67c32e..a42e872 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -1227,7 +1227,8 @@ valueFromFunction(sql * db, /* The database connection */ sql_value_apply_type(pVal, type); assert(rc == SQL_OK); } - pCtx->pParse->rc = rc; + if (rc != SQL_OK) + pCtx->pParse->rc = SQL_TARANTOOL_ERROR; value_from_function_out: if (rc != SQL_OK) { diff --git a/src/box/sql/where.c b/src/box/sql/where.c index 5a3c9be..d86b608 100644 --- a/src/box/sql/where.c +++ b/src/box/sql/where.c @@ -2799,7 +2799,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; } @@ -4458,7 +4457,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 SQL_DEBUG diff --git a/src/box/sql/wherecode.c b/src/box/sql/wherecode.c index 018fd8a..bcb10a5 100644 --- a/src/box/sql/wherecode.c +++ b/src/box/sql/wherecode.c @@ -1472,7 +1472,8 @@ sqlWhereCodeOneLoopStart(WhereInfo * pWInfo, /* Complete information about the W sqlWhereBegin(pParse, pOrTab, pOrExpr, 0, 0, wctrlFlags, iCovCur); - assert(pSubWInfo || pParse->nErr + assert(pSubWInfo || + pParse->rc == SQL_TARANTOOL_ERROR || db->mallocFailed); if (pSubWInfo) { WhereLoop *pSubLoop; -- 2.7.4