One liner ------------ diff -r 354a72d834e6 third_party/sqlite/sqlite3/where.c --- a/third_party/sqlite/sqlite3/where.c Fri Sep 09 15:13:23 2011 +0200 +++ b/third_party/sqlite/sqlite3/where.c Fri Sep 09 15:15:49 2011 +0200 @@ -1971,6 +1971,7 @@ pIdxCons[j].iColumn = pTerm->u.leftColumn; pIdxCons[j].iTermOffset = i; pIdxCons[j].op = (u8)pTerm->eOperator; + pIdxCons[j].pColl = sqlite3BinaryCompareCollSeq(pParse, pTerm->pExpr->pLeft, pTerm->pExpr->pRight); /* The direct assignment in the previous line is possible only because ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The ** following asserts verify this fact. */
Full Patch ------------ diff -r 354a72d834e6 third_party/sqlite/sqlite3/sqlite3.h --- a/third_party/sqlite/sqlite3/sqlite3.h Fri Sep 09 15:13:23 2011 +0200 +++ b/third_party/sqlite/sqlite3/sqlite3.h Fri Sep 09 15:17:16 2011 +0200 @@ -4337,6 +4337,46 @@ }; /* +** A "Collating Sequence" is defined by an instance of the following +** structure. Conceptually, a collating sequence consists of a name and +** a comparison routine that defines the order of that sequence. +** +** There may two separate implementations of the collation function, one +** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that +** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine +** native byte order. When a collation sequence is invoked, SQLite selects +** the version that will require the least expensive encoding +** translations, if any. +** +** The CollSeq.pUser member variable is an extra parameter that passed in +** as the first argument to the UTF-8 comparison function, xCmp. +** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function, +** xCmp16. +** +** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the +** collating sequence is undefined. Indices built on an undefined +** collating sequence may not be read or written. +*/ +struct CollSeq { + char *zName; /* Name of the collating sequence, UTF-8 encoded */ + unsigned char enc; /* Text encoding handled by xCmp() */ + unsigned char type; /* One of the SQLITE_COLL_... values below */ + void *pUser; /* First argument to xCmp() */ + int (*xCmp)(void*,int, const void*, int, const void*); + void (*xDel)(void*); /* Destructor for pUser */ +}; + +typedef struct CollSeq CollSeq; + +/* +** Allowed values of CollSeq.type: +*/ +#define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */ +#define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */ +#define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */ +#define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */ + +/* ** CAPI3REF: Virtual Table Indexing Information ** KEYWORDS: sqlite3_index_info ** @@ -4397,6 +4437,7 @@ unsigned char op; /* Constraint operator */ unsigned char usable; /* True if this constraint is usable */ int iTermOffset; /* Used internally - xBestIndex should ignore */ + CollSeq *pColl; /* Collation sequence */ } *aConstraint; /* Table of WHERE clause constraints */ int nOrderBy; /* Number of terms in the ORDER BY clause */ struct sqlite3_index_orderby { diff -r 354a72d834e6 third_party/sqlite/sqlite3/sqliteInt.h --- a/third_party/sqlite/sqlite3/sqliteInt.h Fri Sep 09 15:13:23 2011 +0200 +++ b/third_party/sqlite/sqlite3/sqliteInt.h Fri Sep 09 15:17:16 2011 +0200 @@ -1057,43 +1057,6 @@ #endif }; -/* -** A "Collating Sequence" is defined by an instance of the following -** structure. Conceptually, a collating sequence consists of a name and -** a comparison routine that defines the order of that sequence. -** -** There may two separate implementations of the collation function, one -** that processes text in UTF-8 encoding (CollSeq.xCmp) and another that -** processes text encoded in UTF-16 (CollSeq.xCmp16), using the machine -** native byte order. When a collation sequence is invoked, SQLite selects -** the version that will require the least expensive encoding -** translations, if any. -** -** The CollSeq.pUser member variable is an extra parameter that passed in -** as the first argument to the UTF-8 comparison function, xCmp. -** CollSeq.pUser16 is the equivalent for the UTF-16 comparison function, -** xCmp16. -** -** If both CollSeq.xCmp and CollSeq.xCmp16 are NULL, it means that the -** collating sequence is undefined. Indices built on an undefined -** collating sequence may not be read or written. -*/ -struct CollSeq { - char *zName; /* Name of the collating sequence, UTF-8 encoded */ - u8 enc; /* Text encoding handled by xCmp() */ - u8 type; /* One of the SQLITE_COLL_... values below */ - void *pUser; /* First argument to xCmp() */ - int (*xCmp)(void*,int, const void*, int, const void*); - void (*xDel)(void*); /* Destructor for pUser */ -}; - -/* -** Allowed values of CollSeq.type: -*/ -#define SQLITE_COLL_BINARY 1 /* The default memcmp() collating sequence */ -#define SQLITE_COLL_NOCASE 2 /* The built-in NOCASE collating sequence */ -#define SQLITE_COLL_REVERSE 3 /* The built-in REVERSE collating sequence */ -#define SQLITE_COLL_USER 0 /* Any other user-defined collating sequence */ /* ** A sort order can be either ASC or DESC. diff -r 354a72d834e6 third_party/sqlite/sqlite3/where.c --- a/third_party/sqlite/sqlite3/where.c Fri Sep 09 15:13:23 2011 +0200 +++ b/third_party/sqlite/sqlite3/where.c Fri Sep 09 15:17:16 2011 +0200 @@ -1971,6 +1971,7 @@ pIdxCons[j].iColumn = pTerm->u.leftColumn; pIdxCons[j].iTermOffset = i; pIdxCons[j].op = (u8)pTerm->eOperator; + pIdxCons[j].pColl = sqlite3BinaryCompareCollSeq(pParse, pTerm->pExpr->pLeft, pTerm->pExpr->pRight); /* The direct assignment in the previous line is possible only because ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The ** following asserts verify this fact. */ -----Original Message----- From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-boun...@sqlite.org] On Behalf Of Ben Harper Sent: 09 September 2011 03:18 PM To: sqlite-users@sqlite.org Subject: [sqlite] Patch to pass collation through to Virtual Tables Hi, I have attached a one-liner (vtab-collation.patch) that sends collation information through to virtual tables. The bigger patch (vtab-collation-full.patch) illustrates the header file changes necessary to make this compile. Unfortunately, it's not as simple as just one line of code, since my patch requires exposure of CollSeq to the outside world. What this patch does is to grant the virtual table the opportunity to distinguish between the following two queries: SELECT * FROM vtab WHERE field = 'abc'; SELECT * FROM vtab WHERE field = 'abc' COLLATE NOCASE; This also grants the virtual table the ability to recognized case-insensitive LIKE queries, which is also not currently possible. I basically just copied the single line from bestBtreeIndex into bestVirtualIndex. Is there any chance something like this could get merged into the main line? Regards, Ben _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users