Index: src/main.c ================================================================== --- src/main.c +++ src/main.c @@ -2161,20 +2161,20 @@ /* Also add a UTF-8 case-insensitive collation sequence. */ createCollation(db, "NOCASE", SQLITE_UTF8, SQLITE_COLL_NOCASE, 0, nocaseCollatingFunc, 0); /* Parse the filename/URI argument. */ + db->openFlags = flags; rc = sqlite3ParseUri(zVfs, zFilename, &flags, &db->pVfs, &zOpen, &zErrMsg); if( rc!=SQLITE_OK ){ if( rc==SQLITE_NOMEM ) db->mallocFailed = 1; sqlite3Error(db, rc, zErrMsg ? "%s" : 0, zErrMsg); sqlite3_free(zErrMsg); goto opendb_out; } /* Open the backend database driver */ - db->openFlags = flags; rc = sqlite3BtreeOpen(db->pVfs, zOpen, db, &db->aDb[0].pBt, 0, flags | SQLITE_OPEN_MAIN_DB); if( rc!=SQLITE_OK ){ if( rc==SQLITE_IOERR_NOMEM ){ rc = SQLITE_NOMEM; Index: test/uri.test ================================================================== --- test/uri.test +++ test/uri.test @@ -19,10 +19,11 @@ # 2.*: That URI options (query parameters) are correctly extracted from URIs. # 3.*: That specifying an unknown VFS causes an error. # 4.*: Tests for specifying other options (other than "vfs"). # 5.*: Test using a different VFS with an attached database. # 6.*: Test that authorities other than "" and localhost cause errors. +# 7.*: Test that a read-write db can be attached to a read-only connection. # set testprefix uri db close sqlite3_shutdown @@ -280,7 +281,29 @@ sqlite3_errmsg $DB } $res catch { sqlite3_close $DB } } -finish_test +forcedelete test.db test.db2 +do_test 7.1 { + sqlite3 db test.db + execsql { + CREATE TABLE t1(a, b); + INSERT INTO t1 VALUES(1, 2); + ATTACH 'test.db2' AS aux; + CREATE TABLE aux.t2(a, b); + INSERT INTO t1 VALUES('a', 'b'); + } + db close +} {} +do_test 7.2 { + sqlite3 db file:test.db?mode=ro + execsql { ATTACH 'file:test.db2?mode=rw' AS aux } +} {} +do_execsql_test 7.3 { + INSERT INTO t2 VALUES('c', 'd') +} {} +do_catchsql_test 7.4 { + INSERT INTO t1 VALUES(3, 4) +} {1 {attempt to write a readonly database}} +finish_test