parser for parsing create table statements
A parser should be created using PLY.
http://
Steps to take:
1) Split out the classes that compose statements into a separate file (/helpers/
2) Create a new statement node class CreateTableStat
3) Create a new test case file: /tests/
4) Create new test cases for all of the following BAD syntaxes:
CREATE TABLE 1; // bad identifier
CREATE TABLE t1 (); // no field list
CREATE TABLE t1 (f1 NOT NULL); // missing column type
CREATE TABLE t1 (INT NOT NULL); // missing column identifier
CREATE TABLE t1 (t1.field1 INT NOT NULL); // column identifier cannot be qualified
5) Create new test cases for all of the following GOOD syntaxes:
CREATE TABLE t1 (field1 INT NOT NULL);
CREATE TABLE IF NOT EXISTS t1 (field1 INT NOT NULL);
CREATE TEMPORARY TABLE t1 (field1 INT NOT NULL);
CREATE TEMPORARY TABLE IF NOT EXISTS t1 (field1 INT NOT NULL);
CREATE TABLE test.t1 (field1 INT NOT NULL); // Note schema name qualifying table name...
CREATE TABLE t1 (field1 INT NOT NULL, PRIMARY KEY field1);
// Use of the REFERENCES clause... all of these are valid
CREATE TABLE t1 (t1_pk INT NOT NULL PRIMARY KEY, t1_fk INT NOT NULL FOREIGN KEY (field2) REFERENCES t2 (t2_pk);
CREATE TABLE t1 (t1_pk INT NOT NULL PRIMARY KEY, t1_fk INT NOT NULL CONSTRAINT c_fk_t2 FOREIGN KEY fk_t2 (field2) REFERENCES t2 (t2_pk); // Shows optional constraint name for the foreign key
CREATE TABLE t1 (t1_pk INT NOT NULL PRIMARY KEY, t1_fk INT NOT NULL FOREIGN KEY fk_t2 (field2) REFERENCES t2 (t2_pk); // Shows optional name for the index on the foreign key
CREATE TABLE t1 (t1_pk INT NOT NULL PRIMARY KEY, t1_fk INT NOT NULL FOREIGN KEY (field2) REFERENCES t2 (t2_pk) ON UPDATE CASCADE; // Shows optional ON UPDATE clause
CREATE TABLE t1 (t1_pk INT NOT NULL PRIMARY KEY, t1_fk INT NOT NULL FOREIGN KEY (field2) REFERENCES t2 (t2_pk) ON DELETE CASCADE; // Shows optional ON DELETE clause