[tarantool-patches] [PATCH v1 19/28] sql: remove SQL_ERROR errcode

imeevma at tarantool.org imeevma at tarantool.org
Mon Jun 10 16:56:56 MSK 2019


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  |  4 ++--
 src/box/sql/vdbesort.c |  2 +-
 11 files changed, 24 insertions(+), 27 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 6e22153..a1bed97 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -4410,7 +4410,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
@@ -4431,7 +4431,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;
 	}
@@ -4620,14 +4620,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);
@@ -4665,7 +4665,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));
@@ -4688,7 +4688,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 ec4eb29..3aabcb2 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 57d6d60..c8ca8c4 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -1068,7 +1068,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 ad8684d..db8687b 100644
--- a/src/box/sql/vdbeapi.c
+++ b/src/box/sql/vdbeapi.c
@@ -708,7 +708,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 443bff0..933ad6f 100644
--- a/src/box/sql/vdbemem.c
+++ b/src/box/sql/vdbemem.c
@@ -562,7 +562,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);
@@ -587,7 +587,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





More information about the Tarantool-patches mailing list