Add the ability to parse FOREIGN KEYs. Foreign keys are still ignored,

but at least they now do not cause a syntax error. (CVS 603)

FossilOrigin-Name: 6fdcee3c99e994ef3ab83a0cc57344cdb16210df
This commit is contained in:
drh
2002-06-02 18:19:00 +00:00
parent e4de1feb3e
commit 04738cb9ff
6 changed files with 117 additions and 15 deletions
+2 -2
View File
@@ -12,10 +12,10 @@
** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite.
**
** $Id: expr.c,v 1.67 2002/06/02 16:09:02 drh Exp $
** $Id: expr.c,v 1.68 2002/06/02 18:19:00 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
/*
** Construct a new expression node and return a pointer to it. Memory
+35 -1
View File
@@ -14,7 +14,7 @@
** the parser. Lemon will also generate a header file containing
** numeric codes for all of the tokens.
**
** @(#) $Id: parse.y,v 1.69 2002/05/24 16:14:15 drh Exp $
** @(#) $Id: parse.y,v 1.70 2002/06/02 18:19:00 drh Exp $
*/
%token_prefix TK_
%token_type {Token}
@@ -115,9 +115,11 @@ id(A) ::= AFTER(X). {A = X;}
id(A) ::= ASC(X). {A = X;}
id(A) ::= BEFORE(X). {A = X;}
id(A) ::= BEGIN(X). {A = X;}
id(A) ::= CASCADE(X). {A = X;}
id(A) ::= CLUSTER(X). {A = X;}
id(A) ::= CONFLICT(X). {A = X;}
id(A) ::= COPY(X). {A = X;}
id(A) ::= DEFERRED(X). {A = X;}
id(A) ::= DELIMITERS(X). {A = X;}
id(A) ::= DESC(X). {A = X;}
id(A) ::= EACH(X). {A = X;}
@@ -125,15 +127,21 @@ id(A) ::= END(X). {A = X;}
id(A) ::= EXPLAIN(X). {A = X;}
id(A) ::= FAIL(X). {A = X;}
id(A) ::= FOR(X). {A = X;}
id(A) ::= FULL(X). {A = X;}
id(A) ::= ID(X). {A = X;}
id(A) ::= IGNORE(X). {A = X;}
id(A) ::= IMMEDATE(X). {A = X;}
id(A) ::= INITIALLY(X). {A = X;}
id(A) ::= INSTEAD(X). {A = X;}
id(A) ::= MATCH(X). {A = X;}
id(A) ::= JOIN(X). {A = X;}
id(A) ::= KEY(X). {A = X;}
id(A) ::= OF(X). {A = X;}
id(A) ::= OFFSET(X). {A = X;}
id(A) ::= PARTIAL(X). {A = X;}
id(A) ::= PRAGMA(X). {A = X;}
id(A) ::= REPLACE(X). {A = X;}
id(A) ::= RESTRICT(X). {A = X;}
id(A) ::= ROW(X). {A = X;}
id(A) ::= STATEMENT(X). {A = X;}
id(A) ::= TEMP(X). {A = X;}
@@ -179,6 +187,29 @@ ccons ::= NOT NULL onconf(R). {sqliteAddNotNull(pParse, R);}
ccons ::= PRIMARY KEY sortorder onconf(R). {sqliteAddPrimaryKey(pParse,0,R);}
ccons ::= UNIQUE onconf(R). {sqliteCreateIndex(pParse,0,0,0,R,0,0);}
ccons ::= CHECK LP expr RP onconf.
ccons ::= references.
ccons ::= defer_subclause.
// A REFERENCES clause is parsed but the current implementation does not
// do anything with it.
//
references ::= REFERENCES ids LP idxlist RP refargs.
references ::= REFERENCES ids refargs.
refargs ::= .
refargs ::= refargs refarg.
refarg ::= MATCH FULL.
refarg ::= MATCH PARTIAL.
refarg ::= ON DELETE refact.
refarg ::= ON UPDATE refact.
refact ::= SET NULL.
refact ::= SET DEFAULT.
refact ::= CASCADE.
refact ::= RESTRICT.
defer_subclause ::= NOT DEFERRABLE init_deferred_pred_opt.
defer_subclause ::= DEFERRABLE init_deferred_pred_opt.
init_deferred_pred_opt ::= .
init_deferred_pred_opt ::= INITIALLY DEFERRED.
init_deferred_pred_opt ::= INITIALLY IMMEDIATE.
// For the time being, the only constraint we care about is the primary
// key and UNIQUE. Both create indices.
@@ -194,6 +225,9 @@ tcons ::= PRIMARY KEY LP idxlist(X) RP onconf(R).
tcons ::= UNIQUE LP idxlist(X) RP onconf(R).
{sqliteCreateIndex(pParse,0,0,X,R,0,0);}
tcons ::= CHECK expr onconf.
tcons ::= FOREIGN KEY LP idxlist RP references defer_subclause_opt.
defer_subclause_opt ::= .
defer_subclause_opt ::= defer_subclause.
// The following is a non-standard extension that allows us to declare the
// default behavior when there is a constraint conflict.
+12 -1
View File
@@ -15,7 +15,7 @@
** individual tokens and sends those tokens one-by-one over to the
** parser for analysis.
**
** $Id: tokenize.c,v 1.43 2002/05/24 16:14:15 drh Exp $
** $Id: tokenize.c,v 1.44 2002/06/02 18:19:00 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@@ -48,6 +48,7 @@ static Keyword aKeywordTable[] = {
{ "BEGIN", 0, TK_BEGIN, 0 },
{ "BETWEEN", 0, TK_BETWEEN, 0 },
{ "BY", 0, TK_BY, 0 },
{ "CASCADE", 0, TK_CASCADE, 0 },
{ "CASE", 0, TK_CASE, 0 },
{ "CHECK", 0, TK_CHECK, 0 },
{ "CLUSTER", 0, TK_CLUSTER, 0 },
@@ -57,6 +58,8 @@ static Keyword aKeywordTable[] = {
{ "COPY", 0, TK_COPY, 0 },
{ "CREATE", 0, TK_CREATE, 0 },
{ "DEFAULT", 0, TK_DEFAULT, 0 },
{ "DEFERRED", 0, TK_DEFERRED, 0 },
{ "DEFERRABLE", 0, TK_DEFERRABLE, 0 },
{ "DELETE", 0, TK_DELETE, 0 },
{ "DELIMITERS", 0, TK_DELIMITERS, 0 },
{ "DESC", 0, TK_DESC, 0 },
@@ -69,13 +72,17 @@ static Keyword aKeywordTable[] = {
{ "EXPLAIN", 0, TK_EXPLAIN, 0 },
{ "FAIL", 0, TK_FAIL, 0 },
{ "FOR", 0, TK_FOR, 0 },
{ "FOREIGN", 0, TK_FOREIGN, 0 },
{ "FROM", 0, TK_FROM, 0 },
{ "FULL", 0, TK_FULL, 0 },
{ "GLOB", 0, TK_GLOB, 0 },
{ "GROUP", 0, TK_GROUP, 0 },
{ "HAVING", 0, TK_HAVING, 0 },
{ "IGNORE", 0, TK_IGNORE, 0 },
{ "IMMEDIATE", 0, TK_IMMEDIATE, 0 },
{ "IN", 0, TK_IN, 0 },
{ "INDEX", 0, TK_INDEX, 0 },
{ "INITIALLY", 0, TK_INITIALLY, 0 },
{ "INSERT", 0, TK_INSERT, 0 },
{ "INSTEAD", 0, TK_INSTEAD, 0 },
{ "INTERSECT", 0, TK_INTERSECT, 0 },
@@ -86,6 +93,7 @@ static Keyword aKeywordTable[] = {
{ "KEY", 0, TK_KEY, 0 },
{ "LIKE", 0, TK_LIKE, 0 },
{ "LIMIT", 0, TK_LIMIT, 0 },
{ "MATCH", 0, TK_MATCH, 0 },
{ "NOT", 0, TK_NOT, 0 },
{ "NOTNULL", 0, TK_NOTNULL, 0 },
{ "NULL", 0, TK_NULL, 0 },
@@ -94,9 +102,12 @@ static Keyword aKeywordTable[] = {
{ "ON", 0, TK_ON, 0 },
{ "OR", 0, TK_OR, 0 },
{ "ORDER", 0, TK_ORDER, 0 },
{ "PARTIAL", 0, TK_PARTIAL, 0 },
{ "PRAGMA", 0, TK_PRAGMA, 0 },
{ "PRIMARY", 0, TK_PRIMARY, 0 },
{ "REFERENCES", 0, TK_REFERENCES, 0 },
{ "REPLACE", 0, TK_REPLACE, 0 },
{ "RESTRICT", 0, TK_RESTRICT, 0 },
{ "ROLLBACK", 0, TK_ROLLBACK, 0 },
{ "ROW", 0, TK_ROW, 0 },
{ "SELECT", 0, TK_SELECT, 0 },