/ Check-in [e30c7414fe]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:In shared-schema mode, handle the case where a connection has created a virtual-table object, but is later assigned a different shared-schema object for which the virtual-table schema has not yet been initialized.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | reuse-schema
Files: files | file ages | folders
SHA3-256: e30c7414fe483fcb68aeedd364dc5a3da62b01a80808a917016a9f148f1f3130
User & Date: dan 2019-08-09 14:54:44
Wiki:reuse-schema
Context
2019-08-13
15:22
Merge latest trunk changes with this branch. check-in: 5b4689d89c user: dan tags: reuse-schema
2019-08-09
14:54
In shared-schema mode, handle the case where a connection has created a virtual-table object, but is later assigned a different shared-schema object for which the virtual-table schema has not yet been initialized. check-in: e30c7414fe user: dan tags: reuse-schema
2019-08-08
15:47
Fix spurious "no such table: x1" errors in shared-schema mode that could occur when a query that is a join across two or more databases needs to call the xConnect() methods of a virtual table. check-in: edf45cd7c6 user: dan tags: reuse-schema
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vtab.c.

   144    144   VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
   145    145     VTable *pVtab;
   146    146     assert( IsVirtual(pTab) );
   147    147   #ifdef SQLITE_ENABLE_SHARED_SCHEMA
   148    148     if( IsSharedSchema(db) ){
   149    149       int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
   150    150       if( iDb!=1 ){
   151         -      for(pVtab=db->aDb[iDb].pVTable; pVtab; pVtab=pVtab->pNext){
   152         -        if( sqlite3StrICmp(pTab->zName, pVtab->zName)==0 ) break;
          151  +      VTable **pp;
          152  +      for(pp=&db->aDb[iDb].pVTable; *pp; pp=&(*pp)->pNext){
          153  +        if( sqlite3StrICmp(pTab->zName, (*pp)->zName)==0 ) break;
          154  +      }
          155  +      pVtab = *pp;
          156  +      if( pVtab && pTab->nCol<=0 ){
          157  +        *pp = pVtab->pNext;
          158  +        sqlite3VtabUnlock(pVtab);
          159  +        pVtab = 0;
   153    160         }
   154    161         return pVtab;
   155    162       }
   156    163     }
   157    164   #endif /* ifdef SQLITE_ENABLE_SHARED_SCHEMA */
   158    165     for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
   159    166     return pVtab;
................................................................................
   660    667     sqlite3 *db = pParse->db;
   661    668     const char *zMod;
   662    669     Module *pMod;
   663    670     int rc;
   664    671   
   665    672     assert( pTab );
   666    673     if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){
          674  +    assert( !IsVirtual(pTab) || pTab->nCol>0 );
   667    675       return SQLITE_OK;
   668    676     }
   669    677   
   670    678     /* Locate the required virtual table module */
   671    679     zMod = pTab->azModuleArg[0];
   672    680     pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
   673    681   

Changes to test/reuse6.test.

   102    102     }
   103    103   
   104    104     sqlite3 db1 test.db -shared-schema 1
   105    105     do_execsql_test -db db1 3.1 {
   106    106       ATTACH 'test.db2' AS aux;
   107    107     }
   108    108   
   109         -breakpoint
   110    109     do_execsql_test -db db1 3.2 {
   111    110       SELECT * FROM main.ft, aux.t1;
   112    111     }
   113    112   }
          113  +db1 close
          114  +
          115  +#-------------------------------------------------------------------------
          116  +reset_db
          117  +forcedelete test.db2
          118  +ifcapable fts5 {
          119  +  do_execsql_test 4.0 {
          120  +    CREATE VIRTUAL TABLE ft USING fts5(a, b);
          121  +  }
          122  +  forcecopy test.db test.db2
          123  +
          124  +  sqlite3 db1 test.db -shared-schema 1
          125  +  do_execsql_test -db db1 4.1 {
          126  +    ATTACH 'test.db2' AS aux;
          127  +    SELECT * FROM main.ft;
          128  +    SELECT * FROM aux.ft;
          129  +  }
   114    130   
          131  +  do_execsql_test -db db1 4.2 {
          132  +    SELECT * FROM main.ft, aux.ft
          133  +  }
          134  +}
   115    135   
   116    136   
   117    137   
   118    138   
   119    139   
   120    140   
   121    141   
   122    142   finish_test
   123    143