Added a select section to the parser. This is to handle function calls that
Ben Faga [Thu, 20 Dec 2007 15:48:09 +0000 (15:48 +0000)]
may affect the tables during creation.

Added the setval function.  Unfortunately, nothing is being done with this
because the parser doesn't seem to handle sequences.

Skipping all COPY commands because they are not needed for schema creation.

Added a line each for revoking and granting permissions for a schema.  This
doesn't actually do anything with that information.

lib/SQL/Translator/Parser/PostgreSQL.pm

index dfe6997..9eafa5e 100644 (file)
@@ -154,6 +154,9 @@ statement : create
   | connect
   | update
   | set
+  | select
+  | copy
+  | readin_symbol
   | <error>
 
 connect : /^\s*\\\connect.*\n/
@@ -172,6 +175,9 @@ revoke : /revoke/i WORD(s /,/) /on/i TABLE(?) table_name /from/i name_with_opt_q
         }
     }
 
+revoke : /revoke/i WORD(s /,/) /on/i SCHEMA(?) schema_name /from/i name_with_opt_quotes(s /,/) ';'
+    { 1 }
+
 grant : /grant/i WORD(s /,/) /on/i TABLE(?) table_name /to/i name_with_opt_quotes(s /,/) ';'
     {
         my $table_info  = $item{'table_name'};
@@ -184,6 +190,9 @@ grant : /grant/i WORD(s /,/) /on/i TABLE(?) table_name /to/i name_with_opt_quote
         }
     }
 
+grant : /grant/i WORD(s /,/) /on/i SCHEMA(?) schema_name /to/i name_with_opt_quotes(s /,/) ';'
+    { 1 }
+
 drop : /drop/i /[^;]*/ ';'
 
 string :
@@ -462,6 +471,8 @@ table_name : schema_qualification(?) name_with_opt_quotes {
 
   schema_qualification : name_with_opt_quotes '.'
 
+schema_name : name_with_opt_quotes
+
 field_name : name_with_opt_quotes
 
 name_with_opt_quotes : double_quote(?) NAME double_quote(?) { $item[2] }
@@ -846,6 +857,24 @@ rename_column : /rename/i COLUMN(?)
 restrict_or_cascade : /restrict/i | 
     /cascade/i
 
+# Handle functions that can be called
+select : SELECT select_function ';' 
+    { 1 }
+
+# Read the setval function but don't do anything with it because this parser
+# isn't handling sequences
+select_function : schema_qualification(?) /setval/i '(' VALUE /,/ VALUE /,/ /(true|false)/i ')' 
+    { 1 }
+
+# Skipping all COPY commands
+copy : COPY WORD /[^;]+/ ';' { 1 }
+    { 1 }
+
+# The "\." allows reading in from STDIN but this isn't needed for schema
+# creation, so it is skipped.
+readin_symbol : '\.'
+    {1}
+
 #
 # End basically useless stuff. - ky
 #
@@ -906,10 +935,16 @@ COLUMN : /column/i
 
 TABLE : /table/i
 
+SCHEMA : /schema/i
+
 SEMICOLON : /\s*;\n?/
 
 SEQUENCE : /sequence/i
 
+SELECT : /select/i
+
+COPY : /copy/i
+
 INTEGER : /\d+/
 
 WORD : /\w+/