From 73795becfe6358659b482f4ebd9a7c0358161a29 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 12 Dec 2011 20:01:12 +0000 Subject: [PATCH 1/6] Backport a minimal set of changes needed to get 8+3 filenames and the multiplexor shim playing well together. FossilOrigin-Name: c4e2ce486217c96373836bfe641f46abf891799a --- manifest | 19 ++++++++++------- manifest.uuid | 2 +- src/os_unix.c | 2 +- src/shell.c | 4 ++-- src/test_multiplex.c | 50 ++++++++++++++++++++++---------------------- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/manifest b/manifest index aa26307489..7bfa9b8297 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Improvements\sto\sthe\sdocumentation\sof\sthe\ssqlite3_db_filename()\sinterface. -D 2011-11-17T11:49:58.484 +C Backport\sa\sminimal\sset\sof\schanges\sneeded\sto\sget\s8+3\sfilenames\sand\sthe\nmultiplexor\sshim\splaying\swell\stogether. +D 2011-12-12T20:01:12.623 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -166,7 +166,7 @@ F src/os.c 28bbdab2170dfce84d86c45456a18eab1d0f99a9 F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9 F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 -F src/os_unix.c 4fbb91726165e105c1679a2660f49a3f4c376e4f +F src/os_unix.c 02b3794c008bab490689399cca9a8b81c1df6eaa F src/os_win.c a22b88d2c088c09a678a471abafa8d60dbf56803 F src/pager.c d981f3bfcc0e4460537d983899620700ccf8f539 F src/pager.h 5cd760857707529b403837d813d86b68938d6183 @@ -181,7 +181,7 @@ F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 365ab1c870e38596d6869e76fb544fe6e4ffc809 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c 80f3ac44a8514b1d107b80f5df4a424ae059d2b6 -F src/shell.c 29812a900a780eb0f835c4bc65e216272689def8 +F src/shell.c 183c4b6a84e82c768fefcc554a1256e89fc8feba F src/sqlite.h.in 19706a000717456c4963bb0f96262581436ffb5a F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 F src/sqliteInt.h f412e020e1009163c74be56eaac1bf7f6c0a4515 @@ -214,7 +214,7 @@ F src/test_intarray.h 489edb9068bb926583445cb02589344961054207 F src/test_journal.c 03313c693cca72959dcaaf79f8d76f21c01e19ff F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e F src/test_malloc.c 8d416f29ad8573f32601f6056c9d2b17472e9ad5 -F src/test_multiplex.c 3fc368022c46fe44ec22c5e1ed727223a54a6a1d +F src/test_multiplex.c 7dcf429b53f5f5ef22bba7987bea61234a0c7418 F src/test_multiplex.h e99c571bc4968b7a9363b661481f3934bfead61d F src/test_mutex.c a6bd7b9cf6e19d989e31392b06ac8d189f0d573e F src/test_onefile.c 40cf9e212a377a6511469384a64b01e6e34b2eec @@ -976,7 +976,10 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P 4d3cf9e1d8ac356db5a708913f614e42a6a56b94 -R daa1b38027d3a49fc0c491c85b1f5a39 +P 1c45b2a0c055f6fc5da9d00ae2e9171099d904d4 +R d417f9c46d07ddef314e54db481adadc +T *branch * nx-devkit +T *sym-nx-devkit * +T -sym-trunk * U drh -Z f65f1ce31dbae92bc408999ba5cab4af +Z 6224f10399d131c42f88b8ba9dbbfa5d diff --git a/manifest.uuid b/manifest.uuid index 261f1cf6ad..b0605ecc85 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1c45b2a0c055f6fc5da9d00ae2e9171099d904d4 \ No newline at end of file +c4e2ce486217c96373836bfe641f46abf891799a \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 51d144906a..ecd5bf2448 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -4899,7 +4899,7 @@ static int findCreateFileMode( */ nDb = sqlite3Strlen30(zPath) - 1; #ifdef SQLITE_ENABLE_8_3_NAMES - while( nDb>0 && !sqlite3Isalnum(zPath[nDb]) ) nDb--; + while( nDb>0 && sqlite3Isalnum(zPath[nDb]) ) nDb--; if( nDb==0 || zPath[nDb]!='-' ) return SQLITE_OK; #else while( zPath[nDb]!='-' ){ diff --git a/src/shell.c b/src/shell.c index e33a0687b4..07b1b60b41 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2335,7 +2335,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ }else if( c=='v' && strncmp(azArg[0], "version", n)==0 ){ - printf("SQLite %s %s\n", + printf("SQLite %s %s\n" /*extra-version-info*/, sqlite3_libversion(), sqlite3_sourceid()); }else @@ -2932,7 +2932,7 @@ int main(int argc, char **argv){ char *zHistory = 0; int nHistory; printf( - "SQLite version %s %.19s\n" + "SQLite version %s %.19s\n" /*extra-version-info*/ "Enter \".help\" for instructions\n" "Enter SQL statements terminated with a \";\"\n", sqlite3_libversion(), sqlite3_sourceid() diff --git a/src/test_multiplex.c b/src/test_multiplex.c index 5d29607acb..091f2395fd 100644 --- a/src/test_multiplex.c +++ b/src/test_multiplex.c @@ -96,26 +96,16 @@ # define SQLITE_MULTIPLEX_CHUNK_SIZE 2147418112 #endif -/* Default limit on number of chunks. Care should be taken -** so that values for chunks numbers fit in the SQLITE_MULTIPLEX_EXT_FMT -** format specifier. It may be changed by calling -** the xFileControl() interface. +/* This used to be the default limit on number of chunks, but +** it is no longer enforced. There is currently no limit to the +** number of chunks. +** +** May be changed by calling the xFileControl() interface. */ #ifndef SQLITE_MULTIPLEX_MAX_CHUNKS -# define SQLITE_MULTIPLEX_MAX_CHUNKS 32 +# define SQLITE_MULTIPLEX_MAX_CHUNKS 12 #endif -/* If SQLITE_MULTIPLEX_EXT_OVWR is defined, the -** last SQLITE_MULTIPLEX_EXT_SZ characters of the -** filename will be overwritten, otherwise, the -** multiplex extension is simply appended to the filename. -** Ex. (undefined) test.db -> test.db01 -** (defined) test.db -> test.01 -** Chunk 0 does not have a modified extension. -*/ -#define SQLITE_MULTIPLEX_EXT_FMT "%02d" -#define SQLITE_MULTIPLEX_EXT_SZ 2 - /************************ Object Definitions ******************************/ /* Forward declaration of all object types */ @@ -304,20 +294,25 @@ static int multiplexSubFilename(multiplexGroup *pGroup, int iChunk){ if( pGroup->aReal[iChunk].z==0 ){ char *z; int n = pGroup->nName; - pGroup->aReal[iChunk].z = z = sqlite3_malloc( n+3 ); + pGroup->aReal[iChunk].z = z = sqlite3_malloc( n+4 ); if( z==0 ){ return SQLITE_NOMEM; } memcpy(z, pGroup->zName, n+1); if( iChunk>0 ){ #ifdef SQLITE_ENABLE_8_3_NAMES - if( n>3 && z[n-3]=='.' ){ - n--; - }else if( n>4 && z[n-4]=='.' ){ - n -= 2; + int i; + for(i=n-1; i>0 && i>=n-4 && z[i]!='.'; i--){} + if( i>=n-4 ) n = i+1; + if( pGroup->flags & (SQLITE_OPEN_MAIN_JOURNAL|SQLITE_OPEN_TEMP_JOURNAL) ){ + /* The extensions on overflow files for main databases are 001, 002, + ** 003 and so forth. To avoid name collisions, add 100 to the + ** extensions of journal files so that they are 101, 102, 103, .... + */ + iChunk += 100; } #endif - sqlite3_snprintf(3,&z[n],"%02d",iChunk); + sqlite3_snprintf(4,&z[n],"%03d",iChunk); } } return SQLITE_OK; @@ -754,7 +749,7 @@ static int multiplexTruncate(sqlite3_file *pConn, sqlite3_int64 size){ }else{ rc = pSubOpen->pMethods->xTruncate(pSubOpen, size); } - }else{ + }else if( (pGroup->flags & SQLITE_OPEN_MAIN_DB)==0 ){ int rc2; int i; sqlite3_file *pSubOpen; @@ -819,8 +814,13 @@ static int multiplexFileSize(sqlite3_file *pConn, sqlite3_int64 *pSize){ int exists = 0; rc = multiplexSubFilename(pGroup, i); if( rc ) break; - rc2 = pOrigVfs->xAccess(pOrigVfs, pGroup->aReal[i].z, - SQLITE_ACCESS_EXISTS, &exists); + if( pGroup->flags & SQLITE_OPEN_DELETEONCLOSE ){ + exists = pGroup->nReal>=i && pGroup->aReal[i].p!=0; + rc2 = SQLITE_OK; + }else{ + rc2 = pOrigVfs->xAccess(pOrigVfs, pGroup->aReal[i].z, + SQLITE_ACCESS_EXISTS, &exists); + } if( rc2==SQLITE_OK && exists){ /* if it exists, open it */ pSubOpen = multiplexSubOpen(pGroup, i, &rc, NULL); From 9797706c048e1051147272cb81a894ac5284de20 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 13 Dec 2011 01:34:21 +0000 Subject: [PATCH 2/6] Add a compile-time shutdown procedure to be called by sqlite3_shutdown() to undo the effects of the compile-time initialization procedure. FossilOrigin-Name: c2ed86f5945662a4ddcdc7b303df3f64fb3bf17d --- manifest | 15 ++++++--------- manifest.uuid | 2 +- src/main.c | 4 ++++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 7bfa9b8297..8d8dddccea 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Backport\sa\sminimal\sset\sof\schanges\sneeded\sto\sget\s8+3\sfilenames\sand\sthe\nmultiplexor\sshim\splaying\swell\stogether. -D 2011-12-12T20:01:12.623 +C Add\sa\scompile-time\sshutdown\sprocedure\sto\sbe\scalled\sby\ssqlite3_shutdown()\s\nto\sundo\sthe\seffects\sof\sthe\scompile-time\sinitialization\sprocedure. +D 2011-12-13T01:34:21.866 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -147,7 +147,7 @@ F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f F src/lempar.c 0ee69fca0be54cd93939df98d2aca4ca46f44416 F src/loadext.c d0d2022a5a07274d408820b978b9e549189d314f -F src/main.c 55cbc40465fb58708cb82d4a285a6ea8cf1e4581 +F src/main.c f6abb5b6e34cefce99e598a59da7f9282cb95476 F src/malloc.c 591aedb20ae40813f1045f2ef253438a334775d9 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 7456e2ca0524609ebc06a9befeda5289d4575ad4 @@ -976,10 +976,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P 1c45b2a0c055f6fc5da9d00ae2e9171099d904d4 -R d417f9c46d07ddef314e54db481adadc -T *branch * nx-devkit -T *sym-nx-devkit * -T -sym-trunk * +P c4e2ce486217c96373836bfe641f46abf891799a +R d65c08a2f3d54828df6dbe84b5def66b U drh -Z 6224f10399d131c42f88b8ba9dbbfa5d +Z a5e8c7320fe29c2fddbea8503f1c5fe2 diff --git a/manifest.uuid b/manifest.uuid index b0605ecc85..087f5b1d8d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c4e2ce486217c96373836bfe641f46abf891799a \ No newline at end of file +c2ed86f5945662a4ddcdc7b303df3f64fb3bf17d \ No newline at end of file diff --git a/src/main.c b/src/main.c index 43cd82eaa6..95f2e96872 100644 --- a/src/main.c +++ b/src/main.c @@ -257,6 +257,10 @@ int sqlite3_initialize(void){ */ int sqlite3_shutdown(void){ if( sqlite3GlobalConfig.isInit ){ +#ifdef SQLITE_EXTRA_SHUTDOWN + void SQLITE_EXTRA_SHUTDOWN(void); + SQLITE_EXTRA_SHUTDOWN(); +#endif sqlite3_os_end(); sqlite3_reset_auto_extension(); sqlite3GlobalConfig.isInit = 0; From 43795e3b0b62ad9a1ab17ab4aca23950f3651be3 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 13 Dec 2011 02:41:13 +0000 Subject: [PATCH 3/6] When the multiplexor FileSize procedure fails to open the file, assume that the file is zero bytes in size. FossilOrigin-Name: dc8118cd89da71f2035c6ee07c0edb772bba2186 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/test_multiplex.c | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8d8dddccea..63d5302050 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\scompile-time\sshutdown\sprocedure\sto\sbe\scalled\sby\ssqlite3_shutdown()\s\nto\sundo\sthe\seffects\sof\sthe\scompile-time\sinitialization\sprocedure. -D 2011-12-13T01:34:21.866 +C When\sthe\smultiplexor\sFileSize\sprocedure\sfails\sto\sopen\sthe\sfile,\sassume\sthat\nthe\sfile\sis\szero\sbytes\sin\ssize. +D 2011-12-13T02:41:13.433 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/test_intarray.h 489edb9068bb926583445cb02589344961054207 F src/test_journal.c 03313c693cca72959dcaaf79f8d76f21c01e19ff F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e F src/test_malloc.c 8d416f29ad8573f32601f6056c9d2b17472e9ad5 -F src/test_multiplex.c 7dcf429b53f5f5ef22bba7987bea61234a0c7418 +F src/test_multiplex.c 56f837b9cafb0efb641a4073226f2b05a2c4872d F src/test_multiplex.h e99c571bc4968b7a9363b661481f3934bfead61d F src/test_mutex.c a6bd7b9cf6e19d989e31392b06ac8d189f0d573e F src/test_onefile.c 40cf9e212a377a6511469384a64b01e6e34b2eec @@ -976,7 +976,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P c4e2ce486217c96373836bfe641f46abf891799a -R d65c08a2f3d54828df6dbe84b5def66b +P c2ed86f5945662a4ddcdc7b303df3f64fb3bf17d +R 54dcfa200fabf4bee31d0ce1ef27bb67 U drh -Z a5e8c7320fe29c2fddbea8503f1c5fe2 +Z 12069cbcb91e3fccb976a5eab6a4fcac diff --git a/manifest.uuid b/manifest.uuid index 087f5b1d8d..216e947580 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c2ed86f5945662a4ddcdc7b303df3f64fb3bf17d \ No newline at end of file +dc8118cd89da71f2035c6ee07c0edb772bba2186 \ No newline at end of file diff --git a/src/test_multiplex.c b/src/test_multiplex.c index 091f2395fd..1a3fbdef9f 100644 --- a/src/test_multiplex.c +++ b/src/test_multiplex.c @@ -798,11 +798,12 @@ static int multiplexFileSize(sqlite3_file *pConn, sqlite3_int64 *pSize){ int rc = SQLITE_OK; int rc2; int i; + *pSize = 0; multiplexEnter(); if( !pGroup->bEnabled ){ sqlite3_file *pSubOpen = multiplexSubOpen(pGroup, 0, &rc, NULL); if( pSubOpen==0 ){ - rc = SQLITE_IOERR_FSTAT; + rc = SQLITE_OK; /* If SubOpen failed, assume a size of zero */ }else{ rc = pSubOpen->pMethods->xFileSize(pSubOpen, pSize); } @@ -813,7 +814,7 @@ static int multiplexFileSize(sqlite3_file *pConn, sqlite3_int64 *pSize){ sqlite3_file *pSubOpen = 0; int exists = 0; rc = multiplexSubFilename(pGroup, i); - if( rc ) break; + if( rc ){ rc = SQLITE_OK; /* Assume size of zero */ break; } if( pGroup->flags & SQLITE_OPEN_DELETEONCLOSE ){ exists = pGroup->nReal>=i && pGroup->aReal[i].p!=0; rc2 = SQLITE_OK; From e5077c1211eba1a30995fb5fac43353c54cfad43 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 13 Dec 2011 04:08:36 +0000 Subject: [PATCH 4/6] When an sqlite3_auto_extension() function fails, report back its actual error code, not the generic SQLITE_ERROR. FossilOrigin-Name: ce55f250f56fa3a1ca864f81e9e86f911b981490 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/loadext.c | 5 +++-- src/main.c | 9 ++++++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 63d5302050..5d96461685 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\sthe\smultiplexor\sFileSize\sprocedure\sfails\sto\sopen\sthe\sfile,\sassume\sthat\nthe\sfile\sis\szero\sbytes\sin\ssize. -D 2011-12-13T02:41:13.433 +C When\san\ssqlite3_auto_extension()\sfunction\sfails,\sreport\sback\sits\sactual\nerror\scode,\snot\sthe\sgeneric\sSQLITE_ERROR. +D 2011-12-13T04:08:36.892 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -146,8 +146,8 @@ F src/insert.c 8f283d6734dd837ed7531b26d7622fda70874390 F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f F src/lempar.c 0ee69fca0be54cd93939df98d2aca4ca46f44416 -F src/loadext.c d0d2022a5a07274d408820b978b9e549189d314f -F src/main.c f6abb5b6e34cefce99e598a59da7f9282cb95476 +F src/loadext.c f20382fbaeec832438a1ba7797bee3d3c8a6d51d +F src/main.c 8fc06b5ab42330f26d13fbd8f969eead1d214556 F src/malloc.c 591aedb20ae40813f1045f2ef253438a334775d9 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 7456e2ca0524609ebc06a9befeda5289d4575ad4 @@ -976,7 +976,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P c2ed86f5945662a4ddcdc7b303df3f64fb3bf17d -R 54dcfa200fabf4bee31d0ce1ef27bb67 +P dc8118cd89da71f2035c6ee07c0edb772bba2186 +R fcee0dd6fa555d5216e315a8c5784053 U drh -Z 12069cbcb91e3fccb976a5eab6a4fcac +Z 9d7ca46858b8a86804ab1862673e090c diff --git a/manifest.uuid b/manifest.uuid index 216e947580..1c74b293b8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -dc8118cd89da71f2035c6ee07c0edb772bba2186 \ No newline at end of file +ce55f250f56fa3a1ca864f81e9e86f911b981490 \ No newline at end of file diff --git a/src/loadext.c b/src/loadext.c index e9c97adff3..3fcf5008cf 100644 --- a/src/loadext.c +++ b/src/loadext.c @@ -625,6 +625,7 @@ void sqlite3_reset_auto_extension(void){ void sqlite3AutoLoadExtensions(sqlite3 *db){ int i; int go = 1; + int rc; int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); wsdAutoextInit; @@ -647,8 +648,8 @@ void sqlite3AutoLoadExtensions(sqlite3 *db){ } sqlite3_mutex_leave(mutex); zErrmsg = 0; - if( xInit && xInit(db, &zErrmsg, &sqlite3Apis) ){ - sqlite3Error(db, SQLITE_ERROR, + if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){ + sqlite3Error(db, rc, "automatic extension loading failed: %s", zErrmsg); go = 0; } diff --git a/src/main.c b/src/main.c index 95f2e96872..229af8607c 100644 --- a/src/main.c +++ b/src/main.c @@ -2250,10 +2250,13 @@ static int openDatabase( /* Load automatic extensions - extensions that have been registered ** using the sqlite3_automatic_extension() API. */ - sqlite3AutoLoadExtensions(db); rc = sqlite3_errcode(db); - if( rc!=SQLITE_OK ){ - goto opendb_out; + if( rc==SQLITE_OK ){ + sqlite3AutoLoadExtensions(db); + rc = sqlite3_errcode(db); + if( rc!=SQLITE_OK ){ + goto opendb_out; + } } #ifdef SQLITE_ENABLE_FTS1 From 5b1626aa472c520e50f569766e7944cfdf7657d1 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 13 Dec 2011 15:02:54 +0000 Subject: [PATCH 5/6] Move the multiplexor changes in the experimental branch (check-ins [255d21499b] and [199f52bced]) into the nx-devkit branch. FossilOrigin-Name: eb95d2f72c625bcfd0f8e9db1db2cb8799854b57 --- manifest | 12 +-- manifest.uuid | 2 +- src/test_multiplex.c | 182 ++++++++++++------------------------------- 3 files changed, 58 insertions(+), 138 deletions(-) diff --git a/manifest b/manifest index 5d96461685..b1b9ea84ff 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C When\san\ssqlite3_auto_extension()\sfunction\sfails,\sreport\sback\sits\sactual\nerror\scode,\snot\sthe\sgeneric\sSQLITE_ERROR. -D 2011-12-13T04:08:36.892 +C Move\sthe\smultiplexor\schanges\sin\sthe\sexperimental\sbranch\n(check-ins\s[255d21499b]\sand\s[199f52bced])\sinto\sthe\snx-devkit\sbranch. +D 2011-12-13T15:02:54.819 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/test_intarray.h 489edb9068bb926583445cb02589344961054207 F src/test_journal.c 03313c693cca72959dcaaf79f8d76f21c01e19ff F src/test_loadext.c df586c27176e3c2cb2e099c78da67bf14379a56e F src/test_malloc.c 8d416f29ad8573f32601f6056c9d2b17472e9ad5 -F src/test_multiplex.c 56f837b9cafb0efb641a4073226f2b05a2c4872d +F src/test_multiplex.c 10aaf8b7ebeb74f82d5c96e06c398b776917e457 F src/test_multiplex.h e99c571bc4968b7a9363b661481f3934bfead61d F src/test_mutex.c a6bd7b9cf6e19d989e31392b06ac8d189f0d573e F src/test_onefile.c 40cf9e212a377a6511469384a64b01e6e34b2eec @@ -976,7 +976,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P dc8118cd89da71f2035c6ee07c0edb772bba2186 -R fcee0dd6fa555d5216e315a8c5784053 +P ce55f250f56fa3a1ca864f81e9e86f911b981490 +R cc774ebd7c088b6b617c7f855781c545 U drh -Z 9d7ca46858b8a86804ab1862673e090c +Z 1b3d8d40cb48e276ed9ae7077034a64e diff --git a/manifest.uuid b/manifest.uuid index 1c74b293b8..a4233b55c6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ce55f250f56fa3a1ca864f81e9e86f911b981490 \ No newline at end of file +eb95d2f72c625bcfd0f8e9db1db2cb8799854b57 \ No newline at end of file diff --git a/src/test_multiplex.c b/src/test_multiplex.c index 1a3fbdef9f..ce55bad083 100644 --- a/src/test_multiplex.c +++ b/src/test_multiplex.c @@ -213,71 +213,6 @@ static int multiplexStrlen30(const char *z){ return 0x3fffffff & (int)(z2 - z); } -/* -** Create a temporary file name in zBuf. zBuf must be big enough to -** hold at pOrigVfs->mxPathname characters. This function departs -** from the traditional temporary name generation in the os_win -** and os_unix VFS in several ways, but is necessary so that -** the file name is known for temporary files (like those used -** during vacuum.) -** -** N.B. This routine assumes your underlying VFS is ok with using -** "/" as a directory seperator. This is the default for UNIXs -** and is allowed (even mixed) for most versions of Windows. -*/ -static int multiplexGetTempname(sqlite3_vfs *pOrigVfs, int nBuf, char *zBuf){ - static char zChars[] = - "abcdefghijklmnopqrstuvwxyz" - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "0123456789"; - int i,j; - int attempts = 0; - int exists = 0; - int rc = SQLITE_ERROR; - - /* Check that the output buffer is large enough for - ** pVfs->mxPathname characters. - */ - if( pOrigVfs->mxPathname <= nBuf ){ - char *zTmp = sqlite3_malloc(pOrigVfs->mxPathname); - if( zTmp==0 ) return SQLITE_NOMEM; - - /* sqlite3_temp_directory should always be less than - ** pVfs->mxPathname characters. - */ - sqlite3_snprintf(pOrigVfs->mxPathname, - zTmp, - "%s/", - sqlite3_temp_directory ? sqlite3_temp_directory : "."); - rc = pOrigVfs->xFullPathname(pOrigVfs, zTmp, nBuf, zBuf); - sqlite3_free(zTmp); - if( rc ) return rc; - - /* Check that the output buffer is large enough for the temporary file - ** name. - */ - j = multiplexStrlen30(zBuf); - if( (j + 8 + 1 + 3 + 1) <= nBuf ){ - /* Make 3 attempts to generate a unique name. */ - do { - attempts++; - sqlite3_randomness(8, &zBuf[j]); - for(i=0; i<8; i++){ - unsigned char uc = (unsigned char)zBuf[j+i]; - zBuf[j+i] = (char)zChars[uc%(sizeof(zChars)-1)]; - } - memcpy(&zBuf[j+i], ".tmp", 5); - rc = pOrigVfs->xAccess(pOrigVfs, zBuf, SQLITE_ACCESS_EXISTS, &exists); - } while ( (rc==SQLITE_OK) && exists && (attempts<3) ); - if( rc==SQLITE_OK && exists ){ - rc = SQLITE_ERROR; - } - } - } - - return rc; -} - /* Compute the filename for the iChunk-th chunk */ static int multiplexSubFilename(multiplexGroup *pGroup, int iChunk){ @@ -291,7 +226,7 @@ static int multiplexSubFilename(multiplexGroup *pGroup, int iChunk){ pGroup->aReal = p; pGroup->nReal = iChunk+1; } - if( pGroup->aReal[iChunk].z==0 ){ + if( pGroup->zName && pGroup->aReal[iChunk].z==0 ){ char *z; int n = pGroup->nName; pGroup->aReal[iChunk].z = z = sqlite3_malloc( n+4 ); @@ -461,6 +396,7 @@ static int multiplexOpen( UNUSED_PARAMETER(pVfs); memset(pConn, 0, pVfs->szOsFile); + assert( zName || (flags & SQLITE_OPEN_DELETEONCLOSE) ); /* We need to create a group structure and manage ** access to this group of files. @@ -468,23 +404,9 @@ static int multiplexOpen( multiplexEnter(); pMultiplexOpen = (multiplexConn*)pConn; - /* If the second argument to this function is NULL, generate a - ** temporary file name to use. This will be handled by the - ** original xOpen method. We just need to allocate space for - ** it. - */ - if( !zName ){ - zName = zToFree = sqlite3_malloc( pOrigVfs->mxPathname + 10 ); - if( zName==0 ){ - rc = SQLITE_NOMEM; - }else{ - rc = multiplexGetTempname(pOrigVfs, pOrigVfs->mxPathname, zToFree); - } - } - if( rc==SQLITE_OK ){ /* allocate space for group */ - nName = multiplexStrlen30(zName); + nName = zName ? multiplexStrlen30(zName) : 0; sz = sizeof(multiplexGroup) /* multiplexGroup */ + nName + 1; /* zName */ pGroup = sqlite3_malloc( sz ); @@ -495,32 +417,34 @@ static int multiplexOpen( if( rc==SQLITE_OK ){ /* assign pointers to extra space allocated */ - char *p = (char *)&pGroup[1]; - pMultiplexOpen->pGroup = pGroup; memset(pGroup, 0, sz); + pMultiplexOpen->pGroup = pGroup; pGroup->bEnabled = -1; pGroup->szChunk = SQLITE_MULTIPLEX_CHUNK_SIZE; - if( flags & SQLITE_OPEN_URI ){ - const char *zChunkSize; - zChunkSize = sqlite3_uri_parameter(zName, "chunksize"); - if( zChunkSize ){ - unsigned int n = 0; - int i; - for(i=0; zChunkSize[i]>='0' && zChunkSize[i]<='9'; i++){ - n = n*10 + zChunkSize[i] - '0'; - } - if( n>0 ){ - pGroup->szChunk = (n+0xffff)&~0xffff; - }else{ - /* A zero or negative chunksize disabled the multiplexor */ - pGroup->bEnabled = 0; + + if( zName ){ + char *p = (char *)&pGroup[1]; + if( flags & SQLITE_OPEN_URI ){ + const char *zChunkSize; + zChunkSize = sqlite3_uri_parameter(zName, "chunksize"); + if( zChunkSize ){ + unsigned int n = 0; + int i; + for(i=0; zChunkSize[i]>='0' && zChunkSize[i]<='9'; i++){ + n = n*10 + zChunkSize[i] - '0'; + } + if( n>0 ){ + pGroup->szChunk = (n+0xffff)&~0xffff; + }else{ + /* A zero or negative chunksize disabled the multiplexor */ + pGroup->bEnabled = 0; + } } } + pGroup->zName = p; + memcpy(pGroup->zName, zName, nName+1); + pGroup->nName = nName; } - pGroup->zName = p; - /* save off base filename, name length, and original open flags */ - memcpy(pGroup->zName, zName, nName+1); - pGroup->nName = nName; pGroup->flags = flags; rc = multiplexSubFilename(pGroup, 1); if( rc==SQLITE_OK ){ @@ -796,52 +720,44 @@ static int multiplexFileSize(sqlite3_file *pConn, sqlite3_int64 *pSize){ multiplexConn *p = (multiplexConn*)pConn; multiplexGroup *pGroup = p->pGroup; int rc = SQLITE_OK; - int rc2; int i; - *pSize = 0; multiplexEnter(); if( !pGroup->bEnabled ){ sqlite3_file *pSubOpen = multiplexSubOpen(pGroup, 0, &rc, NULL); if( pSubOpen==0 ){ - rc = SQLITE_OK; /* If SubOpen failed, assume a size of zero */ + rc = SQLITE_IOERR_FSTAT; }else{ rc = pSubOpen->pMethods->xFileSize(pSubOpen, pSize); } }else{ sqlite3_vfs *pOrigVfs = gMultiplex.pOrigVfs; *pSize = 0; - for(i=0; 1; i++){ + for(i=0; rc==SQLITE_OK; i++){ sqlite3_file *pSubOpen = 0; int exists = 0; rc = multiplexSubFilename(pGroup, i); - if( rc ){ rc = SQLITE_OK; /* Assume size of zero */ break; } - if( pGroup->flags & SQLITE_OPEN_DELETEONCLOSE ){ - exists = pGroup->nReal>=i && pGroup->aReal[i].p!=0; - rc2 = SQLITE_OK; - }else{ - rc2 = pOrigVfs->xAccess(pOrigVfs, pGroup->aReal[i].z, - SQLITE_ACCESS_EXISTS, &exists); + if( rc!=SQLITE_OK ) break; + if( pGroup->nReal>i && pGroup->aReal[i].p!=0 ){ + exists = 1; + }else if( (pGroup->flags & SQLITE_OPEN_DELETEONCLOSE)==0 ){ + const char *zReal = pGroup->aReal[i].z; + rc = pOrigVfs->xAccess(pOrigVfs, zReal, SQLITE_ACCESS_EXISTS, &exists); } - if( rc2==SQLITE_OK && exists){ - /* if it exists, open it */ + if( exists==0 ){ + /* stop at first "gap" or IO error. */ + break; + } + if( rc==SQLITE_OK ){ pSubOpen = multiplexSubOpen(pGroup, i, &rc, NULL); - }else{ - /* stop at first "gap" */ - break; } - if( pSubOpen ){ - sqlite3_int64 sz; - rc2 = pSubOpen->pMethods->xFileSize(pSubOpen, &sz); - if( rc2!=SQLITE_OK ){ - rc = rc2; - }else{ - if( sz>pGroup->szChunk ){ - rc = SQLITE_IOERR_FSTAT; - } - *pSize += sz; + assert( pSubOpen || rc!=SQLITE_OK ); + if( rc==SQLITE_OK ){ + sqlite3_int64 sz = 0; + rc = pSubOpen->pMethods->xFileSize(pSubOpen, &sz); + if( rc==SQLITE_OK && sz>pGroup->szChunk ){ + rc = SQLITE_IOERR_FSTAT; } - }else{ - break; + *pSize += sz; } } } @@ -1192,9 +1108,13 @@ static int test_multiplex_dump( for(pGroup=gMultiplex.pGroups; pGroup; pGroup=pGroup->pNext){ pGroupTerm = Tcl_NewObj(); - pGroup->zName[pGroup->nName] = '\0'; - Tcl_ListObjAppendElement(interp, pGroupTerm, + if( pGroup->zName ){ + pGroup->zName[pGroup->nName] = '\0'; + Tcl_ListObjAppendElement(interp, pGroupTerm, Tcl_NewStringObj(pGroup->zName, -1)); + }else{ + Tcl_ListObjAppendElement(interp, pGroupTerm, Tcl_NewObj()); + } Tcl_ListObjAppendElement(interp, pGroupTerm, Tcl_NewIntObj(pGroup->nName)); Tcl_ListObjAppendElement(interp, pGroupTerm, From 658dd586ed49b5fa620c3b6b939716b51f738bac Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 13 Dec 2011 15:25:06 +0000 Subject: [PATCH 6/6] Update the multiplex.test script to conform to that found in the "experimental" branch off of trunk. FossilOrigin-Name: 2eb79efbff9cdab843b172e9fa9fb400c542fab1 --- manifest | 13 +++--- manifest.uuid | 2 +- test/multiplex.test | 12 +++++- test/multiplex3.test | 99 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 8 deletions(-) create mode 100644 test/multiplex3.test diff --git a/manifest b/manifest index b1b9ea84ff..53293465dd 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Move\sthe\smultiplexor\schanges\sin\sthe\sexperimental\sbranch\n(check-ins\s[255d21499b]\sand\s[199f52bced])\sinto\sthe\snx-devkit\sbranch. -D 2011-12-13T15:02:54.819 +C Update\sthe\smultiplex.test\sscript\sto\sconform\sto\sthat\sfound\sin\sthe\s"experimental"\nbranch\soff\sof\strunk. +D 2011-12-13T15:25:06.872 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5b4a3e12a850b021547e43daf886b25133b44c07 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -605,7 +605,8 @@ F test/misc5.test 528468b26d03303b1f047146e5eefc941b9069f5 F test/misc6.test 953cc693924d88e6117aeba16f46f0bf5abede91 F test/misc7.test eafaa41b9133d7a2ded4641bbe5f340731d35a52 F test/misuse.test ba4fb5d1a6101d1c171ea38b3c613d0661c83054 -F test/multiplex.test 9df8bf738b3b97c718fceb3fadb30900ba494418 +F test/multiplex.test 8bc3c71f73fe833bc8a659d454d320044a33b5da +F test/multiplex3.test 2860177d0ec8d494c538f2199b8812df1c09c7c5 F test/mutex1.test 78b2b9bb320e51d156c4efdb71b99b051e7a4b41 F test/mutex2.test bfeaeac2e73095b2ac32285d2756e3a65e681660 F test/nan.test e9648b9d007c7045242af35e11a984d4b169443a @@ -976,7 +977,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P ce55f250f56fa3a1ca864f81e9e86f911b981490 -R cc774ebd7c088b6b617c7f855781c545 +P eb95d2f72c625bcfd0f8e9db1db2cb8799854b57 +R f11319d97c8d3b9123b61c079ca9c86c U drh -Z 1b3d8d40cb48e276ed9ae7077034a64e +Z b47be607cba7caec297cb5893d5ae313 diff --git a/manifest.uuid b/manifest.uuid index a4233b55c6..a66362662f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -eb95d2f72c625bcfd0f8e9db1db2cb8799854b57 \ No newline at end of file +2eb79efbff9cdab843b172e9fa9fb400c542fab1 \ No newline at end of file diff --git a/test/multiplex.test b/test/multiplex.test index 3abdcf4507..7168e753ab 100644 --- a/test/multiplex.test +++ b/test/multiplex.test @@ -14,6 +14,16 @@ set testdir [file dirname $argv0] source $testdir/tester.tcl source $testdir/malloc_common.tcl +# The tests in this file assume that SQLite is compiled without +# ENABLE_8_3_NAMES. +# +ifcapable 8_3_names { + puts -nonewline "SQLite compiled with SQLITE_ENABLE_8_3_NAMES. " + puts "Skipping tests multiplex-*." + finish_test + return +} + set g_chunk_size [ expr ($::SQLITE_MAX_PAGE_SIZE*16384) ] set g_max_chunks 32 @@ -24,7 +34,7 @@ set g_max_chunks 32 # file name with the chunk number. proc multiplex_name {name chunk} { if {$chunk==0} { return $name } - set num [format "%02d" $chunk] + set num [format "%03d" $chunk] ifcapable {multiplex_ext_overwrite} { set name [string range $name 0 [expr [string length $name]-2-1]] } diff --git a/test/multiplex3.test b/test/multiplex3.test new file mode 100644 index 0000000000..b1fd4d1f84 --- /dev/null +++ b/test/multiplex3.test @@ -0,0 +1,99 @@ + +# 2011 December 13 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file contains tests for error (IO, OOM etc.) handling when using +# the multiplexor extension with 8.3 filenames. +# + +set testdir $env(SQLITE_TEST_DIR) +source $testdir/tester.tcl +source $testdir/malloc_common.tcl +set ::testprefix multiplex3 + +ifcapable !8_3_names { + puts -nonewline "SQLite compiled without SQLITE_ENABLE_8_3_NAMES. " + puts "Skipping tests zipvfsD-*." + finish_test + return +} + +db close +sqlite3_shutdown +sqlite3_config_uri 1 +autoinstall_test_functions + +sqlite3_multiplex_initialize "" 1 + +proc destroy_vfs_stack {} { + generic_unregister stack + sqlite3_multiplex_shutdown +} + +proc multiplex_delete_db {} { + forcedelete test.db + for {set i 1} {$i <= 1000} {incr i} { + forcedelete test.[format %03d $i] + } +} + +# Procs to save and restore the current muliplexed database. +# +proc multiplex_save_db {} { + foreach f [glob -nocomplain sv_test.*] { forcedelete $f } + foreach f [glob -nocomplain test.*] { forcecopy $f "sv_$f" } +} +proc multiplex_restore_db {} { + foreach f [glob -nocomplain test.*] {forcedelete $f} + foreach f [glob -nocomplain sv_test.*] {forcecopy $f [string range $f 3 end]} } + + +do_test 1.0 { + multiplex_delete_db + sqlite3 db file:test.db?8_3_names=1 + sqlite3_multiplex_control db main chunk_size [expr 256*1024] + execsql { + CREATE TABLE t1(a PRIMARY KEY, b); + INSERT INTO t1 VALUES(randomblob(15), randomblob(2000)); + INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 2 + INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 4 + INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 8 + INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 16 + INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 32 + INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 64 + INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 128 + INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 256 + INSERT INTO t1 SELECT randomblob(15), randomblob(2000) FROM t1; -- 512 + } + set ::cksum1 [execsql {SELECT md5sum(a, b) FROM t1 ORDER BY a}] + db close + multiplex_save_db +} {} + +do_faultsim_test 1 -prep { + multiplex_restore_db + sqlite3 db file:test.db?8_3_names=1 + sqlite3_multiplex_control db main chunk_size [expr 256*1024] +} -body { + execsql "UPDATE t1 SET a=randomblob(12), b=randomblob(1500) WHERE (rowid%32)=0" +} -test { + faultsim_test_result {0 {}} + if {$testrc!=0} { + set cksum2 [execsql {SELECT md5sum(a, b) FROM t1 ORDER BY a}] + if {$cksum2 != $::cksum1} { error "data mismatch" } + } +} + +catch { db close } + +sqlite3_multiplex_shutdown +finish_test +