Index: src/vdbe.c ================================================================== --- src/vdbe.c +++ src/vdbe.c @@ -6007,17 +6007,28 @@ break; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ #ifndef SQLITE_OMIT_VIRTUALTABLE -/* Opcode: VCreate P1 * * P4 * +/* Opcode: VCreate P1 P2 * * * ** -** P4 is the name of a virtual table in database P1. Call the xCreate method -** for that table. +** P2 is a register that holds the name of a virtual table in database +** P1. Call the xCreate method for that table. */ case OP_VCreate: { - rc = sqlite3VtabCallCreate(db, pOp->p1, pOp->p4.z, &p->zErrMsg); + Mem sMem; /* For storing the record being decoded */ + memset(&sMem, 0, sizeof(sMem)); + sMem.db = db; + rc = sqlite3VdbeMemCopy(&sMem, &aMem[pOp->p2]); + if( rc==SQLITE_OK ){ + const char *zTab = (const char*)sqlite3_value_text(&sMem); + assert( zTab || db->mallocFailed ); + if( zTab ){ + rc = sqlite3VtabCallCreate(db, pOp->p1, zTab, &p->zErrMsg); + } + } + sqlite3VdbeMemRelease(&sMem); break; } #endif /* SQLITE_OMIT_VIRTUALTABLE */ #ifndef SQLITE_OMIT_VIRTUALTABLE Index: src/vtab.c ================================================================== --- src/vtab.c +++ src/vtab.c @@ -387,10 +387,11 @@ */ if( !db->init.busy ){ char *zStmt; char *zWhere; int iDb; + int iReg; Vdbe *v; /* Compute the complete text of the CREATE VIRTUAL TABLE statement */ if( pEnd ){ pParse->sNameToken.n = (int)(pEnd->z - pParse->sNameToken.z) + pEnd->n; @@ -421,12 +422,14 @@ sqlite3ChangeCookie(pParse, iDb); sqlite3VdbeAddOp2(v, OP_Expire, 0, 0); zWhere = sqlite3MPrintf(db, "name='%q' AND type='table'", pTab->zName); sqlite3VdbeAddParseSchemaOp(v, iDb, zWhere); - sqlite3VdbeAddOp4(v, OP_VCreate, iDb, 0, 0, - pTab->zName, sqlite3Strlen30(pTab->zName) + 1); + + iReg = ++pParse->nMem; + sqlite3VdbeAddOp4(v, OP_String8, 0, iReg, 0, pTab->zName, 0); + sqlite3VdbeAddOp2(v, OP_VCreate, iDb, iReg); } /* If we are rereading the sqlite_master table create the in-memory ** record of the table. The xConnect() method is not called until ** the first time the virtual table is used in an SQL statement. This Index: test/vtab2.test ================================================================== --- test/vtab2.test +++ test/vtab2.test @@ -8,14 +8,14 @@ # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. # -# $Id: vtab2.test,v 1.9 2008/10/13 10:37:50 danielk1977 Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl +set testprefix vtab2 ifcapable !vtab||!schema_pragmas { finish_test return } @@ -130,7 +130,25 @@ } } {} do_test vtab2-4.5 { execsql { SELECT * FROM fkey } } {t1 a} + +#------------------------------------------------------------------------- +# +reset_db +do_execsql_test 5.1 { + PRAGMA encoding='UTF16'; +} + +do_test 5.2 { + sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C8 USING fts3 } +} {0 {}} + +do_test 5.3 { + sqlite3_exec_hex db { CREATE VIRTUAL TABLE %C9 USING s } +} {/1 {malformed database schema.* already exists}/} + + finish_test +