/ Check-in [12bb31dd]
Login

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

Overview
Comment:Merge the table constraint parser fixes from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | winrt
Files: files | file ages | folders
SHA1:12bb31dd6f0d8544406710d6f02f0b7c0fe6c537
User & Date: drh 2012-05-10 13:03:28
Context
2012-05-17
21:04
Merge updates from trunk. check-in: 224c65e4 user: mistachkin tags: winrt
2012-05-10
13:03
Merge the table constraint parser fixes from trunk. check-in: 12bb31dd user: drh tags: winrt
2012-05-08
11:17
Further changes to constraint parsing to support legacy syntax. check-in: 38bf90af user: drh tags: trunk
2012-05-07
22:29
Merge parser adjustments from the trunk. check-in: 0d8b920b user: mistachkin tags: winrt
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/parse.y.

   335    335   defer_subclause(A) ::= NOT DEFERRABLE init_deferred_pred_opt.     {A = 0;}
   336    336   defer_subclause(A) ::= DEFERRABLE init_deferred_pred_opt(X).      {A = X;}
   337    337   %type init_deferred_pred_opt {int}
   338    338   init_deferred_pred_opt(A) ::= .                       {A = 0;}
   339    339   init_deferred_pred_opt(A) ::= INITIALLY DEFERRED.     {A = 1;}
   340    340   init_deferred_pred_opt(A) ::= INITIALLY IMMEDIATE.    {A = 0;}
   341    341   
   342         -conslist_opt(A) ::= .                   {A.n = 0; A.z = 0;}
   343         -conslist_opt(A) ::= COMMA(X) conslist.  {A = X;}
   344         -conslist ::= conslist COMMA cname tcons cname.
   345         -conslist ::= cname tcons cname.
          342  +conslist_opt(A) ::= .                         {A.n = 0; A.z = 0;}
          343  +conslist_opt(A) ::= COMMA(X) conslist cname.  {A = X;}
          344  +conslist ::= conslist COMMA cname tcons.
          345  +conslist ::= conslist cname tcons.
          346  +conslist ::= cname tcons.
   346    347   cname ::= .                      {pParse->constraintName.n = 0;}
   347    348   cname ::= CONSTRAINT nm(X).      {pParse->constraintName = X;}
   348    349   tcons ::= PRIMARY KEY LP idxlist(X) autoinc(I) RP onconf(R).
   349    350                                    {sqlite3AddPrimaryKey(pParse,X,R,I,0);}
   350    351   tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
   351    352                                    {sqlite3CreateIndex(pParse,0,0,0,X,R,0,0,0,0);}
   352    353   tcons ::= CHECK LP expr(E) RP onconf.

Added test/schema5.test.

            1  +# 2010 September 28
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +#
           12  +# This file checks corner cases in the CREATE TABLE syntax to make
           13  +# sure that legacy syntax (syntax that is disallowed according to the
           14  +# syntax diagrams) is still accepted, so that older databases that use
           15  +# that syntax can still be read.
           16  +#
           17  +
           18  +set testdir [file dirname $argv0]
           19  +source $testdir/tester.tcl
           20  +
           21  +# Table constraints should be separated by commas, but they do not have
           22  +# to be.
           23  +#
           24  +do_test schema5-1.1 {
           25  +  db eval {
           26  +    CREATE TABLE t1(a,b,c, PRIMARY KEY(a) UNIQUE (a) CONSTRAINT one);
           27  +    INSERT INTO t1 VALUES(1,2,3);
           28  +    SELECT * FROM t1;
           29  +  }
           30  +} {1 2 3}
           31  +do_test schema5-1.2 {
           32  +  catchsql {INSERT INTO t1 VALUES(1,3,4);}
           33  +} {1 {column a is not unique}}
           34  +do_test schema5-1.3 {
           35  +  db eval {
           36  +    DROP TABLE t1;
           37  +    CREATE TABLE t1(a,b,c,
           38  +        CONSTRAINT one PRIMARY KEY(a) CONSTRAINT two CHECK(b<10) UNIQUE(b)
           39  +        CONSTRAINT three
           40  +    );
           41  +    INSERT INTO t1 VALUES(1,2,3);
           42  +    SELECT * FROM t1;
           43  +  }
           44  +} {1 2 3}
           45  +do_test schema5-1.4 {
           46  +  catchsql {INSERT INTO t1 VALUES(10,11,12);}
           47  +} {1 {constraint two failed}}
           48  +
           49  +
           50  +    
           51  +
           52  +finish_test