/ Check-in [7aaf8772]
Login

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

Overview
Comment:Increase the upper bound on SQLITE_MAX_ATTACHED from 30 to 62.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 7aaf8772274422f5020fad9eea490e195170720f
User & Date: drh 2011-03-23 18:22:34
References
2011-04-03
18:19
Make sure that the constant 1 is cast to yDbType before shifting to create an attached database mask. This check-in is a follow-up and fix to the [7aaf8772274422] change that increases the maximum number of attached databases from 30 to 62. check-in: e2a09ea7 user: drh tags: trunk
Context
2011-03-23
22:02
Change the xSetSyscall methods of the VFS so that they do not cast object pointers into function pointers. Fix other unrelated compiler warnings. check-in: e059152a user: drh tags: trunk
18:22
Increase the upper bound on SQLITE_MAX_ATTACHED from 30 to 62. check-in: 7aaf8772 user: drh tags: trunk
17:10
Fix a bug in fts4 to do with matchinfo and deferred tokens. check-in: 30d42dc6 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

   144    144       /* The cookie mask contains one bit for each database file open.
   145    145       ** (Bit 0 is for main, bit 1 is for temp, and so forth.)  Bits are
   146    146       ** set for each database that is used.  Generate code to start a
   147    147       ** transaction on each used database and to verify the schema cookie
   148    148       ** on each used database.
   149    149       */
   150    150       if( pParse->cookieGoto>0 ){
   151         -      u32 mask;
          151  +      tAttachMask mask;
   152    152         int iDb;
   153    153         sqlite3VdbeJumpHere(v, pParse->cookieGoto-1);
   154    154         for(iDb=0, mask=1; iDb<db->nDb; mask<<=1, iDb++){
   155    155           if( (mask & pParse->cookieMask)==0 ) continue;
   156    156           sqlite3VdbeUsesBtree(v, iDb);
   157    157           sqlite3VdbeAddOp2(v,OP_Transaction, iDb, (mask & pParse->writeMask)!=0);
   158    158           if( db->init.busy==0 ){
................................................................................
  3440   3440     if( pToplevel->cookieGoto==0 ){
  3441   3441       Vdbe *v = sqlite3GetVdbe(pToplevel);
  3442   3442       if( v==0 ) return;  /* This only happens if there was a prior error */
  3443   3443       pToplevel->cookieGoto = sqlite3VdbeAddOp2(v, OP_Goto, 0, 0)+1;
  3444   3444     }
  3445   3445     if( iDb>=0 ){
  3446   3446       sqlite3 *db = pToplevel->db;
  3447         -    int mask;
         3447  +    tAttachMask mask;
  3448   3448   
  3449   3449       assert( iDb<db->nDb );
  3450   3450       assert( db->aDb[iDb].pBt!=0 || iDb==1 );
  3451   3451       assert( iDb<SQLITE_MAX_ATTACHED+2 );
  3452         -    mask = 1<<iDb;
         3452  +    mask = ((tAttachMask)1)<<iDb;
  3453   3453       if( (pToplevel->cookieMask & mask)==0 ){
  3454   3454         pToplevel->cookieMask |= mask;
  3455   3455         pToplevel->cookieValue[iDb] = db->aDb[iDb].pSchema->schema_cookie;
  3456   3456         if( !OMIT_TEMPDB && iDb==1 ){
  3457   3457           sqlite3OpenTempDatabase(pToplevel);
  3458   3458         }
  3459   3459       }
................................................................................
  3472   3472   ** rollback the whole transaction.  For operations where all constraints
  3473   3473   ** can be checked before any changes are made to the database, it is never
  3474   3474   ** necessary to undo a write and the checkpoint should not be set.
  3475   3475   */
  3476   3476   void sqlite3BeginWriteOperation(Parse *pParse, int setStatement, int iDb){
  3477   3477     Parse *pToplevel = sqlite3ParseToplevel(pParse);
  3478   3478     sqlite3CodeVerifySchema(pParse, iDb);
  3479         -  pToplevel->writeMask |= 1<<iDb;
         3479  +  pToplevel->writeMask |= ((tAttachMask)1)<<iDb;
  3480   3480     pToplevel->isMultiWrite |= setStatement;
  3481   3481   }
  3482   3482   
  3483   3483   /*
  3484   3484   ** Indicate that the statement currently under construction might write
  3485   3485   ** more than one entry (example: deleting one row then inserting another,
  3486   3486   ** inserting multiple rows in a table, or inserting a row and index entries.)

Changes to src/main.c.

  1719   1719   #endif
  1720   1720   #if SQLITE_MAX_VDBE_OP<40
  1721   1721   # error SQLITE_MAX_VDBE_OP must be at least 40
  1722   1722   #endif
  1723   1723   #if SQLITE_MAX_FUNCTION_ARG<0 || SQLITE_MAX_FUNCTION_ARG>1000
  1724   1724   # error SQLITE_MAX_FUNCTION_ARG must be between 0 and 1000
  1725   1725   #endif
  1726         -#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>30
  1727         -# error SQLITE_MAX_ATTACHED must be between 0 and 30
         1726  +#if SQLITE_MAX_ATTACHED<0 || SQLITE_MAX_ATTACHED>62
         1727  +# error SQLITE_MAX_ATTACHED must be between 0 and 62
  1728   1728   #endif
  1729   1729   #if SQLITE_MAX_LIKE_PATTERN_LENGTH<1
  1730   1730   # error SQLITE_MAX_LIKE_PATTERN_LENGTH must be at least 1
  1731   1731   #endif
  1732   1732   #if SQLITE_MAX_COLUMN>32767
  1733   1733   # error SQLITE_MAX_COLUMN must not exceed 32767
  1734   1734   #endif

Changes to src/sqliteInt.h.

  2121   2121     Trigger *pTrigger;      /* Trigger this program was coded from */
  2122   2122     int orconf;             /* Default ON CONFLICT policy */
  2123   2123     SubProgram *pProgram;   /* Program implementing pTrigger/orconf */
  2124   2124     u32 aColmask[2];        /* Masks of old.*, new.* columns accessed */
  2125   2125     TriggerPrg *pNext;      /* Next entry in Parse.pTriggerPrg list */
  2126   2126   };
  2127   2127   
         2128  +/* Datatype for the bitmask of all attached databases */
         2129  +#if SQLITE_MAX_ATTACHED>30
         2130  +  typedef sqlite3_uint64 tAttachMask;
         2131  +#else
         2132  +  typedef unsigned int tAttachMask;
         2133  +#endif
         2134  +
  2128   2135   /*
  2129   2136   ** An SQL parser context.  A copy of this structure is passed through
  2130   2137   ** the parser and down into all the parser action routine in order to
  2131   2138   ** carry around information that is global to the entire parse.
  2132   2139   **
  2133   2140   ** The structure is divided into two parts.  When the parser and code
  2134   2141   ** generate call themselves recursively, the first part of the structure
................................................................................
  2169   2176       int iTable;           /* Table cursor number */
  2170   2177       int iColumn;          /* Table column number */
  2171   2178       u8 tempReg;           /* iReg is a temp register that needs to be freed */
  2172   2179       int iLevel;           /* Nesting level */
  2173   2180       int iReg;             /* Reg with value of this column. 0 means none. */
  2174   2181       int lru;              /* Least recently used entry has the smallest value */
  2175   2182     } aColCache[SQLITE_N_COLCACHE];  /* One for each column cache entry */
  2176         -  u32 writeMask;       /* Start a write transaction on these databases */
  2177         -  u32 cookieMask;      /* Bitmask of schema verified databases */
         2183  +  tAttachMask writeMask;  /* Start a write transaction on these databases */
         2184  +  tAttachMask cookieMask; /* Bitmask of schema verified databases */
  2178   2185     u8 isMultiWrite;     /* True if statement may affect/insert multiple rows */
  2179   2186     u8 mayAbort;         /* True if statement may throw an ABORT exception */
  2180   2187     int cookieGoto;      /* Address of OP_Goto to cookie verifier subroutine */
  2181   2188     int cookieValue[SQLITE_MAX_ATTACHED+2];  /* Values of cookies to verify */
  2182   2189   #ifndef SQLITE_OMIT_SHARED_CACHE
  2183   2190     int nTableLock;        /* Number of locks in aTableLock */
  2184   2191     TableLock *aTableLock; /* Required table locks for shared-cache mode */

Changes to src/vdbeInt.h.

   298    298     u8 runOnlyOnce;         /* Automatically expire on reset */
   299    299     u8 minWriteFileFormat;  /* Minimum file format for writable database files */
   300    300     u8 inVtabMethod;        /* See comments above */
   301    301     u8 usesStmtJournal;     /* True if uses a statement journal */
   302    302     u8 readOnly;            /* True for read-only statements */
   303    303     u8 isPrepareV2;         /* True if prepared with prepare_v2() */
   304    304     int nChange;            /* Number of db changes made since last reset */
   305         -  int btreeMask;          /* Bitmask of db->aDb[] entries referenced */
          305  +  tAttachMask btreeMask;  /* Bitmask of db->aDb[] entries referenced */
   306    306     int iStatement;         /* Statement number (or 0 if has not opened stmt) */
   307    307     int aCounter[3];        /* Counters used by sqlite3_stmt_status() */
   308    308     BtreeMutexArray aMutex; /* An array of Btree used here and needing locks */
   309    309   #ifndef SQLITE_OMIT_TRACE
   310    310     i64 startTime;          /* Time when query started - used for profiling */
   311    311   #endif
   312    312     i64 nFkConstraint;      /* Number of imm. FK constraints this VM */

Changes to src/vdbeaux.c.

   946    946   **
   947    947   ** The prepared statement has to know in advance which Btree objects
   948    948   ** will be used so that it can acquire mutexes on them all in sorted
   949    949   ** order (via sqlite3VdbeMutexArrayEnter().  Mutexes are acquired
   950    950   ** in order (and released in reverse order) to avoid deadlocks.
   951    951   */
   952    952   void sqlite3VdbeUsesBtree(Vdbe *p, int i){
   953         -  int mask;
   954         -  assert( i>=0 && i<p->db->nDb && i<sizeof(u32)*8 );
          953  +  tAttachMask mask;
          954  +  assert( i>=0 && i<p->db->nDb && i<sizeof(tAttachMask)*8 );
   955    955     assert( i<(int)sizeof(p->btreeMask)*8 );
   956    956     mask = ((u32)1)<<i;
   957    957     if( (p->btreeMask & mask)==0 ){
   958    958       p->btreeMask |= mask;
   959    959       sqlite3BtreeMutexArrayInsert(&p->aMutex, p->db->aDb[i].pBt);
   960    960     }
   961    961   }

Changes to test/attach.test.

   148    148   } {1 {database MAIN is already in use}}
   149    149   do_test attach-1.18 {
   150    150     catchsql {
   151    151       ATTACH 'test.db' as db10;
   152    152       ATTACH 'test.db' as db11;
   153    153     }
   154    154   } {0 {}}
   155         -do_test attach-1.19 {
   156         -  catchsql {
   157         -    ATTACH 'test.db' as db12;
   158         -  }
   159         -} {1 {too many attached databases - max 10}}
   160         -do_test attach-1.19.1 {
   161         -  db errorcode
   162         -} {1}
          155  +if {$SQLITE_MAX_ATTACHED==10} {
          156  +  do_test attach-1.19 {
          157  +    catchsql {
          158  +      ATTACH 'test.db' as db12;
          159  +    }
          160  +  } {1 {too many attached databases - max 10}}
          161  +  do_test attach-1.19.1 {
          162  +    db errorcode
          163  +  } {1}
          164  +}
   163    165   do_test attach-1.20.1 {
   164    166     execsql {
   165    167       DETACH db5;
   166    168     }
   167    169   } {}
   168    170   ifcapable schema_pragmas {
   169    171   do_test attach-1.20.2 {
................................................................................
   175    177     execsql {select * from sqlite_temp_master}
   176    178   }
   177    179   do_test attach-1.21 {
   178    180     catchsql {
   179    181       ATTACH 'test.db' as db12;
   180    182     }
   181    183   } {0 {}}
   182         -do_test attach-1.22 {
   183         -  catchsql {
   184         -    ATTACH 'test.db' as db13;
   185         -  }
   186         -} {1 {too many attached databases - max 10}}
   187         -do_test attach-1.22.1 {
   188         -  db errorcode
   189         -} {1}
          184  +if {$SQLITE_MAX_ATTACHED==10} {
          185  +  do_test attach-1.22 {
          186  +    catchsql {
          187  +      ATTACH 'test.db' as db13;
          188  +    }
          189  +  } {1 {too many attached databases - max 10}}
          190  +  do_test attach-1.22.1 {
          191  +    db errorcode
          192  +  } {1}
          193  +}
   190    194   do_test attach-1.23 {
   191    195     catchsql {
   192    196       DETACH "db14";
   193    197     }
   194    198   } {1 {no such database: db14}}
   195    199   do_test attach-1.24 {
   196    200     catchsql {