OLD | NEW |
| (Empty) |
1 From 8451a8f615c1542a79ae190d4117e10f263857f7 Mon Sep 17 00:00:00 2001 | |
2 From: Scott Hess <shess@chromium.org> | |
3 Date: Mon, 23 Mar 2015 11:24:11 -0700 | |
4 Subject: [PATCH 11/11] [backport] Fix collation dequoting. | |
5 | |
6 Backport https://www.sqlite.org/src/info/eddc05e7bb31fae7 | |
7 "Fix a problem causing collation sequence names to be dequoted | |
8 multiple times under some circumstances." | |
9 | |
10 BUG=469082 | |
11 --- | |
12 third_party/sqlite/src/src/expr.c | 7 ++-- | |
13 third_party/sqlite/src/src/parse.y | 6 ++-- | |
14 third_party/sqlite/src/src/sqliteInt.h | 2 +- | |
15 third_party/sqlite/src/src/where.c | 9 +++-- | |
16 third_party/sqlite/src/test/collate1.test | 58 +++++++++++++++++++++++++++++-- | |
17 5 files changed, 68 insertions(+), 14 deletions(-) | |
18 | |
19 diff --git a/third_party/sqlite/src/src/expr.c b/third_party/sqlite/src/src/expr
.c | |
20 index 65f211e..2d96c8d 100644 | |
21 --- a/third_party/sqlite/src/src/expr.c | |
22 +++ b/third_party/sqlite/src/src/expr.c | |
23 @@ -69,10 +69,11 @@ char sqlite3ExprAffinity(Expr *pExpr){ | |
24 Expr *sqlite3ExprAddCollateToken( | |
25 Parse *pParse, /* Parsing context */ | |
26 Expr *pExpr, /* Add the "COLLATE" clause to this expression */ | |
27 - const Token *pCollName /* Name of collating sequence */ | |
28 + const Token *pCollName, /* Name of collating sequence */ | |
29 + int dequote /* True to dequote pCollName */ | |
30 ){ | |
31 if( pCollName->n>0 ){ | |
32 - Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, 1); | |
33 + Expr *pNew = sqlite3ExprAlloc(pParse->db, TK_COLLATE, pCollName, dequote); | |
34 if( pNew ){ | |
35 pNew->pLeft = pExpr; | |
36 pNew->flags |= EP_Collate|EP_Skip; | |
37 @@ -86,7 +87,7 @@ Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr,
const char *zC){ | |
38 assert( zC!=0 ); | |
39 s.z = zC; | |
40 s.n = sqlite3Strlen30(s.z); | |
41 - return sqlite3ExprAddCollateToken(pParse, pExpr, &s); | |
42 + return sqlite3ExprAddCollateToken(pParse, pExpr, &s, 0); | |
43 } | |
44 | |
45 /* | |
46 diff --git a/third_party/sqlite/src/src/parse.y b/third_party/sqlite/src/src/par
se.y | |
47 index 877827e..d888cff 100644 | |
48 --- a/third_party/sqlite/src/src/parse.y | |
49 +++ b/third_party/sqlite/src/src/parse.y | |
50 @@ -854,7 +854,7 @@ expr(A) ::= VARIABLE(X). { | |
51 spanSet(&A, &X, &X); | |
52 } | |
53 expr(A) ::= expr(E) COLLATE ids(C). { | |
54 - A.pExpr = sqlite3ExprAddCollateToken(pParse, E.pExpr, &C); | |
55 + A.pExpr = sqlite3ExprAddCollateToken(pParse, E.pExpr, &C, 1); | |
56 A.zStart = E.zStart; | |
57 A.zEnd = &C.z[C.n]; | |
58 } | |
59 @@ -1200,14 +1200,14 @@ uniqueflag(A) ::= . {A = OE_None;} | |
60 idxlist_opt(A) ::= . {A = 0;} | |
61 idxlist_opt(A) ::= LP idxlist(X) RP. {A = X;} | |
62 idxlist(A) ::= idxlist(X) COMMA nm(Y) collate(C) sortorder(Z). { | |
63 - Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C); | |
64 + Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C, 1); | |
65 A = sqlite3ExprListAppend(pParse,X, p); | |
66 sqlite3ExprListSetName(pParse,A,&Y,1); | |
67 sqlite3ExprListCheckLength(pParse, A, "index"); | |
68 if( A ) A->a[A->nExpr-1].sortOrder = (u8)Z; | |
69 } | |
70 idxlist(A) ::= nm(Y) collate(C) sortorder(Z). { | |
71 - Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C); | |
72 + Expr *p = sqlite3ExprAddCollateToken(pParse, 0, &C, 1); | |
73 A = sqlite3ExprListAppend(pParse,0, p); | |
74 sqlite3ExprListSetName(pParse, A, &Y, 1); | |
75 sqlite3ExprListCheckLength(pParse, A, "index"); | |
76 diff --git a/third_party/sqlite/src/src/sqliteInt.h b/third_party/sqlite/src/src
/sqliteInt.h | |
77 index 9d6a7d8..264f4fe 100644 | |
78 --- a/third_party/sqlite/src/src/sqliteInt.h | |
79 +++ b/third_party/sqlite/src/src/sqliteInt.h | |
80 @@ -3462,7 +3462,7 @@ int sqlite3ReadSchema(Parse *pParse); | |
81 CollSeq *sqlite3FindCollSeq(sqlite3*,u8 enc, const char*,int); | |
82 CollSeq *sqlite3LocateCollSeq(Parse *pParse, const char*zName); | |
83 CollSeq *sqlite3ExprCollSeq(Parse *pParse, Expr *pExpr); | |
84 -Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*); | |
85 +Expr *sqlite3ExprAddCollateToken(Parse *pParse, Expr*, const Token*, int); | |
86 Expr *sqlite3ExprAddCollateString(Parse*,Expr*,const char*); | |
87 Expr *sqlite3ExprSkipCollate(Expr*); | |
88 int sqlite3CheckCollSeq(Parse *, CollSeq *); | |
89 diff --git a/third_party/sqlite/src/src/where.c b/third_party/sqlite/src/src/whe
re.c | |
90 index bc01107..793b01d 100644 | |
91 --- a/third_party/sqlite/src/src/where.c | |
92 +++ b/third_party/sqlite/src/src/where.c | |
93 @@ -1252,7 +1252,7 @@ static void exprAnalyze( | |
94 Expr *pNewExpr2; | |
95 int idxNew1; | |
96 int idxNew2; | |
97 - Token sCollSeqName; /* Name of collating sequence */ | |
98 + const char *zCollSeqName; /* Name of collating sequence */ | |
99 | |
100 pLeft = pExpr->x.pList->a[1].pExpr; | |
101 pStr2 = sqlite3ExprDup(db, pStr1, 0); | |
102 @@ -1272,11 +1272,10 @@ static void exprAnalyze( | |
103 } | |
104 *pC = c + 1; | |
105 } | |
106 - sCollSeqName.z = noCase ? "NOCASE" : "BINARY"; | |
107 - sCollSeqName.n = 6; | |
108 + zCollSeqName = noCase ? "NOCASE" : "BINARY"; | |
109 pNewExpr1 = sqlite3ExprDup(db, pLeft, 0); | |
110 pNewExpr1 = sqlite3PExpr(pParse, TK_GE, | |
111 - sqlite3ExprAddCollateToken(pParse,pNewExpr1,&sCollSeqName), | |
112 + sqlite3ExprAddCollateString(pParse,pNewExpr1,zCollSeqName), | |
113 pStr1, 0); | |
114 transferJoinMarkings(pNewExpr1, pExpr); | |
115 idxNew1 = whereClauseInsert(pWC, pNewExpr1, TERM_VIRTUAL|TERM_DYNAMIC); | |
116 @@ -1284,7 +1283,7 @@ static void exprAnalyze( | |
117 exprAnalyze(pSrc, pWC, idxNew1); | |
118 pNewExpr2 = sqlite3ExprDup(db, pLeft, 0); | |
119 pNewExpr2 = sqlite3PExpr(pParse, TK_LT, | |
120 - sqlite3ExprAddCollateToken(pParse,pNewExpr2,&sCollSeqName), | |
121 + sqlite3ExprAddCollateString(pParse,pNewExpr2,zCollSeqName), | |
122 pStr2, 0); | |
123 transferJoinMarkings(pNewExpr2, pExpr); | |
124 idxNew2 = whereClauseInsert(pWC, pNewExpr2, TERM_VIRTUAL|TERM_DYNAMIC); | |
125 diff --git a/third_party/sqlite/src/test/collate1.test b/third_party/sqlite/src/
test/collate1.test | |
126 index 2085415..0716ac7 100644 | |
127 --- a/third_party/sqlite/src/test/collate1.test | |
128 +++ b/third_party/sqlite/src/test/collate1.test | |
129 @@ -10,12 +10,12 @@ | |
130 # | |
131 #*********************************************************************** | |
132 # This file implements regression tests for SQLite library. The | |
133 -# focus of this script is page cache subsystem. | |
134 +# focus of this script is testing collation sequences. | |
135 # | |
136 -# $Id: collate1.test,v 1.5 2007/02/01 23:02:46 drh Exp $ | |
137 | |
138 set testdir [file dirname $argv0] | |
139 source $testdir/tester.tcl | |
140 +set testprefix collate1 | |
141 | |
142 # | |
143 # Tests are roughly organised as follows: | |
144 @@ -333,4 +333,58 @@ do_test collate1-5.3 { | |
145 } | |
146 } {1 2} | |
147 | |
148 + | |
149 + | |
150 +#------------------------------------------------------------------------- | |
151 +# Fix problems with handling collation sequences named '"""'. | |
152 +# | |
153 +do_execsql_test 6.1 { | |
154 + SELECT """"""""; | |
155 +} {\"\"\"} | |
156 + | |
157 +do_catchsql_test 6.2 { | |
158 + CREATE TABLE x1(a); | |
159 + SELECT a FROM x1 ORDER BY a COLLATE """"""""; | |
160 +} {1 {no such collation sequence: """}} | |
161 + | |
162 +do_catchsql_test 6.3 { | |
163 + SELECT a FROM x1 ORDER BY 1 COLLATE """"""""; | |
164 +} {1 {no such collation sequence: """}} | |
165 + | |
166 +do_catchsql_test 6.4 { | |
167 + SELECT 0 UNION SELECT 0 ORDER BY 1 COLLATE """"""""; | |
168 +} {1 {no such collation sequence: """}} | |
169 + | |
170 +db collate {"""} [list string compare -nocase] | |
171 + | |
172 +do_execsql_test 6.5 { | |
173 + PRAGMA foreign_keys = ON; | |
174 + CREATE TABLE p1(a PRIMARY KEY COLLATE '"""'); | |
175 + CREATE TABLE c1(x, y REFERENCES p1); | |
176 +} {} | |
177 + | |
178 +do_execsql_test 6.6 { | |
179 + INSERT INTO p1 VALUES('abc'); | |
180 + INSERT INTO c1 VALUES(1, 'ABC'); | |
181 +} | |
182 + | |
183 +ifcapable foreignkey { | |
184 + do_catchsql_test 6.7 { | |
185 + DELETE FROM p1 WHERE rowid = 1 | |
186 + } {1 {FOREIGN KEY constraint failed}} | |
187 +} | |
188 + | |
189 +do_execsql_test 6.8 { | |
190 + INSERT INTO p1 VALUES('abb'); | |
191 + INSERT INTO p1 VALUES('wxz'); | |
192 + INSERT INTO p1 VALUES('wxy'); | |
193 + | |
194 + INSERT INTO c1 VALUES(2, 'abb'); | |
195 + INSERT INTO c1 VALUES(3, 'wxz'); | |
196 + INSERT INTO c1 VALUES(4, 'WXY'); | |
197 + SELECT x, y FROM c1 ORDER BY y COLLATE """"""""; | |
198 +} {2 abb 1 ABC 4 WXY 3 wxz} | |
199 + | |
200 finish_test | |
201 + | |
202 + | |
203 -- | |
204 2.4.5 | |
205 | |
OLD | NEW |