#ifndef TH3_VERSION
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#endif
typedef struct vt02_vtab vt02_vtab;
typedef struct vt02_cur vt02_cur;
struct vt02_vtab {
sqlite3_vtab parent;
sqlite3 *db;
int busy;
};
#define VT02_IGNORE_USABLE 0x0001
#define VT02_NO_SORT_OPT 0x0002
#define VT02_NO_OFFSET 0x0004
#define VT02_ALLOC_IDXSTR 0x0008
#define VT02_BAD_IDXNUM 0x0010
struct vt02_cur {
sqlite3_vtab_cursor parent;
sqlite3_int64 i;
sqlite3_int64 iEof;
int iIncr;
unsigned int mD;
};
int vt02Connect(
sqlite3 *db,
void *pAux,
int argc,
const char *const*argv,
sqlite3_vtab **ppVTab,
char **pzErr
){
vt02_vtab *pVtab;
int rc;
const char *zSchema = (const char*)pAux;
static const char zDefaultSchema[] =
"CREATE TABLE x(x INT, a INT, b INT, c INT, d INT,"
" flags INT HIDDEN, logtab TEXT HIDDEN);";
#define VT02_COL_X 0
#define VT02_COL_A 1
#define VT02_COL_B 2
#define VT02_COL_C 3
#define VT02_COL_D 4
#define VT02_COL_FLAGS 5
#define VT02_COL_LOGTAB 6
#define VT02_COL_NONE 7
pVtab = sqlite3_malloc( sizeof(*pVtab) );
if( pVtab==0 ){
*pzErr = sqlite3_mprintf("out of memory");
return SQLITE_NOMEM;
}
memset(pVtab, 0, sizeof(*pVtab));
pVtab->db = db;
rc = sqlite3_declare_vtab(db, zSchema ? zSchema : zDefaultSchema);
if( rc ){
sqlite3_free(pVtab);
}else{
*ppVTab = &pVtab->parent;
}
return rc;
}
int vt02Disconnect(sqlite3_vtab *pVTab){
sqlite3_free(pVTab);
return SQLITE_OK;
}
static void vt02ErrMsg(sqlite3_vtab *pVtab, const char *zFormat, ...){
va_list ap;
sqlite3_free(pVtab->zErrMsg);
va_start(ap, zFormat);
pVtab->zErrMsg = sqlite3_vmprintf(zFormat, ap);
va_end(ap);
}
static int vt02Open(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
vt02_cur *pCur;
pCur = sqlite3_malloc( sizeof(*pCur) );
if( pCur==0 ){
vt02ErrMsg(pVTab, "out of memory");
return SQLITE_NOMEM;
}
*ppCursor = &pCur->parent;
pCur->i = -1;
return SQLITE_OK;
}
static int vt02Close(sqlite3_vtab_cursor *pCursor){
vt02_cur *pCur = (vt02_cur*)pCursor;
sqlite3_free(pCur);
return SQLITE_OK;
}
static int vt02Eof(sqlite3_vtab_cursor *pCursor){
vt02_cur *pCur = (vt02_cur*)pCursor;
return pCur->i<0 || pCur->i>=pCur->iEof;
}
static int vt02Next(sqlite3_vtab_cursor *pCursor){
vt02_cur *pCur = (vt02_cur*)pCursor;
do{
pCur->i += pCur->iIncr;
if( pCur->i<0 ) pCur->i = pCur->iEof;
}while( (pCur->mD & (1<<(pCur->i%10)))==0 && pCur->i<pCur->iEof );
return SQLITE_OK;
}
static int vt02Filter(
sqlite3_vtab_cursor *pCursor,
int idxNum,
const char *idxStr,
int argc,
sqlite3_value **argv
){
vt02_cur *pCur = (vt02_cur*)pCursor;
int bUseOffset = 0;
int iArg = 0;
int iOrigIdxNum = idxNum;
pCur->iIncr = 1;
pCur->mD = 0x3ff;
if( idxNum>=100 ){
bUseOffset = 1;
idxNum -= 100;
}
if( idxNum<0 || idxNum>38 ) goto vt02_bad_idxnum;
while( idxNum>=10 ){
pCur->iIncr *= 10;
idxNum -= 10;
}
if( idxNum==0 ){
pCur->i = 0;
pCur->iEof = 10000;
}else if( idxNum==1 ){
pCur->i = sqlite3_value_int64(argv[0]);
if( pCur->i<0 ) pCur->i = -1;
if( pCur->i>9999 ) pCur->i = 10000;
pCur->iEof = pCur->i+1;
if( pCur->i<0 || pCur->i>9999 ) pCur->i = pCur->iEof;
}else if( idxNum>=2 && idxNum<=5 ){
int i, e, m;
e = idxNum - 2;
assert( e<=argc-1 );
pCur->i = 0;
for(m=1000, i=0; i<=e; i++, m /= 10){
sqlite3_int64 v = sqlite3_value_int64(argv[iArg++]);
if( v<0 ) v = 0;
if( v>9 ) v = 9;
pCur->i += m*v;
pCur->iEof = pCur->i+m;
}
}else if( idxNum>=6 && idxNum<=8 ){
int i, e, m, rc;
sqlite3_value *pIn, *pVal;
e = idxNum - 6;
assert( e<=argc-2 );
pCur->i = 0;
for(m=1000, i=0; i<=e; i++, m /= 10){
sqlite3_int64 v;
pVal = 0;
if( sqlite3_vtab_in_first(0, &pVal)!=SQLITE_MISUSE
|| sqlite3_vtab_in_first(argv[iArg], &pVal)!=SQLITE_ERROR
){
vt02ErrMsg(pCursor->pVtab,
"unexpected success from sqlite3_vtab_in_first()");
return SQLITE_ERROR;
}
v = sqlite3_value_int64(argv[iArg++]);
if( v<0 ) v = 0;
if( v>9 ) v = 9;
pCur->i += m*v;
pCur->iEof = pCur->i+m;
}
pCur->mD = 0;
pIn = argv[iArg++];
assert( sqlite3_value_type(pIn)==SQLITE_NULL );
for( rc = sqlite3_vtab_in_first(pIn, &pVal);
rc==SQLITE_OK && pVal!=0;
rc = sqlite3_vtab_in_next(pIn, &pVal)
){
int eType = sqlite3_value_numeric_type(pVal);
if( eType==SQLITE_FLOAT ){
double r = sqlite3_value_double(pVal);
if( r<0.0 || r>9.0 || r!=(int)r ) continue;
}else if( eType!=SQLITE_INTEGER ){
continue;
}
i = sqlite3_value_int(pVal);
if( i<0 || i>9 ) continue;
pCur->mD |= 1<<i;
}
if( rc!=SQLITE_OK && rc!=SQLITE_DONE ){
vt02ErrMsg(pCursor->pVtab, "Error from sqlite3_vtab_in_first/next()");
return rc;
}
}else{
goto vt02_bad_idxnum;
}
if( bUseOffset ){
int nSkip = sqlite3_value_int(argv[iArg]);
while( nSkip-- > 0 && pCur->i<pCur->iEof ) vt02Next(pCursor);
}
return SQLITE_OK;
vt02_bad_idxnum:
vt02ErrMsg(pCursor->pVtab, "invalid idxNum for vt02: %d", iOrigIdxNum);
return SQLITE_ERROR;
}
static int vt02Column(
sqlite3_vtab_cursor *pCursor,
sqlite3_context *context,
int N
){
vt02_cur *pCur = (vt02_cur*)pCursor;
int v = pCur->i;
if( N==VT02_COL_X ){
sqlite3_result_int(context, v);
}else if( N>=VT02_COL_A && N<=VT02_COL_D ){
static const int iDivisor[] = { 1, 1000, 100, 10, 1 };
v = (v/iDivisor[N])%10;
sqlite3_result_int(context, v);
}
return SQLITE_OK;
}
static int vt02Rowid(sqlite3_vtab_cursor *pCursor, sqlite3_int64 *pRowid){
vt02_cur *pCur = (vt02_cur*)pCursor;
*pRowid = pCur->i+1;
return SQLITE_OK;
}
static void sqlite3RunSql(
sqlite3 *db,
sqlite3_vtab *pVTab,
const char *zFormat,
...
){
char *zSql;
va_list ap;
va_start(ap, zFormat);
if( zFormat==0 ){
zSql = va_arg(ap, char*);
}else{
zSql = sqlite3_vmprintf(zFormat, ap);
}
va_end(ap);
if( zSql ){
char *zErrMsg = 0;
(void)sqlite3_exec(db, zSql, 0, 0, &zErrMsg);
if( zErrMsg ){
if( pVTab->zErrMsg==0 ){
pVTab->zErrMsg = sqlite3_mprintf("%s in [%s]", zErrMsg, zSql);
}
sqlite3_free(zErrMsg);
}
sqlite3_free(zSql);
}
}
static void sqlite3BestIndexLog(
sqlite3_index_info *pInfo,
const char *zLogTab,
sqlite3 *db,
const char **azColname,
sqlite3_vtab *pVTab
){
int i, rc;
sqlite3_str *pStr;
int iBI;
if( sqlite3_table_column_metadata(db,0,zLogTab,0,0,0,0,0,0) ){
sqlite3RunSql(db,pVTab,
"CREATE TABLE IF NOT EXISTS temp.\"%w\"(\n"
" bi INT, -- BestIndex call number\n"
" vn TEXT, -- Variable Name\n"
" ix INT, -- Index or value\n"
" cn TEXT, -- Column Name\n"
" op INT, -- Opcode or argvIndex\n"
" ux INT, -- usable for omit flag\n"
" rx BOOLEAN, -- Right-hand side value is available\n"
" rhs ANY, -- RHS value\n"
" cs TEXT, -- Collating Sequence\n"
" inop BOOLEAN -- IN operator capable of batch reads\n"
");", zLogTab
);
iBI = 1;
}else{
sqlite3_stmt *pStmt;
char *zSql;
zSql = sqlite3_mprintf("SELECT max(bi) FROM temp.\"%w\"",zLogTab);
if( zSql==0 ){
sqlite3_free(pVTab->zErrMsg);
pVTab->zErrMsg = sqlite3_mprintf("out of memory");
return;
}
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
sqlite3_free(zSql);
if( rc ){
sqlite3_free(pVTab->zErrMsg);
pVTab->zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
iBI = 0;
}else if( sqlite3_step(pStmt)==SQLITE_ROW ){
iBI = sqlite3_column_int(pStmt, 0)+1;
}else{
iBI = 1;
}
sqlite3_finalize(pStmt);
}
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix) VALUES(%d,'nConstraint',%d)",
zLogTab, iBI, pInfo->nConstraint
);
for(i=0; i<pInfo->nConstraint; i++){
sqlite3_value *pVal;
char *zSql;
int iCol = pInfo->aConstraint[i].iColumn;
int op = pInfo->aConstraint[i].op;
const char *zCol;
if( op==SQLITE_INDEX_CONSTRAINT_LIMIT
|| op==SQLITE_INDEX_CONSTRAINT_OFFSET
){
zCol = "";
}else if( iCol<0 ){
zCol = "rowid";
}else{
zCol = azColname[iCol];
}
pStr = sqlite3_str_new(0);
sqlite3_str_appendf(pStr,
"INSERT INTO temp.\"%w\"(bi,vn,ix,cn,op,ux,rx,rhs,cs,inop)"
"VALUES(%d,'aConstraint',%d,%Q,%d,%d",
zLogTab, iBI,
i,
zCol,
op,
pInfo->aConstraint[i].usable);
pVal = 0;
rc = sqlite3_vtab_rhs_value(pInfo, i, &pVal);
assert( pVal!=0 || rc!=SQLITE_OK );
if( rc==SQLITE_OK ){
sqlite3_str_appendf(pStr,",1,?1");
}else{
sqlite3_str_appendf(pStr,",0,NULL");
}
sqlite3_str_appendf(pStr,",%Q,%d)",
sqlite3_vtab_collation(pInfo,i),
sqlite3_vtab_in(pInfo,i,-1));
zSql = sqlite3_str_finish(pStr);
if( zSql==0 ){
if( pVTab->zErrMsg==0 ) pVTab->zErrMsg = sqlite3_mprintf("out of memory");
}else{
sqlite3_stmt *pStmt = 0;
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
if( rc ){
if( pVTab->zErrMsg==0 ){
pVTab->zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
}
}else{
if( pVal ) sqlite3_bind_value(pStmt, 1, pVal);
sqlite3_step(pStmt);
rc = sqlite3_reset(pStmt);
if( rc && pVTab->zErrMsg==0 ){
pVTab->zErrMsg = sqlite3_mprintf("%s", sqlite3_errmsg(db));
}
}
sqlite3_finalize(pStmt);
sqlite3_free(zSql);
}
}
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix) VALUES(%d,'nOrderBy',%d)",
zLogTab, iBI, pInfo->nOrderBy
);
for(i=0; i<pInfo->nOrderBy; i++){
int iCol = pInfo->aOrderBy[i].iColumn;
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix,cn,op)VALUES(%d,'aOrderBy',%d,%Q,%d)",
zLogTab, iBI,
i,
iCol>=0 ? azColname[iCol] : "rowid",
pInfo->aOrderBy[i].desc
);
}
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix) VALUES(%d,'sqlite3_vtab_distinct',%d)",
zLogTab, iBI, sqlite3_vtab_distinct(pInfo)
);
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix) VALUES(%d,'colUsed',%lld)",
zLogTab, iBI, pInfo->colUsed
);
for(i=0; i<pInfo->nConstraint; i++){
int iCol = pInfo->aConstraint[i].iColumn;
int op = pInfo->aConstraint[i].op;
const char *zCol;
if( op==SQLITE_INDEX_CONSTRAINT_LIMIT
|| op==SQLITE_INDEX_CONSTRAINT_OFFSET
){
zCol = "";
}else if( iCol<0 ){
zCol = "rowid";
}else{
zCol = azColname[iCol];
}
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix,cn,op,ux)"
"VALUES(%d,'aConstraintUsage',%d,%Q,%d,%d)",
zLogTab, iBI,
i,
zCol,
pInfo->aConstraintUsage[i].argvIndex,
pInfo->aConstraintUsage[i].omit
);
}
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix)VALUES(%d,'idxNum',%d)",
zLogTab, iBI, pInfo->idxNum
);
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix)VALUES(%d,'estimatedCost',%f)",
zLogTab, iBI, pInfo->estimatedCost
);
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix)VALUES(%d,'estimatedRows',%lld)",
zLogTab, iBI, pInfo->estimatedRows
);
if( pInfo->idxStr ){
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix)VALUES(%d,'idxStr',%Q)",
zLogTab, iBI, pInfo->idxStr
);
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix)VALUES(%d,'needToFreeIdxStr',%d)",
zLogTab, iBI, pInfo->needToFreeIdxStr
);
}
if( pInfo->nOrderBy ){
sqlite3RunSql(db,pVTab,
"INSERT INTO temp.\"%w\"(bi,vn,ix)VALUES(%d,'orderByConsumed',%d)",
zLogTab, iBI, pInfo->orderByConsumed
);
}
}
static int vt02BestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pInfo){
int i;
int isEq[5];
int isUsed[5];
int argvIndex = 0;
int iOffset = -1;
void *pX = 0;
int flags = 0;
const char *zLogTab = 0;
int iFlagTerm = -1;
int iLogTerm = -1;
int iIn = -1;
vt02_vtab *pSelf;
pSelf = (vt02_vtab*)pVTab;
if( pSelf->busy ){
vt02ErrMsg(pVTab, "recursive use of vt02 prohibited");
return SQLITE_CONSTRAINT;
}
pSelf->busy++;
for(i=0; i<pInfo->nConstraint; i++){
sqlite3_value *pVal;
if( !pInfo->aConstraint[i].usable ) continue;
if( pInfo->aConstraint[i].op!=SQLITE_INDEX_CONSTRAINT_EQ ) continue;
switch( pInfo->aConstraint[i].iColumn ){
case VT02_COL_FLAGS:
if( sqlite3_vtab_rhs_value(pInfo, i, &pVal)==SQLITE_OK
&& sqlite3_value_type(pVal)==SQLITE_INTEGER
){
flags = sqlite3_value_int(pVal);
}
iFlagTerm = i;
break;
case VT02_COL_LOGTAB:
if( sqlite3_vtab_rhs_value(pInfo, i, &pVal)==SQLITE_OK
&& sqlite3_value_type(pVal)==SQLITE_TEXT
){
zLogTab = (const char*)sqlite3_value_text(pVal);
}
iLogTerm = i;
break;
}
}
memset(isEq, 0xff, sizeof(isEq));
memset(isUsed, 0xff, sizeof(isUsed));
for(i=0; i<pInfo->nConstraint; i++){
int j = pInfo->aConstraint[i].iColumn;
if( j>=VT02_COL_FLAGS ) continue;
if( pInfo->aConstraint[i].usable==0
&& (flags & VT02_IGNORE_USABLE)==0 ) continue;
if( j<0 ) j = VT02_COL_X;
switch( pInfo->aConstraint[i].op ){
case SQLITE_INDEX_CONSTRAINT_FUNCTION:
case SQLITE_INDEX_CONSTRAINT_EQ:
isEq[j] = i;
break;
case SQLITE_INDEX_CONSTRAINT_LT:
case SQLITE_INDEX_CONSTRAINT_LE:
case SQLITE_INDEX_CONSTRAINT_GT:
case SQLITE_INDEX_CONSTRAINT_GE:
isUsed[j] = i;
break;
case SQLITE_INDEX_CONSTRAINT_OFFSET:
iOffset = i;
break;
}
}
if( isEq[0]>=0 ){
pInfo->estimatedCost = 1;
pInfo->aConstraintUsage[isEq[0]].argvIndex = ++argvIndex;
if( flags & 0x20 ) pInfo->aConstraintUsage[isEq[0]].omit = 1;
pInfo->idxNum = 1;
}else if( isEq[1]<0 ){
pInfo->idxNum = 0;
pInfo->estimatedCost = 10000;
}else{
int v = 1000;
pInfo->aConstraintUsage[isEq[1]].argvIndex = ++argvIndex;
if( flags & 0x20 ) pInfo->aConstraintUsage[isEq[1]].omit = 1;
for(i=2; i<=4 && isEq[i]>=0; i++){
if( i==4 && sqlite3_vtab_in(pInfo, isEq[4], 0) ) break;
pInfo->aConstraintUsage[isEq[i]].argvIndex = ++argvIndex;
if( flags & 0x20 ) pInfo->aConstraintUsage[isEq[i]].omit = 1;
v /= 10;
}
pInfo->idxNum = i;
if( isEq[4]>=0 && sqlite3_vtab_in(pInfo,isEq[4],1) ){
iIn = isEq[4];
pInfo->aConstraintUsage[iIn].argvIndex = ++argvIndex;
if( flags & 0x20 ) pInfo->aConstraintUsage[iIn].omit = 1;
v /= 5;
i++;
pInfo->idxNum += 4;
}
pInfo->estimatedCost = v;
}
pInfo->estimatedRows = (sqlite3_int64)pInfo->estimatedCost;
if( pInfo->nOrderBy>0 && (flags & VT02_NO_SORT_OPT)==0 ){
if( pInfo->idxNum==1 ){
pInfo->orderByConsumed = 1;
}else
if( pInfo->aOrderBy[0].iColumn<=0
&& pInfo->aOrderBy[0].desc==0
){
pInfo->orderByConsumed = 1;
}else
if( sqlite3_vtab_distinct(pInfo)>=1 ){
unsigned int x = 0;
for(i=0; i<pInfo->nOrderBy; i++){
int iCol = pInfo->aOrderBy[i].iColumn;
if( iCol<0 ) iCol = 0;
x |= 1<<iCol;
}
if( sqlite3_vtab_distinct(pInfo)==2 ){
if( x==0x02 ){
pInfo->idxNum += 30;
pInfo->orderByConsumed = 1;
}else if( x==0x06 ){
pInfo->idxNum += 20;
pInfo->orderByConsumed = 1;
}else if( x==0x0e ){
pInfo->idxNum += 10;
pInfo->orderByConsumed = 1;
}else if( x & 0x01 ){
pInfo->orderByConsumed = 1;
}else if( x==0x1e ){
pInfo->orderByConsumed = 1;
}
}else{
if( x==0x02 ){
pInfo->orderByConsumed = 1;
}else if( x==0x06 ){
pInfo->orderByConsumed = 1;
}else if( x==0x0e ){
pInfo->orderByConsumed = 1;
}else if( x & 0x01 ){
pInfo->orderByConsumed = 1;
}else if( x==0x1e ){
pInfo->orderByConsumed = 1;
}
}
}
}
if( flags & VT02_ALLOC_IDXSTR ){
pInfo->idxStr = sqlite3_mprintf("test");
pInfo->needToFreeIdxStr = 1;
}
if( flags & VT02_BAD_IDXNUM ){
pInfo->idxNum += 1000;
}
if( iOffset>=0 ){
pInfo->aConstraintUsage[iOffset].argvIndex = ++argvIndex;
if( (flags & VT02_NO_OFFSET)==0
&& (pInfo->nOrderBy==0 || pInfo->orderByConsumed)
){
pInfo->aConstraintUsage[iOffset].omit = 1;
pInfo->idxNum += 100;
}
}
if( iFlagTerm>=0 ){
pInfo->aConstraintUsage[iFlagTerm].omit = 1;
pInfo->aConstraintUsage[iFlagTerm].argvIndex = ++argvIndex;
}
if( iLogTerm>=0 ){
pInfo->aConstraintUsage[iLogTerm].omit = 1;
pInfo->aConstraintUsage[iLogTerm].argvIndex = ++argvIndex;
}
if( flags & 0x40 ){
for(i=0; i<pInfo->nConstraint; i++){
if( pInfo->aConstraint[i].usable
&& pInfo->aConstraintUsage[i].argvIndex==0
){
pInfo->aConstraintUsage[i].argvIndex = ++argvIndex;
if( flags & 0x20 ) pInfo->aConstraintUsage[i].omit = 1;
}
}
}
if( zLogTab ){
static const char *azColname[] = {
"x", "a", "b", "c", "d", "flags", "logtab"
};
sqlite3 *db = ((vt02_vtab*)pVTab)->db;
sqlite3BestIndexLog(pInfo, zLogTab, db, azColname, pVTab);
}
pSelf->busy--;
pX = sqlite3_malloc(800);
if( pX==0 ) return SQLITE_NOMEM;
sqlite3_free(pX);
return pVTab->zErrMsg!=0 ? SQLITE_ERROR : SQLITE_OK;
}
const sqlite3_module vt02Module = {
2,
0,
vt02Connect,
vt02BestIndex,
vt02Disconnect,
vt02Disconnect,
vt02Open,
vt02Close,
vt02Filter,
vt02Next,
vt02Eof,
vt02Column,
vt02Rowid,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
};
static void vt02CoreInit(sqlite3 *db){
static const char zPkXSchema[] =
"CREATE TABLE x(x INT NOT NULL PRIMARY KEY, a INT, b INT, c INT, d INT,"
" flags INT HIDDEN, logtab TEXT HIDDEN);";
static const char zPkABCDSchema[] =
"CREATE TABLE x(x INT, a INT NOT NULL, b INT NOT NULL, c INT NOT NULL, "
"d INT NOT NULL, flags INT HIDDEN, logtab TEXT HIDDEN, "
"PRIMARY KEY(a,b,c,d));";
sqlite3_create_module(db, "vt02", &vt02Module, 0);
sqlite3_create_module(db, "vt02pkx", &vt02Module, (void*)zPkXSchema);
sqlite3_create_module(db, "vt02pkabcd", &vt02Module, (void*)zPkABCDSchema);
}
#ifdef TH3_VERSION
static void vt02_init(th3state *p, int iDb, char *zArg){
vt02CoreInit(th3dbPointer(p, iDb));
}
#else
#ifdef _WIN32
__declspec(dllexport)
#endif
int sqlite3_vt02_init(
sqlite3 *db,
char **pzErrMsg,
const sqlite3_api_routines *pApi
){
SQLITE_EXTENSION_INIT2(pApi);
vt02CoreInit(db);
return SQLITE_OK;
}
#endif