/ Check-in [651520fa]
Login

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

Overview
Comment:Add the mode=memory option to URI filenames, which when present forces the database to be an in-memory database. This enables named in-memory databases.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:651520fa84ee0c488bef660bab9865500309d5e9
User & Date: drh 2012-05-28 13:58:00
Context
2012-05-28
15:32
Fix Makefile.in so that it works with the new unicode tokenizer of FTS3/4. Update the version number to 3.7.13. check-in: b8720d04 user: drh tags: trunk
13:58
Add the mode=memory option to URI filenames, which when present forces the database to be an in-memory database. This enables named in-memory databases. check-in: 651520fa user: drh tags: trunk
12:22
Omit the fts3 unicode character class routines from the build if fts3/4 is disabled. check-in: c00bb5d4 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/btree.c.

  1717   1717     /* Set the variable isMemdb to true for an in-memory database, or 
  1718   1718     ** false for a file-based database.
  1719   1719     */
  1720   1720   #ifdef SQLITE_OMIT_MEMORYDB
  1721   1721     const int isMemdb = 0;
  1722   1722   #else
  1723   1723     const int isMemdb = (zFilename && strcmp(zFilename, ":memory:")==0)
  1724         -                       || (isTempDb && sqlite3TempInMemory(db));
         1724  +                       || (isTempDb && sqlite3TempInMemory(db))
         1725  +                       || (vfsFlags & SQLITE_OPEN_MEMORY)!=0;
  1725   1726   #endif
  1726   1727   
  1727   1728     assert( db!=0 );
  1728   1729     assert( pVfs!=0 );
  1729   1730     assert( sqlite3_mutex_held(db->mutex) );
  1730   1731     assert( (flags&0xff)==flags );   /* flags fit in 8 bits */
  1731   1732   

Changes to src/main.c.

  2008   2008             zModeType = "cache";
  2009   2009           }
  2010   2010           if( nOpt==4 && memcmp("mode", zOpt, 4)==0 ){
  2011   2011             static struct OpenMode aOpenMode[] = {
  2012   2012               { "ro",  SQLITE_OPEN_READONLY },
  2013   2013               { "rw",  SQLITE_OPEN_READWRITE }, 
  2014   2014               { "rwc", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE },
         2015  +            { "memory",
         2016  +                    SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE 
         2017  +                       | SQLITE_OPEN_MEMORY },
  2015   2018               { 0, 0 }
  2016   2019             };
  2017   2020   
  2018         -          mask = SQLITE_OPEN_READONLY|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
         2021  +          mask = SQLITE_OPEN_READONLY | SQLITE_OPEN_READWRITE
         2022  +                   | SQLITE_OPEN_CREATE | SQLITE_OPEN_MEMORY;
  2019   2023             aMode = aOpenMode;
  2020   2024             limit = mask & flags;
  2021   2025             zModeType = "access";
  2022   2026           }
  2023   2027   
  2024   2028           if( aMode ){
  2025   2029             int i;
................................................................................
  2032   2036               }
  2033   2037             }
  2034   2038             if( mode==0 ){
  2035   2039               *pzErrMsg = sqlite3_mprintf("no such %s mode: %s", zModeType, zVal);
  2036   2040               rc = SQLITE_ERROR;
  2037   2041               goto parse_uri_out;
  2038   2042             }
  2039         -          if( mode>limit ){
         2043  +          if( (mode & ~SQLITE_OPEN_MEMORY)>limit ){
  2040   2044               *pzErrMsg = sqlite3_mprintf("%s mode not allowed: %s",
  2041   2045                                           zModeType, zVal);
  2042   2046               rc = SQLITE_PERM;
  2043   2047               goto parse_uri_out;
  2044   2048             }
  2045   2049             flags = (flags & ~mask) | mode;
  2046   2050           }

Changes to src/sqlite.h.in.

   469    469   #define SQLITE_OPEN_READONLY         0x00000001  /* Ok for sqlite3_open_v2() */
   470    470   #define SQLITE_OPEN_READWRITE        0x00000002  /* Ok for sqlite3_open_v2() */
   471    471   #define SQLITE_OPEN_CREATE           0x00000004  /* Ok for sqlite3_open_v2() */
   472    472   #define SQLITE_OPEN_DELETEONCLOSE    0x00000008  /* VFS only */
   473    473   #define SQLITE_OPEN_EXCLUSIVE        0x00000010  /* VFS only */
   474    474   #define SQLITE_OPEN_AUTOPROXY        0x00000020  /* VFS only */
   475    475   #define SQLITE_OPEN_URI              0x00000040  /* Ok for sqlite3_open_v2() */
          476  +#define SQLITE_OPEN_MEMORY           0x00000080  /* Ok for sqlite3_open_v2() */
   476    477   #define SQLITE_OPEN_MAIN_DB          0x00000100  /* VFS only */
   477    478   #define SQLITE_OPEN_TEMP_DB          0x00000200  /* VFS only */
   478    479   #define SQLITE_OPEN_TRANSIENT_DB     0x00000400  /* VFS only */
   479    480   #define SQLITE_OPEN_MAIN_JOURNAL     0x00000800  /* VFS only */
   480    481   #define SQLITE_OPEN_TEMP_JOURNAL     0x00001000  /* VFS only */
   481    482   #define SQLITE_OPEN_SUBJOURNAL       0x00002000  /* VFS only */
   482    483   #define SQLITE_OPEN_MASTER_JOURNAL   0x00004000  /* VFS only */

Changes to test/e_uri.test.

   250    250   foreach {tn uri error} "
   251    251     1    {file:test.db?mode=ro}    {not an error}
   252    252     2    {file:test.db?mode=rw}    {not an error}
   253    253     3    {file:test.db?mode=rwc}   {not an error}
   254    254     4    {file:test.db?mode=Ro}    {no such access mode: Ro}
   255    255     5    {file:test.db?mode=Rw}    {no such access mode: Rw}
   256    256     6    {file:test.db?mode=Rwc}   {no such access mode: Rwc}
          257  +  7    {file:test.db?mode=memory} {not an error}
          258  +  8    {file:test.db?mode=MEMORY} {no such access mode: MEMORY}
   257    259   " {
   258    260     do_test 7.$tn { open_uri_error $uri } $error
   259    261   }
   260    262   
   261    263   
   262    264   # EVIDENCE-OF: R-09651-31805 If "ro" is specified, then the database is
   263    265   # opened for read-only access, just as if the SQLITE_OPEN_READONLY flag

Changes to test/shared.test.

  1089   1089     db1 eval {
  1090   1090       CREATE TABLE t1(x); INSERT INTO t1 VALUES(4),(5),(6);
  1091   1091     }
  1092   1092     catchsql {
  1093   1093       SELECT * FROM t1;
  1094   1094     } db2
  1095   1095   } {1 {no such table: t1}}
         1096  +
         1097  +# Shared cache on named memory databases.
         1098  +#
         1099  +do_test shared-$av-16.4 {
         1100  +  db1 close
         1101  +  db2 close
         1102  +  forcedelete test.db test.db-wal test.db-journal
         1103  +  sqlite3 db1 file:test.db?mode=memory -uri 1
         1104  +  sqlite3 db2 file:test.db?mode=memory -uri 1
         1105  +  db1 eval {
         1106  +    CREATE TABLE t1(x); INSERT INTO t1 VALUES(1),(2),(3);
         1107  +  }
         1108  +  db2 eval {
         1109  +    SELECT x FROM t1 ORDER BY x;
         1110  +  }
         1111  +} {1 2 3}
         1112  +do_test shared-$av-16.5 {
         1113  +  db2 eval {
         1114  +    INSERT INTO t1 VALUES(99);
         1115  +    DELETE FROM t1 WHERE x=2;
         1116  +  }
         1117  +  db1 eval {
         1118  +    SELECT x FROM t1 ORDER BY x;
         1119  +  }
         1120  +} {1 3 99}
         1121  +do_test shared-$av-16.6 {
         1122  +  file exists test.db
         1123  +} {0}  ;# Verify that the database is in-memory
         1124  +
         1125  +# Shared cache on named memory databases with different names.
         1126  +#
         1127  +do_test shared-$av-16.7 {
         1128  +  db1 close
         1129  +  db2 close
         1130  +  forcedelete test1.db test2.db
         1131  +  sqlite3 db1 file:test1.db?mode=memory -uri 1
         1132  +  sqlite3 db2 file:test2.db?mode=memory -uri 1
         1133  +  db1 eval {
         1134  +    CREATE TABLE t1(x); INSERT INTO t1 VALUES(1),(2),(3);
         1135  +  }
         1136  +  catchsql {
         1137  +    SELECT x FROM t1 ORDER BY x;
         1138  +  } db2
         1139  +} {1 {no such table: t1}}
         1140  +do_test shared-$av-16.8 {
         1141  +  file exists test1.db
         1142  +} {0}  ;# Verify that the database is in-memory
         1143  +
         1144  +
  1096   1145   db1 close
  1097   1146   db2 close
  1098   1147   
  1099   1148   }  ;# end of autovacuum on/off loop
  1100   1149   
  1101   1150   sqlite3_enable_shared_cache $::enable_shared_cache
  1102   1151   finish_test