/ Check-in [0bdea4cf]
Login

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

Overview
Comment:Enhance the OP_JournalMode opcode with an ignore-errors option and use that option the ATTACH command.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 0bdea4cfbd7832f2a00c01b93c92ba13d20139ef
User & Date: drh 2010-05-10 11:20:06
Context
2010-05-10
14:10
If an ATTACH command fails due to OP_JournalMode but still attaches the database, make sure VACUUM still detaches it when done. check-in: 6ecdc7ba user: drh tags: trunk
11:20
Enhance the OP_JournalMode opcode with an ignore-errors option and use that option the ATTACH command. check-in: 0bdea4cf user: drh tags: trunk
2010-05-07
20:34
When running a checkpoint while in locking_mode=EXCLUSIVE, be sure to move the wal-index lock to UNLOCK from READ prior to promoting to CHECKPOINT. check-in: be114bdf user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/attach.c.

344
345
346
347
348
349
350

351
352
353
354
355
356
357
      /* On an attach, also set the journal mode.  Note that
      ** sqlite3VdbeUsesBtree() is not call here since the iDb index
      ** will be out of range prior to the new database being attached.
      ** The OP_JournalMode opcode will all sqlite3VdbeUsesBtree() for us.
      */
      sqlite3VdbeAddOp3(v, OP_JournalMode, db->nDb, regArgs+3, 
                           db->dfltJournalMode);

    }

    /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
    ** statement only). For DETACH, set it to false (expire all existing
    ** statements).
    */
    sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));







>







344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
      /* On an attach, also set the journal mode.  Note that
      ** sqlite3VdbeUsesBtree() is not call here since the iDb index
      ** will be out of range prior to the new database being attached.
      ** The OP_JournalMode opcode will all sqlite3VdbeUsesBtree() for us.
      */
      sqlite3VdbeAddOp3(v, OP_JournalMode, db->nDb, regArgs+3, 
                           db->dfltJournalMode);
      sqlite3VdbeChangeP5(v, 1);
    }

    /* Code an OP_Expire. For an ATTACH statement, set P1 to true (expire this
    ** statement only). For DETACH, set it to false (expire all existing
    ** statements).
    */
    sqlite3VdbeAddOp1(v, OP_Expire, (type==SQLITE_ATTACH));

Changes to src/vdbe.c.

5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210





5211
5212
5213
5214
5215
5216
5217
....
5281
5282
5283
5284
5285
5286
5287
5288
5289



5290
5291

5292
5293
5294
5295
5296
5297


5298
5299



5300
5301
5302
5303
5304
5305
5306
*/
case OP_Checkpoint: {
  rc = sqlite3Checkpoint(db, pOp->p1);
  break;
};  
#endif

/* Opcode: JournalMode P1 P2 P3 * *
**
** Change the journal mode of database P1 to P3. P3 must be one of the
** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
** modes (delete, truncate, persist, off and memory), this is a simple
** operation. No IO is required.
**
** If changing into or out of WAL mode the procedure is more complicated.
**
** Write a string containing the final journal-mode to register P2.





*/
case OP_JournalMode: {    /* out2-prerelease */
  Btree *pBt;                     /* Btree to change journal mode of */
  Pager *pPager;                  /* Pager associated with pBt */
  int eNew;                       /* New journal mode */
  int eOld;                       /* The old journal mode */
  const sqlite3_vfs *pVfs;        /* The VFS of pPager */
................................................................................
        if( eOld==PAGER_JOURNALMODE_WAL ){
          /* If leaving WAL mode, close the log file. If successful, the call
          ** to PagerCloseWal() checkpoints and deletes the write-ahead-log 
          ** file. An EXCLUSIVE lock may still be held on the database file 
          ** after a successful return. 
          */
          rc = sqlite3PagerCloseWal(pPager);
          if( rc!=SQLITE_OK ) goto abort_due_to_error;
          sqlite3PagerJournalMode(pPager, eNew);



        }else{
          sqlite3PagerJournalMode(pPager, PAGER_JOURNALMODE_DELETE);

        }
  
        /* Open a transaction on the database file. Regardless of the journal
        ** mode, this transaction always uses a rollback journal.
        */
        assert( sqlite3BtreeIsInTrans(pBt)==0 );


        rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
        if( rc!=SQLITE_OK ) goto abort_due_to_error;



      }
    }
  }
#endif /* ifndef SQLITE_OMIT_WAL */

  eNew = sqlite3PagerJournalMode(pPager, eNew);
  pOut = &aMem[pOp->p2];







|









>
>
>
>
>







 







|
|
>
>
>


>






>
>
|
|
>
>
>







5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
....
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
*/
case OP_Checkpoint: {
  rc = sqlite3Checkpoint(db, pOp->p1);
  break;
};  
#endif

/* Opcode: JournalMode P1 P2 P3 * P5
**
** Change the journal mode of database P1 to P3. P3 must be one of the
** PAGER_JOURNALMODE_XXX values. If changing between the various rollback
** modes (delete, truncate, persist, off and memory), this is a simple
** operation. No IO is required.
**
** If changing into or out of WAL mode the procedure is more complicated.
**
** Write a string containing the final journal-mode to register P2.
**
** If an attempt to change in to or out of WAL mode fails because another
** connection also has the same database open, then an SQLITE_BUSY error
** is raised if P5==0, or of P5!=0 the journal mode changed is skipped
** without signaling the error.
*/
case OP_JournalMode: {    /* out2-prerelease */
  Btree *pBt;                     /* Btree to change journal mode of */
  Pager *pPager;                  /* Pager associated with pBt */
  int eNew;                       /* New journal mode */
  int eOld;                       /* The old journal mode */
  const sqlite3_vfs *pVfs;        /* The VFS of pPager */
................................................................................
        if( eOld==PAGER_JOURNALMODE_WAL ){
          /* If leaving WAL mode, close the log file. If successful, the call
          ** to PagerCloseWal() checkpoints and deletes the write-ahead-log 
          ** file. An EXCLUSIVE lock may still be held on the database file 
          ** after a successful return. 
          */
          rc = sqlite3PagerCloseWal(pPager);
          if( rc==SQLITE_OK ){
            sqlite3PagerJournalMode(pPager, eNew);
          }else if( rc==SQLITE_BUSY && pOp->p5==0 ){
            goto abort_due_to_error;
          }
        }else{
          sqlite3PagerJournalMode(pPager, PAGER_JOURNALMODE_DELETE);
          rc = SQLITE_OK;
        }
  
        /* Open a transaction on the database file. Regardless of the journal
        ** mode, this transaction always uses a rollback journal.
        */
        assert( sqlite3BtreeIsInTrans(pBt)==0 );
        if( rc==SQLITE_OK ){
          rc = sqlite3BtreeSetVersion(pBt, 
                                      (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
          if( rc==SQLITE_BUSY && pOp->p5==0 ) goto abort_due_to_error;
        }else if( rc==SQLITE_BUSY ){
          rc = SQLITE_OK;
        }
      }
    }
  }
#endif /* ifndef SQLITE_OMIT_WAL */

  eNew = sqlite3PagerJournalMode(pPager, eNew);
  pOut = &aMem[pOp->p2];