/ Check-in [a0f5eb5c]
Login

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

Overview
Comment:Disable PRAGMA journal_mode=OFF when SQLITE_DBCONFIG_DEFENSIVE is turned on. Ticket [f4ec250930342e0c].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: a0f5eb5c79cc33b7224f3421d2baa02a2a19eb9d6eaa8117dda4a1878b229cb5
User & Date: drh 2019-05-17 20:37:17
Context
2019-05-18
19:49
Avoid including the comment in the output of "PRAGMA table_info" in situations where there is a comment following a DEFAULT value within a CREATE TABLE statement. check-in: d91095ba user: dan tags: trunk
2019-05-17
20:37
Disable PRAGMA journal_mode=OFF when SQLITE_DBCONFIG_DEFENSIVE is turned on. Ticket [f4ec250930342e0c]. check-in: a0f5eb5c user: drh tags: trunk
15:59
Always store a REAL value in a column with REAL affinity if the integer equivalent would require 8 bytes of storage. Fix for [3c27b97e3]. check-in: 14c00b10 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/pragma.c.

   639    639         for(eMode=0; (zMode = sqlite3JournalModename(eMode))!=0; eMode++){
   640    640           if( sqlite3StrNICmp(zRight, zMode, n)==0 ) break;
   641    641         }
   642    642         if( !zMode ){
   643    643           /* If the "=MODE" part does not match any known journal mode,
   644    644           ** then do a query */
   645    645           eMode = PAGER_JOURNALMODE_QUERY;
          646  +      }
          647  +      if( eMode==PAGER_JOURNALMODE_OFF && (db->flags & SQLITE_Defensive)!=0 ){
          648  +        /* Do not allow journal-mode "OFF" in defensive since the database
          649  +        ** can become corrupted using ordinary SQL when the journal is off */
          650  +        eMode = PAGER_JOURNALMODE_QUERY;
   646    651         }
   647    652       }
   648    653       if( eMode==PAGER_JOURNALMODE_QUERY && pId2->n==0 ){
   649    654         /* Convert "PRAGMA journal_mode" into "PRAGMA main.journal_mode" */
   650    655         iDb = 0;
   651    656         pId2->n = 1;
   652    657       }

Changes to src/sqlite.h.in.

  2194   2194   ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
  2195   2195   ** "defensive" flag for a database connection.  When the defensive
  2196   2196   ** flag is enabled, language features that allow ordinary SQL to 
  2197   2197   ** deliberately corrupt the database file are disabled.  The disabled
  2198   2198   ** features include but are not limited to the following:
  2199   2199   ** <ul>
  2200   2200   ** <li> The [PRAGMA writable_schema=ON] statement.
         2201  +** <li> The [PRAGMA journal_mode=OFF] statement.
  2201   2202   ** <li> Writes to the [sqlite_dbpage] virtual table.
  2202   2203   ** <li> Direct writes to [shadow tables].
  2203   2204   ** </ul>
  2204   2205   ** </dd>
  2205   2206   **
  2206   2207   ** [[SQLITE_DBCONFIG_WRITABLE_SCHEMA]] <dt>SQLITE_DBCONFIG_WRITABLE_SCHEMA</dt>
  2207   2208   ** <dd>The SQLITE_DBCONFIG_WRITABLE_SCHEMA option activates or deactivates the

Changes to test/jrnlmode.test.

    61     61   do_test jrnlmode-1.2 {
    62     62     execsql {
    63     63       PRAGMA journal_mode;
    64     64       PRAGMA main.journal_mode;
    65     65       PRAGMA temp.journal_mode;
    66     66     } 
    67     67   } [list persist persist [temp_journal_mode persist]]
    68         -do_test jrnlmode-1.4 {
           68  +do_test jrnlmode-1.4a {
           69  +  # When defensive is on, unable to set journal_mode to OFF
           70  +  sqlite3_db_config db DEFENSIVE 1
           71  +  execsql {
           72  +    PRAGMA journal_mode = off;
           73  +  } 
           74  +} {persist}
           75  +do_test jrnlmode-1.4b {
           76  +  # When defensive is on, unable to set journal_mode to OFF
           77  +  sqlite3_db_config db DEFENSIVE 0
    69     78     execsql {
    70     79       PRAGMA journal_mode = off;
    71     80     } 
    72     81   } {off}
    73     82   do_test jrnlmode-1.5 {
    74     83     execsql {
    75     84       PRAGMA journal_mode;