Downgrade global version - highest version in 9002 on cpan is 1.58 - thus go with...
[dbsrgits/SQL-Translator.git] / lib / SQL / Translator / Parser / DBI / SQLServer.pm
index cb2eb4e..267e6f8 100644 (file)
@@ -1,9 +1,7 @@
 package SQL::Translator::Parser::DBI::SQLServer;
 
 # -------------------------------------------------------------------
-# $Id: SQLServer.pm,v 1.1 2005-06-27 19:00:19 duality72 Exp $
-# -------------------------------------------------------------------
-# 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
@@ -40,7 +38,7 @@ use SQL::Translator::Schema;
 use Data::Dumper;
 
 use vars qw[ $DEBUG $VERSION @EXPORT_OK ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/;
+$VERSION = '1.59';
 $DEBUG   = 0 unless defined $DEBUG;
 
 no strict 'refs';
@@ -141,7 +139,7 @@ SELECT o.name, colid,c.text
   FROM syscomments c
   JOIN sysobjects o
     ON c.id = o.id
- WHERE o.type ='P'
+ WHERE o.type in ('P', 'FN', 'TF', 'IF')
 }
 );
 
@@ -224,8 +222,10 @@ $table_info->{TABLE_TYPE},
                                          ) || die $table->error;
                 $f->is_nullable($c->{NULLABLE} == 1);
                 $f->is_auto_increment($is_auto_increment);
-                $c->{COLUMN_DEF} =~ s#\('?(.*?)'?\)#$1#;
-                $f->default_value($c->{COLUMN_DEF}) if defined $c->{COLUMN_DEF};
+                if ( defined $c->{COLUMN_DEF}) {
+                       $c->{COLUMN_DEF} =~ s#\('?(.*?)'?\)#$1#;
+                       $f->default_value($c->{COLUMN_DEF});
+                }
             }
 
             # add in primary key
@@ -243,7 +243,7 @@ $table_info->{TABLE_NAME}", 'COLUMN_NAME');
             }
 
             # add in foreign keys
-            my $h = $dbh->selectall_hashref("sp_fkeys NULL,
+            $h = $dbh->selectall_hashref("sp_fkeys NULL,
 \@fktable_name = '$table_info->{TABLE_NAME}'", 'FK_NAME');
                        foreach my $fk ( values %{$h} ) {
                                my $constraint = $table->add_constraint( name => $fk->{FK_NAME},
@@ -295,6 +295,7 @@ $_->{INDEX_NAME},
         } elsif ($table_info->{TABLE_TYPE} eq 'VIEW') {
                next if $table_info->{TABLE_NAME} eq 'sysconstraints'
                        || $table_info->{TABLE_NAME} eq 'syssegments';
+               next if !$stuff->{view}->{$table_info->{TABLE_NAME}}->{text};
             my $view =  $schema->add_view(
                                           name =>
 $table_info->{TABLE_NAME},
@@ -320,6 +321,7 @@ $table_info->{TABLE_NAME},
     }
 
     foreach my $p (values %{$stuff->{procedures}}) {
+       next if !$p->{text};
         my $proc = $schema->add_procedure(
                                name      => $p->{name},
                                owner     => $p->{PROCEDURE_OWNER},