Hello Richard !

Thanks for reply !

I found the second point that was also controlling the restriction of referencing objects in other databases.

Now it seems to work and I'll leave the initialization to the user level code for now, when the usage normalize I'll revisit it again to see if is worth move that code to my custom sqlite3.

Cheers !

==== ////////////////my changes

  /*
  **   PRAGMA use_attached_dbs
  **   PRAGMA use_attached_dbs = ON/OFF
  **
  ** The first form reports the current setting for the
  ** use_attached_dbs flag.  The second form changes the use_attached_dbs
  ** flag setting and reports thenew value.
  */
  case PragTyp_USE_ATTACHED_DBS: {
    int b = -1;
    if( zRight ){
      b = sqlite3GetBoolean(zRight, 0);
      sqlite3_limit(db, SQLITE_LIMIT_USE_ATTACHED_DBS, b);
    }
    b = sqlite3_limit(db, SQLITE_LIMIT_USE_ATTACHED_DBS, -1);
    returnSingleInt(v, "use_attached_dbs", b);
    break;
  }

====

Table *sqlite3LocateTableItem(
  Parse *pParse,
  u32 flags,
  struct SrcList_item *p
){
  const char *zDb;
int use_attached_dbs = sqlite3_limit(pParse->db, SQLITE_LIMIT_USE_ATTACHED_DBS, -1); ////////////////my changes
  assert( p->pSchema==0 || p->zDatabase==0 );
  if( p->pSchema && !use_attached_dbs){ ////////////////my changes
    int iDb = sqlite3SchemaToIndex(pParse->db, p->pSchema);
    zDb = pParse->db->aDb[iDb].zDbSName;
  }else{
    zDb = p->zDatabase;
  }
  return sqlite3LocateTable(pParse, flags, p->zName, zDb);
}
====

int sqlite3FixSrcList(
  DbFixer *pFix,       /* Context of the fixation */
  SrcList *pList       /* The Source list to check and modify */
){
  int i, use_attached_dbs;
  const char *zDb;
  struct SrcList_item *pItem;

use_attached_dbs = sqlite3_limit(pFix->pParse->db, SQLITE_LIMIT_USE_ATTACHED_DBS, -1); ////////////////my changes
  if( NEVER(pList==0) ) return 0;
  zDb = pFix->zDb;
  for(i=0, pItem=pList->a; i<pList->nSrc; i++, pItem++){
    if( pFix->bVarOnly==0 ){
if( pItem->zDatabase && !use_attached_dbs && sqlite3StrICmp(pItem->zDatabase, zDb) ){ ////////////////my changes
        sqlite3ErrorMsg(pFix->pParse,
            "%s %T cannot reference objects in database %s",
            pFix->zType, pFix->pName, pItem->zDatabase);
        return 1;
      }
      sqlite3DbFree(pFix->pParse->db, pItem->zDatabase);
      pItem->zDatabase = 0;
      pItem->pSchema = pFix->pSchema;
    }
#if !defined(SQLITE_OMIT_VIEW) || !defined(SQLITE_OMIT_TRIGGER)
    if( sqlite3FixSelect(pFix, pItem->pSelect) ) return 1;
    if( sqlite3FixExpr(pFix, pItem->pOn) ) return 1;
#endif
  }
  return 0;
}

====

On 04/10/16 17:30, Richard Hipp wrote:
On 10/4/16, Domingo Alvarez Duarte <mingo...@gmail.com> wrote:
The problem is I didn't found yet the point where I should intercept the
"openDatabase" where I plan to check if there is a table named for
example "use_attached_dbs" and then attach the databases on that table
and then reread the schema to make the views work.

The place to do so probably is at the end of "openDatabase", can someone
shed some light here ?

The sqlite3Init() routine found at
https://www.sqlite.org/src/artifact/b1140c3d0cf59bc8?ln=355


_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to