better _tables_list for MSSQL
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader / DBI / MSSQL.pm
index f3fb9aa..bfc2053 100644 (file)
@@ -2,52 +2,43 @@ package DBIx::Class::Schema::Loader::DBI::MSSQL;
 
 use strict;
 use warnings;
-use base qw/
-    DBIx::Class::Schema::Loader::DBI
-    DBIx::Class::Schema::Loader::DBI::Sybase::Common
-/;
+use base 'DBIx::Class::Schema::Loader::DBI::Sybase::Common';
 use Carp::Clan qw/^DBIx::Class/;
 use Class::C3;
 
-our $VERSION = '0.04999_12';
+our $VERSION = '0.05003';
 
 =head1 NAME
 
 DBIx::Class::Schema::Loader::DBI::MSSQL - DBIx::Class::Schema::Loader::DBI MSSQL Implementation.
 
-=head1 SYNOPSIS
-
-  package My::Schema;
-  use base qw/DBIx::Class::Schema::Loader/;
-
-  __PACKAGE__->loader_options( debug => 1 );
-
-  1;
-
 =head1 DESCRIPTION
 
-See L<DBIx::Class::Schema::Loader::Base>.
+Base driver for Microsoft SQL Server, used by
+L<DBIx::Class::Schema::Loader::DBI::Sybase::Microsoft_SQL_Server> for support
+via L<DBD::Sybase> and
+L<DBIx::Class::Schema::Loader::DBI::ODBC::Microsoft_SQL_Server> for support via
+L<DBD::ODBC>.
+
+See L<DBIx::Class::Schema::Loader> and L<DBIx::Class::Schema::Loader::Base> for
+usage information.
 
 =cut
 
-sub _setup {
+sub _tables_list {
     my $self = shift;
 
-    $self->next::method(@_);
-    $self->{db_schema} ||= $self->_build_db_schema;
-    $self->_set_quote_char_and_name_sep;
-}
+    my $dbh = $self->schema->storage->dbh;
+    my $sth = $dbh->prepare(<<'EOF');
+select t.table_name
+from information_schema.tables t
+where t.table_schema = ?
+EOF
+    $sth->execute($self->db_schema);
 
-# remove 'IDENTITY' from column data_type
-sub _columns_info_for {
-    my $self   = shift;
-    my $result = $self->next::method(@_);
+    my @tables = map lc $_, map @$_, @{ $sth->fetchall_arrayref };
 
-    for my $col (keys %$result) {
-        $result->{$col}->{data_type} =~ s/\s* identity \s*//ix;
-    }
-
-    return $result;
+    return $self->_filter_tables(@tables);
 }
 
 sub _table_pk_info {
@@ -112,11 +103,9 @@ sub _table_uniq_info {
 }
 
 sub _extra_column_info {
-    my ($self, $info) = @_;
+    my ($self, $table, $column, $info, $dbi_info) = @_;
     my %extra_info;
 
-    my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
-
     my $dbh = $self->schema->storage->dbh;
     my $sth = $dbh->prepare(qq{
         SELECT COLUMN_NAME 
@@ -155,6 +144,8 @@ sub _extra_column_info {
 
 =head1 SEE ALSO
 
+L<DBIx::Class::Schema::Loader::DBI::Sybase::Microsoft_SQL_Server>,
+L<DBIx::Class::Schema::Loader::DBI::ODBC::Microsoft_SQL_Server>,
 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
 L<DBIx::Class::Schema::Loader::DBI>