4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
12 ** Code for testing all sorts of SQLite interfaces. This code
13 ** is not included in the SQLite library. It is used for automated
14 ** testing of the SQLite library.
16 #include "sqliteInt.h"
22 #if defined(INCLUDE_SQLITE_TCL_H)
23 # include "sqlite_tcl.h"
31 ** This is a copy of the first part of the SqliteDb structure in
32 ** tclsqlite.c. We need it here so that the get_sqlite_pointer routine
33 ** can extract the sqlite3* pointer from an existing Tcl SQLite
41 ** Convert text generated by the "%p" conversion format back into
44 static int testHexToInt(int h
){
45 if( h
>='0' && h
<='9' ){
47 }else if( h
>='a' && h
<='f' ){
50 assert( h
>='A' && h
<='F' );
54 void *sqlite3TestTextToPtr(const char *z
){
58 if( z
[0]=='0' && z
[1]=='x' ){
63 v
= (v
<<4) + testHexToInt(*z
);
66 if( sizeof(p
)==sizeof(v
) ){
67 memcpy(&p
, &v
, sizeof(p
));
69 assert( sizeof(p
)==sizeof(v2
) );
71 memcpy(&p
, &v2
, sizeof(p
));
78 ** A TCL command that returns the address of the sqlite* pointer
79 ** for an sqlite connection instance. Bad things happen if the
80 ** input is not an sqlite connection.
82 static int SQLITE_TCLAPI
get_sqlite_pointer(
92 Tcl_WrongNumArgs(interp
, 1, objv
, "SQLITE-CONNECTION");
95 if( !Tcl_GetCommandInfo(interp
, Tcl_GetString(objv
[1]), &cmdInfo
) ){
96 Tcl_AppendResult(interp
, "command not found: ",
97 Tcl_GetString(objv
[1]), (char*)0);
100 p
= (struct SqliteDb
*)cmdInfo
.objClientData
;
101 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%p", p
->db
);
102 Tcl_AppendResult(interp
, zBuf
, 0);
107 ** Decode a pointer to an sqlite3 object.
109 int getDbPointer(Tcl_Interp
*interp
, const char *zA
, sqlite3
**ppDb
){
112 if( Tcl_GetCommandInfo(interp
, zA
, &cmdInfo
) ){
113 p
= (struct SqliteDb
*)cmdInfo
.objClientData
;
116 *ppDb
= (sqlite3
*)sqlite3TestTextToPtr(zA
);
123 ** Decode a Win32 HANDLE object.
125 int getWin32Handle(Tcl_Interp
*interp
, const char *zA
, LPHANDLE phFile
){
126 *phFile
= (HANDLE
)sqlite3TestTextToPtr(zA
);
131 extern const char *sqlite3ErrName(int);
132 #define t1ErrorName sqlite3ErrName
135 ** Convert an sqlite3_stmt* into an sqlite3*. This depends on the
136 ** fact that the sqlite3* is the first field in the Vdbe structure.
138 #define StmtToDb(X) sqlite3_db_handle(X)
141 ** Check a return value to make sure it agrees with the results
142 ** from sqlite3_errcode.
144 int sqlite3TestErrCode(Tcl_Interp
*interp
, sqlite3
*db
, int rc
){
145 if( sqlite3_threadsafe()==0 && rc
!=SQLITE_MISUSE
&& rc
!=SQLITE_OK
146 && sqlite3_errcode(db
)!=rc
){
148 int r2
= sqlite3_errcode(db
);
149 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
150 "error code %s (%d) does not match sqlite3_errcode %s (%d)",
151 t1ErrorName(rc
), rc
, t1ErrorName(r2
), r2
);
152 Tcl_ResetResult(interp
);
153 Tcl_AppendResult(interp
, zBuf
, 0);
160 ** Decode a pointer to an sqlite3_stmt object.
162 static int getStmtPointer(
165 sqlite3_stmt
**ppStmt
167 *ppStmt
= (sqlite3_stmt
*)sqlite3TestTextToPtr(zArg
);
172 ** Generate a text representation of a pointer that can be understood
173 ** by the getDbPointer and getVmPointer routines above.
175 ** The problem is, on some machines (Solaris) if you do a printf with
176 ** "%p" you cannot turn around and do a scanf with the same "%p" and
177 ** get your pointer back. You have to prepend a "0x" before it will
178 ** work. Or at least that is what is reported to me (drh). But this
179 ** behavior varies from machine to machine. The solution used her is
180 ** to test the string right after it is generated to see if it can be
181 ** understood by scanf, and if not, try prepending an "0x" to see if
182 ** that helps. If nothing works, a fatal error is generated.
184 int sqlite3TestMakePointerStr(Tcl_Interp
*interp
, char *zPtr
, void *p
){
185 sqlite3_snprintf(100, zPtr
, "%p", p
);
190 ** The callback routine for sqlite3_exec_printf().
192 static int exec_printf_cb(void *pArg
, int argc
, char **argv
, char **name
){
193 Tcl_DString
*str
= (Tcl_DString
*)pArg
;
196 if( Tcl_DStringLength(str
)==0 ){
197 for(i
=0; i
<argc
; i
++){
198 Tcl_DStringAppendElement(str
, name
[i
] ? name
[i
] : "NULL");
201 for(i
=0; i
<argc
; i
++){
202 Tcl_DStringAppendElement(str
, argv
[i
] ? argv
[i
] : "NULL");
208 ** The I/O tracing callback.
210 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
211 static FILE *iotrace_file
= 0;
212 static void io_trace_callback(const char *zFormat
, ...){
214 va_start(ap
, zFormat
);
215 vfprintf(iotrace_file
, zFormat
, ap
);
217 fflush(iotrace_file
);
222 ** Usage: io_trace FILENAME
224 ** Turn I/O tracing on or off. If FILENAME is not an empty string,
225 ** I/O tracing begins going into FILENAME. If FILENAME is an empty
226 ** string, I/O tracing is turned off.
228 static int SQLITE_TCLAPI
test_io_trace(
230 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
231 int argc
, /* Number of arguments */
232 char **argv
/* Text of each argument */
234 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
236 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
241 if( iotrace_file
!=stdout
&& iotrace_file
!=stderr
){
242 fclose(iotrace_file
);
248 if( strcmp(argv
[1],"stdout")==0 ){
249 iotrace_file
= stdout
;
250 }else if( strcmp(argv
[1],"stderr")==0 ){
251 iotrace_file
= stderr
;
253 iotrace_file
= fopen(argv
[1], "w");
255 sqlite3IoTrace
= io_trace_callback
;
262 ** Usage: clang_sanitize_address
264 ** Returns true if the program was compiled using clang with the
265 ** -fsanitize=address switch on the command line. False otherwise.
267 ** Also return true if the OMIT_MISUSE environment variable exists.
269 static int SQLITE_TCLAPI
clang_sanitize_address(
271 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
272 int argc
, /* Number of arguments */
273 char **argv
/* Text of each argument */
276 #if defined(__has_feature)
277 # if __has_feature(address_sanitizer)
281 #ifdef __SANITIZE_ADDRESS__
284 if( res
==0 && getenv("OMIT_MISUSE")!=0 ) res
= 1;
285 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
290 ** Usage: sqlite3_exec_printf DB FORMAT STRING
292 ** Invoke the sqlite3_exec_printf() interface using the open database
293 ** DB. The SQL is the string FORMAT. The format string should contain
294 ** one %s or %q. STRING is the value inserted into %s or %q.
296 static int SQLITE_TCLAPI
test_exec_printf(
298 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
299 int argc
, /* Number of arguments */
300 char **argv
/* Text of each argument */
309 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
310 " DB FORMAT STRING", 0);
313 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
314 Tcl_DStringInit(&str
);
315 zSql
= sqlite3_mprintf(argv
[2], argv
[3]);
316 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
318 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
319 Tcl_AppendElement(interp
, zBuf
);
320 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
321 Tcl_DStringFree(&str
);
322 if( zErr
) sqlite3_free(zErr
);
323 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
328 ** Usage: sqlite3_exec_hex DB HEX
330 ** Invoke the sqlite3_exec() on a string that is obtained by translating
331 ** HEX into ASCII. Most characters are translated as is. %HH becomes
334 static int SQLITE_TCLAPI
test_exec_hex(
336 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
337 int argc
, /* Number of arguments */
338 char **argv
/* Text of each argument */
348 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
352 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
354 for(i
=j
=0; i
<(sizeof(zSql
)-1) && zHex
[j
]; i
++, j
++){
355 if( zHex
[j
]=='%' && zHex
[j
+2] && zHex
[j
+2] ){
356 zSql
[i
] = (testHexToInt(zHex
[j
+1])<<4) + testHexToInt(zHex
[j
+2]);
363 Tcl_DStringInit(&str
);
364 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
365 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
366 Tcl_AppendElement(interp
, zBuf
);
367 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
368 Tcl_DStringFree(&str
);
369 if( zErr
) sqlite3_free(zErr
);
370 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
375 ** Usage: db_enter DB
378 ** Enter or leave the mutex on a database connection.
380 static int SQLITE_TCLAPI
db_enter(
382 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
383 int argc
, /* Number of arguments */
384 char **argv
/* Text of each argument */
388 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
392 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
393 sqlite3_mutex_enter(db
->mutex
);
396 static int SQLITE_TCLAPI
db_leave(
398 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
399 int argc
, /* Number of arguments */
400 char **argv
/* Text of each argument */
404 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
408 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
409 sqlite3_mutex_leave(db
->mutex
);
414 ** Usage: sqlite3_exec DB SQL
416 ** Invoke the sqlite3_exec interface using the open database DB
418 static int SQLITE_TCLAPI
test_exec(
420 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
421 int argc
, /* Number of arguments */
422 char **argv
/* Text of each argument */
432 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
436 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
437 Tcl_DStringInit(&str
);
438 zSql
= sqlite3_mprintf("%s", argv
[2]);
439 for(i
=j
=0; zSql
[i
];){
441 zSql
[j
++] = (testHexToInt(zSql
[i
+1])<<4) + testHexToInt(zSql
[i
+2]);
444 zSql
[j
++] = zSql
[i
++];
448 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
450 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
451 Tcl_AppendElement(interp
, zBuf
);
452 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
453 Tcl_DStringFree(&str
);
454 if( zErr
) sqlite3_free(zErr
);
455 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
460 ** Usage: sqlite3_exec_nr DB SQL
462 ** Invoke the sqlite3_exec interface using the open database DB. Discard
465 static int SQLITE_TCLAPI
test_exec_nr(
467 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
468 int argc
, /* Number of arguments */
469 char **argv
/* Text of each argument */
475 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
479 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
480 rc
= sqlite3_exec(db
, argv
[2], 0, 0, &zErr
);
481 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
486 ** Usage: sqlite3_mprintf_z_test SEPARATOR ARG0 ARG1 ...
488 ** Test the %z format of sqlite_mprintf(). Use multiple mprintf() calls to
489 ** concatenate arg0 through argn using separator as the separator.
490 ** Return the result.
492 static int SQLITE_TCLAPI
test_mprintf_z(
494 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
495 int argc
, /* Number of arguments */
496 char **argv
/* Text of each argument */
501 for(i
=2; i
<argc
&& (i
==2 || zResult
); i
++){
502 zResult
= sqlite3_mprintf("%z%s%s", zResult
, argv
[1], argv
[i
]);
504 Tcl_AppendResult(interp
, zResult
, 0);
505 sqlite3_free(zResult
);
510 ** Usage: sqlite3_mprintf_n_test STRING
512 ** Test the %n format of sqlite_mprintf(). Return the length of the
515 static int SQLITE_TCLAPI
test_mprintf_n(
517 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
518 int argc
, /* Number of arguments */
519 char **argv
/* Text of each argument */
523 zStr
= sqlite3_mprintf("%s%n", argv
[1], &n
);
525 Tcl_SetObjResult(interp
, Tcl_NewIntObj(n
));
530 ** Usage: sqlite3_snprintf_int SIZE FORMAT INT
532 ** Test the of sqlite3_snprintf() routine. SIZE is the size of the
533 ** output buffer in bytes. The maximum size is 100. FORMAT is the
534 ** format string. INT is a single integer argument. The FORMAT
535 ** string must require no more than this one integer argument. If
536 ** You pass in a format string that requires more than one argument,
537 ** bad things will happen.
539 static int SQLITE_TCLAPI
test_snprintf_int(
541 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
542 int argc
, /* Number of arguments */
543 char **argv
/* Text of each argument */
546 int n
= atoi(argv
[1]);
547 const char *zFormat
= argv
[2];
548 int a1
= atoi(argv
[3]);
549 if( n
>sizeof(zStr
) ) n
= sizeof(zStr
);
550 sqlite3_snprintf(sizeof(zStr
), zStr
, "abcdefghijklmnopqrstuvwxyz");
551 sqlite3_snprintf(n
, zStr
, zFormat
, a1
);
552 Tcl_AppendResult(interp
, zStr
, 0);
556 #ifndef SQLITE_OMIT_GET_TABLE
559 ** Usage: sqlite3_get_table_printf DB FORMAT STRING ?--no-counts?
561 ** Invoke the sqlite3_get_table_printf() interface using the open database
562 ** DB. The SQL is the string FORMAT. The format string should contain
563 ** one %s or %q. STRING is the value inserted into %s or %q.
565 static int SQLITE_TCLAPI
test_get_table_printf(
567 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
568 int argc
, /* Number of arguments */
569 char **argv
/* Text of each argument */
575 int nRow
= 0, nCol
= 0;
582 if( Tcl_GetInt(interp
, argv
[4], &resCount
) ) return TCL_ERROR
;
584 if( argc
!=4 && argc
!=5 ){
585 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
586 " DB FORMAT STRING ?COUNT?", 0);
589 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
590 Tcl_DStringInit(&str
);
591 zSql
= sqlite3_mprintf(argv
[2],argv
[3]);
593 rc
= sqlite3_get_table(db
, zSql
, &aResult
, 0, 0, &zErr
);
595 rc
= sqlite3_get_table(db
, zSql
, &aResult
, &nRow
, &nCol
, &zErr
);
596 resCount
= (nRow
+1)*nCol
;
599 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
600 Tcl_AppendElement(interp
, zBuf
);
603 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", nRow
);
604 Tcl_AppendElement(interp
, zBuf
);
605 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", nCol
);
606 Tcl_AppendElement(interp
, zBuf
);
608 for(i
=0; i
<resCount
; i
++){
609 Tcl_AppendElement(interp
, aResult
[i
] ? aResult
[i
] : "NULL");
612 Tcl_AppendElement(interp
, zErr
);
614 sqlite3_free_table(aResult
);
615 if( zErr
) sqlite3_free(zErr
);
616 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
620 #endif /* SQLITE_OMIT_GET_TABLE */
624 ** Usage: sqlite3_last_insert_rowid DB
626 ** Returns the integer ROWID of the most recent insert.
628 static int SQLITE_TCLAPI
test_last_rowid(
630 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
631 int argc
, /* Number of arguments */
632 char **argv
/* Text of each argument */
638 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB\"", 0);
641 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
642 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%lld", sqlite3_last_insert_rowid(db
));
643 Tcl_AppendResult(interp
, zBuf
, 0);
648 ** Usage: sqlite3_key DB KEY
650 ** Set the codec key.
652 static int SQLITE_TCLAPI
test_key(
654 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
655 int argc
, /* Number of arguments */
656 char **argv
/* Text of each argument */
658 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
663 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
667 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
670 sqlite3_key(db
, zKey
, nKey
);
676 ** Usage: sqlite3_rekey DB KEY
678 ** Change the codec key.
680 static int SQLITE_TCLAPI
test_rekey(
682 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
683 int argc
, /* Number of arguments */
684 char **argv
/* Text of each argument */
686 #ifdef SQLITE_HAS_CODEC
691 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
695 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
698 sqlite3_rekey(db
, zKey
, nKey
);
704 ** Usage: sqlite3_close DB
706 ** Closes the database opened by sqlite3_open.
708 static int SQLITE_TCLAPI
sqlite_test_close(
710 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
711 int argc
, /* Number of arguments */
712 char **argv
/* Text of each argument */
717 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
721 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
722 rc
= sqlite3_close(db
);
723 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
728 ** Usage: sqlite3_close_v2 DB
730 ** Closes the database opened by sqlite3_open.
732 static int SQLITE_TCLAPI
sqlite_test_close_v2(
734 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
735 int argc
, /* Number of arguments */
736 char **argv
/* Text of each argument */
741 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
745 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
746 rc
= sqlite3_close_v2(db
);
747 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
752 ** Implementation of the x_coalesce() function.
753 ** Return the first argument non-NULL argument.
755 static void t1_ifnullFunc(
756 sqlite3_context
*context
,
761 for(i
=0; i
<argc
; i
++){
762 if( SQLITE_NULL
!=sqlite3_value_type(argv
[i
]) ){
763 int n
= sqlite3_value_bytes(argv
[i
]);
764 sqlite3_result_text(context
, (char*)sqlite3_value_text(argv
[i
]),
765 n
, SQLITE_TRANSIENT
);
772 ** These are test functions. hex8() interprets its argument as
773 ** UTF8 and returns a hex encoding. hex16le() interprets its argument
774 ** as UTF16le and returns a hex encoding.
776 static void hex8Func(sqlite3_context
*p
, int argc
, sqlite3_value
**argv
){
777 const unsigned char *z
;
780 z
= sqlite3_value_text(argv
[0]);
781 for(i
=0; i
<sizeof(zBuf
)/2 - 2 && z
[i
]; i
++){
782 sqlite3_snprintf(sizeof(zBuf
)-i
*2, &zBuf
[i
*2], "%02x", z
[i
]);
785 sqlite3_result_text(p
, (char*)zBuf
, -1, SQLITE_TRANSIENT
);
787 #ifndef SQLITE_OMIT_UTF16
788 static void hex16Func(sqlite3_context
*p
, int argc
, sqlite3_value
**argv
){
789 const unsigned short int *z
;
792 z
= sqlite3_value_text16(argv
[0]);
793 for(i
=0; i
<sizeof(zBuf
)/4 - 4 && z
[i
]; i
++){
794 sqlite3_snprintf(sizeof(zBuf
)-i
*4, &zBuf
[i
*4],"%04x", z
[i
]&0xff);
797 sqlite3_result_text(p
, (char*)zBuf
, -1, SQLITE_TRANSIENT
);
802 ** A structure into which to accumulate text.
805 int nAlloc
; /* Space allocated */
806 int nUsed
; /* Space used */
807 char *z
; /* The space */
811 ** Append text to a dstr
813 static void dstrAppend(struct dstr
*p
, const char *z
, int divider
){
814 int n
= (int)strlen(z
);
815 if( p
->nUsed
+ n
+ 2 > p
->nAlloc
){
817 p
->nAlloc
= p
->nAlloc
*2 + n
+ 200;
818 zNew
= sqlite3_realloc(p
->z
, p
->nAlloc
);
821 memset(p
, 0, sizeof(*p
));
826 if( divider
&& p
->nUsed
>0 ){
827 p
->z
[p
->nUsed
++] = divider
;
829 memcpy(&p
->z
[p
->nUsed
], z
, n
+1);
834 ** Invoked for each callback from sqlite3ExecFunc
836 static int execFuncCallback(void *pData
, int argc
, char **argv
, char **NotUsed
){
837 struct dstr
*p
= (struct dstr
*)pData
;
839 for(i
=0; i
<argc
; i
++){
841 dstrAppend(p
, "NULL", ' ');
843 dstrAppend(p
, argv
[i
], ' ');
850 ** Implementation of the x_sqlite_exec() function. This function takes
851 ** a single argument and attempts to execute that argument as SQL code.
852 ** This is illegal and should set the SQLITE_MISUSE flag on the database.
854 ** 2004-Jan-07: We have changed this to make it legal to call sqlite3_exec()
855 ** from within a function call.
857 ** This routine simulates the effect of having two threads attempt to
858 ** use the same database at the same time.
860 static void sqlite3ExecFunc(
861 sqlite3_context
*context
,
866 memset(&x
, 0, sizeof(x
));
867 (void)sqlite3_exec((sqlite3
*)sqlite3_user_data(context
),
868 (char*)sqlite3_value_text(argv
[0]),
869 execFuncCallback
, &x
, 0);
870 sqlite3_result_text(context
, x
.z
, x
.nUsed
, SQLITE_TRANSIENT
);
875 ** Implementation of tkt2213func(), a scalar function that takes exactly
876 ** one argument. It has two interesting features:
878 ** * It calls sqlite3_value_text() 3 times on the argument sqlite3_value*.
879 ** If the three pointers returned are not the same an SQL error is raised.
881 ** * Otherwise it returns a copy of the text representation of its
882 ** argument in such a way as the VDBE representation is a Mem* cell
883 ** with the MEM_Term flag clear.
885 ** Ticket #2213 can therefore be tested by evaluating the following
888 ** tkt2213func(tkt2213func('a string'));
890 static void tkt2213Function(
891 sqlite3_context
*context
,
896 unsigned char const *zText1
;
897 unsigned char const *zText2
;
898 unsigned char const *zText3
;
900 nText
= sqlite3_value_bytes(argv
[0]);
901 zText1
= sqlite3_value_text(argv
[0]);
902 zText2
= sqlite3_value_text(argv
[0]);
903 zText3
= sqlite3_value_text(argv
[0]);
905 if( zText1
!=zText2
|| zText2
!=zText3
){
906 sqlite3_result_error(context
, "tkt2213 is not fixed", -1);
908 char *zCopy
= (char *)sqlite3_malloc(nText
);
909 memcpy(zCopy
, zText1
, nText
);
910 sqlite3_result_text(context
, zCopy
, nText
, sqlite3_free
);
915 ** The following SQL function takes 4 arguments. The 2nd and
916 ** 4th argument must be one of these strings: 'text', 'text16',
917 ** or 'blob' corresponding to API functions
919 ** sqlite3_value_text()
920 ** sqlite3_value_text16()
921 ** sqlite3_value_blob()
923 ** The third argument is a string, either 'bytes' or 'bytes16' or 'noop',
924 ** corresponding to APIs:
926 ** sqlite3_value_bytes()
927 ** sqlite3_value_bytes16()
930 ** The APIs designated by the 2nd through 4th arguments are applied
931 ** to the first argument in order. If the pointers returned by the
932 ** second and fourth are different, this routine returns 1. Otherwise,
933 ** this routine returns 0.
935 ** This function is used to test to see when returned pointers from
936 ** the _text(), _text16() and _blob() APIs become invalidated.
938 static void ptrChngFunction(
939 sqlite3_context
*context
,
945 if( argc
!=4 ) return;
946 zCmd
= (const char*)sqlite3_value_text(argv
[1]);
947 if( zCmd
==0 ) return;
948 if( strcmp(zCmd
,"text")==0 ){
949 p1
= (const void*)sqlite3_value_text(argv
[0]);
950 #ifndef SQLITE_OMIT_UTF16
951 }else if( strcmp(zCmd
, "text16")==0 ){
952 p1
= (const void*)sqlite3_value_text16(argv
[0]);
954 }else if( strcmp(zCmd
, "blob")==0 ){
955 p1
= (const void*)sqlite3_value_blob(argv
[0]);
959 zCmd
= (const char*)sqlite3_value_text(argv
[2]);
960 if( zCmd
==0 ) return;
961 if( strcmp(zCmd
,"bytes")==0 ){
962 sqlite3_value_bytes(argv
[0]);
963 #ifndef SQLITE_OMIT_UTF16
964 }else if( strcmp(zCmd
, "bytes16")==0 ){
965 sqlite3_value_bytes16(argv
[0]);
967 }else if( strcmp(zCmd
, "noop")==0 ){
972 zCmd
= (const char*)sqlite3_value_text(argv
[3]);
973 if( zCmd
==0 ) return;
974 if( strcmp(zCmd
,"text")==0 ){
975 p2
= (const void*)sqlite3_value_text(argv
[0]);
976 #ifndef SQLITE_OMIT_UTF16
977 }else if( strcmp(zCmd
, "text16")==0 ){
978 p2
= (const void*)sqlite3_value_text16(argv
[0]);
980 }else if( strcmp(zCmd
, "blob")==0 ){
981 p2
= (const void*)sqlite3_value_blob(argv
[0]);
985 sqlite3_result_int(context
, p1
!=p2
);
989 ** This SQL function returns a different answer each time it is called, even if
990 ** the arguments are the same.
992 static void nondeterministicFunction(
993 sqlite3_context
*context
,
998 sqlite3_result_int(context
, cnt
++);
1002 ** This SQL function returns the integer value of its argument as a MEM_IntReal
1005 static void intrealFunction(
1006 sqlite3_context
*context
,
1008 sqlite3_value
**argv
1010 sqlite3_int64 v
= sqlite3_value_int64(argv
[0]);
1011 sqlite3_result_int64(context
, v
);
1012 sqlite3_test_control(SQLITE_TESTCTRL_RESULT_INTREAL
, context
);
1016 ** Usage: sqlite3_create_function DB
1018 ** Call the sqlite3_create_function API on the given database in order
1019 ** to create a function named "x_coalesce". This function does the same thing
1020 ** as the "coalesce" function. This function also registers an SQL function
1021 ** named "x_sqlite_exec" that invokes sqlite3_exec(). Invoking sqlite3_exec()
1022 ** in this way is illegal recursion and should raise an SQLITE_MISUSE error.
1023 ** The effect is similar to trying to use the same database connection from
1024 ** two threads at the same time.
1026 ** The original motivation for this routine was to be able to call the
1027 ** sqlite3_create_function function while a query is in progress in order
1028 ** to test the SQLITE_MISUSE detection logic.
1030 static int SQLITE_TCLAPI
test_create_function(
1032 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1033 int argc
, /* Number of arguments */
1034 char **argv
/* Text of each argument */
1040 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1044 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1045 rc
= sqlite3_create_function(db
, "x_coalesce", -1, SQLITE_UTF8
, 0,
1046 t1_ifnullFunc
, 0, 0);
1047 if( rc
==SQLITE_OK
){
1048 rc
= sqlite3_create_function(db
, "hex8", 1, SQLITE_UTF8
| SQLITE_DETERMINISTIC
,
1051 #ifndef SQLITE_OMIT_UTF16
1052 if( rc
==SQLITE_OK
){
1053 rc
= sqlite3_create_function(db
, "hex16", 1, SQLITE_UTF16
| SQLITE_DETERMINISTIC
,
1054 0, hex16Func
, 0, 0);
1057 if( rc
==SQLITE_OK
){
1058 rc
= sqlite3_create_function(db
, "tkt2213func", 1, SQLITE_ANY
, 0,
1059 tkt2213Function
, 0, 0);
1061 if( rc
==SQLITE_OK
){
1062 rc
= sqlite3_create_function(db
, "pointer_change", 4, SQLITE_ANY
, 0,
1063 ptrChngFunction
, 0, 0);
1066 /* Functions counter1() and counter2() have the same implementation - they
1067 ** both return an ascending integer with each call. But counter1() is marked
1068 ** as non-deterministic and counter2() is marked as deterministic.
1070 if( rc
==SQLITE_OK
){
1071 rc
= sqlite3_create_function(db
, "counter1", -1, SQLITE_UTF8
,
1072 0, nondeterministicFunction
, 0, 0);
1074 if( rc
==SQLITE_OK
){
1075 rc
= sqlite3_create_function(db
, "counter2", -1, SQLITE_UTF8
|SQLITE_DETERMINISTIC
,
1076 0, nondeterministicFunction
, 0, 0);
1079 /* The intreal() function converts its argument to an integer and returns
1080 ** it as a MEM_IntReal.
1082 if( rc
==SQLITE_OK
){
1083 rc
= sqlite3_create_function(db
, "intreal", 1, SQLITE_UTF8
,
1084 0, intrealFunction
, 0, 0);
1087 #ifndef SQLITE_OMIT_UTF16
1088 /* Use the sqlite3_create_function16() API here. Mainly for fun, but also
1089 ** because it is not tested anywhere else. */
1090 if( rc
==SQLITE_OK
){
1092 sqlite3_value
*pVal
;
1093 sqlite3_mutex_enter(db
->mutex
);
1094 pVal
= sqlite3ValueNew(db
);
1095 sqlite3ValueSetStr(pVal
, -1, "x_sqlite_exec", SQLITE_UTF8
, SQLITE_STATIC
);
1096 zUtf16
= sqlite3ValueText(pVal
, SQLITE_UTF16NATIVE
);
1097 if( db
->mallocFailed
){
1100 rc
= sqlite3_create_function16(db
, zUtf16
,
1101 1, SQLITE_UTF16
, db
, sqlite3ExecFunc
, 0, 0);
1103 sqlite3ValueFree(pVal
);
1104 sqlite3_mutex_leave(db
->mutex
);
1108 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
1109 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
1114 ** Usage: sqlite3_drop_modules DB ?NAME ...?
1116 ** Invoke the sqlite3_drop_modules(D,L) interface on database
1117 ** connection DB, in order to drop all modules except those named in
1120 static int SQLITE_TCLAPI
test_drop_modules(
1122 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1123 int argc
, /* Number of arguments */
1124 char **argv
/* Text of each argument */
1129 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1133 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1134 #ifndef SQLITE_OMIT_VIRTUALTABLE
1135 sqlite3_drop_modules(db
, argc
>2 ? (const char**)(argv
+2) : 0);
1141 ** Routines to implement the x_count() aggregate function.
1143 ** x_count() counts the number of non-null arguments. But there are
1144 ** some twists for testing purposes.
1146 ** If the argument to x_count() is 40 then a UTF-8 error is reported
1147 ** on the step function. If x_count(41) is seen, then a UTF-16 error
1148 ** is reported on the step function. If the total count is 42, then
1149 ** a UTF-8 error is reported on the finalize function.
1151 typedef struct t1CountCtx t1CountCtx
;
1155 static void t1CountStep(
1156 sqlite3_context
*context
,
1158 sqlite3_value
**argv
1161 p
= sqlite3_aggregate_context(context
, sizeof(*p
));
1162 if( (argc
==0 || SQLITE_NULL
!=sqlite3_value_type(argv
[0]) ) && p
){
1166 int v
= sqlite3_value_int(argv
[0]);
1168 sqlite3_result_error(context
, "value of 40 handed to x_count", -1);
1169 #ifndef SQLITE_OMIT_UTF16
1171 const char zUtf16ErrMsg
[] = { 0, 0x61, 0, 0x62, 0, 0x63, 0, 0, 0};
1172 sqlite3_result_error16(context
, &zUtf16ErrMsg
[1-SQLITE_BIGENDIAN
], -1);
1177 static void t1CountFinalize(sqlite3_context
*context
){
1179 p
= sqlite3_aggregate_context(context
, sizeof(*p
));
1182 sqlite3_result_error(context
, "x_count totals to 42", -1);
1184 sqlite3_result_int(context
, p
? p
->n
: 0);
1189 #ifndef SQLITE_OMIT_DEPRECATED
1190 static void legacyCountStep(
1191 sqlite3_context
*context
,
1193 sqlite3_value
**argv
1198 static void legacyCountFinalize(sqlite3_context
*context
){
1199 sqlite3_result_int(context
, sqlite3_aggregate_count(context
));
1204 ** Usage: sqlite3_create_aggregate DB
1206 ** Call the sqlite3_create_function API on the given database in order
1207 ** to create a function named "x_count". This function is similar
1208 ** to the built-in count() function, with a few special quirks
1209 ** for testing the sqlite3_result_error() APIs.
1211 ** The original motivation for this routine was to be able to call the
1212 ** sqlite3_create_aggregate function while a query is in progress in order
1213 ** to test the SQLITE_MISUSE detection logic. See misuse.test.
1215 ** This routine was later extended to test the use of sqlite3_result_error()
1216 ** within aggregate functions.
1218 ** Later: It is now also extended to register the aggregate function
1219 ** "legacy_count()" with the supplied database handle. This is used
1220 ** to test the deprecated sqlite3_aggregate_count() API.
1222 static int SQLITE_TCLAPI
test_create_aggregate(
1224 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1225 int argc
, /* Number of arguments */
1226 char **argv
/* Text of each argument */
1231 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1235 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1236 rc
= sqlite3_create_function(db
, "x_count", 0, SQLITE_UTF8
, 0, 0,
1237 t1CountStep
,t1CountFinalize
);
1238 if( rc
==SQLITE_OK
){
1239 rc
= sqlite3_create_function(db
, "x_count", 1, SQLITE_UTF8
, 0, 0,
1240 t1CountStep
,t1CountFinalize
);
1242 #ifndef SQLITE_OMIT_DEPRECATED
1243 if( rc
==SQLITE_OK
){
1244 rc
= sqlite3_create_function(db
, "legacy_count", 0, SQLITE_ANY
, 0, 0,
1245 legacyCountStep
, legacyCountFinalize
1249 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
1250 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
1256 ** Usage: printf TEXT
1258 ** Send output to printf. Use this rather than puts to merge the output
1259 ** in the correct sequence with debugging printfs inserted into C code.
1260 ** Puts uses a separate buffer and debugging statements will be out of
1261 ** sequence if it is used.
1263 static int SQLITE_TCLAPI
test_printf(
1265 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1266 int argc
, /* Number of arguments */
1267 char **argv
/* Text of each argument */
1270 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1274 printf("%s\n", argv
[1]);
1281 ** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER
1283 ** Call mprintf with three integer arguments
1285 static int SQLITE_TCLAPI
sqlite3_mprintf_int(
1287 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1288 int argc
, /* Number of arguments */
1289 char **argv
/* Text of each argument */
1294 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1295 " FORMAT INT INT INT\"", 0);
1299 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1301 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1302 Tcl_AppendResult(interp
, z
, 0);
1308 ** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER
1310 ** Call mprintf with three 64-bit integer arguments
1312 static int SQLITE_TCLAPI
sqlite3_mprintf_int64(
1314 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1315 int argc
, /* Number of arguments */
1316 char **argv
/* Text of each argument */
1322 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1323 " FORMAT INT INT INT\"", 0);
1327 if( sqlite3Atoi64(argv
[i
], &a
[i
-2], sqlite3Strlen30(argv
[i
]), SQLITE_UTF8
) ){
1328 Tcl_AppendResult(interp
, "argument is not a valid 64-bit integer", 0);
1332 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1333 Tcl_AppendResult(interp
, z
, 0);
1339 ** Usage: sqlite3_mprintf_long FORMAT INTEGER INTEGER INTEGER
1341 ** Call mprintf with three long integer arguments. This might be the
1342 ** same as sqlite3_mprintf_int or sqlite3_mprintf_int64, depending on
1345 static int SQLITE_TCLAPI
sqlite3_mprintf_long(
1347 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1348 int argc
, /* Number of arguments */
1349 char **argv
/* Text of each argument */
1356 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1357 " FORMAT INT INT INT\"", 0);
1361 if( Tcl_GetInt(interp
, argv
[i
], &b
[i
-2]) ) return TCL_ERROR
;
1362 a
[i
-2] = (long int)b
[i
-2];
1363 a
[i
-2] &= (((u64
)1)<<(sizeof(int)*8))-1;
1365 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1366 Tcl_AppendResult(interp
, z
, 0);
1372 ** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING
1374 ** Call mprintf with two integer arguments and one string argument
1376 static int SQLITE_TCLAPI
sqlite3_mprintf_str(
1378 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1379 int argc
, /* Number of arguments */
1380 char **argv
/* Text of each argument */
1384 if( argc
<4 || argc
>5 ){
1385 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1386 " FORMAT INT INT ?STRING?\"", 0);
1390 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1392 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], argc
>4 ? argv
[4] : NULL
);
1393 Tcl_AppendResult(interp
, z
, 0);
1399 ** Usage: sqlite3_snprintf_str INTEGER FORMAT INTEGER INTEGER STRING
1401 ** Call mprintf with two integer arguments and one string argument
1403 static int SQLITE_TCLAPI
sqlite3_snprintf_str(
1405 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1406 int argc
, /* Number of arguments */
1407 char **argv
/* Text of each argument */
1412 if( argc
<5 || argc
>6 ){
1413 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1414 " INT FORMAT INT INT ?STRING?\"", 0);
1417 if( Tcl_GetInt(interp
, argv
[1], &n
) ) return TCL_ERROR
;
1419 Tcl_AppendResult(interp
, "N must be non-negative", 0);
1423 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-3]) ) return TCL_ERROR
;
1425 z
= sqlite3_malloc( n
+1 );
1426 sqlite3_snprintf(n
, z
, argv
[2], a
[0], a
[1], argc
>4 ? argv
[5] : NULL
);
1427 Tcl_AppendResult(interp
, z
, 0);
1433 ** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE
1435 ** Call mprintf with two integer arguments and one double argument
1437 static int SQLITE_TCLAPI
sqlite3_mprintf_double(
1439 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1440 int argc
, /* Number of arguments */
1441 char **argv
/* Text of each argument */
1447 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1448 " FORMAT INT INT DOUBLE\"", 0);
1452 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1454 if( Tcl_GetDouble(interp
, argv
[4], &r
) ) return TCL_ERROR
;
1455 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], r
);
1456 Tcl_AppendResult(interp
, z
, 0);
1462 ** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE
1464 ** Call mprintf with a single double argument which is the product of the
1465 ** two arguments given above. This is used to generate overflow and underflow
1466 ** doubles to test that they are converted properly.
1468 static int SQLITE_TCLAPI
sqlite3_mprintf_scaled(
1470 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1471 int argc
, /* Number of arguments */
1472 char **argv
/* Text of each argument */
1478 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1479 " FORMAT DOUBLE DOUBLE\"", 0);
1483 if( Tcl_GetDouble(interp
, argv
[i
], &r
[i
-2]) ) return TCL_ERROR
;
1485 z
= sqlite3_mprintf(argv
[1], r
[0]*r
[1]);
1486 Tcl_AppendResult(interp
, z
, 0);
1492 ** Usage: sqlite3_mprintf_stronly FORMAT STRING
1494 ** Call mprintf with a single double argument which is the product of the
1495 ** two arguments given above. This is used to generate overflow and underflow
1496 ** doubles to test that they are converted properly.
1498 static int SQLITE_TCLAPI
sqlite3_mprintf_stronly(
1500 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1501 int argc
, /* Number of arguments */
1502 char **argv
/* Text of each argument */
1506 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1507 " FORMAT STRING\"", 0);
1510 z
= sqlite3_mprintf(argv
[1], argv
[2]);
1511 Tcl_AppendResult(interp
, z
, 0);
1517 ** Usage: sqlite3_mprintf_hexdouble FORMAT HEX
1519 ** Call mprintf with a single double argument which is derived from the
1520 ** hexadecimal encoding of an IEEE double.
1522 static int SQLITE_TCLAPI
sqlite3_mprintf_hexdouble(
1524 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1525 int argc
, /* Number of arguments */
1526 char **argv
/* Text of each argument */
1530 unsigned int x1
, x2
;
1533 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1534 " FORMAT STRING\"", 0);
1537 if( sscanf(argv
[2], "%08x%08x", &x2
, &x1
)!=2 ){
1538 Tcl_AppendResult(interp
, "2nd argument should be 16-characters of hex", 0);
1543 memcpy(&r
, &d
, sizeof(r
));
1544 z
= sqlite3_mprintf(argv
[1], r
);
1545 Tcl_AppendResult(interp
, z
, 0);
1551 ** Usage: sqlite3_enable_shared_cache ?BOOLEAN?
1554 #if !defined(SQLITE_OMIT_SHARED_CACHE)
1555 static int SQLITE_TCLAPI
test_enable_shared(
1556 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1557 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1558 int objc
, /* Number of arguments */
1559 Tcl_Obj
*CONST objv
[] /* Command arguments */
1565 if( objc
!=2 && objc
!=1 ){
1566 Tcl_WrongNumArgs(interp
, 1, objv
, "?BOOLEAN?");
1569 ret
= sqlite3GlobalConfig
.sharedCacheEnabled
;
1572 if( Tcl_GetBooleanFromObj(interp
, objv
[1], &enable
) ){
1575 rc
= sqlite3_enable_shared_cache(enable
);
1576 if( rc
!=SQLITE_OK
){
1577 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(rc
), TCL_STATIC
);
1581 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(ret
));
1589 ** Usage: sqlite3_extended_result_codes DB BOOLEAN
1592 static int SQLITE_TCLAPI
test_extended_result_codes(
1593 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1594 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1595 int objc
, /* Number of arguments */
1596 Tcl_Obj
*CONST objv
[] /* Command arguments */
1602 Tcl_WrongNumArgs(interp
, 1, objv
, "DB BOOLEAN");
1605 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1606 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &enable
) ) return TCL_ERROR
;
1607 sqlite3_extended_result_codes(db
, enable
);
1612 ** Usage: sqlite3_libversion_number
1615 static int SQLITE_TCLAPI
test_libversion_number(
1616 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1617 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1618 int objc
, /* Number of arguments */
1619 Tcl_Obj
*CONST objv
[] /* Command arguments */
1621 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_libversion_number()));
1626 ** Usage: sqlite3_table_column_metadata DB dbname tblname colname
1629 static int SQLITE_TCLAPI
test_table_column_metadata(
1630 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1631 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1632 int objc
, /* Number of arguments */
1633 Tcl_Obj
*CONST objv
[] /* Command arguments */
1642 const char *zDatatype
;
1643 const char *zCollseq
;
1648 if( objc
!=5 && objc
!=4 ){
1649 Tcl_WrongNumArgs(interp
, 1, objv
, "DB dbname tblname colname");
1652 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1653 zDb
= Tcl_GetString(objv
[2]);
1654 zTbl
= Tcl_GetString(objv
[3]);
1655 zCol
= objc
==5 ? Tcl_GetString(objv
[4]) : 0;
1657 if( strlen(zDb
)==0 ) zDb
= 0;
1659 rc
= sqlite3_table_column_metadata(db
, zDb
, zTbl
, zCol
,
1660 &zDatatype
, &zCollseq
, ¬null
, &primarykey
, &autoincrement
);
1662 if( rc
!=SQLITE_OK
){
1663 Tcl_AppendResult(interp
, sqlite3_errmsg(db
), 0);
1667 pRet
= Tcl_NewObj();
1668 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zDatatype
, -1));
1669 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zCollseq
, -1));
1670 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(notnull
));
1671 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(primarykey
));
1672 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(autoincrement
));
1673 Tcl_SetObjResult(interp
, pRet
);
1678 #ifndef SQLITE_OMIT_INCRBLOB
1680 static int SQLITE_TCLAPI
blobHandleFromObj(
1683 sqlite3_blob
**ppBlob
1688 z
= Tcl_GetStringFromObj(pObj
, &n
);
1693 Tcl_Channel channel
;
1694 ClientData instanceData
;
1696 channel
= Tcl_GetChannel(interp
, z
, ¬Used
);
1697 if( !channel
) return TCL_ERROR
;
1700 Tcl_Seek(channel
, 0, SEEK_SET
);
1702 instanceData
= Tcl_GetChannelInstanceData(channel
);
1703 *ppBlob
= *((sqlite3_blob
**)instanceData
);
1709 static int SQLITE_TCLAPI
test_blob_reopen(
1710 ClientData clientData
, /* Not used */
1711 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1712 int objc
, /* Number of arguments */
1713 Tcl_Obj
*CONST objv
[] /* Command arguments */
1716 sqlite3_blob
*pBlob
;
1720 Tcl_WrongNumArgs(interp
, 1, objv
, "CHANNEL ROWID");
1724 if( blobHandleFromObj(interp
, objv
[1], &pBlob
) ) return TCL_ERROR
;
1725 if( Tcl_GetWideIntFromObj(interp
, objv
[2], &iRowid
) ) return TCL_ERROR
;
1727 rc
= sqlite3_blob_reopen(pBlob
, iRowid
);
1728 if( rc
!=SQLITE_OK
){
1729 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
1732 return (rc
==SQLITE_OK
? TCL_OK
: TCL_ERROR
);
1738 ** Usage: sqlite3_create_collation_v2 DB-HANDLE NAME CMP-PROC DEL-PROC
1740 ** This Tcl proc is used for testing the experimental
1741 ** sqlite3_create_collation_v2() interface.
1743 struct TestCollationX
{
1748 typedef struct TestCollationX TestCollationX
;
1749 static void testCreateCollationDel(void *pCtx
){
1750 TestCollationX
*p
= (TestCollationX
*)pCtx
;
1752 int rc
= Tcl_EvalObjEx(p
->interp
, p
->pDel
, TCL_EVAL_DIRECT
|TCL_EVAL_GLOBAL
);
1754 Tcl_BackgroundError(p
->interp
);
1757 Tcl_DecrRefCount(p
->pCmp
);
1758 Tcl_DecrRefCount(p
->pDel
);
1759 sqlite3_free((void *)p
);
1761 static int testCreateCollationCmp(
1768 TestCollationX
*p
= (TestCollationX
*)pCtx
;
1769 Tcl_Obj
*pScript
= Tcl_DuplicateObj(p
->pCmp
);
1772 Tcl_IncrRefCount(pScript
);
1773 Tcl_ListObjAppendElement(0, pScript
, Tcl_NewStringObj((char *)zLeft
, nLeft
));
1774 Tcl_ListObjAppendElement(0, pScript
, Tcl_NewStringObj((char *)zRight
,nRight
));
1776 if( TCL_OK
!=Tcl_EvalObjEx(p
->interp
, pScript
, TCL_EVAL_DIRECT
|TCL_EVAL_GLOBAL
)
1777 || TCL_OK
!=Tcl_GetIntFromObj(p
->interp
, Tcl_GetObjResult(p
->interp
), &iRes
)
1779 Tcl_BackgroundError(p
->interp
);
1781 Tcl_DecrRefCount(pScript
);
1785 static int SQLITE_TCLAPI
test_create_collation_v2(
1786 ClientData clientData
, /* Not used */
1787 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1788 int objc
, /* Number of arguments */
1789 Tcl_Obj
*CONST objv
[] /* Command arguments */
1796 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE NAME CMP-PROC DEL-PROC");
1799 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1801 p
= (TestCollationX
*)sqlite3_malloc(sizeof(TestCollationX
));
1805 Tcl_IncrRefCount(p
->pCmp
);
1806 Tcl_IncrRefCount(p
->pDel
);
1808 rc
= sqlite3_create_collation_v2(db
, Tcl_GetString(objv
[2]), 16,
1809 (void *)p
, testCreateCollationCmp
, testCreateCollationDel
1811 if( rc
!=SQLITE_MISUSE
){
1812 Tcl_AppendResult(interp
, "sqlite3_create_collate_v2() failed to detect "
1813 "an invalid encoding", (char*)0);
1816 rc
= sqlite3_create_collation_v2(db
, Tcl_GetString(objv
[2]), SQLITE_UTF8
,
1817 (void *)p
, testCreateCollationCmp
, testCreateCollationDel
1823 ** USAGE: sqlite3_create_function_v2 DB NAME NARG ENC ?SWITCHES?
1825 ** Available switches are:
1832 typedef struct CreateFunctionV2 CreateFunctionV2
;
1833 struct CreateFunctionV2
{
1835 Tcl_Obj
*pFunc
; /* Script for function invocation */
1836 Tcl_Obj
*pStep
; /* Script for agg. step invocation */
1837 Tcl_Obj
*pFinal
; /* Script for agg. finalization invocation */
1838 Tcl_Obj
*pDestroy
; /* Destructor script */
1840 static void cf2Func(sqlite3_context
*ctx
, int nArg
, sqlite3_value
**aArg
){
1842 static void cf2Step(sqlite3_context
*ctx
, int nArg
, sqlite3_value
**aArg
){
1844 static void cf2Final(sqlite3_context
*ctx
){
1846 static void cf2Destroy(void *pUser
){
1847 CreateFunctionV2
*p
= (CreateFunctionV2
*)pUser
;
1849 if( p
->interp
&& p
->pDestroy
){
1850 int rc
= Tcl_EvalObjEx(p
->interp
, p
->pDestroy
, 0);
1851 if( rc
!=TCL_OK
) Tcl_BackgroundError(p
->interp
);
1854 if( p
->pFunc
) Tcl_DecrRefCount(p
->pFunc
);
1855 if( p
->pStep
) Tcl_DecrRefCount(p
->pStep
);
1856 if( p
->pFinal
) Tcl_DecrRefCount(p
->pFinal
);
1857 if( p
->pDestroy
) Tcl_DecrRefCount(p
->pDestroy
);
1860 static int SQLITE_TCLAPI
test_create_function_v2(
1861 ClientData clientData
, /* Not used */
1862 Tcl_Interp
*interp
, /* The invoking TCL interpreter */
1863 int objc
, /* Number of arguments */
1864 Tcl_Obj
*CONST objv
[] /* Command arguments */
1870 CreateFunctionV2
*p
;
1878 {"utf8", SQLITE_UTF8
},
1879 {"utf16", SQLITE_UTF16
},
1880 {"utf16le", SQLITE_UTF16LE
},
1881 {"utf16be", SQLITE_UTF16BE
},
1882 {"any", SQLITE_ANY
},
1886 if( objc
<5 || (objc
%2)==0 ){
1887 Tcl_WrongNumArgs(interp
, 1, objv
, "DB NAME NARG ENC SWITCHES...");
1891 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1892 zFunc
= Tcl_GetString(objv
[2]);
1893 if( Tcl_GetIntFromObj(interp
, objv
[3], &nArg
) ) return TCL_ERROR
;
1894 if( Tcl_GetIndexFromObjStruct(interp
, objv
[4], aEnc
, sizeof(aEnc
[0]),
1895 "encoding", 0, &enc
)
1899 enc
= aEnc
[enc
].enc
;
1901 p
= sqlite3_malloc(sizeof(CreateFunctionV2
));
1903 memset(p
, 0, sizeof(CreateFunctionV2
));
1906 for(i
=5; i
<objc
; i
+=2){
1908 const char *azSwitch
[] = {"-func", "-step", "-final", "-destroy", 0};
1909 if( Tcl_GetIndexFromObj(interp
, objv
[i
], azSwitch
, "switch", 0, &iSwitch
) ){
1915 case 0: p
->pFunc
= objv
[i
+1]; break;
1916 case 1: p
->pStep
= objv
[i
+1]; break;
1917 case 2: p
->pFinal
= objv
[i
+1]; break;
1918 case 3: p
->pDestroy
= objv
[i
+1]; break;
1921 if( p
->pFunc
) p
->pFunc
= Tcl_DuplicateObj(p
->pFunc
);
1922 if( p
->pStep
) p
->pStep
= Tcl_DuplicateObj(p
->pStep
);
1923 if( p
->pFinal
) p
->pFinal
= Tcl_DuplicateObj(p
->pFinal
);
1924 if( p
->pDestroy
) p
->pDestroy
= Tcl_DuplicateObj(p
->pDestroy
);
1926 if( p
->pFunc
) Tcl_IncrRefCount(p
->pFunc
);
1927 if( p
->pStep
) Tcl_IncrRefCount(p
->pStep
);
1928 if( p
->pFinal
) Tcl_IncrRefCount(p
->pFinal
);
1929 if( p
->pDestroy
) Tcl_IncrRefCount(p
->pDestroy
);
1931 rc
= sqlite3_create_function_v2(db
, zFunc
, nArg
, enc
, (void *)p
,
1932 (p
->pFunc
? cf2Func
: 0),
1933 (p
->pStep
? cf2Step
: 0),
1934 (p
->pFinal
? cf2Final
: 0),
1937 if( rc
!=SQLITE_OK
){
1938 Tcl_ResetResult(interp
);
1939 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
1946 ** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC?
1948 static int SQLITE_TCLAPI
test_load_extension(
1949 ClientData clientData
, /* Not used */
1950 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1951 int objc
, /* Number of arguments */
1952 Tcl_Obj
*CONST objv
[] /* Command arguments */
1954 Tcl_CmdInfo cmdInfo
;
1962 if( objc
!=4 && objc
!=3 ){
1963 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE FILE ?PROC?");
1966 zDb
= Tcl_GetString(objv
[1]);
1967 zFile
= Tcl_GetString(objv
[2]);
1969 zProc
= Tcl_GetString(objv
[3]);
1972 /* Extract the C database handle from the Tcl command name */
1973 if( !Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
1974 Tcl_AppendResult(interp
, "command not found: ", zDb
, (char*)0);
1977 db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
1980 /* Call the underlying C function. If an error occurs, set rc to
1981 ** TCL_ERROR and load any error string into the interpreter. If no
1982 ** error occurs, set rc to TCL_OK.
1984 #ifdef SQLITE_OMIT_LOAD_EXTENSION
1986 zErr
= sqlite3_mprintf("this build omits sqlite3_load_extension()");
1990 rc
= sqlite3_load_extension(db
, zFile
, zProc
, &zErr
);
1992 if( rc
!=SQLITE_OK
){
1993 Tcl_SetResult(interp
, zErr
? zErr
: "", TCL_VOLATILE
);
2004 ** Usage: sqlite3_enable_load_extension DB-HANDLE ONOFF
2006 static int SQLITE_TCLAPI
test_enable_load(
2007 ClientData clientData
, /* Not used */
2008 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2009 int objc
, /* Number of arguments */
2010 Tcl_Obj
*CONST objv
[] /* Command arguments */
2012 Tcl_CmdInfo cmdInfo
;
2018 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE ONOFF");
2021 zDb
= Tcl_GetString(objv
[1]);
2023 /* Extract the C database handle from the Tcl command name */
2024 if( !Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
2025 Tcl_AppendResult(interp
, "command not found: ", zDb
, (char*)0);
2028 db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
2031 /* Get the onoff parameter */
2032 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &onoff
) ){
2036 #ifdef SQLITE_OMIT_LOAD_EXTENSION
2037 Tcl_AppendResult(interp
, "this build omits sqlite3_load_extension()");
2040 sqlite3_enable_load_extension(db
, onoff
);
2046 ** Usage: sqlite_abort
2048 ** Shutdown the process immediately. This is not a clean shutdown.
2049 ** This command is used to test the recoverability of a database in
2050 ** the event of a program crash.
2052 static int SQLITE_TCLAPI
sqlite_abort(
2054 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2055 int argc
, /* Number of arguments */
2056 char **argv
/* Text of each argument */
2058 #if defined(_MSC_VER)
2059 /* We do this, otherwise the test will halt with a popup message
2060 * that we have to click away before the test will continue.
2062 _set_abort_behavior( 0, _CALL_REPORTFAULT
);
2065 assert( interp
==0 ); /* This will always fail */
2070 ** The following routine is a user-defined SQL function whose purpose
2071 ** is to test the sqlite_set_result() API.
2073 static void testFunc(sqlite3_context
*context
, int argc
, sqlite3_value
**argv
){
2075 const char *zArg0
= (char*)sqlite3_value_text(argv
[0]);
2077 if( 0==sqlite3StrICmp(zArg0
, "int") ){
2078 sqlite3_result_int(context
, sqlite3_value_int(argv
[1]));
2079 }else if( sqlite3StrICmp(zArg0
,"int64")==0 ){
2080 sqlite3_result_int64(context
, sqlite3_value_int64(argv
[1]));
2081 }else if( sqlite3StrICmp(zArg0
,"string")==0 ){
2082 sqlite3_result_text(context
, (char*)sqlite3_value_text(argv
[1]), -1,
2084 }else if( sqlite3StrICmp(zArg0
,"double")==0 ){
2085 sqlite3_result_double(context
, sqlite3_value_double(argv
[1]));
2086 }else if( sqlite3StrICmp(zArg0
,"null")==0 ){
2087 sqlite3_result_null(context
);
2088 }else if( sqlite3StrICmp(zArg0
,"value")==0 ){
2089 sqlite3_result_value(context
, argv
[sqlite3_value_int(argv
[1])]);
2102 sqlite3_result_error(context
,"first argument should be one of: "
2103 "int int64 string double null value", -1);
2107 ** Usage: sqlite_register_test_function DB NAME
2109 ** Register the test SQL function on the database DB under the name NAME.
2111 static int SQLITE_TCLAPI
test_register_func(
2113 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2114 int argc
, /* Number of arguments */
2115 char **argv
/* Text of each argument */
2120 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
2121 " DB FUNCTION-NAME", 0);
2124 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
2125 rc
= sqlite3_create_function(db
, argv
[2], -1, SQLITE_UTF8
, 0,
2128 Tcl_AppendResult(interp
, sqlite3ErrStr(rc
), 0);
2131 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
2136 ** Usage: sqlite3_finalize STMT
2138 ** Finalize a statement handle.
2140 static int SQLITE_TCLAPI
test_finalize(
2144 Tcl_Obj
*CONST objv
[]
2146 sqlite3_stmt
*pStmt
;
2151 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2152 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2156 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2159 db
= StmtToDb(pStmt
);
2161 rc
= sqlite3_finalize(pStmt
);
2162 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
2163 if( db
&& sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
2168 ** Usage: sqlite3_stmt_status STMT CODE RESETFLAG
2170 ** Get the value of a status counter from a statement.
2172 static int SQLITE_TCLAPI
test_stmt_status(
2176 Tcl_Obj
*CONST objv
[]
2179 int i
, op
= 0, resetFlag
;
2180 const char *zOpName
;
2181 sqlite3_stmt
*pStmt
;
2183 static const struct {
2187 { "SQLITE_STMTSTATUS_FULLSCAN_STEP", SQLITE_STMTSTATUS_FULLSCAN_STEP
},
2188 { "SQLITE_STMTSTATUS_SORT", SQLITE_STMTSTATUS_SORT
},
2189 { "SQLITE_STMTSTATUS_AUTOINDEX", SQLITE_STMTSTATUS_AUTOINDEX
},
2190 { "SQLITE_STMTSTATUS_VM_STEP", SQLITE_STMTSTATUS_VM_STEP
},
2191 { "SQLITE_STMTSTATUS_REPREPARE", SQLITE_STMTSTATUS_REPREPARE
},
2192 { "SQLITE_STMTSTATUS_RUN", SQLITE_STMTSTATUS_RUN
},
2193 { "SQLITE_STMTSTATUS_MEMUSED", SQLITE_STMTSTATUS_MEMUSED
},
2196 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT PARAMETER RESETFLAG");
2199 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2200 zOpName
= Tcl_GetString(objv
[2]);
2201 for(i
=0; i
<ArraySize(aOp
); i
++){
2202 if( strcmp(aOp
[i
].zName
, zOpName
)==0 ){
2207 if( i
>=ArraySize(aOp
) ){
2208 if( Tcl_GetIntFromObj(interp
, objv
[2], &op
) ) return TCL_ERROR
;
2210 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &resetFlag
) ) return TCL_ERROR
;
2211 iValue
= sqlite3_stmt_status(pStmt
, op
, resetFlag
);
2212 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iValue
));
2216 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
2218 ** Usage: sqlite3_stmt_scanstatus STMT IDX
2220 static int SQLITE_TCLAPI
test_stmt_scanstatus(
2224 Tcl_Obj
*CONST objv
[]
2226 sqlite3_stmt
*pStmt
; /* First argument */
2227 int idx
; /* Second argument */
2230 const char *zExplain
;
2231 sqlite3_int64 nLoop
;
2232 sqlite3_int64 nVisit
;
2237 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX");
2240 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2241 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
2243 res
= sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_NLOOP
, (void*)&nLoop
);
2245 Tcl_Obj
*pRet
= Tcl_NewObj();
2246 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nLoop", -1));
2247 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nLoop
));
2248 sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_NVISIT
, (void*)&nVisit
);
2249 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nVisit", -1));
2250 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nVisit
));
2251 sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_EST
, (void*)&rEst
);
2252 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nEst", -1));
2253 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewDoubleObj(rEst
));
2254 sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_NAME
, (void*)&zName
);
2255 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("zName", -1));
2256 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zName
, -1));
2257 sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_EXPLAIN
, (void*)&zExplain
);
2258 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("zExplain", -1));
2259 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zExplain
, -1));
2260 Tcl_SetObjResult(interp
, pRet
);
2262 Tcl_ResetResult(interp
);
2268 ** Usage: sqlite3_stmt_scanstatus_reset STMT
2270 static int SQLITE_TCLAPI
test_stmt_scanstatus_reset(
2274 Tcl_Obj
*CONST objv
[]
2276 sqlite3_stmt
*pStmt
; /* First argument */
2278 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
2281 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2282 sqlite3_stmt_scanstatus_reset(pStmt
);
2287 #ifdef SQLITE_ENABLE_SQLLOG
2289 ** Usage: sqlite3_config_sqllog
2291 ** Zero the SQLITE_CONFIG_SQLLOG configuration
2293 static int SQLITE_TCLAPI
test_config_sqllog(
2297 Tcl_Obj
*CONST objv
[]
2300 Tcl_WrongNumArgs(interp
, 1, objv
, "");
2303 sqlite3_config(SQLITE_CONFIG_SQLLOG
, 0, 0);
2309 ** Usage: sqlite3_config_sorterref
2311 ** Set the SQLITE_CONFIG_SORTERREF_SIZE configuration option
2313 static int SQLITE_TCLAPI
test_config_sorterref(
2317 Tcl_Obj
*CONST objv
[]
2321 Tcl_WrongNumArgs(interp
, 1, objv
, "NBYTE");
2324 if( Tcl_GetIntFromObj(interp
, objv
[1], &iVal
) ) return TCL_ERROR
;
2325 sqlite3_config(SQLITE_CONFIG_SORTERREF_SIZE
, iVal
);
2330 ** Usage: vfs_current_time_int64
2332 ** Return the value returned by the default VFS's xCurrentTimeInt64 method.
2334 static int SQLITE_TCLAPI
vfsCurrentTimeInt64(
2338 Tcl_Obj
*CONST objv
[]
2341 sqlite3_vfs
*pVfs
= sqlite3_vfs_find(0);
2343 Tcl_WrongNumArgs(interp
, 1, objv
, "");
2346 pVfs
->xCurrentTimeInt64(pVfs
, &t
);
2347 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(t
));
2351 #ifdef SQLITE_ENABLE_SNAPSHOT
2353 ** Usage: sqlite3_snapshot_get DB DBNAME
2355 static int SQLITE_TCLAPI
test_snapshot_get(
2359 Tcl_Obj
*CONST objv
[]
2364 sqlite3_snapshot
*pSnapshot
= 0;
2367 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2370 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2371 zName
= Tcl_GetString(objv
[2]);
2373 rc
= sqlite3_snapshot_get(db
, zName
, &pSnapshot
);
2374 if( rc
!=SQLITE_OK
){
2375 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2379 if( sqlite3TestMakePointerStr(interp
, zBuf
, pSnapshot
) ) return TCL_ERROR
;
2380 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zBuf
, -1));
2384 #endif /* SQLITE_ENABLE_SNAPSHOT */
2386 #ifdef SQLITE_ENABLE_SNAPSHOT
2388 ** Usage: sqlite3_snapshot_recover DB DBNAME
2390 static int SQLITE_TCLAPI
test_snapshot_recover(
2394 Tcl_Obj
*CONST objv
[]
2401 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2404 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2405 zName
= Tcl_GetString(objv
[2]);
2407 rc
= sqlite3_snapshot_recover(db
, zName
);
2408 if( rc
!=SQLITE_OK
){
2409 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2412 Tcl_ResetResult(interp
);
2416 #endif /* SQLITE_ENABLE_SNAPSHOT */
2418 #ifdef SQLITE_ENABLE_SNAPSHOT
2420 ** Usage: sqlite3_snapshot_open DB DBNAME SNAPSHOT
2422 static int SQLITE_TCLAPI
test_snapshot_open(
2426 Tcl_Obj
*CONST objv
[]
2431 sqlite3_snapshot
*pSnapshot
;
2434 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SNAPSHOT");
2437 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2438 zName
= Tcl_GetString(objv
[2]);
2439 pSnapshot
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[3]));
2441 rc
= sqlite3_snapshot_open(db
, zName
, pSnapshot
);
2442 if( rc
!=SQLITE_OK
){
2443 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2446 Tcl_ResetResult(interp
);
2450 #endif /* SQLITE_ENABLE_SNAPSHOT */
2452 #ifdef SQLITE_ENABLE_SNAPSHOT
2454 ** Usage: sqlite3_snapshot_free SNAPSHOT
2456 static int SQLITE_TCLAPI
test_snapshot_free(
2460 Tcl_Obj
*CONST objv
[]
2462 sqlite3_snapshot
*pSnapshot
;
2464 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT");
2467 pSnapshot
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[1]));
2468 sqlite3_snapshot_free(pSnapshot
);
2471 #endif /* SQLITE_ENABLE_SNAPSHOT */
2473 #ifdef SQLITE_ENABLE_SNAPSHOT
2475 ** Usage: sqlite3_snapshot_cmp SNAPSHOT1 SNAPSHOT2
2477 static int SQLITE_TCLAPI
test_snapshot_cmp(
2481 Tcl_Obj
*CONST objv
[]
2484 sqlite3_snapshot
*p1
;
2485 sqlite3_snapshot
*p2
;
2487 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT1 SNAPSHOT2");
2490 p1
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[1]));
2491 p2
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[2]));
2492 res
= sqlite3_snapshot_cmp(p1
, p2
);
2493 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
2496 #endif /* SQLITE_ENABLE_SNAPSHOT */
2498 #ifdef SQLITE_ENABLE_SNAPSHOT
2500 ** Usage: sqlite3_snapshot_get_blob DB DBNAME
2502 static int SQLITE_TCLAPI
test_snapshot_get_blob(
2506 Tcl_Obj
*CONST objv
[]
2511 sqlite3_snapshot
*pSnapshot
= 0;
2514 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2517 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2518 zName
= Tcl_GetString(objv
[2]);
2520 rc
= sqlite3_snapshot_get(db
, zName
, &pSnapshot
);
2521 if( rc
!=SQLITE_OK
){
2522 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2525 Tcl_SetObjResult(interp
,
2526 Tcl_NewByteArrayObj((unsigned char*)pSnapshot
, sizeof(sqlite3_snapshot
))
2528 sqlite3_snapshot_free(pSnapshot
);
2532 #endif /* SQLITE_ENABLE_SNAPSHOT */
2534 #ifdef SQLITE_ENABLE_SNAPSHOT
2536 ** Usage: sqlite3_snapshot_open_blob DB DBNAME SNAPSHOT
2538 static int SQLITE_TCLAPI
test_snapshot_open_blob(
2542 Tcl_Obj
*CONST objv
[]
2547 unsigned char *pBlob
;
2551 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SNAPSHOT");
2554 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2555 zName
= Tcl_GetString(objv
[2]);
2556 pBlob
= Tcl_GetByteArrayFromObj(objv
[3], &nBlob
);
2557 if( nBlob
!=sizeof(sqlite3_snapshot
) ){
2558 Tcl_AppendResult(interp
, "bad SNAPSHOT", 0);
2561 rc
= sqlite3_snapshot_open(db
, zName
, (sqlite3_snapshot
*)pBlob
);
2562 if( rc
!=SQLITE_OK
){
2563 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2568 #endif /* SQLITE_ENABLE_SNAPSHOT */
2570 #ifdef SQLITE_ENABLE_SNAPSHOT
2572 ** Usage: sqlite3_snapshot_cmp_blob SNAPSHOT1 SNAPSHOT2
2574 static int SQLITE_TCLAPI
test_snapshot_cmp_blob(
2578 Tcl_Obj
*CONST objv
[]
2587 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT1 SNAPSHOT2");
2591 p1
= Tcl_GetByteArrayFromObj(objv
[1], &n1
);
2592 p2
= Tcl_GetByteArrayFromObj(objv
[2], &n2
);
2594 if( n1
!=sizeof(sqlite3_snapshot
) || n1
!=n2
){
2595 Tcl_AppendResult(interp
, "bad SNAPSHOT", 0);
2599 res
= sqlite3_snapshot_cmp((sqlite3_snapshot
*)p1
, (sqlite3_snapshot
*)p2
);
2600 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
2603 #endif /* SQLITE_ENABLE_SNAPSHOT */
2606 ** Usage: sqlite3_delete_database FILENAME
2608 int sqlite3_delete_database(const char*); /* in test_delete.c */
2609 static int SQLITE_TCLAPI
test_delete_database(
2613 Tcl_Obj
*CONST objv
[]
2618 Tcl_WrongNumArgs(interp
, 1, objv
, "FILE");
2621 zFile
= (const char*)Tcl_GetString(objv
[1]);
2622 rc
= sqlite3_delete_database(zFile
);
2624 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2629 ** Usage: atomic_batch_write PATH
2631 static int SQLITE_TCLAPI
test_atomic_batch_write(
2635 Tcl_Obj
*CONST objv
[]
2637 char *zFile
= 0; /* Path to file to test */
2638 sqlite3
*db
= 0; /* Database handle */
2639 sqlite3_file
*pFd
= 0; /* SQLite fd open on zFile */
2640 int bRes
= 0; /* Integer result of this command */
2641 int dc
= 0; /* Device-characteristics mask */
2642 int rc
; /* sqlite3_open() return code */
2645 Tcl_WrongNumArgs(interp
, 1, objv
, "PATH");
2648 zFile
= Tcl_GetString(objv
[1]);
2650 rc
= sqlite3_open(zFile
, &db
);
2651 if( rc
!=SQLITE_OK
){
2652 Tcl_AppendResult(interp
, sqlite3_errmsg(db
), 0);
2657 rc
= sqlite3_file_control(db
, "main", SQLITE_FCNTL_FILE_POINTER
, (void*)&pFd
);
2658 dc
= pFd
->pMethods
->xDeviceCharacteristics(pFd
);
2659 if( dc
& SQLITE_IOCAP_BATCH_ATOMIC
){
2663 Tcl_SetObjResult(interp
, Tcl_NewIntObj(bRes
));
2669 ** Usage: sqlite3_next_stmt DB STMT
2671 ** Return the next statment in sequence after STMT.
2673 static int SQLITE_TCLAPI
test_next_stmt(
2677 Tcl_Obj
*CONST objv
[]
2679 sqlite3_stmt
*pStmt
;
2684 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2685 Tcl_GetStringFromObj(objv
[0], 0), " DB STMT", 0);
2689 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2690 if( getStmtPointer(interp
, Tcl_GetString(objv
[2]), &pStmt
) ) return TCL_ERROR
;
2691 pStmt
= sqlite3_next_stmt(db
, pStmt
);
2693 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
2694 Tcl_AppendResult(interp
, zBuf
, 0);
2700 ** Usage: sqlite3_stmt_readonly STMT
2702 ** Return true if STMT is a NULL pointer or a pointer to a statement
2703 ** that is guaranteed to leave the database unmodified.
2705 static int SQLITE_TCLAPI
test_stmt_readonly(
2709 Tcl_Obj
*CONST objv
[]
2711 sqlite3_stmt
*pStmt
;
2715 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2716 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2720 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2721 rc
= sqlite3_stmt_readonly(pStmt
);
2722 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(rc
));
2727 ** Usage: sqlite3_stmt_isexplain STMT
2729 ** Return 1, 2, or 0 respectively if STMT is an EXPLAIN statement, an
2730 ** EXPLAIN QUERY PLAN statement or an ordinary statement or NULL pointer.
2732 static int SQLITE_TCLAPI
test_stmt_isexplain(
2736 Tcl_Obj
*CONST objv
[]
2738 sqlite3_stmt
*pStmt
;
2742 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2743 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2747 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2748 rc
= sqlite3_stmt_isexplain(pStmt
);
2749 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
2754 ** Usage: sqlite3_stmt_busy STMT
2756 ** Return true if STMT is a non-NULL pointer to a statement
2757 ** that has been stepped but not to completion.
2759 static int SQLITE_TCLAPI
test_stmt_busy(
2763 Tcl_Obj
*CONST objv
[]
2765 sqlite3_stmt
*pStmt
;
2769 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2770 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2774 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2775 rc
= sqlite3_stmt_busy(pStmt
);
2776 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(rc
));
2781 ** Usage: uses_stmt_journal STMT
2783 ** Return true if STMT uses a statement journal.
2785 static int SQLITE_TCLAPI
uses_stmt_journal(
2789 Tcl_Obj
*CONST objv
[]
2791 sqlite3_stmt
*pStmt
;
2794 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2795 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2799 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2800 sqlite3_stmt_readonly(pStmt
);
2801 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(((Vdbe
*)pStmt
)->usesStmtJournal
));
2807 ** Usage: sqlite3_reset STMT
2809 ** Reset a statement handle.
2811 static int SQLITE_TCLAPI
test_reset(
2815 Tcl_Obj
*CONST objv
[]
2817 sqlite3_stmt
*pStmt
;
2821 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2822 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2826 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2828 rc
= sqlite3_reset(pStmt
);
2829 if( pStmt
&& sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ){
2832 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
2842 ** Usage: sqlite3_expired STMT
2844 ** Return TRUE if a recompilation of the statement is recommended.
2846 static int SQLITE_TCLAPI
test_expired(
2850 Tcl_Obj
*CONST objv
[]
2852 #ifndef SQLITE_OMIT_DEPRECATED
2853 sqlite3_stmt
*pStmt
;
2855 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2856 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2859 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2860 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(sqlite3_expired(pStmt
)));
2866 ** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT
2868 ** Transfer all bindings from FROMSTMT over to TOSTMT
2870 static int SQLITE_TCLAPI
test_transfer_bind(
2874 Tcl_Obj
*CONST objv
[]
2876 #ifndef SQLITE_OMIT_DEPRECATED
2877 sqlite3_stmt
*pStmt1
, *pStmt2
;
2879 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2880 Tcl_GetStringFromObj(objv
[0], 0), " FROM-STMT TO-STMT", 0);
2883 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt1
)) return TCL_ERROR
;
2884 if( getStmtPointer(interp
, Tcl_GetString(objv
[2]), &pStmt2
)) return TCL_ERROR
;
2885 Tcl_SetObjResult(interp
,
2886 Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1
,pStmt2
)));
2892 ** Usage: sqlite3_changes DB
2894 ** Return the number of changes made to the database by the last SQL
2897 static int SQLITE_TCLAPI
test_changes(
2901 Tcl_Obj
*CONST objv
[]
2905 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2906 Tcl_GetString(objv
[0]), " DB", 0);
2909 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2910 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_changes(db
)));
2915 ** This is the "static_bind_value" that variables are bound to when
2916 ** the FLAG option of sqlite3_bind is "static"
2918 static char *sqlite_static_bind_value
= 0;
2919 static int sqlite_static_bind_nbyte
= 0;
2922 ** Usage: sqlite3_bind VM IDX VALUE FLAGS
2924 ** Sets the value of the IDX-th occurrence of "?" in the original SQL
2925 ** string. VALUE is the new value. If FLAGS=="null" then VALUE is
2926 ** ignored and the value is set to NULL. If FLAGS=="static" then
2927 ** the value is set to the value of a static variable named
2928 ** "sqlite_static_bind_value". If FLAGS=="normal" then a copy
2929 ** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored
2930 ** an a 10-byte blob "abc\000xyz\000pq" is inserted.
2932 static int SQLITE_TCLAPI
test_bind(
2934 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2935 int argc
, /* Number of arguments */
2936 char **argv
/* Text of each argument */
2938 sqlite3_stmt
*pStmt
;
2942 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
2943 " VM IDX VALUE (null|static|normal)\"", 0);
2946 if( getStmtPointer(interp
, argv
[1], &pStmt
) ) return TCL_ERROR
;
2947 if( Tcl_GetInt(interp
, argv
[2], &idx
) ) return TCL_ERROR
;
2948 if( strcmp(argv
[4],"null")==0 ){
2949 rc
= sqlite3_bind_null(pStmt
, idx
);
2950 }else if( strcmp(argv
[4],"static")==0 ){
2951 rc
= sqlite3_bind_text(pStmt
, idx
, sqlite_static_bind_value
, -1, 0);
2952 }else if( strcmp(argv
[4],"static-nbytes")==0 ){
2953 rc
= sqlite3_bind_text(pStmt
, idx
, sqlite_static_bind_value
,
2954 sqlite_static_bind_nbyte
, 0);
2955 }else if( strcmp(argv
[4],"normal")==0 ){
2956 rc
= sqlite3_bind_text(pStmt
, idx
, argv
[3], -1, SQLITE_TRANSIENT
);
2957 }else if( strcmp(argv
[4],"blob10")==0 ){
2958 rc
= sqlite3_bind_text(pStmt
, idx
, "abc\000xyz\000pq", 10, SQLITE_STATIC
);
2960 Tcl_AppendResult(interp
, "4th argument should be "
2961 "\"null\" or \"static\" or \"normal\"", 0);
2964 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
2967 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
2968 Tcl_AppendResult(interp
, zBuf
, sqlite3ErrStr(rc
), 0);
2974 #ifndef SQLITE_OMIT_UTF16
2976 ** Usage: add_test_collate <db ptr> <utf8> <utf16le> <utf16be>
2978 ** This function is used to test that SQLite selects the correct collation
2979 ** sequence callback when multiple versions (for different text encodings)
2982 ** Calling this routine registers the collation sequence "test_collate"
2983 ** with database handle <db>. The second argument must be a list of three
2984 ** boolean values. If the first is true, then a version of test_collate is
2985 ** registered for UTF-8, if the second is true, a version is registered for
2986 ** UTF-16le, if the third is true, a UTF-16be version is available.
2987 ** Previous versions of test_collate are deleted.
2989 ** The collation sequence test_collate is implemented by calling the
2990 ** following TCL script:
2992 ** "test_collate <enc> <lhs> <rhs>"
2994 ** The <lhs> and <rhs> are the two values being compared, encoded in UTF-8.
2995 ** The <enc> parameter is the encoding of the collation function that
2996 ** SQLite selected to call. The TCL test script implements the
2997 ** "test_collate" proc.
2999 ** Note that this will only work with one interpreter at a time, as the
3000 ** interp pointer to use when evaluating the TCL script is stored in
3001 ** pTestCollateInterp.
3003 static Tcl_Interp
* pTestCollateInterp
;
3004 static int test_collate_func(
3006 int nA
, const void *zA
,
3007 int nB
, const void *zB
3009 Tcl_Interp
*i
= pTestCollateInterp
;
3010 int encin
= SQLITE_PTR_TO_INT(pCtx
);
3014 sqlite3_value
*pVal
;
3017 pX
= Tcl_NewStringObj("test_collate", -1);
3018 Tcl_IncrRefCount(pX
);
3022 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-8",-1));
3024 case SQLITE_UTF16LE
:
3025 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-16LE",-1));
3027 case SQLITE_UTF16BE
:
3028 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-16BE",-1));
3034 sqlite3BeginBenignMalloc();
3035 pVal
= sqlite3ValueNew(0);
3037 sqlite3ValueSetStr(pVal
, nA
, zA
, encin
, SQLITE_STATIC
);
3038 n
= sqlite3_value_bytes(pVal
);
3039 Tcl_ListObjAppendElement(i
,pX
,
3040 Tcl_NewStringObj((char*)sqlite3_value_text(pVal
),n
));
3041 sqlite3ValueSetStr(pVal
, nB
, zB
, encin
, SQLITE_STATIC
);
3042 n
= sqlite3_value_bytes(pVal
);
3043 Tcl_ListObjAppendElement(i
,pX
,
3044 Tcl_NewStringObj((char*)sqlite3_value_text(pVal
),n
));
3045 sqlite3ValueFree(pVal
);
3047 sqlite3EndBenignMalloc();
3049 Tcl_EvalObjEx(i
, pX
, 0);
3050 Tcl_DecrRefCount(pX
);
3051 Tcl_GetIntFromObj(i
, Tcl_GetObjResult(i
), &res
);
3054 static int SQLITE_TCLAPI
test_collate(
3058 Tcl_Obj
*CONST objv
[]
3062 sqlite3_value
*pVal
;
3065 if( objc
!=5 ) goto bad_args
;
3066 pTestCollateInterp
= interp
;
3067 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3069 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
3070 rc
= sqlite3_create_collation(db
, "test_collate", SQLITE_UTF8
,
3071 (void *)SQLITE_UTF8
, val
?test_collate_func
:0);
3072 if( rc
==SQLITE_OK
){
3074 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
3075 rc
= sqlite3_create_collation(db
, "test_collate", SQLITE_UTF16LE
,
3076 (void *)SQLITE_UTF16LE
, val
?test_collate_func
:0);
3077 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[4], &val
) ) return TCL_ERROR
;
3080 if( sqlite3_iMallocFail
>0 ){
3081 sqlite3_iMallocFail
++;
3084 sqlite3_mutex_enter(db
->mutex
);
3085 pVal
= sqlite3ValueNew(db
);
3086 sqlite3ValueSetStr(pVal
, -1, "test_collate", SQLITE_UTF8
, SQLITE_STATIC
);
3087 zUtf16
= sqlite3ValueText(pVal
, SQLITE_UTF16NATIVE
);
3088 if( db
->mallocFailed
){
3091 rc
= sqlite3_create_collation16(db
, zUtf16
, SQLITE_UTF16BE
,
3092 (void *)SQLITE_UTF16BE
, val
?test_collate_func
:0);
3094 sqlite3ValueFree(pVal
);
3095 sqlite3_mutex_leave(db
->mutex
);
3097 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3099 if( rc
!=SQLITE_OK
){
3100 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3106 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3107 Tcl_GetStringFromObj(objv
[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
3112 ** Usage: add_test_utf16bin_collate <db ptr>
3114 ** Add a utf-16 collation sequence named "utf16bin" to the database
3115 ** handle. This collation sequence compares arguments in the same way as the
3116 ** built-in collation "binary".
3118 static int test_utf16bin_collate_func(
3120 int nA
, const void *zA
,
3121 int nB
, const void *zB
3123 int nCmp
= (nA
>nB
? nB
: nA
);
3124 int res
= memcmp(zA
, zB
, nCmp
);
3125 if( res
==0 ) res
= nA
- nB
;
3128 static int SQLITE_TCLAPI
test_utf16bin_collate(
3132 Tcl_Obj
*CONST objv
[]
3137 if( objc
!=2 ) goto bad_args
;
3138 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3140 rc
= sqlite3_create_collation(db
, "utf16bin", SQLITE_UTF16
, 0,
3141 test_utf16bin_collate_func
3143 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3147 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
3152 ** When the collation needed callback is invoked, record the name of
3153 ** the requested collating function here. The recorded name is linked
3154 ** to a TCL variable and used to make sure that the requested collation
3157 static char zNeededCollation
[200];
3158 static char *pzNeededCollation
= zNeededCollation
;
3162 ** Called when a collating sequence is needed. Registered using
3163 ** sqlite3_collation_needed16().
3165 static void test_collate_needed_cb(
3174 for(z
= (char*)pName
, i
=0; *z
|| z
[1]; z
++){
3175 if( *z
) zNeededCollation
[i
++] = *z
;
3177 zNeededCollation
[i
] = 0;
3178 sqlite3_create_collation(
3179 db
, "test_collate", ENC(db
), SQLITE_INT_TO_PTR(enc
), test_collate_func
);
3183 ** Usage: add_test_collate_needed DB
3185 static int SQLITE_TCLAPI
test_collate_needed(
3189 Tcl_Obj
*CONST objv
[]
3194 if( objc
!=2 ) goto bad_args
;
3195 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3196 rc
= sqlite3_collation_needed16(db
, 0, test_collate_needed_cb
);
3197 zNeededCollation
[0] = 0;
3198 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3202 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
3207 ** tclcmd: add_alignment_test_collations DB
3209 ** Add two new collating sequences to the database DB
3214 ** Both collating sequences use the same sort order as BINARY.
3215 ** The only difference is that the utf16_aligned collating
3216 ** sequence is declared with the SQLITE_UTF16_ALIGNED flag.
3217 ** Both collating functions increment the unaligned utf16 counter
3218 ** whenever they see a string that begins on an odd byte boundary.
3220 static int unaligned_string_counter
= 0;
3221 static int alignmentCollFunc(
3223 int nKey1
, const void *pKey1
,
3224 int nKey2
, const void *pKey2
3227 n
= nKey1
<nKey2
? nKey1
: nKey2
;
3228 if( nKey1
>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey1
))) ) unaligned_string_counter
++;
3229 if( nKey2
>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey2
))) ) unaligned_string_counter
++;
3230 rc
= memcmp(pKey1
, pKey2
, n
);
3236 static int SQLITE_TCLAPI
add_alignment_test_collations(
3240 Tcl_Obj
*CONST objv
[]
3244 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3245 sqlite3_create_collation(db
, "utf16_unaligned", SQLITE_UTF16
,
3246 0, alignmentCollFunc
);
3247 sqlite3_create_collation(db
, "utf16_aligned", SQLITE_UTF16_ALIGNED
,
3248 0, alignmentCollFunc
);
3252 #endif /* !defined(SQLITE_OMIT_UTF16) */
3255 ** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be>
3257 ** This function is used to test that SQLite selects the correct user
3258 ** function callback when multiple versions (for different text encodings)
3261 ** Calling this routine registers up to three versions of the user function
3262 ** "test_function" with database handle <db>. If the second argument is
3263 ** true, then a version of test_function is registered for UTF-8, if the
3264 ** third is true, a version is registered for UTF-16le, if the fourth is
3265 ** true, a UTF-16be version is available. Previous versions of
3266 ** test_function are deleted.
3268 ** The user function is implemented by calling the following TCL script:
3270 ** "test_function <enc> <arg>"
3272 ** Where <enc> is one of UTF-8, UTF-16LE or UTF16BE, and <arg> is the
3273 ** single argument passed to the SQL function. The value returned by
3274 ** the TCL script is used as the return value of the SQL function. It
3275 ** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8
3276 ** for a UTF-16LE test_function(), and UTF-16LE for an implementation that
3277 ** prefers UTF-16BE.
3279 #ifndef SQLITE_OMIT_UTF16
3280 static void test_function_utf8(
3281 sqlite3_context
*pCtx
,
3283 sqlite3_value
**argv
3287 sqlite3_value
*pVal
;
3288 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3289 pX
= Tcl_NewStringObj("test_function", -1);
3290 Tcl_IncrRefCount(pX
);
3291 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-8", -1));
3292 Tcl_ListObjAppendElement(interp
, pX
,
3293 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3294 Tcl_EvalObjEx(interp
, pX
, 0);
3295 Tcl_DecrRefCount(pX
);
3296 sqlite3_result_text(pCtx
, Tcl_GetStringResult(interp
), -1, SQLITE_TRANSIENT
);
3297 pVal
= sqlite3ValueNew(0);
3298 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3299 SQLITE_UTF8
, SQLITE_STATIC
);
3300 sqlite3_result_text16be(pCtx
, sqlite3_value_text16be(pVal
),
3301 -1, SQLITE_TRANSIENT
);
3302 sqlite3ValueFree(pVal
);
3304 static void test_function_utf16le(
3305 sqlite3_context
*pCtx
,
3307 sqlite3_value
**argv
3311 sqlite3_value
*pVal
;
3312 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3313 pX
= Tcl_NewStringObj("test_function", -1);
3314 Tcl_IncrRefCount(pX
);
3315 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-16LE", -1));
3316 Tcl_ListObjAppendElement(interp
, pX
,
3317 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3318 Tcl_EvalObjEx(interp
, pX
, 0);
3319 Tcl_DecrRefCount(pX
);
3320 pVal
= sqlite3ValueNew(0);
3321 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3322 SQLITE_UTF8
, SQLITE_STATIC
);
3323 sqlite3_result_text(pCtx
,(char*)sqlite3_value_text(pVal
),-1,SQLITE_TRANSIENT
);
3324 sqlite3ValueFree(pVal
);
3326 static void test_function_utf16be(
3327 sqlite3_context
*pCtx
,
3329 sqlite3_value
**argv
3333 sqlite3_value
*pVal
;
3334 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3335 pX
= Tcl_NewStringObj("test_function", -1);
3336 Tcl_IncrRefCount(pX
);
3337 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-16BE", -1));
3338 Tcl_ListObjAppendElement(interp
, pX
,
3339 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3340 Tcl_EvalObjEx(interp
, pX
, 0);
3341 Tcl_DecrRefCount(pX
);
3342 pVal
= sqlite3ValueNew(0);
3343 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3344 SQLITE_UTF8
, SQLITE_STATIC
);
3345 sqlite3_result_text16(pCtx
, sqlite3_value_text16le(pVal
),
3346 -1, SQLITE_TRANSIENT
);
3347 sqlite3_result_text16be(pCtx
, sqlite3_value_text16le(pVal
),
3348 -1, SQLITE_TRANSIENT
);
3349 sqlite3_result_text16le(pCtx
, sqlite3_value_text16le(pVal
),
3350 -1, SQLITE_TRANSIENT
);
3351 sqlite3ValueFree(pVal
);
3353 #endif /* SQLITE_OMIT_UTF16 */
3354 static int SQLITE_TCLAPI
test_function(
3358 Tcl_Obj
*CONST objv
[]
3360 #ifndef SQLITE_OMIT_UTF16
3364 if( objc
!=5 ) goto bad_args
;
3365 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3367 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
3369 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF8
,
3370 interp
, test_function_utf8
, 0, 0);
3372 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
3374 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF16LE
,
3375 interp
, test_function_utf16le
, 0, 0);
3377 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[4], &val
) ) return TCL_ERROR
;
3379 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF16BE
,
3380 interp
, test_function_utf16be
, 0, 0);
3385 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3386 Tcl_GetStringFromObj(objv
[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
3387 #endif /* SQLITE_OMIT_UTF16 */
3392 ** Usage: sqlite3_test_errstr <err code>
3394 ** Test that the english language string equivalents for sqlite error codes
3395 ** are sane. The parameter is an integer representing an sqlite error code.
3396 ** The result is a list of two elements, the string representation of the
3397 ** error code and the english language explanation.
3399 static int SQLITE_TCLAPI
test_errstr(
3403 Tcl_Obj
*CONST objv
[]
3408 Tcl_WrongNumArgs(interp
, 1, objv
, "<error code>");
3411 zCode
= Tcl_GetString(objv
[1]);
3412 for(i
=0; i
<200; i
++){
3413 if( 0==strcmp(t1ErrorName(i
), zCode
) ) break;
3415 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(i
), 0);
3420 ** Usage: breakpoint
3422 ** This routine exists for one purpose - to provide a place to put a
3423 ** breakpoint with GDB that can be triggered using TCL code. The use
3424 ** for this is when a particular test fails on (say) the 1485th iteration.
3425 ** In the TCL test script, we can add code like this:
3427 ** if {$i==1485} breakpoint
3429 ** Then run testfixture in the debugger and wait for the breakpoint to
3430 ** fire. Then additional breakpoints can be set to trace down the bug.
3432 static int SQLITE_TCLAPI
test_breakpoint(
3434 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
3435 int argc
, /* Number of arguments */
3436 char **argv
/* Text of each argument */
3438 return TCL_OK
; /* Do nothing */
3442 ** Usage: sqlite3_bind_zeroblob STMT IDX N
3444 ** Test the sqlite3_bind_zeroblob interface. STMT is a prepared statement.
3445 ** IDX is the index of a wildcard in the prepared statement. This command
3446 ** binds a N-byte zero-filled BLOB to the wildcard.
3448 static int SQLITE_TCLAPI
test_bind_zeroblob(
3452 Tcl_Obj
*CONST objv
[]
3454 sqlite3_stmt
*pStmt
;
3460 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX N");
3464 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3465 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3466 if( Tcl_GetIntFromObj(interp
, objv
[3], &n
) ) return TCL_ERROR
;
3468 rc
= sqlite3_bind_zeroblob(pStmt
, idx
, n
);
3469 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3470 if( rc
!=SQLITE_OK
){
3478 ** Usage: sqlite3_bind_zeroblob64 STMT IDX N
3480 ** Test the sqlite3_bind_zeroblob64 interface. STMT is a prepared statement.
3481 ** IDX is the index of a wildcard in the prepared statement. This command
3482 ** binds a N-byte zero-filled BLOB to the wildcard.
3484 static int SQLITE_TCLAPI
test_bind_zeroblob64(
3488 Tcl_Obj
*CONST objv
[]
3490 sqlite3_stmt
*pStmt
;
3496 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX N");
3500 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3501 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3502 if( Tcl_GetWideIntFromObj(interp
, objv
[3], &n
) ) return TCL_ERROR
;
3504 rc
= sqlite3_bind_zeroblob64(pStmt
, idx
, n
);
3505 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3506 if( rc
!=SQLITE_OK
){
3507 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3515 ** Usage: sqlite3_bind_int STMT N VALUE
3517 ** Test the sqlite3_bind_int interface. STMT is a prepared statement.
3518 ** N is the index of a wildcard in the prepared statement. This command
3519 ** binds a 32-bit integer VALUE to that wildcard.
3521 static int SQLITE_TCLAPI
test_bind_int(
3525 Tcl_Obj
*CONST objv
[]
3527 sqlite3_stmt
*pStmt
;
3533 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3534 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3538 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3539 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3540 if( Tcl_GetIntFromObj(interp
, objv
[3], &value
) ) return TCL_ERROR
;
3542 rc
= sqlite3_bind_int(pStmt
, idx
, value
);
3543 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3544 if( rc
!=SQLITE_OK
){
3553 ** Usage: intarray_addr INT ...
3555 ** Return the address of a C-language array of 32-bit integers.
3557 ** Space to hold the array is obtained from malloc(). Call this procedure once
3558 ** with no arguments in order to release memory. Each call to this procedure
3559 ** overwrites the previous array.
3561 static int SQLITE_TCLAPI
test_intarray_addr(
3565 Tcl_Obj
*CONST objv
[]
3573 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3574 if( p
==0 ) return TCL_ERROR
;
3575 for(i
=0; i
<objc
-1; i
++){
3576 if( Tcl_GetIntFromObj(interp
, objv
[1+i
], &p
[i
]) ){
3583 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3587 ** Usage: intarray_addr INT ...
3589 ** Return the address of a C-language array of 32-bit integers.
3591 ** Space to hold the array is obtained from malloc(). Call this procedure once
3592 ** with no arguments in order to release memory. Each call to this procedure
3593 ** overwrites the previous array.
3595 static int SQLITE_TCLAPI
test_int64array_addr(
3599 Tcl_Obj
*CONST objv
[]
3602 static sqlite3_int64
*p
= 0;
3607 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3608 if( p
==0 ) return TCL_ERROR
;
3609 for(i
=0; i
<objc
-1; i
++){
3611 if( Tcl_GetWideIntFromObj(interp
, objv
[1+i
], &v
) ){
3619 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3623 ** Usage: doublearray_addr INT ...
3625 ** Return the address of a C-language array of doubles.
3627 ** Space to hold the array is obtained from malloc(). Call this procedure once
3628 ** with no arguments in order to release memory. Each call to this procedure
3629 ** overwrites the previous array.
3631 static int SQLITE_TCLAPI
test_doublearray_addr(
3635 Tcl_Obj
*CONST objv
[]
3638 static double *p
= 0;
3643 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3644 if( p
==0 ) return TCL_ERROR
;
3645 for(i
=0; i
<objc
-1; i
++){
3646 if( Tcl_GetDoubleFromObj(interp
, objv
[1+i
], &p
[i
]) ){
3653 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3657 ** Usage: textarray_addr TEXT ...
3659 ** Return the address of a C-language array of strings.
3661 ** Space to hold the array is obtained from malloc(). Call this procedure once
3662 ** with no arguments in order to release memory. Each call to this procedure
3663 ** overwrites the previous array.
3665 static int SQLITE_TCLAPI
test_textarray_addr(
3669 Tcl_Obj
*CONST objv
[]
3673 static char **p
= 0;
3675 for(i
=0; i
<n
; i
++) sqlite3_free(p
[i
]);
3679 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3680 if( p
==0 ) return TCL_ERROR
;
3681 for(i
=0; i
<objc
-1; i
++){
3682 p
[i
] = sqlite3_mprintf("%s", Tcl_GetString(objv
[1+i
]));
3686 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3692 ** Usage: sqlite3_bind_int64 STMT N VALUE
3694 ** Test the sqlite3_bind_int64 interface. STMT is a prepared statement.
3695 ** N is the index of a wildcard in the prepared statement. This command
3696 ** binds a 64-bit integer VALUE to that wildcard.
3698 static int SQLITE_TCLAPI
test_bind_int64(
3702 Tcl_Obj
*CONST objv
[]
3704 sqlite3_stmt
*pStmt
;
3710 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3711 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3715 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3716 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3717 if( Tcl_GetWideIntFromObj(interp
, objv
[3], &value
) ) return TCL_ERROR
;
3719 rc
= sqlite3_bind_int64(pStmt
, idx
, value
);
3720 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3721 if( rc
!=SQLITE_OK
){
3730 ** Usage: sqlite3_bind_double STMT N VALUE
3732 ** Test the sqlite3_bind_double interface. STMT is a prepared statement.
3733 ** N is the index of a wildcard in the prepared statement. This command
3734 ** binds a 64-bit integer VALUE to that wildcard.
3736 static int SQLITE_TCLAPI
test_bind_double(
3740 Tcl_Obj
*CONST objv
[]
3742 sqlite3_stmt
*pStmt
;
3748 static const struct {
3749 const char *zName
; /* Name of the special floating point value */
3750 unsigned int iUpper
; /* Upper 32 bits */
3751 unsigned int iLower
; /* Lower 32 bits */
3753 { "NaN", 0x7fffffff, 0xffffffff },
3754 { "SNaN", 0x7ff7ffff, 0xffffffff },
3755 { "-NaN", 0xffffffff, 0xffffffff },
3756 { "-SNaN", 0xfff7ffff, 0xffffffff },
3757 { "+Inf", 0x7ff00000, 0x00000000 },
3758 { "-Inf", 0xfff00000, 0x00000000 },
3759 { "Epsilon", 0x00000000, 0x00000001 },
3760 { "-Epsilon", 0x80000000, 0x00000001 },
3761 { "NaN0", 0x7ff80000, 0x00000000 },
3762 { "-NaN0", 0xfff80000, 0x00000000 },
3766 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3767 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3771 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3772 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3774 /* Intercept the string "NaN" and generate a NaN value for it.
3775 ** All other strings are passed through to Tcl_GetDoubleFromObj().
3776 ** Tcl_GetDoubleFromObj() should understand "NaN" but some versions
3779 zVal
= Tcl_GetString(objv
[3]);
3780 for(i
=0; i
<sizeof(aSpecialFp
)/sizeof(aSpecialFp
[0]); i
++){
3781 if( strcmp(aSpecialFp
[i
].zName
, zVal
)==0 ){
3783 x
= aSpecialFp
[i
].iUpper
;
3785 x
|= aSpecialFp
[i
].iLower
;
3786 assert( sizeof(value
)==8 );
3787 assert( sizeof(x
)==8 );
3788 memcpy(&value
, &x
, 8);
3792 if( i
>=sizeof(aSpecialFp
)/sizeof(aSpecialFp
[0]) &&
3793 Tcl_GetDoubleFromObj(interp
, objv
[3], &value
) ){
3796 rc
= sqlite3_bind_double(pStmt
, idx
, value
);
3797 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3798 if( rc
!=SQLITE_OK
){
3806 ** Usage: sqlite3_bind_null STMT N
3808 ** Test the sqlite3_bind_null interface. STMT is a prepared statement.
3809 ** N is the index of a wildcard in the prepared statement. This command
3810 ** binds a NULL to the wildcard.
3812 static int SQLITE_TCLAPI
test_bind_null(
3816 Tcl_Obj
*CONST objv
[]
3818 sqlite3_stmt
*pStmt
;
3823 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3824 Tcl_GetStringFromObj(objv
[0], 0), " STMT N", 0);
3828 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3829 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3831 rc
= sqlite3_bind_null(pStmt
, idx
);
3832 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3833 if( rc
!=SQLITE_OK
){
3841 ** Usage: sqlite3_bind_text STMT N STRING BYTES
3843 ** Test the sqlite3_bind_text interface. STMT is a prepared statement.
3844 ** N is the index of a wildcard in the prepared statement. This command
3845 ** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes
3848 static int SQLITE_TCLAPI
test_bind_text(
3852 Tcl_Obj
*CONST objv
[]
3854 sqlite3_stmt
*pStmt
;
3861 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3862 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE BYTES", 0);
3866 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3867 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3868 value
= (char*)Tcl_GetByteArrayFromObj(objv
[3], &bytes
);
3869 if( Tcl_GetIntFromObj(interp
, objv
[4], &bytes
) ) return TCL_ERROR
;
3871 rc
= sqlite3_bind_text(pStmt
, idx
, value
, bytes
, SQLITE_TRANSIENT
);
3872 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3873 if( rc
!=SQLITE_OK
){
3874 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3882 ** Usage: sqlite3_bind_text16 ?-static? STMT N STRING BYTES
3884 ** Test the sqlite3_bind_text16 interface. STMT is a prepared statement.
3885 ** N is the index of a wildcard in the prepared statement. This command
3886 ** binds a UTF-16 string STRING to the wildcard. The string is BYTES bytes
3889 static int SQLITE_TCLAPI
test_bind_text16(
3893 Tcl_Obj
*CONST objv
[]
3895 #ifndef SQLITE_OMIT_UTF16
3896 sqlite3_stmt
*pStmt
;
3902 void (*xDel
)(void*) = (objc
==6?SQLITE_STATIC
:SQLITE_TRANSIENT
);
3903 Tcl_Obj
*oStmt
= objv
[objc
-4];
3904 Tcl_Obj
*oN
= objv
[objc
-3];
3905 Tcl_Obj
*oString
= objv
[objc
-2];
3906 Tcl_Obj
*oBytes
= objv
[objc
-1];
3908 if( objc
!=5 && objc
!=6){
3909 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3910 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE BYTES", 0);
3914 if( getStmtPointer(interp
, Tcl_GetString(oStmt
), &pStmt
) ) return TCL_ERROR
;
3915 if( Tcl_GetIntFromObj(interp
, oN
, &idx
) ) return TCL_ERROR
;
3916 value
= (char*)Tcl_GetByteArrayFromObj(oString
, 0);
3917 if( Tcl_GetIntFromObj(interp
, oBytes
, &bytes
) ) return TCL_ERROR
;
3919 rc
= sqlite3_bind_text16(pStmt
, idx
, (void *)value
, bytes
, xDel
);
3920 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3921 if( rc
!=SQLITE_OK
){
3922 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3926 #endif /* SQLITE_OMIT_UTF16 */
3931 ** Usage: sqlite3_bind_blob ?-static? STMT N DATA BYTES
3933 ** Test the sqlite3_bind_blob interface. STMT is a prepared statement.
3934 ** N is the index of a wildcard in the prepared statement. This command
3935 ** binds a BLOB to the wildcard. The BLOB is BYTES bytes in size.
3937 static int SQLITE_TCLAPI
test_bind_blob(
3941 Tcl_Obj
*CONST objv
[]
3943 sqlite3_stmt
*pStmt
;
3948 sqlite3_destructor_type xDestructor
= SQLITE_TRANSIENT
;
3950 if( objc
!=5 && objc
!=6 ){
3951 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3952 Tcl_GetStringFromObj(objv
[0], 0), " STMT N DATA BYTES", 0);
3957 xDestructor
= SQLITE_STATIC
;
3961 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3962 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3964 value
= (char*)Tcl_GetByteArrayFromObj(objv
[3], &len
);
3965 if( Tcl_GetIntFromObj(interp
, objv
[4], &bytes
) ) return TCL_ERROR
;
3969 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
3970 "cannot use %d blob bytes, have %d", bytes
, len
);
3971 Tcl_AppendResult(interp
, zBuf
, (char*)0);
3975 rc
= sqlite3_bind_blob(pStmt
, idx
, value
, bytes
, xDestructor
);
3976 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3977 if( rc
!=SQLITE_OK
){
3985 #ifndef SQLITE_OMIT_VIRTUALTABLE
3987 ** sqlite3_carray_bind [options...] STMT NAME VALUE ...
3997 ** Each call clears static data. Called with no options does nothing
3998 ** but clear static data.
4000 static int SQLITE_TCLAPI
test_carray_bind(
4004 Tcl_Obj
*CONST objv
[]
4006 sqlite3_stmt
*pStmt
;
4007 int eType
= 0; /* CARRAY_INT32 */
4010 int isTransient
= 0;
4015 void (*xDel
)(void*) = sqlite3_free
;
4016 static void *aStaticData
= 0;
4017 static int nStaticData
= 0;
4018 static int eStaticType
= 0;
4019 extern int sqlite3_carray_bind(
4020 sqlite3_stmt
*pStmt
,
4025 void (*xDestroy
)(void*)
4029 /* Always clear preexisting static data on every call */
4030 if( eStaticType
==3 ){
4031 for(i
=0; i
<nStaticData
; i
++){
4032 sqlite3_free(((char**)aStaticData
)[i
]);
4035 sqlite3_free(aStaticData
);
4040 if( objc
==1 ) return TCL_OK
;
4042 for(i
=1; i
<objc
&& Tcl_GetString(objv
[i
])[0]=='-'; i
++){
4043 const char *z
= Tcl_GetString(objv
[i
]);
4044 if( strcmp(z
, "-transient")==0 ){
4046 xDel
= SQLITE_TRANSIENT
;
4048 if( strcmp(z
, "-static")==0 ){
4050 xDel
= SQLITE_STATIC
;
4052 if( strcmp(z
, "-int32")==0 ){
4053 eType
= 0; /* CARRAY_INT32 */
4055 if( strcmp(z
, "-int64")==0 ){
4056 eType
= 1; /* CARRAY_INT64 */
4058 if( strcmp(z
, "-double")==0 ){
4059 eType
= 2; /* CARRAY_DOUBLE */
4061 if( strcmp(z
, "-text")==0 ){
4062 eType
= 3; /* CARRAY_TEXT */
4064 if( strcmp(z
, "--")==0 ){
4068 Tcl_AppendResult(interp
, "unknown option: ", z
, (char*)0);
4072 if( eType
==3 && !isStatic
&& !isTransient
){
4073 Tcl_AppendResult(interp
, "text data must be either -static or -transient",
4077 if( isStatic
&& isTransient
){
4078 Tcl_AppendResult(interp
, "cannot be both -static and -transient",
4083 Tcl_WrongNumArgs(interp
, 1, objv
, "[OPTIONS] STMT IDX VALUE ...");
4086 if( getStmtPointer(interp
, Tcl_GetString(objv
[i
]), &pStmt
) ) return TCL_ERROR
;
4088 if( Tcl_GetIntFromObj(interp
, objv
[i
], &idx
) ) return TCL_ERROR
;
4091 switch( eType
+ 4*(nData
<=0) ){
4092 case 0: { /* INT32 */
4093 int *a
= sqlite3_malloc( sizeof(int)*nData
);
4094 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4095 for(j
=0; j
<nData
; j
++){
4097 if( Tcl_GetIntFromObj(interp
, objv
[i
+j
], &v
) ){
4106 case 1: { /* INT64 */
4107 sqlite3_int64
*a
= sqlite3_malloc( sizeof(sqlite3_int64
)*nData
);
4108 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4109 for(j
=0; j
<nData
; j
++){
4111 if( Tcl_GetWideIntFromObj(interp
, objv
[i
+j
], &v
) ){
4120 case 2: { /* DOUBLE */
4121 double *a
= sqlite3_malloc( sizeof(double)*nData
);
4122 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4123 for(j
=0; j
<nData
; j
++){
4125 if( Tcl_GetDoubleFromObj(interp
, objv
[i
+j
], &v
) ){
4134 case 3: { /* TEXT */
4135 char **a
= sqlite3_malloc( sizeof(char*)*nData
);
4136 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4137 for(j
=0; j
<nData
; j
++){
4138 const char *v
= Tcl_GetString(objv
[i
+j
]);
4139 a
[j
] = sqlite3_mprintf("%s", v
);
4144 case 4: { /* nData==0 */
4146 xDel
= SQLITE_STATIC
;
4153 aStaticData
= aData
;
4154 nStaticData
= nData
;
4155 eStaticType
= eType
;
4157 rc
= sqlite3_carray_bind(pStmt
, idx
, aData
, nData
, eType
, xDel
);
4160 for(i
=0; i
<nData
; i
++) sqlite3_free(((char**)aData
)[i
]);
4162 sqlite3_free(aData
);
4166 Tcl_AppendResult(interp
, sqlite3_errstr(rc
), (char*)0);
4171 #endif /* SQLITE_OMIT_VIRTUALTABLE */
4174 ** Usage: sqlite3_bind_parameter_count STMT
4176 ** Return the number of wildcards in the given statement.
4178 static int SQLITE_TCLAPI
test_bind_parameter_count(
4182 Tcl_Obj
*CONST objv
[]
4184 sqlite3_stmt
*pStmt
;
4187 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4190 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4191 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_bind_parameter_count(pStmt
)));
4196 ** Usage: sqlite3_bind_parameter_name STMT N
4198 ** Return the name of the Nth wildcard. The first wildcard is 1.
4199 ** An empty string is returned if N is out of range or if the wildcard
4202 static int SQLITE_TCLAPI
test_bind_parameter_name(
4206 Tcl_Obj
*CONST objv
[]
4208 sqlite3_stmt
*pStmt
;
4212 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT N");
4215 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4216 if( Tcl_GetIntFromObj(interp
, objv
[2], &i
) ) return TCL_ERROR
;
4217 Tcl_SetObjResult(interp
,
4218 Tcl_NewStringObj(sqlite3_bind_parameter_name(pStmt
,i
),-1)
4224 ** Usage: sqlite3_bind_parameter_index STMT NAME
4226 ** Return the index of the wildcard called NAME. Return 0 if there is
4227 ** no such wildcard.
4229 static int SQLITE_TCLAPI
test_bind_parameter_index(
4233 Tcl_Obj
*CONST objv
[]
4235 sqlite3_stmt
*pStmt
;
4238 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT NAME");
4241 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4242 Tcl_SetObjResult(interp
,
4244 sqlite3_bind_parameter_index(pStmt
,Tcl_GetString(objv
[2]))
4251 ** Usage: sqlite3_clear_bindings STMT
4254 static int SQLITE_TCLAPI
test_clear_bindings(
4258 Tcl_Obj
*CONST objv
[]
4260 sqlite3_stmt
*pStmt
;
4263 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4266 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4267 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_clear_bindings(pStmt
)));
4272 ** Usage: sqlite3_sleep MILLISECONDS
4274 static int SQLITE_TCLAPI
test_sleep(
4278 Tcl_Obj
*CONST objv
[]
4283 Tcl_WrongNumArgs(interp
, 1, objv
, "MILLISECONDS");
4286 if( Tcl_GetIntFromObj(interp
, objv
[1], &ms
) ){
4289 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_sleep(ms
)));
4294 ** Usage: sqlite3_extended_errcode DB
4296 ** Return the string representation of the most recent sqlite3_* API
4297 ** error code. e.g. "SQLITE_ERROR".
4299 static int SQLITE_TCLAPI
test_ex_errcode(
4303 Tcl_Obj
*CONST objv
[]
4309 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4310 Tcl_GetString(objv
[0]), " DB", 0);
4313 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4314 rc
= sqlite3_extended_errcode(db
);
4315 Tcl_AppendResult(interp
, (char *)t1ErrorName(rc
), 0);
4321 ** Usage: sqlite3_errcode DB
4323 ** Return the string representation of the most recent sqlite3_* API
4324 ** error code. e.g. "SQLITE_ERROR".
4326 static int SQLITE_TCLAPI
test_errcode(
4330 Tcl_Obj
*CONST objv
[]
4336 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4337 Tcl_GetString(objv
[0]), " DB", 0);
4340 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4341 rc
= sqlite3_errcode(db
);
4342 Tcl_AppendResult(interp
, (char *)t1ErrorName(rc
), 0);
4347 ** Usage: sqlite3_errmsg DB
4349 ** Returns the UTF-8 representation of the error message string for the
4350 ** most recent sqlite3_* API call.
4352 static int SQLITE_TCLAPI
test_errmsg(
4356 Tcl_Obj
*CONST objv
[]
4362 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4363 Tcl_GetString(objv
[0]), " DB", 0);
4366 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4368 zErr
= sqlite3_errmsg(db
);
4369 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zErr
, -1));
4374 ** Usage: test_errmsg16 DB
4376 ** Returns the UTF-16 representation of the error message string for the
4377 ** most recent sqlite3_* API call. This is a byte array object at the TCL
4378 ** level, and it includes the 0x00 0x00 terminator bytes at the end of the
4381 static int SQLITE_TCLAPI
test_errmsg16(
4385 Tcl_Obj
*CONST objv
[]
4387 #ifndef SQLITE_OMIT_UTF16
4394 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4395 Tcl_GetString(objv
[0]), " DB", 0);
4398 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4400 zErr
= sqlite3_errmsg16(db
);
4403 for(bytes
=0; z
[bytes
] || z
[bytes
+1]; bytes
+=2){}
4405 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(zErr
, bytes
));
4406 #endif /* SQLITE_OMIT_UTF16 */
4411 ** Usage: sqlite3_prepare DB sql bytes ?tailvar?
4413 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4414 ** database handle <DB>. The parameter <tailval> is the name of a global
4415 ** variable that is set to the unused portion of <sql> (if any). A
4416 ** STMT handle is returned.
4418 static int SQLITE_TCLAPI
test_prepare(
4422 Tcl_Obj
*CONST objv
[]
4427 const char *zTail
= 0;
4428 sqlite3_stmt
*pStmt
= 0;
4432 if( objc
!=5 && objc
!=4 ){
4433 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4434 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
4437 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4438 zSql
= Tcl_GetString(objv
[2]);
4439 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4441 rc
= sqlite3_prepare(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4442 Tcl_ResetResult(interp
);
4443 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4444 if( zTail
&& objc
>=5 ){
4446 bytes
= bytes
- (int)(zTail
-zSql
);
4448 if( (int)strlen(zTail
)<bytes
){
4449 bytes
= (int)strlen(zTail
);
4451 Tcl_ObjSetVar2(interp
, objv
[4], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4453 if( rc
!=SQLITE_OK
){
4455 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4456 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4461 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4462 Tcl_AppendResult(interp
, zBuf
, 0);
4468 ** Usage: sqlite3_prepare_v2 DB sql bytes ?tailvar?
4470 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4471 ** database handle <DB>. The parameter <tailval> is the name of a global
4472 ** variable that is set to the unused portion of <sql> (if any). A
4473 ** STMT handle is returned.
4475 static int SQLITE_TCLAPI
test_prepare_v2(
4479 Tcl_Obj
*CONST objv
[]
4483 char *zCopy
= 0; /* malloc() copy of zSql */
4485 const char *zTail
= 0;
4486 const char **pzTail
;
4487 sqlite3_stmt
*pStmt
= 0;
4491 if( objc
!=5 && objc
!=4 ){
4492 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4493 Tcl_GetString(objv
[0]), " DB sql bytes tailvar", 0);
4496 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4497 zSql
= Tcl_GetString(objv
[2]);
4498 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4500 /* Instead of using zSql directly, make a copy into a buffer obtained
4501 ** directly from malloc(). The idea is to make it easier for valgrind
4502 ** to spot buffer overreads. */
4504 zCopy
= malloc(bytes
);
4505 memcpy(zCopy
, zSql
, bytes
);
4507 int n
= (int)strlen(zSql
) + 1;
4509 memcpy(zCopy
, zSql
, n
);
4511 pzTail
= objc
>=5 ? &zTail
: 0;
4512 rc
= sqlite3_prepare_v2(db
, zCopy
, bytes
, &pStmt
, pzTail
);
4514 zTail
= &zSql
[(zTail
- zCopy
)];
4518 assert(rc
==SQLITE_OK
|| pStmt
==0);
4519 Tcl_ResetResult(interp
);
4520 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4521 if( rc
==SQLITE_OK
&& objc
>=5 && zTail
){
4523 bytes
= bytes
- (int)(zTail
-zSql
);
4525 Tcl_ObjSetVar2(interp
, objv
[4], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4527 if( rc
!=SQLITE_OK
){
4529 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4530 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4535 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4536 Tcl_AppendResult(interp
, zBuf
, 0);
4542 ** Usage: sqlite3_prepare_v3 DB sql bytes flags ?tailvar?
4544 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4545 ** database handle <DB> and flags <flags>. The parameter <tailval> is
4546 ** the name of a global variable that is set to the unused portion of
4547 ** <sql> (if any). A STMT handle is returned.
4549 static int SQLITE_TCLAPI
test_prepare_v3(
4553 Tcl_Obj
*CONST objv
[]
4557 char *zCopy
= 0; /* malloc() copy of zSql */
4559 const char *zTail
= 0;
4560 const char **pzTail
;
4561 sqlite3_stmt
*pStmt
= 0;
4565 if( objc
!=6 && objc
!=5 ){
4566 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4567 Tcl_GetString(objv
[0]), " DB sql bytes flags tailvar", 0);
4570 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4571 zSql
= Tcl_GetString(objv
[2]);
4572 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4573 if( Tcl_GetIntFromObj(interp
, objv
[4], &flags
) ) return TCL_ERROR
;
4575 /* Instead of using zSql directly, make a copy into a buffer obtained
4576 ** directly from malloc(). The idea is to make it easier for valgrind
4577 ** to spot buffer overreads. */
4579 zCopy
= malloc(bytes
);
4580 memcpy(zCopy
, zSql
, bytes
);
4582 int n
= (int)strlen(zSql
) + 1;
4584 memcpy(zCopy
, zSql
, n
);
4586 pzTail
= objc
>=6 ? &zTail
: 0;
4587 rc
= sqlite3_prepare_v3(db
, zCopy
, bytes
, (unsigned int)flags
,&pStmt
,pzTail
);
4589 zTail
= &zSql
[(zTail
- zCopy
)];
4591 assert(rc
==SQLITE_OK
|| pStmt
==0);
4592 Tcl_ResetResult(interp
);
4593 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4594 if( rc
==SQLITE_OK
&& zTail
&& objc
>=6 ){
4596 bytes
= bytes
- (int)(zTail
-zSql
);
4598 Tcl_ObjSetVar2(interp
, objv
[5], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4600 if( rc
!=SQLITE_OK
){
4602 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4603 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4608 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4609 Tcl_AppendResult(interp
, zBuf
, 0);
4615 ** Usage: sqlite3_prepare_tkt3134 DB
4617 ** Generate a prepared statement for a zero-byte string as a test
4618 ** for ticket #3134. The string should be preceded by a zero byte.
4620 static int SQLITE_TCLAPI
test_prepare_tkt3134(
4624 Tcl_Obj
*CONST objv
[]
4627 static const char zSql
[] = "\000SELECT 1";
4628 sqlite3_stmt
*pStmt
= 0;
4633 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4634 Tcl_GetString(objv
[0]), " DB sql bytes tailvar", 0);
4637 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4638 rc
= sqlite3_prepare_v2(db
, &zSql
[1], 0, &pStmt
, 0);
4639 assert(rc
==SQLITE_OK
|| pStmt
==0);
4640 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4641 if( rc
!=SQLITE_OK
){
4643 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4644 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4649 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4650 Tcl_AppendResult(interp
, zBuf
, 0);
4656 ** Usage: sqlite3_prepare16 DB sql bytes tailvar
4658 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4659 ** database handle <DB>. The parameter <tailval> is the name of a global
4660 ** variable that is set to the unused portion of <sql> (if any). A
4661 ** STMT handle is returned.
4663 static int SQLITE_TCLAPI
test_prepare16(
4667 Tcl_Obj
*CONST objv
[]
4669 #ifndef SQLITE_OMIT_UTF16
4672 const void *zTail
= 0;
4674 sqlite3_stmt
*pStmt
= 0;
4677 int bytes
; /* The integer specified as arg 3 */
4678 int objlen
; /* The byte-array length of arg 2 */
4680 if( objc
!=5 && objc
!=4 ){
4681 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4682 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
4685 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4686 zSql
= Tcl_GetByteArrayFromObj(objv
[2], &objlen
);
4687 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4689 rc
= sqlite3_prepare16(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4690 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4697 objlen
= objlen
- (int)((u8
*)zTail
-(u8
*)zSql
);
4701 pTail
= Tcl_NewByteArrayObj((u8
*)zTail
, objlen
);
4702 Tcl_IncrRefCount(pTail
);
4703 Tcl_ObjSetVar2(interp
, objv
[4], 0, pTail
, 0);
4704 Tcl_DecrRefCount(pTail
);
4708 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4710 Tcl_AppendResult(interp
, zBuf
, 0);
4711 #endif /* SQLITE_OMIT_UTF16 */
4716 ** Usage: sqlite3_prepare16_v2 DB sql bytes ?tailvar?
4718 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4719 ** database handle <DB>. The parameter <tailval> is the name of a global
4720 ** variable that is set to the unused portion of <sql> (if any). A
4721 ** STMT handle is returned.
4723 static int SQLITE_TCLAPI
test_prepare16_v2(
4727 Tcl_Obj
*CONST objv
[]
4729 #ifndef SQLITE_OMIT_UTF16
4732 const void *zTail
= 0;
4734 sqlite3_stmt
*pStmt
= 0;
4737 int bytes
; /* The integer specified as arg 3 */
4738 int objlen
; /* The byte-array length of arg 2 */
4740 if( objc
!=5 && objc
!=4 ){
4741 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4742 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
4745 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4746 zSql
= Tcl_GetByteArrayFromObj(objv
[2], &objlen
);
4747 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4749 rc
= sqlite3_prepare16_v2(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4750 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4757 objlen
= objlen
- (int)((u8
*)zTail
-(u8
*)zSql
);
4761 pTail
= Tcl_NewByteArrayObj((u8
*)zTail
, objlen
);
4762 Tcl_IncrRefCount(pTail
);
4763 Tcl_ObjSetVar2(interp
, objv
[4], 0, pTail
, 0);
4764 Tcl_DecrRefCount(pTail
);
4768 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4770 Tcl_AppendResult(interp
, zBuf
, 0);
4771 #endif /* SQLITE_OMIT_UTF16 */
4776 ** Usage: sqlite3_open filename ?options-list?
4778 static int SQLITE_TCLAPI
test_open(
4782 Tcl_Obj
*CONST objv
[]
4784 const char *zFilename
;
4788 if( objc
!=3 && objc
!=2 && objc
!=1 ){
4789 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4790 Tcl_GetString(objv
[0]), " filename options-list", 0);
4794 zFilename
= objc
>1 ? Tcl_GetString(objv
[1]) : 0;
4795 sqlite3_open(zFilename
, &db
);
4797 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
4798 Tcl_AppendResult(interp
, zBuf
, 0);
4803 ** Usage: sqlite3_open_v2 FILENAME FLAGS VFS
4805 static int SQLITE_TCLAPI
test_open_v2(
4809 Tcl_Obj
*CONST objv
[]
4811 const char *zFilename
;
4823 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME FLAGS VFS");
4826 zFilename
= Tcl_GetString(objv
[1]);
4827 zVfs
= Tcl_GetString(objv
[3]);
4828 if( zVfs
[0]==0x00 ) zVfs
= 0;
4830 rc
= Tcl_ListObjGetElements(interp
, objv
[2], &nFlag
, &apFlag
);
4831 if( rc
!=TCL_OK
) return rc
;
4832 for(i
=0; i
<nFlag
; i
++){
4838 { "SQLITE_OPEN_READONLY", SQLITE_OPEN_READONLY
},
4839 { "SQLITE_OPEN_READWRITE", SQLITE_OPEN_READWRITE
},
4840 { "SQLITE_OPEN_CREATE", SQLITE_OPEN_CREATE
},
4841 { "SQLITE_OPEN_DELETEONCLOSE", SQLITE_OPEN_DELETEONCLOSE
},
4842 { "SQLITE_OPEN_EXCLUSIVE", SQLITE_OPEN_EXCLUSIVE
},
4843 { "SQLITE_OPEN_AUTOPROXY", SQLITE_OPEN_AUTOPROXY
},
4844 { "SQLITE_OPEN_MAIN_DB", SQLITE_OPEN_MAIN_DB
},
4845 { "SQLITE_OPEN_TEMP_DB", SQLITE_OPEN_TEMP_DB
},
4846 { "SQLITE_OPEN_TRANSIENT_DB", SQLITE_OPEN_TRANSIENT_DB
},
4847 { "SQLITE_OPEN_MAIN_JOURNAL", SQLITE_OPEN_MAIN_JOURNAL
},
4848 { "SQLITE_OPEN_TEMP_JOURNAL", SQLITE_OPEN_TEMP_JOURNAL
},
4849 { "SQLITE_OPEN_SUBJOURNAL", SQLITE_OPEN_SUBJOURNAL
},
4850 { "SQLITE_OPEN_SUPER_JOURNAL", SQLITE_OPEN_SUPER_JOURNAL
},
4851 { "SQLITE_OPEN_NOMUTEX", SQLITE_OPEN_NOMUTEX
},
4852 { "SQLITE_OPEN_FULLMUTEX", SQLITE_OPEN_FULLMUTEX
},
4853 { "SQLITE_OPEN_SHAREDCACHE", SQLITE_OPEN_SHAREDCACHE
},
4854 { "SQLITE_OPEN_PRIVATECACHE", SQLITE_OPEN_PRIVATECACHE
},
4855 { "SQLITE_OPEN_WAL", SQLITE_OPEN_WAL
},
4856 { "SQLITE_OPEN_URI", SQLITE_OPEN_URI
},
4859 rc
= Tcl_GetIndexFromObjStruct(interp
, apFlag
[i
], aFlag
, sizeof(aFlag
[0]),
4862 if( rc
!=TCL_OK
) return rc
;
4863 flags
|= aFlag
[iFlag
].flag
;
4866 rc
= sqlite3_open_v2(zFilename
, &db
, flags
, zVfs
);
4867 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
4868 Tcl_AppendResult(interp
, zBuf
, 0);
4873 ** Usage: sqlite3_open16 filename options
4875 static int SQLITE_TCLAPI
test_open16(
4879 Tcl_Obj
*CONST objv
[]
4881 #ifndef SQLITE_OMIT_UTF16
4882 const void *zFilename
;
4887 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4888 Tcl_GetString(objv
[0]), " filename options-list", 0);
4892 zFilename
= Tcl_GetByteArrayFromObj(objv
[1], 0);
4893 sqlite3_open16(zFilename
, &db
);
4895 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
4896 Tcl_AppendResult(interp
, zBuf
, 0);
4897 #endif /* SQLITE_OMIT_UTF16 */
4902 ** Usage: sqlite3_complete16 <UTF-16 string>
4904 ** Return 1 if the supplied argument is a complete SQL statement, or zero
4907 static int SQLITE_TCLAPI
test_complete16(
4911 Tcl_Obj
*CONST objv
[]
4913 #if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16)
4917 Tcl_WrongNumArgs(interp
, 1, objv
, "<utf-16 sql>");
4921 zBuf
= (char*)Tcl_GetByteArrayFromObj(objv
[1], 0);
4922 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_complete16(zBuf
)));
4923 #endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */
4928 ** Usage: sqlite3_normalize SQL
4930 ** Return the normalized value for an SQL statement.
4932 static int SQLITE_TCLAPI
test_normalize(
4936 Tcl_Obj
*CONST objv
[]
4940 extern char *sqlite3_normalize(const char*);
4943 Tcl_WrongNumArgs(interp
, 1, objv
, "SQL");
4947 zSql
= (char*)Tcl_GetString(objv
[1]);
4948 zNorm
= sqlite3_normalize(zSql
);
4950 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zNorm
, -1));
4951 sqlite3_free(zNorm
);
4957 ** Usage: sqlite3_step STMT
4959 ** Advance the statement to the next row.
4961 static int SQLITE_TCLAPI
test_step(
4965 Tcl_Obj
*CONST objv
[]
4967 sqlite3_stmt
*pStmt
;
4971 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4972 Tcl_GetString(objv
[0]), " STMT", 0);
4976 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4977 rc
= sqlite3_step(pStmt
);
4979 /* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */
4980 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
4984 static int SQLITE_TCLAPI
test_sql(
4988 Tcl_Obj
*CONST objv
[]
4990 sqlite3_stmt
*pStmt
;
4993 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4997 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4998 Tcl_SetResult(interp
, (char *)sqlite3_sql(pStmt
), TCL_VOLATILE
);
5001 static int SQLITE_TCLAPI
test_ex_sql(
5005 Tcl_Obj
*CONST objv
[]
5007 sqlite3_stmt
*pStmt
;
5011 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
5015 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5016 z
= sqlite3_expanded_sql(pStmt
);
5017 Tcl_SetResult(interp
, z
, TCL_VOLATILE
);
5021 #ifdef SQLITE_ENABLE_NORMALIZE
5022 static int SQLITE_TCLAPI
test_norm_sql(
5026 Tcl_Obj
*CONST objv
[]
5028 sqlite3_stmt
*pStmt
;
5031 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
5035 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5036 Tcl_SetResult(interp
, (char *)sqlite3_normalized_sql(pStmt
), TCL_VOLATILE
);
5039 #endif /* SQLITE_ENABLE_NORMALIZE */
5042 ** Usage: sqlite3_column_count STMT
5044 ** Return the number of columns returned by the sql statement STMT.
5046 static int SQLITE_TCLAPI
test_column_count(
5050 Tcl_Obj
*CONST objv
[]
5052 sqlite3_stmt
*pStmt
;
5055 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5056 Tcl_GetString(objv
[0]), " STMT column", 0);
5060 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5062 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_column_count(pStmt
)));
5067 ** Usage: sqlite3_column_type STMT column
5069 ** Return the type of the data in column 'column' of the current row.
5071 static int SQLITE_TCLAPI
test_column_type(
5075 Tcl_Obj
*CONST objv
[]
5077 sqlite3_stmt
*pStmt
;
5082 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5083 Tcl_GetString(objv
[0]), " STMT column", 0);
5087 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5088 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5090 tp
= sqlite3_column_type(pStmt
, col
);
5092 case SQLITE_INTEGER
:
5093 Tcl_SetResult(interp
, "INTEGER", TCL_STATIC
);
5096 Tcl_SetResult(interp
, "NULL", TCL_STATIC
);
5099 Tcl_SetResult(interp
, "FLOAT", TCL_STATIC
);
5102 Tcl_SetResult(interp
, "TEXT", TCL_STATIC
);
5105 Tcl_SetResult(interp
, "BLOB", TCL_STATIC
);
5115 ** Usage: sqlite3_column_int64 STMT column
5117 ** Return the data in column 'column' of the current row cast as an
5118 ** wide (64-bit) integer.
5120 static int SQLITE_TCLAPI
test_column_int64(
5124 Tcl_Obj
*CONST objv
[]
5126 sqlite3_stmt
*pStmt
;
5131 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5132 Tcl_GetString(objv
[0]), " STMT column", 0);
5136 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5137 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5139 iVal
= sqlite3_column_int64(pStmt
, col
);
5140 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(iVal
));
5145 ** Usage: sqlite3_column_blob STMT column
5147 static int SQLITE_TCLAPI
test_column_blob(
5151 Tcl_Obj
*CONST objv
[]
5153 sqlite3_stmt
*pStmt
;
5160 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5161 Tcl_GetString(objv
[0]), " STMT column", 0);
5165 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5166 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5168 len
= sqlite3_column_bytes(pStmt
, col
);
5169 pBlob
= sqlite3_column_blob(pStmt
, col
);
5170 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(pBlob
, len
));
5175 ** Usage: sqlite3_column_double STMT column
5177 ** Return the data in column 'column' of the current row cast as a double.
5179 static int SQLITE_TCLAPI
test_column_double(
5183 Tcl_Obj
*CONST objv
[]
5185 sqlite3_stmt
*pStmt
;
5190 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5191 Tcl_GetString(objv
[0]), " STMT column", 0);
5195 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5196 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5198 rVal
= sqlite3_column_double(pStmt
, col
);
5199 Tcl_SetObjResult(interp
, Tcl_NewDoubleObj(rVal
));
5204 ** Usage: sqlite3_data_count STMT
5206 ** Return the number of columns returned by the sql statement STMT.
5208 static int SQLITE_TCLAPI
test_data_count(
5212 Tcl_Obj
*CONST objv
[]
5214 sqlite3_stmt
*pStmt
;
5217 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5218 Tcl_GetString(objv
[0]), " STMT column", 0);
5222 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5224 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_data_count(pStmt
)));
5229 ** Usage: sqlite3_column_text STMT column
5231 ** Usage: sqlite3_column_decltype STMT column
5233 ** Usage: sqlite3_column_name STMT column
5235 static int SQLITE_TCLAPI
test_stmt_utf8(
5236 void * clientData
, /* Pointer to SQLite API function to be invoke */
5239 Tcl_Obj
*CONST objv
[]
5241 sqlite3_stmt
*pStmt
;
5243 const char *(*xFunc
)(sqlite3_stmt
*, int);
5246 xFunc
= (const char *(*)(sqlite3_stmt
*, int))clientData
;
5248 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5249 Tcl_GetString(objv
[0]), " STMT column", 0);
5253 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5254 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5255 zRet
= xFunc(pStmt
, col
);
5257 Tcl_SetResult(interp
, (char *)zRet
, 0);
5262 static int SQLITE_TCLAPI
test_global_recover(
5266 Tcl_Obj
*CONST objv
[]
5268 #ifndef SQLITE_OMIT_DEPRECATED
5271 Tcl_WrongNumArgs(interp
, 1, objv
, "");
5274 rc
= sqlite3_global_recover();
5275 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5281 ** Usage: sqlite3_column_text STMT column
5283 ** Usage: sqlite3_column_decltype STMT column
5285 ** Usage: sqlite3_column_name STMT column
5287 static int SQLITE_TCLAPI
test_stmt_utf16(
5288 void * clientData
, /* Pointer to SQLite API function to be invoked */
5291 Tcl_Obj
*CONST objv
[]
5293 #ifndef SQLITE_OMIT_UTF16
5294 sqlite3_stmt
*pStmt
;
5297 const void *zName16
;
5298 const void *(*xFunc
)(sqlite3_stmt
*, int);
5300 xFunc
= (const void *(*)(sqlite3_stmt
*, int))clientData
;
5302 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5303 Tcl_GetString(objv
[0]), " STMT column", 0);
5307 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5308 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5310 zName16
= xFunc(pStmt
, col
);
5313 const char *z
= zName16
;
5314 for(n
=0; z
[n
] || z
[n
+1]; n
+=2){}
5315 pRet
= Tcl_NewByteArrayObj(zName16
, n
+2);
5316 Tcl_SetObjResult(interp
, pRet
);
5318 #endif /* SQLITE_OMIT_UTF16 */
5324 ** Usage: sqlite3_column_int STMT column
5326 ** Usage: sqlite3_column_bytes STMT column
5328 ** Usage: sqlite3_column_bytes16 STMT column
5331 static int SQLITE_TCLAPI
test_stmt_int(
5332 void * clientData
, /* Pointer to SQLite API function to be invoked */
5335 Tcl_Obj
*CONST objv
[]
5337 sqlite3_stmt
*pStmt
;
5339 int (*xFunc
)(sqlite3_stmt
*, int);
5341 xFunc
= (int (*)(sqlite3_stmt
*, int))clientData
;
5343 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5344 Tcl_GetString(objv
[0]), " STMT column", 0);
5348 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5349 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5351 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xFunc(pStmt
, col
)));
5356 ** Usage: sqlite_set_magic DB MAGIC-NUMBER
5358 ** Set the db->magic value. This is used to test error recovery logic.
5360 static int SQLITE_TCLAPI
sqlite_set_magic(
5368 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5372 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5373 if( strcmp(argv
[2], "SQLITE_MAGIC_OPEN")==0 ){
5374 db
->magic
= SQLITE_MAGIC_OPEN
;
5375 }else if( strcmp(argv
[2], "SQLITE_MAGIC_CLOSED")==0 ){
5376 db
->magic
= SQLITE_MAGIC_CLOSED
;
5377 }else if( strcmp(argv
[2], "SQLITE_MAGIC_BUSY")==0 ){
5378 db
->magic
= SQLITE_MAGIC_BUSY
;
5379 }else if( strcmp(argv
[2], "SQLITE_MAGIC_ERROR")==0 ){
5380 db
->magic
= SQLITE_MAGIC_ERROR
;
5381 }else if( Tcl_GetInt(interp
, argv
[2], (int*)&db
->magic
) ){
5388 ** Usage: sqlite3_interrupt DB
5390 ** Trigger an interrupt on DB
5392 static int SQLITE_TCLAPI
test_interrupt(
5400 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB", 0);
5403 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5404 sqlite3_interrupt(db
);
5409 ** Usage: sqlite_delete_function DB function-name
5411 ** Delete the user function 'function-name' from database handle DB. It
5412 ** is assumed that the user function was created as UTF8, any number of
5413 ** arguments (the way the TCL interface does it).
5415 static int SQLITE_TCLAPI
delete_function(
5424 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5425 " DB function-name", 0);
5428 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5429 rc
= sqlite3_create_function(db
, argv
[2], -1, SQLITE_UTF8
, 0, 0, 0, 0);
5430 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5435 ** Usage: sqlite_delete_collation DB collation-name
5437 ** Delete the collation sequence 'collation-name' from database handle
5438 ** DB. It is assumed that the collation sequence was created as UTF8 (the
5439 ** way the TCL interface does it).
5441 static int SQLITE_TCLAPI
delete_collation(
5450 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5451 " DB function-name", 0);
5454 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5455 rc
= sqlite3_create_collation(db
, argv
[2], SQLITE_UTF8
, 0, 0);
5456 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5461 ** Usage: sqlite3_get_autocommit DB
5463 ** Return true if the database DB is currently in auto-commit mode.
5464 ** Return false if not.
5466 static int SQLITE_TCLAPI
get_autocommit(
5475 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5479 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5480 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", sqlite3_get_autocommit(db
));
5481 Tcl_AppendResult(interp
, zBuf
, 0);
5486 ** Usage: sqlite3_busy_timeout DB MS
5488 ** Set the busy timeout. This is more easily done using the timeout
5489 ** method of the TCL interface. But we need a way to test the case
5490 ** where it returns SQLITE_MISUSE.
5492 static int SQLITE_TCLAPI
test_busy_timeout(
5501 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5505 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5506 if( Tcl_GetInt(interp
, argv
[2], &ms
) ) return TCL_ERROR
;
5507 rc
= sqlite3_busy_timeout(db
, ms
);
5508 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
5513 ** Usage: tcl_variable_type VARIABLENAME
5515 ** Return the name of the internal representation for the
5516 ** value of the given variable.
5518 static int SQLITE_TCLAPI
tcl_variable_type(
5522 Tcl_Obj
*CONST objv
[]
5526 Tcl_WrongNumArgs(interp
, 1, objv
, "VARIABLE");
5529 pVar
= Tcl_GetVar2Ex(interp
, Tcl_GetString(objv
[1]), 0, TCL_LEAVE_ERR_MSG
);
5530 if( pVar
==0 ) return TCL_ERROR
;
5531 if( pVar
->typePtr
){
5532 Tcl_SetObjResult(interp
, Tcl_NewStringObj(pVar
->typePtr
->name
, -1));
5538 ** Usage: sqlite3_release_memory ?N?
5540 ** Attempt to release memory currently held but not actually required.
5541 ** The integer N is the number of bytes we are trying to release. The
5542 ** return value is the amount of memory actually released.
5544 static int SQLITE_TCLAPI
test_release_memory(
5548 Tcl_Obj
*CONST objv
[]
5550 #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
5553 if( objc
!=1 && objc
!=2 ){
5554 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5558 if( Tcl_GetIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5562 amt
= sqlite3_release_memory(N
);
5563 Tcl_SetObjResult(interp
, Tcl_NewIntObj(amt
));
5570 ** Usage: sqlite3_db_release_memory DB
5572 ** Attempt to release memory currently held by database DB. Return the
5573 ** result code (which in the current implementation is always zero).
5575 static int SQLITE_TCLAPI
test_db_release_memory(
5579 Tcl_Obj
*CONST objv
[]
5584 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5587 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5588 rc
= sqlite3_db_release_memory(db
);
5589 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5594 ** Usage: sqlite3_db_cacheflush DB
5596 ** Attempt to flush any dirty pages to disk.
5598 static int SQLITE_TCLAPI
test_db_cacheflush(
5602 Tcl_Obj
*CONST objv
[]
5607 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5610 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5611 rc
= sqlite3_db_cacheflush(db
);
5613 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(rc
), TCL_STATIC
);
5617 Tcl_ResetResult(interp
);
5622 ** Usage: sqlite3_system_errno DB
5624 ** Return the low-level system errno value.
5626 static int SQLITE_TCLAPI
test_system_errno(
5630 Tcl_Obj
*CONST objv
[]
5635 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5638 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5639 iErrno
= sqlite3_system_errno(db
);
5640 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iErrno
));
5645 ** Usage: sqlite3_db_filename DB DBNAME
5647 ** Return the name of a file associated with a database.
5649 static int SQLITE_TCLAPI
test_db_filename(
5653 Tcl_Obj
*CONST objv
[]
5656 const char *zDbName
;
5658 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
5661 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5662 zDbName
= Tcl_GetString(objv
[2]);
5663 Tcl_AppendResult(interp
, sqlite3_db_filename(db
, zDbName
), (void*)0);
5668 ** Usage: sqlite3_db_readonly DB DBNAME
5670 ** Return 1 or 0 if DBNAME is readonly or not. Return -1 if DBNAME does
5673 static int SQLITE_TCLAPI
test_db_readonly(
5677 Tcl_Obj
*CONST objv
[]
5680 const char *zDbName
;
5682 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
5685 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5686 zDbName
= Tcl_GetString(objv
[2]);
5687 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_db_readonly(db
, zDbName
)));
5692 ** Usage: sqlite3_soft_heap_limit ?N?
5694 ** Query or set the soft heap limit for the current thread. The
5695 ** limit is only changed if the N is present. The previous limit
5698 static int SQLITE_TCLAPI
test_soft_heap_limit(
5702 Tcl_Obj
*CONST objv
[]
5706 if( objc
!=1 && objc
!=2 ){
5707 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5711 if( Tcl_GetWideIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5713 amt
= sqlite3_soft_heap_limit64(N
);
5714 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(amt
));
5719 ** Usage: sqlite3_hard_heap_limit ?N?
5721 ** Query or set the hard heap limit for the current thread. The
5722 ** limit is only changed if the N is present. The previous limit
5725 static int SQLITE_TCLAPI
test_hard_heap_limit(
5729 Tcl_Obj
*CONST objv
[]
5733 if( objc
!=1 && objc
!=2 ){
5734 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5738 if( Tcl_GetWideIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5740 amt
= sqlite3_hard_heap_limit64(N
);
5741 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(amt
));
5746 ** Usage: sqlite3_thread_cleanup
5748 ** Call the sqlite3_thread_cleanup API.
5750 static int SQLITE_TCLAPI
test_thread_cleanup(
5754 Tcl_Obj
*CONST objv
[]
5756 #ifndef SQLITE_OMIT_DEPRECATED
5757 sqlite3_thread_cleanup();
5763 ** Usage: sqlite3_pager_refcounts DB
5765 ** Return a list of numbers which are the PagerRefcount for all
5766 ** pagers on each database connection.
5768 static int SQLITE_TCLAPI
test_pager_refcounts(
5772 Tcl_Obj
*CONST objv
[]
5780 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5781 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
5784 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5785 pResult
= Tcl_NewObj();
5786 for(i
=0; i
<db
->nDb
; i
++){
5787 if( db
->aDb
[i
].pBt
==0 ){
5790 sqlite3_mutex_enter(db
->mutex
);
5791 a
= sqlite3PagerStats(sqlite3BtreePager(db
->aDb
[i
].pBt
));
5793 sqlite3_mutex_leave(db
->mutex
);
5795 Tcl_ListObjAppendElement(0, pResult
, Tcl_NewIntObj(v
));
5797 Tcl_SetObjResult(interp
, pResult
);
5803 ** tclcmd: working_64bit_int
5805 ** Some TCL builds (ex: cygwin) do not support 64-bit integers. This
5806 ** leads to a number of test failures. The present command checks the
5807 ** TCL build to see whether or not it supports 64-bit integers. It
5808 ** returns TRUE if it does and FALSE if not.
5810 ** This command is used to warn users that their TCL build is defective
5811 ** and that the errors they are seeing in the test scripts might be
5812 ** a result of their defective TCL rather than problems in SQLite.
5814 static int SQLITE_TCLAPI
working_64bit_int(
5815 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5816 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5817 int objc
, /* Number of arguments */
5818 Tcl_Obj
*CONST objv
[] /* Command arguments */
5823 pTestObj
= Tcl_NewWideIntObj(1000000*(i64
)1234567890);
5824 working
= strcmp(Tcl_GetString(pTestObj
), "1234567890000000")==0;
5825 Tcl_DecrRefCount(pTestObj
);
5826 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(working
));
5832 ** tclcmd: vfs_unlink_test
5834 ** This TCL command unregisters the primary VFS and then registers
5835 ** it back again. This is used to test the ability to register a
5836 ** VFS when none are previously registered, and the ability to
5837 ** unregister the only available VFS. Ticket #2738
5839 static int SQLITE_TCLAPI
vfs_unlink_test(
5840 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5841 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5842 int objc
, /* Number of arguments */
5843 Tcl_Obj
*CONST objv
[] /* Command arguments */
5847 sqlite3_vfs
*apVfs
[20];
5848 sqlite3_vfs one
, two
;
5850 sqlite3_vfs_unregister(0); /* Unregister of NULL is harmless */
5851 one
.zName
= "__one";
5852 two
.zName
= "__two";
5854 /* Calling sqlite3_vfs_register with 2nd argument of 0 does not
5855 ** change the default VFS
5857 pMain
= sqlite3_vfs_find(0);
5858 sqlite3_vfs_register(&one
, 0);
5859 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
5860 sqlite3_vfs_register(&two
, 0);
5861 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
5863 /* We can find a VFS by its name */
5864 assert( sqlite3_vfs_find("__one")==&one
);
5865 assert( sqlite3_vfs_find("__two")==&two
);
5867 /* Calling sqlite_vfs_register with non-zero second parameter changes the
5868 ** default VFS, even if the 1st parameter is an existig VFS that is
5869 ** previously registered as the non-default.
5871 sqlite3_vfs_register(&one
, 1);
5872 assert( sqlite3_vfs_find("__one")==&one
);
5873 assert( sqlite3_vfs_find("__two")==&two
);
5874 assert( sqlite3_vfs_find(0)==&one
);
5875 sqlite3_vfs_register(&two
, 1);
5876 assert( sqlite3_vfs_find("__one")==&one
);
5877 assert( sqlite3_vfs_find("__two")==&two
);
5878 assert( sqlite3_vfs_find(0)==&two
);
5880 sqlite3_vfs_register(pMain
, 1);
5881 assert( sqlite3_vfs_find("__one")==&one
);
5882 assert( sqlite3_vfs_find("__two")==&two
);
5883 assert( sqlite3_vfs_find(0)==pMain
);
5886 /* Unlink the default VFS. Repeat until there are no more VFSes
5889 for(i
=0; i
<sizeof(apVfs
)/sizeof(apVfs
[0]); i
++){
5890 apVfs
[i
] = sqlite3_vfs_find(0);
5892 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
5893 sqlite3_vfs_unregister(apVfs
[i
]);
5894 assert( 0==sqlite3_vfs_find(apVfs
[i
]->zName
) );
5897 assert( 0==sqlite3_vfs_find(0) );
5899 /* Register the main VFS as non-default (will be made default, since
5900 ** it'll be the only one in existence).
5902 sqlite3_vfs_register(pMain
, 0);
5903 assert( sqlite3_vfs_find(0)==pMain
);
5905 /* Un-register the main VFS again to restore an empty VFS list */
5906 sqlite3_vfs_unregister(pMain
);
5907 assert( 0==sqlite3_vfs_find(0) );
5909 /* Relink all VFSes in reverse order. */
5910 for(i
=sizeof(apVfs
)/sizeof(apVfs
[0])-1; i
>=0; i
--){
5912 sqlite3_vfs_register(apVfs
[i
], 1);
5913 assert( apVfs
[i
]==sqlite3_vfs_find(0) );
5914 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
5918 /* Unregister out sample VFSes. */
5919 sqlite3_vfs_unregister(&one
);
5920 sqlite3_vfs_unregister(&two
);
5922 /* Unregistering a VFS that is not currently registered is harmless */
5923 sqlite3_vfs_unregister(&one
);
5924 sqlite3_vfs_unregister(&two
);
5925 assert( sqlite3_vfs_find("__one")==0 );
5926 assert( sqlite3_vfs_find("__two")==0 );
5928 /* We should be left with the original default VFS back as the
5930 assert( sqlite3_vfs_find(0)==pMain
);
5936 ** tclcmd: vfs_initfail_test
5938 ** This TCL command attempts to vfs_find and vfs_register when the
5939 ** sqlite3_initialize() interface is failing. All calls should fail.
5941 static int SQLITE_TCLAPI
vfs_initfail_test(
5942 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5943 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5944 int objc
, /* Number of arguments */
5945 Tcl_Obj
*CONST objv
[] /* Command arguments */
5948 one
.zName
= "__one";
5950 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
5951 sqlite3_vfs_register(&one
, 0);
5952 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
5953 sqlite3_vfs_register(&one
, 1);
5954 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
5961 static sqlite3_vfs
*apVfs
[20];
5962 static int nVfs
= 0;
5965 ** tclcmd: vfs_unregister_all
5967 ** Unregister all VFSes.
5969 static int SQLITE_TCLAPI
vfs_unregister_all(
5970 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5971 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5972 int objc
, /* Number of arguments */
5973 Tcl_Obj
*CONST objv
[] /* Command arguments */
5976 for(i
=0; i
<ArraySize(apVfs
); i
++){
5977 apVfs
[i
] = sqlite3_vfs_find(0);
5978 if( apVfs
[i
]==0 ) break;
5979 sqlite3_vfs_unregister(apVfs
[i
]);
5985 ** tclcmd: vfs_reregister_all
5987 ** Restore all VFSes that were removed using vfs_unregister_all. Taking
5988 ** care to put the linked list back together in the same order as it was
5989 ** in before vfs_unregister_all was invoked.
5991 static int SQLITE_TCLAPI
vfs_reregister_all(
5992 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5993 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5994 int objc
, /* Number of arguments */
5995 Tcl_Obj
*CONST objv
[] /* Command arguments */
5998 for(i
=nVfs
-1; i
>=0; i
--){
5999 sqlite3_vfs_register(apVfs
[i
], 1);
6006 ** tclcmd: file_control_test DB
6008 ** This TCL command runs the sqlite3_file_control interface and
6009 ** verifies correct operation of the same.
6011 static int SQLITE_TCLAPI
file_control_test(
6012 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6013 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6014 int objc
, /* Number of arguments */
6015 Tcl_Obj
*CONST objv
[] /* Command arguments */
6022 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6023 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6026 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6027 rc
= sqlite3_file_control(db
, 0, 0, &iArg
);
6028 assert( rc
==SQLITE_NOTFOUND
);
6029 rc
= sqlite3_file_control(db
, "notadatabase", SQLITE_FCNTL_LOCKSTATE
, &iArg
);
6030 assert( rc
==SQLITE_ERROR
);
6031 rc
= sqlite3_file_control(db
, "main", -1, &iArg
);
6032 assert( rc
==SQLITE_NOTFOUND
);
6033 rc
= sqlite3_file_control(db
, "temp", -1, &iArg
);
6034 assert( rc
==SQLITE_NOTFOUND
|| rc
==SQLITE_ERROR
);
6041 ** tclcmd: file_control_lasterrno_test DB
6043 ** This TCL command runs the sqlite3_file_control interface and
6044 ** verifies correct operation of the SQLITE_LAST_ERRNO verb.
6046 static int SQLITE_TCLAPI
file_control_lasterrno_test(
6047 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6048 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6049 int objc
, /* Number of arguments */
6050 Tcl_Obj
*CONST objv
[] /* Command arguments */
6057 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6058 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6061 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6064 rc
= sqlite3_file_control(db
, NULL
, SQLITE_LAST_ERRNO
, &iArg
);
6066 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6070 Tcl_AppendResult(interp
, "Unexpected non-zero errno: ",
6071 Tcl_GetStringFromObj(Tcl_NewIntObj(iArg
), 0), " ", 0);
6078 ** tclcmd: file_control_data_version DB DBNAME
6080 ** This TCL command runs the sqlite3_file_control with the
6081 ** SQLITE_FCNTL_DATA_VERSION opcode, returning the result.
6083 static int SQLITE_TCLAPI
file_control_data_version(
6084 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6085 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6086 int objc
, /* Number of arguments */
6087 Tcl_Obj
*CONST objv
[] /* Command arguments */
6089 unsigned int iVers
; /* data version */
6090 char *zDb
; /* Db name ("main", "temp" etc.) */
6091 sqlite3
*db
; /* Database handle */
6092 int rc
; /* file_control() return code */
6095 if( objc
!=3 && objc
!=2 ){
6096 Tcl_WrongNumArgs(interp
, 1, objv
, "DB [DBNAME]");
6099 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6102 zDb
= objc
==3 ? Tcl_GetString(objv
[2]) : NULL
;
6104 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_DATA_VERSION
, (void *)&iVers
);
6106 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
6109 sqlite3_snprintf(sizeof(zBuf
),zBuf
,"%u",iVers
);
6110 Tcl_SetResult(interp
, (char *)zBuf
, TCL_VOLATILE
);
6116 ** tclcmd: file_control_chunksize_test DB DBNAME SIZE
6118 ** This TCL command runs the sqlite3_file_control interface and
6119 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
6120 ** SQLITE_SET_LOCKPROXYFILE verbs.
6122 static int SQLITE_TCLAPI
file_control_chunksize_test(
6123 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6124 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6125 int objc
, /* Number of arguments */
6126 Tcl_Obj
*CONST objv
[] /* Command arguments */
6128 int nSize
; /* New chunk size */
6129 char *zDb
; /* Db name ("main", "temp" etc.) */
6130 sqlite3
*db
; /* Database handle */
6131 int rc
; /* file_control() return code */
6134 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
6137 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6138 || Tcl_GetIntFromObj(interp
, objv
[3], &nSize
)
6142 zDb
= Tcl_GetString(objv
[2]);
6143 if( zDb
[0]=='\0' ) zDb
= NULL
;
6145 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_CHUNK_SIZE
, (void *)&nSize
);
6147 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
6154 ** tclcmd: file_control_sizehint_test DB DBNAME SIZE
6156 ** This TCL command runs the sqlite3_file_control interface
6157 ** with SQLITE_FCNTL_SIZE_HINT
6159 static int SQLITE_TCLAPI
file_control_sizehint_test(
6160 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6161 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6162 int objc
, /* Number of arguments */
6163 Tcl_Obj
*CONST objv
[] /* Command arguments */
6165 Tcl_WideInt nSize
; /* Hinted size */
6166 char *zDb
; /* Db name ("main", "temp" etc.) */
6167 sqlite3
*db
; /* Database handle */
6168 int rc
; /* file_control() return code */
6171 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
6174 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6175 || Tcl_GetWideIntFromObj(interp
, objv
[3], &nSize
)
6179 zDb
= Tcl_GetString(objv
[2]);
6180 if( zDb
[0]=='\0' ) zDb
= NULL
;
6182 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_SIZE_HINT
, (void *)&nSize
);
6184 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
6191 ** tclcmd: file_control_lockproxy_test DB PWD
6193 ** This TCL command runs the sqlite3_file_control interface and
6194 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
6195 ** SQLITE_SET_LOCKPROXYFILE verbs.
6197 static int SQLITE_TCLAPI
file_control_lockproxy_test(
6198 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6199 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6200 int objc
, /* Number of arguments */
6201 Tcl_Obj
*CONST objv
[] /* Command arguments */
6206 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6207 Tcl_GetStringFromObj(objv
[0], 0), " DB PWD", 0);
6210 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6214 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
6215 # if defined(__APPLE__)
6216 # define SQLITE_ENABLE_LOCKING_STYLE 1
6218 # define SQLITE_ENABLE_LOCKING_STYLE 0
6221 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
6227 char proxyPath
[400];
6229 zPwd
= Tcl_GetStringFromObj(objv
[2], &nPwd
);
6230 if( sizeof(proxyPath
)<nPwd
+20 ){
6231 Tcl_AppendResult(interp
, "PWD too big", (void*)0);
6234 sqlite3_snprintf(sizeof(proxyPath
), proxyPath
, "%s/test.proxy", zPwd
);
6235 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
6237 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6240 rc
= sqlite3_file_control(db
, NULL
, SQLITE_GET_LOCKPROXYFILE
, &testPath
);
6241 if( strncmp(proxyPath
,testPath
,11) ){
6242 Tcl_AppendResult(interp
, "Lock proxy file did not match the "
6243 "previously assigned value", 0);
6247 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6250 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
6252 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6262 ** tclcmd: file_control_win32_av_retry DB NRETRY DELAY
6264 ** This TCL command runs the sqlite3_file_control interface with
6265 ** the SQLITE_FCNTL_WIN32_AV_RETRY opcode.
6267 static int SQLITE_TCLAPI
file_control_win32_av_retry(
6268 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6269 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6270 int objc
, /* Number of arguments */
6271 Tcl_Obj
*CONST objv
[] /* Command arguments */
6279 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6280 Tcl_GetStringFromObj(objv
[0], 0), " DB NRETRY DELAY", 0);
6283 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6286 if( Tcl_GetIntFromObj(interp
, objv
[2], &a
[0]) ) return TCL_ERROR
;
6287 if( Tcl_GetIntFromObj(interp
, objv
[3], &a
[1]) ) return TCL_ERROR
;
6288 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_AV_RETRY
, (void*)a
);
6289 sqlite3_snprintf(sizeof(z
), z
, "%d %d %d", rc
, a
[0], a
[1]);
6290 Tcl_AppendResult(interp
, z
, (char*)0);
6295 ** tclcmd: file_control_win32_get_handle DB
6297 ** This TCL command runs the sqlite3_file_control interface with
6298 ** the SQLITE_FCNTL_WIN32_GET_HANDLE opcode.
6300 static int file_control_win32_get_handle(
6301 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6302 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6303 int objc
, /* Number of arguments */
6304 Tcl_Obj
*CONST objv
[] /* Command arguments */
6308 HANDLE hFile
= NULL
;
6312 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6313 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6316 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6319 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_GET_HANDLE
,
6321 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
6322 Tcl_AppendResult(interp
, z
, (char*)0);
6327 ** tclcmd: file_control_win32_set_handle DB HANDLE
6329 ** This TCL command runs the sqlite3_file_control interface with
6330 ** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode.
6332 static int SQLITE_TCLAPI
file_control_win32_set_handle(
6333 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6334 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6335 int objc
, /* Number of arguments */
6336 Tcl_Obj
*CONST objv
[] /* Command arguments */
6340 HANDLE hFile
= NULL
;
6344 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6345 Tcl_GetStringFromObj(objv
[0], 0), " DB HANDLE", 0);
6348 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6351 if( getWin32Handle(interp
, Tcl_GetString(objv
[2]), &hFile
) ){
6354 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_SET_HANDLE
,
6356 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
6357 Tcl_AppendResult(interp
, z
, (char*)0);
6363 ** tclcmd: file_control_persist_wal DB PERSIST-FLAG
6365 ** This TCL command runs the sqlite3_file_control interface with
6366 ** the SQLITE_FCNTL_PERSIST_WAL opcode.
6368 static int SQLITE_TCLAPI
file_control_persist_wal(
6369 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6370 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6371 int objc
, /* Number of arguments */
6372 Tcl_Obj
*CONST objv
[] /* Command arguments */
6380 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6381 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
6384 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6387 if( Tcl_GetIntFromObj(interp
, objv
[2], &bPersist
) ) return TCL_ERROR
;
6388 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_PERSIST_WAL
, (void*)&bPersist
);
6389 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, bPersist
);
6390 Tcl_AppendResult(interp
, z
, (char*)0);
6395 ** tclcmd: file_control_powersafe_overwrite DB PSOW-FLAG
6397 ** This TCL command runs the sqlite3_file_control interface with
6398 ** the SQLITE_FCNTL_POWERSAFE_OVERWRITE opcode.
6400 static int SQLITE_TCLAPI
file_control_powersafe_overwrite(
6401 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6402 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6403 int objc
, /* Number of arguments */
6404 Tcl_Obj
*CONST objv
[] /* Command arguments */
6412 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6413 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
6416 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6419 if( Tcl_GetIntFromObj(interp
, objv
[2], &b
) ) return TCL_ERROR
;
6420 rc
= sqlite3_file_control(db
,NULL
,SQLITE_FCNTL_POWERSAFE_OVERWRITE
,(void*)&b
);
6421 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, b
);
6422 Tcl_AppendResult(interp
, z
, (char*)0);
6428 ** tclcmd: file_control_vfsname DB ?AUXDB?
6430 ** Return a string that describes the stack of VFSes.
6432 static int SQLITE_TCLAPI
file_control_vfsname(
6433 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6434 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6435 int objc
, /* Number of arguments */
6436 Tcl_Obj
*CONST objv
[] /* Command arguments */
6439 const char *zDbName
= "main";
6442 if( objc
!=2 && objc
!=3 ){
6443 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6444 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6447 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6451 zDbName
= Tcl_GetString(objv
[2]);
6453 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_VFSNAME
,(void*)&zVfsName
);
6454 Tcl_AppendResult(interp
, zVfsName
, (char*)0);
6455 sqlite3_free(zVfsName
);
6460 ** tclcmd: file_control_reservebytes DB N
6462 static int SQLITE_TCLAPI
file_control_reservebytes(
6463 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6464 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6465 int objc
, /* Number of arguments */
6466 Tcl_Obj
*CONST objv
[] /* Command arguments */
6469 const char *zDbName
= "main";
6474 Tcl_WrongNumArgs(interp
, 1, objv
, "DB N");
6477 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6478 || Tcl_GetIntFromObj(interp
, objv
[2], &n
)
6483 rc
= sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_RESERVE_BYTES
, (void*)&n
);
6484 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
6490 ** tclcmd: file_control_tempfilename DB ?AUXDB?
6492 ** Return a string that is a temporary filename
6494 static int SQLITE_TCLAPI
file_control_tempfilename(
6495 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6496 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6497 int objc
, /* Number of arguments */
6498 Tcl_Obj
*CONST objv
[] /* Command arguments */
6501 const char *zDbName
= "main";
6504 if( objc
!=2 && objc
!=3 ){
6505 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6506 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6509 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6513 zDbName
= Tcl_GetString(objv
[2]);
6515 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_TEMPFILENAME
, (void*)&zTName
);
6516 Tcl_AppendResult(interp
, zTName
, (char*)0);
6517 sqlite3_free(zTName
);
6523 ** tclcmd: sqlite3_vfs_list
6525 ** Return a tcl list containing the names of all registered vfs's.
6527 static int SQLITE_TCLAPI
vfs_list(
6528 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6529 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6530 int objc
, /* Number of arguments */
6531 Tcl_Obj
*CONST objv
[] /* Command arguments */
6534 Tcl_Obj
*pRet
= Tcl_NewObj();
6536 Tcl_WrongNumArgs(interp
, 1, objv
, "");
6539 for(pVfs
=sqlite3_vfs_find(0); pVfs
; pVfs
=pVfs
->pNext
){
6540 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj(pVfs
->zName
, -1));
6542 Tcl_SetObjResult(interp
, pRet
);
6547 ** tclcmd: sqlite3_limit DB ID VALUE
6549 ** This TCL command runs the sqlite3_limit interface and
6550 ** verifies correct operation of the same.
6552 static int SQLITE_TCLAPI
test_limit(
6553 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6554 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6555 int objc
, /* Number of arguments */
6556 Tcl_Obj
*CONST objv
[] /* Command arguments */
6560 static const struct {
6564 { "SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH
},
6565 { "SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH
},
6566 { "SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN
},
6567 { "SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH
},
6568 { "SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT
},
6569 { "SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP
},
6570 { "SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG
},
6571 { "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED
},
6572 { "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH
},
6573 { "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER
},
6574 { "SQLITE_LIMIT_TRIGGER_DEPTH", SQLITE_LIMIT_TRIGGER_DEPTH
},
6575 { "SQLITE_LIMIT_WORKER_THREADS", SQLITE_LIMIT_WORKER_THREADS
},
6577 /* Out of range test cases */
6578 { "SQLITE_LIMIT_TOOSMALL", -1, },
6579 { "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_WORKER_THREADS
+1 },
6586 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6587 Tcl_GetStringFromObj(objv
[0], 0), " DB ID VALUE", 0);
6590 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6591 zId
= Tcl_GetString(objv
[2]);
6592 for(i
=0; i
<sizeof(aId
)/sizeof(aId
[0]); i
++){
6593 if( strcmp(zId
, aId
[i
].zName
)==0 ){
6598 if( i
>=sizeof(aId
)/sizeof(aId
[0]) ){
6599 Tcl_AppendResult(interp
, "unknown limit type: ", zId
, (char*)0);
6602 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
6603 rc
= sqlite3_limit(db
, id
, val
);
6604 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6609 ** tclcmd: save_prng_state
6611 ** Save the state of the pseudo-random number generator.
6612 ** At the same time, verify that sqlite3_test_control works even when
6613 ** called with an out-of-range opcode.
6615 static int SQLITE_TCLAPI
save_prng_state(
6616 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6617 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6618 int objc
, /* Number of arguments */
6619 Tcl_Obj
*CONST objv
[] /* Command arguments */
6621 int rc
= sqlite3_test_control(9999);
6623 rc
= sqlite3_test_control(-1);
6625 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SAVE
);
6629 ** tclcmd: restore_prng_state
6631 static int SQLITE_TCLAPI
restore_prng_state(
6632 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6633 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6634 int objc
, /* Number of arguments */
6635 Tcl_Obj
*CONST objv
[] /* Command arguments */
6637 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESTORE
);
6641 ** tclcmd: reset_prng_state
6643 static int SQLITE_TCLAPI
reset_prng_state(
6644 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6645 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6646 int objc
, /* Number of arguments */
6647 Tcl_Obj
*CONST objv
[] /* Command arguments */
6649 sqlite3_randomness(0,0);
6653 ** tclcmd: prng_seed INT ?DB?
6655 ** Set up the SQLITE_TESTCTRL_PRNG_SEED pragma with parameter INT and DB.
6656 ** INT is an integer. DB is a database connection, or a NULL pointer if
6659 ** When INT!=0 and DB!=0, set the PRNG seed to the value of the schema
6660 ** cookie for DB, or to INT if the schema cookie happens to be zero.
6662 ** When INT!=0 and DB==0, set the PRNG seed to just INT.
6664 ** If INT==0 and DB==0 then use the default procedure of calling the
6665 ** xRandomness method on the default VFS to get the PRNG seed.
6667 static int SQLITE_TCLAPI
prng_seed(
6668 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6669 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6670 int objc
, /* Number of arguments */
6671 Tcl_Obj
*CONST objv
[] /* Command arguments */
6675 if( objc
!=2 && objc
!=3 ){
6676 Tcl_WrongNumArgs(interp
, 1, objv
, "SEED ?DB?");
6679 if( Tcl_GetIntFromObj(interp
,objv
[0],&i
) ) return TCL_ERROR
;
6680 if( objc
==3 && getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ){
6683 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED
, i
, db
);
6688 ** tclcmd: extra_schema_checks BOOLEAN
6690 ** Enable or disable schema checks when parsing the sqlite_schema file.
6691 ** This is always enabled in production, but it is sometimes useful to
6692 ** disable the checks in order to make some internal error states reachable
6695 static int SQLITE_TCLAPI
extra_schema_checks(
6696 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6697 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6698 int objc
, /* Number of arguments */
6699 Tcl_Obj
*CONST objv
[] /* Command arguments */
6703 Tcl_WrongNumArgs(interp
, 1, objv
, "BOOLEAN");
6706 if( Tcl_GetBooleanFromObj(interp
,objv
[1],&i
) ) return TCL_ERROR
;
6707 sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS
, i
);
6712 ** tclcmd: database_may_be_corrupt
6714 ** Indicate that database files might be corrupt. In other words, set the normal
6715 ** state of operation.
6717 static int SQLITE_TCLAPI
database_may_be_corrupt(
6718 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6719 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6720 int objc
, /* Number of arguments */
6721 Tcl_Obj
*CONST objv
[] /* Command arguments */
6723 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 0);
6727 ** tclcmd: database_never_corrupt
6729 ** Indicate that database files are always well-formed. This enables
6730 ** extra assert() statements that test conditions that are always true
6731 ** for well-formed databases.
6733 static int SQLITE_TCLAPI
database_never_corrupt(
6734 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6735 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6736 int objc
, /* Number of arguments */
6737 Tcl_Obj
*CONST objv
[] /* Command arguments */
6739 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 1);
6744 ** tclcmd: pcache_stats
6746 static int SQLITE_TCLAPI
test_pcache_stats(
6747 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6748 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6749 int objc
, /* Number of arguments */
6750 Tcl_Obj
*CONST objv
[] /* Command arguments */
6758 sqlite3PcacheStats(&nCurrent
, &nMax
, &nMin
, &nRecyclable
);
6760 pRet
= Tcl_NewObj();
6761 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("current", -1));
6762 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCurrent
));
6763 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("max", -1));
6764 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMax
));
6765 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("min", -1));
6766 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMin
));
6767 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("recyclable", -1));
6768 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nRecyclable
));
6770 Tcl_SetObjResult(interp
, pRet
);
6775 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
6776 static void test_unlock_notify_cb(void **aArg
, int nArg
){
6778 for(ii
=0; ii
<nArg
; ii
++){
6779 Tcl_EvalEx((Tcl_Interp
*)aArg
[ii
], "unlock_notify", -1, TCL_EVAL_GLOBAL
);
6782 #endif /* SQLITE_ENABLE_UNLOCK_NOTIFY */
6785 ** tclcmd: sqlite3_unlock_notify db
6787 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
6788 static int SQLITE_TCLAPI
test_unlock_notify(
6789 ClientData clientData
, /* Unused */
6790 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6791 int objc
, /* Number of arguments */
6792 Tcl_Obj
*CONST objv
[] /* Command arguments */
6798 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
6802 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6805 rc
= sqlite3_unlock_notify(db
, test_unlock_notify_cb
, (void *)interp
);
6806 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
6812 ** tclcmd: sqlite3_wal_checkpoint db ?NAME?
6814 static int SQLITE_TCLAPI
test_wal_checkpoint(
6815 ClientData clientData
, /* Unused */
6816 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6817 int objc
, /* Number of arguments */
6818 Tcl_Obj
*CONST objv
[] /* Command arguments */
6824 if( objc
!=3 && objc
!=2 ){
6825 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?NAME?");
6829 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6833 zDb
= Tcl_GetString(objv
[2]);
6835 rc
= sqlite3_wal_checkpoint(db
, zDb
);
6836 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
6841 ** tclcmd: sqlite3_wal_checkpoint_v2 db MODE ?NAME?
6843 ** This command calls the wal_checkpoint_v2() function with the specified
6844 ** mode argument (passive, full or restart). If present, the database name
6845 ** NAME is passed as the second argument to wal_checkpoint_v2(). If it the
6846 ** NAME argument is not present, a NULL pointer is passed instead.
6848 ** If wal_checkpoint_v2() returns any value other than SQLITE_BUSY or
6849 ** SQLITE_OK, then this command returns TCL_ERROR. The Tcl result is set
6850 ** to the error message obtained from sqlite3_errmsg().
6852 ** Otherwise, this command returns a list of three integers. The first integer
6853 ** is 1 if SQLITE_BUSY was returned, or 0 otherwise. The following two integers
6854 ** are the values returned via the output parameters by wal_checkpoint_v2() -
6855 ** the number of frames in the log and the number of frames in the log
6856 ** that have been checkpointed.
6858 static int SQLITE_TCLAPI
test_wal_checkpoint_v2(
6859 ClientData clientData
, /* Unused */
6860 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6861 int objc
, /* Number of arguments */
6862 Tcl_Obj
*CONST objv
[] /* Command arguments */
6873 const char * aMode
[] = { "passive", "full", "restart", "truncate", 0 };
6874 assert( SQLITE_CHECKPOINT_PASSIVE
==0 );
6875 assert( SQLITE_CHECKPOINT_FULL
==1 );
6876 assert( SQLITE_CHECKPOINT_RESTART
==2 );
6877 assert( SQLITE_CHECKPOINT_TRUNCATE
==3 );
6879 if( objc
!=3 && objc
!=4 ){
6880 Tcl_WrongNumArgs(interp
, 1, objv
, "DB MODE ?NAME?");
6885 zDb
= Tcl_GetString(objv
[3]);
6887 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) || (
6888 TCL_OK
!=Tcl_GetIntFromObj(0, objv
[2], &eMode
)
6889 && TCL_OK
!=Tcl_GetIndexFromObj(interp
, objv
[2], aMode
, "mode", 0, &eMode
)
6894 rc
= sqlite3_wal_checkpoint_v2(db
, zDb
, eMode
, &nLog
, &nCkpt
);
6895 if( rc
!=SQLITE_OK
&& rc
!=SQLITE_BUSY
){
6896 const char *zErrCode
= sqlite3ErrName(rc
);
6897 Tcl_ResetResult(interp
);
6898 Tcl_AppendResult(interp
, zErrCode
, " - ", (char *)sqlite3_errmsg(db
), 0);
6902 pRet
= Tcl_NewObj();
6903 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(rc
==SQLITE_BUSY
?1:0));
6904 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nLog
));
6905 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCkpt
));
6906 Tcl_SetObjResult(interp
, pRet
);
6912 ** tclcmd: sqlite3_wal_autocheckpoint db VALUE
6914 static int SQLITE_TCLAPI
test_wal_autocheckpoint(
6915 ClientData clientData
, /* Unused */
6916 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6917 int objc
, /* Number of arguments */
6918 Tcl_Obj
*CONST objv
[] /* Command arguments */
6926 Tcl_WrongNumArgs(interp
, 1, objv
, "DB VALUE");
6930 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6931 || Tcl_GetIntFromObj(0, objv
[2], &iVal
)
6936 rc
= sqlite3_wal_autocheckpoint(db
, iVal
);
6937 Tcl_ResetResult(interp
);
6938 if( rc
!=SQLITE_OK
){
6939 const char *zErrCode
= sqlite3ErrName(rc
);
6940 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zErrCode
, -1));
6949 ** tclcmd: test_sqlite3_log ?SCRIPT?
6951 static struct LogCallback
{
6952 Tcl_Interp
*pInterp
;
6954 } logcallback
= {0, 0};
6955 static void xLogcallback(void *unused
, int err
, char *zMsg
){
6956 Tcl_Obj
*pNew
= Tcl_DuplicateObj(logcallback
.pObj
);
6957 Tcl_IncrRefCount(pNew
);
6958 Tcl_ListObjAppendElement(
6959 0, pNew
, Tcl_NewStringObj(sqlite3ErrName(err
), -1)
6961 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewStringObj(zMsg
, -1));
6962 Tcl_EvalObjEx(logcallback
.pInterp
, pNew
, TCL_EVAL_GLOBAL
|TCL_EVAL_DIRECT
);
6963 Tcl_DecrRefCount(pNew
);
6965 static int SQLITE_TCLAPI
test_sqlite3_log(
6966 ClientData clientData
,
6967 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6968 int objc
, /* Number of arguments */
6969 Tcl_Obj
*CONST objv
[] /* Command arguments */
6972 Tcl_WrongNumArgs(interp
, 1, objv
, "SCRIPT");
6975 if( logcallback
.pObj
){
6976 Tcl_DecrRefCount(logcallback
.pObj
);
6977 logcallback
.pObj
= 0;
6978 logcallback
.pInterp
= 0;
6979 sqlite3_config(SQLITE_CONFIG_LOG
, (void*)0, (void*)0);
6982 logcallback
.pObj
= objv
[1];
6983 Tcl_IncrRefCount(logcallback
.pObj
);
6984 logcallback
.pInterp
= interp
;
6985 sqlite3_config(SQLITE_CONFIG_LOG
, xLogcallback
, (void*)0);
6991 ** tcl_objproc COMMANDNAME ARGS...
6993 ** Run a TCL command using its objProc interface. Throw an error if
6994 ** the command has no objProc interface.
6996 static int SQLITE_TCLAPI
runAsObjProc(
7000 Tcl_Obj
*CONST objv
[]
7002 Tcl_CmdInfo cmdInfo
;
7004 Tcl_WrongNumArgs(interp
, 1, objv
, "COMMAND ...");
7007 if( !Tcl_GetCommandInfo(interp
, Tcl_GetString(objv
[1]), &cmdInfo
) ){
7008 Tcl_AppendResult(interp
, "command not found: ",
7009 Tcl_GetString(objv
[1]), (char*)0);
7012 if( cmdInfo
.objProc
==0 ){
7013 Tcl_AppendResult(interp
, "command has no objProc: ",
7014 Tcl_GetString(objv
[1]), (char*)0);
7017 return cmdInfo
.objProc(cmdInfo
.objClientData
, interp
, objc
-1, objv
+1);
7020 #ifndef SQLITE_OMIT_EXPLAIN
7022 ** WARNING: The following function, printExplainQueryPlan() is an exact
7023 ** copy of example code from eqp.in (eqp.html). If this code is modified,
7024 ** then the documentation copy needs to be modified as well.
7027 ** Argument pStmt is a prepared SQL statement. This function compiles
7028 ** an EXPLAIN QUERY PLAN command to report on the prepared statement,
7029 ** and prints the report to stdout using printf().
7031 int printExplainQueryPlan(sqlite3_stmt
*pStmt
){
7032 const char *zSql
; /* Input SQL */
7033 char *zExplain
; /* SQL with EXPLAIN QUERY PLAN prepended */
7034 sqlite3_stmt
*pExplain
; /* Compiled EXPLAIN QUERY PLAN command */
7035 int rc
; /* Return code from sqlite3_prepare_v2() */
7037 zSql
= sqlite3_sql(pStmt
);
7038 if( zSql
==0 ) return SQLITE_ERROR
;
7040 zExplain
= sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql
);
7041 if( zExplain
==0 ) return SQLITE_NOMEM
;
7043 rc
= sqlite3_prepare_v2(sqlite3_db_handle(pStmt
), zExplain
, -1, &pExplain
, 0);
7044 sqlite3_free(zExplain
);
7045 if( rc
!=SQLITE_OK
) return rc
;
7047 while( SQLITE_ROW
==sqlite3_step(pExplain
) ){
7048 int iSelectid
= sqlite3_column_int(pExplain
, 0);
7049 int iOrder
= sqlite3_column_int(pExplain
, 1);
7050 int iFrom
= sqlite3_column_int(pExplain
, 2);
7051 const char *zDetail
= (const char *)sqlite3_column_text(pExplain
, 3);
7053 printf("%d %d %d %s\n", iSelectid
, iOrder
, iFrom
, zDetail
);
7056 return sqlite3_finalize(pExplain
);
7059 static int SQLITE_TCLAPI
test_print_eqp(
7063 Tcl_Obj
*CONST objv
[]
7066 sqlite3_stmt
*pStmt
;
7069 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
7072 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
7073 rc
= printExplainQueryPlan(pStmt
);
7074 /* This is needed on Windows so that a test case using this
7075 ** function can open a read pipe and get the output of
7076 ** printExplainQueryPlan() immediately.
7079 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
7082 #endif /* SQLITE_OMIT_EXPLAIN */
7085 ** sqlite3_test_control VERB ARGS...
7087 static int SQLITE_TCLAPI
test_test_control(
7091 Tcl_Obj
*CONST objv
[]
7097 { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT
},
7098 { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP
},
7099 { "SQLITE_TESTCTRL_IMPOSTER", SQLITE_TESTCTRL_IMPOSTER
},
7100 { "SQLITE_TESTCTRL_INTERNAL_FUNCTIONS", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
},
7107 Tcl_WrongNumArgs(interp
, 1, objv
, "VERB ARGS...");
7111 rc
= Tcl_GetIndexFromObjStruct(
7112 interp
, objv
[1], aVerb
, sizeof(aVerb
[0]), "VERB", 0, &iVerb
7114 if( rc
!=TCL_OK
) return rc
;
7116 iFlag
= aVerb
[iVerb
].i
;
7118 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
: {
7121 Tcl_WrongNumArgs(interp
, 2, objv
, "DB");
7124 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7125 sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
, db
);
7128 case SQLITE_TESTCTRL_LOCALTIME_FAULT
: {
7131 Tcl_WrongNumArgs(interp
, 2, objv
, "ONOFF");
7134 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
7135 sqlite3_test_control(iFlag
, val
);
7139 case SQLITE_TESTCTRL_SORTER_MMAP
: {
7143 Tcl_WrongNumArgs(interp
, 2, objv
, "DB LIMIT");
7146 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7147 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
7148 sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP
, db
, val
);
7152 case SQLITE_TESTCTRL_IMPOSTER
: {
7154 const char *zDbName
;
7157 Tcl_WrongNumArgs(interp
, 2, objv
, "DB dbName onOff tnum");
7160 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7161 zDbName
= Tcl_GetString(objv
[3]);
7162 if( Tcl_GetIntFromObj(interp
, objv
[4], &onOff
) ) return TCL_ERROR
;
7163 if( Tcl_GetIntFromObj(interp
, objv
[5], &tnum
) ) return TCL_ERROR
;
7164 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER
, db
, zDbName
, onOff
, tnum
);
7169 Tcl_ResetResult(interp
);
7174 #include <sys/time.h>
7175 #include <sys/resource.h>
7177 static int SQLITE_TCLAPI
test_getrusage(
7181 Tcl_Obj
*CONST objv
[]
7185 memset(&r
, 0, sizeof(r
));
7186 getrusage(RUSAGE_SELF
, &r
);
7188 sqlite3_snprintf(sizeof(buf
), buf
,
7189 "ru_utime=%d.%06d ru_stime=%d.%06d ru_minflt=%d ru_majflt=%d",
7190 (int)r
.ru_utime
.tv_sec
, (int)r
.ru_utime
.tv_usec
,
7191 (int)r
.ru_stime
.tv_sec
, (int)r
.ru_stime
.tv_usec
,
7192 (int)r
.ru_minflt
, (int)r
.ru_majflt
7194 Tcl_SetObjResult(interp
, Tcl_NewStringObj(buf
, -1));
7201 ** Information passed from the main thread into the windows file locker
7202 ** background thread.
7204 struct win32FileLocker
{
7205 char *evName
; /* Name of event to signal thread startup */
7206 HANDLE h
; /* Handle of the file to be locked */
7207 int delay1
; /* Delay before locking */
7208 int delay2
; /* Delay before unlocking */
7209 int ok
; /* Finished ok */
7210 int err
; /* True if an error occurs */
7216 #include <process.h>
7218 ** The background thread that does file locking.
7220 static void SQLITE_CDECL
win32_file_locker(void *pAppData
){
7221 struct win32FileLocker
*p
= (struct win32FileLocker
*)pAppData
;
7223 HANDLE ev
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, p
->evName
);
7229 if( p
->delay1
) Sleep(p
->delay1
);
7230 if( LockFile(p
->h
, 0, 0, 100000000, 0) ){
7232 UnlockFile(p
->h
, 0, 0, 100000000, 0);
7246 ** lock_win32_file FILENAME DELAY1 DELAY2
7248 ** Get an exclusive manditory lock on file for DELAY2 milliseconds.
7249 ** Wait DELAY1 milliseconds before acquiring the lock.
7251 static int SQLITE_TCLAPI
win32_file_lock(
7255 Tcl_Obj
*CONST objv
[]
7257 static struct win32FileLocker x
= { "win32_file_lock", 0, 0, 0, 0, 0 };
7258 const char *zFilename
;
7264 if( objc
!=4 && objc
!=1 ){
7265 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME DELAY1 DELAY2");
7269 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d %d %d %d %d",
7270 x
.ok
, x
.err
, x
.delay1
, x
.delay2
, x
.h
);
7271 Tcl_AppendResult(interp
, zBuf
, (char*)0);
7274 while( x
.h
&& retry
<30 ){
7279 Tcl_AppendResult(interp
, "busy", (char*)0);
7282 if( Tcl_GetIntFromObj(interp
, objv
[2], &x
.delay1
) ) return TCL_ERROR
;
7283 if( Tcl_GetIntFromObj(interp
, objv
[3], &x
.delay2
) ) return TCL_ERROR
;
7284 zFilename
= Tcl_GetString(objv
[1]);
7285 x
.h
= CreateFile(zFilename
, GENERIC_READ
|GENERIC_WRITE
,
7286 FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, OPEN_ALWAYS
,
7287 FILE_ATTRIBUTE_NORMAL
, 0);
7289 Tcl_AppendResult(interp
, "cannot open file: ", zFilename
, (char*)0);
7292 ev
= CreateEvent(NULL
, TRUE
, FALSE
, x
.evName
);
7294 Tcl_AppendResult(interp
, "cannot create event: ", x
.evName
, (char*)0);
7297 _beginthread(win32_file_locker
, 0, (void*)&x
);
7299 if ( (wResult
= WaitForSingleObject(ev
, 10000))!=WAIT_OBJECT_0
){
7300 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "0x%x", wResult
);
7301 Tcl_AppendResult(interp
, "wait failed: ", zBuf
, (char*)0);
7310 ** exists_win32_path PATH
7312 ** Returns non-zero if the specified path exists, whose fully qualified name
7313 ** may exceed 260 characters if it is prefixed with "\\?\".
7315 static int SQLITE_TCLAPI
win32_exists_path(
7319 Tcl_Obj
*CONST objv
[]
7322 Tcl_WrongNumArgs(interp
, 1, objv
, "PATH");
7325 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(
7326 GetFileAttributesW( Tcl_GetUnicode(objv
[1]))!=INVALID_FILE_ATTRIBUTES
));
7331 ** find_win32_file PATTERN
7333 ** Returns a list of entries in a directory that match the specified pattern,
7334 ** whose fully qualified name may exceed 248 characters if it is prefixed with
7337 static int SQLITE_TCLAPI
win32_find_file(
7341 Tcl_Obj
*CONST objv
[]
7343 HANDLE hFindFile
= INVALID_HANDLE_VALUE
;
7344 WIN32_FIND_DATAW findData
;
7348 Tcl_WrongNumArgs(interp
, 1, objv
, "PATTERN");
7351 hFindFile
= FindFirstFileW(Tcl_GetUnicode(objv
[1]), &findData
);
7352 if( hFindFile
==INVALID_HANDLE_VALUE
){
7353 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7356 listObj
= Tcl_NewObj();
7357 Tcl_IncrRefCount(listObj
);
7359 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewUnicodeObj(
7360 findData
.cFileName
, -1));
7361 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewWideIntObj(
7362 findData
.dwFileAttributes
));
7363 } while( FindNextFileW(hFindFile
, &findData
) );
7364 lastErrno
= GetLastError();
7365 if( lastErrno
!=NO_ERROR
&& lastErrno
!=ERROR_NO_MORE_FILES
){
7366 FindClose(hFindFile
);
7367 Tcl_DecrRefCount(listObj
);
7368 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7371 FindClose(hFindFile
);
7372 Tcl_SetObjResult(interp
, listObj
);
7377 ** delete_win32_file FILENAME
7379 ** Deletes the specified file, whose fully qualified name may exceed 260
7380 ** characters if it is prefixed with "\\?\".
7382 static int SQLITE_TCLAPI
win32_delete_file(
7386 Tcl_Obj
*CONST objv
[]
7389 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME");
7392 if( !DeleteFileW(Tcl_GetUnicode(objv
[1])) ){
7393 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7396 Tcl_ResetResult(interp
);
7401 ** make_win32_dir DIRECTORY
7403 ** Creates the specified directory, whose fully qualified name may exceed 248
7404 ** characters if it is prefixed with "\\?\".
7406 static int SQLITE_TCLAPI
win32_mkdir(
7410 Tcl_Obj
*CONST objv
[]
7413 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
7416 if( !CreateDirectoryW(Tcl_GetUnicode(objv
[1]), NULL
) ){
7417 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7420 Tcl_ResetResult(interp
);
7425 ** remove_win32_dir DIRECTORY
7427 ** Removes the specified directory, whose fully qualified name may exceed 248
7428 ** characters if it is prefixed with "\\?\".
7430 static int SQLITE_TCLAPI
win32_rmdir(
7434 Tcl_Obj
*CONST objv
[]
7437 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
7440 if( !RemoveDirectoryW(Tcl_GetUnicode(objv
[1])) ){
7441 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7444 Tcl_ResetResult(interp
);
7451 ** optimization_control DB OPT BOOLEAN
7453 ** Enable or disable query optimizations using the sqlite3_test_control()
7454 ** interface. Disable if BOOLEAN is false and enable if BOOLEAN is true.
7455 ** OPT is the name of the optimization to be disabled.
7457 static int SQLITE_TCLAPI
optimization_control(
7461 Tcl_Obj
*CONST objv
[]
7468 static const struct {
7469 const char *zOptName
;
7472 { "all", SQLITE_AllOpts
},
7474 { "query-flattener", SQLITE_QueryFlattener
},
7475 { "groupby-order", SQLITE_GroupByOrder
},
7476 { "factor-constants", SQLITE_FactorOutConst
},
7477 { "distinct-opt", SQLITE_DistinctOpt
},
7478 { "cover-idx-scan", SQLITE_CoverIdxScan
},
7479 { "order-by-idx-join", SQLITE_OrderByIdxJoin
},
7480 { "transitive", SQLITE_Transitive
},
7481 { "omit-noop-join", SQLITE_OmitNoopJoin
},
7482 { "stat4", SQLITE_Stat4
},
7483 { "skip-scan", SQLITE_SkipScan
},
7484 { "push-down", SQLITE_PushDown
},
7488 Tcl_WrongNumArgs(interp
, 1, objv
, "DB OPT BOOLEAN");
7491 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7492 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &onoff
) ) return TCL_ERROR
;
7493 zOpt
= Tcl_GetString(objv
[2]);
7494 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
7495 if( strcmp(zOpt
, aOpt
[i
].zOptName
)==0 ){
7496 mask
= aOpt
[i
].mask
;
7500 if( onoff
) mask
= ~mask
;
7501 if( i
>=sizeof(aOpt
)/sizeof(aOpt
[0]) ){
7502 Tcl_AppendResult(interp
, "unknown optimization - should be one of:",
7504 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
7505 Tcl_AppendResult(interp
, " ", aOpt
[i
].zOptName
, (char*)0);
7509 sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS
, db
, mask
);
7514 ** load_static_extension DB NAME ...
7516 ** Load one or more statically linked extensions.
7518 static int SQLITE_TCLAPI
tclLoadStaticExtensionCmd(
7522 Tcl_Obj
*CONST objv
[]
7524 extern int sqlite3_amatch_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7525 extern int sqlite3_carray_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7526 extern int sqlite3_closure_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7527 extern int sqlite3_csv_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7528 extern int sqlite3_eval_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7529 extern int sqlite3_explain_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7530 extern int sqlite3_fileio_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7531 extern int sqlite3_decimal_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7532 extern int sqlite3_fuzzer_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7533 extern int sqlite3_ieee_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7534 extern int sqlite3_nextchar_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7535 extern int sqlite3_percentile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7536 #ifndef SQLITE_OMIT_VIRTUALTABLE
7537 extern int sqlite3_prefixes_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7539 extern int sqlite3_regexp_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7540 extern int sqlite3_remember_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7541 extern int sqlite3_series_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7542 extern int sqlite3_spellfix_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7543 extern int sqlite3_totype_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7544 extern int sqlite3_wholenumber_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7545 extern int sqlite3_unionvtab_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7546 #ifdef SQLITE_HAVE_ZLIB
7547 extern int sqlite3_zipfile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7549 static const struct {
7550 const char *zExtName
;
7551 int (*pInit
)(sqlite3
*,char**,const sqlite3_api_routines
*);
7553 { "amatch", sqlite3_amatch_init
},
7554 { "carray", sqlite3_carray_init
},
7555 { "closure", sqlite3_closure_init
},
7556 { "csv", sqlite3_csv_init
},
7557 { "decimal", sqlite3_decimal_init
},
7558 { "eval", sqlite3_eval_init
},
7559 { "explain", sqlite3_explain_init
},
7560 { "fileio", sqlite3_fileio_init
},
7561 { "fuzzer", sqlite3_fuzzer_init
},
7562 { "ieee754", sqlite3_ieee_init
},
7563 { "nextchar", sqlite3_nextchar_init
},
7564 { "percentile", sqlite3_percentile_init
},
7565 #ifndef SQLITE_OMIT_VIRTUALTABLE
7566 { "prefixes", sqlite3_prefixes_init
},
7568 { "regexp", sqlite3_regexp_init
},
7569 { "remember", sqlite3_remember_init
},
7570 { "series", sqlite3_series_init
},
7571 { "spellfix", sqlite3_spellfix_init
},
7572 { "totype", sqlite3_totype_init
},
7573 { "unionvtab", sqlite3_unionvtab_init
},
7574 { "wholenumber", sqlite3_wholenumber_init
},
7575 #ifdef SQLITE_HAVE_ZLIB
7576 { "zipfile", sqlite3_zipfile_init
},
7584 Tcl_WrongNumArgs(interp
, 1, objv
, "DB NAME ...");
7587 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7588 for(j
=2; j
<objc
; j
++){
7589 zName
= Tcl_GetString(objv
[j
]);
7590 for(i
=0; i
<ArraySize(aExtension
); i
++){
7591 if( strcmp(zName
, aExtension
[i
].zExtName
)==0 ) break;
7593 if( i
>=ArraySize(aExtension
) ){
7594 Tcl_AppendResult(interp
, "no such extension: ", zName
, (char*)0);
7597 if( aExtension
[i
].pInit
){
7598 rc
= aExtension
[i
].pInit(db
, &zErrMsg
, 0);
7602 if( rc
!=SQLITE_OK
|| zErrMsg
){
7603 Tcl_AppendResult(interp
, "initialization of ", zName
, " failed: ", zErrMsg
,
7605 sqlite3_free(zErrMsg
);
7613 ** sorter_test_fakeheap BOOL
7616 static int SQLITE_TCLAPI
sorter_test_fakeheap(
7620 Tcl_Obj
*CONST objv
[]
7624 Tcl_WrongNumArgs(interp
, 1, objv
, "BOOL");
7628 if( Tcl_GetBooleanFromObj(interp
, objv
[1], &bArg
) ){
7633 if( sqlite3GlobalConfig
.pHeap
==0 ){
7634 sqlite3GlobalConfig
.pHeap
= SQLITE_INT_TO_PTR(-1);
7637 if( sqlite3GlobalConfig
.pHeap
==SQLITE_INT_TO_PTR(-1) ){
7638 sqlite3GlobalConfig
.pHeap
= 0;
7642 Tcl_ResetResult(interp
);
7647 ** sorter_test_sort4_helper DB SQL1 NSTEP SQL2
7649 ** Compile SQL statement $SQL1 and step it $NSTEP times. For each row,
7650 ** check that the leftmost and rightmost columns returned are both integers,
7651 ** and that both contain the same value.
7653 ** Then execute statement $SQL2. Check that the statement returns the same
7654 ** set of integers in the same order as in the previous step (using $SQL1).
7656 static int SQLITE_TCLAPI
sorter_test_sort4_helper(
7660 Tcl_Obj
*CONST objv
[]
7666 unsigned int iCksum1
= 0;
7667 unsigned int iCksum2
= 0;
7671 sqlite3_stmt
*pStmt
;
7674 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SQL1 NSTEP SQL2");
7678 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7679 zSql1
= Tcl_GetString(objv
[2]);
7680 if( Tcl_GetIntFromObj(interp
, objv
[3], &nStep
) ) return TCL_ERROR
;
7681 zSql2
= Tcl_GetString(objv
[4]);
7683 rc
= sqlite3_prepare_v2(db
, zSql1
, -1, &pStmt
, 0);
7684 if( rc
!=SQLITE_OK
) goto sql_error
;
7686 iB
= sqlite3_column_count(pStmt
)-1;
7687 for(iStep
=0; iStep
<nStep
&& SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
7688 int a
= sqlite3_column_int(pStmt
, 0);
7689 if( a
!=sqlite3_column_int(pStmt
, iB
) ){
7690 Tcl_AppendResult(interp
, "data error: (a!=b)", 0);
7694 iCksum1
+= (iCksum1
<< 3) + (unsigned int)a
;
7696 rc
= sqlite3_finalize(pStmt
);
7697 if( rc
!=SQLITE_OK
) goto sql_error
;
7699 rc
= sqlite3_prepare_v2(db
, zSql2
, -1, &pStmt
, 0);
7700 if( rc
!=SQLITE_OK
) goto sql_error
;
7701 for(iStep
=0; SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
7702 int a
= sqlite3_column_int(pStmt
, 0);
7703 iCksum2
+= (iCksum2
<< 3) + (unsigned int)a
;
7705 rc
= sqlite3_finalize(pStmt
);
7706 if( rc
!=SQLITE_OK
) goto sql_error
;
7708 if( iCksum1
!=iCksum2
){
7709 Tcl_AppendResult(interp
, "checksum mismatch", 0);
7715 Tcl_AppendResult(interp
, "sql error: ", sqlite3_errmsg(db
), 0);
7720 #ifdef SQLITE_USER_AUTHENTICATION
7721 #include "sqlite3userauth.h"
7723 ** tclcmd: sqlite3_user_authenticate DB USERNAME PASSWORD
7725 static int SQLITE_TCLAPI
test_user_authenticate(
7726 ClientData clientData
, /* Unused */
7727 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7728 int objc
, /* Number of arguments */
7729 Tcl_Obj
*CONST objv
[] /* Command arguments */
7738 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD");
7741 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7744 zUser
= Tcl_GetString(objv
[2]);
7745 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
7746 rc
= sqlite3_user_authenticate(db
, zUser
, zPasswd
, nPasswd
);
7747 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7750 #endif /* SQLITE_USER_AUTHENTICATION */
7752 #ifdef SQLITE_USER_AUTHENTICATION
7754 ** tclcmd: sqlite3_user_add DB USERNAME PASSWORD ISADMIN
7756 static int SQLITE_TCLAPI
test_user_add(
7757 ClientData clientData
, /* Unused */
7758 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7759 int objc
, /* Number of arguments */
7760 Tcl_Obj
*CONST objv
[] /* Command arguments */
7770 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
7773 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7776 zUser
= Tcl_GetString(objv
[2]);
7777 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
7778 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
7779 rc
= sqlite3_user_add(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
7780 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7783 #endif /* SQLITE_USER_AUTHENTICATION */
7785 #ifdef SQLITE_USER_AUTHENTICATION
7787 ** tclcmd: sqlite3_user_change DB USERNAME PASSWORD ISADMIN
7789 static int SQLITE_TCLAPI
test_user_change(
7790 ClientData clientData
, /* Unused */
7791 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7792 int objc
, /* Number of arguments */
7793 Tcl_Obj
*CONST objv
[] /* Command arguments */
7803 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
7806 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7809 zUser
= Tcl_GetString(objv
[2]);
7810 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
7811 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
7812 rc
= sqlite3_user_change(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
7813 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7816 #endif /* SQLITE_USER_AUTHENTICATION */
7818 #ifdef SQLITE_USER_AUTHENTICATION
7820 ** tclcmd: sqlite3_user_delete DB USERNAME
7822 static int SQLITE_TCLAPI
test_user_delete(
7823 ClientData clientData
, /* Unused */
7824 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7825 int objc
, /* Number of arguments */
7826 Tcl_Obj
*CONST objv
[] /* Command arguments */
7833 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME");
7836 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7839 zUser
= Tcl_GetString(objv
[2]);
7840 rc
= sqlite3_user_delete(db
, zUser
);
7841 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7844 #endif /* SQLITE_USER_AUTHENTICATION */
7847 ** tclcmd: bad_behavior TYPE
7849 ** Do some things that should trigger a valgrind or -fsanitize=undefined
7850 ** warning. This is used to verify that errors and warnings output by those
7851 ** tools are detected by the test scripts.
7854 ** 1 Overflow a signed integer
7855 ** 2 Jump based on an uninitialized variable
7856 ** 3 Read after free
7859 static int SQLITE_TCLAPI
test_bad_behavior(
7860 ClientData clientData
, /* Pointer to an integer containing zero */
7861 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7862 int objc
, /* Number of arguments */
7863 Tcl_Obj
*CONST objv
[] /* Command arguments */
7867 int i
= *(int*)clientData
;
7872 Tcl_WrongNumArgs(interp
, 1, objv
, "TYPE");
7875 if( Tcl_GetIntFromObj(interp
, objv
[1], &iType
) ) return TCL_ERROR
;
7878 xyz
= 0x7fffff00 - i
;
7880 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xyz
));
7885 if( w
[i
]>0 ) w
[1]++;
7886 Tcl_SetObjResult(interp
, Tcl_NewIntObj(w
[1]));
7890 a
= malloc( sizeof(int)*10 );
7891 for(j
=0; j
<10; j
++) a
[j
] = j
;
7893 Tcl_SetObjResult(interp
, Tcl_NewIntObj(a
[i
]));
7897 Tcl_Panic("Deliberate panic");
7905 ** tclcmd: register_dbstat_vtab DB
7907 ** Cause the dbstat virtual table to be available on the connection DB
7909 static int SQLITE_TCLAPI
test_register_dbstat_vtab(
7913 Tcl_Obj
*CONST objv
[]
7915 #ifdef SQLITE_OMIT_VIRTUALTABLE
7916 Tcl_AppendResult(interp
, "dbstat not available because of "
7917 "SQLITE_OMIT_VIRTUALTABLE", (void*)0);
7920 struct SqliteDb
{ sqlite3
*db
; };
7922 Tcl_CmdInfo cmdInfo
;
7925 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
7929 zDb
= Tcl_GetString(objv
[1]);
7930 if( Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
7931 sqlite3
* db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
7932 sqlite3DbstatRegister(db
);
7935 #endif /* SQLITE_OMIT_VIRTUALTABLE */
7939 ** tclcmd: sqlite3_db_config DB SETTING VALUE
7941 ** Invoke sqlite3_db_config() for one of the setting values.
7943 static int SQLITE_TCLAPI
test_sqlite3_db_config(
7947 Tcl_Obj
*CONST objv
[]
7949 static const struct {
7953 { "FKEY", SQLITE_DBCONFIG_ENABLE_FKEY
},
7954 { "TRIGGER", SQLITE_DBCONFIG_ENABLE_TRIGGER
},
7955 { "FTS3_TOKENIZER", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
},
7956 { "LOAD_EXTENSION", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
},
7957 { "NO_CKPT_ON_CLOSE", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
},
7958 { "QPSG", SQLITE_DBCONFIG_ENABLE_QPSG
},
7959 { "TRIGGER_EQP", SQLITE_DBCONFIG_TRIGGER_EQP
},
7960 { "RESET_DB", SQLITE_DBCONFIG_RESET_DATABASE
},
7961 { "DEFENSIVE", SQLITE_DBCONFIG_DEFENSIVE
},
7962 { "WRITABLE_SCHEMA", SQLITE_DBCONFIG_WRITABLE_SCHEMA
},
7963 { "LEGACY_ALTER_TABLE", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
},
7964 { "DQS_DML", SQLITE_DBCONFIG_DQS_DML
},
7965 { "DQS_DDL", SQLITE_DBCONFIG_DQS_DDL
},
7966 { "LEGACY_FILE_FORMAT", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
},
7970 const char *zSetting
;
7973 if( objc
!=4 && objc
!=3 ){
7974 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SETTING [VALUE]");
7977 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7978 zSetting
= Tcl_GetString(objv
[2]);
7979 if( sqlite3_strglob("SQLITE_*", zSetting
)==0 ) zSetting
+= 7;
7980 if( sqlite3_strglob("DBCONFIG_*", zSetting
)==0 ) zSetting
+= 9;
7981 if( sqlite3_strglob("ENABLE_*", zSetting
)==0 ) zSetting
+= 7;
7982 for(i
=0; i
<ArraySize(aSetting
); i
++){
7983 if( strcmp(zSetting
, aSetting
[i
].zName
)==0 ) break;
7985 if( i
>=ArraySize(aSetting
) ){
7986 Tcl_SetObjResult(interp
,
7987 Tcl_NewStringObj("unknown sqlite3_db_config setting", -1));
7991 if( Tcl_GetIntFromObj(interp
, objv
[3], &v
) ) return TCL_ERROR
;
7995 sqlite3_db_config(db
, aSetting
[i
].eVal
, v
, &v
);
7996 Tcl_SetObjResult(interp
, Tcl_NewIntObj(v
));
8000 ** tclcmd: sqlite3_txn_state DB ?SCHEMA?
8002 ** Invoke sqlite3_txn_state(DB,SCHEMA) and return the
8003 ** numeric value that results. Use NULL for SCHEMA if the 3 argument
8006 static int SQLITE_TCLAPI
test_sqlite3_txn_state(
8010 Tcl_Obj
*CONST objv
[]
8013 const char *zSchema
;
8016 if( objc
!=2 && objc
!=3 ){
8017 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?SCHEMA?");
8020 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8021 zSchema
= objc
==3 ? Tcl_GetString(objv
[2]) : 0;
8022 iTxn
= sqlite3_txn_state(db
, zSchema
);
8023 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iTxn
));
8028 ** Change the name of the main database schema from "main" to "icecube".
8030 static int SQLITE_TCLAPI
test_dbconfig_maindbname_icecube(
8034 Tcl_Obj
*CONST objv
[]
8038 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
8040 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
8043 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8044 rc
= sqlite3_db_config(db
, SQLITE_DBCONFIG_MAINDBNAME
, "icecube");
8045 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
8051 ** Usage: sqlite3_mmap_warm DB DBNAME
8053 static int SQLITE_TCLAPI
test_mmap_warm(
8057 Tcl_Obj
*CONST objv
[]
8059 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
8060 extern int sqlite3_mmap_warm(sqlite3
*db
, const char *);
8062 if( objc
!=2 && objc
!=3 ){
8063 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?DBNAME?");
8068 const char *zDb
= 0;
8069 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8071 zDb
= Tcl_GetString(objv
[2]);
8073 rc
= sqlite3_mmap_warm(db
, zDb
);
8074 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
8080 ** Usage: test_write_db DB OFFSET DATA
8082 ** Obtain the sqlite3_file* object for the database file for the "main" db
8083 ** of handle DB. Then invoke its xWrite method to write data DATA to offset
8086 static int SQLITE_TCLAPI
test_write_db(
8090 Tcl_Obj
*CONST objv
[]
8093 Tcl_WideInt iOff
= 0;
8094 const unsigned char *aData
= 0;
8096 sqlite3_file
*pFile
= 0;
8100 Tcl_WrongNumArgs(interp
, 1, objv
, "DB OFFSET DATA");
8103 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8104 if( Tcl_GetWideIntFromObj(interp
, objv
[2], &iOff
) ) return TCL_ERROR
;
8105 aData
= Tcl_GetByteArrayFromObj(objv
[3], &nData
);
8107 sqlite3_file_control(db
, "main", SQLITE_FCNTL_FILE_POINTER
, (void*)&pFile
);
8108 rc
= pFile
->pMethods
->xWrite(pFile
, aData
, nData
, iOff
);
8110 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
8115 ** Usage: sqlite3_register_cksumvfs
8118 static int SQLITE_TCLAPI
test_register_cksumvfs(
8122 Tcl_Obj
*CONST objv
[]
8125 Tcl_WrongNumArgs(interp
, 1, objv
, "");
8128 extern int sqlite3_register_cksumvfs(const char*);
8129 int rc
= sqlite3_register_cksumvfs(0);
8130 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
8136 ** Usage: sqlite3_unregister_cksumvfs
8139 static int SQLITE_TCLAPI
test_unregister_cksumvfs(
8143 Tcl_Obj
*CONST objv
[]
8146 Tcl_WrongNumArgs(interp
, 1, objv
, "");
8149 extern int sqlite3_unregister_cksumvfs(void);
8150 int rc
= sqlite3_unregister_cksumvfs();
8151 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
8157 ** Usage: decode_hexdb TEXT
8159 ** Example: db deserialize [decode_hexdb $output_of_dbtotxt]
8161 ** This routine returns a byte-array for an SQLite database file that
8162 ** is constructed from a text input which is the output of the "dbtotxt"
8165 static int SQLITE_TCLAPI
test_decode_hexdb(
8169 Tcl_Obj
*CONST objv
[]
8171 const char *zIn
= 0;
8172 unsigned char *a
= 0;
8181 Tcl_WrongNumArgs(interp
, 1, objv
, "HEXDB");
8184 zIn
= Tcl_GetString(objv
[1]);
8185 for(i
=0; zIn
[i
]; i
=iNext
){
8187 for(iNext
=i
; zIn
[iNext
] && zIn
[iNext
]!='\n'; iNext
++){}
8188 if( zIn
[iNext
]=='\n' ) iNext
++;
8189 while( zIn
[i
]==' ' || zIn
[i
]=='\t' ){ i
++; }
8192 rc
= sscanf(zIn
+i
, "| size %d pagesize %d", &n
, &pgsz
);
8193 if( rc
!=2 ) continue;
8194 if( pgsz
<512 || pgsz
>65536 || (pgsz
&(pgsz
-1))!=0 ){
8195 Tcl_AppendResult(interp
, "bad 'pagesize' field", (void*)0);
8198 n
= (n
+pgsz
-1)&~(pgsz
-1); /* Round n up to the next multiple of pgsz */
8200 Tcl_AppendResult(interp
, "bad 'size' field", (void*)0);
8205 Tcl_AppendResult(interp
, "out of memory", (void*)0);
8211 rc
= sscanf(zIn
+i
, "| page %d offset %d", &j
, &k
);
8216 rc
= sscanf(zIn
+i
,"| %d: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
8217 &j
, &x
[0], &x
[1], &x
[2], &x
[3], &x
[4], &x
[5], &x
[6], &x
[7],
8218 &x
[8], &x
[9], &x
[10], &x
[11], &x
[12], &x
[13], &x
[14], &x
[15]);
8223 for(ii
=0; ii
<16; ii
++) a
[k
+ii
] = x
[ii
]&0xff;
8228 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(a
, n
));
8235 ** Register commands with the TCL interpreter.
8237 int Sqlitetest1_Init(Tcl_Interp
*interp
){
8238 extern int sqlite3_search_count
;
8239 extern int sqlite3_found_count
;
8240 extern int sqlite3_interrupt_count
;
8241 extern int sqlite3_open_file_count
;
8242 extern int sqlite3_sort_count
;
8243 extern int sqlite3_current_time
;
8244 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
8245 extern int sqlite3_hostid_num
;
8247 extern int sqlite3_max_blobsize
;
8248 extern int SQLITE_TCLAPI
sqlite3BtreeSharedCacheReport(void*,
8249 Tcl_Interp
*,int,Tcl_Obj
*CONST
*);
8250 static int iZero
= 0;
8255 { "db_enter", (Tcl_CmdProc
*)db_enter
},
8256 { "db_leave", (Tcl_CmdProc
*)db_leave
},
8257 { "sqlite3_mprintf_int", (Tcl_CmdProc
*)sqlite3_mprintf_int
},
8258 { "sqlite3_mprintf_int64", (Tcl_CmdProc
*)sqlite3_mprintf_int64
},
8259 { "sqlite3_mprintf_long", (Tcl_CmdProc
*)sqlite3_mprintf_long
},
8260 { "sqlite3_mprintf_str", (Tcl_CmdProc
*)sqlite3_mprintf_str
},
8261 { "sqlite3_snprintf_str", (Tcl_CmdProc
*)sqlite3_snprintf_str
},
8262 { "sqlite3_mprintf_stronly", (Tcl_CmdProc
*)sqlite3_mprintf_stronly
},
8263 { "sqlite3_mprintf_double", (Tcl_CmdProc
*)sqlite3_mprintf_double
},
8264 { "sqlite3_mprintf_scaled", (Tcl_CmdProc
*)sqlite3_mprintf_scaled
},
8265 { "sqlite3_mprintf_hexdouble", (Tcl_CmdProc
*)sqlite3_mprintf_hexdouble
},
8266 { "sqlite3_mprintf_z_test", (Tcl_CmdProc
*)test_mprintf_z
},
8267 { "sqlite3_mprintf_n_test", (Tcl_CmdProc
*)test_mprintf_n
},
8268 { "sqlite3_snprintf_int", (Tcl_CmdProc
*)test_snprintf_int
},
8269 { "sqlite3_last_insert_rowid", (Tcl_CmdProc
*)test_last_rowid
},
8270 { "sqlite3_exec_printf", (Tcl_CmdProc
*)test_exec_printf
},
8271 { "sqlite3_exec_hex", (Tcl_CmdProc
*)test_exec_hex
},
8272 { "sqlite3_exec", (Tcl_CmdProc
*)test_exec
},
8273 { "sqlite3_exec_nr", (Tcl_CmdProc
*)test_exec_nr
},
8274 #ifndef SQLITE_OMIT_GET_TABLE
8275 { "sqlite3_get_table_printf", (Tcl_CmdProc
*)test_get_table_printf
},
8277 { "sqlite3_close", (Tcl_CmdProc
*)sqlite_test_close
},
8278 { "sqlite3_close_v2", (Tcl_CmdProc
*)sqlite_test_close_v2
},
8279 { "sqlite3_create_function", (Tcl_CmdProc
*)test_create_function
},
8280 { "sqlite3_create_aggregate", (Tcl_CmdProc
*)test_create_aggregate
},
8281 { "sqlite3_drop_modules", (Tcl_CmdProc
*)test_drop_modules
},
8282 { "sqlite_register_test_function", (Tcl_CmdProc
*)test_register_func
},
8283 { "sqlite_abort", (Tcl_CmdProc
*)sqlite_abort
},
8284 { "sqlite_bind", (Tcl_CmdProc
*)test_bind
},
8285 { "breakpoint", (Tcl_CmdProc
*)test_breakpoint
},
8286 { "sqlite3_key", (Tcl_CmdProc
*)test_key
},
8287 { "sqlite3_rekey", (Tcl_CmdProc
*)test_rekey
},
8288 { "sqlite_set_magic", (Tcl_CmdProc
*)sqlite_set_magic
},
8289 { "sqlite3_interrupt", (Tcl_CmdProc
*)test_interrupt
},
8290 { "sqlite_delete_function", (Tcl_CmdProc
*)delete_function
},
8291 { "sqlite_delete_collation", (Tcl_CmdProc
*)delete_collation
},
8292 { "sqlite3_get_autocommit", (Tcl_CmdProc
*)get_autocommit
},
8293 { "sqlite3_busy_timeout", (Tcl_CmdProc
*)test_busy_timeout
},
8294 { "printf", (Tcl_CmdProc
*)test_printf
},
8295 { "sqlite3IoTrace", (Tcl_CmdProc
*)test_io_trace
},
8296 { "clang_sanitize_address", (Tcl_CmdProc
*)clang_sanitize_address
},
8300 Tcl_ObjCmdProc
*xProc
;
8303 { "sqlite3_db_config", test_sqlite3_db_config
, 0 },
8304 { "sqlite3_txn_state", test_sqlite3_txn_state
, 0 },
8305 { "bad_behavior", test_bad_behavior
, (void*)&iZero
},
8306 { "register_dbstat_vtab", test_register_dbstat_vtab
},
8307 { "sqlite3_connection_pointer", get_sqlite_pointer
, 0 },
8308 { "intarray_addr", test_intarray_addr
, 0 },
8309 { "int64array_addr", test_int64array_addr
, 0 },
8310 { "doublearray_addr", test_doublearray_addr
, 0 },
8311 { "textarray_addr", test_textarray_addr
, 0 },
8312 { "sqlite3_bind_int", test_bind_int
, 0 },
8313 { "sqlite3_bind_zeroblob", test_bind_zeroblob
, 0 },
8314 { "sqlite3_bind_zeroblob64", test_bind_zeroblob64
, 0 },
8315 { "sqlite3_bind_int64", test_bind_int64
, 0 },
8316 { "sqlite3_bind_double", test_bind_double
, 0 },
8317 { "sqlite3_bind_null", test_bind_null
,0 },
8318 { "sqlite3_bind_text", test_bind_text
,0 },
8319 { "sqlite3_bind_text16", test_bind_text16
,0 },
8320 { "sqlite3_bind_blob", test_bind_blob
,0 },
8321 #ifndef SQLITE_OMIT_VIRTUALTABLE
8322 { "sqlite3_carray_bind", test_carray_bind
,0 },
8324 { "sqlite3_bind_parameter_count", test_bind_parameter_count
, 0},
8325 { "sqlite3_bind_parameter_name", test_bind_parameter_name
, 0},
8326 { "sqlite3_bind_parameter_index", test_bind_parameter_index
, 0},
8327 { "sqlite3_clear_bindings", test_clear_bindings
, 0},
8328 { "sqlite3_sleep", test_sleep
, 0},
8329 { "sqlite3_errcode", test_errcode
,0 },
8330 { "sqlite3_extended_errcode", test_ex_errcode
,0 },
8331 { "sqlite3_errmsg", test_errmsg
,0 },
8332 { "sqlite3_errmsg16", test_errmsg16
,0 },
8333 { "sqlite3_open", test_open
,0 },
8334 { "sqlite3_open16", test_open16
,0 },
8335 { "sqlite3_open_v2", test_open_v2
,0 },
8336 { "sqlite3_complete16", test_complete16
,0 },
8337 { "sqlite3_normalize", test_normalize
,0 },
8339 { "sqlite3_prepare", test_prepare
,0 },
8340 { "sqlite3_prepare16", test_prepare16
,0 },
8341 { "sqlite3_prepare_v2", test_prepare_v2
,0 },
8342 { "sqlite3_prepare_v3", test_prepare_v3
,0 },
8343 { "sqlite3_prepare_tkt3134", test_prepare_tkt3134
, 0},
8344 { "sqlite3_prepare16_v2", test_prepare16_v2
,0 },
8345 { "sqlite3_finalize", test_finalize
,0 },
8346 { "sqlite3_stmt_status", test_stmt_status
,0 },
8347 { "sqlite3_reset", test_reset
,0 },
8348 { "sqlite3_expired", test_expired
,0 },
8349 { "sqlite3_transfer_bindings", test_transfer_bind
,0 },
8350 { "sqlite3_changes", test_changes
,0 },
8351 { "sqlite3_step", test_step
,0 },
8352 { "sqlite3_sql", test_sql
,0 },
8353 { "sqlite3_expanded_sql", test_ex_sql
,0 },
8354 #ifdef SQLITE_ENABLE_NORMALIZE
8355 { "sqlite3_normalized_sql", test_norm_sql
,0 },
8357 { "sqlite3_next_stmt", test_next_stmt
,0 },
8358 { "sqlite3_stmt_readonly", test_stmt_readonly
,0 },
8359 { "sqlite3_stmt_isexplain", test_stmt_isexplain
,0 },
8360 { "sqlite3_stmt_busy", test_stmt_busy
,0 },
8361 { "uses_stmt_journal", uses_stmt_journal
,0 },
8363 { "sqlite3_release_memory", test_release_memory
, 0},
8364 { "sqlite3_db_release_memory", test_db_release_memory
, 0},
8365 { "sqlite3_db_cacheflush", test_db_cacheflush
, 0},
8366 { "sqlite3_system_errno", test_system_errno
, 0},
8367 { "sqlite3_db_filename", test_db_filename
, 0},
8368 { "sqlite3_db_readonly", test_db_readonly
, 0},
8369 { "sqlite3_soft_heap_limit", test_soft_heap_limit
, 0},
8370 { "sqlite3_soft_heap_limit64", test_soft_heap_limit
, 0},
8371 { "sqlite3_hard_heap_limit64", test_hard_heap_limit
, 0},
8372 { "sqlite3_thread_cleanup", test_thread_cleanup
, 0},
8373 { "sqlite3_pager_refcounts", test_pager_refcounts
, 0},
8375 { "sqlite3_load_extension", test_load_extension
, 0},
8376 { "sqlite3_enable_load_extension", test_enable_load
, 0},
8377 { "sqlite3_extended_result_codes", test_extended_result_codes
, 0},
8378 { "sqlite3_limit", test_limit
, 0},
8379 { "dbconfig_maindbname_icecube", test_dbconfig_maindbname_icecube
},
8381 { "save_prng_state", save_prng_state
, 0 },
8382 { "restore_prng_state", restore_prng_state
, 0 },
8383 { "reset_prng_state", reset_prng_state
, 0 },
8384 { "prng_seed", prng_seed
, 0 },
8385 { "extra_schema_checks", extra_schema_checks
, 0},
8386 { "database_never_corrupt", database_never_corrupt
, 0},
8387 { "database_may_be_corrupt", database_may_be_corrupt
, 0},
8388 { "optimization_control", optimization_control
,0},
8390 { "lock_win32_file", win32_file_lock
, 0 },
8391 { "exists_win32_path", win32_exists_path
, 0 },
8392 { "find_win32_file", win32_find_file
, 0 },
8393 { "delete_win32_file", win32_delete_file
, 0 },
8394 { "make_win32_dir", win32_mkdir
, 0 },
8395 { "remove_win32_dir", win32_rmdir
, 0 },
8397 { "tcl_objproc", runAsObjProc
, 0 },
8399 /* sqlite3_column_*() API */
8400 { "sqlite3_column_count", test_column_count
,0 },
8401 { "sqlite3_data_count", test_data_count
,0 },
8402 { "sqlite3_column_type", test_column_type
,0 },
8403 { "sqlite3_column_blob", test_column_blob
,0 },
8404 { "sqlite3_column_double", test_column_double
,0 },
8405 { "sqlite3_column_int64", test_column_int64
,0 },
8406 { "sqlite3_column_text", test_stmt_utf8
, (void*)sqlite3_column_text
},
8407 { "sqlite3_column_name", test_stmt_utf8
, (void*)sqlite3_column_name
},
8408 { "sqlite3_column_int", test_stmt_int
, (void*)sqlite3_column_int
},
8409 { "sqlite3_column_bytes", test_stmt_int
, (void*)sqlite3_column_bytes
},
8410 #ifndef SQLITE_OMIT_DECLTYPE
8411 { "sqlite3_column_decltype",test_stmt_utf8
,(void*)sqlite3_column_decltype
},
8413 #ifdef SQLITE_ENABLE_COLUMN_METADATA
8414 { "sqlite3_column_database_name",test_stmt_utf8
,(void*)sqlite3_column_database_name
},
8415 { "sqlite3_column_table_name",test_stmt_utf8
,(void*)sqlite3_column_table_name
},
8416 { "sqlite3_column_origin_name",test_stmt_utf8
,(void*)sqlite3_column_origin_name
},
8419 #ifndef SQLITE_OMIT_UTF16
8420 { "sqlite3_column_bytes16", test_stmt_int
, (void*)sqlite3_column_bytes16
},
8421 { "sqlite3_column_text16", test_stmt_utf16
, (void*)sqlite3_column_text16
},
8422 { "sqlite3_column_name16", test_stmt_utf16
, (void*)sqlite3_column_name16
},
8423 { "add_alignment_test_collations", add_alignment_test_collations
, 0 },
8424 #ifndef SQLITE_OMIT_DECLTYPE
8425 { "sqlite3_column_decltype16",test_stmt_utf16
,(void*)sqlite3_column_decltype16
},
8427 #ifdef SQLITE_ENABLE_COLUMN_METADATA
8428 {"sqlite3_column_database_name16",
8429 test_stmt_utf16
, (void*)sqlite3_column_database_name16
},
8430 {"sqlite3_column_table_name16", test_stmt_utf16
, (void*)sqlite3_column_table_name16
},
8431 {"sqlite3_column_origin_name16", test_stmt_utf16
, (void*)sqlite3_column_origin_name16
},
8434 { "sqlite3_create_collation_v2", test_create_collation_v2
, 0 },
8435 { "sqlite3_global_recover", test_global_recover
, 0 },
8436 { "working_64bit_int", working_64bit_int
, 0 },
8437 { "vfs_unlink_test", vfs_unlink_test
, 0 },
8438 { "vfs_initfail_test", vfs_initfail_test
, 0 },
8439 { "vfs_unregister_all", vfs_unregister_all
, 0 },
8440 { "vfs_reregister_all", vfs_reregister_all
, 0 },
8441 { "file_control_test", file_control_test
, 0 },
8442 { "file_control_lasterrno_test", file_control_lasterrno_test
, 0 },
8443 { "file_control_lockproxy_test", file_control_lockproxy_test
, 0 },
8444 { "file_control_chunksize_test", file_control_chunksize_test
, 0 },
8445 { "file_control_sizehint_test", file_control_sizehint_test
, 0 },
8446 { "file_control_data_version", file_control_data_version
, 0 },
8448 { "file_control_win32_av_retry", file_control_win32_av_retry
, 0 },
8449 { "file_control_win32_get_handle", file_control_win32_get_handle
, 0 },
8450 { "file_control_win32_set_handle", file_control_win32_set_handle
, 0 },
8452 { "file_control_persist_wal", file_control_persist_wal
, 0 },
8453 { "file_control_powersafe_overwrite",file_control_powersafe_overwrite
,0},
8454 { "file_control_vfsname", file_control_vfsname
, 0 },
8455 { "file_control_reservebytes", file_control_reservebytes
, 0 },
8456 { "file_control_tempfilename", file_control_tempfilename
, 0 },
8457 { "sqlite3_vfs_list", vfs_list
, 0 },
8458 { "sqlite3_create_function_v2", test_create_function_v2
, 0 },
8460 /* Functions from os.h */
8461 #ifndef SQLITE_OMIT_UTF16
8462 { "add_test_collate", test_collate
, 0 },
8463 { "add_test_collate_needed", test_collate_needed
, 0 },
8464 { "add_test_function", test_function
, 0 },
8465 { "add_test_utf16bin_collate", test_utf16bin_collate
, 0 },
8467 { "sqlite3_test_errstr", test_errstr
, 0 },
8468 { "tcl_variable_type", tcl_variable_type
, 0 },
8469 #ifndef SQLITE_OMIT_SHARED_CACHE
8470 { "sqlite3_enable_shared_cache", test_enable_shared
, 0 },
8471 { "sqlite3_shared_cache_report", sqlite3BtreeSharedCacheReport
, 0},
8473 { "sqlite3_libversion_number", test_libversion_number
, 0 },
8474 { "sqlite3_table_column_metadata", test_table_column_metadata
, 0 },
8475 #ifndef SQLITE_OMIT_INCRBLOB
8476 { "sqlite3_blob_reopen", test_blob_reopen
, 0 },
8478 { "pcache_stats", test_pcache_stats
, 0 },
8479 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
8480 { "sqlite3_unlock_notify", test_unlock_notify
, 0 },
8482 { "sqlite3_wal_checkpoint", test_wal_checkpoint
, 0 },
8483 { "sqlite3_wal_checkpoint_v2",test_wal_checkpoint_v2
, 0 },
8484 { "sqlite3_wal_autocheckpoint",test_wal_autocheckpoint
, 0 },
8485 { "test_sqlite3_log", test_sqlite3_log
, 0 },
8486 #ifndef SQLITE_OMIT_EXPLAIN
8487 { "print_explain_query_plan", test_print_eqp
, 0 },
8489 { "sqlite3_test_control", test_test_control
},
8491 { "getrusage", test_getrusage
},
8493 { "load_static_extension", tclLoadStaticExtensionCmd
},
8494 { "sorter_test_fakeheap", sorter_test_fakeheap
},
8495 { "sorter_test_sort4_helper", sorter_test_sort4_helper
},
8496 #ifdef SQLITE_USER_AUTHENTICATION
8497 { "sqlite3_user_authenticate", test_user_authenticate
, 0 },
8498 { "sqlite3_user_add", test_user_add
, 0 },
8499 { "sqlite3_user_change", test_user_change
, 0 },
8500 { "sqlite3_user_delete", test_user_delete
, 0 },
8502 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
8503 { "sqlite3_stmt_scanstatus", test_stmt_scanstatus
, 0 },
8504 { "sqlite3_stmt_scanstatus_reset", test_stmt_scanstatus_reset
, 0 },
8506 #ifdef SQLITE_ENABLE_SQLLOG
8507 { "sqlite3_config_sqllog", test_config_sqllog
, 0 },
8509 { "vfs_current_time_int64", vfsCurrentTimeInt64
, 0 },
8510 #ifdef SQLITE_ENABLE_SNAPSHOT
8511 { "sqlite3_snapshot_get", test_snapshot_get
, 0 },
8512 { "sqlite3_snapshot_open", test_snapshot_open
, 0 },
8513 { "sqlite3_snapshot_free", test_snapshot_free
, 0 },
8514 { "sqlite3_snapshot_cmp", test_snapshot_cmp
, 0 },
8515 { "sqlite3_snapshot_recover", test_snapshot_recover
, 0 },
8516 { "sqlite3_snapshot_get_blob", test_snapshot_get_blob
, 0 },
8517 { "sqlite3_snapshot_open_blob", test_snapshot_open_blob
, 0 },
8518 { "sqlite3_snapshot_cmp_blob", test_snapshot_cmp_blob
, 0 },
8520 { "sqlite3_delete_database", test_delete_database
, 0 },
8521 { "atomic_batch_write", test_atomic_batch_write
, 0 },
8522 { "sqlite3_mmap_warm", test_mmap_warm
, 0 },
8523 { "sqlite3_config_sorterref", test_config_sorterref
, 0 },
8524 { "decode_hexdb", test_decode_hexdb
, 0 },
8525 { "test_write_db", test_write_db
, 0 },
8526 { "sqlite3_register_cksumvfs", test_register_cksumvfs
, 0 },
8527 { "sqlite3_unregister_cksumvfs", test_unregister_cksumvfs
, 0 },
8529 static int bitmask_size
= sizeof(Bitmask
)*8;
8530 static int longdouble_size
= sizeof(LONGDOUBLE_TYPE
);
8532 extern int sqlite3_sync_count
, sqlite3_fullsync_count
;
8533 extern int sqlite3_opentemp_count
;
8534 extern int sqlite3_like_count
;
8535 extern int sqlite3_xferopt_count
;
8536 extern int sqlite3_pager_readdb_count
;
8537 extern int sqlite3_pager_writedb_count
;
8538 extern int sqlite3_pager_writej_count
;
8540 extern LONG
volatile sqlite3_os_type
;
8543 extern int sqlite3WhereTrace
;
8544 extern int sqlite3OSTrace
;
8545 extern int sqlite3WalTrace
;
8548 #ifdef SQLITE_ENABLE_FTS3
8549 extern int sqlite3_fts3_enable_parentheses
;
8552 #if defined(SQLITE_ENABLE_SELECTTRACE)
8553 extern u32 sqlite3_unsupported_selecttrace
;
8556 for(i
=0; i
<sizeof(aCmd
)/sizeof(aCmd
[0]); i
++){
8557 Tcl_CreateCommand(interp
, aCmd
[i
].zName
, aCmd
[i
].xProc
, 0, 0);
8559 for(i
=0; i
<sizeof(aObjCmd
)/sizeof(aObjCmd
[0]); i
++){
8560 Tcl_CreateObjCommand(interp
, aObjCmd
[i
].zName
,
8561 aObjCmd
[i
].xProc
, aObjCmd
[i
].clientData
, 0);
8563 Tcl_LinkVar(interp
, "sqlite_search_count",
8564 (char*)&sqlite3_search_count
, TCL_LINK_INT
);
8565 Tcl_LinkVar(interp
, "sqlite_found_count",
8566 (char*)&sqlite3_found_count
, TCL_LINK_INT
);
8567 Tcl_LinkVar(interp
, "sqlite_sort_count",
8568 (char*)&sqlite3_sort_count
, TCL_LINK_INT
);
8569 Tcl_LinkVar(interp
, "sqlite3_max_blobsize",
8570 (char*)&sqlite3_max_blobsize
, TCL_LINK_INT
);
8571 Tcl_LinkVar(interp
, "sqlite_like_count",
8572 (char*)&sqlite3_like_count
, TCL_LINK_INT
);
8573 Tcl_LinkVar(interp
, "sqlite_interrupt_count",
8574 (char*)&sqlite3_interrupt_count
, TCL_LINK_INT
);
8575 Tcl_LinkVar(interp
, "sqlite_open_file_count",
8576 (char*)&sqlite3_open_file_count
, TCL_LINK_INT
);
8577 Tcl_LinkVar(interp
, "sqlite_current_time",
8578 (char*)&sqlite3_current_time
, TCL_LINK_INT
);
8579 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
8580 Tcl_LinkVar(interp
, "sqlite_hostid_num",
8581 (char*)&sqlite3_hostid_num
, TCL_LINK_INT
);
8583 Tcl_LinkVar(interp
, "sqlite3_xferopt_count",
8584 (char*)&sqlite3_xferopt_count
, TCL_LINK_INT
);
8585 Tcl_LinkVar(interp
, "sqlite3_pager_readdb_count",
8586 (char*)&sqlite3_pager_readdb_count
, TCL_LINK_INT
);
8587 Tcl_LinkVar(interp
, "sqlite3_pager_writedb_count",
8588 (char*)&sqlite3_pager_writedb_count
, TCL_LINK_INT
);
8589 Tcl_LinkVar(interp
, "sqlite3_pager_writej_count",
8590 (char*)&sqlite3_pager_writej_count
, TCL_LINK_INT
);
8591 #ifndef SQLITE_OMIT_UTF16
8592 Tcl_LinkVar(interp
, "unaligned_string_counter",
8593 (char*)&unaligned_string_counter
, TCL_LINK_INT
);
8595 #ifndef SQLITE_OMIT_UTF16
8596 Tcl_LinkVar(interp
, "sqlite_last_needed_collation",
8597 (char*)&pzNeededCollation
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
8600 Tcl_LinkVar(interp
, "sqlite_os_type",
8601 (char*)&sqlite3_os_type
, TCL_LINK_LONG
);
8605 static const char *query_plan
= "*** OBSOLETE VARIABLE ***";
8606 Tcl_LinkVar(interp
, "sqlite_query_plan",
8607 (char*)&query_plan
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
8611 Tcl_LinkVar(interp
, "sqlite_where_trace",
8612 (char*)&sqlite3WhereTrace
, TCL_LINK_INT
);
8613 Tcl_LinkVar(interp
, "sqlite_os_trace",
8614 (char*)&sqlite3OSTrace
, TCL_LINK_INT
);
8615 #ifndef SQLITE_OMIT_WAL
8616 Tcl_LinkVar(interp
, "sqlite_wal_trace",
8617 (char*)&sqlite3WalTrace
, TCL_LINK_INT
);
8620 #ifndef SQLITE_OMIT_DISKIO
8621 Tcl_LinkVar(interp
, "sqlite_opentemp_count",
8622 (char*)&sqlite3_opentemp_count
, TCL_LINK_INT
);
8624 Tcl_LinkVar(interp
, "sqlite_static_bind_value",
8625 (char*)&sqlite_static_bind_value
, TCL_LINK_STRING
);
8626 Tcl_LinkVar(interp
, "sqlite_static_bind_nbyte",
8627 (char*)&sqlite_static_bind_nbyte
, TCL_LINK_INT
);
8628 Tcl_LinkVar(interp
, "sqlite_temp_directory",
8629 (char*)&sqlite3_temp_directory
, TCL_LINK_STRING
);
8630 Tcl_LinkVar(interp
, "sqlite_data_directory",
8631 (char*)&sqlite3_data_directory
, TCL_LINK_STRING
);
8632 Tcl_LinkVar(interp
, "bitmask_size",
8633 (char*)&bitmask_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
8634 Tcl_LinkVar(interp
, "longdouble_size",
8635 (char*)&longdouble_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
8636 Tcl_LinkVar(interp
, "sqlite_sync_count",
8637 (char*)&sqlite3_sync_count
, TCL_LINK_INT
);
8638 Tcl_LinkVar(interp
, "sqlite_fullsync_count",
8639 (char*)&sqlite3_fullsync_count
, TCL_LINK_INT
);
8640 #if defined(SQLITE_ENABLE_SELECTTRACE)
8641 Tcl_LinkVar(interp
, "sqlite3_unsupported_selecttrace",
8642 (char*)&sqlite3_unsupported_selecttrace
, TCL_LINK_INT
);
8644 #if defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_TEST)
8645 Tcl_LinkVar(interp
, "sqlite_fts3_enable_parentheses",
8646 (char*)&sqlite3_fts3_enable_parentheses
, TCL_LINK_INT
);