/ Check-in [e396184c]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Change the journal_mode pragma to remove the "default journal mode" concept. The journal_mode pragma only effects currently attached databases and does not change the behavior of future attachments.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: e396184cd3bdb96e29ac33af5d1f631cac553341
User & Date: drh 2010-07-08 17:40:38
Context
2010-07-08
18:32
Fix test case numbering in backup_malloc.test and issue when running under Windows. check-in: aef26438 user: shaneh tags: trunk
17:40
Change the journal_mode pragma to remove the "default journal mode" concept. The journal_mode pragma only effects currently attached databases and does not change the behavior of future attachments. check-in: e396184c user: drh tags: trunk
16:50
Merged experimental crashsql() into trunk. check-in: 01b575ff user: shaneh tags: trunk
Changes
Hide Diffs Unified Diffs Show Whitespace Changes Patch

Changes to src/attach.c.

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
...
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
    }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
      zErrDyn = sqlite3MPrintf(db, 
        "attached databases must use the same text encoding as main database");
      rc = SQLITE_ERROR;
    }
    pPager = sqlite3BtreePager(aNew->pBt);
    sqlite3PagerLockingMode(pPager, db->dfltLockMode);
    /* journal_mode set by the OP_JournalMode opcode that will following
    ** the OP_Function opcode that invoked this function. */
    sqlite3BtreeSecureDelete(aNew->pBt,
                             sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
  }
  aNew->safety_level = 3;
  aNew->zName = sqlite3DbStrDup(db, zName);
  if( rc==SQLITE_OK && aNew->zName==0 ){
    rc = SQLITE_NOMEM;
................................................................................
  assert( v || db->mallocFailed );
  if( v ){
    sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);
    assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );
    sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));
    sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);

    if( type==SQLITE_ATTACH ){
      /* 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));
  }
  







<
<







 







<
<
<
<
<
<
<
<
<
<
<







139
140
141
142
143
144
145


146
147
148
149
150
151
152
...
334
335
336
337
338
339
340











341
342
343
344
345
346
347
    }else if( aNew->pSchema->file_format && aNew->pSchema->enc!=ENC(db) ){
      zErrDyn = sqlite3MPrintf(db, 
        "attached databases must use the same text encoding as main database");
      rc = SQLITE_ERROR;
    }
    pPager = sqlite3BtreePager(aNew->pBt);
    sqlite3PagerLockingMode(pPager, db->dfltLockMode);


    sqlite3BtreeSecureDelete(aNew->pBt,
                             sqlite3BtreeSecureDelete(db->aDb[0].pBt,-1) );
  }
  aNew->safety_level = 3;
  aNew->zName = sqlite3DbStrDup(db, zName);
  if( rc==SQLITE_OK && aNew->zName==0 ){
    rc = SQLITE_NOMEM;
................................................................................
  assert( v || db->mallocFailed );
  if( v ){
    sqlite3VdbeAddOp3(v, OP_Function, 0, regArgs+3-pFunc->nArg, regArgs+3);
    assert( pFunc->nArg==-1 || (pFunc->nArg&0xff)==pFunc->nArg );
    sqlite3VdbeChangeP5(v, (u8)(pFunc->nArg));
    sqlite3VdbeChangeP4(v, -1, (char *)pFunc, P4_FUNCDEF);












    /* 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/build.c.

3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
    }
    db->aDb[1].pBt = pBt;
    assert( db->aDb[1].pSchema );
    if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
      db->mallocFailed = 1;
      return 1;
    }
    sqlite3PagerSetJournalMode(sqlite3BtreePager(pBt), db->dfltJournalMode);
  }
  return 0;
}

/*
** Generate VDBE code that will verify the schema cookie and start
** a read-transaction for all named database files.







<







3419
3420
3421
3422
3423
3424
3425

3426
3427
3428
3429
3430
3431
3432
    }
    db->aDb[1].pBt = pBt;
    assert( db->aDb[1].pSchema );
    if( SQLITE_NOMEM==sqlite3BtreeSetPageSize(pBt, db->nextPagesize, -1, 0) ){
      db->mallocFailed = 1;
      return 1;
    }

  }
  return 0;
}

/*
** Generate VDBE code that will verify the schema cookie and start
** a read-transaction for all named database files.

Changes to src/pragma.c.

532
533
534
535
536
537
538

539


540
541
542
543
544
545
546
547


548
549
550
551
552
553
554
555


556
557
558
559
560
561
562
563
564
565
566
567
568
569

570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
  /*
  **  PRAGMA [database.]journal_mode
  **  PRAGMA [database.]journal_mode =
  **                      (delete|persist|off|truncate|memory|wal|off)
  */
  if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
    int eMode;                    /* One of the PAGER_JOURNALMODE_XXX symbols */




    if( sqlite3ReadSchema(pParse) ){
      goto pragma_out;
    }

    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);

    if( zRight==0 ){


      eMode = PAGER_JOURNALMODE_QUERY;
    }else{
      const char *zMode;
      int n = sqlite3Strlen30(zRight);
      for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
        if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
      }
      if( !zMode ){


        eMode = PAGER_JOURNALMODE_QUERY;
      }
    }
    if( pId2->n==0 && eMode==PAGER_JOURNALMODE_QUERY ){
      /* Simple "PRAGMA journal_mode;" statement. This is a query for
      ** the current default journal mode (which may be different to
      ** the journal-mode of the main database).
      */
      eMode = db->dfltJournalMode;
      sqlite3VdbeAddOp2(v, OP_String8, 0, 1);
      sqlite3VdbeChangeP4(v, -1, sqlite3JournalModename(eMode), P4_STATIC);
    }else{
      int ii;


      if( pId2->n==0 ){
        /* When there is no database name before the "journal_mode" keyword
        ** in the PRAGMA, then the journal-mode will be set on
        ** all attached databases, as well as the main db file.
        **
        ** Also, the sqlite3.dfltJournalMode variable is set so that
        ** any subsequently attached databases also use the specified
        ** journal mode.
        */
        db->dfltJournalMode = (u8)eMode;
      }

      for(ii=db->nDb-1; ii>=0; ii--){
        if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
          sqlite3VdbeUsesBtree(v, ii);
          sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
        }
      }
    }

    sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
  }else

  /*
  **  PRAGMA [database.]journal_size_limit
  **  PRAGMA [database.]journal_size_limit=N
  **







>

>
>








>
>








>
>



|
<
<
|
<
<
<
<
<
<
<
>
|
<
<
<
<
<
<
<
<
<
|
<






<
<







532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566


567







568
569









570

571
572
573
574
575
576


577
578
579
580
581
582
583
  /*
  **  PRAGMA [database.]journal_mode
  **  PRAGMA [database.]journal_mode =
  **                      (delete|persist|off|truncate|memory|wal|off)
  */
  if( sqlite3StrICmp(zLeft,"journal_mode")==0 ){
    int eMode;        /* One of the PAGER_JOURNALMODE_XXX symbols */
    int ii;           /* Loop counter */

    /* Force the schema to be loaded on all databases.  This cases all
    ** database files to be opened and the journal_modes set. */
    if( sqlite3ReadSchema(pParse) ){
      goto pragma_out;
    }

    sqlite3VdbeSetNumCols(v, 1);
    sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "journal_mode", SQLITE_STATIC);

    if( zRight==0 ){
      /* If there is no "=MODE" part of the pragma, do a query for the
      ** current mode */
      eMode = PAGER_JOURNALMODE_QUERY;
    }else{
      const char *zMode;
      int n = sqlite3Strlen30(zRight);
      for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
        if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
      }
      if( !zMode ){
        /* If the "=MODE" part does not match any known journal mode,
        ** then do a query */
        eMode = PAGER_JOURNALMODE_QUERY;
      }
    }
    if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){


      /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */







      iDb = 0;
      pId2->n = 1;









    }

    for(ii=db->nDb-1; ii>=0; ii--){
      if( db->aDb[ii].pBt && (ii==iDb || pId2->n==0) ){
        sqlite3VdbeUsesBtree(v, ii);
        sqlite3VdbeAddOp3(v, OP_JournalMode, ii, 1, eMode);
      }
    }


    sqlite3VdbeAddOp2(v, OP_ResultRow, 1, 1);
  }else

  /*
  **  PRAGMA [database.]journal_size_limit
  **  PRAGMA [database.]journal_size_limit=N
  **

Changes to src/sqliteInt.h.

793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
  int openFlags;                /* Flags passed to sqlite3_vfs.xOpen() */
  int errCode;                  /* Most recent error code (SQLITE_*) */
  int errMask;                  /* & result codes with this before returning */
  u8 autoCommit;                /* The auto-commit flag. */
  u8 temp_store;                /* 1: file 2: memory 0: default */
  u8 mallocFailed;              /* True if we have seen a malloc failure */
  u8 dfltLockMode;              /* Default locking-mode for attached dbs */
  u8 dfltJournalMode;           /* Default journal mode for attached dbs */
  signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */
  u8 suppressErr;               /* Do not issue error messages if true */
  int nextPagesize;             /* Pagesize after VACUUM if >0 */
  int nTable;                   /* Number of tables in the database */
  CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
  i64 lastRowid;                /* ROWID of most recent insert (see above) */
  u32 magic;                    /* Magic number for detect library misuse */







<







793
794
795
796
797
798
799

800
801
802
803
804
805
806
  int openFlags;                /* Flags passed to sqlite3_vfs.xOpen() */
  int errCode;                  /* Most recent error code (SQLITE_*) */
  int errMask;                  /* & result codes with this before returning */
  u8 autoCommit;                /* The auto-commit flag. */
  u8 temp_store;                /* 1: file 2: memory 0: default */
  u8 mallocFailed;              /* True if we have seen a malloc failure */
  u8 dfltLockMode;              /* Default locking-mode for attached dbs */

  signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */
  u8 suppressErr;               /* Do not issue error messages if true */
  int nextPagesize;             /* Pagesize after VACUUM if >0 */
  int nTable;                   /* Number of tables in the database */
  CollSeq *pDfltColl;           /* The default collating sequence (BINARY) */
  i64 lastRowid;                /* ROWID of most recent insert (see above) */
  u32 magic;                    /* Magic number for detect library misuse */

Changes to src/vdbe.c.

5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
....
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
** 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 char *zFilename;          /* Name of database file for pPager */
................................................................................
        rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
      }
    }
  }
#endif /* ifndef SQLITE_OMIT_WAL */

  if( rc ){
    if( rc==SQLITE_BUSY && pOp->p5!=0 ) rc = SQLITE_OK;
    eNew = eOld;
  }
  eNew = sqlite3PagerSetJournalMode(pPager, eNew);

  pOut = &aMem[pOp->p2];
  pOut->flags = MEM_Str|MEM_Static|MEM_Term;
  pOut->z = (char *)sqlite3JournalModename(eNew);







<
<
<
<
<







 







<







5161
5162
5163
5164
5165
5166
5167





5168
5169
5170
5171
5172
5173
5174
....
5258
5259
5260
5261
5262
5263
5264

5265
5266
5267
5268
5269
5270
5271
** 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 char *zFilename;          /* Name of database file for pPager */
................................................................................
        rc = sqlite3BtreeSetVersion(pBt, (eNew==PAGER_JOURNALMODE_WAL ? 2 : 1));
      }
    }
  }
#endif /* ifndef SQLITE_OMIT_WAL */

  if( rc ){

    eNew = eOld;
  }
  eNew = sqlite3PagerSetJournalMode(pPager, eNew);

  pOut = &aMem[pOp->p2];
  pOut->flags = MEM_Str|MEM_Static|MEM_Term;
  pOut->z = (char *)sqlite3JournalModename(eNew);

Changes to test/crash8.test.

254
255
256
257
258
259
260

261
262
263
264
265
266
267
      INSERT INTO ab VALUES(2, NULL);
      INSERT INTO ab VALUES(3, NULL);
      INSERT INTO ab VALUES(4, NULL);
      INSERT INTO ab VALUES(5, NULL);
      INSERT INTO ab VALUES(6, NULL);
      UPDATE ab SET b = randstr(1000,1000);
      ATTACH 'test2.db' AS aux;

      CREATE TABLE aux.ab(a, b);
      INSERT INTO aux.ab SELECT * FROM main.ab;

      UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1;
      UPDATE ab SET b = randstr(1000,1000) WHERE a>=1;
    }
    list [file exists test.db-journal] [file exists test2.db-journal]







>







254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
      INSERT INTO ab VALUES(2, NULL);
      INSERT INTO ab VALUES(3, NULL);
      INSERT INTO ab VALUES(4, NULL);
      INSERT INTO ab VALUES(5, NULL);
      INSERT INTO ab VALUES(6, NULL);
      UPDATE ab SET b = randstr(1000,1000);
      ATTACH 'test2.db' AS aux;
      PRAGMA aux.journal_mode = persist;
      CREATE TABLE aux.ab(a, b);
      INSERT INTO aux.ab SELECT * FROM main.ab;

      UPDATE aux.ab SET b = randstr(1000,1000) WHERE a>=1;
      UPDATE ab SET b = randstr(1000,1000) WHERE a>=1;
    }
    list [file exists test.db-journal] [file exists test2.db-journal]

Changes to test/jrnlmode.test.

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
...
313
314
315
316
317
318
319

320
321
322

323
324
325
326
327
328
329
...
333
334
335
336
337
338
339

340


341
342
343
344
345
346
347
348
      PRAGMA aux1.journal_mode;
    }
  } [list off [temp_journal_mode persist] memory]
  do_test jrnlmode-1.11 {
    execsql {
      PRAGMA journal_mode;
    }
  } {persist}
  do_test jrnlmode-1.12 {
    execsql {
      ATTACH ':memory:' as aux2;
    }
    execsql {
      PRAGMA main.journal_mode;
      PRAGMA aux1.journal_mode;
................................................................................

  do_test jrnlmode-5.2 {
    execsql { PRAGMA journal_size_limit }
  } {-1}
  do_test jrnlmode-5.3 {
    execsql { 
      ATTACH 'test2.db' AS aux;

      PRAGMA aux.journal_size_limit;
    }
  } {-1}

  do_test jrnlmode-5.4.1 {
    execsql { PRAGMA aux.journal_size_limit = 999999999999 }
  } {999999999999}
  do_test jrnlmode-5.4.2 {
    execsql { PRAGMA aux.journal_size_limit = 10240 }
  } {10240}
  do_test jrnlmode-5.5 {
................................................................................
    execsql { PRAGMA journal_size_limit }
  } {20480}
  do_test jrnlmode-5.7 {
    execsql { PRAGMA aux.journal_size_limit }
  } {10240}

  do_test jrnlmode-5.8 {

    execsql { ATTACH 'test3.db' AS aux2 }


  } {}

  do_test jrnlmode-5.9 {
    execsql {
      CREATE TABLE main.t1(a, b, c);
      CREATE TABLE aux.t2(a, b, c);
      CREATE TABLE aux2.t3(a, b, c);
    }







|







 







>


<
>







 







>
|
>
>
|







128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
...
313
314
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330
...
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
      PRAGMA aux1.journal_mode;
    }
  } [list off [temp_journal_mode persist] memory]
  do_test jrnlmode-1.11 {
    execsql {
      PRAGMA journal_mode;
    }
  } {off}
  do_test jrnlmode-1.12 {
    execsql {
      ATTACH ':memory:' as aux2;
    }
    execsql {
      PRAGMA main.journal_mode;
      PRAGMA aux1.journal_mode;
................................................................................

  do_test jrnlmode-5.2 {
    execsql { PRAGMA journal_size_limit }
  } {-1}
  do_test jrnlmode-5.3 {
    execsql { 
      ATTACH 'test2.db' AS aux;
      PRAGMA aux.journal_mode=persist;
      PRAGMA aux.journal_size_limit;
    }

  } {persist -1}
  do_test jrnlmode-5.4.1 {
    execsql { PRAGMA aux.journal_size_limit = 999999999999 }
  } {999999999999}
  do_test jrnlmode-5.4.2 {
    execsql { PRAGMA aux.journal_size_limit = 10240 }
  } {10240}
  do_test jrnlmode-5.5 {
................................................................................
    execsql { PRAGMA journal_size_limit }
  } {20480}
  do_test jrnlmode-5.7 {
    execsql { PRAGMA aux.journal_size_limit }
  } {10240}

  do_test jrnlmode-5.8 {
    execsql {
      ATTACH 'test3.db' AS aux2;
      PRAGMA aux2.journal_mode=persist;
    }
  } {persist}

  do_test jrnlmode-5.9 {
    execsql {
      CREATE TABLE main.t1(a, b, c);
      CREATE TABLE aux.t2(a, b, c);
      CREATE TABLE aux2.t3(a, b, c);
    }

Changes to test/walmode.test.

299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356









357
358
359
360
361
362
363
...
365
366
367
368
369
370
371
372
  sqlite3 db test.db
  execsql {
    PRAGMA journal_mode = WAL;
    CREATE TABLE t1(a, b);
  }
} {wal}
foreach {tn sql result} {
  1  "PRAGMA journal_mode"                delete
  2  "PRAGMA main.journal_mode"           wal
  3  "PRAGMA journal_mode = delete"       delete
  4  "PRAGMA journal_mode"                delete
  5  "PRAGMA main.journal_mode"           delete
  6  "PRAGMA journal_mode = wal"          wal
  7  "PRAGMA journal_mode"                delete
  8  "PRAGMA main.journal_mode"           wal

  9  "PRAGMA journal_mode"                delete
 10  "PRAGMA main.journal_mode"           wal
 11  "PRAGMA main.journal_mode = delete"  delete
 12  "PRAGMA journal_mode"                delete
 13  "PRAGMA main.journal_mode"           delete
 14  "PRAGMA main.journal_mode = wal"     wal
 15  "PRAGMA journal_mode"                delete
 16  "PRAGMA main.journal_mode"           wal
} {
  do_test walmode-7.$tn { 
    db close
    sqlite3 db test.db
    execsql $sql
  } $result
................................................................................
do_execsql_test walmode-8.1 {
  CREATE TABLE t1(a, b);
  PRAGMA journal_mode = WAL;
  ATTACH 'test.db2' AS two;
  CREATE TABLE two.t2(a, b);
} {wal}
do_execsql_test walmode-8.2 { PRAGMA main.journal_mode }         {wal}
do_execsql_test walmode-8.3 { PRAGMA two.journal_mode  }         {wal}
do_execsql_test walmode-8.4 { PRAGMA two.journal_mode = DELETE } {delete}

db close
sqlite3 db test.db
do_execsql_test walmode-8.5  { ATTACH 'test.db2' AS two }          {}
do_execsql_test walmode-8.6  { PRAGMA main.journal_mode }          {wal}
do_execsql_test walmode-8.7  { PRAGMA two.journal_mode  }          {delete}
do_execsql_test walmode-8.8  { INSERT INTO two.t2 DEFAULT VALUES } {}
do_execsql_test walmode-8.9  { PRAGMA two.journal_mode  }          {delete}
do_execsql_test walmode-8.10 { INSERT INTO t1 DEFAULT VALUES } {}
do_execsql_test walmode-8.11 { PRAGMA main.journal_mode  }         {wal}
do_execsql_test walmode-8.12 { PRAGMA journal_mode  }              {delete}










db close
sqlite3 db test.db
do_execsql_test walmode-8.13 { PRAGMA journal_mode = WAL }         {wal}
do_execsql_test walmode-8.14 { ATTACH 'test.db2' AS two  }         {}
do_execsql_test walmode-8.15 { PRAGMA main.journal_mode  }         {wal}
do_execsql_test walmode-8.16 { PRAGMA two.journal_mode   }         {wal}
................................................................................
do_execsql_test walmode-8.18 { PRAGMA two.journal_mode   }         {wal}
 
sqlite3 db2 test.db2
do_test walmode-8.19 { execsql { PRAGMA main.journal_mode } db2 }  {wal}
db2 close

finish_test








|





|


|





|







 







|











|
>
>
>
>
>
>
>
>
>







 







<
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
...
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
...
374
375
376
377
378
379
380

  sqlite3 db test.db
  execsql {
    PRAGMA journal_mode = WAL;
    CREATE TABLE t1(a, b);
  }
} {wal}
foreach {tn sql result} {
  1  "PRAGMA journal_mode"                wal
  2  "PRAGMA main.journal_mode"           wal
  3  "PRAGMA journal_mode = delete"       delete
  4  "PRAGMA journal_mode"                delete
  5  "PRAGMA main.journal_mode"           delete
  6  "PRAGMA journal_mode = wal"          wal
  7  "PRAGMA journal_mode"                wal
  8  "PRAGMA main.journal_mode"           wal

  9  "PRAGMA journal_mode"                wal
 10  "PRAGMA main.journal_mode"           wal
 11  "PRAGMA main.journal_mode = delete"  delete
 12  "PRAGMA journal_mode"                delete
 13  "PRAGMA main.journal_mode"           delete
 14  "PRAGMA main.journal_mode = wal"     wal
 15  "PRAGMA journal_mode"                wal
 16  "PRAGMA main.journal_mode"           wal
} {
  do_test walmode-7.$tn { 
    db close
    sqlite3 db test.db
    execsql $sql
  } $result
................................................................................
do_execsql_test walmode-8.1 {
  CREATE TABLE t1(a, b);
  PRAGMA journal_mode = WAL;
  ATTACH 'test.db2' AS two;
  CREATE TABLE two.t2(a, b);
} {wal}
do_execsql_test walmode-8.2 { PRAGMA main.journal_mode }         {wal}
do_execsql_test walmode-8.3 { PRAGMA two.journal_mode  }         {delete}
do_execsql_test walmode-8.4 { PRAGMA two.journal_mode = DELETE } {delete}

db close
sqlite3 db test.db
do_execsql_test walmode-8.5  { ATTACH 'test.db2' AS two }          {}
do_execsql_test walmode-8.6  { PRAGMA main.journal_mode }          {wal}
do_execsql_test walmode-8.7  { PRAGMA two.journal_mode  }          {delete}
do_execsql_test walmode-8.8  { INSERT INTO two.t2 DEFAULT VALUES } {}
do_execsql_test walmode-8.9  { PRAGMA two.journal_mode  }          {delete}
do_execsql_test walmode-8.10 { INSERT INTO t1 DEFAULT VALUES } {}
do_execsql_test walmode-8.11 { PRAGMA main.journal_mode  }         {wal}
do_execsql_test walmode-8.12 { PRAGMA journal_mode  }              {wal}

# Change to WAL mode on test2.db and make sure (in the tests that follow)
# that this mode change persists. 
do_test walmode-8.x1 {
  execsql {
     PRAGMA two.journal_mode=WAL;
     PRAGMA two.journal_mode;
  }
} {wal wal}

db close
sqlite3 db test.db
do_execsql_test walmode-8.13 { PRAGMA journal_mode = WAL }         {wal}
do_execsql_test walmode-8.14 { ATTACH 'test.db2' AS two  }         {}
do_execsql_test walmode-8.15 { PRAGMA main.journal_mode  }         {wal}
do_execsql_test walmode-8.16 { PRAGMA two.journal_mode   }         {wal}
................................................................................
do_execsql_test walmode-8.18 { PRAGMA two.journal_mode   }         {wal}
 
sqlite3 db2 test.db2
do_test walmode-8.19 { execsql { PRAGMA main.journal_mode } db2 }  {wal}
db2 close

finish_test