Change the name of the intarray() extension to carray() and give it an
optional third parameter that specifies the datatype as one of 'int32', 'int64', 'double', or 'char*'. 'int32' is the default. FossilOrigin-Name: a204ba99db34b356acb259189158a32d2df25da0
This commit is contained in:
parent
ba637157ca
commit
2e3f87ae84
@ -416,7 +416,7 @@ TESTSRC = \
|
||||
#
|
||||
TESTSRC += \
|
||||
$(TOP)/ext/misc/amatch.c \
|
||||
$(TOP)/ext/misc/array.c \
|
||||
$(TOP)/ext/misc/carray.c \
|
||||
$(TOP)/ext/misc/closure.c \
|
||||
$(TOP)/ext/misc/csv.c \
|
||||
$(TOP)/ext/misc/eval.c \
|
||||
|
@ -1292,6 +1292,7 @@ TESTSRC = \
|
||||
#
|
||||
TESTEXT = \
|
||||
$(TOP)\ext\misc\amatch.c \
|
||||
$(TOP)\ext\misc\carray.c \
|
||||
$(TOP)\ext\misc\closure.c \
|
||||
$(TOP)\ext\misc\csv.c \
|
||||
$(TOP)\ext\misc\eval.c \
|
||||
|
293
ext/misc/array.c
293
ext/misc/array.c
@ -1,293 +0,0 @@
|
||||
/*
|
||||
** 2016-06-29
|
||||
**
|
||||
** 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 demonstrates how to create a table-valued-function that
|
||||
** returns the values in a C-language array.
|
||||
** Examples:
|
||||
**
|
||||
** SELECT * FROM intarray($ptr,5)
|
||||
**
|
||||
** The query above returns 5 integers contained in a C-language array
|
||||
** at the address $ptr. $ptr is a pointer to the array of integers that
|
||||
** has been cast to an integer.
|
||||
**
|
||||
** HOW IT WORKS
|
||||
**
|
||||
** The intarray "function" is really a virtual table with the
|
||||
** following schema:
|
||||
**
|
||||
** CREATE TABLE intarray(
|
||||
** value,
|
||||
** pointer HIDDEN,
|
||||
** count HIDDEN
|
||||
** );
|
||||
*/
|
||||
#include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
|
||||
|
||||
/* intarray_cursor is a subclass of sqlite3_vtab_cursor which will
|
||||
** serve as the underlying representation of a cursor that scans
|
||||
** over rows of the result
|
||||
*/
|
||||
typedef struct intarray_cursor intarray_cursor;
|
||||
struct intarray_cursor {
|
||||
sqlite3_vtab_cursor base; /* Base class - must be first */
|
||||
int isDesc; /* True to count down rather than up */
|
||||
sqlite3_int64 iRowid; /* The rowid */
|
||||
sqlite3_int64 iPtr; /* Pointer to array of integers */
|
||||
sqlite3_int64 iCnt; /* Number of integers in the array */
|
||||
};
|
||||
|
||||
/*
|
||||
** The intarrayConnect() method is invoked to create a new
|
||||
** intarray_vtab that describes the intarray virtual table.
|
||||
**
|
||||
** Think of this routine as the constructor for intarray_vtab objects.
|
||||
**
|
||||
** All this routine needs to do is:
|
||||
**
|
||||
** (1) Allocate the intarray_vtab object and initialize all fields.
|
||||
**
|
||||
** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
|
||||
** result set of queries against intarray will look like.
|
||||
*/
|
||||
static int intarrayConnect(
|
||||
sqlite3 *db,
|
||||
void *pAux,
|
||||
int argc, const char *const*argv,
|
||||
sqlite3_vtab **ppVtab,
|
||||
char **pzErr
|
||||
){
|
||||
sqlite3_vtab *pNew;
|
||||
int rc;
|
||||
|
||||
/* Column numbers */
|
||||
#define INTARRAY_COLUMN_VALUE 0
|
||||
#define INTARRAY_COLUMN_POINTER 1
|
||||
#define INTARRAY_COLUMN_COUNT 2
|
||||
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
"CREATE TABLE x(value,pointer hidden,count hidden)");
|
||||
if( rc==SQLITE_OK ){
|
||||
pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
|
||||
if( pNew==0 ) return SQLITE_NOMEM;
|
||||
memset(pNew, 0, sizeof(*pNew));
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This method is the destructor for intarray_cursor objects.
|
||||
*/
|
||||
static int intarrayDisconnect(sqlite3_vtab *pVtab){
|
||||
sqlite3_free(pVtab);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Constructor for a new intarray_cursor object.
|
||||
*/
|
||||
static int intarrayOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
|
||||
intarray_cursor *pCur;
|
||||
pCur = sqlite3_malloc( sizeof(*pCur) );
|
||||
if( pCur==0 ) return SQLITE_NOMEM;
|
||||
memset(pCur, 0, sizeof(*pCur));
|
||||
*ppCursor = &pCur->base;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Destructor for a intarray_cursor.
|
||||
*/
|
||||
static int intarrayClose(sqlite3_vtab_cursor *cur){
|
||||
sqlite3_free(cur);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Advance a intarray_cursor to its next row of output.
|
||||
*/
|
||||
static int intarrayNext(sqlite3_vtab_cursor *cur){
|
||||
intarray_cursor *pCur = (intarray_cursor*)cur;
|
||||
pCur->iRowid++;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return values of columns for the row at which the intarray_cursor
|
||||
** is currently pointing.
|
||||
*/
|
||||
static int intarrayColumn(
|
||||
sqlite3_vtab_cursor *cur, /* The cursor */
|
||||
sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
|
||||
int i /* Which column to return */
|
||||
){
|
||||
intarray_cursor *pCur = (intarray_cursor*)cur;
|
||||
sqlite3_int64 x = 0;
|
||||
switch( i ){
|
||||
case INTARRAY_COLUMN_POINTER: x = pCur->iPtr; break;
|
||||
case INTARRAY_COLUMN_COUNT: x = pCur->iCnt; break;
|
||||
default: {
|
||||
int *p = (int*)pCur->iPtr;
|
||||
x = (int)p[pCur->iRowid-1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
sqlite3_result_int64(ctx, x);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the rowid for the current row. In this implementation, the
|
||||
** rowid is the same as the output value.
|
||||
*/
|
||||
static int intarrayRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
||||
intarray_cursor *pCur = (intarray_cursor*)cur;
|
||||
*pRowid = pCur->iRowid;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if the cursor has been moved off of the last
|
||||
** row of output.
|
||||
*/
|
||||
static int intarrayEof(sqlite3_vtab_cursor *cur){
|
||||
intarray_cursor *pCur = (intarray_cursor*)cur;
|
||||
return pCur->iRowid>pCur->iCnt;
|
||||
}
|
||||
|
||||
/*
|
||||
** This method is called to "rewind" the intarray_cursor object back
|
||||
** to the first row of output.
|
||||
*/
|
||||
static int intarrayFilter(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
intarray_cursor *pCur = (intarray_cursor *)pVtabCursor;
|
||||
if( idxNum ){
|
||||
pCur->iPtr = sqlite3_value_int64(argv[0]);
|
||||
pCur->iCnt = sqlite3_value_int64(argv[1]);
|
||||
}else{
|
||||
pCur->iPtr = 0;
|
||||
pCur->iCnt = 0;
|
||||
}
|
||||
pCur->iRowid = 1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** SQLite will invoke this method one or more times while planning a query
|
||||
** that uses the intarray virtual table. This routine needs to create
|
||||
** a query plan for each invocation and compute an estimated cost for that
|
||||
** plan.
|
||||
**
|
||||
** In this implementation idxNum is used to represent the
|
||||
** query plan. idxStr is unused.
|
||||
**
|
||||
** idxNum is 1 if the pointer= and count= constraints exist and is 0 otherwise.
|
||||
** If idxNum is 0, then intarray becomes an empty table.
|
||||
*/
|
||||
static int intarrayBestIndex(
|
||||
sqlite3_vtab *tab,
|
||||
sqlite3_index_info *pIdxInfo
|
||||
){
|
||||
int i; /* Loop over constraints */
|
||||
int ptrIdx = -1; /* Index of the pointer= constraint, or -1 if none */
|
||||
int cntIdx = -1; /* Index of the count= constraint, or -1 if none */
|
||||
|
||||
const struct sqlite3_index_constraint *pConstraint;
|
||||
pConstraint = pIdxInfo->aConstraint;
|
||||
for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
|
||||
if( pConstraint->usable==0 ) continue;
|
||||
if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
|
||||
switch( pConstraint->iColumn ){
|
||||
case INTARRAY_COLUMN_POINTER:
|
||||
ptrIdx = i;
|
||||
break;
|
||||
case INTARRAY_COLUMN_COUNT:
|
||||
cntIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( ptrIdx>=0 && cntIdx>=0 ){
|
||||
pIdxInfo->aConstraintUsage[ptrIdx].argvIndex = 1;
|
||||
pIdxInfo->aConstraintUsage[ptrIdx].omit = 1;
|
||||
pIdxInfo->aConstraintUsage[cntIdx].argvIndex = 2;
|
||||
pIdxInfo->aConstraintUsage[cntIdx].omit = 1;
|
||||
pIdxInfo->estimatedCost = (double)1;
|
||||
pIdxInfo->estimatedRows = (double)100;
|
||||
pIdxInfo->idxNum = 1;
|
||||
}else{
|
||||
pIdxInfo->estimatedCost = (double)2147483647;
|
||||
pIdxInfo->estimatedRows = (double)2147483647;
|
||||
pIdxInfo->idxNum = 0;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This following structure defines all the methods for the
|
||||
** intarray virtual table.
|
||||
*/
|
||||
static sqlite3_module intarrayModule = {
|
||||
0, /* iVersion */
|
||||
0, /* xCreate */
|
||||
intarrayConnect, /* xConnect */
|
||||
intarrayBestIndex, /* xBestIndex */
|
||||
intarrayDisconnect, /* xDisconnect */
|
||||
0, /* xDestroy */
|
||||
intarrayOpen, /* xOpen - open a cursor */
|
||||
intarrayClose, /* xClose - close a cursor */
|
||||
intarrayFilter, /* xFilter - configure scan constraints */
|
||||
intarrayNext, /* xNext - advance a cursor */
|
||||
intarrayEof, /* xEof - check for end of scan */
|
||||
intarrayColumn, /* xColumn - read data */
|
||||
intarrayRowid, /* xRowid - read data */
|
||||
0, /* xUpdate */
|
||||
0, /* xBegin */
|
||||
0, /* xSync */
|
||||
0, /* xCommit */
|
||||
0, /* xRollback */
|
||||
0, /* xFindMethod */
|
||||
0, /* xRename */
|
||||
};
|
||||
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_array_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
if( sqlite3_libversion_number()<3008012 ){
|
||||
*pzErrMsg = sqlite3_mprintf(
|
||||
"intarray() requires SQLite 3.8.12 or later");
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
rc = sqlite3_create_module(db, "intarray", &intarrayModule, 0);
|
||||
#endif
|
||||
return rc;
|
||||
}
|
369
ext/misc/carray.c
Normal file
369
ext/misc/carray.c
Normal file
@ -0,0 +1,369 @@
|
||||
/*
|
||||
** 2016-06-29
|
||||
**
|
||||
** 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 demonstrates how to create a table-valued-function that
|
||||
** returns the values in a C-language array.
|
||||
** Examples:
|
||||
**
|
||||
** SELECT * FROM array($ptr,5)
|
||||
**
|
||||
** The query above returns 5 integers contained in a C-language array
|
||||
** at the address $ptr. $ptr is a pointer to the array of integers that
|
||||
** has been cast to an integer.
|
||||
**
|
||||
** There is an optional third parameter to determine the datatype of
|
||||
** the C-language array. Allowed values of the third parameter are
|
||||
** 'int32', 'int64', 'double', 'char*'. Example:
|
||||
**
|
||||
** SELECT * FROM array($ptr,10,'char*');
|
||||
**
|
||||
** HOW IT WORKS
|
||||
**
|
||||
** The carray "function" is really a virtual table with the
|
||||
** following schema:
|
||||
**
|
||||
** CREATE TABLE carray(
|
||||
** value,
|
||||
** pointer HIDDEN,
|
||||
** count HIDDEN,
|
||||
** ctype TEXT HIDDEN
|
||||
** );
|
||||
**
|
||||
** If the hidden columns "pointer" and "count" are unconstrained, then
|
||||
** the virtual table has no rows. Otherwise, the virtual table interprets
|
||||
** the integer value of "pointer" as a pointer to the array and "count"
|
||||
** as the number of elements in the array. The virtual table steps through
|
||||
** the array, element by element.
|
||||
*/
|
||||
#include "sqlite3ext.h"
|
||||
SQLITE_EXTENSION_INIT1
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
|
||||
/*
|
||||
** Allowed datatypes
|
||||
*/
|
||||
#define CARRAY_INT32 0
|
||||
#define CARRAY_INT64 1
|
||||
#define CARRAY_DOUBLE 2
|
||||
#define CARRAY_TEXT 3
|
||||
|
||||
/*
|
||||
** Names of types
|
||||
*/
|
||||
static const char *azType[] = { "int32", "int64", "double", "char*" };
|
||||
|
||||
|
||||
/* carray_cursor is a subclass of sqlite3_vtab_cursor which will
|
||||
** serve as the underlying representation of a cursor that scans
|
||||
** over rows of the result
|
||||
*/
|
||||
typedef struct carray_cursor carray_cursor;
|
||||
struct carray_cursor {
|
||||
sqlite3_vtab_cursor base; /* Base class - must be first */
|
||||
sqlite3_int64 iRowid; /* The rowid */
|
||||
sqlite3_int64 iPtr; /* Pointer to array of values */
|
||||
sqlite3_int64 iCnt; /* Number of integers in the array */
|
||||
unsigned char eType; /* One of the CARRAY_type values */
|
||||
};
|
||||
|
||||
/*
|
||||
** The carrayConnect() method is invoked to create a new
|
||||
** carray_vtab that describes the carray virtual table.
|
||||
**
|
||||
** Think of this routine as the constructor for carray_vtab objects.
|
||||
**
|
||||
** All this routine needs to do is:
|
||||
**
|
||||
** (1) Allocate the carray_vtab object and initialize all fields.
|
||||
**
|
||||
** (2) Tell SQLite (via the sqlite3_declare_vtab() interface) what the
|
||||
** result set of queries against carray will look like.
|
||||
*/
|
||||
static int carrayConnect(
|
||||
sqlite3 *db,
|
||||
void *pAux,
|
||||
int argc, const char *const*argv,
|
||||
sqlite3_vtab **ppVtab,
|
||||
char **pzErr
|
||||
){
|
||||
sqlite3_vtab *pNew;
|
||||
int rc;
|
||||
|
||||
/* Column numbers */
|
||||
#define CARRAY_COLUMN_VALUE 0
|
||||
#define CARRAY_COLUMN_POINTER 1
|
||||
#define CARRAY_COLUMN_COUNT 2
|
||||
#define CARRAY_COLUMN_CTYPE 3
|
||||
|
||||
rc = sqlite3_declare_vtab(db,
|
||||
"CREATE TABLE x(value,pointer hidden,count hidden,ctype hidden)");
|
||||
if( rc==SQLITE_OK ){
|
||||
pNew = *ppVtab = sqlite3_malloc( sizeof(*pNew) );
|
||||
if( pNew==0 ) return SQLITE_NOMEM;
|
||||
memset(pNew, 0, sizeof(*pNew));
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
** This method is the destructor for carray_cursor objects.
|
||||
*/
|
||||
static int carrayDisconnect(sqlite3_vtab *pVtab){
|
||||
sqlite3_free(pVtab);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Constructor for a new carray_cursor object.
|
||||
*/
|
||||
static int carrayOpen(sqlite3_vtab *p, sqlite3_vtab_cursor **ppCursor){
|
||||
carray_cursor *pCur;
|
||||
pCur = sqlite3_malloc( sizeof(*pCur) );
|
||||
if( pCur==0 ) return SQLITE_NOMEM;
|
||||
memset(pCur, 0, sizeof(*pCur));
|
||||
*ppCursor = &pCur->base;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Destructor for a carray_cursor.
|
||||
*/
|
||||
static int carrayClose(sqlite3_vtab_cursor *cur){
|
||||
sqlite3_free(cur);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** Advance a carray_cursor to its next row of output.
|
||||
*/
|
||||
static int carrayNext(sqlite3_vtab_cursor *cur){
|
||||
carray_cursor *pCur = (carray_cursor*)cur;
|
||||
pCur->iRowid++;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return values of columns for the row at which the carray_cursor
|
||||
** is currently pointing.
|
||||
*/
|
||||
static int carrayColumn(
|
||||
sqlite3_vtab_cursor *cur, /* The cursor */
|
||||
sqlite3_context *ctx, /* First argument to sqlite3_result_...() */
|
||||
int i /* Which column to return */
|
||||
){
|
||||
carray_cursor *pCur = (carray_cursor*)cur;
|
||||
sqlite3_int64 x = 0;
|
||||
switch( i ){
|
||||
case CARRAY_COLUMN_POINTER: x = pCur->iPtr; break;
|
||||
case CARRAY_COLUMN_COUNT: x = pCur->iCnt; break;
|
||||
case CARRAY_COLUMN_CTYPE: {
|
||||
sqlite3_result_text(ctx, azType[pCur->eType], -1, SQLITE_STATIC);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
default: {
|
||||
switch( pCur->eType ){
|
||||
case CARRAY_INT32: {
|
||||
int *p = (int*)pCur->iPtr;
|
||||
sqlite3_result_int(ctx, p[pCur->iRowid-1]);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
case CARRAY_INT64: {
|
||||
sqlite3_int64 *p = (sqlite3_int64*)pCur->iPtr;
|
||||
sqlite3_result_int64(ctx, p[pCur->iRowid-1]);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
case CARRAY_DOUBLE: {
|
||||
double *p = (double*)pCur->iPtr;
|
||||
sqlite3_result_double(ctx, p[pCur->iRowid-1]);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
case CARRAY_TEXT: {
|
||||
const char **p = (const char**)pCur->iPtr;
|
||||
sqlite3_result_text(ctx, p[pCur->iRowid-1], -1, SQLITE_TRANSIENT);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_result_int64(ctx, x);
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return the rowid for the current row. In this implementation, the
|
||||
** rowid is the same as the output value.
|
||||
*/
|
||||
static int carrayRowid(sqlite3_vtab_cursor *cur, sqlite_int64 *pRowid){
|
||||
carray_cursor *pCur = (carray_cursor*)cur;
|
||||
*pRowid = pCur->iRowid;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return TRUE if the cursor has been moved off of the last
|
||||
** row of output.
|
||||
*/
|
||||
static int carrayEof(sqlite3_vtab_cursor *cur){
|
||||
carray_cursor *pCur = (carray_cursor*)cur;
|
||||
return pCur->iRowid>pCur->iCnt;
|
||||
}
|
||||
|
||||
/*
|
||||
** This method is called to "rewind" the carray_cursor object back
|
||||
** to the first row of output.
|
||||
*/
|
||||
static int carrayFilter(
|
||||
sqlite3_vtab_cursor *pVtabCursor,
|
||||
int idxNum, const char *idxStr,
|
||||
int argc, sqlite3_value **argv
|
||||
){
|
||||
carray_cursor *pCur = (carray_cursor *)pVtabCursor;
|
||||
if( idxNum ){
|
||||
pCur->iPtr = sqlite3_value_int64(argv[0]);
|
||||
pCur->iCnt = sqlite3_value_int64(argv[1]);
|
||||
if( idxNum<3 ){
|
||||
pCur->eType = CARRAY_INT32;
|
||||
}else{
|
||||
int i;
|
||||
const char *zType = (const char*)sqlite3_value_text(argv[2]);
|
||||
for(i=0; i<sizeof(azType)/sizeof(azType[0]); i++){
|
||||
if( sqlite3_stricmp(zType, azType[i])==0 ) break;
|
||||
}
|
||||
if( i>=sizeof(azType)/sizeof(azType[0]) ){
|
||||
pVtabCursor->pVtab->zErrMsg = sqlite3_mprintf(
|
||||
"unknown datatype: %Q", zType);
|
||||
return SQLITE_ERROR;
|
||||
}else{
|
||||
pCur->eType = i;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
pCur->iPtr = 0;
|
||||
pCur->iCnt = 0;
|
||||
}
|
||||
pCur->iRowid = 1;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** SQLite will invoke this method one or more times while planning a query
|
||||
** that uses the carray virtual table. This routine needs to create
|
||||
** a query plan for each invocation and compute an estimated cost for that
|
||||
** plan.
|
||||
**
|
||||
** In this implementation idxNum is used to represent the
|
||||
** query plan. idxStr is unused.
|
||||
**
|
||||
** idxNum is 2 if the pointer= and count= constraints exist,
|
||||
** 3 if the ctype= constraint also exists, and is 0 otherwise.
|
||||
** If idxNum is 0, then carray becomes an empty table.
|
||||
*/
|
||||
static int carrayBestIndex(
|
||||
sqlite3_vtab *tab,
|
||||
sqlite3_index_info *pIdxInfo
|
||||
){
|
||||
int i; /* Loop over constraints */
|
||||
int ptrIdx = -1; /* Index of the pointer= constraint, or -1 if none */
|
||||
int cntIdx = -1; /* Index of the count= constraint, or -1 if none */
|
||||
int ctypeIdx = -1; /* Index of the ctype= constraint, or -1 if none */
|
||||
|
||||
const struct sqlite3_index_constraint *pConstraint;
|
||||
pConstraint = pIdxInfo->aConstraint;
|
||||
for(i=0; i<pIdxInfo->nConstraint; i++, pConstraint++){
|
||||
if( pConstraint->usable==0 ) continue;
|
||||
if( pConstraint->op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
|
||||
switch( pConstraint->iColumn ){
|
||||
case CARRAY_COLUMN_POINTER:
|
||||
ptrIdx = i;
|
||||
break;
|
||||
case CARRAY_COLUMN_COUNT:
|
||||
cntIdx = i;
|
||||
break;
|
||||
case CARRAY_COLUMN_CTYPE:
|
||||
ctypeIdx = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( ptrIdx>=0 && cntIdx>=0 ){
|
||||
pIdxInfo->aConstraintUsage[ptrIdx].argvIndex = 1;
|
||||
pIdxInfo->aConstraintUsage[ptrIdx].omit = 1;
|
||||
pIdxInfo->aConstraintUsage[cntIdx].argvIndex = 2;
|
||||
pIdxInfo->aConstraintUsage[cntIdx].omit = 1;
|
||||
pIdxInfo->estimatedCost = (double)1;
|
||||
pIdxInfo->estimatedRows = (double)100;
|
||||
pIdxInfo->idxNum = 2;
|
||||
if( ctypeIdx>=0 ){
|
||||
pIdxInfo->aConstraintUsage[ctypeIdx].argvIndex = 3;
|
||||
pIdxInfo->aConstraintUsage[ctypeIdx].omit = 1;
|
||||
pIdxInfo->idxNum = 3;
|
||||
}
|
||||
}else{
|
||||
pIdxInfo->estimatedCost = (double)2147483647;
|
||||
pIdxInfo->estimatedRows = (double)2147483647;
|
||||
pIdxInfo->idxNum = 0;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** This following structure defines all the methods for the
|
||||
** carray virtual table.
|
||||
*/
|
||||
static sqlite3_module carrayModule = {
|
||||
0, /* iVersion */
|
||||
0, /* xCreate */
|
||||
carrayConnect, /* xConnect */
|
||||
carrayBestIndex, /* xBestIndex */
|
||||
carrayDisconnect, /* xDisconnect */
|
||||
0, /* xDestroy */
|
||||
carrayOpen, /* xOpen - open a cursor */
|
||||
carrayClose, /* xClose - close a cursor */
|
||||
carrayFilter, /* xFilter - configure scan constraints */
|
||||
carrayNext, /* xNext - advance a cursor */
|
||||
carrayEof, /* xEof - check for end of scan */
|
||||
carrayColumn, /* xColumn - read data */
|
||||
carrayRowid, /* xRowid - read data */
|
||||
0, /* xUpdate */
|
||||
0, /* xBegin */
|
||||
0, /* xSync */
|
||||
0, /* xCommit */
|
||||
0, /* xRollback */
|
||||
0, /* xFindMethod */
|
||||
0, /* xRename */
|
||||
};
|
||||
|
||||
#endif /* SQLITE_OMIT_VIRTUALTABLE */
|
||||
|
||||
#ifdef _WIN32
|
||||
__declspec(dllexport)
|
||||
#endif
|
||||
int sqlite3_carray_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
int rc = SQLITE_OK;
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
#ifndef SQLITE_OMIT_VIRTUALTABLE
|
||||
if( sqlite3_libversion_number()<3008012 ){
|
||||
*pzErrMsg = sqlite3_mprintf(
|
||||
"carray() requires SQLite 3.8.12 or later");
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
rc = sqlite3_create_module(db, "carray", &carrayModule, 0);
|
||||
#endif
|
||||
return rc;
|
||||
}
|
2
main.mk
2
main.mk
@ -324,7 +324,7 @@ TESTSRC = \
|
||||
#
|
||||
TESTSRC += \
|
||||
$(TOP)/ext/misc/amatch.c \
|
||||
$(TOP)/ext/misc/array.c \
|
||||
$(TOP)/ext/misc/carray.c \
|
||||
$(TOP)/ext/misc/closure.c \
|
||||
$(TOP)/ext/misc/csv.c \
|
||||
$(TOP)/ext/misc/eval.c \
|
||||
|
22
manifest
22
manifest
@ -1,8 +1,8 @@
|
||||
C Fix\san\soff-by-one\scomparison\sin\sthe\sintarray()\svirtual\stable.\s\sGet\sthe\nintarray()\svirtual\stable\stests\sworking\susing\sthe\slegacy\smakefile.
|
||||
D 2016-07-02T20:57:06.871
|
||||
F Makefile.in 541d493154ec3b0b20b2f1d495ec66f55905191e
|
||||
C Change\sthe\sname\sof\sthe\sintarray()\sextension\sto\scarray()\sand\sgive\sit\san\noptional\sthird\sparameter\sthat\sspecifies\sthe\sdatatype\sas\sone\sof\s'int32',\n'int64',\s'double',\sor\s'char*'.\s\s'int32'\sis\sthe\sdefault.
|
||||
D 2016-07-03T02:35:47.798
|
||||
F Makefile.in 6c20d44f72d4564f11652b26291a214c8367e5db
|
||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||
F Makefile.msc 50149765ef72f4e652b9a0f1f6462c4784bb9423
|
||||
F Makefile.msc d66d0395c38571aab3804f8db0fa20707ae4609a
|
||||
F README.md 8ecc12493ff9f820cdea6520a9016001cb2e59b7
|
||||
F VERSION cb29eb11e493dd85b3eeec4053c03949bf98478e
|
||||
F aclocal.m4 a5c22d164aff7ed549d53a90fa56d56955281f50
|
||||
@ -204,7 +204,7 @@ F ext/icu/README.txt d9fbbad0c2f647c3fdf715fc9fd64af53aedfc43
|
||||
F ext/icu/icu.c 43df9d8ef2fae7a325100ebd713ab089dc829dd7
|
||||
F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
|
||||
F ext/misc/amatch.c 211108e201105e4bb0c076527b8cfd34330fc234
|
||||
F ext/misc/array.c bce2608f123d35eff81ac73e443b0620bed89ca1
|
||||
F ext/misc/carray.c f1947c7d5bbce17f8244c9a05baae11d5d68467e w ext/misc/array.c
|
||||
F ext/misc/closure.c 0d2a038df8fbae7f19de42e7c7d71f2e4dc88704
|
||||
F ext/misc/compress.c 122faa92d25033d6c3f07c39231de074ab3d2e83
|
||||
F ext/misc/csv.c f01126ba170fd4ef7c752b156568a80c912d4441
|
||||
@ -308,7 +308,7 @@ F ext/userauth/userauth.c 5fa3bdb492f481bbc1709fc83c91ebd13460c69e
|
||||
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
|
||||
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
|
||||
F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60
|
||||
F main.mk 162bb978db5519dbcaba141be346247c82b7caa8
|
||||
F main.mk e9d66f1b1c4874221d12d940be3ce5f397c10741
|
||||
F mkso.sh fd21c06b063bb16a5d25deea1752c2da6ac3ed83
|
||||
F mptest/config01.test 3c6adcbc50b991866855f1977ff172eb6d901271
|
||||
F mptest/config02.test 4415dfe36c48785f751e16e32c20b077c28ae504
|
||||
@ -393,7 +393,7 @@ F src/sqliteLimit.h c0373387c287c8d0932510b5547ecde31b5da247
|
||||
F src/status.c 70912d7be68e9e2dbc4010c93d344af61d4c59ba
|
||||
F src/table.c 5226df15ab9179b9ed558d89575ea0ce37b03fc9
|
||||
F src/tclsqlite.c 25fbbbb97f76dbfd113153fb63f52d7ecfac5dd0
|
||||
F src/test1.c 081e4ed40525590406a51f7e7e4cee31cdb5d029
|
||||
F src/test1.c 7cbfda741fbfa541ecce305ff2d7c6bb730aa991
|
||||
F src/test2.c 5586f43fcd9a1be0830793cf9d354082c261b25b
|
||||
F src/test3.c c75c8af0eadb335236c9e61b51044c58a8f7dd59
|
||||
F src/test4.c d168f83cc78d02e8d35567bb5630e40dcd85ac1e
|
||||
@ -1116,7 +1116,7 @@ F test/symlink.test c9ebe7330d228249e447038276bfc8a7b22f4849
|
||||
F test/sync.test 2f84bdbc2b2df1fcb0220575b4b9f8cea94b7529
|
||||
F test/syscall.test f59ba4e25f7ba4a4c031026cc2ef8b6e4b4c639c
|
||||
F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04
|
||||
F test/tabfunc01.test ebcfb548b88f874a5ded67e7c85ca0d5ab31f4b5
|
||||
F test/tabfunc01.test 50a9fb379f9747fd0d40ea6d8fa3a101361bb537
|
||||
F test/table.test b708f3e5fa2542fa51dfab21fc07b36ea445cb2f
|
||||
F test/tableapi.test 2674633fa95d80da917571ebdd759a14d9819126
|
||||
F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930
|
||||
@ -1504,7 +1504,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 507fdbfb54ce377f0d870260b07d71b797843fcf
|
||||
R 7bb6d7d8a00bd78e137b76d2018230b6
|
||||
P 7c3d441f2a9f642f3d91dcee854a4d16d298bc34
|
||||
R 41f36cbba6be0bbd66a667562505a546
|
||||
U drh
|
||||
Z f5dbc3921a51d0860e9141544e9a9fdc
|
||||
Z 31f2105436c0dcfd40b6904e7b94f7b1
|
||||
|
@ -1 +1 @@
|
||||
7c3d441f2a9f642f3d91dcee854a4d16d298bc34
|
||||
a204ba99db34b356acb259189158a32d2df25da0
|
147
src/test1.c
147
src/test1.c
@ -3242,41 +3242,137 @@ static int test_bind_int(
|
||||
|
||||
|
||||
/*
|
||||
** Usage: sqlite3_bind_intarray STMT N INT ...
|
||||
** Usage: intarray_addr INT ...
|
||||
**
|
||||
** Create a C-language array of integers from the arguments. Bind a pointer
|
||||
** to this array to the NAME parameter of STMT.
|
||||
** Return the address of a C-language array of 32-bit integers.
|
||||
**
|
||||
** Space to hold the array is obtained from malloc(). Call this procedure once
|
||||
** with no arguments in order to release memory. Each call to this procedure
|
||||
** overwrites the previous array.
|
||||
*/
|
||||
static int test_bind_intarray(
|
||||
static int test_intarray_addr(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
sqlite3_stmt *pStmt;
|
||||
int idx;
|
||||
int i;
|
||||
static int *p = 0;
|
||||
|
||||
sqlite3_free(p);
|
||||
p = 0;
|
||||
if( objc<4 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"",
|
||||
Tcl_GetStringFromObj(objv[0], 0), " STMT NAME INT...", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
||||
if( Tcl_GetIntFromObj(interp, objv[2], &idx) ) return TCL_ERROR;
|
||||
p = sqlite3_malloc( sizeof(int)*(objc-3) );
|
||||
if( p==0 ) return TCL_ERROR;
|
||||
for(i=0; i<objc-3; i++){
|
||||
if( Tcl_GetIntFromObj(interp, objv[3+i], &p[i]) ){
|
||||
sqlite3_free(p);
|
||||
return TCL_ERROR;
|
||||
if( objc>1 ){
|
||||
p = sqlite3_malloc( sizeof(p[0])*(objc-1) );
|
||||
if( p==0 ) return TCL_ERROR;
|
||||
for(i=0; i<objc-1; i++){
|
||||
if( Tcl_GetIntFromObj(interp, objv[1+i], &p[i]) ){
|
||||
sqlite3_free(p);
|
||||
p = 0;
|
||||
return TCL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_bind_int64(pStmt, idx, (sqlite3_int64)p);
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj((sqlite3_int64)p));
|
||||
return TCL_OK;
|
||||
}
|
||||
/*
|
||||
** Usage: intarray_addr INT ...
|
||||
**
|
||||
** Return the address of a C-language array of 32-bit integers.
|
||||
**
|
||||
** Space to hold the array is obtained from malloc(). Call this procedure once
|
||||
** with no arguments in order to release memory. Each call to this procedure
|
||||
** overwrites the previous array.
|
||||
*/
|
||||
static int test_int64array_addr(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int i;
|
||||
static sqlite3_int64 *p = 0;
|
||||
|
||||
sqlite3_free(p);
|
||||
p = 0;
|
||||
if( objc>1 ){
|
||||
p = sqlite3_malloc( sizeof(p[0])*(objc-1) );
|
||||
if( p==0 ) return TCL_ERROR;
|
||||
for(i=0; i<objc-1; i++){
|
||||
if( Tcl_GetWideIntFromObj(interp, objv[1+i], &p[i]) ){
|
||||
sqlite3_free(p);
|
||||
p = 0;
|
||||
return TCL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj((sqlite3_int64)p));
|
||||
return TCL_OK;
|
||||
}
|
||||
/*
|
||||
** Usage: doublearray_addr INT ...
|
||||
**
|
||||
** Return the address of a C-language array of doubles.
|
||||
**
|
||||
** Space to hold the array is obtained from malloc(). Call this procedure once
|
||||
** with no arguments in order to release memory. Each call to this procedure
|
||||
** overwrites the previous array.
|
||||
*/
|
||||
static int test_doublearray_addr(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int i;
|
||||
static double *p = 0;
|
||||
|
||||
sqlite3_free(p);
|
||||
p = 0;
|
||||
if( objc>1 ){
|
||||
p = sqlite3_malloc( sizeof(p[0])*(objc-1) );
|
||||
if( p==0 ) return TCL_ERROR;
|
||||
for(i=0; i<objc-1; i++){
|
||||
if( Tcl_GetDoubleFromObj(interp, objv[1+i], &p[i]) ){
|
||||
sqlite3_free(p);
|
||||
p = 0;
|
||||
return TCL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj((sqlite3_int64)p));
|
||||
return TCL_OK;
|
||||
}
|
||||
/*
|
||||
** Usage: textarray_addr TEXT ...
|
||||
**
|
||||
** Return the address of a C-language array of strings.
|
||||
**
|
||||
** Space to hold the array is obtained from malloc(). Call this procedure once
|
||||
** with no arguments in order to release memory. Each call to this procedure
|
||||
** overwrites the previous array.
|
||||
*/
|
||||
static int test_textarray_addr(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int i;
|
||||
static int n = 0;
|
||||
static char **p = 0;
|
||||
|
||||
for(i=0; i<n; i++) sqlite3_free(p[i]);
|
||||
sqlite3_free(p);
|
||||
p = 0;
|
||||
if( objc>1 ){
|
||||
p = sqlite3_malloc( sizeof(p[0])*(objc-1) );
|
||||
if( p==0 ) return TCL_ERROR;
|
||||
for(i=0; i<objc-1; i++){
|
||||
p[i] = sqlite3_mprintf("%s", Tcl_GetString(objv[1+i]));
|
||||
}
|
||||
}
|
||||
Tcl_SetObjResult(interp, Tcl_NewWideIntObj((sqlite3_int64)p));
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
@ -6623,7 +6719,7 @@ static int tclLoadStaticExtensionCmd(
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
extern int sqlite3_amatch_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
extern int sqlite3_array_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
extern int sqlite3_carray_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
extern int sqlite3_closure_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
extern int sqlite3_csv_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
extern int sqlite3_eval_init(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
@ -6642,7 +6738,7 @@ static int tclLoadStaticExtensionCmd(
|
||||
int (*pInit)(sqlite3*,char**,const sqlite3_api_routines*);
|
||||
} aExtension[] = {
|
||||
{ "amatch", sqlite3_amatch_init },
|
||||
{ "array", sqlite3_array_init },
|
||||
{ "carray", sqlite3_carray_init },
|
||||
{ "closure", sqlite3_closure_init },
|
||||
{ "csv", sqlite3_csv_init },
|
||||
{ "eval", sqlite3_eval_init },
|
||||
@ -7137,8 +7233,11 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
{ "bad_behavior", test_bad_behavior, (void*)&iZero },
|
||||
{ "register_dbstat_vtab", test_register_dbstat_vtab },
|
||||
{ "sqlite3_connection_pointer", get_sqlite_pointer, 0 },
|
||||
{ "intarray_addr", test_intarray_addr, 0 },
|
||||
{ "int64array_addr", test_int64array_addr, 0 },
|
||||
{ "doublearray_addr", test_doublearray_addr, 0 },
|
||||
{ "textarray_addr", test_textarray_addr, 0 },
|
||||
{ "sqlite3_bind_int", test_bind_int, 0 },
|
||||
{ "sqlite3_bind_intarray", test_bind_intarray, 0 },
|
||||
{ "sqlite3_bind_zeroblob", test_bind_zeroblob, 0 },
|
||||
{ "sqlite3_bind_zeroblob64", test_bind_zeroblob64, 0 },
|
||||
{ "sqlite3_bind_int64", test_bind_int64, 0 },
|
||||
|
@ -22,7 +22,7 @@ ifcapable !vtab {
|
||||
return
|
||||
}
|
||||
load_static_extension db series
|
||||
load_static_extension db array
|
||||
load_static_extension db carray
|
||||
|
||||
do_execsql_test tabfunc01-1.1 {
|
||||
SELECT *, '|' FROM generate_series WHERE start=1 AND stop=9 AND step=2;
|
||||
@ -146,74 +146,51 @@ do_execsql_test tabfunc01-600 {
|
||||
} {(002) (012) (022) (032) (042) (052)}
|
||||
|
||||
|
||||
do_test tabfunc01-600 {
|
||||
set TAIL {}
|
||||
set VM [sqlite3_prepare db {SELECT * FROM intarray(?2,?3)} -1 TAIL]
|
||||
set TAIL
|
||||
} {}
|
||||
do_test tabfunc01-610 {
|
||||
sqlite3_bind_intarray $VM 2 11 22 33 44 55
|
||||
sqlite3_bind_int $VM 3 4
|
||||
sqlite3_step $VM
|
||||
} SQLITE_ROW
|
||||
do_test tabfunc01-620 {
|
||||
sqlite3_column_int $VM 0
|
||||
} 11
|
||||
do_test tabfunc01-621 {
|
||||
sqlite3_step $VM
|
||||
sqlite3_column_int $VM 0
|
||||
} 22
|
||||
sqlite3_finalize $VM
|
||||
|
||||
do_test tabfunc01-650 {
|
||||
do_test tabfunc01-700 {
|
||||
set PTR [intarray_addr 5 7 13 17 23]
|
||||
db eval {
|
||||
DROP TABLE IF EXISTS t6;
|
||||
CREATE TABLE t6(x INTEGER PRIMARY KEY, y BLOB);
|
||||
WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100)
|
||||
INSERT INTO t6(x,y) SELECT x, randomblob(x) FROM c;
|
||||
SELECT b FROM t600, carray($PTR,5) WHERE a=value;
|
||||
}
|
||||
set TAIL {}
|
||||
set VM [sqlite3_prepare db {
|
||||
SELECT length(y) FROM t6 WHERE x IN (SELECT value FROM intarray(?1,3));
|
||||
} -1 TAIL]
|
||||
string trim $TAIL
|
||||
} {}
|
||||
do_test tabfunc01-660 {
|
||||
sqlite3_bind_intarray $VM 1 11 22 33 44 55
|
||||
sqlite3_step $VM
|
||||
} SQLITE_ROW
|
||||
do_test tabfunc01-661 {
|
||||
sqlite3_column_int $VM 0
|
||||
} 11
|
||||
sqlite3_finalize $VM
|
||||
} {(005) (007) (013) (017) (023)}
|
||||
do_test tabfunc01-701 {
|
||||
db eval {
|
||||
SELECT b FROM t600 WHERE a IN carray($PTR,5,'int32');
|
||||
}
|
||||
} {(005) (007) (013) (017) (023)}
|
||||
do_test tabfunc01-702 {
|
||||
db eval {
|
||||
SELECT b FROM t600 WHERE a IN carray($PTR,4,'int32');
|
||||
}
|
||||
} {(005) (007) (013) (017)}
|
||||
do_catchsql_test tabfunc01-710 {
|
||||
SELECT b FROM t600 WHERE a IN carray($PTR,5,'int33');
|
||||
} {1 {unknown datatype: 'int33'}}
|
||||
|
||||
do_test tabfunc01-670 {
|
||||
set TAIL {}
|
||||
set VM [sqlite3_prepare db {
|
||||
SELECT length(y) FROM t6 WHERE x IN intarray(?1,3);
|
||||
} -1 TAIL]
|
||||
string trim $TAIL
|
||||
} {}
|
||||
do_test tabfunc01-671 {
|
||||
sqlite3_bind_intarray $VM 1 11 22 33 44 55
|
||||
sqlite3_step $VM
|
||||
} SQLITE_ROW
|
||||
do_test tabfunc01-672 {
|
||||
sqlite3_column_int $VM 0
|
||||
} 11
|
||||
do_test tabfunc01-673 {
|
||||
sqlite3_step $VM
|
||||
sqlite3_column_int $VM 0
|
||||
} 22
|
||||
do_test tabfunc01-674 {
|
||||
sqlite3_step $VM
|
||||
sqlite3_column_int $VM 0
|
||||
} 33
|
||||
do_test tabfunc01-675 {
|
||||
sqlite3_step $VM
|
||||
} {SQLITE_DONE}
|
||||
sqlite3_finalize $VM
|
||||
do_test tabfunc01-720 {
|
||||
set PTR [int64array_addr 5 7 13 17 23]
|
||||
db eval {
|
||||
SELECT b FROM t600, carray($PTR,5,'int64') WHERE a=value;
|
||||
}
|
||||
} {(005) (007) (013) (017) (023)}
|
||||
|
||||
catch {sqlite3_bind_intarray}
|
||||
do_test tabfunc01-730 {
|
||||
set PTR [doublearray_addr 5.0 7.0 13.0 17.0 23.0]
|
||||
db eval {
|
||||
SELECT b FROM t600, carray($PTR,5,'double') WHERE a=value;
|
||||
}
|
||||
} {(005) (007) (013) (017) (023)}
|
||||
|
||||
do_test tabfunc01-740 {
|
||||
set PTR [textarray_addr 5 7 13 17 23]
|
||||
db eval {
|
||||
SELECT b FROM t600, carray($PTR,5,'char*') WHERE a=value;
|
||||
}
|
||||
} {(005) (007) (013) (017) (023)}
|
||||
|
||||
|
||||
intarray_addr
|
||||
int64array_addr
|
||||
doublearray_addr
|
||||
textarray_addr
|
||||
|
||||
finish_test
|
||||
|
Loading…
Reference in New Issue
Block a user