/ 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 Unified Diffs Show Whitespace Changes Patch

Changes to src/vtab.c.

144
145
146
147
148
149
150

151
152






153
154
155
156
157
158
159
...
660
661
662
663
664
665
666

667
668
669
670
671
672
673
VTable *sqlite3GetVTable(sqlite3 *db, Table *pTab){
  VTable *pVtab;
  assert( IsVirtual(pTab) );
#ifdef SQLITE_ENABLE_SHARED_SCHEMA
  if( IsSharedSchema(db) ){
    int iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
    if( iDb!=1 ){

      for(pVtab=db->aDb[iDb].pVTable; pVtab; pVtab=pVtab->pNext){
        if( sqlite3StrICmp(pTab->zName, pVtab->zName)==0 ) break;






      }
      return pVtab;
    }
  }
#endif /* ifdef SQLITE_ENABLE_SHARED_SCHEMA */
  for(pVtab=pTab->pVTable; pVtab && pVtab->db!=db; pVtab=pVtab->pNext);
  return pVtab;
................................................................................
  sqlite3 *db = pParse->db;
  const char *zMod;
  Module *pMod;
  int rc;

  assert( pTab );
  if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){

    return SQLITE_OK;
  }

  /* Locate the required virtual table module */
  zMod = pTab->azModuleArg[0];
  pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);








>
|
|
>
>
>
>
>
>







 







>







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

  assert( pTab );
  if( !IsVirtual(pTab) || sqlite3GetVTable(db, pTab) ){
    assert( !IsVirtual(pTab) || pTab->nCol>0 );
    return SQLITE_OK;
  }

  /* Locate the required virtual table module */
  zMod = pTab->azModuleArg[0];
  pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);

Changes to test/reuse6.test.

102
103
104
105
106
107
108
109
110
111
112
113

114




















115
116
117
118
119
120
121
122
123
  }

  sqlite3 db1 test.db -shared-schema 1
  do_execsql_test -db db1 3.1 {
    ATTACH 'test.db2' AS aux;
  }

breakpoint
  do_execsql_test -db db1 3.2 {
    SELECT * FROM main.ft, aux.t1;
  }
}





























finish_test








<




>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









102
103
104
105
106
107
108

109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  }

  sqlite3 db1 test.db -shared-schema 1
  do_execsql_test -db db1 3.1 {
    ATTACH 'test.db2' AS aux;
  }


  do_execsql_test -db db1 3.2 {
    SELECT * FROM main.ft, aux.t1;
  }
}
db1 close

#-------------------------------------------------------------------------
reset_db
forcedelete test.db2
ifcapable fts5 {
  do_execsql_test 4.0 {
    CREATE VIRTUAL TABLE ft USING fts5(a, b);
  }
  forcecopy test.db test.db2

  sqlite3 db1 test.db -shared-schema 1
  do_execsql_test -db db1 4.1 {
    ATTACH 'test.db2' AS aux;
    SELECT * FROM main.ft;
    SELECT * FROM aux.ft;
  }

  do_execsql_test -db db1 4.2 {
    SELECT * FROM main.ft, aux.ft
  }
}







finish_test