| Index: third_party/sqlite/src/src/test8.c
|
| diff --git a/third_party/sqlite/src/src/test8.c b/third_party/sqlite/src/src/test8.c
|
| index b3e6058acb19d331715a9a0cdd0d39d9ce6c0417..8bc835d638c322ce4c0353bdfd2ed46d8d0b69dd 100644
|
| --- a/third_party/sqlite/src/src/test8.c
|
| +++ b/third_party/sqlite/src/src/test8.c
|
| @@ -192,7 +192,7 @@ static int getColumnNames(
|
| rc = SQLITE_NOMEM;
|
| goto out;
|
| }
|
| - nBytes += strlen(zName)+1;
|
| + nBytes += (int)strlen(zName)+1;
|
| }
|
| aCol = (char **)sqlite3MallocZero(nBytes);
|
| if( !aCol ){
|
| @@ -265,6 +265,7 @@ static int getIndexArray(
|
| while( pStmt && sqlite3_step(pStmt)==SQLITE_ROW ){
|
| const char *zIdx = (const char *)sqlite3_column_text(pStmt, 1);
|
| sqlite3_stmt *pStmt2 = 0;
|
| + if( zIdx==0 ) continue;
|
| zSql = sqlite3_mprintf("PRAGMA index_info(%s)", zIdx);
|
| if( !zSql ){
|
| rc = SQLITE_NOMEM;
|
| @@ -831,13 +832,10 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
| if( !isIgnoreUsable && !pConstraint->usable ) continue;
|
|
|
| iCol = pConstraint->iColumn;
|
| - if( pVtab->aIndex[iCol] || iCol<0 ){
|
| - char *zCol = pVtab->aCol[iCol];
|
| + if( iCol<0 || pVtab->aIndex[iCol] ){
|
| + char *zCol = iCol>=0 ? pVtab->aCol[iCol] : "rowid";
|
| char *zOp = 0;
|
| useIdx = 1;
|
| - if( iCol<0 ){
|
| - zCol = "rowid";
|
| - }
|
| switch( pConstraint->op ){
|
| case SQLITE_INDEX_CONSTRAINT_EQ:
|
| zOp = "="; break;
|
| @@ -870,13 +868,12 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
| ** on a column that this virtual table has an index for, then consume
|
| ** the ORDER BY clause.
|
| */
|
| - if( pIdxInfo->nOrderBy==1 && pVtab->aIndex[pIdxInfo->aOrderBy->iColumn] ){
|
| + if( pIdxInfo->nOrderBy==1 && (
|
| + pIdxInfo->aOrderBy->iColumn<0 ||
|
| + pVtab->aIndex[pIdxInfo->aOrderBy->iColumn]) ){
|
| int iCol = pIdxInfo->aOrderBy->iColumn;
|
| - char *zCol = pVtab->aCol[iCol];
|
| + char *zCol = iCol>=0 ? pVtab->aCol[iCol] : "rowid";
|
| char *zDir = pIdxInfo->aOrderBy->desc?"DESC":"ASC";
|
| - if( iCol<0 ){
|
| - zCol = "rowid";
|
| - }
|
| zNew = sqlite3_mprintf(" ORDER BY %s %s", zCol, zDir);
|
| string_concat(&zQuery, zNew, 1, &rc);
|
| pIdxInfo->orderByConsumed = 1;
|
| @@ -895,7 +892,7 @@ static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
|
| pIdxInfo->estimatedCost = cost;
|
| }else if( useIdx ){
|
| /* Approximation of log2(nRow). */
|
| - for( ii=0; ii<(sizeof(int)*8); ii++ ){
|
| + for( ii=0; ii<(sizeof(int)*8)-1; ii++ ){
|
| if( nRow & (1<<ii) ){
|
| pIdxInfo->estimatedCost = (double)ii;
|
| }
|
| @@ -1221,7 +1218,7 @@ static int echoRename(sqlite3_vtab *vtab, const char *zNewName){
|
| }
|
|
|
| if( p->isPattern ){
|
| - int nThis = strlen(p->zThis);
|
| + int nThis = (int)strlen(p->zThis);
|
| char *zSql = sqlite3_mprintf("ALTER TABLE %s RENAME TO %s%s",
|
| p->zTableName, zNewName, &p->zTableName[nThis]
|
| );
|
| @@ -1232,12 +1229,50 @@ static int echoRename(sqlite3_vtab *vtab, const char *zNewName){
|
| return rc;
|
| }
|
|
|
| +static int echoSavepoint(sqlite3_vtab *pVTab, int iSavepoint){
|
| + assert( pVTab );
|
| + return SQLITE_OK;
|
| +}
|
| +
|
| +static int echoRelease(sqlite3_vtab *pVTab, int iSavepoint){
|
| + assert( pVTab );
|
| + return SQLITE_OK;
|
| +}
|
| +
|
| +static int echoRollbackTo(sqlite3_vtab *pVTab, int iSavepoint){
|
| + assert( pVTab );
|
| + return SQLITE_OK;
|
| +}
|
| +
|
| /*
|
| ** A virtual table module that merely "echos" the contents of another
|
| ** table (like an SQL VIEW).
|
| */
|
| static sqlite3_module echoModule = {
|
| - 0, /* iVersion */
|
| + 1, /* iVersion */
|
| + echoCreate,
|
| + echoConnect,
|
| + echoBestIndex,
|
| + echoDisconnect,
|
| + echoDestroy,
|
| + echoOpen, /* xOpen - open a cursor */
|
| + echoClose, /* xClose - close a cursor */
|
| + echoFilter, /* xFilter - configure scan constraints */
|
| + echoNext, /* xNext - advance a cursor */
|
| + echoEof, /* xEof */
|
| + echoColumn, /* xColumn - read data */
|
| + echoRowid, /* xRowid - read data */
|
| + echoUpdate, /* xUpdate - write data */
|
| + echoBegin, /* xBegin - begin transaction */
|
| + echoSync, /* xSync - sync transaction */
|
| + echoCommit, /* xCommit - commit transaction */
|
| + echoRollback, /* xRollback - rollback transaction */
|
| + echoFindFunction, /* xFindFunction - function overloading */
|
| + echoRename /* xRename - rename the table */
|
| +};
|
| +
|
| +static sqlite3_module echoModuleV2 = {
|
| + 2, /* iVersion */
|
| echoCreate,
|
| echoConnect,
|
| echoBestIndex,
|
| @@ -1257,12 +1292,16 @@ static sqlite3_module echoModule = {
|
| echoRollback, /* xRollback - rollback transaction */
|
| echoFindFunction, /* xFindFunction - function overloading */
|
| echoRename, /* xRename - rename the table */
|
| + echoSavepoint,
|
| + echoRelease,
|
| + echoRollbackTo
|
| };
|
|
|
| /*
|
| ** Decode a pointer to an sqlite3 object.
|
| */
|
| extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
|
| +extern const char *sqlite3ErrName(int);
|
|
|
| static void moduleDestroy(void *p){
|
| sqlite3_free(p);
|
| @@ -1277,6 +1316,7 @@ static int register_echo_module(
|
| int objc, /* Number of arguments */
|
| Tcl_Obj *CONST objv[] /* Command arguments */
|
| ){
|
| + int rc;
|
| sqlite3 *db;
|
| EchoModule *pMod;
|
| if( objc!=2 ){
|
| @@ -1284,9 +1324,24 @@ static int register_echo_module(
|
| return TCL_ERROR;
|
| }
|
| if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;
|
| +
|
| + /* Virtual table module "echo" */
|
| pMod = sqlite3_malloc(sizeof(EchoModule));
|
| pMod->interp = interp;
|
| - sqlite3_create_module_v2(db, "echo", &echoModule, (void*)pMod, moduleDestroy);
|
| + rc = sqlite3_create_module_v2(
|
| + db, "echo", &echoModule, (void*)pMod, moduleDestroy
|
| + );
|
| +
|
| + /* Virtual table module "echo_v2" */
|
| + if( rc==SQLITE_OK ){
|
| + pMod = sqlite3_malloc(sizeof(EchoModule));
|
| + pMod->interp = interp;
|
| + rc = sqlite3_create_module_v2(db, "echo_v2",
|
| + &echoModuleV2, (void*)pMod, moduleDestroy
|
| + );
|
| + }
|
| +
|
| + Tcl_SetResult(interp, (char *)sqlite3ErrName(rc), TCL_STATIC);
|
| return TCL_OK;
|
| }
|
|
|
| @@ -1328,8 +1383,8 @@ int Sqlitetest8_Init(Tcl_Interp *interp){
|
| Tcl_ObjCmdProc *xProc;
|
| void *clientData;
|
| } aObjCmd[] = {
|
| - { "register_echo_module", register_echo_module, 0 },
|
| - { "sqlite3_declare_vtab", declare_vtab, 0 },
|
| + { "register_echo_module", register_echo_module, 0 },
|
| + { "sqlite3_declare_vtab", declare_vtab, 0 },
|
| };
|
| int i;
|
| for(i=0; i<sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
|
|
|