From a34001c9a38589ebf6e3378186cbeba89f3a2f87 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 2 Feb 2007 12:44:37 +0000 Subject: [PATCH] Minor tweaks to collating sequences. We'll hold of making major changes until 3.4.0, since we'll likely end up with some minor technical imcompatibilities. (CVS 3626) FossilOrigin-Name: 9740aa95a3f848fc663c88263a911fbc76ada243 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/build.c | 14 ++++++++++++-- src/callback.c | 7 ++++++- src/expr.c | 19 ++++++++++++++++--- src/parse.y | 12 +++++++----- 6 files changed, 51 insertions(+), 21 deletions(-) diff --git a/manifest b/manifest index 62290d1aa0..6b366c592c 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\stypos\sin\sthe\spragma\sdocumentation.\s\sTicket\s#2210.\s(CVS\s3625) -D 2007-02-02T12:33:17 +C Minor\stweaks\sto\scollating\ssequences.\s\sWe'll\shold\sof\smaking\smajor\schanges\nuntil\s3.4.0,\ssince\swe'll\slikely\send\sup\swith\ssome\sminor\stechnical\nimcompatibilities.\s(CVS\s3626) +D 2007-02-02T12:44:37 F Makefile.in 7fa74bf4359aa899da5586e394d17735f221315f F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -59,13 +59,13 @@ F src/attach.c b11eb4d5d3fb99a10a626956bccc7215f6b68b16 F src/auth.c 902f4722661c796b97f007d9606bd7529c02597f F src/btree.c 51aef6a4b18df165b83b332befd1447c011b4389 F src/btree.h 066444ee25bd6e6accb997bfd2cf5ace14dbcd00 -F src/build.c 02aedde724dc73295d6e9b8dc29afb5dd38de507 -F src/callback.c fd9bb39f7ff6b52bad8365617abc61c720640429 +F src/build.c 6bd68dc730b01c1727738f8e4b5c730eb0ddb421 +F src/callback.c 31d22b4919c7645cbcbb1591ce2453e8c677c558 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675 F src/date.c 393c73fc027597e008dcd81454544659e978b05c F src/delete.c 804384761144fe1a5035b99f4bd7d706976831bd F src/experimental.c 1b2d1a6cd62ecc39610e97670332ca073c50792b -F src/expr.c 4ece4d575fa8686535877bbfb2e9d74093a4aa94 +F src/expr.c 8cf28815fd3207ca99b5d755b1c8b662c263b29b F src/func.c b7e1e220a6795ecae7649815145ea5f8644dfa5f F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564 @@ -87,7 +87,7 @@ F src/os_win.c 8736cf3a49fd651a6538857480f302807d57814c F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b F src/pager.c d6ad66eb119602cb2e6a097f8f635372ba677d23 F src/pager.h 2e6d42f4ae004ae748a037b8468112b851c447a7 -F src/parse.y ebf4253e3710452953cd1ba8171beb86f47f7f57 +F src/parse.y bcfe366c1fd61cfc40e5344eb69a31997a821af0 F src/pragma.c 5091300911670ddaa552bfa12c45cbca1bb7e7d6 F src/prepare.c 484389c6811415b8f23d259ac9c029613e1c72c3 F src/printf.c aade23a789d7cc88b397ec0d33a0a01a33a7a9c1 @@ -428,7 +428,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 -P 85cca7cd252d46ba71d302a89bc67c56146ec552 -R d8f2f27fd4898ee810910b4a4a23b048 +P f0c66ad8e9bc303e3173438a56e47802c8fdde05 +R bd13f8a83574be8b00dc95661da5a69f U drh -Z 34857a339a05810f6531dd10590ab571 +Z a941f51c66596680d325cc016ae38453 diff --git a/manifest.uuid b/manifest.uuid index 88a0598146..62bb3c1b23 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f0c66ad8e9bc303e3173438a56e47802c8fdde05 \ No newline at end of file +9740aa95a3f848fc663c88263a911fbc76ada243 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 00b89f2fd6..0316f9c000 100644 --- a/src/build.c +++ b/src/build.c @@ -22,7 +22,7 @@ ** COMMIT ** ROLLBACK ** -** $Id: build.c,v 1.412 2006/12/16 16:25:15 drh Exp $ +** $Id: build.c,v 1.413 2007/02/02 12:44:37 drh Exp $ */ #include "sqliteInt.h" #include @@ -1222,6 +1222,10 @@ void sqlite3AddCollateType(Parse *pParse, const char *zType, int nType){ ** If no versions of the requested collations sequence are available, or ** another error occurs, NULL is returned and an error message written into ** pParse. +** +** This routine is a wrapper around sqlite3FindCollSeq(). This routine +** invokes the collation factory if the named collation cannot be found +** and generates an error message. */ CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){ sqlite3 *db = pParse->db; @@ -2457,7 +2461,7 @@ void sqlite3CreateIndex( const char *zColName = pListItem->zName; Column *pTabCol; int requestedSortOrder; - char *zColl; /* Collation sequence */ + char *zColl; /* Collation sequence name */ for(j=0, pTabCol=pTab->aCol; jnCol; j++, pTabCol++){ if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break; @@ -2467,6 +2471,12 @@ void sqlite3CreateIndex( pTab->zName, zColName); goto exit_create_index; } + /* TODO: Add a test to make sure that the same column is not named + ** more than once within the same index. Only the first instance of + ** the column will ever be used by the optimizer. Note that using the + ** same column more than once cannot be an error because that would + ** break backwards compatibility - it needs to be a warning. + */ pIndex->aiColumn[i] = j; if( pListItem->pExpr ){ assert( pListItem->pExpr->pColl ); diff --git a/src/callback.c b/src/callback.c index 2a87677dd3..96985ba858 100644 --- a/src/callback.c +++ b/src/callback.c @@ -13,7 +13,7 @@ ** This file contains functions used to access the internal hash tables ** of user defined functions and collation sequences. ** -** $Id: callback.c,v 1.15 2006/05/24 12:43:27 drh Exp $ +** $Id: callback.c,v 1.16 2007/02/02 12:44:37 drh Exp $ */ #include "sqliteInt.h" @@ -195,6 +195,11 @@ static CollSeq *findCollSeqEntry( ** ** If the entry specified is not found and 'create' is true, then create a ** new entry. Otherwise return NULL. +** +** A separate function sqlite3LocateCollSeq() is a wrapper around +** this routine. sqlite3LocateCollSeq() invokes the collation factory +** if necessary and generates an error message if the collating sequence +** cannot be found. */ CollSeq *sqlite3FindCollSeq( sqlite3 *db, diff --git a/src/expr.c b/src/expr.c index 7b34352c94..27bb7b85a5 100644 --- a/src/expr.c +++ b/src/expr.c @@ -12,7 +12,7 @@ ** This file contains routines used for analyzing expressions and ** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.273 2007/02/01 23:02:45 drh Exp $ +** $Id: expr.c,v 1.274 2007/02/02 12:44:37 drh Exp $ */ #include "sqliteInt.h" #include @@ -52,6 +52,9 @@ char sqlite3ExprAffinity(Expr *pExpr){ /* ** Set the collating sequence for expression pExpr to be the collating ** sequence named by pToken. Return a pointer to the revised expression. +** The collating sequence is marked as "explicit" using the EP_ExpCollate +** flag. An explicit collating sequence will override implicit +** collating sequences. */ Expr *sqlite3ExprSetColl(Parse *pParse, Expr *pExpr, Token *pName){ CollSeq *pColl; @@ -220,8 +223,18 @@ Expr *sqlite3Expr(int op, Expr *pLeft, Expr *pRight, const Token *pToken){ if( pToken ){ assert( pToken->dyn==0 ); pNew->span = pNew->token = *pToken; - }else if( pLeft && pRight ){ - sqlite3ExprSpan(pNew, &pLeft->span, &pRight->span); + }else if( pLeft ){ + if( pRight ){ + sqlite3ExprSpan(pNew, &pLeft->span, &pRight->span); + if( pRight->flags && EP_ExpCollate ){ + pNew->flags |= EP_ExpCollate; + pNew->pColl = pRight->pColl; + } + } + if( pLeft->flags && EP_ExpCollate ){ + pNew->flags |= EP_ExpCollate; + pNew->pColl = pLeft->pColl; + } } return pNew; } diff --git a/src/parse.y b/src/parse.y index ea64d96c37..bc05044db2 100644 --- a/src/parse.y +++ b/src/parse.y @@ -14,7 +14,7 @@ ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** -** @(#) $Id: parse.y,v 1.214 2007/02/01 23:02:45 drh Exp $ +** @(#) $Id: parse.y,v 1.215 2007/02/02 12:44:37 drh Exp $ */ // All token codes are small integers with #defines that begin with "TK_" @@ -204,7 +204,8 @@ id(A) ::= ID(X). {A = X;} %left BITAND BITOR LSHIFT RSHIFT. %left PLUS MINUS. %left STAR SLASH REM. -%left CONCAT COLLATE. +%left CONCAT. +%left COLLATE. %right UMINUS UPLUS BITNOT. // And "ids" is an identifer-or-string. @@ -526,13 +527,10 @@ sortlist(A) ::= sortitem(Y) sortorder(Z). { sortitem(A) ::= expr(X). {A = X;} %type sortorder {int} -%type collate {Token} sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;} sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;} sortorder(A) ::= . {A = SQLITE_SO_ASC;} -collate(C) ::= . {C.z = 0; C.n = 0;} -collate(C) ::= COLLATE id(X). {C = X;} %type groupby_opt {ExprList*} %destructor groupby_opt {sqlite3ExprListDelete($$);} @@ -880,6 +878,10 @@ idxlist(A) ::= idxitem(Y) collate(C) sortorder(Z). { } idxitem(A) ::= nm(X). {A = X;} +%type collate {Token} +collate(C) ::= . {C.z = 0; C.n = 0;} +collate(C) ::= COLLATE id(X). {C = X;} + ///////////////////////////// The DROP INDEX command ///////////////////////// // -- 2.47.2