aboutsummaryrefslogtreecommitdiff
path: root/src/build.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/build.c')
-rw-r--r--src/build.c35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/build.c b/src/build.c
index e45908dc3..0a816b398 100644
--- a/src/build.c
+++ b/src/build.c
@@ -1321,7 +1321,7 @@ void sqlite3AddPrimaryKey(
}
if( nTerm==1
&& zType && sqlite3StrICmp(zType, "INTEGER")==0
- && sortOrder==SQLITE_SO_ASC
+ && sortOrder!=SQLITE_SO_DESC
){
pTab->iPKey = iCol;
pTab->keyConf = (u8)onError;
@@ -2600,6 +2600,8 @@ void sqlite3CreateForeignKey(
assert( pTo!=0 );
if( p==0 || IN_DECLARE_VTAB ) goto fk_end;
+ sqlite3RestrictColumnListSyntax(pParse, pFromCol);
+ sqlite3RestrictColumnListSyntax(pParse, pToCol);
if( pFromCol==0 ){
int iCol = p->nCol-1;
if( NEVER(iCol<0) ) goto fk_end;
@@ -3038,7 +3040,8 @@ Index *sqlite3CreateIndex(
if( pList==0 ) goto exit_create_index;
pList->a[0].zName = sqlite3DbStrDup(pParse->db,
pTab->aCol[pTab->nCol-1].zName);
- pList->a[0].sortOrder = (u8)sortOrder;
+ assert( pList->nExpr==1 );
+ sqlite3ExprListSetSortOrder(pList, sortOrder);
}
/* Figure out how many bytes of space are required to store explicitly
@@ -4283,6 +4286,32 @@ KeyInfo *sqlite3KeyInfoOfIndex(Parse *pParse, Index *pIdx){
return pKey;
}
+/*
+** Generate a syntax error if the expression list provided contains
+** any COLLATE or ASC or DESC keywords.
+**
+** Some legacy versions of SQLite allowed constructs like:
+**
+** CREATE TABLE x(..., FOREIGN KEY(x COLLATE binary DESC) REFERENCES...);
+** ^^^^^^^^^^^^^^^^^^^
+**
+** The COLLATE and sort order terms were ignored. To prevent compatibility
+** problems in case something like this appears in a legacy sqlite_master
+** table, only enforce the restriction on new SQL statements, not when
+** parsing the schema out of the sqlite_master table.
+*/
+void sqlite3RestrictColumnListSyntax(Parse *pParse, ExprList *p){
+ int i;
+ if( p==0 || pParse->db->init.busy ) return;
+ for(i=0; i<p->nExpr; i++){
+ if( p->a[i].pExpr!=0 || p->a[i].bDefinedSO ){
+ sqlite3ErrorMsg(pParse, "syntax error after column name \"%w\"",
+ p->a[i].zName);
+ return;
+ }
+ }
+}
+
#ifndef SQLITE_OMIT_CTE
/*
** This routine is invoked once per CTE by the parser while parsing a
@@ -4299,6 +4328,8 @@ With *sqlite3WithAdd(
With *pNew;
char *zName;
+ sqlite3RestrictColumnListSyntax(pParse, pArglist);
+
/* Check that the CTE name is unique within this WITH clause. If
** not, store an error in the Parse structure. */
zName = sqlite3NameFromToken(pParse->db, pName);