Have the ATTACH command do URI interpretation in the same way as sqlite3_open() and sqlite3_open_v2() do.

FossilOrigin-Name: 68240e75e87a54cde93352b0ec364d34365a8170
This commit is contained in:
dan 2011-04-23 15:54:54 +00:00
parent 5de1537478
commit 3a6d8aec2a
11 changed files with 77 additions and 25 deletions

View File

@ -1,5 +1,5 @@
C Fix\sparsing\sof\s%00\sin\suri\shandling\scode.
D 2011-04-23T10:12:30.605
C Have\sthe\sATTACH\scommand\sdo\sURI\sinterpretation\sin\sthe\ssame\sway\sas\ssqlite3_open()\sand\ssqlite3_open_v2()\sdo.
D 2011-04-23T15:54:54.370
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -116,19 +116,19 @@ F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
F src/alter.c 280f5c04b11b492703a342222b3de0a999445280
F src/analyze.c a425d62e8fa9ebcb4359ab84ff0c62c6563d2e2a
F src/attach.c 7f97ca76ef2453440170929531a9c778267c0830
F src/attach.c 79f8e5d286a2873e78d2068f35c4d6270572728f
F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
F src/backup.c 986c15232757f2873dff35ee3b35cbf935fc573c
F src/bitvec.c af50f1c8c0ff54d6bdb7a80e2fceca5a93670bef
F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
F src/btree.c 6a9164af8a2ef4612ee30b253635a9bd8e5e1b1b
F src/btree.h 11753dd46597a20702bca8746cb4caa4486a82b5
F src/btree.c 26f8a9d6169413c5682b89b5397d20437b653154
F src/btree.h f5d775cd6cfc7ac32a2535b70e8d2af48ef5f2ce
F src/btreeInt.h 67978c014fa4f7cc874032dd3aacadd8db656bc3
F src/build.c f09c46c66a1e7668c6ee25c9a2518aaa6842044c
F src/build.c 0132bc6631fa617a1d28ef805921f6dbac18a514
F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
F src/ctime.c 7deec4534f3b5a0c3b4a4cbadf809d321f64f9c4
F src/date.c 1548fdac51377e4e7833251de878b4058c148e1b
F src/date.c 0d63575d484322aeb344224f6a11ab7c00373dd0
F src/delete.c 7a24fcc9a31664d145acb97ce56b6d9f249a25e4
F src/expr.c e3cf0957c6b8faaaf7386a3bc69e53c0dc9705be
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
@ -143,7 +143,7 @@ F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e
F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f
F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e
F src/loadext.c 3ae0d52da013a6326310655be6473fd472347b85
F src/main.c cc9f5592000ee42e38b7086a097b19dc63518085
F src/main.c 8b4ebab18189148b702afd931efd2f40476e6e05
F src/malloc.c 74c740e8ba22b806cfb980c8c0ddea1cbd54a20e
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 00bd8265c81abb665c48fea1e0c234eb3b922206
@ -187,7 +187,7 @@ F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
F src/tclsqlite.c 501c9a200fd998a268be475be5858febc90b725b
F src/test1.c 9ca440e80e16e53920904a0a5ac7feffb9b2c9a1
F src/test2.c 80d323d11e909cf0eb1b6fbb4ac22276483bcf31
F src/test3.c 056093cfef69ff4227a6bdb9108564dc7f45e4bc
F src/test3.c 124ff9735fb6bb7d41de180d6bac90e7b1509432
F src/test4.c d1e5a5e904d4b444cf572391fdcb017638e36ff7
F src/test5.c e1a19845625144caf038031234a12185e40d315c
F src/test6.c c7256cc21d2409486d094277d5b017e8eced44ba
@ -235,7 +235,7 @@ F src/update.c 81911be16ece3c3e7716aa18565b4814ec41f8b9
F src/utf.c d83650c3ea08f7407bd9d0839d9885241c209c60
F src/util.c 914e860d21496b19a912cd14f6f7a889a22f44e1
F src/vacuum.c 05513dca036a1e7848fe18d5ed1265ac0b32365e
F src/vdbe.c 05deeec6659f2579674a5e6510b3ada2a442f8d5
F src/vdbe.c a7f8f72ae817f7f81a25be6e18d9a37e09b0649f
F src/vdbe.h 8a675fefdf7119441fe817c800a9a52440c2e797
F src/vdbeInt.h fe8f58d305e629fff02f61f655aca1d299f1f6ae
F src/vdbeapi.c e0e2672e0a96ae3f8575c8ecd02912a3e8a554a1
@ -837,7 +837,7 @@ F test/unique.test 083c7fff74695bcc27a71d75699deba3595bc9c2
F test/unixexcl.test 9d80a54d86d2261f660758928959368ffc36151e
F test/unordered.test e81169ce2a8f31b2c6b66af691887e1376ab3ced
F test/update.test 8bc86fd7ef1a00014f76dc6a6a7c974df4aef172
F test/uri.test b951a30a7cde3cdd978bdbfb2484c12a521f92d4
F test/uri.test 72d31f90b982e65763541db45ef3cb16f797d9fc
F test/utf16align.test 54cd35a27c005a9b6e7815d887718780b6a462ae
F test/vacuum.test 29b60e8cc9e573b39676df6c4a75fe9e02d04a09
F test/vacuum2.test 91a84c9b08adfc4472097d2e8deb0150214e0e76
@ -930,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
P b8a8132e7148a7c90ca1352f20ab71d97b0bc4b0
R d5dabedbe6f28cafb26739963e69b2b4
P 44f0874a95408c75a296964a04eef00341abb94a
R 72226daec7234c928303c103545adaa3
U dan
Z 7110de44a23dae8e6e6e15b3bc372cbd
Z b332a80681747acde88f379c7f0557c6

View File

@ -1 +1 @@
44f0874a95408c75a296964a04eef00341abb94a
68240e75e87a54cde93352b0ec364d34365a8170

View File

@ -70,8 +70,12 @@ static void attachFunc(
sqlite3 *db = sqlite3_context_db_handle(context);
const char *zName;
const char *zFile;
char *zPath = 0;
char *zErr = 0;
int flags;
Db *aNew;
char *zErrDyn = 0;
sqlite3_vfs *pVfs;
UNUSED_PARAMETER(NotUsed);
@ -124,8 +128,17 @@ static void attachFunc(
** it to obtain the database schema. At this point the schema may
** or may not be initialised.
*/
rc = sqlite3BtreeOpen(zFile, db, &aNew->pBt, 0,
db->openFlags | SQLITE_OPEN_MAIN_DB);
flags = db->openFlags;
rc = sqlite3ParseUri(db->pVfs->zName, zFile, &flags, &pVfs, &zPath, &zErr);
if( rc!=SQLITE_OK ){
sqlite3_result_error(context, zErr, -1);
sqlite3_free(zErr);
return;
}
assert( pVfs );
flags |= SQLITE_OPEN_MAIN_DB;
rc = sqlite3BtreeOpen(pVfs, zPath, db, &aNew->pBt, 0, flags);
sqlite3_free( zPath );
db->nDb++;
if( rc==SQLITE_CONSTRAINT ){
rc = SQLITE_ERROR;

View File

@ -1688,13 +1688,13 @@ static int btreeInvokeBusyHandler(void *pArg){
** to problems with locking.
*/
int sqlite3BtreeOpen(
sqlite3_vfs *pVfs, /* VFS to use for this b-tree */
const char *zFilename, /* Name of the file containing the BTree database */
sqlite3 *db, /* Associated database handle */
Btree **ppBtree, /* Pointer to new Btree object written here */
int flags, /* Options */
int vfsFlags /* Flags passed through to sqlite3_vfs.xOpen() */
){
sqlite3_vfs *pVfs; /* The VFS to use for this btree */
BtShared *pBt = 0; /* Shared part of btree structure */
Btree *p; /* Handle to return */
sqlite3_mutex *mutexOpen = 0; /* Prevents a race condition. Ticket #3537 */
@ -1716,6 +1716,7 @@ int sqlite3BtreeOpen(
#endif
assert( db!=0 );
assert( pVfs!=0 );
assert( sqlite3_mutex_held(db->mutex) );
assert( (flags&0xff)==flags ); /* flags fit in 8 bits */
@ -1734,7 +1735,6 @@ int sqlite3BtreeOpen(
if( (vfsFlags & SQLITE_OPEN_MAIN_DB)!=0 && (isMemdb || isTempDb) ){
vfsFlags = (vfsFlags & ~SQLITE_OPEN_MAIN_DB) | SQLITE_OPEN_TEMP_DB;
}
pVfs = db->pVfs;
p = sqlite3MallocZero(sizeof(Btree));
if( !p ){
return SQLITE_NOMEM;

View File

@ -42,6 +42,7 @@ typedef struct BtShared BtShared;
int sqlite3BtreeOpen(
sqlite3_vfs *pVfs, /* VFS to use with this b-tree */
const char *zFilename, /* Name of database file to open */
sqlite3 *db, /* Associated database connection */
Btree **ppBtree, /* Return open Btree* here */

View File

@ -3443,7 +3443,7 @@ int sqlite3OpenTempDatabase(Parse *pParse){
SQLITE_OPEN_DELETEONCLOSE |
SQLITE_OPEN_TEMP_DB;
rc = sqlite3BtreeOpen(0, db, &pBt, 0, flags);
rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pBt, 0, flags);
if( rc!=SQLITE_OK ){
sqlite3ErrorMsg(pParse, "unable to open a temporary database "
"file for storing temporary tables");

View File

@ -1039,7 +1039,7 @@ static void currentTimeFunc(
UNUSED_PARAMETER(argv);
db = sqlite3_context_db_handle(context);
sqlite3OsCurrentTimeInt64(db->pVfs, &iT);
sqlite3OsCurrentTimeInt64(db->pVfs &iT);
t = iT/1000 - 10000*(sqlite3_int64)21086676;
#ifdef HAVE_GMTIME_R
{

View File

@ -2106,7 +2106,7 @@ static int openDatabase(
/* Open the backend database driver */
db->openFlags = flags;
rc = sqlite3BtreeOpen(zOpen, db, &db->aDb[0].pBt, 0,
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 ){

View File

@ -78,7 +78,7 @@ static int btree_open(
sDb.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
sqlite3_mutex_enter(sDb.mutex);
}
rc = sqlite3BtreeOpen(argv[1], &sDb, &pBt, 0,
rc = sqlite3BtreeOpen(sDb.pVfs, argv[1], &sDb, &pBt, 0,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB);
if( rc!=SQLITE_OK ){
Tcl_AppendResult(interp, errorName(rc), 0);

View File

@ -3132,7 +3132,7 @@ case OP_OpenEphemeral: {
pCx = allocateCursor(p, pOp->p1, pOp->p2, -1, 1);
if( pCx==0 ) goto no_mem;
pCx->nullRow = 1;
rc = sqlite3BtreeOpen(0, db, &pCx->pBt,
rc = sqlite3BtreeOpen(db->pVfs, 0, db, &pCx->pBt,
BTREE_OMIT_JOURNAL | BTREE_SINGLE | pOp->p5, vfsFlags);
if( rc==SQLITE_OK ){
rc = sqlite3BtreeBeginTrans(pCx->pBt, 1);

View File

@ -47,6 +47,13 @@ foreach {tn uri file} {
set DB [sqlite3_open $uri]
do_test 1.$tn.2 { file exists $file } 1
sqlite3_close $DB
forcedelete $file
do_test 1.$tn.3 { file exists $file } 0
sqlite3 db xxx.db
execsql { ATTACH $uri AS aux }
do_test 1.$tn.4 { file exists $file } 1
db close
}
@ -73,11 +80,19 @@ foreach {tn uri kvlist} {
10 file:test.db?hello=%00world&xyz= {hello {} xyz {}}
11 file:test.db?=#ravada {}
12 file:test.db?&&&&&&&&hello=world&&&&&&& {hello world}
13 test.db?&&&&&&&&hello=world&&&&&&& {}
14 http:test.db?hello&world {}
} {
set ::arglist ""
set DB [sqlite3_open $uri]
do_test 2.$tn { set ::arglist } $kvlist
do_test 2.$tn.1 { set ::arglist } $kvlist
sqlite3_close $DB
sqlite3 db xxx.db
set ::arglist ""
execsql { ATTACH $uri AS aux }
do_test 2.$tn.2 { set ::arglist } $kvlist
db close
}
tvfs delete
@ -88,5 +103,28 @@ do_test 3.1 {
list [catch { sqlite3 db "file:test.db?vfs=nosuchvfs" } msg] $msg
} {1 {no such vfs: nosuchvfs}}
#-------------------------------------------------------------------------
# Test the "readonly" URI option.
#
do_test 4.0 {
sqlite3 db test.db
db eval {CREATE TABLE t1(a, b)}
db close
} {}
foreach {tn uri ro} {
1 "file:test.db" 0
2 "file:test.db?readonly=0" 0
3 "file:test.db?readonly=1&readwrite=0&create=0" 1
} {
set RES(0) {0 {}}
set RES(1) {1 {attempt to write a readonly database}}
do_test 4.$tn {
sqlite3 db $uri
catchsql { INSERT INTO t1 VALUES(1, 2) }
} $RES($ro)
db close
}
finish_test