Tarantool development patches archive
 help / color / mirror / Atom feed
From: imeevma@tarantool.org
To: korablev@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] [PATCH v1 01/21] sql: remove unused functions of SQL error system
Date: Sat, 25 May 2019 13:44:31 +0300	[thread overview]
Message-ID: <bda324551d4ef3a9f8dbe587a6f018d370e15825.1558780708.git.imeevma@gmail.com> (raw)
In-Reply-To: <cover.1558780708.git.imeevma@gmail.com>

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

  reply	other threads:[~2019-05-25 10:44 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-25 10:44 [tarantool-patches] [PATCH v1 00/21] sql: remove " imeevma
2019-05-25 10:44 ` imeevma [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bda324551d4ef3a9f8dbe587a6f018d370e15825.1558780708.git.imeevma@gmail.com \
    --to=imeevma@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v1 01/21] sql: remove unused functions of SQL error system' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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