Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system.
@ 2019-05-25 10:44 imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 01/21] sql: remove unused functions of " imeevma
                   ` (21 more replies)
  0 siblings, 22 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

This patch-set is a follow-up for issue #4074. Since we are using
the Tarantool error system, the SQL error system should be
removed.

https://github.com/tarantool/tarantool/issues/4074
https://github.com/tarantool/tarantool/tree/imeevma/gh-4074-diag_set-in-vdbe

Mergen Imeev (21):
  sql: remove unused functions of SQL error system
  sql: disable lookaside system
  sql: remove SQL_OK error/status code
  sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes
  sql: remove SQL_CANTOPEN errcode
  sql: remove SQL_NOTFOUND error/status code
  sql: remove SQL_LOCKED errcode
  sql: remove SQL_FULL errcode
  sql: remove SQL_MISUSE errcode
  sql: remove SQL_RANGE errcode
  sql: remove SQL_SCHEMA errcode
  sql: remove SQL_TOOBIG errcode
  sql: remove SQL_BUSY errcode
  sql: remove SQL_CONSTRAINT errcode
  sql: remove SQL_ERROR errcode
  sql: remove SQL_NOMEM errcode
  sql: remove SQL_IOERR errcode
  sql: remove SQL_TARANTOOL_ERROR errcode
  sql: remove field errMask from struct sql
  sql: replace rc by is_aborted in struct Parse
  sql: remove sql_log()

 src/box/bind.c              |  15 +--
 src/box/execute.c           |   6 +-
 src/box/sql.c               | 122 ++++++++-----------
 src/box/sql/analyze.c       |  12 +-
 src/box/sql/build.c         |   5 +-
 src/box/sql/cursor.c        |   4 +-
 src/box/sql/date.c          |  14 +--
 src/box/sql/expr.c          |   4 +-
 src/box/sql/fault.c         |   4 +-
 src/box/sql/fk_constraint.c |   6 +-
 src/box/sql/func.c          |  16 +--
 src/box/sql/global.c        |   3 -
 src/box/sql/insert.c        |   6 +-
 src/box/sql/legacy.c        |  19 ++-
 src/box/sql/main.c          | 171 +++++----------------------
 src/box/sql/malloc.c        | 158 ++-----------------------
 src/box/sql/os.c            |  14 +--
 src/box/sql/os_unix.c       | 281 +++++++++++++-------------------------------
 src/box/sql/prepare.c       |  70 ++---------
 src/box/sql/printf.c        |  36 +-----
 src/box/sql/resolve.c       |   3 +-
 src/box/sql/select.c        |  66 +++++------
 src/box/sql/sqlInt.h        | 146 +----------------------
 src/box/sql/status.c        |  37 +-----
 src/box/sql/tarantoolInt.h  |   9 +-
 src/box/sql/trigger.c       |   2 +-
 src/box/sql/util.c          |  81 -------------
 src/box/sql/vdbe.c          | 158 ++++++++++---------------
 src/box/sql/vdbe.h          |   1 -
 src/box/sql/vdbeInt.h       |  11 +-
 src/box/sql/vdbeapi.c       | 226 ++++++++---------------------------
 src/box/sql/vdbeaux.c       | 167 +++++++-------------------
 src/box/sql/vdbemem.c       | 122 +++++++++----------
 src/box/sql/vdbesort.c      | 266 ++++++++++++++++++++---------------------
 src/box/sql/where.c         | 107 +++++++----------
 src/box/sql/whereexpr.c     |   3 +-
 36 files changed, 658 insertions(+), 1713 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 01/21] sql: remove unused functions of SQL error system
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 02/21] sql: disable lookaside system imeevma
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

These functions are not currently used and should be removed.
---
 src/box/sql.c              |  7 ----
 src/box/sql/global.c       |  3 --
 src/box/sql/legacy.c       |  3 +-
 src/box/sql/main.c         | 34 -------------------
 src/box/sql/prepare.c      |  4 +--
 src/box/sql/sqlInt.h       | 13 --------
 src/box/sql/tarantoolInt.h |  3 --
 src/box/sql/util.c         | 81 ----------------------------------------------
 src/box/sql/vdbeapi.c      | 40 ++---------------------
 src/box/sql/vdbesort.c     | 11 ++-----
 10 files changed, 8 insertions(+), 191 deletions(-)

diff --git a/src/box/sql.c b/src/box/sql.c
index 59a8bfb..34e11bf 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -155,13 +155,6 @@ cursor_seek(BtCursor *pCur, int *pRes);
 static int
 cursor_advance(BtCursor *pCur, int *pRes);
 
-const char *tarantoolErrorMessage()
-{
-	if (diag_is_empty(&fiber()->diag))
-		return NULL;
-	return box_error_message(box_error_last());
-}
-
 const void *tarantoolsqlPayloadFetch(BtCursor *pCur, u32 *pAmt)
 {
 	assert(pCur->curFlags & BTCF_TaCursor ||
diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index 9af671a..e394db8 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -204,9 +204,6 @@ SQL_WSD struct sqlConfig sqlConfig = {
 	0,			/* xVdbeBranch */
 	0,			/* pVbeBranchArg */
 #endif
-#ifndef SQL_UNTESTABLE
-	0,			/* xTestCallback */
-#endif
 	0,			/* bLocaltimeFault */
 	0x7ffffffe		/* iOnceResetThreshold */
 };
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index b6e8f6e..518c184 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -65,8 +65,7 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	int callbackIsInit;	/* True if callback data is initialized */
 	struct session *user_session = current_session();
 
-	if (!sqlSafetyCheckOk(db))
-		return SQL_MISUSE;
+	assert(db != NULL);
 	if (zSql == 0)
 		zSql = "";
 
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index f35c84f..450f7d1 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -302,40 +302,6 @@ sqlRollbackAll(Vdbe * pVdbe)
 }
 
 /*
- * Return a static string that describes the kind of error specified in the
- * argument.
- */
-const char *
-sqlErrStr(int rc)
-{
-	static const char *const aMsg[] = {
-		/* SQL_OK          */ "not an error",
-		/* SQL_ERROR       */ "SQL logic error or missing database",
-		/* SQL_PERM        */ "access permission denied",
-		/* SQL_ABORT       */ "callback requested query abort",
-		/* SQL_BUSY        */ "database is locked",
-		/* SQL_LOCKED      */ "database table is locked",
-		/* SQL_NOMEM       */ "out of memory",
-		/* SQL_IOERR       */ "disk I/O error",
-		/* SQL_NOTFOUND    */ "unknown operation",
-		/* SQL_FULL        */ "database or disk is full",
-		/* SQL_CANTOPEN    */ "unable to open database file",
-		/* SQL_SCHEMA      */ "database schema has changed",
-		/* SQL_TOOBIG      */ "string or blob too big",
-		/* SQL_CONSTRAINT  */ "constraint failed",
-		/* SQL_MISUSE      */
-		    "library routine called out of sequence",
-		/* SQL_RANGE       */ "bind or column index out of range",
-		/* SQL_TARANTOOL_ERROR */ "SQL-/Tarantool error",
-	};
-	const char *zErr = "unknown error";
-	rc &= 0xff;
-	if (ALWAYS(rc >= 0) && rc < ArraySize(aMsg) && aMsg[rc] != 0)
-		zErr = aMsg[rc];
-	return zErr;
-}
-
-/*
  * This function is exactly the same as sql_create_function(), except
  * that it is designed to be called by internal code. The difference is
  * that if a malloc() fails in sql_create_function(), an error code
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 5e0faa1..21c2fb8 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -193,9 +193,7 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
 	int rc;
 
 	*ppStmt = 0;
-	if (!sqlSafetyCheckOk(db) || zSql == 0) {
-		return SQL_MISUSE;
-	}
+	assert(zSql != NULL && db != NULL);
 	rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
 			    pzTail);
 	if (rc == SQL_SCHEMA) {
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0cfc4bc..c51a3cc 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -2885,9 +2885,6 @@ struct sqlConfig {
 	void (*xVdbeBranch) (void *, int iSrcLine, u8 eThis, u8 eMx);	/* Callback */
 	void *pVdbeBranchArg;	/* 1st argument */
 #endif
-#ifndef SQL_UNTESTABLE
-	int (*xTestCallback) (int);	/* Invoked by sqlFaultSim() */
-#endif
 	int bLocaltimeFault;	/* True to fail localtime() calls */
 	int iOnceResetThreshold;	/* When to reset OP_Once counters */
 };
@@ -3346,12 +3343,6 @@ int
 vdbe_emit_open_cursor(struct Parse *parse, int cursor, int index_id,
 		      struct space *space);
 
-#ifdef SQL_UNTESTABLE
-#define sqlFaultSim(X) SQL_OK
-#else
-int sqlFaultSim(int);
-#endif
-
 /**
  * The parser calls this routine in order to create a new VIEW.
  *
@@ -3895,8 +3886,6 @@ FuncDef *sqlFindFunction(sql *, const char *, int, u8);
 void sqlRegisterBuiltinFunctions(void);
 void sqlRegisterDateTimeFunctions(void);
 void sqlRegisterPerConnectionBuiltinFunctions(sql *);
-int sqlSafetyCheckOk(sql *);
-int sqlSafetyCheckSickOrOk(sql *);
 
 /**
  * Evaluate a view and store its result in an ephemeral table.
@@ -4417,8 +4406,6 @@ sql_dec_or_hex_to_i64(const char *z, int64_t *val);
 void *sqlHexToBlob(sql *, const char *z, int n);
 u8 sqlHexToInt(int h);
 
-const char *sqlErrStr(int);
-
 /**
  * Return the collation sequence for the expression pExpr. If
  * there is no defined collating sequence, return NULL.
diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h
index f15e147..1a727de 100644
--- a/src/box/sql/tarantoolInt.h
+++ b/src/box/sql/tarantoolInt.h
@@ -10,9 +10,6 @@
 
 struct fk_constraint_def;
 
-/* Misc */
-const char *tarantoolErrorMessage();
-
 /* Storage interface. */
 const void *tarantoolsqlPayloadFetch(BtCursor * pCur, u32 * pAmt);
 
diff --git a/src/box/sql/util.c b/src/box/sql/util.c
index d5f6447..713e535 100644
--- a/src/box/sql/util.c
+++ b/src/box/sql/util.c
@@ -58,26 +58,6 @@ sqlCoverage(int x)
 #endif
 
 /*
- * Give a callback to the test harness that can be used to simulate faults
- * in places where it is difficult or expensive to do so purely by means
- * of inputs.
- *
- * The intent of the integer argument is to let the fault simulator know
- * which of multiple sqlFaultSim() calls has been hit.
- *
- * Return whatever integer value the test callback returns, or return
- * SQL_OK if no test callback is installed.
- */
-#ifndef SQL_UNTESTABLE
-int
-   sqlFaultSim(int iTest)
-{
-	int (*xCallback) (int) = sqlGlobalConfig.xTestCallback;
-	return xCallback ? xCallback(iTest) : SQL_OK;
-}
-#endif
-
-/*
  * Return true if the floating point value is Not a Number (NaN).
  *
  * Use the math library isnan() function if compiled with SQL_HAVE_ISNAN.
@@ -1131,67 +1111,6 @@ sqlHexToBlob(sql * db, const char *z, int n)
 #endif				/* !SQL_OMIT_BLOB_LITERAL || SQL_HAS_CODEC */
 
 /*
- * Log an error that is an API call on a connection pointer that should
- * not have been used.  The "type" of connection pointer is given as the
- * argument.  The zType is a word like "NULL" or "closed" or "invalid".
- */
-static void
-logBadConnection(const char *zType)
-{
-	sql_log(SQL_MISUSE,
-		    "API call with %s database connection pointer", zType);
-}
-
-/*
- * Check to make sure we have a valid db pointer.  This test is not
- * foolproof but it does provide some measure of protection against
- * misuse of the interface such as passing in db pointers that are
- * NULL or which have been previously closed.  If this routine returns
- * 1 it means that the db pointer is valid and 0 if it should not be
- * dereferenced for any reason.  The calling function should invoke
- * SQL_MISUSE immediately.
- *
- * sqlSafetyCheckOk() requires that the db pointer be valid for
- * use.  sqlSafetyCheckSickOrOk() allows a db pointer that failed to
- * open properly and is not fit for general use but which can be
- * used as an argument to sql_errmsg() or sql_close().
- */
-int
-sqlSafetyCheckOk(sql * db)
-{
-	u32 magic;
-	if (db == 0) {
-		logBadConnection("NULL");
-		return 0;
-	}
-	magic = db->magic;
-	if (magic != SQL_MAGIC_OPEN) {
-		if (sqlSafetyCheckSickOrOk(db)) {
-			testcase(sqlGlobalConfig.xLog != 0);
-			logBadConnection("unopened");
-		}
-		return 0;
-	} else {
-		return 1;
-	}
-}
-
-int
-sqlSafetyCheckSickOrOk(sql * db)
-{
-	u32 magic;
-	magic = db->magic;
-	if (magic != SQL_MAGIC_SICK &&
-	    magic != SQL_MAGIC_OPEN && magic != SQL_MAGIC_BUSY) {
-		testcase(sqlGlobalConfig.xLog != 0);
-		logBadConnection("invalid");
-		return 0;
-	} else {
-		return 1;
-	}
-}
-
-/*
  * Attempt to add, substract, or multiply the 64-bit signed value iB against
  * the other 64-bit signed integer at *pA and store the result in *pA.
  * Return 0 on success.  Or if the operation would have resulted in an
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 0ca8142..4e4c239 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -37,35 +37,6 @@
 #include "sqlInt.h"
 #include "vdbeInt.h"
 
-/*
- * Check on a Vdbe to make sure it has not been finalized.  Log
- * an error and return true if it has been finalized (or is otherwise
- * invalid).  Return false if it is ok.
- */
-static int
-vdbeSafety(Vdbe * p)
-{
-	if (p->db == 0) {
-		sql_log(SQL_MISUSE,
-			    "API called with finalized prepared statement");
-		return 1;
-	} else {
-		return 0;
-	}
-}
-
-static int
-vdbeSafetyNotNull(Vdbe * p)
-{
-	if (p == 0) {
-		sql_log(SQL_MISUSE,
-			    "API called with NULL prepared statement");
-		return 1;
-	} else {
-		return vdbeSafety(p);
-	}
-}
-
 #ifndef SQL_OMIT_TRACE
 /*
  * Invoke the profile callback.  This routine is only called if we already
@@ -120,8 +91,7 @@ sql_finalize(sql_stmt * pStmt)
 	} else {
 		Vdbe *v = (Vdbe *) pStmt;
 		sql *db = v->db;
-		if (vdbeSafety(v))
-			return SQL_MISUSE;
+		assert(db != NULL);
 		checkProfileCallback(db, v);
 		rc = sqlVdbeFinalize(v);
 		rc = sqlApiExit(db, rc);
@@ -551,9 +521,7 @@ sql_step(sql_stmt * pStmt)
 	Vdbe *v = (Vdbe *) pStmt;	/* the prepared statement */
 	int cnt = 0;		/* Counter to prevent infinite loop of reprepares */
 
-	if (vdbeSafetyNotNull(v)) {
-		return SQL_MISUSE;
-	}
+	assert(v != NULL);
 	v->doingRerun = 0;
 	while ((rc = sqlStep(v)) == SQL_SCHEMA
 	       && cnt++ < SQL_MAX_SCHEMA_RETRY) {
@@ -1032,9 +1000,7 @@ static int
 vdbeUnbind(Vdbe * p, int i)
 {
 	Mem *pVar;
-	if (vdbeSafetyNotNull(p)) {
-		return SQL_MISUSE;
-	}
+	assert(p != NULL);
 	if (p->magic != VDBE_MAGIC_RUN || p->pc >= 0) {
 		sql_log(SQL_MISUSE,
 			    "bind on a busy prepared statement: [%s]", p->zSql);
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 779e832..da9ee3e 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -679,8 +679,6 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 
 	assert(pReadr->pIncr == 0 || pReadr->pIncr->bEof == 0);
 
-	if (sqlFaultSim(201))
-		return SQL_IOERR_READ;
 	if (pReadr->aMap) {
 		sqlOsUnfetch(pReadr->pFd, 0, pReadr->aMap);
 		pReadr->aMap = 0;
@@ -1105,8 +1103,7 @@ vdbeMergeEngineNew(int nReader)
 		N += N;
 	nByte = sizeof(MergeEngine) + N * (sizeof(int) + sizeof(PmaReader));
 
-	pNew =
-	    sqlFaultSim(100) ? 0 : (MergeEngine *) sqlMallocZero(nByte);
+	pNew = (MergeEngine *) sqlMallocZero(nByte);
 	if (pNew) {
 		pNew->nTree = N;
 		pNew->pTask = 0;
@@ -1243,8 +1240,6 @@ vdbeSorterOpenTempFile(sql * db,	/* Database handle doing sort */
 		       sql_file ** ppFd)
 {
 	int rc;
-	if (sqlFaultSim(202))
-		return SQL_IOERR_ACCESS;
 	rc = sqlOsOpenMalloc(db->pVfs, 0, ppFd,
 				 SQL_OPEN_READWRITE | SQL_OPEN_CREATE |
 				 SQL_OPEN_EXCLUSIVE |
@@ -2001,8 +1996,8 @@ vdbeIncrMergerNew(SortSubtask * pTask,	/* The thread that will be using the new
     )
 {
 	int rc = SQL_OK;
-	IncrMerger *pIncr = *ppOut = (IncrMerger *)
-	    (sqlFaultSim(100) ? 0 : sqlMallocZero(sizeof(*pIncr)));
+	IncrMerger *pIncr = *ppOut =
+		(IncrMerger *) sqlMallocZero(sizeof(*pIncr));
 	if (pIncr) {
 		pIncr->pMerger = pMerger;
 		pIncr->pTask = pTask;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 02/21] sql: disable lookaside system
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 01/21] sql: remove unused functions of " imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 03/21] sql: remove SQL_OK error/status code imeevma
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Since the lookaside system is not currently in use, it must be
completely disabled.
---
 src/box/sql/main.c      | 76 -----------------------------------------
 src/box/sql/malloc.c    | 91 ++++---------------------------------------------
 src/box/sql/printf.c    |  2 +-
 src/box/sql/sqlInt.h    | 44 +-----------------------
 src/box/sql/vdbeaux.c   |  2 +-
 src/box/sql/vdbemem.c   |  9 +++--
 src/box/sql/whereexpr.c |  3 +-
 7 files changed, 14 insertions(+), 213 deletions(-)

diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 450f7d1..29a7911 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -173,78 +173,6 @@ sql_initialize(void)
 	return rc;
 }
 
-/*
- * Set up the lookaside buffers for a database connection.
- * Return SQL_OK on success.
- * If lookaside is already active, return SQL_BUSY.
- *
- * The sz parameter is the number of bytes in each lookaside slot.
- * The cnt parameter is the number of slots.  If pStart is NULL the
- * space for the lookaside memory is obtained from sql_malloc().
- * If pStart is not NULL then it is sz*cnt bytes of memory to use for
- * the lookaside memory.
- */
-static int
-setupLookaside(sql * db, void *pBuf, int sz, int cnt)
-{
-#ifndef SQL_OMIT_LOOKASIDE
-	void *pStart;
-	if (db->lookaside.nOut) {
-		return SQL_BUSY;
-	}
-	/* Free any existing lookaside buffer for this handle before
-	 * allocating a new one so we don't have to have space for
-	 * both at the same time.
-	 */
-	if (db->lookaside.bMalloced) {
-		sql_free(db->lookaside.pStart);
-	}
-	/* The size of a lookaside slot after ROUNDDOWN8 needs to be larger
-	 * than a pointer to be useful.
-	 */
-	sz = ROUNDDOWN8(sz);	/* IMP: R-33038-09382 */
-	if (sz <= (int)sizeof(LookasideSlot *))
-		sz = 0;
-	if (cnt < 0)
-		cnt = 0;
-	if (sz == 0 || cnt == 0) {
-		sz = 0;
-		pStart = 0;
-	} else if (pBuf == 0) {
-		sqlBeginBenignMalloc();
-		pStart = sqlMalloc(sz * cnt);	/* IMP: R-61949-35727 */
-		sqlEndBenignMalloc();
-		if (pStart)
-			cnt = sqlMallocSize(pStart) / sz;
-	} else {
-		pStart = pBuf;
-	}
-	db->lookaside.pStart = pStart;
-	db->lookaside.pFree = 0;
-	db->lookaside.sz = (u16) sz;
-	if (pStart) {
-		int i;
-		LookasideSlot *p;
-		assert(sz > (int)sizeof(LookasideSlot *));
-		p = (LookasideSlot *) pStart;
-		for (i = cnt - 1; i >= 0; i--) {
-			p->pNext = db->lookaside.pFree;
-			db->lookaside.pFree = p;
-			p = (LookasideSlot *) & ((u8 *) p)[sz];
-		}
-		db->lookaside.pEnd = p;
-		db->lookaside.bDisable = 0;
-		db->lookaside.bMalloced = pBuf == 0 ? 1 : 0;
-	} else {
-		db->lookaside.pStart = db;
-		db->lookaside.pEnd = db;
-		db->lookaside.bDisable = 1;
-		db->lookaside.bMalloced = 0;
-	}
-#endif				/* SQL_OMIT_LOOKASIDE */
-	return SQL_OK;
-}
-
 void
 sql_row_count(struct sql_context *context, MAYBE_UNUSED int unused1,
 	      MAYBE_UNUSED sql_value **unused2)
@@ -630,10 +558,6 @@ sql_init_db(sql **out_db)
 	 */
 	sqlRegisterPerConnectionBuiltinFunctions(db);
 
-	/* Enable the lookaside-malloc subsystem */
-	setupLookaside(db, 0, sqlGlobalConfig.szLookaside,
-		       sqlGlobalConfig.nLookaside);
-
 opendb_out:
 	assert(db != 0 || rc == SQL_NOMEM);
 	if (rc == SQL_NOMEM)
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 925ffb2..5c9c8d5 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -412,7 +412,6 @@ sqlScratchMalloc(int n)
 			sqlStatusUp(SQL_STATUS_SCRATCH_OVERFLOW,
 					sqlMallocSize(p));
 		}
-		sqlMemdebugSetType(p, MEMTYPE_SCRATCH);
 	}
 
 #if !defined(NDEBUG)
@@ -457,10 +456,6 @@ sqlScratchFree(void *p)
 			sqlStatusDown(SQL_STATUS_SCRATCH_USED, 1);
 		} else {
 			/* Release memory back to the heap */
-			assert(sqlMemdebugHasType(p, MEMTYPE_SCRATCH));
-			assert(sqlMemdebugNoType
-			       (p, (u8) ~ MEMTYPE_SCRATCH));
-			sqlMemdebugSetType(p, MEMTYPE_HEAP);
 			if (sqlGlobalConfig.bMemstat) {
 				int iSize = sqlMallocSize(p);
 				sqlStatusDown
@@ -477,55 +472,25 @@ sqlScratchFree(void *p)
 }
 
 /*
- * TRUE if p is a lookaside memory allocation from db
- */
-#ifndef SQL_OMIT_LOOKASIDE
-static int
-isLookaside(sql * db, void *p)
-{
-	return SQL_WITHIN(p, db->lookaside.pStart, db->lookaside.pEnd);
-}
-#else
-#define isLookaside(A,B) 0
-#endif
-
-/*
  * Return the size of a memory allocation previously obtained from
  * sqlMalloc() or sql_malloc().
  */
 int
 sqlMallocSize(void *p)
 {
-	assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
 	return sql_sized_sizeof(p);
 }
 
 int
-sqlDbMallocSize(sql * db, void *p)
+sqlDbMallocSize(void *p)
 {
 	assert(p != 0);
-	if (db == 0 || !isLookaside(db, p)) {
-#if SQL_DEBUG
-		if (db == 0) {
-			assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP));
-			assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
-		} else {
-			assert(sqlMemdebugHasType
-			       (p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-			assert(sqlMemdebugNoType
-			       (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-		}
-#endif
-		return sql_sized_sizeof(p);
-	} else
-		return db->lookaside.sz;
+	return sql_sized_sizeof(p);
 }
 
 sql_uint64
 sql_msize(void *p)
 {
-	assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP));
-	assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
 	return p ? sql_sized_sizeof(p) : 0;
 }
 
@@ -537,8 +502,6 @@ sql_free(void *p)
 {
 	if (p == 0)
 		return;		/* IMP: R-49053-54554 */
-	assert(sqlMemdebugHasType(p, MEMTYPE_HEAP));
-	assert(sqlMemdebugNoType(p, (u8) ~ MEMTYPE_HEAP));
 	if (sqlGlobalConfig.bMemstat) {
 		sqlStatusDown(SQL_STATUS_MEMORY_USED,
 				  sqlMallocSize(p));
@@ -555,7 +518,7 @@ sql_free(void *p)
 static SQL_NOINLINE void
 measureAllocationSize(sql * db, void *p)
 {
-	*db->pnBytesFreed += sqlDbMallocSize(db, p);
+	*db->pnBytesFreed += sqlDbMallocSize(p);
 }
 
 /*
@@ -572,23 +535,7 @@ sqlDbFree(sql * db, void *p)
 			measureAllocationSize(db, p);
 			return;
 		}
-		if (isLookaside(db, p)) {
-			LookasideSlot *pBuf = (LookasideSlot *) p;
-#if SQL_DEBUG
-			/* Trash all content in the buffer being freed */
-			memset(p, 0xaa, db->lookaside.sz);
-#endif
-			pBuf->pNext = db->lookaside.pFree;
-			db->lookaside.pFree = pBuf;
-			db->lookaside.nOut--;
-			return;
-		}
 	}
-	assert(sqlMemdebugHasType(p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-	assert(sqlMemdebugNoType
-	       (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-	assert(db != 0 || sqlMemdebugNoType(p, MEMTYPE_LOOKASIDE));
-	sqlMemdebugSetType(p, MEMTYPE_HEAP);
 	sql_free(p);
 }
 
@@ -600,8 +547,6 @@ sqlRealloc(void *pOld, u64 nBytes)
 {
 	int nOld, nNew, nDiff;
 	void *pNew;
-	assert(sqlMemdebugHasType(pOld, MEMTYPE_HEAP));
-	assert(sqlMemdebugNoType(pOld, (u8) ~ MEMTYPE_HEAP));
 	if (pOld == 0) {
 		return sqlMalloc(nBytes);	/* IMP: R-04300-56712 */
 	}
@@ -698,9 +643,6 @@ dbMallocRawFinish(sql * db, u64 n)
 	p = sqlMalloc(n);
 	if (!p)
 		sqlOomFault(db);
-	sqlMemdebugSetType(p,
-			       (db->lookaside.bDisable ==
-				0) ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP);
 	return p;
 }
 
@@ -733,7 +675,6 @@ sqlDbMallocRaw(sql * db, u64 n)
 	if (db)
 		return sqlDbMallocRawNN(db, n);
 	p = sqlMalloc(n);
-	sqlMemdebugSetType(p, MEMTYPE_HEAP);
 	return p;
 }
 
@@ -785,8 +726,6 @@ sqlDbRealloc(sql * db, void *p, u64 n)
 	assert(db != 0);
 	if (p == 0)
 		return sqlDbMallocRawNN(db, n);
-	if (isLookaside(db, p) && n <= db->lookaside.sz)
-		return p;
 	return dbReallocFinish(db, p, n);
 }
 
@@ -797,27 +736,9 @@ dbReallocFinish(sql * db, void *p, u64 n)
 	assert(db != 0);
 	assert(p != 0);
 	if (db->mallocFailed == 0) {
-		if (isLookaside(db, p)) {
-			pNew = sqlDbMallocRawNN(db, n);
-			if (pNew) {
-				memcpy(pNew, p, db->lookaside.sz);
-				sqlDbFree(db, p);
-			}
-		} else {
-			assert(sqlMemdebugHasType
-			       (p, (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-			assert(sqlMemdebugNoType
-			       (p, (u8) ~ (MEMTYPE_LOOKASIDE | MEMTYPE_HEAP)));
-			sqlMemdebugSetType(p, MEMTYPE_HEAP);
-			pNew = sql_realloc64(p, n);
-			if (!pNew) {
-				sqlOomFault(db);
-			}
-			sqlMemdebugSetType(pNew,
-					       (db->lookaside.bDisable ==
-						0 ? MEMTYPE_LOOKASIDE :
-						MEMTYPE_HEAP));
-		}
+		pNew = sql_realloc64(p, n);
+		if (!pNew)
+			sqlOomFault(db);
 	}
 	return pNew;
 }
diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c
index 31d21db..c364055 100644
--- a/src/box/sql/printf.c
+++ b/src/box/sql/printf.c
@@ -874,7 +874,7 @@ sqlStrAccumEnlarge(StrAccum * p, int N)
 			if (!isMalloced(p) && p->nChar > 0)
 				memcpy(zNew, p->zText, p->nChar);
 			p->zText = zNew;
-			p->nAlloc = sqlDbMallocSize(p->db, zNew);
+			p->nAlloc = sqlDbMallocSize(zNew);
 			p->printfFlags |= SQL_PRINTF_MALLOCED;
 		} else {
 			sqlStrAccumReset(p);
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index c51a3cc..98a0ccb 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -2998,7 +2998,7 @@ void *sqlDbReallocOrFree(sql *, void *, u64);
 void *sqlDbRealloc(sql *, void *, u64);
 void sqlDbFree(sql *, void *);
 int sqlMallocSize(void *);
-int sqlDbMallocSize(sql *, void *);
+int sqlDbMallocSize(void *);
 void *sqlScratchMalloc(int);
 void sqlScratchFree(void *);
 void *sqlPageMalloc(int);
@@ -4902,48 +4902,6 @@ void sqlVdbeIOTraceSql(Vdbe *);
 #endif
 
 /*
- * These routines are available for the mem2.c debugging memory allocator
- * only.  They are used to verify that different "types" of memory
- * allocations are properly tracked by the system.
- *
- * sqlMemdebugSetType() sets the "type" of an allocation to one of
- * the MEMTYPE_* macros defined below.  The type must be a bitmask with
- * a single bit set.
- *
- * sqlMemdebugHasType() returns true if any of the bits in its second
- * argument match the type set by the previous sqlMemdebugSetType().
- * sqlMemdebugHasType() is intended for use inside assert() statements.
- *
- * sqlMemdebugNoType() returns true if none of the bits in its second
- * argument match the type set by the previous sqlMemdebugSetType().
- *
- * Perhaps the most important point is the difference between MEMTYPE_HEAP
- * and MEMTYPE_LOOKASIDE.  If an allocation is MEMTYPE_LOOKASIDE, that means
- * it might have been allocated by lookaside, except the allocation was
- * too large or lookaside was already full.  It is important to verify
- * that allocations that might have been satisfied by lookaside are not
- * passed back to non-lookaside free() routines.  Asserts such as the
- * example above are placed on the non-lookaside free() routines to verify
- * this constraint.
- *
- * All of this is no-op for a production build.  It only comes into
- * play when the sql_MEMDEBUG compile-time option is used.
- */
-#ifdef SQL_MEMDEBUG
-void sqlMemdebugSetType(void *, u8);
-int sqlMemdebugHasType(void *, u8);
-int sqlMemdebugNoType(void *, u8);
-#else
-#define sqlMemdebugSetType(X,Y)	/* no-op */
-#define sqlMemdebugHasType(X,Y)  1
-#define sqlMemdebugNoType(X,Y)   1
-#endif
-#define MEMTYPE_HEAP       0x01	/* General heap allocations */
-#define MEMTYPE_LOOKASIDE  0x02	/* Heap that might have been lookaside */
-#define MEMTYPE_SCRATCH    0x04	/* Scratch allocations */
-#define MEMTYPE_PCACHE     0x08	/* Page cache allocations */
-
-/*
  * Threading interface
  */
 #if SQL_MAX_WORKER_THREADS>0
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 697dffd..fbe5338 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -192,7 +192,7 @@ growOpArray(Vdbe * v, int nOp)
 	assert(nNew >= (p->nOpAlloc + nOp));
 	pNew = sqlDbRealloc(p->db, v->aOp, nNew * sizeof(Op));
 	if (pNew) {
-		p->szOpAlloc = sqlDbMallocSize(p->db, pNew);
+		p->szOpAlloc = sqlDbMallocSize(pNew);
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
 	}
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index d6375a6..1a0fa75 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -70,7 +70,7 @@ sqlVdbeCheckMemInvariants(Mem * p)
 
 	/* The szMalloc field holds the correct memory allocation size */
 	assert(p->szMalloc == 0
-	       || p->szMalloc == sqlDbMallocSize(p->db, p->zMalloc));
+	       || p->szMalloc == sqlDbMallocSize(p->zMalloc));
 
 	/* If p holds a string or blob, the Mem.z must point to exactly
 	 * one of the following:
@@ -112,8 +112,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 	testcase(bPreserve && pMem->z == 0);
 
 	assert(pMem->szMalloc == 0
-	       || pMem->szMalloc == sqlDbMallocSize(pMem->db,
-							pMem->zMalloc));
+	       || pMem->szMalloc == sqlDbMallocSize(pMem->zMalloc));
 	if (pMem->szMalloc < n) {
 		if (n < 32)
 			n = 32;
@@ -133,7 +132,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 			return SQL_NOMEM;
 		} else {
 			pMem->szMalloc =
-			    sqlDbMallocSize(pMem->db, pMem->zMalloc);
+			    sqlDbMallocSize(pMem->zMalloc);
 		}
 	}
 
@@ -993,7 +992,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	} else if (xDel == SQL_DYNAMIC) {
 		sqlVdbeMemRelease(pMem);
 		pMem->zMalloc = pMem->z = (char *)z;
-		pMem->szMalloc = sqlDbMallocSize(pMem->db, pMem->zMalloc);
+		pMem->szMalloc = sqlDbMallocSize(pMem->zMalloc);
 	} else {
 		sqlVdbeMemRelease(pMem);
 		pMem->z = (char *)z;
diff --git a/src/box/sql/whereexpr.c b/src/box/sql/whereexpr.c
index 30017b0..a954b17 100644
--- a/src/box/sql/whereexpr.c
+++ b/src/box/sql/whereexpr.c
@@ -107,8 +107,7 @@ whereClauseInsert(WhereClause * pWC, Expr * p, u16 wtFlags)
 		if (pOld != pWC->aStatic) {
 			sqlDbFree(db, pOld);
 		}
-		pWC->nSlot =
-		    sqlDbMallocSize(db, pWC->a) / sizeof(pWC->a[0]);
+		pWC->nSlot = sqlDbMallocSize(pWC->a) / sizeof(pWC->a[0]);
 	}
 	pTerm = &pWC->a[idx = pWC->nTerm++];
 	if (p && ExprHasProperty(p, EP_Unlikely)) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 03/21] sql: remove SQL_OK error/status code
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 01/21] sql: remove unused functions of " imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 02/21] sql: disable lookaside system imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 14:45   ` [tarantool-patches] " n.pettik
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 04/21] sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes imeevma
                   ` (18 subsequent siblings)
  21 siblings, 1 reply; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error/status code is part of getting rid of the SQL
error system.
---
 src/box/bind.c             |   2 +-
 src/box/execute.c          |   6 +-
 src/box/sql.c              |  44 +++++-----
 src/box/sql/analyze.c      |   6 +-
 src/box/sql/cursor.c       |   4 +-
 src/box/sql/date.c         |  10 +--
 src/box/sql/expr.c         |   2 +-
 src/box/sql/func.c         |   6 +-
 src/box/sql/insert.c       |   2 +-
 src/box/sql/legacy.c       |  10 +--
 src/box/sql/main.c         |  26 +++---
 src/box/sql/os.c           |  10 +--
 src/box/sql/os_unix.c      |  96 ++++++++++-----------
 src/box/sql/prepare.c      |  16 ++--
 src/box/sql/select.c       |  26 +++---
 src/box/sql/sqlInt.h       |   4 +-
 src/box/sql/status.c       |   4 +-
 src/box/sql/tarantoolInt.h |   4 +-
 src/box/sql/trigger.c      |   2 +-
 src/box/sql/vdbe.c         | 106 +++++++++++------------
 src/box/sql/vdbeapi.c      |  38 ++++----
 src/box/sql/vdbeaux.c      |  50 +++++------
 src/box/sql/vdbemem.c      |  76 ++++++++--------
 src/box/sql/vdbesort.c     | 210 ++++++++++++++++++++++-----------------------
 src/box/sql/where.c        |  74 ++++++++--------
 25 files changed, 416 insertions(+), 418 deletions(-)

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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 04/21] sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (2 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 03/21] sql: remove SQL_OK error/status code imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 05/21] sql: remove SQL_CANTOPEN errcode imeevma
                   ` (17 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing these error codes is part of getting rid of the SQL error
system.
---
 src/box/sql/legacy.c  |  4 ++--
 src/box/sql/os_unix.c | 47 -----------------------------------------------
 src/box/sql/sqlInt.h  |  6 ------
 src/box/sql/where.c   | 10 ----------
 4 files changed, 2 insertions(+), 65 deletions(-)

diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index e3024f2..600c53c 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -138,9 +138,9 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 				if (xCallback(pArg, nCol, azVals, azCols)) {
 					/* EVIDENCE-OF: R-38229-40159 If the callback function to
 					 * sql_exec() returns non-zero, then sql_exec() will
-					 * return SQL_ABORT.
+					 * return -1.
 					 */
-					rc = SQL_ABORT;
+					rc = -1;
 					sqlVdbeFinalize((Vdbe *) pStmt);
 					pStmt = 0;
 					goto exec_out;
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index fd9576e..d9e5656 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -164,9 +164,6 @@ robust_open(const char *z, int f, mode_t m)
 		if (fd >= SQL_MINIMUM_FILE_DESCRIPTOR)
 			break;
 		close(fd);
-		sql_log(SQL_WARNING,
-			    "attempt to open \"%s\" as file descriptor %d", z,
-			    fd);
 		fd = -1;
 		if (open("/dev/null", f, m) < 0)
 			break;
@@ -502,48 +499,6 @@ fileHasMoved(unixFile * pFile)
 }
 
 /*
- * Check a unixFile that is a database.  Verify the following:
- *
- * (1) There is exactly one hard link on the file
- * (2) The file is not a symbolic link
- * (3) The file has not been renamed or unlinked
- *
- * Issue sql_log(SQL_WARNING,...) messages if anything is not right.
- */
-static void
-verifyDbFile(unixFile * pFile)
-{
-	struct stat buf;
-	int rc;
-
-	/* These verifications occurs for the main database only */
-	if (pFile->ctrlFlags & UNIXFILE_NOLOCK)
-		return;
-
-	rc = fstat(pFile->h, &buf);
-	if (rc != 0) {
-		sql_log(SQL_WARNING, "cannot fstat db file %s",
-			    pFile->zPath);
-		return;
-	}
-	if (buf.st_nlink == 0) {
-		sql_log(SQL_WARNING, "file unlinked while open: %s",
-			    pFile->zPath);
-		return;
-	}
-	if (buf.st_nlink > 1) {
-		sql_log(SQL_WARNING, "multiple links to file: %s",
-			    pFile->zPath);
-		return;
-	}
-	if (fileHasMoved(pFile)) {
-		sql_log(SQL_WARNING, "file renamed while open: %s",
-			    pFile->zPath);
-		return;
-	}
-}
-
-/*
  * Attempt to set a system-lock on the file pFile.  The lock is
  * described by pLock.
  *
@@ -766,7 +721,6 @@ unixClose(sql_file * id)
 {
 	int rc;
 	unixFile *pFile = (unixFile *) id;
-	verifyDbFile(pFile);
 	unixUnlock(id, NO_LOCK);
 
 	/* unixFile.pInode is always valid here. Otherwise, a different close
@@ -1528,7 +1482,6 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 			robust_close(pNew, h, __LINE__);
 	} else {
 		pNew->pMethod = pLockingStyle;
-		verifyDbFile(pNew);
 	}
 	return rc;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index c989664..e3f50b0 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -358,10 +358,6 @@ struct sql_vfs {
 enum sql_ret_code {
 	/** Common error code. */
 	SQL_ERROR = 1,
-	/** Access permission denied. */
-	SQL_PERM,
-	/** Callback routine requested an abort. */
-	SQL_ABORT,
 	/** The database file is locked. */
 	SQL_BUSY,
 	/** A table in the database is locked. */
@@ -387,8 +383,6 @@ enum sql_ret_code {
 	/** 2nd parameter to sql_bind out of range. */
 	SQL_RANGE,
 	SQL_TARANTOOL_ERROR,
-	/** Warnings from sql_log(). */
-	SQL_WARNING,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
 	/** sql_step() has finished executing. */
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index c716a0e..0b1ccd9 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -742,7 +742,6 @@ constructAutomaticIndex(Parse * pParse,			/* The parsing context */
 	char *zNotUsed;		/* Extra space on the end of pIdx */
 	Bitmask idxCols;	/* Bitmap of columns used for indexing */
 	Bitmask extraCols;	/* Bitmap of additional columns */
-	u8 sentWarning = 0;	/* True if a warnning has been issued */
 	int iContinue = 0;	/* Jump here to skip excluded rows */
 	struct SrcList_item *pTabItem;	/* FROM clause term being indexed */
 	int addrCounter = 0;	/* Address where integer counter is initialized */
@@ -769,15 +768,6 @@ constructAutomaticIndex(Parse * pParse,			/* The parsing context */
 			int iCol = pTerm->u.leftColumn;
 			Bitmask cMask =
 			    iCol >= BMS ? MASKBIT(BMS - 1) : MASKBIT(iCol);
-			testcase(iCol == BMS);
-			testcase(iCol == BMS - 1);
-			if (!sentWarning) {
-				sql_log(SQL_WARNING_AUTOINDEX,
-					    "automatic index on %s(%s)",
-					    pTable->def->name,
-					    pTable->aCol[iCol].zName);
-				sentWarning = 1;
-			}
 			if ((idxCols & cMask) == 0) {
 				if (whereLoopResize
 				    (pParse->db, pLoop, nKeyCol + 1)) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 05/21] sql: remove SQL_CANTOPEN errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (3 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 04/21] sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code imeevma
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/os_unix.c | 89 +++++++--------------------------------------------
 src/box/sql/sqlInt.h  |  2 --
 2 files changed, 11 insertions(+), 80 deletions(-)

diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index d9e5656..18e42e5 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -318,66 +318,6 @@ struct unixInodeInfo {
 static unixInodeInfo *inodeList = 0;
 
 /*
- *
- * This function - unixLogErrorAtLine(), is only ever called via the macro
- * unixLogError().
- *
- * It is invoked after an error occurs in an OS function and errno has been
- * set. It logs a message using sql_log() containing the current value of
- * errno and, if possible, the human-readable equivalent from strerror() or
- * strerror_r().
- *
- * The first argument passed to the macro should be the error code that
- * will be returned to sql (e.g. SQL_IOERR_DELETE, SQL_CANTOPEN).
- * The two subsequent arguments should be the name of the OS function that
- * failed (e.g. "unlink", "open") and the associated file-system path,
- * if any.
- */
-#define unixLogError(a,b,c)     unixLogErrorAtLine(a,b,c,__LINE__)
-static int
-unixLogErrorAtLine(int errcode,	/* sql error code */
-		   const char *zFunc,	/* Name of OS function that failed */
-		   const char *zPath,	/* File path associated with error */
-		   int iLine	/* Source line number where error occurred */
-    )
-{
-	char *zErr;		/* Message from strerror() or equivalent */
-	int iErrno = errno;	/* Saved syscall error number */
-
-	zErr = strerror(iErrno);
-
-	if (zPath == 0)
-		zPath = "";
-	sql_log(errcode,
-		    "os_unix.c:%d: (%d) %s(%s) - %s",
-		    iLine, iErrno, zFunc, zPath, zErr);
-
-	return errcode;
-}
-
-/*
- * Close a file descriptor.
- *
- * We assume that close() almost always works, since it is only in a
- * very sick application or on a very sick platform that it might fail.
- * If it does fail, simply leak the file descriptor, but do log the
- * error.
- *
- * Note that it is not safe to retry close() after EINTR since the
- * file descriptor might have already been reused by another thread.
- * So we don't even try to recover from an EINTR.  Just log the error
- * and move on.
- */
-static void
-robust_close(unixFile * pFile, int h, int lineno)
-{
-	if (close(h) != 0) {
-		unixLogErrorAtLine(SQL_IOERR_CLOSE, "close",
-				   pFile ? pFile->zPath : 0, lineno);
-	}
-}
-
-/*
  * Set the pFile->lastErrno.  Do this in a subroutine as that provides
  * a convenient place to set a breakpoint.
  */
@@ -398,7 +338,7 @@ closePendingFds(unixFile * pFile)
 	UnixUnusedFd *pNext;
 	for (p = pInode->pUnused; p; p = pNext) {
 		pNext = p->pNext;
-		robust_close(pFile, p->fd, __LINE__);
+		close(p->fd);
 		sql_free(p);
 	}
 	pInode->pUnused = 0;
@@ -705,7 +645,7 @@ closeUnixFile(sql_file * id)
 	unixUnmapfile(pFile);
 #endif
 	if (pFile->h >= 0) {
-		robust_close(pFile, pFile->h, __LINE__);
+		close(pFile->h);
 		pFile->h = -1;
 	}
 	sql_free(pFile->pUnused);
@@ -946,8 +886,7 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
 /*
  * Open a file descriptor to the directory containing file zFilename.
  * If successful, *pFd is set to the opened file descriptor and
- * 0 is returned. If an error occurs, either SQL_NOMEM
- * or SQL_CANTOPEN is returned and *pFd is set to an undefined
+ * 0 is returned. If an error occurs, -1 is set to an undefined
  * value.
  *
  * The directory file descriptor is used for only one thing - to
@@ -987,7 +926,7 @@ openDirectory(const char *zFilename, int *pFd)
 	*pFd = fd;
 	if (fd >= 0)
 		return 0;
-	return unixLogError(SQL_CANTOPEN, "openDirectory", zDirname);
+	return -1;
 }
 
 /*
@@ -1032,8 +971,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 		if (pFile->szChunk <= 0) {
 			if (robust_ftruncate(pFile->h, nByte)) {
 				storeLastErrno(pFile, errno);
-				return unixLogError(SQL_IOERR_TRUNCATE,
-						    "ftruncate", pFile->zPath);
+				return -1;
 			}
 		}
 
@@ -1147,7 +1085,6 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
 	      i64 nNew		/* Required mapping size */
     )
 {
-	const char *zErr = "mmap";
 	int h = pFd->h;		/* File descriptor open on db file */
 	u8 *pOrig = (u8 *) pFd->pMapRegion;	/* Pointer to current file mapping */
 	i64 nOrig = pFd->mmapSizeActual;	/* Size of pOrig region in bytes */
@@ -1170,7 +1107,6 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
 			munmap(pReq, nOrig - nReuse);
 		#if !defined(__APPLE__) && !defined(__FreeBSD__)
 		pNew = mremap(pOrig, nReuse, nNew, MREMAP_MAYMOVE);
-		zErr = "mremap";
 		#else
 		pNew = mmap(pReq, nNew - nReuse, flags, MAP_SHARED, h, nReuse);
 		if (pNew != MAP_FAILED) {
@@ -1195,7 +1131,6 @@ unixRemapfile(unixFile * pFd,	/* File descriptor object */
 	if (pNew == MAP_FAILED) {
 		pNew = 0;
 		nNew = 0;
-		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
@@ -1472,14 +1407,14 @@ fillInUnixFile(sql_vfs * pVfs,	/* Pointer to vfs object */
 			 * implicit assumption here is that if fstat() fails, things are in
 			 * such bad shape that dropping a lock or two doesn't matter much.
 			 */
-			robust_close(pNew, h, __LINE__);
+			close(h);
 			h = -1;
 		}
 	}
 	storeLastErrno(pNew, 0);
 	if (rc != 0) {
 		if (h >= 0)
-			robust_close(pNew, h, __LINE__);
+			close(h);
 	} else {
 		pNew->pMethod = pLockingStyle;
 	}
@@ -1830,7 +1765,7 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 			fd = robust_open(zName, openFlags, openMode);
 		}
 		if (fd < 0) {
-			rc = unixLogError(SQL_CANTOPEN, "open", zName);
+			rc = -1;
 			goto open_finished;
 		}
 		
@@ -1886,7 +1821,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 		if (errno == ENOENT) {
 			rc = SQL_IOERR_DELETE_NOENT;
 		} else {
-			rc = unixLogError(SQL_IOERR_DELETE, "unlink", zPath);
+			rc = -1;
 		}
 		return rc;
 	}
@@ -1897,12 +1832,10 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 		if (rc == 0) {
 			struct stat buf;
 			if (fstat(fd, &buf)) {
-				rc = unixLogError(SQL_IOERR_DIR_FSYNC,
-						  "fsync", zPath);
+				rc = -1;
 			}
-			robust_close(0, fd, __LINE__);
+			close(fd);
 		} else {
-			assert(rc == SQL_CANTOPEN);
 			rc = 0;
 		}
 	}
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index e3f50b0..d8629ab 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -370,8 +370,6 @@ enum sql_ret_code {
 	SQL_NOTFOUND,
 	/** Insertion failed because database is full. */
 	SQL_FULL,
-	/** Unable to open the database file. */
-	SQL_CANTOPEN,
 	/** The database schema changed. */
 	SQL_SCHEMA,
 	/** String or BLOB exceeds size limit. */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (4 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 05/21] sql: remove SQL_CANTOPEN errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 14:58   ` [tarantool-patches] " n.pettik
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 07/21] sql: remove SQL_LOCKED errcode imeevma
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error/status code is part of getting rid of the SQL
error system.
---
 src/box/sql/os_unix.c |  2 +-
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/where.c   | 13 ++-----------
 3 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 18e42e5..75263e3 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -1047,7 +1047,7 @@ unixFileControl(sql_file * id, int op, void *pArg)
 			return rc;
 		}
 	}
-	return SQL_NOTFOUND;
+	return -1;
 }
 
 /*
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index d8629ab..bf1bf39 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -366,8 +366,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** Unknown opcode in sql_file_control(). */
-	SQL_NOTFOUND,
 	/** Insertion failed because database is full. */
 	SQL_FULL,
 	/** The database schema changed. */
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 0b1ccd9..060dfee 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1528,21 +1528,14 @@ whereEqualScanEst(Parse * pParse,	/* Parsing & code generating context */
 	assert(nEq >= 1);
 	assert(nEq <= (int) p->key_def->part_count);
 	assert(pBuilder->nRecValid < nEq);
-
-	/* If values are not available for all fields of the index to the left
-	 * of this one, no estimate can be made. Return SQL_NOTFOUND.
-	 */
-	if (pBuilder->nRecValid < (nEq - 1)) {
-		return SQL_NOTFOUND;
-	}
+	assert(pBuilder->nRecValid >= (nEq - 1));
 
 	rc = sqlStat4ProbeSetValue(pParse, p, &pRec, pExpr, 1, nEq - 1,
 				       &bOk);
 	pBuilder->pRec = pRec;
 	if (rc != 0)
 		return rc;
-	if (bOk == 0)
-		return SQL_NOTFOUND;
+	assert(bOk != 0);
 	pBuilder->nRecValid = nEq;
 
 	whereKeyStats(pParse, p, pRec, 0, a);
@@ -2542,8 +2535,6 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 								    pExpr->x.pList,
 								    &nOut);
 					}
-					if (rc == SQL_NOTFOUND)
-						rc = 0;
 					if (rc != 0)
 						break;	/* Jump out of the pTerm loop */
 					if (nOut) {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 07/21] sql: remove SQL_LOCKED errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (5 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 08/21] sql: remove SQL_FULL errcode imeevma
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/prepare.c |  5 -----
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/vdbeapi.c | 27 +--------------------------
 3 files changed, 1 insertion(+), 33 deletions(-)

diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index e7422e2..2083d27 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -207,11 +207,6 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
 
 /*
  * Rerun the compilation of a statement after a schema change.
- *
- * 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.
  */
 int
 sqlReprepare(Vdbe * p)
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index bf1bf39..1838245 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -360,8 +360,6 @@ enum sql_ret_code {
 	SQL_ERROR = 1,
 	/** The database file is locked. */
 	SQL_BUSY,
-	/** A table in the database is locked. */
-	SQL_LOCKED,
 	/** A malloc() failed. */
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 75078da..32f4608 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -427,33 +427,8 @@ sqlStep(Vdbe * p)
 	int rc;
 
 	assert(p);
-	if (p->magic != VDBE_MAGIC_RUN) {
-		/* We used to require that sql_reset() be called before retrying
-		 * sql_step() after any error or after SQL_DONE.  But beginning
-		 * with version 3.7.0, we changed this so that sql_reset() would
-		 * be called automatically instead of throwing the SQL_MISUSE error.
-		 * This "automatic-reset" change is not technically an incompatibility,
-		 * since any application that receives an SQL_MISUSE is broken by
-		 * definition.
-		 *
-		 * Nevertheless, some published applications that were originally written
-		 * for version 3.6.23 or earlier do in fact depend on SQL_MISUSE
-		 * returns, and those were broken by the automatic-reset change.  As a
-		 * a work-around, the SQL_OMIT_AUTORESET compile-time restores the
-		 * legacy behavior of returning SQL_MISUSE for cases where the
-		 * previous sql_step() returned something other than a SQL_LOCKED
-		 * or SQL_BUSY error.
-		 */
-#ifdef SQL_OMIT_AUTORESET
-		if ((rc = p->rc & 0xff) == SQL_BUSY || rc == SQL_LOCKED) {
-			sql_reset((sql_stmt *) p);
-		} else {
-			return SQL_MISUSE;
-		}
-#else
+	if (p->magic != VDBE_MAGIC_RUN)
 		sql_reset((sql_stmt *) p);
-#endif
-	}
 
 	/* Check that malloc() has not failed. If it has, return early. */
 	db = p->db;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 08/21] sql: remove SQL_FULL errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (6 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 07/21] sql: remove SQL_LOCKED errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 09/21] sql: remove SQL_MISUSE errcode imeevma
                   ` (13 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/os_unix.c | 2 +-
 src/box/sql/sqlInt.h  | 2 --
 src/box/sql/vdbeaux.c | 6 ++----
 3 files changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 75263e3..fa28c46 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -876,7 +876,7 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
 			return SQL_IOERR_WRITE;
 		} else {
 			storeLastErrno(pFile, 0);	/* not a system error */
-			return SQL_FULL;
+			return -1;
 		}
 	}
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 1838245..3c312b0 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -364,8 +364,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** Insertion failed because database is full. */
-	SQL_FULL,
 	/** The database schema changed. */
 	SQL_SCHEMA,
 	/** String or BLOB exceeds size limit. */
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 7f81fad..efc5103 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2179,7 +2179,6 @@ sqlVdbeHalt(Vdbe * p)
 	 *
 	 *     SQL_NOMEM
 	 *     SQL_IOERR
-	 *     SQL_FULL
 	 *
 	 * Then the internal cache might have been left in an inconsistent
 	 * state.  We need to rollback the statement transaction, if there is
@@ -2205,8 +2204,7 @@ sqlVdbeHalt(Vdbe * p)
 
 		/* Check for one of the special errors */
 		mrc = p->rc & 0xff;
-		isSpecialError = mrc == SQL_NOMEM || mrc == SQL_IOERR ||
-				 mrc == SQL_FULL;
+		isSpecialError = mrc == SQL_NOMEM || mrc == SQL_IOERR;
 		if (isSpecialError) {
 			/* At least a savepoint transaction must be rolled back
 			 * to restore the database to a consistent state.
@@ -2218,7 +2216,7 @@ sqlVdbeHalt(Vdbe * p)
 			 * pagerStress() in pager.c), the rollback is required to restore
 			 * the pager to a consistent state.
 			 */
-			if ((mrc == SQL_NOMEM || mrc == SQL_FULL)
+			if ((mrc == SQL_NOMEM)
 			    && box_txn()) {
 				eStatementOp = SAVEPOINT_ROLLBACK;
 			} else {
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 09/21] sql: remove SQL_MISUSE errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (7 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 08/21] sql: remove SQL_FULL errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 10/21] sql: remove SQL_RANGE errcode imeevma
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/malloc.c  | 56 ---------------------------------------------------
 src/box/sql/sqlInt.h  | 13 ------------
 src/box/sql/status.c  | 33 ------------------------------
 src/box/sql/vdbeapi.c |  6 +-----
 4 files changed, 1 insertion(+), 107 deletions(-)

diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 5c9c8d5..6ed9aeb 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -174,38 +174,6 @@ static SQL_WSD struct Mem0Global {
 
 #define mem0 GLOBAL(struct Mem0Global, mem0)
 
-
-/*
- * Set the soft heap-size limit for the library. Passing a zero or
- * negative value indicates no limit.
- */
-sql_int64
-sql_soft_heap_limit64(sql_int64 n)
-{
-	sql_int64 priorLimit;
-	sql_int64 excess;
-	sql_int64 nUsed;
-	priorLimit = mem0.alarmThreshold;
-	if (n < 0) {
-		return priorLimit;
-	}
-	mem0.alarmThreshold = n;
-	nUsed = sqlStatusValue(SQL_STATUS_MEMORY_USED);
-	mem0.nearlyFull = (n > 0 && n <= nUsed);
-	excess = sql_memory_used() - n;
-	if (excess > 0)
-		sql_release_memory((int)(excess & 0x7fffffff));
-	return priorLimit;
-}
-
-void
-sql_soft_heap_limit(int n)
-{
-	if (n < 0)
-		n = 0;
-	sql_soft_heap_limit64(n);
-}
-
 /*
  * Initialize the memory allocation subsystem.
  */
@@ -263,30 +231,6 @@ sqlMallocEnd(void)
 }
 
 /*
- * Return the amount of memory currently checked out.
- */
-sql_int64
-sql_memory_used(void)
-{
-	sql_int64 res, mx;
-	sql_status64(SQL_STATUS_MEMORY_USED, &res, &mx, 0);
-	return res;
-}
-
-/*
- * Return the maximum amount of memory that has ever been
- * checked out since either the beginning of this process
- * or since the most recent reset.
- */
-sql_int64
-sql_memory_highwater(int resetFlag)
-{
-	sql_int64 res, mx;
-	sql_status64(SQL_STATUS_MEMORY_USED, &res, &mx, resetFlag);
-	return mx;
-}
-
-/*
  * Trigger the alarm
  */
 static void
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 3c312b0..e6bd5ba 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -370,8 +370,6 @@ enum sql_ret_code {
 	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
 	SQL_CONSTRAINT,
-	/** Library used incorrectly. */
-	SQL_MISUSE,
 	/** 2nd parameter to sql_bind out of range. */
 	SQL_RANGE,
 	SQL_TARANTOOL_ERROR,
@@ -690,9 +688,6 @@ sql_os_end(void);
 #define SQL_STATUS_SCRATCH_SIZE         8
 #define SQL_STATUS_MALLOC_COUNT         9
 
-sql_int64
-sql_memory_used(void);
-
 int
 sql_create_function_v2(sql * db,
 			   const char *zFunctionName,
@@ -751,11 +746,6 @@ sql_vfs_find(const char *zVfsName);
 #define SQL_TESTCTRL_SORTER_MMAP             24
 #define SQL_TESTCTRL_LAST                    24
 
-int
-sql_status64(int op, sql_int64 * pCurrent,
-		 sql_int64 * pHighwater,
-		 int resetFlag);
-
 
 typedef struct sql_io_methods sql_io_methods;
 struct sql_io_methods {
@@ -795,9 +785,6 @@ struct sql_io_methods {
 int
 sql_os_init(void);
 
-sql_int64
-sql_soft_heap_limit64(sql_int64 N);
-
 int
 sql_limit(sql *, int id, int newVal);
 
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index 2d4eae0..10be3d9 100644
--- a/src/box/sql/status.c
+++ b/src/box/sql/status.c
@@ -127,39 +127,6 @@ sqlStatusHighwater(int op, int X)
 }
 
 /*
- * Query status information.
- */
-int
-sql_status64(int op,
-		 sql_int64 * pCurrent,
-		 sql_int64 * pHighwater, int resetFlag)
-{
-	wsdStatInit;
-	if (op < 0 || op >= ArraySize(wsdStat.nowValue)) {
-		return SQL_MISUSE;
-	}
-	*pCurrent = wsdStat.nowValue[op];
-	*pHighwater = wsdStat.mxValue[op];
-	if (resetFlag) {
-		wsdStat.mxValue[op] = wsdStat.nowValue[op];
-	}
-	return 0;
-}
-
-int
-sql_status(int op, int *pCurrent, int *pHighwater, int resetFlag)
-{
-	sql_int64 iCur = 0, iHwtr = 0;
-	int rc;
-	rc = sql_status64(op, &iCur, &iHwtr, resetFlag);
-	if (rc == 0) {
-		*pCurrent = (int)iCur;
-		*pHighwater = (int)iHwtr;
-	}
-	return rc;
-}
-
-/*
  * Query status information for a single database connection
  */
 int
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 32f4608..c4891a5 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -976,11 +976,7 @@ vdbeUnbind(Vdbe * p, int i)
 {
 	Mem *pVar;
 	assert(p != NULL);
-	if (p->magic != VDBE_MAGIC_RUN || p->pc >= 0) {
-		sql_log(SQL_MISUSE,
-			    "bind on a busy prepared statement: [%s]", p->zSql);
-		return SQL_MISUSE;
-	}
+	assert(p->magic == VDBE_MAGIC_RUN && p->pc < 0);
 	if (i < 1 || i > p->nVar) {
 		return SQL_RANGE;
 	}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 10/21] sql: remove SQL_RANGE errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (8 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 09/21] sql: remove SQL_MISUSE errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 11/21] sql: remove SQL_SCHEMA errcode imeevma
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/vdbeapi.c | 10 ++--------
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index e6bd5ba..8da946a 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -370,8 +370,6 @@ enum sql_ret_code {
 	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
 	SQL_CONSTRAINT,
-	/** 2nd parameter to sql_bind out of range. */
-	SQL_RANGE,
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index c4891a5..c697efb 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -965,11 +965,7 @@ sql_column_origin_name(sql_stmt * pStmt, int N)
  */
 /*
  * Unbind the value bound to variable i in virtual machine p. This is the
- * the same as binding a NULL value to the column. If the "i" parameter is
- * out of range, then SQL_RANGE is returned. Othewise 0.
- *
- * The error code stored in database p->db is overwritten with the return
- * value in any case.
+ * the same as binding a NULL value to the column.
  */
 static int
 vdbeUnbind(Vdbe * p, int i)
@@ -977,9 +973,7 @@ vdbeUnbind(Vdbe * p, int i)
 	Mem *pVar;
 	assert(p != NULL);
 	assert(p->magic == VDBE_MAGIC_RUN && p->pc < 0);
-	if (i < 1 || i > p->nVar) {
-		return SQL_RANGE;
-	}
+	assert(i > 0 && i <= p->nVar);
 	i--;
 	pVar = &p->aVar[i];
 	sqlVdbeMemRelease(pVar);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 11/21] sql: remove SQL_SCHEMA errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (9 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 10/21] sql: remove SQL_RANGE errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 16:18   ` [tarantool-patches] " n.pettik
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 12/21] sql: remove SQL_TOOBIG errcode imeevma
                   ` (10 subsequent siblings)
  21 siblings, 1 reply; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/prepare.c | 45 ++-------------------------------------------
 src/box/sql/sqlInt.h  |  3 ---
 src/box/sql/vdbe.c    |  5 +----
 src/box/sql/vdbeInt.h |  8 --------
 src/box/sql/vdbeapi.c | 23 +++--------------------
 5 files changed, 6 insertions(+), 78 deletions(-)

diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 2083d27..61081fb 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -190,56 +190,15 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
 		      sql_stmt ** ppStmt,	/* OUT: A pointer to the prepared statement */
 		      const char **pzTail)	/* OUT: End of parsed string */
 {
-	int rc;
-
 	*ppStmt = 0;
 	assert(zSql != NULL && db != NULL);
-	rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
-			    pzTail);
-	if (rc == SQL_SCHEMA) {
-		sql_finalize(*ppStmt);
-		rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
-				    pzTail);
-	}
-	assert(rc == 0 || *ppStmt == 0);
-	return rc;
-}
-
-/*
- * Rerun the compilation of a statement after a schema change.
- */
-int
-sqlReprepare(Vdbe * p)
-{
-	int rc;
-	sql_stmt *pNew;
-	const char *zSql;
-	sql *db;
-
-	zSql = sql_sql((sql_stmt *) p);
-	assert(zSql != 0);	/* Reprepare only called for prepare_v2() statements */
-	db = sqlVdbeDb(p);
-	rc = sqlLockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
-	if (rc) {
-		if (rc == SQL_NOMEM) {
-			sqlOomFault(db);
-		}
-		assert(pNew == 0);
-		return rc;
-	} else {
-		assert(pNew != 0);
-	}
-	sqlVdbeSwap((Vdbe *) pNew, p);
-	sqlTransferBindings(pNew, (sql_stmt *) p);
-	sqlVdbeResetStepResult((Vdbe *) pNew);
-	sqlVdbeFinalize((Vdbe *) pNew);
-	return 0;
+	return sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
 }
 
 /*
  * Two versions of the official API.  Legacy and new use.  In the legacy
  * version, the original SQL text is not saved in the prepared statement
- * and so if a schema change occurs, SQL_SCHEMA is returned by
+ * and so if a schema change occurs, error is returned by
  * sql_step().  In the new version, the original SQL text is retained
  * and the statement is automatically recompiled if an schema change
  * occurs.
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 8da946a..0419933 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -364,8 +364,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** The database schema changed. */
-	SQL_SCHEMA,
 	/** String or BLOB exceeds size limit. */
 	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
@@ -4687,7 +4685,6 @@ void sqlInvalidFunction(sql_context *, int, sql_value **);
 sql_int64 sqlStmtCurrentTime(sql_context *);
 int sqlVdbeParameterIndex(Vdbe *, const char *, int);
 int sqlTransferBindings(sql_stmt *, sql_stmt *);
-int sqlReprepare(Vdbe *);
 
 /**
  * This function verifies that two collations (to be more precise
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index a1be48d..27ad06f 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -5142,10 +5142,7 @@ case OP_AggFinal: {
 
 /* Opcode: Expire P1 * * * *
  *
- * Cause precompiled statements to expire.  When an expired statement
- * is executed using sql_step() it will either automatically
- * reprepare itself (if it was originally created using sql_prepare_v2())
- * or it will fail with SQL_SCHEMA.
+ * Cause precompiled statements to expire.
  *
  * If P1 is 0, then all SQL statements become expired. If P1 is non-zero,
  * then only the currently executing statement is expired.
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index a163940..59a5cc8 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -40,14 +40,6 @@
 #define SQL_VDBEINT_H
 
 /*
- * The maximum number of times that a statement will try to reparse
- * itself before giving up and returning SQL_SCHEMA.
- */
-#ifndef SQL_MAX_SCHEMA_RETRY
-#define SQL_MAX_SCHEMA_RETRY 50
-#endif
-
-/*
  * SQL is translated into a sequence of instructions to be
  * executed by a virtual machine.  Each instruction is an instance
  * of the following structure.
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index c697efb..78b6db9 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -438,9 +438,8 @@ sqlStep(Vdbe * p)
 	}
 
 	if (p->pc <= 0 && p->expired) {
-		p->rc = SQL_SCHEMA;
-		rc = SQL_ERROR;
-		goto end_of_step;
+		p->rc = SQL_TARANTOOL_ERROR;
+		return SQL_TARANTOOL_ERROR;
 	}
 	if (p->pc < 0) {
 
@@ -473,7 +472,6 @@ sqlStep(Vdbe * p)
 	if (SQL_NOMEM == sqlApiExit(p->db, p->rc)) {
 		p->rc = SQL_NOMEM;
 	}
- end_of_step:
 	if (p->isPrepareV2 && rc != SQL_ROW && rc != SQL_DONE) {
 		/* If this statement was prepared using sql_prepare_v2(), and an
 		 * error has occurred, then return the error code in p->rc to the
@@ -492,24 +490,9 @@ sqlStep(Vdbe * p)
 int
 sql_step(sql_stmt * pStmt)
 {
-	int rc;			/* Result from sqlStep() */
 	Vdbe *v = (Vdbe *) pStmt;	/* the prepared statement */
-	int cnt = 0;		/* Counter to prevent infinite loop of reprepares */
-
 	assert(v != NULL);
-	v->doingRerun = 0;
-	while ((rc = sqlStep(v)) == SQL_SCHEMA
-	       && cnt++ < SQL_MAX_SCHEMA_RETRY) {
-		int savedPc = v->pc;
-		rc = sqlReprepare(v);
-		if (rc != 0)
-			break;
-		sql_reset(pStmt);
-		if (savedPc >= 0)
-			v->doingRerun = 1;
-		assert(v->expired == 0);
-	}
-	return rc;
+	return sqlStep(v);
 }
 
 /*
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 12/21] sql: remove SQL_TOOBIG errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (10 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 11/21] sql: remove SQL_SCHEMA errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 16:11   ` [tarantool-patches] " n.pettik
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 13/21] sql: remove SQL_BUSY errcode imeevma
                   ` (9 subsequent siblings)
  21 siblings, 1 reply; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/bind.c        | 13 ++-----------
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/vdbeapi.c | 25 +++++++++++++------------
 src/box/sql/vdbemem.c | 10 +++++++---
 4 files changed, 22 insertions(+), 28 deletions(-)

diff --git a/src/box/bind.c b/src/box/bind.c
index 90d56d6..754f6c7 100644
--- a/src/box/bind.c
+++ b/src/box/bind.c
@@ -207,16 +207,7 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 	}
 	if (rc == 0)
 		return 0;
-
-	switch (rc) {
-	case SQL_NOMEM:
-		diag_set(OutOfMemory, p->bytes, "vdbe", "bind value");
-		break;
-	case SQL_TOOBIG:
-	default:
-		diag_set(ClientError, ER_SQL_BIND_VALUE, sql_bind_name(p),
-			 mp_type_strs[p->type]);
-		break;
-	}
+	diag_set(ClientError, ER_SQL_BIND_VALUE, sql_bind_name(p),
+		 mp_type_strs[p->type]);
 	return -1;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0419933..fee6857 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -364,8 +364,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** String or BLOB exceeds size limit. */
-	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
 	SQL_CONSTRAINT,
 	SQL_TARANTOOL_ERROR,
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 78b6db9..55b4b2e 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -272,7 +272,7 @@ sql_value_free(sql_value * pOld)
  *
  * The setStrOrError() function calls sqlVdbeMemSetStr() to store the
  * result as a string or blob but if the string or blob is too large, it
- * then sets the error code to SQL_TOOBIG
+ * then sets the error code.
  *
  * The invokeValueDestructor(P,X) routine invokes destructor function X()
  * on value P is not going to be used and need to be destroyed.
@@ -284,16 +284,14 @@ setResultStrOrError(sql_context * pCtx,	/* Function context */
 		    void (*xDel) (void *)	/* Destructor function */
     )
 {
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,1, xDel) == SQL_TOOBIG) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,1, xDel) != 0)
 		pCtx->is_aborted = true;
-	}
 }
 
 static int
 invokeValueDestructor(const void *p,	/* Value to destroy */
 		      void (*xDel) (void *),	/* The destructor */
-		      sql_context * pCtx	/* Set a SQL_TOOBIG error if no NULL */
+		      sql_context * pCtx	/* Set an error if no NULL */
     )
 {
 	assert(xDel != SQL_DYNAMIC);
@@ -305,10 +303,11 @@ invokeValueDestructor(const void *p,	/* Value to destroy */
 		xDel((void *)p);
 	}
 	if (pCtx) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
 		pCtx->is_aborted = true;
 	}
-	return SQL_TOOBIG;
+	return SQL_TARANTOOL_ERROR;
 }
 
 void
@@ -317,10 +316,8 @@ sql_result_blob(sql_context * pCtx,
     )
 {
 	assert(n >= 0);
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,0, xDel) == SQL_TOOBIG) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,0, xDel) != 0)
 		pCtx->is_aborted = true;
-	}
 }
 
 void
@@ -405,7 +402,9 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n)
 {
 	Mem *pOut = pCtx->pOut;
 	if (n > (u64) pOut->db->aLimit[SQL_LIMIT_LENGTH]) {
-		return SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		return SQL_TARANTOOL_ERROR;
 	}
 	sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n);
 	return 0;
@@ -1189,7 +1188,9 @@ sql_bind_zeroblob64(sql_stmt * pStmt, int i, sql_uint64 n)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	if (n > (u64) p->db->aLimit[SQL_LIMIT_LENGTH]) {
-		rc = SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		rc = SQL_TARANTOOL_ERROR;
 	} else {
 		assert((n & 0x7FFFFFFF) == n);
 		rc = sql_bind_zeroblob(pStmt, i, n);
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 4bb82b8..8be2e69 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -936,7 +936,7 @@ sqlVdbeMemMove(Mem * pTo, Mem * pFrom)
  * size limit) then no memory allocation occurs.  If the string can be
  * stored without allocating memory, then it is.  If a memory allocation
  * is required to store the string, then value of pMem is unchanged.  In
- * either case, SQL_TOOBIG is returned.
+ * either case, error is returned.
  */
 int
 sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
@@ -980,7 +980,9 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 			nAlloc += 1; //SQL_UTF8
 		}
 		if (nByte > iLimit) {
-			return SQL_TOOBIG;
+			diag_set(ClientError, ER_SQL_EXECUTE, "string or blob "\
+				 "is too big");
+			return SQL_TARANTOOL_ERROR;
 		}
 		testcase(nAlloc == 0);
 		testcase(nAlloc == 31);
@@ -1004,7 +1006,9 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	pMem->flags = flags;
 
 	if (nByte > iLimit) {
-		return SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		return SQL_TARANTOOL_ERROR;
 	}
 
 	return 0;
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 13/21] sql: remove SQL_BUSY errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (11 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 12/21] sql: remove SQL_TOOBIG errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 14/21] sql: remove SQL_CONSTRAINT errcode imeevma
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/main.c    |  2 +-
 src/box/sql/os_unix.c |  4 +---
 src/box/sql/sqlInt.h  |  2 --
 src/box/sql/vdbe.c    | 20 ++++++--------------
 src/box/sql/vdbeaux.c | 14 ++++----------
 5 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 65d8de5..052683e 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -266,7 +266,7 @@ sqlCreateFunc(sql * db,
 
 
 	/* Check if an existing function is being overridden or deleted. If so,
-	 * and there are active VMs, then return SQL_BUSY. If a function
+	 * and there are active VMs, then return an error. If a function
 	 * is being overridden/deleted but there are no active VMs, allow the
 	 * operation to continue but invalidate all precompiled statements.
 	 */
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index fa28c46..69f6867 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -554,9 +554,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 					/* In theory, the call to unixFileLock() cannot fail because another
 					 * process is holding an incompatible lock. If it does, this
 					 * indicates that the other process is not following the locking
-					 * protocol. If this happens, return SQL_IOERR_RDLOCK. Returning
-					 * SQL_BUSY would confuse the upper layer (in practice it causes
-					 * an assert to fail).
+					 * protocol. If this happens, return SQL_IOERR_RDLOCK.
 					 */
 					rc = SQL_IOERR_RDLOCK;
 					storeLastErrno(pFile, errno);
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index fee6857..3cf2b8d 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -358,8 +358,6 @@ struct sql_vfs {
 enum sql_ret_code {
 	/** Common error code. */
 	SQL_ERROR = 1,
-	/** The database file is locked. */
-	SQL_BUSY,
 	/** A malloc() failed. */
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 27ad06f..f4859b8 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -638,7 +638,7 @@ int sqlVdbeExec(Vdbe *p)
 		 */
 		goto no_mem;
 	}
-	assert(p->rc==0 || (p->rc&0xff)==SQL_BUSY);
+	assert(p->rc == 0);
 	p->rc = 0;
 	p->iCurrentTime = 0;
 	assert(p->explain==0);
@@ -981,13 +981,9 @@ case OP_Halt: {
 		assert(! diag_is_empty(diag_get()));
 	}
 	rc = sqlVdbeHalt(p);
-	assert(rc==SQL_BUSY || rc==0 || rc==SQL_ERROR);
-	if (rc==SQL_BUSY) {
-		p->rc = SQL_BUSY;
-	} else {
-		assert(rc==0 || (p->rc&0xff)==SQL_CONSTRAINT);
-		rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
-	}
+	assert(rc == 0 || rc==SQL_ERROR);
+	assert(rc==0 || (p->rc&0xff)==SQL_CONSTRAINT);
+	rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	goto vdbe_return;
 }
 
@@ -2900,11 +2896,7 @@ case OP_Savepoint: {
 				if ((rc = sqlVdbeCheckFk(p, 1))!=0) {
 					goto vdbe_return;
 				}
-				if (sqlVdbeHalt(p)==SQL_BUSY) {
-					p->pc = (int)(pOp - aOp);
-					p->rc = rc = SQL_BUSY;
-					goto vdbe_return;
-				}
+				sqlVdbeHalt(p);
 				if (p->rc != 0)
 					goto abort_due_to_error;
 			} else {
@@ -5313,7 +5305,7 @@ vdbe_return:
 	assert(rc!=0 || nExtraDelete==0
 		|| sql_strlike_ci("DELETE%", p->zSql, 0) != 0
 		);
-	assert(rc == 0 || rc == SQL_BUSY || rc == SQL_TARANTOOL_ERROR ||
+	assert(rc == 0 || rc == SQL_TARANTOOL_ERROR ||
 	       rc == SQL_ROW || rc == SQL_DONE);
 	return rc;
 
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index efc5103..4f06369 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1420,8 +1420,7 @@ sqlVdbeList(Vdbe * p)
 
 	assert(p->explain);
 	assert(p->magic == VDBE_MAGIC_RUN);
-	assert(p->rc == 0 || p->rc == SQL_BUSY
-	       || p->rc == SQL_NOMEM);
+	assert(p->rc == 0 || p->rc == SQL_NOMEM);
 
 	/* Even though this opcode does not use dynamic strings for
 	 * the result, result columns may become dynamic if the user calls
@@ -2161,9 +2160,7 @@ sql_savepoint(MAYBE_UNUSED Vdbe *p, const char *zName)
  * SQL_MAGIC_RUN to SQL_MAGIC_HALT.  It is harmless to
  * call this on a VM that is in the SQL_MAGIC_HALT state.
  *
- * Return an error code.  If the commit could not complete because of
- * lock contention, return SQL_BUSY.  If SQL_BUSY is returned, it
- * means the close did not happen and needs to be repeated.
+ * Return an error code.
  */
 int
 sqlVdbeHalt(Vdbe * p)
@@ -2268,10 +2265,7 @@ sqlVdbeHalt(Vdbe * p)
 					     0 : SQL_TARANTOOL_ERROR;
 					closeCursorsAndFree(p);
 				}
-				if (rc == SQL_BUSY && !p->pDelFrame) {
-					closeCursorsAndFree(p);
-					return SQL_BUSY;
-				} else if (rc != 0) {
+				if (rc != 0) {
 					p->rc = rc;
 					box_txn_rollback();
 					closeCursorsAndFree(p);
@@ -2348,7 +2342,7 @@ sqlVdbeHalt(Vdbe * p)
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
 	       p->anonymous_savepoint == NULL);
-	return (p->rc == SQL_BUSY ? SQL_BUSY : 0);
+	return 0;
 }
 
 /*
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 14/21] sql: remove SQL_CONSTRAINT errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (12 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 13/21] sql: remove SQL_BUSY errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 15/21] sql: remove SQL_ERROR errcode imeevma
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/fk_constraint.c |  4 ++--
 src/box/sql/sqlInt.h        |  8 --------
 src/box/sql/vdbe.c          |  1 -
 src/box/sql/vdbeaux.c       | 10 +++-------
 4 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/src/box/sql/fk_constraint.c b/src/box/sql/fk_constraint.c
index 602f439..542709a 100644
--- a/src/box/sql/fk_constraint.c
+++ b/src/box/sql/fk_constraint.c
@@ -45,7 +45,7 @@
  *
  * Foreign keys in sql come in two flavours: deferred and immediate.
  * If an immediate foreign key constraint is violated,
- * SQL_CONSTRAINT_FOREIGNKEY is returned and the current
+ * -1 is returned and the current
  * statement transaction rolled back. If a
  * deferred foreign key constraint is violated, no action is taken
  * immediately. However if the application attempts to commit the
@@ -111,7 +111,7 @@
  * is that the counter used is stored as part of each individual statement
  * object (struct Vdbe). If, after the statement has run, its immediate
  * constraint counter is greater than zero,
- * it returns SQL_CONSTRAINT_FOREIGNKEY
+ * it returns -1.
  * and the statement transaction is rolled back. An exception is an INSERT
  * statement that inserts a single row only (no triggers). In this case,
  * instead of using a counter, an exception is thrown immediately if the
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 3cf2b8d..802a367 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -363,7 +363,6 @@ enum sql_ret_code {
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
 	/** Abort due to constraint violation. */
-	SQL_CONSTRAINT,
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
@@ -593,13 +592,6 @@ sql_exec(sql *,	/* An open database */
 #define SQL_IOERR_GETTEMPPATH       (SQL_IOERR | (25<<8))
 #define SQL_IOERR_CONVPATH          (SQL_IOERR | (26<<8))
 #define SQL_IOERR_VNODE             (SQL_IOERR | (27<<8))
-#define SQL_CONSTRAINT_CHECK        (SQL_CONSTRAINT | (1<<8))
-#define SQL_CONSTRAINT_FOREIGNKEY   (SQL_CONSTRAINT | (3<<8))
-#define SQL_CONSTRAINT_FUNCTION     (SQL_CONSTRAINT | (4<<8))
-#define SQL_CONSTRAINT_NOTNULL      (SQL_CONSTRAINT | (5<<8))
-#define SQL_CONSTRAINT_PRIMARYKEY   (SQL_CONSTRAINT | (6<<8))
-#define SQL_CONSTRAINT_TRIGGER      (SQL_CONSTRAINT | (7<<8))
-#define SQL_CONSTRAINT_UNIQUE       (SQL_CONSTRAINT | (8<<8))
 
 /**
  * Subtype of a main type. Allows to do some subtype specific
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index f4859b8..9a9ca55 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -982,7 +982,6 @@ case OP_Halt: {
 	}
 	rc = sqlVdbeHalt(p);
 	assert(rc == 0 || rc==SQL_ERROR);
-	assert(rc==0 || (p->rc&0xff)==SQL_CONSTRAINT);
 	rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	goto vdbe_return;
 }
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 4f06369..308373b 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2088,8 +2088,7 @@ sqlVdbeCloseStatement(Vdbe * p, int eOp)
  * 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
- * and write an error message to it. Then return SQL_ERROR.
+ * SQL_TARANTOOL_ERROR and set an error.
  */
 int
 sqlVdbeCheckFk(Vdbe * p, int deferred)
@@ -2253,7 +2252,6 @@ sqlVdbeHalt(Vdbe * p)
 						closeCursorsAndFree(p);
 						return SQL_ERROR;
 					}
-					rc = SQL_CONSTRAINT_FOREIGNKEY;
 				} else {
 					/* The auto-commit flag is true, the vdbe program was successful
 					 * or hit an 'OR FAIL' constraint and there are no deferred foreign
@@ -2296,17 +2294,15 @@ 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 0 or SQL_CONSTRAINT, then promote the
+		 * error code is 0 or -1, then promote the
 		 * current statement error code.
 		 */
 		if (eStatementOp) {
 			rc = sqlVdbeCloseStatement(p, eStatementOp);
 			if (rc) {
 				box_txn_rollback();
-				if (p->rc == 0
-				    || (p->rc & 0xff) == SQL_CONSTRAINT) {
+				if (p->rc == 0)
 					p->rc = rc;
-				}
 				closeCursorsAndFree(p);
 				sqlRollbackAll(p);
 				sqlCloseSavepoints(p);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 15/21] sql: remove SQL_ERROR errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (13 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 14/21] sql: remove SQL_CONSTRAINT errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 16/21] sql: remove SQL_NOMEM errcode imeevma
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/date.c     |  4 ++--
 src/box/sql/main.c     |  2 +-
 src/box/sql/os_unix.c  |  5 ++---
 src/box/sql/select.c   | 12 ++++++------
 src/box/sql/sqlInt.h   |  4 +---
 src/box/sql/status.c   |  2 +-
 src/box/sql/vdbe.c     |  2 +-
 src/box/sql/vdbeapi.c  |  2 +-
 src/box/sql/vdbeaux.c  | 12 ++++++------
 src/box/sql/vdbemem.c  |  6 +++---
 src/box/sql/vdbesort.c |  2 +-
 11 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/src/box/sql/date.c b/src/box/sql/date.c
index e193035..547932b 100644
--- a/src/box/sql/date.c
+++ b/src/box/sql/date.c
@@ -578,7 +578,7 @@ osLocaltime(time_t * t, struct tm *pTm)
  * (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 0.
  *
- * Or, if an error does occur, set *pRc to SQL_ERROR. The returned value
+ * Or, if an error does occur, set *pRc to -1. The returned value
  * is undefined in this case.
  */
 static sql_int64
@@ -619,7 +619,7 @@ localtimeOffset(DateTime * p,	/* Date at which to calculate offset */
 	if (osLocaltime(&t, &sLocal)) {
 		diag_set(ClientError, ER_SQL_EXECUTE, "local time unavailable");
 		pCtx->is_aborted = true;
-		*pRc = SQL_ERROR;
+		*pRc = -1;
 		return 0;
 	}
 	y.Y = sLocal.tm_year + 1900;
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 052683e..8474836 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -320,7 +320,7 @@ sql_create_function_v2(sql * db,
 			   void (*xFinal) (sql_context *),
 			   void (*xDestroy) (void *))
 {
-	int rc = SQL_ERROR;
+	int rc = -1;
 	FuncDestructor *pArg = 0;
 
 	if (xDestroy) {
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 69f6867..8b3aec1 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -1482,7 +1482,7 @@ unixGetTempname(int nBuf, char *zBuf)
 				 "%s/" SQL_TEMP_FILE_PREFIX "%llx%c", zDir,
 				 r, 0);
 		if (zBuf[nBuf - 2] != 0 || (iLimit++) > 10)
-			return SQL_ERROR;
+			return -1;
 	} while (access(zBuf, 0) == 0);
 	return 0;
 }
@@ -1877,8 +1877,7 @@ int sql_current_time = 0;
  * epoch of noon in Greenwich on November 24, 4714 B.C according to the
  * proleptic Gregorian calendar.
  *
- * On success, return 0.  Return SQL_ERROR if the time and date
- * cannot be found.
+ * On success, return 0.
  */
 static int
 unixCurrentTimeInt64(sql_vfs * NotUsed, sql_int64 * piNow)
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 39a7383..5aad7f3 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -4422,7 +4422,7 @@ is_simple_count(struct Select *select, struct AggInfo *agg_info)
  * If the source-list item passed as an argument was augmented with an
  * 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
+ * -1 and set an error. Otherwise, populate
  * pFrom->pIndex and return 0.
  */
 int
@@ -4443,7 +4443,7 @@ sqlIndexedByLookup(Parse * pParse, struct SrcList_item *pFrom)
 			diag_set(ClientError, ER_NO_SUCH_INDEX_NAME,
 				 zIndexedBy, space->def->name);
 			pParse->is_aborted = true;
-			return SQL_ERROR;
+			return -1;
 		}
 		pFrom->pIBIndex = idx->def;
 	}
@@ -4632,14 +4632,14 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 			diag_set(ClientError, ER_SQL_PARSER_GENERIC,
 				 tt_sprintf(pCte->zCteErr, pCte->zName));
 			pParse->is_aborted = true;
-			return SQL_ERROR;
+			return -1;
 		}
 		if (pFrom->fg.isTabFunc) {
 			const char *err = "'%s' is not a function";
 			diag_set(ClientError, ER_SQL_PARSER_GENERIC,
 				 tt_sprintf(err, pFrom->zName));
 			pParse->is_aborted = true;
-			return SQL_ERROR;
+			return -1;
 		}
 
 		assert(pFrom->space == NULL);
@@ -4677,7 +4677,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 					   "table: %s", pCte->zName);
 			diag_set(ClientError, ER_SQL_PARSER_GENERIC, err_msg);
 			pParse->is_aborted = true;
-			return SQL_ERROR;
+			return -1;
 		}
 		assert(ref_counter == 0 ||
 			((pSel->selFlags & SF_Recursive) && ref_counter == 1));
@@ -4700,7 +4700,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 				diag_set(ClientError, ER_SQL_PARSER_GENERIC, err_msg);
 				pParse->is_aborted = true;
 				pParse->pWith = pSavedWith;
-				return SQL_ERROR;
+				return -1;
 			}
 			pEList = pCte->pCols;
 		}
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 802a367..a7b3355 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -356,10 +356,8 @@ struct sql_vfs {
 #define SQL_LIMIT_WORKER_THREADS           10
 
 enum sql_ret_code {
-	/** Common error code. */
-	SQL_ERROR = 1,
 	/** A malloc() failed. */
-	SQL_NOMEM,
+	SQL_NOMEM = 2,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
 	/** Abort due to constraint violation. */
diff --git a/src/box/sql/status.c b/src/box/sql/status.c
index 10be3d9..d6de484 100644
--- a/src/box/sql/status.c
+++ b/src/box/sql/status.c
@@ -257,7 +257,7 @@ sql_db_status(sql * db,	/* The database connection whose status is desired */
 		}
 
 	default:{
-			rc = SQL_ERROR;
+			rc = -1;
 		}
 	}
 	return rc;
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 9a9ca55..e3f8ee3 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -981,7 +981,7 @@ case OP_Halt: {
 		assert(! diag_is_empty(diag_get()));
 	}
 	rc = sqlVdbeHalt(p);
-	assert(rc == 0 || rc==SQL_ERROR);
+	assert(rc == 0 || rc == -1);
 	rc = p->rc ? SQL_TARANTOOL_ERROR : SQL_DONE;
 	goto vdbe_return;
 }
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 55b4b2e..8fd4c20 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -718,7 +718,7 @@ columnMallocFailure(sql_stmt * pStmt)
 {
 	/* If malloc() failed during an encoding conversion within an
 	 * sql_column_XXX API, then set the return code of the statement to
-	 * SQL_NOMEM. The next call to _step() (if any) will return SQL_ERROR
+	 * SQL_NOMEM. The next call to _step() (if any) will return -1
 	 * and _finalize() will return NOMEM.
 	 */
 	Vdbe *p = (Vdbe *) pStmt;
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 308373b..e056c40 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1434,7 +1434,7 @@ sqlVdbeList(Vdbe * p)
 		 * sql_column_text16() failed.
 		 */
 		sqlOomFault(db);
-		return SQL_ERROR;
+		return -1;
 	}
 
 	/* When the number of output rows reaches nRow, that means the
@@ -1540,7 +1540,7 @@ sqlVdbeList(Vdbe * p)
 
 		if (sqlVdbeMemClearAndResize(pMem, 256)) {
 			assert(p->db->mallocFailed);
-			return SQL_ERROR;
+			return -1;
 		}
 		pMem->flags = MEM_Str | MEM_Term;
 		zP4 = displayP4(pOp, pMem->z, pMem->szMalloc);
@@ -1557,7 +1557,7 @@ sqlVdbeList(Vdbe * p)
 		if (p->explain == 1) {
 			if (sqlVdbeMemClearAndResize(pMem, 4)) {
 				assert(p->db->mallocFailed);
-				return SQL_ERROR;
+				return -1;
 			}
 			pMem->flags = MEM_Str | MEM_Term;
 			pMem->n = 2;
@@ -1567,7 +1567,7 @@ sqlVdbeList(Vdbe * p)
 #ifdef SQL_ENABLE_EXPLAIN_COMMENTS
 			if (sqlVdbeMemClearAndResize(pMem, 500)) {
 				assert(p->db->mallocFailed);
-				return SQL_ERROR;
+				return -1;
 			}
 			pMem->flags = MEM_Str | MEM_Term;
 			pMem->n = displayComment(pOp, zP4, pMem->z, 500);
@@ -2085,7 +2085,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, 0.
+ * violations, return -1. Otherwise, 0.
  *
  * If there are outstanding FK violations and this function returns
  * SQL_TARANTOOL_ERROR and set an error.
@@ -2250,7 +2250,7 @@ sqlVdbeHalt(Vdbe * p)
 					 */
 					if (NEVER(p->pDelFrame)) {
 						closeCursorsAndFree(p);
-						return SQL_ERROR;
+						return -1;
 					}
 				} else {
 					/* The auto-commit flag is true, the vdbe program was successful
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 8be2e69..860e382 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -543,7 +543,7 @@ sqlVdbeMemIntegerify(Mem * pMem, bool is_forced)
 
 	double d;
 	if (sqlVdbeRealValue(pMem, &d) || (int64_t) d != d) {
-		return SQL_ERROR;
+		return -1;
 	}
 	pMem->u.i = (int64_t) d;
 	MemSetTypeFlag(pMem, MEM_Int);
@@ -560,7 +560,7 @@ sqlVdbeMemRealify(Mem * pMem)
 	assert(EIGHT_BYTE_ALIGNMENT(pMem));
 	double v;
 	if (sqlVdbeRealValue(pMem, &v))
-		return SQL_ERROR;
+		return -1;
 
 	pMem->u.r = v;
 	MemSetTypeFlag(pMem, MEM_Real);
@@ -585,7 +585,7 @@ sqlVdbeMemNumerify(Mem * pMem)
 		} else {
 			double v;
 			if (sqlVdbeRealValue(pMem, &v))
-				return SQL_ERROR;
+				return -1;
 			pMem->u.r = v;
 			MemSetTypeFlag(pMem, MEM_Real);
 			mem_apply_integer_type(pMem);
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index f7fc8e1..b6ae888 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -1027,7 +1027,7 @@ vdbeSorterJoinThread(SortSubtask * pTask)
 #ifdef SQL_DEBUG_SORTER_THREADS
 		int bDone = pTask->bDone;
 #endif
-		void *pRet = SQL_INT_TO_PTR(SQL_ERROR);
+		void *pRet = SQL_INT_TO_PTR(-1);
 		vdbeSorterBlockDebug(pTask, !bDone, "enter");
 		(void)sqlThreadJoin(pTask->pThread, &pRet);
 		vdbeSorterBlockDebug(pTask, !bDone, "exit");
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 16/21] sql: remove SQL_NOMEM errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (14 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 15/21] sql: remove SQL_ERROR errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 17/21] sql: remove SQL_IOERR errcode imeevma
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/fault.c    |  4 ++--
 src/box/sql/func.c     | 14 ++++----------
 src/box/sql/legacy.c   |  1 -
 src/box/sql/main.c     | 26 ++++++++++---------------
 src/box/sql/malloc.c   |  7 ++-----
 src/box/sql/os.c       |  4 ++--
 src/box/sql/os_unix.c  |  4 ++--
 src/box/sql/select.c   | 11 +++++------
 src/box/sql/sqlInt.h   |  4 +---
 src/box/sql/vdbe.c     |  6 ------
 src/box/sql/vdbeapi.c  | 52 ++------------------------------------------------
 src/box/sql/vdbeaux.c  | 48 ++++++++++++++++------------------------------
 src/box/sql/vdbemem.c  | 25 ++++++++++++------------
 src/box/sql/vdbesort.c | 46 +++++++++++++++++++++-----------------------
 src/box/sql/where.c    | 12 ++++++------
 15 files changed, 86 insertions(+), 178 deletions(-)

diff --git a/src/box/sql/fault.c b/src/box/sql/fault.c
index 8ee774e..0e0978d 100644
--- a/src/box/sql/fault.c
+++ b/src/box/sql/fault.c
@@ -37,8 +37,8 @@
  * and returns 0).
  *
  * Most malloc failures are non-benign. After they occur, sql
- * abandons the current operation and returns an error code (usually
- * SQL_NOMEM) to the user. However, sometimes a fault is not necessarily
+ * abandons the current operation and returns an -1
+ * to the user. However, sometimes a fault is not necessarily
  * fatal. For example, if a malloc fails while resizing a hash table, this
  * is completely recoverable simply by not carrying out the resize. The
  * hash table will continue to function normally.  So a malloc failure
diff --git a/src/box/sql/func.c b/src/box/sql/func.c
index 29712e0..994d97e 100644
--- a/src/box/sql/func.c
+++ b/src/box/sql/func.c
@@ -1799,14 +1799,11 @@ static inline int
 sql_overload_function(sql * db, const char *zName,
 			  enum field_type type, int nArg)
 {
-	int rc = 0;
-
 	if (sqlFindFunction(db, zName, nArg, 0) == 0) {
-		rc = sqlCreateFunc(db, zName, type, nArg, 0, 0,
-				       sqlInvalidFunction, 0, 0, 0);
+		return sqlCreateFunc(db, zName, type, nArg, 0, 0,
+				     sqlInvalidFunction, 0, 0, 0);
 	}
-	rc = sqlApiExit(db, rc);
-	return rc;
+	return 0;
 }
 
 /*
@@ -1817,11 +1814,8 @@ sql_overload_function(sql * db, const char *zName,
 void
 sqlRegisterPerConnectionBuiltinFunctions(sql * db)
 {
-	int rc = sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2);
-	assert(rc == SQL_NOMEM || rc == 0);
-	if (rc == SQL_NOMEM) {
+	if (sql_overload_function(db, "MATCH", FIELD_TYPE_SCALAR, 2) != 0)
 		sqlOomFault(db);
-	}
 }
 
 /*
diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index 600c53c..e9c9961 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -166,7 +166,6 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 		sqlVdbeFinalize((Vdbe *) pStmt);
 	sqlDbFree(db, azCols);
 
-	rc = sqlApiExit(db, rc);
 	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 8474836..e6d3a3d 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -525,16 +525,16 @@ int
 sql_init_db(sql **out_db)
 {
 	sql *db;
-	int rc;			/* Return code */
 
-	rc = sql_initialize();
-	if (rc)
-		return rc;
+	if (sql_initialize())
+		return -1;
 
 	/* Allocate the sql data structure */
 	db = sqlMallocZero(sizeof(sql));
-	if (db == 0)
-		goto opendb_out;
+	if (db == NULL) {
+		*out_db = NULL;
+		return -1;
+	}
 	db->errMask = 0xff;
 	db->magic = SQL_MAGIC_BUSY;
 
@@ -549,7 +549,9 @@ sql_init_db(sql **out_db)
 
 	db->magic = SQL_MAGIC_OPEN;
 	if (db->mallocFailed) {
-		goto opendb_out;
+		sql_free(db);
+		*out_db = NULL;
+		return -1;
 	}
 
 	/* Register all built-in functions, but do not attempt to read the
@@ -558,16 +560,8 @@ sql_init_db(sql **out_db)
 	 */
 	sqlRegisterPerConnectionBuiltinFunctions(db);
 
-opendb_out:
-	assert(db != 0 || rc == SQL_NOMEM);
-	if (rc == SQL_NOMEM)
-		db = NULL;
-	else if (rc != 0)
-		db->magic = SQL_MAGIC_SICK;
-
 	*out_db = db;
-
-	return rc;
+	return 0;
 }
 
 /*
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 6ed9aeb..14b35a7 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -791,7 +791,7 @@ static SQL_NOINLINE int
 apiOomError(sql * db)
 {
 	sqlOomClear(db);
-	return SQL_NOMEM;
+	return -1;
 }
 
 /*
@@ -800,10 +800,7 @@ apiOomError(sql * db)
  * sql_realloc.
  *
  * The returned value is normally a copy of the second argument to this
- * function. However, if a malloc() failure has occurred since the previous
- * invocation SQL_NOMEM is returned instead.
- *
- * If an OOM as occurred, SQL_NOMEM is returned.
+ * function.
  */
 int
 sqlApiExit(sql * db, int rc)
diff --git a/src/box/sql/os.c b/src/box/sql/os.c
index 273aa6b..9f45eba 100644
--- a/src/box/sql/os.c
+++ b/src/box/sql/os.c
@@ -170,7 +170,7 @@ sqlOsOpenMalloc(sql_vfs * pVfs,
 			*ppFile = pFile;
 		}
 	} else {
-		rc = SQL_NOMEM;
+		rc = -1;
 	}
 	return rc;
 }
@@ -194,7 +194,7 @@ sqlOsInit(void)
 {
 	void *p = sql_malloc(10);
 	if (p == 0)
-		return SQL_NOMEM;
+		return -1;
 	sql_free(p);
 	return sql_os_init();
 }
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index 8b3aec1..e2bda51 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -409,7 +409,7 @@ findInodeInfo(unixFile * pFile,	/* Unix file with file desc used in the key */
 	if (pInode == 0) {
 		pInode = sql_malloc64(sizeof(*pInode));
 		if (pInode == 0) {
-			return SQL_NOMEM;
+			return -1;
 		}
 		memset(pInode, 0, sizeof(*pInode));
 		memcpy(&pInode->fileId, &fileId, sizeof(fileId));
@@ -1697,7 +1697,7 @@ unixOpen(sql_vfs * pVfs,	/* The VFS for which this is the xOpen method */
 		} else {
 			pUnused = sql_malloc64(sizeof(*pUnused));
 			if (!pUnused) {
-				return SQL_NOMEM;
+				return -1;
 			}
 		}
 		p->pUnused = pUnused;
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 5aad7f3..4bb8c58 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1826,7 +1826,7 @@ generateColumnNames(Parse * pParse,	/* Parser context */
  * and other fields of Column are zeroed.
  *
  * Return 0 on success.  If a memory allocation error occurs,
- * store NULL in *paCol and 0 in *pnCol and return SQL_NOMEM.
+ * store NULL in *paCol and 0 in *pnCol and return -1.
  */
 int
 sqlColumnsFromExprList(Parse * parse, ExprList * expr_list,
@@ -1929,17 +1929,16 @@ sqlColumnsFromExprList(Parse * parse, ExprList * expr_list,
 	}
 cleanup:
 	sqlHashClear(&ht);
-	int rc = db->mallocFailed ? SQL_NOMEM : 0;
-	if (rc != 0) {
+	if (db->mallocFailed) {
 		/*
 		 * pTable->def could be not temporal in
 		 * sqlViewGetColumnNames so we need clean-up.
 		 */
 		space_def->fields = NULL;
 		space_def->field_count = 0;
-		rc = SQL_NOMEM;
+		return -1;
 	}
-	return rc;
+	return 0;
 
 }
 
@@ -4648,7 +4647,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
 			return WRC_Abort;
 		pFrom->pSelect = sqlSelectDup(db, pCte->pSelect, 0);
 		if (db->mallocFailed)
-			return SQL_NOMEM;
+			return -1;
 		assert(pFrom->pSelect);
 
 		/* Check if this is a recursive CTE. */
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index a7b3355..a76b4e3 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -356,10 +356,8 @@ struct sql_vfs {
 #define SQL_LIMIT_WORKER_THREADS           10
 
 enum sql_ret_code {
-	/** A malloc() failed. */
-	SQL_NOMEM = 2,
 	/** Some kind of disk I/O error occurred. */
-	SQL_IOERR,
+	SQL_IOERR = 3,
 	/** Abort due to constraint violation. */
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index e3f8ee3..b676a22 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -632,12 +632,6 @@ int sqlVdbeExec(Vdbe *p)
 	/*** INSERT STACK UNION HERE ***/
 
 	assert(p->magic==VDBE_MAGIC_RUN);  /* sql_step() verifies this */
-	if (p->rc==SQL_NOMEM) {
-		/* This happens if a malloc() inside a call to sql_column_text() or
-		 * sql_column_text16() failed.
-		 */
-		goto no_mem;
-	}
 	assert(p->rc == 0);
 	p->rc = 0;
 	p->iCurrentTime = 0;
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 8fd4c20..150ff7b 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -432,8 +432,8 @@ sqlStep(Vdbe * p)
 	/* Check that malloc() has not failed. If it has, return early. */
 	db = p->db;
 	if (db->mallocFailed) {
-		p->rc = SQL_NOMEM;
-		return SQL_NOMEM;
+		p->rc = -1;
+		return -1;
 	}
 
 	if (p->pc <= 0 && p->expired) {
@@ -468,9 +468,6 @@ sqlStep(Vdbe * p)
 		checkProfileCallback(db, p);
 #endif
 
-	if (SQL_NOMEM == sqlApiExit(p->db, p->rc)) {
-		p->rc = SQL_NOMEM;
-	}
 	if (p->isPrepareV2 && rc != SQL_ROW && rc != SQL_DONE) {
 		/* If this statement was prepared using sql_prepare_v2(), and an
 		 * error has occurred, then return the error code in p->rc to the
@@ -696,38 +693,6 @@ columnMem(sql_stmt * pStmt, int i)
 	return pOut;
 }
 
-/*
- * This function is called after invoking an sql_value_XXX function on a
- * column value (i.e. a value returned by evaluating an SQL expression in the
- * select list of a SELECT statement) that may cause a malloc() failure. If
- * malloc() has failed, the threads mallocFailed flag is cleared and the result
- * code of statement pStmt set to SQL_NOMEM.
- *
- * Specifically, this is called from within:
- *
- *     sql_column_int()
- *     sql_column_int64()
- *     sql_column_text()
- *     sql_column_real()
- *     sql_column_bytes()
- *     sql_column_bytes16()
- *     sqiite3_column_blob()
- */
-static void
-columnMallocFailure(sql_stmt * pStmt)
-{
-	/* If malloc() failed during an encoding conversion within an
-	 * sql_column_XXX API, then set the return code of the statement to
-	 * SQL_NOMEM. The next call to _step() (if any) will return -1
-	 * and _finalize() will return NOMEM.
-	 */
-	Vdbe *p = (Vdbe *) pStmt;
-	if (p) {
-		assert(p->db != 0);
-		p->rc = sqlApiExit(p->db, p->rc);
-	}
-}
-
 /**************************** sql_column_  ******************************
  * The following routines are used to access elements of the current row
  * in the result set.
@@ -737,11 +702,6 @@ sql_column_blob(sql_stmt * pStmt, int i)
 {
 	const void *val;
 	val = sql_value_blob(columnMem(pStmt, i));
-	/* Even though there is no encoding conversion, value_blob() might
-	 * need to call malloc() to expand the result of a zeroblob()
-	 * expression.
-	 */
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -749,7 +709,6 @@ int
 sql_column_bytes(sql_stmt * pStmt, int i)
 {
 	int val = sql_value_bytes(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -757,7 +716,6 @@ double
 sql_column_double(sql_stmt * pStmt, int i)
 {
 	double val = sql_value_double(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -765,7 +723,6 @@ int
 sql_column_int(sql_stmt * pStmt, int i)
 {
 	int val = sql_value_int(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -773,7 +730,6 @@ bool
 sql_column_boolean(struct sql_stmt *stmt, int i)
 {
 	bool val = sql_value_boolean(columnMem(stmt, i));
-	columnMallocFailure(stmt);
 	return val;
 }
 
@@ -781,7 +737,6 @@ sql_int64
 sql_column_int64(sql_stmt * pStmt, int i)
 {
 	sql_int64 val = sql_value_int64(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -789,7 +744,6 @@ const unsigned char *
 sql_column_text(sql_stmt * pStmt, int i)
 {
 	const unsigned char *val = sql_value_text(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return val;
 }
 
@@ -801,7 +755,6 @@ sql_column_value(sql_stmt * pStmt, int i)
 		pOut->flags &= ~MEM_Static;
 		pOut->flags |= MEM_Ephem;
 	}
-	columnMallocFailure(pStmt);
 	return (sql_value *) pOut;
 }
 
@@ -809,7 +762,6 @@ enum mp_type
 sql_column_type(sql_stmt * pStmt, int i)
 {
 	enum mp_type type = sql_value_type(columnMem(pStmt, i));
-	columnMallocFailure(pStmt);
 	return type;
 }
 
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index e056c40..7408b9f 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -163,7 +163,7 @@ sqlVdbeSwap(Vdbe * pA, Vdbe * pB)
  * to 1024/sizeof(Op).
  *
  * If an out-of-memory error occurs while resizing the array, return
- * SQL_NOMEM. In this case Vdbe.aOp and Parse.nOpAlloc remain
+ * -1. In this case Vdbe.aOp and Parse.nOpAlloc remain
  * unchanged (this is so that any opcodes already allocated can be
  * correctly deallocated along with the rest of the Vdbe).
  */
@@ -195,8 +195,9 @@ growOpArray(Vdbe * v, int nOp)
 		p->szOpAlloc = sqlDbMallocSize(pNew);
 		p->nOpAlloc = p->szOpAlloc / sizeof(Op);
 		v->aOp = pNew;
+		return 0;
 	}
-	return (pNew ? 0 : SQL_NOMEM);
+	return -1;
 }
 
 #ifdef SQL_DEBUG
@@ -1413,14 +1414,12 @@ sqlVdbeList(Vdbe * p)
 	int nSub = 0;		/* Number of sub-vdbes seen so far */
 	SubProgram **apSub = 0;	/* Array of sub-vdbes */
 	Mem *pSub = 0;		/* Memory cell hold array of subprogs */
-	sql *db = p->db;	/* The database connection */
 	int i;			/* Loop counter */
 	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 == 0 || p->rc == SQL_NOMEM);
 
 	/* Even though this opcode does not use dynamic strings for
 	 * the result, result columns may become dynamic if the user calls
@@ -1429,14 +1428,6 @@ sqlVdbeList(Vdbe * p)
 	releaseMemArray(pMem, 8);
 	p->pResultSet = 0;
 
-	if (p->rc == SQL_NOMEM) {
-		/* This happens if a malloc() inside a call to sql_column_text() or
-		 * sql_column_text16() failed.
-		 */
-		sqlOomFault(db);
-		return -1;
-	}
-
 	/* When the number of output rows reaches nRow, that means the
 	 * listing has finished and sql_step() should return SQL_DONE.
 	 * nRow is the sum of the number of rows in the main program, plus
@@ -2019,7 +2010,7 @@ sqlVdbeSetColName(Vdbe * p,			/* Vdbe being configured */
 	assert(var < COLNAME_N);
 	if (p->db->mallocFailed) {
 		assert(!zName || xDel != SQL_DYNAMIC);
-		return SQL_NOMEM;
+		return -1;
 	}
 	assert(p->aColName != 0);
 	assert(var == COLNAME_NAME || var == COLNAME_DECLTYPE);
@@ -2173,7 +2164,6 @@ sqlVdbeHalt(Vdbe * p)
 	 *
 	 * If any of the following errors occur:
 	 *
-	 *     SQL_NOMEM
 	 *     SQL_IOERR
 	 *
 	 * Then the internal cache might have been left in an inconsistent
@@ -2182,7 +2172,7 @@ sqlVdbeHalt(Vdbe * p)
 	 */
 
 	if (db->mallocFailed) {
-		p->rc = SQL_NOMEM;
+		p->rc = -1;
 	}
 	closeTopFrameCursors(p);
 	if (p->magic != VDBE_MAGIC_RUN) {
@@ -2200,7 +2190,7 @@ sqlVdbeHalt(Vdbe * p)
 
 		/* Check for one of the special errors */
 		mrc = p->rc & 0xff;
-		isSpecialError = mrc == SQL_NOMEM || mrc == SQL_IOERR;
+		isSpecialError = mrc == SQL_IOERR;
 		if (isSpecialError) {
 			/* At least a savepoint transaction must be rolled back
 			 * to restore the database to a consistent state.
@@ -2211,20 +2201,14 @@ sqlVdbeHalt(Vdbe * p)
 			 * file as part of an effort to free up cache space (see function
 			 * pagerStress() in pager.c), the rollback is required to restore
 			 * the pager to a consistent state.
+			 * We are forced to roll back the active transaction. Before doing
+			 * so, abort any other statements this handle currently has active.
 			 */
-			if ((mrc == SQL_NOMEM)
-			    && box_txn()) {
-				eStatementOp = SAVEPOINT_ROLLBACK;
-			} else {
-				/* We are forced to roll back the active transaction. Before doing
-				 * so, abort any other statements this handle currently has active.
-				 */
-				box_txn_rollback();
-				closeCursorsAndFree(p);
-				sqlRollbackAll(p);
-				sqlCloseSavepoints(p);
-				p->nChange = 0;
-			}
+			box_txn_rollback();
+			closeCursorsAndFree(p);
+			sqlRollbackAll(p);
+			sqlCloseSavepoints(p);
+			p->nChange = 0;
 		}
 
 		/* Check for immediate foreign key violations. */
@@ -2333,7 +2317,7 @@ sqlVdbeHalt(Vdbe * p)
 	p->magic = VDBE_MAGIC_HALT;
 	checkActiveVdbeCnt(db);
 	if (db->mallocFailed) {
-		p->rc = SQL_NOMEM;
+		p->rc = -1;
 	}
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
@@ -2974,7 +2958,7 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size)
 	vdbe_mem->n = size;
 	vdbe_mem->z = region_alloc(&fiber()->gc, size);
 	if (vdbe_mem->z == NULL)
-		return SQL_NOMEM;
+		return -1;
 	vdbe_mem->flags = MEM_Ephem | MEM_Blob;
 	assert(sqlVdbeCheckMemInvariants(vdbe_mem));
 	return 0;
@@ -2991,7 +2975,7 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size)
 static int
 vdbeCompareMemString(const Mem * pMem1, const Mem * pMem2,
 		     const struct coll * pColl,
-		     u8 * prcErr)	/* If an OOM occurs, set to SQL_NOMEM */
+		     u8 * prcErr)
 {
 	(void) prcErr;
 	return pColl->cmp(pMem1->z, (size_t)pMem1->n,
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 860e382..2b9e516 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -129,7 +129,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
 			sqlVdbeMemSetNull(pMem);
 			pMem->z = 0;
 			pMem->szMalloc = 0;
-			return SQL_NOMEM;
+			return -1;
 		} else {
 			pMem->szMalloc =
 			    sqlDbMallocSize(pMem->zMalloc);
@@ -159,8 +159,7 @@ sqlVdbeMemGrow(Mem * pMem, int n, int bPreserve)
  * and MEM_Blob values may be discarded, MEM_Int, MEM_Real, and MEM_Null
  * values are preserved.
  *
- * Return 0 on success or an error code (probably SQL_NOMEM)
- * if unable to complete the resizing.
+ * Return 0 on success or -1 if unable to complete the resizing.
  */
 int
 sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
@@ -180,17 +179,17 @@ sqlVdbeMemClearAndResize(Mem * pMem, int szNew)
  * Change pMem so that its MEM_Str or MEM_Blob value is stored in
  * MEM.zMalloc, where it can be safely written.
  *
- * Return 0 on success or SQL_NOMEM if malloc fails.
+ * Return 0 on success or -1 if malloc fails.
  */
 int
 sqlVdbeMemMakeWriteable(Mem * pMem)
 {
 	if ((pMem->flags & (MEM_Str | MEM_Blob)) != 0) {
 		if (ExpandBlob(pMem))
-			return SQL_NOMEM;
+			return -1;
 		if (pMem->szMalloc == 0 || pMem->z != pMem->zMalloc) {
 			if (sqlVdbeMemGrow(pMem, pMem->n + 2, 1)) {
-				return SQL_NOMEM;
+				return -1;
 			}
 			pMem->z[pMem->n] = 0;
 			pMem->z[pMem->n + 1] = 0;
@@ -222,7 +221,7 @@ sqlVdbeMemExpandBlob(Mem * pMem)
 		nByte = 1;
 	}
 	if (sqlVdbeMemGrow(pMem, nByte, 1)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 
 	memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
@@ -239,7 +238,7 @@ static SQL_NOINLINE int
 vdbeMemAddTerminator(Mem * pMem)
 {
 	if (sqlVdbeMemGrow(pMem, pMem->n + 2, 1)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 	pMem->z[pMem->n] = 0;
 	pMem->z[pMem->n + 1] = 0;
@@ -290,7 +289,7 @@ sqlVdbeMemStringify(Mem * pMem, u8 bForce)
 	assert(EIGHT_BYTE_ALIGNMENT(pMem));
 
 	if (sqlVdbeMemClearAndResize(pMem, nByte)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 	if (fg & MEM_Int) {
 		sql_snprintf(nByte, pMem->z, "%lld", pMem->u.i);
@@ -988,7 +987,7 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 		testcase(nAlloc == 31);
 		testcase(nAlloc == 32);
 		if (sqlVdbeMemClearAndResize(pMem, MAX(nAlloc, 32))) {
-			return SQL_NOMEM;
+			return -1;
 		}
 		memcpy(pMem->z, z, nAlloc);
 	} else if (xDel == SQL_DYNAMIC) {
@@ -1259,7 +1258,7 @@ valueFromFunction(sql * db,	/* The database connection */
 							   sizeof(apVal[0]) *
 							   nVal);
 		if (apVal == 0) {
-			rc = SQL_NOMEM;
+			rc = -1;
 			goto value_from_function_out;
 		}
 		for (i = 0; i < nVal; i++) {
@@ -1272,7 +1271,7 @@ valueFromFunction(sql * db,	/* The database connection */
 
 	pVal = valueNew(db, pCtx);
 	if (pVal == 0) {
-		rc = SQL_NOMEM;
+		rc = -1;
 		goto value_from_function_out;
 	}
 
@@ -1436,7 +1435,7 @@ valueFromExpr(sql * db,	/* The database connection */
 	if (pCtx == 0)
 		sqlValueFree(pVal);
 
-	return SQL_NOMEM;
+	return -1;
 }
 
 /*
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index b6ae888..3ff6807 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -570,7 +570,7 @@ vdbePmaReadBlob(PmaReader * p,	/* PmaReader from which to take the blob */
 				nNew = nNew * 2;
 			aNew = sqlRealloc(p->aAlloc, nNew);
 			if (!aNew)
-				return SQL_NOMEM;
+				return -1;
 			p->nAlloc = nNew;
 			p->aAlloc = aNew;
 		}
@@ -694,7 +694,7 @@ vdbePmaReaderSeek(SortSubtask * pTask,	/* Task context */
 		if (pReadr->aBuffer == 0) {
 			pReadr->aBuffer = (u8 *) sqlMalloc(pgsz);
 			if (pReadr->aBuffer == 0)
-				rc = SQL_NOMEM;
+				rc = -1;
 			pReadr->nBuffer = pgsz;
 		}
 		if (rc == 0 && iBuf) {
@@ -803,7 +803,7 @@ vdbePmaReaderInit(SortSubtask * pTask,	/* Task context */
  * version of key2 and *pbKey2Cached set to true before returning.
  *
  * If an OOM error is encountered, (pTask->pUnpacked->error_rc) is set
- * to SQL_NOMEM.
+ * to -1.
  *
  * @param task Subtask context (for key_def).
  * @param key2_cached True if pTask->pUnpacked is key2.
@@ -879,7 +879,7 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 	pSorter = (VdbeSorter *) sqlDbMallocZero(db, sizeof(VdbeSorter));
 	pCsr->uc.pSorter = pSorter;
 	if (pSorter == 0) {
-		rc = SQL_NOMEM;
+		rc = -1;
 	} else {
 		pSorter->key_def = pCsr->key_def;
 		pSorter->pgsz = pgsz = 1024;
@@ -913,7 +913,7 @@ sqlVdbeSorterInit(sql * db,	/* Database connection (for malloc()) */
 				pSorter->list.aMemory =
 				    (u8 *) sqlMalloc(pgsz);
 				if (!pSorter->list.aMemory)
-					rc = SQL_NOMEM;
+					rc = -1;
 			}
 		}
 
@@ -1258,7 +1258,7 @@ vdbeSorterOpenTempFile(sql * db,	/* Database handle doing sort */
 /*
  * If it has not already been allocated, allocate the UnpackedRecord
  * structure at pTask->pUnpacked. Return 0 if successful (or
- * if no allocation was required), or SQL_NOMEM otherwise.
+ * if no allocation was required), or -1 otherwise.
  */
 static int
 vdbeSortAllocUnpacked(SortSubtask * pTask)
@@ -1268,7 +1268,7 @@ vdbeSortAllocUnpacked(SortSubtask * pTask)
 			sqlVdbeAllocUnpackedRecord(pTask->pSorter->db,
 						       pTask->pSorter->key_def);
 		if (pTask->pUnpacked == 0)
-			return SQL_NOMEM;
+			return -1;
 		pTask->pUnpacked->nField = pTask->pSorter->key_def->part_count;
 		pTask->pUnpacked->errCode = 0;
 	}
@@ -1330,7 +1330,7 @@ vdbeSorterGetCompare(VdbeSorter * p)
 
 /*
  * Sort the linked list of records headed at pTask->pList. Return
- * 0 if successful, or an sql error code (i.e. SQL_NOMEM) if
+ * 0 if successful, or an sql error code (i.e. -1) if
  * an error occurs.
  */
 static int
@@ -1351,7 +1351,7 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	aSlot =
 	    (SorterRecord **) sqlMallocZero(64 * sizeof(SorterRecord *));
 	if (!aSlot) {
-		return SQL_NOMEM;
+		return -1;
 	}
 
 	while (p) {
@@ -1388,8 +1388,6 @@ vdbeSorterSort(SortSubtask * pTask, SorterList * pList)
 	pList->pList = p;
 
 	sql_free(aSlot);
-	assert(pTask->pUnpacked->errCode == 0
-	       || pTask->pUnpacked->errCode == SQL_NOMEM);
 	return pTask->pUnpacked->errCode;
 }
 
@@ -1406,7 +1404,7 @@ vdbePmaWriterInit(sql_file * pFd,	/* File handle to write to */
 	memset(p, 0, sizeof(PmaWriter));
 	p->aBuffer = (u8 *) sqlMalloc(nBuf);
 	if (!p->aBuffer) {
-		p->eFWErr = SQL_NOMEM;
+		p->eFWErr = -1;
 	} else {
 		p->iBufEnd = p->iBufStart = (iStart % nBuf);
 		p->iWriteOff = iStart - p->iBufStart;
@@ -1727,7 +1725,7 @@ vdbeSorterFlushPMA(VdbeSorter * pSorter)
 				pSorter->list.aMemory =
 				    sqlMalloc(pSorter->nMemory);
 				if (!pSorter->list.aMemory)
-					return SQL_NOMEM;
+					return -1;
 			}
 
 			rc = vdbeSorterCreateThread(pTask,
@@ -1827,7 +1825,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 
 			aNew = sqlRealloc(pSorter->list.aMemory, nNew);
 			if (!aNew)
-				return SQL_NOMEM;
+				return -1;
 			pSorter->list.pList = (SorterRecord *) & aNew[iListOff];
 			pSorter->list.aMemory = aNew;
 			pSorter->nMemory = nNew;
@@ -1844,7 +1842,7 @@ sqlVdbeSorterWrite(const VdbeCursor * pCsr,	/* Sorter cursor */
 	} else {
 		pNew = (SorterRecord *) sqlMalloc(nReq);
 		if (pNew == 0) {
-			return SQL_NOMEM;
+			return -1;
 		}
 		pNew->u.pNext = pSorter->list.pList;
 	}
@@ -2007,7 +2005,7 @@ vdbeIncrMergerNew(SortSubtask * pTask,	/* The thread that will be using the new
 		pTask->file2.iEof += pIncr->mxSz;
 	} else {
 		vdbeMergeEngineFree(pMerger);
-		rc = SQL_NOMEM;
+		rc = -1;
 	}
 	return rc;
 }
@@ -2332,7 +2330,7 @@ vdbeMergeEngineLevel0(SortSubtask * pTask,	/* Sorter task to read from */
 
 	*ppOut = pNew = vdbeMergeEngineNew(nPMA);
 	if (pNew == 0)
-		rc = SQL_NOMEM;
+		rc = -1;
 
 	for (i = 0; i < nPMA && rc == 0; i++) {
 		i64 nDummy = 0;
@@ -2408,7 +2406,7 @@ vdbeSorterAddToTree(SortSubtask * pTask,	/* Task context */
 			MergeEngine *pNew =
 			    vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
 			if (pNew == 0) {
-				rc = SQL_NOMEM;
+				rc = -1;
 			} else {
 				rc = vdbeIncrMergerNew(pTask, pNew,
 						       &pReadr->pIncr);
@@ -2457,7 +2455,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 	if (pSorter->nTask > 1) {
 		pMain = vdbeMergeEngineNew(pSorter->nTask);
 		if (pMain == 0)
-			rc = SQL_NOMEM;
+			rc = -1;
 	}
 #endif
 
@@ -2478,7 +2476,7 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter,	/* The VDBE cursor that implement
 				pRoot =
 				    vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT);
 				if (pRoot == 0)
-					rc = SQL_NOMEM;
+					rc = -1;
 				for (i = 0; i < pTask->nPMA && rc == 0;
 				     i += SORTER_MAX_MERGE_COUNT) {
 					MergeEngine *pMerger = 0;	/* New level-0 PMA merger */
@@ -2569,7 +2567,7 @@ vdbeSorterSetupMerge(VdbeSorter * pSorter)
 								      (PmaReader));
 				pSorter->pReader = pReadr;
 				if (pReadr == 0)
-					rc = SQL_NOMEM;
+					rc = -1;
 			}
 			if (rc == 0) {
 				rc = vdbeIncrMergerNew(pLast, pMain,
@@ -2773,7 +2771,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut)
 	pSorter = pCsr->uc.pSorter;
 	pKey = vdbeSorterRowkey(pSorter, &nKey);
 	if (sqlVdbeMemClearAndResize(pOut, nKey)) {
-		return SQL_NOMEM;
+		return -1;
 	}
 	pOut->n = nKey;
 	MemSetTypeFlag(pOut, MEM_Blob);
@@ -2790,7 +2788,7 @@ sqlVdbeSorterRowkey(const VdbeCursor * pCsr, Mem * pOut)
  * If the sorter cursor key contains any NULL values, consider it to be
  * less than pVal. Even if pVal also contains NULL values.
  *
- * If an error occurs, return an sql error code (i.e. SQL_NOMEM).
+ * If an error occurs, return -1.
  * Otherwise, set *pRes to a negative, zero or positive value if the
  * key in pVal is smaller than, equal to or larger than the current sorter
  * key.
@@ -2818,7 +2816,7 @@ sqlVdbeSorterCompare(const VdbeCursor * pCsr,	/* Sorter cursor */
 		r2 = pSorter->pUnpacked =
 			sqlVdbeAllocUnpackedRecord(pSorter->db,  pCsr->key_def);
 		if (r2 == 0)
-			return SQL_NOMEM;
+			return -1;
 		r2->nField = nKeyCol;
 	}
 	assert(r2->nField == nKeyCol);
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 060dfee..11c531c 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1743,7 +1743,7 @@ whereLoopResize(sql * db, WhereLoop * p, int n)
 	n = (n + 7) & ~7;
 	paNew = sqlDbMallocRawNN(db, sizeof(p->aLTerm[0]) * n);
 	if (paNew == 0)
-		return SQL_NOMEM;
+		return -1;
 	memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0]) * p->nLSlot);
 	if (p->aLTerm != p->aLTermSpace)
 		sqlDbFree(db, p->aLTerm);
@@ -1764,7 +1764,7 @@ whereLoopXfer(sql * db, WhereLoop * pTo, WhereLoop * pFrom)
 		pTo->nBtm = 0;
 		pTo->nTop = 0;
 		pTo->index_def = NULL;
-		return SQL_NOMEM;
+		return -1;
 	}
 	memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);
 	memcpy(pTo->aLTerm, pFrom->aLTerm,
@@ -2081,7 +2081,7 @@ whereLoopInsert(WhereLoopBuilder * pBuilder, WhereLoop * pTemplate)
 		/* Allocate a new WhereLoop to add to the end of the list */
 		*ppPrev = p = sqlDbMallocRawNN(db, sizeof(WhereLoop));
 		if (p == 0)
-			return SQL_NOMEM;
+			return -1;
 		whereLoopInit(p);
 		p->pNextLoop = 0;
 	} else {
@@ -2310,7 +2310,7 @@ whereLoopAddBtreeIndex(WhereLoopBuilder * pBuilder,	/* The WhereLoop factory */
 
 	pNew = pBuilder->pNew;
 	if (db->mallocFailed)
-		return SQL_NOMEM;
+		return -1;
 	WHERETRACE(0x800, ("BEGIN addBtreeIdx(%s), nEq=%d\n",
 			   probe->name, pNew->nEq));
 
@@ -3547,7 +3547,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 0 on success or SQL_NOMEM of a memory allocation
+ * Return 0 on success or -1 of a memory allocation
  * error occurs.
  */
 static int
@@ -3603,7 +3603,7 @@ wherePathSolver(WhereInfo * pWInfo, LogEst nRowEst)
 	nSpace += sizeof(LogEst) * nOrderBy;
 	pSpace = sqlDbMallocRawNN(db, nSpace);
 	if (pSpace == 0)
-		return SQL_NOMEM;
+		return -1;
 	aTo = (WherePath *) pSpace;
 	aFrom = aTo + mxChoice;
 	memset(aFrom, 0, sizeof(aFrom[0]));
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 17/21] sql: remove SQL_IOERR errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (15 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 16/21] sql: remove SQL_NOMEM errcode imeevma
@ 2019-05-25 10:44 ` imeevma
  2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 18/21] sql: remove SQL_TARANTOOL_ERROR errcode imeevma
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:44 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql/malloc.c   |  2 +-
 src/box/sql/os_unix.c  | 35 +++++++++++++++--------------------
 src/box/sql/sqlInt.h   | 31 +------------------------------
 src/box/sql/vdbeaux.c  | 38 ++------------------------------------
 src/box/sql/vdbesort.c |  1 -
 5 files changed, 19 insertions(+), 88 deletions(-)

diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 14b35a7..3c25458 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -806,7 +806,7 @@ int
 sqlApiExit(sql * db, int rc)
 {
 	assert(db != 0);
-	if (db->mallocFailed || rc == SQL_IOERR_NOMEM) {
+	if (db->mallocFailed) {
 		return apiOomError(db);
 	}
 	return rc & db->errMask;
diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index e2bda51..f0cf4ac 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -396,7 +396,7 @@ findInodeInfo(unixFile * pFile,	/* Unix file with file desc used in the key */
 	rc = fstat(fd, &statbuf);
 	if (rc != 0) {
 		storeLastErrno(pFile, errno);
-		return SQL_IOERR;
+		return -1;
 	}
 
 	memset(&fileId, 0, sizeof(fileId));
@@ -554,9 +554,9 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 					/* In theory, the call to unixFileLock() cannot fail because another
 					 * process is holding an incompatible lock. If it does, this
 					 * indicates that the other process is not following the locking
-					 * protocol. If this happens, return SQL_IOERR_RDLOCK.
+					 * protocol. If this happens, return -1.
 					 */
-					rc = SQL_IOERR_RDLOCK;
+					rc = -1;
 					storeLastErrno(pFile, errno);
 					goto end_unlock;
 				}
@@ -570,7 +570,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 		if (unixFileLock(pFile, &lock) == 0) {
 			pInode->eFileLock = SHARED_LOCK;
 		} else {
-			rc = SQL_IOERR_UNLOCK;
+			rc = -1;
 			storeLastErrno(pFile, errno);
 			goto end_unlock;
 		}
@@ -588,7 +588,7 @@ posixUnlock(sql_file * id, int eFileLock, int handleNFSUnlock)
 			if (unixFileLock(pFile, &lock) == 0) {
 				pInode->eFileLock = NO_LOCK;
 			} else {
-				rc = SQL_IOERR_UNLOCK;
+				rc = -1;
 				storeLastErrno(pFile, errno);
 				pInode->eFileLock = NO_LOCK;
 				pFile->eFileLock = NO_LOCK;
@@ -755,7 +755,7 @@ seekAndRead(unixFile * id, sql_int64 offset, void *pBuf, int cnt)
 
 /*
  * Read data from a file into a buffer.  Return 0 if all
- * bytes were read successfully and SQL_IOERR if anything goes
+ * bytes were read successfully and -1 if anything goes
  * wrong.
  */
 static int
@@ -792,12 +792,12 @@ unixRead(sql_file * id, void *pBuf, int amt, sql_int64 offset)
 		return 0;
 	} else if (got < 0) {
 		/* lastErrno set by seekAndRead */
-		return SQL_IOERR_READ;
+		return -1;
 	} else {
 		storeLastErrno(pFile, 0);	/* not a system error */
 		/* Unread parts of the buffer must be zero-filled */
 		memset(&((char *)pBuf)[got], 0, amt - got);
-		return SQL_IOERR_SHORT_READ;
+		return -1;
 	}
 }
 
@@ -871,7 +871,7 @@ unixWrite(sql_file * id, const void *pBuf, int amt, sql_int64 offset)
 	if (amt > wrote) {
 		if (wrote < 0 && pFile->lastErrno != ENOSPC) {
 			/* lastErrno set by seekAndWrite */
-			return SQL_IOERR_WRITE;
+			return -1;
 		} else {
 			storeLastErrno(pFile, 0);	/* not a system error */
 			return -1;
@@ -941,7 +941,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 		struct stat buf;	/* Used to hold return values of fstat() */
 
 		if (fstat(pFile->h, &buf))
-			return SQL_IOERR_FSTAT;
+			return -1;
 
 		nSize =
 		    ((nByte + pFile->szChunk -
@@ -960,7 +960,7 @@ fcntlSizeHint(unixFile * pFile, i64 nByte)
 					iWrite = nSize - 1;
 				nWrite = seekAndWrite(pFile, iWrite, "", 1);
 				if (nWrite != 1)
-					return SQL_IOERR_WRITE;
+					return -1;
 			}
 		}
 	}
@@ -1167,7 +1167,7 @@ unixMapfile(unixFile * pFd, i64 nMap)
 	if (nMap < 0) {
 		struct stat statbuf;	/* Low-level file information */
 		if (fstat(pFd->h, &statbuf))
-			return SQL_IOERR_FSTAT;
+			return -1;
 		nMap = statbuf.st_size;
 	}
 	if (nMap > pFd->mmapSizeMax) {
@@ -1472,7 +1472,7 @@ unixGetTempname(int nBuf, char *zBuf)
 
 	zDir = unixTempFileDir();
 	if (zDir == 0)
-		return SQL_IOERR_GETTEMPPATH;
+		return -1;
 	do {
 		u64 r;
 		sql_randomness(sizeof(r), &r);
@@ -1559,7 +1559,7 @@ getFileMode(const char *zFile,	/* File name */
 		*pUid = sStat.st_uid;
 		*pGid = sStat.st_gid;
 	} else {
-		rc = SQL_IOERR_FSTAT;
+		rc = -1;
 	}
 	return rc;
 }
@@ -1816,12 +1816,7 @@ unixDelete(sql_vfs * NotUsed,	/* VFS containing this as the xDelete method */
 	int rc = 0;
 	UNUSED_PARAMETER(NotUsed);
 	if (unlink(zPath) == (-1)) {
-		if (errno == ENOENT) {
-			rc = SQL_IOERR_DELETE_NOENT;
-		} else {
-			rc = -1;
-		}
-		return rc;
+		return -1;
 	}
 #ifndef SQL_DISABLE_DIRSYNC
 	if ((dirSync & 1) != 0) {
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index a76b4e3..76ac057 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -356,10 +356,8 @@ struct sql_vfs {
 #define SQL_LIMIT_WORKER_THREADS           10
 
 enum sql_ret_code {
-	/** Some kind of disk I/O error occurred. */
-	SQL_IOERR = 3,
 	/** Abort due to constraint violation. */
-	SQL_TARANTOOL_ERROR,
+	SQL_TARANTOOL_ERROR = 4,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
 	/** sql_step() has finished executing. */
@@ -561,33 +559,6 @@ sql_exec(sql *,	/* An open database */
 	     void *,	/* 1st argument to callback */
 	     char **errmsg	/* Error msg written here */
 	);
-#define SQL_IOERR_READ              (SQL_IOERR | (1<<8))
-#define SQL_IOERR_SHORT_READ        (SQL_IOERR | (2<<8))
-#define SQL_IOERR_WRITE             (SQL_IOERR | (3<<8))
-#define SQL_IOERR_FSYNC             (SQL_IOERR | (4<<8))
-#define SQL_IOERR_DIR_FSYNC         (SQL_IOERR | (5<<8))
-#define SQL_IOERR_TRUNCATE          (SQL_IOERR | (6<<8))
-#define SQL_IOERR_FSTAT             (SQL_IOERR | (7<<8))
-#define SQL_IOERR_UNLOCK            (SQL_IOERR | (8<<8))
-#define SQL_IOERR_RDLOCK            (SQL_IOERR | (9<<8))
-#define SQL_IOERR_DELETE            (SQL_IOERR | (10<<8))
-#define SQL_IOERR_BLOCKED           (SQL_IOERR | (11<<8))
-#define SQL_IOERR_NOMEM             (SQL_IOERR | (12<<8))
-#define SQL_IOERR_ACCESS            (SQL_IOERR | (13<<8))
-#define SQL_IOERR_CHECKRESERVEDLOCK (SQL_IOERR | (14<<8))
-#define SQL_IOERR_LOCK              (SQL_IOERR | (15<<8))
-#define SQL_IOERR_CLOSE             (SQL_IOERR | (16<<8))
-#define SQL_IOERR_DIR_CLOSE         (SQL_IOERR | (17<<8))
-#define SQL_IOERR_SHMOPEN           (SQL_IOERR | (18<<8))
-#define SQL_IOERR_SHMSIZE           (SQL_IOERR | (19<<8))
-#define SQL_IOERR_SHMLOCK           (SQL_IOERR | (20<<8))
-#define SQL_IOERR_SHMMAP            (SQL_IOERR | (21<<8))
-#define SQL_IOERR_SEEK              (SQL_IOERR | (22<<8))
-#define SQL_IOERR_DELETE_NOENT      (SQL_IOERR | (23<<8))
-#define SQL_IOERR_MMAP              (SQL_IOERR | (24<<8))
-#define SQL_IOERR_GETTEMPPATH       (SQL_IOERR | (25<<8))
-#define SQL_IOERR_CONVPATH          (SQL_IOERR | (26<<8))
-#define SQL_IOERR_VNODE             (SQL_IOERR | (27<<8))
 
 /**
  * Subtype of a main type. Allows to do some subtype specific
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 7408b9f..8e2ca35 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2055,7 +2055,7 @@ checkActiveVdbeCnt(sql * db)
  * transaction is rolled back. If eOp is SAVEPOINT_RELEASE, then the
  * statement transaction is committed.
  *
- * If an IO error occurs, an SQL_IOERR_XXX error code is returned.
+ * If an IO error occurs, -1 is returned.
  * Otherwise 0.
  */
 int
@@ -2161,14 +2161,6 @@ sqlVdbeHalt(Vdbe * p)
 	/* This function contains the logic that determines if a statement or
 	 * transaction will be committed or rolled back as a result of the
 	 * execution of this virtual machine.
-	 *
-	 * If any of the following errors occur:
-	 *
-	 *     SQL_IOERR
-	 *
-	 * Then the internal cache might have been left in an inconsistent
-	 * state.  We need to rollback the statement transaction, if there is
-	 * one, or the complete transaction if there is no statement transaction.
 	 */
 
 	if (db->mallocFailed) {
@@ -2184,32 +2176,7 @@ sqlVdbeHalt(Vdbe * p)
 	 * SQL statement does not read or write a database file.
 	 */
 	if (p->pc >= 0) {
-		int mrc;	/* Primary error code from p->rc */
 		int eStatementOp = 0;
-		int isSpecialError;	/* Set to true if a 'special' error */
-
-		/* Check for one of the special errors */
-		mrc = p->rc & 0xff;
-		isSpecialError = mrc == SQL_IOERR;
-		if (isSpecialError) {
-			/* At least a savepoint transaction must be rolled back
-			 * to restore the database to a consistent state.
-			 *
-			 * Even if the statement is read-only, it is important to perform
-			 * a statement or transaction rollback operation. If the error
-			 * occurred while writing to the journal, sub-journal or database
-			 * file as part of an effort to free up cache space (see function
-			 * pagerStress() in pager.c), the rollback is required to restore
-			 * the pager to a consistent state.
-			 * We are forced to roll back the active transaction. Before doing
-			 * so, abort any other statements this handle currently has active.
-			 */
-			box_txn_rollback();
-			closeCursorsAndFree(p);
-			sqlRollbackAll(p);
-			sqlCloseSavepoints(p);
-			p->nChange = 0;
-		}
 
 		/* Check for immediate foreign key violations. */
 		if (p->rc == 0) {
@@ -2224,8 +2191,7 @@ sqlVdbeHalt(Vdbe * p)
 		 */
 		if (p->auto_commit) {
 			if (p->rc == 0
-			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL
-				&& !isSpecialError)) {
+			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL)) {
 				rc = sqlVdbeCheckFk(p, 1);
 				if (rc != 0) {
 					/* Close all opened cursors if
diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c
index 3ff6807..7caf13b 100644
--- a/src/box/sql/vdbesort.c
+++ b/src/box/sql/vdbesort.c
@@ -542,7 +542,6 @@ 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 != 0)
 			return rc;
 	}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 18/21] sql: remove SQL_TARANTOOL_ERROR errcode
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (16 preceding siblings ...)
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 17/21] sql: remove SQL_IOERR errcode imeevma
@ 2019-05-25 10:45 ` imeevma
  2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 19/21] sql: remove field errMask from struct sql imeevma
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:45 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Removing this error code is part of getting rid of the SQL error
system.
---
 src/box/sql.c               | 89 +++++++++++++++++++--------------------------
 src/box/sql/analyze.c       |  6 +--
 src/box/sql/build.c         |  5 +--
 src/box/sql/expr.c          |  2 +-
 src/box/sql/fk_constraint.c |  2 +-
 src/box/sql/insert.c        |  4 +-
 src/box/sql/main.c          |  6 +--
 src/box/sql/prepare.c       |  4 +-
 src/box/sql/select.c        | 21 ++++-------
 src/box/sql/sqlInt.h        |  6 +--
 src/box/sql/tarantoolInt.h  |  6 +--
 src/box/sql/vdbe.c          | 38 ++++++-------------
 src/box/sql/vdbeapi.c       | 10 ++---
 src/box/sql/vdbeaux.c       |  8 ++--
 src/box/sql/vdbemem.c       |  4 +-
 src/box/sql/where.c         |  2 +-
 16 files changed, 86 insertions(+), 127 deletions(-)

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

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 19/21] sql: remove field errMask from struct sql
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (17 preceding siblings ...)
  2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 18/21] sql: remove SQL_TARANTOOL_ERROR errcode imeevma
@ 2019-05-25 10:45 ` imeevma
  2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 20/21] sql: replace rc by is_aborted in struct Parse imeevma
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:45 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

This field has become unused and should be removed.
---
 src/box/sql/legacy.c  | 1 -
 src/box/sql/main.c    | 1 -
 src/box/sql/malloc.c  | 2 +-
 src/box/sql/prepare.c | 2 --
 src/box/sql/sqlInt.h  | 1 -
 src/box/sql/vdbeapi.c | 3 +--
 src/box/sql/vdbeaux.c | 9 ++-------
 7 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c
index e9c9961..0769d3a 100644
--- a/src/box/sql/legacy.c
+++ b/src/box/sql/legacy.c
@@ -167,6 +167,5 @@ sql_exec(sql * db,	/* The database on which the SQL executes */
 	sqlDbFree(db, azCols);
 
 	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 76d464f..145964f 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -535,7 +535,6 @@ sql_init_db(sql **out_db)
 		*out_db = NULL;
 		return -1;
 	}
-	db->errMask = 0xff;
 	db->magic = SQL_MAGIC_BUSY;
 
 	db->pVfs = sql_vfs_find(0);
diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 3c25458..a4911c2 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -809,5 +809,5 @@ sqlApiExit(sql * db, int rc)
 	if (db->mallocFailed) {
 		return apiOomError(db);
 	}
-	return rc & db->errMask;
+	return rc;
 }
diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 61f6493..e1da179 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -176,8 +176,6 @@ sqlPrepare(sql * db,	/* Database handle. */
  end_prepare:
 
 	sql_parser_destroy(&sParse);
-	rc = sqlApiExit(db, rc);
-	assert((rc & db->errMask) == rc);
 	return rc;
 }
 
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 50a577b..0db13ed 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -1332,7 +1332,6 @@ struct sql {
 	struct Vdbe *pVdbe;	/* List of active virtual machines */
 	struct coll *pDfltColl;	/* The default collating sequence (BINARY) */
 	i64 szMmap;		/* Default mmap_size setting */
-	int errMask;		/* & result codes with this before returning */
 	u16 dbOptFlags;		/* Flags to enable/disable optimizations */
 	u8 enc;			/* Text encoding */
 	u8 temp_store;		/* 1: file 2: memory 0: default */
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index f1897e2..1842e26 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -116,7 +116,6 @@ sql_reset(sql_stmt * pStmt)
 		checkProfileCallback(db, v);
 		rc = sqlVdbeReset(v);
 		sqlVdbeRewind(v);
-		assert((rc & (db->errMask)) == rc);
 		rc = sqlApiExit(db, rc);
 	}
 	return rc;
@@ -475,7 +474,7 @@ sqlStep(Vdbe * p)
 		 */
 		rc = p->rc;
 	}
-	return (rc & db->errMask);
+	return rc;
 }
 
 /*
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index d4ba3a3..28b423d 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -2315,9 +2315,6 @@ sqlVdbeResetStepResult(Vdbe * p)
 int
 sqlVdbeReset(Vdbe * p)
 {
-	sql *db;
-	db = p->db;
-
 	/* If the VM did not run to completion or if it encountered an
 	 * error, then it might not have been halted properly.  So halt
 	 * it now.
@@ -2389,7 +2386,7 @@ sqlVdbeReset(Vdbe * p)
 #endif
 	p->iCurrentTime = 0;
 	p->magic = VDBE_MAGIC_RESET;
-	return p->rc & db->errMask;
+	return p->rc;
 }
 
 /*
@@ -2400,10 +2397,8 @@ int
 sqlVdbeFinalize(Vdbe * p)
 {
 	int rc = 0;
-	if (p->magic == VDBE_MAGIC_RUN || p->magic == VDBE_MAGIC_HALT) {
+	if (p->magic == VDBE_MAGIC_RUN || p->magic == VDBE_MAGIC_HALT)
 		rc = sqlVdbeReset(p);
-		assert((rc & p->db->errMask) == rc);
-	}
 	sqlVdbeDelete(p);
 	return rc;
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 20/21] sql: replace rc by is_aborted in struct Parse
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (18 preceding siblings ...)
  2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 19/21] sql: remove field errMask from struct sql imeevma
@ 2019-05-25 10:45 ` imeevma
  2019-05-25 15:46   ` [tarantool-patches] " n.pettik
  2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 21/21] sql: remove sql_log() imeevma
  2019-05-25 16:36 ` [tarantool-patches] Re: [PATCH v1 00/21] sql: remove SQL error system n.pettik
  21 siblings, 1 reply; 36+ messages in thread
From: imeevma @ 2019-05-25 10:45 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

Currently, the rc field of the Parse structure is either 0 or -1.
Due to this, it is better to replace this integer field with the
boolean field is_aborted.
---
 src/box/sql/vdbe.c    | 14 +++++++-------
 src/box/sql/vdbe.h    |  1 -
 src/box/sql/vdbeInt.h |  3 ++-
 src/box/sql/vdbeapi.c | 10 +++++-----
 src/box/sql/vdbeaux.c | 38 ++++++++++++--------------------------
 5 files changed, 26 insertions(+), 40 deletions(-)

diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 237daef..af5b988 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -632,8 +632,7 @@ int sqlVdbeExec(Vdbe *p)
 	/*** INSERT STACK UNION HERE ***/
 
 	assert(p->magic==VDBE_MAGIC_RUN);  /* sql_step() verifies this */
-	assert(p->rc == 0);
-	p->rc = 0;
+	assert(!p->is_aborted);
 	p->iCurrentTime = 0;
 	assert(p->explain==0);
 	p->pResultSet = 0;
@@ -958,16 +957,17 @@ case OP_Halt: {
 		pOp = &aOp[pcx];
 		break;
 	}
-	p->rc = pOp->p1;
+	if (pOp->p1 != 0)
+		p->is_aborted = true;
 	p->errorAction = (u8)pOp->p2;
 	p->pc = pcx;
-	if (p->rc) {
+	if (p->is_aborted) {
 		if (pOp->p4.z != NULL)
 			diag_set(ClientError, pOp->p5, pOp->p4.z);
 		assert(! diag_is_empty(diag_get()));
 	}
 	sqlVdbeHalt(p);
-	rc = p->rc ? -1 : SQL_DONE;
+	rc = p->is_aborted ? -1 : SQL_DONE;
 	goto vdbe_return;
 }
 
@@ -2881,7 +2881,7 @@ case OP_Savepoint: {
 					goto vdbe_return;
 				}
 				sqlVdbeHalt(p);
-				if (p->rc != 0)
+				if (p->is_aborted)
 					goto abort_due_to_error;
 			} else {
 				if (p1==SAVEPOINT_ROLLBACK)
@@ -5274,7 +5274,7 @@ default: {          /* This is really OP_Noop and OP_Explain */
 	 */
 abort_due_to_error:
 	rc = -1;
-	p->rc = rc;
+	p->is_aborted = true;
 
 	/* This is the only way out of this procedure. */
 vdbe_return:
diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h
index 6234dff..c8f2618 100644
--- a/src/box/sql/vdbe.h
+++ b/src/box/sql/vdbe.h
@@ -253,7 +253,6 @@ void sqlVdbeMakeReady(Vdbe *, Parse *);
 int sqlVdbeFinalize(Vdbe *);
 void sqlVdbeResolveLabel(Vdbe *, int);
 int sqlVdbeCurrentAddr(Vdbe *);
-void sqlVdbeResetStepResult(Vdbe *);
 void sqlVdbeRewind(Vdbe *);
 int sqlVdbeReset(Vdbe *);
 void sqlVdbeSetNumCols(Vdbe *, int);
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 59a5cc8..3f8c9bd 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -348,7 +348,8 @@ struct Vdbe {
 	int nCursor;		/* Number of slots in apCsr[] */
 	u32 cacheCtr;		/* VdbeCursor row cache generation counter */
 	int pc;			/* The program counter */
-	int rc;			/* Value to return */
+	/** True, if error occured during VDBE execution. */
+	bool is_aborted;
 	int nChange;		/* Number of db changes made since last reset */
 	int iStatement;		/* Statement number (or 0 if has not opened stmt) */
 	i64 iCurrentTime;	/* Value of julianday('now') for this statement */
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 1842e26..0a4f45f 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -431,12 +431,12 @@ sqlStep(Vdbe * p)
 	/* Check that malloc() has not failed. If it has, return early. */
 	db = p->db;
 	if (db->mallocFailed) {
-		p->rc = -1;
+		p->is_aborted = true;
 		return -1;
 	}
 
 	if (p->pc <= 0 && p->expired) {
-		p->rc = -1;
+		p->is_aborted = true;
 		return -1;
 	}
 	if (p->pc < 0) {
@@ -469,10 +469,10 @@ sqlStep(Vdbe * p)
 
 	if (p->isPrepareV2 && rc != SQL_ROW && rc != SQL_DONE) {
 		/* If this statement was prepared using sql_prepare_v2(), and an
-		 * error has occurred, then return the error code in p->rc to the
-		 * caller. Set the error code in the database handle to the same value.
+		 * error has occurred, then return an error.
 		 */
-		rc = p->rc;
+		if (p->is_aborted)
+			rc = -1;
 	}
 	return rc;
 }
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 28b423d..944a8a7 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1460,7 +1460,6 @@ sqlVdbeList(Vdbe * p)
 		i = p->pc++;
 	} while (i < nRow && p->explain == 2 && p->aOp[i].opcode != OP_Explain);
 	if (i >= nRow) {
-		p->rc = 0;
 		rc = SQL_DONE;
 	} else {
 		char *zP4;
@@ -1569,7 +1568,6 @@ sqlVdbeList(Vdbe * p)
 
 		p->nResColumn = 8 - 4 * (p->explain - 1);
 		p->pResultSet = &p->aMem[1];
-		p->rc = 0;
 		rc = SQL_ROW;
 	}
 	return rc;
@@ -1703,7 +1701,6 @@ sqlVdbeRewind(Vdbe * p)
 	}
 #endif
 	p->pc = -1;
-	p->rc = 0;
 	p->ignoreRaised = 0;
 	p->errorAction = ON_CONFLICT_ACTION_ABORT;
 	p->nChange = 0;
@@ -2088,7 +2085,7 @@ sqlVdbeCheckFk(Vdbe * p, int deferred)
 	if ((deferred && txn != NULL && txn->psql_txn != NULL &&
 	     txn->psql_txn->fk_deferred_count > 0) ||
 	    (!deferred && p->nFkConstraint > 0)) {
-		p->rc = -1;
+		p->is_aborted = true;
 		p->errorAction = ON_CONFLICT_ACTION_ABORT;
 		diag_set(ClientError, ER_SQL_EXECUTE, "FOREIGN KEY constraint "\
 			 "failed");
@@ -2164,7 +2161,7 @@ sqlVdbeHalt(Vdbe * p)
 	 */
 
 	if (db->mallocFailed) {
-		p->rc = -1;
+		p->is_aborted = true;
 	}
 	closeTopFrameCursors(p);
 	if (p->magic != VDBE_MAGIC_RUN) {
@@ -2179,7 +2176,7 @@ sqlVdbeHalt(Vdbe * p)
 		int eStatementOp = 0;
 
 		/* Check for immediate foreign key violations. */
-		if (p->rc == 0) {
+		if (!p->is_aborted) {
 			sqlVdbeCheckFk(p, 0);
 		}
 
@@ -2190,7 +2187,7 @@ sqlVdbeHalt(Vdbe * p)
 		 * above has occurred.
 		 */
 		if (p->auto_commit) {
-			if (p->rc == 0
+			if (!p->is_aborted
 			    || (p->errorAction == ON_CONFLICT_ACTION_FAIL)) {
 				rc = sqlVdbeCheckFk(p, 1);
 				if (rc != 0) {
@@ -2214,7 +2211,7 @@ sqlVdbeHalt(Vdbe * p)
 					closeCursorsAndFree(p);
 				}
 				if (rc != 0) {
-					p->rc = rc;
+					p->is_aborted = true;
 					box_txn_rollback();
 					closeCursorsAndFree(p);
 					sqlRollbackAll(p);
@@ -2228,7 +2225,8 @@ sqlVdbeHalt(Vdbe * p)
 			}
 			p->anonymous_savepoint = NULL;
 		} else if (eStatementOp == 0) {
-			if (p->rc == 0 || p->errorAction == ON_CONFLICT_ACTION_FAIL) {
+			if (!p->is_aborted ||
+			    p->errorAction == ON_CONFLICT_ACTION_FAIL) {
 				eStatementOp = SAVEPOINT_RELEASE;
 			} else if (p->errorAction == ON_CONFLICT_ACTION_ABORT) {
 				eStatementOp = SAVEPOINT_ROLLBACK;
@@ -2251,8 +2249,7 @@ sqlVdbeHalt(Vdbe * p)
 			rc = sqlVdbeCloseStatement(p, eStatementOp);
 			if (rc) {
 				box_txn_rollback();
-				if (p->rc == 0)
-					p->rc = rc;
+				p->is_aborted = true;
 				closeCursorsAndFree(p);
 				sqlRollbackAll(p);
 				sqlCloseSavepoints(p);
@@ -2282,9 +2279,8 @@ sqlVdbeHalt(Vdbe * p)
 	}
 	p->magic = VDBE_MAGIC_HALT;
 	checkActiveVdbeCnt(db);
-	if (db->mallocFailed) {
-		p->rc = -1;
-	}
+	if (db->mallocFailed)
+		p->is_aborted = true;
 
 	assert(db->nVdbeActive > 0 || box_txn() ||
 	       p->anonymous_savepoint == NULL);
@@ -2292,16 +2288,6 @@ sqlVdbeHalt(Vdbe * p)
 }
 
 /*
- * Each VDBE holds the result of the most recent sql_step() call
- * in p->rc.  This routine sets that result back to 0.
- */
-void
-sqlVdbeResetStepResult(Vdbe * p)
-{
-	p->rc = 0;
-}
-
-/*
  * Clean up a VDBE after execution but do not delete the VDBE just yet.
  * Return the result code.
  *
@@ -2337,7 +2323,7 @@ sqlVdbeReset(Vdbe * p)
 		 * is currently disabled, so this error has been
 		 * replaced with assert.
 		 */
-		assert(p->rc == 0 || p->expired == 0);
+		assert(!p->is_aborted || p->expired == 0);
 	}
 
 	/* Reclaim all memory used by the VDBE
@@ -2386,7 +2372,7 @@ sqlVdbeReset(Vdbe * p)
 #endif
 	p->iCurrentTime = 0;
 	p->magic = VDBE_MAGIC_RESET;
-	return p->rc;
+	return p->is_aborted ? -1 : 0;
 }
 
 /*
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] [PATCH v1 21/21] sql: remove sql_log()
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (19 preceding siblings ...)
  2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 20/21] sql: replace rc by is_aborted in struct Parse imeevma
@ 2019-05-25 10:45 ` imeevma
  2019-05-25 16:36 ` [tarantool-patches] Re: [PATCH v1 00/21] sql: remove SQL error system n.pettik
  21 siblings, 0 replies; 36+ messages in thread
From: imeevma @ 2019-05-25 10:45 UTC (permalink / raw)
  To: korablev; +Cc: tarantool-patches

This function is not used in Tarantool and should be removed.
---
 src/box/sql/os_unix.c |  7 +++----
 src/box/sql/printf.c  | 34 ----------------------------------
 src/box/sql/resolve.c |  3 +--
 src/box/sql/sqlInt.h  |  3 ---
 4 files changed, 4 insertions(+), 43 deletions(-)

diff --git a/src/box/sql/os_unix.c b/src/box/sql/os_unix.c
index f0cf4ac..b161580 100644
--- a/src/box/sql/os_unix.c
+++ b/src/box/sql/os_unix.c
@@ -1073,10 +1073,9 @@ unixUnmapfile(unixFile * pFd)
  *       unixFile.mmapSize
  *       unixFile.mmapSizeActual
  *
- * If unsuccessful, an error message is logged via sql_log() and
- * the three variables above are zeroed. In this case sql should
- * continue accessing the database using the xRead() and xWrite()
- * methods.
+ * If unsuccessful,the three variables above are zeroed. In this
+ * case sql should continue accessing the database using the
+ * xRead() and xWrite() methods.
  */
 static void
 unixRemapfile(unixFile * pFd,	/* File descriptor object */
diff --git a/src/box/sql/printf.c b/src/box/sql/printf.c
index c364055..ed41ae9 100644
--- a/src/box/sql/printf.c
+++ b/src/box/sql/printf.c
@@ -1125,40 +1125,6 @@ sql_snprintf(int n, char *zBuf, const char *zFormat, ...)
 	return z;
 }
 
-/*
- * This is the routine that actually formats the sql_log() message.
- * We house it in a separate routine from sql_log() to avoid using
- * stack space on small-stack systems when logging is disabled.
- *
- * sqlVXPrintf() might ask for *temporary* memory allocations for
- * certain format characters (%q) or for very large precisions or widths.
- */
-static void
-renderLogMsg(int iErrCode, const char *zFormat, va_list ap)
-{
-	StrAccum acc;		/* String accumulator */
-	char zMsg[SQL_PRINT_BUF_SIZE * 3];	/* Complete log message */
-
-	sqlStrAccumInit(&acc, 0, zMsg, sizeof(zMsg), 0);
-	sqlVXPrintf(&acc, zFormat, ap);
-	sqlGlobalConfig.xLog(sqlGlobalConfig.pLogArg, iErrCode,
-				 sqlStrAccumFinish(&acc));
-}
-
-/*
- * Format and write a message to the log if logging is enabled.
- */
-void
-sql_log(int iErrCode, const char *zFormat, ...)
-{
-	va_list ap;		/* Vararg list */
-	if (sqlGlobalConfig.xLog) {
-		va_start(ap, zFormat);
-		renderLogMsg(iErrCode, zFormat, ap);
-		va_end(ap);
-	}
-}
-
 #if defined(SQL_DEBUG)
 /*
  * A version of printf() that understands %lld.  Used for debugging.
diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c
index e136312..32e8791 100644
--- a/src/box/sql/resolve.c
+++ b/src/box/sql/resolve.c
@@ -363,8 +363,7 @@ lookupName(Parse * pParse,	/* The parsing context */
 		 * The ability to use an output result-set column in the WHERE, GROUP BY,
 		 * or HAVING clauses, or as part of a larger expression in the ORDER BY
 		 * clause is not standard SQL.  This is a (goofy) sql extension, that
-		 * is supported for backwards compatibility only. Hence, we issue a warning
-		 * on sql_log() whenever the capability is used.
+		 * is supported for backwards compatibility only.
 		 */
 		if ((pEList = pNC->pEList) != 0 && zTab == 0 && cnt == 0) {
 			for (j = 0; j < pEList->nExpr; j++) {
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0db13ed..443d3cc 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -580,9 +580,6 @@ sql_row_count(struct sql_context *context, MAYBE_UNUSED int unused1,
 void *
 sql_user_data(sql_context *);
 
-void
-sql_log(int iErrCode, const char *zFormat, ...);
-
 void *
 sql_aggregate_context(sql_context *,
 			  int nBytes);
-- 
2.7.4

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 03/21] sql: remove SQL_OK error/status code
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 03/21] sql: remove SQL_OK error/status code imeevma
@ 2019-05-25 14:45   ` n.pettik
  2019-05-26  9:39     ` Mergen Imeev
  0 siblings, 1 reply; 36+ messages in thread
From: n.pettik @ 2019-05-25 14:45 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Imeev Mergen

I’ve found two mentions of this macro in sqlInt.h:
in comment for sqlColumnsFromExprList() and
in comment for sql_analysis_load(). Remove
them as well.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code imeevma
@ 2019-05-25 14:58   ` n.pettik
  2019-05-25 20:26     ` Konstantin Osipov
  2019-05-26  9:45     ` Mergen Imeev
  0 siblings, 2 replies; 36+ messages in thread
From: n.pettik @ 2019-05-25 14:58 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Imeev Mergen



> On 25 May 2019, at 13:44, imeevma@tarantool.org wrote:
> 
> Removing this error/status code is part of getting rid of the SQL
> error system.
> ---
> src/box/sql/os_unix.c |  2 +-
> src/box/sql/sqlInt.h  |  2 --
> src/box/sql/where.c   | 13 ++-----------
> 3 files changed, 3 insertions(+), 14 deletions(-)
> 
> diff --git a/src/box/sql/where.c b/src/box/sql/where.c
> index 0b1ccd9..060dfee 100644
> --- a/src/box/sql/where.c
> +++ b/src/box/sql/where.c
> @@ -1528,21 +1528,14 @@ whereEqualScanEst(Parse * pParse,	/* Parsing & code generating context */
> 	assert(nEq >= 1);
> 	assert(nEq <= (int) p->key_def->part_count);
> 	assert(pBuilder->nRecValid < nEq);
> -
> -	/* If values are not available for all fields of the index to the left
> -	 * of this one, no estimate can be made. Return SQL_NOTFOUND.
> -	 */
> -	if (pBuilder->nRecValid < (nEq - 1)) {
> -		return SQL_NOTFOUND;
> -	}
> +	assert(pBuilder->nRecValid >= (nEq - 1));

Taking into consideration assert above, it could
be replaced with assert(pBuilder->nRecValid == nEq - 1);
Btw, this function doesn’t seem to be called at all:
unreachable() assert doesn’t fire. I can assume that it is
connected with stat tables.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 20/21] sql: replace rc by is_aborted in struct Parse
  2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 20/21] sql: replace rc by is_aborted in struct Parse imeevma
@ 2019-05-25 15:46   ` n.pettik
  2019-05-26  9:49     ` Mergen Imeev
  0 siblings, 1 reply; 36+ messages in thread
From: n.pettik @ 2019-05-25 15:46 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Imeev Mergen


Not struct Parse, but struct Vdbe.

> diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
> index 1842e26..0a4f45f 100644
> --- a/src/box/sql/vdbeapi.c
> +++ b/src/box/sql/vdbeapi.c
> 
> 
> diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
> index 28b423d..944a8a7 100644
> --- a/src/box/sql/vdbeaux.c
> +++ b/src/box/sql/vdbeaux.c
> 
> @@ -1703,7 +1701,6 @@ sqlVdbeRewind(Vdbe * p)
> 	}
> #endif
> 	p->pc = -1;
> -	p->rc = 0;

Why not setting here is_aborted = false; ?

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 12/21] sql: remove SQL_TOOBIG errcode
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 12/21] sql: remove SQL_TOOBIG errcode imeevma
@ 2019-05-25 16:11   ` n.pettik
  2019-05-26 12:12     ` Mergen Imeev
  0 siblings, 1 reply; 36+ messages in thread
From: n.pettik @ 2019-05-25 16:11 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Imeev Mergen


> diff --git a/src/box/bind.c b/src/box/bind.c
> index 90d56d6..754f6c7 100644
> --- a/src/box/bind.c
> +++ b/src/box/bind.c
> @@ -207,16 +207,7 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
> 	}
> 	if (rc == 0)
> 		return 0;
> -
> -	switch (rc) {
> -	case SQL_NOMEM:
> -		diag_set(OutOfMemory, p->bytes, "vdbe", "bind value");
> -		break;
> -	case SQL_TOOBIG:
> -	default:
> -		diag_set(ClientError, ER_SQL_BIND_VALUE, sql_bind_name(p),
> -			 mp_type_strs[p->type]);
> -		break;
> -	}
> +	diag_set(ClientError, ER_SQL_BIND_VALUE, sql_bind_name(p),
> +		 mp_type_strs[p->type]);

I guess this refactoring is incorrect a bit. Here you always set
ER_SQL_BIND_VALUE. However, sqlVdbeMemSetStr() and
sql_bind_zeroblob64() already set ER_SQL_EXECUTE error
in case “string or blob is too big”. Probably, this case is not
covered by tests. Please, come up with test case on this condition.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 11/21] sql: remove SQL_SCHEMA errcode
  2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 11/21] sql: remove SQL_SCHEMA errcode imeevma
@ 2019-05-25 16:18   ` n.pettik
  2019-05-26  9:46     ` Mergen Imeev
  0 siblings, 1 reply; 36+ messages in thread
From: n.pettik @ 2019-05-25 16:18 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Imeev Mergen


> diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
> index 2083d27..61081fb 100644
> --- a/src/box/sql/prepare.c
> +++ b/src/box/sql/prepare.c
> @@ -190,56 +190,15 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
> 		      sql_stmt ** ppStmt,	/* OUT: A pointer to the prepared statement */
> 		      const char **pzTail)	/* OUT: End of parsed string */
> {
> -	int rc;

Why not completely replace with sqlPrepare?

> -
> 	*ppStmt = 0;
> 	assert(zSql != NULL && db != NULL);
> -	rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
> -			    pzTail);
> -	if (rc == SQL_SCHEMA) {
> -		sql_finalize(*ppStmt);
> -		rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
> -				    pzTail);
> -	}
> -	assert(rc == 0 || *ppStmt == 0);
> -	return rc;
> -}
> -
> -/*
> - * Rerun the compilation of a statement after a schema change.
> - */
> -int
> -sqlReprepare(Vdbe * p)
> -{
> -	int rc;
> -	sql_stmt *pNew;
> -	const char *zSql;
> -	sql *db;
> -
> -	zSql = sql_sql((sql_stmt *) p);
> -	assert(zSql != 0);	/* Reprepare only called for prepare_v2() statements */
> -	db = sqlVdbeDb(p);
> -	rc = sqlLockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
> -	if (rc) {
> -		if (rc == SQL_NOMEM) {
> -			sqlOomFault(db);
> -		}
> -		assert(pNew == 0);
> -		return rc;
> -	} else {
> -		assert(pNew != 0);
> -	}
> -	sqlVdbeSwap((Vdbe *) pNew, p);
> -	sqlTransferBindings(pNew, (sql_stmt *) p);
> -	sqlVdbeResetStepResult((Vdbe *) pNew);
> -	sqlVdbeFinalize((Vdbe *) pNew);
> -	return 0;
> +	return sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
> }

This routine may turn out to be useful when we add
working prepared statements.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 00/21] sql: remove SQL error system.
  2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
                   ` (20 preceding siblings ...)
  2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 21/21] sql: remove sql_log() imeevma
@ 2019-05-25 16:36 ` n.pettik
  2019-05-28 11:12   ` Mergen Imeev
  21 siblings, 1 reply; 36+ messages in thread
From: n.pettik @ 2019-05-25 16:36 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Imeev Mergen

[-- Attachment #1: Type: text/plain, Size: 200 bytes --]

I’ve pushed couple of follow-ups:
https://github.com/tarantool/tarantool/tree/np/gh-4074-follow-ups <https://github.com/tarantool/tarantool/tree/np/gh-4074-follow-ups>

Check them out please.


[-- Attachment #2: Type: text/html, Size: 484 bytes --]

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code
  2019-05-25 14:58   ` [tarantool-patches] " n.pettik
@ 2019-05-25 20:26     ` Konstantin Osipov
  2019-05-26 16:07       ` n.pettik
  2019-05-26  9:45     ` Mergen Imeev
  1 sibling, 1 reply; 36+ messages in thread
From: Konstantin Osipov @ 2019-05-25 20:26 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Imeev Mergen

* n.pettik <korablev@tarantool.org> [19/05/25 21:58]:
> Taking into consideration assert above, it could
> be replaced with assert(pBuilder->nRecValid == nEq - 1);
> Btw, this function doesn’t seem to be called at all:
> unreachable() assert doesn’t fire. I can assume that it is
> connected with stat tables.
> 

NIkita, could you please be more specific, is it an accept or a
reject? Can review comments be done in their own patches? 

This is a big patch stack and I would like us to stop shuffling it
around. If it does improve things, let it get in please and do the
follow up work separately. Or at least let some of the good
patches in.

-- 
Konstantin Osipov, Moscow, Russia

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 03/21] sql: remove SQL_OK error/status code
  2019-05-25 14:45   ` [tarantool-patches] " n.pettik
@ 2019-05-26  9:39     ` Mergen Imeev
  0 siblings, 0 replies; 36+ messages in thread
From: Mergen Imeev @ 2019-05-26  9:39 UTC (permalink / raw)
  To: n.pettik; +Cc: tarantool-patches

Thank you for review! Mu answer and diff below.

On Sat, May 25, 2019 at 05:45:12PM +0300, n.pettik wrote:
> I’ve found two mentions of this macro in sqlInt.h:
> in comment for sqlColumnsFromExprList() and
> in comment for sql_analysis_load(). Remove
> them as well.
> 
Fixed.

diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index c989664..958960e 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -3268,7 +3268,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,
@@ -4567,7 +4567,7 @@ sql_index_tuple_size(struct space *space, struct index *idx);
  * samples[] arrays.
  *
  * @param db Database handler.
- * @retval sql_OK on success, smth else otherwise.
+ * @retval 0 on success, smth else otherwise.
  */
 int
 sql_analysis_load(struct sql *db);

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code
  2019-05-25 14:58   ` [tarantool-patches] " n.pettik
  2019-05-25 20:26     ` Konstantin Osipov
@ 2019-05-26  9:45     ` Mergen Imeev
  1 sibling, 0 replies; 36+ messages in thread
From: Mergen Imeev @ 2019-05-26  9:45 UTC (permalink / raw)
  To: n.pettik; +Cc: tarantool-patches

On Sat, May 25, 2019 at 05:58:19PM +0300, n.pettik wrote:
> 
> 
> > On 25 May 2019, at 13:44, imeevma@tarantool.org wrote:
> > 
> > Removing this error/status code is part of getting rid of the SQL
> > error system.
> > ---
> > src/box/sql/os_unix.c |  2 +-
> > src/box/sql/sqlInt.h  |  2 --
> > src/box/sql/where.c   | 13 ++-----------
> > 3 files changed, 3 insertions(+), 14 deletions(-)
> > 
> > diff --git a/src/box/sql/where.c b/src/box/sql/where.c
> > index 0b1ccd9..060dfee 100644
> > --- a/src/box/sql/where.c
> > +++ b/src/box/sql/where.c
> > @@ -1528,21 +1528,14 @@ whereEqualScanEst(Parse * pParse,	/* Parsing & code generating context */
> > 	assert(nEq >= 1);
> > 	assert(nEq <= (int) p->key_def->part_count);
> > 	assert(pBuilder->nRecValid < nEq);
> > -
> > -	/* If values are not available for all fields of the index to the left
> > -	 * of this one, no estimate can be made. Return SQL_NOTFOUND.
> > -	 */
> > -	if (pBuilder->nRecValid < (nEq - 1)) {
> > -		return SQL_NOTFOUND;
> > -	}
> > +	assert(pBuilder->nRecValid >= (nEq - 1));
> 
> Taking into consideration assert above, it could
> be replaced with assert(pBuilder->nRecValid == nEq - 1);
Fixed.

diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 060dfee..81a2739 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -1527,8 +1527,7 @@ whereEqualScanEst(Parse * pParse,	/* Parsing & code generating context */
 
 	assert(nEq >= 1);
 	assert(nEq <= (int) p->key_def->part_count);
-	assert(pBuilder->nRecValid < nEq);
-	assert(pBuilder->nRecValid >= (nEq - 1));
+	assert(pBuilder->nRecValid == (nEq - 1));
 
 	rc = sqlStat4ProbeSetValue(pParse, p, &pRec, pExpr, 1, nEq - 1,
 				       &bOk);

> Btw, this function doesn’t seem to be called at all:
> unreachable() assert doesn’t fire. I can assume that it is
> connected with stat tables.
> 
I think that we do not have the right way to check this, so
I think that we will either enable or delete this function
when the statistics table is created.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 11/21] sql: remove SQL_SCHEMA errcode
  2019-05-25 16:18   ` [tarantool-patches] " n.pettik
@ 2019-05-26  9:46     ` Mergen Imeev
  0 siblings, 0 replies; 36+ messages in thread
From: Mergen Imeev @ 2019-05-26  9:46 UTC (permalink / raw)
  To: n.pettik; +Cc: tarantool-patches

On Sat, May 25, 2019 at 07:18:45PM +0300, n.pettik wrote:
> 
> > diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
> > index 2083d27..61081fb 100644
> > --- a/src/box/sql/prepare.c
> > +++ b/src/box/sql/prepare.c
> > @@ -190,56 +190,15 @@ sqlLockAndPrepare(sql * db,		/* Database handle. */
> > 		      sql_stmt ** ppStmt,	/* OUT: A pointer to the prepared statement */
> > 		      const char **pzTail)	/* OUT: End of parsed string */
> > {
> > -	int rc;
> 
> Why not completely replace with sqlPrepare?
> 
Done.

> > -
> > 	*ppStmt = 0;
> > 	assert(zSql != NULL && db != NULL);
> > -	rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
> > -			    pzTail);
> > -	if (rc == SQL_SCHEMA) {
> > -		sql_finalize(*ppStmt);
> > -		rc = sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt,
> > -				    pzTail);
> > -	}
> > -	assert(rc == 0 || *ppStmt == 0);
> > -	return rc;
> > -}
> > -
> > -/*
> > - * Rerun the compilation of a statement after a schema change.
> > - */
> > -int
> > -sqlReprepare(Vdbe * p)
> > -{
> > -	int rc;
> > -	sql_stmt *pNew;
> > -	const char *zSql;
> > -	sql *db;
> > -
> > -	zSql = sql_sql((sql_stmt *) p);
> > -	assert(zSql != 0);	/* Reprepare only called for prepare_v2() statements */
> > -	db = sqlVdbeDb(p);
> > -	rc = sqlLockAndPrepare(db, zSql, -1, 0, p, &pNew, 0);
> > -	if (rc) {
> > -		if (rc == SQL_NOMEM) {
> > -			sqlOomFault(db);
> > -		}
> > -		assert(pNew == 0);
> > -		return rc;
> > -	} else {
> > -		assert(pNew != 0);
> > -	}
> > -	sqlVdbeSwap((Vdbe *) pNew, p);
> > -	sqlTransferBindings(pNew, (sql_stmt *) p);
> > -	sqlVdbeResetStepResult((Vdbe *) pNew);
> > -	sqlVdbeFinalize((Vdbe *) pNew);
> > -	return 0;
> > +	return sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
> > }
> 
> This routine may turn out to be useful when we add
> working prepared statements.
> 
Done.

Diff:

diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c
index 61081fb..33f6783 100644
--- a/src/box/sql/prepare.c
+++ b/src/box/sql/prepare.c
@@ -56,7 +56,7 @@ sqlPrepare(sql * db,	/* Database handle. */
 	Parse sParse;		/* Parsing context */
 	sql_parser_create(&sParse, db);
 	sParse.pReprepare = pReprepare;
-	assert(ppStmt && *ppStmt == 0);
+	*ppStmt = NULL;
 	/* assert( !db->mallocFailed ); // not true with SQL_USE_ALLOCA */
 
 	/* Check to verify that it is possible to get a read lock on all
@@ -181,24 +181,35 @@ sqlPrepare(sql * db,	/* Database handle. */
 	return rc;
 }
 
-static int
-sqlLockAndPrepare(sql * db,		/* Database handle. */
-		      const char *zSql,		/* UTF-8 encoded SQL statement. */
-		      int nBytes,		/* Length of zSql in bytes. */
-		      int saveSqlFlag,		/* True to copy SQL text into the sql_stmt */
-		      Vdbe * pOld,		/* VM being reprepared */
-		      sql_stmt ** ppStmt,	/* OUT: A pointer to the prepared statement */
-		      const char **pzTail)	/* OUT: End of parsed string */
+/*
+ * Rerun the compilation of a statement after a schema change.
+ */
+int
+sqlReprepare(Vdbe * p)
 {
-	*ppStmt = 0;
-	assert(zSql != NULL && db != NULL);
-	return sqlPrepare(db, zSql, nBytes, saveSqlFlag, pOld, ppStmt, pzTail);
+	sql_stmt *pNew;
+	const char *zSql;
+	sql *db;
+
+	zSql = sql_sql((sql_stmt *) p);
+	assert(zSql != 0);	/* Reprepare only called for prepare_v2() statements */
+	db = sqlVdbeDb(p);
+	if (sqlPrepare(db, zSql, -1, 0, p, &pNew, 0) != 0) {
+		assert(pNew == 0);
+		return -1;
+	}
+	assert(pNew != 0);
+	sqlVdbeSwap((Vdbe *) pNew, p);
+	sqlTransferBindings(pNew, (sql_stmt *) p);
+	sqlVdbeResetStepResult((Vdbe *) pNew);
+	sqlVdbeFinalize((Vdbe *) pNew);
+	return 0;
 }
 
 /*
  * Two versions of the official API.  Legacy and new use.  In the legacy
  * version, the original SQL text is not saved in the prepared statement
- * and so if a schema change occurs, error is returned by
+ * and so if a schema change occurs, SQL_SCHEMA is returned by
  * sql_step().  In the new version, the original SQL text is retained
  * and the statement is automatically recompiled if an schema change
  * occurs.
@@ -211,7 +222,7 @@ sql_prepare(sql * db,		/* Database handle. */
 		const char **pzTail)	/* OUT: End of parsed string */
 {
 	int rc;
-	rc = sqlLockAndPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail);
+	rc = sqlPrepare(db, zSql, nBytes, 0, 0, ppStmt, pzTail);
 	assert(rc == 0 || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
 	return rc;
 }
@@ -225,7 +236,7 @@ sql_prepare_v2(sql * db,	/* Database handle. */
     )
 {
 	int rc;
-	rc = sqlLockAndPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail);
+	rc = sqlPrepare(db, zSql, nBytes, 1, 0, ppStmt, pzTail);
 	assert(rc == 0 || ppStmt == 0 || *ppStmt == 0);	/* VERIFY: F13021 */
 	return rc;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0419933..f0d0fed 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -4685,6 +4685,7 @@ void sqlInvalidFunction(sql_context *, int, sql_value **);
 sql_int64 sqlStmtCurrentTime(sql_context *);
 int sqlVdbeParameterIndex(Vdbe *, const char *, int);
 int sqlTransferBindings(sql_stmt *, sql_stmt *);
+int sqlReprepare(Vdbe *);
 
 /**
  * This function verifies that two collations (to be more precise

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 20/21] sql: replace rc by is_aborted in struct Parse
  2019-05-25 15:46   ` [tarantool-patches] " n.pettik
@ 2019-05-26  9:49     ` Mergen Imeev
  0 siblings, 0 replies; 36+ messages in thread
From: Mergen Imeev @ 2019-05-26  9:49 UTC (permalink / raw)
  To: n.pettik; +Cc: tarantool-patches

On Sat, May 25, 2019 at 06:46:34PM +0300, n.pettik wrote:
> 
> Not struct Parse, but struct Vdbe.
> 
Fixed:

sql: replace rc by is_aborted in struct VDBE

Currently, the rc field of the VDBE structure is either 0 or -1.
Due to this, it is better to replace this integer field with the
boolean field is_aborted.


> > diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
> > index 1842e26..0a4f45f 100644
> > --- a/src/box/sql/vdbeapi.c
> > +++ b/src/box/sql/vdbeapi.c
> > 
> > 
> > diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
> > index 28b423d..944a8a7 100644
> > --- a/src/box/sql/vdbeaux.c
> > +++ b/src/box/sql/vdbeaux.c
> > 
> > @@ -1703,7 +1701,6 @@ sqlVdbeRewind(Vdbe * p)
> > 	}
> > #endif
> > 	p->pc = -1;
> > -	p->rc = 0;
> 
> Why not setting here is_aborted = false; ?
> 
> 
Fixed.

Also, I returned the sqlVdbeResetStepResult() function,
since it is now used in seqReprepare().


Diff:

diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h
index c8f2618..6234dff 100644
--- a/src/box/sql/vdbe.h
+++ b/src/box/sql/vdbe.h
@@ -253,6 +253,7 @@ void sqlVdbeMakeReady(Vdbe *, Parse *);
 int sqlVdbeFinalize(Vdbe *);
 void sqlVdbeResolveLabel(Vdbe *, int);
 int sqlVdbeCurrentAddr(Vdbe *);
+void sqlVdbeResetStepResult(Vdbe *);
 void sqlVdbeRewind(Vdbe *);
 int sqlVdbeReset(Vdbe *);
 void sqlVdbeSetNumCols(Vdbe *, int);
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index 944a8a7..ec303c7 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -1701,6 +1701,7 @@ sqlVdbeRewind(Vdbe * p)
 	}
 #endif
 	p->pc = -1;
+	p->is_aborted = false;
 	p->ignoreRaised = 0;
 	p->errorAction = ON_CONFLICT_ACTION_ABORT;
 	p->nChange = 0;
@@ -2288,6 +2289,15 @@ sqlVdbeHalt(Vdbe * p)
 }
 
 /*
+ * This routine sets is_aborted of VDBE to false.
+ */
+void
+sqlVdbeResetStepResult(Vdbe * p)
+{
+	p->is_aborted = false;
+}
+
+/*
  * Clean up a VDBE after execution but do not delete the VDBE just yet.
  * Return the result code.
  *

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 12/21] sql: remove SQL_TOOBIG errcode
  2019-05-25 16:11   ` [tarantool-patches] " n.pettik
@ 2019-05-26 12:12     ` Mergen Imeev
  0 siblings, 0 replies; 36+ messages in thread
From: Mergen Imeev @ 2019-05-26 12:12 UTC (permalink / raw)
  To: n.pettik; +Cc: tarantool-patches

Hi! Thank you for review! My answer below. Also you can
there diff for patch "sql: remove SQL_RANGE errcode",
new patch "sql: remove SQL_RANGE errcode" and new patch
"sql: remove SQL_TOOBIG".


On Sat, May 25, 2019 at 07:11:00PM +0300, n.pettik wrote:
> 
> > diff --git a/src/box/bind.c b/src/box/bind.c
> > index 90d56d6..754f6c7 100644
> > --- a/src/box/bind.c
> > +++ b/src/box/bind.c
> > @@ -207,16 +207,7 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
> > 	}
> > 	if (rc == 0)
> > 		return 0;
> > -
> > -	switch (rc) {
> > -	case SQL_NOMEM:
> > -		diag_set(OutOfMemory, p->bytes, "vdbe", "bind value");
> > -		break;
> > -	case SQL_TOOBIG:
> > -	default:
> > -		diag_set(ClientError, ER_SQL_BIND_VALUE, sql_bind_name(p),
> > -			 mp_type_strs[p->type]);
> > -		break;
> > -	}
> > +	diag_set(ClientError, ER_SQL_BIND_VALUE, sql_bind_name(p),
> > +		 mp_type_strs[p->type]);
> 
> I guess this refactoring is incorrect a bit. Here you always set
> ER_SQL_BIND_VALUE. However, sqlVdbeMemSetStr() and
> sql_bind_zeroblob64() already set ER_SQL_EXECUTE error
> in case “string or blob is too big”. Probably, this case is not
> covered by tests. Please, come up with test case on this condition.
> 
After some research, I found that this refactoring was definitely
wrong. One reason for this is that you should not set an error
here. If one of the functions sql_bind_ *() returns not 0, it
means that the error has already been set.

After another investigation, I found that one of the assertions I
made in the "sql: remove SQL_RANGE errcode" patch shows an error.
This error is caught by pcall() in tests, so I failed to find it
earlier.

I did some refactoring in the "sql: remove SQL_RANGE errcode"
patch, which solved mentioned problem.


Diff for patch "sql: remove SQL_RANGE errcode":

diff --git a/src/box/bind.c b/src/box/bind.c
index 90d56d6..4888265 100644
--- a/src/box/bind.c
+++ b/src/box/bind.c
@@ -162,7 +162,6 @@ int
 sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 		uint32_t pos)
 {
-	int rc;
 	if (p->name != NULL) {
 		pos = sql_bind_parameter_lindex(stmt, p->name, p->name_len);
 		if (pos == 0) {
@@ -174,15 +173,12 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 	switch (p->type) {
 	case MP_INT:
 	case MP_UINT:
-		rc = sql_bind_int64(stmt, pos, p->i64);
-		break;
+		return sql_bind_int64(stmt, pos, p->i64);
 	case MP_BOOL:
-		rc = sql_bind_boolean(stmt, pos, p->b);
-		break;
+		return sql_bind_boolean(stmt, pos, p->b);
 	case MP_DOUBLE:
 	case MP_FLOAT:
-		rc = sql_bind_double(stmt, pos, p->d);
-		break;
+		return sql_bind_double(stmt, pos, p->d);
 	case MP_STR:
 		/*
 		 * Parameters are allocated within message pack,
@@ -192,31 +188,14 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 		 * there is no need to copy the packet and we can
 		 * use SQL_STATIC.
 		 */
-		rc = sql_bind_text64(stmt, pos, p->s, p->bytes,
-					 SQL_STATIC);
-		break;
+		return sql_bind_text64(stmt, pos, p->s, p->bytes, SQL_STATIC);
 	case MP_NIL:
-		rc = sql_bind_null(stmt, pos);
-		break;
+		return sql_bind_null(stmt, pos);
 	case MP_BIN:
-		rc = sql_bind_blob64(stmt, pos, (const void *) p->s,
-					 p->bytes, SQL_STATIC);
-		break;
+		return sql_bind_blob64(stmt, pos, (const void *) p->s, p->bytes,
+				       SQL_STATIC);
 	default:
 		unreachable();
 	}
-	if (rc == 0)
-		return 0;
-
-	switch (rc) {
-	case SQL_NOMEM:
-		diag_set(OutOfMemory, p->bytes, "vdbe", "bind value");
-		break;
-	case SQL_TOOBIG:
-	default:
-		diag_set(ClientError, ER_SQL_BIND_VALUE, sql_bind_name(p),
-			 mp_type_strs[p->type]);
-		break;
-	}
-	return -1;
+	return 0;
 }
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index c697efb..49ef588 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -973,7 +973,12 @@ vdbeUnbind(Vdbe * p, int i)
 	Mem *pVar;
 	assert(p != NULL);
 	assert(p->magic == VDBE_MAGIC_RUN && p->pc < 0);
-	assert(i > 0 && i <= p->nVar);
+	assert(i > 0);
+	if(i > p->nVar) {
+		diag_set(ClientError, ER_SQL_EXECUTE, "The number of "\
+			 "parameters is too large");
+		return -1;
+	}
 	i--;
 	pVar = &p->aVar[i];
 	sqlVdbeMemRelease(pVar);
@@ -1023,19 +1028,19 @@ sql_bind_type(struct Vdbe *v, uint32_t position, const char *type)
 {
 	if (v->res_var_count < position)
 		return 0;
-	int rc = sqlVdbeSetColName(v, v->var_pos[position - 1],
-				       COLNAME_DECLTYPE, type,
-				       SQL_TRANSIENT);
+	int rc = 0;
+	if (sqlVdbeSetColName(v, v->var_pos[position - 1], COLNAME_DECLTYPE,
+			      type, SQL_TRANSIENT) != 0)
+		rc = -1;
 	const char *bind_name = v->aColName[position - 1].z;
 	if (strcmp(bind_name, "?") == 0)
 		return rc;
 	for (uint32_t i = position; i < v->res_var_count; ++i) {
 		if (strcmp(bind_name,  v->aColName[i].z) == 0) {
-			rc = sqlVdbeSetColName(v, v->var_pos[i],
-						   COLNAME_DECLTYPE, type,
-						   SQL_TRANSIENT);
-			if (rc != 0)
-				return rc;
+			if (sqlVdbeSetColName(v, v->var_pos[i],
+					      COLNAME_DECLTYPE, type,
+					      SQL_TRANSIENT) != 0)
+				return -1;
 		}
 	}
 	return 0;
@@ -1054,21 +1059,17 @@ bindText(sql_stmt * pStmt,	/* The statement to bind against */
 {
 	Vdbe *p = (Vdbe *) pStmt;
 	Mem *pVar;
-	int rc;
-
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		if (zData != 0) {
-			pVar = &p->aVar[i - 1];
-			rc = sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel);
-			if (rc == 0)
-				rc = sql_bind_type(p, i, "TEXT");
-			rc = sqlApiExit(p->db, rc);
-		}
-	} else if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) {
-		xDel((void *)zData);
+	if (vdbeUnbind(p, i) != 0) {
+		if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT)
+			xDel((void *)zData);
+		return -1;
 	}
-	return rc;
+	if (zData == NULL)
+		return 0;
+	pVar = &p->aVar[i - 1];
+	if (sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel) != 0)
+		return -1;
+	return sql_bind_type(p, i, "TEXT");
 }
 
 /*
@@ -1080,19 +1081,17 @@ sql_bind_blob(sql_stmt * pStmt,
     )
 {
 	struct Vdbe *p = (Vdbe *) pStmt;
-	int rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		if (zData != 0) {
-			struct Mem *var = &p->aVar[i - 1];
-			rc = sqlVdbeMemSetStr(var, zData, nData, 0, xDel);
-			if (rc == 0)
-				rc = sql_bind_type(p, i, "BLOB");
-			rc = sqlApiExit(p->db, rc);
-		}
-	} else if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) {
-		xDel((void *)zData);
+	if (vdbeUnbind(p, i) != 0) {
+		if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT)
+			xDel((void *)zData);
+		return -1;
 	}
-	return rc;
+	if (zData == NULL)
+		return 0;
+	struct Mem *var = &p->aVar[i - 1];
+	if (sqlVdbeMemSetStr(var, zData, nData, 0, xDel) != 0)
+		return -1;
+	return sql_bind_type(p, i, "BLOB");
 }
 
 int
@@ -1113,13 +1112,11 @@ sql_bind_blob64(sql_stmt * pStmt,
 int
 sql_bind_double(sql_stmt * pStmt, int i, double rValue)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		rc = sql_bind_type(p, i, "NUMERIC");
-		sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue);
-	}
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	int rc = sql_bind_type(p, i, "NUMERIC");
+	sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue);
 	return rc;
 }
 
@@ -1127,11 +1124,10 @@ int
 sql_bind_boolean(struct sql_stmt *stmt, int i, bool value)
 {
 	struct Vdbe *p = (struct Vdbe *) stmt;
-	int rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		rc = sql_bind_type(p, i, "BOOLEAN");
-		mem_set_bool(&p->aVar[i - 1], value);
-	}
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	int rc = sql_bind_type(p, i, "BOOLEAN");
+	mem_set_bool(&p->aVar[i - 1], value);
 	return rc;
 }
 
@@ -1144,25 +1140,21 @@ sql_bind_int(sql_stmt * p, int i, int iValue)
 int
 sql_bind_int64(sql_stmt * pStmt, int i, sql_int64 iValue)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		rc = sql_bind_type(p, i, "INTEGER");
-		sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue);
-	}
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	int rc = sql_bind_type(p, i, "INTEGER");
+	sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue);
 	return rc;
 }
 
 int
 sql_bind_null(sql_stmt * pStmt, int i)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0)
-		rc = sql_bind_type(p, i, "BOOLEAN");
-	return rc;
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	return sql_bind_type(p, i, "BOOLEAN");
 }
 
 int
@@ -1191,13 +1183,11 @@ sql_bind_text64(sql_stmt * pStmt,
 int
 sql_bind_zeroblob(sql_stmt * pStmt, int i, int n)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n);
-	}
-	return rc;
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n);
+	return 0;
 }
 
 int
diff --git a/test/sql/bind.result b/test/sql/bind.result
index 076bf83..18d546a 100644
--- a/test/sql/bind.result
+++ b/test/sql/bind.result
@@ -294,3 +294,11 @@ box.execute('DROP TABLE test')
 ---
 - row_count: 1
 ...
+box.execute('SELECT ?', {1, 2})
+---
+- error: 'Failed to execute SQL statement: The number of parameters is too large'
+...
+box.execute('SELECT $2', {1, 2, 3})
+---
+- error: 'Failed to execute SQL statement: The number of parameters is too large'
+...
diff --git a/test/sql/bind.test.lua b/test/sql/bind.test.lua
index 229207d..9dac485 100644
--- a/test/sql/bind.test.lua
+++ b/test/sql/bind.test.lua
@@ -98,3 +98,6 @@ end;
 test_run:cmd("setopt delimiter ''");
 
 box.execute('DROP TABLE test')
+
+box.execute('SELECT ?', {1, 2})
+box.execute('SELECT $2', {1, 2, 3})



New patch "sql: remove SQL_RANGE errcode":

From 5cdc8bb97cdaa8f1da2acb8e4b4f134b85b79dd2 Mon Sep 17 00:00:00 2001
Date: Tue, 21 May 2019 17:19:28 +0300
Subject: [PATCH] sql: remove SQL_RANGE errcode

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

diff --git a/src/box/bind.c b/src/box/bind.c
index 90d56d6..4888265 100644
--- a/src/box/bind.c
+++ b/src/box/bind.c
@@ -162,7 +162,6 @@ int
 sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 		uint32_t pos)
 {
-	int rc;
 	if (p->name != NULL) {
 		pos = sql_bind_parameter_lindex(stmt, p->name, p->name_len);
 		if (pos == 0) {
@@ -174,15 +173,12 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 	switch (p->type) {
 	case MP_INT:
 	case MP_UINT:
-		rc = sql_bind_int64(stmt, pos, p->i64);
-		break;
+		return sql_bind_int64(stmt, pos, p->i64);
 	case MP_BOOL:
-		rc = sql_bind_boolean(stmt, pos, p->b);
-		break;
+		return sql_bind_boolean(stmt, pos, p->b);
 	case MP_DOUBLE:
 	case MP_FLOAT:
-		rc = sql_bind_double(stmt, pos, p->d);
-		break;
+		return sql_bind_double(stmt, pos, p->d);
 	case MP_STR:
 		/*
 		 * Parameters are allocated within message pack,
@@ -192,31 +188,14 @@ sql_bind_column(struct sql_stmt *stmt, const struct sql_bind *p,
 		 * there is no need to copy the packet and we can
 		 * use SQL_STATIC.
 		 */
-		rc = sql_bind_text64(stmt, pos, p->s, p->bytes,
-					 SQL_STATIC);
-		break;
+		return sql_bind_text64(stmt, pos, p->s, p->bytes, SQL_STATIC);
 	case MP_NIL:
-		rc = sql_bind_null(stmt, pos);
-		break;
+		return sql_bind_null(stmt, pos);
 	case MP_BIN:
-		rc = sql_bind_blob64(stmt, pos, (const void *) p->s,
-					 p->bytes, SQL_STATIC);
-		break;
+		return sql_bind_blob64(stmt, pos, (const void *) p->s, p->bytes,
+				       SQL_STATIC);
 	default:
 		unreachable();
 	}
-	if (rc == 0)
-		return 0;
-
-	switch (rc) {
-	case SQL_NOMEM:
-		diag_set(OutOfMemory, p->bytes, "vdbe", "bind value");
-		break;
-	case SQL_TOOBIG:
-	default:
-		diag_set(ClientError, ER_SQL_BIND_VALUE, sql_bind_name(p),
-			 mp_type_strs[p->type]);
-		break;
-	}
-	return -1;
+	return 0;
 }
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index adf14a8..a3d99b9 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -370,8 +370,6 @@ enum sql_ret_code {
 	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
 	SQL_CONSTRAINT,
-	/** 2nd parameter to sql_bind out of range. */
-	SQL_RANGE,
 	SQL_TARANTOOL_ERROR,
 	/** sql_step() has another row ready. */
 	SQL_ROW,
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index c4891a5..49ef588 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -965,11 +965,7 @@ sql_column_origin_name(sql_stmt * pStmt, int N)
  */
 /*
  * Unbind the value bound to variable i in virtual machine p. This is the
- * the same as binding a NULL value to the column. If the "i" parameter is
- * out of range, then SQL_RANGE is returned. Othewise 0.
- *
- * The error code stored in database p->db is overwritten with the return
- * value in any case.
+ * the same as binding a NULL value to the column.
  */
 static int
 vdbeUnbind(Vdbe * p, int i)
@@ -977,8 +973,11 @@ vdbeUnbind(Vdbe * p, int i)
 	Mem *pVar;
 	assert(p != NULL);
 	assert(p->magic == VDBE_MAGIC_RUN && p->pc < 0);
-	if (i < 1 || i > p->nVar) {
-		return SQL_RANGE;
+	assert(i > 0);
+	if(i > p->nVar) {
+		diag_set(ClientError, ER_SQL_EXECUTE, "The number of "\
+			 "parameters is too large");
+		return -1;
 	}
 	i--;
 	pVar = &p->aVar[i];
@@ -1029,19 +1028,19 @@ sql_bind_type(struct Vdbe *v, uint32_t position, const char *type)
 {
 	if (v->res_var_count < position)
 		return 0;
-	int rc = sqlVdbeSetColName(v, v->var_pos[position - 1],
-				       COLNAME_DECLTYPE, type,
-				       SQL_TRANSIENT);
+	int rc = 0;
+	if (sqlVdbeSetColName(v, v->var_pos[position - 1], COLNAME_DECLTYPE,
+			      type, SQL_TRANSIENT) != 0)
+		rc = -1;
 	const char *bind_name = v->aColName[position - 1].z;
 	if (strcmp(bind_name, "?") == 0)
 		return rc;
 	for (uint32_t i = position; i < v->res_var_count; ++i) {
 		if (strcmp(bind_name,  v->aColName[i].z) == 0) {
-			rc = sqlVdbeSetColName(v, v->var_pos[i],
-						   COLNAME_DECLTYPE, type,
-						   SQL_TRANSIENT);
-			if (rc != 0)
-				return rc;
+			if (sqlVdbeSetColName(v, v->var_pos[i],
+					      COLNAME_DECLTYPE, type,
+					      SQL_TRANSIENT) != 0)
+				return -1;
 		}
 	}
 	return 0;
@@ -1060,21 +1059,17 @@ bindText(sql_stmt * pStmt,	/* The statement to bind against */
 {
 	Vdbe *p = (Vdbe *) pStmt;
 	Mem *pVar;
-	int rc;
-
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		if (zData != 0) {
-			pVar = &p->aVar[i - 1];
-			rc = sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel);
-			if (rc == 0)
-				rc = sql_bind_type(p, i, "TEXT");
-			rc = sqlApiExit(p->db, rc);
-		}
-	} else if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) {
-		xDel((void *)zData);
+	if (vdbeUnbind(p, i) != 0) {
+		if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT)
+			xDel((void *)zData);
+		return -1;
 	}
-	return rc;
+	if (zData == NULL)
+		return 0;
+	pVar = &p->aVar[i - 1];
+	if (sqlVdbeMemSetStr(pVar, zData, nData, 1, xDel) != 0)
+		return -1;
+	return sql_bind_type(p, i, "TEXT");
 }
 
 /*
@@ -1086,19 +1081,17 @@ sql_bind_blob(sql_stmt * pStmt,
     )
 {
 	struct Vdbe *p = (Vdbe *) pStmt;
-	int rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		if (zData != 0) {
-			struct Mem *var = &p->aVar[i - 1];
-			rc = sqlVdbeMemSetStr(var, zData, nData, 0, xDel);
-			if (rc == 0)
-				rc = sql_bind_type(p, i, "BLOB");
-			rc = sqlApiExit(p->db, rc);
-		}
-	} else if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT) {
-		xDel((void *)zData);
+	if (vdbeUnbind(p, i) != 0) {
+		if (xDel != SQL_STATIC && xDel != SQL_TRANSIENT)
+			xDel((void *)zData);
+		return -1;
 	}
-	return rc;
+	if (zData == NULL)
+		return 0;
+	struct Mem *var = &p->aVar[i - 1];
+	if (sqlVdbeMemSetStr(var, zData, nData, 0, xDel) != 0)
+		return -1;
+	return sql_bind_type(p, i, "BLOB");
 }
 
 int
@@ -1119,13 +1112,11 @@ sql_bind_blob64(sql_stmt * pStmt,
 int
 sql_bind_double(sql_stmt * pStmt, int i, double rValue)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		rc = sql_bind_type(p, i, "NUMERIC");
-		sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue);
-	}
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	int rc = sql_bind_type(p, i, "NUMERIC");
+	sqlVdbeMemSetDouble(&p->aVar[i - 1], rValue);
 	return rc;
 }
 
@@ -1133,11 +1124,10 @@ int
 sql_bind_boolean(struct sql_stmt *stmt, int i, bool value)
 {
 	struct Vdbe *p = (struct Vdbe *) stmt;
-	int rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		rc = sql_bind_type(p, i, "BOOLEAN");
-		mem_set_bool(&p->aVar[i - 1], value);
-	}
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	int rc = sql_bind_type(p, i, "BOOLEAN");
+	mem_set_bool(&p->aVar[i - 1], value);
 	return rc;
 }
 
@@ -1150,25 +1140,21 @@ sql_bind_int(sql_stmt * p, int i, int iValue)
 int
 sql_bind_int64(sql_stmt * pStmt, int i, sql_int64 iValue)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		rc = sql_bind_type(p, i, "INTEGER");
-		sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue);
-	}
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	int rc = sql_bind_type(p, i, "INTEGER");
+	sqlVdbeMemSetInt64(&p->aVar[i - 1], iValue);
 	return rc;
 }
 
 int
 sql_bind_null(sql_stmt * pStmt, int i)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0)
-		rc = sql_bind_type(p, i, "BOOLEAN");
-	return rc;
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	return sql_bind_type(p, i, "BOOLEAN");
 }
 
 int
@@ -1197,13 +1183,11 @@ sql_bind_text64(sql_stmt * pStmt,
 int
 sql_bind_zeroblob(sql_stmt * pStmt, int i, int n)
 {
-	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
-	rc = vdbeUnbind(p, i);
-	if (rc == 0) {
-		sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n);
-	}
-	return rc;
+	if (vdbeUnbind(p, i) != 0)
+		return -1;
+	sqlVdbeMemSetZeroBlob(&p->aVar[i - 1], n);
+	return 0;
 }
 
 int
diff --git a/test/sql/bind.result b/test/sql/bind.result
index 076bf83..18d546a 100644
--- a/test/sql/bind.result
+++ b/test/sql/bind.result
@@ -294,3 +294,11 @@ box.execute('DROP TABLE test')
 ---
 - row_count: 1
 ...
+box.execute('SELECT ?', {1, 2})
+---
+- error: 'Failed to execute SQL statement: The number of parameters is too large'
+...
+box.execute('SELECT $2', {1, 2, 3})
+---
+- error: 'Failed to execute SQL statement: The number of parameters is too large'
+...
diff --git a/test/sql/bind.test.lua b/test/sql/bind.test.lua
index 229207d..9dac485 100644
--- a/test/sql/bind.test.lua
+++ b/test/sql/bind.test.lua
@@ -98,3 +98,6 @@ end;
 test_run:cmd("setopt delimiter ''");
 
 box.execute('DROP TABLE test')
+
+box.execute('SELECT ?', {1, 2})
+box.execute('SELECT $2', {1, 2, 3})


New patch "sql: remove SQL_TOOBIG errcode":

From a534e6ed1b6b4411ee6f00f4d6ac252c3ad7c94a Mon Sep 17 00:00:00 2001
Date: Tue, 21 May 2019 17:44:59 +0300
Subject: [PATCH] sql: remove SQL_TOOBIG errcode

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

diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index 0840a34..8e861be 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -364,8 +364,6 @@ enum sql_ret_code {
 	SQL_NOMEM,
 	/** Some kind of disk I/O error occurred. */
 	SQL_IOERR,
-	/** String or BLOB exceeds size limit. */
-	SQL_TOOBIG,
 	/** Abort due to constraint violation. */
 	SQL_CONSTRAINT,
 	SQL_TARANTOOL_ERROR,
diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c
index 1668ce0..7801fd3 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -272,7 +272,7 @@ sql_value_free(sql_value * pOld)
  *
  * The setStrOrError() function calls sqlVdbeMemSetStr() to store the
  * result as a string or blob but if the string or blob is too large, it
- * then sets the error code to SQL_TOOBIG
+ * then sets the error code.
  *
  * The invokeValueDestructor(P,X) routine invokes destructor function X()
  * on value P is not going to be used and need to be destroyed.
@@ -284,16 +284,14 @@ setResultStrOrError(sql_context * pCtx,	/* Function context */
 		    void (*xDel) (void *)	/* Destructor function */
     )
 {
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,1, xDel) == SQL_TOOBIG) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,1, xDel) != 0)
 		pCtx->is_aborted = true;
-	}
 }
 
 static int
 invokeValueDestructor(const void *p,	/* Value to destroy */
 		      void (*xDel) (void *),	/* The destructor */
-		      sql_context * pCtx	/* Set a SQL_TOOBIG error if no NULL */
+		      sql_context * pCtx	/* Set an error if no NULL */
     )
 {
 	assert(xDel != SQL_DYNAMIC);
@@ -305,10 +303,11 @@ invokeValueDestructor(const void *p,	/* Value to destroy */
 		xDel((void *)p);
 	}
 	if (pCtx) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
 		pCtx->is_aborted = true;
 	}
-	return SQL_TOOBIG;
+	return SQL_TARANTOOL_ERROR;
 }
 
 void
@@ -317,10 +316,8 @@ sql_result_blob(sql_context * pCtx,
     )
 {
 	assert(n >= 0);
-	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,0, xDel) == SQL_TOOBIG) {
-		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob too big");
+	if (sqlVdbeMemSetStr(pCtx->pOut, z, n,0, xDel) != 0)
 		pCtx->is_aborted = true;
-	}
 }
 
 void
@@ -405,7 +402,9 @@ sql_result_zeroblob64(sql_context * pCtx, u64 n)
 {
 	Mem *pOut = pCtx->pOut;
 	if (n > (u64) pOut->db->aLimit[SQL_LIMIT_LENGTH]) {
-		return SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		return SQL_TARANTOOL_ERROR;
 	}
 	sqlVdbeMemSetZeroBlob(pCtx->pOut, (int)n);
 	return 0;
@@ -1179,7 +1178,9 @@ sql_bind_zeroblob64(sql_stmt * pStmt, int i, sql_uint64 n)
 	int rc;
 	Vdbe *p = (Vdbe *) pStmt;
 	if (n > (u64) p->db->aLimit[SQL_LIMIT_LENGTH]) {
-		rc = SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		rc = SQL_TARANTOOL_ERROR;
 	} else {
 		assert((n & 0x7FFFFFFF) == n);
 		rc = sql_bind_zeroblob(pStmt, i, n);
diff --git a/src/box/sql/vdbemem.c b/src/box/sql/vdbemem.c
index 4bb82b8..8be2e69 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -936,7 +936,7 @@ sqlVdbeMemMove(Mem * pTo, Mem * pFrom)
  * size limit) then no memory allocation occurs.  If the string can be
  * stored without allocating memory, then it is.  If a memory allocation
  * is required to store the string, then value of pMem is unchanged.  In
- * either case, SQL_TOOBIG is returned.
+ * either case, error is returned.
  */
 int
 sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
@@ -980,7 +980,9 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 			nAlloc += 1; //SQL_UTF8
 		}
 		if (nByte > iLimit) {
-			return SQL_TOOBIG;
+			diag_set(ClientError, ER_SQL_EXECUTE, "string or blob "\
+				 "is too big");
+			return SQL_TARANTOOL_ERROR;
 		}
 		testcase(nAlloc == 0);
 		testcase(nAlloc == 31);
@@ -1004,7 +1006,9 @@ sqlVdbeMemSetStr(Mem * pMem,	/* Memory cell to set to string value */
 	pMem->flags = flags;
 
 	if (nByte > iLimit) {
-		return SQL_TOOBIG;
+		diag_set(ClientError, ER_SQL_EXECUTE, "string or blob is too "\
+			 "big");
+		return SQL_TARANTOOL_ERROR;
 	}
 
 	return 0;

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code
  2019-05-25 20:26     ` Konstantin Osipov
@ 2019-05-26 16:07       ` n.pettik
  0 siblings, 0 replies; 36+ messages in thread
From: n.pettik @ 2019-05-26 16:07 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Konstantin Osipov



> On 25 May 2019, at 23:26, Konstantin Osipov <kostja@tarantool.org> wrote:
> 
> * n.pettik <korablev@tarantool.org> [19/05/25 21:58]:
>> Taking into consideration assert above, it could
>> be replaced with assert(pBuilder->nRecValid == nEq - 1);
>> Btw, this function doesn’t seem to be called at all:
>> unreachable() assert doesn’t fire. I can assume that it is
>> connected with stat tables.
>> 
> 
> NIkita, could you please be more specific, is it an accept or a
> reject?

I’d say it is rather accept. This fix touches QP and now I
can’t validate it since statistics functionality is disabled.

> Can review comments be done in their own patches? 

Is it common practice for our work-flow? I mean I see
that as a rule fixe are done and squashed with main
patches before they are pushed.

> This is a big patch stack and I would like us to stop shuffling it
> around. If it does improve things, let it get in please and do the
> follow up work separately. Or at least let some of the good
> patches in.

I don’t mind if those patches which I didn’t comment out
will be pushed separately. There’re not so many concerns
from my side, so I guess whole patch-set will be ready soon.

^ permalink raw reply	[flat|nested] 36+ messages in thread

* [tarantool-patches] Re: [PATCH v1 00/21] sql: remove SQL error system.
  2019-05-25 16:36 ` [tarantool-patches] Re: [PATCH v1 00/21] sql: remove SQL error system n.pettik
@ 2019-05-28 11:12   ` Mergen Imeev
  0 siblings, 0 replies; 36+ messages in thread
From: Mergen Imeev @ 2019-05-28 11:12 UTC (permalink / raw)
  To: n.pettik; +Cc: tarantool-patches

On Sat, May 25, 2019 at 07:36:02PM +0300, n.pettik wrote:
> I’ve pushed couple of follow-ups:
> https://github.com/tarantool/tarantool/tree/np/gh-4074-follow-ups <https://github.com/tarantool/tarantool/tree/np/gh-4074-follow-ups>
> 
> Check them out please.
> 
Before I cherry-picked your patch, I made some changes to the
"sql: disable lookaside system" patch and resolved the conflicts
that appeared during the cherry-pick.

Diff for patch "sql: disable lookaside system":

diff --git a/src/box/sql/malloc.c b/src/box/sql/malloc.c
index 5c9c8d5..a7549db 100644
--- a/src/box/sql/malloc.c
+++ b/src/box/sql/malloc.c
@@ -681,35 +681,9 @@ sqlDbMallocRaw(sql * db, u64 n)
 void *
 sqlDbMallocRawNN(sql * db, u64 n)
 {
-#ifndef SQL_OMIT_LOOKASIDE
-	LookasideSlot *pBuf;
-	assert(db != 0);
-	assert(db->pnBytesFreed == 0);
-	if (db->lookaside.bDisable == 0) {
-		assert(db->mallocFailed == 0);
-		if (n > db->lookaside.sz) {
-			db->lookaside.anStat[1]++;
-		} else if ((pBuf = db->lookaside.pFree) == 0) {
-			db->lookaside.anStat[2]++;
-		} else {
-			db->lookaside.pFree = pBuf->pNext;
-			db->lookaside.nOut++;
-			db->lookaside.anStat[0]++;
-			if (db->lookaside.nOut > db->lookaside.mxOut) {
-				db->lookaside.mxOut = db->lookaside.nOut;
-			}
-			return (void *)pBuf;
-		}
-	} else if (db->mallocFailed) {
-		return 0;
-	}
-#else
-	assert(db != 0);
-	assert(db->pnBytesFreed == 0);
-	if (db->mallocFailed) {
-		return 0;
-	}
-#endif
+	assert(db != NULL && db->pnBytesFreed == NULL);
+	if (db->mallocFailed)
+		return NULL;
 	return dbMallocRawFinish(db, n);
 }

^ permalink raw reply	[flat|nested] 36+ messages in thread

end of thread, other threads:[~2019-05-28 11:12 UTC | newest]

Thread overview: 36+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove SQL error system imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 01/21] sql: remove unused functions of " imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 02/21] sql: disable lookaside system imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 03/21] sql: remove SQL_OK error/status code imeevma
2019-05-25 14:45   ` [tarantool-patches] " n.pettik
2019-05-26  9:39     ` Mergen Imeev
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 04/21] sql: remove SQL_PERM, SQL_WARNING, SQL_ABORT errcodes imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 05/21] sql: remove SQL_CANTOPEN errcode imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 06/21] sql: remove SQL_NOTFOUND error/status code imeevma
2019-05-25 14:58   ` [tarantool-patches] " n.pettik
2019-05-25 20:26     ` Konstantin Osipov
2019-05-26 16:07       ` n.pettik
2019-05-26  9:45     ` Mergen Imeev
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 07/21] sql: remove SQL_LOCKED errcode imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 08/21] sql: remove SQL_FULL errcode imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 09/21] sql: remove SQL_MISUSE errcode imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 10/21] sql: remove SQL_RANGE errcode imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 11/21] sql: remove SQL_SCHEMA errcode imeevma
2019-05-25 16:18   ` [tarantool-patches] " n.pettik
2019-05-26  9:46     ` Mergen Imeev
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 12/21] sql: remove SQL_TOOBIG errcode imeevma
2019-05-25 16:11   ` [tarantool-patches] " n.pettik
2019-05-26 12:12     ` Mergen Imeev
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 13/21] sql: remove SQL_BUSY errcode imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 14/21] sql: remove SQL_CONSTRAINT errcode imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 15/21] sql: remove SQL_ERROR errcode imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 16/21] sql: remove SQL_NOMEM errcode imeevma
2019-05-25 10:44 ` [tarantool-patches] [PATCH v1 17/21] sql: remove SQL_IOERR errcode imeevma
2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 18/21] sql: remove SQL_TARANTOOL_ERROR errcode imeevma
2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 19/21] sql: remove field errMask from struct sql imeevma
2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 20/21] sql: replace rc by is_aborted in struct Parse imeevma
2019-05-25 15:46   ` [tarantool-patches] " n.pettik
2019-05-26  9:49     ` Mergen Imeev
2019-05-25 10:45 ` [tarantool-patches] [PATCH v1 21/21] sql: remove sql_log() imeevma
2019-05-25 16:36 ` [tarantool-patches] Re: [PATCH v1 00/21] sql: remove SQL error system n.pettik
2019-05-28 11:12   ` Mergen Imeev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox