4 ** The author disclaims copyright to this source code. In place of
5 ** a legal notice, here is a blessing:
7 ** May you do good and not evil.
8 ** May you find forgiveness for yourself and forgive others.
9 ** May you share freely, never taking more than you give.
11 *************************************************************************
12 ** Code for testing all sorts of SQLite interfaces. This code
13 ** is not included in the SQLite library. It is used for automated
14 ** testing of the SQLite library.
16 #include "sqliteInt.h"
22 # if defined(__APPLE__)
23 # include <sys/param.h>
24 # include <sys/sysctl.h>
29 #if defined(INCLUDE_SQLITE_TCL_H)
30 # include "sqlite_tcl.h"
38 ** This is a copy of the first part of the SqliteDb structure in
39 ** tclsqlite.c. We need it here so that the get_sqlite_pointer routine
40 ** can extract the sqlite3* pointer from an existing Tcl SQLite
48 ** Convert text generated by the "%p" conversion format back into
51 static int testHexToInt(int h
){
52 if( h
>='0' && h
<='9' ){
54 }else if( h
>='a' && h
<='f' ){
57 assert( h
>='A' && h
<='F' );
61 void *sqlite3TestTextToPtr(const char *z
){
65 if( z
[0]=='0' && z
[1]=='x' ){
70 v
= (v
<<4) + testHexToInt(*z
);
73 if( sizeof(p
)==sizeof(v
) ){
74 memcpy(&p
, &v
, sizeof(p
));
76 assert( sizeof(p
)==sizeof(v2
) );
78 memcpy(&p
, &v2
, sizeof(p
));
85 ** A TCL command that returns the address of the sqlite* pointer
86 ** for an sqlite connection instance. Bad things happen if the
87 ** input is not an sqlite connection.
89 static int SQLITE_TCLAPI
get_sqlite_pointer(
99 Tcl_WrongNumArgs(interp
, 1, objv
, "SQLITE-CONNECTION");
102 if( !Tcl_GetCommandInfo(interp
, Tcl_GetString(objv
[1]), &cmdInfo
) ){
103 Tcl_AppendResult(interp
, "command not found: ",
104 Tcl_GetString(objv
[1]), (char*)0);
107 p
= (struct SqliteDb
*)cmdInfo
.objClientData
;
108 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%p", p
->db
);
109 Tcl_AppendResult(interp
, zBuf
, 0);
114 ** Decode a pointer to an sqlite3 object.
116 int getDbPointer(Tcl_Interp
*interp
, const char *zA
, sqlite3
**ppDb
){
119 if( Tcl_GetCommandInfo(interp
, zA
, &cmdInfo
) ){
120 p
= (struct SqliteDb
*)cmdInfo
.objClientData
;
123 *ppDb
= (sqlite3
*)sqlite3TestTextToPtr(zA
);
130 ** Decode a Win32 HANDLE object.
132 int getWin32Handle(Tcl_Interp
*interp
, const char *zA
, LPHANDLE phFile
){
133 *phFile
= (HANDLE
)sqlite3TestTextToPtr(zA
);
138 extern const char *sqlite3ErrName(int);
139 #define t1ErrorName sqlite3ErrName
142 ** Convert an sqlite3_stmt* into an sqlite3*. This depends on the
143 ** fact that the sqlite3* is the first field in the Vdbe structure.
145 #define StmtToDb(X) sqlite3_db_handle(X)
148 ** Check a return value to make sure it agrees with the results
149 ** from sqlite3_errcode.
151 int sqlite3TestErrCode(Tcl_Interp
*interp
, sqlite3
*db
, int rc
){
152 if( sqlite3_threadsafe()==0 && rc
!=SQLITE_MISUSE
&& rc
!=SQLITE_OK
153 && sqlite3_errcode(db
)!=rc
){
155 int r2
= sqlite3_errcode(db
);
156 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
157 "error code %s (%d) does not match sqlite3_errcode %s (%d)",
158 t1ErrorName(rc
), rc
, t1ErrorName(r2
), r2
);
159 Tcl_ResetResult(interp
);
160 Tcl_AppendResult(interp
, zBuf
, 0);
167 ** Decode a pointer to an sqlite3_stmt object.
169 static int getStmtPointer(
172 sqlite3_stmt
**ppStmt
174 *ppStmt
= (sqlite3_stmt
*)sqlite3TestTextToPtr(zArg
);
179 ** Generate a text representation of a pointer that can be understood
180 ** by the getDbPointer and getVmPointer routines above.
182 ** The problem is, on some machines (Solaris) if you do a printf with
183 ** "%p" you cannot turn around and do a scanf with the same "%p" and
184 ** get your pointer back. You have to prepend a "0x" before it will
185 ** work. Or at least that is what is reported to me (drh). But this
186 ** behavior varies from machine to machine. The solution used her is
187 ** to test the string right after it is generated to see if it can be
188 ** understood by scanf, and if not, try prepending an "0x" to see if
189 ** that helps. If nothing works, a fatal error is generated.
191 int sqlite3TestMakePointerStr(Tcl_Interp
*interp
, char *zPtr
, void *p
){
192 sqlite3_snprintf(100, zPtr
, "%p", p
);
197 ** The callback routine for sqlite3_exec_printf().
199 static int exec_printf_cb(void *pArg
, int argc
, char **argv
, char **name
){
200 Tcl_DString
*str
= (Tcl_DString
*)pArg
;
203 if( Tcl_DStringLength(str
)==0 ){
204 for(i
=0; i
<argc
; i
++){
205 Tcl_DStringAppendElement(str
, name
[i
] ? name
[i
] : "NULL");
208 for(i
=0; i
<argc
; i
++){
209 Tcl_DStringAppendElement(str
, argv
[i
] ? argv
[i
] : "NULL");
215 ** The I/O tracing callback.
217 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
218 static FILE *iotrace_file
= 0;
219 static void io_trace_callback(const char *zFormat
, ...){
221 va_start(ap
, zFormat
);
222 vfprintf(iotrace_file
, zFormat
, ap
);
224 fflush(iotrace_file
);
229 ** Usage: io_trace FILENAME
231 ** Turn I/O tracing on or off. If FILENAME is not an empty string,
232 ** I/O tracing begins going into FILENAME. If FILENAME is an empty
233 ** string, I/O tracing is turned off.
235 static int SQLITE_TCLAPI
test_io_trace(
237 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
238 int argc
, /* Number of arguments */
239 char **argv
/* Text of each argument */
241 #if !defined(SQLITE_OMIT_TRACE) && defined(SQLITE_ENABLE_IOTRACE)
243 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
248 if( iotrace_file
!=stdout
&& iotrace_file
!=stderr
){
249 fclose(iotrace_file
);
255 if( strcmp(argv
[1],"stdout")==0 ){
256 iotrace_file
= stdout
;
257 }else if( strcmp(argv
[1],"stderr")==0 ){
258 iotrace_file
= stderr
;
260 iotrace_file
= fopen(argv
[1], "w");
262 sqlite3IoTrace
= io_trace_callback
;
269 ** Usage: clang_sanitize_address
271 ** Returns true if the program was compiled using clang with the
272 ** -fsanitize=address switch on the command line. False otherwise.
274 ** Also return true if the OMIT_MISUSE environment variable exists.
276 static int SQLITE_TCLAPI
clang_sanitize_address(
278 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
279 int argc
, /* Number of arguments */
280 char **argv
/* Text of each argument */
283 #if defined(__has_feature)
284 # if __has_feature(address_sanitizer)
288 #ifdef __SANITIZE_ADDRESS__
291 if( res
==0 && getenv("OMIT_MISUSE")!=0 ) res
= 1;
292 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
297 ** Usage: sqlite3_exec_printf DB FORMAT STRING
299 ** Invoke the sqlite3_exec_printf() interface using the open database
300 ** DB. The SQL is the string FORMAT. The format string should contain
301 ** one %s or %q. STRING is the value inserted into %s or %q.
303 static int SQLITE_TCLAPI
test_exec_printf(
305 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
306 int argc
, /* Number of arguments */
307 char **argv
/* Text of each argument */
316 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
317 " DB FORMAT STRING", 0);
320 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
321 Tcl_DStringInit(&str
);
322 zSql
= sqlite3_mprintf(argv
[2], argv
[3]);
323 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
325 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
326 Tcl_AppendElement(interp
, zBuf
);
327 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
328 Tcl_DStringFree(&str
);
329 if( zErr
) sqlite3_free(zErr
);
330 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
335 ** Usage: sqlite3_exec_hex DB HEX
337 ** Invoke the sqlite3_exec() on a string that is obtained by translating
338 ** HEX into ASCII. Most characters are translated as is. %HH becomes
341 static int SQLITE_TCLAPI
test_exec_hex(
343 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
344 int argc
, /* Number of arguments */
345 char **argv
/* Text of each argument */
355 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
359 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
361 for(i
=j
=0; i
<(sizeof(zSql
)-1) && zHex
[j
]; i
++, j
++){
362 if( zHex
[j
]=='%' && zHex
[j
+2] && zHex
[j
+2] ){
363 zSql
[i
] = (testHexToInt(zHex
[j
+1])<<4) + testHexToInt(zHex
[j
+2]);
370 Tcl_DStringInit(&str
);
371 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
372 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
373 Tcl_AppendElement(interp
, zBuf
);
374 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
375 Tcl_DStringFree(&str
);
376 if( zErr
) sqlite3_free(zErr
);
377 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
382 ** Usage: db_enter DB
385 ** Enter or leave the mutex on a database connection.
387 static int SQLITE_TCLAPI
db_enter(
389 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
390 int argc
, /* Number of arguments */
391 char **argv
/* Text of each argument */
395 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
399 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
400 sqlite3_mutex_enter(db
->mutex
);
403 static int SQLITE_TCLAPI
db_leave(
405 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
406 int argc
, /* Number of arguments */
407 char **argv
/* Text of each argument */
411 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
415 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
416 sqlite3_mutex_leave(db
->mutex
);
421 ** Usage: sqlite3_exec DB SQL
423 ** Invoke the sqlite3_exec interface using the open database DB
425 static int SQLITE_TCLAPI
test_exec(
427 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
428 int argc
, /* Number of arguments */
429 char **argv
/* Text of each argument */
439 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
443 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
444 Tcl_DStringInit(&str
);
445 zSql
= sqlite3_mprintf("%s", argv
[2]);
446 for(i
=j
=0; zSql
[i
];){
448 zSql
[j
++] = (testHexToInt(zSql
[i
+1])<<4) + testHexToInt(zSql
[i
+2]);
451 zSql
[j
++] = zSql
[i
++];
455 rc
= sqlite3_exec(db
, zSql
, exec_printf_cb
, &str
, &zErr
);
457 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
458 Tcl_AppendElement(interp
, zBuf
);
459 Tcl_AppendElement(interp
, rc
==SQLITE_OK
? Tcl_DStringValue(&str
) : zErr
);
460 Tcl_DStringFree(&str
);
461 if( zErr
) sqlite3_free(zErr
);
462 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
467 ** Usage: sqlite3_exec_nr DB SQL
469 ** Invoke the sqlite3_exec interface using the open database DB. Discard
472 static int SQLITE_TCLAPI
test_exec_nr(
474 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
475 int argc
, /* Number of arguments */
476 char **argv
/* Text of each argument */
482 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
486 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
487 rc
= sqlite3_exec(db
, argv
[2], 0, 0, &zErr
);
488 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
493 ** Usage: sqlite3_mprintf_z_test SEPARATOR ARG0 ARG1 ...
495 ** Test the %z format of sqlite_mprintf(). Use multiple mprintf() calls to
496 ** concatenate arg0 through argn using separator as the separator.
497 ** Return the result.
499 static int SQLITE_TCLAPI
test_mprintf_z(
501 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
502 int argc
, /* Number of arguments */
503 char **argv
/* Text of each argument */
508 for(i
=2; i
<argc
&& (i
==2 || zResult
); i
++){
509 zResult
= sqlite3_mprintf("%z%s%s", zResult
, argv
[1], argv
[i
]);
511 Tcl_AppendResult(interp
, zResult
, 0);
512 sqlite3_free(zResult
);
517 ** Usage: sqlite3_mprintf_n_test STRING
519 ** Test the %n format of sqlite_mprintf(). Return the length of the
522 static int SQLITE_TCLAPI
test_mprintf_n(
524 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
525 int argc
, /* Number of arguments */
526 char **argv
/* Text of each argument */
530 zStr
= sqlite3_mprintf("%s%n", argv
[1], &n
);
532 Tcl_SetObjResult(interp
, Tcl_NewIntObj(n
));
537 ** Usage: sqlite3_snprintf_int SIZE FORMAT INT
539 ** Test the of sqlite3_snprintf() routine. SIZE is the size of the
540 ** output buffer in bytes. The maximum size is 100. FORMAT is the
541 ** format string. INT is a single integer argument. The FORMAT
542 ** string must require no more than this one integer argument. If
543 ** You pass in a format string that requires more than one argument,
544 ** bad things will happen.
546 static int SQLITE_TCLAPI
test_snprintf_int(
548 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
549 int argc
, /* Number of arguments */
550 char **argv
/* Text of each argument */
553 int n
= atoi(argv
[1]);
554 const char *zFormat
= argv
[2];
555 int a1
= atoi(argv
[3]);
556 if( n
>sizeof(zStr
) ) n
= sizeof(zStr
);
557 sqlite3_snprintf(sizeof(zStr
), zStr
, "abcdefghijklmnopqrstuvwxyz");
558 sqlite3_snprintf(n
, zStr
, zFormat
, a1
);
559 Tcl_AppendResult(interp
, zStr
, 0);
563 #ifndef SQLITE_OMIT_GET_TABLE
566 ** Usage: sqlite3_get_table_printf DB FORMAT STRING ?--no-counts?
568 ** Invoke the sqlite3_get_table_printf() interface using the open database
569 ** DB. The SQL is the string FORMAT. The format string should contain
570 ** one %s or %q. STRING is the value inserted into %s or %q.
572 static int SQLITE_TCLAPI
test_get_table_printf(
574 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
575 int argc
, /* Number of arguments */
576 char **argv
/* Text of each argument */
582 int nRow
= 0, nCol
= 0;
589 if( Tcl_GetInt(interp
, argv
[4], &resCount
) ) return TCL_ERROR
;
591 if( argc
!=4 && argc
!=5 ){
592 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
593 " DB FORMAT STRING ?COUNT?", 0);
596 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
597 Tcl_DStringInit(&str
);
598 zSql
= sqlite3_mprintf(argv
[2],argv
[3]);
600 rc
= sqlite3_get_table(db
, zSql
, &aResult
, 0, 0, &zErr
);
602 rc
= sqlite3_get_table(db
, zSql
, &aResult
, &nRow
, &nCol
, &zErr
);
603 resCount
= (nRow
+1)*nCol
;
606 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", rc
);
607 Tcl_AppendElement(interp
, zBuf
);
610 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", nRow
);
611 Tcl_AppendElement(interp
, zBuf
);
612 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", nCol
);
613 Tcl_AppendElement(interp
, zBuf
);
615 for(i
=0; i
<resCount
; i
++){
616 Tcl_AppendElement(interp
, aResult
[i
] ? aResult
[i
] : "NULL");
619 Tcl_AppendElement(interp
, zErr
);
621 sqlite3_free_table(aResult
);
622 if( zErr
) sqlite3_free(zErr
);
623 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
627 #endif /* SQLITE_OMIT_GET_TABLE */
631 ** Usage: sqlite3_last_insert_rowid DB
633 ** Returns the integer ROWID of the most recent insert.
635 static int SQLITE_TCLAPI
test_last_rowid(
637 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
638 int argc
, /* Number of arguments */
639 char **argv
/* Text of each argument */
645 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB\"", 0);
648 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
649 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%lld", sqlite3_last_insert_rowid(db
));
650 Tcl_AppendResult(interp
, zBuf
, 0);
655 ** Usage: sqlite3_key DB KEY
657 ** Set the codec key.
659 static int SQLITE_TCLAPI
test_key(
661 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
662 int argc
, /* Number of arguments */
663 char **argv
/* Text of each argument */
669 ** Usage: sqlite3_rekey DB KEY
671 ** Change the codec key.
673 static int SQLITE_TCLAPI
test_rekey(
675 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
676 int argc
, /* Number of arguments */
677 char **argv
/* Text of each argument */
683 ** Usage: sqlite3_close DB
685 ** Closes the database opened by sqlite3_open.
687 static int SQLITE_TCLAPI
sqlite_test_close(
689 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
690 int argc
, /* Number of arguments */
691 char **argv
/* Text of each argument */
696 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
700 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
701 rc
= sqlite3_close(db
);
702 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
707 ** Usage: sqlite3_close_v2 DB
709 ** Closes the database opened by sqlite3_open.
711 static int SQLITE_TCLAPI
sqlite_test_close_v2(
713 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
714 int argc
, /* Number of arguments */
715 char **argv
/* Text of each argument */
720 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
724 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
725 rc
= sqlite3_close_v2(db
);
726 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
731 ** Implementation of the x_coalesce() function.
732 ** Return the first argument non-NULL argument.
734 static void t1_ifnullFunc(
735 sqlite3_context
*context
,
740 for(i
=0; i
<argc
; i
++){
741 if( SQLITE_NULL
!=sqlite3_value_type(argv
[i
]) ){
742 int n
= sqlite3_value_bytes(argv
[i
]);
743 sqlite3_result_text(context
, (char*)sqlite3_value_text(argv
[i
]),
744 n
, SQLITE_TRANSIENT
);
751 ** These are test functions. hex8() interprets its argument as
752 ** UTF8 and returns a hex encoding. hex16le() interprets its argument
753 ** as UTF16le and returns a hex encoding.
755 static void hex8Func(sqlite3_context
*p
, int argc
, sqlite3_value
**argv
){
756 const unsigned char *z
;
759 z
= sqlite3_value_text(argv
[0]);
760 for(i
=0; i
<sizeof(zBuf
)/2 - 2 && z
[i
]; i
++){
761 sqlite3_snprintf(sizeof(zBuf
)-i
*2, &zBuf
[i
*2], "%02x", z
[i
]);
764 sqlite3_result_text(p
, (char*)zBuf
, -1, SQLITE_TRANSIENT
);
766 #ifndef SQLITE_OMIT_UTF16
767 static void hex16Func(sqlite3_context
*p
, int argc
, sqlite3_value
**argv
){
768 const unsigned short int *z
;
771 z
= sqlite3_value_text16(argv
[0]);
772 for(i
=0; i
<sizeof(zBuf
)/4 - 4 && z
[i
]; i
++){
773 sqlite3_snprintf(sizeof(zBuf
)-i
*4, &zBuf
[i
*4],"%04x", z
[i
]&0xff);
776 sqlite3_result_text(p
, (char*)zBuf
, -1, SQLITE_TRANSIENT
);
781 ** A structure into which to accumulate text.
784 int nAlloc
; /* Space allocated */
785 int nUsed
; /* Space used */
786 char *z
; /* The space */
790 ** Append text to a dstr
792 static void dstrAppend(struct dstr
*p
, const char *z
, int divider
){
793 int n
= (int)strlen(z
);
794 if( p
->nUsed
+ n
+ 2 > p
->nAlloc
){
796 p
->nAlloc
= p
->nAlloc
*2 + n
+ 200;
797 zNew
= sqlite3_realloc(p
->z
, p
->nAlloc
);
800 memset(p
, 0, sizeof(*p
));
805 if( divider
&& p
->nUsed
>0 ){
806 p
->z
[p
->nUsed
++] = divider
;
808 memcpy(&p
->z
[p
->nUsed
], z
, n
+1);
813 ** Invoked for each callback from sqlite3ExecFunc
815 static int execFuncCallback(void *pData
, int argc
, char **argv
, char **NotUsed
){
816 struct dstr
*p
= (struct dstr
*)pData
;
818 for(i
=0; i
<argc
; i
++){
820 dstrAppend(p
, "NULL", ' ');
822 dstrAppend(p
, argv
[i
], ' ');
829 ** Implementation of the x_sqlite_exec() function. This function takes
830 ** a single argument and attempts to execute that argument as SQL code.
831 ** This is illegal and should set the SQLITE_MISUSE flag on the database.
833 ** 2004-Jan-07: We have changed this to make it legal to call sqlite3_exec()
834 ** from within a function call.
836 ** This routine simulates the effect of having two threads attempt to
837 ** use the same database at the same time.
839 static void sqlite3ExecFunc(
840 sqlite3_context
*context
,
845 memset(&x
, 0, sizeof(x
));
846 (void)sqlite3_exec((sqlite3
*)sqlite3_user_data(context
),
847 (char*)sqlite3_value_text(argv
[0]),
848 execFuncCallback
, &x
, 0);
849 sqlite3_result_text(context
, x
.z
, x
.nUsed
, SQLITE_TRANSIENT
);
854 ** Implementation of tkt2213func(), a scalar function that takes exactly
855 ** one argument. It has two interesting features:
857 ** * It calls sqlite3_value_text() 3 times on the argument sqlite3_value*.
858 ** If the three pointers returned are not the same an SQL error is raised.
860 ** * Otherwise it returns a copy of the text representation of its
861 ** argument in such a way as the VDBE representation is a Mem* cell
862 ** with the MEM_Term flag clear.
864 ** Ticket #2213 can therefore be tested by evaluating the following
867 ** tkt2213func(tkt2213func('a string'));
869 static void tkt2213Function(
870 sqlite3_context
*context
,
875 unsigned char const *zText1
;
876 unsigned char const *zText2
;
877 unsigned char const *zText3
;
879 nText
= sqlite3_value_bytes(argv
[0]);
880 zText1
= sqlite3_value_text(argv
[0]);
881 zText2
= sqlite3_value_text(argv
[0]);
882 zText3
= sqlite3_value_text(argv
[0]);
884 if( zText1
!=zText2
|| zText2
!=zText3
){
885 sqlite3_result_error(context
, "tkt2213 is not fixed", -1);
887 char *zCopy
= (char *)sqlite3_malloc(nText
);
888 memcpy(zCopy
, zText1
, nText
);
889 sqlite3_result_text(context
, zCopy
, nText
, sqlite3_free
);
894 ** The following SQL function takes 4 arguments. The 2nd and
895 ** 4th argument must be one of these strings: 'text', 'text16',
896 ** or 'blob' corresponding to API functions
898 ** sqlite3_value_text()
899 ** sqlite3_value_text16()
900 ** sqlite3_value_blob()
902 ** The third argument is a string, either 'bytes' or 'bytes16' or 'noop',
903 ** corresponding to APIs:
905 ** sqlite3_value_bytes()
906 ** sqlite3_value_bytes16()
909 ** The APIs designated by the 2nd through 4th arguments are applied
910 ** to the first argument in order. If the pointers returned by the
911 ** second and fourth are different, this routine returns 1. Otherwise,
912 ** this routine returns 0.
914 ** This function is used to test to see when returned pointers from
915 ** the _text(), _text16() and _blob() APIs become invalidated.
917 static void ptrChngFunction(
918 sqlite3_context
*context
,
924 if( argc
!=4 ) return;
925 zCmd
= (const char*)sqlite3_value_text(argv
[1]);
926 if( zCmd
==0 ) return;
927 if( strcmp(zCmd
,"text")==0 ){
928 p1
= (const void*)sqlite3_value_text(argv
[0]);
929 #ifndef SQLITE_OMIT_UTF16
930 }else if( strcmp(zCmd
, "text16")==0 ){
931 p1
= (const void*)sqlite3_value_text16(argv
[0]);
933 }else if( strcmp(zCmd
, "blob")==0 ){
934 p1
= (const void*)sqlite3_value_blob(argv
[0]);
938 zCmd
= (const char*)sqlite3_value_text(argv
[2]);
939 if( zCmd
==0 ) return;
940 if( strcmp(zCmd
,"bytes")==0 ){
941 sqlite3_value_bytes(argv
[0]);
942 #ifndef SQLITE_OMIT_UTF16
943 }else if( strcmp(zCmd
, "bytes16")==0 ){
944 sqlite3_value_bytes16(argv
[0]);
946 }else if( strcmp(zCmd
, "noop")==0 ){
951 zCmd
= (const char*)sqlite3_value_text(argv
[3]);
952 if( zCmd
==0 ) return;
953 if( strcmp(zCmd
,"text")==0 ){
954 p2
= (const void*)sqlite3_value_text(argv
[0]);
955 #ifndef SQLITE_OMIT_UTF16
956 }else if( strcmp(zCmd
, "text16")==0 ){
957 p2
= (const void*)sqlite3_value_text16(argv
[0]);
959 }else if( strcmp(zCmd
, "blob")==0 ){
960 p2
= (const void*)sqlite3_value_blob(argv
[0]);
964 sqlite3_result_int(context
, p1
!=p2
);
968 ** This SQL function returns a different answer each time it is called, even if
969 ** the arguments are the same.
971 static void nondeterministicFunction(
972 sqlite3_context
*context
,
977 sqlite3_result_int(context
, cnt
++);
981 ** This SQL function returns the integer value of its argument as a MEM_IntReal
984 static void intrealFunction(
985 sqlite3_context
*context
,
989 sqlite3_int64 v
= sqlite3_value_int64(argv
[0]);
990 sqlite3_result_int64(context
, v
);
991 sqlite3_test_control(SQLITE_TESTCTRL_RESULT_INTREAL
, context
);
995 ** These SQL functions attempt to return a value (their first argument)
996 ** that has been modified to have multiple datatypes. For example both
999 static void addTextTypeFunction(
1000 sqlite3_context
*context
,
1002 sqlite3_value
**argv
1004 (void)sqlite3_value_text(argv
[0]);
1006 sqlite3_result_value(context
, argv
[0]);
1008 static void addIntTypeFunction(
1009 sqlite3_context
*context
,
1011 sqlite3_value
**argv
1013 (void)sqlite3_value_int64(argv
[0]);
1015 sqlite3_result_value(context
, argv
[0]);
1017 static void addRealTypeFunction(
1018 sqlite3_context
*context
,
1020 sqlite3_value
**argv
1022 (void)sqlite3_value_double(argv
[0]);
1024 sqlite3_result_value(context
, argv
[0]);
1028 ** SQL function: strtod(X)
1030 ** Use the C-library strtod() function to convert string X into a double.
1031 ** Used for comparing the accuracy of SQLite's internal text-to-float conversion
1032 ** routines against the C-library.
1034 static void shellStrtod(
1035 sqlite3_context
*pCtx
,
1037 sqlite3_value
**apVal
1039 char *z
= (char*)sqlite3_value_text(apVal
[0]);
1040 UNUSED_PARAMETER(nVal
);
1042 sqlite3_result_double(pCtx
, strtod(z
,0));
1046 ** SQL function: dtostr(X)
1048 ** Use the C-library printf() function to convert real value X into a string.
1049 ** Used for comparing the accuracy of SQLite's internal float-to-text conversion
1050 ** routines against the C-library.
1052 static void shellDtostr(
1053 sqlite3_context
*pCtx
,
1055 sqlite3_value
**apVal
1057 double r
= sqlite3_value_double(apVal
[0]);
1058 int n
= nVal
>=2 ? sqlite3_value_int(apVal
[1]) : 26;
1061 if( n
>350 ) n
= 350;
1062 sprintf(z
, "%#+.*e", n
, r
);
1063 sqlite3_result_text(pCtx
, z
, -1, SQLITE_TRANSIENT
);
1068 ** Usage: sqlite3_create_function DB
1070 ** Call the sqlite3_create_function API on the given database in order
1071 ** to create a function named "x_coalesce". This function does the same thing
1072 ** as the "coalesce" function. This function also registers an SQL function
1073 ** named "x_sqlite_exec" that invokes sqlite3_exec(). Invoking sqlite3_exec()
1074 ** in this way is illegal recursion and should raise an SQLITE_MISUSE error.
1075 ** The effect is similar to trying to use the same database connection from
1076 ** two threads at the same time.
1078 ** The original motivation for this routine was to be able to call the
1079 ** sqlite3_create_function function while a query is in progress in order
1080 ** to test the SQLITE_MISUSE detection logic.
1082 static int SQLITE_TCLAPI
test_create_function(
1084 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1085 int argc
, /* Number of arguments */
1086 char **argv
/* Text of each argument */
1092 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1096 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1097 rc
= sqlite3_create_function(db
, "x_coalesce", -1, SQLITE_UTF8
, 0,
1098 t1_ifnullFunc
, 0, 0);
1099 if( rc
==SQLITE_OK
){
1100 rc
= sqlite3_create_function(db
, "hex8", 1, SQLITE_UTF8
| SQLITE_DETERMINISTIC
,
1103 #ifndef SQLITE_OMIT_UTF16
1104 if( rc
==SQLITE_OK
){
1105 rc
= sqlite3_create_function(db
, "hex16", 1, SQLITE_UTF16
| SQLITE_DETERMINISTIC
,
1106 0, hex16Func
, 0, 0);
1109 if( rc
==SQLITE_OK
){
1110 rc
= sqlite3_create_function(db
, "tkt2213func", 1, SQLITE_ANY
, 0,
1111 tkt2213Function
, 0, 0);
1113 if( rc
==SQLITE_OK
){
1114 rc
= sqlite3_create_function(db
, "pointer_change", 4, SQLITE_ANY
, 0,
1115 ptrChngFunction
, 0, 0);
1118 /* Functions counter1() and counter2() have the same implementation - they
1119 ** both return an ascending integer with each call. But counter1() is marked
1120 ** as non-deterministic and counter2() is marked as deterministic.
1122 if( rc
==SQLITE_OK
){
1123 rc
= sqlite3_create_function(db
, "counter1", -1, SQLITE_UTF8
,
1124 0, nondeterministicFunction
, 0, 0);
1126 if( rc
==SQLITE_OK
){
1127 rc
= sqlite3_create_function(db
, "counter2", -1, SQLITE_UTF8
|SQLITE_DETERMINISTIC
,
1128 0, nondeterministicFunction
, 0, 0);
1131 /* The intreal() function converts its argument to an integer and returns
1132 ** it as a MEM_IntReal.
1134 if( rc
==SQLITE_OK
){
1135 rc
= sqlite3_create_function(db
, "intreal", 1, SQLITE_UTF8
,
1136 0, intrealFunction
, 0, 0);
1139 /* The add_text_type(), add_int_type(), and add_real_type() functions
1140 ** attempt to return a value that has multiple datatypes.
1142 if( rc
==SQLITE_OK
){
1143 rc
= sqlite3_create_function(db
, "add_text_type", 1, SQLITE_UTF8
,
1144 0, addTextTypeFunction
, 0, 0);
1146 if( rc
==SQLITE_OK
){
1147 rc
= sqlite3_create_function(db
, "add_int_type", 1, SQLITE_UTF8
,
1148 0, addIntTypeFunction
, 0, 0);
1150 if( rc
==SQLITE_OK
){
1151 rc
= sqlite3_create_function(db
, "add_real_type", 1, SQLITE_UTF8
,
1152 0, addRealTypeFunction
, 0, 0);
1155 /* Functions strtod() and dtostr() work as in the shell. These routines
1156 ** use the standard C library to convert between floating point and
1157 ** text. This is used to compare SQLite's internal conversion routines
1158 ** against the standard library conversion routines.
1160 ** Both routines copy/pasted from the shell.c.in implementation
1163 if( rc
==SQLITE_OK
){
1164 rc
= sqlite3_create_function(db
, "strtod", 1, SQLITE_UTF8
, 0,
1167 if( rc
==SQLITE_OK
){
1168 rc
= sqlite3_create_function(db
, "dtostr", 1, SQLITE_UTF8
, 0,
1171 if( rc
==SQLITE_OK
){
1172 rc
= sqlite3_create_function(db
, "dtostr", 2, SQLITE_UTF8
, 0,
1176 #ifndef SQLITE_OMIT_UTF16
1177 /* Use the sqlite3_create_function16() API here. Mainly for fun, but also
1178 ** because it is not tested anywhere else. */
1179 if( rc
==SQLITE_OK
){
1181 sqlite3_value
*pVal
;
1182 sqlite3_mutex_enter(db
->mutex
);
1183 pVal
= sqlite3ValueNew(db
);
1184 sqlite3ValueSetStr(pVal
, -1, "x_sqlite_exec", SQLITE_UTF8
, SQLITE_STATIC
);
1185 zUtf16
= sqlite3ValueText(pVal
, SQLITE_UTF16NATIVE
);
1186 if( db
->mallocFailed
){
1189 rc
= sqlite3_create_function16(db
, zUtf16
,
1190 1, SQLITE_UTF16
, db
, sqlite3ExecFunc
, 0, 0);
1192 sqlite3ValueFree(pVal
);
1193 sqlite3_mutex_leave(db
->mutex
);
1197 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
1198 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
1203 ** Usage: sqlite3_drop_modules DB ?NAME ...?
1205 ** Invoke the sqlite3_drop_modules(D,L) interface on database
1206 ** connection DB, in order to drop all modules except those named in
1209 static int SQLITE_TCLAPI
test_drop_modules(
1211 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1212 int argc
, /* Number of arguments */
1213 char **argv
/* Text of each argument */
1218 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1222 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1223 #ifndef SQLITE_OMIT_VIRTUALTABLE
1224 sqlite3_drop_modules(db
, argc
>2 ? (const char**)(argv
+2) : 0);
1230 ** Routines to implement the x_count() aggregate function.
1232 ** x_count() counts the number of non-null arguments. But there are
1233 ** some twists for testing purposes.
1235 ** If the argument to x_count() is 40 then a UTF-8 error is reported
1236 ** on the step function. If x_count(41) is seen, then a UTF-16 error
1237 ** is reported on the step function. If the total count is 42, then
1238 ** a UTF-8 error is reported on the finalize function.
1240 typedef struct t1CountCtx t1CountCtx
;
1244 static void t1CountStep(
1245 sqlite3_context
*context
,
1247 sqlite3_value
**argv
1250 p
= sqlite3_aggregate_context(context
, sizeof(*p
));
1251 if( (argc
==0 || SQLITE_NULL
!=sqlite3_value_type(argv
[0]) ) && p
){
1255 int v
= sqlite3_value_int(argv
[0]);
1257 sqlite3_result_error(context
, "value of 40 handed to x_count", -1);
1258 #ifndef SQLITE_OMIT_UTF16
1260 const char zUtf16ErrMsg
[] = { 0, 0x61, 0, 0x62, 0, 0x63, 0, 0, 0};
1261 sqlite3_result_error16(context
, &zUtf16ErrMsg
[1-SQLITE_BIGENDIAN
], -1);
1266 static void t1CountFinalize(sqlite3_context
*context
){
1268 p
= sqlite3_aggregate_context(context
, sizeof(*p
));
1271 sqlite3_result_error(context
, "x_count totals to 42", -1);
1273 sqlite3_result_int(context
, p
? p
->n
: 0);
1278 #ifndef SQLITE_OMIT_DEPRECATED
1279 static void legacyCountStep(
1280 sqlite3_context
*context
,
1282 sqlite3_value
**argv
1287 static void legacyCountFinalize(sqlite3_context
*context
){
1288 sqlite3_result_int(context
, sqlite3_aggregate_count(context
));
1293 ** Usage: sqlite3_create_aggregate DB
1295 ** Call the sqlite3_create_function API on the given database in order
1296 ** to create a function named "x_count". This function is similar
1297 ** to the built-in count() function, with a few special quirks
1298 ** for testing the sqlite3_result_error() APIs.
1300 ** The original motivation for this routine was to be able to call the
1301 ** sqlite3_create_aggregate function while a query is in progress in order
1302 ** to test the SQLITE_MISUSE detection logic. See misuse.test.
1304 ** This routine was later extended to test the use of sqlite3_result_error()
1305 ** within aggregate functions.
1307 ** Later: It is now also extended to register the aggregate function
1308 ** "legacy_count()" with the supplied database handle. This is used
1309 ** to test the deprecated sqlite3_aggregate_count() API.
1311 static int SQLITE_TCLAPI
test_create_aggregate(
1313 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1314 int argc
, /* Number of arguments */
1315 char **argv
/* Text of each argument */
1320 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1324 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
1325 rc
= sqlite3_create_function(db
, "x_count", 0, SQLITE_UTF8
, 0, 0,
1326 t1CountStep
,t1CountFinalize
);
1327 if( rc
==SQLITE_OK
){
1328 rc
= sqlite3_create_function(db
, "x_count", 1, SQLITE_UTF8
, 0, 0,
1329 t1CountStep
,t1CountFinalize
);
1331 #ifndef SQLITE_OMIT_DEPRECATED
1332 if( rc
==SQLITE_OK
){
1333 rc
= sqlite3_create_function(db
, "legacy_count", 0, SQLITE_ANY
, 0, 0,
1334 legacyCountStep
, legacyCountFinalize
1338 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
1339 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
1345 ** Usage: printf TEXT
1347 ** Send output to printf. Use this rather than puts to merge the output
1348 ** in the correct sequence with debugging printfs inserted into C code.
1349 ** Puts uses a separate buffer and debugging statements will be out of
1350 ** sequence if it is used.
1352 static int SQLITE_TCLAPI
test_printf(
1354 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1355 int argc
, /* Number of arguments */
1356 char **argv
/* Text of each argument */
1359 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1363 printf("%s\n", argv
[1]);
1370 ** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER
1372 ** Call mprintf with three integer arguments
1374 static int SQLITE_TCLAPI
sqlite3_mprintf_int(
1376 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1377 int argc
, /* Number of arguments */
1378 char **argv
/* Text of each argument */
1383 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1384 " FORMAT INT INT INT\"", 0);
1388 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1390 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1391 Tcl_AppendResult(interp
, z
, 0);
1397 ** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER
1399 ** Call mprintf with three 64-bit integer arguments
1401 static int SQLITE_TCLAPI
sqlite3_mprintf_int64(
1403 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1404 int argc
, /* Number of arguments */
1405 char **argv
/* Text of each argument */
1411 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1412 " FORMAT INT INT INT\"", 0);
1416 if( sqlite3Atoi64(argv
[i
], &a
[i
-2], sqlite3Strlen30(argv
[i
]), SQLITE_UTF8
) ){
1417 Tcl_AppendResult(interp
, "argument is not a valid 64-bit integer", 0);
1421 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1422 Tcl_AppendResult(interp
, z
, 0);
1428 ** Usage: sqlite3_mprintf_long FORMAT INTEGER INTEGER INTEGER
1430 ** Call mprintf with three long integer arguments. This might be the
1431 ** same as sqlite3_mprintf_int or sqlite3_mprintf_int64, depending on
1434 static int SQLITE_TCLAPI
sqlite3_mprintf_long(
1436 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1437 int argc
, /* Number of arguments */
1438 char **argv
/* Text of each argument */
1445 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1446 " FORMAT INT INT INT\"", 0);
1450 if( Tcl_GetInt(interp
, argv
[i
], &b
[i
-2]) ) return TCL_ERROR
;
1451 a
[i
-2] = (long int)b
[i
-2];
1452 a
[i
-2] &= (((u64
)1)<<(sizeof(int)*8))-1;
1454 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], a
[2]);
1455 Tcl_AppendResult(interp
, z
, 0);
1461 ** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING
1463 ** Call mprintf with two integer arguments and one string argument
1465 static int SQLITE_TCLAPI
sqlite3_mprintf_str(
1467 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1468 int argc
, /* Number of arguments */
1469 char **argv
/* Text of each argument */
1473 if( argc
<4 || argc
>5 ){
1474 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1475 " FORMAT INT INT ?STRING?\"", 0);
1479 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1481 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], argc
>4 ? argv
[4] : NULL
);
1482 Tcl_AppendResult(interp
, z
, 0);
1488 ** Usage: sqlite3_snprintf_str INTEGER FORMAT INTEGER INTEGER STRING
1490 ** Call mprintf with two integer arguments and one string argument
1492 static int SQLITE_TCLAPI
sqlite3_snprintf_str(
1494 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1495 int argc
, /* Number of arguments */
1496 char **argv
/* Text of each argument */
1501 if( argc
<5 || argc
>6 ){
1502 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1503 " INT FORMAT INT INT ?STRING?\"", 0);
1506 if( Tcl_GetInt(interp
, argv
[1], &n
) ) return TCL_ERROR
;
1508 Tcl_AppendResult(interp
, "N must be non-negative", 0);
1512 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-3]) ) return TCL_ERROR
;
1514 z
= sqlite3_malloc( n
+1 );
1515 sqlite3_snprintf(n
, z
, argv
[2], a
[0], a
[1], argc
>4 ? argv
[5] : NULL
);
1516 Tcl_AppendResult(interp
, z
, 0);
1522 ** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE
1524 ** Call mprintf with two integer arguments and one double argument
1526 static int SQLITE_TCLAPI
sqlite3_mprintf_double(
1528 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1529 int argc
, /* Number of arguments */
1530 char **argv
/* Text of each argument */
1536 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1537 " FORMAT INT INT DOUBLE\"", 0);
1541 if( Tcl_GetInt(interp
, argv
[i
], &a
[i
-2]) ) return TCL_ERROR
;
1543 if( Tcl_GetDouble(interp
, argv
[4], &r
) ) return TCL_ERROR
;
1544 z
= sqlite3_mprintf(argv
[1], a
[0], a
[1], r
);
1545 Tcl_AppendResult(interp
, z
, 0);
1551 ** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE
1553 ** Call mprintf with a single double argument which is the product of the
1554 ** two arguments given above. This is used to generate overflow and underflow
1555 ** doubles to test that they are converted properly.
1557 static int SQLITE_TCLAPI
sqlite3_mprintf_scaled(
1559 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1560 int argc
, /* Number of arguments */
1561 char **argv
/* Text of each argument */
1567 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1568 " FORMAT DOUBLE DOUBLE\"", 0);
1572 if( Tcl_GetDouble(interp
, argv
[i
], &r
[i
-2]) ) return TCL_ERROR
;
1574 z
= sqlite3_mprintf(argv
[1], r
[0]*r
[1]);
1575 Tcl_AppendResult(interp
, z
, 0);
1581 ** Usage: sqlite3_mprintf_stronly FORMAT STRING
1583 ** Call mprintf with a single double argument which is the product of the
1584 ** two arguments given above. This is used to generate overflow and underflow
1585 ** doubles to test that they are converted properly.
1587 static int SQLITE_TCLAPI
sqlite3_mprintf_stronly(
1589 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1590 int argc
, /* Number of arguments */
1591 char **argv
/* Text of each argument */
1595 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1596 " FORMAT STRING\"", 0);
1599 z
= sqlite3_mprintf(argv
[1], argv
[2]);
1600 Tcl_AppendResult(interp
, z
, 0);
1606 ** Usage: sqlite3_mprintf_hexdouble FORMAT HEX
1608 ** Call mprintf with a single double argument which is derived from the
1609 ** hexadecimal encoding of an IEEE double.
1611 static int SQLITE_TCLAPI
sqlite3_mprintf_hexdouble(
1613 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1614 int argc
, /* Number of arguments */
1615 char **argv
/* Text of each argument */
1619 unsigned int x1
, x2
;
1622 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
1623 " FORMAT STRING\"", 0);
1626 if( sscanf(argv
[2], "%08x%08x", &x2
, &x1
)!=2 ){
1627 Tcl_AppendResult(interp
, "2nd argument should be 16-characters of hex", 0);
1632 memcpy(&r
, &d
, sizeof(r
));
1633 z
= sqlite3_mprintf(argv
[1], r
);
1634 Tcl_AppendResult(interp
, z
, 0);
1640 ** Usage: sqlite3_enable_shared_cache ?BOOLEAN?
1643 #if !defined(SQLITE_OMIT_SHARED_CACHE)
1644 static int SQLITE_TCLAPI
test_enable_shared(
1645 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1646 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1647 int objc
, /* Number of arguments */
1648 Tcl_Obj
*CONST objv
[] /* Command arguments */
1654 if( objc
!=2 && objc
!=1 ){
1655 Tcl_WrongNumArgs(interp
, 1, objv
, "?BOOLEAN?");
1658 ret
= sqlite3GlobalConfig
.sharedCacheEnabled
;
1661 if( Tcl_GetBooleanFromObj(interp
, objv
[1], &enable
) ){
1664 rc
= sqlite3_enable_shared_cache(enable
);
1665 if( rc
!=SQLITE_OK
){
1666 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(rc
), TCL_STATIC
);
1670 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(ret
));
1678 ** Usage: sqlite3_extended_result_codes DB BOOLEAN
1681 static int SQLITE_TCLAPI
test_extended_result_codes(
1682 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1683 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1684 int objc
, /* Number of arguments */
1685 Tcl_Obj
*CONST objv
[] /* Command arguments */
1691 Tcl_WrongNumArgs(interp
, 1, objv
, "DB BOOLEAN");
1694 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1695 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &enable
) ) return TCL_ERROR
;
1696 sqlite3_extended_result_codes(db
, enable
);
1701 ** Usage: sqlite3_libversion_number
1704 static int SQLITE_TCLAPI
test_libversion_number(
1705 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1706 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1707 int objc
, /* Number of arguments */
1708 Tcl_Obj
*CONST objv
[] /* Command arguments */
1710 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_libversion_number()));
1715 ** Usage: sqlite3_table_column_metadata DB dbname tblname colname
1718 static int SQLITE_TCLAPI
test_table_column_metadata(
1719 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
1720 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1721 int objc
, /* Number of arguments */
1722 Tcl_Obj
*CONST objv
[] /* Command arguments */
1731 const char *zDatatype
;
1732 const char *zCollseq
;
1737 if( objc
!=5 && objc
!=4 ){
1738 Tcl_WrongNumArgs(interp
, 1, objv
, "DB dbname tblname colname");
1741 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1742 zDb
= Tcl_GetString(objv
[2]);
1743 zTbl
= Tcl_GetString(objv
[3]);
1744 zCol
= objc
==5 ? Tcl_GetString(objv
[4]) : 0;
1746 if( strlen(zDb
)==0 ) zDb
= 0;
1748 rc
= sqlite3_table_column_metadata(db
, zDb
, zTbl
, zCol
,
1749 &zDatatype
, &zCollseq
, ¬null
, &primarykey
, &autoincrement
);
1751 if( rc
!=SQLITE_OK
){
1752 Tcl_AppendResult(interp
, sqlite3_errmsg(db
), 0);
1756 pRet
= Tcl_NewObj();
1757 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zDatatype
, -1));
1758 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zCollseq
, -1));
1759 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(notnull
));
1760 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(primarykey
));
1761 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(autoincrement
));
1762 Tcl_SetObjResult(interp
, pRet
);
1767 #ifndef SQLITE_OMIT_INCRBLOB
1769 static int SQLITE_TCLAPI
blobHandleFromObj(
1772 sqlite3_blob
**ppBlob
1777 z
= Tcl_GetStringFromObj(pObj
, &n
);
1782 Tcl_Channel channel
;
1783 ClientData instanceData
;
1785 channel
= Tcl_GetChannel(interp
, z
, ¬Used
);
1786 if( !channel
) return TCL_ERROR
;
1789 Tcl_Seek(channel
, 0, SEEK_SET
);
1791 instanceData
= Tcl_GetChannelInstanceData(channel
);
1792 *ppBlob
= *((sqlite3_blob
**)instanceData
);
1798 static int SQLITE_TCLAPI
test_blob_reopen(
1799 ClientData clientData
, /* Not used */
1800 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1801 int objc
, /* Number of arguments */
1802 Tcl_Obj
*CONST objv
[] /* Command arguments */
1805 sqlite3_blob
*pBlob
;
1809 Tcl_WrongNumArgs(interp
, 1, objv
, "CHANNEL ROWID");
1813 if( blobHandleFromObj(interp
, objv
[1], &pBlob
) ) return TCL_ERROR
;
1814 if( Tcl_GetWideIntFromObj(interp
, objv
[2], &iRowid
) ) return TCL_ERROR
;
1816 rc
= sqlite3_blob_reopen(pBlob
, iRowid
);
1817 if( rc
!=SQLITE_OK
){
1818 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
1821 return (rc
==SQLITE_OK
? TCL_OK
: TCL_ERROR
);
1827 ** Usage: sqlite3_create_collation_v2 DB-HANDLE NAME CMP-PROC DEL-PROC
1829 ** This Tcl proc is used for testing the experimental
1830 ** sqlite3_create_collation_v2() interface.
1832 struct TestCollationX
{
1837 typedef struct TestCollationX TestCollationX
;
1838 static void testCreateCollationDel(void *pCtx
){
1839 TestCollationX
*p
= (TestCollationX
*)pCtx
;
1841 int rc
= Tcl_EvalObjEx(p
->interp
, p
->pDel
, TCL_EVAL_DIRECT
|TCL_EVAL_GLOBAL
);
1843 Tcl_BackgroundError(p
->interp
);
1846 Tcl_DecrRefCount(p
->pCmp
);
1847 Tcl_DecrRefCount(p
->pDel
);
1848 sqlite3_free((void *)p
);
1850 static int testCreateCollationCmp(
1857 TestCollationX
*p
= (TestCollationX
*)pCtx
;
1858 Tcl_Obj
*pScript
= Tcl_DuplicateObj(p
->pCmp
);
1861 Tcl_IncrRefCount(pScript
);
1862 Tcl_ListObjAppendElement(0, pScript
, Tcl_NewStringObj((char *)zLeft
, nLeft
));
1863 Tcl_ListObjAppendElement(0, pScript
, Tcl_NewStringObj((char *)zRight
,nRight
));
1865 if( TCL_OK
!=Tcl_EvalObjEx(p
->interp
, pScript
, TCL_EVAL_DIRECT
|TCL_EVAL_GLOBAL
)
1866 || TCL_OK
!=Tcl_GetIntFromObj(p
->interp
, Tcl_GetObjResult(p
->interp
), &iRes
)
1868 Tcl_BackgroundError(p
->interp
);
1870 Tcl_DecrRefCount(pScript
);
1874 static int SQLITE_TCLAPI
test_create_collation_v2(
1875 ClientData clientData
, /* Not used */
1876 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
1877 int objc
, /* Number of arguments */
1878 Tcl_Obj
*CONST objv
[] /* Command arguments */
1885 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE NAME CMP-PROC DEL-PROC");
1888 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1890 p
= (TestCollationX
*)sqlite3_malloc(sizeof(TestCollationX
));
1894 Tcl_IncrRefCount(p
->pCmp
);
1895 Tcl_IncrRefCount(p
->pDel
);
1897 rc
= sqlite3_create_collation_v2(db
, Tcl_GetString(objv
[2]), 16,
1898 (void *)p
, testCreateCollationCmp
, testCreateCollationDel
1900 if( rc
!=SQLITE_MISUSE
){
1901 Tcl_AppendResult(interp
, "sqlite3_create_collate_v2() failed to detect "
1902 "an invalid encoding", (char*)0);
1905 rc
= sqlite3_create_collation_v2(db
, Tcl_GetString(objv
[2]), SQLITE_UTF8
,
1906 (void *)p
, testCreateCollationCmp
, testCreateCollationDel
1912 ** USAGE: sqlite3_create_function_v2 DB NAME NARG ENC ?SWITCHES?
1914 ** Available switches are:
1921 typedef struct CreateFunctionV2 CreateFunctionV2
;
1922 struct CreateFunctionV2
{
1924 Tcl_Obj
*pFunc
; /* Script for function invocation */
1925 Tcl_Obj
*pStep
; /* Script for agg. step invocation */
1926 Tcl_Obj
*pFinal
; /* Script for agg. finalization invocation */
1927 Tcl_Obj
*pDestroy
; /* Destructor script */
1929 static void cf2Func(sqlite3_context
*ctx
, int nArg
, sqlite3_value
**aArg
){
1931 static void cf2Step(sqlite3_context
*ctx
, int nArg
, sqlite3_value
**aArg
){
1933 static void cf2Final(sqlite3_context
*ctx
){
1935 static void cf2Destroy(void *pUser
){
1936 CreateFunctionV2
*p
= (CreateFunctionV2
*)pUser
;
1938 if( p
->interp
&& p
->pDestroy
){
1939 int rc
= Tcl_EvalObjEx(p
->interp
, p
->pDestroy
, 0);
1940 if( rc
!=TCL_OK
) Tcl_BackgroundError(p
->interp
);
1943 if( p
->pFunc
) Tcl_DecrRefCount(p
->pFunc
);
1944 if( p
->pStep
) Tcl_DecrRefCount(p
->pStep
);
1945 if( p
->pFinal
) Tcl_DecrRefCount(p
->pFinal
);
1946 if( p
->pDestroy
) Tcl_DecrRefCount(p
->pDestroy
);
1949 static int SQLITE_TCLAPI
test_create_function_v2(
1950 ClientData clientData
, /* Not used */
1951 Tcl_Interp
*interp
, /* The invoking TCL interpreter */
1952 int objc
, /* Number of arguments */
1953 Tcl_Obj
*CONST objv
[] /* Command arguments */
1959 CreateFunctionV2
*p
;
1967 {"utf8", SQLITE_UTF8
},
1968 {"utf16", SQLITE_UTF16
},
1969 {"utf16le", SQLITE_UTF16LE
},
1970 {"utf16be", SQLITE_UTF16BE
},
1971 {"any", SQLITE_ANY
},
1976 if( objc
<5 || (objc
%2)==0 ){
1977 Tcl_WrongNumArgs(interp
, 1, objv
, "DB NAME NARG ENC SWITCHES...");
1981 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
1982 zFunc
= Tcl_GetString(objv
[2]);
1983 if( Tcl_GetIntFromObj(interp
, objv
[3], &nArg
) ) return TCL_ERROR
;
1984 if( Tcl_GetIndexFromObjStruct(interp
, objv
[4], aEnc
, sizeof(aEnc
[0]),
1985 "encoding", 0, &enc
)
1989 enc
= aEnc
[enc
].enc
;
1991 p
= sqlite3_malloc(sizeof(CreateFunctionV2
));
1993 memset(p
, 0, sizeof(CreateFunctionV2
));
1996 for(i
=5; i
<objc
; i
+=2){
1998 const char *azSwitch
[] = {"-func", "-step", "-final", "-destroy", 0};
1999 if( Tcl_GetIndexFromObj(interp
, objv
[i
], azSwitch
, "switch", 0, &iSwitch
) ){
2005 case 0: p
->pFunc
= objv
[i
+1]; break;
2006 case 1: p
->pStep
= objv
[i
+1]; break;
2007 case 2: p
->pFinal
= objv
[i
+1]; break;
2008 case 3: p
->pDestroy
= objv
[i
+1]; break;
2011 if( p
->pFunc
) p
->pFunc
= Tcl_DuplicateObj(p
->pFunc
);
2012 if( p
->pStep
) p
->pStep
= Tcl_DuplicateObj(p
->pStep
);
2013 if( p
->pFinal
) p
->pFinal
= Tcl_DuplicateObj(p
->pFinal
);
2014 if( p
->pDestroy
) p
->pDestroy
= Tcl_DuplicateObj(p
->pDestroy
);
2016 if( p
->pFunc
) Tcl_IncrRefCount(p
->pFunc
);
2017 if( p
->pStep
) Tcl_IncrRefCount(p
->pStep
);
2018 if( p
->pFinal
) Tcl_IncrRefCount(p
->pFinal
);
2019 if( p
->pDestroy
) Tcl_IncrRefCount(p
->pDestroy
);
2021 rc
= sqlite3_create_function_v2(db
, zFunc
, nArg
, enc
, (void *)p
,
2022 (p
->pFunc
? cf2Func
: 0),
2023 (p
->pStep
? cf2Step
: 0),
2024 (p
->pFinal
? cf2Final
: 0),
2027 if( rc
!=SQLITE_OK
){
2028 Tcl_ResetResult(interp
);
2029 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
2036 ** Usage: sqlite3_load_extension DB-HANDLE FILE ?PROC?
2038 static int SQLITE_TCLAPI
test_load_extension(
2039 ClientData clientData
, /* Not used */
2040 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2041 int objc
, /* Number of arguments */
2042 Tcl_Obj
*CONST objv
[] /* Command arguments */
2044 Tcl_CmdInfo cmdInfo
;
2052 if( objc
!=4 && objc
!=3 ){
2053 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE FILE ?PROC?");
2056 zDb
= Tcl_GetString(objv
[1]);
2057 zFile
= Tcl_GetString(objv
[2]);
2059 zProc
= Tcl_GetString(objv
[3]);
2062 /* Extract the C database handle from the Tcl command name */
2063 if( !Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
2064 Tcl_AppendResult(interp
, "command not found: ", zDb
, (char*)0);
2067 db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
2070 /* Call the underlying C function. If an error occurs, set rc to
2071 ** TCL_ERROR and load any error string into the interpreter. If no
2072 ** error occurs, set rc to TCL_OK.
2074 #ifdef SQLITE_OMIT_LOAD_EXTENSION
2076 zErr
= sqlite3_mprintf("this build omits sqlite3_load_extension()");
2080 rc
= sqlite3_load_extension(db
, zFile
, zProc
, &zErr
);
2082 if( rc
!=SQLITE_OK
){
2083 Tcl_SetResult(interp
, zErr
? zErr
: "", TCL_VOLATILE
);
2094 ** Usage: sqlite3_enable_load_extension DB-HANDLE ONOFF
2096 static int SQLITE_TCLAPI
test_enable_load(
2097 ClientData clientData
, /* Not used */
2098 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2099 int objc
, /* Number of arguments */
2100 Tcl_Obj
*CONST objv
[] /* Command arguments */
2102 Tcl_CmdInfo cmdInfo
;
2108 Tcl_WrongNumArgs(interp
, 1, objv
, "DB-HANDLE ONOFF");
2111 zDb
= Tcl_GetString(objv
[1]);
2113 /* Extract the C database handle from the Tcl command name */
2114 if( !Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
2115 Tcl_AppendResult(interp
, "command not found: ", zDb
, (char*)0);
2118 db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
2121 /* Get the onoff parameter */
2122 if( Tcl_GetBooleanFromObj(interp
, objv
[2], &onoff
) ){
2126 #ifdef SQLITE_OMIT_LOAD_EXTENSION
2127 Tcl_AppendResult(interp
, "this build omits sqlite3_load_extension()");
2130 sqlite3_enable_load_extension(db
, onoff
);
2136 ** Usage: sqlite_abort
2138 ** Shutdown the process immediately. This is not a clean shutdown.
2139 ** This command is used to test the recoverability of a database in
2140 ** the event of a program crash.
2142 static int SQLITE_TCLAPI
sqlite_abort(
2144 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2145 int argc
, /* Number of arguments */
2146 char **argv
/* Text of each argument */
2148 #if defined(_MSC_VER)
2149 /* We do this, otherwise the test will halt with a popup message
2150 * that we have to click away before the test will continue.
2152 _set_abort_behavior( 0, _CALL_REPORTFAULT
);
2155 assert( interp
==0 ); /* This will always fail */
2160 ** The following routine is a user-defined SQL function whose purpose
2161 ** is to test the sqlite_set_result() API.
2163 static void testFunc(sqlite3_context
*context
, int argc
, sqlite3_value
**argv
){
2165 const char *zArg0
= (char*)sqlite3_value_text(argv
[0]);
2167 if( 0==sqlite3StrICmp(zArg0
, "int") ){
2168 sqlite3_result_int(context
, sqlite3_value_int(argv
[1]));
2169 }else if( sqlite3StrICmp(zArg0
,"int64")==0 ){
2170 sqlite3_result_int64(context
, sqlite3_value_int64(argv
[1]));
2171 }else if( sqlite3StrICmp(zArg0
,"string")==0 ){
2172 sqlite3_result_text(context
, (char*)sqlite3_value_text(argv
[1]), -1,
2174 }else if( sqlite3StrICmp(zArg0
,"double")==0 ){
2175 sqlite3_result_double(context
, sqlite3_value_double(argv
[1]));
2176 }else if( sqlite3StrICmp(zArg0
,"null")==0 ){
2177 sqlite3_result_null(context
);
2178 }else if( sqlite3StrICmp(zArg0
,"value")==0 ){
2179 sqlite3_result_value(context
, argv
[sqlite3_value_int(argv
[1])]);
2192 sqlite3_result_error(context
,"first argument should be one of: "
2193 "int int64 string double null value", -1);
2197 ** Usage: sqlite_register_test_function DB NAME
2199 ** Register the test SQL function on the database DB under the name NAME.
2201 static int SQLITE_TCLAPI
test_register_func(
2203 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
2204 int argc
, /* Number of arguments */
2205 char **argv
/* Text of each argument */
2210 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
2211 " DB FUNCTION-NAME", 0);
2214 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
2215 rc
= sqlite3_create_function(db
, argv
[2], -1, SQLITE_UTF8
, 0,
2218 Tcl_AppendResult(interp
, sqlite3ErrStr(rc
), 0);
2221 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
2226 ** Usage: sqlite3_finalize STMT
2228 ** Finalize a statement handle.
2230 static int SQLITE_TCLAPI
test_finalize(
2234 Tcl_Obj
*CONST objv
[]
2236 sqlite3_stmt
*pStmt
;
2241 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2242 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
2246 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2249 db
= StmtToDb(pStmt
);
2251 rc
= sqlite3_finalize(pStmt
);
2252 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
2253 if( db
&& sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
2258 ** Usage: sqlite3_stmt_status STMT CODE RESETFLAG
2260 ** Get the value of a status counter from a statement.
2262 static int SQLITE_TCLAPI
test_stmt_status(
2266 Tcl_Obj
*CONST objv
[]
2269 int i
, op
= 0, resetFlag
;
2270 const char *zOpName
;
2271 sqlite3_stmt
*pStmt
;
2273 static const struct {
2277 { "SQLITE_STMTSTATUS_FULLSCAN_STEP", SQLITE_STMTSTATUS_FULLSCAN_STEP
},
2278 { "SQLITE_STMTSTATUS_SORT", SQLITE_STMTSTATUS_SORT
},
2279 { "SQLITE_STMTSTATUS_AUTOINDEX", SQLITE_STMTSTATUS_AUTOINDEX
},
2280 { "SQLITE_STMTSTATUS_VM_STEP", SQLITE_STMTSTATUS_VM_STEP
},
2281 { "SQLITE_STMTSTATUS_REPREPARE", SQLITE_STMTSTATUS_REPREPARE
},
2282 { "SQLITE_STMTSTATUS_RUN", SQLITE_STMTSTATUS_RUN
},
2283 { "SQLITE_STMTSTATUS_MEMUSED", SQLITE_STMTSTATUS_MEMUSED
},
2286 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT PARAMETER RESETFLAG");
2289 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2290 zOpName
= Tcl_GetString(objv
[2]);
2291 for(i
=0; i
<ArraySize(aOp
); i
++){
2292 if( strcmp(aOp
[i
].zName
, zOpName
)==0 ){
2297 if( i
>=ArraySize(aOp
) ){
2298 if( Tcl_GetIntFromObj(interp
, objv
[2], &op
) ) return TCL_ERROR
;
2300 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &resetFlag
) ) return TCL_ERROR
;
2301 iValue
= sqlite3_stmt_status(pStmt
, op
, resetFlag
);
2302 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iValue
));
2306 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
2308 ** Usage: sqlite3_stmt_scanstatus ?-flags FLAGS? STMT IDX
2310 static int SQLITE_TCLAPI
test_stmt_scanstatus(
2314 Tcl_Obj
*CONST objv
[]
2316 sqlite3_stmt
*pStmt
; /* First argument */
2317 int idx
; /* Second argument */
2320 const char *zExplain
;
2321 sqlite3_int64 nLoop
;
2322 sqlite3_int64 nVisit
;
2323 sqlite3_int64 nCycle
;
2336 {"complex", SQLITE_SCANSTAT_COMPLEX
},
2341 Tcl_Obj
**aFlag
= 0;
2345 if( Tcl_ListObjGetElements(interp
, objv
[2], &nFlag
, &aFlag
) ){
2348 for(ii
=0; ii
<nFlag
; ii
++){
2350 int res
= Tcl_GetIndexFromObjStruct(
2351 interp
, aFlag
[ii
], aTbl
, sizeof(aTbl
[0]), "flag", 0, &iVal
2353 if( res
) return TCL_ERROR
;
2354 if( aTbl
[iVal
].flag
==-1 ){
2357 flags
|= aTbl
[iVal
].flag
;
2362 if( objc
!=3 && objc
!=5 ){
2363 Tcl_WrongNumArgs(interp
, 1, objv
, "-flags FLAGS STMT IDX");
2366 if( getStmtPointer(interp
, Tcl_GetString(objv
[objc
-2]), &pStmt
)
2367 || Tcl_GetIntFromObj(interp
, objv
[objc
-1], &idx
)
2372 if( bDebug
&& 0==(flags
& SQLITE_SCANSTAT_COMPLEX
) ){
2373 Tcl_SetObjResult(interp
,
2374 Tcl_NewStringObj("may not specify debug without complex", -1)
2380 Tcl_Obj
*pRet
= Tcl_NewObj();
2381 res
= sqlite3_stmt_scanstatus_v2(
2382 pStmt
, -1, SQLITE_SCANSTAT_NCYCLE
, flags
, (void*)&nCycle
2384 sqlite3_stmt_scanstatus_v2(
2385 pStmt
, idx
, SQLITE_SCANSTAT_NCYCLE
, flags
, (void*)&nCycle
);
2386 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nCycle", -1));
2387 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nCycle
));
2388 Tcl_SetObjResult(interp
, pRet
);
2390 res
= sqlite3_stmt_scanstatus_v2(
2391 pStmt
, idx
, SQLITE_SCANSTAT_NLOOP
, flags
, (void*)&nLoop
2394 Tcl_Obj
*pRet
= Tcl_NewObj();
2395 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nLoop", -1));
2396 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nLoop
));
2397 sqlite3_stmt_scanstatus_v2(
2398 pStmt
, idx
, SQLITE_SCANSTAT_NVISIT
, flags
, (void*)&nVisit
);
2399 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nVisit", -1));
2400 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nVisit
));
2401 sqlite3_stmt_scanstatus_v2(
2402 pStmt
, idx
, SQLITE_SCANSTAT_EST
, flags
, (void*)&rEst
);
2403 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nEst", -1));
2404 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewDoubleObj(rEst
));
2405 sqlite3_stmt_scanstatus_v2(
2406 pStmt
, idx
, SQLITE_SCANSTAT_NAME
, flags
, (void*)&zName
);
2407 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("zName", -1));
2408 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zName
, -1));
2409 sqlite3_stmt_scanstatus_v2(
2410 pStmt
, idx
, SQLITE_SCANSTAT_EXPLAIN
, flags
, (void*)&zExplain
);
2411 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("zExplain", -1));
2412 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj(zExplain
, -1));
2413 sqlite3_stmt_scanstatus_v2(
2414 pStmt
, idx
, SQLITE_SCANSTAT_SELECTID
, flags
, (void*)&iSelectId
);
2415 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("iSelectId", -1));
2416 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(iSelectId
));
2417 sqlite3_stmt_scanstatus_v2(
2418 pStmt
, idx
, SQLITE_SCANSTAT_PARENTID
, flags
, (void*)&iParentId
);
2419 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("iParentId", -1));
2420 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(iParentId
));
2421 sqlite3_stmt_scanstatus_v2(
2422 pStmt
, idx
, SQLITE_SCANSTAT_NCYCLE
, flags
, (void*)&nCycle
);
2423 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("nCycle", -1));
2424 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewWideIntObj(nCycle
));
2428 ScanStatus
*pScan
= &((Vdbe
*)pStmt
)->aScan
[idx
];
2429 Tcl_Obj
*pRange
= Tcl_NewObj();
2430 Tcl_Obj
*pCsr
= Tcl_NewObj();
2432 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("debug_loop", -1));
2433 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(pScan
->addrLoop
));
2434 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("debug_visit", -1));
2435 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(pScan
->addrVisit
));
2436 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("debug_explain",-1));
2437 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewIntObj(pScan
->addrExplain
));
2438 for(ii
=0; ii
<ArraySize(pScan
->aAddrRange
)/2; ii
++){
2439 int iStart
= pScan
->aAddrRange
[ii
*2];
2440 int iEnd
= pScan
->aAddrRange
[ii
*2+1];
2442 Tcl_ListObjAppendElement(0, pRange
, Tcl_NewIntObj(iStart
));
2443 Tcl_ListObjAppendElement(0, pRange
, Tcl_NewIntObj(iEnd
));
2444 }else if( iStart
<0 ){
2445 Tcl_ListObjAppendElement(0, pCsr
, Tcl_NewIntObj(iEnd
));
2449 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("debug_range", -1));
2450 Tcl_ListObjAppendElement(0, pRet
, pRange
);
2451 Tcl_ListObjAppendElement(0, pRet
, Tcl_NewStringObj("debug_csr", -1));
2452 Tcl_ListObjAppendElement(0, pRet
, pCsr
);
2455 Tcl_SetObjResult(interp
, pRet
);
2457 Tcl_ResetResult(interp
);
2464 ** Usage: sqlite3_stmt_scanstatus_reset STMT
2466 static int SQLITE_TCLAPI
test_stmt_scanstatus_reset(
2470 Tcl_Obj
*CONST objv
[]
2472 sqlite3_stmt
*pStmt
; /* First argument */
2474 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
2477 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2478 sqlite3_stmt_scanstatus_reset(pStmt
);
2483 #ifdef SQLITE_ENABLE_SQLLOG
2485 ** Usage: sqlite3_config_sqllog
2487 ** Zero the SQLITE_CONFIG_SQLLOG configuration
2489 static int SQLITE_TCLAPI
test_config_sqllog(
2493 Tcl_Obj
*CONST objv
[]
2496 Tcl_WrongNumArgs(interp
, 1, objv
, "");
2499 sqlite3_config(SQLITE_CONFIG_SQLLOG
, 0, 0);
2505 ** Usage: sqlite3_config_sorterref
2507 ** Set the SQLITE_CONFIG_SORTERREF_SIZE configuration option
2509 static int SQLITE_TCLAPI
test_config_sorterref(
2513 Tcl_Obj
*CONST objv
[]
2517 Tcl_WrongNumArgs(interp
, 1, objv
, "NBYTE");
2520 if( Tcl_GetIntFromObj(interp
, objv
[1], &iVal
) ) return TCL_ERROR
;
2521 sqlite3_config(SQLITE_CONFIG_SORTERREF_SIZE
, iVal
);
2526 ** Usage: vfs_current_time_int64
2528 ** Return the value returned by the default VFS's xCurrentTimeInt64 method.
2530 static int SQLITE_TCLAPI
vfsCurrentTimeInt64(
2534 Tcl_Obj
*CONST objv
[]
2537 sqlite3_vfs
*pVfs
= sqlite3_vfs_find(0);
2539 Tcl_WrongNumArgs(interp
, 1, objv
, "");
2542 pVfs
->xCurrentTimeInt64(pVfs
, &t
);
2543 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(t
));
2547 #ifndef SQLITE_OMIT_VIRTUALTABLE
2549 ** Usage: create_null_module DB NAME
2551 static int SQLITE_TCLAPI
test_create_null_module(
2555 Tcl_Obj
*CONST objv
[]
2561 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2564 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2565 zName
= Tcl_GetString(objv
[2]);
2567 sqlite3_create_module(db
, zName
, 0, 0);
2570 #endif /* SQLITE_OMIT_VIRTUALTABLE */
2572 #ifdef SQLITE_ENABLE_SNAPSHOT
2574 ** Usage: sqlite3_snapshot_get DB DBNAME
2576 static int SQLITE_TCLAPI
test_snapshot_get(
2580 Tcl_Obj
*CONST objv
[]
2585 sqlite3_snapshot
*pSnapshot
= 0;
2588 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2591 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2592 zName
= Tcl_GetString(objv
[2]);
2594 rc
= sqlite3_snapshot_get(db
, zName
, &pSnapshot
);
2595 if( rc
!=SQLITE_OK
){
2596 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2600 if( sqlite3TestMakePointerStr(interp
, zBuf
, pSnapshot
) ) return TCL_ERROR
;
2601 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zBuf
, -1));
2605 #endif /* SQLITE_ENABLE_SNAPSHOT */
2607 #ifdef SQLITE_ENABLE_SNAPSHOT
2609 ** Usage: sqlite3_snapshot_recover DB DBNAME
2611 static int SQLITE_TCLAPI
test_snapshot_recover(
2615 Tcl_Obj
*CONST objv
[]
2622 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2625 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2626 zName
= Tcl_GetString(objv
[2]);
2628 rc
= sqlite3_snapshot_recover(db
, zName
);
2629 if( rc
!=SQLITE_OK
){
2630 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2633 Tcl_ResetResult(interp
);
2637 #endif /* SQLITE_ENABLE_SNAPSHOT */
2639 #ifdef SQLITE_ENABLE_SNAPSHOT
2641 ** Usage: sqlite3_snapshot_open DB DBNAME SNAPSHOT
2643 static int SQLITE_TCLAPI
test_snapshot_open(
2647 Tcl_Obj
*CONST objv
[]
2652 sqlite3_snapshot
*pSnapshot
;
2655 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SNAPSHOT");
2658 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2659 zName
= Tcl_GetString(objv
[2]);
2660 pSnapshot
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[3]));
2662 rc
= sqlite3_snapshot_open(db
, zName
, pSnapshot
);
2663 if( rc
!=SQLITE_OK
){
2664 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2667 Tcl_ResetResult(interp
);
2671 #endif /* SQLITE_ENABLE_SNAPSHOT */
2673 #ifdef SQLITE_ENABLE_SNAPSHOT
2675 ** Usage: sqlite3_snapshot_free SNAPSHOT
2677 static int SQLITE_TCLAPI
test_snapshot_free(
2681 Tcl_Obj
*CONST objv
[]
2683 sqlite3_snapshot
*pSnapshot
;
2685 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT");
2688 pSnapshot
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[1]));
2689 sqlite3_snapshot_free(pSnapshot
);
2692 #endif /* SQLITE_ENABLE_SNAPSHOT */
2694 #ifdef SQLITE_ENABLE_SNAPSHOT
2696 ** Usage: sqlite3_snapshot_cmp SNAPSHOT1 SNAPSHOT2
2698 static int SQLITE_TCLAPI
test_snapshot_cmp(
2702 Tcl_Obj
*CONST objv
[]
2705 sqlite3_snapshot
*p1
;
2706 sqlite3_snapshot
*p2
;
2708 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT1 SNAPSHOT2");
2711 p1
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[1]));
2712 p2
= (sqlite3_snapshot
*)sqlite3TestTextToPtr(Tcl_GetString(objv
[2]));
2713 res
= sqlite3_snapshot_cmp(p1
, p2
);
2714 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
2717 #endif /* SQLITE_ENABLE_SNAPSHOT */
2719 #ifdef SQLITE_ENABLE_SNAPSHOT
2721 ** Usage: sqlite3_snapshot_get_blob DB DBNAME
2723 static int SQLITE_TCLAPI
test_snapshot_get_blob(
2727 Tcl_Obj
*CONST objv
[]
2732 sqlite3_snapshot
*pSnapshot
= 0;
2735 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
2738 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2739 zName
= Tcl_GetString(objv
[2]);
2741 rc
= sqlite3_snapshot_get(db
, zName
, &pSnapshot
);
2742 if( rc
!=SQLITE_OK
){
2743 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2746 Tcl_SetObjResult(interp
,
2747 Tcl_NewByteArrayObj((unsigned char*)pSnapshot
, sizeof(sqlite3_snapshot
))
2749 sqlite3_snapshot_free(pSnapshot
);
2753 #endif /* SQLITE_ENABLE_SNAPSHOT */
2755 #ifdef SQLITE_ENABLE_SNAPSHOT
2757 ** Usage: sqlite3_snapshot_open_blob DB DBNAME SNAPSHOT
2759 static int SQLITE_TCLAPI
test_snapshot_open_blob(
2763 Tcl_Obj
*CONST objv
[]
2768 unsigned char *pBlob
;
2772 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SNAPSHOT");
2775 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2776 zName
= Tcl_GetString(objv
[2]);
2777 pBlob
= Tcl_GetByteArrayFromObj(objv
[3], &nBlob
);
2778 if( nBlob
!=sizeof(sqlite3_snapshot
) ){
2779 Tcl_AppendResult(interp
, "bad SNAPSHOT", 0);
2782 rc
= sqlite3_snapshot_open(db
, zName
, (sqlite3_snapshot
*)pBlob
);
2783 if( rc
!=SQLITE_OK
){
2784 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2789 #endif /* SQLITE_ENABLE_SNAPSHOT */
2791 #ifdef SQLITE_ENABLE_SNAPSHOT
2793 ** Usage: sqlite3_snapshot_cmp_blob SNAPSHOT1 SNAPSHOT2
2795 static int SQLITE_TCLAPI
test_snapshot_cmp_blob(
2799 Tcl_Obj
*CONST objv
[]
2808 Tcl_WrongNumArgs(interp
, 1, objv
, "SNAPSHOT1 SNAPSHOT2");
2812 p1
= Tcl_GetByteArrayFromObj(objv
[1], &n1
);
2813 p2
= Tcl_GetByteArrayFromObj(objv
[2], &n2
);
2815 if( n1
!=sizeof(sqlite3_snapshot
) || n1
!=n2
){
2816 Tcl_AppendResult(interp
, "bad SNAPSHOT", 0);
2820 res
= sqlite3_snapshot_cmp((sqlite3_snapshot
*)p1
, (sqlite3_snapshot
*)p2
);
2821 Tcl_SetObjResult(interp
, Tcl_NewIntObj(res
));
2824 #endif /* SQLITE_ENABLE_SNAPSHOT */
2827 ** Usage: sqlite3_delete_database FILENAME
2829 int sqlite3_delete_database(const char*); /* in test_delete.c */
2830 static int SQLITE_TCLAPI
test_delete_database(
2834 Tcl_Obj
*CONST objv
[]
2839 Tcl_WrongNumArgs(interp
, 1, objv
, "FILE");
2842 zFile
= (const char*)Tcl_GetString(objv
[1]);
2843 rc
= sqlite3_delete_database(zFile
);
2845 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
2850 ** Usage: atomic_batch_write PATH
2852 static int SQLITE_TCLAPI
test_atomic_batch_write(
2856 Tcl_Obj
*CONST objv
[]
2858 char *zFile
= 0; /* Path to file to test */
2859 sqlite3
*db
= 0; /* Database handle */
2860 sqlite3_file
*pFd
= 0; /* SQLite fd open on zFile */
2861 int bRes
= 0; /* Integer result of this command */
2862 int dc
= 0; /* Device-characteristics mask */
2863 int rc
; /* sqlite3_open() return code */
2866 Tcl_WrongNumArgs(interp
, 1, objv
, "PATH");
2869 zFile
= Tcl_GetString(objv
[1]);
2871 rc
= sqlite3_open(zFile
, &db
);
2872 if( rc
!=SQLITE_OK
){
2873 Tcl_AppendResult(interp
, sqlite3_errmsg(db
), 0);
2878 rc
= sqlite3_file_control(db
, "main", SQLITE_FCNTL_FILE_POINTER
, (void*)&pFd
);
2879 dc
= pFd
->pMethods
->xDeviceCharacteristics(pFd
);
2880 if( dc
& SQLITE_IOCAP_BATCH_ATOMIC
){
2884 Tcl_SetObjResult(interp
, Tcl_NewIntObj(bRes
));
2890 ** Usage: sqlite3_next_stmt DB STMT
2892 ** Return the next statement in sequence after STMT.
2894 static int SQLITE_TCLAPI
test_next_stmt(
2898 Tcl_Obj
*CONST objv
[]
2900 sqlite3_stmt
*pStmt
;
2905 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2906 Tcl_GetStringFromObj(objv
[0], 0), " DB STMT", 0);
2910 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
2911 if( getStmtPointer(interp
, Tcl_GetString(objv
[2]), &pStmt
) ) return TCL_ERROR
;
2912 pStmt
= sqlite3_next_stmt(db
, pStmt
);
2914 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
2915 Tcl_AppendResult(interp
, zBuf
, 0);
2921 ** Usage: sqlite3_stmt_readonly STMT
2923 ** Return true if STMT is a NULL pointer or a pointer to a statement
2924 ** that is guaranteed to leave the database unmodified.
2926 static int SQLITE_TCLAPI
test_stmt_readonly(
2930 Tcl_Obj
*CONST objv
[]
2932 sqlite3_stmt
*pStmt
;
2936 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2937 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2941 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2942 rc
= sqlite3_stmt_readonly(pStmt
);
2943 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(rc
));
2948 ** Usage: sqlite3_stmt_isexplain STMT
2950 ** Return 1, 2, or 0 respectively if STMT is an EXPLAIN statement, an
2951 ** EXPLAIN QUERY PLAN statement or an ordinary statement or NULL pointer.
2953 static int SQLITE_TCLAPI
test_stmt_isexplain(
2957 Tcl_Obj
*CONST objv
[]
2959 sqlite3_stmt
*pStmt
;
2963 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2964 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
2968 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2969 rc
= sqlite3_stmt_isexplain(pStmt
);
2970 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
2975 ** Usage: sqlite3_stmt_explain STMT INT
2977 ** Set the explain to normal (0), EXPLAIN (1) or EXPLAIN QUERY PLAN (2).
2979 static int SQLITE_TCLAPI
test_stmt_explain(
2983 Tcl_Obj
*CONST objv
[]
2985 sqlite3_stmt
*pStmt
;
2990 Tcl_AppendResult(interp
, "wrong # args: should be \"",
2991 Tcl_GetStringFromObj(objv
[0], 0), " STMT INT", 0);
2995 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
2996 if( Tcl_GetIntFromObj(interp
, objv
[2], &eMode
) ) return TCL_ERROR
;
2997 rc
= sqlite3_stmt_explain(pStmt
, eMode
);
2998 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
3003 ** Usage: sqlite3_stmt_busy STMT
3005 ** Return true if STMT is a non-NULL pointer to a statement
3006 ** that has been stepped but not to completion.
3008 static int SQLITE_TCLAPI
test_stmt_busy(
3012 Tcl_Obj
*CONST objv
[]
3014 sqlite3_stmt
*pStmt
;
3018 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3019 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
3023 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3024 rc
= sqlite3_stmt_busy(pStmt
);
3025 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(rc
));
3030 ** Usage: uses_stmt_journal STMT
3032 ** Return true if STMT uses a statement journal.
3034 static int SQLITE_TCLAPI
uses_stmt_journal(
3038 Tcl_Obj
*CONST objv
[]
3040 sqlite3_stmt
*pStmt
;
3043 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3044 Tcl_GetStringFromObj(objv
[0], 0), " STMT", 0);
3048 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3049 sqlite3_stmt_readonly(pStmt
);
3050 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(((Vdbe
*)pStmt
)->usesStmtJournal
));
3056 ** Usage: sqlite3_reset STMT
3058 ** Reset a statement handle.
3060 static int SQLITE_TCLAPI
test_reset(
3064 Tcl_Obj
*CONST objv
[]
3066 sqlite3_stmt
*pStmt
;
3070 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3071 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
3075 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3077 rc
= sqlite3_reset(pStmt
);
3078 if( pStmt
&& sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ){
3081 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
3091 ** Usage: sqlite3_expired STMT
3093 ** Return TRUE if a recompilation of the statement is recommended.
3095 static int SQLITE_TCLAPI
test_expired(
3099 Tcl_Obj
*CONST objv
[]
3101 #ifndef SQLITE_OMIT_DEPRECATED
3102 sqlite3_stmt
*pStmt
;
3104 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3105 Tcl_GetStringFromObj(objv
[0], 0), " <STMT>", 0);
3108 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3109 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(sqlite3_expired(pStmt
)));
3115 ** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT
3117 ** Transfer all bindings from FROMSTMT over to TOSTMT
3119 static int SQLITE_TCLAPI
test_transfer_bind(
3123 Tcl_Obj
*CONST objv
[]
3125 #ifndef SQLITE_OMIT_DEPRECATED
3126 sqlite3_stmt
*pStmt1
, *pStmt2
;
3128 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3129 Tcl_GetStringFromObj(objv
[0], 0), " FROM-STMT TO-STMT", 0);
3132 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt1
)) return TCL_ERROR
;
3133 if( getStmtPointer(interp
, Tcl_GetString(objv
[2]), &pStmt2
)) return TCL_ERROR
;
3134 Tcl_SetObjResult(interp
,
3135 Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1
,pStmt2
)));
3141 ** Usage: sqlite3_changes DB
3143 ** Return the number of changes made to the database by the last SQL
3146 static int SQLITE_TCLAPI
test_changes(
3150 Tcl_Obj
*CONST objv
[]
3154 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3155 Tcl_GetString(objv
[0]), " DB", 0);
3158 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3159 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_changes(db
)));
3164 ** This is the "static_bind_value" that variables are bound to when
3165 ** the FLAG option of sqlite3_bind is "static"
3167 static char *sqlite_static_bind_value
= 0;
3168 static int sqlite_static_bind_nbyte
= 0;
3171 ** Usage: sqlite3_bind VM IDX VALUE FLAGS
3173 ** Sets the value of the IDX-th occurrence of "?" in the original SQL
3174 ** string. VALUE is the new value. If FLAGS=="null" then VALUE is
3175 ** ignored and the value is set to NULL. If FLAGS=="static" then
3176 ** the value is set to the value of a static variable named
3177 ** "sqlite_static_bind_value". If FLAGS=="normal" then a copy
3178 ** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored
3179 ** an a 10-byte blob "abc\000xyz\000pq" is inserted.
3181 static int SQLITE_TCLAPI
test_bind(
3183 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
3184 int argc
, /* Number of arguments */
3185 char **argv
/* Text of each argument */
3187 sqlite3_stmt
*pStmt
;
3191 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
3192 " VM IDX VALUE (null|static|normal)\"", 0);
3195 if( getStmtPointer(interp
, argv
[1], &pStmt
) ) return TCL_ERROR
;
3196 if( Tcl_GetInt(interp
, argv
[2], &idx
) ) return TCL_ERROR
;
3197 if( strcmp(argv
[4],"null")==0 ){
3198 rc
= sqlite3_bind_null(pStmt
, idx
);
3199 }else if( strcmp(argv
[4],"static")==0 ){
3200 rc
= sqlite3_bind_text(pStmt
, idx
, sqlite_static_bind_value
, -1, 0);
3201 }else if( strcmp(argv
[4],"static-nbytes")==0 ){
3202 rc
= sqlite3_bind_text(pStmt
, idx
, sqlite_static_bind_value
,
3203 sqlite_static_bind_nbyte
, 0);
3204 }else if( strcmp(argv
[4],"normal")==0 ){
3205 rc
= sqlite3_bind_text(pStmt
, idx
, argv
[3], -1, SQLITE_TRANSIENT
);
3206 }else if( strcmp(argv
[4],"blob10")==0 ){
3207 rc
= sqlite3_bind_text(pStmt
, idx
, "abc\000xyz\000pq", 10, SQLITE_STATIC
);
3209 Tcl_AppendResult(interp
, "4th argument should be "
3210 "\"null\" or \"static\" or \"normal\"", 0);
3213 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3216 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
3217 Tcl_AppendResult(interp
, zBuf
, sqlite3ErrStr(rc
), 0);
3223 #ifndef SQLITE_OMIT_UTF16
3225 ** Usage: add_test_collate <db ptr> <utf8> <utf16le> <utf16be>
3227 ** This function is used to test that SQLite selects the correct collation
3228 ** sequence callback when multiple versions (for different text encodings)
3231 ** Calling this routine registers the collation sequence "test_collate"
3232 ** with database handle <db>. The second argument must be a list of three
3233 ** boolean values. If the first is true, then a version of test_collate is
3234 ** registered for UTF-8, if the second is true, a version is registered for
3235 ** UTF-16le, if the third is true, a UTF-16be version is available.
3236 ** Previous versions of test_collate are deleted.
3238 ** The collation sequence test_collate is implemented by calling the
3239 ** following TCL script:
3241 ** "test_collate <enc> <lhs> <rhs>"
3243 ** The <lhs> and <rhs> are the two values being compared, encoded in UTF-8.
3244 ** The <enc> parameter is the encoding of the collation function that
3245 ** SQLite selected to call. The TCL test script implements the
3246 ** "test_collate" proc.
3248 ** Note that this will only work with one interpreter at a time, as the
3249 ** interp pointer to use when evaluating the TCL script is stored in
3250 ** pTestCollateInterp.
3252 static Tcl_Interp
* pTestCollateInterp
;
3253 static int test_collate_func(
3255 int nA
, const void *zA
,
3256 int nB
, const void *zB
3258 Tcl_Interp
*i
= pTestCollateInterp
;
3259 int encin
= SQLITE_PTR_TO_INT(pCtx
);
3263 sqlite3_value
*pVal
;
3266 pX
= Tcl_NewStringObj("test_collate", -1);
3267 Tcl_IncrRefCount(pX
);
3271 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-8",-1));
3273 case SQLITE_UTF16LE
:
3274 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-16LE",-1));
3276 case SQLITE_UTF16BE
:
3277 Tcl_ListObjAppendElement(i
,pX
,Tcl_NewStringObj("UTF-16BE",-1));
3283 sqlite3BeginBenignMalloc();
3284 pVal
= sqlite3ValueNew(0);
3286 sqlite3ValueSetStr(pVal
, nA
, zA
, encin
, SQLITE_STATIC
);
3287 n
= sqlite3_value_bytes(pVal
);
3288 Tcl_ListObjAppendElement(i
,pX
,
3289 Tcl_NewStringObj((char*)sqlite3_value_text(pVal
),n
));
3290 sqlite3ValueSetStr(pVal
, nB
, zB
, encin
, SQLITE_STATIC
);
3291 n
= sqlite3_value_bytes(pVal
);
3292 Tcl_ListObjAppendElement(i
,pX
,
3293 Tcl_NewStringObj((char*)sqlite3_value_text(pVal
),n
));
3294 sqlite3ValueFree(pVal
);
3296 sqlite3EndBenignMalloc();
3298 Tcl_EvalObjEx(i
, pX
, 0);
3299 Tcl_DecrRefCount(pX
);
3300 Tcl_GetIntFromObj(i
, Tcl_GetObjResult(i
), &res
);
3303 static int SQLITE_TCLAPI
test_collate(
3307 Tcl_Obj
*CONST objv
[]
3311 sqlite3_value
*pVal
;
3314 if( objc
!=5 ) goto bad_args
;
3315 pTestCollateInterp
= interp
;
3316 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3318 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
3319 rc
= sqlite3_create_collation(db
, "test_collate", SQLITE_UTF8
,
3320 (void *)SQLITE_UTF8
, val
?test_collate_func
:0);
3321 if( rc
==SQLITE_OK
){
3323 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
3324 rc
= sqlite3_create_collation(db
, "test_collate", SQLITE_UTF16LE
,
3325 (void *)SQLITE_UTF16LE
, val
?test_collate_func
:0);
3326 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[4], &val
) ) return TCL_ERROR
;
3329 if( sqlite3_iMallocFail
>0 ){
3330 sqlite3_iMallocFail
++;
3333 sqlite3_mutex_enter(db
->mutex
);
3334 pVal
= sqlite3ValueNew(db
);
3335 sqlite3ValueSetStr(pVal
, -1, "test_collate", SQLITE_UTF8
, SQLITE_STATIC
);
3336 zUtf16
= sqlite3ValueText(pVal
, SQLITE_UTF16NATIVE
);
3337 if( db
->mallocFailed
){
3340 rc
= sqlite3_create_collation16(db
, zUtf16
, SQLITE_UTF16BE
,
3341 (void *)SQLITE_UTF16BE
, val
?test_collate_func
:0);
3343 sqlite3ValueFree(pVal
);
3344 sqlite3_mutex_leave(db
->mutex
);
3346 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3348 if( rc
!=SQLITE_OK
){
3349 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3355 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3356 Tcl_GetStringFromObj(objv
[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
3361 ** Usage: add_test_utf16bin_collate <db ptr>
3363 ** Add a utf-16 collation sequence named "utf16bin" to the database
3364 ** handle. This collation sequence compares arguments in the same way as the
3365 ** built-in collation "binary".
3367 static int test_utf16bin_collate_func(
3369 int nA
, const void *zA
,
3370 int nB
, const void *zB
3372 int nCmp
= (nA
>nB
? nB
: nA
);
3373 int res
= memcmp(zA
, zB
, nCmp
);
3374 if( res
==0 ) res
= nA
- nB
;
3377 static int SQLITE_TCLAPI
test_utf16bin_collate(
3381 Tcl_Obj
*CONST objv
[]
3386 if( objc
!=2 ) goto bad_args
;
3387 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3389 rc
= sqlite3_create_collation(db
, "utf16bin", SQLITE_UTF16
, 0,
3390 test_utf16bin_collate_func
3392 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3396 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
3401 ** When the collation needed callback is invoked, record the name of
3402 ** the requested collating function here. The recorded name is linked
3403 ** to a TCL variable and used to make sure that the requested collation
3406 static char zNeededCollation
[200];
3407 static char *pzNeededCollation
= zNeededCollation
;
3411 ** Called when a collating sequence is needed. Registered using
3412 ** sqlite3_collation_needed16().
3414 static void test_collate_needed_cb(
3423 for(z
= (char*)pName
, i
=0; *z
|| z
[1]; z
++){
3424 if( *z
) zNeededCollation
[i
++] = *z
;
3426 zNeededCollation
[i
] = 0;
3427 sqlite3_create_collation(
3428 db
, "test_collate", ENC(db
), SQLITE_INT_TO_PTR(enc
), test_collate_func
);
3432 ** Usage: add_test_collate_needed DB
3434 static int SQLITE_TCLAPI
test_collate_needed(
3438 Tcl_Obj
*CONST objv
[]
3443 if( objc
!=2 ) goto bad_args
;
3444 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3445 rc
= sqlite3_collation_needed16(db
, 0, test_collate_needed_cb
);
3446 zNeededCollation
[0] = 0;
3447 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
3451 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
3456 ** tclcmd: add_alignment_test_collations DB
3458 ** Add two new collating sequences to the database DB
3463 ** Both collating sequences use the same sort order as BINARY.
3464 ** The only difference is that the utf16_aligned collating
3465 ** sequence is declared with the SQLITE_UTF16_ALIGNED flag.
3466 ** Both collating functions increment the unaligned utf16 counter
3467 ** whenever they see a string that begins on an odd byte boundary.
3469 static int unaligned_string_counter
= 0;
3470 static int alignmentCollFunc(
3472 int nKey1
, const void *pKey1
,
3473 int nKey2
, const void *pKey2
3476 n
= nKey1
<nKey2
? nKey1
: nKey2
;
3477 if( nKey1
>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey1
))) ) unaligned_string_counter
++;
3478 if( nKey2
>0 && 1==(1&(SQLITE_PTR_TO_INT(pKey2
))) ) unaligned_string_counter
++;
3479 rc
= memcmp(pKey1
, pKey2
, n
);
3485 static int SQLITE_TCLAPI
add_alignment_test_collations(
3489 Tcl_Obj
*CONST objv
[]
3493 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3494 sqlite3_create_collation(db
, "utf16_unaligned", SQLITE_UTF16
,
3495 0, alignmentCollFunc
);
3496 sqlite3_create_collation(db
, "utf16_aligned", SQLITE_UTF16_ALIGNED
,
3497 0, alignmentCollFunc
);
3501 #endif /* !defined(SQLITE_OMIT_UTF16) */
3504 ** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be>
3506 ** This function is used to test that SQLite selects the correct user
3507 ** function callback when multiple versions (for different text encodings)
3510 ** Calling this routine registers up to three versions of the user function
3511 ** "test_function" with database handle <db>. If the second argument is
3512 ** true, then a version of test_function is registered for UTF-8, if the
3513 ** third is true, a version is registered for UTF-16le, if the fourth is
3514 ** true, a UTF-16be version is available. Previous versions of
3515 ** test_function are deleted.
3517 ** The user function is implemented by calling the following TCL script:
3519 ** "test_function <enc> <arg>"
3521 ** Where <enc> is one of UTF-8, UTF-16LE or UTF16BE, and <arg> is the
3522 ** single argument passed to the SQL function. The value returned by
3523 ** the TCL script is used as the return value of the SQL function. It
3524 ** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8
3525 ** for a UTF-16LE test_function(), and UTF-16LE for an implementation that
3526 ** prefers UTF-16BE.
3528 #ifndef SQLITE_OMIT_UTF16
3529 static void test_function_utf8(
3530 sqlite3_context
*pCtx
,
3532 sqlite3_value
**argv
3536 sqlite3_value
*pVal
;
3537 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3538 pX
= Tcl_NewStringObj("test_function", -1);
3539 Tcl_IncrRefCount(pX
);
3540 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-8", -1));
3541 Tcl_ListObjAppendElement(interp
, pX
,
3542 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3543 Tcl_EvalObjEx(interp
, pX
, 0);
3544 Tcl_DecrRefCount(pX
);
3545 sqlite3_result_text(pCtx
, Tcl_GetStringResult(interp
), -1, SQLITE_TRANSIENT
);
3546 pVal
= sqlite3ValueNew(0);
3547 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3548 SQLITE_UTF8
, SQLITE_STATIC
);
3549 sqlite3_result_text16be(pCtx
, sqlite3_value_text16be(pVal
),
3550 -1, SQLITE_TRANSIENT
);
3551 sqlite3ValueFree(pVal
);
3553 static void test_function_utf16le(
3554 sqlite3_context
*pCtx
,
3556 sqlite3_value
**argv
3560 sqlite3_value
*pVal
;
3561 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3562 pX
= Tcl_NewStringObj("test_function", -1);
3563 Tcl_IncrRefCount(pX
);
3564 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-16LE", -1));
3565 Tcl_ListObjAppendElement(interp
, pX
,
3566 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3567 Tcl_EvalObjEx(interp
, pX
, 0);
3568 Tcl_DecrRefCount(pX
);
3569 pVal
= sqlite3ValueNew(0);
3570 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3571 SQLITE_UTF8
, SQLITE_STATIC
);
3572 sqlite3_result_text(pCtx
,(char*)sqlite3_value_text(pVal
),-1,SQLITE_TRANSIENT
);
3573 sqlite3ValueFree(pVal
);
3575 static void test_function_utf16be(
3576 sqlite3_context
*pCtx
,
3578 sqlite3_value
**argv
3582 sqlite3_value
*pVal
;
3583 interp
= (Tcl_Interp
*)sqlite3_user_data(pCtx
);
3584 pX
= Tcl_NewStringObj("test_function", -1);
3585 Tcl_IncrRefCount(pX
);
3586 Tcl_ListObjAppendElement(interp
, pX
, Tcl_NewStringObj("UTF-16BE", -1));
3587 Tcl_ListObjAppendElement(interp
, pX
,
3588 Tcl_NewStringObj((char*)sqlite3_value_text(argv
[0]), -1));
3589 Tcl_EvalObjEx(interp
, pX
, 0);
3590 Tcl_DecrRefCount(pX
);
3591 pVal
= sqlite3ValueNew(0);
3592 sqlite3ValueSetStr(pVal
, -1, Tcl_GetStringResult(interp
),
3593 SQLITE_UTF8
, SQLITE_STATIC
);
3594 sqlite3_result_text16(pCtx
, sqlite3_value_text16le(pVal
),
3595 -1, SQLITE_TRANSIENT
);
3596 sqlite3_result_text16be(pCtx
, sqlite3_value_text16le(pVal
),
3597 -1, SQLITE_TRANSIENT
);
3598 sqlite3_result_text16le(pCtx
, sqlite3_value_text16le(pVal
),
3599 -1, SQLITE_TRANSIENT
);
3600 sqlite3ValueFree(pVal
);
3602 #endif /* SQLITE_OMIT_UTF16 */
3603 static int SQLITE_TCLAPI
test_function(
3607 Tcl_Obj
*CONST objv
[]
3609 #ifndef SQLITE_OMIT_UTF16
3613 if( objc
!=5 ) goto bad_args
;
3614 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
3616 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
3618 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF8
,
3619 interp
, test_function_utf8
, 0, 0);
3621 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
3623 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF16LE
,
3624 interp
, test_function_utf16le
, 0, 0);
3626 if( TCL_OK
!=Tcl_GetBooleanFromObj(interp
, objv
[4], &val
) ) return TCL_ERROR
;
3628 sqlite3_create_function(db
, "test_function", 1, SQLITE_UTF16BE
,
3629 interp
, test_function_utf16be
, 0, 0);
3634 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3635 Tcl_GetStringFromObj(objv
[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
3636 #endif /* SQLITE_OMIT_UTF16 */
3641 ** Usage: sqlite3_test_errstr <err code>
3643 ** Test that the English language string equivalents for sqlite error codes
3644 ** are sane. The parameter is an integer representing an sqlite error code.
3645 ** The result is a list of two elements, the string representation of the
3646 ** error code and the English language explanation.
3648 static int SQLITE_TCLAPI
test_errstr(
3652 Tcl_Obj
*CONST objv
[]
3657 Tcl_WrongNumArgs(interp
, 1, objv
, "<error code>");
3660 zCode
= Tcl_GetString(objv
[1]);
3661 for(i
=0; i
<200; i
++){
3662 if( 0==strcmp(t1ErrorName(i
), zCode
) ) break;
3664 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(i
), 0);
3669 ** Usage: breakpoint
3671 ** This routine exists for one purpose - to provide a place to put a
3672 ** breakpoint with GDB that can be triggered using TCL code. The use
3673 ** for this is when a particular test fails on (say) the 1485th iteration.
3674 ** In the TCL test script, we can add code like this:
3676 ** if {$i==1485} breakpoint
3678 ** Then run testfixture in the debugger and wait for the breakpoint to
3679 ** fire. Then additional breakpoints can be set to trace down the bug.
3681 static int SQLITE_TCLAPI
test_breakpoint(
3683 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
3684 int argc
, /* Number of arguments */
3685 char **argv
/* Text of each argument */
3687 return TCL_OK
; /* Do nothing */
3691 ** Usage: sqlite3_bind_zeroblob STMT IDX N
3693 ** Test the sqlite3_bind_zeroblob interface. STMT is a prepared statement.
3694 ** IDX is the index of a wildcard in the prepared statement. This command
3695 ** binds a N-byte zero-filled BLOB to the wildcard.
3697 static int SQLITE_TCLAPI
test_bind_zeroblob(
3701 Tcl_Obj
*CONST objv
[]
3703 sqlite3_stmt
*pStmt
;
3709 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX N");
3713 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3714 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3715 if( Tcl_GetIntFromObj(interp
, objv
[3], &n
) ) return TCL_ERROR
;
3717 rc
= sqlite3_bind_zeroblob(pStmt
, idx
, n
);
3718 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3719 if( rc
!=SQLITE_OK
){
3727 ** Usage: sqlite3_bind_zeroblob64 STMT IDX N
3729 ** Test the sqlite3_bind_zeroblob64 interface. STMT is a prepared statement.
3730 ** IDX is the index of a wildcard in the prepared statement. This command
3731 ** binds a N-byte zero-filled BLOB to the wildcard.
3733 static int SQLITE_TCLAPI
test_bind_zeroblob64(
3737 Tcl_Obj
*CONST objv
[]
3739 sqlite3_stmt
*pStmt
;
3745 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT IDX N");
3749 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3750 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3751 if( Tcl_GetWideIntFromObj(interp
, objv
[3], &n
) ) return TCL_ERROR
;
3753 rc
= sqlite3_bind_zeroblob64(pStmt
, idx
, n
);
3754 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3755 if( rc
!=SQLITE_OK
){
3756 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
3764 ** Usage: sqlite3_bind_int STMT N VALUE
3766 ** Test the sqlite3_bind_int interface. STMT is a prepared statement.
3767 ** N is the index of a wildcard in the prepared statement. This command
3768 ** binds a 32-bit integer VALUE to that wildcard.
3770 static int SQLITE_TCLAPI
test_bind_int(
3774 Tcl_Obj
*CONST objv
[]
3776 sqlite3_stmt
*pStmt
;
3782 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3783 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3787 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3788 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3789 if( Tcl_GetIntFromObj(interp
, objv
[3], &value
) ) return TCL_ERROR
;
3791 rc
= sqlite3_bind_int(pStmt
, idx
, value
);
3792 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3793 if( rc
!=SQLITE_OK
){
3802 ** Usage: intarray_addr INT ...
3804 ** Return the address of a C-language array of 32-bit integers.
3806 ** Space to hold the array is obtained from malloc(). Call this procedure once
3807 ** with no arguments in order to release memory. Each call to this procedure
3808 ** overwrites the previous array.
3810 static int SQLITE_TCLAPI
test_intarray_addr(
3814 Tcl_Obj
*CONST objv
[]
3822 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3823 if( p
==0 ) return TCL_ERROR
;
3824 for(i
=0; i
<objc
-1; i
++){
3825 if( Tcl_GetIntFromObj(interp
, objv
[1+i
], &p
[i
]) ){
3832 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((uptr
)p
));
3836 ** Usage: intarray_addr INT ...
3838 ** Return the address of a C-language array of 32-bit integers.
3840 ** Space to hold the array is obtained from malloc(). Call this procedure once
3841 ** with no arguments in order to release memory. Each call to this procedure
3842 ** overwrites the previous array.
3844 static int SQLITE_TCLAPI
test_int64array_addr(
3848 Tcl_Obj
*CONST objv
[]
3851 static sqlite3_int64
*p
= 0;
3856 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3857 if( p
==0 ) return TCL_ERROR
;
3858 for(i
=0; i
<objc
-1; i
++){
3860 if( Tcl_GetWideIntFromObj(interp
, objv
[1+i
], &v
) ){
3868 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((uptr
)p
));
3872 ** Usage: doublearray_addr INT ...
3874 ** Return the address of a C-language array of doubles.
3876 ** Space to hold the array is obtained from malloc(). Call this procedure once
3877 ** with no arguments in order to release memory. Each call to this procedure
3878 ** overwrites the previous array.
3880 static int SQLITE_TCLAPI
test_doublearray_addr(
3884 Tcl_Obj
*CONST objv
[]
3887 static double *p
= 0;
3892 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3893 if( p
==0 ) return TCL_ERROR
;
3894 for(i
=0; i
<objc
-1; i
++){
3895 if( Tcl_GetDoubleFromObj(interp
, objv
[1+i
], &p
[i
]) ){
3902 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((uptr
)p
));
3906 ** Usage: textarray_addr TEXT ...
3908 ** Return the address of a C-language array of strings.
3910 ** Space to hold the array is obtained from malloc(). Call this procedure once
3911 ** with no arguments in order to release memory. Each call to this procedure
3912 ** overwrites the previous array.
3914 static int SQLITE_TCLAPI
test_textarray_addr(
3918 Tcl_Obj
*CONST objv
[]
3922 static char **p
= 0;
3924 for(i
=0; i
<n
; i
++) sqlite3_free(p
[i
]);
3928 p
= sqlite3_malloc( sizeof(p
[0])*(objc
-1) );
3929 if( p
==0 ) return TCL_ERROR
;
3930 for(i
=0; i
<objc
-1; i
++){
3931 p
[i
] = sqlite3_mprintf("%s", Tcl_GetString(objv
[1+i
]));
3935 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj((uptr
)p
));
3941 ** Usage: sqlite3_bind_int64 STMT N VALUE
3943 ** Test the sqlite3_bind_int64 interface. STMT is a prepared statement.
3944 ** N is the index of a wildcard in the prepared statement. This command
3945 ** binds a 64-bit integer VALUE to that wildcard.
3947 static int SQLITE_TCLAPI
test_bind_int64(
3951 Tcl_Obj
*CONST objv
[]
3953 sqlite3_stmt
*pStmt
;
3959 Tcl_AppendResult(interp
, "wrong # args: should be \"",
3960 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
3964 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
3965 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
3966 if( Tcl_GetWideIntFromObj(interp
, objv
[3], &value
) ) return TCL_ERROR
;
3968 rc
= sqlite3_bind_int64(pStmt
, idx
, value
);
3969 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
3970 if( rc
!=SQLITE_OK
){
3979 ** Usage: sqlite3_bind_double STMT N VALUE
3981 ** Test the sqlite3_bind_double interface. STMT is a prepared statement.
3982 ** N is the index of a wildcard in the prepared statement. This command
3983 ** binds a 64-bit integer VALUE to that wildcard.
3985 static int SQLITE_TCLAPI
test_bind_double(
3989 Tcl_Obj
*CONST objv
[]
3991 sqlite3_stmt
*pStmt
;
3997 static const struct {
3998 const char *zName
; /* Name of the special floating point value */
3999 unsigned int iUpper
; /* Upper 32 bits */
4000 unsigned int iLower
; /* Lower 32 bits */
4002 { "NaN", 0x7fffffff, 0xffffffff },
4003 { "SNaN", 0x7ff7ffff, 0xffffffff },
4004 { "-NaN", 0xffffffff, 0xffffffff },
4005 { "-SNaN", 0xfff7ffff, 0xffffffff },
4006 { "+Inf", 0x7ff00000, 0x00000000 },
4007 { "-Inf", 0xfff00000, 0x00000000 },
4008 { "Epsilon", 0x00000000, 0x00000001 },
4009 { "-Epsilon", 0x80000000, 0x00000001 },
4010 { "NaN0", 0x7ff80000, 0x00000000 },
4011 { "-NaN0", 0xfff80000, 0x00000000 },
4015 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4016 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE", 0);
4020 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4021 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
4023 /* Intercept the string "NaN" and generate a NaN value for it.
4024 ** All other strings are passed through to Tcl_GetDoubleFromObj().
4025 ** Tcl_GetDoubleFromObj() should understand "NaN" but some versions
4028 zVal
= Tcl_GetString(objv
[3]);
4029 for(i
=0; i
<sizeof(aSpecialFp
)/sizeof(aSpecialFp
[0]); i
++){
4030 if( strcmp(aSpecialFp
[i
].zName
, zVal
)==0 ){
4032 x
= aSpecialFp
[i
].iUpper
;
4034 x
|= aSpecialFp
[i
].iLower
;
4035 assert( sizeof(value
)==8 );
4036 assert( sizeof(x
)==8 );
4037 memcpy(&value
, &x
, 8);
4041 if( i
>=sizeof(aSpecialFp
)/sizeof(aSpecialFp
[0]) &&
4042 Tcl_GetDoubleFromObj(interp
, objv
[3], &value
) ){
4045 rc
= sqlite3_bind_double(pStmt
, idx
, value
);
4046 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
4047 if( rc
!=SQLITE_OK
){
4055 ** Usage: sqlite3_bind_null STMT N
4057 ** Test the sqlite3_bind_null interface. STMT is a prepared statement.
4058 ** N is the index of a wildcard in the prepared statement. This command
4059 ** binds a NULL to the wildcard.
4061 static int SQLITE_TCLAPI
test_bind_null(
4065 Tcl_Obj
*CONST objv
[]
4067 sqlite3_stmt
*pStmt
;
4072 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4073 Tcl_GetStringFromObj(objv
[0], 0), " STMT N", 0);
4077 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4078 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
4080 rc
= sqlite3_bind_null(pStmt
, idx
);
4081 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
4082 if( rc
!=SQLITE_OK
){
4090 ** Usage: sqlite3_bind_text STMT N STRING BYTES
4092 ** Test the sqlite3_bind_text interface. STMT is a prepared statement.
4093 ** N is the index of a wildcard in the prepared statement. This command
4094 ** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes
4097 static int SQLITE_TCLAPI
test_bind_text(
4101 Tcl_Obj
*CONST objv
[]
4103 sqlite3_stmt
*pStmt
;
4112 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4113 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE BYTES", 0);
4117 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4118 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
4119 value
= (char*)Tcl_GetByteArrayFromObj(objv
[3], &trueLength
);
4120 if( Tcl_GetIntFromObj(interp
, objv
[4], &bytes
) ) return TCL_ERROR
;
4122 toFree
= malloc( trueLength
+ 1 );
4124 Tcl_AppendResult(interp
, "out of memory", (void*)0);
4127 memcpy(toFree
, value
, trueLength
);
4128 toFree
[trueLength
] = 0;
4131 rc
= sqlite3_bind_text(pStmt
, idx
, value
, bytes
, SQLITE_TRANSIENT
);
4133 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
4134 if( rc
!=SQLITE_OK
){
4135 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), (void*)0);
4143 ** Usage: sqlite3_bind_text16 ?-static? STMT N STRING BYTES
4145 ** Test the sqlite3_bind_text16 interface. STMT is a prepared statement.
4146 ** N is the index of a wildcard in the prepared statement. This command
4147 ** binds a UTF-16 string STRING to the wildcard. The string is BYTES bytes
4150 static int SQLITE_TCLAPI
test_bind_text16(
4154 Tcl_Obj
*CONST objv
[]
4156 #ifndef SQLITE_OMIT_UTF16
4157 sqlite3_stmt
*pStmt
;
4165 void (*xDel
)(void*) = (objc
==6?SQLITE_STATIC
:SQLITE_TRANSIENT
);
4166 Tcl_Obj
*oStmt
= objv
[objc
-4];
4167 Tcl_Obj
*oN
= objv
[objc
-3];
4168 Tcl_Obj
*oString
= objv
[objc
-2];
4169 Tcl_Obj
*oBytes
= objv
[objc
-1];
4171 if( objc
!=5 && objc
!=6){
4172 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4173 Tcl_GetStringFromObj(objv
[0], 0), " STMT N VALUE BYTES", 0);
4177 if( getStmtPointer(interp
, Tcl_GetString(oStmt
), &pStmt
) ) return TCL_ERROR
;
4178 if( Tcl_GetIntFromObj(interp
, oN
, &idx
) ) return TCL_ERROR
;
4179 value
= (char*)Tcl_GetByteArrayFromObj(oString
, &trueLength
);
4180 if( Tcl_GetIntFromObj(interp
, oBytes
, &bytes
) ) return TCL_ERROR
;
4181 if( bytes
<0 && xDel
==SQLITE_TRANSIENT
){
4182 toFree
= malloc( trueLength
+ 3 );
4184 Tcl_AppendResult(interp
, "out of memory", (void*)0);
4187 memcpy(toFree
, value
, trueLength
);
4188 memset(toFree
+trueLength
, 0, 3);
4191 rc
= sqlite3_bind_text16(pStmt
, idx
, (void *)value
, bytes
, xDel
);
4193 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
4194 if( rc
!=SQLITE_OK
){
4195 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
4199 #endif /* SQLITE_OMIT_UTF16 */
4204 ** Usage: sqlite3_bind_blob ?-static? STMT N DATA BYTES
4206 ** Test the sqlite3_bind_blob interface. STMT is a prepared statement.
4207 ** N is the index of a wildcard in the prepared statement. This command
4208 ** binds a BLOB to the wildcard. The BLOB is BYTES bytes in size.
4210 static int SQLITE_TCLAPI
test_bind_blob(
4214 Tcl_Obj
*CONST objv
[]
4216 sqlite3_stmt
*pStmt
;
4221 sqlite3_destructor_type xDestructor
= SQLITE_TRANSIENT
;
4223 if( objc
!=5 && objc
!=6 ){
4224 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4225 Tcl_GetStringFromObj(objv
[0], 0), " STMT N DATA BYTES", 0);
4230 xDestructor
= SQLITE_STATIC
;
4234 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4235 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
4237 value
= (char*)Tcl_GetByteArrayFromObj(objv
[3], &len
);
4238 if( Tcl_GetIntFromObj(interp
, objv
[4], &bytes
) ) return TCL_ERROR
;
4242 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
4243 "cannot use %d blob bytes, have %d", bytes
, len
);
4244 Tcl_AppendResult(interp
, zBuf
, (char*)0);
4248 rc
= sqlite3_bind_blob(pStmt
, idx
, value
, bytes
, xDestructor
);
4249 if( sqlite3TestErrCode(interp
, StmtToDb(pStmt
), rc
) ) return TCL_ERROR
;
4250 if( rc
!=SQLITE_OK
){
4258 ** Usage: sqlite3_bind_value_from_preupdate STMT N NEW|OLD IDX
4260 ** Test the sqlite3_bind_value interface using sqlite3_value objects
4261 ** obtained from either sqlite3_preupdate_new() (if arg[3]=="new") or
4262 ** sqlite3_preupdate_old() if (arg[3]=="old"). IDX is the index to
4263 ** pass to the sqlite3_preupdate_xxx() function.
4265 static int SQLITE_TCLAPI
test_bind_value_from_preupdate(
4269 Tcl_Obj
*CONST objv
[]
4271 sqlite3_stmt
*pStmt
;
4274 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
4277 sqlite3_value
*pVal
= 0;
4281 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT N NEW|OLD IDX");
4285 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4286 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
4287 if( Tcl_GetIntFromObj(interp
, objv
[4], &bidx
) ) return TCL_ERROR
;
4289 #ifdef SQLITE_ENABLE_PREUPDATE_HOOK
4290 z3
= Tcl_GetString(objv
[3]);
4291 db
= sqlite3_db_handle(pStmt
);
4293 sqlite3_preupdate_new(db
, bidx
, &pVal
);
4294 }else if( z3
[0]=='o' ){
4295 sqlite3_preupdate_old(db
, bidx
, &pVal
);
4297 Tcl_AppendResult(interp
, "expected new or old, got: ", z3
, (char*)0);
4300 sqlite3_bind_value(pStmt
, idx
, pVal
);
4307 ** Usage: sqlite3_bind_value_from_select STMT N SELECT
4309 ** Test the sqlite3_bind_value interface. STMT is a prepared statement.
4310 ** N is the index of a wildcard in the prepared statement.
4312 static int SQLITE_TCLAPI
test_bind_value_from_select(
4316 Tcl_Obj
*CONST objv
[]
4318 sqlite3_stmt
*pStmt
;
4319 sqlite3_stmt
*pStmt2
;
4321 const char *zSql
= 0;
4326 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT N SELECT");
4330 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4331 if( Tcl_GetIntFromObj(interp
, objv
[2], &idx
) ) return TCL_ERROR
;
4332 zSql
= Tcl_GetString(objv
[3]);
4333 db
= sqlite3_db_handle(pStmt
);
4335 rc
= sqlite3_prepare_v2(db
, zSql
, -1, &pStmt2
, 0);
4336 if( rc
!=SQLITE_OK
){
4337 Tcl_AppendResult(interp
, "error in SQL: ", sqlite3_errmsg(db
), (char*)0);
4340 if( sqlite3_step(pStmt2
)==SQLITE_ROW
){
4341 sqlite3_value
*pVal
= sqlite3_column_value(pStmt2
, 0);
4342 sqlite3_bind_value(pStmt
, idx
, pVal
);
4344 rc
= sqlite3_finalize(pStmt2
);
4345 if( rc
!=SQLITE_OK
){
4346 Tcl_AppendResult(interp
,
4347 "error runnning SQL: ", sqlite3_errmsg(db
), (char*)0
4361 # include <sys/uio.h>
4364 #ifndef SQLITE_OMIT_VIRTUALTABLE
4366 ** sqlite3_carray_bind [options...] STMT NAME VALUE ...
4377 ** Each call clears static data. Called with no options does nothing
4378 ** but clear static data.
4380 static int SQLITE_TCLAPI
test_carray_bind(
4384 Tcl_Obj
*CONST objv
[]
4386 sqlite3_stmt
*pStmt
;
4387 int eType
= 0; /* CARRAY_INT32 */
4390 int isTransient
= 0;
4395 void (*xDel
)(void*) = sqlite3_free
;
4396 static void *aStaticData
= 0;
4397 static int nStaticData
= 0;
4398 static int eStaticType
= 0;
4399 extern int sqlite3_carray_bind(
4400 sqlite3_stmt
*pStmt
,
4405 void (*xDestroy
)(void*)
4409 /* Always clear preexisting static data on every call */
4410 if( eStaticType
==3 ){
4411 for(i
=0; i
<nStaticData
; i
++){
4412 sqlite3_free(((char**)aStaticData
)[i
]);
4415 if( eStaticType
==4 ){
4416 for(i
=0; i
<nStaticData
; i
++){
4417 sqlite3_free(((struct iovec
*)aStaticData
)[i
].iov_base
);
4420 sqlite3_free(aStaticData
);
4425 if( objc
==1 ) return TCL_OK
;
4427 for(i
=1; i
<objc
&& Tcl_GetString(objv
[i
])[0]=='-'; i
++){
4428 const char *z
= Tcl_GetString(objv
[i
]);
4429 if( strcmp(z
, "-transient")==0 ){
4431 xDel
= SQLITE_TRANSIENT
;
4433 if( strcmp(z
, "-static")==0 ){
4435 xDel
= SQLITE_STATIC
;
4437 if( strcmp(z
, "-int32")==0 ){
4438 eType
= 0; /* CARRAY_INT32 */
4440 if( strcmp(z
, "-int64")==0 ){
4441 eType
= 1; /* CARRAY_INT64 */
4443 if( strcmp(z
, "-double")==0 ){
4444 eType
= 2; /* CARRAY_DOUBLE */
4446 if( strcmp(z
, "-text")==0 ){
4447 eType
= 3; /* CARRAY_TEXT */
4449 if( strcmp(z
, "-blob")==0 ){
4450 eType
= 4; /* CARRAY_BLOB */
4452 if( strcmp(z
, "--")==0 ){
4456 Tcl_AppendResult(interp
, "unknown option: ", z
, (char*)0);
4460 if( eType
==3 && !isStatic
&& !isTransient
){
4461 Tcl_AppendResult(interp
, "text data must be either -static or -transient",
4465 if( eType
==4 && !isStatic
&& !isTransient
){
4466 Tcl_AppendResult(interp
, "blob data must be either -static or -transient",
4470 if( isStatic
&& isTransient
){
4471 Tcl_AppendResult(interp
, "cannot be both -static and -transient",
4476 Tcl_WrongNumArgs(interp
, 1, objv
, "[OPTIONS] STMT IDX VALUE ...");
4479 if( getStmtPointer(interp
, Tcl_GetString(objv
[i
]), &pStmt
) ) return TCL_ERROR
;
4481 if( Tcl_GetIntFromObj(interp
, objv
[i
], &idx
) ) return TCL_ERROR
;
4484 switch( eType
+ 5*(nData
<=0) ){
4485 case 0: { /* INT32 */
4486 int *a
= sqlite3_malloc( sizeof(int)*nData
);
4487 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4488 for(j
=0; j
<nData
; j
++){
4490 if( Tcl_GetIntFromObj(interp
, objv
[i
+j
], &v
) ){
4499 case 1: { /* INT64 */
4500 sqlite3_int64
*a
= sqlite3_malloc( sizeof(sqlite3_int64
)*nData
);
4501 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4502 for(j
=0; j
<nData
; j
++){
4504 if( Tcl_GetWideIntFromObj(interp
, objv
[i
+j
], &v
) ){
4513 case 2: { /* DOUBLE */
4514 double *a
= sqlite3_malloc( sizeof(double)*nData
);
4515 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4516 for(j
=0; j
<nData
; j
++){
4518 if( Tcl_GetDoubleFromObj(interp
, objv
[i
+j
], &v
) ){
4527 case 3: { /* TEXT */
4528 char **a
= sqlite3_malloc( sizeof(char*)*nData
);
4529 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4530 for(j
=0; j
<nData
; j
++){
4531 const char *v
= Tcl_GetString(objv
[i
+j
]);
4532 a
[j
] = sqlite3_mprintf("%s", v
);
4537 case 4: { /* BLOB */
4538 struct iovec
*a
= sqlite3_malloc( sizeof(struct iovec
)*nData
);
4539 if( a
==0 ){ rc
= SQLITE_NOMEM
; goto carray_bind_done
; }
4540 for(j
=0; j
<nData
; j
++){
4542 unsigned char *v
= Tcl_GetByteArrayFromObj(objv
[i
+i
], &n
);
4544 a
[j
].iov_base
= sqlite3_malloc64( n
);
4545 if( a
[j
].iov_base
==0 ){
4548 memcpy(a
[j
].iov_base
, v
, n
);
4554 case 5: { /* nData==0 */
4556 xDel
= SQLITE_STATIC
;
4563 aStaticData
= aData
;
4564 nStaticData
= nData
;
4565 eStaticType
= eType
;
4567 rc
= sqlite3_carray_bind(pStmt
, idx
, aData
, nData
, eType
, xDel
);
4570 for(i
=0; i
<nData
; i
++) sqlite3_free(((char**)aData
)[i
]);
4573 for(i
=0; i
<nData
; i
++) sqlite3_free(((struct iovec
*)aData
)[i
].iov_base
);
4575 sqlite3_free(aData
);
4579 Tcl_AppendResult(interp
, sqlite3_errstr(rc
), (char*)0);
4584 #endif /* SQLITE_OMIT_VIRTUALTABLE */
4587 ** Usage: sqlite3_bind_parameter_count STMT
4589 ** Return the number of wildcards in the given statement.
4591 static int SQLITE_TCLAPI
test_bind_parameter_count(
4595 Tcl_Obj
*CONST objv
[]
4597 sqlite3_stmt
*pStmt
;
4600 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4603 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4604 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_bind_parameter_count(pStmt
)));
4609 ** Usage: sqlite3_bind_parameter_name STMT N
4611 ** Return the name of the Nth wildcard. The first wildcard is 1.
4612 ** An empty string is returned if N is out of range or if the wildcard
4615 static int SQLITE_TCLAPI
test_bind_parameter_name(
4619 Tcl_Obj
*CONST objv
[]
4621 sqlite3_stmt
*pStmt
;
4625 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT N");
4628 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4629 if( Tcl_GetIntFromObj(interp
, objv
[2], &i
) ) return TCL_ERROR
;
4630 Tcl_SetObjResult(interp
,
4631 Tcl_NewStringObj(sqlite3_bind_parameter_name(pStmt
,i
),-1)
4637 ** Usage: sqlite3_bind_parameter_index STMT NAME
4639 ** Return the index of the wildcard called NAME. Return 0 if there is
4640 ** no such wildcard.
4642 static int SQLITE_TCLAPI
test_bind_parameter_index(
4646 Tcl_Obj
*CONST objv
[]
4648 sqlite3_stmt
*pStmt
;
4651 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT NAME");
4654 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4655 Tcl_SetObjResult(interp
,
4657 sqlite3_bind_parameter_index(pStmt
,Tcl_GetString(objv
[2]))
4664 ** Usage: sqlite3_clear_bindings STMT
4667 static int SQLITE_TCLAPI
test_clear_bindings(
4671 Tcl_Obj
*CONST objv
[]
4673 sqlite3_stmt
*pStmt
;
4676 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
4679 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
4680 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_clear_bindings(pStmt
)));
4685 ** Usage: sqlite3_sleep MILLISECONDS
4687 static int SQLITE_TCLAPI
test_sleep(
4691 Tcl_Obj
*CONST objv
[]
4696 Tcl_WrongNumArgs(interp
, 1, objv
, "MILLISECONDS");
4699 if( Tcl_GetIntFromObj(interp
, objv
[1], &ms
) ){
4702 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_sleep(ms
)));
4707 ** Usage: sqlite3_extended_errcode DB
4709 ** Return the string representation of the most recent sqlite3_* API
4710 ** error code. e.g. "SQLITE_ERROR".
4712 static int SQLITE_TCLAPI
test_ex_errcode(
4716 Tcl_Obj
*CONST objv
[]
4722 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4723 Tcl_GetString(objv
[0]), " DB", 0);
4726 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4727 rc
= sqlite3_extended_errcode(db
);
4728 Tcl_AppendResult(interp
, (char *)t1ErrorName(rc
), 0);
4734 ** Usage: sqlite3_errcode DB
4736 ** Return the string representation of the most recent sqlite3_* API
4737 ** error code. e.g. "SQLITE_ERROR".
4739 static int SQLITE_TCLAPI
test_errcode(
4743 Tcl_Obj
*CONST objv
[]
4749 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4750 Tcl_GetString(objv
[0]), " DB", 0);
4753 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4754 rc
= sqlite3_errcode(db
);
4755 Tcl_AppendResult(interp
, (char *)t1ErrorName(rc
), 0);
4760 ** Usage: sqlite3_errmsg DB
4762 ** Returns the UTF-8 representation of the error message string for the
4763 ** most recent sqlite3_* API call.
4765 static int SQLITE_TCLAPI
test_errmsg(
4769 Tcl_Obj
*CONST objv
[]
4775 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4776 Tcl_GetString(objv
[0]), " DB", 0);
4779 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4781 zErr
= sqlite3_errmsg(db
);
4782 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zErr
, -1));
4788 ** Usage: sqlite3_error_offset DB
4790 ** Return the byte offset into the input UTF8 SQL for the most recent
4791 ** error, or -1 of the error does not refer to a specific token.
4793 static int SQLITE_TCLAPI
test_error_offset(
4797 Tcl_Obj
*CONST objv
[]
4803 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4804 Tcl_GetString(objv
[0]), " DB", 0);
4807 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4809 iByteOffset
= sqlite3_error_offset(db
);
4810 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iByteOffset
));
4815 ** Usage: test_errmsg16 DB
4817 ** Returns the UTF-16 representation of the error message string for the
4818 ** most recent sqlite3_* API call. This is a byte array object at the TCL
4819 ** level, and it includes the 0x00 0x00 terminator bytes at the end of the
4822 static int SQLITE_TCLAPI
test_errmsg16(
4826 Tcl_Obj
*CONST objv
[]
4828 #ifndef SQLITE_OMIT_UTF16
4835 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4836 Tcl_GetString(objv
[0]), " DB", 0);
4839 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4841 zErr
= sqlite3_errmsg16(db
);
4844 for(bytes
=0; z
[bytes
] || z
[bytes
+1]; bytes
+=2){}
4846 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(zErr
, bytes
));
4847 #endif /* SQLITE_OMIT_UTF16 */
4852 ** Usage: sqlite3_prepare DB sql bytes ?tailvar?
4854 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4855 ** database handle <DB>. The parameter <tailval> is the name of a global
4856 ** variable that is set to the unused portion of <sql> (if any). A
4857 ** STMT handle is returned.
4859 static int SQLITE_TCLAPI
test_prepare(
4863 Tcl_Obj
*CONST objv
[]
4868 const char *zTail
= 0;
4869 sqlite3_stmt
*pStmt
= 0;
4873 if( objc
!=5 && objc
!=4 ){
4874 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4875 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
4878 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4879 zSql
= Tcl_GetString(objv
[2]);
4880 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4882 rc
= sqlite3_prepare(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
4883 Tcl_ResetResult(interp
);
4884 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4885 if( zTail
&& objc
>=5 ){
4887 bytes
= bytes
- (int)(zTail
-zSql
);
4889 if( (int)strlen(zTail
)<bytes
){
4890 bytes
= (int)strlen(zTail
);
4892 Tcl_ObjSetVar2(interp
, objv
[4], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4894 if( rc
!=SQLITE_OK
){
4896 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4897 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4902 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4903 Tcl_AppendResult(interp
, zBuf
, 0);
4909 ** Usage: sqlite3_prepare_v2 DB sql bytes ?tailvar?
4911 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4912 ** database handle <DB>. The parameter <tailval> is the name of a global
4913 ** variable that is set to the unused portion of <sql> (if any). A
4914 ** STMT handle is returned.
4916 static int SQLITE_TCLAPI
test_prepare_v2(
4920 Tcl_Obj
*CONST objv
[]
4924 char *zCopy
= 0; /* malloc() copy of zSql */
4926 const char *zTail
= 0;
4927 const char **pzTail
;
4928 sqlite3_stmt
*pStmt
= 0;
4932 if( objc
!=5 && objc
!=4 ){
4933 Tcl_AppendResult(interp
, "wrong # args: should be \"",
4934 Tcl_GetString(objv
[0]), " DB sql bytes tailvar", 0);
4937 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
4938 zSql
= Tcl_GetString(objv
[2]);
4939 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
4941 /* Instead of using zSql directly, make a copy into a buffer obtained
4942 ** directly from malloc(). The idea is to make it easier for valgrind
4943 ** to spot buffer overreads. */
4945 zCopy
= malloc(bytes
);
4946 memcpy(zCopy
, zSql
, bytes
);
4948 int n
= (int)strlen(zSql
) + 1;
4950 memcpy(zCopy
, zSql
, n
);
4952 pzTail
= objc
>=5 ? &zTail
: 0;
4953 rc
= sqlite3_prepare_v2(db
, zCopy
, bytes
, &pStmt
, pzTail
);
4955 zTail
= &zSql
[(zTail
- zCopy
)];
4959 assert(rc
==SQLITE_OK
|| pStmt
==0);
4960 Tcl_ResetResult(interp
);
4961 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
4962 if( rc
==SQLITE_OK
&& objc
>=5 && zTail
){
4964 bytes
= bytes
- (int)(zTail
-zSql
);
4966 Tcl_ObjSetVar2(interp
, objv
[4], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
4968 if( rc
!=SQLITE_OK
){
4970 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
4971 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
4976 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
4977 Tcl_AppendResult(interp
, zBuf
, 0);
4983 ** Usage: sqlite3_prepare_v3 DB sql bytes flags ?tailvar?
4985 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
4986 ** database handle <DB> and flags <flags>. The parameter <tailval> is
4987 ** the name of a global variable that is set to the unused portion of
4988 ** <sql> (if any). A STMT handle is returned.
4990 static int SQLITE_TCLAPI
test_prepare_v3(
4994 Tcl_Obj
*CONST objv
[]
4998 char *zCopy
= 0; /* malloc() copy of zSql */
5000 const char *zTail
= 0;
5001 const char **pzTail
;
5002 sqlite3_stmt
*pStmt
= 0;
5006 if( objc
!=6 && objc
!=5 ){
5007 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5008 Tcl_GetString(objv
[0]), " DB sql bytes flags tailvar", 0);
5011 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5012 zSql
= Tcl_GetString(objv
[2]);
5013 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
5014 if( Tcl_GetIntFromObj(interp
, objv
[4], &flags
) ) return TCL_ERROR
;
5016 /* Instead of using zSql directly, make a copy into a buffer obtained
5017 ** directly from malloc(). The idea is to make it easier for valgrind
5018 ** to spot buffer overreads. */
5020 zCopy
= malloc(bytes
);
5021 memcpy(zCopy
, zSql
, bytes
);
5023 int n
= (int)strlen(zSql
) + 1;
5025 memcpy(zCopy
, zSql
, n
);
5027 pzTail
= objc
>=6 ? &zTail
: 0;
5028 rc
= sqlite3_prepare_v3(db
, zCopy
, bytes
, (unsigned int)flags
,&pStmt
,pzTail
);
5030 zTail
= &zSql
[(zTail
- zCopy
)];
5032 assert(rc
==SQLITE_OK
|| pStmt
==0);
5033 Tcl_ResetResult(interp
);
5034 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
5035 if( rc
==SQLITE_OK
&& zTail
&& objc
>=6 ){
5037 bytes
= bytes
- (int)(zTail
-zSql
);
5039 Tcl_ObjSetVar2(interp
, objv
[5], 0, Tcl_NewStringObj(zTail
, bytes
), 0);
5041 if( rc
!=SQLITE_OK
){
5043 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
5044 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
5049 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
5050 Tcl_AppendResult(interp
, zBuf
, 0);
5056 ** Usage: sqlite3_prepare_tkt3134 DB
5058 ** Generate a prepared statement for a zero-byte string as a test
5059 ** for ticket #3134. The string should be preceded by a zero byte.
5061 static int SQLITE_TCLAPI
test_prepare_tkt3134(
5065 Tcl_Obj
*CONST objv
[]
5068 static const char zSql
[] = "\000SELECT 1";
5069 sqlite3_stmt
*pStmt
= 0;
5074 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5075 Tcl_GetString(objv
[0]), " DB sql bytes tailvar", 0);
5078 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5079 rc
= sqlite3_prepare_v2(db
, &zSql
[1], 0, &pStmt
, 0);
5080 assert(rc
==SQLITE_OK
|| pStmt
==0);
5081 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
5082 if( rc
!=SQLITE_OK
){
5084 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "(%d) ", rc
);
5085 Tcl_AppendResult(interp
, zBuf
, sqlite3_errmsg(db
), 0);
5090 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
5091 Tcl_AppendResult(interp
, zBuf
, 0);
5097 ** Usage: sqlite3_prepare16 DB sql bytes tailvar
5099 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
5100 ** database handle <DB>. The parameter <tailval> is the name of a global
5101 ** variable that is set to the unused portion of <sql> (if any). A
5102 ** STMT handle is returned.
5104 static int SQLITE_TCLAPI
test_prepare16(
5108 Tcl_Obj
*CONST objv
[]
5110 #ifndef SQLITE_OMIT_UTF16
5113 const void *zTail
= 0;
5115 sqlite3_stmt
*pStmt
= 0;
5118 int bytes
; /* The integer specified as arg 3 */
5119 int objlen
; /* The byte-array length of arg 2 */
5121 if( objc
!=5 && objc
!=4 ){
5122 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5123 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
5126 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5127 zSql
= Tcl_GetByteArrayFromObj(objv
[2], &objlen
);
5128 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
5130 rc
= sqlite3_prepare16(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
5131 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
5138 objlen
= objlen
- (int)((u8
*)zTail
-(u8
*)zSql
);
5142 pTail
= Tcl_NewByteArrayObj((u8
*)zTail
, objlen
);
5143 Tcl_IncrRefCount(pTail
);
5144 Tcl_ObjSetVar2(interp
, objv
[4], 0, pTail
, 0);
5145 Tcl_DecrRefCount(pTail
);
5149 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
5151 Tcl_AppendResult(interp
, zBuf
, 0);
5152 #endif /* SQLITE_OMIT_UTF16 */
5157 ** Usage: sqlite3_prepare16_v2 DB sql bytes ?tailvar?
5159 ** Compile up to <bytes> bytes of the supplied SQL string <sql> using
5160 ** database handle <DB>. The parameter <tailval> is the name of a global
5161 ** variable that is set to the unused portion of <sql> (if any). A
5162 ** STMT handle is returned.
5164 static int SQLITE_TCLAPI
test_prepare16_v2(
5168 Tcl_Obj
*CONST objv
[]
5170 #ifndef SQLITE_OMIT_UTF16
5173 const void *zTail
= 0;
5175 sqlite3_stmt
*pStmt
= 0;
5178 int bytes
; /* The integer specified as arg 3 */
5179 int objlen
; /* The byte-array length of arg 2 */
5181 if( objc
!=5 && objc
!=4 ){
5182 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5183 Tcl_GetString(objv
[0]), " DB sql bytes ?tailvar?", 0);
5186 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
5187 zSql
= Tcl_GetByteArrayFromObj(objv
[2], &objlen
);
5188 if( Tcl_GetIntFromObj(interp
, objv
[3], &bytes
) ) return TCL_ERROR
;
5190 rc
= sqlite3_prepare16_v2(db
, zSql
, bytes
, &pStmt
, objc
>=5 ? &zTail
: 0);
5191 if( sqlite3TestErrCode(interp
, db
, rc
) ) return TCL_ERROR
;
5198 objlen
= objlen
- (int)((u8
*)zTail
-(u8
*)zSql
);
5202 pTail
= Tcl_NewByteArrayObj((u8
*)zTail
, objlen
);
5203 Tcl_IncrRefCount(pTail
);
5204 Tcl_ObjSetVar2(interp
, objv
[4], 0, pTail
, 0);
5205 Tcl_DecrRefCount(pTail
);
5209 if( sqlite3TestMakePointerStr(interp
, zBuf
, pStmt
) ) return TCL_ERROR
;
5211 Tcl_AppendResult(interp
, zBuf
, 0);
5212 #endif /* SQLITE_OMIT_UTF16 */
5217 ** Usage: sqlite3_open filename ?options-list?
5219 static int SQLITE_TCLAPI
test_open(
5223 Tcl_Obj
*CONST objv
[]
5225 const char *zFilename
;
5229 if( objc
!=3 && objc
!=2 && objc
!=1 ){
5230 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5231 Tcl_GetString(objv
[0]), " filename options-list", 0);
5235 zFilename
= objc
>1 ? Tcl_GetString(objv
[1]) : 0;
5236 sqlite3_open(zFilename
, &db
);
5238 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
5239 Tcl_AppendResult(interp
, zBuf
, 0);
5244 ** Usage: sqlite3_open_v2 FILENAME FLAGS VFS
5246 static int SQLITE_TCLAPI
test_open_v2(
5250 Tcl_Obj
*CONST objv
[]
5252 const char *zFilename
;
5264 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME FLAGS VFS");
5267 zFilename
= Tcl_GetString(objv
[1]);
5268 zVfs
= Tcl_GetString(objv
[3]);
5269 if( zVfs
[0]==0x00 ) zVfs
= 0;
5271 rc
= Tcl_ListObjGetElements(interp
, objv
[2], &nFlag
, &apFlag
);
5272 if( rc
!=TCL_OK
) return rc
;
5273 for(i
=0; i
<nFlag
; i
++){
5279 { "SQLITE_OPEN_READONLY", SQLITE_OPEN_READONLY
},
5280 { "SQLITE_OPEN_READWRITE", SQLITE_OPEN_READWRITE
},
5281 { "SQLITE_OPEN_CREATE", SQLITE_OPEN_CREATE
},
5282 { "SQLITE_OPEN_DELETEONCLOSE", SQLITE_OPEN_DELETEONCLOSE
},
5283 { "SQLITE_OPEN_EXCLUSIVE", SQLITE_OPEN_EXCLUSIVE
},
5284 { "SQLITE_OPEN_AUTOPROXY", SQLITE_OPEN_AUTOPROXY
},
5285 { "SQLITE_OPEN_MAIN_DB", SQLITE_OPEN_MAIN_DB
},
5286 { "SQLITE_OPEN_TEMP_DB", SQLITE_OPEN_TEMP_DB
},
5287 { "SQLITE_OPEN_TRANSIENT_DB", SQLITE_OPEN_TRANSIENT_DB
},
5288 { "SQLITE_OPEN_MAIN_JOURNAL", SQLITE_OPEN_MAIN_JOURNAL
},
5289 { "SQLITE_OPEN_TEMP_JOURNAL", SQLITE_OPEN_TEMP_JOURNAL
},
5290 { "SQLITE_OPEN_SUBJOURNAL", SQLITE_OPEN_SUBJOURNAL
},
5291 { "SQLITE_OPEN_SUPER_JOURNAL", SQLITE_OPEN_SUPER_JOURNAL
},
5292 { "SQLITE_OPEN_NOMUTEX", SQLITE_OPEN_NOMUTEX
},
5293 { "SQLITE_OPEN_FULLMUTEX", SQLITE_OPEN_FULLMUTEX
},
5294 { "SQLITE_OPEN_SHAREDCACHE", SQLITE_OPEN_SHAREDCACHE
},
5295 { "SQLITE_OPEN_PRIVATECACHE", SQLITE_OPEN_PRIVATECACHE
},
5296 { "SQLITE_OPEN_WAL", SQLITE_OPEN_WAL
},
5297 { "SQLITE_OPEN_URI", SQLITE_OPEN_URI
},
5298 { "SQLITE_OPEN_EXRESCODE", SQLITE_OPEN_EXRESCODE
},
5301 rc
= Tcl_GetIndexFromObjStruct(interp
, apFlag
[i
], aFlag
, sizeof(aFlag
[0]),
5304 if( rc
!=TCL_OK
) return rc
;
5305 flags
|= aFlag
[iFlag
].flag
;
5308 rc
= sqlite3_open_v2(zFilename
, &db
, flags
, zVfs
);
5309 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
5310 Tcl_AppendResult(interp
, zBuf
, 0);
5315 ** Usage: sqlite3_open16 filename options
5317 static int SQLITE_TCLAPI
test_open16(
5321 Tcl_Obj
*CONST objv
[]
5323 #ifndef SQLITE_OMIT_UTF16
5324 const void *zFilename
;
5329 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5330 Tcl_GetString(objv
[0]), " filename options-list", 0);
5334 zFilename
= Tcl_GetByteArrayFromObj(objv
[1], 0);
5335 sqlite3_open16(zFilename
, &db
);
5337 if( sqlite3TestMakePointerStr(interp
, zBuf
, db
) ) return TCL_ERROR
;
5338 Tcl_AppendResult(interp
, zBuf
, 0);
5339 #endif /* SQLITE_OMIT_UTF16 */
5344 ** Usage: sqlite3_complete16 <UTF-16 string>
5346 ** Return 1 if the supplied argument is a complete SQL statement, or zero
5349 static int SQLITE_TCLAPI
test_complete16(
5353 Tcl_Obj
*CONST objv
[]
5355 #if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16)
5359 Tcl_WrongNumArgs(interp
, 1, objv
, "<utf-16 sql>");
5363 zBuf
= (char*)Tcl_GetByteArrayFromObj(objv
[1], 0);
5364 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_complete16(zBuf
)));
5365 #endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */
5370 ** Usage: sqlite3_normalize SQL
5372 ** Return the normalized value for an SQL statement.
5374 static int SQLITE_TCLAPI
test_normalize(
5378 Tcl_Obj
*CONST objv
[]
5382 extern char *sqlite3_normalize(const char*);
5385 Tcl_WrongNumArgs(interp
, 1, objv
, "SQL");
5389 zSql
= (char*)Tcl_GetString(objv
[1]);
5390 zNorm
= sqlite3_normalize(zSql
);
5392 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zNorm
, -1));
5393 sqlite3_free(zNorm
);
5399 ** Usage: sqlite3_step STMT
5401 ** Advance the statement to the next row.
5403 static int SQLITE_TCLAPI
test_step(
5407 Tcl_Obj
*CONST objv
[]
5409 sqlite3_stmt
*pStmt
;
5413 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5414 Tcl_GetString(objv
[0]), " STMT", 0);
5418 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5419 rc
= sqlite3_step(pStmt
);
5421 /* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */
5422 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
5426 static int SQLITE_TCLAPI
test_sql(
5430 Tcl_Obj
*CONST objv
[]
5432 sqlite3_stmt
*pStmt
;
5435 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
5439 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5440 Tcl_SetResult(interp
, (char *)sqlite3_sql(pStmt
), TCL_VOLATILE
);
5443 static int SQLITE_TCLAPI
test_ex_sql(
5447 Tcl_Obj
*CONST objv
[]
5449 sqlite3_stmt
*pStmt
;
5453 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
5457 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5458 z
= sqlite3_expanded_sql(pStmt
);
5459 Tcl_SetResult(interp
, z
, TCL_VOLATILE
);
5463 #ifdef SQLITE_ENABLE_NORMALIZE
5464 static int SQLITE_TCLAPI
test_norm_sql(
5468 Tcl_Obj
*CONST objv
[]
5470 sqlite3_stmt
*pStmt
;
5473 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
5477 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5478 Tcl_SetResult(interp
, (char *)sqlite3_normalized_sql(pStmt
), TCL_VOLATILE
);
5481 #endif /* SQLITE_ENABLE_NORMALIZE */
5484 ** Usage: sqlite3_column_count STMT
5486 ** Return the number of columns returned by the sql statement STMT.
5488 static int SQLITE_TCLAPI
test_column_count(
5492 Tcl_Obj
*CONST objv
[]
5494 sqlite3_stmt
*pStmt
;
5497 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5498 Tcl_GetString(objv
[0]), " STMT column", 0);
5502 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5504 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_column_count(pStmt
)));
5509 ** Usage: sqlite3_column_type STMT column
5511 ** Return the type of the data in column 'column' of the current row.
5513 static int SQLITE_TCLAPI
test_column_type(
5517 Tcl_Obj
*CONST objv
[]
5519 sqlite3_stmt
*pStmt
;
5524 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5525 Tcl_GetString(objv
[0]), " STMT column", 0);
5529 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5530 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5532 tp
= sqlite3_column_type(pStmt
, col
);
5534 case SQLITE_INTEGER
:
5535 Tcl_SetResult(interp
, "INTEGER", TCL_STATIC
);
5538 Tcl_SetResult(interp
, "NULL", TCL_STATIC
);
5541 Tcl_SetResult(interp
, "FLOAT", TCL_STATIC
);
5544 Tcl_SetResult(interp
, "TEXT", TCL_STATIC
);
5547 Tcl_SetResult(interp
, "BLOB", TCL_STATIC
);
5557 ** Usage: sqlite3_column_int64 STMT column
5559 ** Return the data in column 'column' of the current row cast as an
5560 ** wide (64-bit) integer.
5562 static int SQLITE_TCLAPI
test_column_int64(
5566 Tcl_Obj
*CONST objv
[]
5568 sqlite3_stmt
*pStmt
;
5573 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5574 Tcl_GetString(objv
[0]), " STMT column", 0);
5578 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5579 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5581 iVal
= sqlite3_column_int64(pStmt
, col
);
5582 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(iVal
));
5587 ** Usage: sqlite3_column_blob STMT column
5589 static int SQLITE_TCLAPI
test_column_blob(
5593 Tcl_Obj
*CONST objv
[]
5595 sqlite3_stmt
*pStmt
;
5602 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5603 Tcl_GetString(objv
[0]), " STMT column", 0);
5607 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5608 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5610 len
= sqlite3_column_bytes(pStmt
, col
);
5611 pBlob
= sqlite3_column_blob(pStmt
, col
);
5612 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(pBlob
, len
));
5617 ** Usage: sqlite3_column_double STMT column
5619 ** Return the data in column 'column' of the current row cast as a double.
5621 static int SQLITE_TCLAPI
test_column_double(
5625 Tcl_Obj
*CONST objv
[]
5627 sqlite3_stmt
*pStmt
;
5632 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5633 Tcl_GetString(objv
[0]), " STMT column", 0);
5637 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5638 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5640 rVal
= sqlite3_column_double(pStmt
, col
);
5641 Tcl_SetObjResult(interp
, Tcl_NewDoubleObj(rVal
));
5646 ** Usage: sqlite3_data_count STMT
5648 ** Return the number of columns returned by the sql statement STMT.
5650 static int SQLITE_TCLAPI
test_data_count(
5654 Tcl_Obj
*CONST objv
[]
5656 sqlite3_stmt
*pStmt
;
5659 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5660 Tcl_GetString(objv
[0]), " STMT column", 0);
5664 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5666 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_data_count(pStmt
)));
5671 ** Usage: sqlite3_column_text STMT column
5673 ** Usage: sqlite3_column_decltype STMT column
5675 ** Usage: sqlite3_column_name STMT column
5677 static int SQLITE_TCLAPI
test_stmt_utf8(
5678 void * clientData
, /* Pointer to SQLite API function to be invoke */
5681 Tcl_Obj
*CONST objv
[]
5683 sqlite3_stmt
*pStmt
;
5685 const char *(*xFunc
)(sqlite3_stmt
*, int);
5688 xFunc
= (const char *(*)(sqlite3_stmt
*, int))clientData
;
5690 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5691 Tcl_GetString(objv
[0]), " STMT column", 0);
5695 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5696 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5697 zRet
= xFunc(pStmt
, col
);
5699 Tcl_SetResult(interp
, (char *)zRet
, 0);
5704 static int SQLITE_TCLAPI
test_global_recover(
5708 Tcl_Obj
*CONST objv
[]
5710 #ifndef SQLITE_OMIT_DEPRECATED
5713 Tcl_WrongNumArgs(interp
, 1, objv
, "");
5716 rc
= sqlite3_global_recover();
5717 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5723 ** Usage: sqlite3_column_text STMT column
5725 ** Usage: sqlite3_column_decltype STMT column
5727 ** Usage: sqlite3_column_name STMT column
5729 static int SQLITE_TCLAPI
test_stmt_utf16(
5730 void * clientData
, /* Pointer to SQLite API function to be invoked */
5733 Tcl_Obj
*CONST objv
[]
5735 #ifndef SQLITE_OMIT_UTF16
5736 sqlite3_stmt
*pStmt
;
5739 const void *zName16
;
5740 const void *(*xFunc
)(sqlite3_stmt
*, int);
5742 xFunc
= (const void *(*)(sqlite3_stmt
*, int))clientData
;
5744 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5745 Tcl_GetString(objv
[0]), " STMT column", 0);
5749 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5750 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5752 zName16
= xFunc(pStmt
, col
);
5755 const char *z
= zName16
;
5756 for(n
=0; z
[n
] || z
[n
+1]; n
+=2){}
5757 pRet
= Tcl_NewByteArrayObj(zName16
, n
+2);
5758 Tcl_SetObjResult(interp
, pRet
);
5760 #endif /* SQLITE_OMIT_UTF16 */
5766 ** Usage: sqlite3_column_int STMT column
5768 ** Usage: sqlite3_column_bytes STMT column
5770 ** Usage: sqlite3_column_bytes16 STMT column
5773 static int SQLITE_TCLAPI
test_stmt_int(
5774 void * clientData
, /* Pointer to SQLite API function to be invoked */
5777 Tcl_Obj
*CONST objv
[]
5779 sqlite3_stmt
*pStmt
;
5781 int (*xFunc
)(sqlite3_stmt
*, int);
5783 xFunc
= (int (*)(sqlite3_stmt
*, int))clientData
;
5785 Tcl_AppendResult(interp
, "wrong # args: should be \"",
5786 Tcl_GetString(objv
[0]), " STMT column", 0);
5790 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
5791 if( Tcl_GetIntFromObj(interp
, objv
[2], &col
) ) return TCL_ERROR
;
5793 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xFunc(pStmt
, col
)));
5798 ** Usage: sqlite3_interrupt DB
5800 ** Trigger an interrupt on DB
5802 static int SQLITE_TCLAPI
test_interrupt(
5810 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB", 0);
5813 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5814 sqlite3_interrupt(db
);
5819 ** Usage: sqlite3_is_interrupted DB
5821 ** return true if an interrupt is current in effect on DB
5823 static int SQLITE_TCLAPI
test_is_interrupted(
5832 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0], " DB", 0);
5835 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5836 rc
= sqlite3_is_interrupted(db
);
5837 Tcl_AppendResult(interp
, rc
? "1" : "0", (void*)0);
5842 ** Usage: sqlite_delete_function DB function-name
5844 ** Delete the user function 'function-name' from database handle DB. It
5845 ** is assumed that the user function was created as UTF8, any number of
5846 ** arguments (the way the TCL interface does it).
5848 static int SQLITE_TCLAPI
delete_function(
5857 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5858 " DB function-name", 0);
5861 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5862 rc
= sqlite3_create_function(db
, argv
[2], -1, SQLITE_UTF8
, 0, 0, 0, 0);
5863 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5868 ** Usage: sqlite_delete_collation DB collation-name
5870 ** Delete the collation sequence 'collation-name' from database handle
5871 ** DB. It is assumed that the collation sequence was created as UTF8 (the
5872 ** way the TCL interface does it).
5874 static int SQLITE_TCLAPI
delete_collation(
5883 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5884 " DB function-name", 0);
5887 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5888 rc
= sqlite3_create_collation(db
, argv
[2], SQLITE_UTF8
, 0, 0);
5889 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
5894 ** Usage: sqlite3_get_autocommit DB
5896 ** Return true if the database DB is currently in auto-commit mode.
5897 ** Return false if not.
5899 static int SQLITE_TCLAPI
get_autocommit(
5908 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5912 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5913 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d", sqlite3_get_autocommit(db
));
5914 Tcl_AppendResult(interp
, zBuf
, 0);
5919 ** Usage: sqlite3_busy_timeout DB MS
5921 ** Set the busy timeout. This is more easily done using the timeout
5922 ** method of the TCL interface. But we need a way to test the case
5923 ** where it returns SQLITE_MISUSE.
5925 static int SQLITE_TCLAPI
test_busy_timeout(
5934 Tcl_AppendResult(interp
, "wrong # args: should be \"", argv
[0],
5938 if( getDbPointer(interp
, argv
[1], &db
) ) return TCL_ERROR
;
5939 if( Tcl_GetInt(interp
, argv
[2], &ms
) ) return TCL_ERROR
;
5940 rc
= sqlite3_busy_timeout(db
, ms
);
5941 Tcl_AppendResult(interp
, sqlite3ErrName(rc
), 0);
5946 ** Usage: tcl_variable_type VARIABLENAME
5948 ** Return the name of the internal representation for the
5949 ** value of the given variable.
5951 static int SQLITE_TCLAPI
tcl_variable_type(
5955 Tcl_Obj
*CONST objv
[]
5959 Tcl_WrongNumArgs(interp
, 1, objv
, "VARIABLE");
5962 pVar
= Tcl_GetVar2Ex(interp
, Tcl_GetString(objv
[1]), 0, TCL_LEAVE_ERR_MSG
);
5963 if( pVar
==0 ) return TCL_ERROR
;
5964 if( pVar
->typePtr
){
5965 Tcl_SetObjResult(interp
, Tcl_NewStringObj(pVar
->typePtr
->name
, -1));
5971 ** Usage: sqlite3_release_memory ?N?
5973 ** Attempt to release memory currently held but not actually required.
5974 ** The integer N is the number of bytes we are trying to release. The
5975 ** return value is the amount of memory actually released.
5977 static int SQLITE_TCLAPI
test_release_memory(
5981 Tcl_Obj
*CONST objv
[]
5983 #if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
5986 if( objc
!=1 && objc
!=2 ){
5987 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
5991 if( Tcl_GetIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
5995 amt
= sqlite3_release_memory(N
);
5996 Tcl_SetObjResult(interp
, Tcl_NewIntObj(amt
));
6003 ** Usage: sqlite3_db_release_memory DB
6005 ** Attempt to release memory currently held by database DB. Return the
6006 ** result code (which in the current implementation is always zero).
6008 static int SQLITE_TCLAPI
test_db_release_memory(
6012 Tcl_Obj
*CONST objv
[]
6017 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
6020 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6021 rc
= sqlite3_db_release_memory(db
);
6022 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6027 ** Usage: sqlite3_db_cacheflush DB
6029 ** Attempt to flush any dirty pages to disk.
6031 static int SQLITE_TCLAPI
test_db_cacheflush(
6035 Tcl_Obj
*CONST objv
[]
6040 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
6043 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6044 rc
= sqlite3_db_cacheflush(db
);
6046 Tcl_SetResult(interp
, (char *)sqlite3ErrStr(rc
), TCL_STATIC
);
6050 Tcl_ResetResult(interp
);
6055 ** Usage: sqlite3_system_errno DB
6057 ** Return the low-level system errno value.
6059 static int SQLITE_TCLAPI
test_system_errno(
6063 Tcl_Obj
*CONST objv
[]
6068 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
6071 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6072 iErrno
= sqlite3_system_errno(db
);
6073 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iErrno
));
6078 ** Usage: sqlite3_db_filename DB DBNAME
6080 ** Return the name of a file associated with a database.
6082 static int SQLITE_TCLAPI
test_db_filename(
6086 Tcl_Obj
*CONST objv
[]
6089 const char *zDbName
;
6091 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
6094 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6095 zDbName
= Tcl_GetString(objv
[2]);
6096 Tcl_AppendResult(interp
, sqlite3_db_filename(db
, zDbName
), (void*)0);
6101 ** Usage: sqlite3_db_readonly DB DBNAME
6103 ** Return 1 or 0 if DBNAME is readonly or not. Return -1 if DBNAME does
6106 static int SQLITE_TCLAPI
test_db_readonly(
6110 Tcl_Obj
*CONST objv
[]
6113 const char *zDbName
;
6115 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME");
6118 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6119 zDbName
= Tcl_GetString(objv
[2]);
6120 Tcl_SetObjResult(interp
, Tcl_NewIntObj(sqlite3_db_readonly(db
, zDbName
)));
6125 ** Usage: sqlite3_soft_heap_limit ?N?
6127 ** Query or set the soft heap limit for the current thread. The
6128 ** limit is only changed if the N is present. The previous limit
6131 static int SQLITE_TCLAPI
test_soft_heap_limit(
6135 Tcl_Obj
*CONST objv
[]
6139 if( objc
!=1 && objc
!=2 ){
6140 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
6144 if( Tcl_GetWideIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
6146 amt
= sqlite3_soft_heap_limit64(N
);
6147 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(amt
));
6152 ** Usage: sqlite3_hard_heap_limit ?N?
6154 ** Query or set the hard heap limit for the current thread. The
6155 ** limit is only changed if the N is present. The previous limit
6158 static int SQLITE_TCLAPI
test_hard_heap_limit(
6162 Tcl_Obj
*CONST objv
[]
6166 if( objc
!=1 && objc
!=2 ){
6167 Tcl_WrongNumArgs(interp
, 1, objv
, "?N?");
6171 if( Tcl_GetWideIntFromObj(interp
, objv
[1], &N
) ) return TCL_ERROR
;
6173 amt
= sqlite3_hard_heap_limit64(N
);
6174 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(amt
));
6179 ** Usage: sqlite3_thread_cleanup
6181 ** Call the sqlite3_thread_cleanup API.
6183 static int SQLITE_TCLAPI
test_thread_cleanup(
6187 Tcl_Obj
*CONST objv
[]
6189 #ifndef SQLITE_OMIT_DEPRECATED
6190 sqlite3_thread_cleanup();
6196 ** Usage: sqlite3_pager_refcounts DB
6198 ** Return a list of numbers which are the PagerRefcount for all
6199 ** pagers on each database connection.
6201 static int SQLITE_TCLAPI
test_pager_refcounts(
6205 Tcl_Obj
*CONST objv
[]
6213 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6214 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6217 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6218 pResult
= Tcl_NewObj();
6219 for(i
=0; i
<db
->nDb
; i
++){
6220 if( db
->aDb
[i
].pBt
==0 ){
6223 sqlite3_mutex_enter(db
->mutex
);
6224 a
= sqlite3PagerStats(sqlite3BtreePager(db
->aDb
[i
].pBt
));
6226 sqlite3_mutex_leave(db
->mutex
);
6228 Tcl_ListObjAppendElement(0, pResult
, Tcl_NewIntObj(v
));
6230 Tcl_SetObjResult(interp
, pResult
);
6236 ** tclcmd: working_64bit_int
6238 ** Some TCL builds (ex: cygwin) do not support 64-bit integers. This
6239 ** leads to a number of test failures. The present command checks the
6240 ** TCL build to see whether or not it supports 64-bit integers. It
6241 ** returns TRUE if it does and FALSE if not.
6243 ** This command is used to warn users that their TCL build is defective
6244 ** and that the errors they are seeing in the test scripts might be
6245 ** a result of their defective TCL rather than problems in SQLite.
6247 static int SQLITE_TCLAPI
working_64bit_int(
6248 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6249 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6250 int objc
, /* Number of arguments */
6251 Tcl_Obj
*CONST objv
[] /* Command arguments */
6256 pTestObj
= Tcl_NewWideIntObj(1000000*(i64
)1234567890);
6257 working
= strcmp(Tcl_GetString(pTestObj
), "1234567890000000")==0;
6258 Tcl_DecrRefCount(pTestObj
);
6259 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(working
));
6265 ** tclcmd: vfs_unlink_test
6267 ** This TCL command unregisters the primary VFS and then registers
6268 ** it back again. This is used to test the ability to register a
6269 ** VFS when none are previously registered, and the ability to
6270 ** unregister the only available VFS. Ticket #2738
6272 static int SQLITE_TCLAPI
vfs_unlink_test(
6273 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6274 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6275 int objc
, /* Number of arguments */
6276 Tcl_Obj
*CONST objv
[] /* Command arguments */
6280 sqlite3_vfs
*apVfs
[20];
6281 sqlite3_vfs one
, two
;
6283 sqlite3_vfs_unregister(0); /* Unregister of NULL is harmless */
6284 one
.zName
= "__one";
6285 two
.zName
= "__two";
6287 /* Calling sqlite3_vfs_register with 2nd argument of 0 does not
6288 ** change the default VFS
6290 pMain
= sqlite3_vfs_find(0);
6291 sqlite3_vfs_register(&one
, 0);
6292 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
6293 sqlite3_vfs_register(&two
, 0);
6294 assert( pMain
==0 || pMain
==sqlite3_vfs_find(0) );
6296 /* We can find a VFS by its name */
6297 assert( sqlite3_vfs_find("__one")==&one
);
6298 assert( sqlite3_vfs_find("__two")==&two
);
6300 /* Calling sqlite_vfs_register with non-zero second parameter changes the
6301 ** default VFS, even if the 1st parameter is an existing VFS that is
6302 ** previously registered as the non-default.
6304 sqlite3_vfs_register(&one
, 1);
6305 assert( sqlite3_vfs_find("__one")==&one
);
6306 assert( sqlite3_vfs_find("__two")==&two
);
6307 assert( sqlite3_vfs_find(0)==&one
);
6308 sqlite3_vfs_register(&two
, 1);
6309 assert( sqlite3_vfs_find("__one")==&one
);
6310 assert( sqlite3_vfs_find("__two")==&two
);
6311 assert( sqlite3_vfs_find(0)==&two
);
6313 sqlite3_vfs_register(pMain
, 1);
6314 assert( sqlite3_vfs_find("__one")==&one
);
6315 assert( sqlite3_vfs_find("__two")==&two
);
6316 assert( sqlite3_vfs_find(0)==pMain
);
6319 /* Unlink the default VFS. Repeat until there are no more VFSes
6322 for(i
=0; i
<sizeof(apVfs
)/sizeof(apVfs
[0]); i
++){
6323 apVfs
[i
] = sqlite3_vfs_find(0);
6325 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
6326 sqlite3_vfs_unregister(apVfs
[i
]);
6327 assert( 0==sqlite3_vfs_find(apVfs
[i
]->zName
) );
6330 assert( 0==sqlite3_vfs_find(0) );
6332 /* Register the main VFS as non-default (will be made default, since
6333 ** it'll be the only one in existence).
6335 sqlite3_vfs_register(pMain
, 0);
6336 assert( sqlite3_vfs_find(0)==pMain
);
6338 /* Un-register the main VFS again to restore an empty VFS list */
6339 sqlite3_vfs_unregister(pMain
);
6340 assert( 0==sqlite3_vfs_find(0) );
6342 /* Relink all VFSes in reverse order. */
6343 for(i
=sizeof(apVfs
)/sizeof(apVfs
[0])-1; i
>=0; i
--){
6345 sqlite3_vfs_register(apVfs
[i
], 1);
6346 assert( apVfs
[i
]==sqlite3_vfs_find(0) );
6347 assert( apVfs
[i
]==sqlite3_vfs_find(apVfs
[i
]->zName
) );
6351 /* Unregister out sample VFSes. */
6352 sqlite3_vfs_unregister(&one
);
6353 sqlite3_vfs_unregister(&two
);
6355 /* Unregistering a VFS that is not currently registered is harmless */
6356 sqlite3_vfs_unregister(&one
);
6357 sqlite3_vfs_unregister(&two
);
6358 assert( sqlite3_vfs_find("__one")==0 );
6359 assert( sqlite3_vfs_find("__two")==0 );
6361 /* We should be left with the original default VFS back as the
6363 assert( sqlite3_vfs_find(0)==pMain
);
6369 ** tclcmd: vfs_initfail_test
6371 ** This TCL command attempts to vfs_find and vfs_register when the
6372 ** sqlite3_initialize() interface is failing. All calls should fail.
6374 static int SQLITE_TCLAPI
vfs_initfail_test(
6375 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6376 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6377 int objc
, /* Number of arguments */
6378 Tcl_Obj
*CONST objv
[] /* Command arguments */
6381 one
.zName
= "__one";
6383 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
6384 sqlite3_vfs_register(&one
, 0);
6385 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
6386 sqlite3_vfs_register(&one
, 1);
6387 if( sqlite3_vfs_find(0) ) return TCL_ERROR
;
6394 static sqlite3_vfs
*apVfs
[20];
6395 static int nVfs
= 0;
6398 ** tclcmd: vfs_unregister_all
6400 ** Unregister all VFSes.
6402 static int SQLITE_TCLAPI
vfs_unregister_all(
6403 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6404 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6405 int objc
, /* Number of arguments */
6406 Tcl_Obj
*CONST objv
[] /* Command arguments */
6409 for(i
=0; i
<ArraySize(apVfs
); i
++){
6410 apVfs
[i
] = sqlite3_vfs_find(0);
6411 if( apVfs
[i
]==0 ) break;
6412 sqlite3_vfs_unregister(apVfs
[i
]);
6418 ** tclcmd: vfs_reregister_all
6420 ** Restore all VFSes that were removed using vfs_unregister_all. Taking
6421 ** care to put the linked list back together in the same order as it was
6422 ** in before vfs_unregister_all was invoked.
6424 static int SQLITE_TCLAPI
vfs_reregister_all(
6425 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6426 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6427 int objc
, /* Number of arguments */
6428 Tcl_Obj
*CONST objv
[] /* Command arguments */
6431 for(i
=nVfs
-1; i
>=0; i
--){
6432 sqlite3_vfs_register(apVfs
[i
], 1);
6439 ** tclcmd: file_control_test DB
6441 ** This TCL command runs the sqlite3_file_control interface and
6442 ** verifies correct operation of the same.
6444 static int SQLITE_TCLAPI
file_control_test(
6445 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6446 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6447 int objc
, /* Number of arguments */
6448 Tcl_Obj
*CONST objv
[] /* Command arguments */
6455 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6456 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6459 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
6460 rc
= sqlite3_file_control(db
, 0, 0, &iArg
);
6461 assert( rc
==SQLITE_NOTFOUND
);
6462 rc
= sqlite3_file_control(db
, "notadatabase", SQLITE_FCNTL_LOCKSTATE
, &iArg
);
6463 assert( rc
==SQLITE_ERROR
);
6464 rc
= sqlite3_file_control(db
, "main", -1, &iArg
);
6465 assert( rc
==SQLITE_NOTFOUND
);
6466 rc
= sqlite3_file_control(db
, "temp", -1, &iArg
);
6467 assert( rc
==SQLITE_NOTFOUND
|| rc
==SQLITE_ERROR
);
6474 ** tclcmd: file_control_lasterrno_test DB
6476 ** This TCL command runs the sqlite3_file_control interface and
6477 ** verifies correct operation of the SQLITE_LAST_ERRNO verb.
6479 static int SQLITE_TCLAPI
file_control_lasterrno_test(
6480 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6481 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6482 int objc
, /* Number of arguments */
6483 Tcl_Obj
*CONST objv
[] /* Command arguments */
6490 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6491 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6494 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6497 rc
= sqlite3_file_control(db
, NULL
, SQLITE_LAST_ERRNO
, &iArg
);
6499 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6503 Tcl_AppendResult(interp
, "Unexpected non-zero errno: ",
6504 Tcl_GetStringFromObj(Tcl_NewIntObj(iArg
), 0), " ", 0);
6511 ** tclcmd: file_control_data_version DB DBNAME
6513 ** This TCL command runs the sqlite3_file_control with the
6514 ** SQLITE_FCNTL_DATA_VERSION opcode, returning the result.
6516 static int SQLITE_TCLAPI
file_control_data_version(
6517 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6518 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6519 int objc
, /* Number of arguments */
6520 Tcl_Obj
*CONST objv
[] /* Command arguments */
6522 unsigned int iVers
; /* data version */
6523 char *zDb
; /* Db name ("main", "temp" etc.) */
6524 sqlite3
*db
; /* Database handle */
6525 int rc
; /* file_control() return code */
6528 if( objc
!=3 && objc
!=2 ){
6529 Tcl_WrongNumArgs(interp
, 1, objv
, "DB [DBNAME]");
6532 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6535 zDb
= objc
==3 ? Tcl_GetString(objv
[2]) : NULL
;
6537 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_DATA_VERSION
, (void *)&iVers
);
6539 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
6542 sqlite3_snprintf(sizeof(zBuf
),zBuf
,"%u",iVers
);
6543 Tcl_SetResult(interp
, (char *)zBuf
, TCL_VOLATILE
);
6549 ** tclcmd: file_control_chunksize_test DB DBNAME SIZE
6551 ** This TCL command runs the sqlite3_file_control interface and
6552 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
6553 ** SQLITE_SET_LOCKPROXYFILE verbs.
6555 static int SQLITE_TCLAPI
file_control_chunksize_test(
6556 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6557 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6558 int objc
, /* Number of arguments */
6559 Tcl_Obj
*CONST objv
[] /* Command arguments */
6561 int nSize
; /* New chunk size */
6562 char *zDb
; /* Db name ("main", "temp" etc.) */
6563 sqlite3
*db
; /* Database handle */
6564 int rc
; /* file_control() return code */
6567 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
6570 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6571 || Tcl_GetIntFromObj(interp
, objv
[3], &nSize
)
6575 zDb
= Tcl_GetString(objv
[2]);
6576 if( zDb
[0]=='\0' ) zDb
= NULL
;
6578 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_CHUNK_SIZE
, (void *)&nSize
);
6580 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
6587 ** tclcmd: file_control_sizehint_test DB DBNAME SIZE
6589 ** This TCL command runs the sqlite3_file_control interface
6590 ** with SQLITE_FCNTL_SIZE_HINT
6592 static int SQLITE_TCLAPI
file_control_sizehint_test(
6593 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6594 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6595 int objc
, /* Number of arguments */
6596 Tcl_Obj
*CONST objv
[] /* Command arguments */
6598 Tcl_WideInt nSize
; /* Hinted size */
6599 char *zDb
; /* Db name ("main", "temp" etc.) */
6600 sqlite3
*db
; /* Database handle */
6601 int rc
; /* file_control() return code */
6604 Tcl_WrongNumArgs(interp
, 1, objv
, "DB DBNAME SIZE");
6607 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6608 || Tcl_GetWideIntFromObj(interp
, objv
[3], &nSize
)
6612 zDb
= Tcl_GetString(objv
[2]);
6613 if( zDb
[0]=='\0' ) zDb
= NULL
;
6615 rc
= sqlite3_file_control(db
, zDb
, SQLITE_FCNTL_SIZE_HINT
, (void *)&nSize
);
6617 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_STATIC
);
6624 ** tclcmd: file_control_lockproxy_test DB PWD
6626 ** This TCL command runs the sqlite3_file_control interface and
6627 ** verifies correct operation of the SQLITE_GET_LOCKPROXYFILE and
6628 ** SQLITE_SET_LOCKPROXYFILE verbs.
6630 static int SQLITE_TCLAPI
file_control_lockproxy_test(
6631 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6632 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6633 int objc
, /* Number of arguments */
6634 Tcl_Obj
*CONST objv
[] /* Command arguments */
6639 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6640 Tcl_GetStringFromObj(objv
[0], 0), " DB PWD", 0);
6643 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6647 #if !defined(SQLITE_ENABLE_LOCKING_STYLE)
6648 # if defined(__APPLE__)
6649 # define SQLITE_ENABLE_LOCKING_STYLE 1
6651 # define SQLITE_ENABLE_LOCKING_STYLE 0
6654 #if SQLITE_ENABLE_LOCKING_STYLE && defined(__APPLE__)
6660 char proxyPath
[400];
6662 zPwd
= Tcl_GetStringFromObj(objv
[2], &nPwd
);
6663 if( sizeof(proxyPath
)<nPwd
+20 ){
6664 Tcl_AppendResult(interp
, "PWD too big", (void*)0);
6667 sqlite3_snprintf(sizeof(proxyPath
), proxyPath
, "%s/test.proxy", zPwd
);
6668 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
6670 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6673 rc
= sqlite3_file_control(db
, NULL
, SQLITE_GET_LOCKPROXYFILE
, &testPath
);
6674 if( strncmp(proxyPath
,testPath
,11) ){
6675 Tcl_AppendResult(interp
, "Lock proxy file did not match the "
6676 "previously assigned value", 0);
6680 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6683 rc
= sqlite3_file_control(db
, NULL
, SQLITE_SET_LOCKPROXYFILE
, proxyPath
);
6685 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
6695 ** tclcmd: file_control_win32_av_retry DB NRETRY DELAY
6697 ** This TCL command runs the sqlite3_file_control interface with
6698 ** the SQLITE_FCNTL_WIN32_AV_RETRY opcode.
6700 static int SQLITE_TCLAPI
file_control_win32_av_retry(
6701 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6702 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6703 int objc
, /* Number of arguments */
6704 Tcl_Obj
*CONST objv
[] /* Command arguments */
6712 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6713 Tcl_GetStringFromObj(objv
[0], 0), " DB NRETRY DELAY", 0);
6716 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6719 if( Tcl_GetIntFromObj(interp
, objv
[2], &a
[0]) ) return TCL_ERROR
;
6720 if( Tcl_GetIntFromObj(interp
, objv
[3], &a
[1]) ) return TCL_ERROR
;
6721 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_AV_RETRY
, (void*)a
);
6722 sqlite3_snprintf(sizeof(z
), z
, "%d %d %d", rc
, a
[0], a
[1]);
6723 Tcl_AppendResult(interp
, z
, (char*)0);
6728 ** tclcmd: file_control_win32_get_handle DB
6730 ** This TCL command runs the sqlite3_file_control interface with
6731 ** the SQLITE_FCNTL_WIN32_GET_HANDLE opcode.
6733 static int file_control_win32_get_handle(
6734 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6735 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6736 int objc
, /* Number of arguments */
6737 Tcl_Obj
*CONST objv
[] /* Command arguments */
6741 HANDLE hFile
= NULL
;
6745 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6746 Tcl_GetStringFromObj(objv
[0], 0), " DB", 0);
6749 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6752 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_GET_HANDLE
,
6754 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
6755 Tcl_AppendResult(interp
, z
, (char*)0);
6760 ** tclcmd: file_control_win32_set_handle DB HANDLE
6762 ** This TCL command runs the sqlite3_file_control interface with
6763 ** the SQLITE_FCNTL_WIN32_SET_HANDLE opcode.
6765 static int SQLITE_TCLAPI
file_control_win32_set_handle(
6766 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6767 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6768 int objc
, /* Number of arguments */
6769 Tcl_Obj
*CONST objv
[] /* Command arguments */
6773 HANDLE hFile
= NULL
;
6777 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6778 Tcl_GetStringFromObj(objv
[0], 0), " DB HANDLE", 0);
6781 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6784 if( getWin32Handle(interp
, Tcl_GetString(objv
[2]), &hFile
) ){
6787 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_WIN32_SET_HANDLE
,
6789 sqlite3_snprintf(sizeof(z
), z
, "%d %p", rc
, (void*)hFile
);
6790 Tcl_AppendResult(interp
, z
, (char*)0);
6796 ** tclcmd: file_control_persist_wal DB PERSIST-FLAG
6798 ** This TCL command runs the sqlite3_file_control interface with
6799 ** the SQLITE_FCNTL_PERSIST_WAL opcode.
6801 static int SQLITE_TCLAPI
file_control_persist_wal(
6802 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6803 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6804 int objc
, /* Number of arguments */
6805 Tcl_Obj
*CONST objv
[] /* Command arguments */
6813 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6814 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
6817 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6820 if( Tcl_GetIntFromObj(interp
, objv
[2], &bPersist
) ) return TCL_ERROR
;
6821 rc
= sqlite3_file_control(db
, NULL
, SQLITE_FCNTL_PERSIST_WAL
, (void*)&bPersist
);
6822 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, bPersist
);
6823 Tcl_AppendResult(interp
, z
, (char*)0);
6828 ** tclcmd: file_control_powersafe_overwrite DB PSOW-FLAG
6830 ** This TCL command runs the sqlite3_file_control interface with
6831 ** the SQLITE_FCNTL_POWERSAFE_OVERWRITE opcode.
6833 static int SQLITE_TCLAPI
file_control_powersafe_overwrite(
6834 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6835 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6836 int objc
, /* Number of arguments */
6837 Tcl_Obj
*CONST objv
[] /* Command arguments */
6845 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6846 Tcl_GetStringFromObj(objv
[0], 0), " DB FLAG", 0);
6849 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6852 if( Tcl_GetIntFromObj(interp
, objv
[2], &b
) ) return TCL_ERROR
;
6853 rc
= sqlite3_file_control(db
,NULL
,SQLITE_FCNTL_POWERSAFE_OVERWRITE
,(void*)&b
);
6854 sqlite3_snprintf(sizeof(z
), z
, "%d %d", rc
, b
);
6855 Tcl_AppendResult(interp
, z
, (char*)0);
6861 ** tclcmd: file_control_vfsname DB ?AUXDB?
6863 ** Return a string that describes the stack of VFSes.
6865 static int SQLITE_TCLAPI
file_control_vfsname(
6866 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6867 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6868 int objc
, /* Number of arguments */
6869 Tcl_Obj
*CONST objv
[] /* Command arguments */
6872 const char *zDbName
= "main";
6875 if( objc
!=2 && objc
!=3 ){
6876 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6877 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6880 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6884 zDbName
= Tcl_GetString(objv
[2]);
6886 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_VFSNAME
,(void*)&zVfsName
);
6887 Tcl_AppendResult(interp
, zVfsName
, (char*)0);
6888 sqlite3_free(zVfsName
);
6893 ** tclcmd: file_control_reservebytes DB N
6895 static int SQLITE_TCLAPI
file_control_reservebytes(
6896 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6897 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6898 int objc
, /* Number of arguments */
6899 Tcl_Obj
*CONST objv
[] /* Command arguments */
6902 const char *zDbName
= "main";
6907 Tcl_WrongNumArgs(interp
, 1, objv
, "DB N");
6910 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
6911 || Tcl_GetIntFromObj(interp
, objv
[2], &n
)
6916 rc
= sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_RESERVE_BYTES
, (void*)&n
);
6917 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
6923 ** tclcmd: file_control_tempfilename DB ?AUXDB?
6925 ** Return a string that is a temporary filename
6927 static int SQLITE_TCLAPI
file_control_tempfilename(
6928 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6929 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6930 int objc
, /* Number of arguments */
6931 Tcl_Obj
*CONST objv
[] /* Command arguments */
6934 const char *zDbName
= "main";
6937 if( objc
!=2 && objc
!=3 ){
6938 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6939 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6942 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6946 zDbName
= Tcl_GetString(objv
[2]);
6948 sqlite3_file_control(db
, zDbName
, SQLITE_FCNTL_TEMPFILENAME
, (void*)&zTName
);
6949 Tcl_AppendResult(interp
, zTName
, (char*)0);
6950 sqlite3_free(zTName
);
6955 ** tclcmd: file_control_external_reader DB ?AUXDB?
6957 ** Return a string that is a temporary filename
6959 static int SQLITE_TCLAPI
file_control_external_reader(
6960 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6961 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6962 int objc
, /* Number of arguments */
6963 Tcl_Obj
*CONST objv
[] /* Command arguments */
6966 const char *zName
= "main";
6970 if( objc
!=2 && objc
!=3 ){
6971 Tcl_AppendResult(interp
, "wrong # args: should be \"",
6972 Tcl_GetStringFromObj(objv
[0], 0), " DB ?AUXDB?", 0);
6975 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
6979 zName
= Tcl_GetString(objv
[2]);
6981 rc
= sqlite3_file_control(db
, zName
, SQLITE_FCNTL_EXTERNAL_READER
, &iRes
);
6982 if( rc
!=SQLITE_OK
){
6983 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
6986 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iRes
));
6992 ** tclcmd: sqlite3_vfs_list
6994 ** Return a tcl list containing the names of all registered vfs's.
6996 static int SQLITE_TCLAPI
vfs_list(
6997 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
6998 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
6999 int objc
, /* Number of arguments */
7000 Tcl_Obj
*CONST objv
[] /* Command arguments */
7003 Tcl_Obj
*pRet
= Tcl_NewObj();
7005 Tcl_WrongNumArgs(interp
, 1, objv
, "");
7008 for(pVfs
=sqlite3_vfs_find(0); pVfs
; pVfs
=pVfs
->pNext
){
7009 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj(pVfs
->zName
, -1));
7011 Tcl_SetObjResult(interp
, pRet
);
7016 ** tclcmd: sqlite3_limit DB ID VALUE
7018 ** This TCL command runs the sqlite3_limit interface and
7019 ** verifies correct operation of the same.
7021 static int SQLITE_TCLAPI
test_limit(
7022 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7023 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7024 int objc
, /* Number of arguments */
7025 Tcl_Obj
*CONST objv
[] /* Command arguments */
7029 static const struct {
7033 { "SQLITE_LIMIT_LENGTH", SQLITE_LIMIT_LENGTH
},
7034 { "SQLITE_LIMIT_SQL_LENGTH", SQLITE_LIMIT_SQL_LENGTH
},
7035 { "SQLITE_LIMIT_COLUMN", SQLITE_LIMIT_COLUMN
},
7036 { "SQLITE_LIMIT_EXPR_DEPTH", SQLITE_LIMIT_EXPR_DEPTH
},
7037 { "SQLITE_LIMIT_COMPOUND_SELECT", SQLITE_LIMIT_COMPOUND_SELECT
},
7038 { "SQLITE_LIMIT_VDBE_OP", SQLITE_LIMIT_VDBE_OP
},
7039 { "SQLITE_LIMIT_FUNCTION_ARG", SQLITE_LIMIT_FUNCTION_ARG
},
7040 { "SQLITE_LIMIT_ATTACHED", SQLITE_LIMIT_ATTACHED
},
7041 { "SQLITE_LIMIT_LIKE_PATTERN_LENGTH", SQLITE_LIMIT_LIKE_PATTERN_LENGTH
},
7042 { "SQLITE_LIMIT_VARIABLE_NUMBER", SQLITE_LIMIT_VARIABLE_NUMBER
},
7043 { "SQLITE_LIMIT_TRIGGER_DEPTH", SQLITE_LIMIT_TRIGGER_DEPTH
},
7044 { "SQLITE_LIMIT_WORKER_THREADS", SQLITE_LIMIT_WORKER_THREADS
},
7046 /* Out of range test cases */
7047 { "SQLITE_LIMIT_TOOSMALL", -1, },
7048 { "SQLITE_LIMIT_TOOBIG", SQLITE_LIMIT_WORKER_THREADS
+1 },
7055 Tcl_AppendResult(interp
, "wrong # args: should be \"",
7056 Tcl_GetStringFromObj(objv
[0], 0), " DB ID VALUE", 0);
7059 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
7060 zId
= Tcl_GetString(objv
[2]);
7061 for(i
=0; i
<sizeof(aId
)/sizeof(aId
[0]); i
++){
7062 if( strcmp(zId
, aId
[i
].zName
)==0 ){
7067 if( i
>=sizeof(aId
)/sizeof(aId
[0]) ){
7068 Tcl_AppendResult(interp
, "unknown limit type: ", zId
, (char*)0);
7071 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
7072 rc
= sqlite3_limit(db
, id
, val
);
7073 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
7078 ** tclcmd: save_prng_state
7080 ** Save the state of the pseudo-random number generator.
7081 ** At the same time, verify that sqlite3_test_control works even when
7082 ** called with an out-of-range opcode.
7084 static int SQLITE_TCLAPI
save_prng_state(
7085 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7086 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7087 int objc
, /* Number of arguments */
7088 Tcl_Obj
*CONST objv
[] /* Command arguments */
7090 int rc
= sqlite3_test_control(9999);
7092 rc
= sqlite3_test_control(-1);
7094 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SAVE
);
7098 ** tclcmd: restore_prng_state
7100 static int SQLITE_TCLAPI
restore_prng_state(
7101 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7102 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7103 int objc
, /* Number of arguments */
7104 Tcl_Obj
*CONST objv
[] /* Command arguments */
7106 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_RESTORE
);
7110 ** tclcmd: reset_prng_state
7112 static int SQLITE_TCLAPI
reset_prng_state(
7113 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7114 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7115 int objc
, /* Number of arguments */
7116 Tcl_Obj
*CONST objv
[] /* Command arguments */
7118 sqlite3_randomness(0,0);
7122 ** tclcmd: prng_seed INT ?DB?
7124 ** Set up the SQLITE_TESTCTRL_PRNG_SEED pragma with parameter INT and DB.
7125 ** INT is an integer. DB is a database connection, or a NULL pointer if
7128 ** When INT!=0 and DB!=0, set the PRNG seed to the value of the schema
7129 ** cookie for DB, or to INT if the schema cookie happens to be zero.
7131 ** When INT!=0 and DB==0, set the PRNG seed to just INT.
7133 ** If INT==0 and DB==0 then use the default procedure of calling the
7134 ** xRandomness method on the default VFS to get the PRNG seed.
7136 static int SQLITE_TCLAPI
prng_seed(
7137 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7138 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7139 int objc
, /* Number of arguments */
7140 Tcl_Obj
*CONST objv
[] /* Command arguments */
7144 if( objc
!=2 && objc
!=3 ){
7145 Tcl_WrongNumArgs(interp
, 1, objv
, "SEED ?DB?");
7148 if( Tcl_GetIntFromObj(interp
,objv
[1],&i
) ) return TCL_ERROR
;
7149 if( objc
==3 && getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ){
7152 sqlite3_test_control(SQLITE_TESTCTRL_PRNG_SEED
, i
, db
);
7157 ** tclcmd: extra_schema_checks BOOLEAN
7159 ** Enable or disable schema checks when parsing the sqlite_schema file.
7160 ** This is always enabled in production, but it is sometimes useful to
7161 ** disable the checks in order to make some internal error states reachable
7164 static int SQLITE_TCLAPI
extra_schema_checks(
7165 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7166 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7167 int objc
, /* Number of arguments */
7168 Tcl_Obj
*CONST objv
[] /* Command arguments */
7172 Tcl_WrongNumArgs(interp
, 1, objv
, "BOOLEAN");
7175 if( Tcl_GetBooleanFromObj(interp
,objv
[1],&i
) ) return TCL_ERROR
;
7176 sqlite3_test_control(SQLITE_TESTCTRL_EXTRA_SCHEMA_CHECKS
, i
);
7181 ** tclcmd: use_long_double BOOLEAN|"default"
7183 ** If no argument, report the current value of the use-long-double flag.
7185 ** If argument is "default", set the use-long-double flag to the default
7186 ** value for this build, based on the size of LONGDOUBLE_TYPE.
7188 ** If argument is a boolean, set the use-long-double flag accordingly.
7190 ** Return the new setting.
7192 static int SQLITE_TCLAPI
use_long_double(
7193 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7194 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7195 int objc
, /* Number of arguments */
7196 Tcl_Obj
*CONST objv
[] /* Command arguments */
7200 if( strcmp(Tcl_GetString(objv
[1]),"default")==0 ){
7203 if( Tcl_GetBooleanFromObj(interp
,objv
[1],&i
) ) return TCL_ERROR
;
7206 i
= sqlite3_test_control(SQLITE_TESTCTRL_USELONGDOUBLE
, i
);
7207 Tcl_SetObjResult(interp
, Tcl_NewIntObj(i
));
7212 ** tclcmd: database_may_be_corrupt
7214 ** Indicate that database files might be corrupt. In other words, set the normal
7215 ** state of operation.
7217 static int SQLITE_TCLAPI
database_may_be_corrupt(
7218 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7219 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7220 int objc
, /* Number of arguments */
7221 Tcl_Obj
*CONST objv
[] /* Command arguments */
7223 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 0);
7227 ** tclcmd: database_never_corrupt
7229 ** Indicate that database files are always well-formed. This enables
7230 ** extra assert() statements that test conditions that are always true
7231 ** for well-formed databases.
7233 static int SQLITE_TCLAPI
database_never_corrupt(
7234 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7235 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7236 int objc
, /* Number of arguments */
7237 Tcl_Obj
*CONST objv
[] /* Command arguments */
7239 sqlite3_test_control(SQLITE_TESTCTRL_NEVER_CORRUPT
, 1);
7244 ** tclcmd: pcache_stats
7246 static int SQLITE_TCLAPI
test_pcache_stats(
7247 ClientData clientData
, /* Pointer to sqlite3_enable_XXX function */
7248 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7249 int objc
, /* Number of arguments */
7250 Tcl_Obj
*CONST objv
[] /* Command arguments */
7258 sqlite3PcacheStats(&nCurrent
, &nMax
, &nMin
, &nRecyclable
);
7260 pRet
= Tcl_NewObj();
7261 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("current", -1));
7262 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCurrent
));
7263 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("max", -1));
7264 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMax
));
7265 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("min", -1));
7266 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nMin
));
7267 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewStringObj("recyclable", -1));
7268 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nRecyclable
));
7270 Tcl_SetObjResult(interp
, pRet
);
7275 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
7276 static void test_unlock_notify_cb(void **aArg
, int nArg
){
7278 for(ii
=0; ii
<nArg
; ii
++){
7279 Tcl_EvalEx((Tcl_Interp
*)aArg
[ii
], "unlock_notify", -1, TCL_EVAL_GLOBAL
);
7282 #endif /* SQLITE_ENABLE_UNLOCK_NOTIFY */
7285 ** tclcmd: sqlite3_unlock_notify db
7287 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
7288 static int SQLITE_TCLAPI
test_unlock_notify(
7289 ClientData clientData
, /* Unused */
7290 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7291 int objc
, /* Number of arguments */
7292 Tcl_Obj
*CONST objv
[] /* Command arguments */
7298 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
7302 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7305 rc
= sqlite3_unlock_notify(db
, test_unlock_notify_cb
, (void *)interp
);
7306 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7312 ** tclcmd: sqlite3_wal_checkpoint db ?NAME?
7314 static int SQLITE_TCLAPI
test_wal_checkpoint(
7315 ClientData clientData
, /* Unused */
7316 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7317 int objc
, /* Number of arguments */
7318 Tcl_Obj
*CONST objv
[] /* Command arguments */
7324 if( objc
!=3 && objc
!=2 ){
7325 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?NAME?");
7329 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
7333 zDb
= Tcl_GetString(objv
[2]);
7335 rc
= sqlite3_wal_checkpoint(db
, zDb
);
7336 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
7341 ** tclcmd: sqlite3_wal_checkpoint_v2 db MODE ?NAME?
7343 ** This command calls the wal_checkpoint_v2() function with the specified
7344 ** mode argument (passive, full or restart). If present, the database name
7345 ** NAME is passed as the second argument to wal_checkpoint_v2(). If it the
7346 ** NAME argument is not present, a NULL pointer is passed instead.
7348 ** If wal_checkpoint_v2() returns any value other than SQLITE_BUSY or
7349 ** SQLITE_OK, then this command returns TCL_ERROR. The Tcl result is set
7350 ** to the error message obtained from sqlite3_errmsg().
7352 ** Otherwise, this command returns a list of three integers. The first integer
7353 ** is 1 if SQLITE_BUSY was returned, or 0 otherwise. The following two integers
7354 ** are the values returned via the output parameters by wal_checkpoint_v2() -
7355 ** the number of frames in the log and the number of frames in the log
7356 ** that have been checkpointed.
7358 static int SQLITE_TCLAPI
test_wal_checkpoint_v2(
7359 ClientData clientData
, /* Unused */
7360 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7361 int objc
, /* Number of arguments */
7362 Tcl_Obj
*CONST objv
[] /* Command arguments */
7373 const char * aMode
[] = { "passive", "full", "restart", "truncate", 0 };
7374 assert( SQLITE_CHECKPOINT_PASSIVE
==0 );
7375 assert( SQLITE_CHECKPOINT_FULL
==1 );
7376 assert( SQLITE_CHECKPOINT_RESTART
==2 );
7377 assert( SQLITE_CHECKPOINT_TRUNCATE
==3 );
7379 if( objc
!=3 && objc
!=4 ){
7380 Tcl_WrongNumArgs(interp
, 1, objv
, "DB MODE ?NAME?");
7385 zDb
= Tcl_GetString(objv
[3]);
7387 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) || (
7388 TCL_OK
!=Tcl_GetIntFromObj(0, objv
[2], &eMode
)
7389 && TCL_OK
!=Tcl_GetIndexFromObj(interp
, objv
[2], aMode
, "mode", 0, &eMode
)
7394 rc
= sqlite3_wal_checkpoint_v2(db
, zDb
, eMode
, &nLog
, &nCkpt
);
7395 if( rc
!=SQLITE_OK
&& rc
!=SQLITE_BUSY
){
7396 const char *zErrCode
= sqlite3ErrName(rc
);
7397 Tcl_ResetResult(interp
);
7398 Tcl_AppendResult(interp
, zErrCode
, " - ", (char *)sqlite3_errmsg(db
), 0);
7402 pRet
= Tcl_NewObj();
7403 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(rc
==SQLITE_BUSY
?1:0));
7404 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nLog
));
7405 Tcl_ListObjAppendElement(interp
, pRet
, Tcl_NewIntObj(nCkpt
));
7406 Tcl_SetObjResult(interp
, pRet
);
7412 ** tclcmd: sqlite3_wal_autocheckpoint db VALUE
7414 static int SQLITE_TCLAPI
test_wal_autocheckpoint(
7415 ClientData clientData
, /* Unused */
7416 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7417 int objc
, /* Number of arguments */
7418 Tcl_Obj
*CONST objv
[] /* Command arguments */
7426 Tcl_WrongNumArgs(interp
, 1, objv
, "DB VALUE");
7430 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
)
7431 || Tcl_GetIntFromObj(0, objv
[2], &iVal
)
7436 rc
= sqlite3_wal_autocheckpoint(db
, iVal
);
7437 Tcl_ResetResult(interp
);
7438 if( rc
!=SQLITE_OK
){
7439 const char *zErrCode
= sqlite3ErrName(rc
);
7440 Tcl_SetObjResult(interp
, Tcl_NewStringObj(zErrCode
, -1));
7449 ** tclcmd: test_sqlite3_log ?SCRIPT?
7451 static struct LogCallback
{
7452 Tcl_Interp
*pInterp
;
7454 } logcallback
= {0, 0};
7455 static void xLogcallback(void *unused
, int err
, char *zMsg
){
7456 Tcl_Obj
*pNew
= Tcl_DuplicateObj(logcallback
.pObj
);
7457 Tcl_IncrRefCount(pNew
);
7458 Tcl_ListObjAppendElement(
7459 0, pNew
, Tcl_NewStringObj(sqlite3ErrName(err
), -1)
7461 Tcl_ListObjAppendElement(0, pNew
, Tcl_NewStringObj(zMsg
, -1));
7462 Tcl_EvalObjEx(logcallback
.pInterp
, pNew
, TCL_EVAL_GLOBAL
|TCL_EVAL_DIRECT
);
7463 Tcl_DecrRefCount(pNew
);
7465 static int SQLITE_TCLAPI
test_sqlite3_log(
7466 ClientData clientData
,
7467 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
7468 int objc
, /* Number of arguments */
7469 Tcl_Obj
*CONST objv
[] /* Command arguments */
7472 Tcl_WrongNumArgs(interp
, 1, objv
, "SCRIPT");
7475 if( logcallback
.pObj
){
7476 Tcl_DecrRefCount(logcallback
.pObj
);
7477 logcallback
.pObj
= 0;
7478 logcallback
.pInterp
= 0;
7479 sqlite3_config(SQLITE_CONFIG_LOG
, (void*)0, (void*)0);
7482 logcallback
.pObj
= objv
[1];
7483 Tcl_IncrRefCount(logcallback
.pObj
);
7484 logcallback
.pInterp
= interp
;
7485 sqlite3_config(SQLITE_CONFIG_LOG
, xLogcallback
, (void*)0);
7491 ** tcl_objproc COMMANDNAME ARGS...
7493 ** Run a TCL command using its objProc interface. Throw an error if
7494 ** the command has no objProc interface.
7496 static int SQLITE_TCLAPI
runAsObjProc(
7500 Tcl_Obj
*CONST objv
[]
7502 Tcl_CmdInfo cmdInfo
;
7504 Tcl_WrongNumArgs(interp
, 1, objv
, "COMMAND ...");
7507 if( !Tcl_GetCommandInfo(interp
, Tcl_GetString(objv
[1]), &cmdInfo
) ){
7508 Tcl_AppendResult(interp
, "command not found: ",
7509 Tcl_GetString(objv
[1]), (char*)0);
7512 if( cmdInfo
.objProc
==0 ){
7513 Tcl_AppendResult(interp
, "command has no objProc: ",
7514 Tcl_GetString(objv
[1]), (char*)0);
7517 return cmdInfo
.objProc(cmdInfo
.objClientData
, interp
, objc
-1, objv
+1);
7520 #ifndef SQLITE_OMIT_EXPLAIN
7522 ** WARNING: The following function, printExplainQueryPlan() is an exact
7523 ** copy of example code from eqp.in (eqp.html). If this code is modified,
7524 ** then the documentation copy needs to be modified as well.
7527 ** Argument pStmt is a prepared SQL statement. This function compiles
7528 ** an EXPLAIN QUERY PLAN command to report on the prepared statement,
7529 ** and prints the report to stdout using printf().
7531 int printExplainQueryPlan(sqlite3_stmt
*pStmt
){
7532 const char *zSql
; /* Input SQL */
7533 char *zExplain
; /* SQL with EXPLAIN QUERY PLAN prepended */
7534 sqlite3_stmt
*pExplain
; /* Compiled EXPLAIN QUERY PLAN command */
7535 int rc
; /* Return code from sqlite3_prepare_v2() */
7537 zSql
= sqlite3_sql(pStmt
);
7538 if( zSql
==0 ) return SQLITE_ERROR
;
7540 zExplain
= sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql
);
7541 if( zExplain
==0 ) return SQLITE_NOMEM
;
7543 rc
= sqlite3_prepare_v2(sqlite3_db_handle(pStmt
), zExplain
, -1, &pExplain
, 0);
7544 sqlite3_free(zExplain
);
7545 if( rc
!=SQLITE_OK
) return rc
;
7547 while( SQLITE_ROW
==sqlite3_step(pExplain
) ){
7548 int iSelectid
= sqlite3_column_int(pExplain
, 0);
7549 int iOrder
= sqlite3_column_int(pExplain
, 1);
7550 int iFrom
= sqlite3_column_int(pExplain
, 2);
7551 const char *zDetail
= (const char *)sqlite3_column_text(pExplain
, 3);
7553 printf("%d %d %d %s\n", iSelectid
, iOrder
, iFrom
, zDetail
);
7556 return sqlite3_finalize(pExplain
);
7559 static int SQLITE_TCLAPI
test_print_eqp(
7563 Tcl_Obj
*CONST objv
[]
7566 sqlite3_stmt
*pStmt
;
7569 Tcl_WrongNumArgs(interp
, 1, objv
, "STMT");
7572 if( getStmtPointer(interp
, Tcl_GetString(objv
[1]), &pStmt
) ) return TCL_ERROR
;
7573 rc
= printExplainQueryPlan(pStmt
);
7574 /* This is needed on Windows so that a test case using this
7575 ** function can open a read pipe and get the output of
7576 ** printExplainQueryPlan() immediately.
7579 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), 0);
7582 #endif /* SQLITE_OMIT_EXPLAIN */
7586 ** This is an alternative localtime_r() implementation used for testing
7587 ** the 'localtime' and 'utc' modifiers of date-time functions. Because
7588 ** the OS-supplied localtime_r() is locale-dependent, this alternative is
7589 ** provided as a stable test platform.
7593 ** (1) Localtime is 30 minutes earlier than (west of) UTC on
7594 ** even days (counting from 1970-01-01)
7596 ** (2) Localtime is 30 minutes later than (east of) UTC on odd days.
7598 ** (3) The function fails for the specific date/time value
7599 ** of 2000-05-29 14:16:00 in order to test the ability of
7600 ** SQLite to deal with localtime_r() failures.
7602 static int testLocaltime(const void *aliasT
, void *aliasTM
){
7603 const time_t t
= *(const time_t*)aliasT
;
7604 struct tm
*pTm
= (struct tm
*)aliasTM
;
7607 int Z
, A
, B
, C
, D
, E
, X1
, S
;
7609 if( (t
/86400) & 1 ){
7610 altT
= t
+ 1800; /* 30 minutes later on odd days */
7612 altT
= t
- 1800; /* 30 minutes earlier on even days */
7614 iJD
= (sqlite3_int64
)(altT
+ 210866760000);
7615 Z
= (int)((iJD
+ 43200)/86400);
7616 A
= (int)((Z
- 1867216.25)/36524.25);
7617 A
= Z
+ 1 + A
- (A
/4);
7619 C
= (int)((B
- 122.1)/365.25);
7620 D
= (36525*(C
&32767))/100;
7621 E
= (int)((B
-D
)/30.6001);
7622 X1
= (int)(30.6001*E
);
7623 pTm
->tm_mday
= B
- D
- X1
;
7624 pTm
->tm_mon
= E
<14 ? E
-2 : E
-14;
7625 pTm
->tm_year
= (pTm
->tm_mon
>1 ? C
- 4716 : C
- 4715) - 1900;
7626 S
= (int)((iJD
+ 43200)%86400);
7627 pTm
->tm_hour
= S
/3600;
7628 pTm
->tm_min
= (S
/60)%60;
7629 pTm
->tm_sec
= S
% 60;
7630 return t
==959609760; /* Special case: 2000-05-29 14:16:00 fails */
7634 ** TCLCMD: strftime FORMAT UNIXTIMESTAMP
7636 ** Access to the C-library strftime() routine, so that its results
7637 ** can be compared against SQLite's internal strftime() SQL function
7640 static int SQLITE_TCLAPI
strftime_cmd(
7644 Tcl_Obj
*CONST objv
[]
7653 Tcl_WrongNumArgs(interp
, 1, objv
, "FORMAT UNIXTIMESTAMP");
7656 if( Tcl_GetWideIntFromObj(interp
, objv
[2], &ts
) ) return TCL_ERROR
;
7657 zFmt
= Tcl_GetString(objv
[1]);
7660 n
= strftime(zBuf
, sizeof(zBuf
)-1, zFmt
, pTm
);
7661 if( n
>=0 && n
<sizeof(zBuf
) ){
7663 Tcl_SetResult(interp
, zBuf
, TCL_VOLATILE
);
7671 static int SQLITE_TCLAPI
test_treetrace(
7675 Tcl_Obj
*CONST objv
[]
7679 if( Tcl_GetIntFromObj(interp
, objv
[1], (int*)&v
)==TCL_OK
){
7680 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS
, 1, &v
);
7683 sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS
, 0, &v
);
7684 Tcl_SetObjResult(interp
, Tcl_NewIntObj((int)v
));
7689 ** sqlite3_test_control VERB ARGS...
7691 static int SQLITE_TCLAPI
test_test_control(
7695 Tcl_Obj
*CONST objv
[]
7701 { "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT
},
7702 { "SQLITE_TESTCTRL_SORTER_MMAP", SQLITE_TESTCTRL_SORTER_MMAP
},
7703 { "SQLITE_TESTCTRL_IMPOSTER", SQLITE_TESTCTRL_IMPOSTER
},
7704 { "SQLITE_TESTCTRL_INTERNAL_FUNCTIONS", SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
},
7705 { "SQLITE_TESTCTRL_FK_NO_ACTION", SQLITE_TESTCTRL_FK_NO_ACTION
},
7713 Tcl_WrongNumArgs(interp
, 1, objv
, "VERB ARGS...");
7717 rc
= Tcl_GetIndexFromObjStruct(
7718 interp
, objv
[1], aVerb
, sizeof(aVerb
[0]), "VERB", 0, &iVerb
7720 if( rc
!=TCL_OK
) return rc
;
7722 iFlag
= aVerb
[iVerb
].i
;
7724 case SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
: {
7727 Tcl_WrongNumArgs(interp
, 2, objv
, "DB");
7730 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7731 sqlite3_test_control(SQLITE_TESTCTRL_INTERNAL_FUNCTIONS
, db
);
7734 case SQLITE_TESTCTRL_LOCALTIME_FAULT
: {
7737 Tcl_WrongNumArgs(interp
, 2, objv
, "0|1|2");
7740 if( Tcl_GetIntFromObj(interp
, objv
[2], &val
) ) return TCL_ERROR
;
7741 sqlite3_test_control(iFlag
, val
, testLocaltime
);
7745 case SQLITE_TESTCTRL_FK_NO_ACTION
: {
7749 Tcl_WrongNumArgs(interp
, 2, objv
, "DB BOOLEAN");
7752 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7753 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
7755 sqlite3_test_control(SQLITE_TESTCTRL_FK_NO_ACTION
, db
, val
);
7759 case SQLITE_TESTCTRL_SORTER_MMAP
: {
7763 Tcl_WrongNumArgs(interp
, 2, objv
, "DB LIMIT");
7766 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7767 if( Tcl_GetIntFromObj(interp
, objv
[3], &val
) ) return TCL_ERROR
;
7768 sqlite3_test_control(SQLITE_TESTCTRL_SORTER_MMAP
, db
, val
);
7772 case SQLITE_TESTCTRL_IMPOSTER
: {
7774 const char *zDbName
;
7777 Tcl_WrongNumArgs(interp
, 2, objv
, "DB dbName onOff tnum");
7780 if( getDbPointer(interp
, Tcl_GetString(objv
[2]), &db
) ) return TCL_ERROR
;
7781 zDbName
= Tcl_GetString(objv
[3]);
7782 if( Tcl_GetIntFromObj(interp
, objv
[4], &onOff
) ) return TCL_ERROR
;
7783 if( Tcl_GetIntFromObj(interp
, objv
[5], &tnum
) ) return TCL_ERROR
;
7784 sqlite3_test_control(SQLITE_TESTCTRL_IMPOSTER
, db
, zDbName
, onOff
, tnum
);
7789 Tcl_ResetResult(interp
);
7794 #include <sys/time.h>
7795 #include <sys/resource.h>
7797 static int SQLITE_TCLAPI
test_getrusage(
7801 Tcl_Obj
*CONST objv
[]
7805 memset(&r
, 0, sizeof(r
));
7806 getrusage(RUSAGE_SELF
, &r
);
7808 sqlite3_snprintf(sizeof(buf
), buf
,
7809 "ru_utime=%d.%06d ru_stime=%d.%06d ru_minflt=%d ru_majflt=%d",
7810 (int)r
.ru_utime
.tv_sec
, (int)r
.ru_utime
.tv_usec
,
7811 (int)r
.ru_stime
.tv_sec
, (int)r
.ru_stime
.tv_usec
,
7812 (int)r
.ru_minflt
, (int)r
.ru_majflt
7814 Tcl_SetObjResult(interp
, Tcl_NewStringObj(buf
, -1));
7821 ** Information passed from the main thread into the windows file locker
7822 ** background thread.
7824 struct win32FileLocker
{
7825 char *evName
; /* Name of event to signal thread startup */
7826 HANDLE h
; /* Handle of the file to be locked */
7827 int delay1
; /* Delay before locking */
7828 int delay2
; /* Delay before unlocking */
7829 int ok
; /* Finished ok */
7830 int err
; /* True if an error occurs */
7836 #include <process.h>
7838 ** The background thread that does file locking.
7840 static void SQLITE_CDECL
win32_file_locker(void *pAppData
){
7841 struct win32FileLocker
*p
= (struct win32FileLocker
*)pAppData
;
7843 HANDLE ev
= OpenEvent(EVENT_MODIFY_STATE
, FALSE
, p
->evName
);
7849 if( p
->delay1
) Sleep(p
->delay1
);
7850 if( LockFile(p
->h
, 0, 0, 100000000, 0) ){
7852 UnlockFile(p
->h
, 0, 0, 100000000, 0);
7866 ** lock_win32_file FILENAME DELAY1 DELAY2
7868 ** Get an exclusive manditory lock on file for DELAY2 milliseconds.
7869 ** Wait DELAY1 milliseconds before acquiring the lock.
7871 static int SQLITE_TCLAPI
win32_file_lock(
7875 Tcl_Obj
*CONST objv
[]
7877 static struct win32FileLocker x
= { "win32_file_lock", 0, 0, 0, 0, 0 };
7878 const char *zFilename
;
7884 if( objc
!=4 && objc
!=1 ){
7885 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME DELAY1 DELAY2");
7889 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%d %d %d %d %d",
7890 x
.ok
, x
.err
, x
.delay1
, x
.delay2
, x
.h
);
7891 Tcl_AppendResult(interp
, zBuf
, (char*)0);
7894 while( x
.h
&& retry
<30 ){
7899 Tcl_AppendResult(interp
, "busy", (char*)0);
7902 if( Tcl_GetIntFromObj(interp
, objv
[2], &x
.delay1
) ) return TCL_ERROR
;
7903 if( Tcl_GetIntFromObj(interp
, objv
[3], &x
.delay2
) ) return TCL_ERROR
;
7904 zFilename
= Tcl_GetString(objv
[1]);
7905 x
.h
= CreateFile(zFilename
, GENERIC_READ
|GENERIC_WRITE
,
7906 FILE_SHARE_READ
|FILE_SHARE_WRITE
, 0, OPEN_ALWAYS
,
7907 FILE_ATTRIBUTE_NORMAL
, 0);
7909 Tcl_AppendResult(interp
, "cannot open file: ", zFilename
, (char*)0);
7912 ev
= CreateEvent(NULL
, TRUE
, FALSE
, x
.evName
);
7914 Tcl_AppendResult(interp
, "cannot create event: ", x
.evName
, (char*)0);
7917 _beginthread(win32_file_locker
, 0, (void*)&x
);
7919 if ( (wResult
= WaitForSingleObject(ev
, 10000))!=WAIT_OBJECT_0
){
7920 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "0x%x", wResult
);
7921 Tcl_AppendResult(interp
, "wait failed: ", zBuf
, (char*)0);
7930 ** exists_win32_path PATH
7932 ** Returns non-zero if the specified path exists, whose fully qualified name
7933 ** may exceed 260 characters if it is prefixed with "\\?\".
7935 static int SQLITE_TCLAPI
win32_exists_path(
7939 Tcl_Obj
*CONST objv
[]
7942 Tcl_WrongNumArgs(interp
, 1, objv
, "PATH");
7945 Tcl_SetObjResult(interp
, Tcl_NewBooleanObj(
7946 GetFileAttributesW( Tcl_GetUnicode(objv
[1]))!=INVALID_FILE_ATTRIBUTES
));
7951 ** find_win32_file PATTERN
7953 ** Returns a list of entries in a directory that match the specified pattern,
7954 ** whose fully qualified name may exceed 248 characters if it is prefixed with
7957 static int SQLITE_TCLAPI
win32_find_file(
7961 Tcl_Obj
*CONST objv
[]
7963 HANDLE hFindFile
= INVALID_HANDLE_VALUE
;
7964 WIN32_FIND_DATAW findData
;
7968 Tcl_WrongNumArgs(interp
, 1, objv
, "PATTERN");
7971 hFindFile
= FindFirstFileW(Tcl_GetUnicode(objv
[1]), &findData
);
7972 if( hFindFile
==INVALID_HANDLE_VALUE
){
7973 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7976 listObj
= Tcl_NewObj();
7977 Tcl_IncrRefCount(listObj
);
7979 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewUnicodeObj(
7980 findData
.cFileName
, -1));
7981 Tcl_ListObjAppendElement(interp
, listObj
, Tcl_NewWideIntObj(
7982 findData
.dwFileAttributes
));
7983 } while( FindNextFileW(hFindFile
, &findData
) );
7984 lastErrno
= GetLastError();
7985 if( lastErrno
!=NO_ERROR
&& lastErrno
!=ERROR_NO_MORE_FILES
){
7986 FindClose(hFindFile
);
7987 Tcl_DecrRefCount(listObj
);
7988 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
7991 FindClose(hFindFile
);
7992 Tcl_SetObjResult(interp
, listObj
);
7997 ** delete_win32_file FILENAME
7999 ** Deletes the specified file, whose fully qualified name may exceed 260
8000 ** characters if it is prefixed with "\\?\".
8002 static int SQLITE_TCLAPI
win32_delete_file(
8006 Tcl_Obj
*CONST objv
[]
8009 Tcl_WrongNumArgs(interp
, 1, objv
, "FILENAME");
8012 if( !DeleteFileW(Tcl_GetUnicode(objv
[1])) ){
8013 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
8016 Tcl_ResetResult(interp
);
8021 ** make_win32_dir DIRECTORY
8023 ** Creates the specified directory, whose fully qualified name may exceed 248
8024 ** characters if it is prefixed with "\\?\".
8026 static int SQLITE_TCLAPI
win32_mkdir(
8030 Tcl_Obj
*CONST objv
[]
8033 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
8036 if( !CreateDirectoryW(Tcl_GetUnicode(objv
[1]), NULL
) ){
8037 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
8040 Tcl_ResetResult(interp
);
8045 ** remove_win32_dir DIRECTORY
8047 ** Removes the specified directory, whose fully qualified name may exceed 248
8048 ** characters if it is prefixed with "\\?\".
8050 static int SQLITE_TCLAPI
win32_rmdir(
8054 Tcl_Obj
*CONST objv
[]
8057 Tcl_WrongNumArgs(interp
, 1, objv
, "DIRECTORY");
8060 if( !RemoveDirectoryW(Tcl_GetUnicode(objv
[1])) ){
8061 Tcl_SetObjResult(interp
, Tcl_NewWideIntObj(GetLastError()));
8064 Tcl_ResetResult(interp
);
8071 ** optimization_control DB OPT BOOLEAN
8073 ** Enable or disable query optimizations using the sqlite3_test_control()
8074 ** interface. Disable if BOOLEAN is false and enable if BOOLEAN is true.
8075 ** OPT is the name of the optimization to be disabled. OPT can also be a
8076 ** list or optimizations names, in which case all optimizations named are
8077 ** enabled or disabled.
8079 ** Each invocation of this control overrides all prior invocations. The
8080 ** changes are not cumulative.
8082 static int SQLITE_TCLAPI
optimization_control(
8086 Tcl_Obj
*CONST objv
[]
8094 static const struct {
8095 const char *zOptName
;
8098 { "all", SQLITE_AllOpts
},
8100 { "query-flattener", SQLITE_QueryFlattener
},
8101 { "groupby-order", SQLITE_GroupByOrder
},
8102 { "factor-constants", SQLITE_FactorOutConst
},
8103 { "distinct-opt", SQLITE_DistinctOpt
},
8104 { "cover-idx-scan", SQLITE_CoverIdxScan
},
8105 { "order-by-idx-join", SQLITE_OrderByIdxJoin
},
8106 { "transitive", SQLITE_Transitive
},
8107 { "omit-noop-join", SQLITE_OmitNoopJoin
},
8108 { "stat4", SQLITE_Stat4
},
8109 { "skip-scan", SQLITE_SkipScan
},
8110 { "push-down", SQLITE_PushDown
},
8111 { "balanced-merge", SQLITE_BalancedMerge
},
8112 { "propagate-const", SQLITE_PropagateConst
},
8113 { "one-pass", SQLITE_OnePass
},
8117 Tcl_WrongNumArgs(interp
, 1, objv
, "DB OPT BOOLEAN");
8120 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8121 if( Tcl_GetBooleanFromObj(interp
, objv
[3], &onoff
) ) return TCL_ERROR
;
8122 zOpt
= Tcl_GetString(objv
[2]);
8123 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
8124 if( strstr(zOpt
, aOpt
[i
].zOptName
)!=0 ){
8125 mask
|= aOpt
[i
].mask
;
8129 if( onoff
) mask
= ~mask
;
8131 Tcl_AppendResult(interp
, "unknown optimization - should be one of:",
8133 for(i
=0; i
<sizeof(aOpt
)/sizeof(aOpt
[0]); i
++){
8134 Tcl_AppendResult(interp
, " ", aOpt
[i
].zOptName
, (char*)0);
8138 sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS
, db
, mask
);
8139 Tcl_SetObjResult(interp
, Tcl_NewIntObj(mask
));
8144 ** load_static_extension DB NAME ...
8146 ** Load one or more statically linked extensions.
8148 static int SQLITE_TCLAPI
tclLoadStaticExtensionCmd(
8152 Tcl_Obj
*CONST objv
[]
8154 extern int sqlite3_amatch_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8155 extern int sqlite3_appendvfs_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8156 extern int sqlite3_basexx_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8157 extern int sqlite3_carray_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8158 extern int sqlite3_closure_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8159 extern int sqlite3_csv_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8160 extern int sqlite3_eval_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8161 extern int sqlite3_explain_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8162 extern int sqlite3_fileio_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8163 extern int sqlite3_decimal_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8164 extern int sqlite3_fuzzer_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8165 extern int sqlite3_ieee_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8166 extern int sqlite3_nextchar_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8167 extern int sqlite3_percentile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8168 #ifndef SQLITE_OMIT_VIRTUALTABLE
8169 extern int sqlite3_prefixes_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8171 extern int sqlite3_qpvtab_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8172 extern int sqlite3_randomjson_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8173 extern int sqlite3_regexp_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8174 extern int sqlite3_remember_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8175 extern int sqlite3_series_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8176 extern int sqlite3_spellfix_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8177 extern int sqlite3_totype_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8178 extern int sqlite3_wholenumber_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8179 extern int sqlite3_unionvtab_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8180 #ifdef SQLITE_HAVE_ZLIB
8181 extern int sqlite3_zipfile_init(sqlite3
*,char**,const sqlite3_api_routines
*);
8183 static const struct {
8184 const char *zExtName
;
8185 int (*pInit
)(sqlite3
*,char**,const sqlite3_api_routines
*);
8187 { "amatch", sqlite3_amatch_init
},
8188 { "appendvfs", sqlite3_appendvfs_init
},
8189 { "basexx", sqlite3_basexx_init
},
8190 { "carray", sqlite3_carray_init
},
8191 { "closure", sqlite3_closure_init
},
8192 { "csv", sqlite3_csv_init
},
8193 { "decimal", sqlite3_decimal_init
},
8194 { "eval", sqlite3_eval_init
},
8195 { "explain", sqlite3_explain_init
},
8196 { "fileio", sqlite3_fileio_init
},
8197 { "fuzzer", sqlite3_fuzzer_init
},
8198 { "ieee754", sqlite3_ieee_init
},
8199 { "nextchar", sqlite3_nextchar_init
},
8200 { "percentile", sqlite3_percentile_init
},
8201 #ifndef SQLITE_OMIT_VIRTUALTABLE
8202 { "prefixes", sqlite3_prefixes_init
},
8204 { "qpvtab", sqlite3_qpvtab_init
},
8205 { "randomjson", sqlite3_randomjson_init
},
8206 { "regexp", sqlite3_regexp_init
},
8207 { "remember", sqlite3_remember_init
},
8208 { "series", sqlite3_series_init
},
8209 { "spellfix", sqlite3_spellfix_init
},
8210 { "totype", sqlite3_totype_init
},
8211 { "unionvtab", sqlite3_unionvtab_init
},
8212 { "wholenumber", sqlite3_wholenumber_init
},
8213 #ifdef SQLITE_HAVE_ZLIB
8214 { "zipfile", sqlite3_zipfile_init
},
8222 Tcl_WrongNumArgs(interp
, 1, objv
, "DB NAME ...");
8225 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8226 for(j
=2; j
<objc
; j
++){
8227 zName
= Tcl_GetString(objv
[j
]);
8228 for(i
=0; i
<ArraySize(aExtension
); i
++){
8229 if( strcmp(zName
, aExtension
[i
].zExtName
)==0 ) break;
8231 if( i
>=ArraySize(aExtension
) ){
8232 Tcl_AppendResult(interp
, "no such extension: ", zName
, (char*)0);
8235 if( aExtension
[i
].pInit
){
8236 rc
= aExtension
[i
].pInit(db
, &zErrMsg
, 0);
8240 if( (rc
!=SQLITE_OK
&& rc
!=SQLITE_OK_LOAD_PERMANENTLY
) || zErrMsg
){
8241 Tcl_AppendResult(interp
, "initialization of ", zName
, " failed: ", zErrMsg
,
8243 sqlite3_free(zErrMsg
);
8251 ** sorter_test_fakeheap BOOL
8254 static int SQLITE_TCLAPI
sorter_test_fakeheap(
8258 Tcl_Obj
*CONST objv
[]
8262 Tcl_WrongNumArgs(interp
, 1, objv
, "BOOL");
8266 if( Tcl_GetBooleanFromObj(interp
, objv
[1], &bArg
) ){
8271 if( sqlite3GlobalConfig
.pHeap
==0 ){
8272 sqlite3GlobalConfig
.pHeap
= SQLITE_INT_TO_PTR(-1);
8275 if( sqlite3GlobalConfig
.pHeap
==SQLITE_INT_TO_PTR(-1) ){
8276 sqlite3GlobalConfig
.pHeap
= 0;
8280 Tcl_ResetResult(interp
);
8285 ** sorter_test_sort4_helper DB SQL1 NSTEP SQL2
8287 ** Compile SQL statement $SQL1 and step it $NSTEP times. For each row,
8288 ** check that the leftmost and rightmost columns returned are both integers,
8289 ** and that both contain the same value.
8291 ** Then execute statement $SQL2. Check that the statement returns the same
8292 ** set of integers in the same order as in the previous step (using $SQL1).
8294 static int SQLITE_TCLAPI
sorter_test_sort4_helper(
8298 Tcl_Obj
*CONST objv
[]
8304 unsigned int iCksum1
= 0;
8305 unsigned int iCksum2
= 0;
8309 sqlite3_stmt
*pStmt
;
8312 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SQL1 NSTEP SQL2");
8316 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8317 zSql1
= Tcl_GetString(objv
[2]);
8318 if( Tcl_GetIntFromObj(interp
, objv
[3], &nStep
) ) return TCL_ERROR
;
8319 zSql2
= Tcl_GetString(objv
[4]);
8321 rc
= sqlite3_prepare_v2(db
, zSql1
, -1, &pStmt
, 0);
8322 if( rc
!=SQLITE_OK
) goto sql_error
;
8324 iB
= sqlite3_column_count(pStmt
)-1;
8325 for(iStep
=0; iStep
<nStep
&& SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
8326 int a
= sqlite3_column_int(pStmt
, 0);
8327 if( a
!=sqlite3_column_int(pStmt
, iB
) ){
8328 Tcl_AppendResult(interp
, "data error: (a!=b)", 0);
8332 iCksum1
+= (iCksum1
<< 3) + (unsigned int)a
;
8334 rc
= sqlite3_finalize(pStmt
);
8335 if( rc
!=SQLITE_OK
) goto sql_error
;
8337 rc
= sqlite3_prepare_v2(db
, zSql2
, -1, &pStmt
, 0);
8338 if( rc
!=SQLITE_OK
) goto sql_error
;
8339 for(iStep
=0; SQLITE_ROW
==sqlite3_step(pStmt
); iStep
++){
8340 int a
= sqlite3_column_int(pStmt
, 0);
8341 iCksum2
+= (iCksum2
<< 3) + (unsigned int)a
;
8343 rc
= sqlite3_finalize(pStmt
);
8344 if( rc
!=SQLITE_OK
) goto sql_error
;
8346 if( iCksum1
!=iCksum2
){
8347 Tcl_AppendResult(interp
, "checksum mismatch", 0);
8353 Tcl_AppendResult(interp
, "sql error: ", sqlite3_errmsg(db
), 0);
8358 #ifdef SQLITE_USER_AUTHENTICATION
8359 #include "sqlite3userauth.h"
8361 ** tclcmd: sqlite3_user_authenticate DB USERNAME PASSWORD
8363 static int SQLITE_TCLAPI
test_user_authenticate(
8364 ClientData clientData
, /* Unused */
8365 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8366 int objc
, /* Number of arguments */
8367 Tcl_Obj
*CONST objv
[] /* Command arguments */
8376 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD");
8379 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
8382 zUser
= Tcl_GetString(objv
[2]);
8383 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
8384 rc
= sqlite3_user_authenticate(db
, zUser
, zPasswd
, nPasswd
);
8385 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
8388 #endif /* SQLITE_USER_AUTHENTICATION */
8390 #ifdef SQLITE_USER_AUTHENTICATION
8392 ** tclcmd: sqlite3_user_add DB USERNAME PASSWORD ISADMIN
8394 static int SQLITE_TCLAPI
test_user_add(
8395 ClientData clientData
, /* Unused */
8396 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8397 int objc
, /* Number of arguments */
8398 Tcl_Obj
*CONST objv
[] /* Command arguments */
8408 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
8411 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
8414 zUser
= Tcl_GetString(objv
[2]);
8415 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
8416 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
8417 rc
= sqlite3_user_add(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
8418 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
8421 #endif /* SQLITE_USER_AUTHENTICATION */
8423 #ifdef SQLITE_USER_AUTHENTICATION
8425 ** tclcmd: sqlite3_user_change DB USERNAME PASSWORD ISADMIN
8427 static int SQLITE_TCLAPI
test_user_change(
8428 ClientData clientData
, /* Unused */
8429 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8430 int objc
, /* Number of arguments */
8431 Tcl_Obj
*CONST objv
[] /* Command arguments */
8441 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME PASSWORD ISADMIN");
8444 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
8447 zUser
= Tcl_GetString(objv
[2]);
8448 zPasswd
= Tcl_GetStringFromObj(objv
[3], &nPasswd
);
8449 Tcl_GetBooleanFromObj(interp
, objv
[4], &isAdmin
);
8450 rc
= sqlite3_user_change(db
, zUser
, zPasswd
, nPasswd
, isAdmin
);
8451 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
8454 #endif /* SQLITE_USER_AUTHENTICATION */
8456 #ifdef SQLITE_USER_AUTHENTICATION
8458 ** tclcmd: sqlite3_user_delete DB USERNAME
8460 static int SQLITE_TCLAPI
test_user_delete(
8461 ClientData clientData
, /* Unused */
8462 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8463 int objc
, /* Number of arguments */
8464 Tcl_Obj
*CONST objv
[] /* Command arguments */
8471 Tcl_WrongNumArgs(interp
, 1, objv
, "DB USERNAME");
8474 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ){
8477 zUser
= Tcl_GetString(objv
[2]);
8478 rc
= sqlite3_user_delete(db
, zUser
);
8479 Tcl_SetResult(interp
, (char *)t1ErrorName(rc
), TCL_STATIC
);
8482 #endif /* SQLITE_USER_AUTHENTICATION */
8485 ** tclcmd: bad_behavior TYPE
8487 ** Do some things that should trigger a valgrind or -fsanitize=undefined
8488 ** warning. This is used to verify that errors and warnings output by those
8489 ** tools are detected by the test scripts.
8492 ** 1 Overflow a signed integer
8493 ** 2 Jump based on an uninitialized variable
8494 ** 3 Read after free
8497 static int SQLITE_TCLAPI
test_bad_behavior(
8498 ClientData clientData
, /* Pointer to an integer containing zero */
8499 Tcl_Interp
*interp
, /* The TCL interpreter that invoked this command */
8500 int objc
, /* Number of arguments */
8501 Tcl_Obj
*CONST objv
[] /* Command arguments */
8505 int i
= *(int*)clientData
;
8510 Tcl_WrongNumArgs(interp
, 1, objv
, "TYPE");
8513 if( Tcl_GetIntFromObj(interp
, objv
[1], &iType
) ) return TCL_ERROR
;
8516 xyz
= 0x7fffff00 - i
;
8518 Tcl_SetObjResult(interp
, Tcl_NewIntObj(xyz
));
8523 if( w
[i
]>0 ) w
[1]++;
8524 Tcl_SetObjResult(interp
, Tcl_NewIntObj(w
[1]));
8528 a
= malloc( sizeof(int)*10 );
8529 for(j
=0; j
<10; j
++) a
[j
] = j
;
8531 Tcl_SetObjResult(interp
, Tcl_NewIntObj(a
[i
]));
8535 Tcl_Panic("Deliberate panic");
8543 ** tclcmd: register_dbstat_vtab DB
8545 ** Cause the dbstat virtual table to be available on the connection DB
8547 static int SQLITE_TCLAPI
test_register_dbstat_vtab(
8551 Tcl_Obj
*CONST objv
[]
8553 #ifdef SQLITE_OMIT_VIRTUALTABLE
8554 Tcl_AppendResult(interp
, "dbstat not available because of "
8555 "SQLITE_OMIT_VIRTUALTABLE", (void*)0);
8558 struct SqliteDb
{ sqlite3
*db
; };
8560 Tcl_CmdInfo cmdInfo
;
8563 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
8567 zDb
= Tcl_GetString(objv
[1]);
8568 if( Tcl_GetCommandInfo(interp
, zDb
, &cmdInfo
) ){
8569 sqlite3
* db
= ((struct SqliteDb
*)cmdInfo
.objClientData
)->db
;
8570 sqlite3DbstatRegister(db
);
8573 #endif /* SQLITE_OMIT_VIRTUALTABLE */
8577 ** tclcmd: sqlite3_db_config DB SETTING VALUE
8579 ** Invoke sqlite3_db_config() for one of the setting values.
8581 static int SQLITE_TCLAPI
test_sqlite3_db_config(
8585 Tcl_Obj
*CONST objv
[]
8587 static const struct {
8591 { "FKEY", SQLITE_DBCONFIG_ENABLE_FKEY
},
8592 { "TRIGGER", SQLITE_DBCONFIG_ENABLE_TRIGGER
},
8593 { "FTS3_TOKENIZER", SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER
},
8594 { "LOAD_EXTENSION", SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION
},
8595 { "NO_CKPT_ON_CLOSE", SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE
},
8596 { "QPSG", SQLITE_DBCONFIG_ENABLE_QPSG
},
8597 { "TRIGGER_EQP", SQLITE_DBCONFIG_TRIGGER_EQP
},
8598 { "RESET_DB", SQLITE_DBCONFIG_RESET_DATABASE
},
8599 { "DEFENSIVE", SQLITE_DBCONFIG_DEFENSIVE
},
8600 { "WRITABLE_SCHEMA", SQLITE_DBCONFIG_WRITABLE_SCHEMA
},
8601 { "LEGACY_ALTER_TABLE", SQLITE_DBCONFIG_LEGACY_ALTER_TABLE
},
8602 { "DQS_DML", SQLITE_DBCONFIG_DQS_DML
},
8603 { "DQS_DDL", SQLITE_DBCONFIG_DQS_DDL
},
8604 { "LEGACY_FILE_FORMAT", SQLITE_DBCONFIG_LEGACY_FILE_FORMAT
},
8605 { "STMT_SCANSTATUS", SQLITE_DBCONFIG_STMT_SCANSTATUS
},
8609 const char *zSetting
;
8612 if( objc
!=4 && objc
!=3 ){
8613 Tcl_WrongNumArgs(interp
, 1, objv
, "DB SETTING [VALUE]");
8616 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8617 zSetting
= Tcl_GetString(objv
[2]);
8618 if( sqlite3_strglob("SQLITE_*", zSetting
)==0 ) zSetting
+= 7;
8619 if( sqlite3_strglob("DBCONFIG_*", zSetting
)==0 ) zSetting
+= 9;
8620 if( sqlite3_strglob("ENABLE_*", zSetting
)==0 ) zSetting
+= 7;
8621 for(i
=0; i
<ArraySize(aSetting
); i
++){
8622 if( strcmp(zSetting
, aSetting
[i
].zName
)==0 ) break;
8624 if( i
>=ArraySize(aSetting
) ){
8625 Tcl_SetObjResult(interp
,
8626 Tcl_NewStringObj("unknown sqlite3_db_config setting", -1));
8630 if( Tcl_GetIntFromObj(interp
, objv
[3], &v
) ) return TCL_ERROR
;
8634 sqlite3_db_config(db
, aSetting
[i
].eVal
, v
, &v
);
8635 Tcl_SetObjResult(interp
, Tcl_NewIntObj(v
));
8639 ** tclcmd: sqlite3_txn_state DB ?SCHEMA?
8641 ** Invoke sqlite3_txn_state(DB,SCHEMA) and return the
8642 ** numeric value that results. Use NULL for SCHEMA if the 3 argument
8645 static int SQLITE_TCLAPI
test_sqlite3_txn_state(
8649 Tcl_Obj
*CONST objv
[]
8652 const char *zSchema
;
8655 if( objc
!=2 && objc
!=3 ){
8656 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?SCHEMA?");
8659 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8660 zSchema
= objc
==3 ? Tcl_GetString(objv
[2]) : 0;
8661 iTxn
= sqlite3_txn_state(db
, zSchema
);
8662 Tcl_SetObjResult(interp
, Tcl_NewIntObj(iTxn
));
8667 ** Change the name of the main database schema from "main" to "icecube".
8669 static int SQLITE_TCLAPI
test_dbconfig_maindbname_icecube(
8673 Tcl_Obj
*CONST objv
[]
8677 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
8679 Tcl_WrongNumArgs(interp
, 1, objv
, "DB");
8682 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8683 rc
= sqlite3_db_config(db
, SQLITE_DBCONFIG_MAINDBNAME
, "icecube");
8684 Tcl_SetObjResult(interp
, Tcl_NewIntObj(rc
));
8690 ** Usage: sqlite3_mmap_warm DB DBNAME
8692 static int SQLITE_TCLAPI
test_mmap_warm(
8696 Tcl_Obj
*CONST objv
[]
8698 extern int getDbPointer(Tcl_Interp
*, const char*, sqlite3
**);
8699 extern int sqlite3_mmap_warm(sqlite3
*db
, const char *);
8701 if( objc
!=2 && objc
!=3 ){
8702 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?DBNAME?");
8707 const char *zDb
= 0;
8708 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8710 zDb
= Tcl_GetString(objv
[2]);
8712 rc
= sqlite3_mmap_warm(db
, zDb
);
8713 Tcl_SetObjResult(interp
, Tcl_NewStringObj(sqlite3ErrName(rc
), -1));
8719 ** Usage: test_write_db DB OFFSET DATA
8721 ** Obtain the sqlite3_file* object for the database file for the "main" db
8722 ** of handle DB. Then invoke its xWrite method to write data DATA to offset
8725 static int SQLITE_TCLAPI
test_write_db(
8729 Tcl_Obj
*CONST objv
[]
8732 Tcl_WideInt iOff
= 0;
8733 const unsigned char *aData
= 0;
8735 sqlite3_file
*pFile
= 0;
8739 Tcl_WrongNumArgs(interp
, 1, objv
, "DB OFFSET DATA");
8742 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8743 if( Tcl_GetWideIntFromObj(interp
, objv
[2], &iOff
) ) return TCL_ERROR
;
8744 aData
= Tcl_GetByteArrayFromObj(objv
[3], &nData
);
8746 sqlite3_file_control(db
, "main", SQLITE_FCNTL_FILE_POINTER
, (void*)&pFile
);
8747 rc
= pFile
->pMethods
->xWrite(pFile
, aData
, nData
, iOff
);
8749 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
8754 ** Usage: sqlite3_register_cksumvfs
8757 static int SQLITE_TCLAPI
test_register_cksumvfs(
8761 Tcl_Obj
*CONST objv
[]
8764 Tcl_WrongNumArgs(interp
, 1, objv
, "");
8767 extern int sqlite3_register_cksumvfs(const char*);
8768 int rc
= sqlite3_register_cksumvfs(0);
8769 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
8775 ** Usage: sqlite3_unregister_cksumvfs
8778 static int SQLITE_TCLAPI
test_unregister_cksumvfs(
8782 Tcl_Obj
*CONST objv
[]
8785 Tcl_WrongNumArgs(interp
, 1, objv
, "");
8788 extern int sqlite3_unregister_cksumvfs(void);
8789 int rc
= sqlite3_unregister_cksumvfs();
8790 Tcl_SetResult(interp
, (char *)sqlite3ErrName(rc
), TCL_VOLATILE
);
8796 ** Usage: decode_hexdb TEXT
8798 ** Example: db deserialize [decode_hexdb $output_of_dbtotxt]
8800 ** This routine returns a byte-array for an SQLite database file that
8801 ** is constructed from a text input which is the output of the "dbtotxt"
8804 static int SQLITE_TCLAPI
test_decode_hexdb(
8808 Tcl_Obj
*CONST objv
[]
8810 const char *zIn
= 0;
8811 unsigned char *a
= 0;
8820 Tcl_WrongNumArgs(interp
, 1, objv
, "HEXDB");
8823 zIn
= Tcl_GetString(objv
[1]);
8824 for(i
=0; zIn
[i
]; i
=iNext
){
8826 for(iNext
=i
; zIn
[iNext
] && zIn
[iNext
]!='\n'; iNext
++){}
8827 if( zIn
[iNext
]=='\n' ) iNext
++;
8828 while( zIn
[i
]==' ' || zIn
[i
]=='\t' ){ i
++; }
8831 rc
= sscanf(zIn
+i
, "| size %d pagesize %d", &n
, &pgsz
);
8832 if( rc
!=2 ) continue;
8833 if( pgsz
<512 || pgsz
>65536 || (pgsz
&(pgsz
-1))!=0 ){
8834 Tcl_AppendResult(interp
, "bad 'pagesize' field", (void*)0);
8837 n
= (n
+pgsz
-1)&~(pgsz
-1); /* Round n up to the next multiple of pgsz */
8839 Tcl_AppendResult(interp
, "bad 'size' field", (void*)0);
8844 Tcl_AppendResult(interp
, "out of memory", (void*)0);
8850 rc
= sscanf(zIn
+i
, "| page %d offset %d", &j
, &k
);
8855 rc
= sscanf(zIn
+i
,"| %d: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x",
8856 &j
, &x
[0], &x
[1], &x
[2], &x
[3], &x
[4], &x
[5], &x
[6], &x
[7],
8857 &x
[8], &x
[9], &x
[10], &x
[11], &x
[12], &x
[13], &x
[14], &x
[15]);
8862 for(ii
=0; ii
<16; ii
++) a
[k
+ii
] = x
[ii
]&0xff;
8867 Tcl_SetObjResult(interp
, Tcl_NewByteArrayObj(a
, n
));
8873 ** Client data for the autovacuum_pages callback.
8875 struct AutovacPageData
{
8879 typedef struct AutovacPageData AutovacPageData
;
8882 ** Callback functions for sqlite3_autovacuum_pages
8884 static unsigned int test_autovacuum_pages_callback(
8886 const char *zSchema
,
8887 unsigned int nFilePages
,
8888 unsigned int nFreePages
,
8889 unsigned int nBytePerPage
8891 AutovacPageData
*pData
= (AutovacPageData
*)pClientData
;
8895 Tcl_DStringInit(&str
);
8896 Tcl_DStringAppend(&str
, pData
->zScript
, -1);
8897 Tcl_DStringAppendElement(&str
, zSchema
);
8898 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%u", nFilePages
);
8899 Tcl_DStringAppendElement(&str
, zBuf
);
8900 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%u", nFreePages
);
8901 Tcl_DStringAppendElement(&str
, zBuf
);
8902 sqlite3_snprintf(sizeof(zBuf
), zBuf
, "%u", nBytePerPage
);
8903 Tcl_DStringAppendElement(&str
, zBuf
);
8904 Tcl_ResetResult(pData
->interp
);
8905 Tcl_Eval(pData
->interp
, Tcl_DStringValue(&str
));
8906 Tcl_DStringFree(&str
);
8908 (void)Tcl_GetIntFromObj(0, Tcl_GetObjResult(pData
->interp
), (int*)&x
);
8913 ** Usage: sqlite3_autovacuum_pages DB SCRIPT
8915 ** Add an autovacuum-pages callback to database connection DB. The callback
8916 ** will invoke SCRIPT, after appending parameters.
8918 ** If SCRIPT is an empty string or is omitted, then the callback is
8921 static int SQLITE_TCLAPI
test_autovacuum_pages(
8925 Tcl_Obj
*CONST objv
[]
8927 AutovacPageData
*pData
;
8930 const char *zScript
;
8931 if( objc
!=2 && objc
!=3 ){
8932 Tcl_WrongNumArgs(interp
, 1, objv
, "DB ?SCRIPT?");
8935 if( getDbPointer(interp
, Tcl_GetString(objv
[1]), &db
) ) return TCL_ERROR
;
8936 zScript
= objc
==3 ? Tcl_GetString(objv
[2]) : 0;
8938 size_t nScript
= strlen(zScript
);
8939 pData
= sqlite3_malloc64( sizeof(*pData
) + nScript
+ 1 );
8941 Tcl_AppendResult(interp
, "out of memory", (void*)0);
8944 pData
->interp
= interp
;
8945 pData
->zScript
= (char*)&pData
[1];
8946 memcpy(pData
->zScript
, zScript
, nScript
+1);
8947 rc
= sqlite3_autovacuum_pages(db
,test_autovacuum_pages_callback
,
8948 pData
, sqlite3_free
);
8950 rc
= sqlite3_autovacuum_pages(db
, 0, 0, 0);
8954 sqlite3_snprintf(sizeof(zBuf
), zBuf
,
8955 "sqlite3_autovacuum_pages() returns %d", rc
);
8956 Tcl_AppendResult(interp
, zBuf
, (void*)0);
8963 ** Usage: number_of_cores
8965 ** Return a guess at the number of available cores available on the
8966 ** processor on which this process is running.
8968 static int SQLITE_TCLAPI
guess_number_of_cores(
8972 Tcl_Obj
*CONST objv
[]
8974 unsigned int nCore
= 1;
8976 SYSTEM_INFO sysinfo
;
8977 GetSystemInfo(&sysinfo
);
8978 nCore
= (unsigned int)sysinfo
.dwNumberOfProcessors
;
8979 #elif defined(__APPLE__)
8982 nm
[0] = CTL_HW
; nm
[1] = HW_AVAILCPU
;
8983 sysctl(nm
, 2, &nCore
, &len
, NULL
, 0);
8986 sysctl(nm
, 2, &nCore
, &len
, NULL
, 0);
8989 nCore
= sysconf(_SC_NPROCESSORS_ONLN
);
8991 if( nCore
<=0 ) nCore
= 1;
8992 Tcl_SetObjResult(interp
, Tcl_NewIntObj((int)nCore
));
8998 ** Register commands with the TCL interpreter.
9000 int Sqlitetest1_Init(Tcl_Interp
*interp
){
9001 extern int sqlite3_search_count
;
9002 extern int sqlite3_found_count
;
9003 extern int sqlite3_interrupt_count
;
9004 extern int sqlite3_open_file_count
;
9005 extern int sqlite3_sort_count
;
9006 extern int sqlite3_current_time
;
9007 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
9008 extern int sqlite3_hostid_num
;
9010 extern int sqlite3_max_blobsize
;
9011 extern int SQLITE_TCLAPI
sqlite3BtreeSharedCacheReport(void*,
9012 Tcl_Interp
*,int,Tcl_Obj
*CONST
*);
9013 static int iZero
= 0;
9018 { "db_enter", (Tcl_CmdProc
*)db_enter
},
9019 { "db_leave", (Tcl_CmdProc
*)db_leave
},
9020 { "sqlite3_mprintf_int", (Tcl_CmdProc
*)sqlite3_mprintf_int
},
9021 { "sqlite3_mprintf_int64", (Tcl_CmdProc
*)sqlite3_mprintf_int64
},
9022 { "sqlite3_mprintf_long", (Tcl_CmdProc
*)sqlite3_mprintf_long
},
9023 { "sqlite3_mprintf_str", (Tcl_CmdProc
*)sqlite3_mprintf_str
},
9024 { "sqlite3_snprintf_str", (Tcl_CmdProc
*)sqlite3_snprintf_str
},
9025 { "sqlite3_mprintf_stronly", (Tcl_CmdProc
*)sqlite3_mprintf_stronly
},
9026 { "sqlite3_mprintf_double", (Tcl_CmdProc
*)sqlite3_mprintf_double
},
9027 { "sqlite3_mprintf_scaled", (Tcl_CmdProc
*)sqlite3_mprintf_scaled
},
9028 { "sqlite3_mprintf_hexdouble", (Tcl_CmdProc
*)sqlite3_mprintf_hexdouble
},
9029 { "sqlite3_mprintf_z_test", (Tcl_CmdProc
*)test_mprintf_z
},
9030 { "sqlite3_mprintf_n_test", (Tcl_CmdProc
*)test_mprintf_n
},
9031 { "sqlite3_snprintf_int", (Tcl_CmdProc
*)test_snprintf_int
},
9032 { "sqlite3_last_insert_rowid", (Tcl_CmdProc
*)test_last_rowid
},
9033 { "sqlite3_exec_printf", (Tcl_CmdProc
*)test_exec_printf
},
9034 { "sqlite3_exec_hex", (Tcl_CmdProc
*)test_exec_hex
},
9035 { "sqlite3_exec", (Tcl_CmdProc
*)test_exec
},
9036 { "sqlite3_exec_nr", (Tcl_CmdProc
*)test_exec_nr
},
9037 #ifndef SQLITE_OMIT_GET_TABLE
9038 { "sqlite3_get_table_printf", (Tcl_CmdProc
*)test_get_table_printf
},
9040 { "sqlite3_close", (Tcl_CmdProc
*)sqlite_test_close
},
9041 { "sqlite3_close_v2", (Tcl_CmdProc
*)sqlite_test_close_v2
},
9042 { "sqlite3_create_function", (Tcl_CmdProc
*)test_create_function
},
9043 { "sqlite3_create_aggregate", (Tcl_CmdProc
*)test_create_aggregate
},
9044 { "sqlite3_drop_modules", (Tcl_CmdProc
*)test_drop_modules
},
9045 { "sqlite_register_test_function", (Tcl_CmdProc
*)test_register_func
},
9046 { "sqlite_abort", (Tcl_CmdProc
*)sqlite_abort
},
9047 { "sqlite_bind", (Tcl_CmdProc
*)test_bind
},
9048 { "breakpoint", (Tcl_CmdProc
*)test_breakpoint
},
9049 { "sqlite3_key", (Tcl_CmdProc
*)test_key
},
9050 { "sqlite3_rekey", (Tcl_CmdProc
*)test_rekey
},
9051 { "sqlite3_interrupt", (Tcl_CmdProc
*)test_interrupt
},
9052 { "sqlite3_is_interrupted", (Tcl_CmdProc
*)test_is_interrupted
},
9053 { "sqlite_delete_function", (Tcl_CmdProc
*)delete_function
},
9054 { "sqlite_delete_collation", (Tcl_CmdProc
*)delete_collation
},
9055 { "sqlite3_get_autocommit", (Tcl_CmdProc
*)get_autocommit
},
9056 { "sqlite3_busy_timeout", (Tcl_CmdProc
*)test_busy_timeout
},
9057 { "printf", (Tcl_CmdProc
*)test_printf
},
9058 { "sqlite3IoTrace", (Tcl_CmdProc
*)test_io_trace
},
9059 { "clang_sanitize_address", (Tcl_CmdProc
*)clang_sanitize_address
},
9063 Tcl_ObjCmdProc
*xProc
;
9066 { "sqlite3_db_config", test_sqlite3_db_config
, 0 },
9067 { "sqlite3_txn_state", test_sqlite3_txn_state
, 0 },
9068 { "bad_behavior", test_bad_behavior
, (void*)&iZero
},
9069 { "register_dbstat_vtab", test_register_dbstat_vtab
},
9070 { "sqlite3_connection_pointer", get_sqlite_pointer
, 0 },
9071 { "intarray_addr", test_intarray_addr
, 0 },
9072 { "int64array_addr", test_int64array_addr
, 0 },
9073 { "doublearray_addr", test_doublearray_addr
, 0 },
9074 { "textarray_addr", test_textarray_addr
, 0 },
9075 { "sqlite3_bind_int", test_bind_int
, 0 },
9076 { "sqlite3_bind_zeroblob", test_bind_zeroblob
, 0 },
9077 { "sqlite3_bind_zeroblob64", test_bind_zeroblob64
, 0 },
9078 { "sqlite3_bind_int64", test_bind_int64
, 0 },
9079 { "sqlite3_bind_double", test_bind_double
, 0 },
9080 { "sqlite3_bind_null", test_bind_null
,0 },
9081 { "sqlite3_bind_text", test_bind_text
,0 },
9082 { "sqlite3_bind_text16", test_bind_text16
,0 },
9083 { "sqlite3_bind_blob", test_bind_blob
,0 },
9084 { "sqlite3_bind_value_from_select",test_bind_value_from_select
,0 },
9085 { "sqlite3_bind_value_from_preupdate",test_bind_value_from_preupdate
,0 },
9086 #ifndef SQLITE_OMIT_VIRTUALTABLE
9087 { "sqlite3_carray_bind", test_carray_bind
,0 },
9089 { "sqlite3_bind_parameter_count", test_bind_parameter_count
, 0},
9090 { "sqlite3_bind_parameter_name", test_bind_parameter_name
, 0},
9091 { "sqlite3_bind_parameter_index", test_bind_parameter_index
, 0},
9092 { "sqlite3_clear_bindings", test_clear_bindings
, 0},
9093 { "sqlite3_sleep", test_sleep
, 0},
9094 { "sqlite3_errcode", test_errcode
,0 },
9095 { "sqlite3_extended_errcode", test_ex_errcode
,0 },
9096 { "sqlite3_errmsg", test_errmsg
,0 },
9097 { "sqlite3_error_offset", test_error_offset
,0 },
9098 { "sqlite3_errmsg16", test_errmsg16
,0 },
9099 { "sqlite3_open", test_open
,0 },
9100 { "sqlite3_open16", test_open16
,0 },
9101 { "sqlite3_open_v2", test_open_v2
,0 },
9102 { "sqlite3_complete16", test_complete16
,0 },
9103 { "sqlite3_normalize", test_normalize
,0 },
9105 { "sqlite3_prepare", test_prepare
,0 },
9106 { "sqlite3_prepare16", test_prepare16
,0 },
9107 { "sqlite3_prepare_v2", test_prepare_v2
,0 },
9108 { "sqlite3_prepare_v3", test_prepare_v3
,0 },
9109 { "sqlite3_prepare_tkt3134", test_prepare_tkt3134
, 0},
9110 { "sqlite3_prepare16_v2", test_prepare16_v2
,0 },
9111 { "sqlite3_finalize", test_finalize
,0 },
9112 { "sqlite3_stmt_status", test_stmt_status
,0 },
9113 { "sqlite3_reset", test_reset
,0 },
9114 { "sqlite3_expired", test_expired
,0 },
9115 { "sqlite3_transfer_bindings", test_transfer_bind
,0 },
9116 { "sqlite3_changes", test_changes
,0 },
9117 { "sqlite3_step", test_step
,0 },
9118 { "sqlite3_sql", test_sql
,0 },
9119 { "sqlite3_expanded_sql", test_ex_sql
,0 },
9120 #ifdef SQLITE_ENABLE_NORMALIZE
9121 { "sqlite3_normalized_sql", test_norm_sql
,0 },
9123 { "sqlite3_next_stmt", test_next_stmt
,0 },
9124 { "sqlite3_stmt_readonly", test_stmt_readonly
,0 },
9125 { "sqlite3_stmt_isexplain", test_stmt_isexplain
,0 },
9126 { "sqlite3_stmt_explain", test_stmt_explain
,0 },
9127 { "sqlite3_stmt_busy", test_stmt_busy
,0 },
9128 { "uses_stmt_journal", uses_stmt_journal
,0 },
9130 { "sqlite3_release_memory", test_release_memory
, 0},
9131 { "sqlite3_db_release_memory", test_db_release_memory
, 0},
9132 { "sqlite3_db_cacheflush", test_db_cacheflush
, 0},
9133 { "sqlite3_system_errno", test_system_errno
, 0},
9134 { "sqlite3_db_filename", test_db_filename
, 0},
9135 { "sqlite3_db_readonly", test_db_readonly
, 0},
9136 { "sqlite3_soft_heap_limit", test_soft_heap_limit
, 0},
9137 { "sqlite3_soft_heap_limit64", test_soft_heap_limit
, 0},
9138 { "sqlite3_hard_heap_limit64", test_hard_heap_limit
, 0},
9139 { "sqlite3_thread_cleanup", test_thread_cleanup
, 0},
9140 { "sqlite3_pager_refcounts", test_pager_refcounts
, 0},
9142 { "sqlite3_load_extension", test_load_extension
, 0},
9143 { "sqlite3_enable_load_extension", test_enable_load
, 0},
9144 { "sqlite3_extended_result_codes", test_extended_result_codes
, 0},
9145 { "sqlite3_limit", test_limit
, 0},
9146 { "dbconfig_maindbname_icecube", test_dbconfig_maindbname_icecube
},
9148 { "save_prng_state", save_prng_state
, 0 },
9149 { "restore_prng_state", restore_prng_state
, 0 },
9150 { "reset_prng_state", reset_prng_state
, 0 },
9151 { "prng_seed", prng_seed
, 0 },
9152 { "extra_schema_checks", extra_schema_checks
, 0},
9153 { "use_long_double", use_long_double
, 0},
9154 { "database_never_corrupt", database_never_corrupt
, 0},
9155 { "database_may_be_corrupt", database_may_be_corrupt
, 0},
9156 { "optimization_control", optimization_control
,0},
9158 { "lock_win32_file", win32_file_lock
, 0 },
9159 { "exists_win32_path", win32_exists_path
, 0 },
9160 { "find_win32_file", win32_find_file
, 0 },
9161 { "delete_win32_file", win32_delete_file
, 0 },
9162 { "make_win32_dir", win32_mkdir
, 0 },
9163 { "remove_win32_dir", win32_rmdir
, 0 },
9165 { "tcl_objproc", runAsObjProc
, 0 },
9167 /* sqlite3_column_*() API */
9168 { "sqlite3_column_count", test_column_count
,0 },
9169 { "sqlite3_data_count", test_data_count
,0 },
9170 { "sqlite3_column_type", test_column_type
,0 },
9171 { "sqlite3_column_blob", test_column_blob
,0 },
9172 { "sqlite3_column_double", test_column_double
,0 },
9173 { "sqlite3_column_int64", test_column_int64
,0 },
9174 { "sqlite3_column_text", test_stmt_utf8
, (void*)sqlite3_column_text
},
9175 { "sqlite3_column_name", test_stmt_utf8
, (void*)sqlite3_column_name
},
9176 { "sqlite3_column_int", test_stmt_int
, (void*)sqlite3_column_int
},
9177 { "sqlite3_column_bytes", test_stmt_int
, (void*)sqlite3_column_bytes
},
9178 #ifndef SQLITE_OMIT_DECLTYPE
9179 { "sqlite3_column_decltype",test_stmt_utf8
,(void*)sqlite3_column_decltype
},
9181 #ifdef SQLITE_ENABLE_COLUMN_METADATA
9182 { "sqlite3_column_database_name",test_stmt_utf8
,(void*)sqlite3_column_database_name
},
9183 { "sqlite3_column_table_name",test_stmt_utf8
,(void*)sqlite3_column_table_name
},
9184 { "sqlite3_column_origin_name",test_stmt_utf8
,(void*)sqlite3_column_origin_name
},
9187 #ifndef SQLITE_OMIT_UTF16
9188 { "sqlite3_column_bytes16", test_stmt_int
, (void*)sqlite3_column_bytes16
},
9189 { "sqlite3_column_text16", test_stmt_utf16
, (void*)sqlite3_column_text16
},
9190 { "sqlite3_column_name16", test_stmt_utf16
, (void*)sqlite3_column_name16
},
9191 { "add_alignment_test_collations", add_alignment_test_collations
, 0 },
9192 #ifndef SQLITE_OMIT_DECLTYPE
9193 { "sqlite3_column_decltype16",test_stmt_utf16
,(void*)sqlite3_column_decltype16
},
9195 #ifdef SQLITE_ENABLE_COLUMN_METADATA
9196 {"sqlite3_column_database_name16",
9197 test_stmt_utf16
, (void*)sqlite3_column_database_name16
},
9198 {"sqlite3_column_table_name16", test_stmt_utf16
, (void*)sqlite3_column_table_name16
},
9199 {"sqlite3_column_origin_name16", test_stmt_utf16
, (void*)sqlite3_column_origin_name16
},
9202 { "sqlite3_create_collation_v2", test_create_collation_v2
, 0 },
9203 { "sqlite3_global_recover", test_global_recover
, 0 },
9204 { "working_64bit_int", working_64bit_int
, 0 },
9205 { "vfs_unlink_test", vfs_unlink_test
, 0 },
9206 { "vfs_initfail_test", vfs_initfail_test
, 0 },
9207 { "vfs_unregister_all", vfs_unregister_all
, 0 },
9208 { "vfs_reregister_all", vfs_reregister_all
, 0 },
9209 { "file_control_test", file_control_test
, 0 },
9210 { "file_control_lasterrno_test", file_control_lasterrno_test
, 0 },
9211 { "file_control_lockproxy_test", file_control_lockproxy_test
, 0 },
9212 { "file_control_chunksize_test", file_control_chunksize_test
, 0 },
9213 { "file_control_sizehint_test", file_control_sizehint_test
, 0 },
9214 { "file_control_data_version", file_control_data_version
, 0 },
9216 { "file_control_win32_av_retry", file_control_win32_av_retry
, 0 },
9217 { "file_control_win32_get_handle", file_control_win32_get_handle
, 0 },
9218 { "file_control_win32_set_handle", file_control_win32_set_handle
, 0 },
9220 { "file_control_persist_wal", file_control_persist_wal
, 0 },
9221 { "file_control_powersafe_overwrite",file_control_powersafe_overwrite
,0},
9222 { "file_control_vfsname", file_control_vfsname
, 0 },
9223 { "file_control_reservebytes", file_control_reservebytes
, 0 },
9224 { "file_control_tempfilename", file_control_tempfilename
, 0 },
9225 { "file_control_external_reader", file_control_external_reader
, 0 },
9226 { "sqlite3_vfs_list", vfs_list
, 0 },
9227 { "sqlite3_create_function_v2", test_create_function_v2
, 0 },
9229 /* Functions from os.h */
9230 #ifndef SQLITE_OMIT_UTF16
9231 { "add_test_collate", test_collate
, 0 },
9232 { "add_test_collate_needed", test_collate_needed
, 0 },
9233 { "add_test_function", test_function
, 0 },
9234 { "add_test_utf16bin_collate", test_utf16bin_collate
, 0 },
9236 { "sqlite3_test_errstr", test_errstr
, 0 },
9237 { "tcl_variable_type", tcl_variable_type
, 0 },
9238 #ifndef SQLITE_OMIT_SHARED_CACHE
9239 { "sqlite3_enable_shared_cache", test_enable_shared
, 0 },
9240 { "sqlite3_shared_cache_report", sqlite3BtreeSharedCacheReport
, 0},
9242 { "sqlite3_libversion_number", test_libversion_number
, 0 },
9243 { "sqlite3_table_column_metadata", test_table_column_metadata
, 0 },
9244 #ifndef SQLITE_OMIT_INCRBLOB
9245 { "sqlite3_blob_reopen", test_blob_reopen
, 0 },
9247 { "pcache_stats", test_pcache_stats
, 0 },
9248 #ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
9249 { "sqlite3_unlock_notify", test_unlock_notify
, 0 },
9251 { "sqlite3_wal_checkpoint", test_wal_checkpoint
, 0 },
9252 { "sqlite3_wal_checkpoint_v2",test_wal_checkpoint_v2
, 0 },
9253 { "sqlite3_wal_autocheckpoint",test_wal_autocheckpoint
, 0 },
9254 { "test_sqlite3_log", test_sqlite3_log
, 0 },
9255 #ifndef SQLITE_OMIT_EXPLAIN
9256 { "print_explain_query_plan", test_print_eqp
, 0 },
9258 { "strftime", strftime_cmd
},
9259 { "sqlite3_test_control", test_test_control
},
9260 { ".treetrace", test_treetrace
},
9262 { "getrusage", test_getrusage
},
9264 { "load_static_extension", tclLoadStaticExtensionCmd
},
9265 { "sorter_test_fakeheap", sorter_test_fakeheap
},
9266 { "sorter_test_sort4_helper", sorter_test_sort4_helper
},
9267 #ifdef SQLITE_USER_AUTHENTICATION
9268 { "sqlite3_user_authenticate", test_user_authenticate
, 0 },
9269 { "sqlite3_user_add", test_user_add
, 0 },
9270 { "sqlite3_user_change", test_user_change
, 0 },
9271 { "sqlite3_user_delete", test_user_delete
, 0 },
9273 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
9274 { "sqlite3_stmt_scanstatus", test_stmt_scanstatus
, 0 },
9275 { "sqlite3_stmt_scanstatus_reset", test_stmt_scanstatus_reset
, 0 },
9277 #ifdef SQLITE_ENABLE_SQLLOG
9278 { "sqlite3_config_sqllog", test_config_sqllog
, 0 },
9280 { "vfs_current_time_int64", vfsCurrentTimeInt64
, 0 },
9281 #ifdef SQLITE_ENABLE_SNAPSHOT
9282 { "sqlite3_snapshot_get", test_snapshot_get
, 0 },
9283 { "sqlite3_snapshot_open", test_snapshot_open
, 0 },
9284 { "sqlite3_snapshot_free", test_snapshot_free
, 0 },
9285 { "sqlite3_snapshot_cmp", test_snapshot_cmp
, 0 },
9286 { "sqlite3_snapshot_recover", test_snapshot_recover
, 0 },
9287 { "sqlite3_snapshot_get_blob", test_snapshot_get_blob
, 0 },
9288 { "sqlite3_snapshot_open_blob", test_snapshot_open_blob
, 0 },
9289 { "sqlite3_snapshot_cmp_blob", test_snapshot_cmp_blob
, 0 },
9291 { "sqlite3_delete_database", test_delete_database
, 0 },
9292 { "atomic_batch_write", test_atomic_batch_write
, 0 },
9293 { "sqlite3_mmap_warm", test_mmap_warm
, 0 },
9294 { "sqlite3_config_sorterref", test_config_sorterref
, 0 },
9295 { "sqlite3_autovacuum_pages", test_autovacuum_pages
, 0 },
9296 { "decode_hexdb", test_decode_hexdb
, 0 },
9297 { "test_write_db", test_write_db
, 0 },
9298 { "sqlite3_register_cksumvfs", test_register_cksumvfs
, 0 },
9299 { "sqlite3_unregister_cksumvfs", test_unregister_cksumvfs
, 0 },
9300 { "number_of_cores", guess_number_of_cores
, 0 },
9301 #ifndef SQLITE_OMIT_VIRTUALTABLE
9302 { "create_null_module", test_create_null_module
, 0 },
9305 static int bitmask_size
= sizeof(Bitmask
)*8;
9306 static int longdouble_size
= sizeof(LONGDOUBLE_TYPE
);
9308 extern int sqlite3_sync_count
, sqlite3_fullsync_count
;
9309 extern int sqlite3_opentemp_count
;
9310 extern int sqlite3_like_count
;
9311 extern int sqlite3_xferopt_count
;
9312 extern int sqlite3_pager_readdb_count
;
9313 extern int sqlite3_pager_writedb_count
;
9314 extern int sqlite3_pager_writej_count
;
9316 extern LONG
volatile sqlite3_os_type
;
9319 extern u32 sqlite3WhereTrace
;
9320 extern int sqlite3OSTrace
;
9321 extern int sqlite3WalTrace
;
9324 #ifdef SQLITE_ENABLE_FTS3
9325 extern int sqlite3_fts3_enable_parentheses
;
9329 for(i
=0; i
<sizeof(aCmd
)/sizeof(aCmd
[0]); i
++){
9330 Tcl_CreateCommand(interp
, aCmd
[i
].zName
, aCmd
[i
].xProc
, 0, 0);
9332 for(i
=0; i
<sizeof(aObjCmd
)/sizeof(aObjCmd
[0]); i
++){
9333 Tcl_CreateObjCommand(interp
, aObjCmd
[i
].zName
,
9334 aObjCmd
[i
].xProc
, aObjCmd
[i
].clientData
, 0);
9336 Tcl_LinkVar(interp
, "sqlite_search_count",
9337 (char*)&sqlite3_search_count
, TCL_LINK_INT
);
9338 Tcl_LinkVar(interp
, "sqlite_found_count",
9339 (char*)&sqlite3_found_count
, TCL_LINK_INT
);
9340 Tcl_LinkVar(interp
, "sqlite_sort_count",
9341 (char*)&sqlite3_sort_count
, TCL_LINK_INT
);
9342 Tcl_LinkVar(interp
, "sqlite3_max_blobsize",
9343 (char*)&sqlite3_max_blobsize
, TCL_LINK_INT
);
9344 Tcl_LinkVar(interp
, "sqlite_like_count",
9345 (char*)&sqlite3_like_count
, TCL_LINK_INT
);
9346 Tcl_LinkVar(interp
, "sqlite_interrupt_count",
9347 (char*)&sqlite3_interrupt_count
, TCL_LINK_INT
);
9348 Tcl_LinkVar(interp
, "sqlite_open_file_count",
9349 (char*)&sqlite3_open_file_count
, TCL_LINK_INT
);
9350 Tcl_LinkVar(interp
, "sqlite_current_time",
9351 (char*)&sqlite3_current_time
, TCL_LINK_INT
);
9352 #if SQLITE_OS_UNIX && defined(__APPLE__) && SQLITE_ENABLE_LOCKING_STYLE
9353 Tcl_LinkVar(interp
, "sqlite_hostid_num",
9354 (char*)&sqlite3_hostid_num
, TCL_LINK_INT
);
9356 Tcl_LinkVar(interp
, "sqlite3_xferopt_count",
9357 (char*)&sqlite3_xferopt_count
, TCL_LINK_INT
);
9358 Tcl_LinkVar(interp
, "sqlite3_pager_readdb_count",
9359 (char*)&sqlite3_pager_readdb_count
, TCL_LINK_INT
);
9360 Tcl_LinkVar(interp
, "sqlite3_pager_writedb_count",
9361 (char*)&sqlite3_pager_writedb_count
, TCL_LINK_INT
);
9362 Tcl_LinkVar(interp
, "sqlite3_pager_writej_count",
9363 (char*)&sqlite3_pager_writej_count
, TCL_LINK_INT
);
9364 #ifndef SQLITE_OMIT_UTF16
9365 Tcl_LinkVar(interp
, "unaligned_string_counter",
9366 (char*)&unaligned_string_counter
, TCL_LINK_INT
);
9368 #ifndef SQLITE_OMIT_UTF16
9369 Tcl_LinkVar(interp
, "sqlite_last_needed_collation",
9370 (char*)&pzNeededCollation
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
9373 Tcl_LinkVar(interp
, "sqlite_os_type",
9374 (char*)&sqlite3_os_type
, TCL_LINK_LONG
);
9378 static const char *query_plan
= "*** OBSOLETE VARIABLE ***";
9379 Tcl_LinkVar(interp
, "sqlite_query_plan",
9380 (char*)&query_plan
, TCL_LINK_STRING
|TCL_LINK_READ_ONLY
);
9384 Tcl_LinkVar(interp
, "sqlite_where_trace",
9385 (char*)&sqlite3WhereTrace
, TCL_LINK_INT
);
9386 Tcl_LinkVar(interp
, "sqlite_os_trace",
9387 (char*)&sqlite3OSTrace
, TCL_LINK_INT
);
9388 #ifndef SQLITE_OMIT_WAL
9389 Tcl_LinkVar(interp
, "sqlite_wal_trace",
9390 (char*)&sqlite3WalTrace
, TCL_LINK_INT
);
9393 #ifndef SQLITE_OMIT_DISKIO
9394 Tcl_LinkVar(interp
, "sqlite_opentemp_count",
9395 (char*)&sqlite3_opentemp_count
, TCL_LINK_INT
);
9397 Tcl_LinkVar(interp
, "sqlite_static_bind_value",
9398 (char*)&sqlite_static_bind_value
, TCL_LINK_STRING
);
9399 Tcl_LinkVar(interp
, "sqlite_static_bind_nbyte",
9400 (char*)&sqlite_static_bind_nbyte
, TCL_LINK_INT
);
9401 Tcl_LinkVar(interp
, "sqlite_temp_directory",
9402 (char*)&sqlite3_temp_directory
, TCL_LINK_STRING
);
9403 Tcl_LinkVar(interp
, "sqlite_data_directory",
9404 (char*)&sqlite3_data_directory
, TCL_LINK_STRING
);
9405 Tcl_LinkVar(interp
, "bitmask_size",
9406 (char*)&bitmask_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
9407 Tcl_LinkVar(interp
, "longdouble_size",
9408 (char*)&longdouble_size
, TCL_LINK_INT
|TCL_LINK_READ_ONLY
);
9409 Tcl_LinkVar(interp
, "sqlite_sync_count",
9410 (char*)&sqlite3_sync_count
, TCL_LINK_INT
);
9411 Tcl_LinkVar(interp
, "sqlite_fullsync_count",
9412 (char*)&sqlite3_fullsync_count
, TCL_LINK_INT
);
9413 #if defined(SQLITE_ENABLE_TREETRACE)
9414 Tcl_LinkVar(interp
, "sqlite3_unsupported_treetrace",
9415 (char*)&sqlite3TreeTrace
, TCL_LINK_INT
);
9417 #if defined(SQLITE_ENABLE_FTS3) && defined(SQLITE_TEST)
9418 Tcl_LinkVar(interp
, "sqlite_fts3_enable_parentheses",
9419 (char*)&sqlite3_fts3_enable_parentheses
, TCL_LINK_INT
);