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_normalize SQL
4565 ** Return the normalized value for an SQL statement.
4567 static int SQLITE_TCLAPI
test_normalize(
4571 Tcl_Obj
*CONST objv
[]
4575 extern char *sqlite3_normalize(const char*);
4578 Tcl_WrongNumArgs(interp
, 1, objv
, "SQL");
4582 zSql
= (char*)Tcl_GetString(objv
[1]);
4583 zNorm
= sqlite3_normalize(zSql
);
4585 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zNorm
, -1));
4586 sqlite3_free(zNorm
);
4592 ** Usage: sqlite3_step STMT
4594 ** Advance the statement to the next row.
4596 static int SQLITE_TCLAPI
test_step(
4600 Tcl_Obj
*CONST objv
[]
4602 sqlite3_stmt
*pStmt
;
4606 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4607 Tcl_GetString(objv
[0]), " STMT", 0);
4611 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4612 rc
= sqlite3_step(pStmt
);
4614 /* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */
4615 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
4619 static int SQLITE_TCLAPI
test_sql(
4623 Tcl_Obj
*CONST objv
[]
4625 sqlite3_stmt
*pStmt
;
4628 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4632 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4633 Tcl_SetResult(interp
, (char *)sqlite3_sql(pStmt
), TCL_VOLATILE
);
4636 static int SQLITE_TCLAPI
test_ex_sql(
4640 Tcl_Obj
*CONST objv
[]
4642 sqlite3_stmt
*pStmt
;
4646 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4650 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4651 z
= sqlite3_expanded_sql(pStmt
);
4652 Tcl_SetResult(interp
, z
, TCL_VOLATILE
);
4658 ** Usage: sqlite3_column_count STMT
4660 ** Return the number of columns returned by the sql statement STMT.
4662 static int SQLITE_TCLAPI
test_column_count(
4666 Tcl_Obj
*CONST objv
[]
4668 sqlite3_stmt
*pStmt
;
4671 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4672 Tcl_GetString(objv
[0]), " STMT column", 0);
4676 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4678 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_column_count(pStmt
)));
4683 ** Usage: sqlite3_column_type STMT column
4685 ** Return the type of the data in column 'column' of the current row.
4687 static int SQLITE_TCLAPI
test_column_type(
4691 Tcl_Obj
*CONST objv
[]
4693 sqlite3_stmt
*pStmt
;
4698 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4699 Tcl_GetString(objv
[0]), " STMT column", 0);
4703 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4704 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4706 tp
= sqlite3_column_type(pStmt
, col
);
4708 case SQLITE_INTEGER
:
4709 Tcl_SetResult(interp
, "INTEGER", TCL_STATIC
);
4712 Tcl_SetResult(interp
, "NULL", TCL_STATIC
);
4715 Tcl_SetResult(interp
, "FLOAT", TCL_STATIC
);
4718 Tcl_SetResult(interp
, "TEXT", TCL_STATIC
);
4721 Tcl_SetResult(interp
, "BLOB", TCL_STATIC
);
4731 ** Usage: sqlite3_column_int64 STMT column
4733 ** Return the data in column 'column' of the current row cast as an
4734 ** wide (64-bit) integer.
4736 static int SQLITE_TCLAPI
test_column_int64(
4740 Tcl_Obj
*CONST objv
[]
4742 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 iVal
= sqlite3_column_int64(pStmt
, col
);
4756 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(iVal
));
4761 ** Usage: sqlite3_column_blob STMT column
4763 static int SQLITE_TCLAPI
test_column_blob(
4767 Tcl_Obj
*CONST objv
[]
4769 sqlite3_stmt
*pStmt
;
4776 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4777 Tcl_GetString(objv
[0]), " STMT column", 0);
4781 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4782 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4784 len
= sqlite3_column_bytes(pStmt
, col
);
4785 pBlob
= sqlite3_column_blob(pStmt
, col
);
4786 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(pBlob
, len
));
4791 ** Usage: sqlite3_column_double STMT column
4793 ** Return the data in column 'column' of the current row cast as a double.
4795 static int SQLITE_TCLAPI
test_column_double(
4799 Tcl_Obj
*CONST objv
[]
4801 sqlite3_stmt
*pStmt
;
4806 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4807 Tcl_GetString(objv
[0]), " STMT column", 0);
4811 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4812 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4814 rVal
= sqlite3_column_double(pStmt
, col
);
4815 Tcl_SetObjResult(interp
, Tcl_NewDoubleObj(rVal
));
4820 ** Usage: sqlite3_data_count STMT
4822 ** Return the number of columns returned by the sql statement STMT.
4824 static int SQLITE_TCLAPI
test_data_count(
4828 Tcl_Obj
*CONST objv
[]
4830 sqlite3_stmt
*pStmt
;
4833 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4834 Tcl_GetString(objv
[0]), " STMT column", 0);
4838 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4840 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_data_count(pStmt
)));
4845 ** Usage: sqlite3_column_text STMT column
4847 ** Usage: sqlite3_column_decltype STMT column
4849 ** Usage: sqlite3_column_name STMT column
4851 static int SQLITE_TCLAPI
test_stmt_utf8(
4852 void * clientData
, /* Pointer to SQLite API function to be invoke */
4855 Tcl_Obj
*CONST objv
[]
4857 sqlite3_stmt
*pStmt
;
4859 const char *(*xFunc
)(sqlite3_stmt
*, int);
4862 xFunc
= (const char *(*)(sqlite3_stmt
*, int))clientData
;
4864 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4865 Tcl_GetString(objv
[0]), " STMT column", 0);
4869 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4870 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4871 zRet
= xFunc(pStmt
, col
);
4873 Tcl_SetResult(interp
, (char *)zRet
, 0);
4878 static int SQLITE_TCLAPI
test_global_recover(
4882 Tcl_Obj
*CONST objv
[]
4884 #ifndef SQLITE_OMIT_DEPRECATED
4887 Tcl_WrongNumArgs(interp
, 1, objv
, "");
4890 rc
= sqlite3_global_recover();
4891 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
4897 ** Usage: sqlite3_column_text STMT column
4899 ** Usage: sqlite3_column_decltype STMT column
4901 ** Usage: sqlite3_column_name STMT column
4903 static int SQLITE_TCLAPI
test_stmt_utf16(
4904 void * clientData
, /* Pointer to SQLite API function to be invoked */
4907 Tcl_Obj
*CONST objv
[]
4909 #ifndef SQLITE_OMIT_UTF16
4910 sqlite3_stmt
*pStmt
;
4913 const void *zName16
;
4914 const void *(*xFunc
)(sqlite3_stmt
*, int);
4916 xFunc
= (const void *(*)(sqlite3_stmt
*, int))clientData
;
4918 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4919 Tcl_GetString(objv
[0]), " STMT column", 0);
4923 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4924 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4926 zName16
= xFunc(pStmt
, col
);
4929 const char *z
= zName16
;
4930 for(n
=0; z
[n
] || z
[n
+1]; n
+=2){}
4931 pRet
= Tcl_NewByteArrayObj(zName16
, n
+2);
4932 Tcl_SetObjResult(interp
, pRet
);
4934 #endif /* SQLITE_OMIT_UTF16 */
4940 ** Usage: sqlite3_column_int STMT column
4942 ** Usage: sqlite3_column_bytes STMT column
4944 ** Usage: sqlite3_column_bytes16 STMT column
4947 static int SQLITE_TCLAPI
test_stmt_int(
4948 void * clientData
, /* Pointer to SQLite API function to be invoked */
4951 Tcl_Obj
*CONST objv
[]
4953 sqlite3_stmt
*pStmt
;
4955 int (*xFunc
)(sqlite3_stmt
*, int);
4957 xFunc
= (int (*)(sqlite3_stmt
*, int))clientData
;
4959 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4960 Tcl_GetString(objv
[0]), " STMT column", 0);
4964 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4965 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
4967 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xFunc(pStmt
, col
)));
4972 ** Usage: sqlite_set_magic DB MAGIC-NUMBER
4974 ** Set the db->magic value. This is used to test error recovery logic.
4976 static int SQLITE_TCLAPI
sqlite_set_magic(
4984 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
4988 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
4989 if( strcmp(argv
[2], "SQLITE_MAGIC_OPEN")==0 ){
4990 db
->magic
= SQLITE_MAGIC_OPEN
;
4991 }else if( strcmp(argv
[2], "SQLITE_MAGIC_CLOSED")==0 ){
4992 db
->magic
= SQLITE_MAGIC_CLOSED
;
4993 }else if( strcmp(argv
[2], "SQLITE_MAGIC_BUSY")==0 ){
4994 db
->magic
= SQLITE_MAGIC_BUSY
;
4995 }else if( strcmp(argv
[2], "SQLITE_MAGIC_ERROR")==0 ){
4996 db
->magic
= SQLITE_MAGIC_ERROR
;
4997 }else if( Tcl_GetInt(interp
, argv
[2], (int*)&db
->magic
) ){
5004 ** Usage: sqlite3_interrupt DB
5006 ** Trigger an interrupt on DB
5008 static int SQLITE_TCLAPI
test_interrupt(
5016 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB", 0);
5019 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5020 sqlite3_interrupt(db
);
5025 ** Usage: sqlite_delete_function DB function-name
5027 ** Delete the user function 'function-name' from database handle DB. It
5028 ** is assumed that the user function was created as UTF8, any number of
5029 ** arguments (the way the TCL interface does it).
5031 static int SQLITE_TCLAPI
delete_function(
5040 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5041 " DB function-name", 0);
5044 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5045 rc
= sqlite3_create_function(db
, argv
[2], -1, SQLITE_UTF8
, 0, 0, 0, 0);
5046 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5051 ** Usage: sqlite_delete_collation DB collation-name
5053 ** Delete the collation sequence 'collation-name' from database handle
5054 ** DB. It is assumed that the collation sequence was created as UTF8 (the
5055 ** way the TCL interface does it).
5057 static int SQLITE_TCLAPI
delete_collation(
5066 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5067 " DB function-name", 0);
5070 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5071 rc
= sqlite3_create_collation(db
, argv
[2], SQLITE_UTF8
, 0, 0);
5072 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5077 ** Usage: sqlite3_get_autocommit DB
5079 ** Return true if the database DB is currently in auto-commit mode.
5080 ** Return false if not.
5082 static int SQLITE_TCLAPI
get_autocommit(
5091 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5095 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5096 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", sqlite3_get_autocommit(db
));
5097 Tcl_AppendResult(interp
, zBuf
, 0);
5102 ** Usage: sqlite3_busy_timeout DB MS
5104 ** Set the busy timeout. This is more easily done using the timeout
5105 ** method of the TCL interface. But we need a way to test the case
5106 ** where it returns SQLITE_MISUSE.
5108 static int SQLITE_TCLAPI
test_busy_timeout(
5117 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5121 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5122 if( Tcl_GetInt(interp
, argv
[2], &ms
) ) return TCL_ERROR
;
5123 rc
= sqlite3_busy_timeout(db
, ms
);
5124 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
5129 ** Usage: tcl_variable_type VARIABLENAME
5131 ** Return the name of the internal representation for the
5132 ** value of the given variable.
5134 static int SQLITE_TCLAPI
tcl_variable_type(
5138 Tcl_Obj
*CONST objv
[]
5142 Tcl_WrongNumArgs(interp
, 1, objv
, "VARIABLE");
5145 pVar
= Tcl_GetVar2Ex(interp
, Tcl_GetString(objv
[1]), 0, TCL_LEAVE_ERR_MSG
);
5146 if( pVar
==0 ) return TCL_ERROR
;
5147 if( pVar
->typePtr
){
5148 Tcl_SetObjResult(interp
, Tcl_NewStringObj(pVar
->typePtr
->name
, -1));
5154 ** Usage: sqlite3_release_memory ?N?
5156 ** Attempt to release memory currently held but not actually required.
5157 ** The integer N is the number of bytes we are trying to release. The
5158 ** return value is the amount of memory actually released.
5160 static int SQLITE_TCLAPI
test_release_memory(
5164 Tcl_Obj
*CONST objv
[]
5166 #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
5169 if( objc
!=1 && objc
!=2 ){
5170 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5174 if( Tcl_GetIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5178 amt
= sqlite3_release_memory(N
);
5179 Tcl_SetObjResult(interp
, Tcl_NewIntObj(amt
));
5186 ** Usage: sqlite3_db_release_memory DB
5188 ** Attempt to release memory currently held by database DB. Return the
5189 ** result code (which in the current implementation is always zero).
5191 static int SQLITE_TCLAPI
test_db_release_memory(
5195 Tcl_Obj
*CONST objv
[]
5200 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5203 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5204 rc
= sqlite3_db_release_memory(db
);
5205 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5210 ** Usage: sqlite3_db_cacheflush DB
5212 ** Attempt to flush any dirty pages to disk.
5214 static int SQLITE_TCLAPI
test_db_cacheflush(
5218 Tcl_Obj
*CONST objv
[]
5223 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5226 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5227 rc
= sqlite3_db_cacheflush(db
);
5229 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(rc
), TCL_STATIC
);
5233 Tcl_ResetResult(interp
);
5238 ** Usage: sqlite3_system_errno DB
5240 ** Return the low-level system errno value.
5242 static int SQLITE_TCLAPI
test_system_errno(
5246 Tcl_Obj
*CONST objv
[]
5251 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
5254 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5255 iErrno
= sqlite3_system_errno(db
);
5256 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iErrno
));
5261 ** Usage: sqlite3_db_filename DB DBNAME
5263 ** Return the name of a file associated with a database.
5265 static int SQLITE_TCLAPI
test_db_filename(
5269 Tcl_Obj
*CONST objv
[]
5272 const char *zDbName
;
5274 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
5277 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5278 zDbName
= Tcl_GetString(objv
[2]);
5279 Tcl_AppendResult(interp
, sqlite3_db_filename(db
, zDbName
), (void*)0);
5284 ** Usage: sqlite3_db_readonly DB DBNAME
5286 ** Return 1 or 0 if DBNAME is readonly or not. Return -1 if DBNAME does
5289 static int SQLITE_TCLAPI
test_db_readonly(
5293 Tcl_Obj
*CONST objv
[]
5296 const char *zDbName
;
5298 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
5301 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5302 zDbName
= Tcl_GetString(objv
[2]);
5303 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_db_readonly(db
, zDbName
)));
5308 ** Usage: sqlite3_soft_heap_limit ?N?
5310 ** Query or set the soft heap limit for the current thread. The
5311 ** limit is only changed if the N is present. The previous limit
5314 static int SQLITE_TCLAPI
test_soft_heap_limit(
5318 Tcl_Obj
*CONST objv
[]
5322 if( objc
!=1 && objc
!=2 ){
5323 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5327 if( Tcl_GetWideIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5329 amt
= sqlite3_soft_heap_limit64(N
);
5330 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(amt
));
5335 ** Usage: sqlite3_thread_cleanup
5337 ** Call the sqlite3_thread_cleanup API.
5339 static int SQLITE_TCLAPI
test_thread_cleanup(
5343 Tcl_Obj
*CONST objv
[]
5345 #ifndef SQLITE_OMIT_DEPRECATED
5346 sqlite3_thread_cleanup();
5352 ** Usage: sqlite3_pager_refcounts DB
5354 ** Return a list of numbers which are the PagerRefcount for all
5355 ** pagers on each database connection.
5357 static int SQLITE_TCLAPI
test_pager_refcounts(
5361 Tcl_Obj
*CONST objv
[]
5369 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5370 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
5373 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5374 pResult
= Tcl_NewObj();
5375 for(i
=0; i
<db
->nDb
; i
++){
5376 if( db
->aDb
[i
].pBt
==0 ){
5379 sqlite3_mutex_enter(db
->mutex
);
5380 a
= sqlite3PagerStats(sqlite3BtreePager(db
->aDb
[i
].pBt
));
5382 sqlite3_mutex_leave(db
->mutex
);
5384 Tcl_ListObjAppendElement(0, pResult
, Tcl_NewIntObj(v
));
5386 Tcl_SetObjResult(interp
, pResult
);
5392 ** tclcmd: working_64bit_int
5394 ** Some TCL builds (ex: cygwin) do not support 64-bit integers. This
5395 ** leads to a number of test failures. The present command checks the
5396 ** TCL build to see whether or not it supports 64-bit integers. It
5397 ** returns TRUE if it does and FALSE if not.
5399 ** This command is used to warn users that their TCL build is defective
5400 ** and that the errors they are seeing in the test scripts might be
5401 ** a result of their defective TCL rather than problems in SQLite.
5403 static int SQLITE_TCLAPI
working_64bit_int(
5404 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5405 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5406 int objc
, /* Number of arguments */
5407 Tcl_Obj
*CONST objv
[] /* Command arguments */
5412 pTestObj
= Tcl_NewWideIntObj(1000000*(i64
)1234567890);
5413 working
= strcmp(Tcl_GetString(pTestObj
), "1234567890000000")==0;
5414 Tcl_DecrRefCount(pTestObj
);
5415 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(working
));
5421 ** tclcmd: vfs_unlink_test
5423 ** This TCL command unregisters the primary VFS and then registers
5424 ** it back again. This is used to test the ability to register a
5425 ** VFS when none are previously registered, and the ability to
5426 ** unregister the only available VFS. Ticket #2738
5428 static int SQLITE_TCLAPI
vfs_unlink_test(
5429 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5430 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5431 int objc
, /* Number of arguments */
5432 Tcl_Obj
*CONST objv
[] /* Command arguments */
5436 sqlite3_vfs
*apVfs
[20];
5437 sqlite3_vfs one
, two
;
5439 sqlite3_vfs_unregister(0); /* Unregister of NULL is harmless */
5440 one
.zName
= "__one";
5441 two
.zName
= "__two";
5443 /* Calling sqlite3_vfs_register with 2nd argument of 0 does not
5444 ** change the default VFS
5446 pMain
= sqlite3_vfs_find(0);
5447 sqlite3_vfs_register(&one
, 0);
5448 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
5449 sqlite3_vfs_register(&two
, 0);
5450 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
5452 /* We can find a VFS by its name */
5453 assert( sqlite3_vfs_find("__one")==&one
);
5454 assert( sqlite3_vfs_find("__two")==&two
);
5456 /* Calling sqlite_vfs_register with non-zero second parameter changes the
5457 ** default VFS, even if the 1st parameter is an existig VFS that is
5458 ** previously registered as the non-default.
5460 sqlite3_vfs_register(&one
, 1);
5461 assert( sqlite3_vfs_find("__one")==&one
);
5462 assert( sqlite3_vfs_find("__two")==&two
);
5463 assert( sqlite3_vfs_find(0)==&one
);
5464 sqlite3_vfs_register(&two
, 1);
5465 assert( sqlite3_vfs_find("__one")==&one
);
5466 assert( sqlite3_vfs_find("__two")==&two
);
5467 assert( sqlite3_vfs_find(0)==&two
);
5469 sqlite3_vfs_register(pMain
, 1);
5470 assert( sqlite3_vfs_find("__one")==&one
);
5471 assert( sqlite3_vfs_find("__two")==&two
);
5472 assert( sqlite3_vfs_find(0)==pMain
);
5475 /* Unlink the default VFS. Repeat until there are no more VFSes
5478 for(i
=0; i
<sizeof(apVfs
)/sizeof(apVfs
[0]); i
++){
5479 apVfs
[i
] = sqlite3_vfs_find(0);
5481 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
5482 sqlite3_vfs_unregister(apVfs
[i
]);
5483 assert( 0==sqlite3_vfs_find(apVfs
[i
]->zName
) );
5486 assert( 0==sqlite3_vfs_find(0) );
5488 /* Register the main VFS as non-default (will be made default, since
5489 ** it'll be the only one in existence).
5491 sqlite3_vfs_register(pMain
, 0);
5492 assert( sqlite3_vfs_find(0)==pMain
);
5494 /* Un-register the main VFS again to restore an empty VFS list */
5495 sqlite3_vfs_unregister(pMain
);
5496 assert( 0==sqlite3_vfs_find(0) );
5498 /* Relink all VFSes in reverse order. */
5499 for(i
=sizeof(apVfs
)/sizeof(apVfs
[0])-1; i
>=0; i
--){
5501 sqlite3_vfs_register(apVfs
[i
], 1);
5502 assert( apVfs
[i
]==sqlite3_vfs_find(0) );
5503 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
5507 /* Unregister out sample VFSes. */
5508 sqlite3_vfs_unregister(&one
);
5509 sqlite3_vfs_unregister(&two
);
5511 /* Unregistering a VFS that is not currently registered is harmless */
5512 sqlite3_vfs_unregister(&one
);
5513 sqlite3_vfs_unregister(&two
);
5514 assert( sqlite3_vfs_find("__one")==0 );
5515 assert( sqlite3_vfs_find("__two")==0 );
5517 /* We should be left with the original default VFS back as the
5519 assert( sqlite3_vfs_find(0)==pMain
);
5525 ** tclcmd: vfs_initfail_test
5527 ** This TCL command attempts to vfs_find and vfs_register when the
5528 ** sqlite3_initialize() interface is failing. All calls should fail.
5530 static int SQLITE_TCLAPI
vfs_initfail_test(
5531 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5532 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5533 int objc
, /* Number of arguments */
5534 Tcl_Obj
*CONST objv
[] /* Command arguments */
5537 one
.zName
= "__one";
5539 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
5540 sqlite3_vfs_register(&one
, 0);
5541 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
5542 sqlite3_vfs_register(&one
, 1);
5543 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
5550 static sqlite3_vfs
*apVfs
[20];
5551 static int nVfs
= 0;
5554 ** tclcmd: vfs_unregister_all
5556 ** Unregister all VFSes.
5558 static int SQLITE_TCLAPI
vfs_unregister_all(
5559 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5560 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5561 int objc
, /* Number of arguments */
5562 Tcl_Obj
*CONST objv
[] /* Command arguments */
5565 for(i
=0; i
<ArraySize(apVfs
); i
++){
5566 apVfs
[i
] = sqlite3_vfs_find(0);
5567 if( apVfs
[i
]==0 ) break;
5568 sqlite3_vfs_unregister(apVfs
[i
]);
5574 ** tclcmd: vfs_reregister_all
5576 ** Restore all VFSes that were removed using vfs_unregister_all. Taking
5577 ** care to put the linked list back together in the same order as it was
5578 ** in before vfs_unregister_all was invoked.
5580 static int SQLITE_TCLAPI
vfs_reregister_all(
5581 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5582 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5583 int objc
, /* Number of arguments */
5584 Tcl_Obj
*CONST objv
[] /* Command arguments */
5587 for(i
=nVfs
-1; i
>=0; i
--){
5588 sqlite3_vfs_register(apVfs
[i
], 1);
5595 ** tclcmd: file_control_test DB
5597 ** This TCL command runs the sqlite3_file_control interface and
5598 ** verifies correct operation of the same.
5600 static int SQLITE_TCLAPI
file_control_test(
5601 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5602 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5603 int objc
, /* Number of arguments */
5604 Tcl_Obj
*CONST objv
[] /* Command arguments */
5611 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5612 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
5615 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5616 rc
= sqlite3_file_control(db
, 0, 0, &iArg
);
5617 assert( rc
==SQLITE_NOTFOUND
);
5618 rc
= sqlite3_file_control(db
, "notadatabase", SQLITE_FCNTL_LOCKSTATE
, &iArg
);
5619 assert( rc
==SQLITE_ERROR
);
5620 rc
= sqlite3_file_control(db
, "main", -1, &iArg
);
5621 assert( rc
==SQLITE_NOTFOUND
);
5622 rc
= sqlite3_file_control(db
, "temp", -1, &iArg
);
5623 assert( rc
==SQLITE_NOTFOUND
|| rc
==SQLITE_ERROR
);
5630 ** tclcmd: file_control_lasterrno_test DB
5632 ** This TCL command runs the sqlite3_file_control interface and
5633 ** verifies correct operation of the SQLITE_LAST_ERRNO verb.
5635 static int SQLITE_TCLAPI
file_control_lasterrno_test(
5636 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5637 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5638 int objc
, /* Number of arguments */
5639 Tcl_Obj
*CONST objv
[] /* Command arguments */
5646 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5647 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
5650 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5653 rc
= sqlite3_file_control(db
, NULL
, SQLITE_LAST_ERRNO
, &iArg
);
5655 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5659 Tcl_AppendResult(interp
, "Unexpected non-zero errno: ",
5660 Tcl_GetStringFromObj(Tcl_NewIntObj(iArg
), 0), " ", 0);
5667 ** tclcmd: file_control_chunksize_test DB DBNAME SIZE
5669 ** This TCL command runs the sqlite3_file_control interface and
5670 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
5671 ** SQLITE_SET_LOCKPROXYFILE verbs.
5673 static int SQLITE_TCLAPI
file_control_chunksize_test(
5674 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5675 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5676 int objc
, /* Number of arguments */
5677 Tcl_Obj
*CONST objv
[] /* Command arguments */
5679 int nSize
; /* New chunk size */
5680 char *zDb
; /* Db name ("main", "temp" etc.) */
5681 sqlite3
*db
; /* Database handle */
5682 int rc
; /* file_control() return code */
5685 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
5688 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
5689 || Tcl_GetIntFromObj(interp
, objv
[3], &nSize
)
5693 zDb
= Tcl_GetString(objv
[2]);
5694 if( zDb
[0]=='\0' ) zDb
= NULL
;
5696 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_CHUNK_SIZE
, (void *)&nSize
);
5698 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
5705 ** tclcmd: file_control_sizehint_test DB DBNAME SIZE
5707 ** This TCL command runs the sqlite3_file_control interface
5708 ** with SQLITE_FCNTL_SIZE_HINT
5710 static int SQLITE_TCLAPI
file_control_sizehint_test(
5711 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5712 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5713 int objc
, /* Number of arguments */
5714 Tcl_Obj
*CONST objv
[] /* Command arguments */
5716 Tcl_WideInt nSize
; /* Hinted size */
5717 char *zDb
; /* Db name ("main", "temp" etc.) */
5718 sqlite3
*db
; /* Database handle */
5719 int rc
; /* file_control() return code */
5722 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
5725 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
5726 || Tcl_GetWideIntFromObj(interp
, objv
[3], &nSize
)
5730 zDb
= Tcl_GetString(objv
[2]);
5731 if( zDb
[0]=='\0' ) zDb
= NULL
;
5733 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_SIZE_HINT
, (void *)&nSize
);
5735 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
5742 ** tclcmd: file_control_lockproxy_test DB PWD
5744 ** This TCL command runs the sqlite3_file_control interface and
5745 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
5746 ** SQLITE_SET_LOCKPROXYFILE verbs.
5748 static int SQLITE_TCLAPI
file_control_lockproxy_test(
5749 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5750 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5751 int objc
, /* Number of arguments */
5752 Tcl_Obj
*CONST objv
[] /* Command arguments */
5757 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5758 Tcl_GetStringFromObj(objv
[0], 0), " DB PWD", 0);
5761 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5765 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
5766 # if defined(__APPLE__)
5767 # define SQLITE_ENABLE_LOCKING_STYLE 1
5769 # define SQLITE_ENABLE_LOCKING_STYLE 0
5772 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
5778 char proxyPath
[400];
5780 zPwd
= Tcl_GetStringFromObj(objv
[2], &nPwd
);
5781 if( sizeof(proxyPath
)<nPwd
+20 ){
5782 Tcl_AppendResult(interp
, "PWD too big", (void*)0);
5785 sqlite3_snprintf(sizeof(proxyPath
), proxyPath
, "%s/test.proxy", zPwd
);
5786 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
5788 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5791 rc
= sqlite3_file_control(db
, NULL
, SQLITE_GET_LOCKPROXYFILE
, &testPath
);
5792 if( strncmp(proxyPath
,testPath
,11) ){
5793 Tcl_AppendResult(interp
, "Lock proxy file did not match the "
5794 "previously assigned value", 0);
5798 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5801 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
5803 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
5813 ** tclcmd: file_control_win32_av_retry DB NRETRY DELAY
5815 ** This TCL command runs the sqlite3_file_control interface with
5816 ** the SQLITE_FCNTL_WIN32_AV_RETRY opcode.
5818 static int SQLITE_TCLAPI
file_control_win32_av_retry(
5819 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5820 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5821 int objc
, /* Number of arguments */
5822 Tcl_Obj
*CONST objv
[] /* Command arguments */
5830 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5831 Tcl_GetStringFromObj(objv
[0], 0), " DB NRETRY DELAY", 0);
5834 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5837 if( Tcl_GetIntFromObj(interp
, objv
[2], &a
[0]) ) return TCL_ERROR
;
5838 if( Tcl_GetIntFromObj(interp
, objv
[3], &a
[1]) ) return TCL_ERROR
;
5839 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_AV_RETRY
, (void*)a
);
5840 sqlite3_snprintf(sizeof(z
), z
, "%d %d %d", rc
, a
[0], a
[1]);
5841 Tcl_AppendResult(interp
, z
, (char*)0);
5846 ** tclcmd: file_control_win32_get_handle DB
5848 ** This TCL command runs the sqlite3_file_control interface with
5849 ** the SQLITE_FCNTL_WIN32_GET_HANDLE opcode.
5851 static int file_control_win32_get_handle(
5852 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5853 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5854 int objc
, /* Number of arguments */
5855 Tcl_Obj
*CONST objv
[] /* Command arguments */
5859 HANDLE hFile
= NULL
;
5863 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5864 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
5867 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5870 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_GET_HANDLE
,
5872 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
5873 Tcl_AppendResult(interp
, z
, (char*)0);
5878 ** tclcmd: file_control_win32_set_handle DB HANDLE
5880 ** This TCL command runs the sqlite3_file_control interface with
5881 ** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode.
5883 static int SQLITE_TCLAPI
file_control_win32_set_handle(
5884 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5885 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5886 int objc
, /* Number of arguments */
5887 Tcl_Obj
*CONST objv
[] /* Command arguments */
5891 HANDLE hFile
= NULL
;
5895 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5896 Tcl_GetStringFromObj(objv
[0], 0), " DB HANDLE", 0);
5899 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5902 if( getWin32Handle(interp
, Tcl_GetString(objv
[2]), &hFile
) ){
5905 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_SET_HANDLE
,
5907 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
5908 Tcl_AppendResult(interp
, z
, (char*)0);
5914 ** tclcmd: file_control_persist_wal DB PERSIST-FLAG
5916 ** This TCL command runs the sqlite3_file_control interface with
5917 ** the SQLITE_FCNTL_PERSIST_WAL opcode.
5919 static int SQLITE_TCLAPI
file_control_persist_wal(
5920 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5921 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5922 int objc
, /* Number of arguments */
5923 Tcl_Obj
*CONST objv
[] /* Command arguments */
5931 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5932 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
5935 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5938 if( Tcl_GetIntFromObj(interp
, objv
[2], &bPersist
) ) return TCL_ERROR
;
5939 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_PERSIST_WAL
, (void*)&bPersist
);
5940 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, bPersist
);
5941 Tcl_AppendResult(interp
, z
, (char*)0);
5946 ** tclcmd: file_control_powersafe_overwrite DB PSOW-FLAG
5948 ** This TCL command runs the sqlite3_file_control interface with
5949 ** the SQLITE_FCNTL_POWERSAFE_OVERWRITE opcode.
5951 static int SQLITE_TCLAPI
file_control_powersafe_overwrite(
5952 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5953 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5954 int objc
, /* Number of arguments */
5955 Tcl_Obj
*CONST objv
[] /* Command arguments */
5963 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5964 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
5967 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
5970 if( Tcl_GetIntFromObj(interp
, objv
[2], &b
) ) return TCL_ERROR
;
5971 rc
= sqlite3_file_control(db
,NULL
,SQLITE_FCNTL_POWERSAFE_OVERWRITE
,(void*)&b
);
5972 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, b
);
5973 Tcl_AppendResult(interp
, z
, (char*)0);
5979 ** tclcmd: file_control_vfsname DB ?AUXDB?
5981 ** Return a string that describes the stack of VFSes.
5983 static int SQLITE_TCLAPI
file_control_vfsname(
5984 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
5985 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
5986 int objc
, /* Number of arguments */
5987 Tcl_Obj
*CONST objv
[] /* Command arguments */
5990 const char *zDbName
= "main";
5993 if( objc
!=2 && objc
!=3 ){
5994 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5995 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
5998 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6002 zDbName
= Tcl_GetString(objv
[2]);
6004 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_VFSNAME
,(void*)&zVfsName
);
6005 Tcl_AppendResult(interp
, zVfsName
, (char*)0);
6006 sqlite3_free(zVfsName
);
6011 ** tclcmd: file_control_tempfilename DB ?AUXDB?
6013 ** Return a string that is a temporary filename
6015 static int SQLITE_TCLAPI
file_control_tempfilename(
6016 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6017 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6018 int objc
, /* Number of arguments */
6019 Tcl_Obj
*CONST objv
[] /* Command arguments */
6022 const char *zDbName
= "main";
6025 if( objc
!=2 && objc
!=3 ){
6026 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6027 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6030 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6034 zDbName
= Tcl_GetString(objv
[2]);
6036 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_TEMPFILENAME
, (void*)&zTName
);
6037 Tcl_AppendResult(interp
, zTName
, (char*)0);
6038 sqlite3_free(zTName
);
6044 ** tclcmd: sqlite3_vfs_list
6046 ** Return a tcl list containing the names of all registered vfs's.
6048 static int SQLITE_TCLAPI
vfs_list(
6049 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6050 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6051 int objc
, /* Number of arguments */
6052 Tcl_Obj
*CONST objv
[] /* Command arguments */
6055 Tcl_Obj
*pRet
= Tcl_NewObj();
6057 Tcl_WrongNumArgs(interp
, 1, objv
, "");
6060 for(pVfs
=sqlite3_vfs_find(0); pVfs
; pVfs
=pVfs
->pNext
){
6061 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj(pVfs
->zName
, -1));
6063 Tcl_SetObjResult(interp
, pRet
);
6068 ** tclcmd: sqlite3_limit DB ID VALUE
6070 ** This TCL command runs the sqlite3_limit interface and
6071 ** verifies correct operation of the same.
6073 static int SQLITE_TCLAPI
test_limit(
6074 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6075 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6076 int objc
, /* Number of arguments */
6077 Tcl_Obj
*CONST objv
[] /* Command arguments */
6081 static const struct {
6085 { "SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH
},
6086 { "SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH
},
6087 { "SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN
},
6088 { "SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH
},
6089 { "SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT
},
6090 { "SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP
},
6091 { "SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG
},
6092 { "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED
},
6093 { "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH
},
6094 { "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER
},
6095 { "SQLITE_LIMIT_TRIGGER_DEPTH", SQLITE_LIMIT_TRIGGER_DEPTH
},
6096 { "SQLITE_LIMIT_WORKER_THREADS", SQLITE_LIMIT_WORKER_THREADS
},
6098 /* Out of range test cases */
6099 { "SQLITE_LIMIT_TOOSMALL", -1, },
6100 { "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_WORKER_THREADS
+1 },
6107 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6108 Tcl_GetStringFromObj(objv
[0], 0), " DB ID VALUE", 0);
6111 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6112 zId
= Tcl_GetString(objv
[2]);
6113 for(i
=0; i
<sizeof(aId
)/sizeof(aId
[0]); i
++){
6114 if( strcmp(zId
, aId
[i
].zName
)==0 ){
6119 if( i
>=sizeof(aId
)/sizeof(aId
[0]) ){
6120 Tcl_AppendResult(interp
, "unknown limit type: ", zId
, (char*)0);
6123 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
6124 rc
= sqlite3_limit(db
, id
, val
);
6125 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6130 ** tclcmd: save_prng_state
6132 ** Save the state of the pseudo-random number generator.
6133 ** At the same time, verify that sqlite3_test_control works even when
6134 ** called with an out-of-range opcode.
6136 static int SQLITE_TCLAPI
save_prng_state(
6137 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6138 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6139 int objc
, /* Number of arguments */
6140 Tcl_Obj
*CONST objv
[] /* Command arguments */
6142 int rc
= sqlite3_test_control(9999);
6144 rc
= sqlite3_test_control(-1);
6146 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SAVE
);
6150 ** tclcmd: restore_prng_state
6152 static int SQLITE_TCLAPI
restore_prng_state(
6153 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6154 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6155 int objc
, /* Number of arguments */
6156 Tcl_Obj
*CONST objv
[] /* Command arguments */
6158 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESTORE
);
6162 ** tclcmd: reset_prng_state
6164 static int SQLITE_TCLAPI
reset_prng_state(
6165 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6166 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6167 int objc
, /* Number of arguments */
6168 Tcl_Obj
*CONST objv
[] /* Command arguments */
6170 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESET
);
6175 ** tclcmd: database_may_be_corrupt
6177 ** Indicate that database files might be corrupt. In other words, set the normal
6178 ** state of operation.
6180 static int SQLITE_TCLAPI
database_may_be_corrupt(
6181 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6182 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6183 int objc
, /* Number of arguments */
6184 Tcl_Obj
*CONST objv
[] /* Command arguments */
6186 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 0);
6190 ** tclcmd: database_never_corrupt
6192 ** Indicate that database files are always well-formed. This enables extra assert()
6193 ** statements that test conditions that are always true for well-formed databases.
6195 static int SQLITE_TCLAPI
database_never_corrupt(
6196 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6197 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6198 int objc
, /* Number of arguments */
6199 Tcl_Obj
*CONST objv
[] /* Command arguments */
6201 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 1);
6206 ** tclcmd: pcache_stats
6208 static int SQLITE_TCLAPI
test_pcache_stats(
6209 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6210 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6211 int objc
, /* Number of arguments */
6212 Tcl_Obj
*CONST objv
[] /* Command arguments */
6220 sqlite3PcacheStats(&nCurrent
, &nMax
, &nMin
, &nRecyclable
);
6222 pRet
= Tcl_NewObj();
6223 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("current", -1));
6224 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCurrent
));
6225 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("max", -1));
6226 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMax
));
6227 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("min", -1));
6228 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMin
));
6229 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("recyclable", -1));
6230 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nRecyclable
));
6232 Tcl_SetObjResult(interp
, pRet
);
6237 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
6238 static void test_unlock_notify_cb(void **aArg
, int nArg
){
6240 for(ii
=0; ii
<nArg
; ii
++){
6241 Tcl_EvalEx((Tcl_Interp
*)aArg
[ii
], "unlock_notify", -1, TCL_EVAL_GLOBAL
);
6244 #endif /* SQLITE_ENABLE_UNLOCK_NOTIFY */
6247 ** tclcmd: sqlite3_unlock_notify db
6249 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
6250 static int SQLITE_TCLAPI
test_unlock_notify(
6251 ClientData clientData
, /* Unused */
6252 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6253 int objc
, /* Number of arguments */
6254 Tcl_Obj
*CONST objv
[] /* Command arguments */
6260 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
6264 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6267 rc
= sqlite3_unlock_notify(db
, test_unlock_notify_cb
, (void *)interp
);
6268 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
6274 ** tclcmd: sqlite3_wal_checkpoint db ?NAME?
6276 static int SQLITE_TCLAPI
test_wal_checkpoint(
6277 ClientData clientData
, /* Unused */
6278 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6279 int objc
, /* Number of arguments */
6280 Tcl_Obj
*CONST objv
[] /* Command arguments */
6286 if( objc
!=3 && objc
!=2 ){
6287 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?NAME?");
6291 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6295 zDb
= Tcl_GetString(objv
[2]);
6297 rc
= sqlite3_wal_checkpoint(db
, zDb
);
6298 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
6303 ** tclcmd: sqlite3_wal_checkpoint_v2 db MODE ?NAME?
6305 ** This command calls the wal_checkpoint_v2() function with the specified
6306 ** mode argument (passive, full or restart). If present, the database name
6307 ** NAME is passed as the second argument to wal_checkpoint_v2(). If it the
6308 ** NAME argument is not present, a NULL pointer is passed instead.
6310 ** If wal_checkpoint_v2() returns any value other than SQLITE_BUSY or
6311 ** SQLITE_OK, then this command returns TCL_ERROR. The Tcl result is set
6312 ** to the error message obtained from sqlite3_errmsg().
6314 ** Otherwise, this command returns a list of three integers. The first integer
6315 ** is 1 if SQLITE_BUSY was returned, or 0 otherwise. The following two integers
6316 ** are the values returned via the output parameters by wal_checkpoint_v2() -
6317 ** the number of frames in the log and the number of frames in the log
6318 ** that have been checkpointed.
6320 static int SQLITE_TCLAPI
test_wal_checkpoint_v2(
6321 ClientData clientData
, /* Unused */
6322 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6323 int objc
, /* Number of arguments */
6324 Tcl_Obj
*CONST objv
[] /* Command arguments */
6335 const char * aMode
[] = { "passive", "full", "restart", "truncate", 0 };
6336 assert( SQLITE_CHECKPOINT_PASSIVE
==0 );
6337 assert( SQLITE_CHECKPOINT_FULL
==1 );
6338 assert( SQLITE_CHECKPOINT_RESTART
==2 );
6339 assert( SQLITE_CHECKPOINT_TRUNCATE
==3 );
6341 if( objc
!=3 && objc
!=4 ){
6342 Tcl_WrongNumArgs(interp
, 1, objv
, "DB MODE ?NAME?");
6347 zDb
= Tcl_GetString(objv
[3]);
6349 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) || (
6350 TCL_OK
!=Tcl_GetIntFromObj(0, objv
[2], &eMode
)
6351 && TCL_OK
!=Tcl_GetIndexFromObj(interp
, objv
[2], aMode
, "mode", 0, &eMode
)
6356 rc
= sqlite3_wal_checkpoint_v2(db
, zDb
, eMode
, &nLog
, &nCkpt
);
6357 if( rc
!=SQLITE_OK
&& rc
!=SQLITE_BUSY
){
6358 const char *zErrCode
= sqlite3ErrName(rc
);
6359 Tcl_ResetResult(interp
);
6360 Tcl_AppendResult(interp
, zErrCode
, " - ", (char *)sqlite3_errmsg(db
), 0);
6364 pRet
= Tcl_NewObj();
6365 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(rc
==SQLITE_BUSY
?1:0));
6366 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nLog
));
6367 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCkpt
));
6368 Tcl_SetObjResult(interp
, pRet
);
6374 ** tclcmd: sqlite3_wal_autocheckpoint db VALUE
6376 static int SQLITE_TCLAPI
test_wal_autocheckpoint(
6377 ClientData clientData
, /* Unused */
6378 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6379 int objc
, /* Number of arguments */
6380 Tcl_Obj
*CONST objv
[] /* Command arguments */
6388 Tcl_WrongNumArgs(interp
, 1, objv
, "DB VALUE");
6392 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6393 || Tcl_GetIntFromObj(0, objv
[2], &iVal
)
6398 rc
= sqlite3_wal_autocheckpoint(db
, iVal
);
6399 Tcl_ResetResult(interp
);
6400 if( rc
!=SQLITE_OK
){
6401 const char *zErrCode
= sqlite3ErrName(rc
);
6402 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zErrCode
, -1));
6411 ** tclcmd: test_sqlite3_log ?SCRIPT?
6413 static struct LogCallback
{
6414 Tcl_Interp
*pInterp
;
6416 } logcallback
= {0, 0};
6417 static void xLogcallback(void *unused
, int err
, char *zMsg
){
6418 Tcl_Obj
*pNew
= Tcl_DuplicateObj(logcallback
.pObj
);
6419 Tcl_IncrRefCount(pNew
);
6420 Tcl_ListObjAppendElement(
6421 0, pNew
, Tcl_NewStringObj(sqlite3ErrName(err
), -1)
6423 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewStringObj(zMsg
, -1));
6424 Tcl_EvalObjEx(logcallback
.pInterp
, pNew
, TCL_EVAL_GLOBAL
|TCL_EVAL_DIRECT
);
6425 Tcl_DecrRefCount(pNew
);
6427 static int SQLITE_TCLAPI
test_sqlite3_log(
6428 ClientData clientData
,
6429 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6430 int objc
, /* Number of arguments */
6431 Tcl_Obj
*CONST objv
[] /* Command arguments */
6434 Tcl_WrongNumArgs(interp
, 1, objv
, "SCRIPT");
6437 if( logcallback
.pObj
){
6438 Tcl_DecrRefCount(logcallback
.pObj
);
6439 logcallback
.pObj
= 0;
6440 logcallback
.pInterp
= 0;
6441 sqlite3_config(SQLITE_CONFIG_LOG
, (void*)0, (void*)0);
6444 logcallback
.pObj
= objv
[1];
6445 Tcl_IncrRefCount(logcallback
.pObj
);
6446 logcallback
.pInterp
= interp
;
6447 sqlite3_config(SQLITE_CONFIG_LOG
, xLogcallback
, (void*)0);
6453 ** tcl_objproc COMMANDNAME ARGS...
6455 ** Run a TCL command using its objProc interface. Throw an error if
6456 ** the command has no objProc interface.
6458 static int SQLITE_TCLAPI
runAsObjProc(
6462 Tcl_Obj
*CONST objv
[]
6464 Tcl_CmdInfo cmdInfo
;
6466 Tcl_WrongNumArgs(interp
, 1, objv
, "COMMAND ...");
6469 if( !Tcl_GetCommandInfo(interp
, Tcl_GetString(objv
[1]), &cmdInfo
) ){
6470 Tcl_AppendResult(interp
, "command not found: ",
6471 Tcl_GetString(objv
[1]), (char*)0);
6474 if( cmdInfo
.objProc
==0 ){
6475 Tcl_AppendResult(interp
, "command has no objProc: ",
6476 Tcl_GetString(objv
[1]), (char*)0);
6479 return cmdInfo
.objProc(cmdInfo
.objClientData
, interp
, objc
-1, objv
+1);
6482 #ifndef SQLITE_OMIT_EXPLAIN
6484 ** WARNING: The following function, printExplainQueryPlan() is an exact
6485 ** copy of example code from eqp.in (eqp.html). If this code is modified,
6486 ** then the documentation copy needs to be modified as well.
6489 ** Argument pStmt is a prepared SQL statement. This function compiles
6490 ** an EXPLAIN QUERY PLAN command to report on the prepared statement,
6491 ** and prints the report to stdout using printf().
6493 int printExplainQueryPlan(sqlite3_stmt
*pStmt
){
6494 const char *zSql
; /* Input SQL */
6495 char *zExplain
; /* SQL with EXPLAIN QUERY PLAN prepended */
6496 sqlite3_stmt
*pExplain
; /* Compiled EXPLAIN QUERY PLAN command */
6497 int rc
; /* Return code from sqlite3_prepare_v2() */
6499 zSql
= sqlite3_sql(pStmt
);
6500 if( zSql
==0 ) return SQLITE_ERROR
;
6502 zExplain
= sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql
);
6503 if( zExplain
==0 ) return SQLITE_NOMEM
;
6505 rc
= sqlite3_prepare_v2(sqlite3_db_handle(pStmt
), zExplain
, -1, &pExplain
, 0);
6506 sqlite3_free(zExplain
);
6507 if( rc
!=SQLITE_OK
) return rc
;
6509 while( SQLITE_ROW
==sqlite3_step(pExplain
) ){
6510 int iSelectid
= sqlite3_column_int(pExplain
, 0);
6511 int iOrder
= sqlite3_column_int(pExplain
, 1);
6512 int iFrom
= sqlite3_column_int(pExplain
, 2);
6513 const char *zDetail
= (const char *)sqlite3_column_text(pExplain
, 3);
6515 printf("%d %d %d %s\n", iSelectid
, iOrder
, iFrom
, zDetail
);
6518 return sqlite3_finalize(pExplain
);
6521 static int SQLITE_TCLAPI
test_print_eqp(
6525 Tcl_Obj
*CONST objv
[]
6528 sqlite3_stmt
*pStmt
;
6531 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
6534 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
6535 rc
= printExplainQueryPlan(pStmt
);
6536 /* This is needed on Windows so that a test case using this
6537 ** function can open a read pipe and get the output of
6538 ** printExplainQueryPlan() immediately.
6541 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
6544 #endif /* SQLITE_OMIT_EXPLAIN */
6547 ** sqlite3_test_control VERB ARGS...
6549 static int SQLITE_TCLAPI
test_test_control(
6553 Tcl_Obj
*CONST objv
[]
6559 { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT
},
6560 { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP
},
6561 { "SQLITE_TESTCTRL_IMPOSTER", SQLITE_TESTCTRL_IMPOSTER
},
6568 Tcl_WrongNumArgs(interp
, 1, objv
, "VERB ARGS...");
6572 rc
= Tcl_GetIndexFromObjStruct(
6573 interp
, objv
[1], aVerb
, sizeof(aVerb
[0]), "VERB", 0, &iVerb
6575 if( rc
!=TCL_OK
) return rc
;
6577 iFlag
= aVerb
[iVerb
].i
;
6579 case SQLITE_TESTCTRL_LOCALTIME_FAULT
: {
6582 Tcl_WrongNumArgs(interp
, 2, objv
, "ONOFF");
6585 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
6586 sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT
, val
);
6590 case SQLITE_TESTCTRL_SORTER_MMAP
: {
6594 Tcl_WrongNumArgs(interp
, 2, objv
, "DB LIMIT");
6597 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
6598 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
6599 sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP
, db
, val
);
6603 case SQLITE_TESTCTRL_IMPOSTER
: {
6605 const char *zDbName
;
6608 Tcl_WrongNumArgs(interp
, 2, objv
, "DB dbName onOff tnum");
6611 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
6612 zDbName
= Tcl_GetString(objv
[3]);
6613 if( Tcl_GetIntFromObj(interp
, objv
[4], &onOff
) ) return TCL_ERROR
;
6614 if( Tcl_GetIntFromObj(interp
, objv
[5], &tnum
) ) return TCL_ERROR
;
6615 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER
, db
, zDbName
, onOff
, tnum
);
6620 Tcl_ResetResult(interp
);
6625 #include <sys/time.h>
6626 #include <sys/resource.h>
6628 static int SQLITE_TCLAPI
test_getrusage(
6632 Tcl_Obj
*CONST objv
[]
6636 memset(&r
, 0, sizeof(r
));
6637 getrusage(RUSAGE_SELF
, &r
);
6639 sqlite3_snprintf(sizeof(buf
), buf
,
6640 "ru_utime=%d.%06d ru_stime=%d.%06d ru_minflt=%d ru_majflt=%d",
6641 (int)r
.ru_utime
.tv_sec
, (int)r
.ru_utime
.tv_usec
,
6642 (int)r
.ru_stime
.tv_sec
, (int)r
.ru_stime
.tv_usec
,
6643 (int)r
.ru_minflt
, (int)r
.ru_majflt
6645 Tcl_SetObjResult(interp
, Tcl_NewStringObj(buf
, -1));
6652 ** Information passed from the main thread into the windows file locker
6653 ** background thread.
6655 struct win32FileLocker
{
6656 char *evName
; /* Name of event to signal thread startup */
6657 HANDLE h
; /* Handle of the file to be locked */
6658 int delay1
; /* Delay before locking */
6659 int delay2
; /* Delay before unlocking */
6660 int ok
; /* Finished ok */
6661 int err
; /* True if an error occurs */
6667 #include <process.h>
6669 ** The background thread that does file locking.
6671 static void SQLITE_CDECL
win32_file_locker(void *pAppData
){
6672 struct win32FileLocker
*p
= (struct win32FileLocker
*)pAppData
;
6674 HANDLE ev
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, p
->evName
);
6680 if( p
->delay1
) Sleep(p
->delay1
);
6681 if( LockFile(p
->h
, 0, 0, 100000000, 0) ){
6683 UnlockFile(p
->h
, 0, 0, 100000000, 0);
6697 ** lock_win32_file FILENAME DELAY1 DELAY2
6699 ** Get an exclusive manditory lock on file for DELAY2 milliseconds.
6700 ** Wait DELAY1 milliseconds before acquiring the lock.
6702 static int SQLITE_TCLAPI
win32_file_lock(
6706 Tcl_Obj
*CONST objv
[]
6708 static struct win32FileLocker x
= { "win32_file_lock", 0, 0, 0, 0, 0 };
6709 const char *zFilename
;
6715 if( objc
!=4 && objc
!=1 ){
6716 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME DELAY1 DELAY2");
6720 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d %d %d %d %d",
6721 x
.ok
, x
.err
, x
.delay1
, x
.delay2
, x
.h
);
6722 Tcl_AppendResult(interp
, zBuf
, (char*)0);
6725 while( x
.h
&& retry
<30 ){
6730 Tcl_AppendResult(interp
, "busy", (char*)0);
6733 if( Tcl_GetIntFromObj(interp
, objv
[2], &x
.delay1
) ) return TCL_ERROR
;
6734 if( Tcl_GetIntFromObj(interp
, objv
[3], &x
.delay2
) ) return TCL_ERROR
;
6735 zFilename
= Tcl_GetString(objv
[1]);
6736 x
.h
= CreateFile(zFilename
, GENERIC_READ
|GENERIC_WRITE
,
6737 FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, OPEN_ALWAYS
,
6738 FILE_ATTRIBUTE_NORMAL
, 0);
6740 Tcl_AppendResult(interp
, "cannot open file: ", zFilename
, (char*)0);
6743 ev
= CreateEvent(NULL
, TRUE
, FALSE
, x
.evName
);
6745 Tcl_AppendResult(interp
, "cannot create event: ", x
.evName
, (char*)0);
6748 _beginthread(win32_file_locker
, 0, (void*)&x
);
6750 if ( (wResult
= WaitForSingleObject(ev
, 10000))!=WAIT_OBJECT_0
){
6751 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "0x%x", wResult
);
6752 Tcl_AppendResult(interp
, "wait failed: ", zBuf
, (char*)0);
6761 ** exists_win32_path PATH
6763 ** Returns non-zero if the specified path exists, whose fully qualified name
6764 ** may exceed 260 characters if it is prefixed with "\\?\".
6766 static int SQLITE_TCLAPI
win32_exists_path(
6770 Tcl_Obj
*CONST objv
[]
6773 Tcl_WrongNumArgs(interp
, 1, objv
, "PATH");
6776 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(
6777 GetFileAttributesW( Tcl_GetUnicode(objv
[1]))!=INVALID_FILE_ATTRIBUTES
));
6782 ** find_win32_file PATTERN
6784 ** Returns a list of entries in a directory that match the specified pattern,
6785 ** whose fully qualified name may exceed 248 characters if it is prefixed with
6788 static int SQLITE_TCLAPI
win32_find_file(
6792 Tcl_Obj
*CONST objv
[]
6794 HANDLE hFindFile
= INVALID_HANDLE_VALUE
;
6795 WIN32_FIND_DATAW findData
;
6799 Tcl_WrongNumArgs(interp
, 1, objv
, "PATTERN");
6802 hFindFile
= FindFirstFileW(Tcl_GetUnicode(objv
[1]), &findData
);
6803 if( hFindFile
==INVALID_HANDLE_VALUE
){
6804 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6807 listObj
= Tcl_NewObj();
6808 Tcl_IncrRefCount(listObj
);
6810 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewUnicodeObj(
6811 findData
.cFileName
, -1));
6812 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewWideIntObj(
6813 findData
.dwFileAttributes
));
6814 } while( FindNextFileW(hFindFile
, &findData
) );
6815 lastErrno
= GetLastError();
6816 if( lastErrno
!=NO_ERROR
&& lastErrno
!=ERROR_NO_MORE_FILES
){
6817 FindClose(hFindFile
);
6818 Tcl_DecrRefCount(listObj
);
6819 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6822 FindClose(hFindFile
);
6823 Tcl_SetObjResult(interp
, listObj
);
6828 ** delete_win32_file FILENAME
6830 ** Deletes the specified file, whose fully qualified name may exceed 260
6831 ** characters if it is prefixed with "\\?\".
6833 static int SQLITE_TCLAPI
win32_delete_file(
6837 Tcl_Obj
*CONST objv
[]
6840 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME");
6843 if( !DeleteFileW(Tcl_GetUnicode(objv
[1])) ){
6844 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6847 Tcl_ResetResult(interp
);
6852 ** make_win32_dir DIRECTORY
6854 ** Creates the specified directory, whose fully qualified name may exceed 248
6855 ** characters if it is prefixed with "\\?\".
6857 static int SQLITE_TCLAPI
win32_mkdir(
6861 Tcl_Obj
*CONST objv
[]
6864 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
6867 if( !CreateDirectoryW(Tcl_GetUnicode(objv
[1]), NULL
) ){
6868 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6871 Tcl_ResetResult(interp
);
6876 ** remove_win32_dir DIRECTORY
6878 ** Removes the specified directory, whose fully qualified name may exceed 248
6879 ** characters if it is prefixed with "\\?\".
6881 static int SQLITE_TCLAPI
win32_rmdir(
6885 Tcl_Obj
*CONST objv
[]
6888 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
6891 if( !RemoveDirectoryW(Tcl_GetUnicode(objv
[1])) ){
6892 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
6895 Tcl_ResetResult(interp
);
6902 ** optimization_control DB OPT BOOLEAN
6904 ** Enable or disable query optimizations using the sqlite3_test_control()
6905 ** interface. Disable if BOOLEAN is false and enable if BOOLEAN is true.
6906 ** OPT is the name of the optimization to be disabled.
6908 static int SQLITE_TCLAPI
optimization_control(
6912 Tcl_Obj
*CONST objv
[]
6919 static const struct {
6920 const char *zOptName
;
6923 { "all", SQLITE_AllOpts
},
6925 { "query-flattener", SQLITE_QueryFlattener
},
6926 { "column-cache", SQLITE_ColumnCache
},
6927 { "groupby-order", SQLITE_GroupByOrder
},
6928 { "factor-constants", SQLITE_FactorOutConst
},
6929 { "distinct-opt", SQLITE_DistinctOpt
},
6930 { "cover-idx-scan", SQLITE_CoverIdxScan
},
6931 { "order-by-idx-join", SQLITE_OrderByIdxJoin
},
6932 { "transitive", SQLITE_Transitive
},
6933 { "omit-noop-join", SQLITE_OmitNoopJoin
},
6934 { "stat3", SQLITE_Stat34
},
6935 { "stat4", SQLITE_Stat34
},
6939 Tcl_WrongNumArgs(interp
, 1, objv
, "DB OPT BOOLEAN");
6942 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6943 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &onoff
) ) return TCL_ERROR
;
6944 zOpt
= Tcl_GetString(objv
[2]);
6945 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
6946 if( strcmp(zOpt
, aOpt
[i
].zOptName
)==0 ){
6947 mask
= aOpt
[i
].mask
;
6951 if( onoff
) mask
= ~mask
;
6952 if( i
>=sizeof(aOpt
)/sizeof(aOpt
[0]) ){
6953 Tcl_AppendResult(interp
, "unknown optimization - should be one of:",
6955 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
6956 Tcl_AppendResult(interp
, " ", aOpt
[i
].zOptName
, (char*)0);
6960 sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS
, db
, mask
);
6965 ** load_static_extension DB NAME ...
6967 ** Load one or more statically linked extensions.
6969 static int SQLITE_TCLAPI
tclLoadStaticExtensionCmd(
6973 Tcl_Obj
*CONST objv
[]
6975 extern int sqlite3_amatch_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6976 extern int sqlite3_carray_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6977 extern int sqlite3_closure_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6978 extern int sqlite3_csv_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6979 extern int sqlite3_eval_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6980 extern int sqlite3_fileio_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6981 extern int sqlite3_fuzzer_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6982 extern int sqlite3_ieee_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6983 extern int sqlite3_nextchar_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6984 extern int sqlite3_percentile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6985 extern int sqlite3_regexp_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6986 extern int sqlite3_remember_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6987 extern int sqlite3_series_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6988 extern int sqlite3_spellfix_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6989 extern int sqlite3_totype_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6990 extern int sqlite3_wholenumber_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6991 extern int sqlite3_unionvtab_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6992 #ifdef SQLITE_HAVE_ZLIB
6993 extern int sqlite3_zipfile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
6995 static const struct {
6996 const char *zExtName
;
6997 int (*pInit
)(sqlite3
*,char**,const sqlite3_api_routines
*);
6999 { "amatch", sqlite3_amatch_init
},
7000 { "carray", sqlite3_carray_init
},
7001 { "closure", sqlite3_closure_init
},
7002 { "csv", sqlite3_csv_init
},
7003 { "eval", sqlite3_eval_init
},
7004 { "fileio", sqlite3_fileio_init
},
7005 { "fuzzer", sqlite3_fuzzer_init
},
7006 { "ieee754", sqlite3_ieee_init
},
7007 { "nextchar", sqlite3_nextchar_init
},
7008 { "percentile", sqlite3_percentile_init
},
7009 { "regexp", sqlite3_regexp_init
},
7010 { "remember", sqlite3_remember_init
},
7011 { "series", sqlite3_series_init
},
7012 { "spellfix", sqlite3_spellfix_init
},
7013 { "totype", sqlite3_totype_init
},
7014 { "unionvtab", sqlite3_unionvtab_init
},
7015 { "wholenumber", sqlite3_wholenumber_init
},
7016 #ifdef SQLITE_HAVE_ZLIB
7017 { "zipfile", sqlite3_zipfile_init
},
7025 Tcl_WrongNumArgs(interp
, 1, objv
, "DB NAME ...");
7028 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7029 for(j
=2; j
<objc
; j
++){
7030 zName
= Tcl_GetString(objv
[j
]);
7031 for(i
=0; i
<ArraySize(aExtension
); i
++){
7032 if( strcmp(zName
, aExtension
[i
].zExtName
)==0 ) break;
7034 if( i
>=ArraySize(aExtension
) ){
7035 Tcl_AppendResult(interp
, "no such extension: ", zName
, (char*)0);
7038 if( aExtension
[i
].pInit
){
7039 rc
= aExtension
[i
].pInit(db
, &zErrMsg
, 0);
7043 if( rc
!=SQLITE_OK
|| zErrMsg
){
7044 Tcl_AppendResult(interp
, "initialization of ", zName
, " failed: ", zErrMsg
,
7046 sqlite3_free(zErrMsg
);
7054 ** sorter_test_fakeheap BOOL
7057 static int SQLITE_TCLAPI
sorter_test_fakeheap(
7061 Tcl_Obj
*CONST objv
[]
7065 Tcl_WrongNumArgs(interp
, 1, objv
, "BOOL");
7069 if( Tcl_GetBooleanFromObj(interp
, objv
[1], &bArg
) ){
7074 if( sqlite3GlobalConfig
.pHeap
==0 ){
7075 sqlite3GlobalConfig
.pHeap
= SQLITE_INT_TO_PTR(-1);
7078 if( sqlite3GlobalConfig
.pHeap
==SQLITE_INT_TO_PTR(-1) ){
7079 sqlite3GlobalConfig
.pHeap
= 0;
7083 Tcl_ResetResult(interp
);
7088 ** sorter_test_sort4_helper DB SQL1 NSTEP SQL2
7090 ** Compile SQL statement $SQL1 and step it $NSTEP times. For each row,
7091 ** check that the leftmost and rightmost columns returned are both integers,
7092 ** and that both contain the same value.
7094 ** Then execute statement $SQL2. Check that the statement returns the same
7095 ** set of integers in the same order as in the previous step (using $SQL1).
7097 static int SQLITE_TCLAPI
sorter_test_sort4_helper(
7101 Tcl_Obj
*CONST objv
[]
7107 unsigned int iCksum1
= 0;
7108 unsigned int iCksum2
= 0;
7112 sqlite3_stmt
*pStmt
;
7115 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SQL1 NSTEP SQL2");
7119 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7120 zSql1
= Tcl_GetString(objv
[2]);
7121 if( Tcl_GetIntFromObj(interp
, objv
[3], &nStep
) ) return TCL_ERROR
;
7122 zSql2
= Tcl_GetString(objv
[4]);
7124 rc
= sqlite3_prepare_v2(db
, zSql1
, -1, &pStmt
, 0);
7125 if( rc
!=SQLITE_OK
) goto sql_error
;
7127 iB
= sqlite3_column_count(pStmt
)-1;
7128 for(iStep
=0; iStep
<nStep
&& SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
7129 int a
= sqlite3_column_int(pStmt
, 0);
7130 if( a
!=sqlite3_column_int(pStmt
, iB
) ){
7131 Tcl_AppendResult(interp
, "data error: (a!=b)", 0);
7135 iCksum1
+= (iCksum1
<< 3) + (unsigned int)a
;
7137 rc
= sqlite3_finalize(pStmt
);
7138 if( rc
!=SQLITE_OK
) goto sql_error
;
7140 rc
= sqlite3_prepare_v2(db
, zSql2
, -1, &pStmt
, 0);
7141 if( rc
!=SQLITE_OK
) goto sql_error
;
7142 for(iStep
=0; SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
7143 int a
= sqlite3_column_int(pStmt
, 0);
7144 iCksum2
+= (iCksum2
<< 3) + (unsigned int)a
;
7146 rc
= sqlite3_finalize(pStmt
);
7147 if( rc
!=SQLITE_OK
) goto sql_error
;
7149 if( iCksum1
!=iCksum2
){
7150 Tcl_AppendResult(interp
, "checksum mismatch", 0);
7156 Tcl_AppendResult(interp
, "sql error: ", sqlite3_errmsg(db
), 0);
7161 #ifdef SQLITE_USER_AUTHENTICATION
7162 #include "sqlite3userauth.h"
7164 ** tclcmd: sqlite3_user_authenticate DB USERNAME PASSWORD
7166 static int SQLITE_TCLAPI
test_user_authenticate(
7167 ClientData clientData
, /* Unused */
7168 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7169 int objc
, /* Number of arguments */
7170 Tcl_Obj
*CONST objv
[] /* Command arguments */
7179 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD");
7182 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7185 zUser
= Tcl_GetString(objv
[2]);
7186 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
7187 rc
= sqlite3_user_authenticate(db
, zUser
, zPasswd
, nPasswd
);
7188 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7191 #endif /* SQLITE_USER_AUTHENTICATION */
7193 #ifdef SQLITE_USER_AUTHENTICATION
7195 ** tclcmd: sqlite3_user_add DB USERNAME PASSWORD ISADMIN
7197 static int SQLITE_TCLAPI
test_user_add(
7198 ClientData clientData
, /* Unused */
7199 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7200 int objc
, /* Number of arguments */
7201 Tcl_Obj
*CONST objv
[] /* Command arguments */
7211 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
7214 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7217 zUser
= Tcl_GetString(objv
[2]);
7218 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
7219 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
7220 rc
= sqlite3_user_add(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
7221 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7224 #endif /* SQLITE_USER_AUTHENTICATION */
7226 #ifdef SQLITE_USER_AUTHENTICATION
7228 ** tclcmd: sqlite3_user_change DB USERNAME PASSWORD ISADMIN
7230 static int SQLITE_TCLAPI
test_user_change(
7231 ClientData clientData
, /* Unused */
7232 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7233 int objc
, /* Number of arguments */
7234 Tcl_Obj
*CONST objv
[] /* Command arguments */
7244 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
7247 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7250 zUser
= Tcl_GetString(objv
[2]);
7251 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
7252 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
7253 rc
= sqlite3_user_change(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
7254 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7257 #endif /* SQLITE_USER_AUTHENTICATION */
7259 #ifdef SQLITE_USER_AUTHENTICATION
7261 ** tclcmd: sqlite3_user_delete DB USERNAME
7263 static int SQLITE_TCLAPI
test_user_delete(
7264 ClientData clientData
, /* Unused */
7265 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7266 int objc
, /* Number of arguments */
7267 Tcl_Obj
*CONST objv
[] /* Command arguments */
7274 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME");
7277 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7280 zUser
= Tcl_GetString(objv
[2]);
7281 rc
= sqlite3_user_delete(db
, zUser
);
7282 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7285 #endif /* SQLITE_USER_AUTHENTICATION */
7288 ** tclcmd: bad_behavior TYPE
7290 ** Do some things that should trigger a valgrind or -fsanitize=undefined
7291 ** warning. This is used to verify that errors and warnings output by those
7292 ** tools are detected by the test scripts.
7295 ** 1 Overflow a signed integer
7296 ** 2 Jump based on an uninitialized variable
7297 ** 3 Read after free
7300 static int SQLITE_TCLAPI
test_bad_behavior(
7301 ClientData clientData
, /* Pointer to an integer containing zero */
7302 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7303 int objc
, /* Number of arguments */
7304 Tcl_Obj
*CONST objv
[] /* Command arguments */
7308 int i
= *(int*)clientData
;
7313 Tcl_WrongNumArgs(interp
, 1, objv
, "TYPE");
7316 if( Tcl_GetIntFromObj(interp
, objv
[1], &iType
) ) return TCL_ERROR
;
7319 xyz
= 0x7fffff00 - i
;
7321 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xyz
));
7326 if( w
[i
]>0 ) w
[1]++;
7327 Tcl_SetObjResult(interp
, Tcl_NewIntObj(w
[1]));
7331 a
= malloc( sizeof(int)*10 );
7332 for(j
=0; j
<10; j
++) a
[j
] = j
;
7334 Tcl_SetObjResult(interp
, Tcl_NewIntObj(a
[i
]));
7338 Tcl_Panic("Deliberate panic");
7346 ** tclcmd: register_dbstat_vtab DB
7348 ** Cause the dbstat virtual table to be available on the connection DB
7350 static int SQLITE_TCLAPI
test_register_dbstat_vtab(
7354 Tcl_Obj
*CONST objv
[]
7356 #ifdef SQLITE_OMIT_VIRTUALTABLE
7357 Tcl_AppendResult(interp
, "dbstat not available because of "
7358 "SQLITE_OMIT_VIRTUALTABLE", (void*)0);
7361 struct SqliteDb
{ sqlite3
*db
; };
7363 Tcl_CmdInfo cmdInfo
;
7366 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
7370 zDb
= Tcl_GetString(objv
[1]);
7371 if( Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
7372 sqlite3
* db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
7373 sqlite3DbstatRegister(db
);
7376 #endif /* SQLITE_OMIT_VIRTUALTABLE */
7380 ** tclcmd: sqlite3_db_config DB SETTING VALUE
7382 ** Invoke sqlite3_db_config() for one of the setting values.
7384 static int SQLITE_TCLAPI
test_sqlite3_db_config(
7388 Tcl_Obj
*CONST objv
[]
7390 static const struct {
7394 { "FKEY", SQLITE_DBCONFIG_ENABLE_FKEY
},
7395 { "TRIGGER", SQLITE_DBCONFIG_ENABLE_TRIGGER
},
7396 { "FTS3_TOKENIZER", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
},
7397 { "LOAD_EXTENSION", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
},
7398 { "NO_CKPT_ON_CLOSE",SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
},
7399 { "QPSG", SQLITE_DBCONFIG_ENABLE_QPSG
},
7403 const char *zSetting
;
7407 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SETTING VALUE");
7410 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7411 zSetting
= Tcl_GetString(objv
[2]);
7412 if( sqlite3_strglob("SQLITE_*", zSetting
)==0 ) zSetting
+= 7;
7413 if( sqlite3_strglob("DBCONFIG_*", zSetting
)==0 ) zSetting
+= 9;
7414 if( sqlite3_strglob("ENABLE_*", zSetting
)==0 ) zSetting
+= 7;
7415 for(i
=0; i
<ArraySize(aSetting
); i
++){
7416 if( strcmp(zSetting
, aSetting
[i
].zName
)==0 ) break;
7418 if( i
>=ArraySize(aSetting
) ){
7419 Tcl_SetObjResult(interp
,
7420 Tcl_NewStringObj("unknown sqlite3_db_config setting", -1));
7423 if( Tcl_GetIntFromObj(interp
, objv
[3], &v
) ) return TCL_ERROR
;
7424 sqlite3_db_config(db
, aSetting
[i
].eVal
, v
, &v
);
7425 Tcl_SetObjResult(interp
, Tcl_NewIntObj(v
));
7430 ** Change the name of the main database schema from "main" to "icecube".
7432 static int SQLITE_TCLAPI
test_dbconfig_maindbname_icecube(
7436 Tcl_Obj
*CONST objv
[]
7440 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
7442 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
7445 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7446 rc
= sqlite3_db_config(db
, SQLITE_DBCONFIG_MAINDBNAME
, "icecube");
7447 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
7453 ** Usage: sqlite3_mmap_warm DB DBNAME
7455 static int SQLITE_TCLAPI
test_mmap_warm(
7459 Tcl_Obj
*CONST objv
[]
7461 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
7462 extern int sqlite3_mmap_warm(sqlite3
*db
, const char *);
7464 if( objc
!=2 && objc
!=3 ){
7465 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?DBNAME?");
7470 const char *zDb
= 0;
7471 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7473 zDb
= Tcl_GetString(objv
[2]);
7475 rc
= sqlite3_mmap_warm(db
, zDb
);
7476 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
7482 ** Register commands with the TCL interpreter.
7484 int Sqlitetest1_Init(Tcl_Interp
*interp
){
7485 extern int sqlite3_search_count
;
7486 extern int sqlite3_found_count
;
7487 extern int sqlite3_interrupt_count
;
7488 extern int sqlite3_open_file_count
;
7489 extern int sqlite3_sort_count
;
7490 extern int sqlite3_current_time
;
7491 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
7492 extern int sqlite3_hostid_num
;
7494 extern int sqlite3_max_blobsize
;
7495 extern int SQLITE_TCLAPI
sqlite3BtreeSharedCacheReport(void*,
7496 Tcl_Interp
*,int,Tcl_Obj
*CONST
*);
7497 static int iZero
= 0;
7502 { "db_enter", (Tcl_CmdProc
*)db_enter
},
7503 { "db_leave", (Tcl_CmdProc
*)db_leave
},
7504 { "sqlite3_mprintf_int", (Tcl_CmdProc
*)sqlite3_mprintf_int
},
7505 { "sqlite3_mprintf_int64", (Tcl_CmdProc
*)sqlite3_mprintf_int64
},
7506 { "sqlite3_mprintf_long", (Tcl_CmdProc
*)sqlite3_mprintf_long
},
7507 { "sqlite3_mprintf_str", (Tcl_CmdProc
*)sqlite3_mprintf_str
},
7508 { "sqlite3_snprintf_str", (Tcl_CmdProc
*)sqlite3_snprintf_str
},
7509 { "sqlite3_mprintf_stronly", (Tcl_CmdProc
*)sqlite3_mprintf_stronly
},
7510 { "sqlite3_mprintf_double", (Tcl_CmdProc
*)sqlite3_mprintf_double
},
7511 { "sqlite3_mprintf_scaled", (Tcl_CmdProc
*)sqlite3_mprintf_scaled
},
7512 { "sqlite3_mprintf_hexdouble", (Tcl_CmdProc
*)sqlite3_mprintf_hexdouble
},
7513 { "sqlite3_mprintf_z_test", (Tcl_CmdProc
*)test_mprintf_z
},
7514 { "sqlite3_mprintf_n_test", (Tcl_CmdProc
*)test_mprintf_n
},
7515 { "sqlite3_snprintf_int", (Tcl_CmdProc
*)test_snprintf_int
},
7516 { "sqlite3_last_insert_rowid", (Tcl_CmdProc
*)test_last_rowid
},
7517 { "sqlite3_exec_printf", (Tcl_CmdProc
*)test_exec_printf
},
7518 { "sqlite3_exec_hex", (Tcl_CmdProc
*)test_exec_hex
},
7519 { "sqlite3_exec", (Tcl_CmdProc
*)test_exec
},
7520 { "sqlite3_exec_nr", (Tcl_CmdProc
*)test_exec_nr
},
7521 #ifndef SQLITE_OMIT_GET_TABLE
7522 { "sqlite3_get_table_printf", (Tcl_CmdProc
*)test_get_table_printf
},
7524 { "sqlite3_close", (Tcl_CmdProc
*)sqlite_test_close
},
7525 { "sqlite3_close_v2", (Tcl_CmdProc
*)sqlite_test_close_v2
},
7526 { "sqlite3_create_function", (Tcl_CmdProc
*)test_create_function
},
7527 { "sqlite3_create_aggregate", (Tcl_CmdProc
*)test_create_aggregate
},
7528 { "sqlite_register_test_function", (Tcl_CmdProc
*)test_register_func
},
7529 { "sqlite_abort", (Tcl_CmdProc
*)sqlite_abort
},
7530 { "sqlite_bind", (Tcl_CmdProc
*)test_bind
},
7531 { "breakpoint", (Tcl_CmdProc
*)test_breakpoint
},
7532 { "sqlite3_key", (Tcl_CmdProc
*)test_key
},
7533 { "sqlite3_rekey", (Tcl_CmdProc
*)test_rekey
},
7534 { "sqlite_set_magic", (Tcl_CmdProc
*)sqlite_set_magic
},
7535 { "sqlite3_interrupt", (Tcl_CmdProc
*)test_interrupt
},
7536 { "sqlite_delete_function", (Tcl_CmdProc
*)delete_function
},
7537 { "sqlite_delete_collation", (Tcl_CmdProc
*)delete_collation
},
7538 { "sqlite3_get_autocommit", (Tcl_CmdProc
*)get_autocommit
},
7539 { "sqlite3_busy_timeout", (Tcl_CmdProc
*)test_busy_timeout
},
7540 { "printf", (Tcl_CmdProc
*)test_printf
},
7541 { "sqlite3IoTrace", (Tcl_CmdProc
*)test_io_trace
},
7542 { "clang_sanitize_address", (Tcl_CmdProc
*)clang_sanitize_address
},
7546 Tcl_ObjCmdProc
*xProc
;
7549 { "sqlite3_db_config", test_sqlite3_db_config
, 0 },
7550 { "bad_behavior", test_bad_behavior
, (void*)&iZero
},
7551 { "register_dbstat_vtab", test_register_dbstat_vtab
},
7552 { "sqlite3_connection_pointer", get_sqlite_pointer
, 0 },
7553 { "intarray_addr", test_intarray_addr
, 0 },
7554 { "int64array_addr", test_int64array_addr
, 0 },
7555 { "doublearray_addr", test_doublearray_addr
, 0 },
7556 { "textarray_addr", test_textarray_addr
, 0 },
7557 { "sqlite3_bind_int", test_bind_int
, 0 },
7558 { "sqlite3_bind_zeroblob", test_bind_zeroblob
, 0 },
7559 { "sqlite3_bind_zeroblob64", test_bind_zeroblob64
, 0 },
7560 { "sqlite3_bind_int64", test_bind_int64
, 0 },
7561 { "sqlite3_bind_double", test_bind_double
, 0 },
7562 { "sqlite3_bind_null", test_bind_null
,0 },
7563 { "sqlite3_bind_text", test_bind_text
,0 },
7564 { "sqlite3_bind_text16", test_bind_text16
,0 },
7565 { "sqlite3_bind_blob", test_bind_blob
,0 },
7566 { "sqlite3_bind_parameter_count", test_bind_parameter_count
, 0},
7567 { "sqlite3_bind_parameter_name", test_bind_parameter_name
, 0},
7568 { "sqlite3_bind_parameter_index", test_bind_parameter_index
, 0},
7569 { "sqlite3_clear_bindings", test_clear_bindings
, 0},
7570 { "sqlite3_sleep", test_sleep
, 0},
7571 { "sqlite3_errcode", test_errcode
,0 },
7572 { "sqlite3_extended_errcode", test_ex_errcode
,0 },
7573 { "sqlite3_errmsg", test_errmsg
,0 },
7574 { "sqlite3_errmsg16", test_errmsg16
,0 },
7575 { "sqlite3_open", test_open
,0 },
7576 { "sqlite3_open16", test_open16
,0 },
7577 { "sqlite3_open_v2", test_open_v2
,0 },
7578 { "sqlite3_complete16", test_complete16
,0 },
7579 { "sqlite3_normalize", test_normalize
,0 },
7581 { "sqlite3_prepare", test_prepare
,0 },
7582 { "sqlite3_prepare16", test_prepare16
,0 },
7583 { "sqlite3_prepare_v2", test_prepare_v2
,0 },
7584 { "sqlite3_prepare_tkt3134", test_prepare_tkt3134
, 0},
7585 { "sqlite3_prepare16_v2", test_prepare16_v2
,0 },
7586 { "sqlite3_finalize", test_finalize
,0 },
7587 { "sqlite3_stmt_status", test_stmt_status
,0 },
7588 { "sqlite3_reset", test_reset
,0 },
7589 { "sqlite3_expired", test_expired
,0 },
7590 { "sqlite3_transfer_bindings", test_transfer_bind
,0 },
7591 { "sqlite3_changes", test_changes
,0 },
7592 { "sqlite3_step", test_step
,0 },
7593 { "sqlite3_sql", test_sql
,0 },
7594 { "sqlite3_expanded_sql", test_ex_sql
,0 },
7595 { "sqlite3_next_stmt", test_next_stmt
,0 },
7596 { "sqlite3_stmt_readonly", test_stmt_readonly
,0 },
7597 { "sqlite3_stmt_busy", test_stmt_busy
,0 },
7598 { "uses_stmt_journal", uses_stmt_journal
,0 },
7600 { "sqlite3_release_memory", test_release_memory
, 0},
7601 { "sqlite3_db_release_memory", test_db_release_memory
, 0},
7602 { "sqlite3_db_cacheflush", test_db_cacheflush
, 0},
7603 { "sqlite3_system_errno", test_system_errno
, 0},
7604 { "sqlite3_db_filename", test_db_filename
, 0},
7605 { "sqlite3_db_readonly", test_db_readonly
, 0},
7606 { "sqlite3_soft_heap_limit", test_soft_heap_limit
, 0},
7607 { "sqlite3_thread_cleanup", test_thread_cleanup
, 0},
7608 { "sqlite3_pager_refcounts", test_pager_refcounts
, 0},
7610 { "sqlite3_load_extension", test_load_extension
, 0},
7611 { "sqlite3_enable_load_extension", test_enable_load
, 0},
7612 { "sqlite3_extended_result_codes", test_extended_result_codes
, 0},
7613 { "sqlite3_limit", test_limit
, 0},
7614 { "dbconfig_maindbname_icecube", test_dbconfig_maindbname_icecube
},
7616 { "save_prng_state", save_prng_state
, 0 },
7617 { "restore_prng_state", restore_prng_state
, 0 },
7618 { "reset_prng_state", reset_prng_state
, 0 },
7619 { "database_never_corrupt", database_never_corrupt
, 0},
7620 { "database_may_be_corrupt", database_may_be_corrupt
, 0},
7621 { "optimization_control", optimization_control
,0},
7623 { "lock_win32_file", win32_file_lock
, 0 },
7624 { "exists_win32_path", win32_exists_path
, 0 },
7625 { "find_win32_file", win32_find_file
, 0 },
7626 { "delete_win32_file", win32_delete_file
, 0 },
7627 { "make_win32_dir", win32_mkdir
, 0 },
7628 { "remove_win32_dir", win32_rmdir
, 0 },
7630 { "tcl_objproc", runAsObjProc
, 0 },
7632 /* sqlite3_column_*() API */
7633 { "sqlite3_column_count", test_column_count
,0 },
7634 { "sqlite3_data_count", test_data_count
,0 },
7635 { "sqlite3_column_type", test_column_type
,0 },
7636 { "sqlite3_column_blob", test_column_blob
,0 },
7637 { "sqlite3_column_double", test_column_double
,0 },
7638 { "sqlite3_column_int64", test_column_int64
,0 },
7639 { "sqlite3_column_text", test_stmt_utf8
, (void*)sqlite3_column_text
},
7640 { "sqlite3_column_name", test_stmt_utf8
, (void*)sqlite3_column_name
},
7641 { "sqlite3_column_int", test_stmt_int
, (void*)sqlite3_column_int
},
7642 { "sqlite3_column_bytes", test_stmt_int
, (void*)sqlite3_column_bytes
},
7643 #ifndef SQLITE_OMIT_DECLTYPE
7644 { "sqlite3_column_decltype",test_stmt_utf8
,(void*)sqlite3_column_decltype
},
7646 #ifdef SQLITE_ENABLE_COLUMN_METADATA
7647 { "sqlite3_column_database_name",test_stmt_utf8
,(void*)sqlite3_column_database_name
},
7648 { "sqlite3_column_table_name",test_stmt_utf8
,(void*)sqlite3_column_table_name
},
7649 { "sqlite3_column_origin_name",test_stmt_utf8
,(void*)sqlite3_column_origin_name
},
7652 #ifndef SQLITE_OMIT_UTF16
7653 { "sqlite3_column_bytes16", test_stmt_int
, (void*)sqlite3_column_bytes16
},
7654 { "sqlite3_column_text16", test_stmt_utf16
, (void*)sqlite3_column_text16
},
7655 { "sqlite3_column_name16", test_stmt_utf16
, (void*)sqlite3_column_name16
},
7656 { "add_alignment_test_collations", add_alignment_test_collations
, 0 },
7657 #ifndef SQLITE_OMIT_DECLTYPE
7658 { "sqlite3_column_decltype16",test_stmt_utf16
,(void*)sqlite3_column_decltype16
},
7660 #ifdef SQLITE_ENABLE_COLUMN_METADATA
7661 {"sqlite3_column_database_name16",
7662 test_stmt_utf16
, (void*)sqlite3_column_database_name16
},
7663 {"sqlite3_column_table_name16", test_stmt_utf16
, (void*)sqlite3_column_table_name16
},
7664 {"sqlite3_column_origin_name16", test_stmt_utf16
, (void*)sqlite3_column_origin_name16
},
7667 { "sqlite3_create_collation_v2", test_create_collation_v2
, 0 },
7668 { "sqlite3_global_recover", test_global_recover
, 0 },
7669 { "working_64bit_int", working_64bit_int
, 0 },
7670 { "vfs_unlink_test", vfs_unlink_test
, 0 },
7671 { "vfs_initfail_test", vfs_initfail_test
, 0 },
7672 { "vfs_unregister_all", vfs_unregister_all
, 0 },
7673 { "vfs_reregister_all", vfs_reregister_all
, 0 },
7674 { "file_control_test", file_control_test
, 0 },
7675 { "file_control_lasterrno_test", file_control_lasterrno_test
, 0 },
7676 { "file_control_lockproxy_test", file_control_lockproxy_test
, 0 },
7677 { "file_control_chunksize_test", file_control_chunksize_test
, 0 },
7678 { "file_control_sizehint_test", file_control_sizehint_test
, 0 },
7680 { "file_control_win32_av_retry", file_control_win32_av_retry
, 0 },
7681 { "file_control_win32_get_handle", file_control_win32_get_handle
, 0 },
7682 { "file_control_win32_set_handle", file_control_win32_set_handle
, 0 },
7684 { "file_control_persist_wal", file_control_persist_wal
, 0 },
7685 { "file_control_powersafe_overwrite",file_control_powersafe_overwrite
,0},
7686 { "file_control_vfsname", file_control_vfsname
, 0 },
7687 { "file_control_tempfilename", file_control_tempfilename
, 0 },
7688 { "sqlite3_vfs_list", vfs_list
, 0 },
7689 { "sqlite3_create_function_v2", test_create_function_v2
, 0 },
7691 /* Functions from os.h */
7692 #ifndef SQLITE_OMIT_UTF16
7693 { "add_test_collate", test_collate
, 0 },
7694 { "add_test_collate_needed", test_collate_needed
, 0 },
7695 { "add_test_function", test_function
, 0 },
7696 { "add_test_utf16bin_collate", test_utf16bin_collate
, 0 },
7698 { "sqlite3_test_errstr", test_errstr
, 0 },
7699 { "tcl_variable_type", tcl_variable_type
, 0 },
7700 #ifndef SQLITE_OMIT_SHARED_CACHE
7701 { "sqlite3_enable_shared_cache", test_enable_shared
, 0 },
7702 { "sqlite3_shared_cache_report", sqlite3BtreeSharedCacheReport
, 0},
7704 { "sqlite3_libversion_number", test_libversion_number
, 0 },
7705 { "sqlite3_table_column_metadata", test_table_column_metadata
, 0 },
7706 #ifndef SQLITE_OMIT_INCRBLOB
7707 { "sqlite3_blob_reopen", test_blob_reopen
, 0 },
7709 { "pcache_stats", test_pcache_stats
, 0 },
7710 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
7711 { "sqlite3_unlock_notify", test_unlock_notify
, 0 },
7713 { "sqlite3_wal_checkpoint", test_wal_checkpoint
, 0 },
7714 { "sqlite3_wal_checkpoint_v2",test_wal_checkpoint_v2
, 0 },
7715 { "sqlite3_wal_autocheckpoint",test_wal_autocheckpoint
, 0 },
7716 { "test_sqlite3_log", test_sqlite3_log
, 0 },
7717 #ifndef SQLITE_OMIT_EXPLAIN
7718 { "print_explain_query_plan", test_print_eqp
, 0 },
7720 { "sqlite3_test_control", test_test_control
},
7722 { "getrusage", test_getrusage
},
7724 { "load_static_extension", tclLoadStaticExtensionCmd
},
7725 { "sorter_test_fakeheap", sorter_test_fakeheap
},
7726 { "sorter_test_sort4_helper", sorter_test_sort4_helper
},
7727 #ifdef SQLITE_USER_AUTHENTICATION
7728 { "sqlite3_user_authenticate", test_user_authenticate
, 0 },
7729 { "sqlite3_user_add", test_user_add
, 0 },
7730 { "sqlite3_user_change", test_user_change
, 0 },
7731 { "sqlite3_user_delete", test_user_delete
, 0 },
7733 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
7734 { "sqlite3_stmt_scanstatus", test_stmt_scanstatus
, 0 },
7735 { "sqlite3_stmt_scanstatus_reset", test_stmt_scanstatus_reset
, 0 },
7737 #ifdef SQLITE_ENABLE_SQLLOG
7738 { "sqlite3_config_sqllog", test_config_sqllog
, 0 },
7740 { "vfs_current_time_int64", vfsCurrentTimeInt64
, 0 },
7741 #ifdef SQLITE_ENABLE_SNAPSHOT
7742 { "sqlite3_snapshot_get", test_snapshot_get
, 0 },
7743 { "sqlite3_snapshot_open", test_snapshot_open
, 0 },
7744 { "sqlite3_snapshot_free", test_snapshot_free
, 0 },
7745 { "sqlite3_snapshot_cmp", test_snapshot_cmp
, 0 },
7746 { "sqlite3_snapshot_recover", test_snapshot_recover
, 0 },
7747 { "sqlite3_snapshot_get_blob", test_snapshot_get_blob
, 0 },
7748 { "sqlite3_snapshot_open_blob", test_snapshot_open_blob
, 0 },
7749 { "sqlite3_snapshot_cmp_blob", test_snapshot_cmp_blob
, 0 },
7751 { "sqlite3_delete_database", test_delete_database
, 0 },
7752 { "atomic_batch_write", test_atomic_batch_write
, 0 },
7753 { "sqlite3_mmap_warm", test_mmap_warm
, 0 },
7755 static int bitmask_size
= sizeof(Bitmask
)*8;
7756 static int longdouble_size
= sizeof(LONGDOUBLE_TYPE
);
7758 extern int sqlite3_sync_count
, sqlite3_fullsync_count
;
7759 extern int sqlite3_opentemp_count
;
7760 extern int sqlite3_like_count
;
7761 extern int sqlite3_xferopt_count
;
7762 extern int sqlite3_pager_readdb_count
;
7763 extern int sqlite3_pager_writedb_count
;
7764 extern int sqlite3_pager_writej_count
;
7766 extern LONG
volatile sqlite3_os_type
;
7769 extern int sqlite3WhereTrace
;
7770 extern int sqlite3OSTrace
;
7771 extern int sqlite3WalTrace
;
7774 #ifdef SQLITE_ENABLE_FTS3
7775 extern int sqlite3_fts3_enable_parentheses
;
7779 for(i
=0; i
<sizeof(aCmd
)/sizeof(aCmd
[0]); i
++){
7780 Tcl_CreateCommand(interp
, aCmd
[i
].zName
, aCmd
[i
].xProc
, 0, 0);
7782 for(i
=0; i
<sizeof(aObjCmd
)/sizeof(aObjCmd
[0]); i
++){
7783 Tcl_CreateObjCommand(interp
, aObjCmd
[i
].zName
,
7784 aObjCmd
[i
].xProc
, aObjCmd
[i
].clientData
, 0);
7786 Tcl_LinkVar(interp
, "sqlite_search_count",
7787 (char*)&sqlite3_search_count
, TCL_LINK_INT
);
7788 Tcl_LinkVar(interp
, "sqlite_found_count",
7789 (char*)&sqlite3_found_count
, TCL_LINK_INT
);
7790 Tcl_LinkVar(interp
, "sqlite_sort_count",
7791 (char*)&sqlite3_sort_count
, TCL_LINK_INT
);
7792 Tcl_LinkVar(interp
, "sqlite3_max_blobsize",
7793 (char*)&sqlite3_max_blobsize
, TCL_LINK_INT
);
7794 Tcl_LinkVar(interp
, "sqlite_like_count",
7795 (char*)&sqlite3_like_count
, TCL_LINK_INT
);
7796 Tcl_LinkVar(interp
, "sqlite_interrupt_count",
7797 (char*)&sqlite3_interrupt_count
, TCL_LINK_INT
);
7798 Tcl_LinkVar(interp
, "sqlite_open_file_count",
7799 (char*)&sqlite3_open_file_count
, TCL_LINK_INT
);
7800 Tcl_LinkVar(interp
, "sqlite_current_time",
7801 (char*)&sqlite3_current_time
, TCL_LINK_INT
);
7802 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
7803 Tcl_LinkVar(interp
, "sqlite_hostid_num",
7804 (char*)&sqlite3_hostid_num
, TCL_LINK_INT
);
7806 Tcl_LinkVar(interp
, "sqlite3_xferopt_count",
7807 (char*)&sqlite3_xferopt_count
, TCL_LINK_INT
);
7808 Tcl_LinkVar(interp
, "sqlite3_pager_readdb_count",
7809 (char*)&sqlite3_pager_readdb_count
, TCL_LINK_INT
);
7810 Tcl_LinkVar(interp
, "sqlite3_pager_writedb_count",
7811 (char*)&sqlite3_pager_writedb_count
, TCL_LINK_INT
);
7812 Tcl_LinkVar(interp
, "sqlite3_pager_writej_count",
7813 (char*)&sqlite3_pager_writej_count
, TCL_LINK_INT
);
7814 #ifndef SQLITE_OMIT_UTF16
7815 Tcl_LinkVar(interp
, "unaligned_string_counter",
7816 (char*)&unaligned_string_counter
, TCL_LINK_INT
);
7818 #ifndef SQLITE_OMIT_UTF16
7819 Tcl_LinkVar(interp
, "sqlite_last_needed_collation",
7820 (char*)&pzNeededCollation
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
7823 Tcl_LinkVar(interp
, "sqlite_os_type",
7824 (char*)&sqlite3_os_type
, TCL_LINK_LONG
);
7828 static const char *query_plan
= "*** OBSOLETE VARIABLE ***";
7829 Tcl_LinkVar(interp
, "sqlite_query_plan",
7830 (char*)&query_plan
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
7834 Tcl_LinkVar(interp
, "sqlite_where_trace",
7835 (char*)&sqlite3WhereTrace
, TCL_LINK_INT
);
7836 Tcl_LinkVar(interp
, "sqlite_os_trace",
7837 (char*)&sqlite3OSTrace
, TCL_LINK_INT
);
7838 #ifndef SQLITE_OMIT_WAL
7839 Tcl_LinkVar(interp
, "sqlite_wal_trace",
7840 (char*)&sqlite3WalTrace
, TCL_LINK_INT
);
7843 #ifndef SQLITE_OMIT_DISKIO
7844 Tcl_LinkVar(interp
, "sqlite_opentemp_count",
7845 (char*)&sqlite3_opentemp_count
, TCL_LINK_INT
);
7847 Tcl_LinkVar(interp
, "sqlite_static_bind_value",
7848 (char*)&sqlite_static_bind_value
, TCL_LINK_STRING
);
7849 Tcl_LinkVar(interp
, "sqlite_static_bind_nbyte",
7850 (char*)&sqlite_static_bind_nbyte
, TCL_LINK_INT
);
7851 Tcl_LinkVar(interp
, "sqlite_temp_directory",
7852 (char*)&sqlite3_temp_directory
, TCL_LINK_STRING
);
7853 Tcl_LinkVar(interp
, "sqlite_data_directory",
7854 (char*)&sqlite3_data_directory
, TCL_LINK_STRING
);
7855 Tcl_LinkVar(interp
, "bitmask_size",
7856 (char*)&bitmask_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
7857 Tcl_LinkVar(interp
, "longdouble_size",
7858 (char*)&longdouble_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
7859 Tcl_LinkVar(interp
, "sqlite_sync_count",
7860 (char*)&sqlite3_sync_count
, TCL_LINK_INT
);
7861 Tcl_LinkVar(interp
, "sqlite_fullsync_count",
7862 (char*)&sqlite3_fullsync_count
, TCL_LINK_INT
);
7863 #if defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_TEST)
7864 Tcl_LinkVar(interp
, "sqlite_fts3_enable_parentheses",
7865 (char*)&sqlite3_fts3_enable_parentheses
, TCL_LINK_INT
);