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(__APPLE__)
23 # include <sys/param.h>
24 # include <sys/sysctl.h>
29 #if defined(INCLUDE_SQLITE_TCL_H)
30 # include "sqlite_tcl.h"
38 ** This is a copy of the first part of the SqliteDb structure in
39 ** tclsqlite.c. We need it here so that the get_sqlite_pointer routine
40 ** can extract the sqlite3* pointer from an existing Tcl SQLite
48 ** Convert text generated by the "%p" conversion format back into
51 static int testHexToInt(int h
){
52 if( h
>='0' && h
<='9' ){
54 }else if( h
>='a' && h
<='f' ){
57 assert( h
>='A' && h
<='F' );
61 void *sqlite3TestTextToPtr(const char *z
){
65 if( z
[0]=='0' && z
[1]=='x' ){
70 v
= (v
<<4) + testHexToInt(*z
);
73 if( sizeof(p
)==sizeof(v
) ){
74 memcpy(&p
, &v
, sizeof(p
));
76 assert( sizeof(p
)==sizeof(v2
) );
78 memcpy(&p
, &v2
, sizeof(p
));
85 ** A TCL command that returns the address of the sqlite* pointer
86 ** for an sqlite connection instance. Bad things happen if the
87 ** input is not an sqlite connection.
89 static int SQLITE_TCLAPI
get_sqlite_pointer(
99 Tcl_WrongNumArgs(interp
, 1, objv
, "SQLITE-CONNECTION");
102 if( !Tcl_GetCommandInfo(interp
, Tcl_GetString(objv
[1]), &cmdInfo
) ){
103 Tcl_AppendResult(interp
, "command not found: ",
104 Tcl_GetString(objv
[1]), (char*)0);
107 p
= (struct SqliteDb
*)cmdInfo
.objClientData
;
108 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%p", p
->db
);
109 Tcl_AppendResult(interp
, zBuf
, 0);
114 ** Decode a pointer to an sqlite3 object.
116 int getDbPointer(Tcl_Interp
*interp
, const char *zA
, sqlite3
**ppDb
){
119 if( Tcl_GetCommandInfo(interp
, zA
, &cmdInfo
) ){
120 p
= (struct SqliteDb
*)cmdInfo
.objClientData
;
123 *ppDb
= (sqlite3
*)sqlite3TestTextToPtr(zA
);
130 ** Decode a Win32 HANDLE object.
132 int getWin32Handle(Tcl_Interp
*interp
, const char *zA
, LPHANDLE phFile
){
133 *phFile
= (HANDLE
)sqlite3TestTextToPtr(zA
);
138 extern const char *sqlite3ErrName(int);
139 #define t1ErrorName sqlite3ErrName
142 ** Convert an sqlite3_stmt* into an sqlite3*. This depends on the
143 ** fact that the sqlite3* is the first field in the Vdbe structure.
145 #define StmtToDb(X) sqlite3_db_handle(X)
148 ** Check a return value to make sure it agrees with the results
149 ** from sqlite3_errcode.
151 int sqlite3TestErrCode(Tcl_Interp
*interp
, sqlite3
*db
, int rc
){
152 if( sqlite3_threadsafe()==0 && rc
!=SQLITE_MISUSE
&& rc
!=SQLITE_OK
153 && sqlite3_errcode(db
)!=rc
){
155 int r2
= sqlite3_errcode(db
);
156 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
157 "error code %s (%d) does not match sqlite3_errcode %s (%d)",
158 t1ErrorName(rc
), rc
, t1ErrorName(r2
), r2
);
159 Tcl_ResetResult(interp
);
160 Tcl_AppendResult(interp
, zBuf
, 0);
167 ** Decode a pointer to an sqlite3_stmt object.
169 static int getStmtPointer(
172 sqlite3_stmt
**ppStmt
174 *ppStmt
= (sqlite3_stmt
*)sqlite3TestTextToPtr(zArg
);
179 ** Generate a text representation of a pointer that can be understood
180 ** by the getDbPointer and getVmPointer routines above.
182 ** The problem is, on some machines (Solaris) if you do a printf with
183 ** "%p" you cannot turn around and do a scanf with the same "%p" and
184 ** get your pointer back. You have to prepend a "0x" before it will
185 ** work. Or at least that is what is reported to me (drh). But this
186 ** behavior varies from machine to machine. The solution used her is
187 ** to test the string right after it is generated to see if it can be
188 ** understood by scanf, and if not, try prepending an "0x" to see if
189 ** that helps. If nothing works, a fatal error is generated.
191 int sqlite3TestMakePointerStr(Tcl_Interp
*interp
, char *zPtr
, void *p
){
192 sqlite3_snprintf(100, zPtr
, "%p", p
);
197 ** The callback routine for sqlite3_exec_printf().
199 static int exec_printf_cb(void *pArg
, int argc
, char **argv
, char **name
){
200 Tcl_DString
*str
= (Tcl_DString
*)pArg
;
203 if( Tcl_DStringLength(str
)==0 ){
204 for(i
=0; i
<argc
; i
++){
205 Tcl_DStringAppendElement(str
, name
[i
] ? name
[i
] : "NULL");
208 for(i
=0; i
<argc
; i
++){
209 Tcl_DStringAppendElement(str
, argv
[i
] ? argv
[i
] : "NULL");
215 ** The I/O tracing callback.
217 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
218 static FILE *iotrace_file
= 0;
219 static void io_trace_callback(const char *zFormat
, ...){
221 va_start(ap
, zFormat
);
222 vfprintf(iotrace_file
, zFormat
, ap
);
224 fflush(iotrace_file
);
229 ** Usage: io_trace FILENAME
231 ** Turn I/O tracing on or off. If FILENAME is not an empty string,
232 ** I/O tracing begins going into FILENAME. If FILENAME is an empty
233 ** string, I/O tracing is turned off.
235 static int SQLITE_TCLAPI
test_io_trace(
237 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
238 int argc
, /* Number of arguments */
239 char **argv
/* Text of each argument */
241 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
243 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
248 if( iotrace_file
!=stdout
&& iotrace_file
!=stderr
){
249 fclose(iotrace_file
);
255 if( strcmp(argv
[1],"stdout")==0 ){
256 iotrace_file
= stdout
;
257 }else if( strcmp(argv
[1],"stderr")==0 ){
258 iotrace_file
= stderr
;
260 iotrace_file
= fopen(argv
[1], "w");
262 sqlite3IoTrace
= io_trace_callback
;
269 ** Usage: clang_sanitize_address
271 ** Returns true if the program was compiled using clang with the
272 ** -fsanitize=address switch on the command line. False otherwise.
274 ** Also return true if the OMIT_MISUSE environment variable exists.
276 static int SQLITE_TCLAPI
clang_sanitize_address(
278 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
279 int argc
, /* Number of arguments */
280 char **argv
/* Text of each argument */
283 #if defined(__has_feature)
284 # if __has_feature(address_sanitizer)
288 #ifdef __SANITIZE_ADDRESS__
291 if( res
==0 && getenv("OMIT_MISUSE")!=0 ) res
= 1;
292 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
297 ** Usage: sqlite3_exec_printf DB FORMAT STRING
299 ** Invoke the sqlite3_exec_printf() interface using the open database
300 ** DB. The SQL is the string FORMAT. The format string should contain
301 ** one %s or %q. STRING is the value inserted into %s or %q.
303 static int SQLITE_TCLAPI
test_exec_printf(
305 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
306 int argc
, /* Number of arguments */
307 char **argv
/* Text of each argument */
316 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
317 " DB FORMAT STRING", 0);
320 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
321 Tcl_DStringInit(&str
);
322 zSql
= sqlite3_mprintf(argv
[2], argv
[3]);
323 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
325 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
326 Tcl_AppendElement(interp
, zBuf
);
327 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
328 Tcl_DStringFree(&str
);
329 if( zErr
) sqlite3_free(zErr
);
330 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
335 ** Usage: sqlite3_exec_hex DB HEX
337 ** Invoke the sqlite3_exec() on a string that is obtained by translating
338 ** HEX into ASCII. Most characters are translated as is. %HH becomes
341 static int SQLITE_TCLAPI
test_exec_hex(
343 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
344 int argc
, /* Number of arguments */
345 char **argv
/* Text of each argument */
355 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
359 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
361 for(i
=j
=0; i
<(sizeof(zSql
)-1) && zHex
[j
]; i
++, j
++){
362 if( zHex
[j
]=='%' && zHex
[j
+2] && zHex
[j
+2] ){
363 zSql
[i
] = (testHexToInt(zHex
[j
+1])<<4) + testHexToInt(zHex
[j
+2]);
370 Tcl_DStringInit(&str
);
371 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
372 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
373 Tcl_AppendElement(interp
, zBuf
);
374 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
375 Tcl_DStringFree(&str
);
376 if( zErr
) sqlite3_free(zErr
);
377 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
382 ** Usage: db_enter DB
385 ** Enter or leave the mutex on a database connection.
387 static int SQLITE_TCLAPI
db_enter(
389 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
390 int argc
, /* Number of arguments */
391 char **argv
/* Text of each argument */
395 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
399 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
400 sqlite3_mutex_enter(db
->mutex
);
403 static int SQLITE_TCLAPI
db_leave(
405 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
406 int argc
, /* Number of arguments */
407 char **argv
/* Text of each argument */
411 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
415 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
416 sqlite3_mutex_leave(db
->mutex
);
421 ** Usage: sqlite3_exec DB SQL
423 ** Invoke the sqlite3_exec interface using the open database DB
425 static int SQLITE_TCLAPI
test_exec(
427 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
428 int argc
, /* Number of arguments */
429 char **argv
/* Text of each argument */
439 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
443 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
444 Tcl_DStringInit(&str
);
445 zSql
= sqlite3_mprintf("%s", argv
[2]);
446 for(i
=j
=0; zSql
[i
];){
448 zSql
[j
++] = (testHexToInt(zSql
[i
+1])<<4) + testHexToInt(zSql
[i
+2]);
451 zSql
[j
++] = zSql
[i
++];
455 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
457 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
458 Tcl_AppendElement(interp
, zBuf
);
459 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
460 Tcl_DStringFree(&str
);
461 if( zErr
) sqlite3_free(zErr
);
462 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
467 ** Usage: sqlite3_exec_nr DB SQL
469 ** Invoke the sqlite3_exec interface using the open database DB. Discard
472 static int SQLITE_TCLAPI
test_exec_nr(
474 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
475 int argc
, /* Number of arguments */
476 char **argv
/* Text of each argument */
482 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
486 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
487 rc
= sqlite3_exec(db
, argv
[2], 0, 0, &zErr
);
488 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
493 ** Usage: sqlite3_mprintf_z_test SEPARATOR ARG0 ARG1 ...
495 ** Test the %z format of sqlite_mprintf(). Use multiple mprintf() calls to
496 ** concatenate arg0 through argn using separator as the separator.
497 ** Return the result.
499 static int SQLITE_TCLAPI
test_mprintf_z(
501 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
502 int argc
, /* Number of arguments */
503 char **argv
/* Text of each argument */
508 for(i
=2; i
<argc
&& (i
==2 || zResult
); i
++){
509 zResult
= sqlite3_mprintf("%z%s%s", zResult
, argv
[1], argv
[i
]);
511 Tcl_AppendResult(interp
, zResult
, 0);
512 sqlite3_free(zResult
);
517 ** Usage: sqlite3_mprintf_n_test STRING
519 ** Test the %n format of sqlite_mprintf(). Return the length of the
522 static int SQLITE_TCLAPI
test_mprintf_n(
524 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
525 int argc
, /* Number of arguments */
526 char **argv
/* Text of each argument */
530 zStr
= sqlite3_mprintf("%s%n", argv
[1], &n
);
532 Tcl_SetObjResult(interp
, Tcl_NewIntObj(n
));
537 ** Usage: sqlite3_snprintf_int SIZE FORMAT INT
539 ** Test the of sqlite3_snprintf() routine. SIZE is the size of the
540 ** output buffer in bytes. The maximum size is 100. FORMAT is the
541 ** format string. INT is a single integer argument. The FORMAT
542 ** string must require no more than this one integer argument. If
543 ** You pass in a format string that requires more than one argument,
544 ** bad things will happen.
546 static int SQLITE_TCLAPI
test_snprintf_int(
548 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
549 int argc
, /* Number of arguments */
550 char **argv
/* Text of each argument */
553 int n
= atoi(argv
[1]);
554 const char *zFormat
= argv
[2];
555 int a1
= atoi(argv
[3]);
556 if( n
>sizeof(zStr
) ) n
= sizeof(zStr
);
557 sqlite3_snprintf(sizeof(zStr
), zStr
, "abcdefghijklmnopqrstuvwxyz");
558 sqlite3_snprintf(n
, zStr
, zFormat
, a1
);
559 Tcl_AppendResult(interp
, zStr
, 0);
563 #ifndef SQLITE_OMIT_GET_TABLE
566 ** Usage: sqlite3_get_table_printf DB FORMAT STRING ?--no-counts?
568 ** Invoke the sqlite3_get_table_printf() interface using the open database
569 ** DB. The SQL is the string FORMAT. The format string should contain
570 ** one %s or %q. STRING is the value inserted into %s or %q.
572 static int SQLITE_TCLAPI
test_get_table_printf(
574 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
575 int argc
, /* Number of arguments */
576 char **argv
/* Text of each argument */
582 int nRow
= 0, nCol
= 0;
589 if( Tcl_GetInt(interp
, argv
[4], &resCount
) ) return TCL_ERROR
;
591 if( argc
!=4 && argc
!=5 ){
592 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
593 " DB FORMAT STRING ?COUNT?", 0);
596 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
597 Tcl_DStringInit(&str
);
598 zSql
= sqlite3_mprintf(argv
[2],argv
[3]);
600 rc
= sqlite3_get_table(db
, zSql
, &aResult
, 0, 0, &zErr
);
602 rc
= sqlite3_get_table(db
, zSql
, &aResult
, &nRow
, &nCol
, &zErr
);
603 resCount
= (nRow
+1)*nCol
;
606 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
607 Tcl_AppendElement(interp
, zBuf
);
610 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", nRow
);
611 Tcl_AppendElement(interp
, zBuf
);
612 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", nCol
);
613 Tcl_AppendElement(interp
, zBuf
);
615 for(i
=0; i
<resCount
; i
++){
616 Tcl_AppendElement(interp
, aResult
[i
] ? aResult
[i
] : "NULL");
619 Tcl_AppendElement(interp
, zErr
);
621 sqlite3_free_table(aResult
);
622 if( zErr
) sqlite3_free(zErr
);
623 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
627 #endif /* SQLITE_OMIT_GET_TABLE */
631 ** Usage: sqlite3_last_insert_rowid DB
633 ** Returns the integer ROWID of the most recent insert.
635 static int SQLITE_TCLAPI
test_last_rowid(
637 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
638 int argc
, /* Number of arguments */
639 char **argv
/* Text of each argument */
645 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB\"", 0);
648 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
649 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%lld", sqlite3_last_insert_rowid(db
));
650 Tcl_AppendResult(interp
, zBuf
, 0);
655 ** Usage: sqlite3_key DB KEY
657 ** Set the codec key.
659 static int SQLITE_TCLAPI
test_key(
661 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
662 int argc
, /* Number of arguments */
663 char **argv
/* Text of each argument */
665 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
670 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
674 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
677 sqlite3_key(db
, zKey
, nKey
);
683 ** Usage: sqlite3_rekey DB KEY
685 ** Change the codec key.
687 static int SQLITE_TCLAPI
test_rekey(
689 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
690 int argc
, /* Number of arguments */
691 char **argv
/* Text of each argument */
693 #ifdef SQLITE_HAS_CODEC
698 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
702 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
705 sqlite3_rekey(db
, zKey
, nKey
);
711 ** Usage: sqlite3_close DB
713 ** Closes the database opened by sqlite3_open.
715 static int SQLITE_TCLAPI
sqlite_test_close(
717 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
718 int argc
, /* Number of arguments */
719 char **argv
/* Text of each argument */
724 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
728 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
729 rc
= sqlite3_close(db
);
730 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
735 ** Usage: sqlite3_close_v2 DB
737 ** Closes the database opened by sqlite3_open.
739 static int SQLITE_TCLAPI
sqlite_test_close_v2(
741 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
742 int argc
, /* Number of arguments */
743 char **argv
/* Text of each argument */
748 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
752 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
753 rc
= sqlite3_close_v2(db
);
754 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
759 ** Implementation of the x_coalesce() function.
760 ** Return the first argument non-NULL argument.
762 static void t1_ifnullFunc(
763 sqlite3_context
*context
,
768 for(i
=0; i
<argc
; i
++){
769 if( SQLITE_NULL
!=sqlite3_value_type(argv
[i
]) ){
770 int n
= sqlite3_value_bytes(argv
[i
]);
771 sqlite3_result_text(context
, (char*)sqlite3_value_text(argv
[i
]),
772 n
, SQLITE_TRANSIENT
);
779 ** These are test functions. hex8() interprets its argument as
780 ** UTF8 and returns a hex encoding. hex16le() interprets its argument
781 ** as UTF16le and returns a hex encoding.
783 static void hex8Func(sqlite3_context
*p
, int argc
, sqlite3_value
**argv
){
784 const unsigned char *z
;
787 z
= sqlite3_value_text(argv
[0]);
788 for(i
=0; i
<sizeof(zBuf
)/2 - 2 && z
[i
]; i
++){
789 sqlite3_snprintf(sizeof(zBuf
)-i
*2, &zBuf
[i
*2], "%02x", z
[i
]);
792 sqlite3_result_text(p
, (char*)zBuf
, -1, SQLITE_TRANSIENT
);
794 #ifndef SQLITE_OMIT_UTF16
795 static void hex16Func(sqlite3_context
*p
, int argc
, sqlite3_value
**argv
){
796 const unsigned short int *z
;
799 z
= sqlite3_value_text16(argv
[0]);
800 for(i
=0; i
<sizeof(zBuf
)/4 - 4 && z
[i
]; i
++){
801 sqlite3_snprintf(sizeof(zBuf
)-i
*4, &zBuf
[i
*4],"%04x", z
[i
]&0xff);
804 sqlite3_result_text(p
, (char*)zBuf
, -1, SQLITE_TRANSIENT
);
809 ** A structure into which to accumulate text.
812 int nAlloc
; /* Space allocated */
813 int nUsed
; /* Space used */
814 char *z
; /* The space */
818 ** Append text to a dstr
820 static void dstrAppend(struct dstr
*p
, const char *z
, int divider
){
821 int n
= (int)strlen(z
);
822 if( p
->nUsed
+ n
+ 2 > p
->nAlloc
){
824 p
->nAlloc
= p
->nAlloc
*2 + n
+ 200;
825 zNew
= sqlite3_realloc(p
->z
, p
->nAlloc
);
828 memset(p
, 0, sizeof(*p
));
833 if( divider
&& p
->nUsed
>0 ){
834 p
->z
[p
->nUsed
++] = divider
;
836 memcpy(&p
->z
[p
->nUsed
], z
, n
+1);
841 ** Invoked for each callback from sqlite3ExecFunc
843 static int execFuncCallback(void *pData
, int argc
, char **argv
, char **NotUsed
){
844 struct dstr
*p
= (struct dstr
*)pData
;
846 for(i
=0; i
<argc
; i
++){
848 dstrAppend(p
, "NULL", ' ');
850 dstrAppend(p
, argv
[i
], ' ');
857 ** Implementation of the x_sqlite_exec() function. This function takes
858 ** a single argument and attempts to execute that argument as SQL code.
859 ** This is illegal and should set the SQLITE_MISUSE flag on the database.
861 ** 2004-Jan-07: We have changed this to make it legal to call sqlite3_exec()
862 ** from within a function call.
864 ** This routine simulates the effect of having two threads attempt to
865 ** use the same database at the same time.
867 static void sqlite3ExecFunc(
868 sqlite3_context
*context
,
873 memset(&x
, 0, sizeof(x
));
874 (void)sqlite3_exec((sqlite3
*)sqlite3_user_data(context
),
875 (char*)sqlite3_value_text(argv
[0]),
876 execFuncCallback
, &x
, 0);
877 sqlite3_result_text(context
, x
.z
, x
.nUsed
, SQLITE_TRANSIENT
);
882 ** Implementation of tkt2213func(), a scalar function that takes exactly
883 ** one argument. It has two interesting features:
885 ** * It calls sqlite3_value_text() 3 times on the argument sqlite3_value*.
886 ** If the three pointers returned are not the same an SQL error is raised.
888 ** * Otherwise it returns a copy of the text representation of its
889 ** argument in such a way as the VDBE representation is a Mem* cell
890 ** with the MEM_Term flag clear.
892 ** Ticket #2213 can therefore be tested by evaluating the following
895 ** tkt2213func(tkt2213func('a string'));
897 static void tkt2213Function(
898 sqlite3_context
*context
,
903 unsigned char const *zText1
;
904 unsigned char const *zText2
;
905 unsigned char const *zText3
;
907 nText
= sqlite3_value_bytes(argv
[0]);
908 zText1
= sqlite3_value_text(argv
[0]);
909 zText2
= sqlite3_value_text(argv
[0]);
910 zText3
= sqlite3_value_text(argv
[0]);
912 if( zText1
!=zText2
|| zText2
!=zText3
){
913 sqlite3_result_error(context
, "tkt2213 is not fixed", -1);
915 char *zCopy
= (char *)sqlite3_malloc(nText
);
916 memcpy(zCopy
, zText1
, nText
);
917 sqlite3_result_text(context
, zCopy
, nText
, sqlite3_free
);
922 ** The following SQL function takes 4 arguments. The 2nd and
923 ** 4th argument must be one of these strings: 'text', 'text16',
924 ** or 'blob' corresponding to API functions
926 ** sqlite3_value_text()
927 ** sqlite3_value_text16()
928 ** sqlite3_value_blob()
930 ** The third argument is a string, either 'bytes' or 'bytes16' or 'noop',
931 ** corresponding to APIs:
933 ** sqlite3_value_bytes()
934 ** sqlite3_value_bytes16()
937 ** The APIs designated by the 2nd through 4th arguments are applied
938 ** to the first argument in order. If the pointers returned by the
939 ** second and fourth are different, this routine returns 1. Otherwise,
940 ** this routine returns 0.
942 ** This function is used to test to see when returned pointers from
943 ** the _text(), _text16() and _blob() APIs become invalidated.
945 static void ptrChngFunction(
946 sqlite3_context
*context
,
952 if( argc
!=4 ) return;
953 zCmd
= (const char*)sqlite3_value_text(argv
[1]);
954 if( zCmd
==0 ) return;
955 if( strcmp(zCmd
,"text")==0 ){
956 p1
= (const void*)sqlite3_value_text(argv
[0]);
957 #ifndef SQLITE_OMIT_UTF16
958 }else if( strcmp(zCmd
, "text16")==0 ){
959 p1
= (const void*)sqlite3_value_text16(argv
[0]);
961 }else if( strcmp(zCmd
, "blob")==0 ){
962 p1
= (const void*)sqlite3_value_blob(argv
[0]);
966 zCmd
= (const char*)sqlite3_value_text(argv
[2]);
967 if( zCmd
==0 ) return;
968 if( strcmp(zCmd
,"bytes")==0 ){
969 sqlite3_value_bytes(argv
[0]);
970 #ifndef SQLITE_OMIT_UTF16
971 }else if( strcmp(zCmd
, "bytes16")==0 ){
972 sqlite3_value_bytes16(argv
[0]);
974 }else if( strcmp(zCmd
, "noop")==0 ){
979 zCmd
= (const char*)sqlite3_value_text(argv
[3]);
980 if( zCmd
==0 ) return;
981 if( strcmp(zCmd
,"text")==0 ){
982 p2
= (const void*)sqlite3_value_text(argv
[0]);
983 #ifndef SQLITE_OMIT_UTF16
984 }else if( strcmp(zCmd
, "text16")==0 ){
985 p2
= (const void*)sqlite3_value_text16(argv
[0]);
987 }else if( strcmp(zCmd
, "blob")==0 ){
988 p2
= (const void*)sqlite3_value_blob(argv
[0]);
992 sqlite3_result_int(context
, p1
!=p2
);
996 ** This SQL function returns a different answer each time it is called, even if
997 ** the arguments are the same.
999 static void nondeterministicFunction(
1000 sqlite3_context
*context
,
1002 sqlite3_value
**argv
1005 sqlite3_result_int(context
, cnt
++);
1009 ** This SQL function returns the integer value of its argument as a MEM_IntReal
1012 static void intrealFunction(
1013 sqlite3_context
*context
,
1015 sqlite3_value
**argv
1017 sqlite3_int64 v
= sqlite3_value_int64(argv
[0]);
1018 sqlite3_result_int64(context
, v
);
1019 sqlite3_test_control(SQLITE_TESTCTRL_RESULT_INTREAL
, context
);
1023 ** Usage: sqlite3_create_function DB
1025 ** Call the sqlite3_create_function API on the given database in order
1026 ** to create a function named "x_coalesce". This function does the same thing
1027 ** as the "coalesce" function. This function also registers an SQL function
1028 ** named "x_sqlite_exec" that invokes sqlite3_exec(). Invoking sqlite3_exec()
1029 ** in this way is illegal recursion and should raise an SQLITE_MISUSE error.
1030 ** The effect is similar to trying to use the same database connection from
1031 ** two threads at the same time.
1033 ** The original motivation for this routine was to be able to call the
1034 ** sqlite3_create_function function while a query is in progress in order
1035 ** to test the SQLITE_MISUSE detection logic.
1037 static int SQLITE_TCLAPI
test_create_function(
1039 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1040 int argc
, /* Number of arguments */
1041 char **argv
/* Text of each argument */
1047 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1051 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1052 rc
= sqlite3_create_function(db
, "x_coalesce", -1, SQLITE_UTF8
, 0,
1053 t1_ifnullFunc
, 0, 0);
1054 if( rc
==SQLITE_OK
){
1055 rc
= sqlite3_create_function(db
, "hex8", 1, SQLITE_UTF8
| SQLITE_DETERMINISTIC
,
1058 #ifndef SQLITE_OMIT_UTF16
1059 if( rc
==SQLITE_OK
){
1060 rc
= sqlite3_create_function(db
, "hex16", 1, SQLITE_UTF16
| SQLITE_DETERMINISTIC
,
1061 0, hex16Func
, 0, 0);
1064 if( rc
==SQLITE_OK
){
1065 rc
= sqlite3_create_function(db
, "tkt2213func", 1, SQLITE_ANY
, 0,
1066 tkt2213Function
, 0, 0);
1068 if( rc
==SQLITE_OK
){
1069 rc
= sqlite3_create_function(db
, "pointer_change", 4, SQLITE_ANY
, 0,
1070 ptrChngFunction
, 0, 0);
1073 /* Functions counter1() and counter2() have the same implementation - they
1074 ** both return an ascending integer with each call. But counter1() is marked
1075 ** as non-deterministic and counter2() is marked as deterministic.
1077 if( rc
==SQLITE_OK
){
1078 rc
= sqlite3_create_function(db
, "counter1", -1, SQLITE_UTF8
,
1079 0, nondeterministicFunction
, 0, 0);
1081 if( rc
==SQLITE_OK
){
1082 rc
= sqlite3_create_function(db
, "counter2", -1, SQLITE_UTF8
|SQLITE_DETERMINISTIC
,
1083 0, nondeterministicFunction
, 0, 0);
1086 /* The intreal() function converts its argument to an integer and returns
1087 ** it as a MEM_IntReal.
1089 if( rc
==SQLITE_OK
){
1090 rc
= sqlite3_create_function(db
, "intreal", 1, SQLITE_UTF8
,
1091 0, intrealFunction
, 0, 0);
1094 #ifndef SQLITE_OMIT_UTF16
1095 /* Use the sqlite3_create_function16() API here. Mainly for fun, but also
1096 ** because it is not tested anywhere else. */
1097 if( rc
==SQLITE_OK
){
1099 sqlite3_value
*pVal
;
1100 sqlite3_mutex_enter(db
->mutex
);
1101 pVal
= sqlite3ValueNew(db
);
1102 sqlite3ValueSetStr(pVal
, -1, "x_sqlite_exec", SQLITE_UTF8
, SQLITE_STATIC
);
1103 zUtf16
= sqlite3ValueText(pVal
, SQLITE_UTF16NATIVE
);
1104 if( db
->mallocFailed
){
1107 rc
= sqlite3_create_function16(db
, zUtf16
,
1108 1, SQLITE_UTF16
, db
, sqlite3ExecFunc
, 0, 0);
1110 sqlite3ValueFree(pVal
);
1111 sqlite3_mutex_leave(db
->mutex
);
1115 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
1116 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
1121 ** Usage: sqlite3_drop_modules DB ?NAME ...?
1123 ** Invoke the sqlite3_drop_modules(D,L) interface on database
1124 ** connection DB, in order to drop all modules except those named in
1127 static int SQLITE_TCLAPI
test_drop_modules(
1129 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1130 int argc
, /* Number of arguments */
1131 char **argv
/* Text of each argument */
1136 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1140 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1141 #ifndef SQLITE_OMIT_VIRTUALTABLE
1142 sqlite3_drop_modules(db
, argc
>2 ? (const char**)(argv
+2) : 0);
1148 ** Routines to implement the x_count() aggregate function.
1150 ** x_count() counts the number of non-null arguments. But there are
1151 ** some twists for testing purposes.
1153 ** If the argument to x_count() is 40 then a UTF-8 error is reported
1154 ** on the step function. If x_count(41) is seen, then a UTF-16 error
1155 ** is reported on the step function. If the total count is 42, then
1156 ** a UTF-8 error is reported on the finalize function.
1158 typedef struct t1CountCtx t1CountCtx
;
1162 static void t1CountStep(
1163 sqlite3_context
*context
,
1165 sqlite3_value
**argv
1168 p
= sqlite3_aggregate_context(context
, sizeof(*p
));
1169 if( (argc
==0 || SQLITE_NULL
!=sqlite3_value_type(argv
[0]) ) && p
){
1173 int v
= sqlite3_value_int(argv
[0]);
1175 sqlite3_result_error(context
, "value of 40 handed to x_count", -1);
1176 #ifndef SQLITE_OMIT_UTF16
1178 const char zUtf16ErrMsg
[] = { 0, 0x61, 0, 0x62, 0, 0x63, 0, 0, 0};
1179 sqlite3_result_error16(context
, &zUtf16ErrMsg
[1-SQLITE_BIGENDIAN
], -1);
1184 static void t1CountFinalize(sqlite3_context
*context
){
1186 p
= sqlite3_aggregate_context(context
, sizeof(*p
));
1189 sqlite3_result_error(context
, "x_count totals to 42", -1);
1191 sqlite3_result_int(context
, p
? p
->n
: 0);
1196 #ifndef SQLITE_OMIT_DEPRECATED
1197 static void legacyCountStep(
1198 sqlite3_context
*context
,
1200 sqlite3_value
**argv
1205 static void legacyCountFinalize(sqlite3_context
*context
){
1206 sqlite3_result_int(context
, sqlite3_aggregate_count(context
));
1211 ** Usage: sqlite3_create_aggregate DB
1213 ** Call the sqlite3_create_function API on the given database in order
1214 ** to create a function named "x_count". This function is similar
1215 ** to the built-in count() function, with a few special quirks
1216 ** for testing the sqlite3_result_error() APIs.
1218 ** The original motivation for this routine was to be able to call the
1219 ** sqlite3_create_aggregate function while a query is in progress in order
1220 ** to test the SQLITE_MISUSE detection logic. See misuse.test.
1222 ** This routine was later extended to test the use of sqlite3_result_error()
1223 ** within aggregate functions.
1225 ** Later: It is now also extended to register the aggregate function
1226 ** "legacy_count()" with the supplied database handle. This is used
1227 ** to test the deprecated sqlite3_aggregate_count() API.
1229 static int SQLITE_TCLAPI
test_create_aggregate(
1231 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1232 int argc
, /* Number of arguments */
1233 char **argv
/* Text of each argument */
1238 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1242 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1243 rc
= sqlite3_create_function(db
, "x_count", 0, SQLITE_UTF8
, 0, 0,
1244 t1CountStep
,t1CountFinalize
);
1245 if( rc
==SQLITE_OK
){
1246 rc
= sqlite3_create_function(db
, "x_count", 1, SQLITE_UTF8
, 0, 0,
1247 t1CountStep
,t1CountFinalize
);
1249 #ifndef SQLITE_OMIT_DEPRECATED
1250 if( rc
==SQLITE_OK
){
1251 rc
= sqlite3_create_function(db
, "legacy_count", 0, SQLITE_ANY
, 0, 0,
1252 legacyCountStep
, legacyCountFinalize
1256 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
1257 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
1263 ** Usage: printf TEXT
1265 ** Send output to printf. Use this rather than puts to merge the output
1266 ** in the correct sequence with debugging printfs inserted into C code.
1267 ** Puts uses a separate buffer and debugging statements will be out of
1268 ** sequence if it is used.
1270 static int SQLITE_TCLAPI
test_printf(
1272 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1273 int argc
, /* Number of arguments */
1274 char **argv
/* Text of each argument */
1277 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1281 printf("%s\n", argv
[1]);
1288 ** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER
1290 ** Call mprintf with three integer arguments
1292 static int SQLITE_TCLAPI
sqlite3_mprintf_int(
1294 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1295 int argc
, /* Number of arguments */
1296 char **argv
/* Text of each argument */
1301 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1302 " FORMAT INT INT INT\"", 0);
1306 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1308 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1309 Tcl_AppendResult(interp
, z
, 0);
1315 ** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER
1317 ** Call mprintf with three 64-bit integer arguments
1319 static int SQLITE_TCLAPI
sqlite3_mprintf_int64(
1321 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1322 int argc
, /* Number of arguments */
1323 char **argv
/* Text of each argument */
1329 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1330 " FORMAT INT INT INT\"", 0);
1334 if( sqlite3Atoi64(argv
[i
], &a
[i
-2], sqlite3Strlen30(argv
[i
]), SQLITE_UTF8
) ){
1335 Tcl_AppendResult(interp
, "argument is not a valid 64-bit integer", 0);
1339 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1340 Tcl_AppendResult(interp
, z
, 0);
1346 ** Usage: sqlite3_mprintf_long FORMAT INTEGER INTEGER INTEGER
1348 ** Call mprintf with three long integer arguments. This might be the
1349 ** same as sqlite3_mprintf_int or sqlite3_mprintf_int64, depending on
1352 static int SQLITE_TCLAPI
sqlite3_mprintf_long(
1354 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1355 int argc
, /* Number of arguments */
1356 char **argv
/* Text of each argument */
1363 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1364 " FORMAT INT INT INT\"", 0);
1368 if( Tcl_GetInt(interp
, argv
[i
], &b
[i
-2]) ) return TCL_ERROR
;
1369 a
[i
-2] = (long int)b
[i
-2];
1370 a
[i
-2] &= (((u64
)1)<<(sizeof(int)*8))-1;
1372 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1373 Tcl_AppendResult(interp
, z
, 0);
1379 ** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING
1381 ** Call mprintf with two integer arguments and one string argument
1383 static int SQLITE_TCLAPI
sqlite3_mprintf_str(
1385 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1386 int argc
, /* Number of arguments */
1387 char **argv
/* Text of each argument */
1391 if( argc
<4 || argc
>5 ){
1392 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1393 " FORMAT INT INT ?STRING?\"", 0);
1397 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1399 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], argc
>4 ? argv
[4] : NULL
);
1400 Tcl_AppendResult(interp
, z
, 0);
1406 ** Usage: sqlite3_snprintf_str INTEGER FORMAT INTEGER INTEGER STRING
1408 ** Call mprintf with two integer arguments and one string argument
1410 static int SQLITE_TCLAPI
sqlite3_snprintf_str(
1412 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1413 int argc
, /* Number of arguments */
1414 char **argv
/* Text of each argument */
1419 if( argc
<5 || argc
>6 ){
1420 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1421 " INT FORMAT INT INT ?STRING?\"", 0);
1424 if( Tcl_GetInt(interp
, argv
[1], &n
) ) return TCL_ERROR
;
1426 Tcl_AppendResult(interp
, "N must be non-negative", 0);
1430 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-3]) ) return TCL_ERROR
;
1432 z
= sqlite3_malloc( n
+1 );
1433 sqlite3_snprintf(n
, z
, argv
[2], a
[0], a
[1], argc
>4 ? argv
[5] : NULL
);
1434 Tcl_AppendResult(interp
, z
, 0);
1440 ** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE
1442 ** Call mprintf with two integer arguments and one double argument
1444 static int SQLITE_TCLAPI
sqlite3_mprintf_double(
1446 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1447 int argc
, /* Number of arguments */
1448 char **argv
/* Text of each argument */
1454 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1455 " FORMAT INT INT DOUBLE\"", 0);
1459 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1461 if( Tcl_GetDouble(interp
, argv
[4], &r
) ) return TCL_ERROR
;
1462 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], r
);
1463 Tcl_AppendResult(interp
, z
, 0);
1469 ** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE
1471 ** Call mprintf with a single double argument which is the product of the
1472 ** two arguments given above. This is used to generate overflow and underflow
1473 ** doubles to test that they are converted properly.
1475 static int SQLITE_TCLAPI
sqlite3_mprintf_scaled(
1477 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1478 int argc
, /* Number of arguments */
1479 char **argv
/* Text of each argument */
1485 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1486 " FORMAT DOUBLE DOUBLE\"", 0);
1490 if( Tcl_GetDouble(interp
, argv
[i
], &r
[i
-2]) ) return TCL_ERROR
;
1492 z
= sqlite3_mprintf(argv
[1], r
[0]*r
[1]);
1493 Tcl_AppendResult(interp
, z
, 0);
1499 ** Usage: sqlite3_mprintf_stronly FORMAT STRING
1501 ** Call mprintf with a single double argument which is the product of the
1502 ** two arguments given above. This is used to generate overflow and underflow
1503 ** doubles to test that they are converted properly.
1505 static int SQLITE_TCLAPI
sqlite3_mprintf_stronly(
1507 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1508 int argc
, /* Number of arguments */
1509 char **argv
/* Text of each argument */
1513 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1514 " FORMAT STRING\"", 0);
1517 z
= sqlite3_mprintf(argv
[1], argv
[2]);
1518 Tcl_AppendResult(interp
, z
, 0);
1524 ** Usage: sqlite3_mprintf_hexdouble FORMAT HEX
1526 ** Call mprintf with a single double argument which is derived from the
1527 ** hexadecimal encoding of an IEEE double.
1529 static int SQLITE_TCLAPI
sqlite3_mprintf_hexdouble(
1531 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1532 int argc
, /* Number of arguments */
1533 char **argv
/* Text of each argument */
1537 unsigned int x1
, x2
;
1540 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1541 " FORMAT STRING\"", 0);
1544 if( sscanf(argv
[2], "%08x%08x", &x2
, &x1
)!=2 ){
1545 Tcl_AppendResult(interp
, "2nd argument should be 16-characters of hex", 0);
1550 memcpy(&r
, &d
, sizeof(r
));
1551 z
= sqlite3_mprintf(argv
[1], r
);
1552 Tcl_AppendResult(interp
, z
, 0);
1558 ** Usage: sqlite3_enable_shared_cache ?BOOLEAN?
1561 #if !defined(SQLITE_OMIT_SHARED_CACHE)
1562 static int SQLITE_TCLAPI
test_enable_shared(
1563 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1564 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1565 int objc
, /* Number of arguments */
1566 Tcl_Obj
*CONST objv
[] /* Command arguments */
1572 if( objc
!=2 && objc
!=1 ){
1573 Tcl_WrongNumArgs(interp
, 1, objv
, "?BOOLEAN?");
1576 ret
= sqlite3GlobalConfig
.sharedCacheEnabled
;
1579 if( Tcl_GetBooleanFromObj(interp
, objv
[1], &enable
) ){
1582 rc
= sqlite3_enable_shared_cache(enable
);
1583 if( rc
!=SQLITE_OK
){
1584 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(rc
), TCL_STATIC
);
1588 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(ret
));
1596 ** Usage: sqlite3_extended_result_codes DB BOOLEAN
1599 static int SQLITE_TCLAPI
test_extended_result_codes(
1600 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1601 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1602 int objc
, /* Number of arguments */
1603 Tcl_Obj
*CONST objv
[] /* Command arguments */
1609 Tcl_WrongNumArgs(interp
, 1, objv
, "DB BOOLEAN");
1612 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1613 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &enable
) ) return TCL_ERROR
;
1614 sqlite3_extended_result_codes(db
, enable
);
1619 ** Usage: sqlite3_libversion_number
1622 static int SQLITE_TCLAPI
test_libversion_number(
1623 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1624 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1625 int objc
, /* Number of arguments */
1626 Tcl_Obj
*CONST objv
[] /* Command arguments */
1628 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_libversion_number()));
1633 ** Usage: sqlite3_table_column_metadata DB dbname tblname colname
1636 static int SQLITE_TCLAPI
test_table_column_metadata(
1637 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1638 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1639 int objc
, /* Number of arguments */
1640 Tcl_Obj
*CONST objv
[] /* Command arguments */
1649 const char *zDatatype
;
1650 const char *zCollseq
;
1655 if( objc
!=5 && objc
!=4 ){
1656 Tcl_WrongNumArgs(interp
, 1, objv
, "DB dbname tblname colname");
1659 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1660 zDb
= Tcl_GetString(objv
[2]);
1661 zTbl
= Tcl_GetString(objv
[3]);
1662 zCol
= objc
==5 ? Tcl_GetString(objv
[4]) : 0;
1664 if( strlen(zDb
)==0 ) zDb
= 0;
1666 rc
= sqlite3_table_column_metadata(db
, zDb
, zTbl
, zCol
,
1667 &zDatatype
, &zCollseq
, ¬null
, &primarykey
, &autoincrement
);
1669 if( rc
!=SQLITE_OK
){
1670 Tcl_AppendResult(interp
, sqlite3_errmsg(db
), 0);
1674 pRet
= Tcl_NewObj();
1675 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zDatatype
, -1));
1676 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zCollseq
, -1));
1677 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(notnull
));
1678 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(primarykey
));
1679 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(autoincrement
));
1680 Tcl_SetObjResult(interp
, pRet
);
1685 #ifndef SQLITE_OMIT_INCRBLOB
1687 static int SQLITE_TCLAPI
blobHandleFromObj(
1690 sqlite3_blob
**ppBlob
1695 z
= Tcl_GetStringFromObj(pObj
, &n
);
1700 Tcl_Channel channel
;
1701 ClientData instanceData
;
1703 channel
= Tcl_GetChannel(interp
, z
, ¬Used
);
1704 if( !channel
) return TCL_ERROR
;
1707 Tcl_Seek(channel
, 0, SEEK_SET
);
1709 instanceData
= Tcl_GetChannelInstanceData(channel
);
1710 *ppBlob
= *((sqlite3_blob
**)instanceData
);
1716 static int SQLITE_TCLAPI
test_blob_reopen(
1717 ClientData clientData
, /* Not used */
1718 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1719 int objc
, /* Number of arguments */
1720 Tcl_Obj
*CONST objv
[] /* Command arguments */
1723 sqlite3_blob
*pBlob
;
1727 Tcl_WrongNumArgs(interp
, 1, objv
, "CHANNEL ROWID");
1731 if( blobHandleFromObj(interp
, objv
[1], &pBlob
) ) return TCL_ERROR
;
1732 if( Tcl_GetWideIntFromObj(interp
, objv
[2], &iRowid
) ) return TCL_ERROR
;
1734 rc
= sqlite3_blob_reopen(pBlob
, iRowid
);
1735 if( rc
!=SQLITE_OK
){
1736 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
1739 return (rc
==SQLITE_OK
? TCL_OK
: TCL_ERROR
);
1745 ** Usage: sqlite3_create_collation_v2 DB-HANDLE NAME CMP-PROC DEL-PROC
1747 ** This Tcl proc is used for testing the experimental
1748 ** sqlite3_create_collation_v2() interface.
1750 struct TestCollationX
{
1755 typedef struct TestCollationX TestCollationX
;
1756 static void testCreateCollationDel(void *pCtx
){
1757 TestCollationX
*p
= (TestCollationX
*)pCtx
;
1759 int rc
= Tcl_EvalObjEx(p
->interp
, p
->pDel
, TCL_EVAL_DIRECT
|TCL_EVAL_GLOBAL
);
1761 Tcl_BackgroundError(p
->interp
);
1764 Tcl_DecrRefCount(p
->pCmp
);
1765 Tcl_DecrRefCount(p
->pDel
);
1766 sqlite3_free((void *)p
);
1768 static int testCreateCollationCmp(
1775 TestCollationX
*p
= (TestCollationX
*)pCtx
;
1776 Tcl_Obj
*pScript
= Tcl_DuplicateObj(p
->pCmp
);
1779 Tcl_IncrRefCount(pScript
);
1780 Tcl_ListObjAppendElement(0, pScript
, Tcl_NewStringObj((char *)zLeft
, nLeft
));
1781 Tcl_ListObjAppendElement(0, pScript
, Tcl_NewStringObj((char *)zRight
,nRight
));
1783 if( TCL_OK
!=Tcl_EvalObjEx(p
->interp
, pScript
, TCL_EVAL_DIRECT
|TCL_EVAL_GLOBAL
)
1784 || TCL_OK
!=Tcl_GetIntFromObj(p
->interp
, Tcl_GetObjResult(p
->interp
), &iRes
)
1786 Tcl_BackgroundError(p
->interp
);
1788 Tcl_DecrRefCount(pScript
);
1792 static int SQLITE_TCLAPI
test_create_collation_v2(
1793 ClientData clientData
, /* Not used */
1794 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1795 int objc
, /* Number of arguments */
1796 Tcl_Obj
*CONST objv
[] /* Command arguments */
1803 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE NAME CMP-PROC DEL-PROC");
1806 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1808 p
= (TestCollationX
*)sqlite3_malloc(sizeof(TestCollationX
));
1812 Tcl_IncrRefCount(p
->pCmp
);
1813 Tcl_IncrRefCount(p
->pDel
);
1815 rc
= sqlite3_create_collation_v2(db
, Tcl_GetString(objv
[2]), 16,
1816 (void *)p
, testCreateCollationCmp
, testCreateCollationDel
1818 if( rc
!=SQLITE_MISUSE
){
1819 Tcl_AppendResult(interp
, "sqlite3_create_collate_v2() failed to detect "
1820 "an invalid encoding", (char*)0);
1823 rc
= sqlite3_create_collation_v2(db
, Tcl_GetString(objv
[2]), SQLITE_UTF8
,
1824 (void *)p
, testCreateCollationCmp
, testCreateCollationDel
1830 ** USAGE: sqlite3_create_function_v2 DB NAME NARG ENC ?SWITCHES?
1832 ** Available switches are:
1839 typedef struct CreateFunctionV2 CreateFunctionV2
;
1840 struct CreateFunctionV2
{
1842 Tcl_Obj
*pFunc
; /* Script for function invocation */
1843 Tcl_Obj
*pStep
; /* Script for agg. step invocation */
1844 Tcl_Obj
*pFinal
; /* Script for agg. finalization invocation */
1845 Tcl_Obj
*pDestroy
; /* Destructor script */
1847 static void cf2Func(sqlite3_context
*ctx
, int nArg
, sqlite3_value
**aArg
){
1849 static void cf2Step(sqlite3_context
*ctx
, int nArg
, sqlite3_value
**aArg
){
1851 static void cf2Final(sqlite3_context
*ctx
){
1853 static void cf2Destroy(void *pUser
){
1854 CreateFunctionV2
*p
= (CreateFunctionV2
*)pUser
;
1856 if( p
->interp
&& p
->pDestroy
){
1857 int rc
= Tcl_EvalObjEx(p
->interp
, p
->pDestroy
, 0);
1858 if( rc
!=TCL_OK
) Tcl_BackgroundError(p
->interp
);
1861 if( p
->pFunc
) Tcl_DecrRefCount(p
->pFunc
);
1862 if( p
->pStep
) Tcl_DecrRefCount(p
->pStep
);
1863 if( p
->pFinal
) Tcl_DecrRefCount(p
->pFinal
);
1864 if( p
->pDestroy
) Tcl_DecrRefCount(p
->pDestroy
);
1867 static int SQLITE_TCLAPI
test_create_function_v2(
1868 ClientData clientData
, /* Not used */
1869 Tcl_Interp
*interp
, /* The invoking TCL interpreter */
1870 int objc
, /* Number of arguments */
1871 Tcl_Obj
*CONST objv
[] /* Command arguments */
1877 CreateFunctionV2
*p
;
1885 {"utf8", SQLITE_UTF8
},
1886 {"utf16", SQLITE_UTF16
},
1887 {"utf16le", SQLITE_UTF16LE
},
1888 {"utf16be", SQLITE_UTF16BE
},
1889 {"any", SQLITE_ANY
},
1894 if( objc
<5 || (objc
%2)==0 ){
1895 Tcl_WrongNumArgs(interp
, 1, objv
, "DB NAME NARG ENC SWITCHES...");
1899 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1900 zFunc
= Tcl_GetString(objv
[2]);
1901 if( Tcl_GetIntFromObj(interp
, objv
[3], &nArg
) ) return TCL_ERROR
;
1902 if( Tcl_GetIndexFromObjStruct(interp
, objv
[4], aEnc
, sizeof(aEnc
[0]),
1903 "encoding", 0, &enc
)
1907 enc
= aEnc
[enc
].enc
;
1909 p
= sqlite3_malloc(sizeof(CreateFunctionV2
));
1911 memset(p
, 0, sizeof(CreateFunctionV2
));
1914 for(i
=5; i
<objc
; i
+=2){
1916 const char *azSwitch
[] = {"-func", "-step", "-final", "-destroy", 0};
1917 if( Tcl_GetIndexFromObj(interp
, objv
[i
], azSwitch
, "switch", 0, &iSwitch
) ){
1923 case 0: p
->pFunc
= objv
[i
+1]; break;
1924 case 1: p
->pStep
= objv
[i
+1]; break;
1925 case 2: p
->pFinal
= objv
[i
+1]; break;
1926 case 3: p
->pDestroy
= objv
[i
+1]; break;
1929 if( p
->pFunc
) p
->pFunc
= Tcl_DuplicateObj(p
->pFunc
);
1930 if( p
->pStep
) p
->pStep
= Tcl_DuplicateObj(p
->pStep
);
1931 if( p
->pFinal
) p
->pFinal
= Tcl_DuplicateObj(p
->pFinal
);
1932 if( p
->pDestroy
) p
->pDestroy
= Tcl_DuplicateObj(p
->pDestroy
);
1934 if( p
->pFunc
) Tcl_IncrRefCount(p
->pFunc
);
1935 if( p
->pStep
) Tcl_IncrRefCount(p
->pStep
);
1936 if( p
->pFinal
) Tcl_IncrRefCount(p
->pFinal
);
1937 if( p
->pDestroy
) Tcl_IncrRefCount(p
->pDestroy
);
1939 rc
= sqlite3_create_function_v2(db
, zFunc
, nArg
, enc
, (void *)p
,
1940 (p
->pFunc
? cf2Func
: 0),
1941 (p
->pStep
? cf2Step
: 0),
1942 (p
->pFinal
? cf2Final
: 0),
1945 if( rc
!=SQLITE_OK
){
1946 Tcl_ResetResult(interp
);
1947 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
1954 ** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC?
1956 static int SQLITE_TCLAPI
test_load_extension(
1957 ClientData clientData
, /* Not used */
1958 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1959 int objc
, /* Number of arguments */
1960 Tcl_Obj
*CONST objv
[] /* Command arguments */
1962 Tcl_CmdInfo cmdInfo
;
1970 if( objc
!=4 && objc
!=3 ){
1971 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE FILE ?PROC?");
1974 zDb
= Tcl_GetString(objv
[1]);
1975 zFile
= Tcl_GetString(objv
[2]);
1977 zProc
= Tcl_GetString(objv
[3]);
1980 /* Extract the C database handle from the Tcl command name */
1981 if( !Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
1982 Tcl_AppendResult(interp
, "command not found: ", zDb
, (char*)0);
1985 db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
1988 /* Call the underlying C function. If an error occurs, set rc to
1989 ** TCL_ERROR and load any error string into the interpreter. If no
1990 ** error occurs, set rc to TCL_OK.
1992 #ifdef SQLITE_OMIT_LOAD_EXTENSION
1994 zErr
= sqlite3_mprintf("this build omits sqlite3_load_extension()");
1998 rc
= sqlite3_load_extension(db
, zFile
, zProc
, &zErr
);
2000 if( rc
!=SQLITE_OK
){
2001 Tcl_SetResult(interp
, zErr
? zErr
: "", TCL_VOLATILE
);
2012 ** Usage: sqlite3_enable_load_extension DB-HANDLE ONOFF
2014 static int SQLITE_TCLAPI
test_enable_load(
2015 ClientData clientData
, /* Not used */
2016 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2017 int objc
, /* Number of arguments */
2018 Tcl_Obj
*CONST objv
[] /* Command arguments */
2020 Tcl_CmdInfo cmdInfo
;
2026 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE ONOFF");
2029 zDb
= Tcl_GetString(objv
[1]);
2031 /* Extract the C database handle from the Tcl command name */
2032 if( !Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
2033 Tcl_AppendResult(interp
, "command not found: ", zDb
, (char*)0);
2036 db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
2039 /* Get the onoff parameter */
2040 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &onoff
) ){
2044 #ifdef SQLITE_OMIT_LOAD_EXTENSION
2045 Tcl_AppendResult(interp
, "this build omits sqlite3_load_extension()");
2048 sqlite3_enable_load_extension(db
, onoff
);
2054 ** Usage: sqlite_abort
2056 ** Shutdown the process immediately. This is not a clean shutdown.
2057 ** This command is used to test the recoverability of a database in
2058 ** the event of a program crash.
2060 static int SQLITE_TCLAPI
sqlite_abort(
2062 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2063 int argc
, /* Number of arguments */
2064 char **argv
/* Text of each argument */
2066 #if defined(_MSC_VER)
2067 /* We do this, otherwise the test will halt with a popup message
2068 * that we have to click away before the test will continue.
2070 _set_abort_behavior( 0, _CALL_REPORTFAULT
);
2073 assert( interp
==0 ); /* This will always fail */
2078 ** The following routine is a user-defined SQL function whose purpose
2079 ** is to test the sqlite_set_result() API.
2081 static void testFunc(sqlite3_context
*context
, int argc
, sqlite3_value
**argv
){
2083 const char *zArg0
= (char*)sqlite3_value_text(argv
[0]);
2085 if( 0==sqlite3StrICmp(zArg0
, "int") ){
2086 sqlite3_result_int(context
, sqlite3_value_int(argv
[1]));
2087 }else if( sqlite3StrICmp(zArg0
,"int64")==0 ){
2088 sqlite3_result_int64(context
, sqlite3_value_int64(argv
[1]));
2089 }else if( sqlite3StrICmp(zArg0
,"string")==0 ){
2090 sqlite3_result_text(context
, (char*)sqlite3_value_text(argv
[1]), -1,
2092 }else if( sqlite3StrICmp(zArg0
,"double")==0 ){
2093 sqlite3_result_double(context
, sqlite3_value_double(argv
[1]));
2094 }else if( sqlite3StrICmp(zArg0
,"null")==0 ){
2095 sqlite3_result_null(context
);
2096 }else if( sqlite3StrICmp(zArg0
,"value")==0 ){
2097 sqlite3_result_value(context
, argv
[sqlite3_value_int(argv
[1])]);
2110 sqlite3_result_error(context
,"first argument should be one of: "
2111 "int int64 string double null value", -1);
2115 ** Usage: sqlite_register_test_function DB NAME
2117 ** Register the test SQL function on the database DB under the name NAME.
2119 static int SQLITE_TCLAPI
test_register_func(
2121 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2122 int argc
, /* Number of arguments */
2123 char **argv
/* Text of each argument */
2128 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
2129 " DB FUNCTION-NAME", 0);
2132 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
2133 rc
= sqlite3_create_function(db
, argv
[2], -1, SQLITE_UTF8
, 0,
2136 Tcl_AppendResult(interp
, sqlite3ErrStr(rc
), 0);
2139 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
2144 ** Usage: sqlite3_finalize STMT
2146 ** Finalize a statement handle.
2148 static int SQLITE_TCLAPI
test_finalize(
2152 Tcl_Obj
*CONST objv
[]
2154 sqlite3_stmt
*pStmt
;
2159 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2160 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2164 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2167 db
= StmtToDb(pStmt
);
2169 rc
= sqlite3_finalize(pStmt
);
2170 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
2171 if( db
&& sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
2176 ** Usage: sqlite3_stmt_status STMT CODE RESETFLAG
2178 ** Get the value of a status counter from a statement.
2180 static int SQLITE_TCLAPI
test_stmt_status(
2184 Tcl_Obj
*CONST objv
[]
2187 int i
, op
= 0, resetFlag
;
2188 const char *zOpName
;
2189 sqlite3_stmt
*pStmt
;
2191 static const struct {
2195 { "SQLITE_STMTSTATUS_FULLSCAN_STEP", SQLITE_STMTSTATUS_FULLSCAN_STEP
},
2196 { "SQLITE_STMTSTATUS_SORT", SQLITE_STMTSTATUS_SORT
},
2197 { "SQLITE_STMTSTATUS_AUTOINDEX", SQLITE_STMTSTATUS_AUTOINDEX
},
2198 { "SQLITE_STMTSTATUS_VM_STEP", SQLITE_STMTSTATUS_VM_STEP
},
2199 { "SQLITE_STMTSTATUS_REPREPARE", SQLITE_STMTSTATUS_REPREPARE
},
2200 { "SQLITE_STMTSTATUS_RUN", SQLITE_STMTSTATUS_RUN
},
2201 { "SQLITE_STMTSTATUS_MEMUSED", SQLITE_STMTSTATUS_MEMUSED
},
2204 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT PARAMETER RESETFLAG");
2207 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2208 zOpName
= Tcl_GetString(objv
[2]);
2209 for(i
=0; i
<ArraySize(aOp
); i
++){
2210 if( strcmp(aOp
[i
].zName
, zOpName
)==0 ){
2215 if( i
>=ArraySize(aOp
) ){
2216 if( Tcl_GetIntFromObj(interp
, objv
[2], &op
) ) return TCL_ERROR
;
2218 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &resetFlag
) ) return TCL_ERROR
;
2219 iValue
= sqlite3_stmt_status(pStmt
, op
, resetFlag
);
2220 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iValue
));
2224 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
2226 ** Usage: sqlite3_stmt_scanstatus ?-flags FLAGS? STMT IDX
2228 static int SQLITE_TCLAPI
test_stmt_scanstatus(
2232 Tcl_Obj
*CONST objv
[]
2234 sqlite3_stmt
*pStmt
; /* First argument */
2235 int idx
; /* Second argument */
2238 const char *zExplain
;
2239 sqlite3_int64 nLoop
;
2240 sqlite3_int64 nVisit
;
2241 sqlite3_int64 nCycle
;
2253 {"complex", SQLITE_SCANSTAT_COMPLEX
},
2257 Tcl_Obj
**aFlag
= 0;
2261 if( Tcl_ListObjGetElements(interp
, objv
[2], &nFlag
, &aFlag
) ){
2264 for(ii
=0; ii
<nFlag
; ii
++){
2266 int res
= Tcl_GetIndexFromObjStruct(
2267 interp
, aFlag
[ii
], aTbl
, sizeof(aTbl
[0]), "flag", 0, &iVal
2269 if( res
) return TCL_ERROR
;
2270 flags
|= aTbl
[iVal
].flag
;
2274 if( objc
!=3 && objc
!=5 ){
2275 Tcl_WrongNumArgs(interp
, 1, objv
, "-flags FLAGS STMT IDX");
2278 if( getStmtPointer(interp
, Tcl_GetString(objv
[objc
-2]), &pStmt
)
2279 || Tcl_GetIntFromObj(interp
, objv
[objc
-1], &idx
)
2285 Tcl_Obj
*pRet
= Tcl_NewObj();
2286 res
= sqlite3_stmt_scanstatus_v2(
2287 pStmt
, -1, SQLITE_SCANSTAT_NCYCLE
, flags
, (void*)&nCycle
2289 sqlite3_stmt_scanstatus_v2(
2290 pStmt
, idx
, SQLITE_SCANSTAT_NCYCLE
, flags
, (void*)&nCycle
);
2291 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nCycle", -1));
2292 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nCycle
));
2293 Tcl_SetObjResult(interp
, pRet
);
2295 res
= sqlite3_stmt_scanstatus_v2(
2296 pStmt
, idx
, SQLITE_SCANSTAT_NLOOP
, flags
, (void*)&nLoop
2299 Tcl_Obj
*pRet
= Tcl_NewObj();
2300 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nLoop", -1));
2301 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nLoop
));
2302 sqlite3_stmt_scanstatus_v2(
2303 pStmt
, idx
, SQLITE_SCANSTAT_NVISIT
, flags
, (void*)&nVisit
);
2304 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nVisit", -1));
2305 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nVisit
));
2306 sqlite3_stmt_scanstatus_v2(
2307 pStmt
, idx
, SQLITE_SCANSTAT_EST
, flags
, (void*)&rEst
);
2308 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nEst", -1));
2309 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewDoubleObj(rEst
));
2310 sqlite3_stmt_scanstatus_v2(
2311 pStmt
, idx
, SQLITE_SCANSTAT_NAME
, flags
, (void*)&zName
);
2312 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("zName", -1));
2313 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zName
, -1));
2314 sqlite3_stmt_scanstatus_v2(
2315 pStmt
, idx
, SQLITE_SCANSTAT_EXPLAIN
, flags
, (void*)&zExplain
);
2316 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("zExplain", -1));
2317 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zExplain
, -1));
2318 sqlite3_stmt_scanstatus_v2(
2319 pStmt
, idx
, SQLITE_SCANSTAT_SELECTID
, flags
, (void*)&iSelectId
);
2320 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("iSelectId", -1));
2321 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(iSelectId
));
2322 sqlite3_stmt_scanstatus_v2(
2323 pStmt
, idx
, SQLITE_SCANSTAT_PARENTID
, flags
, (void*)&iParentId
);
2324 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("iParentId", -1));
2325 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(iParentId
));
2326 sqlite3_stmt_scanstatus_v2(
2327 pStmt
, idx
, SQLITE_SCANSTAT_NCYCLE
, flags
, (void*)&nCycle
);
2328 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nCycle", -1));
2329 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nCycle
));
2330 Tcl_SetObjResult(interp
, pRet
);
2332 Tcl_ResetResult(interp
);
2339 ** Usage: sqlite3_stmt_scanstatus_reset STMT
2341 static int SQLITE_TCLAPI
test_stmt_scanstatus_reset(
2345 Tcl_Obj
*CONST objv
[]
2347 sqlite3_stmt
*pStmt
; /* First argument */
2349 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
2352 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2353 sqlite3_stmt_scanstatus_reset(pStmt
);
2358 #ifdef SQLITE_ENABLE_SQLLOG
2360 ** Usage: sqlite3_config_sqllog
2362 ** Zero the SQLITE_CONFIG_SQLLOG configuration
2364 static int SQLITE_TCLAPI
test_config_sqllog(
2368 Tcl_Obj
*CONST objv
[]
2371 Tcl_WrongNumArgs(interp
, 1, objv
, "");
2374 sqlite3_config(SQLITE_CONFIG_SQLLOG
, 0, 0);
2380 ** Usage: sqlite3_config_sorterref
2382 ** Set the SQLITE_CONFIG_SORTERREF_SIZE configuration option
2384 static int SQLITE_TCLAPI
test_config_sorterref(
2388 Tcl_Obj
*CONST objv
[]
2392 Tcl_WrongNumArgs(interp
, 1, objv
, "NBYTE");
2395 if( Tcl_GetIntFromObj(interp
, objv
[1], &iVal
) ) return TCL_ERROR
;
2396 sqlite3_config(SQLITE_CONFIG_SORTERREF_SIZE
, iVal
);
2401 ** Usage: vfs_current_time_int64
2403 ** Return the value returned by the default VFS's xCurrentTimeInt64 method.
2405 static int SQLITE_TCLAPI
vfsCurrentTimeInt64(
2409 Tcl_Obj
*CONST objv
[]
2412 sqlite3_vfs
*pVfs
= sqlite3_vfs_find(0);
2414 Tcl_WrongNumArgs(interp
, 1, objv
, "");
2417 pVfs
->xCurrentTimeInt64(pVfs
, &t
);
2418 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(t
));
2422 #ifndef SQLITE_OMIT_VIRTUALTABLE
2424 ** Usage: create_null_module DB NAME
2426 static int SQLITE_TCLAPI
test_create_null_module(
2430 Tcl_Obj
*CONST objv
[]
2436 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2439 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2440 zName
= Tcl_GetString(objv
[2]);
2442 sqlite3_create_module(db
, zName
, 0, 0);
2445 #endif /* SQLITE_OMIT_VIRTUALTABLE */
2447 #ifdef SQLITE_ENABLE_SNAPSHOT
2449 ** Usage: sqlite3_snapshot_get DB DBNAME
2451 static int SQLITE_TCLAPI
test_snapshot_get(
2455 Tcl_Obj
*CONST objv
[]
2460 sqlite3_snapshot
*pSnapshot
= 0;
2463 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2466 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2467 zName
= Tcl_GetString(objv
[2]);
2469 rc
= sqlite3_snapshot_get(db
, zName
, &pSnapshot
);
2470 if( rc
!=SQLITE_OK
){
2471 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2475 if( sqlite3TestMakePointerStr(interp
, zBuf
, pSnapshot
) ) return TCL_ERROR
;
2476 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zBuf
, -1));
2480 #endif /* SQLITE_ENABLE_SNAPSHOT */
2482 #ifdef SQLITE_ENABLE_SNAPSHOT
2484 ** Usage: sqlite3_snapshot_recover DB DBNAME
2486 static int SQLITE_TCLAPI
test_snapshot_recover(
2490 Tcl_Obj
*CONST objv
[]
2497 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2500 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2501 zName
= Tcl_GetString(objv
[2]);
2503 rc
= sqlite3_snapshot_recover(db
, zName
);
2504 if( rc
!=SQLITE_OK
){
2505 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2508 Tcl_ResetResult(interp
);
2512 #endif /* SQLITE_ENABLE_SNAPSHOT */
2514 #ifdef SQLITE_ENABLE_SNAPSHOT
2516 ** Usage: sqlite3_snapshot_open DB DBNAME SNAPSHOT
2518 static int SQLITE_TCLAPI
test_snapshot_open(
2522 Tcl_Obj
*CONST objv
[]
2527 sqlite3_snapshot
*pSnapshot
;
2530 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SNAPSHOT");
2533 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2534 zName
= Tcl_GetString(objv
[2]);
2535 pSnapshot
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[3]));
2537 rc
= sqlite3_snapshot_open(db
, zName
, pSnapshot
);
2538 if( rc
!=SQLITE_OK
){
2539 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2542 Tcl_ResetResult(interp
);
2546 #endif /* SQLITE_ENABLE_SNAPSHOT */
2548 #ifdef SQLITE_ENABLE_SNAPSHOT
2550 ** Usage: sqlite3_snapshot_free SNAPSHOT
2552 static int SQLITE_TCLAPI
test_snapshot_free(
2556 Tcl_Obj
*CONST objv
[]
2558 sqlite3_snapshot
*pSnapshot
;
2560 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT");
2563 pSnapshot
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[1]));
2564 sqlite3_snapshot_free(pSnapshot
);
2567 #endif /* SQLITE_ENABLE_SNAPSHOT */
2569 #ifdef SQLITE_ENABLE_SNAPSHOT
2571 ** Usage: sqlite3_snapshot_cmp SNAPSHOT1 SNAPSHOT2
2573 static int SQLITE_TCLAPI
test_snapshot_cmp(
2577 Tcl_Obj
*CONST objv
[]
2580 sqlite3_snapshot
*p1
;
2581 sqlite3_snapshot
*p2
;
2583 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT1 SNAPSHOT2");
2586 p1
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[1]));
2587 p2
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[2]));
2588 res
= sqlite3_snapshot_cmp(p1
, p2
);
2589 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
2592 #endif /* SQLITE_ENABLE_SNAPSHOT */
2594 #ifdef SQLITE_ENABLE_SNAPSHOT
2596 ** Usage: sqlite3_snapshot_get_blob DB DBNAME
2598 static int SQLITE_TCLAPI
test_snapshot_get_blob(
2602 Tcl_Obj
*CONST objv
[]
2607 sqlite3_snapshot
*pSnapshot
= 0;
2610 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2613 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2614 zName
= Tcl_GetString(objv
[2]);
2616 rc
= sqlite3_snapshot_get(db
, zName
, &pSnapshot
);
2617 if( rc
!=SQLITE_OK
){
2618 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2621 Tcl_SetObjResult(interp
,
2622 Tcl_NewByteArrayObj((unsigned char*)pSnapshot
, sizeof(sqlite3_snapshot
))
2624 sqlite3_snapshot_free(pSnapshot
);
2628 #endif /* SQLITE_ENABLE_SNAPSHOT */
2630 #ifdef SQLITE_ENABLE_SNAPSHOT
2632 ** Usage: sqlite3_snapshot_open_blob DB DBNAME SNAPSHOT
2634 static int SQLITE_TCLAPI
test_snapshot_open_blob(
2638 Tcl_Obj
*CONST objv
[]
2643 unsigned char *pBlob
;
2647 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SNAPSHOT");
2650 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2651 zName
= Tcl_GetString(objv
[2]);
2652 pBlob
= Tcl_GetByteArrayFromObj(objv
[3], &nBlob
);
2653 if( nBlob
!=sizeof(sqlite3_snapshot
) ){
2654 Tcl_AppendResult(interp
, "bad SNAPSHOT", 0);
2657 rc
= sqlite3_snapshot_open(db
, zName
, (sqlite3_snapshot
*)pBlob
);
2658 if( rc
!=SQLITE_OK
){
2659 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2664 #endif /* SQLITE_ENABLE_SNAPSHOT */
2666 #ifdef SQLITE_ENABLE_SNAPSHOT
2668 ** Usage: sqlite3_snapshot_cmp_blob SNAPSHOT1 SNAPSHOT2
2670 static int SQLITE_TCLAPI
test_snapshot_cmp_blob(
2674 Tcl_Obj
*CONST objv
[]
2683 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT1 SNAPSHOT2");
2687 p1
= Tcl_GetByteArrayFromObj(objv
[1], &n1
);
2688 p2
= Tcl_GetByteArrayFromObj(objv
[2], &n2
);
2690 if( n1
!=sizeof(sqlite3_snapshot
) || n1
!=n2
){
2691 Tcl_AppendResult(interp
, "bad SNAPSHOT", 0);
2695 res
= sqlite3_snapshot_cmp((sqlite3_snapshot
*)p1
, (sqlite3_snapshot
*)p2
);
2696 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
2699 #endif /* SQLITE_ENABLE_SNAPSHOT */
2702 ** Usage: sqlite3_delete_database FILENAME
2704 int sqlite3_delete_database(const char*); /* in test_delete.c */
2705 static int SQLITE_TCLAPI
test_delete_database(
2709 Tcl_Obj
*CONST objv
[]
2714 Tcl_WrongNumArgs(interp
, 1, objv
, "FILE");
2717 zFile
= (const char*)Tcl_GetString(objv
[1]);
2718 rc
= sqlite3_delete_database(zFile
);
2720 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2725 ** Usage: atomic_batch_write PATH
2727 static int SQLITE_TCLAPI
test_atomic_batch_write(
2731 Tcl_Obj
*CONST objv
[]
2733 char *zFile
= 0; /* Path to file to test */
2734 sqlite3
*db
= 0; /* Database handle */
2735 sqlite3_file
*pFd
= 0; /* SQLite fd open on zFile */
2736 int bRes
= 0; /* Integer result of this command */
2737 int dc
= 0; /* Device-characteristics mask */
2738 int rc
; /* sqlite3_open() return code */
2741 Tcl_WrongNumArgs(interp
, 1, objv
, "PATH");
2744 zFile
= Tcl_GetString(objv
[1]);
2746 rc
= sqlite3_open(zFile
, &db
);
2747 if( rc
!=SQLITE_OK
){
2748 Tcl_AppendResult(interp
, sqlite3_errmsg(db
), 0);
2753 rc
= sqlite3_file_control(db
, "main", SQLITE_FCNTL_FILE_POINTER
, (void*)&pFd
);
2754 dc
= pFd
->pMethods
->xDeviceCharacteristics(pFd
);
2755 if( dc
& SQLITE_IOCAP_BATCH_ATOMIC
){
2759 Tcl_SetObjResult(interp
, Tcl_NewIntObj(bRes
));
2765 ** Usage: sqlite3_next_stmt DB STMT
2767 ** Return the next statment in sequence after STMT.
2769 static int SQLITE_TCLAPI
test_next_stmt(
2773 Tcl_Obj
*CONST objv
[]
2775 sqlite3_stmt
*pStmt
;
2780 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2781 Tcl_GetStringFromObj(objv
[0], 0), " DB STMT", 0);
2785 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2786 if( getStmtPointer(interp
, Tcl_GetString(objv
[2]), &pStmt
) ) return TCL_ERROR
;
2787 pStmt
= sqlite3_next_stmt(db
, pStmt
);
2789 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
2790 Tcl_AppendResult(interp
, zBuf
, 0);
2796 ** Usage: sqlite3_stmt_readonly STMT
2798 ** Return true if STMT is a NULL pointer or a pointer to a statement
2799 ** that is guaranteed to leave the database unmodified.
2801 static int SQLITE_TCLAPI
test_stmt_readonly(
2805 Tcl_Obj
*CONST objv
[]
2807 sqlite3_stmt
*pStmt
;
2811 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2812 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2816 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2817 rc
= sqlite3_stmt_readonly(pStmt
);
2818 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(rc
));
2823 ** Usage: sqlite3_stmt_isexplain STMT
2825 ** Return 1, 2, or 0 respectively if STMT is an EXPLAIN statement, an
2826 ** EXPLAIN QUERY PLAN statement or an ordinary statement or NULL pointer.
2828 static int SQLITE_TCLAPI
test_stmt_isexplain(
2832 Tcl_Obj
*CONST objv
[]
2834 sqlite3_stmt
*pStmt
;
2838 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2839 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2843 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2844 rc
= sqlite3_stmt_isexplain(pStmt
);
2845 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
2850 ** Usage: sqlite3_stmt_busy STMT
2852 ** Return true if STMT is a non-NULL pointer to a statement
2853 ** that has been stepped but not to completion.
2855 static int SQLITE_TCLAPI
test_stmt_busy(
2859 Tcl_Obj
*CONST objv
[]
2861 sqlite3_stmt
*pStmt
;
2865 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2866 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2870 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2871 rc
= sqlite3_stmt_busy(pStmt
);
2872 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(rc
));
2877 ** Usage: uses_stmt_journal STMT
2879 ** Return true if STMT uses a statement journal.
2881 static int SQLITE_TCLAPI
uses_stmt_journal(
2885 Tcl_Obj
*CONST objv
[]
2887 sqlite3_stmt
*pStmt
;
2890 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2891 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2895 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2896 sqlite3_stmt_readonly(pStmt
);
2897 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(((Vdbe
*)pStmt
)->usesStmtJournal
));
2903 ** Usage: sqlite3_reset STMT
2905 ** Reset a statement handle.
2907 static int SQLITE_TCLAPI
test_reset(
2911 Tcl_Obj
*CONST objv
[]
2913 sqlite3_stmt
*pStmt
;
2917 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2918 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2922 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2924 rc
= sqlite3_reset(pStmt
);
2925 if( pStmt
&& sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ){
2928 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
2938 ** Usage: sqlite3_expired STMT
2940 ** Return TRUE if a recompilation of the statement is recommended.
2942 static int SQLITE_TCLAPI
test_expired(
2946 Tcl_Obj
*CONST objv
[]
2948 #ifndef SQLITE_OMIT_DEPRECATED
2949 sqlite3_stmt
*pStmt
;
2951 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2952 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2955 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2956 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(sqlite3_expired(pStmt
)));
2962 ** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT
2964 ** Transfer all bindings from FROMSTMT over to TOSTMT
2966 static int SQLITE_TCLAPI
test_transfer_bind(
2970 Tcl_Obj
*CONST objv
[]
2972 #ifndef SQLITE_OMIT_DEPRECATED
2973 sqlite3_stmt
*pStmt1
, *pStmt2
;
2975 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2976 Tcl_GetStringFromObj(objv
[0], 0), " FROM-STMT TO-STMT", 0);
2979 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt1
)) return TCL_ERROR
;
2980 if( getStmtPointer(interp
, Tcl_GetString(objv
[2]), &pStmt2
)) return TCL_ERROR
;
2981 Tcl_SetObjResult(interp
,
2982 Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1
,pStmt2
)));
2988 ** Usage: sqlite3_changes DB
2990 ** Return the number of changes made to the database by the last SQL
2993 static int SQLITE_TCLAPI
test_changes(
2997 Tcl_Obj
*CONST objv
[]
3001 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3002 Tcl_GetString(objv
[0]), " DB", 0);
3005 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3006 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_changes(db
)));
3011 ** This is the "static_bind_value" that variables are bound to when
3012 ** the FLAG option of sqlite3_bind is "static"
3014 static char *sqlite_static_bind_value
= 0;
3015 static int sqlite_static_bind_nbyte
= 0;
3018 ** Usage: sqlite3_bind VM IDX VALUE FLAGS
3020 ** Sets the value of the IDX-th occurrence of "?" in the original SQL
3021 ** string. VALUE is the new value. If FLAGS=="null" then VALUE is
3022 ** ignored and the value is set to NULL. If FLAGS=="static" then
3023 ** the value is set to the value of a static variable named
3024 ** "sqlite_static_bind_value". If FLAGS=="normal" then a copy
3025 ** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored
3026 ** an a 10-byte blob "abc\000xyz\000pq" is inserted.
3028 static int SQLITE_TCLAPI
test_bind(
3030 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
3031 int argc
, /* Number of arguments */
3032 char **argv
/* Text of each argument */
3034 sqlite3_stmt
*pStmt
;
3038 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
3039 " VM IDX VALUE (null|static|normal)\"", 0);
3042 if( getStmtPointer(interp
, argv
[1], &pStmt
) ) return TCL_ERROR
;
3043 if( Tcl_GetInt(interp
, argv
[2], &idx
) ) return TCL_ERROR
;
3044 if( strcmp(argv
[4],"null")==0 ){
3045 rc
= sqlite3_bind_null(pStmt
, idx
);
3046 }else if( strcmp(argv
[4],"static")==0 ){
3047 rc
= sqlite3_bind_text(pStmt
, idx
, sqlite_static_bind_value
, -1, 0);
3048 }else if( strcmp(argv
[4],"static-nbytes")==0 ){
3049 rc
= sqlite3_bind_text(pStmt
, idx
, sqlite_static_bind_value
,
3050 sqlite_static_bind_nbyte
, 0);
3051 }else if( strcmp(argv
[4],"normal")==0 ){
3052 rc
= sqlite3_bind_text(pStmt
, idx
, argv
[3], -1, SQLITE_TRANSIENT
);
3053 }else if( strcmp(argv
[4],"blob10")==0 ){
3054 rc
= sqlite3_bind_text(pStmt
, idx
, "abc\000xyz\000pq", 10, SQLITE_STATIC
);
3056 Tcl_AppendResult(interp
, "4th argument should be "
3057 "\"null\" or \"static\" or \"normal\"", 0);
3060 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3063 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
3064 Tcl_AppendResult(interp
, zBuf
, sqlite3ErrStr(rc
), 0);
3070 #ifndef SQLITE_OMIT_UTF16
3072 ** Usage: add_test_collate <db ptr> <utf8> <utf16le> <utf16be>
3074 ** This function is used to test that SQLite selects the correct collation
3075 ** sequence callback when multiple versions (for different text encodings)
3078 ** Calling this routine registers the collation sequence "test_collate"
3079 ** with database handle <db>. The second argument must be a list of three
3080 ** boolean values. If the first is true, then a version of test_collate is
3081 ** registered for UTF-8, if the second is true, a version is registered for
3082 ** UTF-16le, if the third is true, a UTF-16be version is available.
3083 ** Previous versions of test_collate are deleted.
3085 ** The collation sequence test_collate is implemented by calling the
3086 ** following TCL script:
3088 ** "test_collate <enc> <lhs> <rhs>"
3090 ** The <lhs> and <rhs> are the two values being compared, encoded in UTF-8.
3091 ** The <enc> parameter is the encoding of the collation function that
3092 ** SQLite selected to call. The TCL test script implements the
3093 ** "test_collate" proc.
3095 ** Note that this will only work with one interpreter at a time, as the
3096 ** interp pointer to use when evaluating the TCL script is stored in
3097 ** pTestCollateInterp.
3099 static Tcl_Interp
* pTestCollateInterp
;
3100 static int test_collate_func(
3102 int nA
, const void *zA
,
3103 int nB
, const void *zB
3105 Tcl_Interp
*i
= pTestCollateInterp
;
3106 int encin
= SQLITE_PTR_TO_INT(pCtx
);
3110 sqlite3_value
*pVal
;
3113 pX
= Tcl_NewStringObj("test_collate", -1);
3114 Tcl_IncrRefCount(pX
);
3118 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-8",-1));
3120 case SQLITE_UTF16LE
:
3121 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-16LE",-1));
3123 case SQLITE_UTF16BE
:
3124 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-16BE",-1));
3130 sqlite3BeginBenignMalloc();
3131 pVal
= sqlite3ValueNew(0);
3133 sqlite3ValueSetStr(pVal
, nA
, zA
, encin
, SQLITE_STATIC
);
3134 n
= sqlite3_value_bytes(pVal
);
3135 Tcl_ListObjAppendElement(i
,pX
,
3136 Tcl_NewStringObj((char*)sqlite3_value_text(pVal
),n
));
3137 sqlite3ValueSetStr(pVal
, nB
, zB
, encin
, SQLITE_STATIC
);
3138 n
= sqlite3_value_bytes(pVal
);
3139 Tcl_ListObjAppendElement(i
,pX
,
3140 Tcl_NewStringObj((char*)sqlite3_value_text(pVal
),n
));
3141 sqlite3ValueFree(pVal
);
3143 sqlite3EndBenignMalloc();
3145 Tcl_EvalObjEx(i
, pX
, 0);
3146 Tcl_DecrRefCount(pX
);
3147 Tcl_GetIntFromObj(i
, Tcl_GetObjResult(i
), &res
);
3150 static int SQLITE_TCLAPI
test_collate(
3154 Tcl_Obj
*CONST objv
[]
3158 sqlite3_value
*pVal
;
3161 if( objc
!=5 ) goto bad_args
;
3162 pTestCollateInterp
= interp
;
3163 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3165 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
3166 rc
= sqlite3_create_collation(db
, "test_collate", SQLITE_UTF8
,
3167 (void *)SQLITE_UTF8
, val
?test_collate_func
:0);
3168 if( rc
==SQLITE_OK
){
3170 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
3171 rc
= sqlite3_create_collation(db
, "test_collate", SQLITE_UTF16LE
,
3172 (void *)SQLITE_UTF16LE
, val
?test_collate_func
:0);
3173 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[4], &val
) ) return TCL_ERROR
;
3176 if( sqlite3_iMallocFail
>0 ){
3177 sqlite3_iMallocFail
++;
3180 sqlite3_mutex_enter(db
->mutex
);
3181 pVal
= sqlite3ValueNew(db
);
3182 sqlite3ValueSetStr(pVal
, -1, "test_collate", SQLITE_UTF8
, SQLITE_STATIC
);
3183 zUtf16
= sqlite3ValueText(pVal
, SQLITE_UTF16NATIVE
);
3184 if( db
->mallocFailed
){
3187 rc
= sqlite3_create_collation16(db
, zUtf16
, SQLITE_UTF16BE
,
3188 (void *)SQLITE_UTF16BE
, val
?test_collate_func
:0);
3190 sqlite3ValueFree(pVal
);
3191 sqlite3_mutex_leave(db
->mutex
);
3193 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3195 if( rc
!=SQLITE_OK
){
3196 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3202 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3203 Tcl_GetStringFromObj(objv
[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
3208 ** Usage: add_test_utf16bin_collate <db ptr>
3210 ** Add a utf-16 collation sequence named "utf16bin" to the database
3211 ** handle. This collation sequence compares arguments in the same way as the
3212 ** built-in collation "binary".
3214 static int test_utf16bin_collate_func(
3216 int nA
, const void *zA
,
3217 int nB
, const void *zB
3219 int nCmp
= (nA
>nB
? nB
: nA
);
3220 int res
= memcmp(zA
, zB
, nCmp
);
3221 if( res
==0 ) res
= nA
- nB
;
3224 static int SQLITE_TCLAPI
test_utf16bin_collate(
3228 Tcl_Obj
*CONST objv
[]
3233 if( objc
!=2 ) goto bad_args
;
3234 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3236 rc
= sqlite3_create_collation(db
, "utf16bin", SQLITE_UTF16
, 0,
3237 test_utf16bin_collate_func
3239 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3243 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
3248 ** When the collation needed callback is invoked, record the name of
3249 ** the requested collating function here. The recorded name is linked
3250 ** to a TCL variable and used to make sure that the requested collation
3253 static char zNeededCollation
[200];
3254 static char *pzNeededCollation
= zNeededCollation
;
3258 ** Called when a collating sequence is needed. Registered using
3259 ** sqlite3_collation_needed16().
3261 static void test_collate_needed_cb(
3270 for(z
= (char*)pName
, i
=0; *z
|| z
[1]; z
++){
3271 if( *z
) zNeededCollation
[i
++] = *z
;
3273 zNeededCollation
[i
] = 0;
3274 sqlite3_create_collation(
3275 db
, "test_collate", ENC(db
), SQLITE_INT_TO_PTR(enc
), test_collate_func
);
3279 ** Usage: add_test_collate_needed DB
3281 static int SQLITE_TCLAPI
test_collate_needed(
3285 Tcl_Obj
*CONST objv
[]
3290 if( objc
!=2 ) goto bad_args
;
3291 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3292 rc
= sqlite3_collation_needed16(db
, 0, test_collate_needed_cb
);
3293 zNeededCollation
[0] = 0;
3294 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3298 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
3303 ** tclcmd: add_alignment_test_collations DB
3305 ** Add two new collating sequences to the database DB
3310 ** Both collating sequences use the same sort order as BINARY.
3311 ** The only difference is that the utf16_aligned collating
3312 ** sequence is declared with the SQLITE_UTF16_ALIGNED flag.
3313 ** Both collating functions increment the unaligned utf16 counter
3314 ** whenever they see a string that begins on an odd byte boundary.
3316 static int unaligned_string_counter
= 0;
3317 static int alignmentCollFunc(
3319 int nKey1
, const void *pKey1
,
3320 int nKey2
, const void *pKey2
3323 n
= nKey1
<nKey2
? nKey1
: nKey2
;
3324 if( nKey1
>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey1
))) ) unaligned_string_counter
++;
3325 if( nKey2
>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey2
))) ) unaligned_string_counter
++;
3326 rc
= memcmp(pKey1
, pKey2
, n
);
3332 static int SQLITE_TCLAPI
add_alignment_test_collations(
3336 Tcl_Obj
*CONST objv
[]
3340 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3341 sqlite3_create_collation(db
, "utf16_unaligned", SQLITE_UTF16
,
3342 0, alignmentCollFunc
);
3343 sqlite3_create_collation(db
, "utf16_aligned", SQLITE_UTF16_ALIGNED
,
3344 0, alignmentCollFunc
);
3348 #endif /* !defined(SQLITE_OMIT_UTF16) */
3351 ** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be>
3353 ** This function is used to test that SQLite selects the correct user
3354 ** function callback when multiple versions (for different text encodings)
3357 ** Calling this routine registers up to three versions of the user function
3358 ** "test_function" with database handle <db>. If the second argument is
3359 ** true, then a version of test_function is registered for UTF-8, if the
3360 ** third is true, a version is registered for UTF-16le, if the fourth is
3361 ** true, a UTF-16be version is available. Previous versions of
3362 ** test_function are deleted.
3364 ** The user function is implemented by calling the following TCL script:
3366 ** "test_function <enc> <arg>"
3368 ** Where <enc> is one of UTF-8, UTF-16LE or UTF16BE, and <arg> is the
3369 ** single argument passed to the SQL function. The value returned by
3370 ** the TCL script is used as the return value of the SQL function. It
3371 ** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8
3372 ** for a UTF-16LE test_function(), and UTF-16LE for an implementation that
3373 ** prefers UTF-16BE.
3375 #ifndef SQLITE_OMIT_UTF16
3376 static void test_function_utf8(
3377 sqlite3_context
*pCtx
,
3379 sqlite3_value
**argv
3383 sqlite3_value
*pVal
;
3384 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3385 pX
= Tcl_NewStringObj("test_function", -1);
3386 Tcl_IncrRefCount(pX
);
3387 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-8", -1));
3388 Tcl_ListObjAppendElement(interp
, pX
,
3389 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3390 Tcl_EvalObjEx(interp
, pX
, 0);
3391 Tcl_DecrRefCount(pX
);
3392 sqlite3_result_text(pCtx
, Tcl_GetStringResult(interp
), -1, SQLITE_TRANSIENT
);
3393 pVal
= sqlite3ValueNew(0);
3394 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3395 SQLITE_UTF8
, SQLITE_STATIC
);
3396 sqlite3_result_text16be(pCtx
, sqlite3_value_text16be(pVal
),
3397 -1, SQLITE_TRANSIENT
);
3398 sqlite3ValueFree(pVal
);
3400 static void test_function_utf16le(
3401 sqlite3_context
*pCtx
,
3403 sqlite3_value
**argv
3407 sqlite3_value
*pVal
;
3408 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3409 pX
= Tcl_NewStringObj("test_function", -1);
3410 Tcl_IncrRefCount(pX
);
3411 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-16LE", -1));
3412 Tcl_ListObjAppendElement(interp
, pX
,
3413 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3414 Tcl_EvalObjEx(interp
, pX
, 0);
3415 Tcl_DecrRefCount(pX
);
3416 pVal
= sqlite3ValueNew(0);
3417 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3418 SQLITE_UTF8
, SQLITE_STATIC
);
3419 sqlite3_result_text(pCtx
,(char*)sqlite3_value_text(pVal
),-1,SQLITE_TRANSIENT
);
3420 sqlite3ValueFree(pVal
);
3422 static void test_function_utf16be(
3423 sqlite3_context
*pCtx
,
3425 sqlite3_value
**argv
3429 sqlite3_value
*pVal
;
3430 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3431 pX
= Tcl_NewStringObj("test_function", -1);
3432 Tcl_IncrRefCount(pX
);
3433 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-16BE", -1));
3434 Tcl_ListObjAppendElement(interp
, pX
,
3435 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3436 Tcl_EvalObjEx(interp
, pX
, 0);
3437 Tcl_DecrRefCount(pX
);
3438 pVal
= sqlite3ValueNew(0);
3439 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3440 SQLITE_UTF8
, SQLITE_STATIC
);
3441 sqlite3_result_text16(pCtx
, sqlite3_value_text16le(pVal
),
3442 -1, SQLITE_TRANSIENT
);
3443 sqlite3_result_text16be(pCtx
, sqlite3_value_text16le(pVal
),
3444 -1, SQLITE_TRANSIENT
);
3445 sqlite3_result_text16le(pCtx
, sqlite3_value_text16le(pVal
),
3446 -1, SQLITE_TRANSIENT
);
3447 sqlite3ValueFree(pVal
);
3449 #endif /* SQLITE_OMIT_UTF16 */
3450 static int SQLITE_TCLAPI
test_function(
3454 Tcl_Obj
*CONST objv
[]
3456 #ifndef SQLITE_OMIT_UTF16
3460 if( objc
!=5 ) goto bad_args
;
3461 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3463 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
3465 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF8
,
3466 interp
, test_function_utf8
, 0, 0);
3468 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
3470 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF16LE
,
3471 interp
, test_function_utf16le
, 0, 0);
3473 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[4], &val
) ) return TCL_ERROR
;
3475 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF16BE
,
3476 interp
, test_function_utf16be
, 0, 0);
3481 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3482 Tcl_GetStringFromObj(objv
[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
3483 #endif /* SQLITE_OMIT_UTF16 */
3488 ** Usage: sqlite3_test_errstr <err code>
3490 ** Test that the english language string equivalents for sqlite error codes
3491 ** are sane. The parameter is an integer representing an sqlite error code.
3492 ** The result is a list of two elements, the string representation of the
3493 ** error code and the english language explanation.
3495 static int SQLITE_TCLAPI
test_errstr(
3499 Tcl_Obj
*CONST objv
[]
3504 Tcl_WrongNumArgs(interp
, 1, objv
, "<error code>");
3507 zCode
= Tcl_GetString(objv
[1]);
3508 for(i
=0; i
<200; i
++){
3509 if( 0==strcmp(t1ErrorName(i
), zCode
) ) break;
3511 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(i
), 0);
3516 ** Usage: breakpoint
3518 ** This routine exists for one purpose - to provide a place to put a
3519 ** breakpoint with GDB that can be triggered using TCL code. The use
3520 ** for this is when a particular test fails on (say) the 1485th iteration.
3521 ** In the TCL test script, we can add code like this:
3523 ** if {$i==1485} breakpoint
3525 ** Then run testfixture in the debugger and wait for the breakpoint to
3526 ** fire. Then additional breakpoints can be set to trace down the bug.
3528 static int SQLITE_TCLAPI
test_breakpoint(
3530 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
3531 int argc
, /* Number of arguments */
3532 char **argv
/* Text of each argument */
3534 return TCL_OK
; /* Do nothing */
3538 ** Usage: sqlite3_bind_zeroblob STMT IDX N
3540 ** Test the sqlite3_bind_zeroblob interface. STMT is a prepared statement.
3541 ** IDX is the index of a wildcard in the prepared statement. This command
3542 ** binds a N-byte zero-filled BLOB to the wildcard.
3544 static int SQLITE_TCLAPI
test_bind_zeroblob(
3548 Tcl_Obj
*CONST objv
[]
3550 sqlite3_stmt
*pStmt
;
3556 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX N");
3560 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3561 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3562 if( Tcl_GetIntFromObj(interp
, objv
[3], &n
) ) return TCL_ERROR
;
3564 rc
= sqlite3_bind_zeroblob(pStmt
, idx
, n
);
3565 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3566 if( rc
!=SQLITE_OK
){
3574 ** Usage: sqlite3_bind_zeroblob64 STMT IDX N
3576 ** Test the sqlite3_bind_zeroblob64 interface. STMT is a prepared statement.
3577 ** IDX is the index of a wildcard in the prepared statement. This command
3578 ** binds a N-byte zero-filled BLOB to the wildcard.
3580 static int SQLITE_TCLAPI
test_bind_zeroblob64(
3584 Tcl_Obj
*CONST objv
[]
3586 sqlite3_stmt
*pStmt
;
3592 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX N");
3596 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3597 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3598 if( Tcl_GetWideIntFromObj(interp
, objv
[3], &n
) ) return TCL_ERROR
;
3600 rc
= sqlite3_bind_zeroblob64(pStmt
, idx
, n
);
3601 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3602 if( rc
!=SQLITE_OK
){
3603 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3611 ** Usage: sqlite3_bind_int STMT N VALUE
3613 ** Test the sqlite3_bind_int interface. STMT is a prepared statement.
3614 ** N is the index of a wildcard in the prepared statement. This command
3615 ** binds a 32-bit integer VALUE to that wildcard.
3617 static int SQLITE_TCLAPI
test_bind_int(
3621 Tcl_Obj
*CONST objv
[]
3623 sqlite3_stmt
*pStmt
;
3629 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3630 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3634 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3635 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3636 if( Tcl_GetIntFromObj(interp
, objv
[3], &value
) ) return TCL_ERROR
;
3638 rc
= sqlite3_bind_int(pStmt
, idx
, value
);
3639 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3640 if( rc
!=SQLITE_OK
){
3649 ** Usage: intarray_addr INT ...
3651 ** Return the address of a C-language array of 32-bit integers.
3653 ** Space to hold the array is obtained from malloc(). Call this procedure once
3654 ** with no arguments in order to release memory. Each call to this procedure
3655 ** overwrites the previous array.
3657 static int SQLITE_TCLAPI
test_intarray_addr(
3661 Tcl_Obj
*CONST objv
[]
3669 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3670 if( p
==0 ) return TCL_ERROR
;
3671 for(i
=0; i
<objc
-1; i
++){
3672 if( Tcl_GetIntFromObj(interp
, objv
[1+i
], &p
[i
]) ){
3679 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3683 ** Usage: intarray_addr INT ...
3685 ** Return the address of a C-language array of 32-bit integers.
3687 ** Space to hold the array is obtained from malloc(). Call this procedure once
3688 ** with no arguments in order to release memory. Each call to this procedure
3689 ** overwrites the previous array.
3691 static int SQLITE_TCLAPI
test_int64array_addr(
3695 Tcl_Obj
*CONST objv
[]
3698 static sqlite3_int64
*p
= 0;
3703 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3704 if( p
==0 ) return TCL_ERROR
;
3705 for(i
=0; i
<objc
-1; i
++){
3707 if( Tcl_GetWideIntFromObj(interp
, objv
[1+i
], &v
) ){
3715 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3719 ** Usage: doublearray_addr INT ...
3721 ** Return the address of a C-language array of doubles.
3723 ** Space to hold the array is obtained from malloc(). Call this procedure once
3724 ** with no arguments in order to release memory. Each call to this procedure
3725 ** overwrites the previous array.
3727 static int SQLITE_TCLAPI
test_doublearray_addr(
3731 Tcl_Obj
*CONST objv
[]
3734 static double *p
= 0;
3739 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3740 if( p
==0 ) return TCL_ERROR
;
3741 for(i
=0; i
<objc
-1; i
++){
3742 if( Tcl_GetDoubleFromObj(interp
, objv
[1+i
], &p
[i
]) ){
3749 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3753 ** Usage: textarray_addr TEXT ...
3755 ** Return the address of a C-language array of strings.
3757 ** Space to hold the array is obtained from malloc(). Call this procedure once
3758 ** with no arguments in order to release memory. Each call to this procedure
3759 ** overwrites the previous array.
3761 static int SQLITE_TCLAPI
test_textarray_addr(
3765 Tcl_Obj
*CONST objv
[]
3769 static char **p
= 0;
3771 for(i
=0; i
<n
; i
++) sqlite3_free(p
[i
]);
3775 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3776 if( p
==0 ) return TCL_ERROR
;
3777 for(i
=0; i
<objc
-1; i
++){
3778 p
[i
] = sqlite3_mprintf("%s", Tcl_GetString(objv
[1+i
]));
3782 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3788 ** Usage: sqlite3_bind_int64 STMT N VALUE
3790 ** Test the sqlite3_bind_int64 interface. STMT is a prepared statement.
3791 ** N is the index of a wildcard in the prepared statement. This command
3792 ** binds a 64-bit integer VALUE to that wildcard.
3794 static int SQLITE_TCLAPI
test_bind_int64(
3798 Tcl_Obj
*CONST objv
[]
3800 sqlite3_stmt
*pStmt
;
3806 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3807 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3811 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3812 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3813 if( Tcl_GetWideIntFromObj(interp
, objv
[3], &value
) ) return TCL_ERROR
;
3815 rc
= sqlite3_bind_int64(pStmt
, idx
, value
);
3816 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3817 if( rc
!=SQLITE_OK
){
3826 ** Usage: sqlite3_bind_double STMT N VALUE
3828 ** Test the sqlite3_bind_double interface. STMT is a prepared statement.
3829 ** N is the index of a wildcard in the prepared statement. This command
3830 ** binds a 64-bit integer VALUE to that wildcard.
3832 static int SQLITE_TCLAPI
test_bind_double(
3836 Tcl_Obj
*CONST objv
[]
3838 sqlite3_stmt
*pStmt
;
3844 static const struct {
3845 const char *zName
; /* Name of the special floating point value */
3846 unsigned int iUpper
; /* Upper 32 bits */
3847 unsigned int iLower
; /* Lower 32 bits */
3849 { "NaN", 0x7fffffff, 0xffffffff },
3850 { "SNaN", 0x7ff7ffff, 0xffffffff },
3851 { "-NaN", 0xffffffff, 0xffffffff },
3852 { "-SNaN", 0xfff7ffff, 0xffffffff },
3853 { "+Inf", 0x7ff00000, 0x00000000 },
3854 { "-Inf", 0xfff00000, 0x00000000 },
3855 { "Epsilon", 0x00000000, 0x00000001 },
3856 { "-Epsilon", 0x80000000, 0x00000001 },
3857 { "NaN0", 0x7ff80000, 0x00000000 },
3858 { "-NaN0", 0xfff80000, 0x00000000 },
3862 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3863 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3867 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3868 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3870 /* Intercept the string "NaN" and generate a NaN value for it.
3871 ** All other strings are passed through to Tcl_GetDoubleFromObj().
3872 ** Tcl_GetDoubleFromObj() should understand "NaN" but some versions
3875 zVal
= Tcl_GetString(objv
[3]);
3876 for(i
=0; i
<sizeof(aSpecialFp
)/sizeof(aSpecialFp
[0]); i
++){
3877 if( strcmp(aSpecialFp
[i
].zName
, zVal
)==0 ){
3879 x
= aSpecialFp
[i
].iUpper
;
3881 x
|= aSpecialFp
[i
].iLower
;
3882 assert( sizeof(value
)==8 );
3883 assert( sizeof(x
)==8 );
3884 memcpy(&value
, &x
, 8);
3888 if( i
>=sizeof(aSpecialFp
)/sizeof(aSpecialFp
[0]) &&
3889 Tcl_GetDoubleFromObj(interp
, objv
[3], &value
) ){
3892 rc
= sqlite3_bind_double(pStmt
, idx
, value
);
3893 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3894 if( rc
!=SQLITE_OK
){
3902 ** Usage: sqlite3_bind_null STMT N
3904 ** Test the sqlite3_bind_null interface. STMT is a prepared statement.
3905 ** N is the index of a wildcard in the prepared statement. This command
3906 ** binds a NULL to the wildcard.
3908 static int SQLITE_TCLAPI
test_bind_null(
3912 Tcl_Obj
*CONST objv
[]
3914 sqlite3_stmt
*pStmt
;
3919 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3920 Tcl_GetStringFromObj(objv
[0], 0), " STMT N", 0);
3924 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3925 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3927 rc
= sqlite3_bind_null(pStmt
, idx
);
3928 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3929 if( rc
!=SQLITE_OK
){
3937 ** Usage: sqlite3_bind_text STMT N STRING BYTES
3939 ** Test the sqlite3_bind_text interface. STMT is a prepared statement.
3940 ** N is the index of a wildcard in the prepared statement. This command
3941 ** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes
3944 static int SQLITE_TCLAPI
test_bind_text(
3948 Tcl_Obj
*CONST objv
[]
3950 sqlite3_stmt
*pStmt
;
3959 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3960 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE BYTES", 0);
3964 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3965 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3966 value
= (char*)Tcl_GetByteArrayFromObj(objv
[3], &trueLength
);
3967 if( Tcl_GetIntFromObj(interp
, objv
[4], &bytes
) ) return TCL_ERROR
;
3969 toFree
= malloc( trueLength
+ 1 );
3971 Tcl_AppendResult(interp
, "out of memory", (void*)0);
3974 memcpy(toFree
, value
, trueLength
);
3975 toFree
[trueLength
] = 0;
3978 rc
= sqlite3_bind_text(pStmt
, idx
, value
, bytes
, SQLITE_TRANSIENT
);
3980 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3981 if( rc
!=SQLITE_OK
){
3982 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), (void*)0);
3990 ** Usage: sqlite3_bind_text16 ?-static? STMT N STRING BYTES
3992 ** Test the sqlite3_bind_text16 interface. STMT is a prepared statement.
3993 ** N is the index of a wildcard in the prepared statement. This command
3994 ** binds a UTF-16 string STRING to the wildcard. The string is BYTES bytes
3997 static int SQLITE_TCLAPI
test_bind_text16(
4001 Tcl_Obj
*CONST objv
[]
4003 #ifndef SQLITE_OMIT_UTF16
4004 sqlite3_stmt
*pStmt
;
4012 void (*xDel
)(void*) = (objc
==6?SQLITE_STATIC
:SQLITE_TRANSIENT
);
4013 Tcl_Obj
*oStmt
= objv
[objc
-4];
4014 Tcl_Obj
*oN
= objv
[objc
-3];
4015 Tcl_Obj
*oString
= objv
[objc
-2];
4016 Tcl_Obj
*oBytes
= objv
[objc
-1];
4018 if( objc
!=5 && objc
!=6){
4019 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4020 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE BYTES", 0);
4024 if( getStmtPointer(interp
, Tcl_GetString(oStmt
), &pStmt
) ) return TCL_ERROR
;
4025 if( Tcl_GetIntFromObj(interp
, oN
, &idx
) ) return TCL_ERROR
;
4026 value
= (char*)Tcl_GetByteArrayFromObj(oString
, &trueLength
);
4027 if( Tcl_GetIntFromObj(interp
, oBytes
, &bytes
) ) return TCL_ERROR
;
4028 if( bytes
<0 && xDel
==SQLITE_TRANSIENT
){
4029 toFree
= malloc( trueLength
+ 3 );
4031 Tcl_AppendResult(interp
, "out of memory", (void*)0);
4034 memcpy(toFree
, value
, trueLength
);
4035 memset(toFree
+trueLength
, 0, 3);
4038 rc
= sqlite3_bind_text16(pStmt
, idx
, (void *)value
, bytes
, xDel
);
4040 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
4041 if( rc
!=SQLITE_OK
){
4042 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
4046 #endif /* SQLITE_OMIT_UTF16 */
4051 ** Usage: sqlite3_bind_blob ?-static? STMT N DATA BYTES
4053 ** Test the sqlite3_bind_blob interface. STMT is a prepared statement.
4054 ** N is the index of a wildcard in the prepared statement. This command
4055 ** binds a BLOB to the wildcard. The BLOB is BYTES bytes in size.
4057 static int SQLITE_TCLAPI
test_bind_blob(
4061 Tcl_Obj
*CONST objv
[]
4063 sqlite3_stmt
*pStmt
;
4068 sqlite3_destructor_type xDestructor
= SQLITE_TRANSIENT
;
4070 if( objc
!=5 && objc
!=6 ){
4071 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4072 Tcl_GetStringFromObj(objv
[0], 0), " STMT N DATA BYTES", 0);
4077 xDestructor
= SQLITE_STATIC
;
4081 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4082 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
4084 value
= (char*)Tcl_GetByteArrayFromObj(objv
[3], &len
);
4085 if( Tcl_GetIntFromObj(interp
, objv
[4], &bytes
) ) return TCL_ERROR
;
4089 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
4090 "cannot use %d blob bytes, have %d", bytes
, len
);
4091 Tcl_AppendResult(interp
, zBuf
, (char*)0);
4095 rc
= sqlite3_bind_blob(pStmt
, idx
, value
, bytes
, xDestructor
);
4096 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
4097 if( rc
!=SQLITE_OK
){
4105 ** Usage: sqlite3_bind_value_from_preupdate STMT N NEW|OLD IDX
4107 ** Test the sqlite3_bind_value interface using sqlite3_value objects
4108 ** obtained from either sqlite3_preupdate_new() (if arg[3]=="new") or
4109 ** sqlite3_preupdate_old() if (arg[3]=="old"). IDX is the index to
4110 ** pass to the sqlite3_preupdate_xxx() function.
4112 static int SQLITE_TCLAPI
test_bind_value_from_preupdate(
4116 Tcl_Obj
*CONST objv
[]
4118 sqlite3_stmt
*pStmt
;
4123 sqlite3_value
*pVal
= 0;
4126 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT N NEW|OLD IDX");
4130 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4131 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
4132 z3
= Tcl_GetString(objv
[3]);
4133 if( Tcl_GetIntFromObj(interp
, objv
[4], &bidx
) ) return TCL_ERROR
;
4134 db
= sqlite3_db_handle(pStmt
);
4136 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
4138 sqlite3_preupdate_new(db
, bidx
, &pVal
);
4139 }else if( z3
[0]=='o' ){
4140 sqlite3_preupdate_old(db
, bidx
, &pVal
);
4142 Tcl_AppendResult(interp
, "expected new or old, got: ", z3
, (char*)0);
4145 sqlite3_bind_value(pStmt
, idx
, pVal
);
4152 ** Usage: sqlite3_bind_value_from_select STMT N SELECT
4154 ** Test the sqlite3_bind_value interface. STMT is a prepared statement.
4155 ** N is the index of a wildcard in the prepared statement.
4157 static int SQLITE_TCLAPI
test_bind_value_from_select(
4161 Tcl_Obj
*CONST objv
[]
4163 sqlite3_stmt
*pStmt
;
4164 sqlite3_stmt
*pStmt2
;
4166 const char *zSql
= 0;
4171 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT N SELECT");
4175 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4176 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
4177 zSql
= Tcl_GetString(objv
[3]);
4178 db
= sqlite3_db_handle(pStmt
);
4180 rc
= sqlite3_prepare_v2(db
, zSql
, -1, &pStmt2
, 0);
4181 if( rc
!=SQLITE_OK
){
4182 Tcl_AppendResult(interp
, "error in SQL: ", sqlite3_errmsg(db
), (char*)0);
4185 if( sqlite3_step(pStmt2
)==SQLITE_ROW
){
4186 sqlite3_value
*pVal
= sqlite3_column_value(pStmt2
, 0);
4187 sqlite3_bind_value(pStmt
, idx
, pVal
);
4189 rc
= sqlite3_finalize(pStmt2
);
4190 if( rc
!=SQLITE_OK
){
4191 Tcl_AppendResult(interp
,
4192 "error runnning SQL: ", sqlite3_errmsg(db
), (char*)0
4206 # include <sys/uio.h>
4209 #ifndef SQLITE_OMIT_VIRTUALTABLE
4211 ** sqlite3_carray_bind [options...] STMT NAME VALUE ...
4222 ** Each call clears static data. Called with no options does nothing
4223 ** but clear static data.
4225 static int SQLITE_TCLAPI
test_carray_bind(
4229 Tcl_Obj
*CONST objv
[]
4231 sqlite3_stmt
*pStmt
;
4232 int eType
= 0; /* CARRAY_INT32 */
4235 int isTransient
= 0;
4240 void (*xDel
)(void*) = sqlite3_free
;
4241 static void *aStaticData
= 0;
4242 static int nStaticData
= 0;
4243 static int eStaticType
= 0;
4244 extern int sqlite3_carray_bind(
4245 sqlite3_stmt
*pStmt
,
4250 void (*xDestroy
)(void*)
4254 /* Always clear preexisting static data on every call */
4255 if( eStaticType
==3 ){
4256 for(i
=0; i
<nStaticData
; i
++){
4257 sqlite3_free(((char**)aStaticData
)[i
]);
4260 if( eStaticType
==4 ){
4261 for(i
=0; i
<nStaticData
; i
++){
4262 sqlite3_free(((struct iovec
*)aStaticData
)[i
].iov_base
);
4265 sqlite3_free(aStaticData
);
4270 if( objc
==1 ) return TCL_OK
;
4272 for(i
=1; i
<objc
&& Tcl_GetString(objv
[i
])[0]=='-'; i
++){
4273 const char *z
= Tcl_GetString(objv
[i
]);
4274 if( strcmp(z
, "-transient")==0 ){
4276 xDel
= SQLITE_TRANSIENT
;
4278 if( strcmp(z
, "-static")==0 ){
4280 xDel
= SQLITE_STATIC
;
4282 if( strcmp(z
, "-int32")==0 ){
4283 eType
= 0; /* CARRAY_INT32 */
4285 if( strcmp(z
, "-int64")==0 ){
4286 eType
= 1; /* CARRAY_INT64 */
4288 if( strcmp(z
, "-double")==0 ){
4289 eType
= 2; /* CARRAY_DOUBLE */
4291 if( strcmp(z
, "-text")==0 ){
4292 eType
= 3; /* CARRAY_TEXT */
4294 if( strcmp(z
, "-blob")==0 ){
4295 eType
= 4; /* CARRAY_BLOB */
4297 if( strcmp(z
, "--")==0 ){
4301 Tcl_AppendResult(interp
, "unknown option: ", z
, (char*)0);
4305 if( eType
==3 && !isStatic
&& !isTransient
){
4306 Tcl_AppendResult(interp
, "text data must be either -static or -transient",
4310 if( eType
==4 && !isStatic
&& !isTransient
){
4311 Tcl_AppendResult(interp
, "blob data must be either -static or -transient",
4315 if( isStatic
&& isTransient
){
4316 Tcl_AppendResult(interp
, "cannot be both -static and -transient",
4321 Tcl_WrongNumArgs(interp
, 1, objv
, "[OPTIONS] STMT IDX VALUE ...");
4324 if( getStmtPointer(interp
, Tcl_GetString(objv
[i
]), &pStmt
) ) return TCL_ERROR
;
4326 if( Tcl_GetIntFromObj(interp
, objv
[i
], &idx
) ) return TCL_ERROR
;
4329 switch( eType
+ 5*(nData
<=0) ){
4330 case 0: { /* INT32 */
4331 int *a
= sqlite3_malloc( sizeof(int)*nData
);
4332 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4333 for(j
=0; j
<nData
; j
++){
4335 if( Tcl_GetIntFromObj(interp
, objv
[i
+j
], &v
) ){
4344 case 1: { /* INT64 */
4345 sqlite3_int64
*a
= sqlite3_malloc( sizeof(sqlite3_int64
)*nData
);
4346 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4347 for(j
=0; j
<nData
; j
++){
4349 if( Tcl_GetWideIntFromObj(interp
, objv
[i
+j
], &v
) ){
4358 case 2: { /* DOUBLE */
4359 double *a
= sqlite3_malloc( sizeof(double)*nData
);
4360 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4361 for(j
=0; j
<nData
; j
++){
4363 if( Tcl_GetDoubleFromObj(interp
, objv
[i
+j
], &v
) ){
4372 case 3: { /* TEXT */
4373 char **a
= sqlite3_malloc( sizeof(char*)*nData
);
4374 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4375 for(j
=0; j
<nData
; j
++){
4376 const char *v
= Tcl_GetString(objv
[i
+j
]);
4377 a
[j
] = sqlite3_mprintf("%s", v
);
4382 case 4: { /* BLOB */
4383 struct iovec
*a
= sqlite3_malloc( sizeof(struct iovec
)*nData
);
4384 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4385 for(j
=0; j
<nData
; j
++){
4387 unsigned char *v
= Tcl_GetByteArrayFromObj(objv
[i
+i
], &n
);
4389 a
[j
].iov_base
= sqlite3_malloc64( n
);
4390 if( a
[j
].iov_base
==0 ){
4393 memcpy(a
[j
].iov_base
, v
, n
);
4399 case 5: { /* nData==0 */
4401 xDel
= SQLITE_STATIC
;
4408 aStaticData
= aData
;
4409 nStaticData
= nData
;
4410 eStaticType
= eType
;
4412 rc
= sqlite3_carray_bind(pStmt
, idx
, aData
, nData
, eType
, xDel
);
4415 for(i
=0; i
<nData
; i
++) sqlite3_free(((char**)aData
)[i
]);
4418 for(i
=0; i
<nData
; i
++) sqlite3_free(((struct iovec
*)aData
)[i
].iov_base
);
4420 sqlite3_free(aData
);
4424 Tcl_AppendResult(interp
, sqlite3_errstr(rc
), (char*)0);
4429 #endif /* SQLITE_OMIT_VIRTUALTABLE */
4432 ** Usage: sqlite3_bind_parameter_count STMT
4434 ** Return the number of wildcards in the given statement.
4436 static int SQLITE_TCLAPI
test_bind_parameter_count(
4440 Tcl_Obj
*CONST objv
[]
4442 sqlite3_stmt
*pStmt
;
4445 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4448 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4449 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_bind_parameter_count(pStmt
)));
4454 ** Usage: sqlite3_bind_parameter_name STMT N
4456 ** Return the name of the Nth wildcard. The first wildcard is 1.
4457 ** An empty string is returned if N is out of range or if the wildcard
4460 static int SQLITE_TCLAPI
test_bind_parameter_name(
4464 Tcl_Obj
*CONST objv
[]
4466 sqlite3_stmt
*pStmt
;
4470 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT N");
4473 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4474 if( Tcl_GetIntFromObj(interp
, objv
[2], &i
) ) return TCL_ERROR
;
4475 Tcl_SetObjResult(interp
,
4476 Tcl_NewStringObj(sqlite3_bind_parameter_name(pStmt
,i
),-1)
4482 ** Usage: sqlite3_bind_parameter_index STMT NAME
4484 ** Return the index of the wildcard called NAME. Return 0 if there is
4485 ** no such wildcard.
4487 static int SQLITE_TCLAPI
test_bind_parameter_index(
4491 Tcl_Obj
*CONST objv
[]
4493 sqlite3_stmt
*pStmt
;
4496 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT NAME");
4499 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4500 Tcl_SetObjResult(interp
,
4502 sqlite3_bind_parameter_index(pStmt
,Tcl_GetString(objv
[2]))
4509 ** Usage: sqlite3_clear_bindings STMT
4512 static int SQLITE_TCLAPI
test_clear_bindings(
4516 Tcl_Obj
*CONST objv
[]
4518 sqlite3_stmt
*pStmt
;
4521 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4524 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4525 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_clear_bindings(pStmt
)));
4530 ** Usage: sqlite3_sleep MILLISECONDS
4532 static int SQLITE_TCLAPI
test_sleep(
4536 Tcl_Obj
*CONST objv
[]
4541 Tcl_WrongNumArgs(interp
, 1, objv
, "MILLISECONDS");
4544 if( Tcl_GetIntFromObj(interp
, objv
[1], &ms
) ){
4547 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_sleep(ms
)));
4552 ** Usage: sqlite3_extended_errcode DB
4554 ** Return the string representation of the most recent sqlite3_* API
4555 ** error code. e.g. "SQLITE_ERROR".
4557 static int SQLITE_TCLAPI
test_ex_errcode(
4561 Tcl_Obj
*CONST objv
[]
4567 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4568 Tcl_GetString(objv
[0]), " DB", 0);
4571 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4572 rc
= sqlite3_extended_errcode(db
);
4573 Tcl_AppendResult(interp
, (char *)t1ErrorName(rc
), 0);
4579 ** Usage: sqlite3_errcode DB
4581 ** Return the string representation of the most recent sqlite3_* API
4582 ** error code. e.g. "SQLITE_ERROR".
4584 static int SQLITE_TCLAPI
test_errcode(
4588 Tcl_Obj
*CONST objv
[]
4594 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4595 Tcl_GetString(objv
[0]), " DB", 0);
4598 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4599 rc
= sqlite3_errcode(db
);
4600 Tcl_AppendResult(interp
, (char *)t1ErrorName(rc
), 0);
4605 ** Usage: sqlite3_errmsg DB
4607 ** Returns the UTF-8 representation of the error message string for the
4608 ** most recent sqlite3_* API call.
4610 static int SQLITE_TCLAPI
test_errmsg(
4614 Tcl_Obj
*CONST objv
[]
4620 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4621 Tcl_GetString(objv
[0]), " DB", 0);
4624 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4626 zErr
= sqlite3_errmsg(db
);
4627 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zErr
, -1));
4633 ** Usage: sqlite3_error_offset DB
4635 ** Return the byte offset into the input UTF8 SQL for the most recent
4636 ** error, or -1 of the error does not refer to a specific token.
4638 static int SQLITE_TCLAPI
test_error_offset(
4642 Tcl_Obj
*CONST objv
[]
4648 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4649 Tcl_GetString(objv
[0]), " DB", 0);
4652 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4654 iByteOffset
= sqlite3_error_offset(db
);
4655 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iByteOffset
));
4660 ** Usage: test_errmsg16 DB
4662 ** Returns the UTF-16 representation of the error message string for the
4663 ** most recent sqlite3_* API call. This is a byte array object at the TCL
4664 ** level, and it includes the 0x00 0x00 terminator bytes at the end of the
4667 static int SQLITE_TCLAPI
test_errmsg16(
4671 Tcl_Obj
*CONST objv
[]
4673 #ifndef SQLITE_OMIT_UTF16
4680 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4681 Tcl_GetString(objv
[0]), " DB", 0);
4684 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4686 zErr
= sqlite3_errmsg16(db
);
4689 for(bytes
=0; z
[bytes
] || z
[bytes
+1]; bytes
+=2){}
4691 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(zErr
, bytes
));
4692 #endif /* SQLITE_OMIT_UTF16 */
4697 ** Usage: sqlite3_prepare DB sql bytes ?tailvar?
4699 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4700 ** database handle <DB>. The parameter <tailval> is the name of a global
4701 ** variable that is set to the unused portion of <sql> (if any). A
4702 ** STMT handle is returned.
4704 static int SQLITE_TCLAPI
test_prepare(
4708 Tcl_Obj
*CONST objv
[]
4713 const char *zTail
= 0;
4714 sqlite3_stmt
*pStmt
= 0;
4718 if( objc
!=5 && objc
!=4 ){
4719 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4720 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
4723 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4724 zSql
= Tcl_GetString(objv
[2]);
4725 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4727 rc
= sqlite3_prepare(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4728 Tcl_ResetResult(interp
);
4729 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4730 if( zTail
&& objc
>=5 ){
4732 bytes
= bytes
- (int)(zTail
-zSql
);
4734 if( (int)strlen(zTail
)<bytes
){
4735 bytes
= (int)strlen(zTail
);
4737 Tcl_ObjSetVar2(interp
, objv
[4], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4739 if( rc
!=SQLITE_OK
){
4741 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4742 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4747 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4748 Tcl_AppendResult(interp
, zBuf
, 0);
4754 ** Usage: sqlite3_prepare_v2 DB sql bytes ?tailvar?
4756 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4757 ** database handle <DB>. The parameter <tailval> is the name of a global
4758 ** variable that is set to the unused portion of <sql> (if any). A
4759 ** STMT handle is returned.
4761 static int SQLITE_TCLAPI
test_prepare_v2(
4765 Tcl_Obj
*CONST objv
[]
4769 char *zCopy
= 0; /* malloc() copy of zSql */
4771 const char *zTail
= 0;
4772 const char **pzTail
;
4773 sqlite3_stmt
*pStmt
= 0;
4777 if( objc
!=5 && objc
!=4 ){
4778 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4779 Tcl_GetString(objv
[0]), " DB sql bytes tailvar", 0);
4782 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4783 zSql
= Tcl_GetString(objv
[2]);
4784 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4786 /* Instead of using zSql directly, make a copy into a buffer obtained
4787 ** directly from malloc(). The idea is to make it easier for valgrind
4788 ** to spot buffer overreads. */
4790 zCopy
= malloc(bytes
);
4791 memcpy(zCopy
, zSql
, bytes
);
4793 int n
= (int)strlen(zSql
) + 1;
4795 memcpy(zCopy
, zSql
, n
);
4797 pzTail
= objc
>=5 ? &zTail
: 0;
4798 rc
= sqlite3_prepare_v2(db
, zCopy
, bytes
, &pStmt
, pzTail
);
4800 zTail
= &zSql
[(zTail
- zCopy
)];
4804 assert(rc
==SQLITE_OK
|| pStmt
==0);
4805 Tcl_ResetResult(interp
);
4806 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4807 if( rc
==SQLITE_OK
&& objc
>=5 && zTail
){
4809 bytes
= bytes
- (int)(zTail
-zSql
);
4811 Tcl_ObjSetVar2(interp
, objv
[4], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4813 if( rc
!=SQLITE_OK
){
4815 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4816 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4821 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4822 Tcl_AppendResult(interp
, zBuf
, 0);
4828 ** Usage: sqlite3_prepare_v3 DB sql bytes flags ?tailvar?
4830 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4831 ** database handle <DB> and flags <flags>. The parameter <tailval> is
4832 ** the name of a global variable that is set to the unused portion of
4833 ** <sql> (if any). A STMT handle is returned.
4835 static int SQLITE_TCLAPI
test_prepare_v3(
4839 Tcl_Obj
*CONST objv
[]
4843 char *zCopy
= 0; /* malloc() copy of zSql */
4845 const char *zTail
= 0;
4846 const char **pzTail
;
4847 sqlite3_stmt
*pStmt
= 0;
4851 if( objc
!=6 && objc
!=5 ){
4852 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4853 Tcl_GetString(objv
[0]), " DB sql bytes flags tailvar", 0);
4856 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4857 zSql
= Tcl_GetString(objv
[2]);
4858 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4859 if( Tcl_GetIntFromObj(interp
, objv
[4], &flags
) ) return TCL_ERROR
;
4861 /* Instead of using zSql directly, make a copy into a buffer obtained
4862 ** directly from malloc(). The idea is to make it easier for valgrind
4863 ** to spot buffer overreads. */
4865 zCopy
= malloc(bytes
);
4866 memcpy(zCopy
, zSql
, bytes
);
4868 int n
= (int)strlen(zSql
) + 1;
4870 memcpy(zCopy
, zSql
, n
);
4872 pzTail
= objc
>=6 ? &zTail
: 0;
4873 rc
= sqlite3_prepare_v3(db
, zCopy
, bytes
, (unsigned int)flags
,&pStmt
,pzTail
);
4875 zTail
= &zSql
[(zTail
- zCopy
)];
4877 assert(rc
==SQLITE_OK
|| pStmt
==0);
4878 Tcl_ResetResult(interp
);
4879 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4880 if( rc
==SQLITE_OK
&& zTail
&& objc
>=6 ){
4882 bytes
= bytes
- (int)(zTail
-zSql
);
4884 Tcl_ObjSetVar2(interp
, objv
[5], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4886 if( rc
!=SQLITE_OK
){
4888 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4889 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4894 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4895 Tcl_AppendResult(interp
, zBuf
, 0);
4901 ** Usage: sqlite3_prepare_tkt3134 DB
4903 ** Generate a prepared statement for a zero-byte string as a test
4904 ** for ticket #3134. The string should be preceded by a zero byte.
4906 static int SQLITE_TCLAPI
test_prepare_tkt3134(
4910 Tcl_Obj
*CONST objv
[]
4913 static const char zSql
[] = "\000SELECT 1";
4914 sqlite3_stmt
*pStmt
= 0;
4919 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4920 Tcl_GetString(objv
[0]), " DB sql bytes tailvar", 0);
4923 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4924 rc
= sqlite3_prepare_v2(db
, &zSql
[1], 0, &pStmt
, 0);
4925 assert(rc
==SQLITE_OK
|| pStmt
==0);
4926 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4927 if( rc
!=SQLITE_OK
){
4929 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4930 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4935 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4936 Tcl_AppendResult(interp
, zBuf
, 0);
4942 ** Usage: sqlite3_prepare16 DB sql bytes tailvar
4944 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4945 ** database handle <DB>. The parameter <tailval> is the name of a global
4946 ** variable that is set to the unused portion of <sql> (if any). A
4947 ** STMT handle is returned.
4949 static int SQLITE_TCLAPI
test_prepare16(
4953 Tcl_Obj
*CONST objv
[]
4955 #ifndef SQLITE_OMIT_UTF16
4958 const void *zTail
= 0;
4960 sqlite3_stmt
*pStmt
= 0;
4963 int bytes
; /* The integer specified as arg 3 */
4964 int objlen
; /* The byte-array length of arg 2 */
4966 if( objc
!=5 && objc
!=4 ){
4967 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4968 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
4971 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4972 zSql
= Tcl_GetByteArrayFromObj(objv
[2], &objlen
);
4973 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4975 rc
= sqlite3_prepare16(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4976 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4983 objlen
= objlen
- (int)((u8
*)zTail
-(u8
*)zSql
);
4987 pTail
= Tcl_NewByteArrayObj((u8
*)zTail
, objlen
);
4988 Tcl_IncrRefCount(pTail
);
4989 Tcl_ObjSetVar2(interp
, objv
[4], 0, pTail
, 0);
4990 Tcl_DecrRefCount(pTail
);
4994 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4996 Tcl_AppendResult(interp
, zBuf
, 0);
4997 #endif /* SQLITE_OMIT_UTF16 */
5002 ** Usage: sqlite3_prepare16_v2 DB sql bytes ?tailvar?
5004 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
5005 ** database handle <DB>. The parameter <tailval> is the name of a global
5006 ** variable that is set to the unused portion of <sql> (if any). A
5007 ** STMT handle is returned.
5009 static int SQLITE_TCLAPI
test_prepare16_v2(
5013 Tcl_Obj
*CONST objv
[]
5015 #ifndef SQLITE_OMIT_UTF16
5018 const void *zTail
= 0;
5020 sqlite3_stmt
*pStmt
= 0;
5023 int bytes
; /* The integer specified as arg 3 */
5024 int objlen
; /* The byte-array length of arg 2 */
5026 if( objc
!=5 && objc
!=4 ){
5027 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5028 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
5031 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5032 zSql
= Tcl_GetByteArrayFromObj(objv
[2], &objlen
);
5033 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
5035 rc
= sqlite3_prepare16_v2(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
5036 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
5043 objlen
= objlen
- (int)((u8
*)zTail
-(u8
*)zSql
);
5047 pTail
= Tcl_NewByteArrayObj((u8
*)zTail
, objlen
);
5048 Tcl_IncrRefCount(pTail
);
5049 Tcl_ObjSetVar2(interp
, objv
[4], 0, pTail
, 0);
5050 Tcl_DecrRefCount(pTail
);
5054 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
5056 Tcl_AppendResult(interp
, zBuf
, 0);
5057 #endif /* SQLITE_OMIT_UTF16 */
5062 ** Usage: sqlite3_open filename ?options-list?
5064 static int SQLITE_TCLAPI
test_open(
5068 Tcl_Obj
*CONST objv
[]
5070 const char *zFilename
;
5074 if( objc
!=3 && objc
!=2 && objc
!=1 ){
5075 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5076 Tcl_GetString(objv
[0]), " filename options-list", 0);
5080 zFilename
= objc
>1 ? Tcl_GetString(objv
[1]) : 0;
5081 sqlite3_open(zFilename
, &db
);
5083 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
5084 Tcl_AppendResult(interp
, zBuf
, 0);
5089 ** Usage: sqlite3_open_v2 FILENAME FLAGS VFS
5091 static int SQLITE_TCLAPI
test_open_v2(
5095 Tcl_Obj
*CONST objv
[]
5097 const char *zFilename
;
5109 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME FLAGS VFS");
5112 zFilename
= Tcl_GetString(objv
[1]);
5113 zVfs
= Tcl_GetString(objv
[3]);
5114 if( zVfs
[0]==0x00 ) zVfs
= 0;
5116 rc
= Tcl_ListObjGetElements(interp
, objv
[2], &nFlag
, &apFlag
);
5117 if( rc
!=TCL_OK
) return rc
;
5118 for(i
=0; i
<nFlag
; i
++){
5124 { "SQLITE_OPEN_READONLY", SQLITE_OPEN_READONLY
},
5125 { "SQLITE_OPEN_READWRITE", SQLITE_OPEN_READWRITE
},
5126 { "SQLITE_OPEN_CREATE", SQLITE_OPEN_CREATE
},
5127 { "SQLITE_OPEN_DELETEONCLOSE", SQLITE_OPEN_DELETEONCLOSE
},
5128 { "SQLITE_OPEN_EXCLUSIVE", SQLITE_OPEN_EXCLUSIVE
},
5129 { "SQLITE_OPEN_AUTOPROXY", SQLITE_OPEN_AUTOPROXY
},
5130 { "SQLITE_OPEN_MAIN_DB", SQLITE_OPEN_MAIN_DB
},
5131 { "SQLITE_OPEN_TEMP_DB", SQLITE_OPEN_TEMP_DB
},
5132 { "SQLITE_OPEN_TRANSIENT_DB", SQLITE_OPEN_TRANSIENT_DB
},
5133 { "SQLITE_OPEN_MAIN_JOURNAL", SQLITE_OPEN_MAIN_JOURNAL
},
5134 { "SQLITE_OPEN_TEMP_JOURNAL", SQLITE_OPEN_TEMP_JOURNAL
},
5135 { "SQLITE_OPEN_SUBJOURNAL", SQLITE_OPEN_SUBJOURNAL
},
5136 { "SQLITE_OPEN_SUPER_JOURNAL", SQLITE_OPEN_SUPER_JOURNAL
},
5137 { "SQLITE_OPEN_NOMUTEX", SQLITE_OPEN_NOMUTEX
},
5138 { "SQLITE_OPEN_FULLMUTEX", SQLITE_OPEN_FULLMUTEX
},
5139 { "SQLITE_OPEN_SHAREDCACHE", SQLITE_OPEN_SHAREDCACHE
},
5140 { "SQLITE_OPEN_PRIVATECACHE", SQLITE_OPEN_PRIVATECACHE
},
5141 { "SQLITE_OPEN_WAL", SQLITE_OPEN_WAL
},
5142 { "SQLITE_OPEN_URI", SQLITE_OPEN_URI
},
5143 { "SQLITE_OPEN_EXRESCODE", SQLITE_OPEN_EXRESCODE
},
5146 rc
= Tcl_GetIndexFromObjStruct(interp
, apFlag
[i
], aFlag
, sizeof(aFlag
[0]),
5149 if( rc
!=TCL_OK
) return rc
;
5150 flags
|= aFlag
[iFlag
].flag
;
5153 rc
= sqlite3_open_v2(zFilename
, &db
, flags
, zVfs
);
5154 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
5155 Tcl_AppendResult(interp
, zBuf
, 0);
5160 ** Usage: sqlite3_open16 filename options
5162 static int SQLITE_TCLAPI
test_open16(
5166 Tcl_Obj
*CONST objv
[]
5168 #ifndef SQLITE_OMIT_UTF16
5169 const void *zFilename
;
5174 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5175 Tcl_GetString(objv
[0]), " filename options-list", 0);
5179 zFilename
= Tcl_GetByteArrayFromObj(objv
[1], 0);
5180 sqlite3_open16(zFilename
, &db
);
5182 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
5183 Tcl_AppendResult(interp
, zBuf
, 0);
5184 #endif /* SQLITE_OMIT_UTF16 */
5189 ** Usage: sqlite3_complete16 <UTF-16 string>
5191 ** Return 1 if the supplied argument is a complete SQL statement, or zero
5194 static int SQLITE_TCLAPI
test_complete16(
5198 Tcl_Obj
*CONST objv
[]
5200 #if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16)
5204 Tcl_WrongNumArgs(interp
, 1, objv
, "<utf-16 sql>");
5208 zBuf
= (char*)Tcl_GetByteArrayFromObj(objv
[1], 0);
5209 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_complete16(zBuf
)));
5210 #endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */
5215 ** Usage: sqlite3_normalize SQL
5217 ** Return the normalized value for an SQL statement.
5219 static int SQLITE_TCLAPI
test_normalize(
5223 Tcl_Obj
*CONST objv
[]
5227 extern char *sqlite3_normalize(const char*);
5230 Tcl_WrongNumArgs(interp
, 1, objv
, "SQL");
5234 zSql
= (char*)Tcl_GetString(objv
[1]);
5235 zNorm
= sqlite3_normalize(zSql
);
5237 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zNorm
, -1));
5238 sqlite3_free(zNorm
);
5244 ** Usage: sqlite3_step STMT
5246 ** Advance the statement to the next row.
5248 static int SQLITE_TCLAPI
test_step(
5252 Tcl_Obj
*CONST objv
[]
5254 sqlite3_stmt
*pStmt
;
5258 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5259 Tcl_GetString(objv
[0]), " STMT", 0);
5263 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5264 rc
= sqlite3_step(pStmt
);
5266 /* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */
5267 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
5271 static int SQLITE_TCLAPI
test_sql(
5275 Tcl_Obj
*CONST objv
[]
5277 sqlite3_stmt
*pStmt
;
5280 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
5284 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5285 Tcl_SetResult(interp
, (char *)sqlite3_sql(pStmt
), TCL_VOLATILE
);
5288 static int SQLITE_TCLAPI
test_ex_sql(
5292 Tcl_Obj
*CONST objv
[]
5294 sqlite3_stmt
*pStmt
;
5298 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
5302 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5303 z
= sqlite3_expanded_sql(pStmt
);
5304 Tcl_SetResult(interp
, z
, TCL_VOLATILE
);
5308 #ifdef SQLITE_ENABLE_NORMALIZE
5309 static int SQLITE_TCLAPI
test_norm_sql(
5313 Tcl_Obj
*CONST objv
[]
5315 sqlite3_stmt
*pStmt
;
5318 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
5322 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5323 Tcl_SetResult(interp
, (char *)sqlite3_normalized_sql(pStmt
), TCL_VOLATILE
);
5326 #endif /* SQLITE_ENABLE_NORMALIZE */
5329 ** Usage: sqlite3_column_count STMT
5331 ** Return the number of columns returned by the sql statement STMT.
5333 static int SQLITE_TCLAPI
test_column_count(
5337 Tcl_Obj
*CONST objv
[]
5339 sqlite3_stmt
*pStmt
;
5342 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5343 Tcl_GetString(objv
[0]), " STMT column", 0);
5347 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5349 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_column_count(pStmt
)));
5354 ** Usage: sqlite3_column_type STMT column
5356 ** Return the type of the data in column 'column' of the current row.
5358 static int SQLITE_TCLAPI
test_column_type(
5362 Tcl_Obj
*CONST objv
[]
5364 sqlite3_stmt
*pStmt
;
5369 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5370 Tcl_GetString(objv
[0]), " STMT column", 0);
5374 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5375 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5377 tp
= sqlite3_column_type(pStmt
, col
);
5379 case SQLITE_INTEGER
:
5380 Tcl_SetResult(interp
, "INTEGER", TCL_STATIC
);
5383 Tcl_SetResult(interp
, "NULL", TCL_STATIC
);
5386 Tcl_SetResult(interp
, "FLOAT", TCL_STATIC
);
5389 Tcl_SetResult(interp
, "TEXT", TCL_STATIC
);
5392 Tcl_SetResult(interp
, "BLOB", TCL_STATIC
);
5402 ** Usage: sqlite3_column_int64 STMT column
5404 ** Return the data in column 'column' of the current row cast as an
5405 ** wide (64-bit) integer.
5407 static int SQLITE_TCLAPI
test_column_int64(
5411 Tcl_Obj
*CONST objv
[]
5413 sqlite3_stmt
*pStmt
;
5418 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5419 Tcl_GetString(objv
[0]), " STMT column", 0);
5423 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5424 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5426 iVal
= sqlite3_column_int64(pStmt
, col
);
5427 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(iVal
));
5432 ** Usage: sqlite3_column_blob STMT column
5434 static int SQLITE_TCLAPI
test_column_blob(
5438 Tcl_Obj
*CONST objv
[]
5440 sqlite3_stmt
*pStmt
;
5447 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5448 Tcl_GetString(objv
[0]), " STMT column", 0);
5452 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5453 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5455 len
= sqlite3_column_bytes(pStmt
, col
);
5456 pBlob
= sqlite3_column_blob(pStmt
, col
);
5457 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(pBlob
, len
));
5462 ** Usage: sqlite3_column_double STMT column
5464 ** Return the data in column 'column' of the current row cast as a double.
5466 static int SQLITE_TCLAPI
test_column_double(
5470 Tcl_Obj
*CONST objv
[]
5472 sqlite3_stmt
*pStmt
;
5477 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5478 Tcl_GetString(objv
[0]), " STMT column", 0);
5482 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5483 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5485 rVal
= sqlite3_column_double(pStmt
, col
);
5486 Tcl_SetObjResult(interp
, Tcl_NewDoubleObj(rVal
));
5491 ** Usage: sqlite3_data_count STMT
5493 ** Return the number of columns returned by the sql statement STMT.
5495 static int SQLITE_TCLAPI
test_data_count(
5499 Tcl_Obj
*CONST objv
[]
5501 sqlite3_stmt
*pStmt
;
5504 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5505 Tcl_GetString(objv
[0]), " STMT column", 0);
5509 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5511 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_data_count(pStmt
)));
5516 ** Usage: sqlite3_column_text STMT column
5518 ** Usage: sqlite3_column_decltype STMT column
5520 ** Usage: sqlite3_column_name STMT column
5522 static int SQLITE_TCLAPI
test_stmt_utf8(
5523 void * clientData
, /* Pointer to SQLite API function to be invoke */
5526 Tcl_Obj
*CONST objv
[]
5528 sqlite3_stmt
*pStmt
;
5530 const char *(*xFunc
)(sqlite3_stmt
*, int);
5533 xFunc
= (const char *(*)(sqlite3_stmt
*, int))clientData
;
5535 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5536 Tcl_GetString(objv
[0]), " STMT column", 0);
5540 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5541 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5542 zRet
= xFunc(pStmt
, col
);
5544 Tcl_SetResult(interp
, (char *)zRet
, 0);
5549 static int SQLITE_TCLAPI
test_global_recover(
5553 Tcl_Obj
*CONST objv
[]
5555 #ifndef SQLITE_OMIT_DEPRECATED
5558 Tcl_WrongNumArgs(interp
, 1, objv
, "");
5561 rc
= sqlite3_global_recover();
5562 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5568 ** Usage: sqlite3_column_text STMT column
5570 ** Usage: sqlite3_column_decltype STMT column
5572 ** Usage: sqlite3_column_name STMT column
5574 static int SQLITE_TCLAPI
test_stmt_utf16(
5575 void * clientData
, /* Pointer to SQLite API function to be invoked */
5578 Tcl_Obj
*CONST objv
[]
5580 #ifndef SQLITE_OMIT_UTF16
5581 sqlite3_stmt
*pStmt
;
5584 const void *zName16
;
5585 const void *(*xFunc
)(sqlite3_stmt
*, int);
5587 xFunc
= (const void *(*)(sqlite3_stmt
*, int))clientData
;
5589 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5590 Tcl_GetString(objv
[0]), " STMT column", 0);
5594 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5595 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5597 zName16
= xFunc(pStmt
, col
);
5600 const char *z
= zName16
;
5601 for(n
=0; z
[n
] || z
[n
+1]; n
+=2){}
5602 pRet
= Tcl_NewByteArrayObj(zName16
, n
+2);
5603 Tcl_SetObjResult(interp
, pRet
);
5605 #endif /* SQLITE_OMIT_UTF16 */
5611 ** Usage: sqlite3_column_int STMT column
5613 ** Usage: sqlite3_column_bytes STMT column
5615 ** Usage: sqlite3_column_bytes16 STMT column
5618 static int SQLITE_TCLAPI
test_stmt_int(
5619 void * clientData
, /* Pointer to SQLite API function to be invoked */
5622 Tcl_Obj
*CONST objv
[]
5624 sqlite3_stmt
*pStmt
;
5626 int (*xFunc
)(sqlite3_stmt
*, int);
5628 xFunc
= (int (*)(sqlite3_stmt
*, int))clientData
;
5630 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5631 Tcl_GetString(objv
[0]), " STMT column", 0);
5635 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5636 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5638 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xFunc(pStmt
, col
)));
5643 ** Usage: sqlite3_interrupt DB
5645 ** Trigger an interrupt on DB
5647 static int SQLITE_TCLAPI
test_interrupt(
5655 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB", 0);
5658 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5659 sqlite3_interrupt(db
);
5664 ** Usage: sqlite3_is_interrupted DB
5666 ** return true if an interrupt is current in effect on DB
5668 static int SQLITE_TCLAPI
test_is_interrupted(
5677 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB", 0);
5680 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5681 rc
= sqlite3_is_interrupted(db
);
5682 Tcl_AppendResult(interp
, rc
? "1" : "0", (void*)0);
5687 ** Usage: sqlite_delete_function DB function-name
5689 ** Delete the user function 'function-name' from database handle DB. It
5690 ** is assumed that the user function was created as UTF8, any number of
5691 ** arguments (the way the TCL interface does it).
5693 static int SQLITE_TCLAPI
delete_function(
5702 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5703 " DB function-name", 0);
5706 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5707 rc
= sqlite3_create_function(db
, argv
[2], -1, SQLITE_UTF8
, 0, 0, 0, 0);
5708 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5713 ** Usage: sqlite_delete_collation DB collation-name
5715 ** Delete the collation sequence 'collation-name' from database handle
5716 ** DB. It is assumed that the collation sequence was created as UTF8 (the
5717 ** way the TCL interface does it).
5719 static int SQLITE_TCLAPI
delete_collation(
5728 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5729 " DB function-name", 0);
5732 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5733 rc
= sqlite3_create_collation(db
, argv
[2], SQLITE_UTF8
, 0, 0);
5734 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5739 ** Usage: sqlite3_get_autocommit DB
5741 ** Return true if the database DB is currently in auto-commit mode.
5742 ** Return false if not.
5744 static int SQLITE_TCLAPI
get_autocommit(
5753 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5757 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5758 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", sqlite3_get_autocommit(db
));
5759 Tcl_AppendResult(interp
, zBuf
, 0);
5764 ** Usage: sqlite3_busy_timeout DB MS
5766 ** Set the busy timeout. This is more easily done using the timeout
5767 ** method of the TCL interface. But we need a way to test the case
5768 ** where it returns SQLITE_MISUSE.
5770 static int SQLITE_TCLAPI
test_busy_timeout(
5779 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5783 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5784 if( Tcl_GetInt(interp
, argv
[2], &ms
) ) return TCL_ERROR
;
5785 rc
= sqlite3_busy_timeout(db
, ms
);
5786 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
5791 ** Usage: tcl_variable_type VARIABLENAME
5793 ** Return the name of the internal representation for the
5794 ** value of the given variable.
5796 static int SQLITE_TCLAPI
tcl_variable_type(
5800 Tcl_Obj
*CONST objv
[]
5804 Tcl_WrongNumArgs(interp
, 1, objv
, "VARIABLE");
5807 pVar
= Tcl_GetVar2Ex(interp
, Tcl_GetString(objv
[1]), 0, TCL_LEAVE_ERR_MSG
);
5808 if( pVar
==0 ) return TCL_ERROR
;
5809 if( pVar
->typePtr
){
5810 Tcl_SetObjResult(interp
, Tcl_NewStringObj(pVar
->typePtr
->name
, -1));
5816 ** Usage: sqlite3_release_memory ?N?
5818 ** Attempt to release memory currently held but not actually required.
5819 ** The integer N is the number of bytes we are trying to release. The
5820 ** return value is the amount of memory actually released.
5822 static int SQLITE_TCLAPI
test_release_memory(
5826 Tcl_Obj
*CONST objv
[]
5828 #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
5831 if( objc
!=1 && objc
!=2 ){
5832 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5836 if( Tcl_GetIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5840 amt
= sqlite3_release_memory(N
);
5841 Tcl_SetObjResult(interp
, Tcl_NewIntObj(amt
));
5848 ** Usage: sqlite3_db_release_memory DB
5850 ** Attempt to release memory currently held by database DB. Return the
5851 ** result code (which in the current implementation is always zero).
5853 static int SQLITE_TCLAPI
test_db_release_memory(
5857 Tcl_Obj
*CONST objv
[]
5862 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5865 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5866 rc
= sqlite3_db_release_memory(db
);
5867 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5872 ** Usage: sqlite3_db_cacheflush DB
5874 ** Attempt to flush any dirty pages to disk.
5876 static int SQLITE_TCLAPI
test_db_cacheflush(
5880 Tcl_Obj
*CONST objv
[]
5885 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5888 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5889 rc
= sqlite3_db_cacheflush(db
);
5891 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(rc
), TCL_STATIC
);
5895 Tcl_ResetResult(interp
);
5900 ** Usage: sqlite3_system_errno DB
5902 ** Return the low-level system errno value.
5904 static int SQLITE_TCLAPI
test_system_errno(
5908 Tcl_Obj
*CONST objv
[]
5913 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5916 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5917 iErrno
= sqlite3_system_errno(db
);
5918 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iErrno
));
5923 ** Usage: sqlite3_db_filename DB DBNAME
5925 ** Return the name of a file associated with a database.
5927 static int SQLITE_TCLAPI
test_db_filename(
5931 Tcl_Obj
*CONST objv
[]
5934 const char *zDbName
;
5936 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
5939 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5940 zDbName
= Tcl_GetString(objv
[2]);
5941 Tcl_AppendResult(interp
, sqlite3_db_filename(db
, zDbName
), (void*)0);
5946 ** Usage: sqlite3_db_readonly DB DBNAME
5948 ** Return 1 or 0 if DBNAME is readonly or not. Return -1 if DBNAME does
5951 static int SQLITE_TCLAPI
test_db_readonly(
5955 Tcl_Obj
*CONST objv
[]
5958 const char *zDbName
;
5960 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
5963 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5964 zDbName
= Tcl_GetString(objv
[2]);
5965 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_db_readonly(db
, zDbName
)));
5970 ** Usage: sqlite3_soft_heap_limit ?N?
5972 ** Query or set the soft heap limit for the current thread. The
5973 ** limit is only changed if the N is present. The previous limit
5976 static int SQLITE_TCLAPI
test_soft_heap_limit(
5980 Tcl_Obj
*CONST objv
[]
5984 if( objc
!=1 && objc
!=2 ){
5985 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5989 if( Tcl_GetWideIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5991 amt
= sqlite3_soft_heap_limit64(N
);
5992 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(amt
));
5997 ** Usage: sqlite3_hard_heap_limit ?N?
5999 ** Query or set the hard heap limit for the current thread. The
6000 ** limit is only changed if the N is present. The previous limit
6003 static int SQLITE_TCLAPI
test_hard_heap_limit(
6007 Tcl_Obj
*CONST objv
[]
6011 if( objc
!=1 && objc
!=2 ){
6012 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
6016 if( Tcl_GetWideIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
6018 amt
= sqlite3_hard_heap_limit64(N
);
6019 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(amt
));
6024 ** Usage: sqlite3_thread_cleanup
6026 ** Call the sqlite3_thread_cleanup API.
6028 static int SQLITE_TCLAPI
test_thread_cleanup(
6032 Tcl_Obj
*CONST objv
[]
6034 #ifndef SQLITE_OMIT_DEPRECATED
6035 sqlite3_thread_cleanup();
6041 ** Usage: sqlite3_pager_refcounts DB
6043 ** Return a list of numbers which are the PagerRefcount for all
6044 ** pagers on each database connection.
6046 static int SQLITE_TCLAPI
test_pager_refcounts(
6050 Tcl_Obj
*CONST objv
[]
6058 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6059 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6062 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6063 pResult
= Tcl_NewObj();
6064 for(i
=0; i
<db
->nDb
; i
++){
6065 if( db
->aDb
[i
].pBt
==0 ){
6068 sqlite3_mutex_enter(db
->mutex
);
6069 a
= sqlite3PagerStats(sqlite3BtreePager(db
->aDb
[i
].pBt
));
6071 sqlite3_mutex_leave(db
->mutex
);
6073 Tcl_ListObjAppendElement(0, pResult
, Tcl_NewIntObj(v
));
6075 Tcl_SetObjResult(interp
, pResult
);
6081 ** tclcmd: working_64bit_int
6083 ** Some TCL builds (ex: cygwin) do not support 64-bit integers. This
6084 ** leads to a number of test failures. The present command checks the
6085 ** TCL build to see whether or not it supports 64-bit integers. It
6086 ** returns TRUE if it does and FALSE if not.
6088 ** This command is used to warn users that their TCL build is defective
6089 ** and that the errors they are seeing in the test scripts might be
6090 ** a result of their defective TCL rather than problems in SQLite.
6092 static int SQLITE_TCLAPI
working_64bit_int(
6093 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6094 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6095 int objc
, /* Number of arguments */
6096 Tcl_Obj
*CONST objv
[] /* Command arguments */
6101 pTestObj
= Tcl_NewWideIntObj(1000000*(i64
)1234567890);
6102 working
= strcmp(Tcl_GetString(pTestObj
), "1234567890000000")==0;
6103 Tcl_DecrRefCount(pTestObj
);
6104 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(working
));
6110 ** tclcmd: vfs_unlink_test
6112 ** This TCL command unregisters the primary VFS and then registers
6113 ** it back again. This is used to test the ability to register a
6114 ** VFS when none are previously registered, and the ability to
6115 ** unregister the only available VFS. Ticket #2738
6117 static int SQLITE_TCLAPI
vfs_unlink_test(
6118 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6119 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6120 int objc
, /* Number of arguments */
6121 Tcl_Obj
*CONST objv
[] /* Command arguments */
6125 sqlite3_vfs
*apVfs
[20];
6126 sqlite3_vfs one
, two
;
6128 sqlite3_vfs_unregister(0); /* Unregister of NULL is harmless */
6129 one
.zName
= "__one";
6130 two
.zName
= "__two";
6132 /* Calling sqlite3_vfs_register with 2nd argument of 0 does not
6133 ** change the default VFS
6135 pMain
= sqlite3_vfs_find(0);
6136 sqlite3_vfs_register(&one
, 0);
6137 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
6138 sqlite3_vfs_register(&two
, 0);
6139 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
6141 /* We can find a VFS by its name */
6142 assert( sqlite3_vfs_find("__one")==&one
);
6143 assert( sqlite3_vfs_find("__two")==&two
);
6145 /* Calling sqlite_vfs_register with non-zero second parameter changes the
6146 ** default VFS, even if the 1st parameter is an existig VFS that is
6147 ** previously registered as the non-default.
6149 sqlite3_vfs_register(&one
, 1);
6150 assert( sqlite3_vfs_find("__one")==&one
);
6151 assert( sqlite3_vfs_find("__two")==&two
);
6152 assert( sqlite3_vfs_find(0)==&one
);
6153 sqlite3_vfs_register(&two
, 1);
6154 assert( sqlite3_vfs_find("__one")==&one
);
6155 assert( sqlite3_vfs_find("__two")==&two
);
6156 assert( sqlite3_vfs_find(0)==&two
);
6158 sqlite3_vfs_register(pMain
, 1);
6159 assert( sqlite3_vfs_find("__one")==&one
);
6160 assert( sqlite3_vfs_find("__two")==&two
);
6161 assert( sqlite3_vfs_find(0)==pMain
);
6164 /* Unlink the default VFS. Repeat until there are no more VFSes
6167 for(i
=0; i
<sizeof(apVfs
)/sizeof(apVfs
[0]); i
++){
6168 apVfs
[i
] = sqlite3_vfs_find(0);
6170 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
6171 sqlite3_vfs_unregister(apVfs
[i
]);
6172 assert( 0==sqlite3_vfs_find(apVfs
[i
]->zName
) );
6175 assert( 0==sqlite3_vfs_find(0) );
6177 /* Register the main VFS as non-default (will be made default, since
6178 ** it'll be the only one in existence).
6180 sqlite3_vfs_register(pMain
, 0);
6181 assert( sqlite3_vfs_find(0)==pMain
);
6183 /* Un-register the main VFS again to restore an empty VFS list */
6184 sqlite3_vfs_unregister(pMain
);
6185 assert( 0==sqlite3_vfs_find(0) );
6187 /* Relink all VFSes in reverse order. */
6188 for(i
=sizeof(apVfs
)/sizeof(apVfs
[0])-1; i
>=0; i
--){
6190 sqlite3_vfs_register(apVfs
[i
], 1);
6191 assert( apVfs
[i
]==sqlite3_vfs_find(0) );
6192 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
6196 /* Unregister out sample VFSes. */
6197 sqlite3_vfs_unregister(&one
);
6198 sqlite3_vfs_unregister(&two
);
6200 /* Unregistering a VFS that is not currently registered is harmless */
6201 sqlite3_vfs_unregister(&one
);
6202 sqlite3_vfs_unregister(&two
);
6203 assert( sqlite3_vfs_find("__one")==0 );
6204 assert( sqlite3_vfs_find("__two")==0 );
6206 /* We should be left with the original default VFS back as the
6208 assert( sqlite3_vfs_find(0)==pMain
);
6214 ** tclcmd: vfs_initfail_test
6216 ** This TCL command attempts to vfs_find and vfs_register when the
6217 ** sqlite3_initialize() interface is failing. All calls should fail.
6219 static int SQLITE_TCLAPI
vfs_initfail_test(
6220 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6221 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6222 int objc
, /* Number of arguments */
6223 Tcl_Obj
*CONST objv
[] /* Command arguments */
6226 one
.zName
= "__one";
6228 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
6229 sqlite3_vfs_register(&one
, 0);
6230 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
6231 sqlite3_vfs_register(&one
, 1);
6232 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
6239 static sqlite3_vfs
*apVfs
[20];
6240 static int nVfs
= 0;
6243 ** tclcmd: vfs_unregister_all
6245 ** Unregister all VFSes.
6247 static int SQLITE_TCLAPI
vfs_unregister_all(
6248 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6249 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6250 int objc
, /* Number of arguments */
6251 Tcl_Obj
*CONST objv
[] /* Command arguments */
6254 for(i
=0; i
<ArraySize(apVfs
); i
++){
6255 apVfs
[i
] = sqlite3_vfs_find(0);
6256 if( apVfs
[i
]==0 ) break;
6257 sqlite3_vfs_unregister(apVfs
[i
]);
6263 ** tclcmd: vfs_reregister_all
6265 ** Restore all VFSes that were removed using vfs_unregister_all. Taking
6266 ** care to put the linked list back together in the same order as it was
6267 ** in before vfs_unregister_all was invoked.
6269 static int SQLITE_TCLAPI
vfs_reregister_all(
6270 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6271 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6272 int objc
, /* Number of arguments */
6273 Tcl_Obj
*CONST objv
[] /* Command arguments */
6276 for(i
=nVfs
-1; i
>=0; i
--){
6277 sqlite3_vfs_register(apVfs
[i
], 1);
6284 ** tclcmd: file_control_test DB
6286 ** This TCL command runs the sqlite3_file_control interface and
6287 ** verifies correct operation of the same.
6289 static int SQLITE_TCLAPI
file_control_test(
6290 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6291 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6292 int objc
, /* Number of arguments */
6293 Tcl_Obj
*CONST objv
[] /* Command arguments */
6300 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6301 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6304 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6305 rc
= sqlite3_file_control(db
, 0, 0, &iArg
);
6306 assert( rc
==SQLITE_NOTFOUND
);
6307 rc
= sqlite3_file_control(db
, "notadatabase", SQLITE_FCNTL_LOCKSTATE
, &iArg
);
6308 assert( rc
==SQLITE_ERROR
);
6309 rc
= sqlite3_file_control(db
, "main", -1, &iArg
);
6310 assert( rc
==SQLITE_NOTFOUND
);
6311 rc
= sqlite3_file_control(db
, "temp", -1, &iArg
);
6312 assert( rc
==SQLITE_NOTFOUND
|| rc
==SQLITE_ERROR
);
6319 ** tclcmd: file_control_lasterrno_test DB
6321 ** This TCL command runs the sqlite3_file_control interface and
6322 ** verifies correct operation of the SQLITE_LAST_ERRNO verb.
6324 static int SQLITE_TCLAPI
file_control_lasterrno_test(
6325 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6326 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6327 int objc
, /* Number of arguments */
6328 Tcl_Obj
*CONST objv
[] /* Command arguments */
6335 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6336 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6339 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6342 rc
= sqlite3_file_control(db
, NULL
, SQLITE_LAST_ERRNO
, &iArg
);
6344 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6348 Tcl_AppendResult(interp
, "Unexpected non-zero errno: ",
6349 Tcl_GetStringFromObj(Tcl_NewIntObj(iArg
), 0), " ", 0);
6356 ** tclcmd: file_control_data_version DB DBNAME
6358 ** This TCL command runs the sqlite3_file_control with the
6359 ** SQLITE_FCNTL_DATA_VERSION opcode, returning the result.
6361 static int SQLITE_TCLAPI
file_control_data_version(
6362 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6363 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6364 int objc
, /* Number of arguments */
6365 Tcl_Obj
*CONST objv
[] /* Command arguments */
6367 unsigned int iVers
; /* data version */
6368 char *zDb
; /* Db name ("main", "temp" etc.) */
6369 sqlite3
*db
; /* Database handle */
6370 int rc
; /* file_control() return code */
6373 if( objc
!=3 && objc
!=2 ){
6374 Tcl_WrongNumArgs(interp
, 1, objv
, "DB [DBNAME]");
6377 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6380 zDb
= objc
==3 ? Tcl_GetString(objv
[2]) : NULL
;
6382 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_DATA_VERSION
, (void *)&iVers
);
6384 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
6387 sqlite3_snprintf(sizeof(zBuf
),zBuf
,"%u",iVers
);
6388 Tcl_SetResult(interp
, (char *)zBuf
, TCL_VOLATILE
);
6394 ** tclcmd: file_control_chunksize_test DB DBNAME SIZE
6396 ** This TCL command runs the sqlite3_file_control interface and
6397 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
6398 ** SQLITE_SET_LOCKPROXYFILE verbs.
6400 static int SQLITE_TCLAPI
file_control_chunksize_test(
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 */
6406 int nSize
; /* New chunk size */
6407 char *zDb
; /* Db name ("main", "temp" etc.) */
6408 sqlite3
*db
; /* Database handle */
6409 int rc
; /* file_control() return code */
6412 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
6415 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6416 || Tcl_GetIntFromObj(interp
, objv
[3], &nSize
)
6420 zDb
= Tcl_GetString(objv
[2]);
6421 if( zDb
[0]=='\0' ) zDb
= NULL
;
6423 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_CHUNK_SIZE
, (void *)&nSize
);
6425 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
6432 ** tclcmd: file_control_sizehint_test DB DBNAME SIZE
6434 ** This TCL command runs the sqlite3_file_control interface
6435 ** with SQLITE_FCNTL_SIZE_HINT
6437 static int SQLITE_TCLAPI
file_control_sizehint_test(
6438 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6439 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6440 int objc
, /* Number of arguments */
6441 Tcl_Obj
*CONST objv
[] /* Command arguments */
6443 Tcl_WideInt nSize
; /* Hinted size */
6444 char *zDb
; /* Db name ("main", "temp" etc.) */
6445 sqlite3
*db
; /* Database handle */
6446 int rc
; /* file_control() return code */
6449 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
6452 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6453 || Tcl_GetWideIntFromObj(interp
, objv
[3], &nSize
)
6457 zDb
= Tcl_GetString(objv
[2]);
6458 if( zDb
[0]=='\0' ) zDb
= NULL
;
6460 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_SIZE_HINT
, (void *)&nSize
);
6462 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
6469 ** tclcmd: file_control_lockproxy_test DB PWD
6471 ** This TCL command runs the sqlite3_file_control interface and
6472 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
6473 ** SQLITE_SET_LOCKPROXYFILE verbs.
6475 static int SQLITE_TCLAPI
file_control_lockproxy_test(
6476 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6477 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6478 int objc
, /* Number of arguments */
6479 Tcl_Obj
*CONST objv
[] /* Command arguments */
6484 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6485 Tcl_GetStringFromObj(objv
[0], 0), " DB PWD", 0);
6488 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6492 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
6493 # if defined(__APPLE__)
6494 # define SQLITE_ENABLE_LOCKING_STYLE 1
6496 # define SQLITE_ENABLE_LOCKING_STYLE 0
6499 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
6505 char proxyPath
[400];
6507 zPwd
= Tcl_GetStringFromObj(objv
[2], &nPwd
);
6508 if( sizeof(proxyPath
)<nPwd
+20 ){
6509 Tcl_AppendResult(interp
, "PWD too big", (void*)0);
6512 sqlite3_snprintf(sizeof(proxyPath
), proxyPath
, "%s/test.proxy", zPwd
);
6513 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
6515 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6518 rc
= sqlite3_file_control(db
, NULL
, SQLITE_GET_LOCKPROXYFILE
, &testPath
);
6519 if( strncmp(proxyPath
,testPath
,11) ){
6520 Tcl_AppendResult(interp
, "Lock proxy file did not match the "
6521 "previously assigned value", 0);
6525 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6528 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
6530 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6540 ** tclcmd: file_control_win32_av_retry DB NRETRY DELAY
6542 ** This TCL command runs the sqlite3_file_control interface with
6543 ** the SQLITE_FCNTL_WIN32_AV_RETRY opcode.
6545 static int SQLITE_TCLAPI
file_control_win32_av_retry(
6546 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6547 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6548 int objc
, /* Number of arguments */
6549 Tcl_Obj
*CONST objv
[] /* Command arguments */
6557 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6558 Tcl_GetStringFromObj(objv
[0], 0), " DB NRETRY DELAY", 0);
6561 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6564 if( Tcl_GetIntFromObj(interp
, objv
[2], &a
[0]) ) return TCL_ERROR
;
6565 if( Tcl_GetIntFromObj(interp
, objv
[3], &a
[1]) ) return TCL_ERROR
;
6566 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_AV_RETRY
, (void*)a
);
6567 sqlite3_snprintf(sizeof(z
), z
, "%d %d %d", rc
, a
[0], a
[1]);
6568 Tcl_AppendResult(interp
, z
, (char*)0);
6573 ** tclcmd: file_control_win32_get_handle DB
6575 ** This TCL command runs the sqlite3_file_control interface with
6576 ** the SQLITE_FCNTL_WIN32_GET_HANDLE opcode.
6578 static int file_control_win32_get_handle(
6579 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6580 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6581 int objc
, /* Number of arguments */
6582 Tcl_Obj
*CONST objv
[] /* Command arguments */
6586 HANDLE hFile
= NULL
;
6590 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6591 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6594 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6597 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_GET_HANDLE
,
6599 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
6600 Tcl_AppendResult(interp
, z
, (char*)0);
6605 ** tclcmd: file_control_win32_set_handle DB HANDLE
6607 ** This TCL command runs the sqlite3_file_control interface with
6608 ** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode.
6610 static int SQLITE_TCLAPI
file_control_win32_set_handle(
6611 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6612 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6613 int objc
, /* Number of arguments */
6614 Tcl_Obj
*CONST objv
[] /* Command arguments */
6618 HANDLE hFile
= NULL
;
6622 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6623 Tcl_GetStringFromObj(objv
[0], 0), " DB HANDLE", 0);
6626 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6629 if( getWin32Handle(interp
, Tcl_GetString(objv
[2]), &hFile
) ){
6632 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_SET_HANDLE
,
6634 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
6635 Tcl_AppendResult(interp
, z
, (char*)0);
6641 ** tclcmd: file_control_persist_wal DB PERSIST-FLAG
6643 ** This TCL command runs the sqlite3_file_control interface with
6644 ** the SQLITE_FCNTL_PERSIST_WAL opcode.
6646 static int SQLITE_TCLAPI
file_control_persist_wal(
6647 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6648 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6649 int objc
, /* Number of arguments */
6650 Tcl_Obj
*CONST objv
[] /* Command arguments */
6658 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6659 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
6662 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6665 if( Tcl_GetIntFromObj(interp
, objv
[2], &bPersist
) ) return TCL_ERROR
;
6666 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_PERSIST_WAL
, (void*)&bPersist
);
6667 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, bPersist
);
6668 Tcl_AppendResult(interp
, z
, (char*)0);
6673 ** tclcmd: file_control_powersafe_overwrite DB PSOW-FLAG
6675 ** This TCL command runs the sqlite3_file_control interface with
6676 ** the SQLITE_FCNTL_POWERSAFE_OVERWRITE opcode.
6678 static int SQLITE_TCLAPI
file_control_powersafe_overwrite(
6679 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6680 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6681 int objc
, /* Number of arguments */
6682 Tcl_Obj
*CONST objv
[] /* Command arguments */
6690 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6691 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
6694 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6697 if( Tcl_GetIntFromObj(interp
, objv
[2], &b
) ) return TCL_ERROR
;
6698 rc
= sqlite3_file_control(db
,NULL
,SQLITE_FCNTL_POWERSAFE_OVERWRITE
,(void*)&b
);
6699 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, b
);
6700 Tcl_AppendResult(interp
, z
, (char*)0);
6706 ** tclcmd: file_control_vfsname DB ?AUXDB?
6708 ** Return a string that describes the stack of VFSes.
6710 static int SQLITE_TCLAPI
file_control_vfsname(
6711 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6712 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6713 int objc
, /* Number of arguments */
6714 Tcl_Obj
*CONST objv
[] /* Command arguments */
6717 const char *zDbName
= "main";
6720 if( objc
!=2 && objc
!=3 ){
6721 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6722 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6725 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6729 zDbName
= Tcl_GetString(objv
[2]);
6731 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_VFSNAME
,(void*)&zVfsName
);
6732 Tcl_AppendResult(interp
, zVfsName
, (char*)0);
6733 sqlite3_free(zVfsName
);
6738 ** tclcmd: file_control_reservebytes DB N
6740 static int SQLITE_TCLAPI
file_control_reservebytes(
6741 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6742 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6743 int objc
, /* Number of arguments */
6744 Tcl_Obj
*CONST objv
[] /* Command arguments */
6747 const char *zDbName
= "main";
6752 Tcl_WrongNumArgs(interp
, 1, objv
, "DB N");
6755 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6756 || Tcl_GetIntFromObj(interp
, objv
[2], &n
)
6761 rc
= sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_RESERVE_BYTES
, (void*)&n
);
6762 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
6768 ** tclcmd: file_control_tempfilename DB ?AUXDB?
6770 ** Return a string that is a temporary filename
6772 static int SQLITE_TCLAPI
file_control_tempfilename(
6773 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6774 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6775 int objc
, /* Number of arguments */
6776 Tcl_Obj
*CONST objv
[] /* Command arguments */
6779 const char *zDbName
= "main";
6782 if( objc
!=2 && objc
!=3 ){
6783 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6784 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6787 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6791 zDbName
= Tcl_GetString(objv
[2]);
6793 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_TEMPFILENAME
, (void*)&zTName
);
6794 Tcl_AppendResult(interp
, zTName
, (char*)0);
6795 sqlite3_free(zTName
);
6800 ** tclcmd: file_control_external_reader DB ?AUXDB?
6802 ** Return a string that is a temporary filename
6804 static int SQLITE_TCLAPI
file_control_external_reader(
6805 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6806 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6807 int objc
, /* Number of arguments */
6808 Tcl_Obj
*CONST objv
[] /* Command arguments */
6811 const char *zName
= "main";
6815 if( objc
!=2 && objc
!=3 ){
6816 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6817 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6820 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6824 zName
= Tcl_GetString(objv
[2]);
6826 rc
= sqlite3_file_control(db
, zName
, SQLITE_FCNTL_EXTERNAL_READER
, &iRes
);
6827 if( rc
!=SQLITE_OK
){
6828 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
6831 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iRes
));
6837 ** tclcmd: sqlite3_vfs_list
6839 ** Return a tcl list containing the names of all registered vfs's.
6841 static int SQLITE_TCLAPI
vfs_list(
6842 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6843 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6844 int objc
, /* Number of arguments */
6845 Tcl_Obj
*CONST objv
[] /* Command arguments */
6848 Tcl_Obj
*pRet
= Tcl_NewObj();
6850 Tcl_WrongNumArgs(interp
, 1, objv
, "");
6853 for(pVfs
=sqlite3_vfs_find(0); pVfs
; pVfs
=pVfs
->pNext
){
6854 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj(pVfs
->zName
, -1));
6856 Tcl_SetObjResult(interp
, pRet
);
6861 ** tclcmd: sqlite3_limit DB ID VALUE
6863 ** This TCL command runs the sqlite3_limit interface and
6864 ** verifies correct operation of the same.
6866 static int SQLITE_TCLAPI
test_limit(
6867 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6868 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6869 int objc
, /* Number of arguments */
6870 Tcl_Obj
*CONST objv
[] /* Command arguments */
6874 static const struct {
6878 { "SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH
},
6879 { "SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH
},
6880 { "SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN
},
6881 { "SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH
},
6882 { "SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT
},
6883 { "SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP
},
6884 { "SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG
},
6885 { "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED
},
6886 { "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH
},
6887 { "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER
},
6888 { "SQLITE_LIMIT_TRIGGER_DEPTH", SQLITE_LIMIT_TRIGGER_DEPTH
},
6889 { "SQLITE_LIMIT_WORKER_THREADS", SQLITE_LIMIT_WORKER_THREADS
},
6891 /* Out of range test cases */
6892 { "SQLITE_LIMIT_TOOSMALL", -1, },
6893 { "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_WORKER_THREADS
+1 },
6900 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6901 Tcl_GetStringFromObj(objv
[0], 0), " DB ID VALUE", 0);
6904 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6905 zId
= Tcl_GetString(objv
[2]);
6906 for(i
=0; i
<sizeof(aId
)/sizeof(aId
[0]); i
++){
6907 if( strcmp(zId
, aId
[i
].zName
)==0 ){
6912 if( i
>=sizeof(aId
)/sizeof(aId
[0]) ){
6913 Tcl_AppendResult(interp
, "unknown limit type: ", zId
, (char*)0);
6916 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
6917 rc
= sqlite3_limit(db
, id
, val
);
6918 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6923 ** tclcmd: save_prng_state
6925 ** Save the state of the pseudo-random number generator.
6926 ** At the same time, verify that sqlite3_test_control works even when
6927 ** called with an out-of-range opcode.
6929 static int SQLITE_TCLAPI
save_prng_state(
6930 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6931 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6932 int objc
, /* Number of arguments */
6933 Tcl_Obj
*CONST objv
[] /* Command arguments */
6935 int rc
= sqlite3_test_control(9999);
6937 rc
= sqlite3_test_control(-1);
6939 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SAVE
);
6943 ** tclcmd: restore_prng_state
6945 static int SQLITE_TCLAPI
restore_prng_state(
6946 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6947 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6948 int objc
, /* Number of arguments */
6949 Tcl_Obj
*CONST objv
[] /* Command arguments */
6951 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESTORE
);
6955 ** tclcmd: reset_prng_state
6957 static int SQLITE_TCLAPI
reset_prng_state(
6958 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6959 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6960 int objc
, /* Number of arguments */
6961 Tcl_Obj
*CONST objv
[] /* Command arguments */
6963 sqlite3_randomness(0,0);
6967 ** tclcmd: prng_seed INT ?DB?
6969 ** Set up the SQLITE_TESTCTRL_PRNG_SEED pragma with parameter INT and DB.
6970 ** INT is an integer. DB is a database connection, or a NULL pointer if
6973 ** When INT!=0 and DB!=0, set the PRNG seed to the value of the schema
6974 ** cookie for DB, or to INT if the schema cookie happens to be zero.
6976 ** When INT!=0 and DB==0, set the PRNG seed to just INT.
6978 ** If INT==0 and DB==0 then use the default procedure of calling the
6979 ** xRandomness method on the default VFS to get the PRNG seed.
6981 static int SQLITE_TCLAPI
prng_seed(
6982 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6983 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6984 int objc
, /* Number of arguments */
6985 Tcl_Obj
*CONST objv
[] /* Command arguments */
6989 if( objc
!=2 && objc
!=3 ){
6990 Tcl_WrongNumArgs(interp
, 1, objv
, "SEED ?DB?");
6993 if( Tcl_GetIntFromObj(interp
,objv
[1],&i
) ) return TCL_ERROR
;
6994 if( objc
==3 && getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ){
6997 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED
, i
, db
);
7002 ** tclcmd: extra_schema_checks BOOLEAN
7004 ** Enable or disable schema checks when parsing the sqlite_schema file.
7005 ** This is always enabled in production, but it is sometimes useful to
7006 ** disable the checks in order to make some internal error states reachable
7009 static int SQLITE_TCLAPI
extra_schema_checks(
7010 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7011 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7012 int objc
, /* Number of arguments */
7013 Tcl_Obj
*CONST objv
[] /* Command arguments */
7017 Tcl_WrongNumArgs(interp
, 1, objv
, "BOOLEAN");
7020 if( Tcl_GetBooleanFromObj(interp
,objv
[1],&i
) ) return TCL_ERROR
;
7021 sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS
, i
);
7026 ** tclcmd: database_may_be_corrupt
7028 ** Indicate that database files might be corrupt. In other words, set the normal
7029 ** state of operation.
7031 static int SQLITE_TCLAPI
database_may_be_corrupt(
7032 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7033 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7034 int objc
, /* Number of arguments */
7035 Tcl_Obj
*CONST objv
[] /* Command arguments */
7037 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 0);
7041 ** tclcmd: database_never_corrupt
7043 ** Indicate that database files are always well-formed. This enables
7044 ** extra assert() statements that test conditions that are always true
7045 ** for well-formed databases.
7047 static int SQLITE_TCLAPI
database_never_corrupt(
7048 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7049 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7050 int objc
, /* Number of arguments */
7051 Tcl_Obj
*CONST objv
[] /* Command arguments */
7053 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 1);
7058 ** tclcmd: pcache_stats
7060 static int SQLITE_TCLAPI
test_pcache_stats(
7061 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7062 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7063 int objc
, /* Number of arguments */
7064 Tcl_Obj
*CONST objv
[] /* Command arguments */
7072 sqlite3PcacheStats(&nCurrent
, &nMax
, &nMin
, &nRecyclable
);
7074 pRet
= Tcl_NewObj();
7075 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("current", -1));
7076 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCurrent
));
7077 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("max", -1));
7078 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMax
));
7079 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("min", -1));
7080 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMin
));
7081 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("recyclable", -1));
7082 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nRecyclable
));
7084 Tcl_SetObjResult(interp
, pRet
);
7089 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
7090 static void test_unlock_notify_cb(void **aArg
, int nArg
){
7092 for(ii
=0; ii
<nArg
; ii
++){
7093 Tcl_EvalEx((Tcl_Interp
*)aArg
[ii
], "unlock_notify", -1, TCL_EVAL_GLOBAL
);
7096 #endif /* SQLITE_ENABLE_UNLOCK_NOTIFY */
7099 ** tclcmd: sqlite3_unlock_notify db
7101 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
7102 static int SQLITE_TCLAPI
test_unlock_notify(
7103 ClientData clientData
, /* Unused */
7104 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7105 int objc
, /* Number of arguments */
7106 Tcl_Obj
*CONST objv
[] /* Command arguments */
7112 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
7116 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7119 rc
= sqlite3_unlock_notify(db
, test_unlock_notify_cb
, (void *)interp
);
7120 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7126 ** tclcmd: sqlite3_wal_checkpoint db ?NAME?
7128 static int SQLITE_TCLAPI
test_wal_checkpoint(
7129 ClientData clientData
, /* Unused */
7130 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7131 int objc
, /* Number of arguments */
7132 Tcl_Obj
*CONST objv
[] /* Command arguments */
7138 if( objc
!=3 && objc
!=2 ){
7139 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?NAME?");
7143 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7147 zDb
= Tcl_GetString(objv
[2]);
7149 rc
= sqlite3_wal_checkpoint(db
, zDb
);
7150 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7155 ** tclcmd: sqlite3_wal_checkpoint_v2 db MODE ?NAME?
7157 ** This command calls the wal_checkpoint_v2() function with the specified
7158 ** mode argument (passive, full or restart). If present, the database name
7159 ** NAME is passed as the second argument to wal_checkpoint_v2(). If it the
7160 ** NAME argument is not present, a NULL pointer is passed instead.
7162 ** If wal_checkpoint_v2() returns any value other than SQLITE_BUSY or
7163 ** SQLITE_OK, then this command returns TCL_ERROR. The Tcl result is set
7164 ** to the error message obtained from sqlite3_errmsg().
7166 ** Otherwise, this command returns a list of three integers. The first integer
7167 ** is 1 if SQLITE_BUSY was returned, or 0 otherwise. The following two integers
7168 ** are the values returned via the output parameters by wal_checkpoint_v2() -
7169 ** the number of frames in the log and the number of frames in the log
7170 ** that have been checkpointed.
7172 static int SQLITE_TCLAPI
test_wal_checkpoint_v2(
7173 ClientData clientData
, /* Unused */
7174 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7175 int objc
, /* Number of arguments */
7176 Tcl_Obj
*CONST objv
[] /* Command arguments */
7187 const char * aMode
[] = { "passive", "full", "restart", "truncate", 0 };
7188 assert( SQLITE_CHECKPOINT_PASSIVE
==0 );
7189 assert( SQLITE_CHECKPOINT_FULL
==1 );
7190 assert( SQLITE_CHECKPOINT_RESTART
==2 );
7191 assert( SQLITE_CHECKPOINT_TRUNCATE
==3 );
7193 if( objc
!=3 && objc
!=4 ){
7194 Tcl_WrongNumArgs(interp
, 1, objv
, "DB MODE ?NAME?");
7199 zDb
= Tcl_GetString(objv
[3]);
7201 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) || (
7202 TCL_OK
!=Tcl_GetIntFromObj(0, objv
[2], &eMode
)
7203 && TCL_OK
!=Tcl_GetIndexFromObj(interp
, objv
[2], aMode
, "mode", 0, &eMode
)
7208 rc
= sqlite3_wal_checkpoint_v2(db
, zDb
, eMode
, &nLog
, &nCkpt
);
7209 if( rc
!=SQLITE_OK
&& rc
!=SQLITE_BUSY
){
7210 const char *zErrCode
= sqlite3ErrName(rc
);
7211 Tcl_ResetResult(interp
);
7212 Tcl_AppendResult(interp
, zErrCode
, " - ", (char *)sqlite3_errmsg(db
), 0);
7216 pRet
= Tcl_NewObj();
7217 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(rc
==SQLITE_BUSY
?1:0));
7218 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nLog
));
7219 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCkpt
));
7220 Tcl_SetObjResult(interp
, pRet
);
7226 ** tclcmd: sqlite3_wal_autocheckpoint db VALUE
7228 static int SQLITE_TCLAPI
test_wal_autocheckpoint(
7229 ClientData clientData
, /* Unused */
7230 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7231 int objc
, /* Number of arguments */
7232 Tcl_Obj
*CONST objv
[] /* Command arguments */
7240 Tcl_WrongNumArgs(interp
, 1, objv
, "DB VALUE");
7244 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
7245 || Tcl_GetIntFromObj(0, objv
[2], &iVal
)
7250 rc
= sqlite3_wal_autocheckpoint(db
, iVal
);
7251 Tcl_ResetResult(interp
);
7252 if( rc
!=SQLITE_OK
){
7253 const char *zErrCode
= sqlite3ErrName(rc
);
7254 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zErrCode
, -1));
7263 ** tclcmd: test_sqlite3_log ?SCRIPT?
7265 static struct LogCallback
{
7266 Tcl_Interp
*pInterp
;
7268 } logcallback
= {0, 0};
7269 static void xLogcallback(void *unused
, int err
, char *zMsg
){
7270 Tcl_Obj
*pNew
= Tcl_DuplicateObj(logcallback
.pObj
);
7271 Tcl_IncrRefCount(pNew
);
7272 Tcl_ListObjAppendElement(
7273 0, pNew
, Tcl_NewStringObj(sqlite3ErrName(err
), -1)
7275 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewStringObj(zMsg
, -1));
7276 Tcl_EvalObjEx(logcallback
.pInterp
, pNew
, TCL_EVAL_GLOBAL
|TCL_EVAL_DIRECT
);
7277 Tcl_DecrRefCount(pNew
);
7279 static int SQLITE_TCLAPI
test_sqlite3_log(
7280 ClientData clientData
,
7281 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7282 int objc
, /* Number of arguments */
7283 Tcl_Obj
*CONST objv
[] /* Command arguments */
7286 Tcl_WrongNumArgs(interp
, 1, objv
, "SCRIPT");
7289 if( logcallback
.pObj
){
7290 Tcl_DecrRefCount(logcallback
.pObj
);
7291 logcallback
.pObj
= 0;
7292 logcallback
.pInterp
= 0;
7293 sqlite3_config(SQLITE_CONFIG_LOG
, (void*)0, (void*)0);
7296 logcallback
.pObj
= objv
[1];
7297 Tcl_IncrRefCount(logcallback
.pObj
);
7298 logcallback
.pInterp
= interp
;
7299 sqlite3_config(SQLITE_CONFIG_LOG
, xLogcallback
, (void*)0);
7305 ** tcl_objproc COMMANDNAME ARGS...
7307 ** Run a TCL command using its objProc interface. Throw an error if
7308 ** the command has no objProc interface.
7310 static int SQLITE_TCLAPI
runAsObjProc(
7314 Tcl_Obj
*CONST objv
[]
7316 Tcl_CmdInfo cmdInfo
;
7318 Tcl_WrongNumArgs(interp
, 1, objv
, "COMMAND ...");
7321 if( !Tcl_GetCommandInfo(interp
, Tcl_GetString(objv
[1]), &cmdInfo
) ){
7322 Tcl_AppendResult(interp
, "command not found: ",
7323 Tcl_GetString(objv
[1]), (char*)0);
7326 if( cmdInfo
.objProc
==0 ){
7327 Tcl_AppendResult(interp
, "command has no objProc: ",
7328 Tcl_GetString(objv
[1]), (char*)0);
7331 return cmdInfo
.objProc(cmdInfo
.objClientData
, interp
, objc
-1, objv
+1);
7334 #ifndef SQLITE_OMIT_EXPLAIN
7336 ** WARNING: The following function, printExplainQueryPlan() is an exact
7337 ** copy of example code from eqp.in (eqp.html). If this code is modified,
7338 ** then the documentation copy needs to be modified as well.
7341 ** Argument pStmt is a prepared SQL statement. This function compiles
7342 ** an EXPLAIN QUERY PLAN command to report on the prepared statement,
7343 ** and prints the report to stdout using printf().
7345 int printExplainQueryPlan(sqlite3_stmt
*pStmt
){
7346 const char *zSql
; /* Input SQL */
7347 char *zExplain
; /* SQL with EXPLAIN QUERY PLAN prepended */
7348 sqlite3_stmt
*pExplain
; /* Compiled EXPLAIN QUERY PLAN command */
7349 int rc
; /* Return code from sqlite3_prepare_v2() */
7351 zSql
= sqlite3_sql(pStmt
);
7352 if( zSql
==0 ) return SQLITE_ERROR
;
7354 zExplain
= sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql
);
7355 if( zExplain
==0 ) return SQLITE_NOMEM
;
7357 rc
= sqlite3_prepare_v2(sqlite3_db_handle(pStmt
), zExplain
, -1, &pExplain
, 0);
7358 sqlite3_free(zExplain
);
7359 if( rc
!=SQLITE_OK
) return rc
;
7361 while( SQLITE_ROW
==sqlite3_step(pExplain
) ){
7362 int iSelectid
= sqlite3_column_int(pExplain
, 0);
7363 int iOrder
= sqlite3_column_int(pExplain
, 1);
7364 int iFrom
= sqlite3_column_int(pExplain
, 2);
7365 const char *zDetail
= (const char *)sqlite3_column_text(pExplain
, 3);
7367 printf("%d %d %d %s\n", iSelectid
, iOrder
, iFrom
, zDetail
);
7370 return sqlite3_finalize(pExplain
);
7373 static int SQLITE_TCLAPI
test_print_eqp(
7377 Tcl_Obj
*CONST objv
[]
7380 sqlite3_stmt
*pStmt
;
7383 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
7386 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
7387 rc
= printExplainQueryPlan(pStmt
);
7388 /* This is needed on Windows so that a test case using this
7389 ** function can open a read pipe and get the output of
7390 ** printExplainQueryPlan() immediately.
7393 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
7396 #endif /* SQLITE_OMIT_EXPLAIN */
7400 ** This is an alternative localtime_r() implementation used for testing
7401 ** the 'localtime' and 'utc' modifiers of date-time functions. Because
7402 ** the OS-supplied localtime_r() is locale-dependent, this alternative is
7403 ** provided as a stable test platform.
7407 ** (1) Localtime is 30 minutes earlier than (west of) UTC on
7408 ** even days (counting from 1970-01-01)
7410 ** (2) Localtime is 30 minutes later than (east of) UTC on odd days.
7412 ** (3) The function fails for the specific date/time value
7413 ** of 2000-05-29 14:16:00 in order to test the ability of
7414 ** SQLite to deal with localtime_r() failures.
7416 static int testLocaltime(const void *aliasT
, void *aliasTM
){
7417 const time_t t
= *(const time_t*)aliasT
;
7418 struct tm
*pTm
= (struct tm
*)aliasTM
;
7421 int Z
, A
, B
, C
, D
, E
, X1
, S
;
7423 if( (t
/86400) & 1 ){
7424 altT
= t
+ 1800; /* 30 minutes later on odd days */
7426 altT
= t
- 1800; /* 30 minutes earlier on even days */
7428 iJD
= (sqlite3_int64
)(altT
+ 210866760000);
7429 Z
= (int)((iJD
+ 43200)/86400);
7430 A
= (int)((Z
- 1867216.25)/36524.25);
7431 A
= Z
+ 1 + A
- (A
/4);
7433 C
= (int)((B
- 122.1)/365.25);
7434 D
= (36525*(C
&32767))/100;
7435 E
= (int)((B
-D
)/30.6001);
7436 X1
= (int)(30.6001*E
);
7437 pTm
->tm_mday
= B
- D
- X1
;
7438 pTm
->tm_mon
= E
<14 ? E
-2 : E
-14;
7439 pTm
->tm_year
= (pTm
->tm_mon
>1 ? C
- 4716 : C
- 4715) - 1900;
7440 S
= (int)((iJD
+ 43200)%86400);
7441 pTm
->tm_hour
= S
/3600;
7442 pTm
->tm_min
= (S
/60)%60;
7443 pTm
->tm_sec
= S
% 60;
7444 return t
==959609760; /* Special case: 2000-05-29 14:16:00 fails */
7448 ** sqlite3_test_control VERB ARGS...
7450 static int SQLITE_TCLAPI
test_test_control(
7454 Tcl_Obj
*CONST objv
[]
7460 { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT
},
7461 { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP
},
7462 { "SQLITE_TESTCTRL_IMPOSTER", SQLITE_TESTCTRL_IMPOSTER
},
7463 { "SQLITE_TESTCTRL_INTERNAL_FUNCTIONS", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
},
7471 Tcl_WrongNumArgs(interp
, 1, objv
, "VERB ARGS...");
7475 rc
= Tcl_GetIndexFromObjStruct(
7476 interp
, objv
[1], aVerb
, sizeof(aVerb
[0]), "VERB", 0, &iVerb
7478 if( rc
!=TCL_OK
) return rc
;
7480 iFlag
= aVerb
[iVerb
].i
;
7482 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
: {
7485 Tcl_WrongNumArgs(interp
, 2, objv
, "DB");
7488 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7489 sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
, db
);
7492 case SQLITE_TESTCTRL_LOCALTIME_FAULT
: {
7495 Tcl_WrongNumArgs(interp
, 2, objv
, "0|1|2");
7498 if( Tcl_GetIntFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
7499 sqlite3_test_control(iFlag
, val
, testLocaltime
);
7503 case SQLITE_TESTCTRL_SORTER_MMAP
: {
7507 Tcl_WrongNumArgs(interp
, 2, objv
, "DB LIMIT");
7510 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7511 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
7512 sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP
, db
, val
);
7516 case SQLITE_TESTCTRL_IMPOSTER
: {
7518 const char *zDbName
;
7521 Tcl_WrongNumArgs(interp
, 2, objv
, "DB dbName onOff tnum");
7524 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7525 zDbName
= Tcl_GetString(objv
[3]);
7526 if( Tcl_GetIntFromObj(interp
, objv
[4], &onOff
) ) return TCL_ERROR
;
7527 if( Tcl_GetIntFromObj(interp
, objv
[5], &tnum
) ) return TCL_ERROR
;
7528 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER
, db
, zDbName
, onOff
, tnum
);
7533 Tcl_ResetResult(interp
);
7538 #include <sys/time.h>
7539 #include <sys/resource.h>
7541 static int SQLITE_TCLAPI
test_getrusage(
7545 Tcl_Obj
*CONST objv
[]
7549 memset(&r
, 0, sizeof(r
));
7550 getrusage(RUSAGE_SELF
, &r
);
7552 sqlite3_snprintf(sizeof(buf
), buf
,
7553 "ru_utime=%d.%06d ru_stime=%d.%06d ru_minflt=%d ru_majflt=%d",
7554 (int)r
.ru_utime
.tv_sec
, (int)r
.ru_utime
.tv_usec
,
7555 (int)r
.ru_stime
.tv_sec
, (int)r
.ru_stime
.tv_usec
,
7556 (int)r
.ru_minflt
, (int)r
.ru_majflt
7558 Tcl_SetObjResult(interp
, Tcl_NewStringObj(buf
, -1));
7565 ** Information passed from the main thread into the windows file locker
7566 ** background thread.
7568 struct win32FileLocker
{
7569 char *evName
; /* Name of event to signal thread startup */
7570 HANDLE h
; /* Handle of the file to be locked */
7571 int delay1
; /* Delay before locking */
7572 int delay2
; /* Delay before unlocking */
7573 int ok
; /* Finished ok */
7574 int err
; /* True if an error occurs */
7580 #include <process.h>
7582 ** The background thread that does file locking.
7584 static void SQLITE_CDECL
win32_file_locker(void *pAppData
){
7585 struct win32FileLocker
*p
= (struct win32FileLocker
*)pAppData
;
7587 HANDLE ev
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, p
->evName
);
7593 if( p
->delay1
) Sleep(p
->delay1
);
7594 if( LockFile(p
->h
, 0, 0, 100000000, 0) ){
7596 UnlockFile(p
->h
, 0, 0, 100000000, 0);
7610 ** lock_win32_file FILENAME DELAY1 DELAY2
7612 ** Get an exclusive manditory lock on file for DELAY2 milliseconds.
7613 ** Wait DELAY1 milliseconds before acquiring the lock.
7615 static int SQLITE_TCLAPI
win32_file_lock(
7619 Tcl_Obj
*CONST objv
[]
7621 static struct win32FileLocker x
= { "win32_file_lock", 0, 0, 0, 0, 0 };
7622 const char *zFilename
;
7628 if( objc
!=4 && objc
!=1 ){
7629 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME DELAY1 DELAY2");
7633 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d %d %d %d %d",
7634 x
.ok
, x
.err
, x
.delay1
, x
.delay2
, x
.h
);
7635 Tcl_AppendResult(interp
, zBuf
, (char*)0);
7638 while( x
.h
&& retry
<30 ){
7643 Tcl_AppendResult(interp
, "busy", (char*)0);
7646 if( Tcl_GetIntFromObj(interp
, objv
[2], &x
.delay1
) ) return TCL_ERROR
;
7647 if( Tcl_GetIntFromObj(interp
, objv
[3], &x
.delay2
) ) return TCL_ERROR
;
7648 zFilename
= Tcl_GetString(objv
[1]);
7649 x
.h
= CreateFile(zFilename
, GENERIC_READ
|GENERIC_WRITE
,
7650 FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, OPEN_ALWAYS
,
7651 FILE_ATTRIBUTE_NORMAL
, 0);
7653 Tcl_AppendResult(interp
, "cannot open file: ", zFilename
, (char*)0);
7656 ev
= CreateEvent(NULL
, TRUE
, FALSE
, x
.evName
);
7658 Tcl_AppendResult(interp
, "cannot create event: ", x
.evName
, (char*)0);
7661 _beginthread(win32_file_locker
, 0, (void*)&x
);
7663 if ( (wResult
= WaitForSingleObject(ev
, 10000))!=WAIT_OBJECT_0
){
7664 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "0x%x", wResult
);
7665 Tcl_AppendResult(interp
, "wait failed: ", zBuf
, (char*)0);
7674 ** exists_win32_path PATH
7676 ** Returns non-zero if the specified path exists, whose fully qualified name
7677 ** may exceed 260 characters if it is prefixed with "\\?\".
7679 static int SQLITE_TCLAPI
win32_exists_path(
7683 Tcl_Obj
*CONST objv
[]
7686 Tcl_WrongNumArgs(interp
, 1, objv
, "PATH");
7689 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(
7690 GetFileAttributesW( Tcl_GetUnicode(objv
[1]))!=INVALID_FILE_ATTRIBUTES
));
7695 ** find_win32_file PATTERN
7697 ** Returns a list of entries in a directory that match the specified pattern,
7698 ** whose fully qualified name may exceed 248 characters if it is prefixed with
7701 static int SQLITE_TCLAPI
win32_find_file(
7705 Tcl_Obj
*CONST objv
[]
7707 HANDLE hFindFile
= INVALID_HANDLE_VALUE
;
7708 WIN32_FIND_DATAW findData
;
7712 Tcl_WrongNumArgs(interp
, 1, objv
, "PATTERN");
7715 hFindFile
= FindFirstFileW(Tcl_GetUnicode(objv
[1]), &findData
);
7716 if( hFindFile
==INVALID_HANDLE_VALUE
){
7717 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7720 listObj
= Tcl_NewObj();
7721 Tcl_IncrRefCount(listObj
);
7723 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewUnicodeObj(
7724 findData
.cFileName
, -1));
7725 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewWideIntObj(
7726 findData
.dwFileAttributes
));
7727 } while( FindNextFileW(hFindFile
, &findData
) );
7728 lastErrno
= GetLastError();
7729 if( lastErrno
!=NO_ERROR
&& lastErrno
!=ERROR_NO_MORE_FILES
){
7730 FindClose(hFindFile
);
7731 Tcl_DecrRefCount(listObj
);
7732 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7735 FindClose(hFindFile
);
7736 Tcl_SetObjResult(interp
, listObj
);
7741 ** delete_win32_file FILENAME
7743 ** Deletes the specified file, whose fully qualified name may exceed 260
7744 ** characters if it is prefixed with "\\?\".
7746 static int SQLITE_TCLAPI
win32_delete_file(
7750 Tcl_Obj
*CONST objv
[]
7753 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME");
7756 if( !DeleteFileW(Tcl_GetUnicode(objv
[1])) ){
7757 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7760 Tcl_ResetResult(interp
);
7765 ** make_win32_dir DIRECTORY
7767 ** Creates the specified directory, whose fully qualified name may exceed 248
7768 ** characters if it is prefixed with "\\?\".
7770 static int SQLITE_TCLAPI
win32_mkdir(
7774 Tcl_Obj
*CONST objv
[]
7777 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
7780 if( !CreateDirectoryW(Tcl_GetUnicode(objv
[1]), NULL
) ){
7781 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7784 Tcl_ResetResult(interp
);
7789 ** remove_win32_dir DIRECTORY
7791 ** Removes the specified directory, whose fully qualified name may exceed 248
7792 ** characters if it is prefixed with "\\?\".
7794 static int SQLITE_TCLAPI
win32_rmdir(
7798 Tcl_Obj
*CONST objv
[]
7801 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
7804 if( !RemoveDirectoryW(Tcl_GetUnicode(objv
[1])) ){
7805 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7808 Tcl_ResetResult(interp
);
7815 ** optimization_control DB OPT BOOLEAN
7817 ** Enable or disable query optimizations using the sqlite3_test_control()
7818 ** interface. Disable if BOOLEAN is false and enable if BOOLEAN is true.
7819 ** OPT is the name of the optimization to be disabled. OPT can also be a
7820 ** list or optimizations names, in which case all optimizations named are
7821 ** enabled or disabled.
7823 ** Each invocation of this control overrides all prior invocations. The
7824 ** changes are not cumulative.
7826 static int SQLITE_TCLAPI
optimization_control(
7830 Tcl_Obj
*CONST objv
[]
7838 static const struct {
7839 const char *zOptName
;
7842 { "all", SQLITE_AllOpts
},
7844 { "query-flattener", SQLITE_QueryFlattener
},
7845 { "groupby-order", SQLITE_GroupByOrder
},
7846 { "factor-constants", SQLITE_FactorOutConst
},
7847 { "distinct-opt", SQLITE_DistinctOpt
},
7848 { "cover-idx-scan", SQLITE_CoverIdxScan
},
7849 { "order-by-idx-join", SQLITE_OrderByIdxJoin
},
7850 { "transitive", SQLITE_Transitive
},
7851 { "omit-noop-join", SQLITE_OmitNoopJoin
},
7852 { "stat4", SQLITE_Stat4
},
7853 { "skip-scan", SQLITE_SkipScan
},
7854 { "push-down", SQLITE_PushDown
},
7855 { "balanced-merge", SQLITE_BalancedMerge
},
7856 { "propagate-const", SQLITE_PropagateConst
},
7860 Tcl_WrongNumArgs(interp
, 1, objv
, "DB OPT BOOLEAN");
7863 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7864 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &onoff
) ) return TCL_ERROR
;
7865 zOpt
= Tcl_GetString(objv
[2]);
7866 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
7867 if( strstr(zOpt
, aOpt
[i
].zOptName
)!=0 ){
7868 mask
|= aOpt
[i
].mask
;
7872 if( onoff
) mask
= ~mask
;
7874 Tcl_AppendResult(interp
, "unknown optimization - should be one of:",
7876 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
7877 Tcl_AppendResult(interp
, " ", aOpt
[i
].zOptName
, (char*)0);
7881 sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS
, db
, mask
);
7882 Tcl_SetObjResult(interp
, Tcl_NewIntObj(mask
));
7887 ** load_static_extension DB NAME ...
7889 ** Load one or more statically linked extensions.
7891 static int SQLITE_TCLAPI
tclLoadStaticExtensionCmd(
7895 Tcl_Obj
*CONST objv
[]
7897 extern int sqlite3_amatch_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7898 extern int sqlite3_appendvfs_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7899 extern int sqlite3_basexx_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7900 extern int sqlite3_carray_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7901 extern int sqlite3_closure_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7902 extern int sqlite3_csv_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7903 extern int sqlite3_eval_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7904 extern int sqlite3_explain_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7905 extern int sqlite3_fileio_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7906 extern int sqlite3_decimal_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7907 extern int sqlite3_fuzzer_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7908 extern int sqlite3_ieee_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7909 extern int sqlite3_nextchar_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7910 extern int sqlite3_percentile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7911 #ifndef SQLITE_OMIT_VIRTUALTABLE
7912 extern int sqlite3_prefixes_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7914 extern int sqlite3_qpvtab_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7915 extern int sqlite3_regexp_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7916 extern int sqlite3_remember_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7917 extern int sqlite3_series_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7918 extern int sqlite3_spellfix_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7919 extern int sqlite3_totype_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7920 extern int sqlite3_wholenumber_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7921 extern int sqlite3_unionvtab_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7922 #ifdef SQLITE_HAVE_ZLIB
7923 extern int sqlite3_zipfile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
7925 static const struct {
7926 const char *zExtName
;
7927 int (*pInit
)(sqlite3
*,char**,const sqlite3_api_routines
*);
7929 { "amatch", sqlite3_amatch_init
},
7930 { "appendvfs", sqlite3_appendvfs_init
},
7931 { "basexx", sqlite3_basexx_init
},
7932 { "carray", sqlite3_carray_init
},
7933 { "closure", sqlite3_closure_init
},
7934 { "csv", sqlite3_csv_init
},
7935 { "decimal", sqlite3_decimal_init
},
7936 { "eval", sqlite3_eval_init
},
7937 { "explain", sqlite3_explain_init
},
7938 { "fileio", sqlite3_fileio_init
},
7939 { "fuzzer", sqlite3_fuzzer_init
},
7940 { "ieee754", sqlite3_ieee_init
},
7941 { "nextchar", sqlite3_nextchar_init
},
7942 { "percentile", sqlite3_percentile_init
},
7943 #ifndef SQLITE_OMIT_VIRTUALTABLE
7944 { "prefixes", sqlite3_prefixes_init
},
7946 { "qpvtab", sqlite3_qpvtab_init
},
7947 { "regexp", sqlite3_regexp_init
},
7948 { "remember", sqlite3_remember_init
},
7949 { "series", sqlite3_series_init
},
7950 { "spellfix", sqlite3_spellfix_init
},
7951 { "totype", sqlite3_totype_init
},
7952 { "unionvtab", sqlite3_unionvtab_init
},
7953 { "wholenumber", sqlite3_wholenumber_init
},
7954 #ifdef SQLITE_HAVE_ZLIB
7955 { "zipfile", sqlite3_zipfile_init
},
7963 Tcl_WrongNumArgs(interp
, 1, objv
, "DB NAME ...");
7966 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7967 for(j
=2; j
<objc
; j
++){
7968 zName
= Tcl_GetString(objv
[j
]);
7969 for(i
=0; i
<ArraySize(aExtension
); i
++){
7970 if( strcmp(zName
, aExtension
[i
].zExtName
)==0 ) break;
7972 if( i
>=ArraySize(aExtension
) ){
7973 Tcl_AppendResult(interp
, "no such extension: ", zName
, (char*)0);
7976 if( aExtension
[i
].pInit
){
7977 rc
= aExtension
[i
].pInit(db
, &zErrMsg
, 0);
7981 if( (rc
!=SQLITE_OK
&& rc
!=SQLITE_OK_LOAD_PERMANENTLY
) || zErrMsg
){
7982 Tcl_AppendResult(interp
, "initialization of ", zName
, " failed: ", zErrMsg
,
7984 sqlite3_free(zErrMsg
);
7992 ** sorter_test_fakeheap BOOL
7995 static int SQLITE_TCLAPI
sorter_test_fakeheap(
7999 Tcl_Obj
*CONST objv
[]
8003 Tcl_WrongNumArgs(interp
, 1, objv
, "BOOL");
8007 if( Tcl_GetBooleanFromObj(interp
, objv
[1], &bArg
) ){
8012 if( sqlite3GlobalConfig
.pHeap
==0 ){
8013 sqlite3GlobalConfig
.pHeap
= SQLITE_INT_TO_PTR(-1);
8016 if( sqlite3GlobalConfig
.pHeap
==SQLITE_INT_TO_PTR(-1) ){
8017 sqlite3GlobalConfig
.pHeap
= 0;
8021 Tcl_ResetResult(interp
);
8026 ** sorter_test_sort4_helper DB SQL1 NSTEP SQL2
8028 ** Compile SQL statement $SQL1 and step it $NSTEP times. For each row,
8029 ** check that the leftmost and rightmost columns returned are both integers,
8030 ** and that both contain the same value.
8032 ** Then execute statement $SQL2. Check that the statement returns the same
8033 ** set of integers in the same order as in the previous step (using $SQL1).
8035 static int SQLITE_TCLAPI
sorter_test_sort4_helper(
8039 Tcl_Obj
*CONST objv
[]
8045 unsigned int iCksum1
= 0;
8046 unsigned int iCksum2
= 0;
8050 sqlite3_stmt
*pStmt
;
8053 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SQL1 NSTEP SQL2");
8057 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8058 zSql1
= Tcl_GetString(objv
[2]);
8059 if( Tcl_GetIntFromObj(interp
, objv
[3], &nStep
) ) return TCL_ERROR
;
8060 zSql2
= Tcl_GetString(objv
[4]);
8062 rc
= sqlite3_prepare_v2(db
, zSql1
, -1, &pStmt
, 0);
8063 if( rc
!=SQLITE_OK
) goto sql_error
;
8065 iB
= sqlite3_column_count(pStmt
)-1;
8066 for(iStep
=0; iStep
<nStep
&& SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
8067 int a
= sqlite3_column_int(pStmt
, 0);
8068 if( a
!=sqlite3_column_int(pStmt
, iB
) ){
8069 Tcl_AppendResult(interp
, "data error: (a!=b)", 0);
8073 iCksum1
+= (iCksum1
<< 3) + (unsigned int)a
;
8075 rc
= sqlite3_finalize(pStmt
);
8076 if( rc
!=SQLITE_OK
) goto sql_error
;
8078 rc
= sqlite3_prepare_v2(db
, zSql2
, -1, &pStmt
, 0);
8079 if( rc
!=SQLITE_OK
) goto sql_error
;
8080 for(iStep
=0; SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
8081 int a
= sqlite3_column_int(pStmt
, 0);
8082 iCksum2
+= (iCksum2
<< 3) + (unsigned int)a
;
8084 rc
= sqlite3_finalize(pStmt
);
8085 if( rc
!=SQLITE_OK
) goto sql_error
;
8087 if( iCksum1
!=iCksum2
){
8088 Tcl_AppendResult(interp
, "checksum mismatch", 0);
8094 Tcl_AppendResult(interp
, "sql error: ", sqlite3_errmsg(db
), 0);
8099 #ifdef SQLITE_USER_AUTHENTICATION
8100 #include "sqlite3userauth.h"
8102 ** tclcmd: sqlite3_user_authenticate DB USERNAME PASSWORD
8104 static int SQLITE_TCLAPI
test_user_authenticate(
8105 ClientData clientData
, /* Unused */
8106 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8107 int objc
, /* Number of arguments */
8108 Tcl_Obj
*CONST objv
[] /* Command arguments */
8117 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD");
8120 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
8123 zUser
= Tcl_GetString(objv
[2]);
8124 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
8125 rc
= sqlite3_user_authenticate(db
, zUser
, zPasswd
, nPasswd
);
8126 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
8129 #endif /* SQLITE_USER_AUTHENTICATION */
8131 #ifdef SQLITE_USER_AUTHENTICATION
8133 ** tclcmd: sqlite3_user_add DB USERNAME PASSWORD ISADMIN
8135 static int SQLITE_TCLAPI
test_user_add(
8136 ClientData clientData
, /* Unused */
8137 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8138 int objc
, /* Number of arguments */
8139 Tcl_Obj
*CONST objv
[] /* Command arguments */
8149 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
8152 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
8155 zUser
= Tcl_GetString(objv
[2]);
8156 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
8157 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
8158 rc
= sqlite3_user_add(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
8159 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
8162 #endif /* SQLITE_USER_AUTHENTICATION */
8164 #ifdef SQLITE_USER_AUTHENTICATION
8166 ** tclcmd: sqlite3_user_change DB USERNAME PASSWORD ISADMIN
8168 static int SQLITE_TCLAPI
test_user_change(
8169 ClientData clientData
, /* Unused */
8170 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8171 int objc
, /* Number of arguments */
8172 Tcl_Obj
*CONST objv
[] /* Command arguments */
8182 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
8185 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
8188 zUser
= Tcl_GetString(objv
[2]);
8189 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
8190 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
8191 rc
= sqlite3_user_change(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
8192 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
8195 #endif /* SQLITE_USER_AUTHENTICATION */
8197 #ifdef SQLITE_USER_AUTHENTICATION
8199 ** tclcmd: sqlite3_user_delete DB USERNAME
8201 static int SQLITE_TCLAPI
test_user_delete(
8202 ClientData clientData
, /* Unused */
8203 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8204 int objc
, /* Number of arguments */
8205 Tcl_Obj
*CONST objv
[] /* Command arguments */
8212 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME");
8215 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
8218 zUser
= Tcl_GetString(objv
[2]);
8219 rc
= sqlite3_user_delete(db
, zUser
);
8220 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
8223 #endif /* SQLITE_USER_AUTHENTICATION */
8226 ** tclcmd: bad_behavior TYPE
8228 ** Do some things that should trigger a valgrind or -fsanitize=undefined
8229 ** warning. This is used to verify that errors and warnings output by those
8230 ** tools are detected by the test scripts.
8233 ** 1 Overflow a signed integer
8234 ** 2 Jump based on an uninitialized variable
8235 ** 3 Read after free
8238 static int SQLITE_TCLAPI
test_bad_behavior(
8239 ClientData clientData
, /* Pointer to an integer containing zero */
8240 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8241 int objc
, /* Number of arguments */
8242 Tcl_Obj
*CONST objv
[] /* Command arguments */
8246 int i
= *(int*)clientData
;
8251 Tcl_WrongNumArgs(interp
, 1, objv
, "TYPE");
8254 if( Tcl_GetIntFromObj(interp
, objv
[1], &iType
) ) return TCL_ERROR
;
8257 xyz
= 0x7fffff00 - i
;
8259 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xyz
));
8264 if( w
[i
]>0 ) w
[1]++;
8265 Tcl_SetObjResult(interp
, Tcl_NewIntObj(w
[1]));
8269 a
= malloc( sizeof(int)*10 );
8270 for(j
=0; j
<10; j
++) a
[j
] = j
;
8272 Tcl_SetObjResult(interp
, Tcl_NewIntObj(a
[i
]));
8276 Tcl_Panic("Deliberate panic");
8284 ** tclcmd: register_dbstat_vtab DB
8286 ** Cause the dbstat virtual table to be available on the connection DB
8288 static int SQLITE_TCLAPI
test_register_dbstat_vtab(
8292 Tcl_Obj
*CONST objv
[]
8294 #ifdef SQLITE_OMIT_VIRTUALTABLE
8295 Tcl_AppendResult(interp
, "dbstat not available because of "
8296 "SQLITE_OMIT_VIRTUALTABLE", (void*)0);
8299 struct SqliteDb
{ sqlite3
*db
; };
8301 Tcl_CmdInfo cmdInfo
;
8304 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
8308 zDb
= Tcl_GetString(objv
[1]);
8309 if( Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
8310 sqlite3
* db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
8311 sqlite3DbstatRegister(db
);
8314 #endif /* SQLITE_OMIT_VIRTUALTABLE */
8318 ** tclcmd: sqlite3_db_config DB SETTING VALUE
8320 ** Invoke sqlite3_db_config() for one of the setting values.
8322 static int SQLITE_TCLAPI
test_sqlite3_db_config(
8326 Tcl_Obj
*CONST objv
[]
8328 static const struct {
8332 { "FKEY", SQLITE_DBCONFIG_ENABLE_FKEY
},
8333 { "TRIGGER", SQLITE_DBCONFIG_ENABLE_TRIGGER
},
8334 { "FTS3_TOKENIZER", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
},
8335 { "LOAD_EXTENSION", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
},
8336 { "NO_CKPT_ON_CLOSE", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
},
8337 { "QPSG", SQLITE_DBCONFIG_ENABLE_QPSG
},
8338 { "TRIGGER_EQP", SQLITE_DBCONFIG_TRIGGER_EQP
},
8339 { "RESET_DB", SQLITE_DBCONFIG_RESET_DATABASE
},
8340 { "DEFENSIVE", SQLITE_DBCONFIG_DEFENSIVE
},
8341 { "WRITABLE_SCHEMA", SQLITE_DBCONFIG_WRITABLE_SCHEMA
},
8342 { "LEGACY_ALTER_TABLE", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
},
8343 { "DQS_DML", SQLITE_DBCONFIG_DQS_DML
},
8344 { "DQS_DDL", SQLITE_DBCONFIG_DQS_DDL
},
8345 { "LEGACY_FILE_FORMAT", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
},
8346 { "STMT_SCANSTATUS", SQLITE_DBCONFIG_STMT_SCANSTATUS
},
8350 const char *zSetting
;
8353 if( objc
!=4 && objc
!=3 ){
8354 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SETTING [VALUE]");
8357 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8358 zSetting
= Tcl_GetString(objv
[2]);
8359 if( sqlite3_strglob("SQLITE_*", zSetting
)==0 ) zSetting
+= 7;
8360 if( sqlite3_strglob("DBCONFIG_*", zSetting
)==0 ) zSetting
+= 9;
8361 if( sqlite3_strglob("ENABLE_*", zSetting
)==0 ) zSetting
+= 7;
8362 for(i
=0; i
<ArraySize(aSetting
); i
++){
8363 if( strcmp(zSetting
, aSetting
[i
].zName
)==0 ) break;
8365 if( i
>=ArraySize(aSetting
) ){
8366 Tcl_SetObjResult(interp
,
8367 Tcl_NewStringObj("unknown sqlite3_db_config setting", -1));
8371 if( Tcl_GetIntFromObj(interp
, objv
[3], &v
) ) return TCL_ERROR
;
8375 sqlite3_db_config(db
, aSetting
[i
].eVal
, v
, &v
);
8376 Tcl_SetObjResult(interp
, Tcl_NewIntObj(v
));
8380 ** tclcmd: sqlite3_txn_state DB ?SCHEMA?
8382 ** Invoke sqlite3_txn_state(DB,SCHEMA) and return the
8383 ** numeric value that results. Use NULL for SCHEMA if the 3 argument
8386 static int SQLITE_TCLAPI
test_sqlite3_txn_state(
8390 Tcl_Obj
*CONST objv
[]
8393 const char *zSchema
;
8396 if( objc
!=2 && objc
!=3 ){
8397 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?SCHEMA?");
8400 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8401 zSchema
= objc
==3 ? Tcl_GetString(objv
[2]) : 0;
8402 iTxn
= sqlite3_txn_state(db
, zSchema
);
8403 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iTxn
));
8408 ** Change the name of the main database schema from "main" to "icecube".
8410 static int SQLITE_TCLAPI
test_dbconfig_maindbname_icecube(
8414 Tcl_Obj
*CONST objv
[]
8418 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
8420 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
8423 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8424 rc
= sqlite3_db_config(db
, SQLITE_DBCONFIG_MAINDBNAME
, "icecube");
8425 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
8431 ** Usage: sqlite3_mmap_warm DB DBNAME
8433 static int SQLITE_TCLAPI
test_mmap_warm(
8437 Tcl_Obj
*CONST objv
[]
8439 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
8440 extern int sqlite3_mmap_warm(sqlite3
*db
, const char *);
8442 if( objc
!=2 && objc
!=3 ){
8443 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?DBNAME?");
8448 const char *zDb
= 0;
8449 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8451 zDb
= Tcl_GetString(objv
[2]);
8453 rc
= sqlite3_mmap_warm(db
, zDb
);
8454 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
8460 ** Usage: test_write_db DB OFFSET DATA
8462 ** Obtain the sqlite3_file* object for the database file for the "main" db
8463 ** of handle DB. Then invoke its xWrite method to write data DATA to offset
8466 static int SQLITE_TCLAPI
test_write_db(
8470 Tcl_Obj
*CONST objv
[]
8473 Tcl_WideInt iOff
= 0;
8474 const unsigned char *aData
= 0;
8476 sqlite3_file
*pFile
= 0;
8480 Tcl_WrongNumArgs(interp
, 1, objv
, "DB OFFSET DATA");
8483 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8484 if( Tcl_GetWideIntFromObj(interp
, objv
[2], &iOff
) ) return TCL_ERROR
;
8485 aData
= Tcl_GetByteArrayFromObj(objv
[3], &nData
);
8487 sqlite3_file_control(db
, "main", SQLITE_FCNTL_FILE_POINTER
, (void*)&pFile
);
8488 rc
= pFile
->pMethods
->xWrite(pFile
, aData
, nData
, iOff
);
8490 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
8495 ** Usage: sqlite3_register_cksumvfs
8498 static int SQLITE_TCLAPI
test_register_cksumvfs(
8502 Tcl_Obj
*CONST objv
[]
8505 Tcl_WrongNumArgs(interp
, 1, objv
, "");
8508 extern int sqlite3_register_cksumvfs(const char*);
8509 int rc
= sqlite3_register_cksumvfs(0);
8510 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
8516 ** Usage: sqlite3_unregister_cksumvfs
8519 static int SQLITE_TCLAPI
test_unregister_cksumvfs(
8523 Tcl_Obj
*CONST objv
[]
8526 Tcl_WrongNumArgs(interp
, 1, objv
, "");
8529 extern int sqlite3_unregister_cksumvfs(void);
8530 int rc
= sqlite3_unregister_cksumvfs();
8531 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
8537 ** Usage: decode_hexdb TEXT
8539 ** Example: db deserialize [decode_hexdb $output_of_dbtotxt]
8541 ** This routine returns a byte-array for an SQLite database file that
8542 ** is constructed from a text input which is the output of the "dbtotxt"
8545 static int SQLITE_TCLAPI
test_decode_hexdb(
8549 Tcl_Obj
*CONST objv
[]
8551 const char *zIn
= 0;
8552 unsigned char *a
= 0;
8561 Tcl_WrongNumArgs(interp
, 1, objv
, "HEXDB");
8564 zIn
= Tcl_GetString(objv
[1]);
8565 for(i
=0; zIn
[i
]; i
=iNext
){
8567 for(iNext
=i
; zIn
[iNext
] && zIn
[iNext
]!='\n'; iNext
++){}
8568 if( zIn
[iNext
]=='\n' ) iNext
++;
8569 while( zIn
[i
]==' ' || zIn
[i
]=='\t' ){ i
++; }
8572 rc
= sscanf(zIn
+i
, "| size %d pagesize %d", &n
, &pgsz
);
8573 if( rc
!=2 ) continue;
8574 if( pgsz
<512 || pgsz
>65536 || (pgsz
&(pgsz
-1))!=0 ){
8575 Tcl_AppendResult(interp
, "bad 'pagesize' field", (void*)0);
8578 n
= (n
+pgsz
-1)&~(pgsz
-1); /* Round n up to the next multiple of pgsz */
8580 Tcl_AppendResult(interp
, "bad 'size' field", (void*)0);
8585 Tcl_AppendResult(interp
, "out of memory", (void*)0);
8591 rc
= sscanf(zIn
+i
, "| page %d offset %d", &j
, &k
);
8596 rc
= sscanf(zIn
+i
,"| %d: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
8597 &j
, &x
[0], &x
[1], &x
[2], &x
[3], &x
[4], &x
[5], &x
[6], &x
[7],
8598 &x
[8], &x
[9], &x
[10], &x
[11], &x
[12], &x
[13], &x
[14], &x
[15]);
8603 for(ii
=0; ii
<16; ii
++) a
[k
+ii
] = x
[ii
]&0xff;
8608 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(a
, n
));
8614 ** Client data for the autovacuum_pages callback.
8616 struct AutovacPageData
{
8620 typedef struct AutovacPageData AutovacPageData
;
8623 ** Callback functions for sqlite3_autovacuum_pages
8625 static unsigned int test_autovacuum_pages_callback(
8627 const char *zSchema
,
8628 unsigned int nFilePages
,
8629 unsigned int nFreePages
,
8630 unsigned int nBytePerPage
8632 AutovacPageData
*pData
= (AutovacPageData
*)pClientData
;
8636 Tcl_DStringInit(&str
);
8637 Tcl_DStringAppend(&str
, pData
->zScript
, -1);
8638 Tcl_DStringAppendElement(&str
, zSchema
);
8639 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%u", nFilePages
);
8640 Tcl_DStringAppendElement(&str
, zBuf
);
8641 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%u", nFreePages
);
8642 Tcl_DStringAppendElement(&str
, zBuf
);
8643 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%u", nBytePerPage
);
8644 Tcl_DStringAppendElement(&str
, zBuf
);
8645 Tcl_ResetResult(pData
->interp
);
8646 Tcl_Eval(pData
->interp
, Tcl_DStringValue(&str
));
8647 Tcl_DStringFree(&str
);
8649 (void)Tcl_GetIntFromObj(0, Tcl_GetObjResult(pData
->interp
), (int*)&x
);
8654 ** Usage: sqlite3_autovacuum_pages DB SCRIPT
8656 ** Add an autovacuum-pages callback to database connection DB. The callback
8657 ** will invoke SCRIPT, after appending parameters.
8659 ** If SCRIPT is an empty string or is omitted, then the callback is
8662 static int SQLITE_TCLAPI
test_autovacuum_pages(
8666 Tcl_Obj
*CONST objv
[]
8668 AutovacPageData
*pData
;
8671 const char *zScript
;
8672 if( objc
!=2 && objc
!=3 ){
8673 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?SCRIPT?");
8676 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8677 zScript
= objc
==3 ? Tcl_GetString(objv
[2]) : 0;
8679 size_t nScript
= strlen(zScript
);
8680 pData
= sqlite3_malloc64( sizeof(*pData
) + nScript
+ 1 );
8682 Tcl_AppendResult(interp
, "out of memory", (void*)0);
8685 pData
->interp
= interp
;
8686 pData
->zScript
= (char*)&pData
[1];
8687 memcpy(pData
->zScript
, zScript
, nScript
+1);
8688 rc
= sqlite3_autovacuum_pages(db
,test_autovacuum_pages_callback
,
8689 pData
, sqlite3_free
);
8691 rc
= sqlite3_autovacuum_pages(db
, 0, 0, 0);
8695 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
8696 "sqlite3_autovacuum_pages() returns %d", rc
);
8697 Tcl_AppendResult(interp
, zBuf
, (void*)0);
8704 ** Usage: number_of_cores
8706 ** Return a guess at the number of available cores available on the
8707 ** processor on which this process is running.
8709 static int SQLITE_TCLAPI
guess_number_of_cores(
8713 Tcl_Obj
*CONST objv
[]
8715 unsigned int nCore
= 1;
8717 SYSTEM_INFO sysinfo
;
8718 GetSystemInfo(&sysinfo
);
8719 nCore
= (unsigned int)sysinfo
.dwNumberOfProcessors
;
8720 #elif defined(__APPLE__)
8723 nm
[0] = CTL_HW
; nm
[1] = HW_AVAILCPU
;
8724 sysctl(nm
, 2, &nCore
, &len
, NULL
, 0);
8727 sysctl(nm
, 2, &nCore
, &len
, NULL
, 0);
8730 nCore
= sysconf(_SC_NPROCESSORS_ONLN
);
8732 if( nCore
<=0 ) nCore
= 1;
8733 Tcl_SetObjResult(interp
, Tcl_NewIntObj((int)nCore
));
8739 ** Register commands with the TCL interpreter.
8741 int Sqlitetest1_Init(Tcl_Interp
*interp
){
8742 extern int sqlite3_search_count
;
8743 extern int sqlite3_found_count
;
8744 extern int sqlite3_interrupt_count
;
8745 extern int sqlite3_open_file_count
;
8746 extern int sqlite3_sort_count
;
8747 extern int sqlite3_current_time
;
8748 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
8749 extern int sqlite3_hostid_num
;
8751 extern int sqlite3_max_blobsize
;
8752 extern int SQLITE_TCLAPI
sqlite3BtreeSharedCacheReport(void*,
8753 Tcl_Interp
*,int,Tcl_Obj
*CONST
*);
8754 static int iZero
= 0;
8759 { "db_enter", (Tcl_CmdProc
*)db_enter
},
8760 { "db_leave", (Tcl_CmdProc
*)db_leave
},
8761 { "sqlite3_mprintf_int", (Tcl_CmdProc
*)sqlite3_mprintf_int
},
8762 { "sqlite3_mprintf_int64", (Tcl_CmdProc
*)sqlite3_mprintf_int64
},
8763 { "sqlite3_mprintf_long", (Tcl_CmdProc
*)sqlite3_mprintf_long
},
8764 { "sqlite3_mprintf_str", (Tcl_CmdProc
*)sqlite3_mprintf_str
},
8765 { "sqlite3_snprintf_str", (Tcl_CmdProc
*)sqlite3_snprintf_str
},
8766 { "sqlite3_mprintf_stronly", (Tcl_CmdProc
*)sqlite3_mprintf_stronly
},
8767 { "sqlite3_mprintf_double", (Tcl_CmdProc
*)sqlite3_mprintf_double
},
8768 { "sqlite3_mprintf_scaled", (Tcl_CmdProc
*)sqlite3_mprintf_scaled
},
8769 { "sqlite3_mprintf_hexdouble", (Tcl_CmdProc
*)sqlite3_mprintf_hexdouble
},
8770 { "sqlite3_mprintf_z_test", (Tcl_CmdProc
*)test_mprintf_z
},
8771 { "sqlite3_mprintf_n_test", (Tcl_CmdProc
*)test_mprintf_n
},
8772 { "sqlite3_snprintf_int", (Tcl_CmdProc
*)test_snprintf_int
},
8773 { "sqlite3_last_insert_rowid", (Tcl_CmdProc
*)test_last_rowid
},
8774 { "sqlite3_exec_printf", (Tcl_CmdProc
*)test_exec_printf
},
8775 { "sqlite3_exec_hex", (Tcl_CmdProc
*)test_exec_hex
},
8776 { "sqlite3_exec", (Tcl_CmdProc
*)test_exec
},
8777 { "sqlite3_exec_nr", (Tcl_CmdProc
*)test_exec_nr
},
8778 #ifndef SQLITE_OMIT_GET_TABLE
8779 { "sqlite3_get_table_printf", (Tcl_CmdProc
*)test_get_table_printf
},
8781 { "sqlite3_close", (Tcl_CmdProc
*)sqlite_test_close
},
8782 { "sqlite3_close_v2", (Tcl_CmdProc
*)sqlite_test_close_v2
},
8783 { "sqlite3_create_function", (Tcl_CmdProc
*)test_create_function
},
8784 { "sqlite3_create_aggregate", (Tcl_CmdProc
*)test_create_aggregate
},
8785 { "sqlite3_drop_modules", (Tcl_CmdProc
*)test_drop_modules
},
8786 { "sqlite_register_test_function", (Tcl_CmdProc
*)test_register_func
},
8787 { "sqlite_abort", (Tcl_CmdProc
*)sqlite_abort
},
8788 { "sqlite_bind", (Tcl_CmdProc
*)test_bind
},
8789 { "breakpoint", (Tcl_CmdProc
*)test_breakpoint
},
8790 { "sqlite3_key", (Tcl_CmdProc
*)test_key
},
8791 { "sqlite3_rekey", (Tcl_CmdProc
*)test_rekey
},
8792 { "sqlite3_interrupt", (Tcl_CmdProc
*)test_interrupt
},
8793 { "sqlite3_is_interrupted", (Tcl_CmdProc
*)test_is_interrupted
},
8794 { "sqlite_delete_function", (Tcl_CmdProc
*)delete_function
},
8795 { "sqlite_delete_collation", (Tcl_CmdProc
*)delete_collation
},
8796 { "sqlite3_get_autocommit", (Tcl_CmdProc
*)get_autocommit
},
8797 { "sqlite3_busy_timeout", (Tcl_CmdProc
*)test_busy_timeout
},
8798 { "printf", (Tcl_CmdProc
*)test_printf
},
8799 { "sqlite3IoTrace", (Tcl_CmdProc
*)test_io_trace
},
8800 { "clang_sanitize_address", (Tcl_CmdProc
*)clang_sanitize_address
},
8804 Tcl_ObjCmdProc
*xProc
;
8807 { "sqlite3_db_config", test_sqlite3_db_config
, 0 },
8808 { "sqlite3_txn_state", test_sqlite3_txn_state
, 0 },
8809 { "bad_behavior", test_bad_behavior
, (void*)&iZero
},
8810 { "register_dbstat_vtab", test_register_dbstat_vtab
},
8811 { "sqlite3_connection_pointer", get_sqlite_pointer
, 0 },
8812 { "intarray_addr", test_intarray_addr
, 0 },
8813 { "int64array_addr", test_int64array_addr
, 0 },
8814 { "doublearray_addr", test_doublearray_addr
, 0 },
8815 { "textarray_addr", test_textarray_addr
, 0 },
8816 { "sqlite3_bind_int", test_bind_int
, 0 },
8817 { "sqlite3_bind_zeroblob", test_bind_zeroblob
, 0 },
8818 { "sqlite3_bind_zeroblob64", test_bind_zeroblob64
, 0 },
8819 { "sqlite3_bind_int64", test_bind_int64
, 0 },
8820 { "sqlite3_bind_double", test_bind_double
, 0 },
8821 { "sqlite3_bind_null", test_bind_null
,0 },
8822 { "sqlite3_bind_text", test_bind_text
,0 },
8823 { "sqlite3_bind_text16", test_bind_text16
,0 },
8824 { "sqlite3_bind_blob", test_bind_blob
,0 },
8825 { "sqlite3_bind_value_from_select",test_bind_value_from_select
,0 },
8826 { "sqlite3_bind_value_from_preupdate",test_bind_value_from_preupdate
,0 },
8827 #ifndef SQLITE_OMIT_VIRTUALTABLE
8828 { "sqlite3_carray_bind", test_carray_bind
,0 },
8830 { "sqlite3_bind_parameter_count", test_bind_parameter_count
, 0},
8831 { "sqlite3_bind_parameter_name", test_bind_parameter_name
, 0},
8832 { "sqlite3_bind_parameter_index", test_bind_parameter_index
, 0},
8833 { "sqlite3_clear_bindings", test_clear_bindings
, 0},
8834 { "sqlite3_sleep", test_sleep
, 0},
8835 { "sqlite3_errcode", test_errcode
,0 },
8836 { "sqlite3_extended_errcode", test_ex_errcode
,0 },
8837 { "sqlite3_errmsg", test_errmsg
,0 },
8838 { "sqlite3_error_offset", test_error_offset
,0 },
8839 { "sqlite3_errmsg16", test_errmsg16
,0 },
8840 { "sqlite3_open", test_open
,0 },
8841 { "sqlite3_open16", test_open16
,0 },
8842 { "sqlite3_open_v2", test_open_v2
,0 },
8843 { "sqlite3_complete16", test_complete16
,0 },
8844 { "sqlite3_normalize", test_normalize
,0 },
8846 { "sqlite3_prepare", test_prepare
,0 },
8847 { "sqlite3_prepare16", test_prepare16
,0 },
8848 { "sqlite3_prepare_v2", test_prepare_v2
,0 },
8849 { "sqlite3_prepare_v3", test_prepare_v3
,0 },
8850 { "sqlite3_prepare_tkt3134", test_prepare_tkt3134
, 0},
8851 { "sqlite3_prepare16_v2", test_prepare16_v2
,0 },
8852 { "sqlite3_finalize", test_finalize
,0 },
8853 { "sqlite3_stmt_status", test_stmt_status
,0 },
8854 { "sqlite3_reset", test_reset
,0 },
8855 { "sqlite3_expired", test_expired
,0 },
8856 { "sqlite3_transfer_bindings", test_transfer_bind
,0 },
8857 { "sqlite3_changes", test_changes
,0 },
8858 { "sqlite3_step", test_step
,0 },
8859 { "sqlite3_sql", test_sql
,0 },
8860 { "sqlite3_expanded_sql", test_ex_sql
,0 },
8861 #ifdef SQLITE_ENABLE_NORMALIZE
8862 { "sqlite3_normalized_sql", test_norm_sql
,0 },
8864 { "sqlite3_next_stmt", test_next_stmt
,0 },
8865 { "sqlite3_stmt_readonly", test_stmt_readonly
,0 },
8866 { "sqlite3_stmt_isexplain", test_stmt_isexplain
,0 },
8867 { "sqlite3_stmt_busy", test_stmt_busy
,0 },
8868 { "uses_stmt_journal", uses_stmt_journal
,0 },
8870 { "sqlite3_release_memory", test_release_memory
, 0},
8871 { "sqlite3_db_release_memory", test_db_release_memory
, 0},
8872 { "sqlite3_db_cacheflush", test_db_cacheflush
, 0},
8873 { "sqlite3_system_errno", test_system_errno
, 0},
8874 { "sqlite3_db_filename", test_db_filename
, 0},
8875 { "sqlite3_db_readonly", test_db_readonly
, 0},
8876 { "sqlite3_soft_heap_limit", test_soft_heap_limit
, 0},
8877 { "sqlite3_soft_heap_limit64", test_soft_heap_limit
, 0},
8878 { "sqlite3_hard_heap_limit64", test_hard_heap_limit
, 0},
8879 { "sqlite3_thread_cleanup", test_thread_cleanup
, 0},
8880 { "sqlite3_pager_refcounts", test_pager_refcounts
, 0},
8882 { "sqlite3_load_extension", test_load_extension
, 0},
8883 { "sqlite3_enable_load_extension", test_enable_load
, 0},
8884 { "sqlite3_extended_result_codes", test_extended_result_codes
, 0},
8885 { "sqlite3_limit", test_limit
, 0},
8886 { "dbconfig_maindbname_icecube", test_dbconfig_maindbname_icecube
},
8888 { "save_prng_state", save_prng_state
, 0 },
8889 { "restore_prng_state", restore_prng_state
, 0 },
8890 { "reset_prng_state", reset_prng_state
, 0 },
8891 { "prng_seed", prng_seed
, 0 },
8892 { "extra_schema_checks", extra_schema_checks
, 0},
8893 { "database_never_corrupt", database_never_corrupt
, 0},
8894 { "database_may_be_corrupt", database_may_be_corrupt
, 0},
8895 { "optimization_control", optimization_control
,0},
8897 { "lock_win32_file", win32_file_lock
, 0 },
8898 { "exists_win32_path", win32_exists_path
, 0 },
8899 { "find_win32_file", win32_find_file
, 0 },
8900 { "delete_win32_file", win32_delete_file
, 0 },
8901 { "make_win32_dir", win32_mkdir
, 0 },
8902 { "remove_win32_dir", win32_rmdir
, 0 },
8904 { "tcl_objproc", runAsObjProc
, 0 },
8906 /* sqlite3_column_*() API */
8907 { "sqlite3_column_count", test_column_count
,0 },
8908 { "sqlite3_data_count", test_data_count
,0 },
8909 { "sqlite3_column_type", test_column_type
,0 },
8910 { "sqlite3_column_blob", test_column_blob
,0 },
8911 { "sqlite3_column_double", test_column_double
,0 },
8912 { "sqlite3_column_int64", test_column_int64
,0 },
8913 { "sqlite3_column_text", test_stmt_utf8
, (void*)sqlite3_column_text
},
8914 { "sqlite3_column_name", test_stmt_utf8
, (void*)sqlite3_column_name
},
8915 { "sqlite3_column_int", test_stmt_int
, (void*)sqlite3_column_int
},
8916 { "sqlite3_column_bytes", test_stmt_int
, (void*)sqlite3_column_bytes
},
8917 #ifndef SQLITE_OMIT_DECLTYPE
8918 { "sqlite3_column_decltype",test_stmt_utf8
,(void*)sqlite3_column_decltype
},
8920 #ifdef SQLITE_ENABLE_COLUMN_METADATA
8921 { "sqlite3_column_database_name",test_stmt_utf8
,(void*)sqlite3_column_database_name
},
8922 { "sqlite3_column_table_name",test_stmt_utf8
,(void*)sqlite3_column_table_name
},
8923 { "sqlite3_column_origin_name",test_stmt_utf8
,(void*)sqlite3_column_origin_name
},
8926 #ifndef SQLITE_OMIT_UTF16
8927 { "sqlite3_column_bytes16", test_stmt_int
, (void*)sqlite3_column_bytes16
},
8928 { "sqlite3_column_text16", test_stmt_utf16
, (void*)sqlite3_column_text16
},
8929 { "sqlite3_column_name16", test_stmt_utf16
, (void*)sqlite3_column_name16
},
8930 { "add_alignment_test_collations", add_alignment_test_collations
, 0 },
8931 #ifndef SQLITE_OMIT_DECLTYPE
8932 { "sqlite3_column_decltype16",test_stmt_utf16
,(void*)sqlite3_column_decltype16
},
8934 #ifdef SQLITE_ENABLE_COLUMN_METADATA
8935 {"sqlite3_column_database_name16",
8936 test_stmt_utf16
, (void*)sqlite3_column_database_name16
},
8937 {"sqlite3_column_table_name16", test_stmt_utf16
, (void*)sqlite3_column_table_name16
},
8938 {"sqlite3_column_origin_name16", test_stmt_utf16
, (void*)sqlite3_column_origin_name16
},
8941 { "sqlite3_create_collation_v2", test_create_collation_v2
, 0 },
8942 { "sqlite3_global_recover", test_global_recover
, 0 },
8943 { "working_64bit_int", working_64bit_int
, 0 },
8944 { "vfs_unlink_test", vfs_unlink_test
, 0 },
8945 { "vfs_initfail_test", vfs_initfail_test
, 0 },
8946 { "vfs_unregister_all", vfs_unregister_all
, 0 },
8947 { "vfs_reregister_all", vfs_reregister_all
, 0 },
8948 { "file_control_test", file_control_test
, 0 },
8949 { "file_control_lasterrno_test", file_control_lasterrno_test
, 0 },
8950 { "file_control_lockproxy_test", file_control_lockproxy_test
, 0 },
8951 { "file_control_chunksize_test", file_control_chunksize_test
, 0 },
8952 { "file_control_sizehint_test", file_control_sizehint_test
, 0 },
8953 { "file_control_data_version", file_control_data_version
, 0 },
8955 { "file_control_win32_av_retry", file_control_win32_av_retry
, 0 },
8956 { "file_control_win32_get_handle", file_control_win32_get_handle
, 0 },
8957 { "file_control_win32_set_handle", file_control_win32_set_handle
, 0 },
8959 { "file_control_persist_wal", file_control_persist_wal
, 0 },
8960 { "file_control_powersafe_overwrite",file_control_powersafe_overwrite
,0},
8961 { "file_control_vfsname", file_control_vfsname
, 0 },
8962 { "file_control_reservebytes", file_control_reservebytes
, 0 },
8963 { "file_control_tempfilename", file_control_tempfilename
, 0 },
8964 { "file_control_external_reader", file_control_external_reader
, 0 },
8965 { "sqlite3_vfs_list", vfs_list
, 0 },
8966 { "sqlite3_create_function_v2", test_create_function_v2
, 0 },
8968 /* Functions from os.h */
8969 #ifndef SQLITE_OMIT_UTF16
8970 { "add_test_collate", test_collate
, 0 },
8971 { "add_test_collate_needed", test_collate_needed
, 0 },
8972 { "add_test_function", test_function
, 0 },
8973 { "add_test_utf16bin_collate", test_utf16bin_collate
, 0 },
8975 { "sqlite3_test_errstr", test_errstr
, 0 },
8976 { "tcl_variable_type", tcl_variable_type
, 0 },
8977 #ifndef SQLITE_OMIT_SHARED_CACHE
8978 { "sqlite3_enable_shared_cache", test_enable_shared
, 0 },
8979 { "sqlite3_shared_cache_report", sqlite3BtreeSharedCacheReport
, 0},
8981 { "sqlite3_libversion_number", test_libversion_number
, 0 },
8982 { "sqlite3_table_column_metadata", test_table_column_metadata
, 0 },
8983 #ifndef SQLITE_OMIT_INCRBLOB
8984 { "sqlite3_blob_reopen", test_blob_reopen
, 0 },
8986 { "pcache_stats", test_pcache_stats
, 0 },
8987 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
8988 { "sqlite3_unlock_notify", test_unlock_notify
, 0 },
8990 { "sqlite3_wal_checkpoint", test_wal_checkpoint
, 0 },
8991 { "sqlite3_wal_checkpoint_v2",test_wal_checkpoint_v2
, 0 },
8992 { "sqlite3_wal_autocheckpoint",test_wal_autocheckpoint
, 0 },
8993 { "test_sqlite3_log", test_sqlite3_log
, 0 },
8994 #ifndef SQLITE_OMIT_EXPLAIN
8995 { "print_explain_query_plan", test_print_eqp
, 0 },
8997 { "sqlite3_test_control", test_test_control
},
8999 { "getrusage", test_getrusage
},
9001 { "load_static_extension", tclLoadStaticExtensionCmd
},
9002 { "sorter_test_fakeheap", sorter_test_fakeheap
},
9003 { "sorter_test_sort4_helper", sorter_test_sort4_helper
},
9004 #ifdef SQLITE_USER_AUTHENTICATION
9005 { "sqlite3_user_authenticate", test_user_authenticate
, 0 },
9006 { "sqlite3_user_add", test_user_add
, 0 },
9007 { "sqlite3_user_change", test_user_change
, 0 },
9008 { "sqlite3_user_delete", test_user_delete
, 0 },
9010 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
9011 { "sqlite3_stmt_scanstatus", test_stmt_scanstatus
, 0 },
9012 { "sqlite3_stmt_scanstatus_reset", test_stmt_scanstatus_reset
, 0 },
9014 #ifdef SQLITE_ENABLE_SQLLOG
9015 { "sqlite3_config_sqllog", test_config_sqllog
, 0 },
9017 { "vfs_current_time_int64", vfsCurrentTimeInt64
, 0 },
9018 #ifdef SQLITE_ENABLE_SNAPSHOT
9019 { "sqlite3_snapshot_get", test_snapshot_get
, 0 },
9020 { "sqlite3_snapshot_open", test_snapshot_open
, 0 },
9021 { "sqlite3_snapshot_free", test_snapshot_free
, 0 },
9022 { "sqlite3_snapshot_cmp", test_snapshot_cmp
, 0 },
9023 { "sqlite3_snapshot_recover", test_snapshot_recover
, 0 },
9024 { "sqlite3_snapshot_get_blob", test_snapshot_get_blob
, 0 },
9025 { "sqlite3_snapshot_open_blob", test_snapshot_open_blob
, 0 },
9026 { "sqlite3_snapshot_cmp_blob", test_snapshot_cmp_blob
, 0 },
9028 { "sqlite3_delete_database", test_delete_database
, 0 },
9029 { "atomic_batch_write", test_atomic_batch_write
, 0 },
9030 { "sqlite3_mmap_warm", test_mmap_warm
, 0 },
9031 { "sqlite3_config_sorterref", test_config_sorterref
, 0 },
9032 { "sqlite3_autovacuum_pages", test_autovacuum_pages
, 0 },
9033 { "decode_hexdb", test_decode_hexdb
, 0 },
9034 { "test_write_db", test_write_db
, 0 },
9035 { "sqlite3_register_cksumvfs", test_register_cksumvfs
, 0 },
9036 { "sqlite3_unregister_cksumvfs", test_unregister_cksumvfs
, 0 },
9037 { "number_of_cores", guess_number_of_cores
, 0 },
9038 #ifndef SQLITE_OMIT_VIRTUALTABLE
9039 { "create_null_module", test_create_null_module
, 0 },
9042 static int bitmask_size
= sizeof(Bitmask
)*8;
9043 static int longdouble_size
= sizeof(LONGDOUBLE_TYPE
);
9045 extern int sqlite3_sync_count
, sqlite3_fullsync_count
;
9046 extern int sqlite3_opentemp_count
;
9047 extern int sqlite3_like_count
;
9048 extern int sqlite3_xferopt_count
;
9049 extern int sqlite3_pager_readdb_count
;
9050 extern int sqlite3_pager_writedb_count
;
9051 extern int sqlite3_pager_writej_count
;
9053 extern LONG
volatile sqlite3_os_type
;
9056 extern u32 sqlite3WhereTrace
;
9057 extern int sqlite3OSTrace
;
9058 extern int sqlite3WalTrace
;
9061 #ifdef SQLITE_ENABLE_FTS3
9062 extern int sqlite3_fts3_enable_parentheses
;
9066 for(i
=0; i
<sizeof(aCmd
)/sizeof(aCmd
[0]); i
++){
9067 Tcl_CreateCommand(interp
, aCmd
[i
].zName
, aCmd
[i
].xProc
, 0, 0);
9069 for(i
=0; i
<sizeof(aObjCmd
)/sizeof(aObjCmd
[0]); i
++){
9070 Tcl_CreateObjCommand(interp
, aObjCmd
[i
].zName
,
9071 aObjCmd
[i
].xProc
, aObjCmd
[i
].clientData
, 0);
9073 Tcl_LinkVar(interp
, "sqlite_search_count",
9074 (char*)&sqlite3_search_count
, TCL_LINK_INT
);
9075 Tcl_LinkVar(interp
, "sqlite_found_count",
9076 (char*)&sqlite3_found_count
, TCL_LINK_INT
);
9077 Tcl_LinkVar(interp
, "sqlite_sort_count",
9078 (char*)&sqlite3_sort_count
, TCL_LINK_INT
);
9079 Tcl_LinkVar(interp
, "sqlite3_max_blobsize",
9080 (char*)&sqlite3_max_blobsize
, TCL_LINK_INT
);
9081 Tcl_LinkVar(interp
, "sqlite_like_count",
9082 (char*)&sqlite3_like_count
, TCL_LINK_INT
);
9083 Tcl_LinkVar(interp
, "sqlite_interrupt_count",
9084 (char*)&sqlite3_interrupt_count
, TCL_LINK_INT
);
9085 Tcl_LinkVar(interp
, "sqlite_open_file_count",
9086 (char*)&sqlite3_open_file_count
, TCL_LINK_INT
);
9087 Tcl_LinkVar(interp
, "sqlite_current_time",
9088 (char*)&sqlite3_current_time
, TCL_LINK_INT
);
9089 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
9090 Tcl_LinkVar(interp
, "sqlite_hostid_num",
9091 (char*)&sqlite3_hostid_num
, TCL_LINK_INT
);
9093 Tcl_LinkVar(interp
, "sqlite3_xferopt_count",
9094 (char*)&sqlite3_xferopt_count
, TCL_LINK_INT
);
9095 Tcl_LinkVar(interp
, "sqlite3_pager_readdb_count",
9096 (char*)&sqlite3_pager_readdb_count
, TCL_LINK_INT
);
9097 Tcl_LinkVar(interp
, "sqlite3_pager_writedb_count",
9098 (char*)&sqlite3_pager_writedb_count
, TCL_LINK_INT
);
9099 Tcl_LinkVar(interp
, "sqlite3_pager_writej_count",
9100 (char*)&sqlite3_pager_writej_count
, TCL_LINK_INT
);
9101 #ifndef SQLITE_OMIT_UTF16
9102 Tcl_LinkVar(interp
, "unaligned_string_counter",
9103 (char*)&unaligned_string_counter
, TCL_LINK_INT
);
9105 #ifndef SQLITE_OMIT_UTF16
9106 Tcl_LinkVar(interp
, "sqlite_last_needed_collation",
9107 (char*)&pzNeededCollation
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
9110 Tcl_LinkVar(interp
, "sqlite_os_type",
9111 (char*)&sqlite3_os_type
, TCL_LINK_LONG
);
9115 static const char *query_plan
= "*** OBSOLETE VARIABLE ***";
9116 Tcl_LinkVar(interp
, "sqlite_query_plan",
9117 (char*)&query_plan
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
9121 Tcl_LinkVar(interp
, "sqlite_where_trace",
9122 (char*)&sqlite3WhereTrace
, TCL_LINK_INT
);
9123 Tcl_LinkVar(interp
, "sqlite_os_trace",
9124 (char*)&sqlite3OSTrace
, TCL_LINK_INT
);
9125 #ifndef SQLITE_OMIT_WAL
9126 Tcl_LinkVar(interp
, "sqlite_wal_trace",
9127 (char*)&sqlite3WalTrace
, TCL_LINK_INT
);
9130 #ifndef SQLITE_OMIT_DISKIO
9131 Tcl_LinkVar(interp
, "sqlite_opentemp_count",
9132 (char*)&sqlite3_opentemp_count
, TCL_LINK_INT
);
9134 Tcl_LinkVar(interp
, "sqlite_static_bind_value",
9135 (char*)&sqlite_static_bind_value
, TCL_LINK_STRING
);
9136 Tcl_LinkVar(interp
, "sqlite_static_bind_nbyte",
9137 (char*)&sqlite_static_bind_nbyte
, TCL_LINK_INT
);
9138 Tcl_LinkVar(interp
, "sqlite_temp_directory",
9139 (char*)&sqlite3_temp_directory
, TCL_LINK_STRING
);
9140 Tcl_LinkVar(interp
, "sqlite_data_directory",
9141 (char*)&sqlite3_data_directory
, TCL_LINK_STRING
);
9142 Tcl_LinkVar(interp
, "bitmask_size",
9143 (char*)&bitmask_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
9144 Tcl_LinkVar(interp
, "longdouble_size",
9145 (char*)&longdouble_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
9146 Tcl_LinkVar(interp
, "sqlite_sync_count",
9147 (char*)&sqlite3_sync_count
, TCL_LINK_INT
);
9148 Tcl_LinkVar(interp
, "sqlite_fullsync_count",
9149 (char*)&sqlite3_fullsync_count
, TCL_LINK_INT
);
9150 #if defined(SQLITE_ENABLE_TREETRACE)
9151 Tcl_LinkVar(interp
, "sqlite3_unsupported_treetrace",
9152 (char*)&sqlite3TreeTrace
, TCL_LINK_INT
);
9154 #if defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_TEST)
9155 Tcl_LinkVar(interp
, "sqlite_fts3_enable_parentheses",
9156 (char*)&sqlite3_fts3_enable_parentheses
, TCL_LINK_INT
);