[tarantool-patches] [PATCH v1 3/3] sql: remove unused functions from main.c

imeevma at tarantool.org imeevma at tarantool.org
Tue Apr 9 20:17:06 MSK 2019


These functions unused and should be removed.

Needed for #4074
---
 src/box/sql/build.c  |   2 -
 src/box/sql/global.c |   3 +-
 src/box/sql/main.c   | 956 +--------------------------------------------------
 src/box/sql/random.c |   3 -
 src/box/sql/select.c |   2 -
 src/box/sql/sqlInt.h |  40 +--
 src/box/sql/vdbe.c   |  12 -
 7 files changed, 3 insertions(+), 1015 deletions(-)

diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index a06ba3e..3442442 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -327,8 +327,6 @@ sqlStartTable(Parse *pParse, Token *pName, int noErr)
 		if (!noErr) {
 			diag_set(ClientError, ER_SPACE_EXISTS, zName);
 			pParse->is_aborted = true;
-		} else {
-			assert(!db->init.busy || CORRUPT_DB);
 		}
 		goto cleanup;
 	}
diff --git a/src/box/sql/global.c b/src/box/sql/global.c
index f48cb8c..9af671a 100644
--- a/src/box/sql/global.c
+++ b/src/box/sql/global.c
@@ -228,8 +228,7 @@ FuncDefHash sqlBuiltinFunctions;
  * During testing, it is often desirable to move the pending byte to
  * a different position in the file.  This allows code that has to
  * deal with the pending byte to run on files that are much smaller
- * than 1 GiB.  The sql_test_control() interface can be used to
- * move the pending byte.
+ * than 1 GiB.
  *
  * IMPORTANT:  Changing the pending byte to any value other than
  * 0x40000000 results in an incompatible database file format!
diff --git a/src/box/sql/main.c b/src/box/sql/main.c
index 9cc6536..fe1135a 100644
--- a/src/box/sql/main.c
+++ b/src/box/sql/main.c
@@ -75,8 +75,7 @@ char *sql_data_directory = 0;
  * and VFS subsystems prior to doing any serious work with
  * sql.
  *
- * This routine is a no-op except on its very first call for the process,
- * or for the first call after a call to sql_shutdown.
+ * This routine is a no-op except on its very first call for the process.
  *
  * The first thread to call this routine runs the initialization to
  * completion.  If subsequent threads call this routine before the first
@@ -175,177 +174,6 @@ sql_initialize(void)
 }
 
 /*
- * Undo the effects of sql_initialize().  Must not be called while
- * there are outstanding database connections or memory allocations or
- * while any part of sql is otherwise in use in any thread.  This
- * routine is not threadsafe.  But it is safe to invoke this routine
- * on when sql is already shut down.  If sql is already shut down
- * when this routine is invoked, then this routine is a harmless no-op.
- */
-int
-sql_shutdown(void)
-{
-	if (sqlGlobalConfig.isInit) {
-#ifdef SQL_EXTRA_SHUTDOWN
-		void SQL_EXTRA_SHUTDOWN(void);
-		SQL_EXTRA_SHUTDOWN();
-#endif
-		sql_os_end();
-		sqlGlobalConfig.isInit = 0;
-	}
-	if (sqlGlobalConfig.isMallocInit) {
-		sqlMallocEnd();
-		sqlGlobalConfig.isMallocInit = 0;
-
-#ifndef SQL_OMIT_SHUTDOWN_DIRECTORIES
-		/* The heap subsystem has now been shutdown and these values are supposed
-		 * to be NULL or point to memory that was obtained from sql_malloc(),
-		 * which would rely on that heap subsystem; therefore, make sure these
-		 * values cannot refer to heap memory that was just invalidated when the
-		 * heap subsystem was shutdown.  This is only done if the current call to
-		 * this function resulted in the heap subsystem actually being shutdown.
-		 */
-		sql_data_directory = 0;
-		sql_temp_directory = 0;
-#endif
-	}
-
-	return SQL_OK;
-}
-
-/*
- * This API allows applications to modify the global configuration of
- * the sql library at run-time.
- *
- * This routine should only be called when there are no outstanding
- * database connections or memory allocations.  This routine is not
- * threadsafe.  Failure to heed these warnings can lead to unpredictable
- * behavior.
- */
-int
-sql_config(int op, ...)
-{
-	va_list ap;
-	int rc = SQL_OK;
-
-	/* sql_config() shall return SQL_MISUSE if it is invoked while
-	 * the sql library is in use.
-	 */
-	if (sqlGlobalConfig.isInit)
-		return SQL_MISUSE;
-
-	va_start(ap, op);
-	switch (op) {
-	case SQL_CONFIG_MEMSTATUS:{
-			/* EVIDENCE-OF: R-61275-35157 The SQL_CONFIG_MEMSTATUS option takes
-			 * single argument of type int, interpreted as a boolean, which enables
-			 * or disables the collection of memory allocation statistics.
-			 */
-			sqlGlobalConfig.bMemstat = va_arg(ap, int);
-			break;
-		}
-	case SQL_CONFIG_SCRATCH:{
-			/* EVIDENCE-OF: R-08404-60887 There are three arguments to
-			 * SQL_CONFIG_SCRATCH: A pointer an 8-byte aligned memory buffer from
-			 * which the scratch allocations will be drawn, the size of each scratch
-			 * allocation (sz), and the maximum number of scratch allocations (N).
-			 */
-			sqlGlobalConfig.pScratch = va_arg(ap, void *);
-			sqlGlobalConfig.szScratch = va_arg(ap, int);
-			sqlGlobalConfig.nScratch = va_arg(ap, int);
-			break;
-		}
-
-	case SQL_CONFIG_LOOKASIDE:{
-			sqlGlobalConfig.szLookaside = va_arg(ap, int);
-			sqlGlobalConfig.nLookaside = va_arg(ap, int);
-			break;
-		}
-
-		/* Record a pointer to the logger function and its first argument.
-		 * The default is NULL.  Logging is disabled if the function pointer is
-		 * NULL.
-		 */
-	case SQL_CONFIG_LOG:{
-			typedef void (*LOGFUNC_t) (void *, int, const char *);
-			sqlGlobalConfig.xLog = va_arg(ap, LOGFUNC_t);
-			sqlGlobalConfig.pLogArg = va_arg(ap, void *);
-			break;
-		}
-
-		/* EVIDENCE-OF: R-55548-33817 The compile-time setting for URI filenames
-		 * can be changed at start-time using the
-		 * sql_config(SQL_CONFIG_URI,1) or
-		 * sql_config(SQL_CONFIG_URI,0) configuration calls.
-		 */
-	case SQL_CONFIG_URI:{
-			/* EVIDENCE-OF: R-25451-61125 The SQL_CONFIG_URI option takes a single
-			 * argument of type int. If non-zero, then URI handling is globally
-			 * enabled. If the parameter is zero, then URI handling is globally
-			 * disabled.
-			 */
-			sqlGlobalConfig.bOpenUri = va_arg(ap, int);
-			break;
-		}
-
-	case SQL_CONFIG_COVERING_INDEX_SCAN:{
-			/* EVIDENCE-OF: R-36592-02772 The SQL_CONFIG_COVERING_INDEX_SCAN
-			 * option takes a single integer argument which is interpreted as a
-			 * boolean in order to enable or disable the use of covering indices for
-			 * full table scans in the query optimizer.
-			 */
-			sqlGlobalConfig.bUseCis = va_arg(ap, int);
-			break;
-		}
-
-	case SQL_CONFIG_MMAP_SIZE:{
-			/* EVIDENCE-OF: R-58063-38258 SQL_CONFIG_MMAP_SIZE takes two 64-bit
-			 * integer (sql_int64) values that are the default mmap size limit
-			 * (the default setting for PRAGMA mmap_size) and the maximum allowed
-			 * mmap size limit.
-			 */
-			sql_int64 szMmap = va_arg(ap, sql_int64);
-			sql_int64 mxMmap = va_arg(ap, sql_int64);
-			/* EVIDENCE-OF: R-53367-43190 If either argument to this option is
-			 * negative, then that argument is changed to its compile-time default.
-			 *
-			 * EVIDENCE-OF: R-34993-45031 The maximum allowed mmap size will be
-			 * silently truncated if necessary so that it does not exceed the
-			 * compile-time maximum mmap size set by the SQL_MAX_MMAP_SIZE
-			 * compile-time option.
-			 */
-			if (mxMmap < 0 || mxMmap > SQL_MAX_MMAP_SIZE) {
-				mxMmap = SQL_MAX_MMAP_SIZE;
-			}
-			if (szMmap < 0)
-				szMmap = SQL_DEFAULT_MMAP_SIZE;
-			if (szMmap > mxMmap)
-				szMmap = mxMmap;
-			sqlGlobalConfig.mxMmap = mxMmap;
-			sqlGlobalConfig.szMmap = szMmap;
-			break;
-		}
-
-	case SQL_CONFIG_PMASZ:{
-			sqlGlobalConfig.szPma = va_arg(ap, unsigned int);
-			break;
-		}
-
-	case SQL_CONFIG_STMTJRNL_SPILL:{
-			sqlGlobalConfig.nStmtSpill = va_arg(ap, int);
-			break;
-		}
-
-	default:{
-			rc = SQL_ERROR;
-			break;
-		}
-	}
-	va_end(ap);
-	return rc;
-}
-
-/*
  * Set up the lookaside buffers for a database connection.
  * Return SQL_OK on success.
  * If lookaside is already active, return SQL_BUSY.
@@ -567,37 +395,6 @@ sqlErrStr(int rc)
 	return zErr;
 }
 
-#ifndef SQL_OMIT_PROGRESS_CALLBACK
-/*
- * This routine sets the progress callback for an Sqlite database to the
- * given callback function with the given argument. The progress callback will
- * be invoked every nOps opcodes.
- */
-void
-sql_progress_handler(sql * db,
-			 int nOps, int (*xProgress) (void *), void *pArg)
-{
-	if (nOps > 0) {
-		db->xProgress = xProgress;
-		db->nProgressOps = (unsigned)nOps;
-		db->pProgressArg = pArg;
-	} else {
-		db->xProgress = 0;
-		db->nProgressOps = 0;
-		db->pProgressArg = 0;
-	}
-}
-#endif
-
-/*
- * Cause any pending operation to stop at its earliest opportunity.
- */
-void
-sql_interrupt(sql * db)
-{
-	db->u1.isInterrupted = 1;
-}
-
 /*
  * This function is exactly the same as sql_create_function(), except
  * that it is designed to be called by internal code. The difference is
@@ -738,78 +535,6 @@ sql_trace_v2(sql * db,		/* Trace this connection */
 #endif				/* SQL_OMIT_TRACE */
 
 /*
- * Register a function to be invoked when a transaction commits.
- * If the invoked function returns non-zero, then the commit becomes a
- * rollback.
- */
-void *
-sql_commit_hook(sql * db,	/* Attach the hook to this database */
-		    int (*xCallback) (void *),	/* Function to invoke on each commit */
-		    void *pArg)		/* Argument to the function */
-{
-	void *pOld;
-
-	pOld = db->pCommitArg;
-	db->xCommitCallback = xCallback;
-	db->pCommitArg = pArg;
-	return pOld;
-}
-
-/*
- * Register a callback to be invoked each time a row is updated,
- * inserted or deleted using this database connection.
- */
-void *
-sql_update_hook(sql * db,	/* Attach the hook to this database */
-		    void (*xCallback) (void *, int, char const *,
-				       char const *, sql_int64),
-		    void *pArg)		/* Argument to the function */
-{
-	void *pRet;
-
-	pRet = db->pUpdateArg;
-	db->xUpdateCallback = xCallback;
-	db->pUpdateArg = pArg;
-	return pRet;
-}
-
-/*
- * Register a callback to be invoked each time a transaction is rolled
- * back by this database connection.
- */
-void *
-sql_rollback_hook(sql * db,	/* Attach the hook to this database */
-		      void (*xCallback) (void *),	/* Callback function */
-		      void *pArg)	/* Argument to the function */
-{
-	void *pRet;
-
-	pRet = db->pRollbackArg;
-	db->xRollbackCallback = xCallback;
-	db->pRollbackArg = pArg;
-	return pRet;
-}
-
-/*
- * Configure an sql_wal_hook() callback to automatically checkpoint
- * a database after committing a transaction if there are nFrame or
- * more frames in the log file. Passing zero or a negative value as the
- * nFrame parameter disables automatic checkpoints entirely.
- *
- * The callback registered by this function replaces any existing callback
- * registered using sql_wal_hook(). Likewise, registering a callback
- * using sql_wal_hook() disables the automatic checkpoint mechanism
- * configured by this function.
- */
-int
-sql_wal_autocheckpoint(sql * db, int nFrame)
-{
-	UNUSED_PARAMETER(db);
-	UNUSED_PARAMETER(nFrame);
-	return SQL_OK;
-}
-
-/*
  * This function returns true if main-memory should be used instead of
  * a temporary file for transient pager files and statement journals.
  * The value returned depends on the value of db->temp_store (runtime
@@ -848,37 +573,6 @@ sqlTempInMemory(const sql * db)
 }
 
 /*
- * Return UTF-8 encoded English language explanation of the most recent
- * error.
- */
-const char *
-sql_errmsg(sql * db)
-{
-	const char *z;
-	if (!db) {
-		return sqlErrStr(SQL_NOMEM);
-	}
-	if (!sqlSafetyCheckSickOrOk(db)) {
-		return sqlErrStr(SQL_MISUSE);
-	}
-	if (db->mallocFailed) {
-		z = sqlErrStr(SQL_NOMEM);
-	} else {
-		testcase(db->pErr == 0);
-		assert(!db->mallocFailed);
-		if (db->errCode != SQL_TARANTOOL_ERROR) {
-			z = (char *)sql_value_text(db->pErr);
-			if (z == NULL)
-				z = sqlErrStr(db->errCode);
-		} else {
-			z = diag_last_error(diag_get())->errmsg;
-		}
-		assert(z != NULL);
-	}
-	return z;
-}
-
-/*
  * Return the most recent error code generated by an sql routine. If NULL is
  * passed to this function, we assume a malloc() failed during sql_open().
  */
@@ -894,35 +588,6 @@ sql_errcode(sql * db)
 	return db->errCode & db->errMask;
 }
 
-int
-sql_extended_errcode(sql * db)
-{
-	if (db && !sqlSafetyCheckSickOrOk(db)) {
-		return SQL_MISUSE;
-	}
-	if (!db || db->mallocFailed) {
-		return SQL_NOMEM;
-	}
-	return db->errCode;
-}
-
-int
-sql_system_errno(sql * db)
-{
-	return db ? db->iSysErrno : 0;
-}
-
-/*
- * Return a string that describes the kind of error specified in the
- * argument.  For now, this simply calls the internal sqlErrStr()
- * function.
- */
-const char *
-sql_errstr(int rc)
-{
-	return sqlErrStr(rc);
-}
-
 /*
  * This array defines hard upper bounds on limit values.  The
  * initializer must be kept in sync with the SQL_LIMIT_*
@@ -1030,297 +695,6 @@ sql_limit(sql * db, int limitId, int newLimit)
 	return oldLimit;	/* IMP: R-53341-35419 */
 }
 
-/*
- * This function is used to parse both URIs and non-URI filenames passed by the
- * user to API functions sql_open() or sql_open_v2(), and for database
- * URIs specified as part of ATTACH statements.
- *
- * The first argument to this function is the name of the VFS to use (or
- * a NULL to signify the default VFS) if the URI does not contain a "vfs=xxx"
- * query parameter. The second argument contains the URI (or non-URI filename)
- * itself. When this function is called the *pFlags variable should contain
- * the default flags to open the database handle with. The value stored in
- * *pFlags may be updated before returning if the URI filename contains
- * "cache=xxx" or "mode=xxx" query parameters.
- *
- * If successful, SQL_OK is returned. In this case *ppVfs is set to point to
- * the VFS that should be used to open the database file. *pzFile is set to
- * point to a buffer containing the name of the file to open. It is the
- * responsibility of the caller to eventually call sql_free() to release
- * this buffer.
- *
- * If an error occurs, then an sql error code is returned and *pzErrMsg
- * may be set to point to a buffer containing an English language error
- * message. It is the responsibility of the caller to eventually release
- * this buffer by calling sql_free().
- */
-int
-sqlParseUri(const char *zDefaultVfs,	/* VFS to use if no "vfs=xxx" query option */
-		const char *zUri,		/* Nul-terminated URI to parse */
-		unsigned int *pFlags,		/* IN/OUT: SQL_OPEN_XXX flags */
-		sql_vfs ** ppVfs,		/* OUT: VFS to use */
-		char **pzFile,			/* OUT: Filename component of URI */
-		char **pzErrMsg)		/* OUT: Error message (if rc!=SQL_OK) */
-{
-	int rc = SQL_OK;
-	unsigned int flags = *pFlags;
-	const char *zVfs = zDefaultVfs;
-	char *zFile;
-	char c;
-	int nUri = sqlStrlen30(zUri);
-
-	assert(*pzErrMsg == 0);
-
-	if (((flags & SQL_OPEN_URI)	/* IMP: R-48725-32206 */
-	     ||sqlGlobalConfig.bOpenUri)	/* IMP: R-51689-46548 */
-	    &&nUri >= 5 && memcmp(zUri, "file:", 5) == 0	/* IMP: R-57884-37496 */
-	    ) {
-		char *zOpt;
-		int eState;	/* Parser state when parsing URI */
-		int iIn;	/* Input character index */
-		int iOut = 0;	/* Output character index */
-		u64 nByte = nUri + 2;	/* Bytes of space to allocate */
-
-		/* Make sure the SQL_OPEN_URI flag is set to indicate to the VFS xOpen
-		 * method that there may be extra parameters following the file-name.
-		 */
-		flags |= SQL_OPEN_URI;
-
-		for (iIn = 0; iIn < nUri; iIn++)
-			nByte += (zUri[iIn] == '&');
-		zFile = sql_malloc64(nByte);
-		if (!zFile)
-			return SQL_NOMEM;
-
-		iIn = 5;
-#ifdef SQL_ALLOW_URI_AUTHORITY
-		if (strncmp(zUri + 5, "///", 3) == 0) {
-			iIn = 7;
-			/* The following condition causes URIs with five leading / characters
-			 * like file://///host/path to be converted into UNCs like //host/path.
-			 * The correct URI for that UNC has only two or four leading / characters
-			 * file://host/path or file:////host/path.  But 5 leading slashes is a
-			 * common error, we are told, so we handle it as a special case.
-			 */
-			if (strncmp(zUri + 7, "///", 3) == 0) {
-				iIn++;
-			}
-		} else if (strncmp(zUri + 5, "//localhost/", 12) == 0) {
-			iIn = 16;
-		}
-#else
-		/* Discard the scheme and authority segments of the URI. */
-		if (zUri[5] == '/' && zUri[6] == '/') {
-			iIn = 7;
-			while (zUri[iIn] && zUri[iIn] != '/')
-				iIn++;
-			if (iIn != 7
-			    && (iIn != 16
-				|| memcmp("localhost", &zUri[7], 9))) {
-				*pzErrMsg =
-				    sql_mprintf
-				    ("invalid uri authority: %.*s", iIn - 7,
-				     &zUri[7]);
-				rc = SQL_ERROR;
-				goto parse_uri_out;
-			}
-		}
-#endif
-
-		/* Copy the filename and any query parameters into the zFile buffer.
-		 * Decode %HH escape codes along the way.
-		 *
-		 * Within this loop, variable eState may be set to 0, 1 or 2, depending
-		 * on the parsing context. As follows:
-		 *
-		 *   0: Parsing file-name.
-		 *   1: Parsing name section of a name=value query parameter.
-		 *   2: Parsing value section of a name=value query parameter.
-		 */
-		eState = 0;
-		while ((c = zUri[iIn]) != 0 && c != '#') {
-			iIn++;
-			if (c == '%' && sqlIsxdigit(zUri[iIn])
-			    && sqlIsxdigit(zUri[iIn + 1])
-			    ) {
-				int octet = (sqlHexToInt(zUri[iIn++]) << 4);
-				octet += sqlHexToInt(zUri[iIn++]);
-
-				assert(octet >= 0 && octet < 256);
-				if (octet == 0) {
-#ifndef SQL_ENABLE_URI_00_ERROR
-					/* This branch is taken when "%00" appears within the URI. In this
-					 * case we ignore all text in the remainder of the path, name or
-					 * value currently being parsed. So ignore the current character
-					 * and skip to the next "?", "=" or "&", as appropriate.
-					 */
-					while ((c = zUri[iIn]) != 0 && c != '#'
-					       && (eState != 0 || c != '?')
-					       && (eState != 1
-						   || (c != '=' && c != '&'))
-					       && (eState != 2 || c != '&')
-					    ) {
-						iIn++;
-					}
-					continue;
-#else
-					/* If ENABLE_URI_00_ERROR is defined, "%00" in a URI is an error. */
-					*pzErrMsg =
-					    sql_mprintf
-					    ("unexpected %%00 in uri");
-					rc = SQL_ERROR;
-					goto parse_uri_out;
-#endif
-				}
-				c = octet;
-			} else if (eState == 1 && (c == '&' || c == '=')) {
-				if (zFile[iOut - 1] == 0) {
-					/* An empty option name. Ignore this option altogether. */
-					while (zUri[iIn] && zUri[iIn] != '#'
-					       && zUri[iIn - 1] != '&')
-						iIn++;
-					continue;
-				}
-				if (c == '&') {
-					zFile[iOut++] = '\0';
-				} else {
-					eState = 2;
-				}
-				c = 0;
-			} else if ((eState == 0 && c == '?')
-				   || (eState == 2 && c == '&')) {
-				c = 0;
-				eState = 1;
-			}
-			zFile[iOut++] = c;
-		}
-		if (eState == 1)
-			zFile[iOut++] = '\0';
-		zFile[iOut++] = '\0';
-		zFile[iOut++] = '\0';
-
-		/* Check if there were any options specified that should be interpreted
-		 * here. Options that are interpreted here include "vfs" and those that
-		 * correspond to flags that may be passed to the sql_open_v2()
-		 * method.
-		 */
-		zOpt = &zFile[sqlStrlen30(zFile) + 1];
-		while (zOpt[0]) {
-			int nOpt = sqlStrlen30(zOpt);
-			char *zVal = &zOpt[nOpt + 1];
-			unsigned int nVal = sqlStrlen30(zVal);
-
-			if (nOpt == 3 && memcmp("vfs", zOpt, 3) == 0) {
-				zVfs = zVal;
-			} else {
-				struct OpenMode {
-					const char *z;
-					int mode;
-				} *aMode = 0;
-				char *zModeType = 0;
-				int mask = 0;
-				int limit = 0;
-
-				if (nOpt == 5 && memcmp("cache", zOpt, 5) == 0) {
-					static struct OpenMode aCacheMode[] = {
-						{"shared",
-						 SQL_OPEN_SHAREDCACHE},
-						{"private",
-						 SQL_OPEN_PRIVATECACHE},
-						{0, 0}
-					};
-
-					mask =
-					    SQL_OPEN_SHAREDCACHE |
-					    SQL_OPEN_PRIVATECACHE;
-					aMode = aCacheMode;
-					limit = mask;
-					zModeType = "cache";
-				}
-				if (nOpt == 4 && memcmp("mode", zOpt, 4) == 0) {
-					static struct OpenMode aOpenMode[] = {
-						{"ro", SQL_OPEN_READONLY},
-						{"rw", SQL_OPEN_READWRITE},
-						{"rwc",
-						 SQL_OPEN_READWRITE |
-						 SQL_OPEN_CREATE},
-						{"memory", SQL_OPEN_MEMORY},
-						{0, 0}
-					};
-
-					mask =
-					    SQL_OPEN_READONLY |
-					    SQL_OPEN_READWRITE |
-					    SQL_OPEN_CREATE |
-					    SQL_OPEN_MEMORY;
-					aMode = aOpenMode;
-					limit = mask & flags;
-					zModeType = "access";
-				}
-
-				if (aMode) {
-					int i;
-					int mode = 0;
-					for (i = 0; aMode[i].z; i++) {
-						const char *z = aMode[i].z;
-						if (nVal == sqlStrlen30(z)
-						    && 0 == memcmp(zVal, z,
-								   nVal)) {
-							mode = aMode[i].mode;
-							break;
-						}
-					}
-					if (mode == 0) {
-						*pzErrMsg =
-						    sql_mprintf
-						    ("no such %s mode: %s",
-						     zModeType, zVal);
-						rc = SQL_ERROR;
-						goto parse_uri_out;
-					}
-					if ((mode & ~SQL_OPEN_MEMORY) >
-					    limit) {
-						*pzErrMsg =
-						    sql_mprintf
-						    ("%s mode not allowed: %s",
-						     zModeType, zVal);
-						rc = SQL_PERM;
-						goto parse_uri_out;
-					}
-					flags = (flags & ~mask) | mode;
-				}
-			}
-
-			zOpt = &zVal[nVal + 1];
-		}
-
-	} else {
-		zFile = sql_malloc64(nUri + 2);
-		if (!zFile)
-			return SQL_NOMEM;
-		if (nUri) {
-			memcpy(zFile, zUri, nUri);
-		}
-		zFile[nUri] = '\0';
-		zFile[nUri + 1] = '\0';
-		flags &= ~SQL_OPEN_URI;
-	}
-
-	*ppVfs = sql_vfs_find(zVfs);
-	if (*ppVfs == 0) {
-		*pzErrMsg = sql_mprintf("no such vfs: %s", zVfs);
-		rc = SQL_ERROR;
-	}
- parse_uri_out:
-	if (rc != SQL_OK) {
-		sql_free(zFile);
-		zFile = 0;
-	}
-	*pFlags = flags;
-	*pzFile = zFile;
-	return rc;
-}
-
 /**
  * This routine does the work of initialization of main
  * SQL connection instance.
@@ -1389,308 +763,6 @@ opendb_out:
 }
 
 /*
- * Enable or disable the extended result codes.
- */
-int
-sql_extended_result_codes(sql * db, int onoff)
-{
-	db->errMask = onoff ? 0xffffffff : 0xff;
-	return SQL_OK;
-}
-
-/*
- * Interface to the testing logic.
- */
-int
-sql_test_control(int op, ...)
-{
-	int rc = 0;
-#ifdef SQL_UNTESTABLE
-	UNUSED_PARAMETER(op);
-#else
-	va_list ap;
-	va_start(ap, op);
-	switch (op) {
-
-		/*
-		 * Save the current state of the PRNG.
-		 */
-	case SQL_TESTCTRL_PRNG_SAVE:{
-			sqlPrngSaveState();
-			break;
-		}
-
-		/*
-		 * Restore the state of the PRNG to the last state saved using
-		 * PRNG_SAVE.  If PRNG_SAVE has never before been called, then
-		 * this verb acts like PRNG_RESET.
-		 */
-	case SQL_TESTCTRL_PRNG_RESTORE:{
-			sqlPrngRestoreState();
-			break;
-		}
-
-		/*
-		 * Reset the PRNG back to its uninitialized state.  The next call
-		 * to sql_randomness() will reseed the PRNG using a single call
-		 * to the xRandomness method of the default VFS.
-		 */
-	case SQL_TESTCTRL_PRNG_RESET:{
-			sql_randomness(0, 0);
-			break;
-		}
-
-		/*
-		 *  sql_test_control(FAULT_INSTALL, xCallback)
-		 *
-		 * Arrange to invoke xCallback() whenever sqlFaultSim() is called,
-		 * if xCallback is not NULL.
-		 *
-		 * As a test of the fault simulator mechanism itself, sqlFaultSim(0)
-		 * is called immediately after installing the new callback and the return
-		 * value from sqlFaultSim(0) becomes the return from
-		 * sql_test_control().
-		 */
-	case SQL_TESTCTRL_FAULT_INSTALL:{
-			typedef int (*TESTCALLBACKFUNC_t) (int);
-			sqlGlobalConfig.xTestCallback =
-			    va_arg(ap, TESTCALLBACKFUNC_t);
-			rc = sqlFaultSim(0);
-			break;
-		}
-
-		/*
-		 *  sql_test_control(BENIGN_MALLOC_HOOKS, xBegin, xEnd)
-		 *
-		 * Register hooks to call to indicate which malloc() failures
-		 * are benign.
-		 */
-	case SQL_TESTCTRL_BENIGN_MALLOC_HOOKS:{
-			typedef void (*void_function) (void);
-			void_function xBenignBegin;
-			void_function xBenignEnd;
-			xBenignBegin = va_arg(ap, void_function);
-			xBenignEnd = va_arg(ap, void_function);
-			sqlBenignMallocHooks(xBenignBegin, xBenignEnd);
-			break;
-		}
-
-		/*
-		 *  sql_test_control(SQL_TESTCTRL_PENDING_BYTE, unsigned int X)
-		 *
-		 * Set the PENDING byte to the value in the argument, if X>0.
-		 * Make no changes if X==0.  Return the value of the pending byte
-		 * as it existing before this routine was called.
-		 *
-		 * IMPORTANT:  Changing the PENDING byte from 0x40000000 results in
-		 * an incompatible database file format.  Changing the PENDING byte
-		 * while any database connection is open results in undefined and
-		 * deleterious behavior.
-		 */
-	case SQL_TESTCTRL_PENDING_BYTE:{
-			rc = PENDING_BYTE;
-			{
-				unsigned int newVal = va_arg(ap, unsigned int);
-				if (newVal)
-					sqlPendingByte = newVal;
-			}
-			break;
-		}
-
-		/*
-		 *  sql_test_control(SQL_TESTCTRL_ASSERT, int X)
-		 *
-		 * This action provides a run-time test to see whether or not
-		 * assert() was enabled at compile-time.  If X is true and assert()
-		 * is enabled, then the return value is true.  If X is true and
-		 * assert() is disabled, then the return value is zero.  If X is
-		 * false and assert() is enabled, then the assertion fires and the
-		 * process aborts.  If X is false and assert() is disabled, then the
-		 * return value is zero.
-		 */
-	case SQL_TESTCTRL_ASSERT:{
-			volatile int x = 0;
-			assert( /*side-effects-ok */ (x = va_arg(ap, int)) !=
-			       0);
-			rc = x;
-			break;
-		}
-
-		/*
-		 *  sql_test_control(SQL_TESTCTRL_ALWAYS, int X)
-		 *
-		 * This action provides a run-time test to see how the ALWAYS and
-		 * NEVER macros were defined at compile-time.
-		 *
-		 * The return value is ALWAYS(X).
-		 *
-		 * The recommended test is X==2.  If the return value is 2, that means
-		 * ALWAYS() and NEVER() are both no-op pass-through macros, which is the
-		 * default setting.  If the return value is 1, then ALWAYS() is either
-		 * hard-coded to true or else it asserts if its argument is false.
-		 * The first behavior (hard-coded to true) is the case if
-		 * SQL_TESTCTRL_ASSERT shows that assert() is disabled and the second
-		 * behavior (assert if the argument to ALWAYS() is false) is the case if
-		 * SQL_TESTCTRL_ASSERT shows that assert() is enabled.
-		 *
-		 * The run-time test procedure might look something like this:
-		 *
-		 *    if( sql_test_control(SQL_TESTCTRL_ALWAYS, 2)==2 ){
-		 *      // ALWAYS() and NEVER() are no-op pass-through macros
-		 *    }else if( sql_test_control(SQL_TESTCTRL_ASSERT, 1) ){
-		 *      // ALWAYS(x) asserts that x is true. NEVER(x) asserts x is false.
-		 *    }else{
-		 *      // ALWAYS(x) is a constant 1.  NEVER(x) is a constant 0.
-		 *    }
-		 */
-	case SQL_TESTCTRL_ALWAYS:{
-			int x = va_arg(ap, int);
-			rc = ALWAYS(x);
-			break;
-		}
-
-		/*
-		 *   sql_test_control(SQL_TESTCTRL_BYTEORDER);
-		 *
-		 * The integer returned reveals the byte-order of the computer on which
-		 * sql is running:
-		 *
-		 *       1     big-endian,    determined at run-time
-		 *      10     little-endian, determined at run-time
-		 *  432101     big-endian,    determined at compile-time
-		 *  123410     little-endian, determined at compile-time
-		 */
-	case SQL_TESTCTRL_BYTEORDER:{
-			rc = SQL_BYTEORDER * 100 + SQL_LITTLEENDIAN * 10 +
-			    SQL_BIGENDIAN;
-			break;
-		}
-
-		/*  sql_test_control(SQL_TESTCTRL_OPTIMIZATIONS, sql *db, int N)
-		 *
-		 * Enable or disable various optimizations for testing purposes.  The
-		 * argument N is a bitmask of optimizations to be disabled.  For normal
-		 * operation N should be 0.  The idea is that a test program (like the
-		 * SQL Logic Test or SLT test module) can run the same SQL multiple times
-		 * with various optimizations disabled to verify that the same answer
-		 * is obtained in every case.
-		 */
-	case SQL_TESTCTRL_OPTIMIZATIONS:{
-			sql *db = va_arg(ap, sql *);
-			db->dbOptFlags = (u16) (va_arg(ap, int) & 0xffff);
-			break;
-		}
-
-#ifdef SQL_N_KEYWORD
-		/* sql_test_control(SQL_TESTCTRL_ISKEYWORD, const char *zWord)
-		 *
-		 * If zWord is a keyword recognized by the parser, then return the
-		 * number of keywords.  Or if zWord is not a keyword, return 0.
-		 *
-		 * This test feature is only available in the amalgamation since
-		 * the SQL_N_KEYWORD macro is not defined in this file if sql
-		 * is built using separate source files.
-		 */
-	case SQL_TESTCTRL_ISKEYWORD:{
-			const char *zWord = va_arg(ap, const char *);
-			int n = sqlStrlen30(zWord);
-			rc = (sqlKeywordCode((u8 *) zWord, n) !=
-			      TK_ID) ? SQL_N_KEYWORD : 0;
-			break;
-		}
-#endif
-
-		/* sql_test_control(SQL_TESTCTRL_SCRATCHMALLOC, sz, &pNew, pFree);
-		 *
-		 * Pass pFree into sqlScratchFree().
-		 * If sz>0 then allocate a scratch buffer into pNew.
-		 */
-	case SQL_TESTCTRL_SCRATCHMALLOC:{
-			void *pFree, **ppNew;
-			int sz;
-			sz = va_arg(ap, int);
-			ppNew = va_arg(ap, void **);
-			pFree = va_arg(ap, void *);
-			if (sz)
-				*ppNew = sqlScratchMalloc(sz);
-			sqlScratchFree(pFree);
-			break;
-		}
-
-		/*   sql_test_control(SQL_TESTCTRL_LOCALTIME_FAULT, int onoff);
-		 *
-		 * If parameter onoff is non-zero, configure the wrappers so that all
-		 * subsequent calls to localtime() and variants fail. If onoff is zero,
-		 * undo this setting.
-		 */
-	case SQL_TESTCTRL_LOCALTIME_FAULT:{
-			sqlGlobalConfig.bLocaltimeFault = va_arg(ap, int);
-			break;
-		}
-
-		/*   sql_test_control(SQL_TESTCTRL_NEVER_CORRUPT, int);
-		 *
-		 * Set or clear a flag that indicates that the database file is always well-
-		 * formed and never corrupt.  This flag is clear by default, indicating that
-		 * database files might have arbitrary corruption.  Setting the flag during
-		 * testing causes certain assert() statements in the code to be activated
-		 * that demonstrat invariants on well-formed database files.
-		 */
-	case SQL_TESTCTRL_NEVER_CORRUPT:{
-			sqlGlobalConfig.neverCorrupt = va_arg(ap, int);
-			break;
-		}
-
-		/* Set the threshold at which OP_Once counters reset back to zero.
-		 * By default this is 0x7ffffffe (over 2 billion), but that value is
-		 * too big to test in a reasonable amount of time, so this control is
-		 * provided to set a small and easily reachable reset value.
-		 */
-	case SQL_TESTCTRL_ONCE_RESET_THRESHOLD:{
-			sqlGlobalConfig.iOnceResetThreshold =
-			    va_arg(ap, int);
-			break;
-		}
-
-		/*   sql_test_control(SQL_TESTCTRL_VDBE_COVERAGE, xCallback, ptr);
-		 *
-		 * Set the VDBE coverage callback function to xCallback with context
-		 * pointer ptr.
-		 */
-	case SQL_TESTCTRL_VDBE_COVERAGE:{
-#ifdef SQL_VDBE_COVERAGE
-			typedef void (*branch_callback) (void *, int, u8, u8);
-			sqlGlobalConfig.xVdbeBranch =
-			    va_arg(ap, branch_callback);
-			sqlGlobalConfig.pVdbeBranchArg = va_arg(ap, void *);
-#endif
-			break;
-		}
-
-		/*   sql_test_control(SQL_TESTCTRL_SORTER_MMAP, db, nMax); */
-	case SQL_TESTCTRL_SORTER_MMAP:{
-			sql *db = va_arg(ap, sql *);
-			db->nMaxSorterMmap = va_arg(ap, int);
-			break;
-		}
-
-		/*   sql_test_control(SQL_TESTCTRL_ISINIT);
-		 *
-		 * Return SQL_OK if sql has been initialized and SQL_ERROR if
-		 * not.
-		 */
-	case SQL_TESTCTRL_ISINIT:{
-			if (sqlGlobalConfig.isInit == 0)
-				rc = SQL_ERROR;
-			break;
-		}
-	}
-	va_end(ap);
-#endif				/* SQL_UNTESTABLE */
-	return rc;
-}
-
-/*
  * This is a utility routine, useful to VFS implementations, that checks
  * to see if a database file was a URI that contained a specific query
  * parameter, and if so obtains the value of the query parameter.
@@ -1716,29 +788,3 @@ sql_uri_parameter(const char *zFilename, const char *zParam)
 	}
 	return 0;
 }
-
-/*
- * Return a boolean value for a query parameter.
- */
-int
-sql_uri_boolean(const char *zFilename, const char *zParam, int bDflt)
-{
-	const char *z = sql_uri_parameter(zFilename, zParam);
-	bDflt = bDflt != 0;
-	return z ? sqlGetBoolean(z, bDflt) : bDflt;
-}
-
-/*
- * Return a 64-bit integer value for a query parameter.
- */
-sql_int64
-sql_uri_int64(const char *zFilename,	/* Filename as passed to xOpen */
-		  const char *zParam,	/* URI parameter sought */
-		  sql_int64 bDflt)	/* return if parameter is missing */
-{
-	const char *z = sql_uri_parameter(zFilename, zParam);
-	int64_t v;
-	if (z != NULL && sql_dec_or_hex_to_i64(z, &v) == 0)
-		bDflt = v;
-	return bDflt;
-}
diff --git a/src/box/sql/random.c b/src/box/sql/random.c
index 2de1890..9e1122b 100644
--- a/src/box/sql/random.c
+++ b/src/box/sql/random.c
@@ -114,9 +114,6 @@ sql_randomness(int N, void *pBuf)
  * PRNG and restore the PRNG to its saved state at a later time, or
  * to reset the PRNG to its initial state.  These routines accomplish
  * those tasks.
- *
- * The sql_test_control() interface calls these routines to
- * control the PRNG.
  */
 static SQL_WSD struct sqlPrngType sqlSavedPrng;
 void
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index b1ec8c7..e0ed5db 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -5659,8 +5659,6 @@ sqlSelect(Parse * pParse,		/* The parser context */
 		 *   (2)  The ALL keyword after SELECT is omitted.  (Applications are
 		 *        allowed to say "SELECT ALL" instead of just "SELECT" to disable
 		 *        the use of co-routines.)
-		 *   (3)  Co-routines are not disabled using sql_test_control()
-		 *        with SQL_TESTCTRL_OPTIMIZATIONS.
 		 *
 		 * TODO: Are there other reasons beside (1) to use a co-routine
 		 * implementation?
diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
index cfeb49c..7579e75 100644
--- a/src/box/sql/sqlInt.h
+++ b/src/box/sql/sqlInt.h
@@ -675,9 +675,6 @@ sql_column_name(sql_stmt *, int N);
 const char *
 sql_column_datatype(sql_stmt *, int N);
 
-const char *
-sql_errmsg(sql *);
-
 int
 sql_initialize(void);
 
@@ -784,9 +781,6 @@ sql_status64(int op, sql_int64 * pCurrent,
 		 sql_int64 * pHighwater,
 		 int resetFlag);
 
-int
-sql_config(int, ...);
-
 
 typedef struct sql_io_methods sql_io_methods;
 struct sql_io_methods {
@@ -836,10 +830,6 @@ sql_limit(sql *, int id, int newVal);
 #define SQL_SYNC_FULL          0x00003
 #define SQL_SYNC_DATAONLY      0x00010
 
-int
-sql_uri_boolean(const char *zFile,
-		    const char *zParam, int bDefault);
-
 extern char *
 sql_temp_directory;
 
@@ -876,9 +866,6 @@ sql_vfs_register(sql_vfs *, int makeDflt);
 #define SQL_STMTSTATUS_AUTOINDEX         3
 #define SQL_STMTSTATUS_VM_STEP           4
 
-void
-sql_interrupt(sql *);
-
 int
 sql_bind_blob(sql_stmt *, int, const void *,
 		  int n, void (*)(void *));
@@ -1507,11 +1494,7 @@ struct sql {
 #define SQL_DeferFKs       0x02000000	/* Defer all FK constraints */
 #define SQL_VdbeEQP        0x08000000	/* Debug EXPLAIN QUERY PLAN */
 
-/*
- * Bits of the sql.dbOptFlags field that are used by the
- * sql_test_control(sql_TESTCTRL_OPTIMIZATIONS,...) interface to
- * selectively disable various optimizations.
- */
+/* Bits of the sql.dbOptFlags field. */
 #define SQL_QueryFlattener 0x0001	/* Query flattening */
 #define SQL_ColumnCache    0x0002	/* Column cache */
 #define SQL_GroupByOrder   0x0004	/* GROUPBY cover of ORDERBY */
@@ -2916,24 +2899,6 @@ struct sqlConfig {
 };
 
 /*
- * This macro is used inside of assert() statements to indicate that
- * the assert is only valid on a well-formed database.  Instead of:
- *
- *     assert( X );
- *
- * One writes:
- *
- *     assert( X || CORRUPT_DB );
- *
- * CORRUPT_DB is true during normal operation.  CORRUPT_DB does not indicate
- * that the database is definitely corrupt, only that it might be corrupt.
- * For most test cases, CORRUPT_DB is set to false using a special
- * sql_test_control().  This enables assert() statements to prove
- * things that are always true for well-formed databases.
- */
-#define CORRUPT_DB  (sqlConfig.neverCorrupt==0)
-
-/*
  * Context pointer passed down through the tree-walk.
  */
 struct Walker {
@@ -3387,9 +3352,6 @@ int
 vdbe_emit_open_cursor(struct Parse *parse, int cursor, int index_id,
 		      struct space *space);
 
-int sqlParseUri(const char *, const char *, unsigned int *,
-		    sql_vfs **, char **, char **);
-
 #ifdef SQL_UNTESTABLE
 #define sqlFaultSim(X) SQL_OK
 #else
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index f746559..d452892 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -743,18 +743,6 @@ int sqlVdbeExec(Vdbe *p)
 #endif
 
 
-		/* Check to see if we need to simulate an interrupt.  This only happens
-		 * if we have a special test build.
-		 */
-#ifdef SQL_TEST
-		if (sql_interrupt_count>0) {
-			sql_interrupt_count--;
-			if (sql_interrupt_count==0) {
-				sql_interrupt(db);
-			}
-		}
-#endif
-
 		/* Sanity checking on other operands */
 #ifdef SQL_DEBUG
 		{
-- 
2.7.4







More information about the Tarantool-patches mailing list