/ Check-in [9740aa95]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:9740aa95a3f848fc663c88263a911fbc76ada243
User & Date: drh 2007-02-02 12:44:37
Context
2007-02-05
14:21
Set the MEM_Term flag when an internal string has a nul-terminator appended to it. Fix for #2213. (CVS 3627) check-in: fc969ad9 user: danielk1977 tags: trunk
2007-02-02
12:44
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) check-in: 9740aa95 user: drh tags: trunk
12:33
Fix typos in the pragma documentation. Ticket #2210. (CVS 3625) check-in: f0c66ad8 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.412 2006/12/16 16:25:15 drh Exp $
           25  +** $Id: build.c,v 1.413 2007/02/02 12:44:37 drh Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
  1218   1218   ** request it. If the collation factory does not supply such a sequence,
  1219   1219   ** and the sequence is available in another text encoding, then that is
  1220   1220   ** returned instead.
  1221   1221   **
  1222   1222   ** If no versions of the requested collations sequence are available, or
  1223   1223   ** another error occurs, NULL is returned and an error message written into
  1224   1224   ** pParse.
         1225  +**
         1226  +** This routine is a wrapper around sqlite3FindCollSeq().  This routine
         1227  +** invokes the collation factory if the named collation cannot be found
         1228  +** and generates an error message.
  1225   1229   */
  1226   1230   CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char *zName, int nName){
  1227   1231     sqlite3 *db = pParse->db;
  1228   1232     u8 enc = ENC(db);
  1229   1233     u8 initbusy = db->init.busy;
  1230   1234     CollSeq *pColl;
  1231   1235   
................................................................................
  2453   2457     ** load the column indices into the Index structure.  Report an error
  2454   2458     ** if any column is not found.
  2455   2459     */
  2456   2460     for(i=0, pListItem=pList->a; i<pList->nExpr; i++, pListItem++){
  2457   2461       const char *zColName = pListItem->zName;
  2458   2462       Column *pTabCol;
  2459   2463       int requestedSortOrder;
  2460         -    char *zColl;                   /* Collation sequence */
         2464  +    char *zColl;                   /* Collation sequence name */
  2461   2465   
  2462   2466       for(j=0, pTabCol=pTab->aCol; j<pTab->nCol; j++, pTabCol++){
  2463   2467         if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break;
  2464   2468       }
  2465   2469       if( j>=pTab->nCol ){
  2466   2470         sqlite3ErrorMsg(pParse, "table %s has no column named %s",
  2467   2471           pTab->zName, zColName);
  2468   2472         goto exit_create_index;
  2469   2473       }
         2474  +    /* TODO:  Add a test to make sure that the same column is not named
         2475  +    ** more than once within the same index.  Only the first instance of
         2476  +    ** the column will ever be used by the optimizer.  Note that using the
         2477  +    ** same column more than once cannot be an error because that would 
         2478  +    ** break backwards compatibility - it needs to be a warning.
         2479  +    */
  2470   2480       pIndex->aiColumn[i] = j;
  2471   2481       if( pListItem->pExpr ){
  2472   2482         assert( pListItem->pExpr->pColl );
  2473   2483         zColl = zExtra;
  2474   2484         strcpy(zExtra, pListItem->pExpr->pColl->zName);
  2475   2485         zExtra += (strlen(zColl) + 1);
  2476   2486       }else{

Changes to src/callback.c.

     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   **
    13     13   ** This file contains functions used to access the internal hash tables
    14     14   ** of user defined functions and collation sequences.
    15     15   **
    16         -** $Id: callback.c,v 1.15 2006/05/24 12:43:27 drh Exp $
           16  +** $Id: callback.c,v 1.16 2007/02/02 12:44:37 drh Exp $
    17     17   */
    18     18   
    19     19   #include "sqliteInt.h"
    20     20   
    21     21   /*
    22     22   ** Invoke the 'collation needed' callback to request a collation sequence
    23     23   ** in the database text encoding of name zName, length nName.
................................................................................
   191    191   /*
   192    192   ** Parameter zName points to a UTF-8 encoded string nName bytes long.
   193    193   ** Return the CollSeq* pointer for the collation sequence named zName
   194    194   ** for the encoding 'enc' from the database 'db'.
   195    195   **
   196    196   ** If the entry specified is not found and 'create' is true, then create a
   197    197   ** new entry.  Otherwise return NULL.
          198  +**
          199  +** A separate function sqlite3LocateCollSeq() is a wrapper around
          200  +** this routine.  sqlite3LocateCollSeq() invokes the collation factory
          201  +** if necessary and generates an error message if the collating sequence
          202  +** cannot be found.
   198    203   */
   199    204   CollSeq *sqlite3FindCollSeq(
   200    205     sqlite3 *db,
   201    206     u8 enc,
   202    207     const char *zName,
   203    208     int nName,
   204    209     int create

Changes to src/expr.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.273 2007/02/01 23:02:45 drh Exp $
           15  +** $Id: expr.c,v 1.274 2007/02/02 12:44:37 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** Return the 'affinity' of the expression pExpr if any.
    22     22   **
................................................................................
    48     48   #endif
    49     49     return pExpr->affinity;
    50     50   }
    51     51   
    52     52   /*
    53     53   ** Set the collating sequence for expression pExpr to be the collating
    54     54   ** sequence named by pToken.   Return a pointer to the revised expression.
           55  +** The collating sequence is marked as "explicit" using the EP_ExpCollate
           56  +** flag.  An explicit collating sequence will override implicit
           57  +** collating sequences.
    55     58   */
    56     59   Expr *sqlite3ExprSetColl(Parse *pParse, Expr *pExpr, Token *pName){
    57     60     CollSeq *pColl;
    58     61     if( pExpr==0 ) return 0;
    59     62     pColl = sqlite3LocateCollSeq(pParse, (char*)pName->z, pName->n);
    60     63     if( pColl ){
    61     64       pExpr->pColl = pColl;
................................................................................
   216    219     pNew->op = op;
   217    220     pNew->pLeft = pLeft;
   218    221     pNew->pRight = pRight;
   219    222     pNew->iAgg = -1;
   220    223     if( pToken ){
   221    224       assert( pToken->dyn==0 );
   222    225       pNew->span = pNew->token = *pToken;
   223         -  }else if( pLeft && pRight ){
   224         -    sqlite3ExprSpan(pNew, &pLeft->span, &pRight->span);
          226  +  }else if( pLeft ){
          227  +    if( pRight ){
          228  +      sqlite3ExprSpan(pNew, &pLeft->span, &pRight->span);
          229  +      if( pRight->flags && EP_ExpCollate ){
          230  +        pNew->flags |= EP_ExpCollate;
          231  +        pNew->pColl = pRight->pColl;
          232  +      }
          233  +    }
          234  +    if( pLeft->flags && EP_ExpCollate ){
          235  +      pNew->flags |= EP_ExpCollate;
          236  +      pNew->pColl = pLeft->pColl;
          237  +    }
   225    238     }
   226    239     return pNew;
   227    240   }
   228    241   
   229    242   /*
   230    243   ** Works like sqlite3Expr() but frees its pLeft and pRight arguments
   231    244   ** if it fails due to a malloc problem.

Changes to src/parse.y.

    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains SQLite's grammar for SQL.  Process this file
    13     13   ** using the lemon parser generator to generate C code that runs
    14     14   ** the parser.  Lemon will also generate a header file containing
    15     15   ** numeric codes for all of the tokens.
    16     16   **
    17         -** @(#) $Id: parse.y,v 1.214 2007/02/01 23:02:45 drh Exp $
           17  +** @(#) $Id: parse.y,v 1.215 2007/02/02 12:44:37 drh Exp $
    18     18   */
    19     19   
    20     20   // All token codes are small integers with #defines that begin with "TK_"
    21     21   %token_prefix TK_
    22     22   
    23     23   // The type of the data attached to each token is Token.  This is also the
    24     24   // default type for non-terminals.
................................................................................
   200    200   %right NOT.
   201    201   %left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ.
   202    202   %left GT LE LT GE.
   203    203   %right ESCAPE.
   204    204   %left BITAND BITOR LSHIFT RSHIFT.
   205    205   %left PLUS MINUS.
   206    206   %left STAR SLASH REM.
   207         -%left CONCAT COLLATE.
          207  +%left CONCAT.
          208  +%left COLLATE.
   208    209   %right UMINUS UPLUS BITNOT.
   209    210   
   210    211   // And "ids" is an identifer-or-string.
   211    212   //
   212    213   %type ids {Token}
   213    214   ids(A) ::= ID|STRING(X).   {A = X;}
   214    215   
................................................................................
   522    523   sortlist(A) ::= sortitem(Y) sortorder(Z). {
   523    524     A = sqlite3ExprListAppend(0,Y,0);
   524    525     if( A && A->a ) A->a[0].sortOrder = Z;
   525    526   }
   526    527   sortitem(A) ::= expr(X).   {A = X;}
   527    528   
   528    529   %type sortorder {int}
   529         -%type collate {Token}
   530    530   
   531    531   sortorder(A) ::= ASC.           {A = SQLITE_SO_ASC;}
   532    532   sortorder(A) ::= DESC.          {A = SQLITE_SO_DESC;}
   533    533   sortorder(A) ::= .              {A = SQLITE_SO_ASC;}
   534         -collate(C) ::= .                {C.z = 0; C.n = 0;}
   535         -collate(C) ::= COLLATE id(X).   {C = X;}
   536    534   
   537    535   %type groupby_opt {ExprList*}
   538    536   %destructor groupby_opt {sqlite3ExprListDelete($$);}
   539    537   groupby_opt(A) ::= .                      {A = 0;}
   540    538   groupby_opt(A) ::= GROUP BY exprlist(X).  {A = X;}
   541    539   
   542    540   %type having_opt {Expr*}
................................................................................
   876    874       if( p ) p->pColl = sqlite3LocateCollSeq(pParse, (char*)C.z, C.n);
   877    875     }
   878    876     A = sqlite3ExprListAppend(0, p, &Y);
   879    877     if( A ) A->a[A->nExpr-1].sortOrder = Z;
   880    878   }
   881    879   idxitem(A) ::= nm(X).              {A = X;}
   882    880   
          881  +%type collate {Token}
          882  +collate(C) ::= .                {C.z = 0; C.n = 0;}
          883  +collate(C) ::= COLLATE id(X).   {C = X;}
          884  +
   883    885   
   884    886   ///////////////////////////// The DROP INDEX command /////////////////////////
   885    887   //
   886    888   cmd ::= DROP INDEX ifexists(E) fullname(X).   {sqlite3DropIndex(pParse, X, E);}
   887    889   
   888    890   ///////////////////////////// The VACUUM command /////////////////////////////
   889    891   //