From: Ken Youens-Clark Date: Tue, 25 Feb 2003 14:55:36 +0000 (+0000) Subject: Added some documentation to PG and MySQL; the "eofile" rule to MySQL. X-Git-Tag: v0.01~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=629b76f99c2e35e96a2a5cc4fc4b7dc552dab64f;p=dbsrgits%2FSQL-Translator.git Added some documentation to PG and MySQL; the "eofile" rule to MySQL. --- diff --git a/lib/SQL/Translator/Parser/MySQL.pm b/lib/SQL/Translator/Parser/MySQL.pm index ca93f2b..cd1b31b 100644 --- a/lib/SQL/Translator/Parser/MySQL.pm +++ b/lib/SQL/Translator/Parser/MySQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::MySQL; # ------------------------------------------------------------------- -# $Id: MySQL.pm,v 1.11 2003-02-15 02:30:59 kycl4rk Exp $ +# $Id: MySQL.pm,v 1.12 2003-02-25 14:55:35 kycl4rk Exp $ # ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark , # darren chamberlain , @@ -38,11 +38,92 @@ SQL::Translator::Parser::MySQL - parser for MySQL The grammar is influenced heavily by Tim Bunce's "mysql2ora" grammar. +Here's the word from the MySQL site +(http://www.mysql.com/doc/en/CREATE_TABLE.html): + + CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)] + [table_options] [select_statement] + + or + + CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name LIKE old_table_name; + + create_definition: + col_name type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] + [PRIMARY KEY] [reference_definition] + or PRIMARY KEY (index_col_name,...) + or KEY [index_name] (index_col_name,...) + or INDEX [index_name] (index_col_name,...) + or UNIQUE [INDEX] [index_name] (index_col_name,...) + or FULLTEXT [INDEX] [index_name] (index_col_name,...) + or [CONSTRAINT symbol] FOREIGN KEY [index_name] (index_col_name,...) + [reference_definition] + or CHECK (expr) + + type: + TINYINT[(length)] [UNSIGNED] [ZEROFILL] + or SMALLINT[(length)] [UNSIGNED] [ZEROFILL] + or MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL] + or INT[(length)] [UNSIGNED] [ZEROFILL] + or INTEGER[(length)] [UNSIGNED] [ZEROFILL] + or BIGINT[(length)] [UNSIGNED] [ZEROFILL] + or REAL[(length,decimals)] [UNSIGNED] [ZEROFILL] + or DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL] + or FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL] + or DECIMAL(length,decimals) [UNSIGNED] [ZEROFILL] + or NUMERIC(length,decimals) [UNSIGNED] [ZEROFILL] + or CHAR(length) [BINARY] + or VARCHAR(length) [BINARY] + or DATE + or TIME + or TIMESTAMP + or DATETIME + or TINYBLOB + or BLOB + or MEDIUMBLOB + or LONGBLOB + or TINYTEXT + or TEXT + or MEDIUMTEXT + or LONGTEXT + or ENUM(value1,value2,value3,...) + or SET(value1,value2,value3,...) + + index_col_name: + col_name [(length)] + + reference_definition: + REFERENCES tbl_name [(index_col_name,...)] + [MATCH FULL | MATCH PARTIAL] + [ON DELETE reference_option] + [ON UPDATE reference_option] + + reference_option: + RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT + + table_options: + TYPE = {BDB | HEAP | ISAM | InnoDB | MERGE | MRG_MYISAM | MYISAM } + or AUTO_INCREMENT = # + or AVG_ROW_LENGTH = # + or CHECKSUM = {0 | 1} + or COMMENT = "string" + or MAX_ROWS = # + or MIN_ROWS = # + or PACK_KEYS = {0 | 1 | DEFAULT} + or PASSWORD = "string" + or DELAY_KEY_WRITE = {0 | 1} + or ROW_FORMAT= { default | dynamic | fixed | compressed } + or RAID_TYPE= {1 | STRIPED | RAID0 } RAID_CHUNKS=# RAID_CHUNKSIZE=# + or UNION = (table_name,[table_name...]) + or INSERT_METHOD= {NO | FIRST | LAST } + or DATA DIRECTORY="absolute path to directory" + or INDEX DIRECTORY="absolute path to directory" + =cut use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.11 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.12 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -64,7 +145,15 @@ $GRAMMAR = q! { our ( %tables, $table_order ) } -startrule : statement(s) { \%tables } +# +# The "eofile" rule makes the parser fail if any "statement" rule +# fails. Otherwise, the first successful match by a "statement" +# won't cause the failure needed to know that the parse, as a whole, +# failed. -ky +# +startrule : statement(s) eofile { \%tables } + +eofile : /^\Z/ statement : comment | drop diff --git a/lib/SQL/Translator/Parser/PostgreSQL.pm b/lib/SQL/Translator/Parser/PostgreSQL.pm index 1796561..5b026e2 100644 --- a/lib/SQL/Translator/Parser/PostgreSQL.pm +++ b/lib/SQL/Translator/Parser/PostgreSQL.pm @@ -1,7 +1,7 @@ package SQL::Translator::Parser::PostgreSQL; # ------------------------------------------------------------------- -# $Id: PostgreSQL.pm,v 1.5 2003-02-25 05:01:35 kycl4rk Exp $ +# $Id: PostgreSQL.pm,v 1.6 2003-02-25 14:55:36 kycl4rk Exp $ # ------------------------------------------------------------------- # Copyright (C) 2003 Ken Y. Clark , # Allen Day , @@ -41,52 +41,54 @@ The grammar was started from the MySQL parsers. Here is the description from PostgreSQL: Table: - - CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name ( - { column_name data_type [ DEFAULT default_expr ] - [ column_constraint [, ... ] ] - | table_constraint } [, ... ] - ) - [ INHERITS ( parent_table [, ... ] ) ] - [ WITH OIDS | WITHOUT OIDS ] - - where column_constraint is: - - [ CONSTRAINT constraint_name ] - { NOT NULL | NULL | UNIQUE | PRIMARY KEY | - CHECK (expression) | - REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL ] - [ ON DELETE action ] [ ON UPDATE action ] } - [ DEFERRABLE | NOT DEFERRABLE ] - [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] - - and table_constraint is: - - [ CONSTRAINT constraint_name ] - { UNIQUE ( column_name [, ... ] ) | - PRIMARY KEY ( column_name [, ... ] ) | - CHECK ( expression ) | - FOREIGN KEY ( column_name [, ... ] ) - REFERENCES reftable [ ( refcolumn [, ... ] ) ] - [ MATCH FULL | MATCH PARTIAL ] - [ ON DELETE action ] [ ON UPDATE action ] } - [ DEFERRABLE | NOT DEFERRABLE ] - [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] +(http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=sql-createtable.html) + + CREATE [ [ LOCAL ] { TEMPORARY | TEMP } ] TABLE table_name ( + { column_name data_type [ DEFAULT default_expr ] + [ column_constraint [, ... ] ] + | table_constraint } [, ... ] + ) + [ INHERITS ( parent_table [, ... ] ) ] + [ WITH OIDS | WITHOUT OIDS ] + + where column_constraint is: + + [ CONSTRAINT constraint_name ] + { NOT NULL | NULL | UNIQUE | PRIMARY KEY | + CHECK (expression) | + REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL ] + [ ON DELETE action ] [ ON UPDATE action ] } + [ DEFERRABLE | NOT DEFERRABLE ] + [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] + + and table_constraint is: + + [ CONSTRAINT constraint_name ] + { UNIQUE ( column_name [, ... ] ) | + PRIMARY KEY ( column_name [, ... ] ) | + CHECK ( expression ) | + FOREIGN KEY ( column_name [, ... ] ) + REFERENCES reftable [ ( refcolumn [, ... ] ) ] + [ MATCH FULL | MATCH PARTIAL ] + [ ON DELETE action ] [ ON UPDATE action ] } + [ DEFERRABLE | NOT DEFERRABLE ] + [ INITIALLY DEFERRED | INITIALLY IMMEDIATE ] Index: +(http://www.postgresql.org/docs/view.php?version=7.3&idoc=1&file=sql-createindex.html) - CREATE [ UNIQUE ] INDEX index_name ON table - [ USING acc_method ] ( column [ ops_name ] [, ...] ) - [ WHERE predicate ] - CREATE [ UNIQUE ] INDEX index_name ON table - [ USING acc_method ] ( func_name( column [, ... ]) [ ops_name ] ) - [ WHERE predicate ] + CREATE [ UNIQUE ] INDEX index_name ON table + [ USING acc_method ] ( column [ ops_name ] [, ...] ) + [ WHERE predicate ] + CREATE [ UNIQUE ] INDEX index_name ON table + [ USING acc_method ] ( func_name( column [, ... ]) [ ops_name ] ) + [ WHERE predicate ] =cut use strict; use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ]; -$VERSION = sprintf "%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/; $DEBUG = 0 unless defined $DEBUG; use Data::Dumper; @@ -108,6 +110,12 @@ $GRAMMAR = q! { our ( %tables, $table_order ) } +# +# The "eofile" rule makes the parser fail if any "statement" rule +# fails. Otherwise, the first successful match by a "statement" +# won't cause the failure needed to know that the parse, as a whole, +# failed. -ky +# startrule : statement(s) eofile { \%tables } eofile : /^\Z/