[tarantool-patches] Re: [PATCH v1 07/28] sql: remove SQL_OK error/status code

Mergen Imeev imeevma at tarantool.org
Sat Jun 15 12:52:22 MSK 2019


On Fri, Jun 14, 2019 at 12:24:47AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> Consider my review fixes below and on the branch
> in a separate commit.
> 
Thank you! After rebase, he became a little shorter.
New patch:

>From 58399d0aa831ad23385988ba6ddcc5e03bec50e3 Mon Sep 17 00:00:00 2001
Date: Tue, 21 May 2019 16:31:37 +0300
Subject: [PATCH] sql: remove SQL_OK error/status code

Removing this error/status code is part of getting rid of the SQL
error system.

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/ck_constraint.c b/src/box/ck_constraint.c
index 543c8b3..1cde270 100644
--- a/src/box/ck_constraint.c
+++ b/src/box/ck_constraint.c
@@ -172,7 +172,7 @@ ck_constraint_program_run(struct ck_constraint *ck_constraint,
 	 * Get VDBE execution state and reset VM to run it
 	 * next time.
 	 */
-	return sql_reset(ck_constraint->stmt) != SQL_OK ? -1 : 0;
+	return sql_reset(ck_constraint->stmt);
 }
 
 void
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 ae92ba0..51f7b77 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();
 		}
@@ -199,7 +199,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);
@@ -214,7 +214,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);
@@ -292,12 +292,11 @@ int tarantoolsqlMovetoUnpacked(BtCursor *pCur, UnpackedRecord *pIdxKey,
 }
 
 /*
- * Count number of tuples in ephemeral space and write it to pnEntry.
+ * Count number of tuples in ephemeral space.
  *
  * @param pCur Cursor which will point to ephemeral space.
- * @param[out] pnEntry Number of tuples in ephemeral space.
  *
- * @retval SQL_OK
+ * @retval Number of tuples in ephemeral space.
  */
 int64_t
 tarantoolsqlEphemeralCount(struct BtCursor *pCur)
@@ -385,7 +384,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(). */
@@ -395,7 +394,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
@@ -411,7 +410,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,
@@ -432,7 +431,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)
 {
@@ -453,7 +452,7 @@ int tarantoolsqlEphemeralDelete(BtCursor *pCur)
 		diag_log();
 		return SQL_TARANTOOL_ERROR;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 int tarantoolsqlDelete(BtCursor *pCur, u8 flags)
@@ -476,7 +475,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
@@ -494,7 +493,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;
 }
 
 /*
@@ -504,7 +503,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)
 {
@@ -533,7 +532,7 @@ int tarantoolsqlEphemeralClearTable(BtCursor *pCur)
 	}
 	iterator_delete(it);
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -569,7 +568,7 @@ int tarantoolsqlClearTable(struct space *space, uint32_t *tuple_count)
 	}
 	iterator_delete(iter);
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -849,7 +848,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)
@@ -895,7 +894,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)
@@ -915,7 +914,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 4106bce..410d9e8 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) {
diff --git a/src/box/sql/cursor.c b/src/box/sql/cursor.c
index 2187b90..bb2dae8 100644
--- a/src/box/sql/cursor.c
+++ b/src/box/sql/cursor.c
@@ -93,12 +93,8 @@ 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
- * wrong.  An error is returned if "offset+amt" is larger than
- * the available payload.
  */
-int
+void
 sqlCursorPayload(BtCursor *pCur, u32 offset, u32 amt, void *pBuf)
 {
 	assert(pCur->eState == CURSOR_VALID);
@@ -110,7 +106,6 @@ 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;
 }
 
 /* Move the cursor so that it points to an entry near the key
diff --git a/src/box/sql/cursor.h b/src/box/sql/cursor.h
index e5c49d7..88e5441 100644
--- a/src/box/sql/cursor.h
+++ b/src/box/sql/cursor.h
@@ -64,7 +64,8 @@ int sqlCursorMovetoUnpacked(BtCursor *, UnpackedRecord * pUnKey, int *pRes);
 
 int sqlCursorNext(BtCursor *, int *pRes);
 int sqlCursorPrevious(BtCursor *, int *pRes);
-int sqlCursorPayload(BtCursor *, u32 offset, u32 amt, void *);
+void
+sqlCursorPayload(BtCursor *, u32 offset, u32 amt, void *);
 
 /**
  * Release tuple, free iterator, invalidate cursor's state.
diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index f2a2c16..4812a0a 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 3263cb2..4a49ec6 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -4340,7 +4340,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 ec4f76d..7b3c20e 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1181,7 +1181,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;
 	}
@@ -1772,7 +1772,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,
@@ -1791,7 +1791,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 3ea12dd..f0a2e3d 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -1246,7 +1246,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 1a3804e..42fd3d1 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 */
@@ -68,16 +68,15 @@ 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] != 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 == NULL);
+		if (rc != 0)
 			continue;
-		}
 		if (!pStmt) {
 			/* this happens for a comment or white-space */
 			zSql = zLeftover;
@@ -163,7 +162,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 3004ae7..1a25dde 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -89,7 +89,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
@@ -103,17 +103,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
@@ -134,12 +134,8 @@ sql_initialize(void)
 		memset(&sqlBuiltinFunctions, 0,
 		       sizeof(sqlBuiltinFunctions));
 		sqlRegisterBuiltinFunctions();
-		if (rc == SQL_OK) {
-			rc = sqlOsInit();
-		}
-		if (rc == SQL_OK) {
-			sqlGlobalConfig.isInit = 1;
-		}
+		sql_os_init();
+		sqlGlobalConfig.isInit = 1;
 		sqlGlobalConfig.inProgress = 0;
 	}
 
@@ -150,17 +146,14 @@ sql_initialize(void)
 	 */
 #ifndef NDEBUG
 	/* This section of code's only "output" is via assert() statements. */
-	if (rc == SQL_OK) {
-		u64 x = (((u64) 1) << 63) - 1;
-		double y;
-		assert(sizeof(x) == 8);
-		assert(sizeof(x) == sizeof(y));
-		memcpy(&y, &x, 8);
-		assert(sqlIsNaN(y));
-	}
+	u64 x = (((u64) 1) << 63) - 1;
+	double y;
+	assert(sizeof(x) == 8);
+	assert(sizeof(x) == sizeof(y));
+	memcpy(&y, &x, 8);
+	assert(sqlIsNaN(y));
 #endif
-
-	return rc;
+	return 0;
 }
 
 void
@@ -202,7 +195,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
@@ -293,7 +286,7 @@ sqlCreateFunc(sql * db,
 	p->pUserData = pUserData;
 	p->nArg = (u16) nArg;
 	p->ret_type = type;
-	return SQL_OK;
+	return 0;
 }
 
 int
@@ -328,7 +321,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);
 	}
@@ -485,7 +478,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 a060675..10b68c8 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;
 }
 
@@ -158,7 +158,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;
@@ -178,22 +178,6 @@ sqlOsCloseFree(sql_file * pFile)
 }
 
 /*
- * This function is a wrapper around the OS specific implementation of
- * sql_os_init(). The purpose of the wrapper is to provide the
- * ability to simulate a malloc failure, so that the handling of an
- * error in sql_os_init() by the upper layers can be tested.
- */
-int
-sqlOsInit(void)
-{
-	void *p = sql_malloc(10);
-	if (p == 0)
-		return SQL_NOMEM;
-	sql_free(p);
-	return sql_os_init();
-}
-
-/*
  * The list of all registered VFS implementations.
  */
 static sql_vfs *SQL_WSD vfsList = 0;
@@ -255,5 +239,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.h b/src/box/sql/os.h
index 9122e9c..3c891f3 100644
--- a/src/box/sql/os.h
+++ b/src/box/sql/os.h
@@ -127,11 +127,6 @@
 #define SHARED_SIZE       510
 
 /*
- * Wrapper around OS specific sql_os_init() function.
- */
-int sqlOsInit(void);
-
-/*
  * Functions for accessing sql_file methods
  */
 void sqlOsClose(sql_file *);
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index e0a2805..ccc8d35 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,9 +1827,8 @@ 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;
 
 		/* Generated temporary filenames are always double-zero terminated
@@ -1861,7 +1860,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,9 +1910,8 @@ 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 +1925,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) {
@@ -1940,7 +1938,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,
@@ -1949,7 +1947,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;
 		}
 	}
 	return rc;
@@ -1991,15 +1989,13 @@ 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
- * cannot be found.
+ * Always returns 0.
  */
 static int
 unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
 {
 	static const sql_int64 unixEpoch =
 	    24405875 * (sql_int64) 8640000;
-	int rc = SQL_OK;
 	struct timeval sNow;
 	(void)gettimeofday(&sNow, 0);	/* Cannot fail given valid arguments */
 	*piNow =
@@ -2013,7 +2009,7 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
 	}
 #endif
 	UNUSED_PARAMETER(NotUsed);
-	return rc;
+	return 0;
 }
 
 /*
@@ -2047,16 +2043,15 @@ unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
  * Initialize the operating system interface.
  *
  * This routine registers all VFS implementations for unix-like operating
- * systems.  This routine, and the sql_os_end() routine that follows,
- * should be the only routines in this file that are visible from other
- * files.
+ * systems.  This routine should be the only one in this file that
+ * are visible from other files.
  *
  * This routine is called once during sql initialization and by a
  * single thread.  The memory allocation subsystem have not
  * necessarily been initialized when this routine \is called, and so they
  * should not be used.
  */
-int
+void
 sql_os_init(void)
 {
 	/*
@@ -2074,18 +2069,4 @@ 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;
-}
-
-/*
- * Shutdown the operating system interface.
- *
- * Some operating systems might need to do some cleanup in this routine,
- * to release dynamically allocated objects.  But not on unix.
- * This routine is a no-op for unix.
- */
-int
-sql_os_end(void)
-{
-	return SQL_OK;
 }
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 4ac8698..7a8a2d8 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, current_session()->sql_flags);
 	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 != NULL && 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 != NULL && (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 == NULL);
 	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 == NULL || *ppStmt == NULL);	/* 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 == NULL || *ppStmt == NULL);	/* VERIFY: F13021 */
 	return rc;
 }
 
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 3b6b4b6..c60a280 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1812,7 +1812,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
@@ -1916,8 +1916,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.
@@ -2551,7 +2551,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 */
@@ -2664,7 +2664,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 =
@@ -2751,7 +2751,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.
 				 */
@@ -2865,7 +2865,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)
@@ -4390,7 +4390,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)
@@ -4414,7 +4414,7 @@ sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom)
 		}
 		pFrom->pIBIndex = idx->def;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -4567,9 +4567,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)
@@ -4687,7 +4687,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 		pParse->pWith = pSavedWith;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -6386,7 +6386,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 559bcd9..5f08ed1 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -325,10 +325,8 @@ struct sql_vfs {
 #define SQL_LIMIT_TRIGGER_DEPTH             9
 
 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. */
@@ -553,7 +551,7 @@ sql_finalize(sql_stmt * pStmt);
  * it back to its starting state so that it can be reused.
  *
  * @param stmt VDBE program.
- * @retval SQL_OK On success.
+ * @retval 0 On success.
  * @retval sql_ret_code Error code on error.
  */
 int
@@ -626,9 +624,6 @@ sql_column_datatype(sql_stmt *, int N);
 int
 sql_initialize(void);
 
-int
-sql_os_end(void);
-
 #define SQL_TRACE_STMT       0x01
 #define SQL_TRACE_PROFILE    0x02
 #define SQL_TRACE_ROW        0x04
@@ -707,7 +702,7 @@ struct sql_io_methods {
 #define SQL_FCNTL_MMAP_SIZE              16
 #define SQL_FCNTL_HAS_MOVED              18
 
-int
+void
 sql_os_init(void);
 
 sql_int64
@@ -3031,7 +3026,7 @@ sql_space_column_is_in_pk(struct space *space, uint32_t);
  * @param parse Parsing context.
  * @param expr_list  Expr list from which to derive column names.
  * @param space_def Destination space definition.
- * @retval sql_OK on success.
+ * @retval 0 on success.
  * @retval error codef on error.
  */
 int sqlColumnsFromExprList(Parse *parse, ExprList *expr_list,
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index 950d5f4..d7ecc9d 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
diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h
index 375a8cc..71073ad 100644
--- a/src/box/sql/tarantoolInt.h
+++ b/src/box/sql/tarantoolInt.h
@@ -35,7 +35,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,
@@ -82,7 +82,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 bfc6c10..d746ef8 100644
--- a/src/box/sql/trigger.c
+++ b/src/box/sql/trigger.c
@@ -783,7 +783,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 0914fda..37e0892 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 (sqlVdbeMemClearAndResize(pMem, nByte) == 0) {
 		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;
 }
@@ -634,7 +634,7 @@ vdbe_field_ref_fast_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
  * @param field_ref The initialized vdbe_field_ref instance to use.
  * @param fieldno The id of the field to fetch.
  * @param[out] dest_mem The memory variable to store result.
- * @retval SQL_OK Status code in case of success.
+ * @retval 0 Status code in case of success.
  * @retval sql_ret_code Error code otherwise.
  */
 static int
@@ -645,7 +645,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 	uint32_t *slots = field_ref->slots;
 	if (fieldno >= field_ref->field_count) {
 		UPDATE_MAX_BLOBSIZE(dest_mem);
-		return SQL_OK;
+		return 0;
 	}
 
 	const char *data;
@@ -713,7 +713,7 @@ vdbe_field_ref_fetch(struct vdbe_field_ref *field_ref, uint32_t fieldno,
 		dest_mem->flags |= MEM_Term;
 	}
 	UPDATE_MAX_BLOBSIZE(dest_mem);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -730,7 +730,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 */
@@ -752,8 +752,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;
@@ -788,7 +788,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
@@ -1032,7 +1032,7 @@ case OP_Halt: {
 	int pcx;
 
 	pcx = (int)(pOp - aOp);
-	if (pOp->p1==SQL_OK && p->pFrame) {
+	if (pOp->p1 == 0 && p->pFrame != NULL) {
 		/* Halt the sub-program. Return control to the parent frame. */
 		pFrame = p->pFrame;
 		p->pFrame = pFrame->pParent;
@@ -1064,11 +1064,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;
@@ -1141,7 +1141,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;
 }
@@ -1436,7 +1436,7 @@ case OP_ResultRow: {
 	 */
 	assert(p->iStatement == 0 || (p->sql_flags & SQL_CountRows) != 0);
 	rc = sqlVdbeCloseStatement(p, SAVEPOINT_RELEASE);
-	assert(rc==SQL_OK);
+	assert(rc==0);
 
 	/* Invalidate all ephemeral cursor row caches */
 	p->cacheCtr = (p->cacheCtr + 2)|1;
@@ -2624,7 +2624,7 @@ case OP_Column: {
 	struct Mem *default_val_mem =
 		pOp->p4type == P4_MEM ? pOp->p4.pMem : NULL;
 	rc = vdbe_field_ref_fetch(&pC->field_ref, p2, pDest);
-	if (rc != SQL_OK)
+	if (rc != 0)
 		goto abort_due_to_error;
 
 	if ((pDest->flags & MEM_Null) &&
@@ -2658,7 +2658,7 @@ case OP_Fetch: {
 	struct Mem *dest_mem = &aMem[pOp->p3];
 	memAboutToChange(p, dest_mem);
 	rc = vdbe_field_ref_fetch(field_ref, field_idx, dest_mem);
-	if (rc != SQL_OK)
+	if (rc != 0)
 		goto abort_due_to_error;
 	REGISTER_TRACE(p, pOp->p3, dest_mem);
 	break;
@@ -2877,9 +2877,8 @@ 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) {
 					p->pc = (int)(pOp - aOp);
 					p->rc = rc = SQL_BUSY;
@@ -3427,7 +3426,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);
@@ -3440,7 +3439,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;
@@ -3449,7 +3448,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
@@ -3595,8 +3594,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);
@@ -3907,9 +3906,9 @@ case OP_RowData: {
 	testcase( n==0);
 
 	sqlVdbeMemRelease(pOut);
-	if (sql_vdbe_mem_alloc_region(pOut, n) != 0 ||
-	    sqlCursorPayload(pCrsr, 0, n, pOut->z) != 0)
+	if (sql_vdbe_mem_alloc_region(pOut, n) != 0)
 		goto abort_due_to_error;
+	sqlCursorPayload(pCrsr, 0, n, pOut->z);
 	UPDATE_MAX_BLOBSIZE(pOut);
 	REGISTER_TRACE(p, pOp->p2, pOut);
 	break;
@@ -4256,7 +4255,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++;
@@ -4265,7 +4264,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;
@@ -4342,7 +4341,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;
@@ -4352,7 +4351,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.
@@ -4364,7 +4363,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;
@@ -5257,10 +5256,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 a4e9d27..fc34722 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -83,7 +83,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;
@@ -115,7 +115,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]);
@@ -136,7 +136,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;
 		}
@@ -235,7 +235,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;
 		}
@@ -394,7 +394,7 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n)
 		return SQL_TOOBIG;
 	}
 	sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -497,7 +497,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)
@@ -912,7 +912,7 @@ sql_column_decltype(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.
@@ -950,7 +950,7 @@ vdbeUnbind(Vdbe * p, int i)
 	    ) {
 		p->expired = 1;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /**
@@ -1013,11 +1013,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);
 		}
@@ -1037,11 +1037,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);
 		}
@@ -1072,7 +1072,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);
 	}
@@ -1084,7 +1084,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);
 	}
@@ -1103,7 +1103,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);
 	}
@@ -1116,7 +1116,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;
 }
@@ -1126,7 +1126,7 @@ sql_bind_ptr(struct sql_stmt *stmt, int i, void *ptr)
 {
 	struct Vdbe *p = (struct Vdbe *) stmt;
 	int rc = vdbeUnbind(p, i);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = sql_bind_type(p, i, "BLOB");
 		mem_set_ptr(&p->aVar[i - 1], ptr);
 	}
@@ -1162,7 +1162,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;
@@ -1250,7 +1250,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 5f7e772..4835781 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -191,8 +191,9 @@ growOpArray(Vdbe * v, int nOp)
 		p->szOpAlloc = sqlMallocSize(pNew);
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
+		return 0;
 	}
-	return (pNew ? SQL_OK : SQL_NOMEM);
+	return SQL_NOMEM;
 }
 
 #ifdef SQL_DEBUG
@@ -1384,12 +1385,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
@@ -1439,7 +1440,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;
@@ -1483,11 +1484,9 @@ sqlVdbeList(Vdbe * p)
 					if (apSub[j] == pOp->p4.pProgram)
 						break;
 				}
-				if (j == nSub
-				    && SQL_OK == sqlVdbeMemGrow(pSub,
-								       nByte,
-								       nSub !=
-								       0)) {
+				if (j == nSub &&
+				    sqlVdbeMemGrow(pSub, nByte,
+						   nSub != 0) == 0) {
 					apSub = (SubProgram **) pSub->z;
 					apSub[nSub++] = pOp->p4.pProgram;
 					pSub->flags |= MEM_Blob;
@@ -1548,7 +1547,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;
@@ -1648,7 +1647,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;
@@ -1992,12 +1991,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.
@@ -2012,7 +2011,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
@@ -2031,7 +2030,7 @@ sqlVdbeCheckFk(Vdbe * p, int deferred)
 			 "failed");
 		return SQL_TARANTOOL_ERROR;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 int
@@ -2117,7 +2116,7 @@ sqlVdbeHalt(Vdbe * p)
 	}
 	closeTopFrameCursors(p);
 	if (p->magic != VDBE_MAGIC_RUN) {
-		return SQL_OK;
+		return 0;
 	}
 	checkActiveVdbeCnt(db);
 
@@ -2160,9 +2159,8 @@ sqlVdbeHalt(Vdbe * p)
 		}
 
 		/* Check for immediate foreign key violations. */
-		if (p->rc == SQL_OK) {
+		if (p->rc == 0)
 			sqlVdbeCheckFk(p, 0);
-		}
 
 		/* If the auto-commit flag is set and this is the only active writer
 		 * VM, then we do either a commit or rollback of the current transaction.
@@ -2171,11 +2169,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.
@@ -2193,13 +2191,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);
@@ -2214,7 +2212,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;
@@ -2230,14 +2228,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;
 				}
@@ -2276,17 +2274,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;
 }
 
 /*
@@ -2387,7 +2385,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);
@@ -2906,7 +2904,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 3669336..3052bec 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -145,7 +145,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;
 }
 
 /*
@@ -158,7 +158,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
@@ -172,14 +172,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)
@@ -201,7 +201,7 @@ sqlVdbeMemMakeWriteable(Mem * pMem)
 	pMem->pScopyFrom = 0;
 #endif
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -227,7 +227,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;
 }
 
 /*
@@ -243,7 +243,7 @@ vdbeMemAddTerminator(Mem * pMem)
 	pMem->z[pMem->n] = 0;
 	pMem->z[pMem->n + 1] = 0;
 	pMem->flags |= MEM_Term;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -255,7 +255,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);
 	}
@@ -282,7 +282,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));
@@ -303,7 +303,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;
 }
 
 /*
@@ -565,7 +565,7 @@ sqlVdbeMemRealify(Mem * pMem)
 
 	pMem->u.r = v;
 	MemSetTypeFlag(pMem, MEM_Real);
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -594,7 +594,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;
 }
 
 /**
@@ -644,7 +644,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);
@@ -704,7 +704,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;
 	}
 }
 
@@ -903,7 +903,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);
@@ -966,7 +966,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) {
@@ -1020,7 +1020,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 		return SQL_TOOBIG;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1047,16 +1047,12 @@ vdbeMemFromBtreeResize(BtCursor * pCur,	/* Cursor pointing at record to retrieve
 {
 	int rc;
 	pMem->flags = MEM_Null;
-	if (SQL_OK == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) {
-		rc = sqlCursorPayload(pCur, offset, amt, pMem->z);
-		if (rc == SQL_OK) {
-			pMem->z[amt] = 0;
-			pMem->z[amt + 1] = 0;
-			pMem->flags = MEM_Blob | MEM_Term;
-			pMem->n = (int)amt;
-		} else {
-			sqlVdbeMemRelease(pMem);
-		}
+	if (0 == (rc = sqlVdbeMemClearAndResize(pMem, amt + 2))) {
+		sqlCursorPayload(pCur, offset, amt, pMem->z);
+		pMem->z[amt] = 0;
+		pMem->z[amt + 1] = 0;
+		pMem->flags = MEM_Blob | MEM_Term;
+		pMem->n = (int) amt;
 	}
 	return rc;
 }
@@ -1070,7 +1066,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));
@@ -1222,13 +1218,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.
  */
@@ -1245,7 +1241,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 */
 
@@ -1259,7 +1255,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) {
@@ -1274,7 +1270,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;
 		}
 	}
@@ -1292,12 +1288,11 @@ 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) {
 		for (i = 0; i < nVal; i++) {
 			sqlValueFree(apVal[i]);
@@ -1332,7 +1327,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)
@@ -1349,7 +1344,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);
@@ -1393,10 +1388,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;
@@ -1412,7 +1407,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
@@ -1544,7 +1539,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;
 
@@ -1568,9 +1563,8 @@ 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;
 			}
 		}
@@ -1613,7 +1607,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.
  */
@@ -1627,7 +1621,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) {
@@ -1662,8 +1656,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 4034a34..230bb0c 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -464,7 +464,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
@@ -482,7 +482,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);
@@ -507,7 +507,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;
@@ -558,7 +558,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);
@@ -568,7 +568,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 		*ppOut = p->aAlloc;
 	}
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -600,14 +600,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.
@@ -615,13 +615,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;
@@ -629,7 +629,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
@@ -639,7 +639,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);
 
@@ -652,7 +652,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 == NULL) {
 		int pgsz = pTask->pSorter->pgsz;
 		int iBuf = pReadr->iReadOff % pgsz;
 		if (pReadr->aBuffer == 0) {
@@ -661,14 +661,14 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 				rc = SQL_NOMEM;
 			pReadr->nBuffer = pgsz;
 		}
-		if (rc == SQL_OK && iBuf) {
+		if (rc == 0 && iBuf != 0) {
 			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);
 		}
 	}
 
@@ -676,13 +676,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) {
@@ -690,7 +690,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);
@@ -701,18 +701,17 @@ 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;
@@ -743,16 +742,15 @@ 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;
 }
 
@@ -806,7 +804,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()) */
@@ -815,7 +813,7 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 {
 	int pgsz;		/* Page size of main database */
 	VdbeSorter *pSorter;	/* The new sorter */
-	int rc = SQL_OK;
+	int rc = 0;
 
 	assert(pCsr->key_def != NULL);
 	assert(pCsr->eCurType == CURTYPE_SORTER);
@@ -964,7 +962,7 @@ vdbeIncrFree(IncrMerger * pIncr)
 void
 sqlVdbeSorterReset(sql * db, VdbeSorter * pSorter)
 {
-	(void)vdbeSorterJoinAll(pSorter, SQL_OK);
+	(void)vdbeSorterJoinAll(pSorter, 0);
 	assert(pSorter->pReader == 0);
 	vdbeMergeEngineFree(pSorter->pMerger);
 	pSorter->pMerger = 0;
@@ -1028,7 +1026,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
@@ -1041,7 +1039,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);
@@ -1054,7 +1052,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
@@ -1069,7 +1067,7 @@ vdbeSortAllocUnpacked(SortSubtask * pTask)
 		pTask->pUnpacked->nField = pTask->pSorter->key_def->part_count;
 		pTask->pUnpacked->errCode = 0;
 	}
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1127,7 +1125,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
@@ -1139,7 +1137,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	int rc;
 
 	rc = vdbeSortAllocUnpacked(pTask);
-	if (rc != SQL_OK)
+	if (rc != 0)
 		return rc;
 
 	p = pList->pList;
@@ -1185,7 +1183,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;
 }
@@ -1213,7 +1211,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
@@ -1245,7 +1243,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
@@ -1270,7 +1268,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)
@@ -1283,7 +1281,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:
@@ -1299,7 +1297,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
@@ -1316,23 +1314,22 @@ 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;
 
@@ -1351,8 +1348,8 @@ vdbeSorterListToPMA(SortSubtask * pTask, SorterList * pList)
 		rc = vdbePmaWriterFinish(&writer, &pTask->file.iEof);
 	}
 
-	assert(rc != SQL_OK || pList->pList == 0);
-	assert(rc != SQL_OK || pTask->file.iEof == iSz);
+	assert(rc != 0 || pList->pList == NULL);
+	assert(rc != 0 || pTask->file.iEof == iSz);
 	return rc;
 }
 
@@ -1361,7 +1358,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 */
@@ -1376,7 +1373,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 */
@@ -1437,7 +1434,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;
 }
 
 /*
@@ -1460,7 +1457,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 */
@@ -1512,7 +1509,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 == NULL);
 		}
 	}
 
@@ -1575,7 +1572,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];
@@ -1585,7 +1582,7 @@ vdbeIncrPopulate(IncrMerger * pIncr)
 	assert(pIncr->bEof == 0);
 
 	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;
@@ -1608,7 +1605,7 @@ vdbeIncrPopulate(IncrMerger * pIncr)
 	}
 
 	rc2 = vdbePmaWriterFinish(&writer, &pOut->iEof);
-	if (rc == SQL_OK)
+	if (rc == 0)
 		rc = rc2;
 	return rc;
 }
@@ -1628,7 +1625,7 @@ vdbeIncrPopulate(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)
@@ -1654,7 +1651,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) {
@@ -1738,14 +1735,14 @@ static int vdbePmaReaderIncrInit(PmaReader * pReader);
  * 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 */
 		    MergeEngine * pMerger 	/* MergeEngine to initialize */
     )
 {
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	int i;			/* For looping over PmaReader objects */
 	int nTree = pMerger->nTree;
 
@@ -1755,7 +1752,7 @@ vdbeMergeEngineInit(SortSubtask * pTask,	/* Thread that will run pMerger */
 
 	for (i = 0; i < nTree; i++) {
 		rc = vdbePmaReaderIncrInit(&pMerger->aReadr[i]);
-		if (rc != SQL_OK)
+		if (rc != 0)
 			return rc;
 	}
 
@@ -1776,12 +1773,12 @@ vdbeMergeEngineInit(SortSubtask * pTask,	/* Thread that will run pMerger */
  * loaded into the buffers belonging to pReadr and it is 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 rc = SQL_OK;
+	int rc = 0;
 	IncrMerger *pIncr = pReadr->pIncr;
 	SortSubtask *pTask = pIncr->pTask;
 	sql *db = pTask->pSorter->db;
@@ -1792,7 +1789,7 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr)
 	 * 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 (pTask->file2.pFd == 0) {
 			assert(pTask->file2.iEof > 0);
@@ -1801,14 +1798,14 @@ vdbePmaReaderIncrMergeInit(PmaReader * pReadr)
 						    &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;
 		}
 	}
 
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = vdbePmaReaderNext(pReadr);
 	}
 
@@ -1830,7 +1827,7 @@ static int
 vdbePmaReaderIncrInit(PmaReader * pReadr)
 {
 	IncrMerger *pIncr = pReadr->pIncr;	/* Incremental merger */
-	int rc = SQL_OK;	/* Return code */
+	int rc = 0;	/* Return code */
 	if (pIncr) {
 		rc = vdbePmaReaderIncrMergeInit(pReadr);
 	}
@@ -1840,7 +1837,7 @@ vdbePmaReaderIncrInit(PmaReader * pReadr)
 /*
  * 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
@@ -1859,13 +1856,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,
@@ -1873,7 +1870,7 @@ vdbeMergeEngineLevel0(SortSubtask * pTask,	/* Sorter task to read from */
 		iOff = pReadr->iEof;
 	}
 
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		vdbeMergeEngineFree(pNew);
 		*ppOut = 0;
 	}
@@ -1908,7 +1905,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
@@ -1919,7 +1916,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;
@@ -1931,7 +1928,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];
 
@@ -1945,13 +1942,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);
@@ -1965,7 +1962,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.
@@ -1976,7 +1973,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
     )
 {
 	MergeEngine *pMain = 0;
-	int rc = SQL_OK;
+	int rc = 0;
 
 	SortSubtask *pTask = &pSorter->aTask;
 	assert(pTask->nPMA > 0);
@@ -1995,7 +1992,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 */
@@ -2007,7 +2004,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 							   nReader,
 							   &iReadOff,
 							   &pMerger);
-				if (rc == SQL_OK) {
+				if (rc == 0) {
 					rc = vdbeSorterAddToTree(pTask,
 								 nDepth,
 								 iSeq++,
@@ -2017,7 +2014,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 			}
 		}
 
-		if (rc == SQL_OK) {
+		if (rc == 0) {
 			assert(pMain == 0);
 			pMain = pRoot;
 		} else {
@@ -2025,7 +2022,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 		}
 	}
 
-	if (rc != SQL_OK) {
+	if (rc != 0) {
 		vdbeMergeEngineFree(pMain);
 		pMain = 0;
 	}
@@ -2040,7 +2037,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)
@@ -2049,15 +2046,14 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 	MergeEngine *pMain = 0;
 
 	rc = vdbeSorterMergeTreeBuild(pSorter, &pMain);
-	if (rc == SQL_OK) {
+	if (rc == 0) {
 		rc = vdbeMergeEngineInit(&pSorter->aTask, pMain);
 		pSorter->pMerger = pMain;
 		pMain = 0;
 	}
 
-	if (rc != SQL_OK) {
+	if (rc != 0)
 		vdbeMergeEngineFree(pMain);
-	}
 	return rc;
 }
 
@@ -2070,7 +2066,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;
@@ -2105,7 +2101,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;
 	}
@@ -2138,7 +2134,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;
 }
@@ -2189,7 +2185,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut)
 	MemSetTypeFlag(pOut, MEM_Blob);
 	memcpy(pOut->z, pKey, nKey);
 
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -2238,10 +2234,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 b1eca58..a2f8934 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1175,7 +1175,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 */
@@ -1193,7 +1193,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 */
@@ -1206,7 +1206,7 @@ whereRangeSkipScanEst(Parse * pParse,		/* Parsing & code generating context */
 					       type, &p1);
 		nLower = 0;
 	}
-	if (pUpper && rc == SQL_OK) {
+	if (pUpper != NULL && rc == 0) {
 		rc = sqlStat4ValueFromExpr(pParse, pUpper->pExpr->pRight,
 					       type, &p2);
 		nUpper = p2 ? 0 : index->def->opts.stat->sample_count;
@@ -1217,15 +1217,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 != NULL) {
 				int res = sqlMemCompare(p1, pVal, coll);
 				if (res >= 0)
 					nLower++;
 			}
-			if (rc == SQL_OK && p2) {
+			if (rc == 0 && p2 != NULL) {
 				int res = sqlMemCompare(p2, pVal, coll);
 				if (res >= 0)
 					nUpper++;
@@ -1309,7 +1309,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;
 
@@ -1399,7 +1399,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 != 0) {
 					tRowcnt iNew;
 					u16 mask = WO_GT | WO_LE;
 					if (sqlExprVectorSize(pExpr) > n)
@@ -1425,7 +1425,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 != 0) {
 					tRowcnt iNew;
 					u16 mask = WO_GT | WO_LE;
 					if (sqlExprVectorSize(pExpr) > n)
@@ -1445,7 +1445,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
@@ -1513,7 +1513,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.
  *
@@ -1548,7 +1548,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;
@@ -1569,7 +1569,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.
  *
@@ -1586,12 +1586,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);
@@ -1599,7 +1599,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;
@@ -1755,7 +1755,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)
@@ -1765,7 +1765,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n)
 		sqlDbFree(db, p->aLTerm);
 	p->aLTerm = paNew;
 	p->nLSlot = n;
-	return SQL_OK;
+	return 0;
 }
 
 /*
@@ -1787,7 +1787,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;
 }
 
 /*
@@ -2056,7 +2056,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 			}
 #endif
 		}
-		return SQL_OK;
+		return 0;
 	}
 
 	/* Look for an existing WhereLoop to replace with pTemplate
@@ -2074,7 +2074,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 			whereLoopPrint(pTemplate, pBuilder->pWC);
 		}
 #endif
-		return SQL_OK;
+		return 0;
 	} else {
 		p = *ppPrev;
 	}
@@ -2318,7 +2318,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 */
@@ -2370,7 +2370,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 != NULL; pTerm = whereScanNext(&scan)) {
 		u16 eOp = pTerm->eOperator;	/* Shorthand for pTerm->eOperator */
 		LogEst rCostIdx;
 		LogEst nOutUnadjusted;	/* nOut before IN() and WHERE adjustments */
@@ -2552,8 +2552,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 =
@@ -2651,7 +2651,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++;
@@ -2760,7 +2760,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,9 +3115,8 @@ whereLoopAddAll(WhereLoopBuilder * pBuilder)
 		{
 			rc = whereLoopAddBtree(pBuilder, mPrereq);
 		}
-		if (rc == SQL_OK) {
+		if (rc == 0)
 			rc = whereLoopAddOr(pBuilder, mPrereq, mUnusable);
-		}
 		mPrior |= pNew->maskSelf;
 		if (rc || db->mallocFailed)
 			break;
@@ -3566,7 +3565,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 +4000,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 
 	/* Free temporary memory and return success */
 	sqlDbFree(db, pSpace);
-	return SQL_OK;
+	return 0;
 }
 
 /**





More information about the Tarantool-patches mailing list