4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
12 ** Code for testing all sorts of SQLite interfaces. This code
13 ** is not included in the SQLite library. It is used for automated
14 ** testing of the SQLite library.
16 #include "sqliteInt.h"
22 #if defined(INCLUDE_SQLITE_TCL_H)
23 # include "sqlite_tcl.h"
31 ** This is a copy of the first part of the SqliteDb structure in
32 ** tclsqlite.c. We need it here so that the get_sqlite_pointer routine
33 ** can extract the sqlite3* pointer from an existing Tcl SQLite
41 ** Convert text generated by the "%p" conversion format back into
44 static int testHexToInt(int h
){
45 if( h
>='0' && h
<='9' ){
47 }else if( h
>='a' && h
<='f' ){
50 assert( h
>='A' && h
<='F' );
54 void *sqlite3TestTextToPtr(const char *z
){
58 if( z
[0]=='0' && z
[1]=='x' ){
63 v
= (v
<<4) + testHexToInt(*z
);
66 if( sizeof(p
)==sizeof(v
) ){
67 memcpy(&p
, &v
, sizeof(p
));
69 assert( sizeof(p
)==sizeof(v2
) );
71 memcpy(&p
, &v2
, sizeof(p
));
78 ** A TCL command that returns the address of the sqlite* pointer
79 ** for an sqlite connection instance. Bad things happen if the
80 ** input is not an sqlite connection.
82 static int SQLITE_TCLAPI
get_sqlite_pointer(
92 Tcl_WrongNumArgs(interp
, 1, objv
, "SQLITE-CONNECTION");
95 if( !Tcl_GetCommandInfo(interp
, Tcl_GetString(objv
[1]), &cmdInfo
) ){
96 Tcl_AppendResult(interp
, "command not found: ",
97 Tcl_GetString(objv
[1]), (char*)0);
100 p
= (struct SqliteDb
*)cmdInfo
.objClientData
;
101 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%p", p
->db
);
102 Tcl_AppendResult(interp
, zBuf
, 0);
107 ** Decode a pointer to an sqlite3 object.
109 int getDbPointer(Tcl_Interp
*interp
, const char *zA
, sqlite3
**ppDb
){
112 if( Tcl_GetCommandInfo(interp
, zA
, &cmdInfo
) ){
113 p
= (struct SqliteDb
*)cmdInfo
.objClientData
;
116 *ppDb
= (sqlite3
*)sqlite3TestTextToPtr(zA
);
123 ** Decode a Win32 HANDLE object.
125 int getWin32Handle(Tcl_Interp
*interp
, const char *zA
, LPHANDLE phFile
){
126 *phFile
= (HANDLE
)sqlite3TestTextToPtr(zA
);
131 extern const char *sqlite3ErrName(int);
132 #define t1ErrorName sqlite3ErrName
135 ** Convert an sqlite3_stmt* into an sqlite3*. This depends on the
136 ** fact that the sqlite3* is the first field in the Vdbe structure.
138 #define StmtToDb(X) sqlite3_db_handle(X)
141 ** Check a return value to make sure it agrees with the results
142 ** from sqlite3_errcode.
144 int sqlite3TestErrCode(Tcl_Interp
*interp
, sqlite3
*db
, int rc
){
145 if( sqlite3_threadsafe()==0 && rc
!=SQLITE_MISUSE
&& rc
!=SQLITE_OK
146 && sqlite3_errcode(db
)!=rc
){
148 int r2
= sqlite3_errcode(db
);
149 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
150 "error code %s (%d) does not match sqlite3_errcode %s (%d)",
151 t1ErrorName(rc
), rc
, t1ErrorName(r2
), r2
);
152 Tcl_ResetResult(interp
);
153 Tcl_AppendResult(interp
, zBuf
, 0);
160 ** Decode a pointer to an sqlite3_stmt object.
162 static int getStmtPointer(
165 sqlite3_stmt
**ppStmt
167 *ppStmt
= (sqlite3_stmt
*)sqlite3TestTextToPtr(zArg
);
172 ** Generate a text representation of a pointer that can be understood
173 ** by the getDbPointer and getVmPointer routines above.
175 ** The problem is, on some machines (Solaris) if you do a printf with
176 ** "%p" you cannot turn around and do a scanf with the same "%p" and
177 ** get your pointer back. You have to prepend a "0x" before it will
178 ** work. Or at least that is what is reported to me (drh). But this
179 ** behavior varies from machine to machine. The solution used her is
180 ** to test the string right after it is generated to see if it can be
181 ** understood by scanf, and if not, try prepending an "0x" to see if
182 ** that helps. If nothing works, a fatal error is generated.
184 int sqlite3TestMakePointerStr(Tcl_Interp
*interp
, char *zPtr
, void *p
){
185 sqlite3_snprintf(100, zPtr
, "%p", p
);
190 ** The callback routine for sqlite3_exec_printf().
192 static int exec_printf_cb(void *pArg
, int argc
, char **argv
, char **name
){
193 Tcl_DString
*str
= (Tcl_DString
*)pArg
;
196 if( Tcl_DStringLength(str
)==0 ){
197 for(i
=0; i
<argc
; i
++){
198 Tcl_DStringAppendElement(str
, name
[i
] ? name
[i
] : "NULL");
201 for(i
=0; i
<argc
; i
++){
202 Tcl_DStringAppendElement(str
, argv
[i
] ? argv
[i
] : "NULL");
208 ** The I/O tracing callback.
210 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
211 static FILE *iotrace_file
= 0;
212 static void io_trace_callback(const char *zFormat
, ...){
214 va_start(ap
, zFormat
);
215 vfprintf(iotrace_file
, zFormat
, ap
);
217 fflush(iotrace_file
);
222 ** Usage: io_trace FILENAME
224 ** Turn I/O tracing on or off. If FILENAME is not an empty string,
225 ** I/O tracing begins going into FILENAME. If FILENAME is an empty
226 ** string, I/O tracing is turned off.
228 static int SQLITE_TCLAPI
test_io_trace(
230 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
231 int argc
, /* Number of arguments */
232 char **argv
/* Text of each argument */
234 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
236 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
241 if( iotrace_file
!=stdout
&& iotrace_file
!=stderr
){
242 fclose(iotrace_file
);
248 if( strcmp(argv
[1],"stdout")==0 ){
249 iotrace_file
= stdout
;
250 }else if( strcmp(argv
[1],"stderr")==0 ){
251 iotrace_file
= stderr
;
253 iotrace_file
= fopen(argv
[1], "w");
255 sqlite3IoTrace
= io_trace_callback
;
262 ** Usage: clang_sanitize_address
264 ** Returns true if the program was compiled using clang with the
265 ** -fsanitize=address switch on the command line. False otherwise.
267 ** Also return true if the OMIT_MISUSE environment variable exists.
269 static int SQLITE_TCLAPI
clang_sanitize_address(
271 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
272 int argc
, /* Number of arguments */
273 char **argv
/* Text of each argument */
276 #if defined(__has_feature)
277 # if __has_feature(address_sanitizer)
281 #ifdef __SANITIZE_ADDRESS__
284 if( res
==0 && getenv("OMIT_MISUSE")!=0 ) res
= 1;
285 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
290 ** Usage: sqlite3_exec_printf DB FORMAT STRING
292 ** Invoke the sqlite3_exec_printf() interface using the open database
293 ** DB. The SQL is the string FORMAT. The format string should contain
294 ** one %s or %q. STRING is the value inserted into %s or %q.
296 static int SQLITE_TCLAPI
test_exec_printf(
298 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
299 int argc
, /* Number of arguments */
300 char **argv
/* Text of each argument */
309 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
310 " DB FORMAT STRING", 0);
313 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
314 Tcl_DStringInit(&str
);
315 zSql
= sqlite3_mprintf(argv
[2], argv
[3]);
316 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
318 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
319 Tcl_AppendElement(interp
, zBuf
);
320 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
321 Tcl_DStringFree(&str
);
322 if( zErr
) sqlite3_free(zErr
);
323 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
328 ** Usage: sqlite3_exec_hex DB HEX
330 ** Invoke the sqlite3_exec() on a string that is obtained by translating
331 ** HEX into ASCII. Most characters are translated as is. %HH becomes
334 static int SQLITE_TCLAPI
test_exec_hex(
336 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
337 int argc
, /* Number of arguments */
338 char **argv
/* Text of each argument */
348 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
352 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
354 for(i
=j
=0; i
<(sizeof(zSql
)-1) && zHex
[j
]; i
++, j
++){
355 if( zHex
[j
]=='%' && zHex
[j
+2] && zHex
[j
+2] ){
356 zSql
[i
] = (testHexToInt(zHex
[j
+1])<<4) + testHexToInt(zHex
[j
+2]);
363 Tcl_DStringInit(&str
);
364 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
365 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
366 Tcl_AppendElement(interp
, zBuf
);
367 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
368 Tcl_DStringFree(&str
);
369 if( zErr
) sqlite3_free(zErr
);
370 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
375 ** Usage: db_enter DB
378 ** Enter or leave the mutex on a database connection.
380 static int SQLITE_TCLAPI
db_enter(
382 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
383 int argc
, /* Number of arguments */
384 char **argv
/* Text of each argument */
388 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
392 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
393 sqlite3_mutex_enter(db
->mutex
);
396 static int SQLITE_TCLAPI
db_leave(
398 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
399 int argc
, /* Number of arguments */
400 char **argv
/* Text of each argument */
404 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
408 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
409 sqlite3_mutex_leave(db
->mutex
);
414 ** Usage: sqlite3_exec DB SQL
416 ** Invoke the sqlite3_exec interface using the open database DB
418 static int SQLITE_TCLAPI
test_exec(
420 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
421 int argc
, /* Number of arguments */
422 char **argv
/* Text of each argument */
432 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
436 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
437 Tcl_DStringInit(&str
);
438 zSql
= sqlite3_mprintf("%s", argv
[2]);
439 for(i
=j
=0; zSql
[i
];){
441 zSql
[j
++] = (testHexToInt(zSql
[i
+1])<<4) + testHexToInt(zSql
[i
+2]);
444 zSql
[j
++] = zSql
[i
++];
448 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
450 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
451 Tcl_AppendElement(interp
, zBuf
);
452 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
453 Tcl_DStringFree(&str
);
454 if( zErr
) sqlite3_free(zErr
);
455 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
460 ** Usage: sqlite3_exec_nr DB SQL
462 ** Invoke the sqlite3_exec interface using the open database DB. Discard
465 static int SQLITE_TCLAPI
test_exec_nr(
467 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
468 int argc
, /* Number of arguments */
469 char **argv
/* Text of each argument */
475 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
479 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
480 rc
= sqlite3_exec(db
, argv
[2], 0, 0, &zErr
);
481 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
486 ** Usage: sqlite3_mprintf_z_test SEPARATOR ARG0 ARG1 ...
488 ** Test the %z format of sqlite_mprintf(). Use multiple mprintf() calls to
489 ** concatenate arg0 through argn using separator as the separator.
490 ** Return the result.
492 static int SQLITE_TCLAPI
test_mprintf_z(
494 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
495 int argc
, /* Number of arguments */
496 char **argv
/* Text of each argument */
501 for(i
=2; i
<argc
&& (i
==2 || zResult
); i
++){
502 zResult
= sqlite3_mprintf("%z%s%s", zResult
, argv
[1], argv
[i
]);
504 Tcl_AppendResult(interp
, zResult
, 0);
505 sqlite3_free(zResult
);
510 ** Usage: sqlite3_mprintf_n_test STRING
512 ** Test the %n format of sqlite_mprintf(). Return the length of the
515 static int SQLITE_TCLAPI
test_mprintf_n(
517 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
518 int argc
, /* Number of arguments */
519 char **argv
/* Text of each argument */
523 zStr
= sqlite3_mprintf("%s%n", argv
[1], &n
);
525 Tcl_SetObjResult(interp
, Tcl_NewIntObj(n
));
530 ** Usage: sqlite3_snprintf_int SIZE FORMAT INT
532 ** Test the of sqlite3_snprintf() routine. SIZE is the size of the
533 ** output buffer in bytes. The maximum size is 100. FORMAT is the
534 ** format string. INT is a single integer argument. The FORMAT
535 ** string must require no more than this one integer argument. If
536 ** You pass in a format string that requires more than one argument,
537 ** bad things will happen.
539 static int SQLITE_TCLAPI
test_snprintf_int(
541 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
542 int argc
, /* Number of arguments */
543 char **argv
/* Text of each argument */
546 int n
= atoi(argv
[1]);
547 const char *zFormat
= argv
[2];
548 int a1
= atoi(argv
[3]);
549 if( n
>sizeof(zStr
) ) n
= sizeof(zStr
);
550 sqlite3_snprintf(sizeof(zStr
), zStr
, "abcdefghijklmnopqrstuvwxyz");
551 sqlite3_snprintf(n
, zStr
, zFormat
, a1
);
552 Tcl_AppendResult(interp
, zStr
, 0);
556 #ifndef SQLITE_OMIT_GET_TABLE
559 ** Usage: sqlite3_get_table_printf DB FORMAT STRING ?--no-counts?
561 ** Invoke the sqlite3_get_table_printf() interface using the open database
562 ** DB. The SQL is the string FORMAT. The format string should contain
563 ** one %s or %q. STRING is the value inserted into %s or %q.
565 static int SQLITE_TCLAPI
test_get_table_printf(
567 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
568 int argc
, /* Number of arguments */
569 char **argv
/* Text of each argument */
575 int nRow
= 0, nCol
= 0;
582 if( Tcl_GetInt(interp
, argv
[4], &resCount
) ) return TCL_ERROR
;
584 if( argc
!=4 && argc
!=5 ){
585 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
586 " DB FORMAT STRING ?COUNT?", 0);
589 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
590 Tcl_DStringInit(&str
);
591 zSql
= sqlite3_mprintf(argv
[2],argv
[3]);
593 rc
= sqlite3_get_table(db
, zSql
, &aResult
, 0, 0, &zErr
);
595 rc
= sqlite3_get_table(db
, zSql
, &aResult
, &nRow
, &nCol
, &zErr
);
596 resCount
= (nRow
+1)*nCol
;
599 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
600 Tcl_AppendElement(interp
, zBuf
);
603 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", nRow
);
604 Tcl_AppendElement(interp
, zBuf
);
605 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", nCol
);
606 Tcl_AppendElement(interp
, zBuf
);
608 for(i
=0; i
<resCount
; i
++){
609 Tcl_AppendElement(interp
, aResult
[i
] ? aResult
[i
] : "NULL");
612 Tcl_AppendElement(interp
, zErr
);
614 sqlite3_free_table(aResult
);
615 if( zErr
) sqlite3_free(zErr
);
616 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
620 #endif /* SQLITE_OMIT_GET_TABLE */
624 ** Usage: sqlite3_last_insert_rowid DB
626 ** Returns the integer ROWID of the most recent insert.
628 static int SQLITE_TCLAPI
test_last_rowid(
630 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
631 int argc
, /* Number of arguments */
632 char **argv
/* Text of each argument */
638 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB\"", 0);
641 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
642 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%lld", sqlite3_last_insert_rowid(db
));
643 Tcl_AppendResult(interp
, zBuf
, 0);
648 ** Usage: sqlite3_key DB KEY
650 ** Set the codec key.
652 static int SQLITE_TCLAPI
test_key(
654 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
655 int argc
, /* Number of arguments */
656 char **argv
/* Text of each argument */
658 #if defined(SQLITE_HAS_CODEC) && !defined(SQLITE_OMIT_CODEC_FROM_TCL)
663 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
667 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
670 sqlite3_key(db
, zKey
, nKey
);
676 ** Usage: sqlite3_rekey DB KEY
678 ** Change the codec key.
680 static int SQLITE_TCLAPI
test_rekey(
682 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
683 int argc
, /* Number of arguments */
684 char **argv
/* Text of each argument */
686 #ifdef SQLITE_HAS_CODEC
691 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
695 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
698 sqlite3_rekey(db
, zKey
, nKey
);
704 ** Usage: sqlite3_close DB
706 ** Closes the database opened by sqlite3_open.
708 static int SQLITE_TCLAPI
sqlite_test_close(
710 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
711 int argc
, /* Number of arguments */
712 char **argv
/* Text of each argument */
717 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
721 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
722 rc
= sqlite3_close(db
);
723 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
728 ** Usage: sqlite3_close_v2 DB
730 ** Closes the database opened by sqlite3_open.
732 static int SQLITE_TCLAPI
sqlite_test_close_v2(
734 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
735 int argc
, /* Number of arguments */
736 char **argv
/* Text of each argument */
741 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
745 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
746 rc
= sqlite3_close_v2(db
);
747 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
752 ** Implementation of the x_coalesce() function.
753 ** Return the first argument non-NULL argument.
755 static void t1_ifnullFunc(
756 sqlite3_context
*context
,
761 for(i
=0; i
<argc
; i
++){
762 if( SQLITE_NULL
!=sqlite3_value_type(argv
[i
]) ){
763 int n
= sqlite3_value_bytes(argv
[i
]);
764 sqlite3_result_text(context
, (char*)sqlite3_value_text(argv
[i
]),
765 n
, SQLITE_TRANSIENT
);
772 ** These are test functions. hex8() interprets its argument as
773 ** UTF8 and returns a hex encoding. hex16le() interprets its argument
774 ** as UTF16le and returns a hex encoding.
776 static void hex8Func(sqlite3_context
*p
, int argc
, sqlite3_value
**argv
){
777 const unsigned char *z
;
780 z
= sqlite3_value_text(argv
[0]);
781 for(i
=0; i
<sizeof(zBuf
)/2 - 2 && z
[i
]; i
++){
782 sqlite3_snprintf(sizeof(zBuf
)-i
*2, &zBuf
[i
*2], "%02x", z
[i
]);
785 sqlite3_result_text(p
, (char*)zBuf
, -1, SQLITE_TRANSIENT
);
787 #ifndef SQLITE_OMIT_UTF16
788 static void hex16Func(sqlite3_context
*p
, int argc
, sqlite3_value
**argv
){
789 const unsigned short int *z
;
792 z
= sqlite3_value_text16(argv
[0]);
793 for(i
=0; i
<sizeof(zBuf
)/4 - 4 && z
[i
]; i
++){
794 sqlite3_snprintf(sizeof(zBuf
)-i
*4, &zBuf
[i
*4],"%04x", z
[i
]&0xff);
797 sqlite3_result_text(p
, (char*)zBuf
, -1, SQLITE_TRANSIENT
);
802 ** A structure into which to accumulate text.
805 int nAlloc
; /* Space allocated */
806 int nUsed
; /* Space used */
807 char *z
; /* The space */
811 ** Append text to a dstr
813 static void dstrAppend(struct dstr
*p
, const char *z
, int divider
){
814 int n
= (int)strlen(z
);
815 if( p
->nUsed
+ n
+ 2 > p
->nAlloc
){
817 p
->nAlloc
= p
->nAlloc
*2 + n
+ 200;
818 zNew
= sqlite3_realloc(p
->z
, p
->nAlloc
);
821 memset(p
, 0, sizeof(*p
));
826 if( divider
&& p
->nUsed
>0 ){
827 p
->z
[p
->nUsed
++] = divider
;
829 memcpy(&p
->z
[p
->nUsed
], z
, n
+1);
834 ** Invoked for each callback from sqlite3ExecFunc
836 static int execFuncCallback(void *pData
, int argc
, char **argv
, char **NotUsed
){
837 struct dstr
*p
= (struct dstr
*)pData
;
839 for(i
=0; i
<argc
; i
++){
841 dstrAppend(p
, "NULL", ' ');
843 dstrAppend(p
, argv
[i
], ' ');
850 ** Implementation of the x_sqlite_exec() function. This function takes
851 ** a single argument and attempts to execute that argument as SQL code.
852 ** This is illegal and should set the SQLITE_MISUSE flag on the database.
854 ** 2004-Jan-07: We have changed this to make it legal to call sqlite3_exec()
855 ** from within a function call.
857 ** This routine simulates the effect of having two threads attempt to
858 ** use the same database at the same time.
860 static void sqlite3ExecFunc(
861 sqlite3_context
*context
,
866 memset(&x
, 0, sizeof(x
));
867 (void)sqlite3_exec((sqlite3
*)sqlite3_user_data(context
),
868 (char*)sqlite3_value_text(argv
[0]),
869 execFuncCallback
, &x
, 0);
870 sqlite3_result_text(context
, x
.z
, x
.nUsed
, SQLITE_TRANSIENT
);
875 ** Implementation of tkt2213func(), a scalar function that takes exactly
876 ** one argument. It has two interesting features:
878 ** * It calls sqlite3_value_text() 3 times on the argument sqlite3_value*.
879 ** If the three pointers returned are not the same an SQL error is raised.
881 ** * Otherwise it returns a copy of the text representation of its
882 ** argument in such a way as the VDBE representation is a Mem* cell
883 ** with the MEM_Term flag clear.
885 ** Ticket #2213 can therefore be tested by evaluating the following
888 ** tkt2213func(tkt2213func('a string'));
890 static void tkt2213Function(
891 sqlite3_context
*context
,
896 unsigned char const *zText1
;
897 unsigned char const *zText2
;
898 unsigned char const *zText3
;
900 nText
= sqlite3_value_bytes(argv
[0]);
901 zText1
= sqlite3_value_text(argv
[0]);
902 zText2
= sqlite3_value_text(argv
[0]);
903 zText3
= sqlite3_value_text(argv
[0]);
905 if( zText1
!=zText2
|| zText2
!=zText3
){
906 sqlite3_result_error(context
, "tkt2213 is not fixed", -1);
908 char *zCopy
= (char *)sqlite3_malloc(nText
);
909 memcpy(zCopy
, zText1
, nText
);
910 sqlite3_result_text(context
, zCopy
, nText
, sqlite3_free
);
915 ** The following SQL function takes 4 arguments. The 2nd and
916 ** 4th argument must be one of these strings: 'text', 'text16',
917 ** or 'blob' corresponding to API functions
919 ** sqlite3_value_text()
920 ** sqlite3_value_text16()
921 ** sqlite3_value_blob()
923 ** The third argument is a string, either 'bytes' or 'bytes16' or 'noop',
924 ** corresponding to APIs:
926 ** sqlite3_value_bytes()
927 ** sqlite3_value_bytes16()
930 ** The APIs designated by the 2nd through 4th arguments are applied
931 ** to the first argument in order. If the pointers returned by the
932 ** second and fourth are different, this routine returns 1. Otherwise,
933 ** this routine returns 0.
935 ** This function is used to test to see when returned pointers from
936 ** the _text(), _text16() and _blob() APIs become invalidated.
938 static void ptrChngFunction(
939 sqlite3_context
*context
,
945 if( argc
!=4 ) return;
946 zCmd
= (const char*)sqlite3_value_text(argv
[1]);
947 if( zCmd
==0 ) return;
948 if( strcmp(zCmd
,"text")==0 ){
949 p1
= (const void*)sqlite3_value_text(argv
[0]);
950 #ifndef SQLITE_OMIT_UTF16
951 }else if( strcmp(zCmd
, "text16")==0 ){
952 p1
= (const void*)sqlite3_value_text16(argv
[0]);
954 }else if( strcmp(zCmd
, "blob")==0 ){
955 p1
= (const void*)sqlite3_value_blob(argv
[0]);
959 zCmd
= (const char*)sqlite3_value_text(argv
[2]);
960 if( zCmd
==0 ) return;
961 if( strcmp(zCmd
,"bytes")==0 ){
962 sqlite3_value_bytes(argv
[0]);
963 #ifndef SQLITE_OMIT_UTF16
964 }else if( strcmp(zCmd
, "bytes16")==0 ){
965 sqlite3_value_bytes16(argv
[0]);
967 }else if( strcmp(zCmd
, "noop")==0 ){
972 zCmd
= (const char*)sqlite3_value_text(argv
[3]);
973 if( zCmd
==0 ) return;
974 if( strcmp(zCmd
,"text")==0 ){
975 p2
= (const void*)sqlite3_value_text(argv
[0]);
976 #ifndef SQLITE_OMIT_UTF16
977 }else if( strcmp(zCmd
, "text16")==0 ){
978 p2
= (const void*)sqlite3_value_text16(argv
[0]);
980 }else if( strcmp(zCmd
, "blob")==0 ){
981 p2
= (const void*)sqlite3_value_blob(argv
[0]);
985 sqlite3_result_int(context
, p1
!=p2
);
989 ** This SQL function returns a different answer each time it is called, even if
990 ** the arguments are the same.
992 static void nondeterministicFunction(
993 sqlite3_context
*context
,
998 sqlite3_result_int(context
, cnt
++);
1002 ** Usage: sqlite3_create_function DB
1004 ** Call the sqlite3_create_function API on the given database in order
1005 ** to create a function named "x_coalesce". This function does the same thing
1006 ** as the "coalesce" function. This function also registers an SQL function
1007 ** named "x_sqlite_exec" that invokes sqlite3_exec(). Invoking sqlite3_exec()
1008 ** in this way is illegal recursion and should raise an SQLITE_MISUSE error.
1009 ** The effect is similar to trying to use the same database connection from
1010 ** two threads at the same time.
1012 ** The original motivation for this routine was to be able to call the
1013 ** sqlite3_create_function function while a query is in progress in order
1014 ** to test the SQLITE_MISUSE detection logic.
1016 static int SQLITE_TCLAPI
test_create_function(
1018 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1019 int argc
, /* Number of arguments */
1020 char **argv
/* Text of each argument */
1026 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1030 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1031 rc
= sqlite3_create_function(db
, "x_coalesce", -1, SQLITE_UTF8
, 0,
1032 t1_ifnullFunc
, 0, 0);
1033 if( rc
==SQLITE_OK
){
1034 rc
= sqlite3_create_function(db
, "hex8", 1, SQLITE_UTF8
| SQLITE_DETERMINISTIC
,
1037 #ifndef SQLITE_OMIT_UTF16
1038 if( rc
==SQLITE_OK
){
1039 rc
= sqlite3_create_function(db
, "hex16", 1, SQLITE_UTF16
| SQLITE_DETERMINISTIC
,
1040 0, hex16Func
, 0, 0);
1043 if( rc
==SQLITE_OK
){
1044 rc
= sqlite3_create_function(db
, "tkt2213func", 1, SQLITE_ANY
, 0,
1045 tkt2213Function
, 0, 0);
1047 if( rc
==SQLITE_OK
){
1048 rc
= sqlite3_create_function(db
, "pointer_change", 4, SQLITE_ANY
, 0,
1049 ptrChngFunction
, 0, 0);
1052 /* Functions counter1() and counter2() have the same implementation - they
1053 ** both return an ascending integer with each call. But counter1() is marked
1054 ** as non-deterministic and counter2() is marked as deterministic.
1056 if( rc
==SQLITE_OK
){
1057 rc
= sqlite3_create_function(db
, "counter1", -1, SQLITE_UTF8
,
1058 0, nondeterministicFunction
, 0, 0);
1060 if( rc
==SQLITE_OK
){
1061 rc
= sqlite3_create_function(db
, "counter2", -1, SQLITE_UTF8
|SQLITE_DETERMINISTIC
,
1062 0, nondeterministicFunction
, 0, 0);
1065 #ifndef SQLITE_OMIT_UTF16
1066 /* Use the sqlite3_create_function16() API here. Mainly for fun, but also
1067 ** because it is not tested anywhere else. */
1068 if( rc
==SQLITE_OK
){
1070 sqlite3_value
*pVal
;
1071 sqlite3_mutex_enter(db
->mutex
);
1072 pVal
= sqlite3ValueNew(db
);
1073 sqlite3ValueSetStr(pVal
, -1, "x_sqlite_exec", SQLITE_UTF8
, SQLITE_STATIC
);
1074 zUtf16
= sqlite3ValueText(pVal
, SQLITE_UTF16NATIVE
);
1075 if( db
->mallocFailed
){
1078 rc
= sqlite3_create_function16(db
, zUtf16
,
1079 1, SQLITE_UTF16
, db
, sqlite3ExecFunc
, 0, 0);
1081 sqlite3ValueFree(pVal
);
1082 sqlite3_mutex_leave(db
->mutex
);
1086 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
1087 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
1092 ** Routines to implement the x_count() aggregate function.
1094 ** x_count() counts the number of non-null arguments. But there are
1095 ** some twists for testing purposes.
1097 ** If the argument to x_count() is 40 then a UTF-8 error is reported
1098 ** on the step function. If x_count(41) is seen, then a UTF-16 error
1099 ** is reported on the step function. If the total count is 42, then
1100 ** a UTF-8 error is reported on the finalize function.
1102 typedef struct t1CountCtx t1CountCtx
;
1106 static void t1CountStep(
1107 sqlite3_context
*context
,
1109 sqlite3_value
**argv
1112 p
= sqlite3_aggregate_context(context
, sizeof(*p
));
1113 if( (argc
==0 || SQLITE_NULL
!=sqlite3_value_type(argv
[0]) ) && p
){
1117 int v
= sqlite3_value_int(argv
[0]);
1119 sqlite3_result_error(context
, "value of 40 handed to x_count", -1);
1120 #ifndef SQLITE_OMIT_UTF16
1122 const char zUtf16ErrMsg
[] = { 0, 0x61, 0, 0x62, 0, 0x63, 0, 0, 0};
1123 sqlite3_result_error16(context
, &zUtf16ErrMsg
[1-SQLITE_BIGENDIAN
], -1);
1128 static void t1CountFinalize(sqlite3_context
*context
){
1130 p
= sqlite3_aggregate_context(context
, sizeof(*p
));
1133 sqlite3_result_error(context
, "x_count totals to 42", -1);
1135 sqlite3_result_int(context
, p
? p
->n
: 0);
1140 #ifndef SQLITE_OMIT_DEPRECATED
1141 static void legacyCountStep(
1142 sqlite3_context
*context
,
1144 sqlite3_value
**argv
1149 static void legacyCountFinalize(sqlite3_context
*context
){
1150 sqlite3_result_int(context
, sqlite3_aggregate_count(context
));
1155 ** Usage: sqlite3_create_aggregate DB
1157 ** Call the sqlite3_create_function API on the given database in order
1158 ** to create a function named "x_count". This function is similar
1159 ** to the built-in count() function, with a few special quirks
1160 ** for testing the sqlite3_result_error() APIs.
1162 ** The original motivation for this routine was to be able to call the
1163 ** sqlite3_create_aggregate function while a query is in progress in order
1164 ** to test the SQLITE_MISUSE detection logic. See misuse.test.
1166 ** This routine was later extended to test the use of sqlite3_result_error()
1167 ** within aggregate functions.
1169 ** Later: It is now also extended to register the aggregate function
1170 ** "legacy_count()" with the supplied database handle. This is used
1171 ** to test the deprecated sqlite3_aggregate_count() API.
1173 static int SQLITE_TCLAPI
test_create_aggregate(
1175 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1176 int argc
, /* Number of arguments */
1177 char **argv
/* Text of each argument */
1182 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1186 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1187 rc
= sqlite3_create_function(db
, "x_count", 0, SQLITE_UTF8
, 0, 0,
1188 t1CountStep
,t1CountFinalize
);
1189 if( rc
==SQLITE_OK
){
1190 rc
= sqlite3_create_function(db
, "x_count", 1, SQLITE_UTF8
, 0, 0,
1191 t1CountStep
,t1CountFinalize
);
1193 #ifndef SQLITE_OMIT_DEPRECATED
1194 if( rc
==SQLITE_OK
){
1195 rc
= sqlite3_create_function(db
, "legacy_count", 0, SQLITE_ANY
, 0, 0,
1196 legacyCountStep
, legacyCountFinalize
1200 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
1201 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
1207 ** Usage: printf TEXT
1209 ** Send output to printf. Use this rather than puts to merge the output
1210 ** in the correct sequence with debugging printfs inserted into C code.
1211 ** Puts uses a separate buffer and debugging statements will be out of
1212 ** sequence if it is used.
1214 static int SQLITE_TCLAPI
test_printf(
1216 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1217 int argc
, /* Number of arguments */
1218 char **argv
/* Text of each argument */
1221 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1225 printf("%s\n", argv
[1]);
1232 ** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER
1234 ** Call mprintf with three integer arguments
1236 static int SQLITE_TCLAPI
sqlite3_mprintf_int(
1238 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1239 int argc
, /* Number of arguments */
1240 char **argv
/* Text of each argument */
1245 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1246 " FORMAT INT INT INT\"", 0);
1250 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1252 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1253 Tcl_AppendResult(interp
, z
, 0);
1259 ** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER
1261 ** Call mprintf with three 64-bit integer arguments
1263 static int SQLITE_TCLAPI
sqlite3_mprintf_int64(
1265 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1266 int argc
, /* Number of arguments */
1267 char **argv
/* Text of each argument */
1273 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1274 " FORMAT INT INT INT\"", 0);
1278 if( sqlite3Atoi64(argv
[i
], &a
[i
-2], sqlite3Strlen30(argv
[i
]), SQLITE_UTF8
) ){
1279 Tcl_AppendResult(interp
, "argument is not a valid 64-bit integer", 0);
1283 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1284 Tcl_AppendResult(interp
, z
, 0);
1290 ** Usage: sqlite3_mprintf_long FORMAT INTEGER INTEGER INTEGER
1292 ** Call mprintf with three long integer arguments. This might be the
1293 ** same as sqlite3_mprintf_int or sqlite3_mprintf_int64, depending on
1296 static int SQLITE_TCLAPI
sqlite3_mprintf_long(
1298 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1299 int argc
, /* Number of arguments */
1300 char **argv
/* Text of each argument */
1307 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1308 " FORMAT INT INT INT\"", 0);
1312 if( Tcl_GetInt(interp
, argv
[i
], &b
[i
-2]) ) return TCL_ERROR
;
1313 a
[i
-2] = (long int)b
[i
-2];
1314 a
[i
-2] &= (((u64
)1)<<(sizeof(int)*8))-1;
1316 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1317 Tcl_AppendResult(interp
, z
, 0);
1323 ** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING
1325 ** Call mprintf with two integer arguments and one string argument
1327 static int SQLITE_TCLAPI
sqlite3_mprintf_str(
1329 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1330 int argc
, /* Number of arguments */
1331 char **argv
/* Text of each argument */
1335 if( argc
<4 || argc
>5 ){
1336 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1337 " FORMAT INT INT ?STRING?\"", 0);
1341 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1343 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], argc
>4 ? argv
[4] : NULL
);
1344 Tcl_AppendResult(interp
, z
, 0);
1350 ** Usage: sqlite3_snprintf_str INTEGER FORMAT INTEGER INTEGER STRING
1352 ** Call mprintf with two integer arguments and one string argument
1354 static int SQLITE_TCLAPI
sqlite3_snprintf_str(
1356 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1357 int argc
, /* Number of arguments */
1358 char **argv
/* Text of each argument */
1363 if( argc
<5 || argc
>6 ){
1364 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1365 " INT FORMAT INT INT ?STRING?\"", 0);
1368 if( Tcl_GetInt(interp
, argv
[1], &n
) ) return TCL_ERROR
;
1370 Tcl_AppendResult(interp
, "N must be non-negative", 0);
1374 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-3]) ) return TCL_ERROR
;
1376 z
= sqlite3_malloc( n
+1 );
1377 sqlite3_snprintf(n
, z
, argv
[2], a
[0], a
[1], argc
>4 ? argv
[5] : NULL
);
1378 Tcl_AppendResult(interp
, z
, 0);
1384 ** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE
1386 ** Call mprintf with two integer arguments and one double argument
1388 static int SQLITE_TCLAPI
sqlite3_mprintf_double(
1390 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1391 int argc
, /* Number of arguments */
1392 char **argv
/* Text of each argument */
1398 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1399 " FORMAT INT INT DOUBLE\"", 0);
1403 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1405 if( Tcl_GetDouble(interp
, argv
[4], &r
) ) return TCL_ERROR
;
1406 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], r
);
1407 Tcl_AppendResult(interp
, z
, 0);
1413 ** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE
1415 ** Call mprintf with a single double argument which is the product of the
1416 ** two arguments given above. This is used to generate overflow and underflow
1417 ** doubles to test that they are converted properly.
1419 static int SQLITE_TCLAPI
sqlite3_mprintf_scaled(
1421 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1422 int argc
, /* Number of arguments */
1423 char **argv
/* Text of each argument */
1429 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1430 " FORMAT DOUBLE DOUBLE\"", 0);
1434 if( Tcl_GetDouble(interp
, argv
[i
], &r
[i
-2]) ) return TCL_ERROR
;
1436 z
= sqlite3_mprintf(argv
[1], r
[0]*r
[1]);
1437 Tcl_AppendResult(interp
, z
, 0);
1443 ** Usage: sqlite3_mprintf_stronly FORMAT STRING
1445 ** Call mprintf with a single double argument which is the product of the
1446 ** two arguments given above. This is used to generate overflow and underflow
1447 ** doubles to test that they are converted properly.
1449 static int SQLITE_TCLAPI
sqlite3_mprintf_stronly(
1451 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1452 int argc
, /* Number of arguments */
1453 char **argv
/* Text of each argument */
1457 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1458 " FORMAT STRING\"", 0);
1461 z
= sqlite3_mprintf(argv
[1], argv
[2]);
1462 Tcl_AppendResult(interp
, z
, 0);
1468 ** Usage: sqlite3_mprintf_hexdouble FORMAT HEX
1470 ** Call mprintf with a single double argument which is derived from the
1471 ** hexadecimal encoding of an IEEE double.
1473 static int SQLITE_TCLAPI
sqlite3_mprintf_hexdouble(
1475 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1476 int argc
, /* Number of arguments */
1477 char **argv
/* Text of each argument */
1481 unsigned int x1
, x2
;
1484 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1485 " FORMAT STRING\"", 0);
1488 if( sscanf(argv
[2], "%08x%08x", &x2
, &x1
)!=2 ){
1489 Tcl_AppendResult(interp
, "2nd argument should be 16-characters of hex", 0);
1494 memcpy(&r
, &d
, sizeof(r
));
1495 z
= sqlite3_mprintf(argv
[1], r
);
1496 Tcl_AppendResult(interp
, z
, 0);
1502 ** Usage: sqlite3_enable_shared_cache ?BOOLEAN?
1505 #if !defined(SQLITE_OMIT_SHARED_CACHE)
1506 static int SQLITE_TCLAPI
test_enable_shared(
1507 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1508 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1509 int objc
, /* Number of arguments */
1510 Tcl_Obj
*CONST objv
[] /* Command arguments */
1516 if( objc
!=2 && objc
!=1 ){
1517 Tcl_WrongNumArgs(interp
, 1, objv
, "?BOOLEAN?");
1520 ret
= sqlite3GlobalConfig
.sharedCacheEnabled
;
1523 if( Tcl_GetBooleanFromObj(interp
, objv
[1], &enable
) ){
1526 rc
= sqlite3_enable_shared_cache(enable
);
1527 if( rc
!=SQLITE_OK
){
1528 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(rc
), TCL_STATIC
);
1532 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(ret
));
1540 ** Usage: sqlite3_extended_result_codes DB BOOLEAN
1543 static int SQLITE_TCLAPI
test_extended_result_codes(
1544 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1545 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1546 int objc
, /* Number of arguments */
1547 Tcl_Obj
*CONST objv
[] /* Command arguments */
1553 Tcl_WrongNumArgs(interp
, 1, objv
, "DB BOOLEAN");
1556 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1557 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &enable
) ) return TCL_ERROR
;
1558 sqlite3_extended_result_codes(db
, enable
);
1563 ** Usage: sqlite3_libversion_number
1566 static int SQLITE_TCLAPI
test_libversion_number(
1567 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1568 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1569 int objc
, /* Number of arguments */
1570 Tcl_Obj
*CONST objv
[] /* Command arguments */
1572 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_libversion_number()));
1577 ** Usage: sqlite3_table_column_metadata DB dbname tblname colname
1580 static int SQLITE_TCLAPI
test_table_column_metadata(
1581 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1582 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1583 int objc
, /* Number of arguments */
1584 Tcl_Obj
*CONST objv
[] /* Command arguments */
1593 const char *zDatatype
;
1594 const char *zCollseq
;
1599 if( objc
!=5 && objc
!=4 ){
1600 Tcl_WrongNumArgs(interp
, 1, objv
, "DB dbname tblname colname");
1603 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1604 zDb
= Tcl_GetString(objv
[2]);
1605 zTbl
= Tcl_GetString(objv
[3]);
1606 zCol
= objc
==5 ? Tcl_GetString(objv
[4]) : 0;
1608 if( strlen(zDb
)==0 ) zDb
= 0;
1610 rc
= sqlite3_table_column_metadata(db
, zDb
, zTbl
, zCol
,
1611 &zDatatype
, &zCollseq
, ¬null
, &primarykey
, &autoincrement
);
1613 if( rc
!=SQLITE_OK
){
1614 Tcl_AppendResult(interp
, sqlite3_errmsg(db
), 0);
1618 pRet
= Tcl_NewObj();
1619 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zDatatype
, -1));
1620 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zCollseq
, -1));
1621 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(notnull
));
1622 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(primarykey
));
1623 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(autoincrement
));
1624 Tcl_SetObjResult(interp
, pRet
);
1629 #ifndef SQLITE_OMIT_INCRBLOB
1631 static int SQLITE_TCLAPI
blobHandleFromObj(
1634 sqlite3_blob
**ppBlob
1639 z
= Tcl_GetStringFromObj(pObj
, &n
);
1644 Tcl_Channel channel
;
1645 ClientData instanceData
;
1647 channel
= Tcl_GetChannel(interp
, z
, ¬Used
);
1648 if( !channel
) return TCL_ERROR
;
1651 Tcl_Seek(channel
, 0, SEEK_SET
);
1653 instanceData
= Tcl_GetChannelInstanceData(channel
);
1654 *ppBlob
= *((sqlite3_blob
**)instanceData
);
1660 static int SQLITE_TCLAPI
test_blob_reopen(
1661 ClientData clientData
, /* Not used */
1662 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1663 int objc
, /* Number of arguments */
1664 Tcl_Obj
*CONST objv
[] /* Command arguments */
1667 sqlite3_blob
*pBlob
;
1671 Tcl_WrongNumArgs(interp
, 1, objv
, "CHANNEL ROWID");
1675 if( blobHandleFromObj(interp
, objv
[1], &pBlob
) ) return TCL_ERROR
;
1676 if( Tcl_GetWideIntFromObj(interp
, objv
[2], &iRowid
) ) return TCL_ERROR
;
1678 rc
= sqlite3_blob_reopen(pBlob
, iRowid
);
1679 if( rc
!=SQLITE_OK
){
1680 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
1683 return (rc
==SQLITE_OK
? TCL_OK
: TCL_ERROR
);
1689 ** Usage: sqlite3_create_collation_v2 DB-HANDLE NAME CMP-PROC DEL-PROC
1691 ** This Tcl proc is used for testing the experimental
1692 ** sqlite3_create_collation_v2() interface.
1694 struct TestCollationX
{
1699 typedef struct TestCollationX TestCollationX
;
1700 static void testCreateCollationDel(void *pCtx
){
1701 TestCollationX
*p
= (TestCollationX
*)pCtx
;
1703 int rc
= Tcl_EvalObjEx(p
->interp
, p
->pDel
, TCL_EVAL_DIRECT
|TCL_EVAL_GLOBAL
);
1705 Tcl_BackgroundError(p
->interp
);
1708 Tcl_DecrRefCount(p
->pCmp
);
1709 Tcl_DecrRefCount(p
->pDel
);
1710 sqlite3_free((void *)p
);
1712 static int testCreateCollationCmp(
1719 TestCollationX
*p
= (TestCollationX
*)pCtx
;
1720 Tcl_Obj
*pScript
= Tcl_DuplicateObj(p
->pCmp
);
1723 Tcl_IncrRefCount(pScript
);
1724 Tcl_ListObjAppendElement(0, pScript
, Tcl_NewStringObj((char *)zLeft
, nLeft
));
1725 Tcl_ListObjAppendElement(0, pScript
, Tcl_NewStringObj((char *)zRight
,nRight
));
1727 if( TCL_OK
!=Tcl_EvalObjEx(p
->interp
, pScript
, TCL_EVAL_DIRECT
|TCL_EVAL_GLOBAL
)
1728 || TCL_OK
!=Tcl_GetIntFromObj(p
->interp
, Tcl_GetObjResult(p
->interp
), &iRes
)
1730 Tcl_BackgroundError(p
->interp
);
1732 Tcl_DecrRefCount(pScript
);
1736 static int SQLITE_TCLAPI
test_create_collation_v2(
1737 ClientData clientData
, /* Not used */
1738 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1739 int objc
, /* Number of arguments */
1740 Tcl_Obj
*CONST objv
[] /* Command arguments */
1747 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE NAME CMP-PROC DEL-PROC");
1750 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1752 p
= (TestCollationX
*)sqlite3_malloc(sizeof(TestCollationX
));
1756 Tcl_IncrRefCount(p
->pCmp
);
1757 Tcl_IncrRefCount(p
->pDel
);
1759 rc
= sqlite3_create_collation_v2(db
, Tcl_GetString(objv
[2]), 16,
1760 (void *)p
, testCreateCollationCmp
, testCreateCollationDel
1762 if( rc
!=SQLITE_MISUSE
){
1763 Tcl_AppendResult(interp
, "sqlite3_create_collate_v2() failed to detect "
1764 "an invalid encoding", (char*)0);
1767 rc
= sqlite3_create_collation_v2(db
, Tcl_GetString(objv
[2]), SQLITE_UTF8
,
1768 (void *)p
, testCreateCollationCmp
, testCreateCollationDel
1774 ** USAGE: sqlite3_create_function_v2 DB NAME NARG ENC ?SWITCHES?
1776 ** Available switches are:
1783 typedef struct CreateFunctionV2 CreateFunctionV2
;
1784 struct CreateFunctionV2
{
1786 Tcl_Obj
*pFunc
; /* Script for function invocation */
1787 Tcl_Obj
*pStep
; /* Script for agg. step invocation */
1788 Tcl_Obj
*pFinal
; /* Script for agg. finalization invocation */
1789 Tcl_Obj
*pDestroy
; /* Destructor script */
1791 static void cf2Func(sqlite3_context
*ctx
, int nArg
, sqlite3_value
**aArg
){
1793 static void cf2Step(sqlite3_context
*ctx
, int nArg
, sqlite3_value
**aArg
){
1795 static void cf2Final(sqlite3_context
*ctx
){
1797 static void cf2Destroy(void *pUser
){
1798 CreateFunctionV2
*p
= (CreateFunctionV2
*)pUser
;
1800 if( p
->interp
&& p
->pDestroy
){
1801 int rc
= Tcl_EvalObjEx(p
->interp
, p
->pDestroy
, 0);
1802 if( rc
!=TCL_OK
) Tcl_BackgroundError(p
->interp
);
1805 if( p
->pFunc
) Tcl_DecrRefCount(p
->pFunc
);
1806 if( p
->pStep
) Tcl_DecrRefCount(p
->pStep
);
1807 if( p
->pFinal
) Tcl_DecrRefCount(p
->pFinal
);
1808 if( p
->pDestroy
) Tcl_DecrRefCount(p
->pDestroy
);
1811 static int SQLITE_TCLAPI
test_create_function_v2(
1812 ClientData clientData
, /* Not used */
1813 Tcl_Interp
*interp
, /* The invoking TCL interpreter */
1814 int objc
, /* Number of arguments */
1815 Tcl_Obj
*CONST objv
[] /* Command arguments */
1821 CreateFunctionV2
*p
;
1829 {"utf8", SQLITE_UTF8
},
1830 {"utf16", SQLITE_UTF16
},
1831 {"utf16le", SQLITE_UTF16LE
},
1832 {"utf16be", SQLITE_UTF16BE
},
1833 {"any", SQLITE_ANY
},
1837 if( objc
<5 || (objc
%2)==0 ){
1838 Tcl_WrongNumArgs(interp
, 1, objv
, "DB NAME NARG ENC SWITCHES...");
1842 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1843 zFunc
= Tcl_GetString(objv
[2]);
1844 if( Tcl_GetIntFromObj(interp
, objv
[3], &nArg
) ) return TCL_ERROR
;
1845 if( Tcl_GetIndexFromObjStruct(interp
, objv
[4], aEnc
, sizeof(aEnc
[0]),
1846 "encoding", 0, &enc
)
1850 enc
= aEnc
[enc
].enc
;
1852 p
= sqlite3_malloc(sizeof(CreateFunctionV2
));
1854 memset(p
, 0, sizeof(CreateFunctionV2
));
1857 for(i
=5; i
<objc
; i
+=2){
1859 const char *azSwitch
[] = {"-func", "-step", "-final", "-destroy", 0};
1860 if( Tcl_GetIndexFromObj(interp
, objv
[i
], azSwitch
, "switch", 0, &iSwitch
) ){
1866 case 0: p
->pFunc
= objv
[i
+1]; break;
1867 case 1: p
->pStep
= objv
[i
+1]; break;
1868 case 2: p
->pFinal
= objv
[i
+1]; break;
1869 case 3: p
->pDestroy
= objv
[i
+1]; break;
1872 if( p
->pFunc
) p
->pFunc
= Tcl_DuplicateObj(p
->pFunc
);
1873 if( p
->pStep
) p
->pStep
= Tcl_DuplicateObj(p
->pStep
);
1874 if( p
->pFinal
) p
->pFinal
= Tcl_DuplicateObj(p
->pFinal
);
1875 if( p
->pDestroy
) p
->pDestroy
= Tcl_DuplicateObj(p
->pDestroy
);
1877 if( p
->pFunc
) Tcl_IncrRefCount(p
->pFunc
);
1878 if( p
->pStep
) Tcl_IncrRefCount(p
->pStep
);
1879 if( p
->pFinal
) Tcl_IncrRefCount(p
->pFinal
);
1880 if( p
->pDestroy
) Tcl_IncrRefCount(p
->pDestroy
);
1882 rc
= sqlite3_create_function_v2(db
, zFunc
, nArg
, enc
, (void *)p
,
1883 (p
->pFunc
? cf2Func
: 0),
1884 (p
->pStep
? cf2Step
: 0),
1885 (p
->pFinal
? cf2Final
: 0),
1888 if( rc
!=SQLITE_OK
){
1889 Tcl_ResetResult(interp
);
1890 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
1897 ** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC?
1899 static int SQLITE_TCLAPI
test_load_extension(
1900 ClientData clientData
, /* Not used */
1901 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1902 int objc
, /* Number of arguments */
1903 Tcl_Obj
*CONST objv
[] /* Command arguments */
1905 Tcl_CmdInfo cmdInfo
;
1913 if( objc
!=4 && objc
!=3 ){
1914 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE FILE ?PROC?");
1917 zDb
= Tcl_GetString(objv
[1]);
1918 zFile
= Tcl_GetString(objv
[2]);
1920 zProc
= Tcl_GetString(objv
[3]);
1923 /* Extract the C database handle from the Tcl command name */
1924 if( !Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
1925 Tcl_AppendResult(interp
, "command not found: ", zDb
, (char*)0);
1928 db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
1931 /* Call the underlying C function. If an error occurs, set rc to
1932 ** TCL_ERROR and load any error string into the interpreter. If no
1933 ** error occurs, set rc to TCL_OK.
1935 #ifdef SQLITE_OMIT_LOAD_EXTENSION
1937 zErr
= sqlite3_mprintf("this build omits sqlite3_load_extension()");
1941 rc
= sqlite3_load_extension(db
, zFile
, zProc
, &zErr
);
1943 if( rc
!=SQLITE_OK
){
1944 Tcl_SetResult(interp
, zErr
? zErr
: "", TCL_VOLATILE
);
1955 ** Usage: sqlite3_enable_load_extension DB-HANDLE ONOFF
1957 static int SQLITE_TCLAPI
test_enable_load(
1958 ClientData clientData
, /* Not used */
1959 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1960 int objc
, /* Number of arguments */
1961 Tcl_Obj
*CONST objv
[] /* Command arguments */
1963 Tcl_CmdInfo cmdInfo
;
1969 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE ONOFF");
1972 zDb
= Tcl_GetString(objv
[1]);
1974 /* Extract the C database handle from the Tcl command name */
1975 if( !Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
1976 Tcl_AppendResult(interp
, "command not found: ", zDb
, (char*)0);
1979 db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
1982 /* Get the onoff parameter */
1983 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &onoff
) ){
1987 #ifdef SQLITE_OMIT_LOAD_EXTENSION
1988 Tcl_AppendResult(interp
, "this build omits sqlite3_load_extension()");
1991 sqlite3_enable_load_extension(db
, onoff
);
1997 ** Usage: sqlite_abort
1999 ** Shutdown the process immediately. This is not a clean shutdown.
2000 ** This command is used to test the recoverability of a database in
2001 ** the event of a program crash.
2003 static int SQLITE_TCLAPI
sqlite_abort(
2005 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2006 int argc
, /* Number of arguments */
2007 char **argv
/* Text of each argument */
2009 #if defined(_MSC_VER)
2010 /* We do this, otherwise the test will halt with a popup message
2011 * that we have to click away before the test will continue.
2013 _set_abort_behavior( 0, _CALL_REPORTFAULT
);
2016 assert( interp
==0 ); /* This will always fail */
2021 ** The following routine is a user-defined SQL function whose purpose
2022 ** is to test the sqlite_set_result() API.
2024 static void testFunc(sqlite3_context
*context
, int argc
, sqlite3_value
**argv
){
2026 const char *zArg0
= (char*)sqlite3_value_text(argv
[0]);
2028 if( 0==sqlite3StrICmp(zArg0
, "int") ){
2029 sqlite3_result_int(context
, sqlite3_value_int(argv
[1]));
2030 }else if( sqlite3StrICmp(zArg0
,"int64")==0 ){
2031 sqlite3_result_int64(context
, sqlite3_value_int64(argv
[1]));
2032 }else if( sqlite3StrICmp(zArg0
,"string")==0 ){
2033 sqlite3_result_text(context
, (char*)sqlite3_value_text(argv
[1]), -1,
2035 }else if( sqlite3StrICmp(zArg0
,"double")==0 ){
2036 sqlite3_result_double(context
, sqlite3_value_double(argv
[1]));
2037 }else if( sqlite3StrICmp(zArg0
,"null")==0 ){
2038 sqlite3_result_null(context
);
2039 }else if( sqlite3StrICmp(zArg0
,"value")==0 ){
2040 sqlite3_result_value(context
, argv
[sqlite3_value_int(argv
[1])]);
2053 sqlite3_result_error(context
,"first argument should be one of: "
2054 "int int64 string double null value", -1);
2058 ** Usage: sqlite_register_test_function DB NAME
2060 ** Register the test SQL function on the database DB under the name NAME.
2062 static int SQLITE_TCLAPI
test_register_func(
2064 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2065 int argc
, /* Number of arguments */
2066 char **argv
/* Text of each argument */
2071 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
2072 " DB FUNCTION-NAME", 0);
2075 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
2076 rc
= sqlite3_create_function(db
, argv
[2], -1, SQLITE_UTF8
, 0,
2079 Tcl_AppendResult(interp
, sqlite3ErrStr(rc
), 0);
2082 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
2087 ** Usage: sqlite3_finalize STMT
2089 ** Finalize a statement handle.
2091 static int SQLITE_TCLAPI
test_finalize(
2095 Tcl_Obj
*CONST objv
[]
2097 sqlite3_stmt
*pStmt
;
2102 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2103 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2107 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2110 db
= StmtToDb(pStmt
);
2112 rc
= sqlite3_finalize(pStmt
);
2113 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
2114 if( db
&& sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
2119 ** Usage: sqlite3_stmt_status STMT CODE RESETFLAG
2121 ** Get the value of a status counter from a statement.
2123 static int SQLITE_TCLAPI
test_stmt_status(
2127 Tcl_Obj
*CONST objv
[]
2130 int i
, op
= 0, resetFlag
;
2131 const char *zOpName
;
2132 sqlite3_stmt
*pStmt
;
2134 static const struct {
2138 { "SQLITE_STMTSTATUS_FULLSCAN_STEP", SQLITE_STMTSTATUS_FULLSCAN_STEP
},
2139 { "SQLITE_STMTSTATUS_SORT", SQLITE_STMTSTATUS_SORT
},
2140 { "SQLITE_STMTSTATUS_AUTOINDEX", SQLITE_STMTSTATUS_AUTOINDEX
},
2141 { "SQLITE_STMTSTATUS_VM_STEP", SQLITE_STMTSTATUS_VM_STEP
},
2142 { "SQLITE_STMTSTATUS_REPREPARE", SQLITE_STMTSTATUS_REPREPARE
},
2143 { "SQLITE_STMTSTATUS_RUN", SQLITE_STMTSTATUS_RUN
},
2144 { "SQLITE_STMTSTATUS_MEMUSED", SQLITE_STMTSTATUS_MEMUSED
},
2147 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT PARAMETER RESETFLAG");
2150 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2151 zOpName
= Tcl_GetString(objv
[2]);
2152 for(i
=0; i
<ArraySize(aOp
); i
++){
2153 if( strcmp(aOp
[i
].zName
, zOpName
)==0 ){
2158 if( i
>=ArraySize(aOp
) ){
2159 if( Tcl_GetIntFromObj(interp
, objv
[2], &op
) ) return TCL_ERROR
;
2161 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &resetFlag
) ) return TCL_ERROR
;
2162 iValue
= sqlite3_stmt_status(pStmt
, op
, resetFlag
);
2163 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iValue
));
2167 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
2169 ** Usage: sqlite3_stmt_scanstatus STMT IDX
2171 static int SQLITE_TCLAPI
test_stmt_scanstatus(
2175 Tcl_Obj
*CONST objv
[]
2177 sqlite3_stmt
*pStmt
; /* First argument */
2178 int idx
; /* Second argument */
2181 const char *zExplain
;
2182 sqlite3_int64 nLoop
;
2183 sqlite3_int64 nVisit
;
2188 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX");
2191 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2192 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
2194 res
= sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_NLOOP
, (void*)&nLoop
);
2196 Tcl_Obj
*pRet
= Tcl_NewObj();
2197 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nLoop", -1));
2198 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nLoop
));
2199 sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_NVISIT
, (void*)&nVisit
);
2200 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nVisit", -1));
2201 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nVisit
));
2202 sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_EST
, (void*)&rEst
);
2203 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nEst", -1));
2204 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewDoubleObj(rEst
));
2205 sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_NAME
, (void*)&zName
);
2206 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("zName", -1));
2207 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zName
, -1));
2208 sqlite3_stmt_scanstatus(pStmt
, idx
, SQLITE_SCANSTAT_EXPLAIN
, (void*)&zExplain
);
2209 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("zExplain", -1));
2210 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zExplain
, -1));
2211 Tcl_SetObjResult(interp
, pRet
);
2213 Tcl_ResetResult(interp
);
2219 ** Usage: sqlite3_stmt_scanstatus_reset STMT
2221 static int SQLITE_TCLAPI
test_stmt_scanstatus_reset(
2225 Tcl_Obj
*CONST objv
[]
2227 sqlite3_stmt
*pStmt
; /* First argument */
2229 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
2232 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2233 sqlite3_stmt_scanstatus_reset(pStmt
);
2238 #ifdef SQLITE_ENABLE_SQLLOG
2240 ** Usage: sqlite3_config_sqllog
2242 ** Zero the SQLITE_CONFIG_SQLLOG configuration
2244 static int SQLITE_TCLAPI
test_config_sqllog(
2248 Tcl_Obj
*CONST objv
[]
2251 Tcl_WrongNumArgs(interp
, 1, objv
, "");
2254 sqlite3_config(SQLITE_CONFIG_SQLLOG
, 0, 0);
2260 ** Usage: vfs_current_time_int64
2262 ** Return the value returned by the default VFS's xCurrentTimeInt64 method.
2264 static int SQLITE_TCLAPI
vfsCurrentTimeInt64(
2268 Tcl_Obj
*CONST objv
[]
2271 sqlite3_vfs
*pVfs
= sqlite3_vfs_find(0);
2273 Tcl_WrongNumArgs(interp
, 1, objv
, "");
2276 pVfs
->xCurrentTimeInt64(pVfs
, &t
);
2277 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(t
));
2281 #ifdef SQLITE_ENABLE_SNAPSHOT
2283 ** Usage: sqlite3_snapshot_get DB DBNAME
2285 static int SQLITE_TCLAPI
test_snapshot_get(
2289 Tcl_Obj
*CONST objv
[]
2294 sqlite3_snapshot
*pSnapshot
= 0;
2297 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2300 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2301 zName
= Tcl_GetString(objv
[2]);
2303 rc
= sqlite3_snapshot_get(db
, zName
, &pSnapshot
);
2304 if( rc
!=SQLITE_OK
){
2305 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2309 if( sqlite3TestMakePointerStr(interp
, zBuf
, pSnapshot
) ) return TCL_ERROR
;
2310 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zBuf
, -1));
2314 #endif /* SQLITE_ENABLE_SNAPSHOT */
2316 #ifdef SQLITE_ENABLE_SNAPSHOT
2318 ** Usage: sqlite3_snapshot_recover DB DBNAME
2320 static int SQLITE_TCLAPI
test_snapshot_recover(
2324 Tcl_Obj
*CONST objv
[]
2331 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2334 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2335 zName
= Tcl_GetString(objv
[2]);
2337 rc
= sqlite3_snapshot_recover(db
, zName
);
2338 if( rc
!=SQLITE_OK
){
2339 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2342 Tcl_ResetResult(interp
);
2346 #endif /* SQLITE_ENABLE_SNAPSHOT */
2348 #ifdef SQLITE_ENABLE_SNAPSHOT
2350 ** Usage: sqlite3_snapshot_open DB DBNAME SNAPSHOT
2352 static int SQLITE_TCLAPI
test_snapshot_open(
2356 Tcl_Obj
*CONST objv
[]
2361 sqlite3_snapshot
*pSnapshot
;
2364 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SNAPSHOT");
2367 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2368 zName
= Tcl_GetString(objv
[2]);
2369 pSnapshot
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[3]));
2371 rc
= sqlite3_snapshot_open(db
, zName
, pSnapshot
);
2372 if( rc
!=SQLITE_OK
){
2373 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2378 #endif /* SQLITE_ENABLE_SNAPSHOT */
2380 #ifdef SQLITE_ENABLE_SNAPSHOT
2382 ** Usage: sqlite3_snapshot_free SNAPSHOT
2384 static int SQLITE_TCLAPI
test_snapshot_free(
2388 Tcl_Obj
*CONST objv
[]
2390 sqlite3_snapshot
*pSnapshot
;
2392 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT");
2395 pSnapshot
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[1]));
2396 sqlite3_snapshot_free(pSnapshot
);
2399 #endif /* SQLITE_ENABLE_SNAPSHOT */
2401 #ifdef SQLITE_ENABLE_SNAPSHOT
2403 ** Usage: sqlite3_snapshot_cmp SNAPSHOT1 SNAPSHOT2
2405 static int SQLITE_TCLAPI
test_snapshot_cmp(
2409 Tcl_Obj
*CONST objv
[]
2412 sqlite3_snapshot
*p1
;
2413 sqlite3_snapshot
*p2
;
2415 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT1 SNAPSHOT2");
2418 p1
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[1]));
2419 p2
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[2]));
2420 res
= sqlite3_snapshot_cmp(p1
, p2
);
2421 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
2424 #endif /* SQLITE_ENABLE_SNAPSHOT */
2426 #ifdef SQLITE_ENABLE_SNAPSHOT
2428 ** Usage: sqlite3_snapshot_get_blob DB DBNAME
2430 static int SQLITE_TCLAPI
test_snapshot_get_blob(
2434 Tcl_Obj
*CONST objv
[]
2439 sqlite3_snapshot
*pSnapshot
= 0;
2442 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2445 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2446 zName
= Tcl_GetString(objv
[2]);
2448 rc
= sqlite3_snapshot_get(db
, zName
, &pSnapshot
);
2449 if( rc
!=SQLITE_OK
){
2450 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2453 Tcl_SetObjResult(interp
,
2454 Tcl_NewByteArrayObj((unsigned char*)pSnapshot
, sizeof(sqlite3_snapshot
))
2456 sqlite3_snapshot_free(pSnapshot
);
2460 #endif /* SQLITE_ENABLE_SNAPSHOT */
2462 #ifdef SQLITE_ENABLE_SNAPSHOT
2464 ** Usage: sqlite3_snapshot_open_blob DB DBNAME SNAPSHOT
2466 static int SQLITE_TCLAPI
test_snapshot_open_blob(
2470 Tcl_Obj
*CONST objv
[]
2475 unsigned char *pBlob
;
2479 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SNAPSHOT");
2482 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2483 zName
= Tcl_GetString(objv
[2]);
2484 pBlob
= Tcl_GetByteArrayFromObj(objv
[3], &nBlob
);
2485 if( nBlob
!=sizeof(sqlite3_snapshot
) ){
2486 Tcl_AppendResult(interp
, "bad SNAPSHOT", 0);
2489 rc
= sqlite3_snapshot_open(db
, zName
, (sqlite3_snapshot
*)pBlob
);
2490 if( rc
!=SQLITE_OK
){
2491 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2496 #endif /* SQLITE_ENABLE_SNAPSHOT */
2498 #ifdef SQLITE_ENABLE_SNAPSHOT
2500 ** Usage: sqlite3_snapshot_cmp_blob SNAPSHOT1 SNAPSHOT2
2502 static int SQLITE_TCLAPI
test_snapshot_cmp_blob(
2506 Tcl_Obj
*CONST objv
[]
2515 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT1 SNAPSHOT2");
2519 p1
= Tcl_GetByteArrayFromObj(objv
[1], &n1
);
2520 p2
= Tcl_GetByteArrayFromObj(objv
[2], &n2
);
2522 if( n1
!=sizeof(sqlite3_snapshot
) || n1
!=n2
){
2523 Tcl_AppendResult(interp
, "bad SNAPSHOT", 0);
2527 res
= sqlite3_snapshot_cmp((sqlite3_snapshot
*)p1
, (sqlite3_snapshot
*)p2
);
2528 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
2531 #endif /* SQLITE_ENABLE_SNAPSHOT */
2534 ** Usage: sqlite3_delete_database FILENAME
2536 int sqlite3_delete_database(const char*); /* in test_delete.c */
2537 static int SQLITE_TCLAPI
test_delete_database(
2541 Tcl_Obj
*CONST objv
[]
2546 Tcl_WrongNumArgs(interp
, 1, objv
, "FILE");
2549 zFile
= (const char*)Tcl_GetString(objv
[1]);
2550 rc
= sqlite3_delete_database(zFile
);
2552 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2557 ** Usage: atomic_batch_write PATH
2559 static int SQLITE_TCLAPI
test_atomic_batch_write(
2563 Tcl_Obj
*CONST objv
[]
2565 char *zFile
= 0; /* Path to file to test */
2566 sqlite3
*db
= 0; /* Database handle */
2567 sqlite3_file
*pFd
= 0; /* SQLite fd open on zFile */
2568 int bRes
= 0; /* Integer result of this command */
2569 int dc
= 0; /* Device-characteristics mask */
2570 int rc
; /* sqlite3_open() return code */
2573 Tcl_WrongNumArgs(interp
, 1, objv
, "PATH");
2576 zFile
= Tcl_GetString(objv
[1]);
2578 rc
= sqlite3_open(zFile
, &db
);
2579 if( rc
!=SQLITE_OK
){
2580 Tcl_AppendResult(interp
, sqlite3_errmsg(db
), 0);
2585 rc
= sqlite3_file_control(db
, "main", SQLITE_FCNTL_FILE_POINTER
, (void*)&pFd
);
2586 dc
= pFd
->pMethods
->xDeviceCharacteristics(pFd
);
2587 if( dc
& SQLITE_IOCAP_BATCH_ATOMIC
){
2591 Tcl_SetObjResult(interp
, Tcl_NewIntObj(bRes
));
2597 ** Usage: sqlite3_next_stmt DB STMT
2599 ** Return the next statment in sequence after STMT.
2601 static int SQLITE_TCLAPI
test_next_stmt(
2605 Tcl_Obj
*CONST objv
[]
2607 sqlite3_stmt
*pStmt
;
2612 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2613 Tcl_GetStringFromObj(objv
[0], 0), " DB STMT", 0);
2617 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2618 if( getStmtPointer(interp
, Tcl_GetString(objv
[2]), &pStmt
) ) return TCL_ERROR
;
2619 pStmt
= sqlite3_next_stmt(db
, pStmt
);
2621 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
2622 Tcl_AppendResult(interp
, zBuf
, 0);
2628 ** Usage: sqlite3_stmt_readonly STMT
2630 ** Return true if STMT is a NULL pointer or a pointer to a statement
2631 ** that is guaranteed to leave the database unmodified.
2633 static int SQLITE_TCLAPI
test_stmt_readonly(
2637 Tcl_Obj
*CONST objv
[]
2639 sqlite3_stmt
*pStmt
;
2643 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2644 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2648 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2649 rc
= sqlite3_stmt_readonly(pStmt
);
2650 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(rc
));
2655 ** Usage: sqlite3_stmt_busy STMT
2657 ** Return true if STMT is a non-NULL pointer to a statement
2658 ** that has been stepped but not to completion.
2660 static int SQLITE_TCLAPI
test_stmt_busy(
2664 Tcl_Obj
*CONST objv
[]
2666 sqlite3_stmt
*pStmt
;
2670 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2671 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2675 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2676 rc
= sqlite3_stmt_busy(pStmt
);
2677 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(rc
));
2682 ** Usage: uses_stmt_journal STMT
2684 ** Return true if STMT uses a statement journal.
2686 static int SQLITE_TCLAPI
uses_stmt_journal(
2690 Tcl_Obj
*CONST objv
[]
2692 sqlite3_stmt
*pStmt
;
2695 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2696 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2700 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2701 sqlite3_stmt_readonly(pStmt
);
2702 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(((Vdbe
*)pStmt
)->usesStmtJournal
));
2708 ** Usage: sqlite3_reset STMT
2710 ** Reset a statement handle.
2712 static int SQLITE_TCLAPI
test_reset(
2716 Tcl_Obj
*CONST objv
[]
2718 sqlite3_stmt
*pStmt
;
2722 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2723 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2727 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2729 rc
= sqlite3_reset(pStmt
);
2730 if( pStmt
&& sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ){
2733 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
2743 ** Usage: sqlite3_expired STMT
2745 ** Return TRUE if a recompilation of the statement is recommended.
2747 static int SQLITE_TCLAPI
test_expired(
2751 Tcl_Obj
*CONST objv
[]
2753 #ifndef SQLITE_OMIT_DEPRECATED
2754 sqlite3_stmt
*pStmt
;
2756 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2757 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2760 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2761 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(sqlite3_expired(pStmt
)));
2767 ** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT
2769 ** Transfer all bindings from FROMSTMT over to TOSTMT
2771 static int SQLITE_TCLAPI
test_transfer_bind(
2775 Tcl_Obj
*CONST objv
[]
2777 #ifndef SQLITE_OMIT_DEPRECATED
2778 sqlite3_stmt
*pStmt1
, *pStmt2
;
2780 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2781 Tcl_GetStringFromObj(objv
[0], 0), " FROM-STMT TO-STMT", 0);
2784 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt1
)) return TCL_ERROR
;
2785 if( getStmtPointer(interp
, Tcl_GetString(objv
[2]), &pStmt2
)) return TCL_ERROR
;
2786 Tcl_SetObjResult(interp
,
2787 Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1
,pStmt2
)));
2793 ** Usage: sqlite3_changes DB
2795 ** Return the number of changes made to the database by the last SQL
2798 static int SQLITE_TCLAPI
test_changes(
2802 Tcl_Obj
*CONST objv
[]
2806 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2807 Tcl_GetString(objv
[0]), " DB", 0);
2810 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2811 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_changes(db
)));
2816 ** This is the "static_bind_value" that variables are bound to when
2817 ** the FLAG option of sqlite3_bind is "static"
2819 static char *sqlite_static_bind_value
= 0;
2820 static int sqlite_static_bind_nbyte
= 0;
2823 ** Usage: sqlite3_bind VM IDX VALUE FLAGS
2825 ** Sets the value of the IDX-th occurrence of "?" in the original SQL
2826 ** string. VALUE is the new value. If FLAGS=="null" then VALUE is
2827 ** ignored and the value is set to NULL. If FLAGS=="static" then
2828 ** the value is set to the value of a static variable named
2829 ** "sqlite_static_bind_value". If FLAGS=="normal" then a copy
2830 ** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored
2831 ** an a 10-byte blob "abc\000xyz\000pq" is inserted.
2833 static int SQLITE_TCLAPI
test_bind(
2835 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2836 int argc
, /* Number of arguments */
2837 char **argv
/* Text of each argument */
2839 sqlite3_stmt
*pStmt
;
2843 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
2844 " VM IDX VALUE (null|static|normal)\"", 0);
2847 if( getStmtPointer(interp
, argv
[1], &pStmt
) ) return TCL_ERROR
;
2848 if( Tcl_GetInt(interp
, argv
[2], &idx
) ) return TCL_ERROR
;
2849 if( strcmp(argv
[4],"null")==0 ){
2850 rc
= sqlite3_bind_null(pStmt
, idx
);
2851 }else if( strcmp(argv
[4],"static")==0 ){
2852 rc
= sqlite3_bind_text(pStmt
, idx
, sqlite_static_bind_value
, -1, 0);
2853 }else if( strcmp(argv
[4],"static-nbytes")==0 ){
2854 rc
= sqlite3_bind_text(pStmt
, idx
, sqlite_static_bind_value
,
2855 sqlite_static_bind_nbyte
, 0);
2856 }else if( strcmp(argv
[4],"normal")==0 ){
2857 rc
= sqlite3_bind_text(pStmt
, idx
, argv
[3], -1, SQLITE_TRANSIENT
);
2858 }else if( strcmp(argv
[4],"blob10")==0 ){
2859 rc
= sqlite3_bind_text(pStmt
, idx
, "abc\000xyz\000pq", 10, SQLITE_STATIC
);
2861 Tcl_AppendResult(interp
, "4th argument should be "
2862 "\"null\" or \"static\" or \"normal\"", 0);
2865 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
2868 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
2869 Tcl_AppendResult(interp
, zBuf
, sqlite3ErrStr(rc
), 0);
2875 #ifndef SQLITE_OMIT_UTF16
2877 ** Usage: add_test_collate <db ptr> <utf8> <utf16le> <utf16be>
2879 ** This function is used to test that SQLite selects the correct collation
2880 ** sequence callback when multiple versions (for different text encodings)
2883 ** Calling this routine registers the collation sequence "test_collate"
2884 ** with database handle <db>. The second argument must be a list of three
2885 ** boolean values. If the first is true, then a version of test_collate is
2886 ** registered for UTF-8, if the second is true, a version is registered for
2887 ** UTF-16le, if the third is true, a UTF-16be version is available.
2888 ** Previous versions of test_collate are deleted.
2890 ** The collation sequence test_collate is implemented by calling the
2891 ** following TCL script:
2893 ** "test_collate <enc> <lhs> <rhs>"
2895 ** The <lhs> and <rhs> are the two values being compared, encoded in UTF-8.
2896 ** The <enc> parameter is the encoding of the collation function that
2897 ** SQLite selected to call. The TCL test script implements the
2898 ** "test_collate" proc.
2900 ** Note that this will only work with one interpreter at a time, as the
2901 ** interp pointer to use when evaluating the TCL script is stored in
2902 ** pTestCollateInterp.
2904 static Tcl_Interp
* pTestCollateInterp
;
2905 static int test_collate_func(
2907 int nA
, const void *zA
,
2908 int nB
, const void *zB
2910 Tcl_Interp
*i
= pTestCollateInterp
;
2911 int encin
= SQLITE_PTR_TO_INT(pCtx
);
2915 sqlite3_value
*pVal
;
2918 pX
= Tcl_NewStringObj("test_collate", -1);
2919 Tcl_IncrRefCount(pX
);
2923 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-8",-1));
2925 case SQLITE_UTF16LE
:
2926 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-16LE",-1));
2928 case SQLITE_UTF16BE
:
2929 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-16BE",-1));
2935 sqlite3BeginBenignMalloc();
2936 pVal
= sqlite3ValueNew(0);
2938 sqlite3ValueSetStr(pVal
, nA
, zA
, encin
, SQLITE_STATIC
);
2939 n
= sqlite3_value_bytes(pVal
);
2940 Tcl_ListObjAppendElement(i
,pX
,
2941 Tcl_NewStringObj((char*)sqlite3_value_text(pVal
),n
));
2942 sqlite3ValueSetStr(pVal
, nB
, zB
, encin
, SQLITE_STATIC
);
2943 n
= sqlite3_value_bytes(pVal
);
2944 Tcl_ListObjAppendElement(i
,pX
,
2945 Tcl_NewStringObj((char*)sqlite3_value_text(pVal
),n
));
2946 sqlite3ValueFree(pVal
);
2948 sqlite3EndBenignMalloc();
2950 Tcl_EvalObjEx(i
, pX
, 0);
2951 Tcl_DecrRefCount(pX
);
2952 Tcl_GetIntFromObj(i
, Tcl_GetObjResult(i
), &res
);
2955 static int SQLITE_TCLAPI
test_collate(
2959 Tcl_Obj
*CONST objv
[]
2963 sqlite3_value
*pVal
;
2966 if( objc
!=5 ) goto bad_args
;
2967 pTestCollateInterp
= interp
;
2968 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2970 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
2971 rc
= sqlite3_create_collation(db
, "test_collate", SQLITE_UTF8
,
2972 (void *)SQLITE_UTF8
, val
?test_collate_func
:0);
2973 if( rc
==SQLITE_OK
){
2975 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
2976 rc
= sqlite3_create_collation(db
, "test_collate", SQLITE_UTF16LE
,
2977 (void *)SQLITE_UTF16LE
, val
?test_collate_func
:0);
2978 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[4], &val
) ) return TCL_ERROR
;
2981 if( sqlite3_iMallocFail
>0 ){
2982 sqlite3_iMallocFail
++;
2985 sqlite3_mutex_enter(db
->mutex
);
2986 pVal
= sqlite3ValueNew(db
);
2987 sqlite3ValueSetStr(pVal
, -1, "test_collate", SQLITE_UTF8
, SQLITE_STATIC
);
2988 zUtf16
= sqlite3ValueText(pVal
, SQLITE_UTF16NATIVE
);
2989 if( db
->mallocFailed
){
2992 rc
= sqlite3_create_collation16(db
, zUtf16
, SQLITE_UTF16BE
,
2993 (void *)SQLITE_UTF16BE
, val
?test_collate_func
:0);
2995 sqlite3ValueFree(pVal
);
2996 sqlite3_mutex_leave(db
->mutex
);
2998 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3000 if( rc
!=SQLITE_OK
){
3001 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3007 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3008 Tcl_GetStringFromObj(objv
[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
3013 ** Usage: add_test_utf16bin_collate <db ptr>
3015 ** Add a utf-16 collation sequence named "utf16bin" to the database
3016 ** handle. This collation sequence compares arguments in the same way as the
3017 ** built-in collation "binary".
3019 static int test_utf16bin_collate_func(
3021 int nA
, const void *zA
,
3022 int nB
, const void *zB
3024 int nCmp
= (nA
>nB
? nB
: nA
);
3025 int res
= memcmp(zA
, zB
, nCmp
);
3026 if( res
==0 ) res
= nA
- nB
;
3029 static int SQLITE_TCLAPI
test_utf16bin_collate(
3033 Tcl_Obj
*CONST objv
[]
3038 if( objc
!=2 ) goto bad_args
;
3039 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3041 rc
= sqlite3_create_collation(db
, "utf16bin", SQLITE_UTF16
, 0,
3042 test_utf16bin_collate_func
3044 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3048 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
3053 ** When the collation needed callback is invoked, record the name of
3054 ** the requested collating function here. The recorded name is linked
3055 ** to a TCL variable and used to make sure that the requested collation
3058 static char zNeededCollation
[200];
3059 static char *pzNeededCollation
= zNeededCollation
;
3063 ** Called when a collating sequence is needed. Registered using
3064 ** sqlite3_collation_needed16().
3066 static void test_collate_needed_cb(
3075 for(z
= (char*)pName
, i
=0; *z
|| z
[1]; z
++){
3076 if( *z
) zNeededCollation
[i
++] = *z
;
3078 zNeededCollation
[i
] = 0;
3079 sqlite3_create_collation(
3080 db
, "test_collate", ENC(db
), SQLITE_INT_TO_PTR(enc
), test_collate_func
);
3084 ** Usage: add_test_collate_needed DB
3086 static int SQLITE_TCLAPI
test_collate_needed(
3090 Tcl_Obj
*CONST objv
[]
3095 if( objc
!=2 ) goto bad_args
;
3096 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3097 rc
= sqlite3_collation_needed16(db
, 0, test_collate_needed_cb
);
3098 zNeededCollation
[0] = 0;
3099 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3103 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
3108 ** tclcmd: add_alignment_test_collations DB
3110 ** Add two new collating sequences to the database DB
3115 ** Both collating sequences use the same sort order as BINARY.
3116 ** The only difference is that the utf16_aligned collating
3117 ** sequence is declared with the SQLITE_UTF16_ALIGNED flag.
3118 ** Both collating functions increment the unaligned utf16 counter
3119 ** whenever they see a string that begins on an odd byte boundary.
3121 static int unaligned_string_counter
= 0;
3122 static int alignmentCollFunc(
3124 int nKey1
, const void *pKey1
,
3125 int nKey2
, const void *pKey2
3128 n
= nKey1
<nKey2
? nKey1
: nKey2
;
3129 if( nKey1
>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey1
))) ) unaligned_string_counter
++;
3130 if( nKey2
>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey2
))) ) unaligned_string_counter
++;
3131 rc
= memcmp(pKey1
, pKey2
, n
);
3137 static int SQLITE_TCLAPI
add_alignment_test_collations(
3141 Tcl_Obj
*CONST objv
[]
3145 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3146 sqlite3_create_collation(db
, "utf16_unaligned", SQLITE_UTF16
,
3147 0, alignmentCollFunc
);
3148 sqlite3_create_collation(db
, "utf16_aligned", SQLITE_UTF16_ALIGNED
,
3149 0, alignmentCollFunc
);
3153 #endif /* !defined(SQLITE_OMIT_UTF16) */
3156 ** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be>
3158 ** This function is used to test that SQLite selects the correct user
3159 ** function callback when multiple versions (for different text encodings)
3162 ** Calling this routine registers up to three versions of the user function
3163 ** "test_function" with database handle <db>. If the second argument is
3164 ** true, then a version of test_function is registered for UTF-8, if the
3165 ** third is true, a version is registered for UTF-16le, if the fourth is
3166 ** true, a UTF-16be version is available. Previous versions of
3167 ** test_function are deleted.
3169 ** The user function is implemented by calling the following TCL script:
3171 ** "test_function <enc> <arg>"
3173 ** Where <enc> is one of UTF-8, UTF-16LE or UTF16BE, and <arg> is the
3174 ** single argument passed to the SQL function. The value returned by
3175 ** the TCL script is used as the return value of the SQL function. It
3176 ** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8
3177 ** for a UTF-16LE test_function(), and UTF-16LE for an implementation that
3178 ** prefers UTF-16BE.
3180 #ifndef SQLITE_OMIT_UTF16
3181 static void test_function_utf8(
3182 sqlite3_context
*pCtx
,
3184 sqlite3_value
**argv
3188 sqlite3_value
*pVal
;
3189 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3190 pX
= Tcl_NewStringObj("test_function", -1);
3191 Tcl_IncrRefCount(pX
);
3192 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-8", -1));
3193 Tcl_ListObjAppendElement(interp
, pX
,
3194 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3195 Tcl_EvalObjEx(interp
, pX
, 0);
3196 Tcl_DecrRefCount(pX
);
3197 sqlite3_result_text(pCtx
, Tcl_GetStringResult(interp
), -1, SQLITE_TRANSIENT
);
3198 pVal
= sqlite3ValueNew(0);
3199 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3200 SQLITE_UTF8
, SQLITE_STATIC
);
3201 sqlite3_result_text16be(pCtx
, sqlite3_value_text16be(pVal
),
3202 -1, SQLITE_TRANSIENT
);
3203 sqlite3ValueFree(pVal
);
3205 static void test_function_utf16le(
3206 sqlite3_context
*pCtx
,
3208 sqlite3_value
**argv
3212 sqlite3_value
*pVal
;
3213 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3214 pX
= Tcl_NewStringObj("test_function", -1);
3215 Tcl_IncrRefCount(pX
);
3216 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-16LE", -1));
3217 Tcl_ListObjAppendElement(interp
, pX
,
3218 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3219 Tcl_EvalObjEx(interp
, pX
, 0);
3220 Tcl_DecrRefCount(pX
);
3221 pVal
= sqlite3ValueNew(0);
3222 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3223 SQLITE_UTF8
, SQLITE_STATIC
);
3224 sqlite3_result_text(pCtx
,(char*)sqlite3_value_text(pVal
),-1,SQLITE_TRANSIENT
);
3225 sqlite3ValueFree(pVal
);
3227 static void test_function_utf16be(
3228 sqlite3_context
*pCtx
,
3230 sqlite3_value
**argv
3234 sqlite3_value
*pVal
;
3235 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3236 pX
= Tcl_NewStringObj("test_function", -1);
3237 Tcl_IncrRefCount(pX
);
3238 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-16BE", -1));
3239 Tcl_ListObjAppendElement(interp
, pX
,
3240 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3241 Tcl_EvalObjEx(interp
, pX
, 0);
3242 Tcl_DecrRefCount(pX
);
3243 pVal
= sqlite3ValueNew(0);
3244 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3245 SQLITE_UTF8
, SQLITE_STATIC
);
3246 sqlite3_result_text16(pCtx
, sqlite3_value_text16le(pVal
),
3247 -1, SQLITE_TRANSIENT
);
3248 sqlite3_result_text16be(pCtx
, sqlite3_value_text16le(pVal
),
3249 -1, SQLITE_TRANSIENT
);
3250 sqlite3_result_text16le(pCtx
, sqlite3_value_text16le(pVal
),
3251 -1, SQLITE_TRANSIENT
);
3252 sqlite3ValueFree(pVal
);
3254 #endif /* SQLITE_OMIT_UTF16 */
3255 static int SQLITE_TCLAPI
test_function(
3259 Tcl_Obj
*CONST objv
[]
3261 #ifndef SQLITE_OMIT_UTF16
3265 if( objc
!=5 ) goto bad_args
;
3266 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3268 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
3270 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF8
,
3271 interp
, test_function_utf8
, 0, 0);
3273 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
3275 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF16LE
,
3276 interp
, test_function_utf16le
, 0, 0);
3278 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[4], &val
) ) return TCL_ERROR
;
3280 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF16BE
,
3281 interp
, test_function_utf16be
, 0, 0);
3286 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3287 Tcl_GetStringFromObj(objv
[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
3288 #endif /* SQLITE_OMIT_UTF16 */
3293 ** Usage: sqlite3_test_errstr <err code>
3295 ** Test that the english language string equivalents for sqlite error codes
3296 ** are sane. The parameter is an integer representing an sqlite error code.
3297 ** The result is a list of two elements, the string representation of the
3298 ** error code and the english language explanation.
3300 static int SQLITE_TCLAPI
test_errstr(
3304 Tcl_Obj
*CONST objv
[]
3309 Tcl_WrongNumArgs(interp
, 1, objv
, "<error code>");
3312 zCode
= Tcl_GetString(objv
[1]);
3313 for(i
=0; i
<200; i
++){
3314 if( 0==strcmp(t1ErrorName(i
), zCode
) ) break;
3316 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(i
), 0);
3321 ** Usage: breakpoint
3323 ** This routine exists for one purpose - to provide a place to put a
3324 ** breakpoint with GDB that can be triggered using TCL code. The use
3325 ** for this is when a particular test fails on (say) the 1485th iteration.
3326 ** In the TCL test script, we can add code like this:
3328 ** if {$i==1485} breakpoint
3330 ** Then run testfixture in the debugger and wait for the breakpoint to
3331 ** fire. Then additional breakpoints can be set to trace down the bug.
3333 static int SQLITE_TCLAPI
test_breakpoint(
3335 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
3336 int argc
, /* Number of arguments */
3337 char **argv
/* Text of each argument */
3339 return TCL_OK
; /* Do nothing */
3343 ** Usage: sqlite3_bind_zeroblob STMT IDX N
3345 ** Test the sqlite3_bind_zeroblob interface. STMT is a prepared statement.
3346 ** IDX is the index of a wildcard in the prepared statement. This command
3347 ** binds a N-byte zero-filled BLOB to the wildcard.
3349 static int SQLITE_TCLAPI
test_bind_zeroblob(
3353 Tcl_Obj
*CONST objv
[]
3355 sqlite3_stmt
*pStmt
;
3361 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX N");
3365 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3366 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3367 if( Tcl_GetIntFromObj(interp
, objv
[3], &n
) ) return TCL_ERROR
;
3369 rc
= sqlite3_bind_zeroblob(pStmt
, idx
, n
);
3370 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3371 if( rc
!=SQLITE_OK
){
3379 ** Usage: sqlite3_bind_zeroblob64 STMT IDX N
3381 ** Test the sqlite3_bind_zeroblob64 interface. STMT is a prepared statement.
3382 ** IDX is the index of a wildcard in the prepared statement. This command
3383 ** binds a N-byte zero-filled BLOB to the wildcard.
3385 static int SQLITE_TCLAPI
test_bind_zeroblob64(
3389 Tcl_Obj
*CONST objv
[]
3391 sqlite3_stmt
*pStmt
;
3397 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX N");
3401 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3402 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3403 if( Tcl_GetWideIntFromObj(interp
, objv
[3], &n
) ) return TCL_ERROR
;
3405 rc
= sqlite3_bind_zeroblob64(pStmt
, idx
, n
);
3406 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3407 if( rc
!=SQLITE_OK
){
3408 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3416 ** Usage: sqlite3_bind_int STMT N VALUE
3418 ** Test the sqlite3_bind_int interface. STMT is a prepared statement.
3419 ** N is the index of a wildcard in the prepared statement. This command
3420 ** binds a 32-bit integer VALUE to that wildcard.
3422 static int SQLITE_TCLAPI
test_bind_int(
3426 Tcl_Obj
*CONST objv
[]
3428 sqlite3_stmt
*pStmt
;
3434 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3435 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3439 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3440 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3441 if( Tcl_GetIntFromObj(interp
, objv
[3], &value
) ) return TCL_ERROR
;
3443 rc
= sqlite3_bind_int(pStmt
, idx
, value
);
3444 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3445 if( rc
!=SQLITE_OK
){
3454 ** Usage: intarray_addr INT ...
3456 ** Return the address of a C-language array of 32-bit integers.
3458 ** Space to hold the array is obtained from malloc(). Call this procedure once
3459 ** with no arguments in order to release memory. Each call to this procedure
3460 ** overwrites the previous array.
3462 static int SQLITE_TCLAPI
test_intarray_addr(
3466 Tcl_Obj
*CONST objv
[]
3474 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3475 if( p
==0 ) return TCL_ERROR
;
3476 for(i
=0; i
<objc
-1; i
++){
3477 if( Tcl_GetIntFromObj(interp
, objv
[1+i
], &p
[i
]) ){
3484 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3488 ** Usage: intarray_addr INT ...
3490 ** Return the address of a C-language array of 32-bit integers.
3492 ** Space to hold the array is obtained from malloc(). Call this procedure once
3493 ** with no arguments in order to release memory. Each call to this procedure
3494 ** overwrites the previous array.
3496 static int SQLITE_TCLAPI
test_int64array_addr(
3500 Tcl_Obj
*CONST objv
[]
3503 static sqlite3_int64
*p
= 0;
3508 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3509 if( p
==0 ) return TCL_ERROR
;
3510 for(i
=0; i
<objc
-1; i
++){
3512 if( Tcl_GetWideIntFromObj(interp
, objv
[1+i
], &v
) ){
3520 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3524 ** Usage: doublearray_addr INT ...
3526 ** Return the address of a C-language array of doubles.
3528 ** Space to hold the array is obtained from malloc(). Call this procedure once
3529 ** with no arguments in order to release memory. Each call to this procedure
3530 ** overwrites the previous array.
3532 static int SQLITE_TCLAPI
test_doublearray_addr(
3536 Tcl_Obj
*CONST objv
[]
3539 static double *p
= 0;
3544 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3545 if( p
==0 ) return TCL_ERROR
;
3546 for(i
=0; i
<objc
-1; i
++){
3547 if( Tcl_GetDoubleFromObj(interp
, objv
[1+i
], &p
[i
]) ){
3554 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3558 ** Usage: textarray_addr TEXT ...
3560 ** Return the address of a C-language array of strings.
3562 ** Space to hold the array is obtained from malloc(). Call this procedure once
3563 ** with no arguments in order to release memory. Each call to this procedure
3564 ** overwrites the previous array.
3566 static int SQLITE_TCLAPI
test_textarray_addr(
3570 Tcl_Obj
*CONST objv
[]
3574 static char **p
= 0;
3576 for(i
=0; i
<n
; i
++) sqlite3_free(p
[i
]);
3580 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3581 if( p
==0 ) return TCL_ERROR
;
3582 for(i
=0; i
<objc
-1; i
++){
3583 p
[i
] = sqlite3_mprintf("%s", Tcl_GetString(objv
[1+i
]));
3587 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((sqlite3_int64
)p
));
3593 ** Usage: sqlite3_bind_int64 STMT N VALUE
3595 ** Test the sqlite3_bind_int64 interface. STMT is a prepared statement.
3596 ** N is the index of a wildcard in the prepared statement. This command
3597 ** binds a 64-bit integer VALUE to that wildcard.
3599 static int SQLITE_TCLAPI
test_bind_int64(
3603 Tcl_Obj
*CONST objv
[]
3605 sqlite3_stmt
*pStmt
;
3611 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3612 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3616 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3617 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3618 if( Tcl_GetWideIntFromObj(interp
, objv
[3], &value
) ) return TCL_ERROR
;
3620 rc
= sqlite3_bind_int64(pStmt
, idx
, value
);
3621 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3622 if( rc
!=SQLITE_OK
){
3631 ** Usage: sqlite3_bind_double STMT N VALUE
3633 ** Test the sqlite3_bind_double interface. STMT is a prepared statement.
3634 ** N is the index of a wildcard in the prepared statement. This command
3635 ** binds a 64-bit integer VALUE to that wildcard.
3637 static int SQLITE_TCLAPI
test_bind_double(
3641 Tcl_Obj
*CONST objv
[]
3643 sqlite3_stmt
*pStmt
;
3649 static const struct {
3650 const char *zName
; /* Name of the special floating point value */
3651 unsigned int iUpper
; /* Upper 32 bits */
3652 unsigned int iLower
; /* Lower 32 bits */
3654 { "NaN", 0x7fffffff, 0xffffffff },
3655 { "SNaN", 0x7ff7ffff, 0xffffffff },
3656 { "-NaN", 0xffffffff, 0xffffffff },
3657 { "-SNaN", 0xfff7ffff, 0xffffffff },
3658 { "+Inf", 0x7ff00000, 0x00000000 },
3659 { "-Inf", 0xfff00000, 0x00000000 },
3660 { "Epsilon", 0x00000000, 0x00000001 },
3661 { "-Epsilon", 0x80000000, 0x00000001 },
3662 { "NaN0", 0x7ff80000, 0x00000000 },
3663 { "-NaN0", 0xfff80000, 0x00000000 },
3667 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3668 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3672 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3673 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3675 /* Intercept the string "NaN" and generate a NaN value for it.
3676 ** All other strings are passed through to Tcl_GetDoubleFromObj().
3677 ** Tcl_GetDoubleFromObj() should understand "NaN" but some versions
3680 zVal
= Tcl_GetString(objv
[3]);
3681 for(i
=0; i
<sizeof(aSpecialFp
)/sizeof(aSpecialFp
[0]); i
++){
3682 if( strcmp(aSpecialFp
[i
].zName
, zVal
)==0 ){
3684 x
= aSpecialFp
[i
].iUpper
;
3686 x
|= aSpecialFp
[i
].iLower
;
3687 assert( sizeof(value
)==8 );
3688 assert( sizeof(x
)==8 );
3689 memcpy(&value
, &x
, 8);
3693 if( i
>=sizeof(aSpecialFp
)/sizeof(aSpecialFp
[0]) &&
3694 Tcl_GetDoubleFromObj(interp
, objv
[3], &value
) ){
3697 rc
= sqlite3_bind_double(pStmt
, idx
, value
);
3698 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3699 if( rc
!=SQLITE_OK
){
3707 ** Usage: sqlite3_bind_null STMT N
3709 ** Test the sqlite3_bind_null interface. STMT is a prepared statement.
3710 ** N is the index of a wildcard in the prepared statement. This command
3711 ** binds a NULL to the wildcard.
3713 static int SQLITE_TCLAPI
test_bind_null(
3717 Tcl_Obj
*CONST objv
[]
3719 sqlite3_stmt
*pStmt
;
3724 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3725 Tcl_GetStringFromObj(objv
[0], 0), " STMT N", 0);
3729 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3730 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3732 rc
= sqlite3_bind_null(pStmt
, idx
);
3733 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3734 if( rc
!=SQLITE_OK
){
3742 ** Usage: sqlite3_bind_text STMT N STRING BYTES
3744 ** Test the sqlite3_bind_text interface. STMT is a prepared statement.
3745 ** N is the index of a wildcard in the prepared statement. This command
3746 ** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes
3749 static int SQLITE_TCLAPI
test_bind_text(
3753 Tcl_Obj
*CONST objv
[]
3755 sqlite3_stmt
*pStmt
;
3762 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3763 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE BYTES", 0);
3767 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3768 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3769 value
= (char*)Tcl_GetByteArrayFromObj(objv
[3], &bytes
);
3770 if( Tcl_GetIntFromObj(interp
, objv
[4], &bytes
) ) return TCL_ERROR
;
3772 rc
= sqlite3_bind_text(pStmt
, idx
, value
, bytes
, SQLITE_TRANSIENT
);
3773 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3774 if( rc
!=SQLITE_OK
){
3775 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3783 ** Usage: sqlite3_bind_text16 ?-static? STMT N STRING BYTES
3785 ** Test the sqlite3_bind_text16 interface. STMT is a prepared statement.
3786 ** N is the index of a wildcard in the prepared statement. This command
3787 ** binds a UTF-16 string STRING to the wildcard. The string is BYTES bytes
3790 static int SQLITE_TCLAPI
test_bind_text16(
3794 Tcl_Obj
*CONST objv
[]
3796 #ifndef SQLITE_OMIT_UTF16
3797 sqlite3_stmt
*pStmt
;
3803 void (*xDel
)(void*) = (objc
==6?SQLITE_STATIC
:SQLITE_TRANSIENT
);
3804 Tcl_Obj
*oStmt
= objv
[objc
-4];
3805 Tcl_Obj
*oN
= objv
[objc
-3];
3806 Tcl_Obj
*oString
= objv
[objc
-2];
3807 Tcl_Obj
*oBytes
= objv
[objc
-1];
3809 if( objc
!=5 && objc
!=6){
3810 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3811 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE BYTES", 0);
3815 if( getStmtPointer(interp
, Tcl_GetString(oStmt
), &pStmt
) ) return TCL_ERROR
;
3816 if( Tcl_GetIntFromObj(interp
, oN
, &idx
) ) return TCL_ERROR
;
3817 value
= (char*)Tcl_GetByteArrayFromObj(oString
, 0);
3818 if( Tcl_GetIntFromObj(interp
, oBytes
, &bytes
) ) return TCL_ERROR
;
3820 rc
= sqlite3_bind_text16(pStmt
, idx
, (void *)value
, bytes
, xDel
);
3821 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3822 if( rc
!=SQLITE_OK
){
3823 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3827 #endif /* SQLITE_OMIT_UTF16 */
3832 ** Usage: sqlite3_bind_blob ?-static? STMT N DATA BYTES
3834 ** Test the sqlite3_bind_blob interface. STMT is a prepared statement.
3835 ** N is the index of a wildcard in the prepared statement. This command
3836 ** binds a BLOB to the wildcard. The BLOB is BYTES bytes in size.
3838 static int SQLITE_TCLAPI
test_bind_blob(
3842 Tcl_Obj
*CONST objv
[]
3844 sqlite3_stmt
*pStmt
;
3849 sqlite3_destructor_type xDestructor
= SQLITE_TRANSIENT
;
3851 if( objc
!=5 && objc
!=6 ){
3852 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3853 Tcl_GetStringFromObj(objv
[0], 0), " STMT N DATA BYTES", 0);
3858 xDestructor
= SQLITE_STATIC
;
3862 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3863 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3865 value
= (char*)Tcl_GetByteArrayFromObj(objv
[3], &len
);
3866 if( Tcl_GetIntFromObj(interp
, objv
[4], &bytes
) ) return TCL_ERROR
;
3870 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
3871 "cannot use %d blob bytes, have %d", bytes
, len
);
3872 Tcl_AppendResult(interp
, zBuf
, -1);
3876 rc
= sqlite3_bind_blob(pStmt
, idx
, value
, bytes
, xDestructor
);
3877 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3878 if( rc
!=SQLITE_OK
){
3886 ** Usage: sqlite3_bind_parameter_count STMT
3888 ** Return the number of wildcards in the given statement.
3890 static int SQLITE_TCLAPI
test_bind_parameter_count(
3894 Tcl_Obj
*CONST objv
[]
3896 sqlite3_stmt
*pStmt
;
3899 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
3902 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3903 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_bind_parameter_count(pStmt
)));
3908 ** Usage: sqlite3_bind_parameter_name STMT N
3910 ** Return the name of the Nth wildcard. The first wildcard is 1.
3911 ** An empty string is returned if N is out of range or if the wildcard
3914 static int SQLITE_TCLAPI
test_bind_parameter_name(
3918 Tcl_Obj
*CONST objv
[]
3920 sqlite3_stmt
*pStmt
;
3924 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT N");
3927 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3928 if( Tcl_GetIntFromObj(interp
, objv
[2], &i
) ) return TCL_ERROR
;
3929 Tcl_SetObjResult(interp
,
3930 Tcl_NewStringObj(sqlite3_bind_parameter_name(pStmt
,i
),-1)
3936 ** Usage: sqlite3_bind_parameter_index STMT NAME
3938 ** Return the index of the wildcard called NAME. Return 0 if there is
3939 ** no such wildcard.
3941 static int SQLITE_TCLAPI
test_bind_parameter_index(
3945 Tcl_Obj
*CONST objv
[]
3947 sqlite3_stmt
*pStmt
;
3950 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT NAME");
3953 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3954 Tcl_SetObjResult(interp
,
3956 sqlite3_bind_parameter_index(pStmt
,Tcl_GetString(objv
[2]))
3963 ** Usage: sqlite3_clear_bindings STMT
3966 static int SQLITE_TCLAPI
test_clear_bindings(
3970 Tcl_Obj
*CONST objv
[]
3972 sqlite3_stmt
*pStmt
;
3975 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
3978 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3979 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_clear_bindings(pStmt
)));
3984 ** Usage: sqlite3_sleep MILLISECONDS
3986 static int SQLITE_TCLAPI
test_sleep(
3990 Tcl_Obj
*CONST objv
[]
3995 Tcl_WrongNumArgs(interp
, 1, objv
, "MILLISECONDS");
3998 if( Tcl_GetIntFromObj(interp
, objv
[1], &ms
) ){
4001 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_sleep(ms
)));
4006 ** Usage: sqlite3_extended_errcode DB
4008 ** Return the string representation of the most recent sqlite3_* API
4009 ** error code. e.g. "SQLITE_ERROR".
4011 static int SQLITE_TCLAPI
test_ex_errcode(
4015 Tcl_Obj
*CONST objv
[]
4021 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4022 Tcl_GetString(objv
[0]), " DB", 0);
4025 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4026 rc
= sqlite3_extended_errcode(db
);
4027 Tcl_AppendResult(interp
, (char *)t1ErrorName(rc
), 0);
4033 ** Usage: sqlite3_errcode DB
4035 ** Return the string representation of the most recent sqlite3_* API
4036 ** error code. e.g. "SQLITE_ERROR".
4038 static int SQLITE_TCLAPI
test_errcode(
4042 Tcl_Obj
*CONST objv
[]
4048 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4049 Tcl_GetString(objv
[0]), " DB", 0);
4052 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4053 rc
= sqlite3_errcode(db
);
4054 Tcl_AppendResult(interp
, (char *)t1ErrorName(rc
), 0);
4059 ** Usage: sqlite3_errmsg DB
4061 ** Returns the UTF-8 representation of the error message string for the
4062 ** most recent sqlite3_* API call.
4064 static int SQLITE_TCLAPI
test_errmsg(
4068 Tcl_Obj
*CONST objv
[]
4074 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4075 Tcl_GetString(objv
[0]), " DB", 0);
4078 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4080 zErr
= sqlite3_errmsg(db
);
4081 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zErr
, -1));
4086 ** Usage: test_errmsg16 DB
4088 ** Returns the UTF-16 representation of the error message string for the
4089 ** most recent sqlite3_* API call. This is a byte array object at the TCL
4090 ** level, and it includes the 0x00 0x00 terminator bytes at the end of the
4093 static int SQLITE_TCLAPI
test_errmsg16(
4097 Tcl_Obj
*CONST objv
[]
4099 #ifndef SQLITE_OMIT_UTF16
4106 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4107 Tcl_GetString(objv
[0]), " DB", 0);
4110 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4112 zErr
= sqlite3_errmsg16(db
);
4115 for(bytes
=0; z
[bytes
] || z
[bytes
+1]; bytes
+=2){}
4117 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(zErr
, bytes
));
4118 #endif /* SQLITE_OMIT_UTF16 */
4123 ** Usage: sqlite3_prepare DB sql bytes ?tailvar?
4125 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4126 ** database handle <DB>. The parameter <tailval> is the name of a global
4127 ** variable that is set to the unused portion of <sql> (if any). A
4128 ** STMT handle is returned.
4130 static int SQLITE_TCLAPI
test_prepare(
4134 Tcl_Obj
*CONST objv
[]
4139 const char *zTail
= 0;
4140 sqlite3_stmt
*pStmt
= 0;
4144 if( objc
!=5 && objc
!=4 ){
4145 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4146 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
4149 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4150 zSql
= Tcl_GetString(objv
[2]);
4151 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4153 rc
= sqlite3_prepare(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4154 Tcl_ResetResult(interp
);
4155 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4156 if( zTail
&& objc
>=5 ){
4158 bytes
= bytes
- (int)(zTail
-zSql
);
4160 if( (int)strlen(zTail
)<bytes
){
4161 bytes
= (int)strlen(zTail
);
4163 Tcl_ObjSetVar2(interp
, objv
[4], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4165 if( rc
!=SQLITE_OK
){
4167 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4168 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4173 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4174 Tcl_AppendResult(interp
, zBuf
, 0);
4180 ** Usage: sqlite3_prepare_v2 DB sql bytes ?tailvar?
4182 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4183 ** database handle <DB>. The parameter <tailval> is the name of a global
4184 ** variable that is set to the unused portion of <sql> (if any). A
4185 ** STMT handle is returned.
4187 static int SQLITE_TCLAPI
test_prepare_v2(
4191 Tcl_Obj
*CONST objv
[]
4195 char *zCopy
= 0; /* malloc() copy of zSql */
4197 const char *zTail
= 0;
4198 sqlite3_stmt
*pStmt
= 0;
4202 if( objc
!=5 && objc
!=4 ){
4203 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4204 Tcl_GetString(objv
[0]), " DB sql bytes tailvar", 0);
4207 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4208 zSql
= Tcl_GetString(objv
[2]);
4209 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4211 /* Instead of using zSql directly, make a copy into a buffer obtained
4212 ** directly from malloc(). The idea is to make it easier for valgrind
4213 ** to spot buffer overreads. */
4215 zCopy
= malloc(bytes
);
4216 memcpy(zCopy
, zSql
, bytes
);
4218 int n
= (int)strlen(zSql
) + 1;
4220 memcpy(zCopy
, zSql
, n
);
4222 rc
= sqlite3_prepare_v2(db
, zCopy
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4224 zTail
= &zSql
[(zTail
- zCopy
)];
4226 assert(rc
==SQLITE_OK
|| pStmt
==0);
4227 Tcl_ResetResult(interp
);
4228 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4229 if( rc
==SQLITE_OK
&& zTail
&& objc
>=5 ){
4231 bytes
= bytes
- (int)(zTail
-zSql
);
4233 Tcl_ObjSetVar2(interp
, objv
[4], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4235 if( rc
!=SQLITE_OK
){
4237 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4238 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4243 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4244 Tcl_AppendResult(interp
, zBuf
, 0);
4250 ** Usage: sqlite3_prepare_tkt3134 DB
4252 ** Generate a prepared statement for a zero-byte string as a test
4253 ** for ticket #3134. The string should be preceded by a zero byte.
4255 static int SQLITE_TCLAPI
test_prepare_tkt3134(
4259 Tcl_Obj
*CONST objv
[]
4262 static const char zSql
[] = "\000SELECT 1";
4263 sqlite3_stmt
*pStmt
= 0;
4268 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4269 Tcl_GetString(objv
[0]), " DB sql bytes tailvar", 0);
4272 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4273 rc
= sqlite3_prepare_v2(db
, &zSql
[1], 0, &pStmt
, 0);
4274 assert(rc
==SQLITE_OK
|| pStmt
==0);
4275 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4276 if( rc
!=SQLITE_OK
){
4278 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4279 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4284 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4285 Tcl_AppendResult(interp
, zBuf
, 0);
4291 ** Usage: sqlite3_prepare16 DB sql bytes tailvar
4293 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4294 ** database handle <DB>. The parameter <tailval> is the name of a global
4295 ** variable that is set to the unused portion of <sql> (if any). A
4296 ** STMT handle is returned.
4298 static int SQLITE_TCLAPI
test_prepare16(
4302 Tcl_Obj
*CONST objv
[]
4304 #ifndef SQLITE_OMIT_UTF16
4307 const void *zTail
= 0;
4309 sqlite3_stmt
*pStmt
= 0;
4312 int bytes
; /* The integer specified as arg 3 */
4313 int objlen
; /* The byte-array length of arg 2 */
4315 if( objc
!=5 && objc
!=4 ){
4316 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4317 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
4320 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4321 zSql
= Tcl_GetByteArrayFromObj(objv
[2], &objlen
);
4322 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4324 rc
= sqlite3_prepare16(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4325 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4332 objlen
= objlen
- (int)((u8
*)zTail
-(u8
*)zSql
);
4336 pTail
= Tcl_NewByteArrayObj((u8
*)zTail
, objlen
);
4337 Tcl_IncrRefCount(pTail
);
4338 Tcl_ObjSetVar2(interp
, objv
[4], 0, pTail
, 0);
4339 Tcl_DecrRefCount(pTail
);
4343 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4345 Tcl_AppendResult(interp
, zBuf
, 0);
4346 #endif /* SQLITE_OMIT_UTF16 */
4351 ** Usage: sqlite3_prepare16_v2 DB sql bytes ?tailvar?
4353 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4354 ** database handle <DB>. The parameter <tailval> is the name of a global
4355 ** variable that is set to the unused portion of <sql> (if any). A
4356 ** STMT handle is returned.
4358 static int SQLITE_TCLAPI
test_prepare16_v2(
4362 Tcl_Obj
*CONST objv
[]
4364 #ifndef SQLITE_OMIT_UTF16
4367 const void *zTail
= 0;
4369 sqlite3_stmt
*pStmt
= 0;
4372 int bytes
; /* The integer specified as arg 3 */
4373 int objlen
; /* The byte-array length of arg 2 */
4375 if( objc
!=5 && objc
!=4 ){
4376 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4377 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
4380 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4381 zSql
= Tcl_GetByteArrayFromObj(objv
[2], &objlen
);
4382 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4384 rc
= sqlite3_prepare16_v2(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4385 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4392 objlen
= objlen
- (int)((u8
*)zTail
-(u8
*)zSql
);
4396 pTail
= Tcl_NewByteArrayObj((u8
*)zTail
, objlen
);
4397 Tcl_IncrRefCount(pTail
);
4398 Tcl_ObjSetVar2(interp
, objv
[4], 0, pTail
, 0);
4399 Tcl_DecrRefCount(pTail
);
4403 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4405 Tcl_AppendResult(interp
, zBuf
, 0);
4406 #endif /* SQLITE_OMIT_UTF16 */
4411 ** Usage: sqlite3_open filename ?options-list?
4413 static int SQLITE_TCLAPI
test_open(
4417 Tcl_Obj
*CONST objv
[]
4419 const char *zFilename
;
4423 if( objc
!=3 && objc
!=2 && objc
!=1 ){
4424 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4425 Tcl_GetString(objv
[0]), " filename options-list", 0);
4429 zFilename
= objc
>1 ? Tcl_GetString(objv
[1]) : 0;
4430 sqlite3_open(zFilename
, &db
);
4432 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
4433 Tcl_AppendResult(interp
, zBuf
, 0);
4438 ** Usage: sqlite3_open_v2 FILENAME FLAGS VFS
4440 static int SQLITE_TCLAPI
test_open_v2(
4444 Tcl_Obj
*CONST objv
[]
4446 const char *zFilename
;
4458 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME FLAGS VFS");
4461 zFilename
= Tcl_GetString(objv
[1]);
4462 zVfs
= Tcl_GetString(objv
[3]);
4463 if( zVfs
[0]==0x00 ) zVfs
= 0;
4465 rc
= Tcl_ListObjGetElements(interp
, objv
[2], &nFlag
, &apFlag
);
4466 if( rc
!=TCL_OK
) return rc
;
4467 for(i
=0; i
<nFlag
; i
++){
4473 { "SQLITE_OPEN_READONLY", SQLITE_OPEN_READONLY
},
4474 { "SQLITE_OPEN_READWRITE", SQLITE_OPEN_READWRITE
},
4475 { "SQLITE_OPEN_CREATE", SQLITE_OPEN_CREATE
},
4476 { "SQLITE_OPEN_DELETEONCLOSE", SQLITE_OPEN_DELETEONCLOSE
},
4477 { "SQLITE_OPEN_EXCLUSIVE", SQLITE_OPEN_EXCLUSIVE
},
4478 { "SQLITE_OPEN_AUTOPROXY", SQLITE_OPEN_AUTOPROXY
},
4479 { "SQLITE_OPEN_MAIN_DB", SQLITE_OPEN_MAIN_DB
},
4480 { "SQLITE_OPEN_TEMP_DB", SQLITE_OPEN_TEMP_DB
},
4481 { "SQLITE_OPEN_TRANSIENT_DB", SQLITE_OPEN_TRANSIENT_DB
},
4482 { "SQLITE_OPEN_MAIN_JOURNAL", SQLITE_OPEN_MAIN_JOURNAL
},
4483 { "SQLITE_OPEN_TEMP_JOURNAL", SQLITE_OPEN_TEMP_JOURNAL
},
4484 { "SQLITE_OPEN_SUBJOURNAL", SQLITE_OPEN_SUBJOURNAL
},
4485 { "SQLITE_OPEN_MASTER_JOURNAL", SQLITE_OPEN_MASTER_JOURNAL
},
4486 { "SQLITE_OPEN_NOMUTEX", SQLITE_OPEN_NOMUTEX
},
4487 { "SQLITE_OPEN_FULLMUTEX", SQLITE_OPEN_FULLMUTEX
},
4488 { "SQLITE_OPEN_SHAREDCACHE", SQLITE_OPEN_SHAREDCACHE
},
4489 { "SQLITE_OPEN_PRIVATECACHE", SQLITE_OPEN_PRIVATECACHE
},
4490 { "SQLITE_OPEN_WAL", SQLITE_OPEN_WAL
},
4491 { "SQLITE_OPEN_URI", SQLITE_OPEN_URI
},
4494 rc
= Tcl_GetIndexFromObjStruct(interp
, apFlag
[i
], aFlag
, sizeof(aFlag
[0]),
4497 if( rc
!=TCL_OK
) return rc
;
4498 flags
|= aFlag
[iFlag
].flag
;
4501 rc
= sqlite3_open_v2(zFilename
, &db
, flags
, zVfs
);
4502 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
4503 Tcl_AppendResult(interp
, zBuf
, 0);
4508 ** Usage: sqlite3_open16 filename options
4510 static int SQLITE_TCLAPI
test_open16(
4514 Tcl_Obj
*CONST objv
[]
4516 #ifndef SQLITE_OMIT_UTF16
4517 const void *zFilename
;
4522 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4523 Tcl_GetString(objv
[0]), " filename options-list", 0);
4527 zFilename
= Tcl_GetByteArrayFromObj(objv
[1], 0);
4528 sqlite3_open16(zFilename
, &db
);
4530 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
4531 Tcl_AppendResult(interp
, zBuf
, 0);
4532 #endif /* SQLITE_OMIT_UTF16 */
4537 ** Usage: sqlite3_complete16 <UTF-16 string>
4539 ** Return 1 if the supplied argument is a complete SQL statement, or zero
4542 static int SQLITE_TCLAPI
test_complete16(
4546 Tcl_Obj
*CONST objv
[]
4548 #if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16)
4552 Tcl_WrongNumArgs(interp
, 1, objv
, "<utf-16 sql>");
4556 zBuf
= (char*)Tcl_GetByteArrayFromObj(objv
[1], 0);
4557 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_complete16(zBuf
)));
4558 #endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */
4563 ** Usage: sqlite3_step STMT
4565 ** Advance the statement to the next row.
4567 static int SQLITE_TCLAPI
test_step(
4571 Tcl_Obj
*CONST objv
[]
4573 sqlite3_stmt
*pStmt
;
4577 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4578 Tcl_GetString(objv
[0]), " STMT", 0);
4582 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4583 rc
= sqlite3_step(pStmt
);
4585 /* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */
4586 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
4590 static int SQLITE_TCLAPI
test_sql(
4594 Tcl_Obj
*CONST objv
[]
4596 sqlite3_stmt
*pStmt
;
4599 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4603 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4604 Tcl_SetResult(interp
, (char *)sqlite3_sql(pStmt
), TCL_VOLATILE
);
4607 static int SQLITE_TCLAPI
test_ex_sql(
4611 Tcl_Obj
*CONST objv
[]
4613 sqlite3_stmt
*pStmt
;
4617 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4621 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4622 z
= sqlite3_expanded_sql(pStmt
);
4623 Tcl_SetResult(interp
, z
, TCL_VOLATILE
);
4629 ** Usage: sqlite3_column_count STMT
4631 ** Return the number of columns returned by the sql statement STMT.
4633 static int SQLITE_TCLAPI
test_column_count(
4637 Tcl_Obj
*CONST objv
[]
4639 sqlite3_stmt
*pStmt
;
4642 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4643 Tcl_GetString(objv
[0]), " STMT column", 0);
4647 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4649 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_column_count(pStmt
)));
4654 ** Usage: sqlite3_column_type STMT column
4656 ** Return the type of the data in column 'column' of the current row.
4658 static int SQLITE_TCLAPI
test_column_type(
4662 Tcl_Obj
*CONST objv
[]
4664 sqlite3_stmt
*pStmt
;
4669 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4670 Tcl_GetString(objv
[0]), " STMT column", 0);
4674 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4675 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4677 tp
= sqlite3_column_type(pStmt
, col
);
4679 case SQLITE_INTEGER
:
4680 Tcl_SetResult(interp
, "INTEGER", TCL_STATIC
);
4683 Tcl_SetResult(interp
, "NULL", TCL_STATIC
);
4686 Tcl_SetResult(interp
, "FLOAT", TCL_STATIC
);
4689 Tcl_SetResult(interp
, "TEXT", TCL_STATIC
);
4692 Tcl_SetResult(interp
, "BLOB", TCL_STATIC
);
4702 ** Usage: sqlite3_column_int64 STMT column
4704 ** Return the data in column 'column' of the current row cast as an
4705 ** wide (64-bit) integer.
4707 static int SQLITE_TCLAPI
test_column_int64(
4711 Tcl_Obj
*CONST objv
[]
4713 sqlite3_stmt
*pStmt
;
4718 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4719 Tcl_GetString(objv
[0]), " STMT column", 0);
4723 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4724 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4726 iVal
= sqlite3_column_int64(pStmt
, col
);
4727 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(iVal
));
4732 ** Usage: sqlite3_column_blob STMT column
4734 static int SQLITE_TCLAPI
test_column_blob(
4738 Tcl_Obj
*CONST objv
[]
4740 sqlite3_stmt
*pStmt
;
4747 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4748 Tcl_GetString(objv
[0]), " STMT column", 0);
4752 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4753 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4755 len
= sqlite3_column_bytes(pStmt
, col
);
4756 pBlob
= sqlite3_column_blob(pStmt
, col
);
4757 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(pBlob
, len
));
4762 ** Usage: sqlite3_column_double STMT column
4764 ** Return the data in column 'column' of the current row cast as a double.
4766 static int SQLITE_TCLAPI
test_column_double(
4770 Tcl_Obj
*CONST objv
[]
4772 sqlite3_stmt
*pStmt
;
4777 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4778 Tcl_GetString(objv
[0]), " STMT column", 0);
4782 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4783 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4785 rVal
= sqlite3_column_double(pStmt
, col
);
4786 Tcl_SetObjResult(interp
, Tcl_NewDoubleObj(rVal
));
4791 ** Usage: sqlite3_data_count STMT
4793 ** Return the number of columns returned by the sql statement STMT.
4795 static int SQLITE_TCLAPI
test_data_count(
4799 Tcl_Obj
*CONST objv
[]
4801 sqlite3_stmt
*pStmt
;
4804 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4805 Tcl_GetString(objv
[0]), " STMT column", 0);
4809 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4811 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_data_count(pStmt
)));
4816 ** Usage: sqlite3_column_text STMT column
4818 ** Usage: sqlite3_column_decltype STMT column
4820 ** Usage: sqlite3_column_name STMT column
4822 static int SQLITE_TCLAPI
test_stmt_utf8(
4823 void * clientData
, /* Pointer to SQLite API function to be invoke */
4826 Tcl_Obj
*CONST objv
[]
4828 sqlite3_stmt
*pStmt
;
4830 const char *(*xFunc
)(sqlite3_stmt
*, int);
4833 xFunc
= (const char *(*)(sqlite3_stmt
*, int))clientData
;
4835 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4836 Tcl_GetString(objv
[0]), " STMT column", 0);
4840 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4841 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4842 zRet
= xFunc(pStmt
, col
);
4844 Tcl_SetResult(interp
, (char *)zRet
, 0);
4849 static int SQLITE_TCLAPI
test_global_recover(
4853 Tcl_Obj
*CONST objv
[]
4855 #ifndef SQLITE_OMIT_DEPRECATED
4858 Tcl_WrongNumArgs(interp
, 1, objv
, "");
4861 rc
= sqlite3_global_recover();
4862 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
4868 ** Usage: sqlite3_column_text STMT column
4870 ** Usage: sqlite3_column_decltype STMT column
4872 ** Usage: sqlite3_column_name STMT column
4874 static int SQLITE_TCLAPI
test_stmt_utf16(
4875 void * clientData
, /* Pointer to SQLite API function to be invoked */
4878 Tcl_Obj
*CONST objv
[]
4880 #ifndef SQLITE_OMIT_UTF16
4881 sqlite3_stmt
*pStmt
;
4884 const void *zName16
;
4885 const void *(*xFunc
)(sqlite3_stmt
*, int);
4887 xFunc
= (const void *(*)(sqlite3_stmt
*, int))clientData
;
4889 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4890 Tcl_GetString(objv
[0]), " STMT column", 0);
4894 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4895 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4897 zName16
= xFunc(pStmt
, col
);
4900 const char *z
= zName16
;
4901 for(n
=0; z
[n
] || z
[n
+1]; n
+=2){}
4902 pRet
= Tcl_NewByteArrayObj(zName16
, n
+2);
4903 Tcl_SetObjResult(interp
, pRet
);
4905 #endif /* SQLITE_OMIT_UTF16 */
4911 ** Usage: sqlite3_column_int STMT column
4913 ** Usage: sqlite3_column_bytes STMT column
4915 ** Usage: sqlite3_column_bytes16 STMT column
4918 static int SQLITE_TCLAPI
test_stmt_int(
4919 void * clientData
, /* Pointer to SQLite API function to be invoked */
4922 Tcl_Obj
*CONST objv
[]
4924 sqlite3_stmt
*pStmt
;
4926 int (*xFunc
)(sqlite3_stmt
*, int);
4928 xFunc
= (int (*)(sqlite3_stmt
*, int))clientData
;
4930 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4931 Tcl_GetString(objv
[0]), " STMT column", 0);
4935 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4936 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4938 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xFunc(pStmt
, col
)));
4943 ** Usage: sqlite_set_magic DB MAGIC-NUMBER
4945 ** Set the db->magic value. This is used to test error recovery logic.
4947 static int SQLITE_TCLAPI
sqlite_set_magic(
4955 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
4959 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
4960 if( strcmp(argv
[2], "SQLITE_MAGIC_OPEN")==0 ){
4961 db
->magic
= SQLITE_MAGIC_OPEN
;
4962 }else if( strcmp(argv
[2], "SQLITE_MAGIC_CLOSED")==0 ){
4963 db
->magic
= SQLITE_MAGIC_CLOSED
;
4964 }else if( strcmp(argv
[2], "SQLITE_MAGIC_BUSY")==0 ){
4965 db
->magic
= SQLITE_MAGIC_BUSY
;
4966 }else if( strcmp(argv
[2], "SQLITE_MAGIC_ERROR")==0 ){
4967 db
->magic
= SQLITE_MAGIC_ERROR
;
4968 }else if( Tcl_GetInt(interp
, argv
[2], (int*)&db
->magic
) ){
4975 ** Usage: sqlite3_interrupt DB
4977 ** Trigger an interrupt on DB
4979 static int SQLITE_TCLAPI
test_interrupt(
4987 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB", 0);
4990 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
4991 sqlite3_interrupt(db
);
4996 ** Usage: sqlite_delete_function DB function-name
4998 ** Delete the user function 'function-name' from database handle DB. It
4999 ** is assumed that the user function was created as UTF8, any number of
5000 ** arguments (the way the TCL interface does it).
5002 static int SQLITE_TCLAPI
delete_function(
5011 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5012 " DB function-name", 0);
5015 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5016 rc
= sqlite3_create_function(db
, argv
[2], -1, SQLITE_UTF8
, 0, 0, 0, 0);
5017 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5022 ** Usage: sqlite_delete_collation DB collation-name
5024 ** Delete the collation sequence 'collation-name' from database handle
5025 ** DB. It is assumed that the collation sequence was created as UTF8 (the
5026 ** way the TCL interface does it).
5028 static int SQLITE_TCLAPI
delete_collation(
5037 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5038 " DB function-name", 0);
5041 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5042 rc
= sqlite3_create_collation(db
, argv
[2], SQLITE_UTF8
, 0, 0);
5043 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5048 ** Usage: sqlite3_get_autocommit DB
5050 ** Return true if the database DB is currently in auto-commit mode.
5051 ** Return false if not.
5053 static int SQLITE_TCLAPI
get_autocommit(
5062 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5066 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5067 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", sqlite3_get_autocommit(db
));
5068 Tcl_AppendResult(interp
, zBuf
, 0);
5073 ** Usage: sqlite3_busy_timeout DB MS
5075 ** Set the busy timeout. This is more easily done using the timeout
5076 ** method of the TCL interface. But we need a way to test the case
5077 ** where it returns SQLITE_MISUSE.
5079 static int SQLITE_TCLAPI
test_busy_timeout(
5088 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5092 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5093 if( Tcl_GetInt(interp
, argv
[2], &ms
) ) return TCL_ERROR
;
5094 rc
= sqlite3_busy_timeout(db
, ms
);
5095 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
5100 ** Usage: tcl_variable_type VARIABLENAME
5102 ** Return the name of the internal representation for the
5103 ** value of the given variable.
5105 static int SQLITE_TCLAPI
tcl_variable_type(
5109 Tcl_Obj
*CONST objv
[]
5113 Tcl_WrongNumArgs(interp
, 1, objv
, "VARIABLE");
5116 pVar
= Tcl_GetVar2Ex(interp
, Tcl_GetString(objv
[1]), 0, TCL_LEAVE_ERR_MSG
);
5117 if( pVar
==0 ) return TCL_ERROR
;
5118 if( pVar
->typePtr
){
5119 Tcl_SetObjResult(interp
, Tcl_NewStringObj(pVar
->typePtr
->name
, -1));
5125 ** Usage: sqlite3_release_memory ?N?
5127 ** Attempt to release memory currently held but not actually required.
5128 ** The integer N is the number of bytes we are trying to release. The
5129 ** return value is the amount of memory actually released.
5131 static int SQLITE_TCLAPI
test_release_memory(
5135 Tcl_Obj
*CONST objv
[]
5137 #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
5140 if( objc
!=1 && objc
!=2 ){
5141 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5145 if( Tcl_GetIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5149 amt
= sqlite3_release_memory(N
);
5150 Tcl_SetObjResult(interp
, Tcl_NewIntObj(amt
));
5157 ** Usage: sqlite3_db_release_memory DB
5159 ** Attempt to release memory currently held by database DB. Return the
5160 ** result code (which in the current implementation is always zero).
5162 static int SQLITE_TCLAPI
test_db_release_memory(
5166 Tcl_Obj
*CONST objv
[]
5171 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5174 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5175 rc
= sqlite3_db_release_memory(db
);
5176 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5181 ** Usage: sqlite3_db_cacheflush DB
5183 ** Attempt to flush any dirty pages to disk.
5185 static int SQLITE_TCLAPI
test_db_cacheflush(
5189 Tcl_Obj
*CONST objv
[]
5194 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5197 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5198 rc
= sqlite3_db_cacheflush(db
);
5200 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(rc
), TCL_STATIC
);
5204 Tcl_ResetResult(interp
);
5209 ** Usage: sqlite3_system_errno DB
5211 ** Return the low-level system errno value.
5213 static int SQLITE_TCLAPI
test_system_errno(
5217 Tcl_Obj
*CONST objv
[]
5222 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5225 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5226 iErrno
= sqlite3_system_errno(db
);
5227 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iErrno
));
5232 ** Usage: sqlite3_db_filename DB DBNAME
5234 ** Return the name of a file associated with a database.
5236 static int SQLITE_TCLAPI
test_db_filename(
5240 Tcl_Obj
*CONST objv
[]
5243 const char *zDbName
;
5245 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
5248 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5249 zDbName
= Tcl_GetString(objv
[2]);
5250 Tcl_AppendResult(interp
, sqlite3_db_filename(db
, zDbName
), (void*)0);
5255 ** Usage: sqlite3_db_readonly DB DBNAME
5257 ** Return 1 or 0 if DBNAME is readonly or not. Return -1 if DBNAME does
5260 static int SQLITE_TCLAPI
test_db_readonly(
5264 Tcl_Obj
*CONST objv
[]
5267 const char *zDbName
;
5269 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
5272 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5273 zDbName
= Tcl_GetString(objv
[2]);
5274 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_db_readonly(db
, zDbName
)));
5279 ** Usage: sqlite3_soft_heap_limit ?N?
5281 ** Query or set the soft heap limit for the current thread. The
5282 ** limit is only changed if the N is present. The previous limit
5285 static int SQLITE_TCLAPI
test_soft_heap_limit(
5289 Tcl_Obj
*CONST objv
[]
5293 if( objc
!=1 && objc
!=2 ){
5294 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5298 if( Tcl_GetWideIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5300 amt
= sqlite3_soft_heap_limit64(N
);
5301 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(amt
));
5306 ** Usage: sqlite3_thread_cleanup
5308 ** Call the sqlite3_thread_cleanup API.
5310 static int SQLITE_TCLAPI
test_thread_cleanup(
5314 Tcl_Obj
*CONST objv
[]
5316 #ifndef SQLITE_OMIT_DEPRECATED
5317 sqlite3_thread_cleanup();
5323 ** Usage: sqlite3_pager_refcounts DB
5325 ** Return a list of numbers which are the PagerRefcount for all
5326 ** pagers on each database connection.
5328 static int SQLITE_TCLAPI
test_pager_refcounts(
5332 Tcl_Obj
*CONST objv
[]
5340 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5341 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
5344 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5345 pResult
= Tcl_NewObj();
5346 for(i
=0; i
<db
->nDb
; i
++){
5347 if( db
->aDb
[i
].pBt
==0 ){
5350 sqlite3_mutex_enter(db
->mutex
);
5351 a
= sqlite3PagerStats(sqlite3BtreePager(db
->aDb
[i
].pBt
));
5353 sqlite3_mutex_leave(db
->mutex
);
5355 Tcl_ListObjAppendElement(0, pResult
, Tcl_NewIntObj(v
));
5357 Tcl_SetObjResult(interp
, pResult
);
5363 ** tclcmd: working_64bit_int
5365 ** Some TCL builds (ex: cygwin) do not support 64-bit integers. This
5366 ** leads to a number of test failures. The present command checks the
5367 ** TCL build to see whether or not it supports 64-bit integers. It
5368 ** returns TRUE if it does and FALSE if not.
5370 ** This command is used to warn users that their TCL build is defective
5371 ** and that the errors they are seeing in the test scripts might be
5372 ** a result of their defective TCL rather than problems in SQLite.
5374 static int SQLITE_TCLAPI
working_64bit_int(
5375 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5376 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5377 int objc
, /* Number of arguments */
5378 Tcl_Obj
*CONST objv
[] /* Command arguments */
5383 pTestObj
= Tcl_NewWideIntObj(1000000*(i64
)1234567890);
5384 working
= strcmp(Tcl_GetString(pTestObj
), "1234567890000000")==0;
5385 Tcl_DecrRefCount(pTestObj
);
5386 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(working
));
5392 ** tclcmd: vfs_unlink_test
5394 ** This TCL command unregisters the primary VFS and then registers
5395 ** it back again. This is used to test the ability to register a
5396 ** VFS when none are previously registered, and the ability to
5397 ** unregister the only available VFS. Ticket #2738
5399 static int SQLITE_TCLAPI
vfs_unlink_test(
5400 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5401 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5402 int objc
, /* Number of arguments */
5403 Tcl_Obj
*CONST objv
[] /* Command arguments */
5407 sqlite3_vfs
*apVfs
[20];
5408 sqlite3_vfs one
, two
;
5410 sqlite3_vfs_unregister(0); /* Unregister of NULL is harmless */
5411 one
.zName
= "__one";
5412 two
.zName
= "__two";
5414 /* Calling sqlite3_vfs_register with 2nd argument of 0 does not
5415 ** change the default VFS
5417 pMain
= sqlite3_vfs_find(0);
5418 sqlite3_vfs_register(&one
, 0);
5419 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
5420 sqlite3_vfs_register(&two
, 0);
5421 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
5423 /* We can find a VFS by its name */
5424 assert( sqlite3_vfs_find("__one")==&one
);
5425 assert( sqlite3_vfs_find("__two")==&two
);
5427 /* Calling sqlite_vfs_register with non-zero second parameter changes the
5428 ** default VFS, even if the 1st parameter is an existig VFS that is
5429 ** previously registered as the non-default.
5431 sqlite3_vfs_register(&one
, 1);
5432 assert( sqlite3_vfs_find("__one")==&one
);
5433 assert( sqlite3_vfs_find("__two")==&two
);
5434 assert( sqlite3_vfs_find(0)==&one
);
5435 sqlite3_vfs_register(&two
, 1);
5436 assert( sqlite3_vfs_find("__one")==&one
);
5437 assert( sqlite3_vfs_find("__two")==&two
);
5438 assert( sqlite3_vfs_find(0)==&two
);
5440 sqlite3_vfs_register(pMain
, 1);
5441 assert( sqlite3_vfs_find("__one")==&one
);
5442 assert( sqlite3_vfs_find("__two")==&two
);
5443 assert( sqlite3_vfs_find(0)==pMain
);
5446 /* Unlink the default VFS. Repeat until there are no more VFSes
5449 for(i
=0; i
<sizeof(apVfs
)/sizeof(apVfs
[0]); i
++){
5450 apVfs
[i
] = sqlite3_vfs_find(0);
5452 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
5453 sqlite3_vfs_unregister(apVfs
[i
]);
5454 assert( 0==sqlite3_vfs_find(apVfs
[i
]->zName
) );
5457 assert( 0==sqlite3_vfs_find(0) );
5459 /* Register the main VFS as non-default (will be made default, since
5460 ** it'll be the only one in existence).
5462 sqlite3_vfs_register(pMain
, 0);
5463 assert( sqlite3_vfs_find(0)==pMain
);
5465 /* Un-register the main VFS again to restore an empty VFS list */
5466 sqlite3_vfs_unregister(pMain
);
5467 assert( 0==sqlite3_vfs_find(0) );
5469 /* Relink all VFSes in reverse order. */
5470 for(i
=sizeof(apVfs
)/sizeof(apVfs
[0])-1; i
>=0; i
--){
5472 sqlite3_vfs_register(apVfs
[i
], 1);
5473 assert( apVfs
[i
]==sqlite3_vfs_find(0) );
5474 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
5478 /* Unregister out sample VFSes. */
5479 sqlite3_vfs_unregister(&one
);
5480 sqlite3_vfs_unregister(&two
);
5482 /* Unregistering a VFS that is not currently registered is harmless */
5483 sqlite3_vfs_unregister(&one
);
5484 sqlite3_vfs_unregister(&two
);
5485 assert( sqlite3_vfs_find("__one")==0 );
5486 assert( sqlite3_vfs_find("__two")==0 );
5488 /* We should be left with the original default VFS back as the
5490 assert( sqlite3_vfs_find(0)==pMain
);
5496 ** tclcmd: vfs_initfail_test
5498 ** This TCL command attempts to vfs_find and vfs_register when the
5499 ** sqlite3_initialize() interface is failing. All calls should fail.
5501 static int SQLITE_TCLAPI
vfs_initfail_test(
5502 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5503 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5504 int objc
, /* Number of arguments */
5505 Tcl_Obj
*CONST objv
[] /* Command arguments */
5508 one
.zName
= "__one";
5510 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
5511 sqlite3_vfs_register(&one
, 0);
5512 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
5513 sqlite3_vfs_register(&one
, 1);
5514 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
5521 static sqlite3_vfs
*apVfs
[20];
5522 static int nVfs
= 0;
5525 ** tclcmd: vfs_unregister_all
5527 ** Unregister all VFSes.
5529 static int SQLITE_TCLAPI
vfs_unregister_all(
5530 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5531 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5532 int objc
, /* Number of arguments */
5533 Tcl_Obj
*CONST objv
[] /* Command arguments */
5536 for(i
=0; i
<ArraySize(apVfs
); i
++){
5537 apVfs
[i
] = sqlite3_vfs_find(0);
5538 if( apVfs
[i
]==0 ) break;
5539 sqlite3_vfs_unregister(apVfs
[i
]);
5545 ** tclcmd: vfs_reregister_all
5547 ** Restore all VFSes that were removed using vfs_unregister_all. Taking
5548 ** care to put the linked list back together in the same order as it was
5549 ** in before vfs_unregister_all was invoked.
5551 static int SQLITE_TCLAPI
vfs_reregister_all(
5552 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5553 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5554 int objc
, /* Number of arguments */
5555 Tcl_Obj
*CONST objv
[] /* Command arguments */
5558 for(i
=nVfs
-1; i
>=0; i
--){
5559 sqlite3_vfs_register(apVfs
[i
], 1);
5566 ** tclcmd: file_control_test DB
5568 ** This TCL command runs the sqlite3_file_control interface and
5569 ** verifies correct operation of the same.
5571 static int SQLITE_TCLAPI
file_control_test(
5572 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5573 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5574 int objc
, /* Number of arguments */
5575 Tcl_Obj
*CONST objv
[] /* Command arguments */
5582 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5583 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
5586 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5587 rc
= sqlite3_file_control(db
, 0, 0, &iArg
);
5588 assert( rc
==SQLITE_NOTFOUND
);
5589 rc
= sqlite3_file_control(db
, "notadatabase", SQLITE_FCNTL_LOCKSTATE
, &iArg
);
5590 assert( rc
==SQLITE_ERROR
);
5591 rc
= sqlite3_file_control(db
, "main", -1, &iArg
);
5592 assert( rc
==SQLITE_NOTFOUND
);
5593 rc
= sqlite3_file_control(db
, "temp", -1, &iArg
);
5594 assert( rc
==SQLITE_NOTFOUND
|| rc
==SQLITE_ERROR
);
5601 ** tclcmd: file_control_lasterrno_test DB
5603 ** This TCL command runs the sqlite3_file_control interface and
5604 ** verifies correct operation of the SQLITE_LAST_ERRNO verb.
5606 static int SQLITE_TCLAPI
file_control_lasterrno_test(
5607 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5608 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5609 int objc
, /* Number of arguments */
5610 Tcl_Obj
*CONST objv
[] /* Command arguments */
5617 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5618 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
5621 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5624 rc
= sqlite3_file_control(db
, NULL
, SQLITE_LAST_ERRNO
, &iArg
);
5626 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5630 Tcl_AppendResult(interp
, "Unexpected non-zero errno: ",
5631 Tcl_GetStringFromObj(Tcl_NewIntObj(iArg
), 0), " ", 0);
5638 ** tclcmd: file_control_chunksize_test DB DBNAME SIZE
5640 ** This TCL command runs the sqlite3_file_control interface and
5641 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
5642 ** SQLITE_SET_LOCKPROXYFILE verbs.
5644 static int SQLITE_TCLAPI
file_control_chunksize_test(
5645 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5646 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5647 int objc
, /* Number of arguments */
5648 Tcl_Obj
*CONST objv
[] /* Command arguments */
5650 int nSize
; /* New chunk size */
5651 char *zDb
; /* Db name ("main", "temp" etc.) */
5652 sqlite3
*db
; /* Database handle */
5653 int rc
; /* file_control() return code */
5656 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
5659 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
5660 || Tcl_GetIntFromObj(interp
, objv
[3], &nSize
)
5664 zDb
= Tcl_GetString(objv
[2]);
5665 if( zDb
[0]=='\0' ) zDb
= NULL
;
5667 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_CHUNK_SIZE
, (void *)&nSize
);
5669 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
5676 ** tclcmd: file_control_sizehint_test DB DBNAME SIZE
5678 ** This TCL command runs the sqlite3_file_control interface
5679 ** with SQLITE_FCNTL_SIZE_HINT
5681 static int SQLITE_TCLAPI
file_control_sizehint_test(
5682 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5683 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5684 int objc
, /* Number of arguments */
5685 Tcl_Obj
*CONST objv
[] /* Command arguments */
5687 Tcl_WideInt nSize
; /* Hinted size */
5688 char *zDb
; /* Db name ("main", "temp" etc.) */
5689 sqlite3
*db
; /* Database handle */
5690 int rc
; /* file_control() return code */
5693 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
5696 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
5697 || Tcl_GetWideIntFromObj(interp
, objv
[3], &nSize
)
5701 zDb
= Tcl_GetString(objv
[2]);
5702 if( zDb
[0]=='\0' ) zDb
= NULL
;
5704 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_SIZE_HINT
, (void *)&nSize
);
5706 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
5713 ** tclcmd: file_control_lockproxy_test DB PWD
5715 ** This TCL command runs the sqlite3_file_control interface and
5716 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
5717 ** SQLITE_SET_LOCKPROXYFILE verbs.
5719 static int SQLITE_TCLAPI
file_control_lockproxy_test(
5720 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5721 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5722 int objc
, /* Number of arguments */
5723 Tcl_Obj
*CONST objv
[] /* Command arguments */
5728 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5729 Tcl_GetStringFromObj(objv
[0], 0), " DB PWD", 0);
5732 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5736 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
5737 # if defined(__APPLE__)
5738 # define SQLITE_ENABLE_LOCKING_STYLE 1
5740 # define SQLITE_ENABLE_LOCKING_STYLE 0
5743 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
5749 char proxyPath
[400];
5751 zPwd
= Tcl_GetStringFromObj(objv
[2], &nPwd
);
5752 if( sizeof(proxyPath
)<nPwd
+20 ){
5753 Tcl_AppendResult(interp
, "PWD too big", (void*)0);
5756 sqlite3_snprintf(sizeof(proxyPath
), proxyPath
, "%s/test.proxy", zPwd
);
5757 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
5759 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5762 rc
= sqlite3_file_control(db
, NULL
, SQLITE_GET_LOCKPROXYFILE
, &testPath
);
5763 if( strncmp(proxyPath
,testPath
,11) ){
5764 Tcl_AppendResult(interp
, "Lock proxy file did not match the "
5765 "previously assigned value", 0);
5769 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5772 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
5774 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5784 ** tclcmd: file_control_win32_av_retry DB NRETRY DELAY
5786 ** This TCL command runs the sqlite3_file_control interface with
5787 ** the SQLITE_FCNTL_WIN32_AV_RETRY opcode.
5789 static int SQLITE_TCLAPI
file_control_win32_av_retry(
5790 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5791 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5792 int objc
, /* Number of arguments */
5793 Tcl_Obj
*CONST objv
[] /* Command arguments */
5801 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5802 Tcl_GetStringFromObj(objv
[0], 0), " DB NRETRY DELAY", 0);
5805 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5808 if( Tcl_GetIntFromObj(interp
, objv
[2], &a
[0]) ) return TCL_ERROR
;
5809 if( Tcl_GetIntFromObj(interp
, objv
[3], &a
[1]) ) return TCL_ERROR
;
5810 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_AV_RETRY
, (void*)a
);
5811 sqlite3_snprintf(sizeof(z
), z
, "%d %d %d", rc
, a
[0], a
[1]);
5812 Tcl_AppendResult(interp
, z
, (char*)0);
5817 ** tclcmd: file_control_win32_get_handle DB
5819 ** This TCL command runs the sqlite3_file_control interface with
5820 ** the SQLITE_FCNTL_WIN32_GET_HANDLE opcode.
5822 static int file_control_win32_get_handle(
5823 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5824 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5825 int objc
, /* Number of arguments */
5826 Tcl_Obj
*CONST objv
[] /* Command arguments */
5830 HANDLE hFile
= NULL
;
5834 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5835 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
5838 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5841 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_GET_HANDLE
,
5843 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
5844 Tcl_AppendResult(interp
, z
, (char*)0);
5849 ** tclcmd: file_control_win32_set_handle DB HANDLE
5851 ** This TCL command runs the sqlite3_file_control interface with
5852 ** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode.
5854 static int SQLITE_TCLAPI
file_control_win32_set_handle(
5855 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5856 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5857 int objc
, /* Number of arguments */
5858 Tcl_Obj
*CONST objv
[] /* Command arguments */
5862 HANDLE hFile
= NULL
;
5866 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5867 Tcl_GetStringFromObj(objv
[0], 0), " DB HANDLE", 0);
5870 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5873 if( getWin32Handle(interp
, Tcl_GetString(objv
[2]), &hFile
) ){
5876 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_SET_HANDLE
,
5878 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
5879 Tcl_AppendResult(interp
, z
, (char*)0);
5885 ** tclcmd: file_control_persist_wal DB PERSIST-FLAG
5887 ** This TCL command runs the sqlite3_file_control interface with
5888 ** the SQLITE_FCNTL_PERSIST_WAL opcode.
5890 static int SQLITE_TCLAPI
file_control_persist_wal(
5891 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5892 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5893 int objc
, /* Number of arguments */
5894 Tcl_Obj
*CONST objv
[] /* Command arguments */
5902 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5903 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
5906 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5909 if( Tcl_GetIntFromObj(interp
, objv
[2], &bPersist
) ) return TCL_ERROR
;
5910 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_PERSIST_WAL
, (void*)&bPersist
);
5911 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, bPersist
);
5912 Tcl_AppendResult(interp
, z
, (char*)0);
5917 ** tclcmd: file_control_powersafe_overwrite DB PSOW-FLAG
5919 ** This TCL command runs the sqlite3_file_control interface with
5920 ** the SQLITE_FCNTL_POWERSAFE_OVERWRITE opcode.
5922 static int SQLITE_TCLAPI
file_control_powersafe_overwrite(
5923 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5924 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5925 int objc
, /* Number of arguments */
5926 Tcl_Obj
*CONST objv
[] /* Command arguments */
5934 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5935 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
5938 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5941 if( Tcl_GetIntFromObj(interp
, objv
[2], &b
) ) return TCL_ERROR
;
5942 rc
= sqlite3_file_control(db
,NULL
,SQLITE_FCNTL_POWERSAFE_OVERWRITE
,(void*)&b
);
5943 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, b
);
5944 Tcl_AppendResult(interp
, z
, (char*)0);
5950 ** tclcmd: file_control_vfsname DB ?AUXDB?
5952 ** Return a string that describes the stack of VFSes.
5954 static int SQLITE_TCLAPI
file_control_vfsname(
5955 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5956 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5957 int objc
, /* Number of arguments */
5958 Tcl_Obj
*CONST objv
[] /* Command arguments */
5961 const char *zDbName
= "main";
5964 if( objc
!=2 && objc
!=3 ){
5965 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5966 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
5969 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5973 zDbName
= Tcl_GetString(objv
[2]);
5975 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_VFSNAME
,(void*)&zVfsName
);
5976 Tcl_AppendResult(interp
, zVfsName
, (char*)0);
5977 sqlite3_free(zVfsName
);
5982 ** tclcmd: file_control_tempfilename DB ?AUXDB?
5984 ** Return a string that is a temporary filename
5986 static int SQLITE_TCLAPI
file_control_tempfilename(
5987 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5988 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5989 int objc
, /* Number of arguments */
5990 Tcl_Obj
*CONST objv
[] /* Command arguments */
5993 const char *zDbName
= "main";
5996 if( objc
!=2 && objc
!=3 ){
5997 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5998 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6001 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6005 zDbName
= Tcl_GetString(objv
[2]);
6007 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_TEMPFILENAME
, (void*)&zTName
);
6008 Tcl_AppendResult(interp
, zTName
, (char*)0);
6009 sqlite3_free(zTName
);
6015 ** tclcmd: sqlite3_vfs_list
6017 ** Return a tcl list containing the names of all registered vfs's.
6019 static int SQLITE_TCLAPI
vfs_list(
6020 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6021 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6022 int objc
, /* Number of arguments */
6023 Tcl_Obj
*CONST objv
[] /* Command arguments */
6026 Tcl_Obj
*pRet
= Tcl_NewObj();
6028 Tcl_WrongNumArgs(interp
, 1, objv
, "");
6031 for(pVfs
=sqlite3_vfs_find(0); pVfs
; pVfs
=pVfs
->pNext
){
6032 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj(pVfs
->zName
, -1));
6034 Tcl_SetObjResult(interp
, pRet
);
6039 ** tclcmd: sqlite3_limit DB ID VALUE
6041 ** This TCL command runs the sqlite3_limit interface and
6042 ** verifies correct operation of the same.
6044 static int SQLITE_TCLAPI
test_limit(
6045 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6046 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6047 int objc
, /* Number of arguments */
6048 Tcl_Obj
*CONST objv
[] /* Command arguments */
6052 static const struct {
6056 { "SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH
},
6057 { "SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH
},
6058 { "SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN
},
6059 { "SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH
},
6060 { "SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT
},
6061 { "SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP
},
6062 { "SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG
},
6063 { "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED
},
6064 { "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH
},
6065 { "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER
},
6066 { "SQLITE_LIMIT_TRIGGER_DEPTH", SQLITE_LIMIT_TRIGGER_DEPTH
},
6067 { "SQLITE_LIMIT_WORKER_THREADS", SQLITE_LIMIT_WORKER_THREADS
},
6069 /* Out of range test cases */
6070 { "SQLITE_LIMIT_TOOSMALL", -1, },
6071 { "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_WORKER_THREADS
+1 },
6078 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6079 Tcl_GetStringFromObj(objv
[0], 0), " DB ID VALUE", 0);
6082 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6083 zId
= Tcl_GetString(objv
[2]);
6084 for(i
=0; i
<sizeof(aId
)/sizeof(aId
[0]); i
++){
6085 if( strcmp(zId
, aId
[i
].zName
)==0 ){
6090 if( i
>=sizeof(aId
)/sizeof(aId
[0]) ){
6091 Tcl_AppendResult(interp
, "unknown limit type: ", zId
, (char*)0);
6094 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
6095 rc
= sqlite3_limit(db
, id
, val
);
6096 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6101 ** tclcmd: save_prng_state
6103 ** Save the state of the pseudo-random number generator.
6104 ** At the same time, verify that sqlite3_test_control works even when
6105 ** called with an out-of-range opcode.
6107 static int SQLITE_TCLAPI
save_prng_state(
6108 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6109 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6110 int objc
, /* Number of arguments */
6111 Tcl_Obj
*CONST objv
[] /* Command arguments */
6113 int rc
= sqlite3_test_control(9999);
6115 rc
= sqlite3_test_control(-1);
6117 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SAVE
);
6121 ** tclcmd: restore_prng_state
6123 static int SQLITE_TCLAPI
restore_prng_state(
6124 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6125 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6126 int objc
, /* Number of arguments */
6127 Tcl_Obj
*CONST objv
[] /* Command arguments */
6129 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESTORE
);
6133 ** tclcmd: reset_prng_state
6135 static int SQLITE_TCLAPI
reset_prng_state(
6136 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6137 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6138 int objc
, /* Number of arguments */
6139 Tcl_Obj
*CONST objv
[] /* Command arguments */
6141 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESET
);
6146 ** tclcmd: database_may_be_corrupt
6148 ** Indicate that database files might be corrupt. In other words, set the normal
6149 ** state of operation.
6151 static int SQLITE_TCLAPI
database_may_be_corrupt(
6152 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6153 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6154 int objc
, /* Number of arguments */
6155 Tcl_Obj
*CONST objv
[] /* Command arguments */
6157 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 0);
6161 ** tclcmd: database_never_corrupt
6163 ** Indicate that database files are always well-formed. This enables extra assert()
6164 ** statements that test conditions that are always true for well-formed databases.
6166 static int SQLITE_TCLAPI
database_never_corrupt(
6167 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6168 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6169 int objc
, /* Number of arguments */
6170 Tcl_Obj
*CONST objv
[] /* Command arguments */
6172 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 1);
6177 ** tclcmd: pcache_stats
6179 static int SQLITE_TCLAPI
test_pcache_stats(
6180 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6181 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6182 int objc
, /* Number of arguments */
6183 Tcl_Obj
*CONST objv
[] /* Command arguments */
6191 sqlite3PcacheStats(&nCurrent
, &nMax
, &nMin
, &nRecyclable
);
6193 pRet
= Tcl_NewObj();
6194 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("current", -1));
6195 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCurrent
));
6196 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("max", -1));
6197 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMax
));
6198 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("min", -1));
6199 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMin
));
6200 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("recyclable", -1));
6201 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nRecyclable
));
6203 Tcl_SetObjResult(interp
, pRet
);
6208 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
6209 static void test_unlock_notify_cb(void **aArg
, int nArg
){
6211 for(ii
=0; ii
<nArg
; ii
++){
6212 Tcl_EvalEx((Tcl_Interp
*)aArg
[ii
], "unlock_notify", -1, TCL_EVAL_GLOBAL
);
6215 #endif /* SQLITE_ENABLE_UNLOCK_NOTIFY */
6218 ** tclcmd: sqlite3_unlock_notify db
6220 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
6221 static int SQLITE_TCLAPI
test_unlock_notify(
6222 ClientData clientData
, /* Unused */
6223 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6224 int objc
, /* Number of arguments */
6225 Tcl_Obj
*CONST objv
[] /* Command arguments */
6231 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
6235 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6238 rc
= sqlite3_unlock_notify(db
, test_unlock_notify_cb
, (void *)interp
);
6239 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
6245 ** tclcmd: sqlite3_wal_checkpoint db ?NAME?
6247 static int SQLITE_TCLAPI
test_wal_checkpoint(
6248 ClientData clientData
, /* Unused */
6249 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6250 int objc
, /* Number of arguments */
6251 Tcl_Obj
*CONST objv
[] /* Command arguments */
6257 if( objc
!=3 && objc
!=2 ){
6258 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?NAME?");
6262 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6266 zDb
= Tcl_GetString(objv
[2]);
6268 rc
= sqlite3_wal_checkpoint(db
, zDb
);
6269 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
6274 ** tclcmd: sqlite3_wal_checkpoint_v2 db MODE ?NAME?
6276 ** This command calls the wal_checkpoint_v2() function with the specified
6277 ** mode argument (passive, full or restart). If present, the database name
6278 ** NAME is passed as the second argument to wal_checkpoint_v2(). If it the
6279 ** NAME argument is not present, a NULL pointer is passed instead.
6281 ** If wal_checkpoint_v2() returns any value other than SQLITE_BUSY or
6282 ** SQLITE_OK, then this command returns TCL_ERROR. The Tcl result is set
6283 ** to the error message obtained from sqlite3_errmsg().
6285 ** Otherwise, this command returns a list of three integers. The first integer
6286 ** is 1 if SQLITE_BUSY was returned, or 0 otherwise. The following two integers
6287 ** are the values returned via the output parameters by wal_checkpoint_v2() -
6288 ** the number of frames in the log and the number of frames in the log
6289 ** that have been checkpointed.
6291 static int SQLITE_TCLAPI
test_wal_checkpoint_v2(
6292 ClientData clientData
, /* Unused */
6293 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6294 int objc
, /* Number of arguments */
6295 Tcl_Obj
*CONST objv
[] /* Command arguments */
6306 const char * aMode
[] = { "passive", "full", "restart", "truncate", 0 };
6307 assert( SQLITE_CHECKPOINT_PASSIVE
==0 );
6308 assert( SQLITE_CHECKPOINT_FULL
==1 );
6309 assert( SQLITE_CHECKPOINT_RESTART
==2 );
6310 assert( SQLITE_CHECKPOINT_TRUNCATE
==3 );
6312 if( objc
!=3 && objc
!=4 ){
6313 Tcl_WrongNumArgs(interp
, 1, objv
, "DB MODE ?NAME?");
6318 zDb
= Tcl_GetString(objv
[3]);
6320 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) || (
6321 TCL_OK
!=Tcl_GetIntFromObj(0, objv
[2], &eMode
)
6322 && TCL_OK
!=Tcl_GetIndexFromObj(interp
, objv
[2], aMode
, "mode", 0, &eMode
)
6327 rc
= sqlite3_wal_checkpoint_v2(db
, zDb
, eMode
, &nLog
, &nCkpt
);
6328 if( rc
!=SQLITE_OK
&& rc
!=SQLITE_BUSY
){
6329 const char *zErrCode
= sqlite3ErrName(rc
);
6330 Tcl_ResetResult(interp
);
6331 Tcl_AppendResult(interp
, zErrCode
, " - ", (char *)sqlite3_errmsg(db
), 0);
6335 pRet
= Tcl_NewObj();
6336 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(rc
==SQLITE_BUSY
?1:0));
6337 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nLog
));
6338 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCkpt
));
6339 Tcl_SetObjResult(interp
, pRet
);
6345 ** tclcmd: sqlite3_wal_autocheckpoint db VALUE
6347 static int SQLITE_TCLAPI
test_wal_autocheckpoint(
6348 ClientData clientData
, /* Unused */
6349 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6350 int objc
, /* Number of arguments */
6351 Tcl_Obj
*CONST objv
[] /* Command arguments */
6359 Tcl_WrongNumArgs(interp
, 1, objv
, "DB VALUE");
6363 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6364 || Tcl_GetIntFromObj(0, objv
[2], &iVal
)
6369 rc
= sqlite3_wal_autocheckpoint(db
, iVal
);
6370 Tcl_ResetResult(interp
);
6371 if( rc
!=SQLITE_OK
){
6372 const char *zErrCode
= sqlite3ErrName(rc
);
6373 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zErrCode
, -1));
6382 ** tclcmd: test_sqlite3_log ?SCRIPT?
6384 static struct LogCallback
{
6385 Tcl_Interp
*pInterp
;
6387 } logcallback
= {0, 0};
6388 static void xLogcallback(void *unused
, int err
, char *zMsg
){
6389 Tcl_Obj
*pNew
= Tcl_DuplicateObj(logcallback
.pObj
);
6390 Tcl_IncrRefCount(pNew
);
6391 Tcl_ListObjAppendElement(
6392 0, pNew
, Tcl_NewStringObj(sqlite3ErrName(err
), -1)
6394 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewStringObj(zMsg
, -1));
6395 Tcl_EvalObjEx(logcallback
.pInterp
, pNew
, TCL_EVAL_GLOBAL
|TCL_EVAL_DIRECT
);
6396 Tcl_DecrRefCount(pNew
);
6398 static int SQLITE_TCLAPI
test_sqlite3_log(
6399 ClientData clientData
,
6400 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6401 int objc
, /* Number of arguments */
6402 Tcl_Obj
*CONST objv
[] /* Command arguments */
6405 Tcl_WrongNumArgs(interp
, 1, objv
, "SCRIPT");
6408 if( logcallback
.pObj
){
6409 Tcl_DecrRefCount(logcallback
.pObj
);
6410 logcallback
.pObj
= 0;
6411 logcallback
.pInterp
= 0;
6412 sqlite3_config(SQLITE_CONFIG_LOG
, (void*)0, (void*)0);
6415 logcallback
.pObj
= objv
[1];
6416 Tcl_IncrRefCount(logcallback
.pObj
);
6417 logcallback
.pInterp
= interp
;
6418 sqlite3_config(SQLITE_CONFIG_LOG
, xLogcallback
, (void*)0);
6424 ** tcl_objproc COMMANDNAME ARGS...
6426 ** Run a TCL command using its objProc interface. Throw an error if
6427 ** the command has no objProc interface.
6429 static int SQLITE_TCLAPI
runAsObjProc(
6433 Tcl_Obj
*CONST objv
[]
6435 Tcl_CmdInfo cmdInfo
;
6437 Tcl_WrongNumArgs(interp
, 1, objv
, "COMMAND ...");
6440 if( !Tcl_GetCommandInfo(interp
, Tcl_GetString(objv
[1]), &cmdInfo
) ){
6441 Tcl_AppendResult(interp
, "command not found: ",
6442 Tcl_GetString(objv
[1]), (char*)0);
6445 if( cmdInfo
.objProc
==0 ){
6446 Tcl_AppendResult(interp
, "command has no objProc: ",
6447 Tcl_GetString(objv
[1]), (char*)0);
6450 return cmdInfo
.objProc(cmdInfo
.objClientData
, interp
, objc
-1, objv
+1);
6453 #ifndef SQLITE_OMIT_EXPLAIN
6455 ** WARNING: The following function, printExplainQueryPlan() is an exact
6456 ** copy of example code from eqp.in (eqp.html). If this code is modified,
6457 ** then the documentation copy needs to be modified as well.
6460 ** Argument pStmt is a prepared SQL statement. This function compiles
6461 ** an EXPLAIN QUERY PLAN command to report on the prepared statement,
6462 ** and prints the report to stdout using printf().
6464 int printExplainQueryPlan(sqlite3_stmt
*pStmt
){
6465 const char *zSql
; /* Input SQL */
6466 char *zExplain
; /* SQL with EXPLAIN QUERY PLAN prepended */
6467 sqlite3_stmt
*pExplain
; /* Compiled EXPLAIN QUERY PLAN command */
6468 int rc
; /* Return code from sqlite3_prepare_v2() */
6470 zSql
= sqlite3_sql(pStmt
);
6471 if( zSql
==0 ) return SQLITE_ERROR
;
6473 zExplain
= sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql
);
6474 if( zExplain
==0 ) return SQLITE_NOMEM
;
6476 rc
= sqlite3_prepare_v2(sqlite3_db_handle(pStmt
), zExplain
, -1, &pExplain
, 0);
6477 sqlite3_free(zExplain
);
6478 if( rc
!=SQLITE_OK
) return rc
;
6480 while( SQLITE_ROW
==sqlite3_step(pExplain
) ){
6481 int iSelectid
= sqlite3_column_int(pExplain
, 0);
6482 int iOrder
= sqlite3_column_int(pExplain
, 1);
6483 int iFrom
= sqlite3_column_int(pExplain
, 2);
6484 const char *zDetail
= (const char *)sqlite3_column_text(pExplain
, 3);
6486 printf("%d %d %d %s\n", iSelectid
, iOrder
, iFrom
, zDetail
);
6489 return sqlite3_finalize(pExplain
);
6492 static int SQLITE_TCLAPI
test_print_eqp(
6496 Tcl_Obj
*CONST objv
[]
6499 sqlite3_stmt
*pStmt
;
6502 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
6505 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
6506 rc
= printExplainQueryPlan(pStmt
);
6507 /* This is needed on Windows so that a test case using this
6508 ** function can open a read pipe and get the output of
6509 ** printExplainQueryPlan() immediately.
6512 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
6515 #endif /* SQLITE_OMIT_EXPLAIN */
6518 ** sqlite3_test_control VERB ARGS...
6520 static int SQLITE_TCLAPI
test_test_control(
6524 Tcl_Obj
*CONST objv
[]
6530 { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT
},
6531 { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP
},
6532 { "SQLITE_TESTCTRL_IMPOSTER", SQLITE_TESTCTRL_IMPOSTER
},
6539 Tcl_WrongNumArgs(interp
, 1, objv
, "VERB ARGS...");
6543 rc
= Tcl_GetIndexFromObjStruct(
6544 interp
, objv
[1], aVerb
, sizeof(aVerb
[0]), "VERB", 0, &iVerb
6546 if( rc
!=TCL_OK
) return rc
;
6548 iFlag
= aVerb
[iVerb
].i
;
6550 case SQLITE_TESTCTRL_LOCALTIME_FAULT
: {
6553 Tcl_WrongNumArgs(interp
, 2, objv
, "ONOFF");
6556 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
6557 sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT
, val
);
6561 case SQLITE_TESTCTRL_SORTER_MMAP
: {
6565 Tcl_WrongNumArgs(interp
, 2, objv
, "DB LIMIT");
6568 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
6569 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
6570 sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP
, db
, val
);
6574 case SQLITE_TESTCTRL_IMPOSTER
: {
6576 const char *zDbName
;
6579 Tcl_WrongNumArgs(interp
, 2, objv
, "DB dbName onOff tnum");
6582 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
6583 zDbName
= Tcl_GetString(objv
[3]);
6584 if( Tcl_GetIntFromObj(interp
, objv
[4], &onOff
) ) return TCL_ERROR
;
6585 if( Tcl_GetIntFromObj(interp
, objv
[5], &tnum
) ) return TCL_ERROR
;
6586 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER
, db
, zDbName
, onOff
, tnum
);
6591 Tcl_ResetResult(interp
);
6596 #include <sys/time.h>
6597 #include <sys/resource.h>
6599 static int SQLITE_TCLAPI
test_getrusage(
6603 Tcl_Obj
*CONST objv
[]
6607 memset(&r
, 0, sizeof(r
));
6608 getrusage(RUSAGE_SELF
, &r
);
6610 sqlite3_snprintf(sizeof(buf
), buf
,
6611 "ru_utime=%d.%06d ru_stime=%d.%06d ru_minflt=%d ru_majflt=%d",
6612 (int)r
.ru_utime
.tv_sec
, (int)r
.ru_utime
.tv_usec
,
6613 (int)r
.ru_stime
.tv_sec
, (int)r
.ru_stime
.tv_usec
,
6614 (int)r
.ru_minflt
, (int)r
.ru_majflt
6616 Tcl_SetObjResult(interp
, Tcl_NewStringObj(buf
, -1));
6623 ** Information passed from the main thread into the windows file locker
6624 ** background thread.
6626 struct win32FileLocker
{
6627 char *evName
; /* Name of event to signal thread startup */
6628 HANDLE h
; /* Handle of the file to be locked */
6629 int delay1
; /* Delay before locking */
6630 int delay2
; /* Delay before unlocking */
6631 int ok
; /* Finished ok */
6632 int err
; /* True if an error occurs */
6638 #include <process.h>
6640 ** The background thread that does file locking.
6642 static void SQLITE_CDECL
win32_file_locker(void *pAppData
){
6643 struct win32FileLocker
*p
= (struct win32FileLocker
*)pAppData
;
6645 HANDLE ev
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, p
->evName
);
6651 if( p
->delay1
) Sleep(p
->delay1
);
6652 if( LockFile(p
->h
, 0, 0, 100000000, 0) ){
6654 UnlockFile(p
->h
, 0, 0, 100000000, 0);
6668 ** lock_win32_file FILENAME DELAY1 DELAY2
6670 ** Get an exclusive manditory lock on file for DELAY2 milliseconds.
6671 ** Wait DELAY1 milliseconds before acquiring the lock.
6673 static int SQLITE_TCLAPI
win32_file_lock(
6677 Tcl_Obj
*CONST objv
[]
6679 static struct win32FileLocker x
= { "win32_file_lock", 0, 0, 0, 0, 0 };
6680 const char *zFilename
;
6686 if( objc
!=4 && objc
!=1 ){
6687 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME DELAY1 DELAY2");
6691 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d %d %d %d %d",
6692 x
.ok
, x
.err
, x
.delay1
, x
.delay2
, x
.h
);
6693 Tcl_AppendResult(interp
, zBuf
, (char*)0);
6696 while( x
.h
&& retry
<30 ){
6701 Tcl_AppendResult(interp
, "busy", (char*)0);
6704 if( Tcl_GetIntFromObj(interp
, objv
[2], &x
.delay1
) ) return TCL_ERROR
;
6705 if( Tcl_GetIntFromObj(interp
, objv
[3], &x
.delay2
) ) return TCL_ERROR
;
6706 zFilename
= Tcl_GetString(objv
[1]);
6707 x
.h
= CreateFile(zFilename
, GENERIC_READ
|GENERIC_WRITE
,
6708 FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, OPEN_ALWAYS
,
6709 FILE_ATTRIBUTE_NORMAL
, 0);
6711 Tcl_AppendResult(interp
, "cannot open file: ", zFilename
, (char*)0);
6714 ev
= CreateEvent(NULL
, TRUE
, FALSE
, x
.evName
);
6716 Tcl_AppendResult(interp
, "cannot create event: ", x
.evName
, (char*)0);
6719 _beginthread(win32_file_locker
, 0, (void*)&x
);
6721 if ( (wResult
= WaitForSingleObject(ev
, 10000))!=WAIT_OBJECT_0
){
6722 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "0x%x", wResult
);
6723 Tcl_AppendResult(interp
, "wait failed: ", zBuf
, (char*)0);
6732 ** exists_win32_path PATH
6734 ** Returns non-zero if the specified path exists, whose fully qualified name
6735 ** may exceed 260 characters if it is prefixed with "\\?\".
6737 static int SQLITE_TCLAPI
win32_exists_path(
6741 Tcl_Obj
*CONST objv
[]
6744 Tcl_WrongNumArgs(interp
, 1, objv
, "PATH");
6747 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(
6748 GetFileAttributesW( Tcl_GetUnicode(objv
[1]))!=INVALID_FILE_ATTRIBUTES
));
6753 ** find_win32_file PATTERN
6755 ** Returns a list of entries in a directory that match the specified pattern,
6756 ** whose fully qualified name may exceed 248 characters if it is prefixed with
6759 static int SQLITE_TCLAPI
win32_find_file(
6763 Tcl_Obj
*CONST objv
[]
6765 HANDLE hFindFile
= INVALID_HANDLE_VALUE
;
6766 WIN32_FIND_DATAW findData
;
6770 Tcl_WrongNumArgs(interp
, 1, objv
, "PATTERN");
6773 hFindFile
= FindFirstFileW(Tcl_GetUnicode(objv
[1]), &findData
);
6774 if( hFindFile
==INVALID_HANDLE_VALUE
){
6775 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6778 listObj
= Tcl_NewObj();
6779 Tcl_IncrRefCount(listObj
);
6781 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewUnicodeObj(
6782 findData
.cFileName
, -1));
6783 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewWideIntObj(
6784 findData
.dwFileAttributes
));
6785 } while( FindNextFileW(hFindFile
, &findData
) );
6786 lastErrno
= GetLastError();
6787 if( lastErrno
!=NO_ERROR
&& lastErrno
!=ERROR_NO_MORE_FILES
){
6788 FindClose(hFindFile
);
6789 Tcl_DecrRefCount(listObj
);
6790 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6793 FindClose(hFindFile
);
6794 Tcl_SetObjResult(interp
, listObj
);
6799 ** delete_win32_file FILENAME
6801 ** Deletes the specified file, whose fully qualified name may exceed 260
6802 ** characters if it is prefixed with "\\?\".
6804 static int SQLITE_TCLAPI
win32_delete_file(
6808 Tcl_Obj
*CONST objv
[]
6811 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME");
6814 if( !DeleteFileW(Tcl_GetUnicode(objv
[1])) ){
6815 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6818 Tcl_ResetResult(interp
);
6823 ** make_win32_dir DIRECTORY
6825 ** Creates the specified directory, whose fully qualified name may exceed 248
6826 ** characters if it is prefixed with "\\?\".
6828 static int SQLITE_TCLAPI
win32_mkdir(
6832 Tcl_Obj
*CONST objv
[]
6835 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
6838 if( !CreateDirectoryW(Tcl_GetUnicode(objv
[1]), NULL
) ){
6839 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6842 Tcl_ResetResult(interp
);
6847 ** remove_win32_dir DIRECTORY
6849 ** Removes the specified directory, whose fully qualified name may exceed 248
6850 ** characters if it is prefixed with "\\?\".
6852 static int SQLITE_TCLAPI
win32_rmdir(
6856 Tcl_Obj
*CONST objv
[]
6859 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
6862 if( !RemoveDirectoryW(Tcl_GetUnicode(objv
[1])) ){
6863 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6866 Tcl_ResetResult(interp
);
6873 ** optimization_control DB OPT BOOLEAN
6875 ** Enable or disable query optimizations using the sqlite3_test_control()
6876 ** interface. Disable if BOOLEAN is false and enable if BOOLEAN is true.
6877 ** OPT is the name of the optimization to be disabled.
6879 static int SQLITE_TCLAPI
optimization_control(
6883 Tcl_Obj
*CONST objv
[]
6890 static const struct {
6891 const char *zOptName
;
6894 { "all", SQLITE_AllOpts
},
6896 { "query-flattener", SQLITE_QueryFlattener
},
6897 { "column-cache", SQLITE_ColumnCache
},
6898 { "groupby-order", SQLITE_GroupByOrder
},
6899 { "factor-constants", SQLITE_FactorOutConst
},
6900 { "distinct-opt", SQLITE_DistinctOpt
},
6901 { "cover-idx-scan", SQLITE_CoverIdxScan
},
6902 { "order-by-idx-join", SQLITE_OrderByIdxJoin
},
6903 { "transitive", SQLITE_Transitive
},
6904 { "omit-noop-join", SQLITE_OmitNoopJoin
},
6905 { "stat3", SQLITE_Stat34
},
6906 { "stat4", SQLITE_Stat34
},
6910 Tcl_WrongNumArgs(interp
, 1, objv
, "DB OPT BOOLEAN");
6913 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6914 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &onoff
) ) return TCL_ERROR
;
6915 zOpt
= Tcl_GetString(objv
[2]);
6916 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
6917 if( strcmp(zOpt
, aOpt
[i
].zOptName
)==0 ){
6918 mask
= aOpt
[i
].mask
;
6922 if( onoff
) mask
= ~mask
;
6923 if( i
>=sizeof(aOpt
)/sizeof(aOpt
[0]) ){
6924 Tcl_AppendResult(interp
, "unknown optimization - should be one of:",
6926 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
6927 Tcl_AppendResult(interp
, " ", aOpt
[i
].zOptName
, (char*)0);
6931 sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS
, db
, mask
);
6936 ** load_static_extension DB NAME ...
6938 ** Load one or more statically linked extensions.
6940 static int SQLITE_TCLAPI
tclLoadStaticExtensionCmd(
6944 Tcl_Obj
*CONST objv
[]
6946 extern int sqlite3_amatch_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6947 extern int sqlite3_carray_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6948 extern int sqlite3_closure_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6949 extern int sqlite3_csv_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6950 extern int sqlite3_eval_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6951 extern int sqlite3_fileio_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6952 extern int sqlite3_fuzzer_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6953 extern int sqlite3_ieee_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6954 extern int sqlite3_nextchar_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6955 extern int sqlite3_percentile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6956 extern int sqlite3_regexp_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6957 extern int sqlite3_remember_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6958 extern int sqlite3_series_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6959 extern int sqlite3_spellfix_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6960 extern int sqlite3_totype_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6961 extern int sqlite3_wholenumber_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6962 extern int sqlite3_unionvtab_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6963 #ifdef SQLITE_HAVE_ZLIB
6964 extern int sqlite3_zipfile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6966 static const struct {
6967 const char *zExtName
;
6968 int (*pInit
)(sqlite3
*,char**,const sqlite3_api_routines
*);
6970 { "amatch", sqlite3_amatch_init
},
6971 { "carray", sqlite3_carray_init
},
6972 { "closure", sqlite3_closure_init
},
6973 { "csv", sqlite3_csv_init
},
6974 { "eval", sqlite3_eval_init
},
6975 { "fileio", sqlite3_fileio_init
},
6976 { "fuzzer", sqlite3_fuzzer_init
},
6977 { "ieee754", sqlite3_ieee_init
},
6978 { "nextchar", sqlite3_nextchar_init
},
6979 { "percentile", sqlite3_percentile_init
},
6980 { "regexp", sqlite3_regexp_init
},
6981 { "remember", sqlite3_remember_init
},
6982 { "series", sqlite3_series_init
},
6983 { "spellfix", sqlite3_spellfix_init
},
6984 { "totype", sqlite3_totype_init
},
6985 { "unionvtab", sqlite3_unionvtab_init
},
6986 { "wholenumber", sqlite3_wholenumber_init
},
6987 #ifdef SQLITE_HAVE_ZLIB
6988 { "zipfile", sqlite3_zipfile_init
},
6996 Tcl_WrongNumArgs(interp
, 1, objv
, "DB NAME ...");
6999 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7000 for(j
=2; j
<objc
; j
++){
7001 zName
= Tcl_GetString(objv
[j
]);
7002 for(i
=0; i
<ArraySize(aExtension
); i
++){
7003 if( strcmp(zName
, aExtension
[i
].zExtName
)==0 ) break;
7005 if( i
>=ArraySize(aExtension
) ){
7006 Tcl_AppendResult(interp
, "no such extension: ", zName
, (char*)0);
7009 if( aExtension
[i
].pInit
){
7010 rc
= aExtension
[i
].pInit(db
, &zErrMsg
, 0);
7014 if( rc
!=SQLITE_OK
|| zErrMsg
){
7015 Tcl_AppendResult(interp
, "initialization of ", zName
, " failed: ", zErrMsg
,
7017 sqlite3_free(zErrMsg
);
7025 ** sorter_test_fakeheap BOOL
7028 static int SQLITE_TCLAPI
sorter_test_fakeheap(
7032 Tcl_Obj
*CONST objv
[]
7036 Tcl_WrongNumArgs(interp
, 1, objv
, "BOOL");
7040 if( Tcl_GetBooleanFromObj(interp
, objv
[1], &bArg
) ){
7045 if( sqlite3GlobalConfig
.pHeap
==0 ){
7046 sqlite3GlobalConfig
.pHeap
= SQLITE_INT_TO_PTR(-1);
7049 if( sqlite3GlobalConfig
.pHeap
==SQLITE_INT_TO_PTR(-1) ){
7050 sqlite3GlobalConfig
.pHeap
= 0;
7054 Tcl_ResetResult(interp
);
7059 ** sorter_test_sort4_helper DB SQL1 NSTEP SQL2
7061 ** Compile SQL statement $SQL1 and step it $NSTEP times. For each row,
7062 ** check that the leftmost and rightmost columns returned are both integers,
7063 ** and that both contain the same value.
7065 ** Then execute statement $SQL2. Check that the statement returns the same
7066 ** set of integers in the same order as in the previous step (using $SQL1).
7068 static int SQLITE_TCLAPI
sorter_test_sort4_helper(
7072 Tcl_Obj
*CONST objv
[]
7078 unsigned int iCksum1
= 0;
7079 unsigned int iCksum2
= 0;
7083 sqlite3_stmt
*pStmt
;
7086 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SQL1 NSTEP SQL2");
7090 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7091 zSql1
= Tcl_GetString(objv
[2]);
7092 if( Tcl_GetIntFromObj(interp
, objv
[3], &nStep
) ) return TCL_ERROR
;
7093 zSql2
= Tcl_GetString(objv
[4]);
7095 rc
= sqlite3_prepare_v2(db
, zSql1
, -1, &pStmt
, 0);
7096 if( rc
!=SQLITE_OK
) goto sql_error
;
7098 iB
= sqlite3_column_count(pStmt
)-1;
7099 for(iStep
=0; iStep
<nStep
&& SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
7100 int a
= sqlite3_column_int(pStmt
, 0);
7101 if( a
!=sqlite3_column_int(pStmt
, iB
) ){
7102 Tcl_AppendResult(interp
, "data error: (a!=b)", 0);
7106 iCksum1
+= (iCksum1
<< 3) + (unsigned int)a
;
7108 rc
= sqlite3_finalize(pStmt
);
7109 if( rc
!=SQLITE_OK
) goto sql_error
;
7111 rc
= sqlite3_prepare_v2(db
, zSql2
, -1, &pStmt
, 0);
7112 if( rc
!=SQLITE_OK
) goto sql_error
;
7113 for(iStep
=0; SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
7114 int a
= sqlite3_column_int(pStmt
, 0);
7115 iCksum2
+= (iCksum2
<< 3) + (unsigned int)a
;
7117 rc
= sqlite3_finalize(pStmt
);
7118 if( rc
!=SQLITE_OK
) goto sql_error
;
7120 if( iCksum1
!=iCksum2
){
7121 Tcl_AppendResult(interp
, "checksum mismatch", 0);
7127 Tcl_AppendResult(interp
, "sql error: ", sqlite3_errmsg(db
), 0);
7132 #ifdef SQLITE_USER_AUTHENTICATION
7133 #include "sqlite3userauth.h"
7135 ** tclcmd: sqlite3_user_authenticate DB USERNAME PASSWORD
7137 static int SQLITE_TCLAPI
test_user_authenticate(
7138 ClientData clientData
, /* Unused */
7139 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7140 int objc
, /* Number of arguments */
7141 Tcl_Obj
*CONST objv
[] /* Command arguments */
7150 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD");
7153 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7156 zUser
= Tcl_GetString(objv
[2]);
7157 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
7158 rc
= sqlite3_user_authenticate(db
, zUser
, zPasswd
, nPasswd
);
7159 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7162 #endif /* SQLITE_USER_AUTHENTICATION */
7164 #ifdef SQLITE_USER_AUTHENTICATION
7166 ** tclcmd: sqlite3_user_add DB USERNAME PASSWORD ISADMIN
7168 static int SQLITE_TCLAPI
test_user_add(
7169 ClientData clientData
, /* Unused */
7170 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7171 int objc
, /* Number of arguments */
7172 Tcl_Obj
*CONST objv
[] /* Command arguments */
7182 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
7185 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7188 zUser
= Tcl_GetString(objv
[2]);
7189 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
7190 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
7191 rc
= sqlite3_user_add(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
7192 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7195 #endif /* SQLITE_USER_AUTHENTICATION */
7197 #ifdef SQLITE_USER_AUTHENTICATION
7199 ** tclcmd: sqlite3_user_change DB USERNAME PASSWORD ISADMIN
7201 static int SQLITE_TCLAPI
test_user_change(
7202 ClientData clientData
, /* Unused */
7203 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7204 int objc
, /* Number of arguments */
7205 Tcl_Obj
*CONST objv
[] /* Command arguments */
7215 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
7218 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7221 zUser
= Tcl_GetString(objv
[2]);
7222 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
7223 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
7224 rc
= sqlite3_user_change(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
7225 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7228 #endif /* SQLITE_USER_AUTHENTICATION */
7230 #ifdef SQLITE_USER_AUTHENTICATION
7232 ** tclcmd: sqlite3_user_delete DB USERNAME
7234 static int SQLITE_TCLAPI
test_user_delete(
7235 ClientData clientData
, /* Unused */
7236 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7237 int objc
, /* Number of arguments */
7238 Tcl_Obj
*CONST objv
[] /* Command arguments */
7245 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME");
7248 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7251 zUser
= Tcl_GetString(objv
[2]);
7252 rc
= sqlite3_user_delete(db
, zUser
);
7253 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7256 #endif /* SQLITE_USER_AUTHENTICATION */
7259 ** tclcmd: bad_behavior TYPE
7261 ** Do some things that should trigger a valgrind or -fsanitize=undefined
7262 ** warning. This is used to verify that errors and warnings output by those
7263 ** tools are detected by the test scripts.
7266 ** 1 Overflow a signed integer
7267 ** 2 Jump based on an uninitialized variable
7268 ** 3 Read after free
7271 static int SQLITE_TCLAPI
test_bad_behavior(
7272 ClientData clientData
, /* Pointer to an integer containing zero */
7273 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7274 int objc
, /* Number of arguments */
7275 Tcl_Obj
*CONST objv
[] /* Command arguments */
7279 int i
= *(int*)clientData
;
7284 Tcl_WrongNumArgs(interp
, 1, objv
, "TYPE");
7287 if( Tcl_GetIntFromObj(interp
, objv
[1], &iType
) ) return TCL_ERROR
;
7290 xyz
= 0x7fffff00 - i
;
7292 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xyz
));
7297 if( w
[i
]>0 ) w
[1]++;
7298 Tcl_SetObjResult(interp
, Tcl_NewIntObj(w
[1]));
7302 a
= malloc( sizeof(int)*10 );
7303 for(j
=0; j
<10; j
++) a
[j
] = j
;
7305 Tcl_SetObjResult(interp
, Tcl_NewIntObj(a
[i
]));
7309 Tcl_Panic("Deliberate panic");
7317 ** tclcmd: register_dbstat_vtab DB
7319 ** Cause the dbstat virtual table to be available on the connection DB
7321 static int SQLITE_TCLAPI
test_register_dbstat_vtab(
7325 Tcl_Obj
*CONST objv
[]
7327 #ifdef SQLITE_OMIT_VIRTUALTABLE
7328 Tcl_AppendResult(interp
, "dbstat not available because of "
7329 "SQLITE_OMIT_VIRTUALTABLE", (void*)0);
7332 struct SqliteDb
{ sqlite3
*db
; };
7334 Tcl_CmdInfo cmdInfo
;
7337 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
7341 zDb
= Tcl_GetString(objv
[1]);
7342 if( Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
7343 sqlite3
* db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
7344 sqlite3DbstatRegister(db
);
7347 #endif /* SQLITE_OMIT_VIRTUALTABLE */
7351 ** tclcmd: sqlite3_db_config DB SETTING VALUE
7353 ** Invoke sqlite3_db_config() for one of the setting values.
7355 static int SQLITE_TCLAPI
test_sqlite3_db_config(
7359 Tcl_Obj
*CONST objv
[]
7361 static const struct {
7365 { "FKEY", SQLITE_DBCONFIG_ENABLE_FKEY
},
7366 { "TRIGGER", SQLITE_DBCONFIG_ENABLE_TRIGGER
},
7367 { "FTS3_TOKENIZER", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
},
7368 { "LOAD_EXTENSION", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
},
7369 { "NO_CKPT_ON_CLOSE",SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
},
7370 { "QPSG", SQLITE_DBCONFIG_ENABLE_QPSG
},
7374 const char *zSetting
;
7378 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SETTING VALUE");
7381 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7382 zSetting
= Tcl_GetString(objv
[2]);
7383 if( sqlite3_strglob("SQLITE_*", zSetting
)==0 ) zSetting
+= 7;
7384 if( sqlite3_strglob("DBCONFIG_*", zSetting
)==0 ) zSetting
+= 9;
7385 if( sqlite3_strglob("ENABLE_*", zSetting
)==0 ) zSetting
+= 7;
7386 for(i
=0; i
<ArraySize(aSetting
); i
++){
7387 if( strcmp(zSetting
, aSetting
[i
].zName
)==0 ) break;
7389 if( i
>=ArraySize(aSetting
) ){
7390 Tcl_SetObjResult(interp
,
7391 Tcl_NewStringObj("unknown sqlite3_db_config setting", -1));
7394 if( Tcl_GetIntFromObj(interp
, objv
[3], &v
) ) return TCL_ERROR
;
7395 sqlite3_db_config(db
, aSetting
[i
].eVal
, v
, &v
);
7396 Tcl_SetObjResult(interp
, Tcl_NewIntObj(v
));
7401 ** Change the name of the main database schema from "main" to "icecube".
7403 static int SQLITE_TCLAPI
test_dbconfig_maindbname_icecube(
7407 Tcl_Obj
*CONST objv
[]
7411 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
7413 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
7416 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7417 rc
= sqlite3_db_config(db
, SQLITE_DBCONFIG_MAINDBNAME
, "icecube");
7418 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
7424 ** Usage: sqlite3_mmap_warm DB DBNAME
7426 static int SQLITE_TCLAPI
test_mmap_warm(
7430 Tcl_Obj
*CONST objv
[]
7432 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
7433 extern int sqlite3_mmap_warm(sqlite3
*db
, const char *);
7435 if( objc
!=2 && objc
!=3 ){
7436 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?DBNAME?");
7441 const char *zDb
= 0;
7442 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7444 zDb
= Tcl_GetString(objv
[2]);
7446 rc
= sqlite3_mmap_warm(db
, zDb
);
7447 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
7453 ** Register commands with the TCL interpreter.
7455 int Sqlitetest1_Init(Tcl_Interp
*interp
){
7456 extern int sqlite3_search_count
;
7457 extern int sqlite3_found_count
;
7458 extern int sqlite3_interrupt_count
;
7459 extern int sqlite3_open_file_count
;
7460 extern int sqlite3_sort_count
;
7461 extern int sqlite3_current_time
;
7462 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
7463 extern int sqlite3_hostid_num
;
7465 extern int sqlite3_max_blobsize
;
7466 extern int SQLITE_TCLAPI
sqlite3BtreeSharedCacheReport(void*,
7467 Tcl_Interp
*,int,Tcl_Obj
*CONST
*);
7468 static int iZero
= 0;
7473 { "db_enter", (Tcl_CmdProc
*)db_enter
},
7474 { "db_leave", (Tcl_CmdProc
*)db_leave
},
7475 { "sqlite3_mprintf_int", (Tcl_CmdProc
*)sqlite3_mprintf_int
},
7476 { "sqlite3_mprintf_int64", (Tcl_CmdProc
*)sqlite3_mprintf_int64
},
7477 { "sqlite3_mprintf_long", (Tcl_CmdProc
*)sqlite3_mprintf_long
},
7478 { "sqlite3_mprintf_str", (Tcl_CmdProc
*)sqlite3_mprintf_str
},
7479 { "sqlite3_snprintf_str", (Tcl_CmdProc
*)sqlite3_snprintf_str
},
7480 { "sqlite3_mprintf_stronly", (Tcl_CmdProc
*)sqlite3_mprintf_stronly
},
7481 { "sqlite3_mprintf_double", (Tcl_CmdProc
*)sqlite3_mprintf_double
},
7482 { "sqlite3_mprintf_scaled", (Tcl_CmdProc
*)sqlite3_mprintf_scaled
},
7483 { "sqlite3_mprintf_hexdouble", (Tcl_CmdProc
*)sqlite3_mprintf_hexdouble
},
7484 { "sqlite3_mprintf_z_test", (Tcl_CmdProc
*)test_mprintf_z
},
7485 { "sqlite3_mprintf_n_test", (Tcl_CmdProc
*)test_mprintf_n
},
7486 { "sqlite3_snprintf_int", (Tcl_CmdProc
*)test_snprintf_int
},
7487 { "sqlite3_last_insert_rowid", (Tcl_CmdProc
*)test_last_rowid
},
7488 { "sqlite3_exec_printf", (Tcl_CmdProc
*)test_exec_printf
},
7489 { "sqlite3_exec_hex", (Tcl_CmdProc
*)test_exec_hex
},
7490 { "sqlite3_exec", (Tcl_CmdProc
*)test_exec
},
7491 { "sqlite3_exec_nr", (Tcl_CmdProc
*)test_exec_nr
},
7492 #ifndef SQLITE_OMIT_GET_TABLE
7493 { "sqlite3_get_table_printf", (Tcl_CmdProc
*)test_get_table_printf
},
7495 { "sqlite3_close", (Tcl_CmdProc
*)sqlite_test_close
},
7496 { "sqlite3_close_v2", (Tcl_CmdProc
*)sqlite_test_close_v2
},
7497 { "sqlite3_create_function", (Tcl_CmdProc
*)test_create_function
},
7498 { "sqlite3_create_aggregate", (Tcl_CmdProc
*)test_create_aggregate
},
7499 { "sqlite_register_test_function", (Tcl_CmdProc
*)test_register_func
},
7500 { "sqlite_abort", (Tcl_CmdProc
*)sqlite_abort
},
7501 { "sqlite_bind", (Tcl_CmdProc
*)test_bind
},
7502 { "breakpoint", (Tcl_CmdProc
*)test_breakpoint
},
7503 { "sqlite3_key", (Tcl_CmdProc
*)test_key
},
7504 { "sqlite3_rekey", (Tcl_CmdProc
*)test_rekey
},
7505 { "sqlite_set_magic", (Tcl_CmdProc
*)sqlite_set_magic
},
7506 { "sqlite3_interrupt", (Tcl_CmdProc
*)test_interrupt
},
7507 { "sqlite_delete_function", (Tcl_CmdProc
*)delete_function
},
7508 { "sqlite_delete_collation", (Tcl_CmdProc
*)delete_collation
},
7509 { "sqlite3_get_autocommit", (Tcl_CmdProc
*)get_autocommit
},
7510 { "sqlite3_busy_timeout", (Tcl_CmdProc
*)test_busy_timeout
},
7511 { "printf", (Tcl_CmdProc
*)test_printf
},
7512 { "sqlite3IoTrace", (Tcl_CmdProc
*)test_io_trace
},
7513 { "clang_sanitize_address", (Tcl_CmdProc
*)clang_sanitize_address
},
7517 Tcl_ObjCmdProc
*xProc
;
7520 { "sqlite3_db_config", test_sqlite3_db_config
, 0 },
7521 { "bad_behavior", test_bad_behavior
, (void*)&iZero
},
7522 { "register_dbstat_vtab", test_register_dbstat_vtab
},
7523 { "sqlite3_connection_pointer", get_sqlite_pointer
, 0 },
7524 { "intarray_addr", test_intarray_addr
, 0 },
7525 { "int64array_addr", test_int64array_addr
, 0 },
7526 { "doublearray_addr", test_doublearray_addr
, 0 },
7527 { "textarray_addr", test_textarray_addr
, 0 },
7528 { "sqlite3_bind_int", test_bind_int
, 0 },
7529 { "sqlite3_bind_zeroblob", test_bind_zeroblob
, 0 },
7530 { "sqlite3_bind_zeroblob64", test_bind_zeroblob64
, 0 },
7531 { "sqlite3_bind_int64", test_bind_int64
, 0 },
7532 { "sqlite3_bind_double", test_bind_double
, 0 },
7533 { "sqlite3_bind_null", test_bind_null
,0 },
7534 { "sqlite3_bind_text", test_bind_text
,0 },
7535 { "sqlite3_bind_text16", test_bind_text16
,0 },
7536 { "sqlite3_bind_blob", test_bind_blob
,0 },
7537 { "sqlite3_bind_parameter_count", test_bind_parameter_count
, 0},
7538 { "sqlite3_bind_parameter_name", test_bind_parameter_name
, 0},
7539 { "sqlite3_bind_parameter_index", test_bind_parameter_index
, 0},
7540 { "sqlite3_clear_bindings", test_clear_bindings
, 0},
7541 { "sqlite3_sleep", test_sleep
, 0},
7542 { "sqlite3_errcode", test_errcode
,0 },
7543 { "sqlite3_extended_errcode", test_ex_errcode
,0 },
7544 { "sqlite3_errmsg", test_errmsg
,0 },
7545 { "sqlite3_errmsg16", test_errmsg16
,0 },
7546 { "sqlite3_open", test_open
,0 },
7547 { "sqlite3_open16", test_open16
,0 },
7548 { "sqlite3_open_v2", test_open_v2
,0 },
7549 { "sqlite3_complete16", test_complete16
,0 },
7551 { "sqlite3_prepare", test_prepare
,0 },
7552 { "sqlite3_prepare16", test_prepare16
,0 },
7553 { "sqlite3_prepare_v2", test_prepare_v2
,0 },
7554 { "sqlite3_prepare_tkt3134", test_prepare_tkt3134
, 0},
7555 { "sqlite3_prepare16_v2", test_prepare16_v2
,0 },
7556 { "sqlite3_finalize", test_finalize
,0 },
7557 { "sqlite3_stmt_status", test_stmt_status
,0 },
7558 { "sqlite3_reset", test_reset
,0 },
7559 { "sqlite3_expired", test_expired
,0 },
7560 { "sqlite3_transfer_bindings", test_transfer_bind
,0 },
7561 { "sqlite3_changes", test_changes
,0 },
7562 { "sqlite3_step", test_step
,0 },
7563 { "sqlite3_sql", test_sql
,0 },
7564 { "sqlite3_expanded_sql", test_ex_sql
,0 },
7565 { "sqlite3_next_stmt", test_next_stmt
,0 },
7566 { "sqlite3_stmt_readonly", test_stmt_readonly
,0 },
7567 { "sqlite3_stmt_busy", test_stmt_busy
,0 },
7568 { "uses_stmt_journal", uses_stmt_journal
,0 },
7570 { "sqlite3_release_memory", test_release_memory
, 0},
7571 { "sqlite3_db_release_memory", test_db_release_memory
, 0},
7572 { "sqlite3_db_cacheflush", test_db_cacheflush
, 0},
7573 { "sqlite3_system_errno", test_system_errno
, 0},
7574 { "sqlite3_db_filename", test_db_filename
, 0},
7575 { "sqlite3_db_readonly", test_db_readonly
, 0},
7576 { "sqlite3_soft_heap_limit", test_soft_heap_limit
, 0},
7577 { "sqlite3_thread_cleanup", test_thread_cleanup
, 0},
7578 { "sqlite3_pager_refcounts", test_pager_refcounts
, 0},
7580 { "sqlite3_load_extension", test_load_extension
, 0},
7581 { "sqlite3_enable_load_extension", test_enable_load
, 0},
7582 { "sqlite3_extended_result_codes", test_extended_result_codes
, 0},
7583 { "sqlite3_limit", test_limit
, 0},
7584 { "dbconfig_maindbname_icecube", test_dbconfig_maindbname_icecube
},
7586 { "save_prng_state", save_prng_state
, 0 },
7587 { "restore_prng_state", restore_prng_state
, 0 },
7588 { "reset_prng_state", reset_prng_state
, 0 },
7589 { "database_never_corrupt", database_never_corrupt
, 0},
7590 { "database_may_be_corrupt", database_may_be_corrupt
, 0},
7591 { "optimization_control", optimization_control
,0},
7593 { "lock_win32_file", win32_file_lock
, 0 },
7594 { "exists_win32_path", win32_exists_path
, 0 },
7595 { "find_win32_file", win32_find_file
, 0 },
7596 { "delete_win32_file", win32_delete_file
, 0 },
7597 { "make_win32_dir", win32_mkdir
, 0 },
7598 { "remove_win32_dir", win32_rmdir
, 0 },
7600 { "tcl_objproc", runAsObjProc
, 0 },
7602 /* sqlite3_column_*() API */
7603 { "sqlite3_column_count", test_column_count
,0 },
7604 { "sqlite3_data_count", test_data_count
,0 },
7605 { "sqlite3_column_type", test_column_type
,0 },
7606 { "sqlite3_column_blob", test_column_blob
,0 },
7607 { "sqlite3_column_double", test_column_double
,0 },
7608 { "sqlite3_column_int64", test_column_int64
,0 },
7609 { "sqlite3_column_text", test_stmt_utf8
, (void*)sqlite3_column_text
},
7610 { "sqlite3_column_name", test_stmt_utf8
, (void*)sqlite3_column_name
},
7611 { "sqlite3_column_int", test_stmt_int
, (void*)sqlite3_column_int
},
7612 { "sqlite3_column_bytes", test_stmt_int
, (void*)sqlite3_column_bytes
},
7613 #ifndef SQLITE_OMIT_DECLTYPE
7614 { "sqlite3_column_decltype",test_stmt_utf8
,(void*)sqlite3_column_decltype
},
7616 #ifdef SQLITE_ENABLE_COLUMN_METADATA
7617 { "sqlite3_column_database_name",test_stmt_utf8
,(void*)sqlite3_column_database_name
},
7618 { "sqlite3_column_table_name",test_stmt_utf8
,(void*)sqlite3_column_table_name
},
7619 { "sqlite3_column_origin_name",test_stmt_utf8
,(void*)sqlite3_column_origin_name
},
7622 #ifndef SQLITE_OMIT_UTF16
7623 { "sqlite3_column_bytes16", test_stmt_int
, (void*)sqlite3_column_bytes16
},
7624 { "sqlite3_column_text16", test_stmt_utf16
, (void*)sqlite3_column_text16
},
7625 { "sqlite3_column_name16", test_stmt_utf16
, (void*)sqlite3_column_name16
},
7626 { "add_alignment_test_collations", add_alignment_test_collations
, 0 },
7627 #ifndef SQLITE_OMIT_DECLTYPE
7628 { "sqlite3_column_decltype16",test_stmt_utf16
,(void*)sqlite3_column_decltype16
},
7630 #ifdef SQLITE_ENABLE_COLUMN_METADATA
7631 {"sqlite3_column_database_name16",
7632 test_stmt_utf16
, (void*)sqlite3_column_database_name16
},
7633 {"sqlite3_column_table_name16", test_stmt_utf16
, (void*)sqlite3_column_table_name16
},
7634 {"sqlite3_column_origin_name16", test_stmt_utf16
, (void*)sqlite3_column_origin_name16
},
7637 { "sqlite3_create_collation_v2", test_create_collation_v2
, 0 },
7638 { "sqlite3_global_recover", test_global_recover
, 0 },
7639 { "working_64bit_int", working_64bit_int
, 0 },
7640 { "vfs_unlink_test", vfs_unlink_test
, 0 },
7641 { "vfs_initfail_test", vfs_initfail_test
, 0 },
7642 { "vfs_unregister_all", vfs_unregister_all
, 0 },
7643 { "vfs_reregister_all", vfs_reregister_all
, 0 },
7644 { "file_control_test", file_control_test
, 0 },
7645 { "file_control_lasterrno_test", file_control_lasterrno_test
, 0 },
7646 { "file_control_lockproxy_test", file_control_lockproxy_test
, 0 },
7647 { "file_control_chunksize_test", file_control_chunksize_test
, 0 },
7648 { "file_control_sizehint_test", file_control_sizehint_test
, 0 },
7650 { "file_control_win32_av_retry", file_control_win32_av_retry
, 0 },
7651 { "file_control_win32_get_handle", file_control_win32_get_handle
, 0 },
7652 { "file_control_win32_set_handle", file_control_win32_set_handle
, 0 },
7654 { "file_control_persist_wal", file_control_persist_wal
, 0 },
7655 { "file_control_powersafe_overwrite",file_control_powersafe_overwrite
,0},
7656 { "file_control_vfsname", file_control_vfsname
, 0 },
7657 { "file_control_tempfilename", file_control_tempfilename
, 0 },
7658 { "sqlite3_vfs_list", vfs_list
, 0 },
7659 { "sqlite3_create_function_v2", test_create_function_v2
, 0 },
7661 /* Functions from os.h */
7662 #ifndef SQLITE_OMIT_UTF16
7663 { "add_test_collate", test_collate
, 0 },
7664 { "add_test_collate_needed", test_collate_needed
, 0 },
7665 { "add_test_function", test_function
, 0 },
7666 { "add_test_utf16bin_collate", test_utf16bin_collate
, 0 },
7668 { "sqlite3_test_errstr", test_errstr
, 0 },
7669 { "tcl_variable_type", tcl_variable_type
, 0 },
7670 #ifndef SQLITE_OMIT_SHARED_CACHE
7671 { "sqlite3_enable_shared_cache", test_enable_shared
, 0 },
7672 { "sqlite3_shared_cache_report", sqlite3BtreeSharedCacheReport
, 0},
7674 { "sqlite3_libversion_number", test_libversion_number
, 0 },
7675 { "sqlite3_table_column_metadata", test_table_column_metadata
, 0 },
7676 #ifndef SQLITE_OMIT_INCRBLOB
7677 { "sqlite3_blob_reopen", test_blob_reopen
, 0 },
7679 { "pcache_stats", test_pcache_stats
, 0 },
7680 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
7681 { "sqlite3_unlock_notify", test_unlock_notify
, 0 },
7683 { "sqlite3_wal_checkpoint", test_wal_checkpoint
, 0 },
7684 { "sqlite3_wal_checkpoint_v2",test_wal_checkpoint_v2
, 0 },
7685 { "sqlite3_wal_autocheckpoint",test_wal_autocheckpoint
, 0 },
7686 { "test_sqlite3_log", test_sqlite3_log
, 0 },
7687 #ifndef SQLITE_OMIT_EXPLAIN
7688 { "print_explain_query_plan", test_print_eqp
, 0 },
7690 { "sqlite3_test_control", test_test_control
},
7692 { "getrusage", test_getrusage
},
7694 { "load_static_extension", tclLoadStaticExtensionCmd
},
7695 { "sorter_test_fakeheap", sorter_test_fakeheap
},
7696 { "sorter_test_sort4_helper", sorter_test_sort4_helper
},
7697 #ifdef SQLITE_USER_AUTHENTICATION
7698 { "sqlite3_user_authenticate", test_user_authenticate
, 0 },
7699 { "sqlite3_user_add", test_user_add
, 0 },
7700 { "sqlite3_user_change", test_user_change
, 0 },
7701 { "sqlite3_user_delete", test_user_delete
, 0 },
7703 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
7704 { "sqlite3_stmt_scanstatus", test_stmt_scanstatus
, 0 },
7705 { "sqlite3_stmt_scanstatus_reset", test_stmt_scanstatus_reset
, 0 },
7707 #ifdef SQLITE_ENABLE_SQLLOG
7708 { "sqlite3_config_sqllog", test_config_sqllog
, 0 },
7710 { "vfs_current_time_int64", vfsCurrentTimeInt64
, 0 },
7711 #ifdef SQLITE_ENABLE_SNAPSHOT
7712 { "sqlite3_snapshot_get", test_snapshot_get
, 0 },
7713 { "sqlite3_snapshot_open", test_snapshot_open
, 0 },
7714 { "sqlite3_snapshot_free", test_snapshot_free
, 0 },
7715 { "sqlite3_snapshot_cmp", test_snapshot_cmp
, 0 },
7716 { "sqlite3_snapshot_recover", test_snapshot_recover
, 0 },
7717 { "sqlite3_snapshot_get_blob", test_snapshot_get_blob
, 0 },
7718 { "sqlite3_snapshot_open_blob", test_snapshot_open_blob
, 0 },
7719 { "sqlite3_snapshot_cmp_blob", test_snapshot_cmp_blob
, 0 },
7721 { "sqlite3_delete_database", test_delete_database
, 0 },
7722 { "atomic_batch_write", test_atomic_batch_write
, 0 },
7723 { "sqlite3_mmap_warm", test_mmap_warm
, 0 },
7725 static int bitmask_size
= sizeof(Bitmask
)*8;
7726 static int longdouble_size
= sizeof(LONGDOUBLE_TYPE
);
7728 extern int sqlite3_sync_count
, sqlite3_fullsync_count
;
7729 extern int sqlite3_opentemp_count
;
7730 extern int sqlite3_like_count
;
7731 extern int sqlite3_xferopt_count
;
7732 extern int sqlite3_pager_readdb_count
;
7733 extern int sqlite3_pager_writedb_count
;
7734 extern int sqlite3_pager_writej_count
;
7736 extern LONG
volatile sqlite3_os_type
;
7739 extern int sqlite3WhereTrace
;
7740 extern int sqlite3OSTrace
;
7741 extern int sqlite3WalTrace
;
7744 #ifdef SQLITE_ENABLE_FTS3
7745 extern int sqlite3_fts3_enable_parentheses
;
7749 for(i
=0; i
<sizeof(aCmd
)/sizeof(aCmd
[0]); i
++){
7750 Tcl_CreateCommand(interp
, aCmd
[i
].zName
, aCmd
[i
].xProc
, 0, 0);
7752 for(i
=0; i
<sizeof(aObjCmd
)/sizeof(aObjCmd
[0]); i
++){
7753 Tcl_CreateObjCommand(interp
, aObjCmd
[i
].zName
,
7754 aObjCmd
[i
].xProc
, aObjCmd
[i
].clientData
, 0);
7756 Tcl_LinkVar(interp
, "sqlite_search_count",
7757 (char*)&sqlite3_search_count
, TCL_LINK_INT
);
7758 Tcl_LinkVar(interp
, "sqlite_found_count",
7759 (char*)&sqlite3_found_count
, TCL_LINK_INT
);
7760 Tcl_LinkVar(interp
, "sqlite_sort_count",
7761 (char*)&sqlite3_sort_count
, TCL_LINK_INT
);
7762 Tcl_LinkVar(interp
, "sqlite3_max_blobsize",
7763 (char*)&sqlite3_max_blobsize
, TCL_LINK_INT
);
7764 Tcl_LinkVar(interp
, "sqlite_like_count",
7765 (char*)&sqlite3_like_count
, TCL_LINK_INT
);
7766 Tcl_LinkVar(interp
, "sqlite_interrupt_count",
7767 (char*)&sqlite3_interrupt_count
, TCL_LINK_INT
);
7768 Tcl_LinkVar(interp
, "sqlite_open_file_count",
7769 (char*)&sqlite3_open_file_count
, TCL_LINK_INT
);
7770 Tcl_LinkVar(interp
, "sqlite_current_time",
7771 (char*)&sqlite3_current_time
, TCL_LINK_INT
);
7772 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
7773 Tcl_LinkVar(interp
, "sqlite_hostid_num",
7774 (char*)&sqlite3_hostid_num
, TCL_LINK_INT
);
7776 Tcl_LinkVar(interp
, "sqlite3_xferopt_count",
7777 (char*)&sqlite3_xferopt_count
, TCL_LINK_INT
);
7778 Tcl_LinkVar(interp
, "sqlite3_pager_readdb_count",
7779 (char*)&sqlite3_pager_readdb_count
, TCL_LINK_INT
);
7780 Tcl_LinkVar(interp
, "sqlite3_pager_writedb_count",
7781 (char*)&sqlite3_pager_writedb_count
, TCL_LINK_INT
);
7782 Tcl_LinkVar(interp
, "sqlite3_pager_writej_count",
7783 (char*)&sqlite3_pager_writej_count
, TCL_LINK_INT
);
7784 #ifndef SQLITE_OMIT_UTF16
7785 Tcl_LinkVar(interp
, "unaligned_string_counter",
7786 (char*)&unaligned_string_counter
, TCL_LINK_INT
);
7788 #ifndef SQLITE_OMIT_UTF16
7789 Tcl_LinkVar(interp
, "sqlite_last_needed_collation",
7790 (char*)&pzNeededCollation
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
7793 Tcl_LinkVar(interp
, "sqlite_os_type",
7794 (char*)&sqlite3_os_type
, TCL_LINK_LONG
);
7798 static const char *query_plan
= "*** OBSOLETE VARIABLE ***";
7799 Tcl_LinkVar(interp
, "sqlite_query_plan",
7800 (char*)&query_plan
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
7804 Tcl_LinkVar(interp
, "sqlite_where_trace",
7805 (char*)&sqlite3WhereTrace
, TCL_LINK_INT
);
7806 Tcl_LinkVar(interp
, "sqlite_os_trace",
7807 (char*)&sqlite3OSTrace
, TCL_LINK_INT
);
7808 #ifndef SQLITE_OMIT_WAL
7809 Tcl_LinkVar(interp
, "sqlite_wal_trace",
7810 (char*)&sqlite3WalTrace
, TCL_LINK_INT
);
7813 #ifndef SQLITE_OMIT_DISKIO
7814 Tcl_LinkVar(interp
, "sqlite_opentemp_count",
7815 (char*)&sqlite3_opentemp_count
, TCL_LINK_INT
);
7817 Tcl_LinkVar(interp
, "sqlite_static_bind_value",
7818 (char*)&sqlite_static_bind_value
, TCL_LINK_STRING
);
7819 Tcl_LinkVar(interp
, "sqlite_static_bind_nbyte",
7820 (char*)&sqlite_static_bind_nbyte
, TCL_LINK_INT
);
7821 Tcl_LinkVar(interp
, "sqlite_temp_directory",
7822 (char*)&sqlite3_temp_directory
, TCL_LINK_STRING
);
7823 Tcl_LinkVar(interp
, "sqlite_data_directory",
7824 (char*)&sqlite3_data_directory
, TCL_LINK_STRING
);
7825 Tcl_LinkVar(interp
, "bitmask_size",
7826 (char*)&bitmask_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
7827 Tcl_LinkVar(interp
, "longdouble_size",
7828 (char*)&longdouble_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
7829 Tcl_LinkVar(interp
, "sqlite_sync_count",
7830 (char*)&sqlite3_sync_count
, TCL_LINK_INT
);
7831 Tcl_LinkVar(interp
, "sqlite_fullsync_count",
7832 (char*)&sqlite3_fullsync_count
, TCL_LINK_INT
);
7833 #if defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_TEST)
7834 Tcl_LinkVar(interp
, "sqlite_fts3_enable_parentheses",
7835 (char*)&sqlite3_fts3_enable_parentheses
, TCL_LINK_INT
);