From 869c0409e3a7a54341cb408533b3c668b9df916d Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 7 Aug 2013 23:15:52 +0000 Subject: [PATCH 1/8] If the SQLITE_ALLOW_URI_AUTHORITY compile-time option is set, then allow non-localhost authorities on URI filenames and pass them through as a UNC to the underlying VFS. FossilOrigin-Name: 3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/main.c | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 190659f0f2..c9e8d0b682 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sa\sguard\s#ifndef\sto\stest_intarray.h\sto\sprevent\sharm\sif\sit\sis\s#included\nmore\sthan\sonce.\s\sAdd\sa\scomment\son\sthe\sclosing\s#endif\sof\sthe\sguards\son\nsqlite3.h\sand\stest_multiplex.h. -D 2013-08-07T14:18:45.279 +C If\sthe\sSQLITE_ALLOW_URI_AUTHORITY\scompile-time\soption\sis\sset,\sthen\sallow\nnon-localhost\sauthorities\son\sURI\sfilenames\sand\spass\sthem\sthrough\sas\sa\sUNC\nto\sthe\sunderlying\sVFS. +D 2013-08-07T23:15:52.266 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -185,7 +185,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c b2592b4119f9b34d20861d1a73a44f07d061508c +F src/main.c 482135b0bf855d621ef10c5bb56c63df23b2ddec F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P f8d8790ede0fcaf6c5b60ac22919c1d97c74e838 -R 2f7b5cf183df4b523d2c445c6f8fcaa5 +P 0ad83ceb79767738bd06a28840cf84da0464ab4f +R a230045986289598d392f4ac16d8f85f U drh -Z cdc793001b4bb9536e6929a443adf8d1 +Z 3dff46ea9ed1198b77cd17bced6ea4de diff --git a/manifest.uuid b/manifest.uuid index bcffddd0ea..bb59190386 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0ad83ceb79767738bd06a28840cf84da0464ab4f \ No newline at end of file +3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 \ No newline at end of file diff --git a/src/main.c b/src/main.c index d848dc7f59..9e8a6ed063 100644 --- a/src/main.c +++ b/src/main.c @@ -2178,20 +2178,20 @@ int sqlite3ParseUri( zFile = sqlite3_malloc(nByte); if( !zFile ) return SQLITE_NOMEM; + iIn = 5; +#ifndef SQLITE_ALLOW_URI_AUTHORITY /* Discard the scheme and authority segments of the URI. */ if( zUri[5]=='/' && zUri[6]=='/' ){ iIn = 7; while( zUri[iIn] && zUri[iIn]!='/' ) iIn++; - if( iIn!=7 && (iIn!=16 || memcmp("localhost", &zUri[7], 9)) ){ *pzErrMsg = sqlite3_mprintf("invalid uri authority: %.*s", iIn-7, &zUri[7]); rc = SQLITE_ERROR; goto parse_uri_out; } - }else{ - iIn = 5; } +#endif /* Copy the filename and any query parameters into the zFile buffer. ** Decode %HH escape codes along the way. From ab80be99e3c96e03982056e33853ec52a34222eb Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 8 Aug 2013 14:38:45 +0000 Subject: [PATCH 2/8] If the SQLITE_EXTRA_INIT function is defined, make sure it is called only once by the effective sqlite3_initialize() call. FossilOrigin-Name: e2b597cafe7c8a8313b051d6a302fed54f235727 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/main.c | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index c9e8d0b682..6cc104b469 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\sSQLITE_ALLOW_URI_AUTHORITY\scompile-time\soption\sis\sset,\sthen\sallow\nnon-localhost\sauthorities\son\sURI\sfilenames\sand\spass\sthem\sthrough\sas\sa\sUNC\nto\sthe\sunderlying\sVFS. -D 2013-08-07T23:15:52.266 +C If\sthe\sSQLITE_EXTRA_INIT\sfunction\sis\sdefined,\smake\ssure\sit\sis\scalled\sonly\nonce\sby\sthe\seffective\ssqlite3_initialize()\scall. +D 2013-08-08T14:38:45.404 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -185,7 +185,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c 482135b0bf855d621ef10c5bb56c63df23b2ddec +F src/main.c f6eb795f17eb88205b55e5116fb37e6593707d82 F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 0ad83ceb79767738bd06a28840cf84da0464ab4f -R a230045986289598d392f4ac16d8f85f +P 3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 +R f58cae922c11c825e7cdfcd2f4c52823 U drh -Z 3dff46ea9ed1198b77cd17bced6ea4de +Z 6adac74ecb750c6ba6eb610c8156f9d8 diff --git a/manifest.uuid b/manifest.uuid index bb59190386..cb24e03baa 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 \ No newline at end of file +e2b597cafe7c8a8313b051d6a302fed54f235727 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 9e8a6ed063..217221d238 100644 --- a/src/main.c +++ b/src/main.c @@ -117,6 +117,9 @@ char *sqlite3_data_directory = 0; int sqlite3_initialize(void){ MUTEX_LOGIC( sqlite3_mutex *pMaster; ) /* The main static mutex */ int rc; /* Result code */ +#ifdef SQLITE_EXTRA_INIT + int bRunExtraInit = 0; /* Extra initialization needed */ +#endif #ifdef SQLITE_OMIT_WSD rc = sqlite3_wsd_init(4096, 24); @@ -214,6 +217,9 @@ int sqlite3_initialize(void){ sqlite3PCacheBufferSetup( sqlite3GlobalConfig.pPage, sqlite3GlobalConfig.szPage, sqlite3GlobalConfig.nPage); sqlite3GlobalConfig.isInit = 1; +#ifdef SQLITE_EXTRA_INIT + bRunExtraInit = 1; +#endif } sqlite3GlobalConfig.inProgress = 0; } @@ -254,7 +260,7 @@ int sqlite3_initialize(void){ ** compile-time option. */ #ifdef SQLITE_EXTRA_INIT - if( rc==SQLITE_OK && sqlite3GlobalConfig.isInit ){ + if( bRunExtraInit ){ int SQLITE_EXTRA_INIT(const char*); rc = SQLITE_EXTRA_INIT(0); } From 037933b8a75f01013fc7fb2899dc06c57eef30dc Mon Sep 17 00:00:00 2001 From: mistachkin Date: Tue, 13 Aug 2013 22:33:41 +0000 Subject: [PATCH 3/8] Fix an outdated comment and a comment typo. No changes to code. FossilOrigin-Name: ac336959490083ffeaaf25aaec97ecb59a2f4536 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/main.c | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 6cc104b469..c1132e63b5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\sSQLITE_EXTRA_INIT\sfunction\sis\sdefined,\smake\ssure\sit\sis\scalled\sonly\nonce\sby\sthe\seffective\ssqlite3_initialize()\scall. -D 2013-08-08T14:38:45.404 +C Fix\san\soutdated\scomment\sand\sa\scomment\stypo.\s\sNo\schanges\sto\scode. +D 2013-08-13T22:33:41.968 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -185,7 +185,7 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c f6eb795f17eb88205b55e5116fb37e6593707d82 +F src/main.c 4e4cd5c2ee09db496c0dde79b507bba6b8bcbdcb F src/malloc.c fe085aa851b666b7c375c1ff957643dc20a04bf6 F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 3adb6c1bfda897859dc9cf9ae7f1e6719855ee68 -R f58cae922c11c825e7cdfcd2f4c52823 -U drh -Z 6adac74ecb750c6ba6eb610c8156f9d8 +P e2b597cafe7c8a8313b051d6a302fed54f235727 +R 725a28de0f0d05555ad0060ad37d65c5 +U mistachkin +Z 538f6198c3d2d5189ca428ea230684f3 diff --git a/manifest.uuid b/manifest.uuid index cb24e03baa..57d601b84e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e2b597cafe7c8a8313b051d6a302fed54f235727 \ No newline at end of file +ac336959490083ffeaaf25aaec97ecb59a2f4536 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 217221d238..6932bf7b9d 100644 --- a/src/main.c +++ b/src/main.c @@ -448,8 +448,8 @@ int sqlite3_config(int op, ...){ memset(&sqlite3GlobalConfig.m, 0, sizeof(sqlite3GlobalConfig.m)); }else{ /* The heap pointer is not NULL, then install one of the - ** mem5.c/mem3.c methods. If neither ENABLE_MEMSYS3 nor - ** ENABLE_MEMSYS5 is defined, return an error. + ** mem5.c/mem3.c methods. The enclosing #if guarantees at + ** least one of these methods is currently enabled. */ #ifdef SQLITE_ENABLE_MEMSYS3 sqlite3GlobalConfig.m = *sqlite3MemGetMemsys3(); @@ -468,7 +468,7 @@ int sqlite3_config(int op, ...){ break; } - /* Record a pointer to the logger funcction and its first argument. + /* Record a pointer to the logger function and its first argument. ** The default is NULL. Logging is disabled if the function pointer is ** NULL. */ From 3dfaf6766c93993a897c3ee38d59a4b3a42c3a30 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 14 Aug 2013 00:20:23 +0000 Subject: [PATCH 4/8] Fix a few more minor comment typos. No changes to code. FossilOrigin-Name: 9e999081a59b161a0a1f968fbc01a1db9ea43b93 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/mem5.c | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index c1132e63b5..5e2d3872f1 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\san\soutdated\scomment\sand\sa\scomment\stypo.\s\sNo\schanges\sto\scode. -D 2013-08-13T22:33:41.968 +C Fix\sa\sfew\smore\sminor\scomment\stypos.\s\sNo\schanges\sto\scode. +D 2013-08-14T00:20:23.461 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -191,7 +191,7 @@ F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c 437c7c4af964895d4650f29881df63535caaa1fa F src/mem2.c e307323e86b5da1853d7111b68fd6b84ad6f09cf F src/mem3.c 61c9d47b792908c532ca3a62b999cf21795c6534 -F src/mem5.c c2c63b7067570b00bf33d751c39af24182316f7f +F src/mem5.c 0025308a93838022bd5696cf9627ff4e40b19918 F src/memjournal.c 0683aac6cab6ec2b5374c0db37c0deb2436a3785 F src/mutex.c d3b66a569368015e0fcb1ac15f81c119f504d3bc F src/mutex.h 5bc526e19dccc412b7ff04642f6fdad3fdfdabea @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P e2b597cafe7c8a8313b051d6a302fed54f235727 -R 725a28de0f0d05555ad0060ad37d65c5 +P ac336959490083ffeaaf25aaec97ecb59a2f4536 +R b65660836257e0b7350de3a479496a6b U mistachkin -Z 538f6198c3d2d5189ca428ea230684f3 +Z 2adbd114c976ac90cd58966c1c244f68 diff --git a/manifest.uuid b/manifest.uuid index 57d601b84e..c5b110f948 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ac336959490083ffeaaf25aaec97ecb59a2f4536 \ No newline at end of file +9e999081a59b161a0a1f968fbc01a1db9ea43b93 \ No newline at end of file diff --git a/src/mem5.c b/src/mem5.c index 783cef6176..5f99ebf43d 100644 --- a/src/mem5.c +++ b/src/mem5.c @@ -130,13 +130,13 @@ static SQLITE_WSD struct Mem5Global { } mem5; /* -** Access the static variable through a macro for SQLITE_OMIT_WSD +** Access the static variable through a macro for SQLITE_OMIT_WSD. */ #define mem5 GLOBAL(struct Mem5Global, mem5) /* ** Assuming mem5.zPool is divided up into an array of Mem5Link -** structures, return a pointer to the idx-th such lik. +** structures, return a pointer to the idx-th such link. */ #define MEM5LINK(idx) ((Mem5Link *)(&mem5.zPool[(idx)*mem5.szAtom])) @@ -232,7 +232,7 @@ static int memsys5UnlinkFirst(int iLogsize){ ** Return a block of memory of at least nBytes in size. ** Return NULL if unable. Return NULL if nBytes==0. ** -** The caller guarantees that nByte positive. +** The caller guarantees that nByte is positive. ** ** The caller has obtained a mutex prior to invoking this ** routine so there is never any chance that two or more @@ -354,7 +354,7 @@ static void memsys5FreeUnsafe(void *pOld){ } /* -** Allocate nBytes of memory +** Allocate nBytes of memory. */ static void *memsys5Malloc(int nBytes){ sqlite3_int64 *p = 0; From 1f28e0703fb33668db136898d03874832babf74f Mon Sep 17 00:00:00 2001 From: mistachkin Date: Thu, 15 Aug 2013 08:06:15 +0000 Subject: [PATCH 5/8] Make it easy to attach a debugger the test fixture process prior to any tests being run. FossilOrigin-Name: c23acba11bfefc019b5945cfb345f9afcf4b6242 --- manifest | 15 +++++++++------ manifest.uuid | 2 +- src/tclsqlite.c | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 5e2d3872f1..c257781adc 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfew\smore\sminor\scomment\stypos.\s\sNo\schanges\sto\scode. -D 2013-08-14T00:20:23.461 +C Make\sit\seasy\sto\sattach\sa\sdebugger\sthe\stest\sfixture\sprocess\sprior\sto\sany\stests\sbeing\srun. +D 2013-08-15T08:06:15.562 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -225,7 +225,7 @@ F src/sqliteInt.h def0e436c0d4ca5084305ca6ae898020fbafaae4 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e -F src/tclsqlite.c b8835978e853a89bf58de88acc943a5ca94d752e +F src/tclsqlite.c 659dad8ef30b54831306a244b43e37af4725a444 F src/test1.c 870fc648a48cb6d6808393174f7ebe82b8c840fa F src/test2.c 7355101c085304b90024f2261e056cdff13c6c35 F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c @@ -1105,7 +1105,10 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P ac336959490083ffeaaf25aaec97ecb59a2f4536 -R b65660836257e0b7350de3a479496a6b +P 9e999081a59b161a0a1f968fbc01a1db9ea43b93 +R c32412a10fe0450296a67115895879b1 +T *branch * dbgTestFixture +T *sym-dbgTestFixture * +T -sym-trunk * U mistachkin -Z 2adbd114c976ac90cd58966c1c244f68 +Z 7b47b87c7211179488e7ecca78b01825 diff --git a/manifest.uuid b/manifest.uuid index c5b110f948..32c235aa4c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e999081a59b161a0a1f968fbc01a1db9ea43b93 \ No newline at end of file +c23acba11bfefc019b5945cfb345f9afcf4b6242 \ No newline at end of file diff --git a/src/tclsqlite.c b/src/tclsqlite.c index 6d2a51e5ab..42f7bcdc3a 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -41,6 +41,18 @@ #endif #include +/* Used to get the current process ID */ +#if !defined(_WIN32) +# include +# define GETPID getpid +#elif !defined(_WIN32_WCE) +# ifndef SQLITE_AMALGAMATION +# define WIN32_LEAN_AND_MEAN +# include +# endif +# define GETPID (int)GetCurrentProcessId +#endif + /* * Windows needs to know which symbols to export. Unix does not. * BUILD_sqlite should be undefined for Unix. @@ -3746,7 +3758,16 @@ static void init_all(Tcl_Interp *interp){ #define TCLSH_MAIN main /* Needed to fake out mktclapp */ int TCLSH_MAIN(int argc, char **argv){ Tcl_Interp *interp; - + +#if !defined(_WIN32_WCE) + if( getenv("BREAK") ){ + fprintf(stderr, + "attach debugger to process %d and press any key to continue.\n", + GETPID()); + fgetc(stdin); + } +#endif + /* Call sqlite3_shutdown() once before doing anything else. This is to ** test that sqlite3_shutdown() can be safely called by a process before ** sqlite3_initialize() is. */ From 26080d924120b24cdc93cd7ab84b98129a68f475 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 15 Aug 2013 14:27:42 +0000 Subject: [PATCH 6/8] Clarification and typo fixes in comments related to name resolution. No changes to code. FossilOrigin-Name: f30abdf9d814d6c75bf1c803054737c737ad636f --- manifest | 16 ++++++++-------- manifest.uuid | 2 +- src/resolve.c | 4 ++-- src/sqliteInt.h | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifest b/manifest index 5e2d3872f1..33f9db7681 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\sfew\smore\sminor\scomment\stypos.\s\sNo\schanges\sto\scode. -D 2013-08-14T00:20:23.461 +C Clarification\sand\stypo\sfixes\sin\scomments\srelated\sto\sname\sresolution.\nNo\schanges\sto\scode. +D 2013-08-15T14:27:42.072 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,14 +214,14 @@ F src/pragma.c 590c75750d93ec5a1f903e4bb0dc6d2a0845bf8b F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 -F src/resolve.c 17e670996729ac41aadf6a31f57b4e6f29b3d819 +F src/resolve.c 94a08f37c04352bbdd4a91b335e1a4feb256a3c7 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca F src/shell.c 927e17b37b63b24461e372d982138fb22c4df321 F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h def0e436c0d4ca5084305ca6ae898020fbafaae4 +F src/sqliteInt.h ac5de15640d7a5d6ea46724fe3e0ffd39af0ed12 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P ac336959490083ffeaaf25aaec97ecb59a2f4536 -R b65660836257e0b7350de3a479496a6b -U mistachkin -Z 2adbd114c976ac90cd58966c1c244f68 +P 9e999081a59b161a0a1f968fbc01a1db9ea43b93 +R 24134e38ea075ceae9b6222f6f5f7529 +U drh +Z 9cfa8ebfbef3728e717dd86578dea4f4 diff --git a/manifest.uuid b/manifest.uuid index c5b110f948..948eae37cd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9e999081a59b161a0a1f968fbc01a1db9ea43b93 \ No newline at end of file +f30abdf9d814d6c75bf1c803054737c737ad636f \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index a194a26553..d5517003b6 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1009,7 +1009,7 @@ int sqlite3ResolveOrderGroupBy( ** If the order-by term is an integer I between 1 and N (where N is the ** number of columns in the result set of the SELECT) then the expression ** in the resolution is a copy of the I-th result-set expression. If -** the order-by term is an identify that corresponds to the AS-name of +** the order-by term is an identifier that corresponds to the AS-name of ** a result-set expression, then the term resolves to a copy of the ** result-set expression. Otherwise, the expression is resolved in ** the usual way - using sqlite3ResolveExprNames(). @@ -1187,7 +1187,7 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ return WRC_Abort; } - /* Add the expression list to the name-context before parsing the + /* Add the output column list to the name-context before parsing the ** other expressions in the SELECT statement. This is so that ** expressions in the WHERE clause (etc.) can refer to expressions by ** aliases in the result set. diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 67f7df2474..a0ba82ab8c 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2006,7 +2006,7 @@ struct SrcList { struct NameContext { Parse *pParse; /* The parser */ SrcList *pSrcList; /* One or more tables used to resolve names */ - ExprList *pEList; /* Optional list of named expressions */ + ExprList *pEList; /* Optional list of result-set columns */ AggInfo *pAggInfo; /* Information about aggregates at this level */ NameContext *pNext; /* Next outer name context. NULL for outermost */ int nRef; /* Number of names resolved by this context */ From e35463b312a5ec35ae5546d155a75380e0d03e64 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 15 Aug 2013 20:24:27 +0000 Subject: [PATCH 7/8] Bare identifiers in ORDER BY clauses bind more tightly to output column name, but identifiers in expressions bind more tightly to input column names. This is a compromise between SQL92 and SQL99 behavior and is what PostgreSQL and MS-SQL do. Ticket [f617ea3125e9c]. FossilOrigin-Name: c78b357c00a35ed48ce2ffbc041de8d22570d1e2 --- manifest | 20 ++++---- manifest.uuid | 2 +- src/resolve.c | 24 +++++---- src/sqliteInt.h | 4 +- test/resolver01.test | 117 ++++++++++++++++++++++++++++++++++++++++++- test/tkt2822.test | 5 +- 6 files changed, 143 insertions(+), 29 deletions(-) diff --git a/manifest b/manifest index 1a10d6e3a3..f200c5dbea 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\sit\seasy\sto\sattach\sa\sdebugger\sthe\stest\sfixture\sprocess\sprior\sto\sany\stests\sbeing\srun. -D 2013-08-15T20:05:03.202 +C Bare\sidentifiers\sin\sORDER\sBY\sclauses\sbind\smore\stightly\sto\soutput\scolumn\sname,\nbut\sidentifiers\sin\sexpressions\sbind\smore\stightly\sto\sinput\scolumn\snames.\nThis\sis\sa\scompromise\sbetween\sSQL92\sand\sSQL99\sbehavior\sand\sis\swhat\nPostgreSQL\sand\sMS-SQL\sdo.\s\sTicket\s[f617ea3125e9c]. +D 2013-08-15T20:24:27.463 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,14 +214,14 @@ F src/pragma.c 590c75750d93ec5a1f903e4bb0dc6d2a0845bf8b F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 -F src/resolve.c 94a08f37c04352bbdd4a91b335e1a4feb256a3c7 +F src/resolve.c 2a760f369ddbcd951f176556c8ec05be04cdd0da F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca F src/shell.c 927e17b37b63b24461e372d982138fb22c4df321 F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h ac5de15640d7a5d6ea46724fe3e0ffd39af0ed12 +F src/sqliteInt.h b2a4e9a85e4bb49c1537fe7fc6532cd7ebe82aa0 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -733,7 +733,7 @@ F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8 F test/reindex.test 44edd3966b474468b823d481eafef0c305022254 F test/releasetest.mk 2eced2f9ae701fd0a29e714a241760503ccba25a F test/releasetest.tcl 06d289d8255794073a58d2850742f627924545ce -F test/resolver01.test d1b487fc567bdb70b5dd09ccaaa877ddc61a233e +F test/resolver01.test a98ed8a2e9f78600155d783389ad4e6537010285 F test/rollback.test a1b4784b864331eae8b2a98c189efa2a8b11ff07 F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 F test/rowid.test f777404492adb0e00868fd706a3721328fd3af48 @@ -906,7 +906,7 @@ F test/tkt2686.test 6ee01c9b9e9c48f6d3a1fdd553b1cc4258f903d6 F test/tkt2767.test 569000d842678f9cf2db7e0d1b27cbc9011381b0 F test/tkt2817.test f31839e01f4243cff7399ef654d3af3558cb8d8d F test/tkt2820.test 39940276b3436d125deb7d8ebeee053e4cf13213 -F test/tkt2822.test c3589494fba643e039bcf0bfde7554ff6028406d +F test/tkt2822.test f391776423a7c0d0949edfce375708bfb0f3141e F test/tkt2832.test a9b0b74a02dca166a04d9e37739c414b10929caa F test/tkt2854.test e432965db29e27e16f539b2ba7f502eb2ccc49af F test/tkt2920.test a8737380e4ae6424e00c0273dc12775704efbebf @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P f30abdf9d814d6c75bf1c803054737c737ad636f c23acba11bfefc019b5945cfb345f9afcf4b6242 -R fb4db235176e52d42891fba292ddbfa5 -U mistachkin -Z 4d072d8f2cb243e6b9c13cb11a27b554 +P 53cd9ebfaf401c7932bf591e134a527c9962b88e +R b873391074dfe27843eed5ca71b0596f +U drh +Z 52475f320db5f901cc1dc06cbb7fef10 diff --git a/manifest.uuid b/manifest.uuid index 836758fb58..1f70b21510 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -53cd9ebfaf401c7932bf591e134a527c9962b88e \ No newline at end of file +c78b357c00a35ed48ce2ffbc041de8d22570d1e2 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index d5517003b6..b41a7adda4 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -55,7 +55,7 @@ static void incrAggFunctionDepth(Expr *pExpr, int N){ ** column reference is so that the column reference will be recognized as ** usable by indices within the WHERE clause processing logic. ** -** Hack: The TK_AS operator is inhibited if zType[0]=='G'. This means +** The TK_AS operator is inhibited if zType[0]=='G'. This means ** that in a GROUP BY clause, the expression is evaluated twice. Hence: ** ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY x @@ -65,8 +65,9 @@ static void incrAggFunctionDepth(Expr *pExpr, int N){ ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5 ** ** The result of random()%5 in the GROUP BY clause is probably different -** from the result in the result-set. We might fix this someday. Or -** then again, we might not... +** from the result in the result-set. On the other hand Standard SQL does +** not allow the GROUP BY clause to contain references to result-set columns. +** So this should never come up in well-formed queries. ** ** If the reference is followed by a COLLATE operator, then make sure ** the COLLATE operator is preserved. For example: @@ -396,10 +397,16 @@ static int lookupName( ** forms the result set entry ("a+b" in the example) and return immediately. ** Note that the expression in the result set should have already been ** resolved by the time the WHERE clause is resolved. + ** + ** The ability to use an output result-set column in the WHERE, GROUP BY, + ** or HAVING clauses, or as part of a larger expression in the ORDRE BY + ** clause is not standard SQL. This is a (goofy) SQLite extension, that + ** is supported for backwards compatibility only. TO DO: Issue a warning + ** on sqlite3_log() whenever the capability is used. */ if( (pEList = pNC->pEList)!=0 && zTab==0 - && ((pNC->ncFlags & NC_AsMaybe)==0 || cnt==0) + && cnt==0 ){ for(j=0; jnExpr; j++){ char *zAs = pEList->a[j].zName; @@ -961,7 +968,7 @@ static int resolveCompoundOrderBy( /* ** Check every term in the ORDER BY or GROUP BY clause pOrderBy of ** the SELECT statement pSelect. If any term is reference to a -** result set expression (as determined by the ExprList.a.iCol field) +** result set expression (as determined by the ExprList.a.iOrderByCol field) ** then convert that term into a copy of the corresponding result set ** column. ** @@ -1035,7 +1042,8 @@ static int resolveOrderGroupBy( pParse = pNC->pParse; for(i=0, pItem=pOrderBy->a; inExpr; i++, pItem++){ Expr *pE = pItem->pExpr; - iCol = resolveAsName(pParse, pSelect->pEList, pE); + Expr *pE2 = sqlite3ExprSkipCollate(pE); + iCol = resolveAsName(pParse, pSelect->pEList, pE2); if( iCol>0 ){ /* If an AS-name match is found, mark this ORDER BY column as being ** a copy of the iCol-th result-set column. The subsequent call to @@ -1044,7 +1052,7 @@ static int resolveOrderGroupBy( pItem->iOrderByCol = (u16)iCol; continue; } - if( sqlite3ExprIsInteger(sqlite3ExprSkipCollate(pE), &iCol) ){ + if( sqlite3ExprIsInteger(pE2, &iCol) ){ /* The ORDER BY term is an integer constant. Again, set the column ** number so that sqlite3ResolveOrderGroupBy() will convert the ** order-by term to a copy of the result-set expression */ @@ -1196,10 +1204,8 @@ static int resolveSelectStep(Walker *pWalker, Select *p){ ** re-evaluated for each reference to it. */ sNC.pEList = p->pEList; - sNC.ncFlags |= NC_AsMaybe; if( sqlite3ResolveExprNames(&sNC, p->pHaving) ) return WRC_Abort; if( sqlite3ResolveExprNames(&sNC, p->pWhere) ) return WRC_Abort; - sNC.ncFlags &= ~NC_AsMaybe; /* The ORDER BY and GROUP BY clauses may not refer to terms in ** outer queries diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a0ba82ab8c..78aa0f8fca 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2021,9 +2021,7 @@ struct NameContext { #define NC_HasAgg 0x02 /* One or more aggregate functions seen */ #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */ #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */ -#define NC_AsMaybe 0x10 /* Resolve to AS terms of the result set only - ** if no other resolution is available */ -#define NC_PartIdx 0x20 /* True if resolving a partial index WHERE */ +#define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */ /* ** An instance of the following structure contains all information diff --git a/test/resolver01.test b/test/resolver01.test index 3ca6acec47..3bad269151 100644 --- a/test/resolver01.test +++ b/test/resolver01.test @@ -13,10 +13,18 @@ # figures out what identifiers in the SQL statement refer to) that # were fixed by ticket [2500cdb9be] # +# See also tickets [1c69be2daf] and [f617ea3125] from 2013-08-14. +# set testdir [file dirname $argv0] source $testdir/tester.tcl +# "ORDER BY y" binds to the output result-set column named "y" +# if available. If no output column is named "y", then try to +# bind against an input column named "y". +# +# This is classical SQL92 behavior. +# do_test resolver01-1.1 { catchsql { CREATE TABLE t1(x, y); INSERT INTO t1 VALUES(11,22); @@ -25,15 +33,120 @@ do_test resolver01-1.1 { } } {0 1} do_test resolver01-1.2 { + catchsql { + SELECT 1 AS yy FROM t1, t2 ORDER BY y; + } +} {1 {ambiguous column name: y}} +do_test resolver01-1.3 { + catchsql { + CREATE TABLE t3(x,y); INSERT INTO t3 VALUES(11,44),(33,22); + SELECT x AS y FROM t3 ORDER BY y; + } +} {0 {11 33}} +do_test resolver01-1.4 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY y; + } +} {0 {33 11}} + +# SQLite allows the WHERE clause to reference output columns if there is +# no other way to resolve the name. +# +do_test resolver01-1.5 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY yy; + } +} {0 {11 33}} +do_test resolver01-1.6 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY 1; + } +} {0 {11 33}} + +# The "ORDER BY y COLLATE nocase" form works the same as "ORDER BY y". +# The "y" binds more tightly to output columns than to input columns. +# +# This is for compatibility with SQL92 and with historical SQLite behavior. +# Note that PostgreSQL considers "y COLLATE nocase" to be an expression +# and thus PostgreSQL treats this case as if it where the 3.x case below. +# +do_test resolver01-2.1 { catchsql { SELECT 2 AS y FROM t1, t2 ORDER BY y COLLATE nocase; } } {0 2} -do_test resolver01-1.3 { +do_test resolver01-2.2 { + catchsql { + SELECT 2 AS yy FROM t1, t2 ORDER BY y COLLATE nocase; + } +} {1 {ambiguous column name: y}} +do_test resolver01-2.3 { + catchsql { + SELECT x AS y FROM t3 ORDER BY y COLLATE nocase; + } +} {0 {11 33}} +do_test resolver01-2.4 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY y COLLATE nocase; + } +} {0 {33 11}} +do_test resolver01-2.5 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY yy COLLATE nocase; + } +} {0 {11 33}} +do_test resolver01-2.6 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY 1 COLLATE nocase; + } +} {0 {11 33}} + +# But if the form is "ORDER BY expr" then bind more tightly to the +# the input column names and only use the output column names if no +# input column name matches. +# +# This is SQL99 behavior, as implemented by PostgreSQL and MS-SQL. +# Note that Oracle works differently. +# +do_test resolver01-3.1 { catchsql { SELECT 3 AS y FROM t1, t2 ORDER BY +y; } -} {0 3} +} {1 {ambiguous column name: y}} +do_test resolver01-3.2 { + catchsql { + SELECT 2 AS yy FROM t1, t2 ORDER BY +y; + } +} {1 {ambiguous column name: y}} +do_test resolver01-3.3 { + catchsql { + SELECT x AS y FROM t3 ORDER BY +y; + } +} {0 {33 11}} +do_test resolver01-3.4 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY +y; + } +} {0 {33 11}} +do_test resolver01-3.5 { + catchsql { + SELECT x AS yy FROM t3 ORDER BY +yy + } +} {0 {11 33}} +# This is the test case given in ticket [f617ea3125e9] (with table name +# changed from "t1" to "t4". The behavior of (1) and (3) match with +# PostgreSQL, but we intentionally break with PostgreSQL to provide +# SQL92 behavior for case (2). +# +do_execsql_test resolver01-4.1 { + CREATE TABLE t4(m CHAR(2)); + INSERT INTO t4 VALUES('az'); + INSERT INTO t4 VALUES('by'); + INSERT INTO t4 VALUES('cx'); + SELECT '1', substr(m,2) AS m FROM t4 ORDER BY m; + SELECT '2', substr(m,2) AS m FROM t4 ORDER BY m COLLATE binary; + SELECT '3', substr(m,2) AS m FROM t4 ORDER BY lower(m); +} {1 x 1 y 1 z 2 x 2 y 2 z 3 z 3 y 3 x} finish_test diff --git a/test/tkt2822.test b/test/tkt2822.test index d3512d3038..d0b16338c6 100644 --- a/test/tkt2822.test +++ b/test/tkt2822.test @@ -208,15 +208,12 @@ do_test tkt2822-5.4 { # In "ORDER BY +b" the term is now an expression rather than # a label. It therefore matches by rule (3) instead of rule (2). -# -# 2013-04-13: This is busted. Changed to conform to PostgreSQL and -# MySQL and Oracle behavior. # do_test tkt2822-5.5 { execsql { SELECT a AS b FROM t3 ORDER BY +b; } -} {1 9} +} {9 1} # Tests for rule 2 in compound queries # From 0af16ab2c2d5eec0eb01f512af96ef01909a095c Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 15 Aug 2013 22:40:21 +0000 Subject: [PATCH 8/8] Make sure that GROUP BY terms select input column names in preference to output column names, in compliance with the SQL standard. Ticket [1c69be2dafc28]. FossilOrigin-Name: f2d175f975cd0be63425424ec322a98fb650019e --- manifest | 14 +++++------ manifest.uuid | 2 +- src/resolve.c | 18 +++++++------- test/resolver01.test | 56 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index f200c5dbea..87a62738cb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Bare\sidentifiers\sin\sORDER\sBY\sclauses\sbind\smore\stightly\sto\soutput\scolumn\sname,\nbut\sidentifiers\sin\sexpressions\sbind\smore\stightly\sto\sinput\scolumn\snames.\nThis\sis\sa\scompromise\sbetween\sSQL92\sand\sSQL99\sbehavior\sand\sis\swhat\nPostgreSQL\sand\sMS-SQL\sdo.\s\sTicket\s[f617ea3125e9c]. -D 2013-08-15T20:24:27.463 +C Make\ssure\sthat\sGROUP\sBY\sterms\sselect\sinput\scolumn\snames\sin\spreference\sto\noutput\scolumn\snames,\sin\scompliance\swith\sthe\sSQL\sstandard.\nTicket\s[1c69be2dafc28]. +D 2013-08-15T22:40:21.803 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -214,7 +214,7 @@ F src/pragma.c 590c75750d93ec5a1f903e4bb0dc6d2a0845bf8b F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 -F src/resolve.c 2a760f369ddbcd951f176556c8ec05be04cdd0da +F src/resolve.c 9d53899cc6e1f4ec0b4632d07e97d57827bf63b9 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c 8b148eb851f384412aea57091659d14b369918ca F src/shell.c 927e17b37b63b24461e372d982138fb22c4df321 @@ -733,7 +733,7 @@ F test/regexp1.test 497ea812f264d12b6198d6e50a76be4a1973a9d8 F test/reindex.test 44edd3966b474468b823d481eafef0c305022254 F test/releasetest.mk 2eced2f9ae701fd0a29e714a241760503ccba25a F test/releasetest.tcl 06d289d8255794073a58d2850742f627924545ce -F test/resolver01.test a98ed8a2e9f78600155d783389ad4e6537010285 +F test/resolver01.test 33abf37ff8335e6bf98f2b45a0af3e06996ccd9a F test/rollback.test a1b4784b864331eae8b2a98c189efa2a8b11ff07 F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 F test/rowid.test f777404492adb0e00868fd706a3721328fd3af48 @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 53cd9ebfaf401c7932bf591e134a527c9962b88e -R b873391074dfe27843eed5ca71b0596f +P c78b357c00a35ed48ce2ffbc041de8d22570d1e2 +R 0cad26d57aaadc86e4d0689961c53035 U drh -Z 52475f320db5f901cc1dc06cbb7fef10 +Z 9ac8068bb659c66e2e7c0f0532626e1f diff --git a/manifest.uuid b/manifest.uuid index 1f70b21510..cb7ffe8748 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c78b357c00a35ed48ce2ffbc041de8d22570d1e2 \ No newline at end of file +f2d175f975cd0be63425424ec322a98fb650019e \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index b41a7adda4..43a3870e23 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -1043,14 +1043,16 @@ static int resolveOrderGroupBy( for(i=0, pItem=pOrderBy->a; inExpr; i++, pItem++){ Expr *pE = pItem->pExpr; Expr *pE2 = sqlite3ExprSkipCollate(pE); - iCol = resolveAsName(pParse, pSelect->pEList, pE2); - if( iCol>0 ){ - /* If an AS-name match is found, mark this ORDER BY column as being - ** a copy of the iCol-th result-set column. The subsequent call to - ** sqlite3ResolveOrderGroupBy() will convert the expression to a - ** copy of the iCol-th result-set expression. */ - pItem->iOrderByCol = (u16)iCol; - continue; + if( zType[0]!='G' ){ + iCol = resolveAsName(pParse, pSelect->pEList, pE2); + if( iCol>0 ){ + /* If an AS-name match is found, mark this ORDER BY column as being + ** a copy of the iCol-th result-set column. The subsequent call to + ** sqlite3ResolveOrderGroupBy() will convert the expression to a + ** copy of the iCol-th result-set expression. */ + pItem->iOrderByCol = (u16)iCol; + continue; + } } if( sqlite3ExprIsInteger(pE2, &iCol) ){ /* The ORDER BY term is an integer constant. Again, set the column diff --git a/test/resolver01.test b/test/resolver01.test index 3bad269151..7d95a2132a 100644 --- a/test/resolver01.test +++ b/test/resolver01.test @@ -149,4 +149,60 @@ do_execsql_test resolver01-4.1 { SELECT '3', substr(m,2) AS m FROM t4 ORDER BY lower(m); } {1 x 1 y 1 z 2 x 2 y 2 z 3 z 3 y 3 x} +########################################################################## +# Test cases for ticket [1c69be2dafc28]: Make sure the GROUP BY binds +# more tightly to the input tables in all cases. +# +# This first case case has been wrong in SQLite for time out of mind. +# For SQLite version 3.7.17 the answer was two rows, which is wrong. +# +do_execsql_test resolver01-5.1 { + CREATE TABLE t5(m CHAR(2)); + INSERT INTO t5 VALUES('ax'); + INSERT INTO t5 VALUES('bx'); + INSERT INTO t5 VALUES('cy'); + SELECT count(*), substr(m,2,1) AS m FROM t5 GROUP BY m ORDER BY 1, 2; +} {1 x 1 x 1 y} + +# This case is unambiguous and has always been correct. +# +do_execsql_test resolver01-5.2 { + SELECT count(*), substr(m,2,1) AS mx FROM t5 GROUP BY m ORDER BY 1, 2; +} {1 x 1 x 1 y} + +# This case is not allowed in standard SQL, but SQLite allows and does +# the sensible thing. +# +do_execsql_test resolver01-5.3 { + SELECT count(*), substr(m,2,1) AS mx FROM t5 GROUP BY mx ORDER BY 1, 2; +} {1 y 2 x} +do_execsql_test resolver01-5.4 { + SELECT count(*), substr(m,2,1) AS mx FROM t5 + GROUP BY substr(m,2,1) ORDER BY 1, 2; +} {1 y 2 x} + +# These test case weere provided in the 2013-08-14 email from Rob Golsteijn +# that originally reported the problem of ticket [1c69be2dafc28]. +# +do_execsql_test resolver01-6.1 { + CREATE TABLE t61(name); + SELECT min(name) FROM t61 GROUP BY lower(name); +} {} +do_execsql_test resolver01-6.2 { + SELECT min(name) AS name FROM t61 GROUP BY lower(name); +} {} +do_execsql_test resolver01-6.3 { + CREATE TABLE t63(name); + INSERT INTO t63 VALUES (NULL); + INSERT INTO t63 VALUES ('abc'); + SELECT count(), + NULLIF(name,'abc') AS name + FROM t63 + GROUP BY lower(name); +} {1 {} 1 {}} + + + + + finish_test