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 DB71D2F902 for ; Sat, 25 May 2019 06:45:03 -0400 (EDT) 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 j2tFbgyneRoe for ; Sat, 25 May 2019 06:45:03 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (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 51AE52FD6F for ; Sat, 25 May 2019 06:45:03 -0400 (EDT) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v1 18/21] sql: remove SQL_TARANTOOL_ERROR errcode Date: Sat, 25 May 2019 13:45:01 +0300 Message-Id: <12d7168644cb3ffa1a2a8f5a214dc437b76d7817.1558780708.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 Removing this error code is part of getting rid of the SQL error system. --- src/box/sql.c | 89 +++++++++++++++++++-------------------------- src/box/sql/analyze.c | 6 +-- src/box/sql/build.c | 5 +-- src/box/sql/expr.c | 2 +- src/box/sql/fk_constraint.c | 2 +- src/box/sql/insert.c | 4 +- src/box/sql/main.c | 6 +-- src/box/sql/prepare.c | 4 +- src/box/sql/select.c | 21 ++++------- src/box/sql/sqlInt.h | 6 +-- src/box/sql/tarantoolInt.h | 6 +-- src/box/sql/vdbe.c | 38 ++++++------------- src/box/sql/vdbeapi.c | 10 ++--- src/box/sql/vdbeaux.c | 8 ++-- src/box/sql/vdbemem.c | 4 +- src/box/sql/where.c | 2 +- 16 files changed, 86 insertions(+), 127 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index 84e7d9c..46f3755 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -191,7 +191,7 @@ tarantoolsqlTupleColumnFast(BtCursor *pCur, u32 fieldno, u32 *field_size) int tarantoolsqlFirst(BtCursor *pCur, int *pRes) { if (key_alloc(pCur, sizeof(nil_key)) != 0) - return SQL_TARANTOOL_ERROR; + return -1; memcpy(pCur->key, nil_key, sizeof(nil_key)); pCur->iter_type = ITER_GE; return cursor_seek(pCur, pRes); @@ -201,7 +201,7 @@ int tarantoolsqlFirst(BtCursor *pCur, int *pRes) int tarantoolsqlLast(BtCursor *pCur, int *pRes) { if (key_alloc(pCur, sizeof(nil_key)) != 0) - return SQL_TARANTOOL_ERROR; + return -1; memcpy(pCur->key, nil_key, sizeof(nil_key)); pCur->iter_type = ITER_LE; return cursor_seek(pCur, pRes); @@ -249,9 +249,9 @@ int tarantoolsqlMovetoUnpacked(BtCursor *pCur, UnpackedRecord *pIdxKey, sql_vdbe_mem_encode_tuple(pIdxKey->aMem, pIdxKey->nField, &tuple_size, region); if (tuple == NULL) - return SQL_TARANTOOL_ERROR; + return -1; if (key_alloc(pCur, tuple_size) != 0) - return SQL_TARANTOOL_ERROR; + return -1; memcpy(pCur->key, tuple, tuple_size); region_truncate(region, used); @@ -404,9 +404,7 @@ int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple, { assert(space != NULL); mp_tuple_assert(tuple, tuple_end); - if (space_ephemeral_replace(space, tuple, tuple_end) != 0) - return SQL_TARANTOOL_ERROR; - return 0; + return space_ephemeral_replace(space, tuple, tuple_end); } /* Simply delete ephemeral space by calling space_delete(). */ @@ -431,8 +429,7 @@ insertOrReplace(struct space *space, const char *tuple, const char *tuple_end, request.space_id = space->def->id; request.type = type; mp_tuple_assert(request.tuple, request.tuple_end); - int rc = box_process_rw(&request, space, NULL); - return rc == 0 ? 0 : SQL_TARANTOOL_ERROR; + return box_process_rw(&request, space, NULL); } int tarantoolsqlInsert(struct space *space, const char *tuple, @@ -453,7 +450,7 @@ int tarantoolsqlReplace(struct space *space, const char *tuple, * * @param pCur Cursor pointing to ephemeral space. * - * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, -1 otherwise. */ int tarantoolsqlEphemeralDelete(BtCursor *pCur) { @@ -467,12 +464,12 @@ int tarantoolsqlEphemeralDelete(BtCursor *pCur) pCur->iter->index->def->key_def, MULTIKEY_NONE, &key_size); if (key == NULL) - return SQL_TARANTOOL_ERROR; + return -1; int rc = space_ephemeral_delete(pCur->space, key); if (rc != 0) { diag_log(); - return SQL_TARANTOOL_ERROR; + return -1; } return 0; } @@ -487,17 +484,14 @@ int tarantoolsqlDelete(BtCursor *pCur, u8 flags) char *key; uint32_t key_size; - int rc; key = tuple_extract_key(pCur->last_tuple, pCur->iter->index->def->key_def, MULTIKEY_NONE, &key_size); if (key == NULL) - return SQL_TARANTOOL_ERROR; - rc = sql_delete_by_key(pCur->space, pCur->index->def->iid, key, - key_size); - - return rc == 0 ? 0 : SQL_TARANTOOL_ERROR; + return -1; + return sql_delete_by_key(pCur->space, pCur->index->def->iid, key, + key_size); } int @@ -513,9 +507,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key, request.space_id = space->def->id; request.index_id = iid; assert(space_index(space, iid)->def->opts.is_unique); - int rc = box_process_rw(&request, space, &unused); - - return rc == 0 ? 0 : SQL_TARANTOOL_ERROR; + return box_process_rw(&request, space, &unused); } /* @@ -525,7 +517,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key, * * @param pCur Cursor pointing to ephemeral space. * - * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, -1 otherwise. */ int tarantoolsqlEphemeralClearTable(BtCursor *pCur) { @@ -537,7 +529,7 @@ int tarantoolsqlEphemeralClearTable(BtCursor *pCur) 0 /* part_count */); if (it == NULL) { pCur->eState = CURSOR_INVALID; - return SQL_TARANTOOL_ERROR; + return -1; } struct tuple *tuple; @@ -549,7 +541,7 @@ int tarantoolsqlEphemeralClearTable(BtCursor *pCur) MULTIKEY_NONE, &key_size); if (space_ephemeral_delete(pCur->space, key) != 0) { iterator_delete(it); - return SQL_TARANTOOL_ERROR; + return -1; } } iterator_delete(it); @@ -576,7 +568,7 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count) struct index *pk = space_index(space, 0 /* PK */); struct iterator *iter = index_create_iterator(pk, ITER_ALL, nil_key, 0); if (iter == NULL) - return SQL_TARANTOOL_ERROR; + return -1; while (iterator_next(iter, &tuple) == 0 && tuple != NULL) { request.key = tuple_extract_key(tuple, pk->def->key_def, MULTIKEY_NONE, &key_size); @@ -584,7 +576,7 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count) rc = box_process_rw(&request, space, &unused); if (rc != 0) { iterator_delete(iter); - return SQL_TARANTOOL_ERROR; + return -1; } (*tuple_count)++; } @@ -614,12 +606,12 @@ int tarantoolsqlRenameTrigger(const char *trig_name, char *key_begin = (char*) region_alloc(&fiber()->gc, key_len); if (key_begin == NULL) { diag_set(OutOfMemory, key_len, "region_alloc", "key_begin"); - return SQL_TARANTOOL_ERROR; + return -1; } char *key = mp_encode_array(key_begin, 1); key = mp_encode_str(key, trig_name, trig_name_len); if (box_index_get(BOX_TRIGGER_ID, 0, key_begin, key, &tuple) != 0) - return SQL_TARANTOOL_ERROR; + return -1; assert(tuple != NULL); assert(tuple_field_count(tuple) == 3); const char *field = tuple_field(tuple, BOX_TRIGGER_FIELD_SPACE_ID); @@ -629,8 +621,11 @@ int tarantoolsqlRenameTrigger(const char *trig_name, assert(mp_typeof(*field) == MP_MAP); mp_decode_map(&field); const char *sql_str = mp_decode_str(&field, &key_len); - if (sqlStrNICmp(sql_str, "sql", 3) != 0) - goto rename_fail; + if (sqlStrNICmp(sql_str, "sql", 3) != 0) { + diag_set(ClientError, ER_SQL_EXECUTE, "can't modify name of "\ + "space created not via SQL facilities"); + return -1; + } uint32_t trigger_stmt_len; const char *trigger_stmt_old = mp_decode_str(&field, &trigger_stmt_len); char *trigger_stmt = (char*)region_alloc(&fiber()->gc, @@ -638,7 +633,7 @@ int tarantoolsqlRenameTrigger(const char *trig_name, if (trigger_stmt == NULL) { diag_set(OutOfMemory, trigger_stmt_len + 1, "region_alloc", "trigger_stmt"); - return SQL_TARANTOOL_ERROR; + return -1; } memcpy(trigger_stmt, trigger_stmt_old, trigger_stmt_len); trigger_stmt[trigger_stmt_len] = '\0'; @@ -655,7 +650,7 @@ int tarantoolsqlRenameTrigger(const char *trig_name, char *new_tuple = (char*)region_alloc(&fiber()->gc, key_len); if (new_tuple == NULL) { diag_set(OutOfMemory, key_len, "region_alloc", "new_tuple"); - return SQL_TARANTOOL_ERROR; + return -1; } char *new_tuple_end = mp_encode_array(new_tuple, 3); new_tuple_end = mp_encode_str(new_tuple_end, trig_name, trig_name_len); @@ -665,15 +660,7 @@ int tarantoolsqlRenameTrigger(const char *trig_name, new_tuple_end = mp_encode_str(new_tuple_end, trigger_stmt, trigger_stmt_new_len); - if (box_replace(BOX_TRIGGER_ID, new_tuple, new_tuple_end, NULL) != 0) - return SQL_TARANTOOL_ERROR; - else - return 0; - -rename_fail: - diag_set(ClientError, ER_SQL_EXECUTE, "can't modify name of space " - "created not via SQL facilities"); - return SQL_TARANTOOL_ERROR; + return box_replace(BOX_TRIGGER_ID, new_tuple, new_tuple_end, NULL); } int @@ -688,7 +675,7 @@ sql_rename_table(uint32_t space_id, const char *new_name) char *raw = (char *) region_alloc(region, size); if (raw == NULL) { diag_set(OutOfMemory, size, "region_alloc", "raw"); - return SQL_TARANTOOL_ERROR; + return -1; } /* Encode key. */ char *pos = mp_encode_array(raw, 1); @@ -701,9 +688,7 @@ sql_rename_table(uint32_t space_id, const char *new_name) pos = mp_encode_str(pos, "=", 1); pos = mp_encode_uint(pos, BOX_SPACE_FIELD_NAME); pos = mp_encode_str(pos, new_name, name_len); - if (box_update(BOX_SPACE_ID, 0, raw, ops, ops, pos, 0, NULL) != 0) - return SQL_TARANTOOL_ERROR; - return 0; + return box_update(BOX_SPACE_ID, 0, raw, ops, ops, pos, 0, NULL); } int @@ -827,7 +812,7 @@ tarantoolsqlIncrementMaxid(uint64_t *space_max_id) request.space_id = space_schema->def->id; if (box_process_rw(&request, space_schema, &res) != 0 || res == NULL || tuple_field_u64(res, 1, space_max_id) != 0) - return SQL_TARANTOOL_ERROR; + return -1; return 0; } @@ -873,7 +858,7 @@ key_alloc(BtCursor *cur, size_t key_size) * @param key Start of buffer containing key. * @param key_end End of buffer containing key. * - * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, -1 otherwise. */ static int cursor_seek(BtCursor *pCur, int *pRes) @@ -887,13 +872,13 @@ cursor_seek(BtCursor *pCur, int *pRes) uint32_t part_count = mp_decode_array(&key); if (key_validate(pCur->index->def, pCur->iter_type, key, part_count)) { diag_log(); - return SQL_TARANTOOL_ERROR; + return -1; } struct space *space = pCur->space; struct txn *txn = NULL; if (space->def->id != 0 && txn_begin_ro_stmt(space, &txn) != 0) - return SQL_TARANTOOL_ERROR; + return -1; struct iterator *it = index_create_iterator(pCur->index, pCur->iter_type, key, part_count); @@ -901,7 +886,7 @@ cursor_seek(BtCursor *pCur, int *pRes) if (txn != NULL) txn_rollback_stmt(); pCur->eState = CURSOR_INVALID; - return SQL_TARANTOOL_ERROR; + return -1; } if (txn != NULL) txn_commit_ro_stmt(txn); @@ -919,7 +904,7 @@ cursor_seek(BtCursor *pCur, int *pRes) * @param pCur Cursor which contains space and tuple. * @param[out] pRes Flag which is 0 if reached end of space, 1 otherwise. * - * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, -1 otherwise. */ static int cursor_advance(BtCursor *pCur, int *pRes) @@ -928,7 +913,7 @@ cursor_advance(BtCursor *pCur, int *pRes) struct tuple *tuple; if (iterator_next(pCur->iter, &tuple) != 0) - return SQL_TARANTOOL_ERROR; + return -1; if (pCur->last_tuple) box_tuple_unref(pCur->last_tuple); if (tuple) { diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index 372426e..05d3cdd 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -1691,7 +1691,7 @@ sql_analysis_load(struct sql *db) assert(stat_space != NULL); ssize_t index_count = box_index_len(stat_space->def->id, 0); if (index_count < 0) - return SQL_TARANTOOL_ERROR; + return -1; if (box_txn_begin() != 0) goto fail; size_t stats_size = index_count * sizeof(struct index_stat); @@ -1771,9 +1771,9 @@ sql_analysis_load(struct sql *db) if (load_stat_to_index(db, order_query, heap_stats) != 0) goto fail; if (box_txn_commit() != 0) - return SQL_TARANTOOL_ERROR; + return -1; return 0; fail: box_txn_rollback(); - return SQL_TARANTOOL_ERROR; + return -1; } diff --git a/src/box/sql/build.c b/src/box/sql/build.c index a0d0088..bbcc95f 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -139,7 +139,7 @@ sql_finish_coding(struct Parse *parse_context) sqlVdbeChangeP2(v, record->insertion_opcode, v->nOp); } - sqlVdbeAddOp1(v, OP_Halt, SQL_TARANTOOL_ERROR); + sqlVdbeAddOp1(v, OP_Halt, -1); VdbeComment((v, "Exit with an error if CREATE statement fails")); } @@ -3085,8 +3085,7 @@ vdbe_emit_halt_with_presence_test(struct Parse *parser, int space_id, if (no_error) { sqlVdbeAddOp0(v, OP_Halt); } else { - sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR,0, 0, error, - P4_DYNAMIC); + sqlVdbeAddOp4(v, OP_Halt, -1, 0, 0, error, P4_DYNAMIC); sqlVdbeChangeP5(v, tarantool_error_code); } sqlVdbeAddOp1(v, OP_Close, cursor); diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index bc73fd4..fa625cf 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -4386,7 +4386,7 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) ON_CONFLICT_ACTION_IGNORE, 0, pExpr->u.zToken, 0); } else { - sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, + sqlVdbeAddOp4(v, OP_Halt, -1, pExpr->on_conflict_action, 0, pExpr->u.zToken, 0); sqlVdbeChangeP5(v, ER_SQL_EXECUTE); diff --git a/src/box/sql/fk_constraint.c b/src/box/sql/fk_constraint.c index 542709a..03864ae 100644 --- a/src/box/sql/fk_constraint.c +++ b/src/box/sql/fk_constraint.c @@ -287,7 +287,7 @@ fk_constraint_lookup_parent(struct Parse *parse_context, struct space *parent, * transaction. */ assert(incr_count == 1); - sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0, 0, "FOREIGN "\ + sqlVdbeAddOp4(v, OP_Halt, -1, 0, 0, "FOREIGN "\ "KEY constraint failed", P4_STATIC); sqlVdbeChangeP5(v, ER_SQL_EXECUTE); } else { diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index b9cd8fc..9fe19fe 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -902,7 +902,7 @@ vdbe_emit_constraint_checks(struct Parse *parse_context, struct space *space, case ON_CONFLICT_ACTION_FAIL: err = tt_sprintf("NOT NULL constraint failed: %s.%s", def->name, def->fields[i].name); - sqlVdbeAddOp4(v, OP_HaltIfNull, SQL_TARANTOOL_ERROR, + sqlVdbeAddOp4(v, OP_HaltIfNull, -1, on_conflict_nullable, new_tuple_reg + i, err, P4_STATIC); sqlVdbeChangeP5(v, ER_SQL_EXECUTE); @@ -951,7 +951,7 @@ vdbe_emit_constraint_checks(struct Parse *parse_context, struct space *space, const char *err = tt_sprintf("CHECK constraint failed: "\ "%s", name); - sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, + sqlVdbeAddOp4(v, OP_Halt, -1, on_conflict_check, 0, err, P4_STATIC); sqlVdbeChangeP5(v, ER_SQL_EXECUTE); diff --git a/src/box/sql/main.c b/src/box/sql/main.c index e6d3a3d..76d464f 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -258,7 +258,7 @@ sqlCreateFunc(sql * db, (255 < (sqlStrlen30(zFunctionName)))) { diag_set(ClientError, ER_CREATE_FUNCTION, zFunctionName, "wrong function definition"); - return SQL_TARANTOOL_ERROR; + return -1; } assert(SQL_FUNC_CONSTANT == SQL_DETERMINISTIC); @@ -276,7 +276,7 @@ sqlCreateFunc(sql * db, diag_set(ClientError, ER_CREATE_FUNCTION, zFunctionName, "unable to create function due to active "\ "statements"); - return SQL_TARANTOOL_ERROR; + return -1; } else { sqlExpirePreparedStatements(db); } @@ -285,7 +285,7 @@ sqlCreateFunc(sql * db, p = sqlFindFunction(db, zFunctionName, nArg, 1); assert(p || db->mallocFailed); if (p == NULL) - return SQL_TARANTOOL_ERROR; + return -1; /* If an older version of the function with a configured destructor is * being replaced invoke the destructor function here. diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c index 61081fb..61f6493 100644 --- a/src/box/sql/prepare.c +++ b/src/box/sql/prepare.c @@ -83,7 +83,7 @@ sqlPrepare(sql * db, /* Database handle. */ if (nBytes > mxLen) { diag_set(ClientError, ER_SQL_PARSER_LIMIT, "SQL command length", nBytes, mxLen); - rc = SQL_TARANTOOL_ERROR; + rc = -1; goto end_prepare; } zSqlCopy = sqlDbStrNDup(db, zSql, nBytes); @@ -105,7 +105,7 @@ sqlPrepare(sql * db, /* Database handle. */ *pzTail = sParse.zTail; } if (sParse.is_aborted) - rc = SQL_TARANTOOL_ERROR; + rc = -1; if (rc == 0 && sParse.pVdbe && sParse.explain) { static const char *const azColName[] = { diff --git a/src/box/sql/select.c b/src/box/sql/select.c index 4bb8c58..3576b71 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -2110,11 +2110,8 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak) "Only positive integers are allowed " "in the LIMIT clause"; sqlVdbeResolveLabel(v, halt_label); - sqlVdbeAddOp4(v, OP_Halt, - SQL_TARANTOOL_ERROR, - 0, 0, - wrong_limit_error, - P4_STATIC); + sqlVdbeAddOp4(v, OP_Halt, -1, 0, 0, wrong_limit_error, + P4_STATIC); sqlVdbeChangeP5(v, ER_SQL_EXECUTE); sqlVdbeResolveLabel(v, positive_limit_label); @@ -2144,9 +2141,8 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak) sqlVdbeAddOp3(v, OP_Eq, iLimit, no_err, r1); const char *error = "Expression subquery could " "be limited only with 1"; - sqlVdbeAddOp4(v, OP_Halt, - SQL_TARANTOOL_ERROR, - 0, 0, error, P4_STATIC); + sqlVdbeAddOp4(v, OP_Halt, -1, 0, 0, error, + P4_STATIC); sqlVdbeChangeP5(v, ER_SQL_EXECUTE); sqlVdbeResolveLabel(v, no_err); sqlReleaseTempReg(pParse, r1); @@ -2172,11 +2168,8 @@ computeLimitRegisters(Parse * pParse, Select * p, int iBreak) "Only positive integers are allowed " "in the OFFSET clause"; sqlVdbeResolveLabel(v, offset_error_label); - sqlVdbeAddOp4(v, OP_Halt, - SQL_TARANTOOL_ERROR, - 0, 0, - wrong_offset_error, - P4_STATIC); + sqlVdbeAddOp4(v, OP_Halt, -1, 0, 0, wrong_offset_error, + P4_STATIC); sqlVdbeChangeP5(v, ER_SQL_EXECUTE); sqlVdbeResolveLabel(v, positive_offset_label); @@ -5447,7 +5440,7 @@ vdbe_code_raise_on_multiple_rows(struct Parse *parser, int limit_reg, int end_ma sqlVdbeAddOp2(v, OP_Integer, 0, r1); sqlVdbeAddOp3(v, OP_Ne, r1, end_mark, limit_reg); const char *error = "Expression subquery returned more than 1 row"; - sqlVdbeAddOp4(v, OP_Halt, SQL_TARANTOOL_ERROR, 0, 0, error, P4_STATIC); + sqlVdbeAddOp4(v, OP_Halt, -1, 0, 0, error, P4_STATIC); sqlVdbeChangeP5(v, ER_SQL_EXECUTE); sqlReleaseTempReg(parser, r1); } diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 76ac057..50a577b 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -356,12 +356,10 @@ struct sql_vfs { #define SQL_LIMIT_WORKER_THREADS 10 enum sql_ret_code { - /** Abort due to constraint violation. */ - SQL_TARANTOOL_ERROR = 4, /** sql_step() has another row ready. */ - SQL_ROW, + SQL_ROW = 1, /** sql_step() has finished executing. */ - SQL_DONE, + SQL_DONE = 2, }; void * diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h index e7e6ff2..c959012 100644 --- a/src/box/sql/tarantoolInt.h +++ b/src/box/sql/tarantoolInt.h @@ -46,7 +46,7 @@ int tarantoolsqlDelete(BtCursor * pCur, u8 flags); * @param key Key of record to be deleted. * @param key_size Size of key. * - * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, -1 otherwise. */ int sql_delete_by_key(struct space *space, uint32_t iid, char *key, @@ -59,7 +59,7 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count); * @param space_id Table's space identifier. * @param new_name new name of table * - * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, -1 otherwise. */ int sql_rename_table(uint32_t space_id, const char *new_name); @@ -92,7 +92,7 @@ sql_ephemeral_space_create(uint32_t filed_count, struct sql_key_info *key_info); * @param tuple Tuple to be inserted. * @param tuple_end End of tuple to be inserted. * - * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, -1 otherwise. */ int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple, const char *tuple_end); diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index b676a22..237daef 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -921,15 +921,8 @@ case OP_HaltIfNull: { /* in3 */ * * If P4 is not null then it is an error message string. * - * If P1 is SQL_TARANTOOL_ERROR then P5 is a ClientError code and - * P4 is error message to set. Else P5 is a value between 0 and 4, - * inclusive, that modifies the P4 string. - * - * 0: (no change) - * 1: NOT NULL contraint failed: P4 - * 2: UNIQUE constraint failed: P4 - * 3: CHECK constraint failed: P4 - * 4: FOREIGN KEY constraint failed: P4 + * If P1 is -1 then P5 is a ClientError code and + * P4 is error message to set. * * If P5 is not zero and P4 is NULL, then everything after the * ":" is omitted. @@ -969,14 +962,12 @@ case OP_Halt: { p->errorAction = (u8)pOp->p2; p->pc = pcx; if (p->rc) { - assert(p->rc == SQL_TARANTOOL_ERROR); if (pOp->p4.z != NULL) diag_set(ClientError, pOp->p5, pOp->p4.z); assert(! diag_is_empty(diag_get())); } - rc = sqlVdbeHalt(p); - assert(rc == 0 || rc == -1); - rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE; + sqlVdbeHalt(p); + rc = p->rc ? -1 : SQL_DONE; goto vdbe_return; } @@ -3619,7 +3610,6 @@ case OP_Found: { /* jump, in3 */ rc = sqlCursorMovetoUnpacked(pC->uc.pCursor, pIdxKey, &res); if (pFree != NULL) sqlDbFree(db, pFree); - assert(rc == 0 || rc == SQL_TARANTOOL_ERROR); if (rc != 0) goto abort_due_to_error; pC->seekResult = res; @@ -3837,8 +3827,7 @@ case OP_SorterCompare: { pIn3 = &aMem[pOp->p3]; nKeyCol = pOp->p4.i; res = 0; - if (sqlVdbeSorterCompare(pC, pIn3, nKeyCol, &res) != 0) - rc = SQL_TARANTOOL_ERROR; + rc = sqlVdbeSorterCompare(pC, pIn3, nKeyCol, &res); VdbeBranchTaken(res!=0,2); if (rc) goto abort_due_to_error; if (res) goto jump_to_p2; @@ -4076,8 +4065,7 @@ case OP_Rewind: { /* jump */ assert(pC->eCurType==CURTYPE_TARANTOOL); pCrsr = pC->uc.pCursor; assert(pCrsr); - if (tarantoolsqlFirst(pCrsr, &res) != 0) - rc = SQL_TARANTOOL_ERROR; + rc = tarantoolsqlFirst(pCrsr, &res); pC->cacheStatus = CACHE_STALE; if (rc != 0) goto abort_due_to_error; @@ -4292,7 +4280,6 @@ case OP_IdxInsert: { } else if (pOp->p5 & OPFLAG_OE_ROLLBACK) { p->errorAction = ON_CONFLICT_ACTION_ROLLBACK; } - assert(rc == 0 || rc == SQL_TARANTOOL_ERROR); if (rc != 0) goto abort_due_to_error; break; @@ -4370,9 +4357,8 @@ case OP_Update: { } assert(rc == 0); - if (box_update(space->def->id, 0, key_mem->z, key_mem->z + key_mem->n, - ops, ops + ops_size, 0, NULL) != 0) - rc = SQL_TARANTOOL_ERROR; + rc = box_update(space->def->id, 0, key_mem->z, key_mem->z + key_mem->n, + ops, ops + ops_size, 0, NULL); if (pOp->p5 & OPFLAG_OE_IGNORE) { /* @@ -4391,7 +4377,6 @@ case OP_Update: { } else if (pOp->p5 & OPFLAG_OE_ROLLBACK) { p->errorAction = ON_CONFLICT_ACTION_ROLLBACK; } - assert(rc == 0 || rc == SQL_TARANTOOL_ERROR); if (rc != 0) goto abort_due_to_error; break; @@ -5181,7 +5166,7 @@ case OP_Init: { /* jump */ */ if (p->pFrame == NULL && sql_vdbe_prepare(p) != 0) { sqlDbFree(db, p); - rc = SQL_TARANTOOL_ERROR; + rc = -1; break; } @@ -5288,7 +5273,7 @@ default: { /* This is really OP_Noop and OP_Explain */ * an error of some kind. */ abort_due_to_error: - rc = SQL_TARANTOOL_ERROR; + rc = -1; p->rc = rc; /* This is the only way out of this procedure. */ @@ -5298,8 +5283,7 @@ vdbe_return: assert(rc!=0 || nExtraDelete==0 || sql_strlike_ci("DELETE%", p->zSql, 0) != 0 ); - assert(rc == 0 || rc == SQL_TARANTOOL_ERROR || - rc == SQL_ROW || rc == SQL_DONE); + assert(rc == 0 || rc == -1 || rc == SQL_ROW || rc == SQL_DONE); return rc; /* Jump to here if a string or blob larger than SQL_MAX_LENGTH diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 150ff7b..f1897e2 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -307,7 +307,7 @@ invokeValueDestructor(const void *p, /* Value to destroy */ "big"); pCtx->is_aborted = true; } - return SQL_TARANTOOL_ERROR; + return -1; } void @@ -404,7 +404,7 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n) if (n > (u64) pOut->db->aLimit[SQL_LIMIT_LENGTH]) { diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\ "big"); - return SQL_TARANTOOL_ERROR; + return -1; } sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n); return 0; @@ -437,8 +437,8 @@ sqlStep(Vdbe * p) } if (p->pc <= 0 && p->expired) { - p->rc = SQL_TARANTOOL_ERROR; - return SQL_TARANTOOL_ERROR; + p->rc = -1; + return -1; } if (p->pc < 0) { @@ -1142,7 +1142,7 @@ sql_bind_zeroblob64(sql_stmt * pStmt, int i, sql_uint64 n) if (n > (u64) p->db->aLimit[SQL_LIMIT_LENGTH]) { diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\ "big"); - rc = SQL_TARANTOOL_ERROR; + rc = -1; } else { assert((n & 0x7FFFFFFF) == n); rc = sql_bind_zeroblob(pStmt, i, n); diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index 8e2ca35..d4ba3a3 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -2079,7 +2079,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp) * violations, return -1. Otherwise, 0. * * If there are outstanding FK violations and this function returns - * SQL_TARANTOOL_ERROR and set an error. + * -1 and set an error. */ int sqlVdbeCheckFk(Vdbe * p, int deferred) @@ -2088,11 +2088,11 @@ sqlVdbeCheckFk(Vdbe * p, int deferred) if ((deferred && txn != NULL && txn->psql_txn != NULL && txn->psql_txn->fk_deferred_count > 0) || (!deferred && p->nFkConstraint > 0)) { - p->rc = SQL_TARANTOOL_ERROR; + p->rc = -1; p->errorAction = ON_CONFLICT_ACTION_ABORT; diag_set(ClientError, ER_SQL_EXECUTE, "FOREIGN KEY constraint "\ "failed"); - return SQL_TARANTOOL_ERROR; + return -1; } return 0; } @@ -2210,7 +2210,7 @@ sqlVdbeHalt(Vdbe * p) */ rc = (in_txn() == NULL || txn_commit(in_txn()) == 0) ? - 0 : SQL_TARANTOOL_ERROR; + 0 : -1; closeCursorsAndFree(p); } if (rc != 0) { diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index 2b9e516..a4596d7 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -981,7 +981,7 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */ if (nByte > iLimit) { diag_set(ClientError, ER_SQL_EXECUTE, "string or blob "\ "is too big"); - return SQL_TARANTOOL_ERROR; + return -1; } testcase(nAlloc == 0); testcase(nAlloc == 31); @@ -1007,7 +1007,7 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */ if (nByte > iLimit) { diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\ "big"); - return SQL_TARANTOOL_ERROR; + return -1; } return 0; diff --git a/src/box/sql/where.c b/src/box/sql/where.c index 11c531c..15beb31 100644 --- a/src/box/sql/where.c +++ b/src/box/sql/where.c @@ -2781,7 +2781,7 @@ whereLoopAddBtree(WhereLoopBuilder * pBuilder, /* WHERE clause information */ if (key_def == NULL) { tnt_error: pWInfo->pParse->is_aborted = true; - return SQL_TARANTOOL_ERROR; + return -1; } struct index_opts opts; -- 2.7.4