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 F160A2FD87 for ; Sat, 25 May 2019 06:44:37 -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 avKNfskwKAGg for ; Sat, 25 May 2019 06:44:37 -0400 (EDT) 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 DE18321CFA for ; Sat, 25 May 2019 06:44:36 -0400 (EDT) From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v1 03/21] sql: remove SQL_OK error/status code Date: Sat, 25 May 2019 13:44:34 +0300 Message-Id: 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/status code is part of getting rid of the SQL error system. --- src/box/bind.c | 2 +- src/box/execute.c | 6 +- src/box/sql.c | 44 +++++----- src/box/sql/analyze.c | 6 +- src/box/sql/cursor.c | 4 +- src/box/sql/date.c | 10 +-- src/box/sql/expr.c | 2 +- src/box/sql/func.c | 6 +- src/box/sql/insert.c | 2 +- src/box/sql/legacy.c | 10 +-- src/box/sql/main.c | 26 +++--- src/box/sql/os.c | 10 +-- src/box/sql/os_unix.c | 96 ++++++++++----------- src/box/sql/prepare.c | 16 ++-- src/box/sql/select.c | 26 +++--- src/box/sql/sqlInt.h | 4 +- src/box/sql/status.c | 4 +- src/box/sql/tarantoolInt.h | 4 +- src/box/sql/trigger.c | 2 +- src/box/sql/vdbe.c | 106 +++++++++++------------ src/box/sql/vdbeapi.c | 38 ++++---- src/box/sql/vdbeaux.c | 50 +++++------ src/box/sql/vdbemem.c | 76 ++++++++-------- src/box/sql/vdbesort.c | 210 ++++++++++++++++++++++----------------------- src/box/sql/where.c | 74 ++++++++-------- 25 files changed, 416 insertions(+), 418 deletions(-) diff --git a/src/box/bind.c b/src/box/bind.c index f159153..90d56d6 100644 --- a/src/box/bind.c +++ b/src/box/bind.c @@ -205,7 +205,7 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p, default: unreachable(); } - if (rc == SQL_OK) + if (rc == 0) return 0; switch (rc) { diff --git a/src/box/execute.c b/src/box/execute.c index e81cc32..64ed3d4 100644 --- a/src/box/execute.c +++ b/src/box/execute.c @@ -420,11 +420,11 @@ sql_execute(struct sql_stmt *stmt, struct port *port, struct region *region) port) != 0) return -1; } - assert(rc == SQL_DONE || rc != SQL_OK); + assert(rc == SQL_DONE || rc != 0); } else { /* No rows. Either DONE or ERROR. */ rc = sql_step(stmt); - assert(rc != SQL_ROW && rc != SQL_OK); + assert(rc != SQL_ROW && rc != 0); } if (rc != SQL_DONE) return -1; @@ -438,7 +438,7 @@ sql_prepare_and_execute(const char *sql, int len, const struct sql_bind *bind, { struct sql_stmt *stmt; struct sql *db = sql_get(); - if (sql_prepare_v2(db, sql, len, &stmt, NULL) != SQL_OK) + if (sql_prepare_v2(db, sql, len, &stmt, NULL) != 0) return -1; assert(stmt != NULL); port_sql_create(port, stmt); diff --git a/src/box/sql.c b/src/box/sql.c index 34e11bf..84e7d9c 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -71,7 +71,7 @@ sql_init() current_session()->sql_flags |= default_sql_flags; - if (sql_init_db(&db) != SQL_OK) + if (sql_init_db(&db) != 0) panic("failed to initialize SQL subsystem"); assert(db != NULL); @@ -86,7 +86,7 @@ sql_load_schema() if (stat->def->field_count == 0) return; db->init.busy = 1; - if (sql_analysis_load(db) != SQL_OK) { + if (sql_analysis_load(db) != 0) { if(!diag_is_empty(&fiber()->diag)) { diag_log(); } @@ -218,7 +218,7 @@ int tarantoolsqlNext(BtCursor *pCur, int *pRes) { if (pCur->eState == CURSOR_INVALID) { *pRes = 1; - return SQL_OK; + return 0; } assert(iterator_direction(pCur->iter_type) > 0); return cursor_advance(pCur, pRes); @@ -233,7 +233,7 @@ int tarantoolsqlPrevious(BtCursor *pCur, int *pRes) { if (pCur->eState == CURSOR_INVALID) { *pRes = 1; - return SQL_OK; + return 0; } assert(iterator_direction(pCur->iter_type) < 0); return cursor_advance(pCur, pRes); @@ -316,7 +316,7 @@ int tarantoolsqlMovetoUnpacked(BtCursor *pCur, UnpackedRecord *pIdxKey, * @param pCur Cursor which will point to ephemeral space. * @param[out] pnEntry Number of tuples in ephemeral space. * - * @retval SQL_OK + * @retval 0 */ int tarantoolsqlEphemeralCount(struct BtCursor *pCur, i64 *pnEntry) { @@ -324,7 +324,7 @@ int tarantoolsqlEphemeralCount(struct BtCursor *pCur, i64 *pnEntry) struct index *primary_index = space_index(pCur->space, 0 /* PK */); *pnEntry = index_count(primary_index, pCur->iter_type, NULL, 0); - return SQL_OK; + return 0; } int tarantoolsqlCount(BtCursor *pCur, i64 *pnEntry) @@ -332,7 +332,7 @@ int tarantoolsqlCount(BtCursor *pCur, i64 *pnEntry) assert(pCur->curFlags & BTCF_TaCursor); *pnEntry = index_count(pCur->index, pCur->iter_type, NULL, 0); - return SQL_OK; + return 0; } struct space * @@ -406,7 +406,7 @@ int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple, mp_tuple_assert(tuple, tuple_end); if (space_ephemeral_replace(space, tuple, tuple_end) != 0) return SQL_TARANTOOL_ERROR; - return SQL_OK; + return 0; } /* Simply delete ephemeral space by calling space_delete(). */ @@ -416,7 +416,7 @@ int tarantoolsqlEphemeralDrop(BtCursor *pCur) assert(pCur->curFlags & BTCF_TEphemCursor); space_delete(pCur->space); pCur->space = NULL; - return SQL_OK; + return 0; } static inline int @@ -432,7 +432,7 @@ insertOrReplace(struct space *space, const char *tuple, const char *tuple_end, request.type = type; mp_tuple_assert(request.tuple, request.tuple_end); int rc = box_process_rw(&request, space, NULL); - return rc == 0 ? SQL_OK : SQL_TARANTOOL_ERROR; + return rc == 0 ? 0 : SQL_TARANTOOL_ERROR; } int tarantoolsqlInsert(struct space *space, const char *tuple, @@ -453,7 +453,7 @@ int tarantoolsqlReplace(struct space *space, const char *tuple, * * @param pCur Cursor pointing to ephemeral space. * - * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. */ int tarantoolsqlEphemeralDelete(BtCursor *pCur) { @@ -474,7 +474,7 @@ int tarantoolsqlEphemeralDelete(BtCursor *pCur) diag_log(); return SQL_TARANTOOL_ERROR; } - return SQL_OK; + return 0; } int tarantoolsqlDelete(BtCursor *pCur, u8 flags) @@ -497,7 +497,7 @@ int tarantoolsqlDelete(BtCursor *pCur, u8 flags) rc = sql_delete_by_key(pCur->space, pCur->index->def->iid, key, key_size); - return rc == 0 ? SQL_OK : SQL_TARANTOOL_ERROR; + return rc == 0 ? 0 : SQL_TARANTOOL_ERROR; } int @@ -515,7 +515,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key, assert(space_index(space, iid)->def->opts.is_unique); int rc = box_process_rw(&request, space, &unused); - return rc == 0 ? SQL_OK : SQL_TARANTOOL_ERROR; + return rc == 0 ? 0 : SQL_TARANTOOL_ERROR; } /* @@ -525,7 +525,7 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key, * * @param pCur Cursor pointing to ephemeral space. * - * @retval SQL_OK on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. */ int tarantoolsqlEphemeralClearTable(BtCursor *pCur) { @@ -554,7 +554,7 @@ int tarantoolsqlEphemeralClearTable(BtCursor *pCur) } iterator_delete(it); - return SQL_OK; + return 0; } /* @@ -590,7 +590,7 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count) } iterator_delete(iter); - return SQL_OK; + return 0; } /* @@ -668,7 +668,7 @@ int tarantoolsqlRenameTrigger(const char *trig_name, if (box_replace(BOX_TRIGGER_ID, new_tuple, new_tuple_end, NULL) != 0) return SQL_TARANTOOL_ERROR; else - return SQL_OK; + return 0; rename_fail: diag_set(ClientError, ER_SQL_EXECUTE, "can't modify name of space " @@ -828,7 +828,7 @@ tarantoolsqlIncrementMaxid(uint64_t *space_max_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 SQL_OK; + return 0; } /* @@ -873,7 +873,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 SQL_OK on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. */ static int cursor_seek(BtCursor *pCur, int *pRes) @@ -919,7 +919,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 SQL_OK on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. */ static int cursor_advance(BtCursor *pCur, int *pRes) @@ -939,7 +939,7 @@ cursor_advance(BtCursor *pCur, int *pRes) *pRes = 1; } pCur->last_tuple = tuple; - return SQL_OK; + return 0; } /********************************************************************* diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index 9795429..372426e 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -1518,7 +1518,7 @@ load_stat_from_space(struct sql *db, const char *sql_select_prepare, stats[current_idx_count].sample_count++; } rc = sql_finalize(stmt); - if (rc == SQL_OK && prev_index != NULL) + if (rc == 0 && prev_index != NULL) init_avg_eq(prev_index, &stats[current_idx_count]); assert(current_idx_count <= index_count); for (uint32_t i = 0; i < current_idx_count; ++i) { @@ -1712,7 +1712,7 @@ sql_analysis_load(struct sql *db) goto fail; if (info.index_count == 0) { box_txn_commit(); - return SQL_OK; + return 0; } /* * This query is used to allocate enough memory for @@ -1772,7 +1772,7 @@ sql_analysis_load(struct sql *db) goto fail; if (box_txn_commit() != 0) return SQL_TARANTOOL_ERROR; - return SQL_OK; + return 0; fail: box_txn_rollback(); return SQL_TARANTOOL_ERROR; diff --git a/src/box/sql/cursor.c b/src/box/sql/cursor.c index 2187b90..f4b19db 100644 --- a/src/box/sql/cursor.c +++ b/src/box/sql/cursor.c @@ -94,7 +94,7 @@ sqlCursorIsValidNN(BtCursor *pCur) * For sqlCursorPayload(), the caller must ensure that pCur is pointing * to a valid row in the table. * - * Return SQL_OK on success or an error code if anything goes + * Return 0 on success or an error code if anything goes * wrong. An error is returned if "offset+amt" is larger than * the available payload. */ @@ -110,7 +110,7 @@ sqlCursorPayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf) pPayload = tarantoolsqlPayloadFetch(pCur, &sz); assert((uptr) (offset + amt) <= sz); memcpy(pBuf, pPayload + offset, amt); - return SQL_OK; + return 0; } /* Move the cursor so that it points to an entry near the key diff --git a/src/box/sql/date.c b/src/box/sql/date.c index 6d3a2b0..e193035 100644 --- a/src/box/sql/date.c +++ b/src/box/sql/date.c @@ -576,7 +576,7 @@ osLocaltime(time_t * t, struct tm *pTm) /* * Compute the difference (in milliseconds) between localtime and UTC * (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs, - * return this value and set *pRc to SQL_OK. + * return this value and set *pRc to 0. * * Or, if an error does occur, set *pRc to SQL_ERROR. The returned value * is undefined in this case. @@ -584,7 +584,7 @@ osLocaltime(time_t * t, struct tm *pTm) static sql_int64 localtimeOffset(DateTime * p, /* Date at which to calculate offset */ sql_context * pCtx, /* Write error here if one occurs */ - int *pRc /* OUT: Error code. SQL_OK or ERROR */ + int *pRc /* OUT: Error code. 0 or ERROR */ ) { DateTime x, y; @@ -635,7 +635,7 @@ localtimeOffset(DateTime * p, /* Date at which to calculate offset */ y.validTZ = 0; y.isError = 0; computeJD(&y); - *pRc = SQL_OK; + *pRc = 0; return y.iJD - x.iJD; } #endif /* SQL_OMIT_LOCALTIME */ @@ -736,7 +736,7 @@ parseModifier(sql_context * pCtx, /* Function context */ sql_int64 c1; computeJD(p); c1 = localtimeOffset(p, pCtx, &rc); - if (rc == SQL_OK) { + if (rc == 0) { p->iJD -= c1; clearYMD_HMS_TZ(p); p->iJD += @@ -746,7 +746,7 @@ parseModifier(sql_context * pCtx, /* Function context */ } p->tzSet = 1; } else { - rc = SQL_OK; + rc = 0; } } #endif diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index a4a2d71..bc73fd4 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -4382,7 +4382,7 @@ sqlExprCodeTarget(Parse * pParse, Expr * pExpr, int target) } assert(!ExprHasProperty(pExpr, EP_IntValue)); if (pExpr->on_conflict_action == ON_CONFLICT_ACTION_IGNORE) { - sqlVdbeAddOp4(v, OP_Halt, SQL_OK, + sqlVdbeAddOp4(v, OP_Halt, 0, ON_CONFLICT_ACTION_IGNORE, 0, pExpr->u.zToken, 0); } else { diff --git a/src/box/sql/func.c b/src/box/sql/func.c index 593aa94..29712e0 100644 --- a/src/box/sql/func.c +++ b/src/box/sql/func.c @@ -1191,7 +1191,7 @@ zeroblobFunc(sql_context * context, int argc, sql_value ** argv) n = sql_value_int64(argv[0]); if (n < 0) n = 0; - if (sql_result_zeroblob64(context, n) != SQL_OK) { + if (sql_result_zeroblob64(context, n) != 0) { diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big"); context->is_aborted = true; } @@ -1799,7 +1799,7 @@ static inline int sql_overload_function(sql * db, const char *zName, enum field_type type, int nArg) { - int rc = SQL_OK; + int rc = 0; if (sqlFindFunction(db, zName, nArg, 0) == 0) { rc = sqlCreateFunc(db, zName, type, nArg, 0, 0, @@ -1818,7 +1818,7 @@ void sqlRegisterPerConnectionBuiltinFunctions(sql * db) { int rc = sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2); - assert(rc == SQL_NOMEM || rc == SQL_OK); + assert(rc == SQL_NOMEM || rc == 0); if (rc == SQL_NOMEM) { sqlOomFault(db); } diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index c4878b2..b9cd8fc 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -1325,7 +1325,7 @@ xferOptimization(Parse * pParse, /* Parser context */ sqlReleaseTempReg(pParse, regTupleid); sqlReleaseTempReg(pParse, regData); if (emptyDestTest) { - sqlVdbeAddOp2(v, OP_Halt, SQL_OK, 0); + sqlVdbeAddOp2(v, OP_Halt, 0, 0); sqlVdbeJumpHere(v, emptyDestTest); sqlVdbeAddOp2(v, OP_Close, iDest, 0); return 0; diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c index 518c184..e3024f2 100644 --- a/src/box/sql/legacy.c +++ b/src/box/sql/legacy.c @@ -58,7 +58,7 @@ sql_exec(sql * db, /* The database on which the SQL executes */ ) { (void)pzErrMsg; - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ const char *zLeftover; /* Tail of unprocessed SQL */ sql_stmt *pStmt = 0; /* The current SQL statement */ char **azCols = 0; /* Names of result columns */ @@ -69,14 +69,14 @@ sql_exec(sql * db, /* The database on which the SQL executes */ if (zSql == 0) zSql = ""; - while (rc == SQL_OK && zSql[0]) { + while (rc == 0 && zSql[0]) { int nCol; char **azVals = 0; pStmt = 0; rc = sql_prepare_v2(db, zSql, -1, &pStmt, &zLeftover); - assert(rc == SQL_OK || pStmt == 0); - if (rc != SQL_OK) { + assert(rc == 0 || pStmt == 0); + if (rc != 0) { continue; } if (!pStmt) { @@ -167,7 +167,7 @@ sql_exec(sql * db, /* The database on which the SQL executes */ sqlDbFree(db, azCols); rc = sqlApiExit(db, rc); - assert(rc == SQL_OK); + assert(rc == 0); assert((rc & db->errMask) == rc); return rc; } diff --git a/src/box/sql/main.c b/src/box/sql/main.c index 29a7911..65d8de5 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -99,7 +99,7 @@ char *sql_data_directory = 0; int sql_initialize(void) { - int rc = SQL_OK; + int rc = 0; /* If the following assert() fails on some obscure processor/compiler * combination, the work-around is to set the correct pointer @@ -113,17 +113,17 @@ sql_initialize(void) * of this routine. */ if (sqlGlobalConfig.isInit) - return SQL_OK; + return 0; if (!sqlGlobalConfig.isMallocInit) sqlMallocInit(); - if (rc == SQL_OK) + if (rc == 0) sqlGlobalConfig.isMallocInit = 1; - /* If rc is not SQL_OK at this point, then the malloc + /* If rc is not 0 at this point, then the malloc * subsystem could not be initialized. */ - if (rc != SQL_OK) + if (rc != 0) return rc; /* Do the rest of the initialization @@ -144,10 +144,10 @@ sql_initialize(void) memset(&sqlBuiltinFunctions, 0, sizeof(sqlBuiltinFunctions)); sqlRegisterBuiltinFunctions(); - if (rc == SQL_OK) { + if (rc == 0) { rc = sqlOsInit(); } - if (rc == SQL_OK) { + if (rc == 0) { sqlGlobalConfig.isInit = 1; } sqlGlobalConfig.inProgress = 0; @@ -160,7 +160,7 @@ sql_initialize(void) */ #ifndef NDEBUG /* This section of code's only "output" is via assert() statements. */ - if (rc == SQL_OK) { + if (rc == 0) { u64 x = (((u64) 1) << 63) - 1; double y; assert(sizeof(x) == 8); @@ -212,7 +212,7 @@ functionDestroy(sql * db, FuncDef * p) } /* - * Rollback all database files. If tripCode is not SQL_OK, then + * Rollback all database files. If tripCode is not 0, then * any write cursors are invalidated ("tripped" - as in "tripping a circuit * breaker") and made to return tripCode if there are any further * attempts to use that cursor. Read cursors remain open and valid @@ -303,7 +303,7 @@ sqlCreateFunc(sql * db, p->pUserData = pUserData; p->nArg = (u16) nArg; p->ret_type = type; - return SQL_OK; + return 0; } int @@ -338,7 +338,7 @@ sql_create_function_v2(sql * db, rc = sqlCreateFunc(db, zFunc, type, nArg, flags, p, xSFunc, xStep, xFinal, pArg); if (pArg && pArg->nRef == 0) { - assert(rc != SQL_OK); + assert(rc != 0); xDestroy(p); sqlDbFree(db, pArg); } @@ -364,7 +364,7 @@ sql_trace_v2(sql * db, /* Trace this connection */ db->mTrace = mTrace; db->xTrace = xTrace; db->pTraceArg = pArg; - return SQL_OK; + return 0; } #endif /* SQL_OMIT_TRACE */ @@ -562,7 +562,7 @@ opendb_out: assert(db != 0 || rc == SQL_NOMEM); if (rc == SQL_NOMEM) db = NULL; - else if (rc != SQL_OK) + else if (rc != 0) db->magic = SQL_MAGIC_SICK; *out_db = db; diff --git a/src/box/sql/os.c b/src/box/sql/os.c index eb7450b..273aa6b 100644 --- a/src/box/sql/os.c +++ b/src/box/sql/os.c @@ -90,7 +90,7 @@ sqlOsFetch(MAYBE_UNUSED sql_file * id, MAYBE_UNUSED int iAmt, void **pp) { *pp = 0; - return SQL_OK; + return 0; } int @@ -98,7 +98,7 @@ sqlOsUnfetch(MAYBE_UNUSED sql_file * id, MAYBE_UNUSED i64 iOff, MAYBE_UNUSED void *p) { - return SQL_OK; + return 0; } #endif @@ -118,7 +118,7 @@ sqlOsOpen(sql_vfs * pVfs, * reaching the VFS. */ rc = pVfs->xOpen(pVfs, zPath, pFile, flags & 0x87f7f, pFlagsOut); - assert(rc == SQL_OK || pFile->pMethods == 0); + assert(rc == 0 || pFile->pMethods == 0); return rc; } @@ -164,7 +164,7 @@ sqlOsOpenMalloc(sql_vfs * pVfs, pFile = (sql_file *) sqlMallocZero(pVfs->szOsFile); if (pFile) { rc = sqlOsOpen(pVfs, zFile, pFile, flags, pOutFlags); - if (rc != SQL_OK) { + if (rc != 0) { sql_free(pFile); } else { *ppFile = pFile; @@ -261,5 +261,5 @@ sql_vfs_register(sql_vfs * pVfs, int makeDflt) vfsList->pNext = pVfs; } assert(vfsList); - return SQL_OK; + return 0; } diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c index 615d539..fd9576e 100644 --- a/src/box/sql/os_unix.c +++ b/src/box/sql/os_unix.c @@ -486,7 +486,7 @@ findInodeInfo(unixFile * pFile, /* Unix file with file desc used in the key */ pInode->nRef++; } *ppInode = pInode; - return SQL_OK; + return 0; } /* @@ -625,13 +625,13 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock) unixFile *pFile = (unixFile *) id; unixInodeInfo *pInode; struct flock lock; - int rc = SQL_OK; + int rc = 0; assert(pFile); assert(eFileLock <= SHARED_LOCK); if (pFile->eFileLock <= eFileLock) { - return SQL_OK; + return 0; } pInode = pFile->pInode; assert(pInode->nShared != 0); @@ -714,7 +714,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock) } end_unlock: - if (rc == SQL_OK) + if (rc == 0) pFile->eFileLock = eFileLock; return rc; } @@ -755,7 +755,7 @@ closeUnixFile(sql_file * id) } sql_free(pFile->pUnused); memset(pFile, 0, sizeof(unixFile)); - return SQL_OK; + return 0; } /* @@ -862,7 +862,7 @@ seekAndRead(unixFile * id, sql_int64 offset, void *pBuf, int cnt) } /* - * Read data from a file into a buffer. Return SQL_OK if all + * Read data from a file into a buffer. Return 0 if all * bytes were read successfully and SQL_IOERR if anything goes * wrong. */ @@ -883,7 +883,7 @@ unixRead(sql_file * id, void *pBuf, int amt, sql_int64 offset) if (offset + amt <= pFile->mmapSize) { memcpy(pBuf, &((u8 *) (pFile->pMapRegion))[offset], amt); - return SQL_OK; + return 0; } else { int nCopy = pFile->mmapSize - offset; memcpy(pBuf, &((u8 *) (pFile->pMapRegion))[offset], @@ -897,7 +897,7 @@ unixRead(sql_file * id, void *pBuf, int amt, sql_int64 offset) got = seekAndRead(pFile, offset, pBuf, amt); if (got == amt) { - return SQL_OK; + return 0; } else if (got < 0) { /* lastErrno set by seekAndRead */ return SQL_IOERR_READ; @@ -958,7 +958,7 @@ seekAndWrite(unixFile * id, i64 offset, const void *pBuf, int cnt) } /* - * Write data from a buffer into a file. Return SQL_OK on success + * Write data from a buffer into a file. Return 0 on success * or some other error code on failure. */ static int @@ -986,13 +986,13 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset) } } - return SQL_OK; + return 0; } /* * Open a file descriptor to the directory containing file zFilename. * If successful, *pFd is set to the opened file descriptor and - * SQL_OK is returned. If an error occurs, either SQL_NOMEM + * 0 is returned. If an error occurs, either SQL_NOMEM * or SQL_CANTOPEN is returned and *pFd is set to an undefined * value. * @@ -1006,10 +1006,10 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset) * chromium sandbox. Opening a directory is a security risk (we are * told) so making it overrideable allows the chromium sandbox to * replace this routine with a harmless no-op. To make this routine - * a no-op, replace it with a stub that returns SQL_OK but leaves + * a no-op, replace it with a stub that returns 0 but leaves * *pFd set to a negative number. * - * If SQL_OK is returned, the caller is responsible for closing + * If 0 is returned, the caller is responsible for closing * the file descriptor *pFd using close(). */ static int @@ -1032,7 +1032,7 @@ openDirectory(const char *zFilename, int *pFd) *pFd = fd; if (fd >= 0) - return SQL_OK; + return 0; return unixLogError(SQL_CANTOPEN, "openDirectory", zDirname); } @@ -1087,7 +1087,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte) return rc; } - return SQL_OK; + return 0; } /* Forward declaration */ @@ -1103,15 +1103,15 @@ unixFileControl(sql_file * id, int op, void *pArg) switch (op) { case SQL_FCNTL_LOCKSTATE:{ *(int *)pArg = pFile->eFileLock; - return SQL_OK; + return 0; } case SQL_FCNTL_LAST_ERRNO:{ *(int *)pArg = pFile->lastErrno; - return SQL_OK; + return 0; } case SQL_FCNTL_CHUNK_SIZE:{ pFile->szChunk = *(int *)pArg; - return SQL_OK; + return 0; } case SQL_FCNTL_SIZE_HINT:{ int rc; @@ -1121,7 +1121,7 @@ unixFileControl(sql_file * id, int op, void *pArg) case SQL_FCNTL_VFSNAME:{ *(char **)pArg = sql_mprintf("%s", pFile->pVfs->zName); - return SQL_OK; + return 0; } case SQL_FCNTL_TEMPFILENAME:{ char *zTFile = @@ -1131,15 +1131,15 @@ unixFileControl(sql_file * id, int op, void *pArg) zTFile); *(char **)pArg = zTFile; } - return SQL_OK; + return 0; } case SQL_FCNTL_HAS_MOVED:{ *(int *)pArg = fileHasMoved(pFile); - return SQL_OK; + return 0; } case SQL_FCNTL_MMAP_SIZE:{ i64 newLimit = *(i64 *) pArg; - int rc = SQL_OK; + int rc = 0; if (newLimit > sqlGlobalConfig.mxMmap) { newLimit = sqlGlobalConfig.mxMmap; } @@ -1241,7 +1241,7 @@ unixRemapfile(unixFile * pFd, /* File descriptor object */ if (pNew == MAP_FAILED) { pNew = 0; nNew = 0; - unixLogError(SQL_OK, zErr, pFd->zPath); + unixLogError(0, zErr, pFd->zPath); /* If the mmap() above failed, assume that all subsequent mmap() calls * will probably fail too. Fall back to using xRead/xWrite exclusively @@ -1265,7 +1265,7 @@ unixRemapfile(unixFile * pFd, /* File descriptor object */ * created mapping is either the requested size or the value configured * using SQL_FCNTL_MMAP_LIMIT, whichever is smaller. * - * SQL_OK is returned if no error occurs (even if the mapping is not + * 0 is returned if no error occurs (even if the mapping is not * recreated as a result of outstanding references) or an sql error * code otherwise. */ @@ -1275,7 +1275,7 @@ unixMapfile(unixFile * pFd, i64 nMap) assert(nMap >= 0 || pFd->nFetchOut == 0); assert(nMap > 0 || (pFd->mmapSize == 0 && pFd->pMapRegion == 0)); if (pFd->nFetchOut > 0) - return SQL_OK; + return 0; if (nMap < 0) { struct stat statbuf; /* Low-level file information */ @@ -1292,15 +1292,15 @@ unixMapfile(unixFile * pFd, i64 nMap) unixRemapfile(pFd, nMap); } - return SQL_OK; + return 0; } /* * If possible, return a pointer to a mapping of file fd starting at offset * iOff. The mapping must be valid for at least nAmt bytes. * - * If such a pointer can be obtained, store it in *pp and return SQL_OK. - * Or, if one cannot but no error occurs, set *pp to 0 and return SQL_OK. + * If such a pointer can be obtained, store it in *pp and return 0. + * Or, if one cannot but no error occurs, set *pp to 0 and return 0. * Finally, if an error does occur, return an sql error code. The final * value of *pp is undefined in this case. * @@ -1321,7 +1321,7 @@ unixFetch(sql_file * fd MAYBE_UNUSED, if (pFd->mmapSizeMax > 0) { if (pFd->pMapRegion == 0) { int rc = unixMapfile(pFd, -1); - if (rc != SQL_OK) + if (rc != 0) return rc; } if (pFd->mmapSize >= iOff + nAmt) { @@ -1330,7 +1330,7 @@ unixFetch(sql_file * fd MAYBE_UNUSED, } } #endif - return SQL_OK; + return 0; } /* @@ -1365,7 +1365,7 @@ unixUnfetch(sql_file * fd, i64 iOff, void *p) } assert(pFd->nFetchOut >= 0); - return SQL_OK; + return 0; } /* @@ -1466,7 +1466,7 @@ fillInUnixFile(sql_vfs * pVfs, /* Pointer to vfs object */ { const sql_io_methods *pLockingStyle; unixFile *pNew = (unixFile *) pId; - int rc = SQL_OK; + int rc = 0; assert(pNew->pInode == NULL); @@ -1499,7 +1499,7 @@ fillInUnixFile(sql_vfs * pVfs, /* Pointer to vfs object */ if (pLockingStyle == &posixIoMethods) { rc = findInodeInfo(pNew, &pNew->pInode); - if (rc != SQL_OK) { + if (rc != 0) { /* If an error occurred in findInodeInfo(), close the file descriptor * immediately. findInodeInfo() may fail * in two scenarios: @@ -1523,7 +1523,7 @@ fillInUnixFile(sql_vfs * pVfs, /* Pointer to vfs object */ } } storeLastErrno(pNew, 0); - if (rc != SQL_OK) { + if (rc != 0) { if (h >= 0) robust_close(pNew, h, __LINE__); } else { @@ -1598,7 +1598,7 @@ unixGetTempname(int nBuf, char *zBuf) if (zBuf[nBuf - 2] != 0 || (iLimit++) > 10) return SQL_ERROR; } while (access(zBuf, 0) == 0); - return SQL_OK; + return 0; } /* @@ -1667,7 +1667,7 @@ getFileMode(const char *zFile, /* File name */ ) { struct stat sStat; /* Output of stat() on database file */ - int rc = SQL_OK; + int rc = 0; if (0 == stat(zFile, &sStat)) { *pMode = sStat.st_mode & 0777; *pUid = sStat.st_uid; @@ -1680,7 +1680,7 @@ getFileMode(const char *zFile, /* File name */ /* * This function is called by unixOpen() to determine the unix permissions - * to create new files with. If no error occurs, then SQL_OK is returned + * to create new files with. If no error occurs, then 0 is returned * and a value suitable for passing as the third argument to open(2) is * written to *pMode. If an IO error occurs, an sql error code is * returned and the value of *pMode is not modified. @@ -1702,7 +1702,7 @@ findCreateFileMode(const char *zPath, /* Path of file (possibly) being created * gid_t * pGid /* OUT: gid to set on the file */ ) { - int rc = SQL_OK; /* Return Code */ + int rc = 0; /* Return Code */ *pMode = 0; *pUid = 0; *pGid = 0; @@ -1827,7 +1827,7 @@ unixOpen(sql_vfs * pVfs, /* The VFS for which this is the xOpen method */ /* If zName is NULL, the upper layer is requesting a temp file. */ assert(isDelete); rc = unixGetTempname(pVfs->mxPathname, zTmpname); - if (rc != SQL_OK) { + if (rc != 0) { return rc; } zName = zTmpname; @@ -1861,7 +1861,7 @@ unixOpen(sql_vfs * pVfs, /* The VFS for which this is the xOpen method */ uid_t uid; /* Userid for the file */ gid_t gid; /* Groupid for the file */ rc = findCreateFileMode(zName, flags, &openMode, &uid, &gid); - if (rc != SQL_OK) { + if (rc != 0) { assert(!p->pUnused); return rc; } @@ -1911,7 +1911,7 @@ unixOpen(sql_vfs * pVfs, /* The VFS for which this is the xOpen method */ rc = fillInUnixFile(pVfs, fd, pFile, zPath, ctrlFlags); open_finished: - if (rc != SQL_OK) { + if (rc != 0) { sql_free(p->pUnused); } return rc; @@ -1927,7 +1927,7 @@ unixDelete(sql_vfs * NotUsed, /* VFS containing this as the xDelete method */ int dirSync /* If true, fsync() directory after deleting file */ ) { - int rc = SQL_OK; + int rc = 0; UNUSED_PARAMETER(NotUsed); if (unlink(zPath) == (-1)) { if (errno == ENOENT) { @@ -1941,7 +1941,7 @@ unixDelete(sql_vfs * NotUsed, /* VFS containing this as the xDelete method */ if ((dirSync & 1) != 0) { int fd; rc = openDirectory(zPath, &fd); - if (rc == SQL_OK) { + if (rc == 0) { struct stat buf; if (fstat(fd, &buf)) { rc = unixLogError(SQL_IOERR_DIR_FSYNC, @@ -1950,7 +1950,7 @@ unixDelete(sql_vfs * NotUsed, /* VFS containing this as the xDelete method */ robust_close(0, fd, __LINE__); } else { assert(rc == SQL_CANTOPEN); - rc = SQL_OK; + rc = 0; } } #endif @@ -1993,7 +1993,7 @@ int sql_current_time = 0; * epoch of noon in Greenwich on November 24, 4714 B.C according to the * proleptic Gregorian calendar. * - * On success, return SQL_OK. Return SQL_ERROR if the time and date + * On success, return 0. Return SQL_ERROR if the time and date * cannot be found. */ static int @@ -2001,7 +2001,7 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow) { static const sql_int64 unixEpoch = 24405875 * (sql_int64) 8640000; - int rc = SQL_OK; + int rc = 0; struct timeval sNow; (void)gettimeofday(&sNow, 0); /* Cannot fail given valid arguments */ *piNow = @@ -2092,7 +2092,7 @@ sql_os_init(void) /* Register all VFSes defined in the aVfs[] array. */ for (unsigned int i = 0; i < (sizeof(aVfs) / sizeof(sql_vfs)); i++) sql_vfs_register(&aVfs[i], i == 0); - return SQL_OK; + return 0; } /* @@ -2105,5 +2105,5 @@ sql_os_init(void) int sql_os_end(void) { - return SQL_OK; + return 0; } diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c index 21c2fb8..e7422e2 100644 --- a/src/box/sql/prepare.c +++ b/src/box/sql/prepare.c @@ -52,7 +52,7 @@ sqlPrepare(sql * db, /* Database handle. */ const char **pzTail /* OUT: End of parsed string */ ) { - int rc = SQL_OK; /* Result code */ + int rc = 0; /* Result code */ Parse sParse; /* Parsing context */ sql_parser_create(&sParse, db); sParse.pReprepare = pReprepare; @@ -107,7 +107,7 @@ sqlPrepare(sql * db, /* Database handle. */ if (sParse.is_aborted) rc = SQL_TARANTOOL_ERROR; - if (rc == SQL_OK && sParse.pVdbe && sParse.explain) { + if (rc == 0 && sParse.pVdbe && sParse.explain) { static const char *const azColName[] = { /* 0 */ "addr", /* 1 */ "INTEGER", @@ -159,7 +159,7 @@ sqlPrepare(sql * db, /* Database handle. */ sqlVdbeSetSql(pVdbe, zSql, (int)(sParse.zTail - zSql), saveSqlFlag); } - if (sParse.pVdbe && (rc != SQL_OK || db->mallocFailed)) { + if (sParse.pVdbe && (rc != 0 || db->mallocFailed)) { sqlVdbeFinalize(sParse.pVdbe); assert(!(*ppStmt)); } else { @@ -201,14 +201,14 @@ sqlLockAndPrepare(sql * db, /* Database handle. */ rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail); } - assert(rc == SQL_OK || *ppStmt == 0); + assert(rc == 0 || *ppStmt == 0); return rc; } /* * Rerun the compilation of a statement after a schema change. * - * If the statement is successfully recompiled, return SQL_OK. Otherwise, + * If the statement is successfully recompiled, return 0. Otherwise, * if the statement cannot be recompiled because another connection has * locked the sql_master table, return SQL_LOCKED. If any other error * occurs, return SQL_SCHEMA. @@ -238,7 +238,7 @@ sqlReprepare(Vdbe * p) sqlTransferBindings(pNew, (sql_stmt *) p); sqlVdbeResetStepResult((Vdbe *) pNew); sqlVdbeFinalize((Vdbe *) pNew); - return SQL_OK; + return 0; } /* @@ -258,7 +258,7 @@ sql_prepare(sql * db, /* Database handle. */ { int rc; rc = sqlLockAndPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail); - assert(rc == SQL_OK || ppStmt == 0 || *ppStmt == 0); /* VERIFY: F13021 */ + assert(rc == 0 || ppStmt == 0 || *ppStmt == 0); /* VERIFY: F13021 */ return rc; } @@ -272,7 +272,7 @@ sql_prepare_v2(sql * db, /* Database handle. */ { int rc; rc = sqlLockAndPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail); - assert(rc == SQL_OK || ppStmt == 0 || *ppStmt == 0); /* VERIFY: F13021 */ + assert(rc == 0 || ppStmt == 0 || *ppStmt == 0); /* VERIFY: F13021 */ return rc; } diff --git a/src/box/sql/select.c b/src/box/sql/select.c index 3f0b540..39a7383 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -1825,7 +1825,7 @@ generateColumnNames(Parse * pParse, /* Parser context */ * Only the column names are computed. Column.zType, Column.zColl, * and other fields of Column are zeroed. * - * Return SQL_OK on success. If a memory allocation error occurs, + * Return 0 on success. If a memory allocation error occurs, * store NULL in *paCol and 0 in *pnCol and return SQL_NOMEM. */ int @@ -1929,8 +1929,8 @@ sqlColumnsFromExprList(Parse * parse, ExprList * expr_list, } cleanup: sqlHashClear(&ht); - int rc = db->mallocFailed ? SQL_NOMEM : SQL_OK; - if (rc != SQL_OK) { + int rc = db->mallocFailed ? SQL_NOMEM : 0; + if (rc != 0) { /* * pTable->def could be not temporal in * sqlViewGetColumnNames so we need clean-up. @@ -2579,7 +2579,7 @@ multiSelect(Parse * pParse, /* Parsing context */ Select * p, /* The right-most of SELECTs to be coded */ SelectDest * pDest) /* What to do with query results */ { - int rc = SQL_OK; /* Success code from a subroutine */ + int rc = 0; /* Success code from a subroutine */ Select *pPrior; /* Another SELECT immediately to our left */ Vdbe *v; /* Generate code to this VDBE */ SelectDest dest; /* Alternative data destination */ @@ -2694,7 +2694,7 @@ multiSelect(Parse * pParse, /* Parsing context */ } iSub2 = pParse->iNextSelectId; rc = sqlSelect(pParse, p, &dest); - testcase(rc != SQL_OK); + testcase(rc != 0); pDelete = p->pPrior; p->pPrior = pPrior; p->nSelectRow = @@ -2781,7 +2781,7 @@ multiSelect(Parse * pParse, /* Parsing context */ uniondest.eDest = op; iSub2 = pParse->iNextSelectId; rc = sqlSelect(pParse, p, &uniondest); - testcase(rc != SQL_OK); + testcase(rc != 0); /* Query flattening in sqlSelect() might refill p->pOrderBy. * Be sure to delete p->pOrderBy, therefore, to avoid a memory leak. */ @@ -2895,7 +2895,7 @@ multiSelect(Parse * pParse, /* Parsing context */ intersectdest.reg_eph = reg_eph2; iSub2 = pParse->iNextSelectId; rc = sqlSelect(pParse, p, &intersectdest); - testcase(rc != SQL_OK); + testcase(rc != 0); pDelete = p->pPrior; p->pPrior = pPrior; if (p->nSelectRow > pPrior->nSelectRow) @@ -4423,7 +4423,7 @@ is_simple_count(struct Select *select, struct AggInfo *agg_info) * INDEXED BY clause, then try to locate the specified index. If there * was such a clause and the named index cannot be found, return * SQL_ERROR and leave an error in pParse. Otherwise, populate - * pFrom->pIndex and return SQL_OK. + * pFrom->pIndex and return 0. */ int sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom) @@ -4447,7 +4447,7 @@ sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom) } pFrom->pIBIndex = idx->def; } - return SQL_OK; + return 0; } /* @@ -4601,9 +4601,9 @@ sqlWithPush(Parse * pParse, With * pWith, u8 bFree) * (pFrom->space!=0) to determine whether or not a successful match * was found. * - * Whether or not a match is found, SQL_OK is returned if no error + * Whether or not a match is found, 0 is returned if no error * occurs. If an error does occur, an error message is stored in the - * parser and some error code other than SQL_OK returned. + * parser and some error code other than 0 returned. */ static int withExpand(Walker * pWalker, struct SrcList_item *pFrom) @@ -4721,7 +4721,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom) pParse->pWith = pSavedWith; } - return SQL_OK; + return 0; } #endif @@ -6426,7 +6426,7 @@ sqlSelect(Parse * pParse, /* The parser context */ /* Identify column names if results of the SELECT are to be output. */ - if (rc == SQL_OK && pDest->eDest == SRT_Output) { + if (rc == 0 && pDest->eDest == SRT_Output) { generateColumnNames(pParse, pTabList, pEList); } diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index 98a0ccb..c989664 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -356,10 +356,8 @@ struct sql_vfs { #define SQL_LIMIT_WORKER_THREADS 10 enum sql_ret_code { - /** Result of a routine is ok. */ - SQL_OK = 0, /** Common error code. */ - SQL_ERROR, + SQL_ERROR = 1, /** Access permission denied. */ SQL_PERM, /** Callback routine requested an abort. */ diff --git a/src/box/sql/status.c b/src/box/sql/status.c index bc170c8..2d4eae0 100644 --- a/src/box/sql/status.c +++ b/src/box/sql/status.c @@ -143,7 +143,7 @@ sql_status64(int op, if (resetFlag) { wsdStat.mxValue[op] = wsdStat.nowValue[op]; } - return SQL_OK; + return 0; } int @@ -170,7 +170,7 @@ sql_db_status(sql * db, /* The database connection whose status is desired */ int resetFlag /* Reset high-water mark if true */ ) { - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ switch (op) { case SQL_DBSTATUS_LOOKASIDE_USED:{ *pCurrent = db->lookaside.nOut; diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h index 1a727de..e7e6ff2 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 SQL_OK on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. */ int sql_delete_by_key(struct space *space, uint32_t iid, char *key, @@ -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 SQL_OK on success, SQL_TARANTOOL_ERROR otherwise. + * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise. */ int tarantoolsqlEphemeralInsert(struct space *space, const char *tuple, const char *tuple_end); diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c index cf0abbd..001e566 100644 --- a/src/box/sql/trigger.c +++ b/src/box/sql/trigger.c @@ -782,7 +782,7 @@ sql_row_trigger_program(struct Parse *parser, struct sql_trigger *trigger, */ if (trigger->pWhen != NULL) { pWhen = sqlExprDup(db, trigger->pWhen, 0); - if (SQL_OK == sqlResolveExprNames(&sNC, pWhen) + if (0 == sqlResolveExprNames(&sNC, pWhen) && db->mallocFailed == 0) { iEndTrigger = sqlVdbeMakeLabel(v); sqlExprIfFalse(pSubParse, pWhen, diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index b64293a..a1be48d 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -247,7 +247,7 @@ allocateCursor( sqlVdbeFreeCursor(p, p->apCsr[iCur]); p->apCsr[iCur] = 0; } - if (SQL_OK==sqlVdbeMemClearAndResize(pMem, nByte)) { + if (0==sqlVdbeMemClearAndResize(pMem, nByte)) { p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z; memset(pCx, 0, offsetof(VdbeCursor,uc)); pCx->eCurType = eCurType; @@ -372,7 +372,7 @@ static u16 SQL_NOINLINE computeNumericType(Mem *pMem) assert((pMem->flags & (MEM_Str|MEM_Blob))!=0); if (sqlAtoF(pMem->z, &pMem->u.r, pMem->n)==0) return 0; - if (sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)==SQL_OK) + if (sql_atoi64(pMem->z, (int64_t *)&pMem->u.i, pMem->n)==0) return MEM_Int; return MEM_Real; } @@ -615,7 +615,7 @@ int sqlVdbeExec(Vdbe *p) #ifdef SQL_DEBUG int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */ #endif - int rc = SQL_OK; /* Value to return */ + int rc = 0; /* Value to return */ sql *db = p->db; /* The database */ int iCompare = 0; /* Result of last comparison */ unsigned nVmStep = 0; /* Number of virtual machine steps */ @@ -638,8 +638,8 @@ int sqlVdbeExec(Vdbe *p) */ goto no_mem; } - assert(p->rc==SQL_OK || (p->rc&0xff)==SQL_BUSY); - p->rc = SQL_OK; + assert(p->rc==0 || (p->rc&0xff)==SQL_BUSY); + p->rc = 0; p->iCurrentTime = 0; assert(p->explain==0); p->pResultSet = 0; @@ -676,7 +676,7 @@ int sqlVdbeExec(Vdbe *p) /* Errors are detected by individual opcodes, with an immediate * jumps to abort_due_to_error. */ - assert(rc==SQL_OK); + assert(rc==0); assert(pOp>=aOp && pOp<&aOp[p->nOp]); #ifdef VDBE_PROFILE @@ -916,7 +916,7 @@ case OP_HaltIfNull: { /* in3 */ * * P1 is the result code returned by sql_exec(), * sql_reset(), or sql_finalize(). For a normal halt, - * this should be SQL_OK (0). + * this should be 0 (0). * For errors, it can be some other value. If P1!=0 then P2 will * determine whether or not to rollback the current transaction. * Do not rollback if P2==ON_CONFLICT_ACTION_FAIL. Do the rollback @@ -949,7 +949,7 @@ case OP_Halt: { int pcx; pcx = (int)(pOp - aOp); - if (pOp->p1==SQL_OK && p->pFrame) { + if (pOp->p1==0 && p->pFrame) { /* Halt the sub-program. Return control to the parent frame. */ pFrame = p->pFrame; p->pFrame = pFrame->pParent; @@ -981,11 +981,11 @@ case OP_Halt: { assert(! diag_is_empty(diag_get())); } rc = sqlVdbeHalt(p); - assert(rc==SQL_BUSY || rc==SQL_OK || rc==SQL_ERROR); + assert(rc==SQL_BUSY || rc==0 || rc==SQL_ERROR); if (rc==SQL_BUSY) { p->rc = SQL_BUSY; } else { - assert(rc==SQL_OK || (p->rc&0xff)==SQL_CONSTRAINT); + assert(rc==0 || (p->rc&0xff)==SQL_CONSTRAINT); rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE; } goto vdbe_return; @@ -1058,7 +1058,7 @@ case OP_String8: { /* same as TK_STRING, out2 */ if (pOp->p1>db->aLimit[SQL_LIMIT_LENGTH]) { goto too_big; } - assert(rc==SQL_OK); + assert(rc==0); /* Fall through to the next case, OP_String */ FALLTHROUGH; } @@ -1331,7 +1331,7 @@ case OP_ResultRow: { * not return the number of rows modified. And do not RELEASE the statement * transaction. It needs to be rolled back. */ - if (sqlVdbeCheckFk(p, 0) != SQL_OK) { + if (sqlVdbeCheckFk(p, 0) != 0) { assert(user_session->sql_flags&SQL_CountRows); goto abort_due_to_error; } @@ -1353,7 +1353,7 @@ case OP_ResultRow: { */ assert(p->iStatement==0 || user_session->sql_flags&SQL_CountRows); rc = sqlVdbeCloseStatement(p, SAVEPOINT_RELEASE); - assert(rc==SQL_OK); + assert(rc==0); /* Invalidate all ephemeral cursor row caches */ p->cacheCtr = (p->cacheCtr + 2)|1; @@ -1432,7 +1432,7 @@ case OP_Concat: { /* same as TK_CONCAT, in1, in2, out3 */ mem_type_to_str(pIn2), mem_type_to_str(pIn1)); goto abort_due_to_error; } - if (ExpandBlob(pIn1) != SQL_OK || ExpandBlob(pIn2) != SQL_OK) + if (ExpandBlob(pIn1) != 0 || ExpandBlob(pIn2) != 0) goto abort_due_to_error; nByte = pIn1->n + pIn2->n; if (nByte>db->aLimit[SQL_LIMIT_LENGTH]) { @@ -1892,7 +1892,7 @@ case OP_Realify: { /* in1 */ */ case OP_Cast: { /* in1 */ pIn1 = &aMem[pOp->p1]; - if (ExpandBlob(pIn1) != SQL_OK) + if (ExpandBlob(pIn1) != 0) goto abort_due_to_error; rc = sqlVdbeMemCast(pIn1, pOp->p2); UPDATE_MAX_BLOBSIZE(pIn1); @@ -2564,7 +2564,7 @@ case OP_Column: { } else { memset(&sMem, 0, sizeof(sMem)); if (sqlVdbeMemFromBtree(pC->uc.pCursor, 0, pC->payloadSize, - &sMem) != SQL_OK) + &sMem) != 0) goto abort_due_to_error; zData = (u8*)sMem.z; zEnd = zData + pC->payloadSize; @@ -2617,7 +2617,7 @@ case OP_Column: { * reach this point if aOffset[p2], aOffset[p2+1] are * all valid. */ - assert(rc==SQL_OK); + assert(rc==0); assert(sqlVdbeCheckMemInvariants(pDest)); if (VdbeMemDynamic(pDest)) { sqlVdbeMemSetNull(pDest); @@ -2829,10 +2829,10 @@ case OP_Count: { /* out2 */ assert(pCrsr); nEntry = 0; /* Not needed. Only used to silence a warning. */ if (pCrsr->curFlags & BTCF_TaCursor) { - if (tarantoolsqlCount(pCrsr, &nEntry) != SQL_OK) + if (tarantoolsqlCount(pCrsr, &nEntry) != 0) goto abort_due_to_error; } else if (pCrsr->curFlags & BTCF_TEphemCursor) { - if (tarantoolsqlEphemeralCount(pCrsr, &nEntry) != SQL_OK) + if (tarantoolsqlEphemeralCount(pCrsr, &nEntry) != 0) goto abort_due_to_error; } else { unreachable(); @@ -2897,7 +2897,7 @@ case OP_Savepoint: { */ int isTransaction = pSavepoint->pNext == 0; if (isTransaction && p1==SAVEPOINT_RELEASE) { - if ((rc = sqlVdbeCheckFk(p, 1))!=SQL_OK) { + if ((rc = sqlVdbeCheckFk(p, 1))!=0) { goto vdbe_return; } if (sqlVdbeHalt(p)==SQL_BUSY) { @@ -2905,7 +2905,7 @@ case OP_Savepoint: { p->rc = rc = SQL_BUSY; goto vdbe_return; } - if (p->rc != SQL_OK) + if (p->rc != 0) goto abort_due_to_error; } else { if (p1==SAVEPOINT_ROLLBACK) @@ -3154,7 +3154,7 @@ case OP_SorterOpen: { pCx = allocateCursor(p, pOp->p1, pOp->p2, CURTYPE_SORTER); if (pCx==0) goto no_mem; pCx->key_def = def; - if (sqlVdbeSorterInit(db, pCx) != SQL_OK) + if (sqlVdbeSorterInit(db, pCx) != 0) goto abort_due_to_error; break; } @@ -3467,7 +3467,7 @@ case OP_SeekGT: { /* jump, in3 */ #endif r.eqSeen = 0; r.opcode = oc; - if (sqlCursorMovetoUnpacked(pC->uc.pCursor, &r, &res) != SQL_OK) + if (sqlCursorMovetoUnpacked(pC->uc.pCursor, &r, &res) != 0) goto abort_due_to_error; if (eqOnly && r.eqSeen==0) { assert(res!=0); @@ -3480,7 +3480,7 @@ case OP_SeekGT: { /* jump, in3 */ if (oc>=OP_SeekGE) { assert(oc==OP_SeekGE || oc==OP_SeekGT); if (res<0 || (res==0 && oc==OP_SeekGT)) { res = 0; - if (sqlCursorNext(pC->uc.pCursor, &res) != SQL_OK) + if (sqlCursorNext(pC->uc.pCursor, &res) != 0) goto abort_due_to_error; } else { res = 0; @@ -3489,7 +3489,7 @@ case OP_SeekGT: { /* jump, in3 */ assert(oc==OP_SeekLT || oc==OP_SeekLE); if (res>0 || (res==0 && oc==OP_SeekLT)) { res = 0; - if (sqlCursorPrevious(pC->uc.pCursor, &res) != SQL_OK) + if (sqlCursorPrevious(pC->uc.pCursor, &res) != 0) goto abort_due_to_error; } else { /* res might be negative because the table is empty. Check to @@ -3634,8 +3634,8 @@ case OP_Found: { /* jump, in3 */ rc = sqlCursorMovetoUnpacked(pC->uc.pCursor, pIdxKey, &res); if (pFree != NULL) sqlDbFree(db, pFree); - assert(rc == SQL_OK || rc == SQL_TARANTOOL_ERROR); - if (rc != SQL_OK) + assert(rc == 0 || rc == SQL_TARANTOOL_ERROR); + if (rc != 0) goto abort_due_to_error; pC->seekResult = res; alreadyExists = (res==0); @@ -3878,7 +3878,7 @@ case OP_SorterData: { pOut = &aMem[pOp->p2]; pC = p->apCsr[pOp->p1]; assert(isSorter(pC)); - if (sqlVdbeSorterRowkey(pC, pOut) != SQL_OK) + if (sqlVdbeSorterRowkey(pC, pOut) != 0) goto abort_due_to_error; assert(pOut->flags & MEM_Blob); assert(pOp->p1>=0 && pOp->p1nCursor); @@ -3948,8 +3948,8 @@ case OP_RowData: { testcase( n==0); sqlVdbeMemRelease(pOut); - if (sql_vdbe_mem_alloc_region(pOut, n) != SQL_OK || - sqlCursorPayload(pCrsr, 0, n, pOut->z) != SQL_OK) + if (sql_vdbe_mem_alloc_region(pOut, n) != 0 || + sqlCursorPayload(pCrsr, 0, n, pOut->z) != 0) goto abort_due_to_error; UPDATE_MAX_BLOBSIZE(pOut); REGISTER_TRACE(pOp->p2, pOut); @@ -4085,16 +4085,16 @@ case OP_Rewind: { /* jump */ pC->seekOp = OP_Rewind; #endif if (isSorter(pC)) { - if (sqlVdbeSorterRewind(pC, &res) != SQL_OK) + if (sqlVdbeSorterRewind(pC, &res) != 0) goto abort_due_to_error; } else { assert(pC->eCurType==CURTYPE_TARANTOOL); pCrsr = pC->uc.pCursor; assert(pCrsr); - if (tarantoolsqlFirst(pCrsr, &res) != SQL_OK) + if (tarantoolsqlFirst(pCrsr, &res) != 0) rc = SQL_TARANTOOL_ERROR; pC->cacheStatus = CACHE_STALE; - if (rc != SQL_OK) + if (rc != 0) goto abort_due_to_error; } pC->nullRow = (u8)res; @@ -4242,8 +4242,8 @@ case OP_SorterInsert: { /* in2 */ assert(isSorter(cursor)); pIn2 = &aMem[pOp->p2]; assert((pIn2->flags & MEM_Blob) != 0); - if (ExpandBlob(pIn2) != SQL_OK || - sqlVdbeSorterWrite(cursor, pIn2) != SQL_OK) + if (ExpandBlob(pIn2) != 0 || + sqlVdbeSorterWrite(cursor, pIn2) != 0) goto abort_due_to_error; break; } @@ -4273,7 +4273,7 @@ case OP_IdxInsert: { assert((pIn2->flags & MEM_Blob) != 0); if (pOp->p5 & OPFLAG_NCHANGE) p->nChange++; - if (ExpandBlob(pIn2) != SQL_OK) + if (ExpandBlob(pIn2) != 0) goto abort_due_to_error; struct space *space; if (pOp->p4type == P4_SPACEPTR) @@ -4298,7 +4298,7 @@ case OP_IdxInsert: { if (pOp->p5 & OPFLAG_OE_IGNORE) { /* Ignore any kind of failes and do not raise error message */ - rc = SQL_OK; + rc = 0; /* If we are in trigger, increment ignore raised counter */ if (p->pFrame) p->ignoreRaised++; @@ -4307,7 +4307,7 @@ case OP_IdxInsert: { } else if (pOp->p5 & OPFLAG_OE_ROLLBACK) { p->errorAction = ON_CONFLICT_ACTION_ROLLBACK; } - assert(rc == SQL_OK || rc == SQL_TARANTOOL_ERROR); + assert(rc == 0 || rc == SQL_TARANTOOL_ERROR); if (rc != 0) goto abort_due_to_error; break; @@ -4384,7 +4384,7 @@ case OP_Update: { goto abort_due_to_error; } - assert(rc == SQL_OK); + 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; @@ -4394,7 +4394,7 @@ case OP_Update: { * Ignore any kind of fails and do not raise * error message */ - rc = SQL_OK; + rc = 0; /* * If we are in trigger, increment ignore raised * counter. @@ -4406,7 +4406,7 @@ case OP_Update: { } else if (pOp->p5 & OPFLAG_OE_ROLLBACK) { p->errorAction = ON_CONFLICT_ACTION_ROLLBACK; } - assert(rc == SQL_OK || rc == SQL_TARANTOOL_ERROR); + assert(rc == 0 || rc == SQL_TARANTOOL_ERROR); if (rc != 0) goto abort_due_to_error; break; @@ -4457,7 +4457,7 @@ case OP_SDelete: { struct space *space = space_by_id(pOp->p1); assert(space != NULL); assert(space_is_system(space)); - if (sql_delete_by_key(space, 0, pIn2->z, pIn2->n) != SQL_OK) + if (sql_delete_by_key(space, 0, pIn2->z, pIn2->n) != 0) goto abort_due_to_error; if (pOp->p5 & OPFLAG_NCHANGE) p->nChange++; @@ -4491,15 +4491,15 @@ case OP_IdxDelete: { r.default_rc = 0; r.aMem = &aMem[pOp->p2]; r.opcode = OP_IdxDelete; - if (sqlCursorMovetoUnpacked(pCrsr, &r, &res) != SQL_OK) + if (sqlCursorMovetoUnpacked(pCrsr, &r, &res) != 0) goto abort_due_to_error; if (res==0) { assert(pCrsr->eState == CURSOR_VALID); if (pCrsr->curFlags & BTCF_TaCursor) { - if (tarantoolsqlDelete(pCrsr, 0) != SQL_OK) + if (tarantoolsqlDelete(pCrsr, 0) != 0) goto abort_due_to_error; } else if (pCrsr->curFlags & BTCF_TEphemCursor) { - if (tarantoolsqlEphemeralDelete(pCrsr) != SQL_OK) + if (tarantoolsqlEphemeralDelete(pCrsr) != 0) goto abort_due_to_error; } else { unreachable(); @@ -4618,7 +4618,7 @@ case OP_Clear: { goto abort_due_to_error; } else { uint32_t tuple_count; - if (tarantoolsqlClearTable(space, &tuple_count) != SQL_OK) + if (tarantoolsqlClearTable(space, &tuple_count) != 0) goto abort_due_to_error; if ((pOp->p5 & OPFLAG_NCHANGE) != 0) p->nChange += tuple_count; @@ -4645,7 +4645,7 @@ case OP_ResetSorter: { } else { assert(pC->eCurType==CURTYPE_TARANTOOL); assert(pC->uc.pCursor->curFlags & BTCF_TEphemCursor); - if (tarantoolsqlEphemeralClearTable(pC->uc.pCursor) != SQL_OK) + if (tarantoolsqlEphemeralClearTable(pC->uc.pCursor) != 0) goto abort_due_to_error; } break; @@ -4679,7 +4679,7 @@ case OP_RenameTable: { zNewTableName = pOp->p4.z; zOldTableName = sqlDbStrNDup(db, zOldTableName, sqlStrlen30(zOldTableName)); - if (sql_rename_table(space_id, zNewTableName) != SQL_OK) + if (sql_rename_table(space_id, zNewTableName) != 0) goto abort_due_to_error; /* * Rebuild 'CREATE TRIGGER' expressions of all triggers @@ -4700,7 +4700,7 @@ case OP_RenameTable: { * try again. */ if (tarantoolsqlRenameTrigger(trigger->zName, zOldTableName, - zNewTableName) != SQL_OK) + zNewTableName) != 0) goto abort_due_to_error; trigger = next_trigger; } @@ -4716,7 +4716,7 @@ case OP_RenameTable: { */ case OP_LoadAnalysis: { assert(pOp->p1==0 ); - if (sql_analysis_load(db) != SQL_OK) + if (sql_analysis_load(db) != 0) goto abort_due_to_error; break; } @@ -5241,7 +5241,7 @@ case OP_IncMaxid: { assert(pOp->p1 > 0); pOut = &aMem[pOp->p1]; - if (tarantoolsqlIncrementMaxid((uint64_t*) &pOut->u.i) != SQL_OK) + if (tarantoolsqlIncrementMaxid((uint64_t*) &pOut->u.i) != 0) goto abort_due_to_error; pOut->flags = MEM_Int; break; @@ -5313,10 +5313,10 @@ abort_due_to_error: vdbe_return: testcase( nVmStep>0); p->aCounter[SQL_STMTSTATUS_VM_STEP] += (int)nVmStep; - assert(rc!=SQL_OK || nExtraDelete==0 + assert(rc!=0 || nExtraDelete==0 || sql_strlike_ci("DELETE%", p->zSql, 0) != 0 ); - assert(rc == SQL_OK || rc == SQL_BUSY || rc == SQL_TARANTOOL_ERROR || + assert(rc == 0 || rc == SQL_BUSY || rc == SQL_TARANTOOL_ERROR || rc == SQL_ROW || rc == SQL_DONE); return rc; diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 4e4c239..75078da 100644 --- a/src/box/sql/vdbeapi.c +++ b/src/box/sql/vdbeapi.c @@ -87,7 +87,7 @@ sql_finalize(sql_stmt * pStmt) /* IMPLEMENTATION-OF: R-57228-12904 Invoking sql_finalize() on a NULL * pointer is a harmless no-op. */ - rc = SQL_OK; + rc = 0; } else { Vdbe *v = (Vdbe *) pStmt; sql *db = v->db; @@ -109,7 +109,7 @@ sql_reset(sql_stmt * pStmt) { int rc; if (pStmt == 0) { - rc = SQL_OK; + rc = 0; } else { Vdbe *v = (Vdbe *) pStmt; sql *db = v->db; @@ -129,7 +129,7 @@ int sql_clear_bindings(sql_stmt * pStmt) { int i; - int rc = SQL_OK; + int rc = 0; Vdbe *p = (Vdbe *) pStmt; for (i = 0; i < p->nVar; i++) { sqlVdbeMemRelease(&p->aVar[i]); @@ -150,7 +150,7 @@ sql_value_blob(sql_value * pVal) { Mem *p = (Mem *) pVal; if (p->flags & (MEM_Blob | MEM_Str)) { - if (ExpandBlob(p) != SQL_OK) { + if (ExpandBlob(p) != 0) { assert(p->flags == MEM_Null && p->z == 0); return 0; } @@ -249,7 +249,7 @@ sql_value_dup(const sql_value * pOrig) if (pNew->flags & (MEM_Str | MEM_Blob)) { pNew->flags &= ~(MEM_Static | MEM_Dyn); pNew->flags |= MEM_Ephem; - if (sqlVdbeMemMakeWriteable(pNew) != SQL_OK) { + if (sqlVdbeMemMakeWriteable(pNew) != 0) { sqlValueFree(pNew); pNew = 0; } @@ -408,7 +408,7 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n) return SQL_TOOBIG; } sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n); - return SQL_OK; + return 0; } /* @@ -527,7 +527,7 @@ sql_step(sql_stmt * pStmt) && cnt++ < SQL_MAX_SCHEMA_RETRY) { int savedPc = v->pc; rc = sqlReprepare(v); - if (rc != SQL_OK) + if (rc != 0) break; sql_reset(pStmt); if (savedPc >= 0) @@ -991,7 +991,7 @@ sql_column_origin_name(sql_stmt * pStmt, int N) /* * Unbind the value bound to variable i in virtual machine p. This is the * the same as binding a NULL value to the column. If the "i" parameter is - * out of range, then SQL_RANGE is returned. Othewise SQL_OK. + * out of range, then SQL_RANGE is returned. Othewise 0. * * The error code stored in database p->db is overwritten with the return * value in any case. @@ -1029,7 +1029,7 @@ vdbeUnbind(Vdbe * p, int i) ) { p->expired = 1; } - return SQL_OK; + return 0; } /** @@ -1092,11 +1092,11 @@ bindText(sql_stmt * pStmt, /* The statement to bind against */ int rc; rc = vdbeUnbind(p, i); - if (rc == SQL_OK) { + if (rc == 0) { if (zData != 0) { pVar = &p->aVar[i - 1]; rc = sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel); - if (rc == SQL_OK) + if (rc == 0) rc = sql_bind_type(p, i, "TEXT"); rc = sqlApiExit(p->db, rc); } @@ -1116,11 +1116,11 @@ sql_bind_blob(sql_stmt * pStmt, { struct Vdbe *p = (Vdbe *) pStmt; int rc = vdbeUnbind(p, i); - if (rc == SQL_OK) { + if (rc == 0) { if (zData != 0) { struct Mem *var = &p->aVar[i - 1]; rc = sqlVdbeMemSetStr(var, zData, nData, 0, xDel); - if (rc == SQL_OK) + if (rc == 0) rc = sql_bind_type(p, i, "BLOB"); rc = sqlApiExit(p->db, rc); } @@ -1151,7 +1151,7 @@ sql_bind_double(sql_stmt * pStmt, int i, double rValue) int rc; Vdbe *p = (Vdbe *) pStmt; rc = vdbeUnbind(p, i); - if (rc == SQL_OK) { + if (rc == 0) { rc = sql_bind_type(p, i, "NUMERIC"); sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue); } @@ -1163,7 +1163,7 @@ sql_bind_boolean(struct sql_stmt *stmt, int i, bool value) { struct Vdbe *p = (struct Vdbe *) stmt; int rc = vdbeUnbind(p, i); - if (rc == SQL_OK) { + if (rc == 0) { rc = sql_bind_type(p, i, "BOOLEAN"); mem_set_bool(&p->aVar[i - 1], value); } @@ -1182,7 +1182,7 @@ sql_bind_int64(sql_stmt * pStmt, int i, sql_int64 iValue) int rc; Vdbe *p = (Vdbe *) pStmt; rc = vdbeUnbind(p, i); - if (rc == SQL_OK) { + if (rc == 0) { rc = sql_bind_type(p, i, "INTEGER"); sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue); } @@ -1195,7 +1195,7 @@ sql_bind_null(sql_stmt * pStmt, int i) int rc; Vdbe *p = (Vdbe *) pStmt; rc = vdbeUnbind(p, i); - if (rc == SQL_OK) + if (rc == 0) rc = sql_bind_type(p, i, "BOOLEAN"); return rc; } @@ -1229,7 +1229,7 @@ sql_bind_zeroblob(sql_stmt * pStmt, int i, int n) int rc; Vdbe *p = (Vdbe *) pStmt; rc = vdbeUnbind(p, i); - if (rc == SQL_OK) { + if (rc == 0) { sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n); } return rc; @@ -1317,7 +1317,7 @@ sqlTransferBindings(sql_stmt * pFromStmt, sql_stmt * pToStmt) for (i = 0; i < pFrom->nVar; i++) { sqlVdbeMemMove(&pTo->aVar[i], &pFrom->aVar[i]); } - return SQL_OK; + return 0; } /* diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index fbe5338..7f81fad 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -196,7 +196,7 @@ growOpArray(Vdbe * v, int nOp) p->nOpAlloc = p->szOpAlloc / sizeof(Op); v->aOp = pNew; } - return (pNew ? SQL_OK : SQL_NOMEM); + return (pNew ? 0 : SQL_NOMEM); } #ifdef SQL_DEBUG @@ -1415,12 +1415,12 @@ sqlVdbeList(Vdbe * p) Mem *pSub = 0; /* Memory cell hold array of subprogs */ sql *db = p->db; /* The database connection */ int i; /* Loop counter */ - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ Mem *pMem = &p->aMem[1]; /* First Mem of result set */ assert(p->explain); assert(p->magic == VDBE_MAGIC_RUN); - assert(p->rc == SQL_OK || p->rc == SQL_BUSY + assert(p->rc == 0 || p->rc == SQL_BUSY || p->rc == SQL_NOMEM); /* Even though this opcode does not use dynamic strings for @@ -1470,7 +1470,7 @@ sqlVdbeList(Vdbe * p) i = p->pc++; } while (i < nRow && p->explain == 2 && p->aOp[i].opcode != OP_Explain); if (i >= nRow) { - p->rc = SQL_OK; + p->rc = 0; rc = SQL_DONE; } else { char *zP4; @@ -1515,7 +1515,7 @@ sqlVdbeList(Vdbe * p) break; } if (j == nSub - && SQL_OK == sqlVdbeMemGrow(pSub, + && 0 == sqlVdbeMemGrow(pSub, nByte, nSub != 0)) { @@ -1579,7 +1579,7 @@ sqlVdbeList(Vdbe * p) p->nResColumn = 8 - 4 * (p->explain - 1); p->pResultSet = &p->aMem[1]; - p->rc = SQL_OK; + p->rc = 0; rc = SQL_ROW; } return rc; @@ -1713,7 +1713,7 @@ sqlVdbeRewind(Vdbe * p) } #endif p->pc = -1; - p->rc = SQL_OK; + p->rc = 0; p->ignoreRaised = 0; p->errorAction = ON_CONFLICT_ACTION_ABORT; p->nChange = 0; @@ -2066,12 +2066,12 @@ checkActiveVdbeCnt(sql * db) * statement transaction is committed. * * If an IO error occurs, an SQL_IOERR_XXX error code is returned. - * Otherwise SQL_OK. + * Otherwise 0. */ int sqlVdbeCloseStatement(Vdbe * p, int eOp) { - int rc = SQL_OK; + int rc = 0; const Savepoint *savepoint = p->anonymous_savepoint; /* * If we have an anonymous transaction opened -> perform eOp. @@ -2086,7 +2086,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp) * This function is called when a transaction opened by the database * handle associated with the VM passed as an argument is about to be * committed. If there are outstanding deferred foreign key constraint - * violations, return SQL_ERROR. Otherwise, SQL_OK. + * violations, return SQL_ERROR. Otherwise, 0. * * If there are outstanding FK violations and this function returns * SQL_ERROR, set the result of the VM to SQL_CONSTRAINT_FOREIGNKEY @@ -2105,7 +2105,7 @@ sqlVdbeCheckFk(Vdbe * p, int deferred) "failed"); return SQL_TARANTOOL_ERROR; } - return SQL_OK; + return 0; } int @@ -2191,7 +2191,7 @@ sqlVdbeHalt(Vdbe * p) } closeTopFrameCursors(p); if (p->magic != VDBE_MAGIC_RUN) { - return SQL_OK; + return 0; } checkActiveVdbeCnt(db); @@ -2234,7 +2234,7 @@ sqlVdbeHalt(Vdbe * p) } /* Check for immediate foreign key violations. */ - if (p->rc == SQL_OK) { + if (p->rc == 0) { sqlVdbeCheckFk(p, 0); } @@ -2245,11 +2245,11 @@ sqlVdbeHalt(Vdbe * p) * above has occurred. */ if (p->auto_commit) { - if (p->rc == SQL_OK + if (p->rc == 0 || (p->errorAction == ON_CONFLICT_ACTION_FAIL && !isSpecialError)) { rc = sqlVdbeCheckFk(p, 1); - if (rc != SQL_OK) { + if (rc != 0) { /* Close all opened cursors if * they exist and free all * VDBE frames. @@ -2267,13 +2267,13 @@ sqlVdbeHalt(Vdbe * p) */ rc = (in_txn() == NULL || txn_commit(in_txn()) == 0) ? - SQL_OK : SQL_TARANTOOL_ERROR; + 0 : SQL_TARANTOOL_ERROR; closeCursorsAndFree(p); } if (rc == SQL_BUSY && !p->pDelFrame) { closeCursorsAndFree(p); return SQL_BUSY; - } else if (rc != SQL_OK) { + } else if (rc != 0) { p->rc = rc; box_txn_rollback(); closeCursorsAndFree(p); @@ -2288,7 +2288,7 @@ sqlVdbeHalt(Vdbe * p) } p->anonymous_savepoint = NULL; } else if (eStatementOp == 0) { - if (p->rc == SQL_OK || p->errorAction == ON_CONFLICT_ACTION_FAIL) { + if (p->rc == 0 || p->errorAction == ON_CONFLICT_ACTION_FAIL) { eStatementOp = SAVEPOINT_RELEASE; } else if (p->errorAction == ON_CONFLICT_ACTION_ABORT) { eStatementOp = SAVEPOINT_ROLLBACK; @@ -2304,14 +2304,14 @@ sqlVdbeHalt(Vdbe * p) /* If eStatementOp is non-zero, then a statement transaction needs to * be committed or rolled back. Call sqlVdbeCloseStatement() to * do so. If this operation returns an error, and the current statement - * error code is SQL_OK or SQL_CONSTRAINT, then promote the + * error code is 0 or SQL_CONSTRAINT, then promote the * current statement error code. */ if (eStatementOp) { rc = sqlVdbeCloseStatement(p, eStatementOp); if (rc) { box_txn_rollback(); - if (p->rc == SQL_OK + if (p->rc == 0 || (p->rc & 0xff) == SQL_CONSTRAINT) { p->rc = rc; } @@ -2350,17 +2350,17 @@ sqlVdbeHalt(Vdbe * p) assert(db->nVdbeActive > 0 || box_txn() || p->anonymous_savepoint == NULL); - return (p->rc == SQL_BUSY ? SQL_BUSY : SQL_OK); + return (p->rc == SQL_BUSY ? SQL_BUSY : 0); } /* * Each VDBE holds the result of the most recent sql_step() call - * in p->rc. This routine sets that result back to SQL_OK. + * in p->rc. This routine sets that result back to 0. */ void sqlVdbeResetStepResult(Vdbe * p) { - p->rc = SQL_OK; + p->rc = 0; } /* @@ -2461,7 +2461,7 @@ sqlVdbeReset(Vdbe * p) int sqlVdbeFinalize(Vdbe * p) { - int rc = SQL_OK; + int rc = 0; if (p->magic == VDBE_MAGIC_RUN || p->magic == VDBE_MAGIC_HALT) { rc = sqlVdbeReset(p); assert((rc & p->db->errMask) == rc); @@ -2989,7 +2989,7 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size) return SQL_NOMEM; vdbe_mem->flags = MEM_Ephem | MEM_Blob; assert(sqlVdbeCheckMemInvariants(vdbe_mem)); - return SQL_OK; + return 0; } /* diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c index 1a0fa75..4bb82b8 100644 --- a/src/box/sql/vdbemem.c +++ b/src/box/sql/vdbemem.c @@ -146,7 +146,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve) pMem->z = pMem->zMalloc; pMem->flags &= ~(MEM_Dyn | MEM_Ephem | MEM_Static); - return SQL_OK; + return 0; } /* @@ -159,7 +159,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve) * and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null * values are preserved. * - * Return SQL_OK on success or an error code (probably SQL_NOMEM) + * Return 0 on success or an error code (probably SQL_NOMEM) * if unable to complete the resizing. */ int @@ -173,14 +173,14 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew) assert((pMem->flags & MEM_Dyn) == 0); pMem->z = pMem->zMalloc; pMem->flags &= (MEM_Null | MEM_Int | MEM_Real); - return SQL_OK; + return 0; } /* * Change pMem so that its MEM_Str or MEM_Blob value is stored in * MEM.zMalloc, where it can be safely written. * - * Return SQL_OK on success or SQL_NOMEM if malloc fails. + * Return 0 on success or SQL_NOMEM if malloc fails. */ int sqlVdbeMemMakeWriteable(Mem * pMem) @@ -202,7 +202,7 @@ sqlVdbeMemMakeWriteable(Mem * pMem) pMem->pScopyFrom = 0; #endif - return SQL_OK; + return 0; } /* @@ -228,7 +228,7 @@ sqlVdbeMemExpandBlob(Mem * pMem) memset(&pMem->z[pMem->n], 0, pMem->u.nZero); pMem->n += pMem->u.nZero; pMem->flags &= ~(MEM_Zero | MEM_Term); - return SQL_OK; + return 0; } /* @@ -244,7 +244,7 @@ vdbeMemAddTerminator(Mem * pMem) pMem->z[pMem->n] = 0; pMem->z[pMem->n + 1] = 0; pMem->flags |= MEM_Term; - return SQL_OK; + return 0; } /* @@ -256,7 +256,7 @@ sqlVdbeMemNulTerminate(Mem * pMem) testcase((pMem->flags & (MEM_Term | MEM_Str)) == (MEM_Term | MEM_Str)); testcase((pMem->flags & (MEM_Term | MEM_Str)) == 0); if ((pMem->flags & (MEM_Term | MEM_Str)) != MEM_Str) { - return SQL_OK; /* Nothing to do */ + return 0; /* Nothing to do */ } else { return vdbeMemAddTerminator(pMem); } @@ -283,7 +283,7 @@ sqlVdbeMemStringify(Mem * pMem, u8 bForce) const int nByte = 32; if ((fg & (MEM_Null | MEM_Str | MEM_Blob)) != 0) - return SQL_OK; + return 0; assert(!(fg & MEM_Zero)); assert(fg & (MEM_Int | MEM_Real | MEM_Bool)); @@ -304,7 +304,7 @@ sqlVdbeMemStringify(Mem * pMem, u8 bForce) pMem->flags |= MEM_Str | MEM_Term; if (bForce) pMem->flags &= ~(MEM_Int | MEM_Real); - return SQL_OK; + return 0; } /* @@ -564,7 +564,7 @@ sqlVdbeMemRealify(Mem * pMem) pMem->u.r = v; MemSetTypeFlag(pMem, MEM_Real); - return SQL_OK; + return 0; } /* @@ -593,7 +593,7 @@ sqlVdbeMemNumerify(Mem * pMem) } assert((pMem->flags & (MEM_Int | MEM_Real | MEM_Null)) != 0); pMem->flags &= ~(MEM_Str | MEM_Blob | MEM_Zero); - return SQL_OK; + return 0; } /** @@ -643,7 +643,7 @@ sqlVdbeMemCast(Mem * pMem, enum field_type type) { assert(type < field_type_MAX); if (pMem->flags & MEM_Null) - return SQL_OK; + return 0; if ((pMem->flags & MEM_Blob) != 0 && type == FIELD_TYPE_NUMBER) { if (sql_atoi64(pMem->z, (int64_t *) &pMem->u.i, pMem->n) == 0) { MemSetTypeFlag(pMem, MEM_Real); @@ -699,7 +699,7 @@ sqlVdbeMemCast(Mem * pMem, enum field_type type) sql_value_apply_type(pMem, FIELD_TYPE_STRING); assert(pMem->flags & MEM_Str || pMem->db->mallocFailed); pMem->flags &= ~(MEM_Int | MEM_Real | MEM_Blob | MEM_Zero); - return SQL_OK; + return 0; } } @@ -890,7 +890,7 @@ sqlVdbeMemShallowCopy(Mem * pTo, const Mem * pFrom, int srcType) int sqlVdbeMemCopy(Mem * pTo, const Mem * pFrom) { - int rc = SQL_OK; + int rc = 0; if (VdbeMemDynamic(pTo)) vdbeMemClearExternAndSetNull(pTo); @@ -953,7 +953,7 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */ /* If z is a NULL pointer, set pMem to contain an SQL NULL. */ if (!z) { sqlVdbeMemSetNull(pMem); - return SQL_OK; + return 0; } if (pMem->db) { @@ -1007,7 +1007,7 @@ sqlVdbeMemSetStr(Mem * pMem, /* Memory cell to set to string value */ return SQL_TOOBIG; } - return SQL_OK; + return 0; } /* @@ -1034,9 +1034,9 @@ vdbeMemFromBtreeResize(BtCursor * pCur, /* Cursor pointing at record to retrieve { int rc; pMem->flags = MEM_Null; - if (SQL_OK == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) { + if (0 == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) { rc = sqlCursorPayload(pCur, offset, amt, pMem->z); - if (rc == SQL_OK) { + if (rc == 0) { pMem->z[amt] = 0; pMem->z[amt + 1] = 0; pMem->flags = MEM_Blob | MEM_Term; @@ -1057,7 +1057,7 @@ sqlVdbeMemFromBtree(BtCursor * pCur, /* Cursor pointing at record to retrieve. * { char *zData; /* Data from the btree layer */ u32 available = 0; /* Number of bytes available on the local btree page */ - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ assert(sqlCursorIsValid(pCur)); assert(!VdbeMemDynamic(pMem)); @@ -1209,13 +1209,13 @@ valueNew(sql * db, struct ValueNewStat4Ctx *p) * * then this routine attempts to invoke the SQL function. Assuming no * error occurs, output parameter (*ppVal) is set to point to a value - * object containing the result before returning SQL_OK. + * object containing the result before returning 0. * * Type @type is applied to the result of the function before returning. * If the result is a text value, the sql_value object uses encoding * enc. * - * If the conditions above are not met, this function returns SQL_OK + * If the conditions above are not met, this function returns 0 * and sets (*ppVal) to NULL. Or, if an error occurs, (*ppVal) is set to * NULL and an sql error code returned. */ @@ -1232,7 +1232,7 @@ valueFromFunction(sql * db, /* The database connection */ int nVal = 0; /* Size of apVal[] array */ FuncDef *pFunc = 0; /* Function definition */ sql_value *pVal = 0; /* New value */ - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ ExprList *pList = 0; /* Function arguments */ int i; /* Iterator variable */ @@ -1246,7 +1246,7 @@ valueFromFunction(sql * db, /* The database connection */ if ((pFunc->funcFlags & (SQL_FUNC_CONSTANT | SQL_FUNC_SLOCHNG)) == 0 || (pFunc->funcFlags & SQL_FUNC_NEEDCOLL) ) { - return SQL_OK; + return 0; } if (pList) { @@ -1261,7 +1261,7 @@ valueFromFunction(sql * db, /* The database connection */ for (i = 0; i < nVal; i++) { rc = sqlValueFromExpr(db, pList->a[i].pExpr, type, &apVal[i]); - if (apVal[i] == 0 || rc != SQL_OK) + if (apVal[i] == 0 || rc != 0) goto value_from_function_out; } } @@ -1279,10 +1279,10 @@ valueFromFunction(sql * db, /* The database connection */ pFunc->xSFunc(&ctx, nVal, apVal); assert(!ctx.is_aborted); sql_value_apply_type(pVal, type); - assert(rc == SQL_OK); + assert(rc == 0); value_from_function_out: - if (rc != SQL_OK) { + if (rc != 0) { pVal = 0; } if (apVal) { @@ -1319,7 +1319,7 @@ valueFromExpr(sql * db, /* The database connection */ sql_value *pVal = 0; int negInt = 1; const char *zNeg = ""; - int rc = SQL_OK; + int rc = 0; assert(pExpr != 0); while ((op = pExpr->op) == TK_UPLUS || op == TK_SPAN) @@ -1336,7 +1336,7 @@ valueFromExpr(sql * db, /* The database connection */ if (op == TK_CAST) { rc = valueFromExpr(db, pExpr->pLeft, pExpr->type, ppVal, pCtx); - testcase(rc != SQL_OK); + testcase(rc != 0); if (*ppVal) { sqlVdbeMemCast(*ppVal, pExpr->type); sql_value_apply_type(*ppVal, type); @@ -1380,10 +1380,10 @@ valueFromExpr(sql * db, /* The database connection */ pVal->flags &= ~MEM_Str; } else if (op == TK_UMINUS) { /* This branch happens for multiple negative signs. Ex: -(-5) */ - if (SQL_OK == + if (0 == sqlValueFromExpr(db, pExpr->pLeft, type, &pVal) && pVal != 0) { - if ((rc = sqlVdbeMemNumerify(pVal)) != SQL_OK) + if ((rc = sqlVdbeMemNumerify(pVal)) != 0) return rc; if (pVal->flags & MEM_Real) { pVal->u.r = -pVal->u.r; @@ -1399,7 +1399,7 @@ valueFromExpr(sql * db, /* The database connection */ pVal = valueNew(db, pCtx); if (pVal == 0) goto no_mem; - if ((rc = sqlVdbeMemNumerify(pVal)) != SQL_OK) + if ((rc = sqlVdbeMemNumerify(pVal)) != 0) return rc; } #ifndef SQL_OMIT_BLOB_LITERAL @@ -1531,7 +1531,7 @@ stat4ValueFromExpr(Parse * pParse, /* Parse context */ sql_value ** ppVal /* OUT: New value object (or NULL) */ ) { - int rc = SQL_OK; + int rc = 0; sql_value *pVal = 0; sql *db = pParse->db; @@ -1555,7 +1555,7 @@ stat4ValueFromExpr(Parse * pParse, /* Parse context */ if (pVal) { rc = sqlVdbeMemCopy((Mem *) pVal, &v->aVar[iBindVar - 1]); - if (rc == SQL_OK) { + if (rc == 0) { sql_value_apply_type(pVal, type); } pVal->db = pParse->db; @@ -1600,7 +1600,7 @@ stat4ValueFromExpr(Parse * pParse, /* Parse context */ * is NULL and a value can be successfully extracted, a new UnpackedRecord * is allocated (and *ppRec set to point to it) before returning. * - * Unless an error is encountered, SQL_OK is returned. It is not an + * Unless an error is encountered, 0 is returned. It is not an * error if a value cannot be extracted from pExpr. If an error does * occur, an sql error code is returned. */ @@ -1614,7 +1614,7 @@ sqlStat4ProbeSetValue(Parse * pParse, /* Parse context */ int *pnExtract /* OUT: Values appended to the record */ ) { - int rc = SQL_OK; + int rc = 0; int nExtract = 0; if (pExpr == 0 || pExpr->op != TK_SELECT) { @@ -1649,8 +1649,8 @@ sqlStat4ProbeSetValue(Parse * pParse, /* Parse context */ * as described for sqlStat4ProbeSetValue() above. * * If successful, set *ppVal to point to a new value object and return - * SQL_OK. If no value can be extracted, but no other error occurs - * (e.g. OOM), return SQL_OK and set *ppVal to NULL. Or, if an error + * 0. If no value can be extracted, but no other error occurs + * (e.g. OOM), return 0 and set *ppVal to NULL. Or, if an error * does occur, return an sql error code. The final value of *ppVal * is undefined in this case. */ diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c index da9ee3e..f7fc8e1 100644 --- a/src/box/sql/vdbesort.c +++ b/src/box/sql/vdbesort.c @@ -500,7 +500,7 @@ vdbePmaReaderClear(PmaReader * pReadr) /* * Read the next nByte bytes of data from the PMA p. * If successful, set *ppOut to point to a buffer containing the data - * and return SQL_OK. Otherwise, if an error occurs, return an sql + * and return 0. Otherwise, if an error occurs, return an sql * error code. * * The buffer returned in *ppOut is only valid until the @@ -518,7 +518,7 @@ vdbePmaReadBlob(PmaReader * p, /* PmaReader from which to take the blob */ if (p->aMap) { *ppOut = &p->aMap[p->iReadOff]; p->iReadOff += nByte; - return SQL_OK; + return 0; } assert(p->aBuffer); @@ -543,7 +543,7 @@ vdbePmaReadBlob(PmaReader * p, /* PmaReader from which to take the blob */ /* Readr data from the file. Return early if an error occurs. */ rc = sqlOsRead(p->pFd, p->aBuffer, nRead, p->iReadOff); assert(rc != SQL_IOERR_SHORT_READ); - if (rc != SQL_OK) + if (rc != 0) return rc; } nAvail = p->nBuffer - iBuf; @@ -594,7 +594,7 @@ vdbePmaReadBlob(PmaReader * p, /* PmaReader from which to take the blob */ if (nRem > p->nBuffer) nCopy = p->nBuffer; rc = vdbePmaReadBlob(p, nCopy, &aNext); - if (rc != SQL_OK) + if (rc != 0) return rc; assert(aNext != p->aAlloc); memcpy(&p->aAlloc[nByte - nRem], aNext, nCopy); @@ -604,7 +604,7 @@ vdbePmaReadBlob(PmaReader * p, /* PmaReader from which to take the blob */ *ppOut = p->aAlloc; } - return SQL_OK; + return 0; } /* @@ -636,14 +636,14 @@ vdbePmaReadVarint(PmaReader * p, u64 * pnOut) } } - return SQL_OK; + return 0; } /* * Attempt to memory map file pFile. If successful, set *pp to point to the - * new mapping and return SQL_OK. If the mapping is not attempted + * new mapping and return 0. If the mapping is not attempted * (because the file is too large or the VFS layer is configured not to use - * mmap), return SQL_OK and set *pp to NULL. + * mmap), return 0 and set *pp to NULL. * * Or, if an error occurs, return an sql error code. The final value of * *pp is undefined in this case. @@ -651,13 +651,13 @@ vdbePmaReadVarint(PmaReader * p, u64 * pnOut) static int vdbeSorterMapFile(SortSubtask * pTask, SorterFile * pFile, u8 ** pp) { - int rc = SQL_OK; + int rc = 0; if (pFile->iEof <= (i64) (pTask->pSorter->db->nMaxSorterMmap)) { sql_file *pFd = pFile->pFd; if (pFd->pMethods->iVersion >= 3) { rc = sqlOsFetch(pFd, 0, (int)pFile->iEof, (void **)pp); - testcase(rc != SQL_OK); + testcase(rc != 0); } } return rc; @@ -665,7 +665,7 @@ vdbeSorterMapFile(SortSubtask * pTask, SorterFile * pFile, u8 ** pp) /* * Attach PmaReader pReadr to file pFile (if it is not already attached to - * that file) and seek it to offset iOff within the file. Return SQL_OK + * that file) and seek it to offset iOff within the file. Return 0 * if successful, or an sql error code if an error occurs. */ static int @@ -675,7 +675,7 @@ vdbePmaReaderSeek(SortSubtask * pTask, /* Task context */ i64 iOff /* Offset in pFile */ ) { - int rc = SQL_OK; + int rc = 0; assert(pReadr->pIncr == 0 || pReadr->pIncr->bEof == 0); @@ -688,7 +688,7 @@ vdbePmaReaderSeek(SortSubtask * pTask, /* Task context */ pReadr->pFd = pFile->pFd; rc = vdbeSorterMapFile(pTask, pFile, &pReadr->aMap); - if (rc == SQL_OK && pReadr->aMap == 0) { + if (rc == 0 && pReadr->aMap == 0) { int pgsz = pTask->pSorter->pgsz; int iBuf = pReadr->iReadOff % pgsz; if (pReadr->aBuffer == 0) { @@ -697,14 +697,14 @@ vdbePmaReaderSeek(SortSubtask * pTask, /* Task context */ rc = SQL_NOMEM; pReadr->nBuffer = pgsz; } - if (rc == SQL_OK && iBuf) { + if (rc == 0 && iBuf) { int nRead = pgsz - iBuf; if ((pReadr->iReadOff + nRead) > pReadr->iEof) { nRead = (int)(pReadr->iEof - pReadr->iReadOff); } rc = sqlOsRead(pReadr->pFd, &pReadr->aBuffer[iBuf], nRead, pReadr->iReadOff); - testcase(rc != SQL_OK); + testcase(rc != 0); } } @@ -712,13 +712,13 @@ vdbePmaReaderSeek(SortSubtask * pTask, /* Task context */ } /* - * Advance PmaReader pReadr to the next key in its PMA. Return SQL_OK if + * Advance PmaReader pReadr to the next key in its PMA. Return 0 if * no error occurs, or an sql error code if one does. */ static int vdbePmaReaderNext(PmaReader * pReadr) { - int rc = SQL_OK; /* Return Code */ + int rc = 0; /* Return Code */ u64 nRec = 0; /* Size of record in bytes */ if (pReadr->iReadOff >= pReadr->iEof) { @@ -726,7 +726,7 @@ vdbePmaReaderNext(PmaReader * pReadr) int bEof = 1; if (pIncr) { rc = vdbeIncrSwap(pIncr); - if (rc == SQL_OK && pIncr->bEof == 0) { + if (rc == 0 && pIncr->bEof == 0) { rc = vdbePmaReaderSeek(pIncr->pTask, pReadr, &pIncr->aFile[0], pIncr->iStartOff); @@ -737,18 +737,18 @@ vdbePmaReaderNext(PmaReader * pReadr) if (bEof) { /* This is an EOF condition */ vdbePmaReaderClear(pReadr); - testcase(rc != SQL_OK); + testcase(rc != 0); return rc; } } - if (rc == SQL_OK) { + if (rc == 0) { rc = vdbePmaReadVarint(pReadr, &nRec); } - if (rc == SQL_OK) { + if (rc == 0) { pReadr->nKey = (int)nRec; rc = vdbePmaReadBlob(pReadr, (int)nRec, &pReadr->aKey); - testcase(rc != SQL_OK); + testcase(rc != 0); } return rc; @@ -779,14 +779,14 @@ vdbePmaReaderInit(SortSubtask * pTask, /* Task context */ assert(pReadr->aMap == 0); rc = vdbePmaReaderSeek(pTask, pReadr, pFile, iStart); - if (rc == SQL_OK) { + if (rc == 0) { u64 nByte = 0; /* Size of PMA in bytes */ rc = vdbePmaReadVarint(pReadr, &nByte); pReadr->iEof = pReadr->iReadOff + nByte; *pnByte += nByte; } - if (rc == SQL_OK) { + if (rc == 0) { rc = vdbePmaReaderNext(pReadr); } return rc; @@ -842,7 +842,7 @@ vdbeSorterCompare(struct SortSubtask *task, bool *key2_cached, * The sorter can guarantee a stable sort when running in single-threaded * mode, but not in multi-threaded mode. * - * SQL_OK is returned if successful, or an sql error code otherwise. + * 0 is returned if successful, or an sql error code otherwise. */ int sqlVdbeSorterInit(sql * db, /* Database connection (for malloc()) */ @@ -852,7 +852,7 @@ sqlVdbeSorterInit(sql * db, /* Database connection (for malloc()) */ int pgsz; /* Page size of main database */ int i; /* Used to iterate through aTask[] */ VdbeSorter *pSorter; /* The new sorter */ - int rc = SQL_OK; + int rc = 0; #if SQL_MAX_WORKER_THREADS==0 #define nWorker 0 #else @@ -1022,7 +1022,7 @@ vdbeSorterBlockDebug(SortSubtask * pTask, int bBlocked, const char *zEvent) static int vdbeSorterJoinThread(SortSubtask * pTask) { - int rc = SQL_OK; + int rc = 0; if (pTask->pThread) { #ifdef SQL_DEBUG_SORTER_THREADS int bDone = pTask->bDone; @@ -1073,14 +1073,14 @@ vdbeSorterJoinAll(VdbeSorter * pSorter, int rcin) for (i = pSorter->nTask - 1; i >= 0; i--) { SortSubtask *pTask = &pSorter->aTask[i]; int rc2 = vdbeSorterJoinThread(pTask); - if (rc == SQL_OK) + if (rc == 0) rc = rc2; } return rc; } #else #define vdbeSorterJoinAll(x,rcin) (rcin) -#define vdbeSorterJoinThread(pTask) SQL_OK +#define vdbeSorterJoinThread(pTask) 0 #endif /* @@ -1157,7 +1157,7 @@ void sqlVdbeSorterReset(sql * db, VdbeSorter * pSorter) { int i; - (void)vdbeSorterJoinAll(pSorter, SQL_OK); + (void)vdbeSorterJoinAll(pSorter, 0); assert(pSorter->bUseThreads || pSorter->pReader == 0); #if SQL_MAX_WORKER_THREADS>0 if (pSorter->pReader) { @@ -1231,7 +1231,7 @@ vdbeSorterExtendFile(sql * db, sql_file * pFd, i64 nByte) /* * Allocate space for a file-handle and open a temporary file. If successful, - * set *ppFd to point to the malloc'd file-handle and return SQL_OK. + * set *ppFd to point to the malloc'd file-handle and return 0. * Otherwise, set *ppFd to 0 and return an sql error code. */ static int @@ -1244,7 +1244,7 @@ vdbeSorterOpenTempFile(sql * db, /* Database handle doing sort */ SQL_OPEN_READWRITE | SQL_OPEN_CREATE | SQL_OPEN_EXCLUSIVE | SQL_OPEN_DELETEONCLOSE, &rc); - if (rc == SQL_OK) { + if (rc == 0) { i64 max = SQL_MAX_MMAP_SIZE; sqlOsFileControlHint(*ppFd, SQL_FCNTL_MMAP_SIZE, (void *)&max); @@ -1257,7 +1257,7 @@ vdbeSorterOpenTempFile(sql * db, /* Database handle doing sort */ /* * If it has not already been allocated, allocate the UnpackedRecord - * structure at pTask->pUnpacked. Return SQL_OK if successful (or + * structure at pTask->pUnpacked. Return 0 if successful (or * if no allocation was required), or SQL_NOMEM otherwise. */ static int @@ -1272,7 +1272,7 @@ vdbeSortAllocUnpacked(SortSubtask * pTask) pTask->pUnpacked->nField = pTask->pSorter->key_def->part_count; pTask->pUnpacked->errCode = 0; } - return SQL_OK; + return 0; } /* @@ -1330,7 +1330,7 @@ vdbeSorterGetCompare(VdbeSorter * p) /* * Sort the linked list of records headed at pTask->pList. Return - * SQL_OK if successful, or an sql error code (i.e. SQL_NOMEM) if + * 0 if successful, or an sql error code (i.e. SQL_NOMEM) if * an error occurs. */ static int @@ -1342,7 +1342,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList) int rc; rc = vdbeSortAllocUnpacked(pTask); - if (rc != SQL_OK) + if (rc != 0) return rc; p = pList->pList; @@ -1388,7 +1388,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList) pList->pList = p; sql_free(aSlot); - assert(pTask->pUnpacked->errCode == SQL_OK + assert(pTask->pUnpacked->errCode == 0 || pTask->pUnpacked->errCode == SQL_NOMEM); return pTask->pUnpacked->errCode; } @@ -1416,7 +1416,7 @@ vdbePmaWriterInit(sql_file * pFd, /* File handle to write to */ } /* - * Write nData bytes of data to the PMA. Return SQL_OK + * Write nData bytes of data to the PMA. Return 0 * if successful, or an sql error code if an error occurs. */ static void @@ -1448,7 +1448,7 @@ vdbePmaWriteBlob(PmaWriter * p, u8 * pData, int nData) /* * Flush any buffered data to disk and clean up the PMA-writer object. * The results of using the PMA-writer after this call are undefined. - * Return SQL_OK if flushing the buffered data succeeds or is not + * Return 0 if flushing the buffered data succeeds or is not * required. Otherwise, return an sql error code. * * Before returning, set *piEof to the offset immediately following the @@ -1473,7 +1473,7 @@ vdbePmaWriterFinish(PmaWriter * p, i64 * piEof) /* * Write value iVal encoded as a varint to the PMA. Return - * SQL_OK if successful, or an sql error code if an error occurs. + * 0 if successful, or an sql error code if an error occurs. */ static void vdbePmaWriteVarint(PmaWriter * p, u64 iVal) @@ -1486,7 +1486,7 @@ vdbePmaWriteVarint(PmaWriter * p, u64 iVal) /* * Write the current contents of in-memory linked-list pList to a level-0 - * PMA in the temp file belonging to sub-task pTask. Return SQL_OK if + * PMA in the temp file belonging to sub-task pTask. Return 0 if * successful, or an sql error code otherwise. * * The format of a PMA is: @@ -1502,7 +1502,7 @@ static int vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList) { sql *db = pTask->pSorter->db; - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ PmaWriter writer; /* Object used to write to the file */ #ifdef SQL_DEBUG @@ -1520,23 +1520,23 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList) /* If the first temporary PMA file has not been opened, open it now. */ if (pTask->file.pFd == 0) { rc = vdbeSorterOpenTempFile(db, 0, &pTask->file.pFd); - assert(rc != SQL_OK || pTask->file.pFd); + assert(rc != 0 || pTask->file.pFd); assert(pTask->file.iEof == 0); assert(pTask->nPMA == 0); } /* Try to get the file to memory map */ - if (rc == SQL_OK) { + if (rc == 0) { vdbeSorterExtendFile(db, pTask->file.pFd, pTask->file.iEof + pList->szPMA + 9); } /* Sort the list */ - if (rc == SQL_OK) { + if (rc == 0) { rc = vdbeSorterSort(pTask, pList); } - if (rc == SQL_OK) { + if (rc == 0) { SorterRecord *p; SorterRecord *pNext = 0; @@ -1556,8 +1556,8 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList) } vdbeSorterWorkDebug(pTask, "exit"); - assert(rc != SQL_OK || pList->pList == 0); - assert(rc != SQL_OK || pTask->file.iEof == iSz); + assert(rc != 0 || pList->pList == 0); + assert(rc != 0 || pTask->file.iEof == iSz); return rc; } @@ -1566,7 +1566,7 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList) * Set *pbEof to true there is no next entry because * the MergeEngine has reached the end of all its inputs. * - * Return SQL_OK if successful or an error code if an error occurs. + * Return 0 if successful or an error code if an error occurs. */ static int vdbeMergeEngineStep(MergeEngine * pMerger, /* The merge engine to advance to the next row */ @@ -1581,7 +1581,7 @@ vdbeMergeEngineStep(MergeEngine * pMerger, /* The merge engine to advance to the rc = vdbePmaReaderNext(&pMerger->aReadr[iPrev]); /* Update contents of aTree[] */ - if (rc == SQL_OK) { + if (rc == 0) { int i; /* Index of aTree[] to recalculate */ PmaReader *pReadr1; /* First PmaReader to compare */ PmaReader *pReadr2; /* Second PmaReader to compare */ @@ -1642,7 +1642,7 @@ vdbeMergeEngineStep(MergeEngine * pMerger, /* The merge engine to advance to the *pbEof = (pMerger->aReadr[pMerger->aTree[1]].pFd == 0); } - return (rc == SQL_OK ? pTask->pUnpacked->errCode : rc); + return (rc == 0 ? pTask->pUnpacked->errCode : rc); } #if SQL_MAX_WORKER_THREADS>0 @@ -1672,7 +1672,7 @@ vdbeSorterFlushPMA(VdbeSorter * pSorter) pSorter->bUsePMA = 1; return vdbeSorterListToPMA(&pSorter->aTask[0], &pSorter->list); #else - int rc = SQL_OK; + int rc = 0; int i; SortSubtask *pTask = 0; /* Thread context used to create new PMA */ int nWorker = (pSorter->nTask - 1); @@ -1697,11 +1697,11 @@ vdbeSorterFlushPMA(VdbeSorter * pSorter) if (pTask->bDone) { rc = vdbeSorterJoinThread(pTask); } - if (rc != SQL_OK || pTask->pThread == 0) + if (rc != 0 || pTask->pThread == 0) break; } - if (rc == SQL_OK) { + if (rc == 0) { if (i == nWorker) { /* Use the foreground thread for this operation */ rc = vdbeSorterListToPMA(&pSorter->aTask[nWorker], @@ -1749,7 +1749,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr, /* Sorter cursor */ ) { VdbeSorter *pSorter; - int rc = SQL_OK; /* Return Code */ + int rc = 0; /* Return Code */ SorterRecord *pNew; /* New list element */ int bFlush; /* True to flush contents of memory to PMA */ int nReq; /* Bytes of memory required */ @@ -1801,7 +1801,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr, /* Sorter cursor */ rc = vdbeSorterFlushPMA(pSorter); pSorter->list.szPMA = 0; pSorter->iMemory = 0; - assert(rc != SQL_OK || pSorter->list.pList == 0); + assert(rc != 0 || pSorter->list.pList == 0); } } @@ -1864,7 +1864,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr, /* Sorter cursor */ static int vdbeIncrPopulate(IncrMerger * pIncr) { - int rc = SQL_OK; + int rc = 0; int rc2; i64 iStart = pIncr->iStartOff; SorterFile *pOut = &pIncr->aFile[1]; @@ -1876,7 +1876,7 @@ vdbeIncrPopulate(IncrMerger * pIncr) vdbeSorterPopulateDebug(pTask, "enter"); vdbePmaWriterInit(pOut->pFd, &writer, pTask->pSorter->pgsz, iStart); - while (rc == SQL_OK) { + while (rc == 0) { int dummy; PmaReader *pReader = &pMerger->aReadr[pMerger->aTree[1]]; int nKey = pReader->nKey; @@ -1899,7 +1899,7 @@ vdbeIncrPopulate(IncrMerger * pIncr) } rc2 = vdbePmaWriterFinish(&writer, &pOut->iEof); - if (rc == SQL_OK) + if (rc == 0) rc = rc2; vdbeSorterPopulateDebug(pTask, "exit"); return rc; @@ -1946,24 +1946,24 @@ vdbeIncrBgPopulate(IncrMerger * pIncr) * been exhausted, this function also launches a new background thread * to populate the new aFile[1]. * - * SQL_OK is returned on success, or an sql error code otherwise. + * 0 is returned on success, or an sql error code otherwise. */ static int vdbeIncrSwap(IncrMerger * pIncr) { - int rc = SQL_OK; + int rc = 0; #if SQL_MAX_WORKER_THREADS>0 if (pIncr->bUseThread) { rc = vdbeSorterJoinThread(pIncr->pTask); - if (rc == SQL_OK) { + if (rc == 0) { SorterFile f0 = pIncr->aFile[0]; pIncr->aFile[0] = pIncr->aFile[1]; pIncr->aFile[1] = f0; } - if (rc == SQL_OK) { + if (rc == 0) { if (pIncr->aFile[0].iEof == pIncr->iStartOff) { pIncr->bEof = 1; } else { @@ -1995,7 +1995,7 @@ vdbeIncrMergerNew(SortSubtask * pTask, /* The thread that will be using the new IncrMerger ** ppOut /* Write the new IncrMerger here */ ) { - int rc = SQL_OK; + int rc = 0; IncrMerger *pIncr = *ppOut = (IncrMerger *) sqlMallocZero(sizeof(*pIncr)); if (pIncr) { @@ -2109,7 +2109,7 @@ static int vdbePmaReaderIncrInit(PmaReader * pReadr, int eMode); * vdbePmaReaderIncrMergeInit() to initialize each PmaReader that feeds data * to pMerger. * - * SQL_OK is returned if successful, or an sql error code otherwise. + * 0 is returned if successful, or an sql error code otherwise. */ static int vdbeMergeEngineInit(SortSubtask * pTask, /* Thread that will run pMerger */ @@ -2117,7 +2117,7 @@ vdbeMergeEngineInit(SortSubtask * pTask, /* Thread that will run pMerger */ int eMode /* One of the INCRINIT_XXX constants */ ) { - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ int i; /* For looping over PmaReader objects */ int nTree = pMerger->nTree; @@ -2143,7 +2143,7 @@ vdbeMergeEngineInit(SortSubtask * pTask, /* Thread that will run pMerger */ rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i], INCRINIT_NORMAL); } - if (rc != SQL_OK) + if (rc != 0) return rc; } @@ -2184,12 +2184,12 @@ vdbeMergeEngineInit(SortSubtask * pTask, /* Thread that will run pMerger */ * In this case vdbePmaReaderNext() is called on all child PmaReaders and * the current PmaReader set to point to the first key in its range. * - * SQL_OK is returned if successful, or an sql error code otherwise. + * 0 is returned if successful, or an sql error code otherwise. */ static int vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode) { - int rc = SQL_OK; + int rc = 0; IncrMerger *pIncr = pReadr->pIncr; SortSubtask *pTask = pIncr->pTask; sql *db = pTask->pSorter->db; @@ -2203,13 +2203,13 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode) * requires two temp files to itself, whereas a single-threaded object * only requires a region of pTask->file2. */ - if (rc == SQL_OK) { + if (rc == 0) { int mxSz = pIncr->mxSz; #if SQL_MAX_WORKER_THREADS>0 if (pIncr->bUseThread) { rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[0].pFd); - if (rc == SQL_OK) { + if (rc == 0) { rc = vdbeSorterOpenTempFile(db, mxSz, &pIncr->aFile[1]. pFd); @@ -2224,7 +2224,7 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode) &pTask->file2.pFd); pTask->file2.iEof = 0; } - if (rc == SQL_OK) { + if (rc == 0) { pIncr->aFile[1].pFd = pTask->file2.pFd; pIncr->iStartOff = pTask->file2.iEof; pTask->file2.iEof += mxSz; @@ -2232,7 +2232,7 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode) } } #if SQL_MAX_WORKER_THREADS>0 - if (rc == SQL_OK && pIncr->bUseThread) { + if (rc == 0 && pIncr->bUseThread) { /* Use the current thread to populate aFile[1], even though this * PmaReader is multi-threaded. If this is an INCRINIT_TASK object, * then this function is already running in background thread @@ -2248,7 +2248,7 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr, int eMode) } #endif - if (rc == SQL_OK + if (rc == 0 && (SQL_MAX_WORKER_THREADS == 0 || eMode != INCRINIT_TASK)) { rc = vdbePmaReaderNext(pReadr); } @@ -2288,7 +2288,7 @@ static int vdbePmaReaderIncrInit(PmaReader * pReadr, int eMode) { IncrMerger *pIncr = pReadr->pIncr; /* Incremental merger */ - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ if (pIncr) { #if SQL_MAX_WORKER_THREADS>0 assert(pIncr->bUseThread == 0 || eMode == INCRINIT_TASK); @@ -2309,7 +2309,7 @@ vdbePmaReaderIncrInit(PmaReader * pReadr, int eMode) /* * Allocate a new MergeEngine object to merge the contents of nPMA level-0 * PMAs from pTask->file. If no error occurs, set *ppOut to point to - * the new object and return SQL_OK. Or, if an error does occur, set *ppOut + * the new object and return 0. Or, if an error does occur, set *ppOut * to NULL and return an sql error code. * * When this function is called, *piOffset is set to the offset of the @@ -2328,13 +2328,13 @@ vdbeMergeEngineLevel0(SortSubtask * pTask, /* Sorter task to read from */ MergeEngine *pNew; /* Merge engine to return */ i64 iOff = *piOffset; int i; - int rc = SQL_OK; + int rc = 0; *ppOut = pNew = vdbeMergeEngineNew(nPMA); if (pNew == 0) rc = SQL_NOMEM; - for (i = 0; i < nPMA && rc == SQL_OK; i++) { + for (i = 0; i < nPMA && rc == 0; i++) { i64 nDummy = 0; PmaReader *pReadr = &pNew->aReadr[i]; rc = vdbePmaReaderInit(pTask, &pTask->file, iOff, pReadr, @@ -2342,7 +2342,7 @@ vdbeMergeEngineLevel0(SortSubtask * pTask, /* Sorter task to read from */ iOff = pReadr->iEof; } - if (rc != SQL_OK) { + if (rc != 0) { vdbeMergeEngineFree(pNew); *ppOut = 0; } @@ -2377,7 +2377,7 @@ vdbeSorterTreeDepth(int nPMA) * to vdbeSorterTreeDepth()). pLeaf is the iSeq'th leaf to be added to the * tree, counting from zero. This function adds pLeaf to the tree. * - * If successful, SQL_OK is returned. If an error occurs, an sql error + * If successful, 0 is returned. If an error occurs, an sql error * code is returned and pLeaf is freed. */ static int @@ -2388,7 +2388,7 @@ vdbeSorterAddToTree(SortSubtask * pTask, /* Task context */ MergeEngine * pLeaf /* Leaf to add to tree */ ) { - int rc = SQL_OK; + int rc = 0; int nDiv = 1; int i; MergeEngine *p = pRoot; @@ -2400,7 +2400,7 @@ vdbeSorterAddToTree(SortSubtask * pTask, /* Task context */ nDiv = nDiv * SORTER_MAX_MERGE_COUNT; } - for (i = 1; i < nDepth && rc == SQL_OK; i++) { + for (i = 1; i < nDepth && rc == 0; i++) { int iIter = (iSeq / nDiv) % SORTER_MAX_MERGE_COUNT; PmaReader *pReadr = &p->aReadr[iIter]; @@ -2414,13 +2414,13 @@ vdbeSorterAddToTree(SortSubtask * pTask, /* Task context */ &pReadr->pIncr); } } - if (rc == SQL_OK) { + if (rc == 0) { p = pReadr->pIncr->pMerger; nDiv = nDiv / SORTER_MAX_MERGE_COUNT; } } - if (rc == SQL_OK) { + if (rc == 0) { p->aReadr[iSeq % SORTER_MAX_MERGE_COUNT].pIncr = pIncr; } else { vdbeIncrFree(pIncr); @@ -2434,7 +2434,7 @@ vdbeSorterAddToTree(SortSubtask * pTask, /* Task context */ * files. It builds a tree of MergeEngine/IncrMerger/PmaReader objects that * can be used to incrementally merge all PMAs on disk. * - * If successful, SQL_OK is returned and *ppOut set to point to the + * If successful, 0 is returned and *ppOut set to point to the * MergeEngine object at the root of the tree before returning. Or, if an * error occurs, an sql error code is returned and the final value * of *ppOut is undefined. @@ -2445,7 +2445,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter, /* The VDBE cursor that implement ) { MergeEngine *pMain = 0; - int rc = SQL_OK; + int rc = 0; int iTask; #if SQL_MAX_WORKER_THREADS>0 @@ -2461,7 +2461,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter, /* The VDBE cursor that implement } #endif - for (iTask = 0; rc == SQL_OK && iTask < pSorter->nTask; iTask++) { + for (iTask = 0; rc == 0 && iTask < pSorter->nTask; iTask++) { SortSubtask *pTask = &pSorter->aTask[iTask]; assert(pTask->nPMA > 0 || SQL_MAX_WORKER_THREADS > 0); if (SQL_MAX_WORKER_THREADS == 0 || pTask->nPMA) { @@ -2479,7 +2479,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter, /* The VDBE cursor that implement vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT); if (pRoot == 0) rc = SQL_NOMEM; - for (i = 0; i < pTask->nPMA && rc == SQL_OK; + for (i = 0; i < pTask->nPMA && rc == 0; i += SORTER_MAX_MERGE_COUNT) { MergeEngine *pMerger = 0; /* New level-0 PMA merger */ int nReader; /* Number of level-0 PMAs to merge */ @@ -2491,7 +2491,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter, /* The VDBE cursor that implement nReader, &iReadOff, &pMerger); - if (rc == SQL_OK) { + if (rc == 0) { rc = vdbeSorterAddToTree(pTask, nDepth, iSeq++, @@ -2501,7 +2501,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter, /* The VDBE cursor that implement } } - if (rc == SQL_OK) { + if (rc == 0) { #if SQL_MAX_WORKER_THREADS>0 if (pMain != 0) { rc = vdbeIncrMergerNew(pTask, pRoot, @@ -2520,7 +2520,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter, /* The VDBE cursor that implement } } - if (rc != SQL_OK) { + if (rc != 0) { vdbeMergeEngineFree(pMain); pMain = 0; } @@ -2535,7 +2535,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter, /* The VDBE cursor that implement * (for multi-threaded sorters) so that it can be used to iterate through * all records stored in the sorter. * - * SQL_OK is returned if successful, or an sql error code otherwise. + * 0 is returned if successful, or an sql error code otherwise. */ static int vdbeSorterSetupMerge(VdbeSorter * pSorter) @@ -2553,7 +2553,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter) #endif rc = vdbeSorterMergeTreeBuild(pSorter, &pMain); - if (rc == SQL_OK) { + if (rc == 0) { #if SQL_MAX_WORKER_THREADS assert(pSorter->bUseThreads == 0 || pSorter->nTask > 1); if (pSorter->bUseThreads) { @@ -2562,7 +2562,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter) SortSubtask *pLast = &pSorter->aTask[pSorter->nTask - 1]; rc = vdbeSortAllocUnpacked(pLast); - if (rc == SQL_OK) { + if (rc == 0) { pReadr = (PmaReader *) sqlDbMallocZero(db, sizeof @@ -2571,10 +2571,10 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter) if (pReadr == 0) rc = SQL_NOMEM; } - if (rc == SQL_OK) { + if (rc == 0) { rc = vdbeIncrMergerNew(pLast, pMain, &pReadr->pIncr); - if (rc == SQL_OK) { + if (rc == 0) { vdbeIncrMergerSetThreads(pReadr->pIncr); for (iTask = 0; iTask < (pSorter->nTask - 1); @@ -2590,7 +2590,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter) } } for (iTask = 0; - rc == SQL_OK + rc == 0 && iTask < pSorter->nTask; iTask++) { /* Check that: @@ -2613,7 +2613,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter) } pMain = 0; } - if (rc == SQL_OK) { + if (rc == 0) { rc = vdbePmaReaderIncrMergeInit(pReadr, INCRINIT_ROOT); } @@ -2627,7 +2627,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter) } } - if (rc != SQL_OK) { + if (rc != 0) { vdbeMergeEngineFree(pMain); } return rc; @@ -2642,7 +2642,7 @@ int sqlVdbeSorterRewind(const VdbeCursor * pCsr, int *pbEof) { VdbeSorter *pSorter; - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ assert(pCsr->eCurType == CURTYPE_SORTER); pSorter = pCsr->uc.pSorter; @@ -2679,7 +2679,7 @@ sqlVdbeSorterRewind(const VdbeCursor * pCsr, int *pbEof) * incrementally read and merge all remaining PMAs. */ assert(pSorter->pReader == 0); - if (rc == SQL_OK) { + if (rc == 0) { rc = vdbeSorterSetupMerge(pSorter); *pbEof = 0; } @@ -2723,7 +2723,7 @@ sqlVdbeSorterNext(sql * db, const VdbeCursor * pCsr, int *pbEof) if (pSorter->list.aMemory == 0) vdbeSorterRecordFree(db, pFree); *pbEof = !pSorter->list.pList; - rc = SQL_OK; + rc = 0; } return rc; } @@ -2779,7 +2779,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut) MemSetTypeFlag(pOut, MEM_Blob); memcpy(pOut->z, pKey, nKey); - return SQL_OK; + return 0; } /* @@ -2828,10 +2828,10 @@ sqlVdbeSorterCompare(const VdbeCursor * pCsr, /* Sorter cursor */ for (i = 0; i < nKeyCol; i++) { if (r2->aMem[i].flags & MEM_Null) { *pRes = -1; - return SQL_OK; + return 0; } } *pRes = sqlVdbeRecordCompareMsgpack(pVal->z, r2); - return SQL_OK; + return 0; } diff --git a/src/box/sql/where.c b/src/box/sql/where.c index 19ee2d0..c716a0e 100644 --- a/src/box/sql/where.c +++ b/src/box/sql/where.c @@ -1176,7 +1176,7 @@ whereRangeAdjust(WhereTerm * pTerm, LogEst nNew) * is left as is. * * If an error occurs, an sql error code is returned. Otherwise, - * SQL_OK. + * 0. */ static int whereRangeSkipScanEst(Parse * pParse, /* Parsing & code generating context */ @@ -1194,7 +1194,7 @@ whereRangeSkipScanEst(Parse * pParse, /* Parsing & code generating context */ sql *db = pParse->db; int nLower = -1; int nUpper = index->def->opts.stat->sample_count + 1; - int rc = SQL_OK; + int rc = 0; enum field_type type = p->key_def->parts[nEq].type; sql_value *p1 = 0; /* Value extracted from pLower */ @@ -1207,7 +1207,7 @@ whereRangeSkipScanEst(Parse * pParse, /* Parsing & code generating context */ type, &p1); nLower = 0; } - if (pUpper && rc == SQL_OK) { + if (pUpper && rc == 0) { rc = sqlStat4ValueFromExpr(pParse, pUpper->pExpr->pRight, type, &p2); nUpper = p2 ? 0 : index->def->opts.stat->sample_count; @@ -1218,15 +1218,15 @@ whereRangeSkipScanEst(Parse * pParse, /* Parsing & code generating context */ int nDiff; struct index_sample *samples = index->def->opts.stat->samples; uint32_t sample_count = index->def->opts.stat->sample_count; - for (i = 0; rc == SQL_OK && i < (int) sample_count; i++) { + for (i = 0; rc == 0 && i < (int) sample_count; i++) { rc = sql_stat4_column(db, samples[i].sample_key, nEq, &pVal); - if (rc == SQL_OK && p1) { + if (rc == 0 && p1) { int res = sqlMemCompare(p1, pVal, coll); if (res >= 0) nLower++; } - if (rc == SQL_OK && p2) { + if (rc == 0 && p2) { int res = sqlMemCompare(p2, pVal, coll); if (res >= 0) nUpper++; @@ -1310,7 +1310,7 @@ whereRangeScanEst(Parse * pParse, /* Parsing & code generating context */ WhereTerm * pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */ WhereLoop * pLoop) /* Modify the .nOut and maybe .rRun fields */ { - int rc = SQL_OK; + int rc = 0; int nOut = pLoop->nOut; LogEst nNew; @@ -1400,7 +1400,7 @@ whereRangeScanEst(Parse * pParse, /* Parsing & code generating context */ rc = sqlStat4ProbeSetValue(pParse, p, &pRec, pExpr, nBtm, nEq, &n); - if (rc == SQL_OK && n) { + if (rc == 0 && n) { tRowcnt iNew; u16 mask = WO_GT | WO_LE; if (sqlExprVectorSize(pExpr) > n) @@ -1426,7 +1426,7 @@ whereRangeScanEst(Parse * pParse, /* Parsing & code generating context */ rc = sqlStat4ProbeSetValue(pParse, p, &pRec, pExpr, nTop, nEq, &n); - if (rc == SQL_OK && n) { + if (rc == 0 && n) { tRowcnt iNew; u16 mask = WO_GT | WO_LE; if (sqlExprVectorSize(pExpr) > n) @@ -1446,7 +1446,7 @@ whereRangeScanEst(Parse * pParse, /* Parsing & code generating context */ } pBuilder->pRec = pRec; - if (rc == SQL_OK) { + if (rc == 0) { if (iUpper > iLower) { nNew = sqlLogEst(iUpper - iLower); /* TUNING: If both iUpper and iLower are derived from the same @@ -1514,7 +1514,7 @@ whereRangeScanEst(Parse * pParse, /* Parsing & code generating context */ * for that index. When pExpr==NULL that means the constraint is * "x IS NULL" instead of "x=VALUE". * - * Write the estimated row count into *pnRow and return SQL_OK. + * Write the estimated row count into *pnRow and return 0. * If unable to make an estimate, leave *pnRow unchanged and return * non-zero. * @@ -1549,7 +1549,7 @@ whereEqualScanEst(Parse * pParse, /* Parsing & code generating context */ rc = sqlStat4ProbeSetValue(pParse, p, &pRec, pExpr, 1, nEq - 1, &bOk); pBuilder->pRec = pRec; - if (rc != SQL_OK) + if (rc != 0) return rc; if (bOk == 0) return SQL_NOTFOUND; @@ -1570,7 +1570,7 @@ whereEqualScanEst(Parse * pParse, /* Parsing & code generating context */ * * WHERE x IN (1,2,3,4) * - * Write the estimated row count into *pnRow and return SQL_OK. + * Write the estimated row count into *pnRow and return 0. * If unable to make an estimate, leave *pnRow unchanged and return * non-zero. * @@ -1587,12 +1587,12 @@ whereInScanEst(Parse * pParse, /* Parsing & code generating context */ struct index_def *p = pBuilder->pNew->index_def; i64 nRow0 = sqlLogEstToInt(index_field_tuple_est(p, 0)); int nRecValid = pBuilder->nRecValid; - int rc = SQL_OK; /* Subfunction return code */ + int rc = 0; /* Subfunction return code */ tRowcnt nEst; /* Number of rows for a single term */ tRowcnt nRowEst = 0; /* New estimate of the number of rows */ int i; /* Loop counter */ - for (i = 0; rc == SQL_OK && i < pList->nExpr; i++) { + for (i = 0; rc == 0 && i < pList->nExpr; i++) { nEst = nRow0; rc = whereEqualScanEst(pParse, pBuilder, pList->a[i].pExpr, &nEst); @@ -1600,7 +1600,7 @@ whereInScanEst(Parse * pParse, /* Parsing & code generating context */ pBuilder->nRecValid = nRecValid; } - if (rc == SQL_OK) { + if (rc == 0) { if (nRowEst > nRow0) nRowEst = nRow0; *pnRow = nRowEst; @@ -1756,7 +1756,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n) { WhereTerm **paNew; if (p->nLSlot >= n) - return SQL_OK; + return 0; n = (n + 7) & ~7; paNew = sqlDbMallocRawNN(db, sizeof(p->aLTerm[0]) * n); if (paNew == 0) @@ -1766,7 +1766,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n) sqlDbFree(db, p->aLTerm); p->aLTerm = paNew; p->nLSlot = n; - return SQL_OK; + return 0; } /* @@ -1788,7 +1788,7 @@ whereLoopXfer(sql * db, WhereLoop * pTo, WhereLoop * pFrom) pTo->nLTerm * sizeof(pTo->aLTerm[0])); if ((pFrom->wsFlags & WHERE_AUTO_INDEX) != 0) pFrom->index_def = NULL; - return SQL_OK; + return 0; } /* @@ -2057,7 +2057,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate) } #endif } - return SQL_OK; + return 0; } /* Look for an existing WhereLoop to replace with pTemplate @@ -2075,7 +2075,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate) whereLoopPrint(pTemplate, pBuilder->pWC); } #endif - return SQL_OK; + return 0; } else { p = *ppPrev; } @@ -2319,7 +2319,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder, /* The WhereLoop factory */ u16 saved_nSkip; /* Original value of pNew->nSkip */ u32 saved_wsFlags; /* Original value of pNew->wsFlags */ LogEst saved_nOut; /* Original value of pNew->nOut */ - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ LogEst rSize; /* Number of rows in the table */ LogEst rLogSize; /* Logarithm of table size */ WhereTerm *pTop = 0, *pBtm = 0; /* Top and bottom range constraints */ @@ -2371,7 +2371,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder, /* The WhereLoop factory */ pNew->rSetup = 0; rSize = index_field_tuple_est(probe, 0); rLogSize = estLog(rSize); - for (; rc == SQL_OK && pTerm != 0; pTerm = whereScanNext(&scan)) { + for (; rc == 0 && pTerm != 0; pTerm = whereScanNext(&scan)) { u16 eOp = pTerm->eOperator; /* Shorthand for pTerm->eOperator */ LogEst rCostIdx; LogEst nOutUnadjusted; /* nOut before IN() and WHERE adjustments */ @@ -2553,8 +2553,8 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder, /* The WhereLoop factory */ &nOut); } if (rc == SQL_NOTFOUND) - rc = SQL_OK; - if (rc != SQL_OK) + rc = 0; + if (rc != 0) break; /* Jump out of the pTerm loop */ if (nOut) { pNew->nOut = @@ -2652,7 +2652,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder, /* The WhereLoop factory */ stat->skip_scan_enabled == true && /* TUNING: Minimum for skip-scan */ index_field_tuple_est(probe, saved_nEq + 1) >= 42 && - (rc = whereLoopResize(db, pNew, pNew->nLTerm + 1)) == SQL_OK) { + (rc = whereLoopResize(db, pNew, pNew->nLTerm + 1)) == 0) { LogEst nIter; pNew->nEq++; pNew->nSkip++; @@ -2761,7 +2761,7 @@ whereLoopAddBtree(WhereLoopBuilder * pBuilder, /* WHERE clause information */ SrcList *pTabList; /* The FROM clause */ struct SrcList_item *pSrc; /* The FROM clause btree term to add */ WhereLoop *pNew; /* Template WhereLoop object */ - int rc = SQL_OK; /* Return code */ + int rc = 0; /* Return code */ int iSortIdx = 1; /* Index number */ int b; /* A boolean value */ LogEst rSize; /* number of rows in the table */ @@ -2843,7 +2843,7 @@ tnt_error: /* Generate auto-index WhereLoops */ WhereTerm *pTerm; WhereTerm *pWCEnd = pWC->a + pWC->nTerm; - for (pTerm = pWC->a; rc == SQL_OK && pTerm < pWCEnd; pTerm++) { + for (pTerm = pWC->a; rc == 0 && pTerm < pWCEnd; pTerm++) { if (pTerm->prereqRight & pNew->maskSelf) continue; if (termCanDriveIndex(pTerm, pSrc, 0)) { @@ -2958,7 +2958,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable) WhereClause *pWC; WhereLoop *pNew; WhereTerm *pTerm, *pWCEnd; - int rc = SQL_OK; + int rc = 0; int iCur; WhereClause tempWC; WhereLoopBuilder sSubBuild; @@ -2972,7 +2972,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable) pItem = pWInfo->pTabList->a + pNew->iTab; iCur = pItem->iCursor; - for (pTerm = pWC->a; pTerm < pWCEnd && rc == SQL_OK; pTerm++) { + for (pTerm = pWC->a; pTerm < pWCEnd && rc == 0; pTerm++) { if ((pTerm->eOperator & WO_OR) != 0 && (pTerm->u.pOrInfo->indexable & pNew->maskSelf) != 0) { WhereClause *const pOrWC = &pTerm->u.pOrInfo->wc; @@ -3015,11 +3015,11 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable) rc = whereLoopAddBtree(&sSubBuild, mPrereq); } - if (rc == SQL_OK) { + if (rc == 0) { rc = whereLoopAddOr(&sSubBuild, mPrereq, mUnusable); } - assert(rc == SQL_OK || sCur.n == 0); + assert(rc == 0 || sCur.n == 0); if (sCur.n == 0) { sSum.n = 0; break; @@ -3052,7 +3052,7 @@ whereLoopAddOr(WhereLoopBuilder * pBuilder, Bitmask mPrereq, Bitmask mUnusable) pNew->nBtm = 0; pNew->nTop = 0; pNew->index_def = NULL; - for (i = 0; rc == SQL_OK && i < sSum.n; i++) { + for (i = 0; rc == 0 && i < sSum.n; i++) { /* TUNING: Currently sSum.a[i].rRun is set to the sum of the costs * of all sub-scans required by the OR-scan. However, due to rounding * errors, it may be that the cost of the OR-scan is equal to its @@ -3092,7 +3092,7 @@ whereLoopAddAll(WhereLoopBuilder * pBuilder) struct SrcList_item *pItem; struct SrcList_item *pEnd = &pTabList->a[pWInfo->nLevel]; sql *db = pWInfo->pParse->db; - int rc = SQL_OK; + int rc = 0; WhereLoop *pNew; u8 priorJointype = 0; @@ -3115,7 +3115,7 @@ whereLoopAddAll(WhereLoopBuilder * pBuilder) { rc = whereLoopAddBtree(pBuilder, mPrereq); } - if (rc == SQL_OK) { + if (rc == 0) { rc = whereLoopAddOr(pBuilder, mPrereq, mUnusable); } mPrior |= pNew->maskSelf; @@ -3566,7 +3566,7 @@ whereSortingCost(WhereInfo * pWInfo, LogEst nRow, int nOrderBy, int nSorted) * will be nRowEst (in the 10*log2 representation). Or, ignore sorting * costs if nRowEst==0. * - * Return SQL_OK on success or SQL_NOMEM of a memory allocation + * Return 0 on success or SQL_NOMEM of a memory allocation * error occurs. */ static int @@ -4001,7 +4001,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst) /* Free temporary memory and return success */ sqlDbFree(db, pSpace); - return SQL_OK; + return 0; } /** -- 2.7.4