-C Fix\sfor\sdatbase\sname\sbeing\signored\swith\sthe\s-batch\soption\sin\sthe\sCLI.\s\sTicket\s[aeff892c57].
-D 2009-11-10T17:07:31
+-----BEGIN PGP SIGNED MESSAGE-----
+Hash: SHA1
+
+C Initial\simplementation\sand\stest\scases\sfor\sthe\s"intarray"\svirtual\stable.
+D 2009-11-10T17:24:37
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
-F Makefile.in b24a5d5f12bd6035d120c15f5e78e5d60ee4dd28
+F Makefile.in 53f3dfa49f28ab5b80cb083fb7c9051e596bcfa1
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F Makefile.vxworks 10010ddbf52e2503c7c49c7c0b7c7a096f8638a6
F README cd04a36fbc7ea56932a4052d7d0b7f09f27c33d6
F ext/rtree/viewrtree.tcl eea6224b3553599ae665b239bd827e182b466024
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
-F main.mk d588eab5d51b0bfe924a1cccdfdd2cbb4cbe40b4
+F main.mk 0320def78eed84285c273f3d84dd20d8f26a0139
F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
F src/sqliteLimit.h 3afab2291762b5d09ae20c18feb8e9fa935a60a6
F src/status.c e651be6b30d397d86384c6867bc016e4913bcac7
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
-F src/tclsqlite.c 21432a361808b6c3d405710cdd22fa1b16f7b84f
+F src/tclsqlite.c 223746524139e1e02b7a2b61c05b5a690f91a0ff
F src/test1.c db4d8fd2849ab9aca0f27fd3773b8d68d078cf86
F src/test2.c b6b43413d495addd039a88b87d65c839f86b18cb
F src/test3.c f17eeaf8114205844d76f4e69bab27ea341087af
F src/test_func.c 1c94388a23d4a9e7cd62ec79d612d1bae2451fa2
F src/test_hexio.c 1c0f4238c6fb36c890ce7c07d9c8e1cecedad9ad
F src/test_init.c 5d624ffd0409d424cf9adbfe1f056b200270077c
+F src/test_intarray.c 52862866211f2f8813471e6ac24f17afe1ddf2b7
+F src/test_intarray.h 489edb9068bb926583445cb02589344961054207
F src/test_journal.c adc0ce3840ed19b49feb1d583b2212f560ef7866
F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e
F src/test_malloc.c f777d15df756bea0e98271932464ac5d882e66fe
F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30
F test/insert4.test 6e382eaf7295a4463e6f29ea20fcd8e63d097eeb
F test/insert5.test 1f93cbe9742110119133d7e8e3ccfe6d7c249766
+F test/intarray.test 829a72b2bf7329c969703788e4355f1d9870116a
F test/interrupt.test 42e7cf98646fd9cb4a3b131a93ed3c50b9e149f1
F test/intpkey.test 537669fd535f62632ca64828e435b9e54e8d677f
F test/io.test e7bd58edb4e2131a8ecd81b4b00af3ee5c79d464
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P f6c045f649036958078cb15cd9d5453680c82b0c
-R 1f800c450b12aea8b2bafa846301d578
-U shaneh
-Z 90330abd89db4a61b87a266140e2ee99
+P 8097c64acfc74c913bc6d7d631bc1423c90df93f
+R 8b070e35abc0273e79586bc251b3aec5
+U drh
+Z 28d3772e2493768aa7f3896b180a9b39
+-----BEGIN PGP SIGNATURE-----
+Version: GnuPG v1.4.6 (GNU/Linux)
+
+iD8DBQFK+aHXoxKgR168RlERAm2qAJ958rJsRjQOpNvspuJfXRgPM0fPugCghSop
+UuOC37hwMLT7++0J6JCbgaM=
+=j9AA
+-----END PGP SIGNATURE-----
--- /dev/null
+/*
+** 2009 November 10
+**
+** The author disclaims copyright to this source code. In place of
+** a legal notice, here is a blessing:
+**
+** 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.
+**
+*************************************************************************
+**
+** This file implements a read-only VIRTUAL TABLE that contains the
+** content of a C-language array of integer values. See the corresponding
+** header file for full details.
+*/
+#include "test_intarray.h"
+#include <string.h>
+#include <assert.h>
+
+
+/*
+** Definition of the sqlite3_intarray object.
+**
+** The internal representation of an intarray object is subject
+** to change, is not externally visible, and should be used by
+** the implementation of intarray only. This object is opaque
+** to users.
+*/
+struct sqlite3_intarray {
+ int n; /* Number of elements in the array */
+ sqlite3_int64 *a; /* Contents of the array */
+ void (*xFree)(void*); /* Function used to free a[] */
+};
+
+/* Objects used internally by the virtual table implementation */
+typedef struct intarray_vtab intarray_vtab;
+typedef struct intarray_cursor intarray_cursor;
+
+/* A intarray table object */
+struct intarray_vtab {
+ sqlite3_vtab base; /* Base class */
+ sqlite3_intarray *pContent; /* Content of the integer array */
+};
+
+/* A intarray cursor object */
+struct intarray_cursor {
+ sqlite3_vtab_cursor base; /* Base class */
+ int i; /* Current cursor position */
+};
+
+/*
+** None of this works unless we have virtual tables.
+*/
+#ifndef SQLITE_OMIT_VIRTUALTABLE
+
+/*
+** Free an sqlite3_intarray object
+*/
+static void intarrayFree(sqlite3_intarray *p){
+ if( p->xFree ){
+ p->xFree(p->a);
+ }
+ sqlite3_free(p);
+}
+
+/*
+** Table destructor for the intarray module.
+*/
+static int intarrayDestroy(sqlite3_vtab *p){
+ intarray_vtab *pVtab = (intarray_vtab*)p;
+ sqlite3_free(pVtab);
+ return 0;
+}
+
+/*
+** Table constructor for the intarray module.
+*/
+static int intarrayCreate(
+ sqlite3 *db, /* Database where module is created */
+ void *pAux, /* clientdata for the module */
+ int argc, /* Number of arguments */
+ const char *const*argv, /* Value for all arguments */
+ sqlite3_vtab **ppVtab, /* Write the new virtual table object here */
+ char **pzErr /* Put error message text here */
+){
+ int rc = SQLITE_NOMEM;
+ intarray_vtab *pVtab = sqlite3_malloc(sizeof(intarray_vtab));
+
+ if( pVtab ){
+ memset(pVtab, 0, sizeof(intarray_vtab));
+ pVtab->pContent = (sqlite3_intarray*)pAux;
+ rc = sqlite3_declare_vtab(db, "CREATE TABLE x(value INTEGER PRIMARY KEY)");
+ }
+ *ppVtab = (sqlite3_vtab *)pVtab;
+ return rc;
+}
+
+/*
+** Open a new cursor on the intarray table.
+*/
+static int intarrayOpen(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
+ int rc = SQLITE_NOMEM;
+ intarray_cursor *pCur;
+ pCur = sqlite3_malloc(sizeof(intarray_cursor));
+ if( pCur ){
+ memset(pCur, 0, sizeof(intarray_cursor));
+ *ppCursor = (sqlite3_vtab_cursor *)pCur;
+ rc = SQLITE_OK;
+ }
+ return rc;
+}
+
+/*
+** Close a intarray table cursor.
+*/
+static int intarrayClose(sqlite3_vtab_cursor *cur){
+ intarray_cursor *pCur = (intarray_cursor *)cur;
+ sqlite3_free(pCur);
+ return SQLITE_OK;
+}
+
+/*
+** Retrieve a column of data.
+*/
+static int intarrayColumn(sqlite3_vtab_cursor *cur, sqlite3_context *ctx, int i){
+ intarray_cursor *pCur = (intarray_cursor*)cur;
+ intarray_vtab *pVtab = (intarray_vtab*)cur->pVtab;
+ if( pCur->i>=0 && pCur->i<pVtab->pContent->n ){
+ sqlite3_result_int64(ctx, pVtab->pContent->a[pCur->i]);
+ }
+ return SQLITE_OK;
+}
+
+/*
+** Retrieve the current rowid.
+*/
+static int intarrayRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
+ intarray_cursor *pCur = (intarray_cursor *)cur;
+ *pRowid = pCur->i;
+ return SQLITE_OK;
+}
+
+static int intarrayEof(sqlite3_vtab_cursor *cur){
+ intarray_cursor *pCur = (intarray_cursor *)cur;
+ intarray_vtab *pVtab = (intarray_vtab *)cur->pVtab;
+ return pCur->i>=pVtab->pContent->n;
+}
+
+/*
+** Advance the cursor to the next row.
+*/
+static int intarrayNext(sqlite3_vtab_cursor *cur){
+ intarray_cursor *pCur = (intarray_cursor *)cur;
+ pCur->i++;
+ return SQLITE_OK;
+}
+
+/*
+** Reset a intarray table cursor.
+*/
+static int intarrayFilter(
+ sqlite3_vtab_cursor *pVtabCursor,
+ int idxNum, const char *idxStr,
+ int argc, sqlite3_value **argv
+){
+ intarray_cursor *pCur = (intarray_cursor *)pVtabCursor;
+ pCur->i = 0;
+ return SQLITE_OK;
+}
+
+/*
+** Analyse the WHERE condition.
+*/
+static int intarrayBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
+ return SQLITE_OK;
+}
+
+/*
+** A virtual table module that merely echos method calls into TCL
+** variables.
+*/
+static sqlite3_module intarrayModule = {
+ 0, /* iVersion */
+ intarrayCreate, /* xCreate - create a new virtual table */
+ intarrayCreate, /* xConnect - connect to an existing vtab */
+ intarrayBestIndex, /* xBestIndex - find the best query index */
+ intarrayDestroy, /* xDisconnect - disconnect a vtab */
+ intarrayDestroy, /* xDestroy - destroy a vtab */
+ intarrayOpen, /* xOpen - open a cursor */
+ intarrayClose, /* xClose - close a cursor */
+ intarrayFilter, /* xFilter - configure scan constraints */
+ intarrayNext, /* xNext - advance a cursor */
+ intarrayEof, /* xEof */
+ intarrayColumn, /* xColumn - read data */
+ intarrayRowid, /* xRowid - read data */
+ 0, /* xUpdate */
+ 0, /* xBegin */
+ 0, /* xSync */
+ 0, /* xCommit */
+ 0, /* xRollback */
+ 0, /* xFindMethod */
+ 0, /* xRename */
+};
+
+#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */
+
+/*
+** Invoke this routine to create a specific instance of an intarray object.
+** The new intarray object is returned by the 3rd parameter.
+**
+** Each intarray object corresponds to a virtual table in the TEMP table
+** with a name of zName.
+**
+** Destroy the intarray object by dropping the virtual table. If not done
+** explicitly by the application, the virtual table will be dropped implicitly
+** by the system when the database connection is closed.
+*/
+int sqlite3_intarray_create(
+ sqlite3 *db,
+ const char *zName,
+ sqlite3_intarray **ppReturn
+){
+ int rc;
+ sqlite3_intarray *p;
+
+ *ppReturn = p = sqlite3_malloc( sizeof(*p) );
+ if( p==0 ){
+ return SQLITE_NOMEM;
+ }
+ memset(p, 0, sizeof(*p));
+ rc = sqlite3_create_module_v2(db, zName, &intarrayModule, p,
+ (void(*)(void*))intarrayFree);
+ if( rc==SQLITE_OK ){
+ char *zSql;
+ zSql = sqlite3_mprintf("CREATE VIRTUAL TABLE temp.%Q USING %Q",
+ zName, zName);
+ rc = sqlite3_exec(db, zSql, 0, 0, 0);
+ sqlite3_free(zSql);
+ }
+ return rc;
+}
+
+/*
+** Bind a new array array of integers to a specific intarray object.
+**
+** The array of integers bound must be unchanged for the duration of
+** any query against the corresponding virtual table. If the integer
+** array does change or is deallocated undefined behavior will result.
+*/
+int sqlite3_intarray_bind(
+ sqlite3_intarray *pIntArray, /* The intarray object to bind to */
+ int nElements, /* Number of elements in the intarray */
+ sqlite3_int64 *aElements, /* Content of the intarray */
+ void (*xFree)(void*) /* How to dispose of the intarray when done */
+){
+ if( pIntArray->xFree ){
+ pIntArray->xFree(pIntArray->a);
+ }
+ pIntArray->n = nElements;
+ pIntArray->a = aElements;
+ pIntArray->xFree = xFree;
+ return SQLITE_OK;
+}
+
+
+/*****************************************************************************
+** Everything below is interface for testing this module.
+*/
+#ifdef SQLITE_TEST
+#include <tcl.h>
+
+/*
+** Routines to encode and decode pointers
+*/
+extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
+extern int sqlite3TestTextToPtr(const char*);
+extern int sqlite3TestMakePointerStr(Tcl_Interp*, char *zPtr, void*);
+extern const char *sqlite3TestErrorName(int);
+
+/*
+** sqlite3_intarray_create DB NAME
+**
+** Invoke the sqlite3_intarray_create interface. A string that becomes
+** the first parameter to sqlite3_intarray_bind.
+*/
+static int test_intarray_create(
+ ClientData clientData, /* Not used */
+ 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 *zName;
+ sqlite3_intarray *pArray;
+ int rc;
+ char zPtr[100];
+
+ if( objc!=3 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "DB");
+ return TCL_ERROR;
+ }
+ if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
+ zName = Tcl_GetString(objv[2]);
+ rc = sqlite3_intarray_create(db, zName, &pArray);
+ if( rc!=SQLITE_OK ){
+ assert( pArray==0 );
+ Tcl_AppendResult(interp, sqlite3TestErrorName(rc), (char*)0);
+ return TCL_ERROR;
+ }
+ sqlite3TestMakePointerStr(interp, zPtr, pArray);
+ Tcl_AppendResult(interp, zPtr, (char*)0);
+ return TCL_OK;
+}
+
+/*
+** sqlite3_intarray_bind INTARRAY ?VALUE ...?
+**
+** Invoke the sqlite3_intarray_bind interface on the given array of integers.
+*/
+static int test_intarray_bind(
+ ClientData clientData, /* Not used */
+ Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
+ int objc, /* Number of arguments */
+ Tcl_Obj *CONST objv[] /* Command arguments */
+){
+ sqlite3_intarray *pArray;
+ int rc;
+ int i, n;
+ sqlite3_int64 *a;
+
+ if( objc<2 ){
+ Tcl_WrongNumArgs(interp, 1, objv, "INTARRAY");
+ return TCL_ERROR;
+ }
+ pArray = (sqlite3_intarray*)sqlite3TestTextToPtr(Tcl_GetString(objv[1]));
+ n = objc - 2;
+ a = sqlite3_malloc( sizeof(a[0])*n );
+ if( a==0 ){
+ Tcl_AppendResult(interp, "SQLITE_NOMEM", (char*)0);
+ return TCL_ERROR;
+ }
+ for(i=0; i<n; i++){
+ a[i] = 0;
+ Tcl_GetWideIntFromObj(0, objv[i+2], &a[i]);
+ }
+ rc = sqlite3_intarray_bind(pArray, n, a, sqlite3_free);
+ if( rc!=SQLITE_OK ){
+ Tcl_AppendResult(interp, sqlite3TestErrorName(rc), (char*)0);
+ return TCL_ERROR;
+ }
+ return TCL_OK;
+}
+
+/*
+** Register commands with the TCL interpreter.
+*/
+int Sqlitetestintarray_Init(Tcl_Interp *interp){
+ static struct {
+ char *zName;
+ Tcl_ObjCmdProc *xProc;
+ void *clientData;
+ } aObjCmd[] = {
+ { "sqlite3_intarray_create", test_intarray_create, 0 },
+ { "sqlite3_intarray_bind", test_intarray_bind, 0 },
+ };
+ int i;
+ for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
+ Tcl_CreateObjCommand(interp, aObjCmd[i].zName,
+ aObjCmd[i].xProc, aObjCmd[i].clientData, 0);
+ }
+ return TCL_OK;
+}
+
+#endif /* SQLITE_TEST */
--- /dev/null
+/*
+** 2009 November 10
+**
+** The author disclaims copyright to this source code. In place of
+** a legal notice, here is a blessing:
+**
+** 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.
+**
+*************************************************************************
+**
+** This is the C-language interface definition for the "intarray" or
+** integer array virtual table for SQLite.
+**
+** The intarray virtual table is designed to facilitate using an
+** array of integers as the right-hand side of an IN operator. So
+** instead of doing a prepared statement like this:
+**
+** SELECT * FROM table WHERE x IN (?,?,?,...,?);
+**
+** And then binding indivdual integers to each of ? slots, a C-language
+** application can create an intarray object (named "ex1" in the following
+** example), prepare a statement like this:
+**
+** SELECT * FROM table WHERE x IN ex1;
+**
+** Then bind an ordinary C/C++ array of integer values to the ex1 object
+** to run the statement.
+**
+** USAGE:
+**
+** One or more intarray objects can be created as follows:
+**
+** sqlite3_intarray *p1, *p2, *p3;
+** sqlite3_intarray_create(db, "ex1", &p1);
+** sqlite3_intarray_create(db, "ex2", &p2);
+** sqlite3_intarray_create(db, "ex3", &p3);
+**
+** Each call to sqlite3_intarray_create() generates a new virtual table
+** module and a singleton of that virtual table module in the TEMP
+** database. Both the module and the virtual table instance use the
+** name given by the second parameter. The virtual tables can then be
+** used in prepared statements:
+**
+** SELECT * FROM t1, t2, t3
+** WHERE t1.x IN ex1
+** AND t2.y IN ex2
+** AND t3.z IN ex3;
+**
+** Each integer array is initially empty. New arrays can be bound to
+** an integer array as follows:
+**
+** sqlite3_int64 a1[] = { 1, 2, 3, 4 };
+** sqlite3_int64 a2[] = { 5, 6, 7, 8, 9, 10, 11 };
+** sqlite3_int64 *a3 = sqlite3_malloc( 100*sizeof(sqlite3_int64) );
+** // Fill in content of a3[]
+** sqlite3_intarray_bind(p1, 4, a1, 0);
+** sqlite3_intarray_bind(p2, 7, a2, 0);
+** sqlite3_intarray_bind(p3, 100, a3, sqlite3_free);
+**
+** A single intarray object can be rebound multiple times. But do not
+** attempt to change the bindings of an intarray while it is in the middle
+** of a query.
+**
+** The array that holds the integers is automatically freed by the function
+** in the fourth parameter to sqlite3_intarray_bind() when the array is no
+** longer needed. The application must not change the intarray values
+** while an intarray is in the middle of a query.
+**
+** The intarray object is automatically destroyed when its corresponding
+** virtual table is dropped. Since the virtual tables are created in the
+** TEMP database, they are automatically dropped when the database connection
+** closes so the application does not normally need to take any special
+** action to free the intarray objects.
+*/
+#include "sqlite3.h"
+
+/*
+** An sqlite3_intarray is an abstract type to stores an instance of
+** an integer array.
+*/
+typedef struct sqlite3_intarray sqlite3_intarray;
+
+/*
+** Invoke this routine to create a specific instance of an intarray object.
+** The new intarray object is returned by the 3rd parameter.
+**
+** Each intarray object corresponds to a virtual table in the TEMP table
+** with a name of zName.
+**
+** Destroy the intarray object by dropping the virtual table. If not done
+** explicitly by the application, the virtual table will be dropped implicitly
+** by the system when the database connection is closed.
+*/
+int sqlite3_intarray_create(
+ sqlite3 *db,
+ const char *zName,
+ sqlite3_intarray **ppReturn
+);
+
+/*
+** Bind a new array array of integers to a specific intarray object.
+**
+** The array of integers bound must be unchanged for the duration of
+** any query against the corresponding virtual table. If the integer
+** array does change or is deallocated undefined behavior will result.
+*/
+int sqlite3_intarray_bind(
+ sqlite3_intarray *pIntArray, /* The intarray object to bind to */
+ int nElements, /* Number of elements in the intarray */
+ sqlite3_int64 *aElements, /* Content of the intarray */
+ void (*xFree)(void*) /* How to dispose of the intarray when done */
+);