1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Update sessions branch with latest trunk changes.

FossilOrigin-Name: 48d5cab3ac08b25ec94d6ecfd25779320558110f
This commit is contained in:
dan
2011-06-22 12:01:08 +00:00
16 changed files with 289 additions and 164 deletions

View File

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

11
main.mk
View File

@@ -221,6 +221,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 \
@@ -301,7 +302,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 \
@@ -553,13 +553,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 \

View File

@@ -1,9 +1,9 @@
C Merge\sthe\slatest\strunk\schanges\sinto\sthe\ssessions\sbranch.
D 2011-06-21T01:29:16.319
C Update\ssessions\sbranch\swith\slatest\strunk\schanges.
D 2011-06-22T12:01:09
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in c1d7a7f4fd8da6b1815032efca950e3d5125407e
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
F Makefile.msc c942f2ceb9385d6c75b01ee3d38d8a189fb76e8c
F Makefile.msc 11082f65b452b908d93013292c17850378c39284
F Makefile.vxworks c85ec1d8597fe2f7bc225af12ac1666e21379151
F README cd04a36fbc7ea56932a4052d7d0b7f09f27c33d6
F VERSION 3fcdd7fbe3eb282df3978fe77288544543767961
@@ -114,7 +114,7 @@ F ext/session/sqlite3session.h 665f5591562e3c71eb3d0da26f1a1efae26f7bcf
F ext/session/test_session.c 311e5b9228374d0b5780448f289847ff1cf7d388
F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x
F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8
F main.mk c864cbc95010ff6bdb6ec6d213c17be0bd2a86a2
F main.mk f56d9895882f5cdd9f9f9ba8f8a679e9202288c1
F mkdll.sh 7d09b23c05d56532e9d44a50868eb4b12ff4f74a
F mkextu.sh 416f9b7089d80e5590a29692c9d9280a10dbad9f
F mkextw.sh 4123480947681d9b434a5e7b1ee08135abe409ac
@@ -141,13 +141,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 c84066147544e8fddb7ca60ac7fd36ed2df8487f
F src/expr.c ab46ab0f0c44979a8164ca31728d7d10ae5e8106
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
F src/fkey.c 9fabba17a4d4778dc660f0cb9d781fc86d7b9d41
F src/func.c 59bb046d7e3df1ab512ac339ccb0a6f996a17cb7
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
@@ -156,7 +156,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 f7e8176ec1a9cad97470801660629179570d6b1d
F src/main.c 8a386605c22e4b2becfe96bab2ac7128b480d489
F src/malloc.c 591aedb20ae40813f1045f2ef253438a334775d9
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
F src/mem1.c 00bd8265c81abb665c48fea1e0c234eb3b922206
@@ -191,14 +191,14 @@ 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 6bff7c59ae3cec01e628800b79ae87a2897c576c
F src/sqlite.h.in f292d325b466081f8980911316743192cce6832a
F src/sqlite3ext.h c90bd5507099f62043832d73f6425d8d5c5da754
F src/sqliteInt.h 928caa40080d47e8f92e1edee83f6249d03c5862
F src/sqliteInt.h 72cff2b19f04b1de96675fc7dbc1dd4645d90e05
F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d
F src/status.c 7ac64842c86cec2fc1a1d0e5c16d3beb8ad332bf
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
F src/tclsqlite.c 6a34149c9ff4a6f998a4cb8336d4481670b576b6
F src/test1.c efca486a25fb894988e7a82e84579a4e57388a02
F src/test1.c ce2fab9e36932f5771c35291539366c9af229df3
F src/test2.c 80d323d11e909cf0eb1b6fbb4ac22276483bcf31
F src/test3.c 124ff9735fb6bb7d41de180d6bac90e7b1509432
F src/test4.c d1e5a5e904d4b444cf572391fdcb017638e36ff7
@@ -238,7 +238,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
@@ -392,7 +392,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
@@ -706,7 +706,7 @@ F test/tclsqlite.test 1ce9b6340d6d412420634e129a2e3722c651056a
F test/tempdb.test 19d0f66e2e3eeffd68661a11c83ba5e6ace9128c
F test/temptable.test f42121a0d29a62f00f93274464164177ab1cc24a
F test/temptrigger.test b0273db072ce5f37cf19140ceb1f0d524bbe9f05
F test/tester.tcl 7b91ddd9b2513024b4f95ac3c0151b2dab8433e0
F test/tester.tcl 3b6143fdafff36c516cf0fd663a20cd420aae36f
F test/thread001.test a3e6a7254d1cb057836cb3145b60c10bf5b7e60f
F test/thread002.test afd20095e6e845b405df4f2c920cb93301ca69db
F test/thread003.test b824d4f52b870ae39fc5bae4d8070eca73085dca
@@ -740,6 +740,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
@@ -853,7 +854,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
@@ -955,9 +956,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 699b884383f735fb9630d87d25dab61c97dc4485 e60eefc76fa5066720d76858f6cfca56365330ee
R e193f5c5190325b306fe583331238ae9
U drh
Z 4fd98ca50300bc27a920f010541b7f13
P f3d148e0d10e16cd744ec88a2961fd617368c5ed 6e1f4df51ad32e36715cba16f9df0d17a08dc653
R 13b557f9f4fbb1acb5f4e9d6383e3c30
U dan
Z e013d0e7eccb6ac9a42c9313b4aac9ad

View File

@@ -1 +1 @@
f3d148e0d10e16cd744ec88a2961fd617368c5ed
48d5cab3ac08b25ec94d6ecfd25779320558110f

View File

@@ -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);
if( osLocaltime(&t, &sLocal) ){
sqlite3_result_error(pCtx, "local time unavailable", -1);
*pRc = SQLITE_ERROR;
return 0;
}
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;
}
#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.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);
c1 = localtimeOffset(p, pCtx, &rc);
if( rc==SQLITE_OK ){
p->iJD -= c1;
clearYMD_HMS_TZ(p);
p->iJD += c1 - localtimeOffset(p);
rc = 0;
p->iJD += c1 - localtimeOffset(p, pCtx, &rc);
}
}
#endif
break;
@@ -731,9 +762,8 @@ static int isDate(
}
}
for(i=1; i<argc; i++){
if( (z = sqlite3_value_text(argv[i]))==0 || parseModifier((char*)z, p) ){
return 1;
}
z = sqlite3_value_text(argv[i]);
if( z==0 || parseModifier(context, (char*)z, p) ) return 1;
}
return 0;
}

View File

@@ -169,6 +169,7 @@ SQLITE_WSD struct Sqlite3Config sqlite3Config = {
0, /* nRefInitMutex */
0, /* xLog */
0, /* pLogArg */
0, /* bLocaltimeFault */
};

View File

@@ -2924,6 +2924,17 @@ int sqlite3_test_control(int op, ...){
break;
}
/* sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, int onoff);
**
** If parameter onoff is non-zero, configure the wrappers so that all
** subsequent calls to localtime() and variants fail. If onoff is zero,
** undo this setting.
*/
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
sqlite3GlobalConfig.bLocaltimeFault = va_arg(ap, int);
break;
}
}
va_end(ap);
#endif /* SQLITE_OMIT_BUILTIN_TEST */

View File

@@ -5573,7 +5573,8 @@ int sqlite3_test_control(int op, ...);
#define SQLITE_TESTCTRL_ISKEYWORD 16
#define SQLITE_TESTCTRL_PGHDRSZ 17
#define SQLITE_TESTCTRL_SCRATCHMALLOC 18
#define SQLITE_TESTCTRL_LAST 18
#define SQLITE_TESTCTRL_LOCALTIME_FAULT 19
#define SQLITE_TESTCTRL_LAST 19
/*
** CAPI3REF: SQLite Runtime Status

View File

@@ -2461,6 +2461,7 @@ struct Sqlite3Config {
int nRefInitMutex; /* Number of users of pInitMutex */
void (*xLog)(void*,int,const char*); /* Function for logging */
void *pLogArg; /* First argument to xLog() */
int bLocaltimeFault; /* True to fail localtime() calls */
};
/*

View File

@@ -5522,6 +5522,54 @@ static int test_print_eqp(
}
#endif /* SQLITE_OMIT_EXPLAIN */
/*
** sqlite3_test_control VERB ARGS...
*/
static int test_test_control(
void * clientData,
Tcl_Interp *interp,
int objc,
Tcl_Obj *CONST objv[]
){
struct Verb {
const char *zName;
int i;
} aVerb[] = {
{ "SQLITE_TESTCTRL_LOCALTIME_FAULT", SQLITE_TESTCTRL_LOCALTIME_FAULT },
};
int iVerb;
int iFlag;
int rc;
if( objc<2 ){
Tcl_WrongNumArgs(interp, 1, objv, "VERB ARGS...");
return TCL_ERROR;
}
rc = Tcl_GetIndexFromObjStruct(
interp, objv[1], aVerb, sizeof(aVerb[0]), "VERB", 0, &iVerb
);
if( rc!=TCL_OK ) return rc;
iFlag = aVerb[iVerb].i;
switch( iFlag ){
case SQLITE_TESTCTRL_LOCALTIME_FAULT: {
int val;
if( objc!=3 ){
Tcl_WrongNumArgs(interp, 2, objv, "ONOFF");
return TCL_ERROR;
}
if( Tcl_GetBooleanFromObj(interp, objv[2], &val) ) return TCL_ERROR;
sqlite3_test_control(SQLITE_TESTCTRL_LOCALTIME_FAULT, val);
break;
}
}
Tcl_ResetResult(interp);
return TCL_OK;
}
/*
** optimization_control DB OPT BOOLEAN
**
@@ -5785,6 +5833,7 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
#ifndef SQLITE_OMIT_EXPLAIN
{ "print_explain_query_plan", test_print_eqp, 0 },
#endif
{ "sqlite3_test_control", test_test_control },
};
static int bitmask_size = sizeof(Bitmask)*8;
int i;

View File

@@ -79,8 +79,6 @@ struct Testvfs {
sqlite3_vfs *pVfs; /* The testvfs registered with SQLite */
Tcl_Interp *interp; /* Interpreter to run script in */
Tcl_Obj *pScript; /* Script to execute */
int nScript; /* Number of elements in array apScript */
Tcl_Obj **apScript; /* Array version of pScript */
TestvfsBuffer *pBuffer; /* List of shared buffers */
int isNoshm;
@@ -267,48 +265,26 @@ static void tvfsExecTcl(
Tcl_Obj *arg3
){
int rc; /* Return code from Tcl_EvalObj() */
int nArg; /* Elements in eval'd list */
int nScript;
Tcl_Obj ** ap;
Tcl_Obj *pEval;
assert( p->pScript );
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; i<nScript; i++){
p->apScript[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);
}

View File

@@ -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} "
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
}
" {
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} "
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
}
" {
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&parameter=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&parameter&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

View File

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

38
test/tkt-bd484a090c.test Normal file
View File

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

View File

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

9
tool/tostr.awk Normal file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/awk
#
# Convert input text into a C string
#
{
gsub(/\\/,"\\\\");
gsub(/\"/,"\\\"");
print "\"" $0 "\\n\"";
}