From 8e2ca029a3b46c32d7326bc46d2357062d4814c2 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 17 Jun 2002 17:07:19 +0000 Subject: [PATCH] Add preliminary logic for the eventual move to having separate TEXT and NUMTEXT datatypes. Also change the version number to 2.5.0 in preparation for an interim release. (CVS 625) FossilOrigin-Name: 05783a9db585c1ead42135252dca97d2bc6e2118 --- VERSION | 2 +- manifest | 22 +++++++++++----------- manifest.uuid | 2 +- src/build.c | 34 +++++++++++++++++++++++++++++++++- src/expr.c | 3 ++- src/parse.y | 20 +++++++++++++------- src/sqliteInt.h | 31 ++++++++++++++++++++++++------- src/tokenize.c | 3 ++- 8 files changed, 87 insertions(+), 30 deletions(-) diff --git a/VERSION b/VERSION index cf95c0186a..437459cd94 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.4.12 +2.5.0 diff --git a/manifest b/manifest index 124ca09495..96edf6a1ca 100644 --- a/manifest +++ b/manifest @@ -1,9 +1,9 @@ -C Expose\san\sadditional\sinternal\sAPI\sroutine\s(sqliteInitCallback())\sfor\nuse\sby\sprivate\scode.\s(CVS\s624) -D 2002-06-16T18:21:44 +C Add\spreliminary\slogic\sfor\sthe\seventual\smove\sto\shaving\sseparate\sTEXT\sand\nNUMTEXT\sdatatypes.\s\sAlso\schange\sthe\sversion\snumber\sto\s2.5.0\sin\spreparation\nfor\san\sinterim\srelease.\s(CVS\s625) +D 2002-06-17T17:07:19 F Makefile.in 6291a33b87d2a395aafd7646ee1ed562c6f2c28c F Makefile.template 4e11752e0b5c7a043ca50af4296ec562857ba495 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0 -F VERSION 45e2ae5cf63867a750b544c539f79a076d53a9a0 +F VERSION 4d924d02a7c61b0eb53a6fc5c6fc9536b9b6f212 F aclocal.m4 11faa843caa38fd451bc6aeb43e248d1723a269d F config.guess f38b1e93d1e0fa6f5a6913e9e7b12774b9232588 F config.sub f14b07d544ca26b5d698259045136b783e18fc7f @@ -20,10 +20,10 @@ F sqlite.1 83f4a9d37bdf2b7ef079a82d54eaf2e3509ee6ea F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6 F src/btree.c 8b86be8f234c1c5dab3186f69cee2544ec9d7257 F src/btree.h 8abeabfe6e0b1a990b64fa457592a6482f6674f3 -F src/build.c 36e42718a7a94f554ea39508993378482f5335c7 +F src/build.c f4633493f57660587c35c76dc7948f5da691a718 F src/delete.c 15789fc723a6776309945b13a79f9a0e78275fc0 F src/encode.c 346b12b46148506c32038524b95c4631ab46d760 -F src/expr.c 2dcfcd0b032206954a307d7e2731bf070d58835b +F src/expr.c ec0689af4e355356df47dc1514ff17523d2f9c71 F src/func.c b8d0fd3011f53ea0e46b6bab857612eb36b5d1ea F src/hash.c 6a6236b89c8c060c65dabd300a1c8ce7c10edb72 F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8 @@ -34,21 +34,21 @@ F src/os.c 9cc40c5384baba4a85e160e67807645ca98ba3cc F src/os.h 4a361fccfbc4e7609b3e1557f604f94c1e96ad10 F src/pager.c 1e41053c949cea1f09d8dafada5fe8f90785e650 F src/pager.h 6fddfddd3b73aa8abc081b973886320e3c614f0e -F src/parse.y 42920305d49666419358b469e4ec522ac867a39f +F src/parse.y 2285d8967d7334d52a2188089e5a881d73ba56f6 F src/printf.c 236ed7a79386feed4456fa728fff8be793f1547c F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe F src/select.c 6c3a92d7a0bdf3448265d530cc0e6f6e5a764997 F src/shell.c 1d22fe870ee852cfb975fd000dbe3973713d0a15 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e F src/sqlite.h.in 0038faa6d642de06b91143ee65a131bd831d020b -F src/sqliteInt.h b09bebf759f71a2c70510204d56053648eee9eb7 +F src/sqliteInt.h ea5c5ce4c321d66934fa1341caf4f32b61e96bec F src/table.c eed2098c9b577aa17f8abe89313a9c4413f57d63 F src/tclsqlite.c 9300c9606a38bc0c75d6c0bc8a6197ab979353d1 F src/test1.c 5cc4f0bbf38237e04e1b2077e285b41bfb4c4cbf F src/test2.c 669cc22781c6461a273416ec1a7414d25c081730 F src/test3.c 4e52fff8b01f08bd202f7633feda5639b7ba2b5e F src/threadtest.c 81f0598e0f031c1bd506af337fdc1b7e8dff263f -F src/tokenize.c 890ca022d45f1798dadc300a798951597428853e +F src/tokenize.c ac4c46f190346b87da54ec3e2605d160af80c619 F src/trigger.c 21342af6ac031fece39c8fc6eabd1739ca5327c1 F src/update.c 05431e23a9c83502fd7911e771c8366fc2b90b4c F src/util.c 876b259f9186e84b944b72e793dd3dad50e63e95 @@ -137,7 +137,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218 -P 633ce4dd252ac351b04bdb7bed2d5374ee9a3f12 -R 704a7f7fff6331780af41f270723daf8 +P cd74495f995803eeb5c2b900d536deb52e5584eb +R 31140297d3b7945de97d1fa5c462c380 U drh -Z 721b8e63e54d0704311d918642ec1d5c +Z 0db839a903dfa0a0a59b04ff4d6071dd diff --git a/manifest.uuid b/manifest.uuid index 9ccde2359b..043e3b6453 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cd74495f995803eeb5c2b900d536deb52e5584eb \ No newline at end of file +05783a9db585c1ead42135252dca97d2bc6e2118 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 4b2da5b7bc..22f87dd242 100644 --- a/src/build.c +++ b/src/build.c @@ -25,7 +25,7 @@ ** ROLLBACK ** PRAGMA ** -** $Id: build.c,v 1.95 2002/05/24 20:31:37 drh Exp $ +** $Id: build.c,v 1.96 2002/06/17 17:07:20 drh Exp $ */ #include "sqliteInt.h" #include @@ -645,6 +645,38 @@ void sqliteAddPrimaryKey(Parse *pParse, IdList *pList, int onError){ } } +/* +** Return the appropriate collating type given the collation type token. +** Report an error if the type is undefined. +*/ +int sqliteCollateType(Parse *pParse, Token *pType){ + if( pType==0 ) return SQLITE_SO_UNK; + if( pType->n==4 && sqliteStrNICmp(pType->z, "text", 4)==0 ){ + return SQLITE_SO_TEXT; + } + if( pType->n==7 && sqliteStrNICmp(pType->z, "numeric", 7)==0 ){ + return SQLITE_SO_NUM; + } + sqliteSetNString(&pParse->zErrMsg, "unknown collating type: ", -1, + pType->z, pType->n, 0); + pParse->nErr++; + return SQLITE_SO_UNK; +} + +/* +** This routine is called by the parser while in the middle of +** parsing a CREATE TABLE statement. A "COLLATE" clause has +** been seen on a column. This routine sets the Column.sortOrder on +** the column currently under construction. +*/ +void sqliteAddCollateType(Parse *pParse, int collType){ + Table *p; + int i; + if( (p = pParse->pNewTable)==0 ) return; + i = p->nCol-1; + if( i>=0 ) p->aCol[i].sortOrder = collType; +} + /* ** Come up with a new random value for the schema cookie. Make sure ** the new value is different from the old. diff --git a/src/expr.c b/src/expr.c index 2d017aa52d..e6a3cfac85 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.71 2002/06/11 02:25:41 danielk1977 Exp $ +** $Id: expr.c,v 1.72 2002/06/17 17:07:20 drh Exp $ */ #include "sqliteInt.h" #include @@ -167,6 +167,7 @@ Expr *sqliteExprDup(Expr *p){ pNew = sqliteMalloc( sizeof(*p) ); if( pNew==0 ) return 0; pNew->op = p->op; + pNew->dataType = p->dataType; pNew->pLeft = sqliteExprDup(p->pLeft); pNew->pRight = sqliteExprDup(p->pRight); pNew->pList = sqliteExprListDup(p->pList); diff --git a/src/parse.y b/src/parse.y index 489c9fd1e0..725ea06a29 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.73 2002/06/11 02:25:42 danielk1977 Exp $ +** @(#) $Id: parse.y,v 1.74 2002/06/17 17:07:20 drh Exp $ */ %token_prefix TK_ %token_type {Token} @@ -117,7 +117,7 @@ id(A) ::= ID(X). {A = X;} // This obviates the need for the "id" nonterminal. // %fallback ID - ABORT AFTER ASC BEFORE BEGIN CASCADE CLUSTER CONFLICT + ABORT AFTER ASC BEFORE BEGIN CASCADE CLUSTER COLLATE CONFLICT COPY DEFERRED DELIMITERS DESC EACH END EXPLAIN FAIL FOR FULL IGNORE IMMEDIATE INITIALLY INSTEAD MATCH JOIN KEY OF OFFSET PARTIAL PRAGMA RAISE REPLACE RESTRICT ROW STATEMENT @@ -163,6 +163,9 @@ ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);} ccons ::= CHECK LP expr RP onconf. ccons ::= references. ccons ::= defer_subclause. +ccons ::= COLLATE id(C). { + sqliteAddCollateType(pParse, sqliteCollateType(pParse, &C)); +} // A REFERENCES clause is parsed but the current implementation does not // do anything with it. @@ -379,9 +382,9 @@ using_opt(U) ::= . {U = 0;} orderby_opt(A) ::= . {A = 0;} orderby_opt(A) ::= ORDER BY sortlist(X). {A = X;} -sortlist(A) ::= sortlist(X) COMMA sortitem(Y) sortorder(Z). { +sortlist(A) ::= sortlist(X) COMMA sortitem(Y) collate(C) sortorder(Z). { A = sqliteExprListAppend(X,Y,0); - if( A ) A->a[A->nExpr-1].sortOrder = Z; /* 0=ascending, 1=decending */ + if( A ) A->a[A->nExpr-1].sortOrder = C+Z; } sortlist(A) ::= sortitem(Y) sortorder(Z). { A = sqliteExprListAppend(0,Y,0); @@ -390,10 +393,13 @@ sortlist(A) ::= sortitem(Y) sortorder(Z). { sortitem(A) ::= expr(X). {A = X;} %type sortorder {int} +%type collate {int} -sortorder(A) ::= ASC. {A = 0;} -sortorder(A) ::= DESC. {A = 1;} -sortorder(A) ::= . {A = 0;} +sortorder(A) ::= ASC. {A = SQLITE_SO_ASC;} +sortorder(A) ::= DESC. {A = SQLITE_SO_DESC;} +sortorder(A) ::= . {A = SQLITE_SO_ASC;} +collate(C) ::= . {C = SQLITE_SO_UNK;} +collate(C) ::= COLLATE id(X). {C = sqliteCollateType(pParse, &X);} %type groupby_opt {ExprList*} %destructor groupby_opt {sqliteExprListDelete($$);} diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 6fc59c2694..c0728ea81a 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.124 2002/06/16 18:21:44 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.125 2002/06/17 17:07:20 drh Exp $ */ #include "sqlite.h" #include "hash.h" @@ -258,8 +258,23 @@ struct Column { char *zType; /* Data type for this column */ u8 notNull; /* True if there is a NOT NULL constraint */ u8 isPrimKey; /* True if this column is an INTEGER PRIMARY KEY */ + u8 sortOrder; /* Some combination of SQLITE_SO_... values */ }; +/* +** The allowed sort orders. +** +** The TEXT and NUM values use bits that do not overlap with DESC and ASC. +** That way the two can be combined into a single number. +*/ +#define SQLITE_SO_UNK 0 /* Use the default collating type. (SCT_NUM) */ +#define SQLITE_SO_TEXT 2 /* Sort using memcmp() */ +#define SQLITE_SO_NUM 4 /* Sort using sqliteCompare() */ +#define SQLITE_SO_TYPEMASK 6 /* Mask to extract the collating sequence */ +#define SQLITE_SO_ASC 0 /* Sort in ascending order */ +#define SQLITE_SO_DESC 1 /* Sort in descending order */ +#define SQLITE_SO_DIRMASK 1 /* Mask to extract the sort direction */ + /* ** Each SQL table is represented in memory by an instance of the ** following structure. @@ -409,15 +424,15 @@ struct Token { ** operand. */ struct Expr { - int op; /* Operation performed by this node */ + u16 op; /* Operation performed by this node */ + u8 dataType; /* Either SQLITE_SO_TEXT or SQLITE_SO_NUM */ Expr *pLeft, *pRight; /* Left and right subnodes */ ExprList *pList; /* A list of expressions used as function arguments ** or in " IN (useAgg==TRUE, pull ** result from the iAgg-th element of the aggregator */ Select *pSelect; /* When the expression is a sub-select. Also the @@ -437,9 +452,9 @@ struct ExprList { struct ExprList_item { Expr *pExpr; /* The list of expressions */ char *zName; /* Token associated with this expression */ - char sortOrder; /* 1 for DESC or 0 for ASC */ - char isAgg; /* True if this is an aggregate like count(*) */ - char done; /* A flag to indicate when processing is finished */ + u8 sortOrder; /* 1 for DESC or 0 for ASC */ + u8 isAgg; /* True if this is an aggregate like count(*) */ + u8 done; /* A flag to indicate when processing is finished */ } *a; /* One entry for each expression */ }; @@ -821,6 +836,8 @@ void sqliteAddNotNull(Parse*, int); void sqliteAddPrimaryKey(Parse*, IdList*, int); void sqliteAddColumnType(Parse*,Token*,Token*); void sqliteAddDefaultValue(Parse*,Token*,int); +int sqliteCollateType(Parse*, Token*); +void sqliteAddCollateType(Parse*, int); void sqliteEndTable(Parse*,Token*,Select*); void sqliteCreateView(Parse*,Token*,Token*,Select*); int sqliteViewGetColumnNames(Parse*,Table*); diff --git a/src/tokenize.c b/src/tokenize.c index ba88164b58..7090c7c576 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -15,7 +15,7 @@ ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** -** $Id: tokenize.c,v 1.45 2002/06/11 02:25:42 danielk1977 Exp $ +** $Id: tokenize.c,v 1.46 2002/06/17 17:07:20 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -52,6 +52,7 @@ static Keyword aKeywordTable[] = { { "CASE", 0, TK_CASE, 0 }, { "CHECK", 0, TK_CHECK, 0 }, { "CLUSTER", 0, TK_CLUSTER, 0 }, + { "COLLATE", 0, TK_COLLATE, 0 }, { "COMMIT", 0, TK_COMMIT, 0 }, { "CONFLICT", 0, TK_CONFLICT, 0 }, { "CONSTRAINT", 0, TK_CONSTRAINT, 0 }, -- 2.47.3