aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2015-11-01 21:19:13 +0000
committerdrh <drh@noemail.net>2015-11-01 21:19:13 +0000
commit153110a7dadd49d5ded395a61242dc046334870c (patch)
tree077698828341af0ab867cf183d37071c3c13e42f /src
parent6a75c8ad942df4cbd0aec29dd2e65abfadd24ac2 (diff)
downloadsqlite-153110a7dadd49d5ded395a61242dc046334870c.tar.gz
sqlite-153110a7dadd49d5ded395a61242dc046334870c.zip
If a table-constraint PRIMARY KEY lists a single column in single-quotes and
that column has type INTEGER, then make that column an integer primary key, for historical compatibility. Fix for ticket [ac661962a2aeab3c331]. FossilOrigin-Name: db319a035feeb6f8fcd04f90fb10cd4b06e68184
Diffstat (limited to 'src')
-rw-r--r--src/build.c49
1 files changed, 25 insertions, 24 deletions
diff --git a/src/build.c b/src/build.c
index 7c79fe540..8cb2d44ac 100644
--- a/src/build.c
+++ b/src/build.c
@@ -1272,6 +1272,30 @@ void sqlite3AddDefaultValue(Parse *pParse, ExprSpan *pSpan){
}
/*
+** Backwards Compatibility Hack:
+**
+** Historical versions of SQLite accepted strings as column names in
+** indexes and PRIMARY KEY constraints and in UNIQUE constraints. Example:
+**
+** CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
+** CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
+**
+** This is goofy. But to preserve backwards compatibility we continue to
+** accept it. This routine does the necessary conversion. It converts
+** the expression given in its argument from a TK_STRING into a TK_ID
+** if the expression is just a TK_STRING with an optional COLLATE clause.
+** If the epxression is anything other than TK_STRING, the expression is
+** unchanged.
+*/
+static void sqlite3StringToId(Expr *p){
+ if( p->op==TK_STRING ){
+ p->op = TK_ID;
+ }else if( p->op==TK_COLLATE && p->pLeft->op==TK_STRING ){
+ p->pLeft->op = TK_ID;
+ }
+}
+
+/*
** Designate the PRIMARY KEY for the table. pList is a list of names
** of columns that form the primary key. If pList is NULL, then the
** most recently added column of the table is the primary key.
@@ -1317,6 +1341,7 @@ void sqlite3AddPrimaryKey(
for(i=0; i<nTerm; i++){
Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
assert( pCExpr!=0 );
+ sqlite3StringToId(pCExpr);
if( pCExpr->op==TK_ID ){
const char *zCName = pCExpr->u.zToken;
for(iCol=0; iCol<pTab->nCol; iCol++){
@@ -2856,30 +2881,6 @@ Index *sqlite3AllocateIndexObject(
}
/*
-** Backwards Compatibility Hack:
-**
-** Historical versions of SQLite accepted strings as column names in
-** indexes and PRIMARY KEY constraints and in UNIQUE constraints. Example:
-**
-** CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
-** CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
-**
-** This is goofy. But to preserve backwards compatibility we continue to
-** accept it. This routine does the necessary conversion. It converts
-** the expression given in its argument from a TK_STRING into a TK_ID
-** if the expression is just a TK_STRING with an optional COLLATE clause.
-** If the epxression is anything other than TK_STRING, the expression is
-** unchanged.
-*/
-static void sqlite3StringToId(Expr *p){
- if( p->op==TK_STRING ){
- p->op = TK_ID;
- }else if( p->op==TK_COLLATE && p->pLeft->op==TK_STRING ){
- p->pLeft->op = TK_ID;
- }
-}
-
-/*
** Create a new index for an SQL table. pName1.pName2 is the name of the index
** and pTblList is the name of the table that is to be indexed. Both will
** be NULL for a primary key or an index that is created to satisfy a