mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Add two new sqlite3_db_config() options that enable the ATTACH command
to create new database files and to open databases read/write. Both default to on for backwards compatibility. FossilOrigin-Name: fe0c58d00b491d1af7c0894f5c32542954aeea2e6510853b3bcbf13ac0bf5ce0
This commit is contained in:
@ -175,6 +175,12 @@ static void attachFunc(
|
||||
sqlite3_free(zErr);
|
||||
return;
|
||||
}
|
||||
if( (db->flags & SQLITE_AttachWrite)==0 ){
|
||||
flags &= ~(SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE);
|
||||
flags |= SQLITE_OPEN_READONLY;
|
||||
}else if( (db->flags & SQLITE_AttachCreate)==0 ){
|
||||
flags &= ~SQLITE_OPEN_CREATE;
|
||||
}
|
||||
assert( pVfs );
|
||||
flags |= SQLITE_OPEN_MAIN_DB;
|
||||
rc = sqlite3BtreeOpen(pVfs, zPath, db, &pNew->pBt, 0, flags);
|
||||
|
@ -959,7 +959,7 @@ int sqlite3_db_config(sqlite3 *db, int op, ...){
|
||||
default: {
|
||||
static const struct {
|
||||
int op; /* The opcode */
|
||||
u32 mask; /* Mask of the bit in sqlite3.flags to set/clear */
|
||||
u64 mask; /* Mask of the bit in sqlite3.flags to set/clear */
|
||||
} aFlagOp[] = {
|
||||
{ SQLITE_DBCONFIG_ENABLE_FKEY, SQLITE_ForeignKeys },
|
||||
{ SQLITE_DBCONFIG_ENABLE_TRIGGER, SQLITE_EnableTrigger },
|
||||
@ -980,6 +980,8 @@ int sqlite3_db_config(sqlite3 *db, int op, ...){
|
||||
{ SQLITE_DBCONFIG_TRUSTED_SCHEMA, SQLITE_TrustedSchema },
|
||||
{ SQLITE_DBCONFIG_STMT_SCANSTATUS, SQLITE_StmtScanStatus },
|
||||
{ SQLITE_DBCONFIG_REVERSE_SCANORDER, SQLITE_ReverseOrder },
|
||||
{ SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE, SQLITE_AttachCreate },
|
||||
{ SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE, SQLITE_AttachWrite },
|
||||
};
|
||||
unsigned int i;
|
||||
rc = SQLITE_ERROR; /* IMP: R-42790-23372 */
|
||||
@ -3321,6 +3323,8 @@ static int openDatabase(
|
||||
| SQLITE_EnableTrigger
|
||||
| SQLITE_EnableView
|
||||
| SQLITE_CacheSpill
|
||||
| SQLITE_AttachCreate
|
||||
| SQLITE_AttachWrite
|
||||
#if !defined(SQLITE_TRUSTED_SCHEMA) || SQLITE_TRUSTED_SCHEMA+0!=0
|
||||
| SQLITE_TrustedSchema
|
||||
#endif
|
||||
|
@ -8725,6 +8725,8 @@ static int do_meta_command(char *zLine, ShellState *p){
|
||||
const char *zName;
|
||||
int op;
|
||||
} aDbConfig[] = {
|
||||
{ "attach_create", SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE },
|
||||
{ "attach_write", SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE },
|
||||
{ "defensive", SQLITE_DBCONFIG_DEFENSIVE },
|
||||
{ "dqs_ddl", SQLITE_DBCONFIG_DQS_DDL },
|
||||
{ "dqs_dml", SQLITE_DBCONFIG_DQS_DML },
|
||||
|
@ -2523,6 +2523,41 @@ struct sqlite3_mem_methods {
|
||||
** first argument.
|
||||
** </dd>
|
||||
**
|
||||
** [[SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]]
|
||||
** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE</dt>
|
||||
** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE option enables the ability
|
||||
** of the [ATTACH DATABASE] SQL command to create a new database if the
|
||||
** database filed named by the SQL command does not already exist. This
|
||||
** ability of [ATTACH] to create a new database is enabled by default, but
|
||||
** can be disabled, using the current DBCONFIG option if desired.
|
||||
** This option takes two arguments which are an integer and a pointer
|
||||
** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
|
||||
** leave unchanged the attach-create flag, respectively. If the second
|
||||
** argument is not NULL, then 0 or 1 is written into the integer that the
|
||||
** second argument points to depending on if the attach-create flag is set
|
||||
** after processing the first argument.
|
||||
** </dd>
|
||||
**
|
||||
** [[SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE]]
|
||||
** <dt>SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE</dt>
|
||||
** <dd>The SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE option enables the ability
|
||||
** of the [ATTACH DATABASE] SQL command to create a new database that is
|
||||
** open for writing. This capability is enabled by default, but
|
||||
** can be disabled, using the current DBCONFIG option if desired. If this
|
||||
** capability is disabled, the [ATTACH] command will still work, but the
|
||||
** database is opened read-only. If this option is disabled, then the
|
||||
** ability to create a new database using [ATTACH] is also disabled,
|
||||
** regardless of the value of the [SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE]
|
||||
** option.
|
||||
** This option takes two arguments which are an integer and a pointer
|
||||
** to an integer. The first argument is 1, 0, or -1 to enable, disable, or
|
||||
** leave unchanged the ability to ATTACH another database for writing,
|
||||
** respectively. If the second argument is not NULL, then 0 or 1 is written
|
||||
** into the integer that the second argument points to depending on if the
|
||||
** ability to ATTACH a read/write database is set
|
||||
** after processing the first argument.
|
||||
** </dd>
|
||||
**
|
||||
** </dl>
|
||||
*/
|
||||
#define SQLITE_DBCONFIG_MAINDBNAME 1000 /* const char* */
|
||||
@ -2545,7 +2580,9 @@ struct sqlite3_mem_methods {
|
||||
#define SQLITE_DBCONFIG_TRUSTED_SCHEMA 1017 /* int int* */
|
||||
#define SQLITE_DBCONFIG_STMT_SCANSTATUS 1018 /* int int* */
|
||||
#define SQLITE_DBCONFIG_REVERSE_SCANORDER 1019 /* int int* */
|
||||
#define SQLITE_DBCONFIG_MAX 1019 /* Largest DBCONFIG */
|
||||
#define SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE 1020 /* int int* */
|
||||
#define SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE 1021 /* int int* */
|
||||
#define SQLITE_DBCONFIG_MAX 1021 /* Largest DBCONFIG */
|
||||
|
||||
/*
|
||||
** CAPI3REF: Enable Or Disable Extended Result Codes
|
||||
|
@ -1830,6 +1830,8 @@ struct sqlite3 {
|
||||
#define SQLITE_CorruptRdOnly HI(0x00002) /* Prohibit writes due to error */
|
||||
#define SQLITE_ReadUncommit HI(0x00004) /* READ UNCOMMITTED in shared-cache */
|
||||
#define SQLITE_FkNoAction HI(0x00008) /* Treat all FK as NO ACTION */
|
||||
#define SQLITE_AttachCreate HI(0x00010) /* ATTACH allowed to create new dbs */
|
||||
#define SQLITE_AttachWrite HI(0x00020) /* ATTACH allowed to open for write */
|
||||
|
||||
/* Flags used only if debugging */
|
||||
#ifdef SQLITE_DEBUG
|
||||
|
Reference in New Issue
Block a user