/ Check-in [9dc2eaa6]
Login

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

Overview
Comment:Add experimental sqlite3_reconfig() interface to more fully support the SQLITE_CONFIG_READONLY option.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | configReadOnly
Files: files | file ages | folders
SHA1: 9dc2eaa64b6a9f69bd6f3ff28de2c97682a69e0a
User & Date: mistachkin 2012-10-03 20:20:15
Context
2012-10-03
20:25
Merge updates from trunk. check-in: 1138815c user: mistachkin tags: configReadOnly
20:20
Add experimental sqlite3_reconfig() interface to more fully support the SQLITE_CONFIG_READONLY option. check-in: 9dc2eaa6 user: mistachkin tags: configReadOnly
2012-09-25
12:45
Merge updates from trunk. check-in: 4a470741 user: mistachkin tags: configReadOnly
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

   477    477   
   478    478       case SQLITE_CONFIG_COVERING_INDEX_SCAN: {
   479    479         sqlite3GlobalConfig.bUseCis = va_arg(ap, int);
   480    480         break;
   481    481       }
   482    482   
   483    483       case SQLITE_CONFIG_READONLY: {
          484  +      sqlite3GlobalConfig.bReadOnly = va_arg(ap, int);
          485  +      break;
          486  +    }
          487  +
          488  +    default: {
          489  +      rc = SQLITE_ERROR;
          490  +      break;
          491  +    }
          492  +  }
          493  +  va_end(ap);
          494  +  return rc;
          495  +}
          496  +
          497  +/*
          498  +** This API allows applications to modify the global configuration of
          499  +** the SQLite library at run-time.
          500  +**
          501  +** This routine differs from sqlite3_config() in that it may be called when
          502  +** there are outstanding database connections and/or memory allocations.
          503  +** This routine is threadsafe.
          504  +*/
          505  +int sqlite3_reconfig(int op, ...){
          506  +  va_list ap;
          507  +  int rc = SQLITE_OK;
          508  +
          509  +  va_start(ap, op);
          510  +  switch( op ){
          511  +    case SQLITE_CONFIG_READONLY: {
          512  +      /*
          513  +      ** On platforms where assignment of an integer value is atomic, there
          514  +      ** is no need for a mutex here.  On other platforms, there could be a
          515  +      ** subtle race condition here; however, the effect would simply be that
          516  +      ** a call to open a database would fail with SQLITE_READONLY.
          517  +      */
   484    518         sqlite3GlobalConfig.bReadOnly = va_arg(ap, int);
   485    519         break;
   486    520       }
   487    521   
   488    522       default: {
   489    523         rc = SQLITE_ERROR;
   490    524         break;

Changes to src/sqlite.h.in.

  1219   1219   int sqlite3_shutdown(void);
  1220   1220   int sqlite3_os_init(void);
  1221   1221   int sqlite3_os_end(void);
  1222   1222   
  1223   1223   /*
  1224   1224   ** CAPI3REF: Configuring The SQLite Library
  1225   1225   **
  1226         -** The sqlite3_config() interface is used to make global configuration
  1227         -** changes to SQLite in order to tune SQLite to the specific needs of
  1228         -** the application.  The default configuration is recommended for most
  1229         -** applications and so this routine is usually not necessary.  It is
  1230         -** provided to support rare applications with unusual needs.
         1226  +** The sqlite3_config() and sqlite3_reconfig() interfaces are used to make
         1227  +** global configuration changes to SQLite in order to tune SQLite to the
         1228  +** specific needs of the application.  The default configuration is recommended
         1229  +** for most applications and so this routine is usually not necessary.  They
         1230  +** are provided to support rare applications with unusual needs.
  1231   1231   **
  1232   1232   ** The sqlite3_config() interface is not threadsafe.  The application
  1233   1233   ** must insure that no other SQLite interfaces are invoked by other
  1234   1234   ** threads while sqlite3_config() is running.  Furthermore, sqlite3_config()
  1235   1235   ** may only be invoked prior to library initialization using
  1236   1236   ** [sqlite3_initialize()] or after shutdown by [sqlite3_shutdown()].
  1237   1237   ** ^If sqlite3_config() is called after [sqlite3_initialize()] and before
  1238   1238   ** [sqlite3_shutdown()] then it will return SQLITE_MISUSE.
  1239   1239   ** Note, however, that ^sqlite3_config() can be called as part of the
  1240   1240   ** implementation of an application-defined [sqlite3_os_init()].
  1241   1241   **
  1242         -** The first argument to sqlite3_config() is an integer
  1243         -** [configuration option] that determines
         1242  +** The sqlite3_reconfig() interface is threadsafe and may be called at any
         1243  +** time.  However, it supports only a small subset of the configuration
         1244  +** options available for use with sqlite3_config().
         1245  +**
         1246  +** The first argument to both sqlite3_config() and sqlite3_reconfig() is an
         1247  +** integer [configuration option] that determines
  1244   1248   ** what property of SQLite is to be configured.  Subsequent arguments
  1245   1249   ** vary depending on the [configuration option]
  1246   1250   ** in the first argument.
  1247   1251   **
  1248         -** ^When a configuration option is set, sqlite3_config() returns [SQLITE_OK].
         1252  +** ^When a configuration option is set, both sqlite3_config() and
         1253  +** sqlite3_reconfig() return [SQLITE_OK].
  1249   1254   ** ^If the option is unknown or SQLite is unable to set the option
  1250         -** then this routine returns a non-zero [error code].
         1255  +** then these routines returns a non-zero [error code].
  1251   1256   */
  1252   1257   int sqlite3_config(int, ...);
         1258  +int sqlite3_reconfig(int, ...);
  1253   1259   
  1254   1260   /*
  1255   1261   ** CAPI3REF: Configure database connections
  1256   1262   **
  1257   1263   ** The sqlite3_db_config() interface is used to make configuration
  1258   1264   ** changes to a [database connection].  The interface is similar to
  1259   1265   ** [sqlite3_config()] except that the changes apply to a single

Changes to src/test_malloc.c.

  1224   1224     Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
  1225   1225   
  1226   1226     return TCL_OK;
  1227   1227   }
  1228   1228   
  1229   1229   /*
  1230   1230   ** Usage:    sqlite3_config_readonly  BOOLEAN
         1231  +**           sqlite3_reconfig_readonly  BOOLEAN
  1231   1232   **
  1232   1233   ** Enables or disables global read-only mode using SQLITE_CONFIG_READONLY.
  1233   1234   */
  1234   1235   static int test_config_readonly(
  1235   1236     void * clientData, 
  1236   1237     Tcl_Interp *interp,
  1237   1238     int objc,
................................................................................
  1244   1245       Tcl_WrongNumArgs(interp, 1, objv, "BOOL");
  1245   1246       return TCL_ERROR;
  1246   1247     }
  1247   1248     if( Tcl_GetBooleanFromObj(interp, objv[1], &bReadOnly) ){
  1248   1249       return TCL_ERROR;
  1249   1250     }
  1250   1251   
  1251         -  rc = sqlite3_config(SQLITE_CONFIG_READONLY, bReadOnly);
         1252  +  switch( SQLITE_PTR_TO_INT(clientData) ){
         1253  +    case 0: {
         1254  +      rc = sqlite3_config(SQLITE_CONFIG_READONLY, bReadOnly);
         1255  +      break;
         1256  +    }
         1257  +    case 1: {
         1258  +      rc = sqlite3_reconfig(SQLITE_CONFIG_READONLY, bReadOnly);
         1259  +      break;
         1260  +    }
         1261  +    default: {
         1262  +      rc = SQLITE_ERROR;
         1263  +      break;
         1264  +    }
         1265  +  }
  1252   1266     Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL_VOLATILE);
  1253   1267   
  1254   1268     return TCL_OK;
  1255   1269   }
  1256   1270   
  1257   1271   /*
  1258   1272   ** Usage:    sqlite3_dump_memsys3  FILENAME
................................................................................
  1502   1516        { "sqlite3_config_heap",        test_config_heap              ,0 },
  1503   1517        { "sqlite3_config_memstatus",   test_config_memstatus         ,0 },
  1504   1518        { "sqlite3_config_lookaside",   test_config_lookaside         ,0 },
  1505   1519        { "sqlite3_config_error",       test_config_error             ,0 },
  1506   1520        { "sqlite3_config_uri",         test_config_uri               ,0 },
  1507   1521        { "sqlite3_config_cis",         test_config_cis               ,0 },
  1508   1522        { "sqlite3_config_readonly",    test_config_readonly          ,0 },
         1523  +     { "sqlite3_reconfig_readonly",  test_config_readonly          ,1 },
  1509   1524        { "sqlite3_db_config_lookaside",test_db_config_lookaside      ,0 },
  1510   1525        { "sqlite3_dump_memsys3",       test_dump_memsys3             ,3 },
  1511   1526        { "sqlite3_dump_memsys5",       test_dump_memsys3             ,5 },
  1512   1527        { "sqlite3_install_memsys3",    test_install_memsys3          ,0 },
  1513   1528        { "sqlite3_memdebug_vfs_oom_test", test_vfs_oom_test          ,0 },
  1514   1529     };
  1515   1530     int i;

Changes to test/openv2.test.

    52     52   } {1 {attempt to write a readonly database}}
    53     53   
    54     54   
    55     55   # Attempt to open a database with SQLITE_OPEN_READWRITE when the
    56     56   # SQLITE_CONFIG_READONLY flag is enabled.
    57     57   #
    58     58   db close
    59         -sqlite3_shutdown
    60         -sqlite3_config_readonly 1
    61         -sqlite3_initialize
    62         -autoinstall_test_functions
           59  +sqlite3_reconfig_readonly 1
    63     60   
    64     61   do_test openv2-3.1 {
    65     62     list [catch {sqlite3 db :memory:} msg] $msg
    66     63   } {1 {attempt to write a readonly database}}
    67     64   catch {db close}
    68     65   do_test openv2-3.2 {
    69     66     list [catch {sqlite3 db test.db} msg] $msg
................................................................................
    82     79   } {1 {attempt to write a readonly database}}
    83     80   catch {db close}
    84     81   do_test openv2-3.6 {
    85     82     list [catch {sqlite3 db test.db -readonly 0} msg] $msg
    86     83   } {1 {attempt to write a readonly database}}
    87     84   catch {db close}
    88     85   
    89         -sqlite3_shutdown
    90         -sqlite3_config_readonly 0
    91         -sqlite3_initialize
    92         -autoinstall_test_functions
           86  +sqlite3_reconfig_readonly 0
    93     87   finish_test