Awesome non-quoted numeric default patch by Stephen Clouse
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / SQLServer.pm
index 2abd91e..38cf64b 100644 (file)
@@ -1,9 +1,7 @@
 package SQL::Translator::Parser::SQLServer;
 
 # -------------------------------------------------------------------
-# $Id$
-# -------------------------------------------------------------------
-# Copyright (C) 2002-4 SQLFairy Authors
+# Copyright (C) 2002-2009 SQLFairy Authors
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License as
@@ -39,7 +37,7 @@ should probably be considered a work in progress.
 use strict;
 
 use vars qw[ $DEBUG $VERSION $GRAMMAR @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision$ =~ /(\d+)\.(\d+)/;
+$VERSION = '1.59';
 $DEBUG   = 0 unless defined $DEBUG;
 
 use Data::Dumper;
@@ -76,6 +74,7 @@ statement : create_table
     | create_index
     | create_constraint
     | comment
+    | drop
     | use
     | setuser
     | if
@@ -134,6 +133,12 @@ comment_end : m#\s*\*\/#
 
 comment_middle : m{([^*]+|\*(?!/))*}
 
+drop : if_exists(?) /drop/i tbl_drop END_STATEMENT
+
+tbl_drop : /table/i NAME
+
+if_exists : /if exists/i '(' /select/i 'name' /from/i 'sysobjects' /[^\)]+/ ')'
+
 #
 # Create table.
 #
@@ -176,12 +181,17 @@ create_table : /create/i /table/i ident '(' create_def(s /,/) ')' lock(?) on_sys
         }
     }
 
-create_constraint : /create/i constraint 
+create_constraint : /create/i constraint
     {
         @table_comments = ();
         push @{ $tables{ $item[2]{'table'} }{'constraints'} }, $item[2];
     }
 
+create_constraint : /alter/i /table/i ident /add/i foreign_key_constraint END_STATEMENT
+    {
+        push @{ $tables{ $item[3]{name} }{constraints} }, $item[5];
+    }
+
 create_index : /create/i index
     {
         @table_comments = ();
@@ -313,6 +323,8 @@ default_val : /default/i /null/i
     { $return = 'null' }
        | /default/i /'[^']*'/ 
     { $item[2]=~ s/'//g; $return = $item[2] }
+       | /default/i WORD
+    { $return = $item[2] }
 
 auto_inc : /identity/i { 1 }
 
@@ -340,6 +352,16 @@ foreign_key_constraint : /constraint/i index_name(?) /foreign/i /key/i parens_fi
         } 
     }
 
+unique_constraint : /constraint/i index_name(?) /unique/i parens_field_list
+    {
+        $return = { 
+            supertype => 'constraint',
+            type      => 'unique',
+            name      => $item[2][0],
+            fields    => $item[4],
+        }
+    }
+
 unique_constraint : /unique/i clustered(?) INDEX(?) index_name(?) on_table(?) parens_field_list
     { 
         $return = { 
@@ -376,7 +398,7 @@ on_table : /on/i table_name
 on_system : /on/i /system/i
     { $return = 1 }
 
-index : clustered(?) INDEX index_name(?) on_table(?) parens_field_list ';'
+index : clustered(?) INDEX index_name(?) on_table(?) parens_field_list END_STATEMENT
     { 
         $return = { 
             supertype => 'index',