2001-04-07 19:24:33 +04:00
|
|
|
/*
|
2001-09-16 04:13:26 +04:00
|
|
|
** 2001 September 15
|
2001-04-07 19:24:33 +04:00
|
|
|
**
|
2001-09-16 04:13:26 +04:00
|
|
|
** The author disclaims copyright to this source code. In place of
|
|
|
|
** a legal notice, here is a blessing:
|
2001-04-07 19:24:33 +04:00
|
|
|
**
|
2001-09-16 04:13:26 +04:00
|
|
|
** May you do good and not evil.
|
|
|
|
** May you find forgiveness for yourself and forgive others.
|
|
|
|
** May you share freely, never taking more than you give.
|
2001-04-07 19:24:33 +04:00
|
|
|
**
|
|
|
|
*************************************************************************
|
|
|
|
** Code for testing the printf() interface to SQLite. This code
|
|
|
|
** is not included in the SQLite library. It is used for automated
|
|
|
|
** testing of the SQLite library.
|
|
|
|
**
|
2006-02-10 06:06:10 +03:00
|
|
|
** $Id: test1.c,v 1.206 2006/02/10 03:06:10 danielk1977 Exp $
|
2001-04-07 19:24:33 +04:00
|
|
|
*/
|
|
|
|
#include "sqliteInt.h"
|
|
|
|
#include "tcl.h"
|
2003-02-17 01:21:32 +03:00
|
|
|
#include "os.h"
|
2001-04-07 19:24:33 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2006-01-03 03:33:50 +03:00
|
|
|
/*
|
|
|
|
** This is a copy of the first part of the SqliteDb structure in
|
|
|
|
** tclsqlite.c. We need it here so that the get_sqlite_pointer routine
|
|
|
|
** can extract the sqlite3* pointer from an existing Tcl SQLite
|
|
|
|
** connection.
|
|
|
|
*/
|
|
|
|
struct SqliteDb {
|
|
|
|
sqlite3 *db;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
** A TCL command that returns the address of the sqlite* pointer
|
|
|
|
** for an sqlite connection instance. Bad things happen if the
|
|
|
|
** input is not an sqlite connection.
|
|
|
|
*/
|
|
|
|
static int get_sqlite_pointer(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
struct SqliteDb *p;
|
|
|
|
Tcl_CmdInfo cmdInfo;
|
|
|
|
char zBuf[100];
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "SQLITE-CONNECTION");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( !Tcl_GetCommandInfo(interp, Tcl_GetString(objv[1]), &cmdInfo) ){
|
|
|
|
Tcl_AppendResult(interp, "command not found: ",
|
|
|
|
Tcl_GetString(objv[1]), (char*)0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
p = (struct SqliteDb*)cmdInfo.objClientData;
|
|
|
|
sprintf(zBuf, "%p", p->db);
|
|
|
|
if( strncmp(zBuf,"0x",2) ){
|
|
|
|
sprintf(zBuf, "0x%p", p->db);
|
|
|
|
}
|
|
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-28 21:18:48 +04:00
|
|
|
const char *sqlite3TestErrorName(int rc){
|
2004-05-20 15:00:52 +04:00
|
|
|
const char *zName = 0;
|
|
|
|
switch( rc ){
|
|
|
|
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
|
|
|
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
|
|
|
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
|
|
|
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
|
|
|
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
|
|
|
case SQLITE_LOCKED: zName = "SQLITE_LOCKED"; break;
|
|
|
|
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
|
|
|
|
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
|
|
|
|
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
|
|
|
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
|
|
|
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
|
|
|
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
|
|
|
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
|
|
|
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
|
|
|
case SQLITE_EMPTY: zName = "SQLITE_EMPTY"; break;
|
|
|
|
case SQLITE_SCHEMA: zName = "SQLITE_SCHEMA"; break;
|
|
|
|
case SQLITE_CONSTRAINT: zName = "SQLITE_CONSTRAINT"; break;
|
|
|
|
case SQLITE_MISMATCH: zName = "SQLITE_MISMATCH"; break;
|
|
|
|
case SQLITE_MISUSE: zName = "SQLITE_MISUSE"; break;
|
|
|
|
case SQLITE_NOLFS: zName = "SQLITE_NOLFS"; break;
|
|
|
|
case SQLITE_AUTH: zName = "SQLITE_AUTH"; break;
|
|
|
|
case SQLITE_FORMAT: zName = "SQLITE_FORMAT"; break;
|
|
|
|
case SQLITE_RANGE: zName = "SQLITE_RANGE"; break;
|
|
|
|
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
|
|
|
|
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
|
2004-09-30 17:43:13 +04:00
|
|
|
case SQLITE_NOTADB: zName = "SQLITE_NOTADB"; break;
|
2004-05-20 15:00:52 +04:00
|
|
|
default: zName = "SQLITE_Unknown"; break;
|
|
|
|
}
|
|
|
|
return zName;
|
|
|
|
}
|
2005-04-28 21:18:48 +04:00
|
|
|
#define errorName sqlite3TestErrorName
|
2004-05-20 15:00:52 +04:00
|
|
|
|
2004-09-30 17:43:13 +04:00
|
|
|
/*
|
|
|
|
** Convert an sqlite3_stmt* into an sqlite3*. This depends on the
|
|
|
|
** fact that the sqlite3* is the first field in the Vdbe structure.
|
|
|
|
*/
|
2005-06-13 02:01:42 +04:00
|
|
|
#define StmtToDb(X) sqlite3_db_handle(X)
|
2004-09-30 17:43:13 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Check a return value to make sure it agrees with the results
|
|
|
|
** from sqlite3_errcode.
|
|
|
|
*/
|
|
|
|
int sqlite3TestErrCode(Tcl_Interp *interp, sqlite3 *db, int rc){
|
|
|
|
if( rc!=SQLITE_MISUSE && rc!=SQLITE_OK && sqlite3_errcode(db)!=rc ){
|
|
|
|
char zBuf[200];
|
|
|
|
int r2 = sqlite3_errcode(db);
|
|
|
|
sprintf(zBuf, "error code %s (%d) does not match sqlite3_errcode %s (%d)",
|
|
|
|
errorName(rc), rc, errorName(r2), r2);
|
|
|
|
Tcl_ResetResult(interp);
|
|
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-01-29 02:13:10 +03:00
|
|
|
/*
|
2004-09-06 21:24:11 +04:00
|
|
|
** Decode a pointer to an sqlite3 object.
|
2003-01-29 02:13:10 +03:00
|
|
|
*/
|
2004-09-06 21:24:11 +04:00
|
|
|
static int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb){
|
2004-09-09 00:13:04 +04:00
|
|
|
*ppDb = (sqlite3*)sqlite3TextToPtr(zA);
|
2003-01-29 02:13:10 +03:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-20 05:12:34 +04:00
|
|
|
/*
|
|
|
|
** Decode a pointer to an sqlite3_stmt object.
|
|
|
|
*/
|
|
|
|
static int getStmtPointer(
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
const char *zArg,
|
|
|
|
sqlite3_stmt **ppStmt
|
|
|
|
){
|
2004-09-09 00:13:04 +04:00
|
|
|
*ppStmt = (sqlite3_stmt*)sqlite3TextToPtr(zArg);
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-01 18:09:28 +04:00
|
|
|
/*
|
|
|
|
** Decode a pointer to an sqlite3_stmt object.
|
|
|
|
*/
|
|
|
|
static int getFilePointer(
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
const char *zArg,
|
|
|
|
OsFile **ppFile
|
|
|
|
){
|
2004-09-09 00:13:04 +04:00
|
|
|
*ppFile = (OsFile*)sqlite3TextToPtr(zArg);
|
2004-06-01 18:09:28 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2003-04-26 17:19:38 +04:00
|
|
|
/*
|
|
|
|
** Generate a text representation of a pointer that can be understood
|
|
|
|
** by the getDbPointer and getVmPointer routines above.
|
|
|
|
**
|
|
|
|
** The problem is, on some machines (Solaris) if you do a printf with
|
|
|
|
** "%p" you cannot turn around and do a scanf with the same "%p" and
|
|
|
|
** get your pointer back. You have to prepend a "0x" before it will
|
|
|
|
** work. Or at least that is what is reported to me (drh). But this
|
|
|
|
** behavior varies from machine to machine. The solution used her is
|
|
|
|
** to test the string right after it is generated to see if it can be
|
|
|
|
** understood by scanf, and if not, try prepending an "0x" to see if
|
|
|
|
** that helps. If nothing works, a fatal error is generated.
|
|
|
|
*/
|
2006-01-15 05:30:57 +03:00
|
|
|
int sqlite3TestMakePointerStr(Tcl_Interp *interp, char *zPtr, void *p){
|
2004-09-09 00:13:04 +04:00
|
|
|
sqlite3_snprintf(100, zPtr, "%p", p);
|
2003-04-26 17:19:38 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-07 19:24:33 +04:00
|
|
|
/*
|
2004-05-10 14:34:51 +04:00
|
|
|
** The callback routine for sqlite3_exec_printf().
|
2001-04-07 19:24:33 +04:00
|
|
|
*/
|
|
|
|
static int exec_printf_cb(void *pArg, int argc, char **argv, char **name){
|
|
|
|
Tcl_DString *str = (Tcl_DString*)pArg;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if( Tcl_DStringLength(str)==0 ){
|
|
|
|
for(i=0; i<argc; i++){
|
|
|
|
Tcl_DStringAppendElement(str, name[i] ? name[i] : "NULL");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for(i=0; i<argc; i++){
|
|
|
|
Tcl_DStringAppendElement(str, argv[i] ? argv[i] : "NULL");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-10 14:34:51 +04:00
|
|
|
** Usage: sqlite3_exec_printf DB FORMAT STRING
|
2001-04-07 19:24:33 +04:00
|
|
|
**
|
2004-05-10 14:34:51 +04:00
|
|
|
** Invoke the sqlite3_exec_printf() interface using the open database
|
2001-04-07 19:24:33 +04:00
|
|
|
** DB. The SQL is the string FORMAT. The format string should contain
|
|
|
|
** one %s or %q. STRING is the value inserted into %s or %q.
|
|
|
|
*/
|
|
|
|
static int test_exec_printf(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2001-04-07 19:24:33 +04:00
|
|
|
Tcl_DString str;
|
|
|
|
int rc;
|
|
|
|
char *zErr = 0;
|
2004-07-26 16:24:22 +04:00
|
|
|
char *zSql;
|
2001-04-07 19:24:33 +04:00
|
|
|
char zBuf[30];
|
|
|
|
if( argc!=4 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" DB FORMAT STRING", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2003-01-29 02:13:10 +03:00
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
2001-04-07 19:24:33 +04:00
|
|
|
Tcl_DStringInit(&str);
|
2004-07-26 16:24:22 +04:00
|
|
|
zSql = sqlite3_mprintf(argv[2], argv[3]);
|
|
|
|
rc = sqlite3_exec(db, zSql, exec_printf_cb, &str, &zErr);
|
|
|
|
sqlite3_free(zSql);
|
2001-04-07 19:24:33 +04:00
|
|
|
sprintf(zBuf, "%d", rc);
|
|
|
|
Tcl_AppendElement(interp, zBuf);
|
|
|
|
Tcl_AppendElement(interp, rc==SQLITE_OK ? Tcl_DStringValue(&str) : zErr);
|
|
|
|
Tcl_DStringFree(&str);
|
|
|
|
if( zErr ) free(zErr);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
2001-04-07 19:24:33 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-16 07:08:18 +04:00
|
|
|
/*
|
2004-05-10 14:34:51 +04:00
|
|
|
** Usage: sqlite3_mprintf_z_test SEPARATOR ARG0 ARG1 ...
|
2003-06-16 07:08:18 +04:00
|
|
|
**
|
|
|
|
** Test the %z format of mprintf(). Use multiple mprintf() calls to
|
|
|
|
** concatenate arg0 through argn using separator as the separator.
|
|
|
|
** Return the result.
|
|
|
|
*/
|
|
|
|
static int test_mprintf_z(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
char *zResult = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=2; i<argc; i++){
|
2004-05-08 12:23:19 +04:00
|
|
|
zResult = sqlite3MPrintf("%z%s%s", zResult, argv[1], argv[i]);
|
2003-06-16 07:08:18 +04:00
|
|
|
}
|
|
|
|
Tcl_AppendResult(interp, zResult, 0);
|
2004-02-21 22:02:30 +03:00
|
|
|
sqliteFree(zResult);
|
2003-06-16 07:08:18 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-07 19:24:33 +04:00
|
|
|
/*
|
2004-05-10 14:34:51 +04:00
|
|
|
** Usage: sqlite3_get_table_printf DB FORMAT STRING
|
2001-04-07 19:24:33 +04:00
|
|
|
**
|
2004-05-10 14:34:51 +04:00
|
|
|
** Invoke the sqlite3_get_table_printf() interface using the open database
|
2001-04-07 19:24:33 +04:00
|
|
|
** DB. The SQL is the string FORMAT. The format string should contain
|
|
|
|
** one %s or %q. STRING is the value inserted into %s or %q.
|
|
|
|
*/
|
|
|
|
static int test_get_table_printf(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2001-04-07 19:24:33 +04:00
|
|
|
Tcl_DString str;
|
|
|
|
int rc;
|
|
|
|
char *zErr = 0;
|
|
|
|
int nRow, nCol;
|
|
|
|
char **aResult;
|
|
|
|
int i;
|
|
|
|
char zBuf[30];
|
2004-07-26 16:24:22 +04:00
|
|
|
char *zSql;
|
2001-04-07 19:24:33 +04:00
|
|
|
if( argc!=4 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" DB FORMAT STRING", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2003-01-29 02:13:10 +03:00
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
2001-04-07 19:24:33 +04:00
|
|
|
Tcl_DStringInit(&str);
|
2004-07-26 16:24:22 +04:00
|
|
|
zSql = sqlite3_mprintf(argv[2],argv[3]);
|
|
|
|
rc = sqlite3_get_table(db, zSql, &aResult, &nRow, &nCol, &zErr);
|
|
|
|
sqlite3_free(zSql);
|
2001-04-07 19:24:33 +04:00
|
|
|
sprintf(zBuf, "%d", rc);
|
|
|
|
Tcl_AppendElement(interp, zBuf);
|
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
sprintf(zBuf, "%d", nRow);
|
|
|
|
Tcl_AppendElement(interp, zBuf);
|
|
|
|
sprintf(zBuf, "%d", nCol);
|
|
|
|
Tcl_AppendElement(interp, zBuf);
|
|
|
|
for(i=0; i<(nRow+1)*nCol; i++){
|
|
|
|
Tcl_AppendElement(interp, aResult[i] ? aResult[i] : "NULL");
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
Tcl_AppendElement(interp, zErr);
|
|
|
|
}
|
2004-05-10 14:34:51 +04:00
|
|
|
sqlite3_free_table(aResult);
|
2001-04-07 19:24:33 +04:00
|
|
|
if( zErr ) free(zErr);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
2001-04-07 19:24:33 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-17 00:00:27 +03:00
|
|
|
|
|
|
|
/*
|
2004-05-10 14:34:51 +04:00
|
|
|
** Usage: sqlite3_last_insert_rowid DB
|
2002-01-17 00:00:27 +03:00
|
|
|
**
|
|
|
|
** Returns the integer ROWID of the most recent insert.
|
|
|
|
*/
|
|
|
|
static int test_last_rowid(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2002-01-17 00:00:27 +03:00
|
|
|
char zBuf[30];
|
|
|
|
|
|
|
|
if( argc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2003-01-29 02:13:10 +03:00
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
2004-05-27 13:28:41 +04:00
|
|
|
sprintf(zBuf, "%lld", sqlite3_last_insert_rowid(db));
|
2002-01-17 00:00:27 +03:00
|
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
|
|
return SQLITE_OK;
|
|
|
|
}
|
|
|
|
|
2004-07-22 19:02:25 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_key DB KEY
|
|
|
|
**
|
|
|
|
** Set the codec key.
|
|
|
|
*/
|
|
|
|
static int test_key(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2004-07-22 19:02:25 +04:00
|
|
|
const char *zKey;
|
|
|
|
int nKey;
|
|
|
|
if( argc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" FILENAME\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
|
|
zKey = argv[2];
|
|
|
|
nKey = strlen(zKey);
|
|
|
|
#ifdef SQLITE_HAS_CODEC
|
|
|
|
sqlite3_key(db, zKey, nKey);
|
|
|
|
#endif
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_rekey DB KEY
|
|
|
|
**
|
|
|
|
** Change the codec key.
|
|
|
|
*/
|
|
|
|
static int test_rekey(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2004-07-22 19:02:25 +04:00
|
|
|
const char *zKey;
|
|
|
|
int nKey;
|
|
|
|
if( argc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" FILENAME\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
|
|
zKey = argv[2];
|
|
|
|
nKey = strlen(zKey);
|
|
|
|
#ifdef SQLITE_HAS_CODEC
|
|
|
|
sqlite3_rekey(db, zKey, nKey);
|
|
|
|
#endif
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-07 19:24:33 +04:00
|
|
|
/*
|
2004-05-10 14:34:51 +04:00
|
|
|
** Usage: sqlite3_close DB
|
2001-04-07 19:24:33 +04:00
|
|
|
**
|
2004-05-10 14:34:51 +04:00
|
|
|
** Closes the database opened by sqlite3_open.
|
2001-04-07 19:24:33 +04:00
|
|
|
*/
|
|
|
|
static int sqlite_test_close(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2004-06-19 07:33:57 +04:00
|
|
|
int rc;
|
2001-04-07 19:24:33 +04:00
|
|
|
if( argc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" FILENAME\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2003-01-29 02:13:10 +03:00
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
2004-06-19 07:33:57 +04:00
|
|
|
rc = sqlite3_close(db);
|
2004-06-19 12:18:07 +04:00
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
2001-04-07 19:24:33 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2002-05-10 17:14:07 +04:00
|
|
|
/*
|
|
|
|
** Implementation of the x_coalesce() function.
|
|
|
|
** Return the first argument non-NULL argument.
|
|
|
|
*/
|
2004-05-25 16:05:56 +04:00
|
|
|
static void ifnullFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
2002-05-10 17:14:07 +04:00
|
|
|
int i;
|
|
|
|
for(i=0; i<argc; i++){
|
2004-05-31 22:51:57 +04:00
|
|
|
if( SQLITE_NULL!=sqlite3_value_type(argv[i]) ){
|
2005-12-09 23:21:58 +03:00
|
|
|
sqlite3_result_text(context, (char*)sqlite3_value_text(argv[i]),
|
2005-12-05 16:20:01 +03:00
|
|
|
sqlite3_value_bytes(argv[i]), SQLITE_TRANSIENT);
|
2002-05-10 17:14:07 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-07 22:24:48 +03:00
|
|
|
/*
|
|
|
|
** A structure into which to accumulate text.
|
|
|
|
*/
|
|
|
|
struct dstr {
|
|
|
|
int nAlloc; /* Space allocated */
|
|
|
|
int nUsed; /* Space used */
|
|
|
|
char *z; /* The space */
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Append text to a dstr
|
|
|
|
*/
|
|
|
|
static void dstrAppend(struct dstr *p, const char *z, int divider){
|
|
|
|
int n = strlen(z);
|
|
|
|
if( p->nUsed + n + 2 > p->nAlloc ){
|
|
|
|
char *zNew;
|
|
|
|
p->nAlloc = p->nAlloc*2 + n + 200;
|
|
|
|
zNew = sqliteRealloc(p->z, p->nAlloc);
|
|
|
|
if( zNew==0 ){
|
|
|
|
sqliteFree(p->z);
|
|
|
|
memset(p, 0, sizeof(*p));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p->z = zNew;
|
|
|
|
}
|
|
|
|
if( divider && p->nUsed>0 ){
|
|
|
|
p->z[p->nUsed++] = divider;
|
|
|
|
}
|
|
|
|
memcpy(&p->z[p->nUsed], z, n+1);
|
|
|
|
p->nUsed += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-08 12:23:19 +04:00
|
|
|
** Invoked for each callback from sqlite3ExecFunc
|
2004-01-07 22:24:48 +03:00
|
|
|
*/
|
|
|
|
static int execFuncCallback(void *pData, int argc, char **argv, char **NotUsed){
|
|
|
|
struct dstr *p = (struct dstr*)pData;
|
|
|
|
int i;
|
|
|
|
for(i=0; i<argc; i++){
|
|
|
|
if( argv[i]==0 ){
|
|
|
|
dstrAppend(p, "NULL", ' ');
|
|
|
|
}else{
|
|
|
|
dstrAppend(p, argv[i], ' ');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2002-05-10 17:14:07 +04:00
|
|
|
/*
|
2004-06-26 13:50:11 +04:00
|
|
|
** Implementation of the x_sqlite_exec() function. This function takes
|
2002-05-10 17:14:07 +04:00
|
|
|
** a single argument and attempts to execute that argument as SQL code.
|
2002-07-01 04:31:36 +04:00
|
|
|
** This is illegal and should set the SQLITE_MISUSE flag on the database.
|
2004-01-07 22:24:48 +03:00
|
|
|
**
|
2004-05-10 14:34:51 +04:00
|
|
|
** 2004-Jan-07: We have changed this to make it legal to call sqlite3_exec()
|
2004-01-07 22:24:48 +03:00
|
|
|
** from within a function call.
|
2002-05-10 17:14:07 +04:00
|
|
|
**
|
|
|
|
** This routine simulates the effect of having two threads attempt to
|
|
|
|
** use the same database at the same time.
|
|
|
|
*/
|
2004-05-24 16:39:02 +04:00
|
|
|
static void sqlite3ExecFunc(
|
2004-05-25 16:05:56 +04:00
|
|
|
sqlite3_context *context,
|
2004-05-24 16:39:02 +04:00
|
|
|
int argc,
|
|
|
|
sqlite3_value **argv
|
|
|
|
){
|
2004-01-07 22:24:48 +03:00
|
|
|
struct dstr x;
|
|
|
|
memset(&x, 0, sizeof(x));
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3_exec((sqlite3*)sqlite3_user_data(context),
|
2005-12-09 23:21:58 +03:00
|
|
|
(char*)sqlite3_value_text(argv[0]),
|
2004-01-07 22:24:48 +03:00
|
|
|
execFuncCallback, &x, 0);
|
2004-06-12 13:25:12 +04:00
|
|
|
sqlite3_result_text(context, x.z, x.nUsed, SQLITE_TRANSIENT);
|
2004-01-07 22:24:48 +03:00
|
|
|
sqliteFree(x.z);
|
2002-05-10 17:14:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite_test_create_function DB
|
|
|
|
**
|
2004-05-10 14:34:51 +04:00
|
|
|
** Call the sqlite3_create_function API on the given database in order
|
2002-05-10 17:14:07 +04:00
|
|
|
** to create a function named "x_coalesce". This function does the same thing
|
|
|
|
** as the "coalesce" function. This function also registers an SQL function
|
2004-06-26 13:50:11 +04:00
|
|
|
** named "x_sqlite_exec" that invokes sqlite3_exec(). Invoking sqlite3_exec()
|
2002-05-10 17:14:07 +04:00
|
|
|
** in this way is illegal recursion and should raise an SQLITE_MISUSE error.
|
|
|
|
** The effect is similar to trying to use the same database connection from
|
|
|
|
** two threads at the same time.
|
|
|
|
**
|
|
|
|
** The original motivation for this routine was to be able to call the
|
2004-05-10 14:34:51 +04:00
|
|
|
** sqlite3_create_function function while a query is in progress in order
|
2002-05-10 17:14:07 +04:00
|
|
|
** to test the SQLITE_MISUSE detection logic.
|
|
|
|
*/
|
2002-08-31 22:53:06 +04:00
|
|
|
static int test_create_function(
|
2002-05-10 17:14:07 +04:00
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-09-30 17:43:13 +04:00
|
|
|
int rc;
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
|
|
|
extern void Md5_Register(sqlite3*);
|
2004-06-29 17:18:23 +04:00
|
|
|
|
2002-05-10 17:14:07 +04:00
|
|
|
if( argc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
2005-01-12 15:44:03 +03:00
|
|
|
" DB\"", 0);
|
2002-05-10 17:14:07 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2003-01-29 02:13:10 +03:00
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
2004-09-30 17:43:13 +04:00
|
|
|
rc = sqlite3_create_function(db, "x_coalesce", -1, SQLITE_ANY, 0,
|
|
|
|
ifnullFunc, 0, 0);
|
2004-06-29 17:18:23 +04:00
|
|
|
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-06-29 17:18:23 +04:00
|
|
|
/* Use the sqlite3_create_function16() API here. Mainly for fun, but also
|
|
|
|
** because it is not tested anywhere else. */
|
2004-09-30 17:43:13 +04:00
|
|
|
if( rc==SQLITE_OK ){
|
2005-01-21 14:55:25 +03:00
|
|
|
sqlite3_value *pVal;
|
2006-01-17 16:21:40 +03:00
|
|
|
#ifdef SQLITE_MEMDEBUG
|
|
|
|
if( sqlite3_iMallocFail>0 ){
|
|
|
|
sqlite3_iMallocFail++;
|
|
|
|
}
|
|
|
|
#endif
|
2004-09-30 17:43:13 +04:00
|
|
|
pVal = sqlite3ValueNew();
|
|
|
|
sqlite3ValueSetStr(pVal, -1, "x_sqlite_exec", SQLITE_UTF8, SQLITE_STATIC);
|
|
|
|
rc = sqlite3_create_function16(db,
|
|
|
|
sqlite3ValueText(pVal, SQLITE_UTF16NATIVE),
|
|
|
|
1, SQLITE_UTF16, db, sqlite3ExecFunc, 0, 0);
|
|
|
|
sqlite3ValueFree(pVal);
|
|
|
|
}
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif
|
|
|
|
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
2005-01-12 15:44:03 +03:00
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), 0);
|
2002-05-10 17:14:07 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Routines to implement the x_count() aggregate function.
|
2006-01-20 18:45:36 +03:00
|
|
|
**
|
|
|
|
** x_count() counts the number of non-null arguments. But there are
|
|
|
|
** some twists for testing purposes.
|
|
|
|
**
|
|
|
|
** If the argument to x_count() is 40 then a UTF-8 error is reported
|
|
|
|
** on the step function. If x_count(41) is seen, then a UTF-16 error
|
|
|
|
** is reported on the step function. If the total count is 42, then
|
|
|
|
** a UTF-8 error is reported on the finalize function.
|
2002-05-10 17:14:07 +04:00
|
|
|
*/
|
|
|
|
typedef struct CountCtx CountCtx;
|
|
|
|
struct CountCtx {
|
|
|
|
int n;
|
|
|
|
};
|
2004-05-25 16:05:56 +04:00
|
|
|
static void countStep(sqlite3_context *context, int argc, sqlite3_value **argv){
|
2002-05-10 17:14:07 +04:00
|
|
|
CountCtx *p;
|
2004-05-27 03:25:30 +04:00
|
|
|
p = sqlite3_aggregate_context(context, sizeof(*p));
|
2004-05-31 22:51:57 +04:00
|
|
|
if( (argc==0 || SQLITE_NULL!=sqlite3_value_type(argv[0]) ) && p ){
|
2002-05-10 17:14:07 +04:00
|
|
|
p->n++;
|
|
|
|
}
|
2006-01-20 18:45:36 +03:00
|
|
|
if( argc>0 ){
|
|
|
|
int v = sqlite3_value_int(argv[0]);
|
|
|
|
if( v==40 ){
|
|
|
|
sqlite3_result_error(context, "value of 40 handed to x_count", -1);
|
2006-01-23 10:52:37 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2006-01-20 18:45:36 +03:00
|
|
|
}else if( v==41 ){
|
|
|
|
const char zUtf16ErrMsg[] = { 0, 0x61, 0, 0x62, 0, 0x63, 0, 0, 0};
|
|
|
|
sqlite3_result_error16(context, &zUtf16ErrMsg[1-SQLITE_BIGENDIAN], -1);
|
2006-01-23 10:52:37 +03:00
|
|
|
#endif
|
2006-01-20 18:45:36 +03:00
|
|
|
}
|
|
|
|
}
|
2002-05-10 17:14:07 +04:00
|
|
|
}
|
2004-05-25 16:05:56 +04:00
|
|
|
static void countFinalize(sqlite3_context *context){
|
2002-05-10 17:14:07 +04:00
|
|
|
CountCtx *p;
|
2004-05-27 03:25:30 +04:00
|
|
|
p = sqlite3_aggregate_context(context, sizeof(*p));
|
2006-01-20 18:45:36 +03:00
|
|
|
if( p ){
|
|
|
|
if( p->n==42 ){
|
|
|
|
sqlite3_result_error(context, "x_count totals to 42", -1);
|
|
|
|
}else{
|
|
|
|
sqlite3_result_int(context, p ? p->n : 0);
|
|
|
|
}
|
|
|
|
}
|
2002-05-10 17:14:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite_test_create_aggregate DB
|
|
|
|
**
|
2004-05-10 14:34:51 +04:00
|
|
|
** Call the sqlite3_create_function API on the given database in order
|
2002-05-10 17:14:07 +04:00
|
|
|
** to create a function named "x_count". This function does the same thing
|
|
|
|
** as the "md5sum" function.
|
|
|
|
**
|
|
|
|
** The original motivation for this routine was to be able to call the
|
2004-05-10 14:34:51 +04:00
|
|
|
** sqlite3_create_aggregate function while a query is in progress in order
|
2006-01-20 18:45:36 +03:00
|
|
|
** to test the SQLITE_MISUSE detection logic. See misuse.test.
|
|
|
|
**
|
|
|
|
** This routine was later extended to test the use of sqlite3_result_error()
|
|
|
|
** within aggregate functions.
|
2002-05-10 17:14:07 +04:00
|
|
|
*/
|
2002-08-31 22:53:06 +04:00
|
|
|
static int test_create_aggregate(
|
2002-05-10 17:14:07 +04:00
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2004-09-30 17:43:13 +04:00
|
|
|
int rc;
|
2002-05-10 17:14:07 +04:00
|
|
|
if( argc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" FILENAME\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2003-01-29 02:13:10 +03:00
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
2004-09-30 17:43:13 +04:00
|
|
|
rc = sqlite3_create_function(db, "x_count", 0, SQLITE_UTF8, 0, 0,
|
2004-06-12 13:25:12 +04:00
|
|
|
countStep,countFinalize);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
sqlite3_create_function(db, "x_count", 1, SQLITE_UTF8, 0, 0,
|
|
|
|
countStep,countFinalize);
|
|
|
|
}
|
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
2002-05-10 17:14:07 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-04-07 19:24:33 +04:00
|
|
|
/*
|
2004-05-10 14:34:51 +04:00
|
|
|
** Usage: sqlite3_mprintf_int FORMAT INTEGER INTEGER INTEGER
|
2001-04-07 19:24:33 +04:00
|
|
|
**
|
|
|
|
** Call mprintf with three integer arguments
|
|
|
|
*/
|
2004-05-10 14:34:51 +04:00
|
|
|
static int sqlite3_mprintf_int(
|
2001-04-07 19:24:33 +04:00
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
int a[3], i;
|
|
|
|
char *z;
|
|
|
|
if( argc!=5 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" FORMAT INT INT INT\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
for(i=2; i<5; i++){
|
|
|
|
if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR;
|
|
|
|
}
|
2004-05-10 14:34:51 +04:00
|
|
|
z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]);
|
2001-04-07 19:24:33 +04:00
|
|
|
Tcl_AppendResult(interp, z, 0);
|
2004-05-31 23:34:33 +04:00
|
|
|
sqlite3_free(z);
|
2001-04-07 19:24:33 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-30 08:02:11 +04:00
|
|
|
/*
|
|
|
|
** If zNum represents an integer that will fit in 64-bits, then set
|
|
|
|
** *pValue to that integer and return true. Otherwise return false.
|
|
|
|
*/
|
|
|
|
static int sqlite3GetInt64(const char *zNum, i64 *pValue){
|
|
|
|
if( sqlite3FitsIn64Bits(zNum) ){
|
|
|
|
sqlite3atoi64(zNum, pValue);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-06-25 05:10:48 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_mprintf_int64 FORMAT INTEGER INTEGER INTEGER
|
|
|
|
**
|
|
|
|
** Call mprintf with three 64-bit integer arguments
|
|
|
|
*/
|
|
|
|
static int sqlite3_mprintf_int64(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
int i;
|
|
|
|
sqlite_int64 a[3];
|
|
|
|
char *z;
|
|
|
|
if( argc!=5 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" FORMAT INT INT INT\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
for(i=2; i<5; i++){
|
|
|
|
if( !sqlite3GetInt64(argv[i], &a[i-2]) ){
|
|
|
|
Tcl_AppendResult(interp, "argument is not a valid 64-bit integer", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
z = sqlite3_mprintf(argv[1], a[0], a[1], a[2]);
|
|
|
|
Tcl_AppendResult(interp, z, 0);
|
|
|
|
sqlite3_free(z);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-07 19:24:33 +04:00
|
|
|
/*
|
2004-05-10 14:34:51 +04:00
|
|
|
** Usage: sqlite3_mprintf_str FORMAT INTEGER INTEGER STRING
|
2001-04-07 19:24:33 +04:00
|
|
|
**
|
|
|
|
** Call mprintf with two integer arguments and one string argument
|
|
|
|
*/
|
2004-05-10 14:34:51 +04:00
|
|
|
static int sqlite3_mprintf_str(
|
2001-04-07 19:24:33 +04:00
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
int a[3], i;
|
|
|
|
char *z;
|
2002-06-16 08:54:28 +04:00
|
|
|
if( argc<4 || argc>5 ){
|
2001-04-07 19:24:33 +04:00
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
2002-06-16 08:54:28 +04:00
|
|
|
" FORMAT INT INT ?STRING?\"", 0);
|
2001-04-07 19:24:33 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
for(i=2; i<4; i++){
|
|
|
|
if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR;
|
|
|
|
}
|
2004-05-10 14:34:51 +04:00
|
|
|
z = sqlite3_mprintf(argv[1], a[0], a[1], argc>4 ? argv[4] : NULL);
|
2001-04-07 19:24:33 +04:00
|
|
|
Tcl_AppendResult(interp, z, 0);
|
2004-05-31 23:34:33 +04:00
|
|
|
sqlite3_free(z);
|
2001-04-07 19:24:33 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2005-08-30 23:30:59 +04:00
|
|
|
** Usage: sqlite3_mprintf_double FORMAT INTEGER INTEGER DOUBLE
|
2001-04-07 19:24:33 +04:00
|
|
|
**
|
|
|
|
** Call mprintf with two integer arguments and one double argument
|
|
|
|
*/
|
2004-05-10 14:34:51 +04:00
|
|
|
static int sqlite3_mprintf_double(
|
2001-04-07 19:24:33 +04:00
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
int a[3], i;
|
|
|
|
double r;
|
|
|
|
char *z;
|
|
|
|
if( argc!=5 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
2005-08-30 23:30:59 +04:00
|
|
|
" FORMAT INT INT DOUBLE\"", 0);
|
2001-04-07 19:24:33 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
for(i=2; i<4; i++){
|
|
|
|
if( Tcl_GetInt(interp, argv[i], &a[i-2]) ) return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( Tcl_GetDouble(interp, argv[4], &r) ) return TCL_ERROR;
|
2004-05-10 14:34:51 +04:00
|
|
|
z = sqlite3_mprintf(argv[1], a[0], a[1], r);
|
2001-04-07 19:24:33 +04:00
|
|
|
Tcl_AppendResult(interp, z, 0);
|
2004-05-31 23:34:33 +04:00
|
|
|
sqlite3_free(z);
|
2001-04-07 19:24:33 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-02-21 22:41:04 +03:00
|
|
|
/*
|
2005-08-30 23:30:59 +04:00
|
|
|
** Usage: sqlite3_mprintf_scaled FORMAT DOUBLE DOUBLE
|
2004-02-21 22:41:04 +03:00
|
|
|
**
|
|
|
|
** Call mprintf with a single double argument which is the product of the
|
|
|
|
** two arguments given above. This is used to generate overflow and underflow
|
|
|
|
** doubles to test that they are converted properly.
|
|
|
|
*/
|
2004-05-10 14:34:51 +04:00
|
|
|
static int sqlite3_mprintf_scaled(
|
2004-02-21 22:41:04 +03:00
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
int i;
|
|
|
|
double r[2];
|
|
|
|
char *z;
|
|
|
|
if( argc!=4 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" FORMAT DOUBLE DOUBLE\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
for(i=2; i<4; i++){
|
|
|
|
if( Tcl_GetDouble(interp, argv[i], &r[i-2]) ) return TCL_ERROR;
|
|
|
|
}
|
2004-05-10 14:34:51 +04:00
|
|
|
z = sqlite3_mprintf(argv[1], r[0]*r[1]);
|
2004-02-21 22:41:04 +03:00
|
|
|
Tcl_AppendResult(interp, z, 0);
|
2004-05-31 23:34:33 +04:00
|
|
|
sqlite3_free(z);
|
2004-02-21 22:41:04 +03:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-07-18 01:56:09 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_mprintf_stronly FORMAT STRING
|
|
|
|
**
|
|
|
|
** Call mprintf with a single double argument which is the product of the
|
|
|
|
** two arguments given above. This is used to generate overflow and underflow
|
|
|
|
** doubles to test that they are converted properly.
|
|
|
|
*/
|
|
|
|
static int sqlite3_mprintf_stronly(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
char *z;
|
|
|
|
if( argc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" FORMAT STRING\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
z = sqlite3_mprintf(argv[1], argv[2]);
|
|
|
|
Tcl_AppendResult(interp, z, 0);
|
|
|
|
sqlite3_free(z);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-08-30 23:30:59 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_mprintf_hexdouble FORMAT HEX
|
|
|
|
**
|
|
|
|
** Call mprintf with a single double argument which is derived from the
|
|
|
|
** hexadecimal encoding of an IEEE double.
|
|
|
|
*/
|
|
|
|
static int sqlite3_mprintf_hexdouble(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
char *z;
|
|
|
|
double r;
|
|
|
|
unsigned x1, x2;
|
|
|
|
long long unsigned d;
|
|
|
|
if( argc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" FORMAT STRING\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( sscanf(argv[2], "%08x%08x", &x2, &x1)!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "2nd argument should be 16-characters of hex", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
d = x2;
|
|
|
|
d = (d<<32) + x1;
|
|
|
|
memcpy(&r, &d, sizeof(r));
|
|
|
|
z = sqlite3_mprintf(argv[1], r);
|
|
|
|
Tcl_AppendResult(interp, z, 0);
|
|
|
|
sqlite3_free(z);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-11 18:28:42 +04:00
|
|
|
/*
|
2004-11-20 22:18:00 +03:00
|
|
|
** Usage: sqlite_malloc_fail N ?REPEAT-INTERVAL?
|
2001-04-11 18:28:42 +04:00
|
|
|
**
|
2004-11-20 22:18:00 +03:00
|
|
|
** Rig sqliteMalloc() to fail on the N-th call and every REPEAT-INTERVAL call
|
|
|
|
** after that. If REPEAT-INTERVAL is 0 or is omitted, then only a single
|
|
|
|
** malloc will fail. If REPEAT-INTERVAL is 1 then all mallocs after the
|
|
|
|
** first failure will continue to fail on every call. If REPEAT-INTERVAL is
|
|
|
|
** 2 then every other malloc will fail. And so forth.
|
|
|
|
**
|
2006-01-18 19:51:35 +03:00
|
|
|
** Turn off this mechanism and reset the sqlite3ThreadData()->mallocFailed
|
|
|
|
** variable if N==0.
|
2001-04-11 18:28:42 +04:00
|
|
|
*/
|
2005-01-13 05:14:23 +03:00
|
|
|
#ifdef SQLITE_MEMDEBUG
|
2001-04-11 18:28:42 +04:00
|
|
|
static int sqlite_malloc_fail(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
int n;
|
2004-11-20 22:18:00 +03:00
|
|
|
int rep;
|
|
|
|
if( argc!=2 && argc!=3 ){
|
2001-04-11 18:28:42 +04:00
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " N\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( Tcl_GetInt(interp, argv[1], &n) ) return TCL_ERROR;
|
2004-11-20 22:18:00 +03:00
|
|
|
if( argc==3 ){
|
|
|
|
if( Tcl_GetInt(interp, argv[2], &rep) ) return TCL_ERROR;
|
|
|
|
}else{
|
|
|
|
rep = 0;
|
|
|
|
}
|
2004-05-10 14:34:51 +04:00
|
|
|
sqlite3_iMallocFail = n;
|
2004-11-20 22:18:00 +03:00
|
|
|
sqlite3_iMallocReset = rep;
|
2001-04-11 18:28:42 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite_malloc_stat
|
|
|
|
**
|
|
|
|
** Return the number of prior calls to sqliteMalloc() and sqliteFree().
|
|
|
|
*/
|
2005-01-13 05:14:23 +03:00
|
|
|
#ifdef SQLITE_MEMDEBUG
|
2001-04-11 18:28:42 +04:00
|
|
|
static int sqlite_malloc_stat(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
char zBuf[200];
|
2005-12-20 12:19:37 +03:00
|
|
|
sprintf(zBuf, "%d %d %d", sqlite3_nMalloc,sqlite3_nFree,sqlite3_iMallocFail);
|
2001-04-11 18:28:42 +04:00
|
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
2005-12-20 12:19:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
** This function implements a Tcl command that may be invoked using any of
|
|
|
|
** the four forms enumerated below.
|
|
|
|
**
|
|
|
|
** sqlite_malloc_outstanding
|
|
|
|
** Return a summary of all unfreed blocks of memory allocated by the
|
|
|
|
** current thread. See comments above function sqlite3OutstandingMallocs()
|
|
|
|
** in util.c for a description of the returned value.
|
|
|
|
**
|
|
|
|
** sqlite_malloc_outstanding -bytes
|
|
|
|
** Return the total amount of unfreed memory (in bytes) allocated by
|
|
|
|
** this thread.
|
|
|
|
**
|
|
|
|
** sqlite_malloc_outstanding -maxbytes
|
|
|
|
** Return the maximum amount of dynamic memory in use at one time
|
|
|
|
** by this thread.
|
|
|
|
**
|
|
|
|
** sqlite_malloc_outstanding -clearmaxbytes
|
|
|
|
** Set the value returned by [sqlite_malloc_outstanding -maxbytes]
|
|
|
|
** to the current value of [sqlite_malloc_outstanding -bytes].
|
|
|
|
*/
|
2005-12-09 17:25:08 +03:00
|
|
|
static int sqlite_malloc_outstanding(
|
2005-12-20 12:19:37 +03:00
|
|
|
ClientData clientData,
|
2005-12-09 17:25:08 +03:00
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
2005-12-20 12:19:37 +03:00
|
|
|
int objc, /* Number of arguments */
|
|
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
2005-12-09 17:25:08 +03:00
|
|
|
){
|
|
|
|
extern int sqlite3OutstandingMallocs(Tcl_Interp *interp);
|
2005-12-20 12:19:37 +03:00
|
|
|
|
2006-01-19 14:28:06 +03:00
|
|
|
#if defined(SQLITE_DEBUG) && defined(SQLITE_MEMDEBUG) && SQLITE_MEMDEBUG>1
|
2005-12-20 12:19:37 +03:00
|
|
|
if( objc==2 ){
|
|
|
|
const char *zArg = Tcl_GetString(objv[1]);
|
2006-01-19 10:18:14 +03:00
|
|
|
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
|
|
|
ThreadData const *pTd = sqlite3ThreadDataReadOnly();
|
2005-12-20 12:19:37 +03:00
|
|
|
if( 0==strcmp(zArg, "-bytes") ){
|
2006-01-09 12:59:49 +03:00
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(pTd->nAlloc));
|
2005-12-20 12:19:37 +03:00
|
|
|
}else if( 0==strcmp(zArg, "-clearmaxbytes") ){
|
2006-01-18 19:51:35 +03:00
|
|
|
sqlite3_nMaxAlloc = pTd->nAlloc;
|
2006-01-19 10:18:14 +03:00
|
|
|
}else
|
|
|
|
#endif
|
|
|
|
if( 0==strcmp(zArg, "-maxbytes") ){
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(sqlite3_nMaxAlloc));
|
2005-12-20 12:19:37 +03:00
|
|
|
}else{
|
|
|
|
Tcl_AppendResult(interp, "bad option \"", zArg,
|
|
|
|
"\": must be -bytes, -maxbytes or -clearmaxbytes", 0
|
|
|
|
);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
2006-01-09 12:59:49 +03:00
|
|
|
|
|
|
|
if( objc!=1 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "?-bytes?");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2005-12-20 12:19:37 +03:00
|
|
|
|
2005-12-09 17:25:08 +03:00
|
|
|
return sqlite3OutstandingMallocs(interp);
|
2006-01-19 10:18:14 +03:00
|
|
|
#else
|
|
|
|
return TCL_OK;
|
|
|
|
#endif
|
2005-12-09 17:25:08 +03:00
|
|
|
}
|
2001-04-11 18:28:42 +04:00
|
|
|
#endif
|
|
|
|
|
2005-12-30 19:28:01 +03:00
|
|
|
/*
|
2006-01-09 12:59:49 +03:00
|
|
|
** Usage: sqlite3_enable_shared_cache BOOLEAN
|
2005-12-30 19:28:01 +03:00
|
|
|
**
|
|
|
|
*/
|
2006-01-12 00:41:20 +03:00
|
|
|
#if !defined(SQLITE_OMIT_SHARED_CACHE)
|
|
|
|
static int test_enable_shared(
|
2006-01-09 12:59:49 +03:00
|
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
2005-12-30 19:28:01 +03:00
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int objc, /* Number of arguments */
|
|
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
|
|
){
|
|
|
|
int rc;
|
|
|
|
int enable;
|
2006-01-09 12:59:49 +03:00
|
|
|
int ret = 0;
|
2005-12-30 19:28:01 +03:00
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( Tcl_GetBooleanFromObj(interp, objv[1], &enable) ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2006-01-12 00:41:20 +03:00
|
|
|
ret = sqlite3ThreadDataReadOnly()->useSharedData;
|
|
|
|
rc = sqlite3_enable_shared_cache(enable);
|
2005-12-30 19:28:01 +03:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
Tcl_SetResult(interp, (char *)sqlite3ErrStr(rc), TCL_STATIC);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2006-01-09 12:59:49 +03:00
|
|
|
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(ret));
|
2005-12-30 19:28:01 +03:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-24 13:58:21 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_libversion_number
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
static int test_libversion_number(
|
|
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int objc, /* Number of arguments */
|
|
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
|
|
){
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_libversion_number()));
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-09 16:43:28 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_table_column_metadata DB dbname tblname colname
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
|
|
|
static int test_table_column_metadata(
|
|
|
|
ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int objc, /* Number of arguments */
|
|
|
|
Tcl_Obj *CONST objv[] /* Command arguments */
|
|
|
|
){
|
|
|
|
sqlite3 *db;
|
|
|
|
const char *zDb;
|
|
|
|
const char *zTbl;
|
|
|
|
const char *zCol;
|
|
|
|
int rc;
|
|
|
|
Tcl_Obj *pRet;
|
|
|
|
|
|
|
|
const char *zDatatype;
|
|
|
|
const char *zCollseq;
|
|
|
|
int notnull;
|
|
|
|
int primarykey;
|
|
|
|
int autoincrement;
|
|
|
|
|
|
|
|
if( objc!=5 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB dbname tblname colname");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
zDb = Tcl_GetString(objv[2]);
|
|
|
|
zTbl = Tcl_GetString(objv[3]);
|
|
|
|
zCol = Tcl_GetString(objv[4]);
|
|
|
|
|
|
|
|
if( strlen(zDb)==0 ) zDb = 0;
|
|
|
|
|
|
|
|
rc = sqlite3_table_column_metadata(db, zDb, zTbl, zCol,
|
|
|
|
&zDatatype, &zCollseq, ¬null, &primarykey, &autoincrement);
|
|
|
|
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
Tcl_AppendResult(interp, sqlite3_errmsg(db), 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
pRet = Tcl_NewObj();
|
|
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zDatatype, -1));
|
|
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewStringObj(zCollseq, -1));
|
|
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(notnull));
|
|
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(primarykey));
|
|
|
|
Tcl_ListObjAppendElement(0, pRet, Tcl_NewIntObj(autoincrement));
|
|
|
|
Tcl_SetObjResult(interp, pRet);
|
|
|
|
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-03-11 05:06:13 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite_abort
|
|
|
|
**
|
|
|
|
** Shutdown the process immediately. This is not a clean shutdown.
|
|
|
|
** This command is used to test the recoverability of a database in
|
|
|
|
** the event of a program crash.
|
|
|
|
*/
|
|
|
|
static int sqlite_abort(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
assert( interp==0 ); /* This will always fail */
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2002-07-01 04:31:36 +04:00
|
|
|
/*
|
|
|
|
** The following routine is a user-defined SQL function whose purpose
|
|
|
|
** is to test the sqlite_set_result() API.
|
|
|
|
*/
|
2004-05-25 16:05:56 +04:00
|
|
|
static void testFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
|
2002-07-01 04:31:36 +04:00
|
|
|
while( argc>=2 ){
|
2005-12-09 23:21:58 +03:00
|
|
|
const char *zArg0 = (char*)sqlite3_value_text(argv[0]);
|
2004-05-27 18:23:36 +04:00
|
|
|
if( zArg0 ){
|
|
|
|
if( 0==sqlite3StrICmp(zArg0, "int") ){
|
|
|
|
sqlite3_result_int(context, sqlite3_value_int(argv[1]));
|
|
|
|
}else if( sqlite3StrICmp(zArg0,"int64")==0 ){
|
|
|
|
sqlite3_result_int64(context, sqlite3_value_int64(argv[1]));
|
|
|
|
}else if( sqlite3StrICmp(zArg0,"string")==0 ){
|
2005-12-09 23:21:58 +03:00
|
|
|
sqlite3_result_text(context, (char*)sqlite3_value_text(argv[1]), -1,
|
2004-06-12 13:25:12 +04:00
|
|
|
SQLITE_TRANSIENT);
|
2004-05-27 18:23:36 +04:00
|
|
|
}else if( sqlite3StrICmp(zArg0,"double")==0 ){
|
|
|
|
sqlite3_result_double(context, sqlite3_value_double(argv[1]));
|
|
|
|
}else if( sqlite3StrICmp(zArg0,"null")==0 ){
|
|
|
|
sqlite3_result_null(context);
|
|
|
|
}else if( sqlite3StrICmp(zArg0,"value")==0 ){
|
|
|
|
sqlite3_result_value(context, argv[sqlite3_value_int(argv[1])]);
|
|
|
|
}else{
|
|
|
|
goto error_out;
|
|
|
|
}
|
2002-07-01 04:31:36 +04:00
|
|
|
}else{
|
2004-05-27 18:23:36 +04:00
|
|
|
goto error_out;
|
2002-07-01 04:31:36 +04:00
|
|
|
}
|
|
|
|
argc -= 2;
|
|
|
|
argv += 2;
|
|
|
|
}
|
2004-05-27 18:23:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
error_out:
|
|
|
|
sqlite3_result_error(context,"first argument should be one of: "
|
|
|
|
"int int64 string double null value", -1);
|
2002-07-01 04:31:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite_register_test_function DB NAME
|
|
|
|
**
|
|
|
|
** Register the test SQL function on the database DB under the name NAME.
|
|
|
|
*/
|
2002-08-31 22:53:06 +04:00
|
|
|
static int test_register_func(
|
2002-07-01 04:31:36 +04:00
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2002-07-01 04:31:36 +04:00
|
|
|
int rc;
|
|
|
|
if( argc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" DB FUNCTION-NAME", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2003-01-29 02:13:10 +03:00
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
2004-06-19 12:18:07 +04:00
|
|
|
rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0,
|
2004-06-12 13:25:12 +04:00
|
|
|
testFunc, 0, 0);
|
2002-07-01 04:31:36 +04:00
|
|
|
if( rc!=0 ){
|
2004-06-01 03:56:42 +04:00
|
|
|
Tcl_AppendResult(interp, sqlite3ErrStr(rc), 0);
|
2002-07-01 04:31:36 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
2002-07-01 04:31:36 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-29 02:13:10 +03:00
|
|
|
/*
|
2004-05-21 14:08:53 +04:00
|
|
|
** Usage: sqlite3_finalize STMT
|
2003-01-29 02:13:10 +03:00
|
|
|
**
|
2004-05-21 14:08:53 +04:00
|
|
|
** Finalize a statement handle.
|
2003-01-29 02:13:10 +03:00
|
|
|
*/
|
|
|
|
static int test_finalize(
|
2004-05-21 14:08:53 +04:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
2003-01-29 02:13:10 +03:00
|
|
|
){
|
2004-05-21 14:08:53 +04:00
|
|
|
sqlite3_stmt *pStmt;
|
2003-01-29 02:13:10 +03:00
|
|
|
int rc;
|
2004-09-30 17:43:13 +04:00
|
|
|
sqlite3 *db;
|
2004-05-21 14:08:53 +04:00
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0);
|
2003-01-29 02:13:10 +03:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2004-05-21 14:08:53 +04:00
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
|
2005-01-12 15:44:03 +03:00
|
|
|
if( pStmt ){
|
|
|
|
db = StmtToDb(pStmt);
|
|
|
|
}
|
2004-05-26 06:04:57 +04:00
|
|
|
rc = sqlite3_finalize(pStmt);
|
2004-05-26 17:27:00 +04:00
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
2005-01-12 15:44:03 +03:00
|
|
|
if( db && sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
2003-01-29 02:13:10 +03:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2003-09-06 05:10:47 +04:00
|
|
|
/*
|
2004-05-21 14:08:53 +04:00
|
|
|
** Usage: sqlite3_reset STMT
|
2003-09-06 05:10:47 +04:00
|
|
|
**
|
2005-12-06 15:52:59 +03:00
|
|
|
** Reset a statement handle.
|
2003-09-06 05:10:47 +04:00
|
|
|
*/
|
|
|
|
static int test_reset(
|
2004-05-21 14:08:53 +04:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
2003-09-06 05:10:47 +04:00
|
|
|
){
|
2004-05-21 14:08:53 +04:00
|
|
|
sqlite3_stmt *pStmt;
|
2003-09-06 05:10:47 +04:00
|
|
|
int rc;
|
2004-05-21 14:08:53 +04:00
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0);
|
2003-09-06 05:10:47 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2004-05-21 14:08:53 +04:00
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
|
2004-05-26 06:04:57 +04:00
|
|
|
rc = sqlite3_reset(pStmt);
|
2005-12-06 15:52:59 +03:00
|
|
|
if( pStmt && sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2005-01-12 15:44:03 +03:00
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
2005-12-06 15:52:59 +03:00
|
|
|
/*
|
2003-09-06 05:10:47 +04:00
|
|
|
if( rc ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2005-12-06 15:52:59 +03:00
|
|
|
*/
|
2003-09-06 05:10:47 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-22 06:03:54 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_expired STMT
|
|
|
|
**
|
|
|
|
** Return TRUE if a recompilation of the statement is recommended.
|
|
|
|
*/
|
|
|
|
static int test_expired(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " <STMT>", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewBooleanObj(sqlite3_expired(pStmt)));
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-22 06:38:37 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_transfer_bindings FROMSTMT TOSTMT
|
|
|
|
**
|
|
|
|
** Transfer all bindings from FROMSTMT over to TOSTMT
|
|
|
|
*/
|
|
|
|
static int test_transfer_bind(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt1, *pStmt2;
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " FROM-STMT TO-STMT", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt1)) return TCL_ERROR;
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[2]), &pStmt2)) return TCL_ERROR;
|
|
|
|
Tcl_SetObjResult(interp,
|
|
|
|
Tcl_NewIntObj(sqlite3_transfer_bindings(pStmt1,pStmt2)));
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-21 14:08:53 +04:00
|
|
|
/*
|
2004-06-15 06:44:18 +04:00
|
|
|
** Usage: sqlite3_changes DB
|
2004-05-21 14:08:53 +04:00
|
|
|
**
|
2004-06-15 06:44:18 +04:00
|
|
|
** Return the number of changes made to the database by the last SQL
|
|
|
|
** execution.
|
2004-05-21 14:08:53 +04:00
|
|
|
*/
|
2004-06-15 06:44:18 +04:00
|
|
|
static int test_changes(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3 *db;
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " DB", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_changes(db)));
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
2004-05-21 14:08:53 +04:00
|
|
|
|
2003-09-06 05:10:47 +04:00
|
|
|
/*
|
2003-09-07 02:18:07 +04:00
|
|
|
** This is the "static_bind_value" that variables are bound to when
|
2004-05-10 14:34:51 +04:00
|
|
|
** the FLAG option of sqlite3_bind is "static"
|
2003-09-07 02:18:07 +04:00
|
|
|
*/
|
|
|
|
static char *sqlite_static_bind_value = 0;
|
|
|
|
|
|
|
|
/*
|
2004-05-10 14:34:51 +04:00
|
|
|
** Usage: sqlite3_bind VM IDX VALUE FLAGS
|
2003-09-06 05:10:47 +04:00
|
|
|
**
|
2003-09-07 02:18:07 +04:00
|
|
|
** Sets the value of the IDX-th occurance of "?" in the original SQL
|
|
|
|
** string. VALUE is the new value. If FLAGS=="null" then VALUE is
|
|
|
|
** ignored and the value is set to NULL. If FLAGS=="static" then
|
|
|
|
** the value is set to the value of a static variable named
|
|
|
|
** "sqlite_static_bind_value". If FLAGS=="normal" then a copy
|
2005-12-02 05:44:05 +03:00
|
|
|
** of the VALUE is made. If FLAGS=="blob10" then a VALUE is ignored
|
|
|
|
** an a 10-byte blob "abc\000xyz\000pq" is inserted.
|
2003-09-06 05:10:47 +04:00
|
|
|
*/
|
2003-09-07 02:18:07 +04:00
|
|
|
static int test_bind(
|
2003-09-06 05:10:47 +04:00
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
2004-05-26 06:04:57 +04:00
|
|
|
sqlite3_stmt *pStmt;
|
2003-09-06 05:10:47 +04:00
|
|
|
int rc;
|
2003-09-07 02:18:07 +04:00
|
|
|
int idx;
|
|
|
|
if( argc!=5 ){
|
2003-09-06 05:10:47 +04:00
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
2003-09-07 02:18:07 +04:00
|
|
|
" VM IDX VALUE (null|static|normal)\"", 0);
|
2003-09-06 05:10:47 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2004-05-26 06:04:57 +04:00
|
|
|
if( getStmtPointer(interp, argv[1], &pStmt) ) return TCL_ERROR;
|
2003-09-07 02:18:07 +04:00
|
|
|
if( Tcl_GetInt(interp, argv[2], &idx) ) return TCL_ERROR;
|
|
|
|
if( strcmp(argv[4],"null")==0 ){
|
2004-05-26 06:04:57 +04:00
|
|
|
rc = sqlite3_bind_null(pStmt, idx);
|
2003-09-07 02:18:07 +04:00
|
|
|
}else if( strcmp(argv[4],"static")==0 ){
|
2004-05-26 06:04:57 +04:00
|
|
|
rc = sqlite3_bind_text(pStmt, idx, sqlite_static_bind_value, -1, 0);
|
2003-09-07 02:18:07 +04:00
|
|
|
}else if( strcmp(argv[4],"normal")==0 ){
|
2004-06-12 13:25:12 +04:00
|
|
|
rc = sqlite3_bind_text(pStmt, idx, argv[3], -1, SQLITE_TRANSIENT);
|
2005-12-02 05:44:05 +03:00
|
|
|
}else if( strcmp(argv[4],"blob10")==0 ){
|
|
|
|
rc = sqlite3_bind_text(pStmt, idx, "abc\000xyz\000pq", 10, SQLITE_STATIC);
|
2003-09-07 02:18:07 +04:00
|
|
|
}else{
|
|
|
|
Tcl_AppendResult(interp, "4th argument should be "
|
|
|
|
"\"null\" or \"static\" or \"normal\"", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
2003-09-06 05:10:47 +04:00
|
|
|
if( rc ){
|
|
|
|
char zBuf[50];
|
|
|
|
sprintf(zBuf, "(%d) ", rc);
|
2004-06-01 03:56:42 +04:00
|
|
|
Tcl_AppendResult(interp, zBuf, sqlite3ErrStr(rc), 0);
|
2003-09-06 05:10:47 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-06-10 18:01:08 +04:00
|
|
|
/*
|
|
|
|
** Usage: add_test_collate <db ptr> <utf8> <utf16le> <utf16be>
|
|
|
|
**
|
|
|
|
** This function is used to test that SQLite selects the correct collation
|
|
|
|
** sequence callback when multiple versions (for different text encodings)
|
|
|
|
** are available.
|
|
|
|
**
|
|
|
|
** Calling this routine registers the collation sequence "test_collate"
|
|
|
|
** with database handle <db>. The second argument must be a list of three
|
|
|
|
** boolean values. If the first is true, then a version of test_collate is
|
|
|
|
** registered for UTF-8, if the second is true, a version is registered for
|
|
|
|
** UTF-16le, if the third is true, a UTF-16be version is available.
|
|
|
|
** Previous versions of test_collate are deleted.
|
|
|
|
**
|
|
|
|
** The collation sequence test_collate is implemented by calling the
|
|
|
|
** following TCL script:
|
|
|
|
**
|
|
|
|
** "test_collate <enc> <lhs> <rhs>"
|
|
|
|
**
|
|
|
|
** The <lhs> and <rhs> are the two values being compared, encoded in UTF-8.
|
|
|
|
** The <enc> parameter is the encoding of the collation function that
|
|
|
|
** SQLite selected to call. The TCL test script implements the
|
|
|
|
** "test_collate" proc.
|
|
|
|
**
|
|
|
|
** Note that this will only work with one intepreter at a time, as the
|
|
|
|
** interp pointer to use when evaluating the TCL script is stored in
|
|
|
|
** pTestCollateInterp.
|
|
|
|
*/
|
|
|
|
static Tcl_Interp* pTestCollateInterp;
|
|
|
|
static int test_collate_func(
|
|
|
|
void *pCtx,
|
|
|
|
int nA, const void *zA,
|
|
|
|
int nB, const void *zB
|
|
|
|
){
|
|
|
|
Tcl_Interp *i = pTestCollateInterp;
|
|
|
|
int encin = (int)pCtx;
|
|
|
|
int res;
|
2005-09-01 16:16:28 +04:00
|
|
|
int n;
|
2004-06-10 18:01:08 +04:00
|
|
|
|
|
|
|
sqlite3_value *pVal;
|
|
|
|
Tcl_Obj *pX;
|
|
|
|
|
|
|
|
pX = Tcl_NewStringObj("test_collate", -1);
|
|
|
|
Tcl_IncrRefCount(pX);
|
|
|
|
|
|
|
|
switch( encin ){
|
|
|
|
case SQLITE_UTF8:
|
|
|
|
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-8",-1));
|
|
|
|
break;
|
|
|
|
case SQLITE_UTF16LE:
|
|
|
|
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16LE",-1));
|
|
|
|
break;
|
|
|
|
case SQLITE_UTF16BE:
|
|
|
|
Tcl_ListObjAppendElement(i,pX,Tcl_NewStringObj("UTF-16BE",-1));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pVal = sqlite3ValueNew();
|
2004-06-18 08:24:54 +04:00
|
|
|
sqlite3ValueSetStr(pVal, nA, zA, encin, SQLITE_STATIC);
|
2005-09-01 16:16:28 +04:00
|
|
|
n = sqlite3_value_bytes(pVal);
|
2005-12-09 23:21:58 +03:00
|
|
|
Tcl_ListObjAppendElement(i,pX,
|
|
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n));
|
2004-06-18 08:24:54 +04:00
|
|
|
sqlite3ValueSetStr(pVal, nB, zB, encin, SQLITE_STATIC);
|
2005-09-01 16:16:28 +04:00
|
|
|
n = sqlite3_value_bytes(pVal);
|
2005-12-09 23:21:58 +03:00
|
|
|
Tcl_ListObjAppendElement(i,pX,
|
|
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(pVal),n));
|
2004-06-10 18:01:08 +04:00
|
|
|
sqlite3ValueFree(pVal);
|
|
|
|
|
|
|
|
Tcl_EvalObjEx(i, pX, 0);
|
|
|
|
Tcl_DecrRefCount(pX);
|
|
|
|
Tcl_GetIntFromObj(i, Tcl_GetObjResult(i), &res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
static int test_collate(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3 *db;
|
|
|
|
int val;
|
2004-06-29 17:18:23 +04:00
|
|
|
sqlite3_value *pVal;
|
2004-09-30 17:43:13 +04:00
|
|
|
int rc;
|
2004-06-10 18:01:08 +04:00
|
|
|
|
|
|
|
if( objc!=5 ) goto bad_args;
|
|
|
|
pTestCollateInterp = interp;
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
|
|
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR;
|
2004-09-30 17:43:13 +04:00
|
|
|
rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF8,
|
|
|
|
(void *)SQLITE_UTF8, val?test_collate_func:0);
|
|
|
|
if( rc==SQLITE_OK ){
|
|
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_create_collation(db, "test_collate", SQLITE_UTF16LE,
|
|
|
|
(void *)SQLITE_UTF16LE, val?test_collate_func:0);
|
|
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR;
|
|
|
|
|
2006-01-18 07:26:07 +03:00
|
|
|
#ifdef SQLITE_MEMDEBUG
|
|
|
|
if( sqlite3_iMallocFail>0 ){
|
|
|
|
sqlite3_iMallocFail++;
|
|
|
|
}
|
|
|
|
#endif
|
2004-09-30 17:43:13 +04:00
|
|
|
pVal = sqlite3ValueNew();
|
|
|
|
sqlite3ValueSetStr(pVal, -1, "test_collate", SQLITE_UTF8, SQLITE_STATIC);
|
2006-01-18 07:26:07 +03:00
|
|
|
rc = sqlite3_create_collation16(db,
|
|
|
|
sqlite3ValueText(pVal, SQLITE_UTF16NATIVE), SQLITE_UTF16BE,
|
|
|
|
(void *)SQLITE_UTF16BE, val?test_collate_func:0);
|
2004-09-30 17:43:13 +04:00
|
|
|
sqlite3ValueFree(pVal);
|
|
|
|
}
|
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
2006-01-18 07:26:07 +03:00
|
|
|
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2004-06-10 18:01:08 +04:00
|
|
|
return TCL_OK;
|
|
|
|
|
|
|
|
bad_args:
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-12-14 23:11:30 +03:00
|
|
|
/*
|
|
|
|
** When the collation needed callback is invoked, record the name of
|
|
|
|
** the requested collating function here. The recorded name is linked
|
|
|
|
** to a TCL variable and used to make sure that the requested collation
|
|
|
|
** name is correct.
|
|
|
|
*/
|
|
|
|
static char zNeededCollation[200];
|
|
|
|
static char *pzNeededCollation = zNeededCollation;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Called when a collating sequence is needed. Registered using
|
|
|
|
** sqlite3_collation_needed16().
|
|
|
|
*/
|
2004-06-29 17:18:23 +04:00
|
|
|
static void test_collate_needed_cb(
|
|
|
|
void *pCtx,
|
|
|
|
sqlite3 *db,
|
|
|
|
int eTextRep,
|
2005-12-14 23:11:30 +03:00
|
|
|
const void *pName
|
2004-06-29 17:18:23 +04:00
|
|
|
){
|
2006-01-09 19:12:04 +03:00
|
|
|
int enc = ENC(db);
|
2005-12-14 23:11:30 +03:00
|
|
|
int i;
|
|
|
|
char *z;
|
|
|
|
for(z = (char*)pName, i=0; *z || z[1]; z++){
|
|
|
|
if( *z ) zNeededCollation[i++] = *z;
|
|
|
|
}
|
|
|
|
zNeededCollation[i] = 0;
|
2004-06-29 17:18:23 +04:00
|
|
|
sqlite3_create_collation(
|
2006-01-09 19:12:04 +03:00
|
|
|
db, "test_collate", ENC(db), (void *)enc, test_collate_func);
|
2004-06-29 17:18:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: add_test_collate_needed DB
|
|
|
|
*/
|
|
|
|
static int test_collate_needed(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3 *db;
|
2004-09-30 17:43:13 +04:00
|
|
|
int rc;
|
2004-06-29 17:18:23 +04:00
|
|
|
|
|
|
|
if( objc!=2 ) goto bad_args;
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
2004-09-30 17:43:13 +04:00
|
|
|
rc = sqlite3_collation_needed16(db, 0, test_collate_needed_cb);
|
2005-12-14 23:11:30 +03:00
|
|
|
zNeededCollation[0] = 0;
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
2004-06-29 17:18:23 +04:00
|
|
|
return TCL_OK;
|
|
|
|
|
|
|
|
bad_args:
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "DB");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-06-29 17:18:23 +04:00
|
|
|
|
2004-06-25 16:08:46 +04:00
|
|
|
/*
|
|
|
|
** Usage: add_test_function <db ptr> <utf8> <utf16le> <utf16be>
|
|
|
|
**
|
|
|
|
** This function is used to test that SQLite selects the correct user
|
|
|
|
** function callback when multiple versions (for different text encodings)
|
|
|
|
** are available.
|
|
|
|
**
|
|
|
|
** Calling this routine registers up to three versions of the user function
|
|
|
|
** "test_function" with database handle <db>. If the second argument is
|
|
|
|
** true, then a version of test_function is registered for UTF-8, if the
|
|
|
|
** third is true, a version is registered for UTF-16le, if the fourth is
|
|
|
|
** true, a UTF-16be version is available. Previous versions of
|
|
|
|
** test_function are deleted.
|
|
|
|
**
|
|
|
|
** The user function is implemented by calling the following TCL script:
|
|
|
|
**
|
|
|
|
** "test_function <enc> <arg>"
|
|
|
|
**
|
|
|
|
** Where <enc> is one of UTF-8, UTF-16LE or UTF16BE, and <arg> is the
|
|
|
|
** single argument passed to the SQL function. The value returned by
|
|
|
|
** the TCL script is used as the return value of the SQL function. It
|
|
|
|
** is passed to SQLite using UTF-16BE for a UTF-8 test_function(), UTF-8
|
|
|
|
** for a UTF-16LE test_function(), and UTF-16LE for an implementation that
|
|
|
|
** prefers UTF-16BE.
|
|
|
|
*/
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-06-25 16:08:46 +04:00
|
|
|
static void test_function_utf8(
|
|
|
|
sqlite3_context *pCtx,
|
|
|
|
int nArg,
|
|
|
|
sqlite3_value **argv
|
|
|
|
){
|
|
|
|
Tcl_Interp *interp;
|
|
|
|
Tcl_Obj *pX;
|
|
|
|
sqlite3_value *pVal;
|
|
|
|
interp = (Tcl_Interp *)sqlite3_user_data(pCtx);
|
|
|
|
pX = Tcl_NewStringObj("test_function", -1);
|
|
|
|
Tcl_IncrRefCount(pX);
|
|
|
|
Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-8", -1));
|
|
|
|
Tcl_ListObjAppendElement(interp, pX,
|
2005-12-09 23:21:58 +03:00
|
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1));
|
2004-06-25 16:08:46 +04:00
|
|
|
Tcl_EvalObjEx(interp, pX, 0);
|
|
|
|
Tcl_DecrRefCount(pX);
|
|
|
|
sqlite3_result_text(pCtx, Tcl_GetStringResult(interp), -1, SQLITE_TRANSIENT);
|
|
|
|
pVal = sqlite3ValueNew();
|
|
|
|
sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp),
|
|
|
|
SQLITE_UTF8, SQLITE_STATIC);
|
|
|
|
sqlite3_result_text16be(pCtx, sqlite3_value_text16be(pVal),
|
|
|
|
-1, SQLITE_TRANSIENT);
|
|
|
|
sqlite3ValueFree(pVal);
|
|
|
|
}
|
|
|
|
static void test_function_utf16le(
|
|
|
|
sqlite3_context *pCtx,
|
|
|
|
int nArg,
|
|
|
|
sqlite3_value **argv
|
|
|
|
){
|
|
|
|
Tcl_Interp *interp;
|
|
|
|
Tcl_Obj *pX;
|
|
|
|
sqlite3_value *pVal;
|
|
|
|
interp = (Tcl_Interp *)sqlite3_user_data(pCtx);
|
|
|
|
pX = Tcl_NewStringObj("test_function", -1);
|
|
|
|
Tcl_IncrRefCount(pX);
|
|
|
|
Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16LE", -1));
|
|
|
|
Tcl_ListObjAppendElement(interp, pX,
|
2005-12-09 23:21:58 +03:00
|
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1));
|
2004-06-25 16:08:46 +04:00
|
|
|
Tcl_EvalObjEx(interp, pX, 0);
|
|
|
|
Tcl_DecrRefCount(pX);
|
|
|
|
pVal = sqlite3ValueNew();
|
|
|
|
sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp),
|
|
|
|
SQLITE_UTF8, SQLITE_STATIC);
|
2005-12-09 23:21:58 +03:00
|
|
|
sqlite3_result_text(pCtx,(char*)sqlite3_value_text(pVal),-1,SQLITE_TRANSIENT);
|
2004-06-25 16:08:46 +04:00
|
|
|
sqlite3ValueFree(pVal);
|
|
|
|
}
|
|
|
|
static void test_function_utf16be(
|
|
|
|
sqlite3_context *pCtx,
|
|
|
|
int nArg,
|
|
|
|
sqlite3_value **argv
|
|
|
|
){
|
|
|
|
Tcl_Interp *interp;
|
|
|
|
Tcl_Obj *pX;
|
|
|
|
sqlite3_value *pVal;
|
|
|
|
interp = (Tcl_Interp *)sqlite3_user_data(pCtx);
|
|
|
|
pX = Tcl_NewStringObj("test_function", -1);
|
|
|
|
Tcl_IncrRefCount(pX);
|
|
|
|
Tcl_ListObjAppendElement(interp, pX, Tcl_NewStringObj("UTF-16BE", -1));
|
|
|
|
Tcl_ListObjAppendElement(interp, pX,
|
2005-12-09 23:21:58 +03:00
|
|
|
Tcl_NewStringObj((char*)sqlite3_value_text(argv[0]), -1));
|
2004-06-25 16:08:46 +04:00
|
|
|
Tcl_EvalObjEx(interp, pX, 0);
|
|
|
|
Tcl_DecrRefCount(pX);
|
|
|
|
pVal = sqlite3ValueNew();
|
|
|
|
sqlite3ValueSetStr(pVal, -1, Tcl_GetStringResult(interp),
|
|
|
|
SQLITE_UTF8, SQLITE_STATIC);
|
|
|
|
sqlite3_result_text16le(pCtx, sqlite3_value_text16le(pVal),
|
|
|
|
-1, SQLITE_TRANSIENT);
|
|
|
|
sqlite3ValueFree(pVal);
|
|
|
|
}
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-06-25 16:08:46 +04:00
|
|
|
static int test_function(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-06-25 16:08:46 +04:00
|
|
|
sqlite3 *db;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
if( objc!=5 ) goto bad_args;
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
|
|
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR;
|
|
|
|
if( val ){
|
|
|
|
sqlite3_create_function(db, "test_function", 1, SQLITE_UTF8,
|
|
|
|
interp, test_function_utf8, 0, 0);
|
|
|
|
}
|
|
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[3], &val) ) return TCL_ERROR;
|
|
|
|
if( val ){
|
|
|
|
sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16LE,
|
|
|
|
interp, test_function_utf16le, 0, 0);
|
|
|
|
}
|
|
|
|
if( TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[4], &val) ) return TCL_ERROR;
|
|
|
|
if( val ){
|
|
|
|
sqlite3_create_function(db, "test_function", 1, SQLITE_UTF16BE,
|
|
|
|
interp, test_function_utf16be, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TCL_OK;
|
|
|
|
bad_args:
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " <DB> <utf8> <utf16le> <utf16be>", 0);
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-06-25 16:08:46 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
2004-06-29 17:18:23 +04:00
|
|
|
/*
|
|
|
|
** Usage: test_errstr <err code>
|
|
|
|
**
|
|
|
|
** Test that the english language string equivalents for sqlite error codes
|
|
|
|
** are sane. The parameter is an integer representing an sqlite error code.
|
|
|
|
** The result is a list of two elements, the string representation of the
|
|
|
|
** error code and the english language explanation.
|
|
|
|
*/
|
|
|
|
static int test_errstr(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
char *zCode;
|
|
|
|
int i;
|
|
|
|
if( objc!=1 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "<error code>");
|
|
|
|
}
|
|
|
|
|
|
|
|
zCode = Tcl_GetString(objv[1]);
|
|
|
|
for(i=0; i<200; i++){
|
|
|
|
if( 0==strcmp(errorName(i), zCode) ) break;
|
|
|
|
}
|
|
|
|
Tcl_SetResult(interp, (char *)sqlite3ErrStr(i), 0);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2003-02-16 22:13:36 +03:00
|
|
|
/*
|
|
|
|
** Usage: breakpoint
|
|
|
|
**
|
|
|
|
** This routine exists for one purpose - to provide a place to put a
|
|
|
|
** breakpoint with GDB that can be triggered using TCL code. The use
|
|
|
|
** for this is when a particular test fails on (say) the 1485th iteration.
|
|
|
|
** In the TCL test script, we can add code like this:
|
|
|
|
**
|
|
|
|
** if {$i==1485} breakpoint
|
|
|
|
**
|
|
|
|
** Then run testfixture in the debugger and wait for the breakpoint to
|
|
|
|
** fire. Then additional breakpoints can be set to trace down the bug.
|
|
|
|
*/
|
|
|
|
static int test_breakpoint(
|
|
|
|
void *NotUsed,
|
|
|
|
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
|
|
|
int argc, /* Number of arguments */
|
|
|
|
char **argv /* Text of each argument */
|
|
|
|
){
|
|
|
|
return TCL_OK; /* Do nothing */
|
|
|
|
}
|
|
|
|
|
2004-06-22 16:46:53 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_bind_int STMT N VALUE
|
|
|
|
**
|
|
|
|
** Test the sqlite3_bind_int interface. STMT is a prepared statement.
|
|
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
|
|
** binds a 32-bit integer VALUE to that wildcard.
|
|
|
|
*/
|
|
|
|
static int test_bind_int(
|
2004-05-20 05:12:34 +04:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int idx;
|
|
|
|
int value;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if( objc!=4 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
2004-06-22 16:46:53 +04:00
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0);
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &value) ) return TCL_ERROR;
|
|
|
|
|
2004-05-27 13:28:41 +04:00
|
|
|
rc = sqlite3_bind_int(pStmt, idx, value);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
2004-05-20 05:12:34 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-22 16:46:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_bind_int64 STMT N VALUE
|
|
|
|
**
|
|
|
|
** Test the sqlite3_bind_int64 interface. STMT is a prepared statement.
|
|
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
|
|
** binds a 64-bit integer VALUE to that wildcard.
|
|
|
|
*/
|
2004-05-20 05:12:34 +04:00
|
|
|
static int test_bind_int64(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int idx;
|
|
|
|
i64 value;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if( objc!=4 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
2004-06-22 16:46:53 +04:00
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0);
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetWideIntFromObj(interp, objv[3], &value) ) return TCL_ERROR;
|
|
|
|
|
|
|
|
rc = sqlite3_bind_int64(pStmt, idx, value);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
2004-05-20 05:12:34 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-22 16:46:53 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_bind_double STMT N VALUE
|
|
|
|
**
|
|
|
|
** Test the sqlite3_bind_double interface. STMT is a prepared statement.
|
|
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
|
|
** binds a 64-bit integer VALUE to that wildcard.
|
|
|
|
*/
|
2004-05-20 05:12:34 +04:00
|
|
|
static int test_bind_double(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int idx;
|
|
|
|
double value;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if( objc!=4 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
2004-06-22 16:46:53 +04:00
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE", 0);
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetDoubleFromObj(interp, objv[3], &value) ) return TCL_ERROR;
|
|
|
|
|
|
|
|
rc = sqlite3_bind_double(pStmt, idx, value);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
2004-05-20 05:12:34 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-22 16:46:53 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_bind_null STMT N
|
|
|
|
**
|
|
|
|
** Test the sqlite3_bind_null interface. STMT is a prepared statement.
|
|
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
|
|
** binds a NULL to the wildcard.
|
|
|
|
*/
|
2004-05-20 05:12:34 +04:00
|
|
|
static int test_bind_null(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int idx;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
2004-06-22 16:46:53 +04:00
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N", 0);
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
|
|
|
|
|
|
rc = sqlite3_bind_null(pStmt, idx);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
2004-05-20 05:12:34 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-22 16:46:53 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_bind_text STMT N STRING BYTES
|
|
|
|
**
|
|
|
|
** Test the sqlite3_bind_text interface. STMT is a prepared statement.
|
|
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
|
|
** binds a UTF-8 string STRING to the wildcard. The string is BYTES bytes
|
|
|
|
** long.
|
|
|
|
*/
|
2004-05-20 05:12:34 +04:00
|
|
|
static int test_bind_text(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int idx;
|
|
|
|
int bytes;
|
|
|
|
char *value;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if( objc!=5 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
2004-06-22 16:46:53 +04:00
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0);
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
|
|
value = Tcl_GetString(objv[3]);
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;
|
|
|
|
|
2004-06-12 13:25:12 +04:00
|
|
|
rc = sqlite3_bind_text(pStmt, idx, value, bytes, SQLITE_TRANSIENT);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
2004-05-20 05:12:34 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
2005-06-06 21:54:55 +04:00
|
|
|
Tcl_AppendResult(interp, sqlite3TestErrorName(rc), 0);
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-22 16:46:53 +04:00
|
|
|
/*
|
2006-01-24 13:58:21 +03:00
|
|
|
** Usage: sqlite3_bind_text16 ?-static? STMT N STRING BYTES
|
2004-06-22 16:46:53 +04:00
|
|
|
**
|
|
|
|
** Test the sqlite3_bind_text16 interface. STMT is a prepared statement.
|
|
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
|
|
** binds a UTF-16 string STRING to the wildcard. The string is BYTES bytes
|
|
|
|
** long.
|
|
|
|
*/
|
2004-05-20 05:12:34 +04:00
|
|
|
static int test_bind_text16(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-05-20 05:12:34 +04:00
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int idx;
|
|
|
|
int bytes;
|
|
|
|
char *value;
|
|
|
|
int rc;
|
|
|
|
|
2006-01-24 13:58:21 +03:00
|
|
|
void (*xDel)() = (objc==6?SQLITE_STATIC:SQLITE_TRANSIENT);
|
|
|
|
Tcl_Obj *oStmt = objv[objc-4];
|
|
|
|
Tcl_Obj *oN = objv[objc-3];
|
|
|
|
Tcl_Obj *oString = objv[objc-2];
|
|
|
|
Tcl_Obj *oBytes = objv[objc-1];
|
|
|
|
|
|
|
|
if( objc!=5 && objc!=6){
|
2004-05-20 05:12:34 +04:00
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
2004-06-22 16:46:53 +04:00
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N VALUE BYTES", 0);
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
2006-01-24 13:58:21 +03:00
|
|
|
if( getStmtPointer(interp, Tcl_GetString(oStmt), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, oN, &idx) ) return TCL_ERROR;
|
|
|
|
value = (char*)Tcl_GetByteArrayFromObj(oString, 0);
|
|
|
|
if( Tcl_GetIntFromObj(interp, oBytes, &bytes) ) return TCL_ERROR;
|
2004-05-20 05:12:34 +04:00
|
|
|
|
2006-01-24 13:58:21 +03:00
|
|
|
rc = sqlite3_bind_text16(pStmt, idx, (void *)value, bytes, xDel);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
2004-05-20 05:12:34 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-06-22 16:46:53 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_bind_blob STMT N DATA BYTES
|
|
|
|
**
|
|
|
|
** Test the sqlite3_bind_blob interface. STMT is a prepared statement.
|
|
|
|
** N is the index of a wildcard in the prepared statement. This command
|
|
|
|
** binds a BLOB to the wildcard. The BLOB is BYTES bytes in size.
|
|
|
|
*/
|
2004-05-20 05:12:34 +04:00
|
|
|
static int test_bind_blob(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int idx;
|
|
|
|
int bytes;
|
|
|
|
char *value;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if( objc!=5 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
2004-06-22 16:46:53 +04:00
|
|
|
Tcl_GetStringFromObj(objv[0], 0), " STMT N DATA BYTES", 0);
|
2004-05-20 05:12:34 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
|
|
|
value = Tcl_GetString(objv[3]);
|
2004-05-27 17:55:27 +04:00
|
|
|
if( Tcl_GetIntFromObj(interp, objv[4], &bytes) ) return TCL_ERROR;
|
2004-05-20 05:12:34 +04:00
|
|
|
|
2004-06-12 13:25:12 +04:00
|
|
|
rc = sqlite3_bind_blob(pStmt, idx, value, bytes, SQLITE_TRANSIENT);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, StmtToDb(pStmt), rc) ) return TCL_ERROR;
|
2004-05-20 05:12:34 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-07-15 18:15:00 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_bind_parameter_count STMT
|
|
|
|
**
|
|
|
|
** Return the number of wildcards in the given statement.
|
|
|
|
*/
|
|
|
|
static int test_bind_parameter_count(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_bind_parameter_count(pStmt)));
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-20 20:02:39 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_bind_parameter_name STMT N
|
|
|
|
**
|
|
|
|
** Return the name of the Nth wildcard. The first wildcard is 1.
|
|
|
|
** An empty string is returned if N is out of range or if the wildcard
|
|
|
|
** is nameless.
|
|
|
|
*/
|
|
|
|
static int test_bind_parameter_name(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT N");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &i) ) return TCL_ERROR;
|
|
|
|
Tcl_SetObjResult(interp,
|
|
|
|
Tcl_NewStringObj(sqlite3_bind_parameter_name(pStmt,i),-1)
|
|
|
|
);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-09-07 20:19:52 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_bind_parameter_index STMT NAME
|
|
|
|
**
|
|
|
|
** Return the index of the wildcard called NAME. Return 0 if there is
|
|
|
|
** no such wildcard.
|
|
|
|
*/
|
|
|
|
static int test_bind_parameter_index(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT NAME");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
Tcl_SetObjResult(interp,
|
|
|
|
Tcl_NewIntObj(
|
|
|
|
sqlite3_bind_parameter_index(pStmt,Tcl_GetString(objv[2]))
|
|
|
|
)
|
|
|
|
);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-20 04:14:23 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_clear_bindings STMT
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
static int test_clear_bindings(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "STMT");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_clear_bindings(pStmt)));
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-05-20 15:00:52 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_errcode DB
|
|
|
|
**
|
|
|
|
** Return the string representation of the most recent sqlite3_* API
|
|
|
|
** error code. e.g. "SQLITE_ERROR".
|
|
|
|
*/
|
|
|
|
static int test_errcode(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3 *db;
|
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " DB", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
Tcl_SetResult(interp, (char *)errorName(sqlite3_errcode(db)), 0);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: test_errmsg DB
|
|
|
|
**
|
|
|
|
** Returns the UTF-8 representation of the error message string for the
|
|
|
|
** most recent sqlite3_* API call.
|
|
|
|
*/
|
|
|
|
static int test_errmsg(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2004-05-20 15:00:52 +04:00
|
|
|
const char *zErr;
|
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " DB", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
|
|
|
|
zErr = sqlite3_errmsg(db);
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewStringObj(zErr, -1));
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: test_errmsg16 DB
|
|
|
|
**
|
|
|
|
** Returns the UTF-16 representation of the error message string for the
|
|
|
|
** most recent sqlite3_* API call. This is a byte array object at the TCL
|
|
|
|
** level, and it includes the 0x00 0x00 terminator bytes at the end of the
|
|
|
|
** UTF-16 string.
|
|
|
|
*/
|
|
|
|
static int test_errmsg16(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-09-06 21:24:11 +04:00
|
|
|
sqlite3 *db;
|
2004-05-20 15:00:52 +04:00
|
|
|
const void *zErr;
|
2006-01-18 08:51:57 +03:00
|
|
|
int bytes = 0;
|
2004-05-20 15:00:52 +04:00
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " DB", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
|
|
|
|
zErr = sqlite3_errmsg16(db);
|
2006-01-18 08:51:57 +03:00
|
|
|
if( zErr ){
|
|
|
|
bytes = sqlite3utf16ByteLen(zErr, -1);
|
|
|
|
}
|
2004-05-20 15:00:52 +04:00
|
|
|
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(zErr, bytes));
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-05-20 15:00:52 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_prepare DB sql bytes tailvar
|
|
|
|
**
|
|
|
|
** Compile up to <bytes> bytes of the supplied SQL string <sql> using
|
|
|
|
** database handle <DB>. The parameter <tailval> is the name of a global
|
|
|
|
** variable that is set to the unused portion of <sql> (if any). A
|
|
|
|
** STMT handle is returned.
|
|
|
|
*/
|
|
|
|
static int test_prepare(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3 *db;
|
|
|
|
const char *zSql;
|
|
|
|
int bytes;
|
|
|
|
const char *zTail = 0;
|
|
|
|
sqlite3_stmt *pStmt = 0;
|
|
|
|
char zBuf[50];
|
2004-05-21 05:47:26 +04:00
|
|
|
int rc;
|
2004-05-20 15:00:52 +04:00
|
|
|
|
|
|
|
if( objc!=5 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
zSql = Tcl_GetString(objv[2]);
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR;
|
|
|
|
|
2004-05-21 05:47:26 +04:00
|
|
|
rc = sqlite3_prepare(db, zSql, bytes, &pStmt, &zTail);
|
2004-09-30 17:43:13 +04:00
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
2004-05-20 15:00:52 +04:00
|
|
|
if( zTail ){
|
|
|
|
if( bytes>=0 ){
|
|
|
|
bytes = bytes - (zTail-zSql);
|
|
|
|
}
|
|
|
|
Tcl_ObjSetVar2(interp, objv[4], 0, Tcl_NewStringObj(zTail, bytes), 0);
|
|
|
|
}
|
2004-05-21 05:47:26 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
assert( pStmt==0 );
|
|
|
|
sprintf(zBuf, "(%d) ", rc);
|
|
|
|
Tcl_AppendResult(interp, zBuf, sqlite3_errmsg(db), 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2004-05-20 15:00:52 +04:00
|
|
|
|
2004-05-21 05:47:26 +04:00
|
|
|
if( pStmt ){
|
2006-01-15 05:30:57 +03:00
|
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
2004-05-21 05:47:26 +04:00
|
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
|
|
}
|
2004-05-20 15:00:52 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_prepare DB sql bytes tailvar
|
|
|
|
**
|
|
|
|
** Compile up to <bytes> bytes of the supplied SQL string <sql> using
|
|
|
|
** database handle <DB>. The parameter <tailval> is the name of a global
|
|
|
|
** variable that is set to the unused portion of <sql> (if any). A
|
|
|
|
** STMT handle is returned.
|
|
|
|
*/
|
|
|
|
static int test_prepare16(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-05-20 15:00:52 +04:00
|
|
|
sqlite3 *db;
|
|
|
|
const void *zSql;
|
|
|
|
const void *zTail = 0;
|
|
|
|
Tcl_Obj *pTail = 0;
|
|
|
|
sqlite3_stmt *pStmt = 0;
|
2004-09-30 17:43:13 +04:00
|
|
|
char zBuf[50];
|
|
|
|
int rc;
|
2004-05-20 15:00:52 +04:00
|
|
|
int bytes; /* The integer specified as arg 3 */
|
|
|
|
int objlen; /* The byte-array length of arg 2 */
|
|
|
|
|
|
|
|
if( objc!=5 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " DB sql bytes tailvar", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
|
|
|
zSql = Tcl_GetByteArrayFromObj(objv[2], &objlen);
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[3], &bytes) ) return TCL_ERROR;
|
|
|
|
|
2004-09-30 17:43:13 +04:00
|
|
|
rc = sqlite3_prepare16(db, zSql, bytes, &pStmt, &zTail);
|
|
|
|
if( sqlite3TestErrCode(interp, db, rc) ) return TCL_ERROR;
|
|
|
|
if( rc ){
|
2004-05-20 15:00:52 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( zTail ){
|
|
|
|
objlen = objlen - ((u8 *)zTail-(u8 *)zSql);
|
|
|
|
}else{
|
|
|
|
objlen = 0;
|
|
|
|
}
|
|
|
|
pTail = Tcl_NewByteArrayObj((u8 *)zTail, objlen);
|
|
|
|
Tcl_IncrRefCount(pTail);
|
|
|
|
Tcl_ObjSetVar2(interp, objv[4], 0, pTail, 0);
|
2004-05-21 05:47:26 +04:00
|
|
|
Tcl_DecrRefCount(pTail);
|
|
|
|
|
|
|
|
if( pStmt ){
|
2006-01-15 05:30:57 +03:00
|
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, pStmt) ) return TCL_ERROR;
|
2004-05-21 05:47:26 +04:00
|
|
|
}
|
|
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-05-21 05:47:26 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_open filename ?options-list?
|
|
|
|
*/
|
|
|
|
static int test_open(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
const char *zFilename;
|
|
|
|
sqlite3 *db;
|
|
|
|
int rc;
|
|
|
|
char zBuf[100];
|
2004-05-20 15:00:52 +04:00
|
|
|
|
2004-05-21 05:47:26 +04:00
|
|
|
if( objc!=3 && objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " filename options-list", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
zFilename = Tcl_GetString(objv[1]);
|
2004-06-08 04:02:33 +04:00
|
|
|
rc = sqlite3_open(zFilename, &db);
|
2004-05-21 05:47:26 +04:00
|
|
|
|
2006-01-15 05:30:57 +03:00
|
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
2004-05-20 15:00:52 +04:00
|
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-21 05:47:26 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_open16 filename options
|
|
|
|
*/
|
|
|
|
static int test_open16(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-05-21 05:47:26 +04:00
|
|
|
const void *zFilename;
|
|
|
|
sqlite3 *db;
|
|
|
|
int rc;
|
|
|
|
char zBuf[100];
|
|
|
|
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " filename options-list", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
zFilename = Tcl_GetByteArrayFromObj(objv[1], 0);
|
2004-06-08 04:02:33 +04:00
|
|
|
rc = sqlite3_open16(zFilename, &db);
|
2004-05-21 05:47:26 +04:00
|
|
|
|
2006-01-15 05:30:57 +03:00
|
|
|
if( sqlite3TestMakePointerStr(interp, zBuf, db) ) return TCL_ERROR;
|
2004-05-21 05:47:26 +04:00
|
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-05-21 05:47:26 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
2004-05-21 02:16:29 +04:00
|
|
|
|
2004-06-30 12:20:16 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_complete16 <UTF-16 string>
|
|
|
|
**
|
|
|
|
** Return 1 if the supplied argument is a complete SQL statement, or zero
|
|
|
|
** otherwise.
|
|
|
|
*/
|
|
|
|
static int test_complete16(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2005-02-26 20:31:26 +03:00
|
|
|
#if !defined(SQLITE_OMIT_COMPLETE) && !defined(SQLITE_OMIT_UTF16)
|
2004-06-30 12:20:16 +04:00
|
|
|
char *zBuf;
|
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "<utf-16 sql>");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
2005-12-09 23:21:58 +03:00
|
|
|
zBuf = (char*)Tcl_GetByteArrayFromObj(objv[1], 0);
|
2004-06-30 12:20:16 +04:00
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_complete16(zBuf)));
|
2005-02-26 20:31:26 +03:00
|
|
|
#endif /* SQLITE_OMIT_COMPLETE && SQLITE_OMIT_UTF16 */
|
2004-06-30 12:20:16 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-21 14:08:53 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_step STMT
|
|
|
|
**
|
|
|
|
** Advance the statement to the next row.
|
|
|
|
*/
|
2004-05-26 04:07:25 +04:00
|
|
|
static int test_step(
|
2004-05-21 14:08:53 +04:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int rc;
|
|
|
|
|
2004-05-22 14:33:04 +04:00
|
|
|
if( objc!=2 ){
|
2004-05-21 14:08:53 +04:00
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
2004-05-26 04:07:25 +04:00
|
|
|
rc = sqlite3_step(pStmt);
|
2004-05-21 14:08:53 +04:00
|
|
|
|
2004-06-15 06:44:18 +04:00
|
|
|
/* if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; */
|
2004-05-26 10:18:37 +04:00
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), 0);
|
2004-05-22 14:33:04 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_column_count STMT
|
2004-05-22 14:33:04 +04:00
|
|
|
**
|
2004-05-27 05:04:07 +04:00
|
|
|
** Return the number of columns returned by the sql statement STMT.
|
2004-05-22 14:33:04 +04:00
|
|
|
*/
|
2004-05-27 05:04:07 +04:00
|
|
|
static int test_column_count(
|
2004-05-22 14:33:04 +04:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
if( objc!=2 ){
|
2004-05-22 14:33:04 +04:00
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT column", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_column_count(pStmt)));
|
2004-05-22 14:33:04 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_column_type STMT column
|
2004-05-22 14:33:04 +04:00
|
|
|
**
|
2004-05-27 05:04:07 +04:00
|
|
|
** Return the type of the data in column 'column' of the current row.
|
2004-05-22 14:33:04 +04:00
|
|
|
*/
|
2004-05-27 05:04:07 +04:00
|
|
|
static int test_column_type(
|
2004-05-22 14:33:04 +04:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int col;
|
2004-05-27 05:04:07 +04:00
|
|
|
int tp;
|
2004-05-22 14:33:04 +04:00
|
|
|
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT column", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
|
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
tp = sqlite3_column_type(pStmt, col);
|
|
|
|
switch( tp ){
|
2004-05-31 22:51:57 +04:00
|
|
|
case SQLITE_INTEGER:
|
2004-05-27 05:04:07 +04:00
|
|
|
Tcl_SetResult(interp, "INTEGER", TCL_STATIC);
|
|
|
|
break;
|
2004-05-31 22:51:57 +04:00
|
|
|
case SQLITE_NULL:
|
2004-05-27 05:04:07 +04:00
|
|
|
Tcl_SetResult(interp, "NULL", TCL_STATIC);
|
|
|
|
break;
|
2004-05-31 22:51:57 +04:00
|
|
|
case SQLITE_FLOAT:
|
2004-05-27 05:04:07 +04:00
|
|
|
Tcl_SetResult(interp, "FLOAT", TCL_STATIC);
|
|
|
|
break;
|
2004-05-31 22:51:57 +04:00
|
|
|
case SQLITE_TEXT:
|
2004-05-27 05:04:07 +04:00
|
|
|
Tcl_SetResult(interp, "TEXT", TCL_STATIC);
|
|
|
|
break;
|
2004-05-31 22:51:57 +04:00
|
|
|
case SQLITE_BLOB:
|
2004-05-27 05:04:07 +04:00
|
|
|
Tcl_SetResult(interp, "BLOB", TCL_STATIC);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
}
|
2004-05-22 14:33:04 +04:00
|
|
|
|
2004-05-21 14:08:53 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-26 14:11:05 +04:00
|
|
|
/*
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_column_int64 STMT column
|
2004-05-26 14:11:05 +04:00
|
|
|
**
|
2004-05-27 05:04:07 +04:00
|
|
|
** Return the data in column 'column' of the current row cast as an
|
|
|
|
** wide (64-bit) integer.
|
2004-05-26 14:11:05 +04:00
|
|
|
*/
|
2004-05-27 05:04:07 +04:00
|
|
|
static int test_column_int64(
|
2004-05-26 14:11:05 +04:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int col;
|
2004-05-27 05:04:07 +04:00
|
|
|
i64 iVal;
|
2004-05-26 14:11:05 +04:00
|
|
|
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT column", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
|
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
iVal = sqlite3_column_int64(pStmt, col);
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(iVal));
|
2004-05-26 14:11:05 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-27 05:49:51 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_column_blob STMT column
|
|
|
|
*/
|
|
|
|
static int test_column_blob(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int col;
|
|
|
|
|
|
|
|
int len;
|
2004-05-27 13:28:41 +04:00
|
|
|
const void *pBlob;
|
2004-05-27 05:49:51 +04:00
|
|
|
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT column", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
|
|
|
|
|
|
|
|
pBlob = sqlite3_column_blob(pStmt, col);
|
|
|
|
len = sqlite3_column_bytes(pStmt, col);
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewByteArrayObj(pBlob, len));
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-26 14:11:05 +04:00
|
|
|
/*
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_column_double STMT column
|
2004-05-26 14:11:05 +04:00
|
|
|
**
|
2004-05-27 05:04:07 +04:00
|
|
|
** Return the data in column 'column' of the current row cast as a double.
|
2004-05-26 14:11:05 +04:00
|
|
|
*/
|
2004-05-27 05:04:07 +04:00
|
|
|
static int test_column_double(
|
2004-05-26 14:11:05 +04:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int col;
|
2004-05-27 05:04:07 +04:00
|
|
|
double rVal;
|
2004-05-26 14:11:05 +04:00
|
|
|
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT column", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
|
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
rVal = sqlite3_column_double(pStmt, col);
|
2004-05-27 13:28:41 +04:00
|
|
|
Tcl_SetObjResult(interp, Tcl_NewDoubleObj(rVal));
|
2004-05-26 14:11:05 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-26 04:07:25 +04:00
|
|
|
/*
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_data_count STMT
|
2004-05-26 04:07:25 +04:00
|
|
|
**
|
|
|
|
** Return the number of columns returned by the sql statement STMT.
|
|
|
|
*/
|
2004-05-27 05:04:07 +04:00
|
|
|
static int test_data_count(
|
2004-05-26 04:07:25 +04:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT column", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_data_count(pStmt)));
|
2004-05-26 04:07:25 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-26 14:11:05 +04:00
|
|
|
/*
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_column_text STMT column
|
2004-05-26 14:11:05 +04:00
|
|
|
**
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_column_decltype STMT column
|
|
|
|
**
|
|
|
|
** Usage: sqlite3_column_name STMT column
|
2004-05-26 14:11:05 +04:00
|
|
|
*/
|
2004-05-27 05:04:07 +04:00
|
|
|
static int test_stmt_utf8(
|
2004-06-22 16:46:53 +04:00
|
|
|
void * clientData, /* Pointer to SQLite API function to be invoke */
|
2004-05-26 14:11:05 +04:00
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int col;
|
2004-05-27 13:28:41 +04:00
|
|
|
const char *(*xFunc)(sqlite3_stmt*, int) = clientData;
|
2004-05-27 14:30:52 +04:00
|
|
|
const char *zRet;
|
2004-05-26 14:11:05 +04:00
|
|
|
|
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT column", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
|
2004-05-27 14:30:52 +04:00
|
|
|
zRet = xFunc(pStmt, col);
|
|
|
|
if( zRet ){
|
|
|
|
Tcl_SetResult(interp, (char *)zRet, 0);
|
|
|
|
}
|
2004-05-26 14:11:05 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-21 07:04:02 +03:00
|
|
|
static int test_global_recover(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
#ifndef SQLITE_OMIT_GLOBALRECOVER
|
|
|
|
int rc;
|
|
|
|
if( objc!=1 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
rc = sqlite3_global_recover();
|
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
|
|
|
#endif
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-05-26 04:07:25 +04:00
|
|
|
/*
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_column_text STMT column
|
2004-05-26 04:07:25 +04:00
|
|
|
**
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_column_decltype STMT column
|
|
|
|
**
|
|
|
|
** Usage: sqlite3_column_name STMT column
|
2004-05-26 04:07:25 +04:00
|
|
|
*/
|
2004-05-27 05:04:07 +04:00
|
|
|
static int test_stmt_utf16(
|
2004-06-22 16:46:53 +04:00
|
|
|
void * clientData, /* Pointer to SQLite API function to be invoked */
|
2004-05-26 04:07:25 +04:00
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-05-26 04:07:25 +04:00
|
|
|
sqlite3_stmt *pStmt;
|
2004-05-27 05:04:07 +04:00
|
|
|
int col;
|
|
|
|
Tcl_Obj *pRet;
|
|
|
|
const void *zName16;
|
2004-05-27 13:28:41 +04:00
|
|
|
const void *(*xFunc)(sqlite3_stmt*, int) = clientData;
|
2004-05-26 04:07:25 +04:00
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
if( objc!=3 ){
|
2004-05-26 04:07:25 +04:00
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT column", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
2004-05-27 05:04:07 +04:00
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
|
2004-05-26 04:07:25 +04:00
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
zName16 = xFunc(pStmt, col);
|
2004-05-27 14:30:52 +04:00
|
|
|
if( zName16 ){
|
|
|
|
pRet = Tcl_NewByteArrayObj(zName16, sqlite3utf16ByteLen(zName16, -1)+2);
|
|
|
|
Tcl_SetObjResult(interp, pRet);
|
|
|
|
}
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif /* SQLITE_OMIT_UTF16 */
|
2004-05-26 04:07:25 +04:00
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
return TCL_OK;
|
2004-05-21 02:16:29 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-05-27 05:04:07 +04:00
|
|
|
** Usage: sqlite3_column_int STMT column
|
|
|
|
**
|
|
|
|
** Usage: sqlite3_column_bytes STMT column
|
|
|
|
**
|
|
|
|
** Usage: sqlite3_column_bytes16 STMT column
|
2004-05-21 02:16:29 +04:00
|
|
|
**
|
|
|
|
*/
|
2004-05-27 05:04:07 +04:00
|
|
|
static int test_stmt_int(
|
2004-06-22 16:46:53 +04:00
|
|
|
void * clientData, /* Pointer to SQLite API function to be invoked */
|
2004-05-21 02:16:29 +04:00
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2004-05-27 05:04:07 +04:00
|
|
|
sqlite3_stmt *pStmt;
|
|
|
|
int col;
|
2004-05-27 13:28:41 +04:00
|
|
|
int (*xFunc)(sqlite3_stmt*, int) = clientData;
|
2004-05-21 02:16:29 +04:00
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " STMT column", 0);
|
2004-05-21 02:16:29 +04:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2004-05-27 05:04:07 +04:00
|
|
|
|
|
|
|
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[2], &col) ) return TCL_ERROR;
|
|
|
|
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(xFunc(pStmt, col)));
|
2004-05-21 02:16:29 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-27 13:41:12 +04:00
|
|
|
#ifndef SQLITE_OMIT_DISKIO
|
2004-06-01 18:09:28 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3OsOpenReadWrite <filename>
|
|
|
|
*/
|
|
|
|
static int test_sqlite3OsOpenReadWrite(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2005-11-29 06:13:21 +03:00
|
|
|
OsFile *pFile;
|
2004-06-01 18:09:28 +04:00
|
|
|
int rc;
|
|
|
|
int dummy;
|
|
|
|
char zBuf[100];
|
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " filename", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
2006-01-06 17:32:19 +03:00
|
|
|
rc = sqlite3OsOpenReadWrite(Tcl_GetString(objv[1]), &pFile, &dummy);
|
2004-06-01 18:09:28 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2006-01-15 05:30:57 +03:00
|
|
|
sqlite3TestMakePointerStr(interp, zBuf, pFile);
|
2004-06-01 18:09:28 +04:00
|
|
|
Tcl_SetResult(interp, zBuf, 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3OsClose <file handle>
|
|
|
|
*/
|
|
|
|
static int test_sqlite3OsClose(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2005-11-29 06:13:21 +03:00
|
|
|
OsFile *pFile;
|
2004-06-01 18:09:28 +04:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " filehandle", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getFilePointer(interp, Tcl_GetString(objv[1]), &pFile) ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2005-11-30 06:20:31 +03:00
|
|
|
rc = sqlite3OsClose(&pFile);
|
2004-06-01 18:09:28 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3OsLock <file handle> <locktype>
|
|
|
|
*/
|
|
|
|
static int test_sqlite3OsLock(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
OsFile * pFile;
|
|
|
|
int rc;
|
2004-05-21 02:16:29 +04:00
|
|
|
|
2004-06-01 18:09:28 +04:00
|
|
|
if( objc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]),
|
|
|
|
" filehandle (SHARED|RESERVED|PENDING|EXCLUSIVE)", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getFilePointer(interp, Tcl_GetString(objv[1]), &pFile) ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( 0==strcmp("SHARED", Tcl_GetString(objv[2])) ){
|
2005-11-30 06:20:31 +03:00
|
|
|
rc = sqlite3OsLock(pFile, SHARED_LOCK);
|
2004-06-01 18:09:28 +04:00
|
|
|
}
|
|
|
|
else if( 0==strcmp("RESERVED", Tcl_GetString(objv[2])) ){
|
2005-11-30 06:20:31 +03:00
|
|
|
rc = sqlite3OsLock(pFile, RESERVED_LOCK);
|
2004-06-01 18:09:28 +04:00
|
|
|
}
|
|
|
|
else if( 0==strcmp("PENDING", Tcl_GetString(objv[2])) ){
|
2005-11-30 06:20:31 +03:00
|
|
|
rc = sqlite3OsLock(pFile, PENDING_LOCK);
|
2004-06-01 18:09:28 +04:00
|
|
|
}
|
|
|
|
else if( 0==strcmp("EXCLUSIVE", Tcl_GetString(objv[2])) ){
|
2005-11-30 06:20:31 +03:00
|
|
|
rc = sqlite3OsLock(pFile, EXCLUSIVE_LOCK);
|
2004-06-01 18:09:28 +04:00
|
|
|
}else{
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]),
|
|
|
|
" filehandle (SHARED|RESERVED|PENDING|EXCLUSIVE)", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3OsUnlock <file handle>
|
|
|
|
*/
|
|
|
|
static int test_sqlite3OsUnlock(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
OsFile * pFile;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
|
|
|
Tcl_GetString(objv[0]), " filehandle", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( getFilePointer(interp, Tcl_GetString(objv[1]), &pFile) ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2005-11-30 06:20:31 +03:00
|
|
|
rc = sqlite3OsUnlock(pFile, NO_LOCK);
|
2004-06-01 18:09:28 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
2004-05-27 05:04:07 +04:00
|
|
|
|
2004-08-14 21:10:10 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3OsTempFileName
|
|
|
|
*/
|
|
|
|
static int test_sqlite3OsTempFileName(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
char zFile[SQLITE_TEMPNAME_SIZE];
|
|
|
|
int rc;
|
|
|
|
|
2006-01-06 17:32:19 +03:00
|
|
|
rc = sqlite3OsTempFileName(zFile);
|
2004-08-14 21:10:10 +04:00
|
|
|
if( rc!=SQLITE_OK ){
|
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
Tcl_AppendResult(interp, zFile, 0);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
2005-05-27 13:41:12 +04:00
|
|
|
#endif
|
2004-06-12 13:25:12 +04:00
|
|
|
|
2005-01-11 18:28:33 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite_set_magic DB MAGIC-NUMBER
|
|
|
|
**
|
|
|
|
** Set the db->magic value. This is used to test error recovery logic.
|
|
|
|
*/
|
|
|
|
static int sqlite_set_magic(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int argc,
|
|
|
|
char **argv
|
|
|
|
){
|
|
|
|
sqlite3 *db;
|
|
|
|
if( argc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" DB MAGIC", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
|
|
if( strcmp(argv[2], "SQLITE_MAGIC_OPEN")==0 ){
|
|
|
|
db->magic = SQLITE_MAGIC_OPEN;
|
|
|
|
}else if( strcmp(argv[2], "SQLITE_MAGIC_CLOSED")==0 ){
|
|
|
|
db->magic = SQLITE_MAGIC_CLOSED;
|
|
|
|
}else if( strcmp(argv[2], "SQLITE_MAGIC_BUSY")==0 ){
|
|
|
|
db->magic = SQLITE_MAGIC_BUSY;
|
|
|
|
}else if( strcmp(argv[2], "SQLITE_MAGIC_ERROR")==0 ){
|
|
|
|
db->magic = SQLITE_MAGIC_ERROR;
|
|
|
|
}else if( Tcl_GetInt(interp, argv[2], &db->magic) ){
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-11 19:54:14 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_interrupt DB
|
|
|
|
**
|
|
|
|
** Trigger an interrupt on DB
|
|
|
|
*/
|
|
|
|
static int test_interrupt(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int argc,
|
|
|
|
char **argv
|
|
|
|
){
|
|
|
|
sqlite3 *db;
|
|
|
|
if( argc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
|
|
sqlite3_interrupt(db);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-09-07 01:40:45 +04:00
|
|
|
static u8 *sqlite3_stack_baseline = 0;
|
|
|
|
|
2005-01-20 04:14:23 +03:00
|
|
|
/*
|
2005-09-07 01:40:45 +04:00
|
|
|
** Fill the stack with a known bitpattern.
|
|
|
|
*/
|
|
|
|
static void prepStack(void){
|
|
|
|
int i;
|
|
|
|
u32 bigBuf[65536];
|
|
|
|
for(i=0; i<sizeof(bigBuf); i++) bigBuf[i] = 0xdeadbeef;
|
|
|
|
sqlite3_stack_baseline = (u8*)&bigBuf[65536];
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Get the current stack depth. Used for debugging only.
|
|
|
|
*/
|
|
|
|
u64 sqlite3StackDepth(void){
|
|
|
|
u8 x;
|
|
|
|
return (u64)(sqlite3_stack_baseline - &x);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_stack_used DB SQL
|
2005-01-20 04:14:23 +03:00
|
|
|
**
|
2005-09-07 01:40:45 +04:00
|
|
|
** Try to measure the amount of stack space used by a call to sqlite3_exec
|
2005-01-20 04:14:23 +03:00
|
|
|
*/
|
2005-09-07 01:40:45 +04:00
|
|
|
static int test_stack_used(
|
2005-01-20 04:14:23 +03:00
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int argc,
|
|
|
|
char **argv
|
|
|
|
){
|
|
|
|
sqlite3 *db;
|
2005-09-07 01:40:45 +04:00
|
|
|
int i;
|
|
|
|
if( argc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" DB SQL", 0);
|
2005-01-20 04:14:23 +03:00
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2005-09-07 01:40:45 +04:00
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
|
|
prepStack();
|
|
|
|
sqlite3_exec(db, argv[2], 0, 0, 0);
|
|
|
|
for(i=65535; i>=0 && ((u32*)sqlite3_stack_baseline)[-i]==0xdeadbeef; i--){}
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(i*4));
|
2005-01-20 04:14:23 +03:00
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-01-25 07:27:54 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite_delete_function DB function-name
|
|
|
|
**
|
|
|
|
** Delete the user function 'function-name' from database handle DB. It
|
|
|
|
** is assumed that the user function was created as UTF8, any number of
|
|
|
|
** arguments (the way the TCL interface does it).
|
|
|
|
*/
|
|
|
|
static int delete_function(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int argc,
|
|
|
|
char **argv
|
|
|
|
){
|
|
|
|
int rc;
|
|
|
|
sqlite3 *db;
|
|
|
|
if( argc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" DB function-name", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_create_function(db, argv[2], -1, SQLITE_UTF8, 0, 0, 0, 0);
|
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite_delete_collation DB collation-name
|
|
|
|
**
|
|
|
|
** Delete the collation sequence 'collation-name' from database handle
|
|
|
|
** DB. It is assumed that the collation sequence was created as UTF8 (the
|
|
|
|
** way the TCL interface does it).
|
|
|
|
*/
|
|
|
|
static int delete_collation(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int argc,
|
|
|
|
char **argv
|
|
|
|
){
|
|
|
|
int rc;
|
|
|
|
sqlite3 *db;
|
|
|
|
if( argc!=3 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" DB function-name", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
|
|
rc = sqlite3_create_collation(db, argv[2], SQLITE_UTF8, 0, 0);
|
|
|
|
Tcl_SetResult(interp, (char *)errorName(rc), TCL_STATIC);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2005-05-26 20:23:34 +04:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_get_autocommit DB
|
|
|
|
**
|
|
|
|
** Return true if the database DB is currently in auto-commit mode.
|
|
|
|
** Return false if not.
|
|
|
|
*/
|
|
|
|
static int get_autocommit(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int argc,
|
|
|
|
char **argv
|
|
|
|
){
|
|
|
|
char zBuf[30];
|
|
|
|
sqlite3 *db;
|
|
|
|
if( argc!=2 ){
|
|
|
|
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
|
|
|
" DB", 0);
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR;
|
|
|
|
sprintf(zBuf, "%d", sqlite3_get_autocommit(db));
|
|
|
|
Tcl_AppendResult(interp, zBuf, 0);
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-20 22:34:20 +04:00
|
|
|
/*
|
|
|
|
** Usage: tcl_variable_type VARIABLENAME
|
|
|
|
**
|
|
|
|
** Return the name of the internal representation for the
|
|
|
|
** value of the given variable.
|
|
|
|
*/
|
|
|
|
static int tcl_variable_type(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
Tcl_Obj *pVar;
|
|
|
|
if( objc!=2 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "VARIABLE");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
pVar = Tcl_GetVar2Ex(interp, Tcl_GetString(objv[1]), 0, TCL_LEAVE_ERR_MSG);
|
|
|
|
if( pVar==0 ) return TCL_ERROR;
|
|
|
|
if( pVar->typePtr ){
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewStringObj(pVar->typePtr->name, -1));
|
|
|
|
}
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2006-01-05 18:50:06 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_release_memory ?N?
|
|
|
|
**
|
|
|
|
** Attempt to release memory currently held but not actually required.
|
|
|
|
** The integer N is the number of bytes we are trying to release. The
|
|
|
|
** return value is the amount of memory actually released.
|
|
|
|
*/
|
|
|
|
static int test_release_memory(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2006-01-12 00:41:20 +03:00
|
|
|
#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
|
2006-01-05 18:50:06 +03:00
|
|
|
int N;
|
|
|
|
int amt;
|
|
|
|
if( objc!=1 && objc!=2 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "?N?");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
|
|
|
if( objc==2 ){
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
|
|
|
|
}else{
|
|
|
|
N = -1;
|
|
|
|
}
|
|
|
|
amt = sqlite3_release_memory(N);
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(amt));
|
|
|
|
#endif
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_soft_heap_limit ?N?
|
|
|
|
**
|
|
|
|
** Query or set the soft heap limit for the current thread. The
|
|
|
|
** limit is only changed if the N is present. The previous limit
|
|
|
|
** is returned.
|
|
|
|
*/
|
|
|
|
static int test_soft_heap_limit(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
2006-01-12 00:41:20 +03:00
|
|
|
#if defined(SQLITE_ENABLE_MEMORY_MANAGEMENT) && !defined(SQLITE_OMIT_DISKIO)
|
2006-01-05 18:50:06 +03:00
|
|
|
int amt;
|
|
|
|
if( objc!=1 && objc!=2 ){
|
|
|
|
Tcl_WrongNumArgs(interp, 1, objv, "?N?");
|
|
|
|
return TCL_ERROR;
|
|
|
|
}
|
2006-01-12 00:41:20 +03:00
|
|
|
amt = sqlite3ThreadDataReadOnly()->nSoftHeapLimit;
|
2006-01-05 18:50:06 +03:00
|
|
|
if( objc==2 ){
|
|
|
|
int N;
|
|
|
|
if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
|
|
|
|
sqlite3_soft_heap_limit(N);
|
|
|
|
}
|
|
|
|
Tcl_SetObjResult(interp, Tcl_NewIntObj(amt));
|
|
|
|
#endif
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
2006-01-12 02:40:33 +03:00
|
|
|
/*
|
|
|
|
** Usage: sqlite3_clear_tsd_memdebug
|
|
|
|
**
|
|
|
|
** Clear all of the MEMDEBUG information out of thread-specific data.
|
|
|
|
** This will allow it to be deallocated.
|
|
|
|
*/
|
|
|
|
static int test_clear_tsd_memdebug(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_tsd_release
|
|
|
|
**
|
|
|
|
** Call sqlite3ReleaseThreadData.
|
|
|
|
*/
|
|
|
|
static int test_tsd_release(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
#if defined(SQLITE_MEMDEBUG)
|
|
|
|
sqlite3ReleaseThreadData();
|
|
|
|
#endif
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Usage: sqlite3_thread_cleanup
|
|
|
|
**
|
|
|
|
** Call the sqlite3_thread_cleanup API.
|
|
|
|
*/
|
|
|
|
static int test_thread_cleanup(
|
|
|
|
void * clientData,
|
|
|
|
Tcl_Interp *interp,
|
|
|
|
int objc,
|
|
|
|
Tcl_Obj *CONST objv[]
|
|
|
|
){
|
|
|
|
sqlite3_thread_cleanup();
|
|
|
|
return TCL_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-31 00:23:09 +04:00
|
|
|
/*
|
|
|
|
** This routine sets entries in the global ::sqlite_options() array variable
|
|
|
|
** according to the compile-time configuration of the database. Test
|
|
|
|
** procedures use this to determine when tests should be omitted.
|
|
|
|
*/
|
|
|
|
static void set_options(Tcl_Interp *interp){
|
2005-02-17 03:03:06 +03:00
|
|
|
#ifdef SQLITE_32BIT_ROWID
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "rowid32", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "rowid32", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2005-07-08 16:13:04 +04:00
|
|
|
#ifdef SQLITE_CASE_SENSITIVE_LIKE
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options","casesensitivelike","1",TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options","casesensitivelike","0",TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2005-11-25 13:38:22 +03:00
|
|
|
#ifdef SQLITE_DISABLE_DIRSYNC
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "dirsync", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "dirsync", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2005-11-25 12:01:23 +03:00
|
|
|
#ifdef SQLITE_DISABLE_LFS
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "lfs", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "lfs", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_ALTERTABLE
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "altertable", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "altertable", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2005-07-08 16:13:04 +04:00
|
|
|
#ifdef SQLITE_OMIT_ANALYZE
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "analyze", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "analyze", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-10-31 00:23:09 +04:00
|
|
|
#ifdef SQLITE_OMIT_AUTHORIZATION
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "auth", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "auth", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
|
|
|
#ifdef SQLITE_OMIT_AUTOINCREMENT
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "autoinc", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "autoinc", "1", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
|
|
|
#ifdef SQLITE_OMIT_AUTOVACUUM
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "autovacuum", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "autovacuum", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif /* SQLITE_OMIT_AUTOVACUUM */
|
2004-11-19 10:07:30 +03:00
|
|
|
#if !defined(SQLITE_DEFAULT_AUTOVACUUM) || SQLITE_DEFAULT_AUTOVACUUM==0
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp,"sqlite_options","default_autovacuum","0",TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp,"sqlite_options","default_autovacuum","1",TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2005-08-14 05:20:37 +04:00
|
|
|
#ifdef SQLITE_OMIT_BETWEEN_OPTIMIZATION
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "between_opt", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "between_opt", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_BLOB_LITERAL
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "bloblit", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "bloblit", "1", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2005-06-25 22:42:14 +04:00
|
|
|
#ifdef SQLITE_OMIT_CAST
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "cast", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "cast", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2005-11-03 03:41:17 +03:00
|
|
|
#ifdef SQLITE_OMIT_CHECK
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "check", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "check", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2006-02-09 16:43:28 +03:00
|
|
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "columnmetadata", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "columnmetadata", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2005-02-26 20:31:26 +03:00
|
|
|
#ifdef SQLITE_OMIT_COMPLETE
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "complete", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "complete", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-10-31 00:23:09 +04:00
|
|
|
#ifdef SQLITE_OMIT_COMPOUND_SELECT
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "compound", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "compound", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
|
|
|
#ifdef SQLITE_OMIT_CONFLICT_CLAUSE
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "conflict", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "conflict", "1", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#endif
|
2004-11-22 22:12:19 +03:00
|
|
|
|
2006-01-06 17:32:19 +03:00
|
|
|
#if OS_UNIX
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "crashtest", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "crashtest", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_DATETIME_FUNCS
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "datetime", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "datetime", "1", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2005-04-28 21:18:48 +04:00
|
|
|
#ifdef SQLITE_OMIT_DISKIO
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "diskio", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "diskio", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_EXPLAIN
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "explain", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "explain", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SQLITE_OMIT_FLOATING_POINT
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "floatingpoint", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "floatingpoint", "1", TCL_GLOBAL_ONLY);
|
2004-10-31 00:23:09 +04:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2004-10-31 00:23:09 +04:00
|
|
|
#ifdef SQLITE_OMIT_FOREIGN_KEY
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "foreignkey", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "foreignkey", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2005-03-21 07:04:02 +03:00
|
|
|
#ifdef SQLITE_OMIT_GLOBALRECOVER
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "globalrecover", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "globalrecover", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_INTEGRITY_CHECK
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "integrityck", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 05:22:47 +03:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "integrityck", "1", TCL_GLOBAL_ONLY);
|
2004-10-31 05:22:47 +03:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2005-08-14 05:20:37 +04:00
|
|
|
#ifdef SQLITE_OMIT_LIKE_OPTIMIZATION
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "like_opt", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "like_opt", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-10-31 05:22:47 +03:00
|
|
|
#ifdef SQLITE_OMIT_MEMORYDB
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "memorydb", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "memorydb", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2006-01-12 00:41:20 +03:00
|
|
|
#ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
|
2006-01-05 18:50:06 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "memorymanage", "1", TCL_GLOBAL_ONLY);
|
2006-01-12 00:41:20 +03:00
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "memorymanage", "0", TCL_GLOBAL_ONLY);
|
2006-01-05 18:50:06 +03:00
|
|
|
#endif
|
|
|
|
|
2005-08-14 05:20:37 +04:00
|
|
|
#ifdef SQLITE_OMIT_OR_OPTIMIZATION
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "or_opt", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "or_opt", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_PAGER_PRAGMAS
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "pager_pragmas", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 05:22:47 +03:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "pager_pragmas", "1", TCL_GLOBAL_ONLY);
|
2004-10-31 05:22:47 +03:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2005-04-28 21:18:48 +04:00
|
|
|
#ifdef SQLITE_OMIT_PARSER
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "parser", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "parser", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2005-02-26 21:10:44 +03:00
|
|
|
#if defined(SQLITE_OMIT_PRAGMA) || defined(SQLITE_OMIT_FLAG_PRAGMAS)
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "pragma", "0", TCL_GLOBAL_ONLY);
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "integrityck", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 05:22:47 +03:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "pragma", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SQLITE_OMIT_PROGRESS_CALLBACK
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "progress", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "progress", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2006-01-07 19:06:07 +03:00
|
|
|
#ifdef SQLITE_ENABLE_REDEF_IO
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "redefio", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "redefio", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_REINDEX
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "reindex", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "reindex", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SQLITE_OMIT_SCHEMA_PRAGMAS
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "schema_pragmas", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "schema_pragmas", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "schema_version", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "schema_version", "1", TCL_GLOBAL_ONLY);
|
2004-10-31 05:22:47 +03:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2005-12-30 19:28:01 +03:00
|
|
|
#ifdef SQLITE_OMIT_SHARED_CACHE
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "shared_cache", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "shared_cache", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2005-01-21 06:12:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_SUBQUERY
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "subquery", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "subquery", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-10-31 05:22:47 +03:00
|
|
|
#ifdef SQLITE_OMIT_TCL_VARIABLE
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "tclvar", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "tclvar", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
|
|
|
#if defined(THREADSAFE) && THREADSAFE
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "threadsafe", "1", TCL_GLOBAL_ONLY);
|
2004-10-31 05:22:47 +03:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "threadsafe", "0", TCL_GLOBAL_ONLY);
|
2004-10-31 05:22:47 +03:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2005-08-30 03:00:03 +04:00
|
|
|
#ifdef SQLITE_OMIT_TRACE
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "trace", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "trace", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_TRIGGER
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "trigger", "0", TCL_GLOBAL_ONLY);
|
2004-11-06 02:46:15 +03:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "trigger", "1", TCL_GLOBAL_ONLY);
|
2004-11-06 02:46:15 +03:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
2005-03-29 07:10:59 +04:00
|
|
|
#ifdef SQLITE_OMIT_TEMPDB
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "tempdb", "0", TCL_GLOBAL_ONLY);
|
|
|
|
#else
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "tempdb", "1", TCL_GLOBAL_ONLY);
|
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_UTF16
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "utf16", "0", TCL_GLOBAL_ONLY);
|
2004-11-12 18:53:37 +03:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "utf16", "1", TCL_GLOBAL_ONLY);
|
2004-11-12 18:53:37 +03:00
|
|
|
#endif
|
2004-11-13 18:59:14 +03:00
|
|
|
|
|
|
|
#ifdef SQLITE_OMIT_VACUUM
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "vacuum", "0", TCL_GLOBAL_ONLY);
|
2004-11-13 06:48:06 +03:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "vacuum", "1", TCL_GLOBAL_ONLY);
|
2004-11-13 06:48:06 +03:00
|
|
|
#endif
|
|
|
|
|
2004-11-13 18:59:14 +03:00
|
|
|
#ifdef SQLITE_OMIT_VIEW
|
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "view", "0", TCL_GLOBAL_ONLY);
|
2004-11-10 18:27:38 +03:00
|
|
|
#else
|
2004-11-13 18:59:14 +03:00
|
|
|
Tcl_SetVar2(interp, "sqlite_options", "view", "1", TCL_GLOBAL_ONLY);
|
2004-11-10 18:27:38 +03:00
|
|
|
#endif
|
2004-10-31 00:23:09 +04:00
|
|
|
}
|
|
|
|
|
2001-04-07 19:24:33 +04:00
|
|
|
/*
|
|
|
|
** Register commands with the TCL interpreter.
|
|
|
|
*/
|
|
|
|
int Sqlitetest1_Init(Tcl_Interp *interp){
|
2004-05-10 14:34:51 +04:00
|
|
|
extern int sqlite3_search_count;
|
|
|
|
extern int sqlite3_interrupt_count;
|
|
|
|
extern int sqlite3_open_file_count;
|
2004-11-03 19:27:01 +03:00
|
|
|
extern int sqlite3_sort_count;
|
2004-05-10 14:34:51 +04:00
|
|
|
extern int sqlite3_current_time;
|
2002-08-31 22:53:06 +04:00
|
|
|
static struct {
|
|
|
|
char *zName;
|
|
|
|
Tcl_CmdProc *xProc;
|
|
|
|
} aCmd[] = {
|
2004-05-21 02:16:29 +04:00
|
|
|
{ "sqlite3_mprintf_int", (Tcl_CmdProc*)sqlite3_mprintf_int },
|
2004-06-25 05:10:48 +04:00
|
|
|
{ "sqlite3_mprintf_int64", (Tcl_CmdProc*)sqlite3_mprintf_int64 },
|
2004-05-21 02:16:29 +04:00
|
|
|
{ "sqlite3_mprintf_str", (Tcl_CmdProc*)sqlite3_mprintf_str },
|
2004-07-18 01:56:09 +04:00
|
|
|
{ "sqlite3_mprintf_stronly", (Tcl_CmdProc*)sqlite3_mprintf_stronly},
|
2004-05-21 02:16:29 +04:00
|
|
|
{ "sqlite3_mprintf_double", (Tcl_CmdProc*)sqlite3_mprintf_double },
|
|
|
|
{ "sqlite3_mprintf_scaled", (Tcl_CmdProc*)sqlite3_mprintf_scaled },
|
2005-08-30 23:30:59 +04:00
|
|
|
{ "sqlite3_mprintf_hexdouble", (Tcl_CmdProc*)sqlite3_mprintf_hexdouble},
|
2004-05-21 02:16:29 +04:00
|
|
|
{ "sqlite3_mprintf_z_test", (Tcl_CmdProc*)test_mprintf_z },
|
|
|
|
{ "sqlite3_last_insert_rowid", (Tcl_CmdProc*)test_last_rowid },
|
|
|
|
{ "sqlite3_exec_printf", (Tcl_CmdProc*)test_exec_printf },
|
|
|
|
{ "sqlite3_get_table_printf", (Tcl_CmdProc*)test_get_table_printf },
|
|
|
|
{ "sqlite3_close", (Tcl_CmdProc*)sqlite_test_close },
|
|
|
|
{ "sqlite3_create_function", (Tcl_CmdProc*)test_create_function },
|
|
|
|
{ "sqlite3_create_aggregate", (Tcl_CmdProc*)test_create_aggregate },
|
|
|
|
{ "sqlite_register_test_function", (Tcl_CmdProc*)test_register_func },
|
|
|
|
{ "sqlite_abort", (Tcl_CmdProc*)sqlite_abort },
|
2005-01-13 05:14:23 +03:00
|
|
|
#ifdef SQLITE_MEMDEBUG
|
2004-05-21 02:16:29 +04:00
|
|
|
{ "sqlite_malloc_fail", (Tcl_CmdProc*)sqlite_malloc_fail },
|
|
|
|
{ "sqlite_malloc_stat", (Tcl_CmdProc*)sqlite_malloc_stat },
|
2001-04-11 18:28:42 +04:00
|
|
|
#endif
|
2004-07-22 19:02:25 +04:00
|
|
|
{ "sqlite_bind", (Tcl_CmdProc*)test_bind },
|
|
|
|
{ "breakpoint", (Tcl_CmdProc*)test_breakpoint },
|
|
|
|
{ "sqlite3_key", (Tcl_CmdProc*)test_key },
|
|
|
|
{ "sqlite3_rekey", (Tcl_CmdProc*)test_rekey },
|
2005-01-11 18:28:33 +03:00
|
|
|
{ "sqlite_set_magic", (Tcl_CmdProc*)sqlite_set_magic },
|
2005-01-11 19:54:14 +03:00
|
|
|
{ "sqlite3_interrupt", (Tcl_CmdProc*)test_interrupt },
|
2005-01-20 04:14:23 +03:00
|
|
|
#if 0
|
|
|
|
{ "sqlite3_sleep", (Tcl_CmdProc*)test_sleep },
|
|
|
|
#endif
|
2005-05-26 20:23:34 +04:00
|
|
|
{ "sqlite_delete_function", (Tcl_CmdProc*)delete_function },
|
|
|
|
{ "sqlite_delete_collation", (Tcl_CmdProc*)delete_collation },
|
|
|
|
{ "sqlite3_get_autocommit", (Tcl_CmdProc*)get_autocommit },
|
2005-09-07 01:40:45 +04:00
|
|
|
{ "sqlite3_stack_used", (Tcl_CmdProc*)test_stack_used },
|
2002-08-31 22:53:06 +04:00
|
|
|
};
|
2004-05-20 05:12:34 +04:00
|
|
|
static struct {
|
|
|
|
char *zName;
|
|
|
|
Tcl_ObjCmdProc *xProc;
|
2004-05-27 05:04:07 +04:00
|
|
|
void *clientData;
|
2004-05-20 05:12:34 +04:00
|
|
|
} aObjCmd[] = {
|
2006-01-03 03:33:50 +03:00
|
|
|
{ "sqlite3_connection_pointer", get_sqlite_pointer, 0 },
|
2004-06-22 16:46:53 +04:00
|
|
|
{ "sqlite3_bind_int", test_bind_int, 0 },
|
|
|
|
{ "sqlite3_bind_int64", test_bind_int64, 0 },
|
|
|
|
{ "sqlite3_bind_double", test_bind_double, 0 },
|
2004-05-27 05:04:07 +04:00
|
|
|
{ "sqlite3_bind_null", test_bind_null ,0 },
|
|
|
|
{ "sqlite3_bind_text", test_bind_text ,0 },
|
|
|
|
{ "sqlite3_bind_text16", test_bind_text16 ,0 },
|
|
|
|
{ "sqlite3_bind_blob", test_bind_blob ,0 },
|
2004-07-15 18:15:00 +04:00
|
|
|
{ "sqlite3_bind_parameter_count", test_bind_parameter_count, 0},
|
2004-08-20 20:02:39 +04:00
|
|
|
{ "sqlite3_bind_parameter_name", test_bind_parameter_name, 0},
|
2004-09-07 20:19:52 +04:00
|
|
|
{ "sqlite3_bind_parameter_index", test_bind_parameter_index, 0},
|
2005-01-20 04:14:23 +03:00
|
|
|
#if 0
|
|
|
|
{ "sqlite3_clear_bindings", test_clear_bindings, 0},
|
|
|
|
#endif
|
2004-05-27 05:04:07 +04:00
|
|
|
{ "sqlite3_errcode", test_errcode ,0 },
|
|
|
|
{ "sqlite3_errmsg", test_errmsg ,0 },
|
|
|
|
{ "sqlite3_errmsg16", test_errmsg16 ,0 },
|
|
|
|
{ "sqlite3_open", test_open ,0 },
|
|
|
|
{ "sqlite3_open16", test_open16 ,0 },
|
2004-06-30 12:20:16 +04:00
|
|
|
{ "sqlite3_complete16", test_complete16 ,0 },
|
2004-05-27 05:04:07 +04:00
|
|
|
|
|
|
|
{ "sqlite3_prepare", test_prepare ,0 },
|
|
|
|
{ "sqlite3_prepare16", test_prepare16 ,0 },
|
|
|
|
{ "sqlite3_finalize", test_finalize ,0 },
|
|
|
|
{ "sqlite3_reset", test_reset ,0 },
|
2005-01-22 06:03:54 +03:00
|
|
|
{ "sqlite3_expired", test_expired ,0 },
|
2005-04-22 06:38:37 +04:00
|
|
|
{ "sqlite3_transfer_bindings", test_transfer_bind ,0 },
|
2004-06-15 06:44:18 +04:00
|
|
|
{ "sqlite3_changes", test_changes ,0 },
|
|
|
|
{ "sqlite3_step", test_step ,0 },
|
2004-05-27 05:04:07 +04:00
|
|
|
|
2006-01-12 02:40:33 +03:00
|
|
|
{ "sqlite3_release_memory", test_release_memory, 0},
|
|
|
|
{ "sqlite3_soft_heap_limit", test_soft_heap_limit, 0},
|
|
|
|
{ "sqlite3_clear_tsd_memdebug", test_clear_tsd_memdebug, 0},
|
|
|
|
{ "sqlite3_tsd_release", test_tsd_release, 0},
|
|
|
|
{ "sqlite3_thread_cleanup", test_thread_cleanup, 0},
|
2006-01-05 18:50:06 +03:00
|
|
|
|
2004-05-27 05:04:07 +04:00
|
|
|
/* sqlite3_column_*() API */
|
|
|
|
{ "sqlite3_column_count", test_column_count ,0 },
|
|
|
|
{ "sqlite3_data_count", test_data_count ,0 },
|
|
|
|
{ "sqlite3_column_type", test_column_type ,0 },
|
2004-05-27 05:49:51 +04:00
|
|
|
{ "sqlite3_column_blob", test_column_blob ,0 },
|
2004-05-27 05:04:07 +04:00
|
|
|
{ "sqlite3_column_double", test_column_double ,0 },
|
|
|
|
{ "sqlite3_column_int64", test_column_int64 ,0 },
|
2004-06-22 16:46:53 +04:00
|
|
|
{ "sqlite3_column_text", test_stmt_utf8, sqlite3_column_text },
|
|
|
|
{ "sqlite3_column_decltype", test_stmt_utf8, sqlite3_column_decltype },
|
|
|
|
{ "sqlite3_column_name", test_stmt_utf8, sqlite3_column_name },
|
2004-11-15 00:56:29 +03:00
|
|
|
{ "sqlite3_column_int", test_stmt_int, sqlite3_column_int },
|
|
|
|
{ "sqlite3_column_bytes", test_stmt_int, sqlite3_column_bytes },
|
2006-02-10 06:06:10 +03:00
|
|
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
2006-02-10 05:27:42 +03:00
|
|
|
{ "sqlite3_column_database_name", test_stmt_utf8, sqlite3_column_database_name},
|
|
|
|
{ "sqlite3_column_table_name", test_stmt_utf8, sqlite3_column_table_name},
|
|
|
|
{ "sqlite3_column_origin_name", test_stmt_utf8, sqlite3_column_origin_name},
|
2006-02-10 06:06:10 +03:00
|
|
|
#endif
|
2006-02-10 05:27:42 +03:00
|
|
|
|
2004-11-15 00:56:29 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
|
|
{ "sqlite3_column_bytes16", test_stmt_int, sqlite3_column_bytes16 },
|
2004-06-22 16:46:53 +04:00
|
|
|
{ "sqlite3_column_text16", test_stmt_utf16, sqlite3_column_text16 },
|
|
|
|
{ "sqlite3_column_decltype16", test_stmt_utf16, sqlite3_column_decltype16},
|
|
|
|
{ "sqlite3_column_name16", test_stmt_utf16, sqlite3_column_name16 },
|
2006-02-10 06:06:10 +03:00
|
|
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
2006-02-10 05:27:42 +03:00
|
|
|
{"sqlite3_column_database_name16",
|
|
|
|
test_stmt_utf16, sqlite3_column_database_name16},
|
|
|
|
{"sqlite3_column_table_name16", test_stmt_utf16, sqlite3_column_table_name16},
|
|
|
|
{"sqlite3_column_origin_name16", test_stmt_utf16, sqlite3_column_origin_name16},
|
2006-02-10 06:06:10 +03:00
|
|
|
#endif
|
2004-11-15 00:56:29 +03:00
|
|
|
#endif
|
2005-03-21 07:04:02 +03:00
|
|
|
{ "sqlite3_global_recover", test_global_recover, 0 },
|
2004-05-27 05:04:07 +04:00
|
|
|
|
2004-06-01 18:09:28 +04:00
|
|
|
/* Functions from os.h */
|
2005-05-27 13:41:12 +04:00
|
|
|
#ifndef SQLITE_OMIT_DISKIO
|
2004-06-01 18:09:28 +04:00
|
|
|
{ "sqlite3OsOpenReadWrite",test_sqlite3OsOpenReadWrite, 0 },
|
|
|
|
{ "sqlite3OsClose", test_sqlite3OsClose, 0 },
|
|
|
|
{ "sqlite3OsLock", test_sqlite3OsLock, 0 },
|
2004-08-14 21:10:10 +04:00
|
|
|
{ "sqlite3OsTempFileName", test_sqlite3OsTempFileName, 0 },
|
2004-06-29 17:18:23 +04:00
|
|
|
|
|
|
|
/* Custom test interfaces */
|
|
|
|
{ "sqlite3OsUnlock", test_sqlite3OsUnlock, 0 },
|
2005-05-27 13:41:12 +04:00
|
|
|
#endif
|
2004-11-14 07:04:17 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
2004-06-29 17:18:23 +04:00
|
|
|
{ "add_test_collate", test_collate, 0 },
|
|
|
|
{ "add_test_collate_needed", test_collate_needed, 0 },
|
|
|
|
{ "add_test_function", test_function, 0 },
|
2005-12-20 12:19:37 +03:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_MEMDEBUG
|
|
|
|
{ "sqlite_malloc_outstanding", sqlite_malloc_outstanding, 0},
|
2004-11-14 07:04:17 +03:00
|
|
|
#endif
|
2004-06-29 17:18:23 +04:00
|
|
|
{ "sqlite3_test_errstr", test_errstr, 0 },
|
2004-08-20 22:34:20 +04:00
|
|
|
{ "tcl_variable_type", tcl_variable_type, 0 },
|
2005-12-30 19:28:01 +03:00
|
|
|
#ifndef SQLITE_OMIT_SHARED_CACHE
|
2006-01-12 00:41:20 +03:00
|
|
|
{ "sqlite3_enable_shared_cache", test_enable_shared, 0 },
|
2005-12-30 19:28:01 +03:00
|
|
|
#endif
|
2006-01-24 13:58:21 +03:00
|
|
|
{ "sqlite3_libversion_number", test_libversion_number, 0 },
|
2006-02-09 16:43:28 +03:00
|
|
|
#ifdef SQLITE_ENABLE_COLUMN_METADATA
|
|
|
|
{ "sqlite3_table_column_metadata", test_table_column_metadata, 0 },
|
|
|
|
#endif
|
2004-05-20 05:12:34 +04:00
|
|
|
};
|
2005-01-20 02:24:50 +03:00
|
|
|
static int bitmask_size = sizeof(Bitmask)*8;
|
2002-08-31 22:53:06 +04:00
|
|
|
int i;
|
2004-06-07 20:27:46 +04:00
|
|
|
extern int sqlite3_os_trace;
|
2005-07-24 02:59:55 +04:00
|
|
|
extern int sqlite3_where_trace;
|
2005-03-10 17:11:12 +03:00
|
|
|
extern int sqlite3_sync_count, sqlite3_fullsync_count;
|
2005-06-07 06:12:30 +04:00
|
|
|
extern int sqlite3_opentemp_count;
|
2005-07-20 18:31:53 +04:00
|
|
|
extern int sqlite3_memUsed;
|
2005-12-09 17:25:08 +03:00
|
|
|
extern int sqlite3_malloc_id;
|
2005-07-20 18:31:53 +04:00
|
|
|
extern int sqlite3_memMax;
|
2005-08-14 05:20:37 +04:00
|
|
|
extern int sqlite3_like_count;
|
2006-01-12 02:40:33 +03:00
|
|
|
extern int sqlite3_tsd_count;
|
2006-01-15 03:13:15 +03:00
|
|
|
#if OS_UNIX && defined(SQLITE_TEST) && defined(THREADSAFE) && THREADSAFE
|
|
|
|
extern int threadsOverrideEachOthersLocks;
|
|
|
|
#endif
|
2005-09-05 23:08:29 +04:00
|
|
|
#if OS_WIN
|
|
|
|
extern int sqlite3_os_type;
|
|
|
|
#endif
|
2005-08-19 04:14:42 +04:00
|
|
|
#ifdef SQLITE_DEBUG
|
|
|
|
extern int sqlite3_vdbe_addop_trace;
|
2005-09-19 17:15:23 +04:00
|
|
|
#endif
|
|
|
|
#ifdef SQLITE_TEST
|
|
|
|
extern char sqlite3_query_plan[];
|
2005-07-16 03:24:23 +04:00
|
|
|
static char *query_plan = sqlite3_query_plan;
|
2005-09-19 16:37:27 +04:00
|
|
|
#endif
|
2002-08-31 22:53:06 +04:00
|
|
|
|
|
|
|
for(i=0; i<sizeof(aCmd)/sizeof(aCmd[0]); i++){
|
|
|
|
Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, 0, 0);
|
|
|
|
}
|
2004-05-20 05:12:34 +04:00
|
|
|
for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
|
2004-05-27 13:28:41 +04:00
|
|
|
Tcl_CreateObjCommand(interp, aObjCmd[i].zName,
|
|
|
|
aObjCmd[i].xProc, aObjCmd[i].clientData, 0);
|
2004-05-20 05:12:34 +04:00
|
|
|
}
|
2004-05-11 10:17:21 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_search_count",
|
2004-05-10 14:34:51 +04:00
|
|
|
(char*)&sqlite3_search_count, TCL_LINK_INT);
|
2004-11-03 19:27:01 +03:00
|
|
|
Tcl_LinkVar(interp, "sqlite_sort_count",
|
|
|
|
(char*)&sqlite3_sort_count, TCL_LINK_INT);
|
2005-08-14 05:20:37 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_like_count",
|
|
|
|
(char*)&sqlite3_like_count, TCL_LINK_INT);
|
2004-05-11 10:17:21 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_interrupt_count",
|
2004-05-10 14:34:51 +04:00
|
|
|
(char*)&sqlite3_interrupt_count, TCL_LINK_INT);
|
2004-05-11 10:17:21 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_open_file_count",
|
2004-05-10 14:34:51 +04:00
|
|
|
(char*)&sqlite3_open_file_count, TCL_LINK_INT);
|
2004-05-11 10:17:21 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_current_time",
|
2004-05-10 14:34:51 +04:00
|
|
|
(char*)&sqlite3_current_time, TCL_LINK_INT);
|
2004-06-07 20:27:46 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_os_trace",
|
|
|
|
(char*)&sqlite3_os_trace, TCL_LINK_INT);
|
2006-01-12 02:40:33 +03:00
|
|
|
Tcl_LinkVar(interp, "sqlite3_tsd_count",
|
|
|
|
(char*)&sqlite3_tsd_count, TCL_LINK_INT);
|
2006-01-15 03:13:15 +03:00
|
|
|
#if OS_UNIX && defined(SQLITE_TEST) && defined(THREADSAFE) && THREADSAFE
|
|
|
|
Tcl_LinkVar(interp, "threadsOverrideEachOthersLocks",
|
|
|
|
(char*)&threadsOverrideEachOthersLocks, TCL_LINK_INT);
|
|
|
|
#endif
|
2005-12-14 23:11:30 +03:00
|
|
|
#ifndef SQLITE_OMIT_UTF16
|
|
|
|
Tcl_LinkVar(interp, "sqlite_last_needed_collation",
|
|
|
|
(char*)&pzNeededCollation, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
|
|
|
|
#endif
|
2005-12-09 17:39:04 +03:00
|
|
|
#ifdef SQLITE_MEMDEBUG
|
2005-12-09 17:25:08 +03:00
|
|
|
Tcl_LinkVar(interp, "sqlite_malloc_id",
|
|
|
|
(char*)&sqlite3_malloc_id, TCL_LINK_STRING);
|
2005-12-09 17:39:04 +03:00
|
|
|
#endif
|
2005-09-05 23:08:29 +04:00
|
|
|
#if OS_WIN
|
|
|
|
Tcl_LinkVar(interp, "sqlite_os_type",
|
|
|
|
(char*)&sqlite3_os_type, TCL_LINK_INT);
|
|
|
|
#endif
|
2005-09-19 17:15:23 +04:00
|
|
|
#ifdef SQLITE_TEST
|
|
|
|
Tcl_LinkVar(interp, "sqlite_query_plan",
|
|
|
|
(char*)&query_plan, TCL_LINK_STRING|TCL_LINK_READ_ONLY);
|
|
|
|
#endif
|
2005-08-19 04:14:42 +04:00
|
|
|
#ifdef SQLITE_DEBUG
|
|
|
|
Tcl_LinkVar(interp, "sqlite_addop_trace",
|
|
|
|
(char*)&sqlite3_vdbe_addop_trace, TCL_LINK_INT);
|
2005-09-19 16:37:27 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_where_trace",
|
|
|
|
(char*)&sqlite3_where_trace, TCL_LINK_INT);
|
2005-08-19 04:14:42 +04:00
|
|
|
#endif
|
2005-08-03 01:42:16 +04:00
|
|
|
#ifdef SQLITE_MEMDEBUG
|
2005-07-20 18:31:53 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_memused",
|
|
|
|
(char*)&sqlite3_memUsed, TCL_LINK_INT | TCL_LINK_READ_ONLY);
|
|
|
|
Tcl_LinkVar(interp, "sqlite_memmax",
|
|
|
|
(char*)&sqlite3_memMax, TCL_LINK_INT | TCL_LINK_READ_ONLY);
|
2005-08-03 01:42:16 +04:00
|
|
|
#endif
|
2005-06-07 11:58:48 +04:00
|
|
|
#ifndef SQLITE_OMIT_DISKIO
|
2005-06-07 06:12:30 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_opentemp_count",
|
|
|
|
(char*)&sqlite3_opentemp_count, TCL_LINK_INT);
|
2005-06-07 11:58:48 +04:00
|
|
|
#endif
|
2003-09-07 02:18:07 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_static_bind_value",
|
|
|
|
(char*)&sqlite_static_bind_value, TCL_LINK_STRING);
|
2004-08-14 21:10:10 +04:00
|
|
|
Tcl_LinkVar(interp, "sqlite_temp_directory",
|
2004-08-30 03:42:13 +04:00
|
|
|
(char*)&sqlite3_temp_directory, TCL_LINK_STRING);
|
2005-01-20 02:24:50 +03:00
|
|
|
Tcl_LinkVar(interp, "bitmask_size",
|
|
|
|
(char*)&bitmask_size, TCL_LINK_INT|TCL_LINK_READ_ONLY);
|
2005-03-11 07:41:39 +03:00
|
|
|
#if OS_UNIX
|
2005-03-10 17:11:12 +03:00
|
|
|
Tcl_LinkVar(interp, "sqlite_sync_count",
|
|
|
|
(char*)&sqlite3_sync_count, TCL_LINK_INT);
|
|
|
|
Tcl_LinkVar(interp, "sqlite_fullsync_count",
|
|
|
|
(char*)&sqlite3_fullsync_count, TCL_LINK_INT);
|
2005-03-11 07:41:39 +03:00
|
|
|
#endif /* OS_UNIX */
|
2004-10-31 00:23:09 +04:00
|
|
|
set_options(interp);
|
2006-01-11 17:09:31 +03:00
|
|
|
|
2006-01-12 02:40:33 +03:00
|
|
|
{
|
2006-01-20 13:55:05 +03:00
|
|
|
#ifdef SQLITE_DEBUG
|
2006-01-12 02:40:33 +03:00
|
|
|
extern int sqlite3_shared_cache_report(void *, Tcl_Interp *,
|
|
|
|
int, Tcl_Obj *CONST[]);
|
|
|
|
Tcl_CreateObjCommand(interp, "sqlite_shared_cache_report",
|
|
|
|
sqlite3_shared_cache_report, 0, 0);
|
2006-01-20 13:55:05 +03:00
|
|
|
#endif
|
2006-01-12 02:40:33 +03:00
|
|
|
}
|
2001-04-07 19:24:33 +04:00
|
|
|
return TCL_OK;
|
|
|
|
}
|