summaryrefslogtreecommitdiff
path: root/src/test1.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test1.c')
-rw-r--r--src/test1.c340
1 files changed, 315 insertions, 25 deletions
diff --git a/src/test1.c b/src/test1.c
index a638e48..56487f6 100644
--- a/src/test1.c
+++ b/src/test1.c
@@ -14,6 +14,10 @@
** testing of the SQLite library.
*/
#include "sqliteInt.h"
+#if SQLITE_OS_WIN
+# include "os_win.h"
+#endif
+
#include "vdbeInt.h"
#include "tcl.h"
#include <stdlib.h>
@@ -113,6 +117,16 @@ int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
return TCL_OK;
}
+#if SQLITE_OS_WIN
+/*
+** Decode a Win32 HANDLE object.
+*/
+int getWin32Handle(Tcl_Interp *interp, const char *zA, LPHANDLE phFile){
+ *phFile = (HANDLE)sqlite3TestTextToPtr(zA);
+ return TCL_OK;
+}
+#endif
+
extern const char *sqlite3ErrName(int);
#define t1ErrorName sqlite3ErrName
@@ -242,7 +256,28 @@ static int test_io_trace(
return TCL_OK;
}
-
+/*
+** Usage: clang_sanitize_address
+**
+** Returns true if the program was compiled using clang with the
+** -fsanitize=address switch on the command line. False otherwise.
+*/
+static int clang_sanitize_address(
+ void *NotUsed,
+ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
+ int argc, /* Number of arguments */
+ char **argv /* Text of each argument */
+){
+ int res = 0;
+#if defined(__has_feature)
+# if __has_feature(address_sanitizer)
+ res = 1;
+# endif
+#endif
+ Tcl_SetObjResult(interp, Tcl_NewIntObj(res));
+ return TCL_OK;
+}
+
/*
** Usage: sqlite3_exec_printf DB FORMAT STRING
**
@@ -942,9 +977,21 @@ static void ptrChngFunction(
sqlite3_result_int(context, p1!=p2);
}
+/*
+** This SQL function returns a different answer each time it is called, even if
+** the arguments are the same.
+*/
+static void nondeterministicFunction(
+ sqlite3_context *context,
+ int argc,
+ sqlite3_value **argv
+){
+ static int cnt = 0;
+ sqlite3_result_int(context, cnt++);
+}
/*
-** Usage: sqlite_test_create_function DB
+** Usage: sqlite3_create_function DB
**
** Call the sqlite3_create_function API on the given database in order
** to create a function named "x_coalesce". This function does the same thing
@@ -973,16 +1020,16 @@ static int test_create_function(
return TCL_ERROR;
}
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
- rc = sqlite3_create_function(db, "x_coalesce", -1, SQLITE_ANY, 0,
+ rc = sqlite3_create_function(db, "x_coalesce", -1, SQLITE_UTF8, 0,
t1_ifnullFunc, 0, 0);
if( rc==SQLITE_OK ){
- rc = sqlite3_create_function(db, "hex8", 1, SQLITE_ANY, 0,
- hex8Func, 0, 0);
+ rc = sqlite3_create_function(db, "hex8", 1, SQLITE_UTF8 | SQLITE_DETERMINISTIC,
+ 0, hex8Func, 0, 0);
}
#ifndef SQLITE_OMIT_UTF16
if( rc==SQLITE_OK ){
- rc = sqlite3_create_function(db, "hex16", 1, SQLITE_ANY, 0,
- hex16Func, 0, 0);
+ rc = sqlite3_create_function(db, "hex16", 1, SQLITE_UTF16 | SQLITE_DETERMINISTIC,
+ 0, hex16Func, 0, 0);
}
#endif
if( rc==SQLITE_OK ){
@@ -994,6 +1041,19 @@ static int test_create_function(
ptrChngFunction, 0, 0);
}
+ /* Functions counter1() and counter2() have the same implementation - they
+ ** both return an ascending integer with each call. But counter1() is marked
+ ** as non-deterministic and counter2() is marked as deterministic.
+ */
+ if( rc==SQLITE_OK ){
+ rc = sqlite3_create_function(db, "counter1", -1, SQLITE_UTF8,
+ 0, nondeterministicFunction, 0, 0);
+ }
+ if( rc==SQLITE_OK ){
+ rc = sqlite3_create_function(db, "counter2", -1, SQLITE_UTF8|SQLITE_DETERMINISTIC,
+ 0, nondeterministicFunction, 0, 0);
+ }
+
#ifndef SQLITE_OMIT_UTF16
/* Use the sqlite3_create_function16() API here. Mainly for fun, but also
** because it is not tested anywhere else. */
@@ -2218,6 +2278,7 @@ static int test_stmt_status(
{ "SQLITE_STMTSTATUS_FULLSCAN_STEP", SQLITE_STMTSTATUS_FULLSCAN_STEP },
{ "SQLITE_STMTSTATUS_SORT", SQLITE_STMTSTATUS_SORT },
{ "SQLITE_STMTSTATUS_AUTOINDEX", SQLITE_STMTSTATUS_AUTOINDEX },
+ { "SQLITE_STMTSTATUS_VM_STEP", SQLITE_STMTSTATUS_VM_STEP },
};
if( objc!=4 ){
Tcl_WrongNumArgs(interp, 1, objv, "STMT PARAMETER RESETFLAG");
@@ -2469,7 +2530,7 @@ static int sqlite_static_bind_nbyte = 0;
/*
** Usage: sqlite3_bind VM IDX VALUE FLAGS
**
-** Sets the value of the IDX-th occurance of "?" in the original SQL
+** Sets the value of the IDX-th occurrence of "?" in the original SQL
** string. VALUE is the new value. If FLAGS=="null" then VALUE is
** ignored and the value is set to NULL. If FLAGS=="static" then
** the value is set to the value of a static variable named
@@ -5159,6 +5220,7 @@ static int file_control_lockproxy_test(
return TCL_OK;
}
+#if SQLITE_OS_WIN
/*
** tclcmd: file_control_win32_av_retry DB NRETRY DELAY
**
@@ -5193,6 +5255,42 @@ static int file_control_win32_av_retry(
}
/*
+** tclcmd: file_control_win32_set_handle DB HANDLE
+**
+** This TCL command runs the sqlite3_file_control interface with
+** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode.
+*/
+static int file_control_win32_set_handle(
+ ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
+ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
+ int objc, /* Number of arguments */
+ Tcl_Obj *CONST objv[] /* Command arguments */
+){
+ sqlite3 *db;
+ int rc;
+ HANDLE hFile = NULL;
+ char z[100];
+
+ if( objc!=3 ){
+ Tcl_AppendResult(interp, "wrong # args: should be \"",
+ Tcl_GetStringFromObj(objv[0], 0), " DB HANDLE", 0);
+ return TCL_ERROR;
+ }
+ if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
+ return TCL_ERROR;
+ }
+ if( getWin32Handle(interp, Tcl_GetString(objv[2]), &hFile) ){
+ return TCL_ERROR;
+ }
+ rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_WIN32_SET_HANDLE,
+ (void*)&hFile);
+ sqlite3_snprintf(sizeof(z), z, "%d %p", rc, (void*)hFile);
+ Tcl_AppendResult(interp, z, (char*)0);
+ return TCL_OK;
+}
+#endif
+
+/*
** tclcmd: file_control_persist_wal DB PERSIST-FLAG
**
** This TCL command runs the sqlite3_file_control interface with
@@ -5453,6 +5551,37 @@ static int reset_prng_state(
}
/*
+** tclcmd: database_may_be_corrupt
+**
+** Indicate that database files might be corrupt. In other words, set the normal
+** state of operation.
+*/
+static int database_may_be_corrupt(
+ ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
+ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
+ int objc, /* Number of arguments */
+ Tcl_Obj *CONST objv[] /* Command arguments */
+){
+ sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, 0);
+ return TCL_OK;
+}
+/*
+** tclcmd: database_never_corrupt
+**
+** Indicate that database files are always well-formed. This enables extra assert()
+** statements that test conditions that are always true for well-formed databases.
+*/
+static int database_never_corrupt(
+ ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
+ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
+ int objc, /* Number of arguments */
+ Tcl_Obj *CONST objv[] /* Command arguments */
+){
+ sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT, 1);
+ return TCL_OK;
+}
+
+/*
** tclcmd: pcache_stats
*/
static int test_pcache_stats(
@@ -5563,7 +5692,7 @@ static int test_wal_checkpoint(
**
** Otherwise, this command returns a list of three integers. The first integer
** is 1 if SQLITE_BUSY was returned, or 0 otherwise. The following two integers
-** are the values returned via the output paramaters by wal_checkpoint_v2() -
+** are the values returned via the output parameters by wal_checkpoint_v2() -
** the number of frames in the log and the number of frames in the log
** that have been checkpointed.
*/
@@ -5933,6 +6062,145 @@ static int win32_file_lock(
CloseHandle(ev);
return TCL_OK;
}
+
+/*
+** exists_win32_path PATH
+**
+** Returns non-zero if the specified path exists, whose fully qualified name
+** may exceed 260 characters if it is prefixed with "\\?\".
+*/
+static int win32_exists_path(
+ void *clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "PATH");
+ return TCL_ERROR;
+ }
+ Tcl_SetObjResult(interp, Tcl_NewBooleanObj(
+ GetFileAttributesW( Tcl_GetUnicode(objv[1]))!=INVALID_FILE_ATTRIBUTES ));
+ return TCL_OK;
+}
+
+/*
+** find_win32_file PATTERN
+**
+** Returns a list of entries in a directory that match the specified pattern,
+** whose fully qualified name may exceed 248 characters if it is prefixed with
+** "\\?\".
+*/
+static int win32_find_file(
+ void *clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ HANDLE hFindFile = INVALID_HANDLE_VALUE;
+ WIN32_FIND_DATAW findData;
+ Tcl_Obj *listObj;
+ DWORD lastErrno;
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "PATTERN");
+ return TCL_ERROR;
+ }
+ hFindFile = FindFirstFileW(Tcl_GetUnicode(objv[1]), &findData);
+ if( hFindFile==INVALID_HANDLE_VALUE ){
+ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
+ return TCL_ERROR;
+ }
+ listObj = Tcl_NewObj();
+ Tcl_IncrRefCount(listObj);
+ do {
+ Tcl_ListObjAppendElement(interp, listObj, Tcl_NewUnicodeObj(
+ findData.cFileName, -1));
+ Tcl_ListObjAppendElement(interp, listObj, Tcl_NewWideIntObj(
+ findData.dwFileAttributes));
+ } while( FindNextFileW(hFindFile, &findData) );
+ lastErrno = GetLastError();
+ if( lastErrno!=NO_ERROR && lastErrno!=ERROR_NO_MORE_FILES ){
+ FindClose(hFindFile);
+ Tcl_DecrRefCount(listObj);
+ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
+ return TCL_ERROR;
+ }
+ FindClose(hFindFile);
+ Tcl_SetObjResult(interp, listObj);
+ return TCL_OK;
+}
+
+/*
+** delete_win32_file FILENAME
+**
+** Deletes the specified file, whose fully qualified name may exceed 260
+** characters if it is prefixed with "\\?\".
+*/
+static int win32_delete_file(
+ void *clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "FILENAME");
+ return TCL_ERROR;
+ }
+ if( !DeleteFileW(Tcl_GetUnicode(objv[1])) ){
+ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
+ return TCL_ERROR;
+ }
+ Tcl_ResetResult(interp);
+ return TCL_OK;
+}
+
+/*
+** make_win32_dir DIRECTORY
+**
+** Creates the specified directory, whose fully qualified name may exceed 248
+** characters if it is prefixed with "\\?\".
+*/
+static int win32_mkdir(
+ void *clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "DIRECTORY");
+ return TCL_ERROR;
+ }
+ if( !CreateDirectoryW(Tcl_GetUnicode(objv[1]), NULL) ){
+ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
+ return TCL_ERROR;
+ }
+ Tcl_ResetResult(interp);
+ return TCL_OK;
+}
+
+/*
+** remove_win32_dir DIRECTORY
+**
+** Removes the specified directory, whose fully qualified name may exceed 248
+** characters if it is prefixed with "\\?\".
+*/
+static int win32_rmdir(
+ void *clientData,
+ Tcl_Interp *interp,
+ int objc,
+ Tcl_Obj *CONST objv[]
+){
+ if( objc!=2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "DIRECTORY");
+ return TCL_ERROR;
+ }
+ if( !RemoveDirectoryW(Tcl_GetUnicode(objv[1])) ){
+ Tcl_SetObjResult(interp, Tcl_NewWideIntObj(GetLastError()));
+ return TCL_ERROR;
+ }
+ Tcl_ResetResult(interp);
+ return TCL_OK;
+}
#endif
@@ -5958,15 +6226,19 @@ static int optimization_control(
const char *zOptName;
int mask;
} aOpt[] = {
- { "all", SQLITE_AllOpts },
- { "query-flattener", SQLITE_QueryFlattener },
- { "column-cache", SQLITE_ColumnCache },
- { "groupby-order", SQLITE_GroupByOrder },
- { "factor-constants", SQLITE_FactorOutConst },
- { "real-as-int", SQLITE_IdxRealAsInt },
- { "distinct-opt", SQLITE_DistinctOpt },
- { "cover-idx-scan", SQLITE_CoverIdxScan },
- { "order-by-idx-join",SQLITE_OrderByIdxJoin },
+ { "all", SQLITE_AllOpts },
+ { "none", 0 },
+ { "query-flattener", SQLITE_QueryFlattener },
+ { "column-cache", SQLITE_ColumnCache },
+ { "groupby-order", SQLITE_GroupByOrder },
+ { "factor-constants", SQLITE_FactorOutConst },
+ { "distinct-opt", SQLITE_DistinctOpt },
+ { "cover-idx-scan", SQLITE_CoverIdxScan },
+ { "order-by-idx-join", SQLITE_OrderByIdxJoin },
+ { "transitive", SQLITE_Transitive },
+ { "subquery-coroutine", SQLITE_SubqCoroutine },
+ { "omit-noop-join", SQLITE_OmitNoopJoin },
+ { "stat3", SQLITE_Stat3 },
};
if( objc!=4 ){
@@ -5987,7 +6259,7 @@ static int optimization_control(
Tcl_AppendResult(interp, "unknown optimization - should be one of:",
(char*)0);
for(i=0; i<sizeof(aOpt)/sizeof(aOpt[0]); i++){
- Tcl_AppendResult(interp, " ", aOpt[i].zOptName);
+ Tcl_AppendResult(interp, " ", aOpt[i].zOptName, (char*)0);
}
return TCL_ERROR;
}
@@ -6009,11 +6281,14 @@ static int tclLoadStaticExtensionCmd(
){
extern int sqlite3_amatch_init(sqlite3*,char**,const sqlite3_api_routines*);
extern int sqlite3_closure_init(sqlite3*,char**,const sqlite3_api_routines*);
+ extern int sqlite3_fileio_init(sqlite3*,char**,const sqlite3_api_routines*);
extern int sqlite3_fuzzer_init(sqlite3*,char**,const sqlite3_api_routines*);
extern int sqlite3_ieee_init(sqlite3*,char**,const sqlite3_api_routines*);
extern int sqlite3_nextchar_init(sqlite3*,char**,const sqlite3_api_routines*);
+ extern int sqlite3_percentile_init(sqlite3*,char**,const sqlite3_api_routines*);
extern int sqlite3_regexp_init(sqlite3*,char**,const sqlite3_api_routines*);
extern int sqlite3_spellfix_init(sqlite3*,char**,const sqlite3_api_routines*);
+ extern int sqlite3_totype_init(sqlite3*,char**,const sqlite3_api_routines*);
extern int sqlite3_wholenumber_init(sqlite3*,char**,const sqlite3_api_routines*);
static const struct {
const char *zExtName;
@@ -6021,11 +6296,14 @@ static int tclLoadStaticExtensionCmd(
} aExtension[] = {
{ "amatch", sqlite3_amatch_init },
{ "closure", sqlite3_closure_init },
+ { "fileio", sqlite3_fileio_init },
{ "fuzzer", sqlite3_fuzzer_init },
{ "ieee754", sqlite3_ieee_init },
{ "nextchar", sqlite3_nextchar_init },
+ { "percentile", sqlite3_percentile_init },
{ "regexp", sqlite3_regexp_init },
{ "spellfix", sqlite3_spellfix_init },
+ { "totype", sqlite3_totype_init },
{ "wholenumber", sqlite3_wholenumber_init },
};
sqlite3 *db;
@@ -6119,6 +6397,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "sqlite3_busy_timeout", (Tcl_CmdProc*)test_busy_timeout },
{ "printf", (Tcl_CmdProc*)test_printf },
{ "sqlite3IoTrace", (Tcl_CmdProc*)test_io_trace },
+ { "clang_sanitize_address", (Tcl_CmdProc*)clang_sanitize_address },
};
static struct {
char *zName;
@@ -6182,9 +6461,16 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "save_prng_state", save_prng_state, 0 },
{ "restore_prng_state", restore_prng_state, 0 },
{ "reset_prng_state", reset_prng_state, 0 },
+ { "database_never_corrupt", database_never_corrupt, 0},
+ { "database_may_be_corrupt", database_may_be_corrupt, 0},
{ "optimization_control", optimization_control,0},
#if SQLITE_OS_WIN
{ "lock_win32_file", win32_file_lock, 0 },
+ { "exists_win32_path", win32_exists_path, 0 },
+ { "find_win32_file", win32_find_file, 0 },
+ { "delete_win32_file", win32_delete_file, 0 },
+ { "make_win32_dir", win32_mkdir, 0 },
+ { "remove_win32_dir", win32_rmdir, 0 },
#endif
{ "tcl_objproc", runAsObjProc, 0 },
@@ -6235,7 +6521,10 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
{ "file_control_lockproxy_test", file_control_lockproxy_test, 0 },
{ "file_control_chunksize_test", file_control_chunksize_test, 0 },
{ "file_control_sizehint_test", file_control_sizehint_test, 0 },
+#if SQLITE_OS_WIN
{ "file_control_win32_av_retry", file_control_win32_av_retry, 0 },
+ { "file_control_win32_set_handle", file_control_win32_set_handle, 0 },
+#endif
{ "file_control_persist_wal", file_control_persist_wal, 0 },
{ "file_control_powersafe_overwrite",file_control_powersafe_overwrite,0},
{ "file_control_vfsname", file_control_vfsname, 0 },
@@ -6292,7 +6581,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
extern int sqlite3_pager_writedb_count;
extern int sqlite3_pager_writej_count;
#if SQLITE_OS_WIN
- extern int sqlite3_os_type;
+ extern LONG volatile sqlite3_os_type;
#endif
#ifdef SQLITE_DEBUG
extern int sqlite3WhereTrace;
@@ -6300,8 +6589,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
extern int sqlite3WalTrace;
#endif
#ifdef SQLITE_TEST
- extern char sqlite3_query_plan[];
- static char *query_plan = sqlite3_query_plan;
#ifdef SQLITE_ENABLE_FTS3
extern int sqlite3_fts3_enable_parentheses;
#endif
@@ -6352,11 +6639,14 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
#endif
#if SQLITE_OS_WIN
Tcl_LinkVar(interp, "sqlite_os_type",
- (char*)&sqlite3_os_type, TCL_LINK_INT);
+ (char*)&sqlite3_os_type, TCL_LINK_LONG);
#endif
#ifdef SQLITE_TEST
- Tcl_LinkVar(interp, "sqlite_query_plan",
- (char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
+ {
+ static const char *query_plan = "*** OBSOLETE VARIABLE ***";
+ Tcl_LinkVar(interp, "sqlite_query_plan",
+ (char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
+ }
#endif
#ifdef SQLITE_DEBUG
Tcl_LinkVar(interp, "sqlite_where_trace",