diff --git a/Makefile.msc b/Makefile.msc index 1de682b854..a6d1bf4c2f 100644 --- a/Makefile.msc +++ b/Makefile.msc @@ -114,6 +114,7 @@ LTLINK = $(TCC) -Fe$@ # to deduce the binary type based on the object files. !IF "$(PLATFORM)"!="" LTLINKOPTS = /MACHINE:$(PLATFORM) +LTLIBOPTS = /MACHINE:$(PLATFORM) !ENDIF # nawk compatible awk. @@ -441,10 +442,10 @@ EXTHDR = $(EXTHDR) \ all: libsqlite3.lib sqlite3.exe libtclsqlite3.lib libsqlite3.lib: $(LIBOBJ) - $(LTLIB) -OUT:$@ $(LIBOBJ) $(TLIBS) + $(LTLIB) $(LTLIBOPTS) /OUT:$@ $(LIBOBJ) $(TLIBS) libtclsqlite3.lib: tclsqlite.lo libsqlite3.lib - $(LTLIB) /LIBPATH:$(TCLLIBDIR) -OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCL:tcl=tclstub) $(TLIBS) + $(LTLIB) $(LTLIBOPTS) /LIBPATH:$(TCLLIBDIR) /OUT:$@ tclsqlite.lo libsqlite3.lib $(LIBTCL:tcl=tclstub) $(TLIBS) sqlite3.exe: $(TOP)\src\shell.c libsqlite3.lib sqlite3.h $(LTLINK) $(READLINE_FLAGS) \ @@ -837,7 +838,7 @@ test: testfixture.exe sqlite3.exe .\testfixture.exe $(TOP)\test\veryquick.test spaceanal_tcl.h: $(TOP)\tool\spaceanal.tcl - $(NAWK) "/^[^#]/ { gsub(/\\/,\"\\\\\\\\\");gsub(/\\\"/,\"\\\\\\\"\");gsub(/^/,\"\\\"\");gsub(/$$/,\"\\n\\\"\");print }" \ + $(NAWK) -f $(TOP)/tool/tostr.awk \ $(TOP)\tool\spaceanal.tcl >spaceanal_tcl.h sqlite3_analyzer.exe: $(TESTFIXTURE_SRC) spaceanal_tcl.h @@ -871,4 +872,4 @@ sqlite3.def: libsqlite3.lib | sort >>sqlite3.def sqlite3.dll: $(LIBOBJ) sqlite3.def - link /DLL /OUT:$@ /DEF:sqlite3.def $(LIBOBJ) + link $(LTLINKOPTS) /DLL /DEF:sqlite3.def /OUT:$@ $(LIBOBJ) diff --git a/main.mk b/main.mk index 09a6a5c970..e8c3a1468b 100644 --- a/main.mk +++ b/main.mk @@ -222,6 +222,7 @@ SRC += \ # Source code to the test files. # TESTSRC = \ + $(TOP)/ext/fts3/fts3_term.c \ $(TOP)/ext/fts3/fts3_test.c \ $(TOP)/src/test1.c \ $(TOP)/src/test2.c \ @@ -302,7 +303,6 @@ TESTSRC2 = \ $(TOP)/ext/fts3/fts3.c \ $(TOP)/ext/fts3/fts3_aux.c \ $(TOP)/ext/fts3/fts3_expr.c \ - $(TOP)/ext/fts3/fts3_term.c \ $(TOP)/ext/fts3/fts3_tokenizer.c \ $(TOP)/ext/fts3/fts3_write.c \ $(TOP)/ext/async/sqlite3async.c @@ -554,13 +554,8 @@ threadtest: threadtest3$(EXE) sqlite3_analyzer$(EXE): $(TOP)/src/tclsqlite.c sqlite3.c $(TESTSRC) \ $(TOP)/tool/spaceanal.tcl - sed \ - -e '/^#/d' \ - -e 's,\\,\\\\,g' \ - -e 's,",\\",g' \ - -e 's,^,",' \ - -e 's,$$,\\n",' \ - $(TOP)/tool/spaceanal.tcl >spaceanal_tcl.h + $(NAWK) -f $(TOP)/tool/tostr.awk $(TOP)/tool/spaceanal.tcl \ + >spaceanal_tcl.h $(TCCX) $(TCL_FLAGS) -DTCLSH=2 $(TESTFIXTURE_FLAGS) \ -DSQLITE_TEST=1 -DSQLITE_PRIVATE="" \ $(TESTSRC) $(TOP)/src/tclsqlite.c sqlite3.c \ diff --git a/manifest b/manifest index ce58bd969f..4816b491be 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Merge\sthe\slatest\strunk\schanges\sinto\sthe\sapple-osx\sbranch. -D 2011-06-21T01:30:53.231 +C Update\sapple-osx\sbranch\swith\sthe\slatest\strunk\schanges. +D 2011-06-22T11:24:56 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 8410b02448997eb43bdf0ffa482c9bc2d2624e45 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 -F Makefile.msc c942f2ceb9385d6c75b01ee3d38d8a189fb76e8c +F Makefile.msc 11082f65b452b908d93013292c17850378c39284 F Makefile.vxworks c85ec1d8597fe2f7bc225af12ac1666e21379151 F README cd04a36fbc7ea56932a4052d7d0b7f09f27c33d6 F VERSION 3fcdd7fbe3eb282df3978fe77288544543767961 @@ -107,7 +107,7 @@ F ext/sqlrr/sqlrr.c 8d1e6571cd6a6beabdb5bcdfe3a0e723b914db41 F ext/sqlrr/sqlrr.h 09e4f8929ad9bc2638732c0cc0db5eef8c417824 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 -F main.mk fffabd0d16174b622792e26f6caf6e661f388a1c +F main.mk b2f00a81c37fbce7098d77c58eb816d9bd94d3d3 F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac @@ -134,13 +134,13 @@ F src/build.c 5a428625d21ad409514afb40ad083bee25dd957a F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c 7deec4534f3b5a0c3b4a4cbadf809d321f64f9c4 -F src/date.c 1548fdac51377e4e7833251de878b4058c148e1b +F src/date.c d3c11de76392ea62637bfac0f4655889fc2f5a85 F src/delete.c cecc926c70783452f3e8eb452c728291ce1a0b21 F src/expr.c ab46ab0f0c44979a8164ca31728d7d10ae5e8106 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 9fabba17a4d4778dc660f0cb9d781fc86d7b9d41 F src/func.c 1b9d471b632d8529e0f86b7bd2b918dcc2cb1097 -F src/global.c 29bfb85611dd816b04f10fba0ca910366e128d38 +F src/global.c c70a46f28680f8d7c097dbc0430ccf3b932e90b0 F src/hash.c 458488dcc159c301b8e7686280ab209f1fb915af F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 @@ -149,7 +149,7 @@ F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e F src/legacy.c 015826a958f690302d27e096a68d50b3657e4201 F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e F src/loadext.c 3ae0d52da013a6326310655be6473fd472347b85 -F src/main.c 42f2493a1662a2dee5ac56a05b05c0c545ae6d92 +F src/main.c fbe239ee3e61b0e83a8d53028e9efaf8368bc73f F src/malloc.c 591aedb20ae40813f1045f2ef253438a334775d9 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 46095d62b241466ef51970e592aa3a7a87e443e1 @@ -184,15 +184,15 @@ F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697 F src/select.c d9d440809025a58547e39f4f268c2a296bfb56ff F src/shell.c 0e0173b3e79d956368013e759f084caa7995ecb1 -F src/sqlite.h.in a4d0baabe4f86b3ab9cf56eda23dfd9d022ece0a +F src/sqlite.h.in 4b7255c10d39c5faf089dbd29cde7c367ff39f1f F src/sqlite3_private.h 2a814d17913732831acf13e7e87860105a3416e4 F src/sqlite3ext.h c90bd5507099f62043832d73f6425d8d5c5da754 -F src/sqliteInt.h 7b7ec2394b94fc4516930cd9dae37af0f9312215 +F src/sqliteInt.h a9248d3b0d2b1cf428d8642320fb13044a8888e0 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac64842c86cec2fc1a1d0e5c16d3beb8ad332bf F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e F src/tclsqlite.c 5db825be61708b1a2b3f8f6e185e9b753829acef -F src/test1.c 5c8be86cba3ac703c765730b7dd1ec62bf84e750 +F src/test1.c 4b3b4e58c3f9457d9e8fb0a6d437215c64287b76 F src/test2.c 80d323d11e909cf0eb1b6fbb4ac22276483bcf31 F src/test3.c 124ff9735fb6bb7d41de180d6bac90e7b1509432 F src/test4.c d1e5a5e904d4b444cf572391fdcb017638e36ff7 @@ -232,7 +232,7 @@ F src/test_superlock.c 2b97936ca127d13962c3605dbc9a4ef269c424cd F src/test_syscall.c 162c4ec0137a549c009bb9ecab550527743cfc5d F src/test_tclvar.c f4dc67d5f780707210d6bb0eb6016a431c04c7fa F src/test_thread.c fe9a7803fc1d69cccb60f016f28c1cedf2d9fcfa -F src/test_vfs.c e7855568dfa1e0ba73668d273b65605d9f8b77e8 +F src/test_vfs.c 1d82aee93e644188179da2165f4fe3ad6b62782c F src/test_vfstrace.c 0b884e06094a746da729119a2cabdc7aa790063d F src/test_wholenumber.c 6129adfbe7c7444f2e60cc785927f3aa74e12290 F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9 @@ -386,7 +386,7 @@ F test/e_resolve.test dcce9308fb13b934ce29591105d031d3e14fbba6 F test/e_select.test 7ac53674e822d4d77bbb4a9a4aaefa5fdc9e493f F test/e_select2.test 5c3d3da19c7b3e90ae444579db2b70098599ab92 F test/e_update.test b926341a65955d69a6375c9eb4fd82e7089bc83a -F test/e_uri.test 8b943bc63cd1abb037430214cdb618422e6bf7d6 +F test/e_uri.test 6f35b491f80dac005c8144f38b2dfb4d96483596 F test/e_vacuum.test 6c09c2af7f2f140518f371c5342100118f779dcf F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398 @@ -621,7 +621,7 @@ F test/pagesize.test 76aa9f23ecb0741a4ed9d2e16c5fa82671f28efb F test/pcache.test 065aa286e722ab24f2e51792c1f093bf60656b16 F test/pcache2.test 0d85f2ab6963aee28c671d4c71bec038c00a1d16 F test/permutations.test 1e8892ebf1bd6e9e8036f4841c72a91bf72da74a -F test/pragma.test 88048136eed6baa2097dd7ab5145d3288128ca70 +F test/pragma.test 9b08f84e691065281c5e705988a754bf26c2bfaa F test/pragma2.test 5364893491b9231dd170e3459bfc2e2342658b47 F test/printf.test 05970cde31b1a9f54bd75af60597be75a5c54fea F test/progress.test 5b075c3c790c7b2a61419bc199db87aaf48b8301 @@ -700,7 +700,7 @@ F test/tclsqlite.test 8c154101e704170c2be10f137a5499ac2c6da8d3 F test/tempdb.test 3263e5c3f0604e54d307481e8587327c54544d18 F test/temptable.test f42121a0d29a62f00f93274464164177ab1cc24a F test/temptrigger.test b0273db072ce5f37cf19140ceb1f0d524bbe9f05 -F test/tester.tcl 54a2028984500c76dcfbef6e927ef23ef1141515 +F test/tester.tcl 801cb7ba763bf5a19475cfb865ad55dddb39ad6a F test/thread001.test a3e6a7254d1cb057836cb3145b60c10bf5b7e60f F test/thread002.test afd20095e6e845b405df4f2c920cb93301ca69db F test/thread003.test b824d4f52b870ae39fc5bae4d8070eca73085dca @@ -734,6 +734,7 @@ F test/tkt-94c04eaadb.test be5ea61cb04dfdc047d19b5c5a9e75fa3da67a7f F test/tkt-9d68c883.test 458f7d82a523d7644b54b497c986378a7d8c8b67 F test/tkt-b351d95f9.test d14a503c414c5c58fdde3e80f9a3cfef986498c0 F test/tkt-b72787b1.test e6b62b2b2785c04d0d698d6a603507e384165049 +F test/tkt-bd484a090c.test 60460bf946f79a79712b71f202eda501ca99b898 F test/tkt-cbd054fa6b.test f14f97ea43662e6f70c9e63287081e8be5d9d589 F test/tkt-d11f09d36e.test fb44f7961aa6d4b632fb7b9768239832210b5fc7 F test/tkt-d82e3f3721.test 731359dfdcdb36fea0559cd33fec39dd0ceae8e6 @@ -847,7 +848,7 @@ F test/triggerD.test c6add3817351451e419f6ff9e9a259b02b6e2de7 F test/tt3_checkpoint.c 415eccce672d681b297485fc20f44cdf0eac93af F test/types.test bf816ce73c7dfcfe26b700c19f97ef4050d194ff F test/types2.test 3555aacf8ed8dc883356e59efc314707e6247a84 -F test/types3.test a0f66bf12f80fad89493535474f7a6d16fa58150 +F test/types3.test 99e009491a54f4dc02c06bdbc0c5eea56ae3e25a F test/unique.test 083c7fff74695bcc27a71d75699deba3595bc9c2 F test/unixexcl.test 9d80a54d86d2261f660758928959368ffc36151e F test/unordered.test e81169ce2a8f31b2c6b66af691887e1376ab3ced @@ -949,9 +950,10 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/symbols.sh bc2a3709940d47c8ac8e0a1fdf17ec801f015a00 +F tool/tostr.awk 11760e1b94a5d3dcd42378f3cc18544c06cfa576 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings.sh 347d974d143cf132f953b565fbc03026f19fcb4d -P 4c69e827f4d65e597e125e0d6691b0c8fb5588d7 e60eefc76fa5066720d76858f6cfca56365330ee -R 57a0e9a4fabd4995959d9cd71e887832 -U drh -Z 5c6f3f32328535fdb642daa473cdb5a8 +P 76005fdca05d86f91e424698d86942264419c616 6e1f4df51ad32e36715cba16f9df0d17a08dc653 +R 3fe8d8ccf923ead718e0d406962ef41f +U dan +Z 7cc1c43d462645d28cf861dabb055fe3 diff --git a/manifest.uuid b/manifest.uuid index ad13351b32..9a8b5cfbfd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -76005fdca05d86f91e424698d86942264419c616 \ No newline at end of file +fb7ad09dec805ccb709b138509d6e1eb77323c2f \ No newline at end of file diff --git a/src/date.c b/src/date.c index b81049aa65..c0744e8c72 100644 --- a/src/date.c +++ b/src/date.c @@ -50,22 +50,6 @@ #ifndef SQLITE_OMIT_DATETIME_FUNCS -/* -** On recent Windows platforms, the localtime_s() function is available -** as part of the "Secure CRT". It is essentially equivalent to -** localtime_r() available under most POSIX platforms, except that the -** order of the parameters is reversed. -** -** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx. -** -** If the user has not indicated to use localtime_r() or localtime_s() -** already, check for an MSVC build environment that provides -** localtime_s(). -*/ -#if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \ - defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE) -#define HAVE_LOCALTIME_S 1 -#endif /* ** A structure for holding a single date and time. @@ -411,15 +395,83 @@ static void clearYMD_HMS_TZ(DateTime *p){ p->validTZ = 0; } +/* +** On recent Windows platforms, the localtime_s() function is available +** as part of the "Secure CRT". It is essentially equivalent to +** localtime_r() available under most POSIX platforms, except that the +** order of the parameters is reversed. +** +** See http://msdn.microsoft.com/en-us/library/a442x3ye(VS.80).aspx. +** +** If the user has not indicated to use localtime_r() or localtime_s() +** already, check for an MSVC build environment that provides +** localtime_s(). +*/ +#if !defined(HAVE_LOCALTIME_R) && !defined(HAVE_LOCALTIME_S) && \ + defined(_MSC_VER) && defined(_CRT_INSECURE_DEPRECATE) +#define HAVE_LOCALTIME_S 1 +#endif + #ifndef SQLITE_OMIT_LOCALTIME /* -** Compute the difference (in milliseconds) -** between localtime and UTC (a.k.a. GMT) -** for the time value p where p is in UTC. +** The following routine implements the rough equivalent of localtime_r() +** using whatever operating-system specific localtime facility that +** is available. This routine returns 0 on success and +** non-zero on any kind of error. +** +** If the sqlite3GlobalConfig.bLocaltimeFault variable is true then this +** routine will always fail. */ -static sqlite3_int64 localtimeOffset(DateTime *p){ +static int osLocaltime(time_t *t, struct tm *pTm){ + int rc; +#if (!defined(HAVE_LOCALTIME_R) || !HAVE_LOCALTIME_R) \ + && (!defined(HAVE_LOCALTIME_S) || !HAVE_LOCALTIME_S) + struct tm *pX; + sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER); + sqlite3_mutex_enter(mutex); + pX = localtime(t); +#ifndef SQLITE_OMIT_BUILTIN_TEST + if( sqlite3GlobalConfig.bLocaltimeFault ) pX = 0; +#endif + if( pX ) *pTm = *pX; + sqlite3_mutex_leave(mutex); + rc = pX==0; +#else +#ifndef SQLITE_OMIT_BUILTIN_TEST + if( sqlite3GlobalConfig.bLocaltimeFault ) return 1; +#endif +#if defined(HAVE_LOCALTIME_R) && HAVE_LOCALTIME_R + rc = localtime_r(t, pTm)==0; +#else + rc = localtime_s(pTm, t); +#endif /* HAVE_LOCALTIME_R */ +#endif /* HAVE_LOCALTIME_R || HAVE_LOCALTIME_S */ + return rc; +} +#endif /* SQLITE_OMIT_LOCALTIME */ + + +#ifndef SQLITE_OMIT_LOCALTIME +/* +** Compute the difference (in milliseconds) between localtime and UTC +** (a.k.a. GMT) for the time value p where p is in UTC. If no error occurs, +** return this value and set *pRc to SQLITE_OK. +** +** Or, if an error does occur, set *pRc to SQLITE_ERROR. The returned value +** is undefined in this case. +*/ +static sqlite3_int64 localtimeOffset( + DateTime *p, /* Date at which to calculate offset */ + sqlite3_context *pCtx, /* Write error here if one occurs */ + int *pRc /* OUT: Error code. SQLITE_OK or ERROR */ +){ DateTime x, y; time_t t; + struct tm sLocal; + + /* Initialize the contents of sLocal to avoid a compiler warning. */ + memset(&sLocal, 0, sizeof(sLocal)); + x = *p; computeYMD_HMS(&x); if( x.Y<1971 || x.Y>=2038 ){ @@ -437,47 +489,23 @@ static sqlite3_int64 localtimeOffset(DateTime *p){ x.validJD = 0; computeJD(&x); t = (time_t)(x.iJD/1000 - 21086676*(i64)10000); -#ifdef HAVE_LOCALTIME_R - { - struct tm sLocal; - localtime_r(&t, &sLocal); - y.Y = sLocal.tm_year + 1900; - y.M = sLocal.tm_mon + 1; - y.D = sLocal.tm_mday; - y.h = sLocal.tm_hour; - y.m = sLocal.tm_min; - y.s = sLocal.tm_sec; + if( osLocaltime(&t, &sLocal) ){ + sqlite3_result_error(pCtx, "local time unavailable", -1); + *pRc = SQLITE_ERROR; + return 0; } -#elif defined(HAVE_LOCALTIME_S) && HAVE_LOCALTIME_S - { - struct tm sLocal; - localtime_s(&sLocal, &t); - y.Y = sLocal.tm_year + 1900; - y.M = sLocal.tm_mon + 1; - y.D = sLocal.tm_mday; - y.h = sLocal.tm_hour; - y.m = sLocal.tm_min; - y.s = sLocal.tm_sec; - } -#else - { - struct tm *pTm; - sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); - pTm = localtime(&t); - y.Y = pTm->tm_year + 1900; - y.M = pTm->tm_mon + 1; - y.D = pTm->tm_mday; - y.h = pTm->tm_hour; - y.m = pTm->tm_min; - y.s = pTm->tm_sec; - sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); - } -#endif + y.Y = sLocal.tm_year + 1900; + y.M = sLocal.tm_mon + 1; + y.D = sLocal.tm_mday; + y.h = sLocal.tm_hour; + y.m = sLocal.tm_min; + y.s = sLocal.tm_sec; y.validYMD = 1; y.validHMS = 1; y.validJD = 0; y.validTZ = 0; computeJD(&y); + *pRc = SQLITE_OK; return y.iJD - x.iJD; } #endif /* SQLITE_OMIT_LOCALTIME */ @@ -501,9 +529,12 @@ static sqlite3_int64 localtimeOffset(DateTime *p){ ** localtime ** utc ** -** Return 0 on success and 1 if there is any kind of error. +** Return 0 on success and 1 if there is any kind of error. If the error +** is in a system call (i.e. localtime()), then an error message is written +** to context pCtx. If the error is an unrecognized modifier, no error is +** written to pCtx. */ -static int parseModifier(const char *zMod, DateTime *p){ +static int parseModifier(sqlite3_context *pCtx, const char *zMod, DateTime *p){ int rc = 1; int n; double r; @@ -523,9 +554,8 @@ static int parseModifier(const char *zMod, DateTime *p){ */ if( strcmp(z, "localtime")==0 ){ computeJD(p); - p->iJD += localtimeOffset(p); + p->iJD += localtimeOffset(p, pCtx, &rc); clearYMD_HMS_TZ(p); - rc = 0; } break; } @@ -546,11 +576,12 @@ static int parseModifier(const char *zMod, DateTime *p){ else if( strcmp(z, "utc")==0 ){ sqlite3_int64 c1; computeJD(p); - c1 = localtimeOffset(p); - p->iJD -= c1; - clearYMD_HMS_TZ(p); - p->iJD += c1 - localtimeOffset(p); - rc = 0; + c1 = localtimeOffset(p, pCtx, &rc); + if( rc==SQLITE_OK ){ + p->iJD -= c1; + clearYMD_HMS_TZ(p); + p->iJD += c1 - localtimeOffset(p, pCtx, &rc); + } } #endif break; @@ -731,9 +762,8 @@ static int isDate( } } for(i=1; ipScript ); - if( !p->apScript ){ - int nByte; - int i; - if( TCL_OK!=Tcl_ListObjGetElements(p->interp, p->pScript, &nScript, &ap) ){ - Tcl_BackgroundError(p->interp); - Tcl_ResetResult(p->interp); - return; - } - p->nScript = nScript; - nByte = (nScript+TESTVFS_MAX_ARGS)*sizeof(Tcl_Obj *); - p->apScript = (Tcl_Obj **)ckalloc(nByte); - memset(p->apScript, 0, nByte); - for(i=0; iapScript[i] = ap[i]; - } - } + assert( zMethod ); + assert( p ); + assert( arg2==0 || arg1!=0 ); + assert( arg3==0 || arg2!=0 ); - p->apScript[p->nScript] = Tcl_NewStringObj(zMethod, -1); - p->apScript[p->nScript+1] = arg1; - p->apScript[p->nScript+2] = arg2; - p->apScript[p->nScript+3] = arg3; + pEval = Tcl_DuplicateObj(p->pScript); + Tcl_IncrRefCount(p->pScript); + Tcl_ListObjAppendElement(p->interp, pEval, Tcl_NewStringObj(zMethod, -1)); + if( arg1 ) Tcl_ListObjAppendElement(p->interp, pEval, arg1); + if( arg2 ) Tcl_ListObjAppendElement(p->interp, pEval, arg2); + if( arg3 ) Tcl_ListObjAppendElement(p->interp, pEval, arg3); - for(nArg=p->nScript; p->apScript[nArg]; nArg++){ - Tcl_IncrRefCount(p->apScript[nArg]); - } - - rc = Tcl_EvalObjv(p->interp, nArg, p->apScript, TCL_EVAL_GLOBAL); + rc = Tcl_EvalObjEx(p->interp, pEval, TCL_EVAL_GLOBAL); if( rc!=TCL_OK ){ Tcl_BackgroundError(p->interp); Tcl_ResetResult(p->interp); } - - for(nArg=p->nScript; p->apScript[nArg]; nArg++){ - Tcl_DecrRefCount(p->apScript[nArg]); - p->apScript[nArg] = 0; - } } @@ -1094,10 +1070,8 @@ static int testvfs_obj_cmd( if( objc==3 ){ int nByte; if( p->pScript ){ + int i; Tcl_DecrRefCount(p->pScript); - ckfree((char *)p->apScript); - p->apScript = 0; - p->nScript = 0; p->pScript = 0; } Tcl_GetStringFromObj(objv[2], &nByte); @@ -1249,9 +1223,9 @@ static int testvfs_obj_cmd( static void testvfs_obj_del(ClientData cd){ Testvfs *p = (Testvfs *)cd; + int i; if( p->pScript ) Tcl_DecrRefCount(p->pScript); sqlite3_vfs_unregister(p->pVfs); - ckfree((char *)p->apScript); ckfree((char *)p->pVfs); ckfree((char *)p); } diff --git a/test/e_uri.test b/test/e_uri.test index b6ad54ea03..5275ec1b54 100644 --- a/test/e_uri.test +++ b/test/e_uri.test @@ -121,6 +121,10 @@ if {$tcl_platform(platform) == "unix"} { sqlite3_close $DB } +# ensure uri processing enabled for the rest of the tests +sqlite3_shutdown +sqlite3_config_uri 1 + # EVIDENCE-OF: R-17482-00398 If the authority is not an empty string or # "localhost", an error is returned to the caller. # @@ -144,18 +148,16 @@ if {$tcl_platform(platform) == "unix"} { # EVIDENCE-OF: R-45981-25528 The fragment component of a URI, if # present, is ignored. # -# It is difficult to test that something is ignore correctly. So these tests +# It is difficult to test that something is ignored correctly. So these tests # just show that adding a fragment does not interfere with the pathname or # parameters passed through to the VFS xOpen() methods. # -if {$tcl_platform(platform) == "unix"} { - foreach {tn uri parse} " - 1 {file:test.db#abc} {[pwd]/test.db {}} - 2 {file:test.db?a=b#abc} {[pwd]/test.db {a b}} - 3 {file:test.db?a=b#?c=d} {[pwd]/test.db {a b}} - " { - do_test 3.$tn { parse_uri $uri } $parse - } +foreach {tn uri parse} " + 1 {file:test.db#abc} {[pwd]/test.db {}} + 2 {file:test.db?a=b#abc} {[pwd]/test.db {a b}} + 3 {file:test.db?a=b#?c=d} {[pwd]/test.db {a b}} +" { + do_filepath_test 3.$tn { parse_uri $uri } $parse } # EVIDENCE-OF: R-62557-09390 SQLite uses the path component of the URI @@ -168,16 +170,14 @@ if {$tcl_platform(platform) == "unix"} { # (meaning that the authority section is omitted from the URI) then the # path is interpreted as a relative path. # -if {$tcl_platform(platform) == "unix"} { - foreach {tn uri parse} " - 1 {file:test.db} {[pwd]/test.db {}} - 2 {file:/test.db} {/test.db {}} - 3 {file:///test.db} {/test.db {}} - 4 {file://localhost/test.db} {/test.db {}} - 5 {file:/a/b/c/test.db} {/a/b/c/test.db {}} - " { - do_test 4.$tn { parse_uri $uri } $parse - } +foreach {tn uri parse} " + 1 {file:test.db} {[pwd]/test.db {}} + 2 {file:/test.db} {/test.db {}} + 3 {file:///test.db} {/test.db {}} + 4 {file://localhost/test.db} {/test.db {}} + 5 {file:/a/b/c/test.db} {/a/b/c/test.db {}} +" { + do_filepath_test 4.$tn { parse_uri $uri } $parse } # EVIDENCE-OF: R-01612-30877 The "vfs" parameter may be used to specify @@ -270,8 +270,6 @@ foreach {tn uri error} " # EVIDENCE-OF: R-26845-32976 Value "rwc" is equivalent to setting both # SQLITE_OPEN_READWRITE and SQLITE_OPEN_CREATE. # -sqlite3_shutdown -sqlite3_config_uri 1 foreach {tn uri read write create} { 1 {file:test.db?mode=ro} 1 0 0 2 {file:test.db?mode=rw} 1 1 0 @@ -429,10 +427,10 @@ sqlite3_enable_shared_cache $orig # EVIDENCE-OF: R-63472-46769 Specifying an unknown parameter in the # query component of a URI is not an error. # -do_test 12.1 { +do_filepath_test 12.1 { parse_uri file://localhost/test.db?an=unknown¶meter=is&ok= } {/test.db {an unknown parameter is ok {}}} -do_test 12.2 { +do_filepath_test 12.2 { parse_uri file://localhost/test.db?an&unknown¶meter&is&ok } {/test.db {an {} unknown {} parameter {} is {} ok {}}} @@ -452,7 +450,7 @@ foreach {tn uri parse} " 2 {file:/test.db?%68%65%6c%6c%6f=%77%6f%72%6c%64} {/test.db {hello world}} 3 {file:/%C3%BF.db} {/\xFF.db {}} " { - do_test 13.$tn { parse_uri $uri } $parse + do_filepath_test 13.$tn { parse_uri $uri } $parse } finish_test diff --git a/test/pragma.test b/test/pragma.test index 8cbfef5434..f2ef3a069d 100644 --- a/test/pragma.test +++ b/test/pragma.test @@ -1312,7 +1312,7 @@ if !$skip_lock_proxy_tests { sqlite3 db test.db # set lock proxy name and then query it via pragma interface - set lpp [exec mktemp -t 'proxy1'] + set lpp [exec mktemp -t "proxy1"] do_test pragma-16.1 { execsql "PRAGMA lock_proxy_file='$lpp'" execsql "select * from sqlite_master" @@ -1337,7 +1337,7 @@ if !$skip_lock_proxy_tests { } $lpp db2 close - set lpp2 [exec mktemp -t 'proxy2'] + set lpp2 [exec mktemp -t "proxy2"] # 2nd database connection cannot override the lock proxy file do_test pragma-16.3 { diff --git a/test/tester.tcl b/test/tester.tcl index 54b380e356..391382f4f4 100644 --- a/test/tester.tcl +++ b/test/tester.tcl @@ -354,6 +354,21 @@ proc do_test {name cmd expected} { flush stdout } +proc filepath_normalize {p} { + # test cases should be written to assume "unix"-like file paths + if {$::tcl_platform(platform)!="unix"} { + # lreverse*2 as a hack to remove any unneeded {} after the string map + lreverse [lreverse [string map {\\ /} [regsub -nocase -all {[a-z]:[/\\]+} $p {/}]]] + } { + set p + } +} +proc do_filepath_test {name cmd expected} { + uplevel [list do_test $name [ + subst -nocommands { filepath_normalize [ $cmd ] } + ] [filepath_normalize $expected]] +} + proc realnum_normalize {r} { # different TCL versions display floating point values differently. string map {1.#INF inf Inf inf .0e e} [regsub -all {(e[+-])0+} $r {\1}] diff --git a/test/tkt-bd484a090c.test b/test/tkt-bd484a090c.test new file mode 100644 index 0000000000..3d2b599958 --- /dev/null +++ b/test/tkt-bd484a090c.test @@ -0,0 +1,38 @@ +# 2011 June 21 +# +# 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 SQLite. Specifically, it tests that SQLite +# does not crash and an error is returned if localhost() fails. This +# is the problem reported by ticket bd484a090c. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +set testprefix tkt-bd484a090c + + +do_test 1.1 { + lindex [catchsql { SELECT datetime('now', 'localtime') }] 0 +} {0} +do_test 1.2 { + lindex [catchsql { SELECT datetime('now', 'utc') }] 0 +} {0} + +sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 1 + +do_test 2.1 { + catchsql { SELECT datetime('now', 'localtime') } +} {1 {local time unavailable}} +do_test 2.2 { + catchsql { SELECT datetime('now', 'utc') } +} {1 {local time unavailable}} + +sqlite3_test_control SQLITE_TESTCTRL_LOCALTIME_FAULT 0 + +finish_test diff --git a/test/types3.test b/test/types3.test index 33f2595cb9..807ae84f9d 100644 --- a/test/types3.test +++ b/test/types3.test @@ -21,7 +21,7 @@ source $testdir/tester.tcl # A variable with only a string representation comes in as TEXT do_test types3-1.1 { set V {} - append V {} + append V x concat [tcl_variable_type V] [execsql {SELECT typeof(:V)}] } {string text} diff --git a/tool/tostr.awk b/tool/tostr.awk new file mode 100644 index 0000000000..83c6cc1a50 --- /dev/null +++ b/tool/tostr.awk @@ -0,0 +1,9 @@ +#!/usr/bin/awk +# +# Convert input text into a C string +# +{ + gsub(/\\/,"\\\\"); + gsub(/\"/,"\\\""); + print "\"" $0 "\\n\""; +}