aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--manifest16
-rw-r--r--manifest.uuid2
-rw-r--r--src/build.c49
-rw-r--r--test/index3.test15
4 files changed, 49 insertions, 33 deletions
diff --git a/manifest b/manifest
index b9fdab8d2..fc7f03f6b 100644
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\smutex\soperations\sto\stest\scode\sin\stest3.c\sto\savoid\striggering\sassert()\sfailures\sin\scertain\sconfigurations.
-D 2015-10-30T20:54:25.598
+C If\sa\stable-constraint\sPRIMARY\sKEY\slists\sa\ssingle\scolumn\sin\ssingle-quotes\sand\nthat\scolumn\shas\stype\sINTEGER,\sthen\smake\sthat\scolumn\san\sinteger\sprimary\skey,\nfor\shistorical\scompatibility.\s\sFix\sfor\sticket\s[ac661962a2aeab3c331].
+D 2015-11-01T21:19:13.044
F Makefile.in 4469ed8b02a9934fea9503d791165367d19db2f7
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc 702d3e98f3afc6587a78481257f3c4c900efc3a4
@@ -285,7 +285,7 @@ F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79
F src/btree.c 77343aac89c50bb5e06cbca3ace8c057c14de57c
F src/btree.h b512723e4f27d7ba16b4b985cdecdb82c0f6d0c0
F src/btreeInt.h 8177c9ab90d772d6d2c6c517e05bed774b7c92c0
-F src/build.c d6162335d690396dfc5c4bd59e8b2b0c14ba6285
+F src/build.c ca574d33ffb1763cfd2979383f4d507095bfbe19
F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0
F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f
F src/ctime.c 509ef9c64d1321f42448f111da86400b1799218a
@@ -784,7 +784,7 @@ F test/incrvacuum3.test 75256fb1377e7c39ef2de62bfc42bbff67be295a
F test/incrvacuum_ioerr.test 6ae2f783424e47a0033304808fe27789cf93e635
F test/index.test fe3c7a1aad82af92623747e9c3f3aa94ccd51238
F test/index2.test f835d5e13ca163bd78c4459ca15fd2e4ed487407
-F test/index3.test fa3e49bbaa4f38091c9c742e36a1abe67c4ef1fc
+F test/index3.test 81bc47890b8abfb181bc35f8d10b56c069803386
F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6
F test/index5.test 8621491915800ec274609e42e02a97d67e9b13e7
F test/index6.test 7102ec371414c42dfb1d5ca37eb4519aa9edc23a
@@ -1397,7 +1397,7 @@ F tool/vdbe_profile.tcl 246d0da094856d72d2c12efec03250d71639d19f
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 7565b046ff939e8310631397a4526fbd98b99aaf
-R 614298574df997c982bceb820bb362b3
-U dan
-Z ee268c45e17adbdf740dc7b91893f898
+P 9f19420b0a79dff65fc3a9d548f4b3fc4955f9f9
+R 84796f7face623f0835cebd2cbfc3bf7
+U drh
+Z 6a5992b91acc5a2e6d8856fb63b43984
diff --git a/manifest.uuid b/manifest.uuid
index 4eeefb872..d01007477 100644
--- a/manifest.uuid
+++ b/manifest.uuid
@@ -1 +1 @@
-9f19420b0a79dff65fc3a9d548f4b3fc4955f9f9 \ No newline at end of file
+db319a035feeb6f8fcd04f90fb10cd4b06e68184 \ No newline at end of file
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
diff --git a/test/index3.test b/test/index3.test
index 1d90de1b9..4c00a852d 100644
--- a/test/index3.test
+++ b/test/index3.test
@@ -62,6 +62,21 @@ do_execsql_test index3-2.2eqp {
EXPLAIN QUERY PLAN
SELECT a FROM t1 WHERE b='ab005xy' COLLATE nocase;
} {/USING INDEX/}
+do_execsql_test index3-2.3 {
+ SELECT name FROM sqlite_master WHERE tbl_name='t1' ORDER BY name
+} {sqlite_autoindex_t1_1 sqlite_autoindex_t1_2 t1 t1c t1d}
+do_execsql_test index3-2.4 {
+ CREATE TABLE t2a(a integer, b, PRIMARY KEY(a));
+ CREATE TABLE t2b("a" integer, b, PRIMARY KEY("a"));
+ CREATE TABLE t2c([a] integer, b, PRIMARY KEY([a]));
+ CREATE TABLE t2d('a' integer, b, PRIMARY KEY('a'));
+}
+do_execsql_test index3-2.5 {
+ SELECT name FROM sqlite_master WHERE tbl_name LIKE 't2_' ORDER BY name
+} {t2a t2b t2c t2d}
+
+
+
# This test corrupts the database file so it must be the last test