1
0
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:
drh
2025-01-22 19:37:47 +00:00
parent 9489aefb83
commit c850c2be75
7 changed files with 67 additions and 13 deletions

View File

@ -1,5 +1,5 @@
C Add\sthe\s-q/--quiet\soption\sto\stest/speedtest.tcl.\s\sAutomatically\senable\n-DSQLITE_OMIT_LOAD_EXTENSION\sand\s-DSQLITE_THREADSAFE=0\sso\sthat\sno\sextra\nlibraries\sare\srequired.
D 2025-01-22T17:18:53.134
C Add\stwo\snew\ssqlite3_db_config()\soptions\sthat\senable\sthe\sATTACH\scommand\nto\screate\snew\sdatabase\sfiles\sand\sto\sopen\sdatabases\sread/write.\s\sBoth\ndefault\sto\son\sfor\sbackwards\scompatibility.
D 2025-01-22T19:37:47.938
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
@ -713,7 +713,7 @@ F sqlite3.1 acdff36db796e2d00225b911d3047d580cd136547298435426ce9d40347973cc
F sqlite3.pc.in 0977c03a4da7c4204bd60e784a0efb8d51a190448aba78a4e973fe7192bdaf03
F src/alter.c aa93e37e4a36a0525bbb2a2aeda20d2018f0aa995542c7dc658e031375e3f532
F src/analyze.c 9a8b67239d899ac12289db5db3f5bfe7f7a0ad1277f80f87ead1d048085876eb
F src/attach.c f35bb8cc1fcdde8f6815a7ef09ae413bcac71821d530796800ba24b3c7da1e80
F src/attach.c 3a5cb9ee4aad6c5b22268287340a4f2f7b07959b7a522201be30fee23cd802e9
F src/auth.c 54ab9c6c5803b47c0d45b76ce27eff22a03b4b1f767c5945a3a4eb13aa4c78dc
F src/backup.c 5c97e8023aab1ce14a42387eb3ae00ba5a0644569e3476f38661fa6f824c3523
F src/bitvec.c 9eac5f42c11914d5ef00a75605bb205e934f435c579687f985f1f8b0995c8645
@ -742,7 +742,7 @@ F src/insert.c f8d1a0f8ee258411009c6b7f2d93170e351bd19f5ad89d57e1180644297cbe70
F src/json.c 68a98c020c22127f2d65f08855f7fc7460ff352a6ce0b543d8931dde83319c22
F src/legacy.c d7874bc885906868cd51e6c2156698f2754f02d9eee1bae2d687323c3ca8e5aa
F src/loadext.c 7432c944ff197046d67a1207790a1b13eec4548c85a9457eb0896bb3641dfb36
F src/main.c a19dc8b47760ed95f3fbb255cfa8d3f7146b33c263eb4af05ab05e0115d161b9
F src/main.c 84239c53aaac3aa1734eaf33a41d575c1d2494313bd8af5e6d885f0dc0547cfd
F src/malloc.c 410e570b30c26cc36e3372577df50f7a96ee3eed5b2b161c6b6b48773c650c5e
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 3bb59158c38e05f6270e761a9f435bf19827a264c13d1631c58b84bdc96d73b2
@ -780,11 +780,11 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c c8a5372b97b2a2e972a280676f06ddb5b74e885d3b1f5ce383f839907b57ef68
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
F src/select.c 83e88fbb36f89b6703b348777491619554f0fd6f917c9fdf51e4c2e9cda6c04e
F src/shell.c.in 9ade75afa953c5c2ded38d076533eaa6c9b2ab1977ef6cce0bc773adac178c50
F src/sqlite.h.in 6afbcaae44140216704a6c82e4c4ea4118c46d5f6573d6c5fa4fc901ed9d369e
F src/shell.c.in 9915487b27e3169d59a4018c88d14246059c392c662d98fc516264267396b65e
F src/sqlite.h.in 666fa171bf5a9fa532b637571303a596c80723e89f3e10962c0d81378b2b789d
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
F src/sqliteInt.h 953f2476f712b115ecb43f7a21183d07c88af8d3b4c32f18317724ce1ce04d56
F src/sqliteInt.h dd2385d05fbc892d865296fa3f493ba132044a2bbbd15bfad67984bb4afba1d3
F src/sqliteLimit.h 1bbdbf72bd0411d003267ffebc59a262f061df5653027a75627d03f48ca30523
F src/status.c cb11f8589a6912af2da3bb1ec509a94dd8ef27df4d4c1a97e0bcf2309ece972b
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
@ -2208,8 +2208,11 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P afb0a5923a6db4045fab5226198aab970d746d4866294ebba943c6986e97ecde
R 9d6f6255d4d3d13ac3e7250fb9209015
P c20d21b473d8a45267262c5df1d7b102eccce8e4cfbe1e467ea66c474aea0af5
R 1e3a803f41f6c1dff31eede2c9428a7d
T *branch * enable-attach
T *sym-enable-attach *
T -sym-trunk *
U drh
Z 359fbb7e57428de2830f61ee25224064
Z 45431d003e2c2a4fccdcefe1b482f2e1
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
c20d21b473d8a45267262c5df1d7b102eccce8e4cfbe1e467ea66c474aea0af5
fe0c58d00b491d1af7c0894f5c32542954aeea2e6510853b3bcbf13ac0bf5ce0

View File

@ -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);

View File

@ -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

View File

@ -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 },

View File

@ -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

View File

@ -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