diff --git a/src/box/sql.c b/src/box/sql.c index f2ef5b3025d552a7cc18767e3703b1bc71532693..ae92ba029550d4d7eb45f6620d93f6d3a9afd9ab 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 b6a01731b2b4fc4fd7a2178c844368b1ef6660cb..064f7cf4d8c84dbfb42ed915cf87a1cc6be8d94d 100644 --- a/src/box/sql/global.c +++ b/src/box/sql/global.c @@ -204,7 +204,6 @@ SQL_WSD struct sqlConfig sqlConfig = { 0, /* xVdbeBranch */ 0, /* pVbeBranchArg */ #endif - 0, /* xTestCallback */ 0, /* bLocaltimeFault */ 0x7ffffffe /* iOnceResetThreshold */ }; diff --git a/src/box/sql/legacy.c b/src/box/sql/legacy.c index d51999137173d9ec39c9f64b7f9d98bca9af6c78..1a3804e991ceef8cadc05950ecf15e6a444ebe73 100644 --- a/src/box/sql/legacy.c +++ b/src/box/sql/legacy.c @@ -64,8 +64,7 @@ sql_exec(sql * db, /* The database on which the SQL executes */ char **azCols = 0; /* Names of result columns */ int callbackIsInit; /* True if callback data is initialized */ - 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 0811b2e8099467f233f9755b8ecdadbfa4b17b85..9fdcddee3ab13d715fe1c033205f3a531adc9f69 100644 --- a/src/box/sql/main.c +++ b/src/box/sql/main.c @@ -289,40 +289,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 diff --git a/src/box/sql/prepare.c b/src/box/sql/prepare.c index e692be0a1f966e466e6885262e63587f531c4808..2b3ac29ae4eecfeb3cf0a33c817fd50d56e980bd 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 7051aa90c4ba36a6ff1fe4ddb4abede069c5b70a..ef0c56636e256b5f925ef1169dcaf5013646ebfe 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2727,7 +2727,6 @@ struct sqlConfig { void (*xVdbeBranch) (void *, int iSrcLine, u8 eThis, u8 eMx); /* Callback */ void *pVdbeBranchArg; /* 1st argument */ #endif - int (*xTestCallback) (int); /* Invoked by sqlFaultSim() */ int bLocaltimeFault; /* True to fail localtime() calls */ int iOnceResetThreshold; /* When to reset OP_Once counters */ }; @@ -3164,8 +3163,6 @@ int vdbe_emit_open_cursor(struct Parse *parse, int cursor, int index_id, struct space *space); -int sqlFaultSim(int); - /** * The parser calls this routine in order to create a new VIEW. * @@ -3722,8 +3719,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. @@ -4246,8 +4241,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 f688a026938b271f170e2b98e536007ba9d57309..375a8ccb139041faf97259c65fefc34d896058b6 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 3de157e7310d77945ee580cc9782ce9c56db4d94..92f6f0fa920cfcba1763b3c0ff4244b80accae46 100644 --- a/src/box/sql/util.c +++ b/src/box/sql/util.c @@ -43,24 +43,6 @@ #include <unicode/ucasemap.h> #include "errinj.h" -/* - * 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. - */ -int - sqlFaultSim(int iTest) -{ - int (*xCallback) (int) = sqlGlobalConfig.xTestCallback; - return xCallback ? xCallback(iTest) : SQL_OK; -} - /* * Return true if the floating point value is Not a Number (NaN). * @@ -1044,67 +1026,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. diff --git a/src/box/sql/vdbeapi.c b/src/box/sql/vdbeapi.c index 7d519ce3d65d516bd3e194f84d073f63319d40d4..a4e9d27b31d3ee6045f7a8d762699ec9884df89a 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); - } -} - /* * Invoke the profile callback. This routine is only called if we already * know that the profile callback is defined and needs to be invoked. @@ -116,8 +87,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); @@ -521,9 +491,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) { @@ -953,9 +921,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 3d9d1663c6217f1196fddbd64fd67bc7dedab550..4034a3495ae027f4194f31126f75878a7d0531d1 100644 --- a/src/box/sql/vdbesort.c +++ b/src/box/sql/vdbesort.c @@ -643,8 +643,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; @@ -922,8 +920,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; @@ -1040,8 +1037,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 | @@ -1660,8 +1655,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;