/ Check-in [db319a03]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: db319a035feeb6f8fcd04f90fb10cd4b06e68184
User & Date: drh 2015-11-01 21:19:13
Context
2015-11-02
18:32
Add the "--jobs N" option to the releasetest.tcl script to allow tests to be run in parallel by N processes. N defaults to 1. check-in: 3d29f912 user: dan tags: mp-releasetest
15:08
On unix, if a file is opened via a symlink, create, read and write journal and wal files based on the name of the actual db file, not the symlink. check-in: 6d5ce3ed user: dan tags: trunk
2015-11-01
21:35
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]. check-in: dab0e607 user: drh tags: branch-3.9
21:19
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]. check-in: db319a03 user: drh tags: trunk
2015-10-30
20:54
Add mutex operations to test code in test3.c to avoid triggering assert() failures in certain configurations. check-in: 9f19420b user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

  1266   1266         sqlite3DbFree(db, pCol->zDflt);
  1267   1267         pCol->zDflt = sqlite3DbStrNDup(db, (char*)pSpan->zStart,
  1268   1268                                        (int)(pSpan->zEnd - pSpan->zStart));
  1269   1269       }
  1270   1270     }
  1271   1271     sqlite3ExprDelete(db, pSpan->pExpr);
  1272   1272   }
         1273  +
         1274  +/*
         1275  +** Backwards Compatibility Hack:
         1276  +** 
         1277  +** Historical versions of SQLite accepted strings as column names in
         1278  +** indexes and PRIMARY KEY constraints and in UNIQUE constraints.  Example:
         1279  +**
         1280  +**     CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
         1281  +**     CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
         1282  +**
         1283  +** This is goofy.  But to preserve backwards compatibility we continue to
         1284  +** accept it.  This routine does the necessary conversion.  It converts
         1285  +** the expression given in its argument from a TK_STRING into a TK_ID
         1286  +** if the expression is just a TK_STRING with an optional COLLATE clause.
         1287  +** If the epxression is anything other than TK_STRING, the expression is
         1288  +** unchanged.
         1289  +*/
         1290  +static void sqlite3StringToId(Expr *p){
         1291  +  if( p->op==TK_STRING ){
         1292  +    p->op = TK_ID;
         1293  +  }else if( p->op==TK_COLLATE && p->pLeft->op==TK_STRING ){
         1294  +    p->pLeft->op = TK_ID;
         1295  +  }
         1296  +}
  1273   1297   
  1274   1298   /*
  1275   1299   ** Designate the PRIMARY KEY for the table.  pList is a list of names 
  1276   1300   ** of columns that form the primary key.  If pList is NULL, then the
  1277   1301   ** most recently added column of the table is the primary key.
  1278   1302   **
  1279   1303   ** A table can have at most one primary key.  If the table already has
................................................................................
  1313   1337       zType = pTab->aCol[iCol].zType;
  1314   1338       nTerm = 1;
  1315   1339     }else{
  1316   1340       nTerm = pList->nExpr;
  1317   1341       for(i=0; i<nTerm; i++){
  1318   1342         Expr *pCExpr = sqlite3ExprSkipCollate(pList->a[i].pExpr);
  1319   1343         assert( pCExpr!=0 );
         1344  +      sqlite3StringToId(pCExpr);
  1320   1345         if( pCExpr->op==TK_ID ){
  1321   1346           const char *zCName = pCExpr->u.zToken;
  1322   1347           for(iCol=0; iCol<pTab->nCol; iCol++){
  1323   1348             if( sqlite3StrICmp(zCName, pTab->aCol[iCol].zName)==0 ){
  1324   1349               pTab->aCol[iCol].colFlags |= COLFLAG_PRIMKEY;
  1325   1350               zType = pTab->aCol[iCol].zType;
  1326   1351               break;
................................................................................
  2851   2876       p->nColumn = nCol;
  2852   2877       p->nKeyCol = nCol - 1;
  2853   2878       *ppExtra = ((char*)p) + nByte;
  2854   2879     }
  2855   2880     return p;
  2856   2881   }
  2857   2882   
  2858         -/*
  2859         -** Backwards Compatibility Hack:
  2860         -** 
  2861         -** Historical versions of SQLite accepted strings as column names in
  2862         -** indexes and PRIMARY KEY constraints and in UNIQUE constraints.  Example:
  2863         -**
  2864         -**     CREATE TABLE xyz(a,b,c,d,e,PRIMARY KEY('a'),UNIQUE('b','c' COLLATE trim)
  2865         -**     CREATE INDEX abc ON xyz('c','d' DESC,'e' COLLATE nocase DESC);
  2866         -**
  2867         -** This is goofy.  But to preserve backwards compatibility we continue to
  2868         -** accept it.  This routine does the necessary conversion.  It converts
  2869         -** the expression given in its argument from a TK_STRING into a TK_ID
  2870         -** if the expression is just a TK_STRING with an optional COLLATE clause.
  2871         -** If the epxression is anything other than TK_STRING, the expression is
  2872         -** unchanged.
  2873         -*/
  2874         -static void sqlite3StringToId(Expr *p){
  2875         -  if( p->op==TK_STRING ){
  2876         -    p->op = TK_ID;
  2877         -  }else if( p->op==TK_COLLATE && p->pLeft->op==TK_STRING ){
  2878         -    p->pLeft->op = TK_ID;
  2879         -  }
  2880         -}
  2881         -
  2882   2883   /*
  2883   2884   ** Create a new index for an SQL table.  pName1.pName2 is the name of the index 
  2884   2885   ** and pTblList is the name of the table that is to be indexed.  Both will 
  2885   2886   ** be NULL for a primary key or an index that is created to satisfy a
  2886   2887   ** UNIQUE constraint.  If pTable and pIndex are NULL, use pParse->pNewTable
  2887   2888   ** as the table to be indexed.  pParse->pNewTable is a table that is
  2888   2889   ** currently being constructed by a CREATE TABLE statement.

Changes to test/index3.test.

    58     58   do_execsql_test index3-2.2 {
    59     59     SELECT a FROM t1 WHERE b='ab005xy' COLLATE nocase;
    60     60   } {5}
    61     61   do_execsql_test index3-2.2eqp {
    62     62     EXPLAIN QUERY PLAN
    63     63     SELECT a FROM t1 WHERE b='ab005xy' COLLATE nocase;
    64     64   } {/USING INDEX/}
           65  +do_execsql_test index3-2.3 {
           66  +  SELECT name FROM sqlite_master WHERE tbl_name='t1' ORDER BY name
           67  +} {sqlite_autoindex_t1_1 sqlite_autoindex_t1_2 t1 t1c t1d}
           68  +do_execsql_test index3-2.4 {
           69  +  CREATE TABLE t2a(a integer, b, PRIMARY KEY(a));
           70  +  CREATE TABLE t2b("a" integer, b, PRIMARY KEY("a"));
           71  +  CREATE TABLE t2c([a] integer, b, PRIMARY KEY([a]));
           72  +  CREATE TABLE t2d('a' integer, b, PRIMARY KEY('a'));
           73  +}
           74  +do_execsql_test index3-2.5 {
           75  +  SELECT name FROM sqlite_master WHERE tbl_name LIKE 't2_' ORDER BY name
           76  +} {t2a t2b t2c t2d}
           77  + 
           78  +
           79  +
    65     80   
    66     81   
    67     82   # This test corrupts the database file so it must be the last test
    68     83   # in the series.
    69     84   #
    70     85   do_test index3-99.1 {
    71     86     execsql {