1 package DBIx::Class::Schema::Loader::DBI::MSSQL;
5 use base 'DBIx::Class::Schema::Loader::DBI';
6 use Carp::Clan qw/^DBIx::Class/;
9 our $VERSION = '0.04999_06';
13 DBIx::Class::Schema::Loader::DBI::MSSQL - DBIx::Class::Schema::Loader::DBI MSSQL Implementation.
18 use base qw/DBIx::Class::Schema::Loader/;
20 __PACKAGE__->loader_options( debug => 1 );
26 See L<DBIx::Class::Schema::Loader::Base>.
33 $self->next::method(@_);
34 $self->{db_schema} ||= 'dbo';
38 my ($self, $table) = @_;
39 my $dbh = $self->schema->storage->dbh;
40 my $sth = $dbh->prepare(qq{sp_pkeys '$table'});
45 while (my $row = $sth->fetchrow_hashref) {
46 push @keydata, lc $row->{COLUMN_NAME};
53 my ($self, $table) = @_;
55 my ($local_cols, $remote_cols, $remote_table, @rels);
56 my $dbh = $self->schema->storage->dbh;
57 my $sth = $dbh->prepare(qq{sp_fkeys \@FKTABLE_NAME = '$table'});
60 while (my $row = $sth->fetchrow_hashref) {
61 my $fk = $row->{FK_NAME};
62 push @{$local_cols->{$fk}}, lc $row->{FKCOLUMN_NAME};
63 push @{$remote_cols->{$fk}}, lc $row->{PKCOLUMN_NAME};
64 $remote_table->{$fk} = $row->{PKTABLE_NAME};
67 foreach my $fk (keys %$remote_table) {
69 local_columns => \@{$local_cols->{$fk}},
70 remote_columns => \@{$remote_cols->{$fk}},
71 remote_table => $remote_table->{$fk},
78 sub _table_uniq_info {
79 my ($self, $table) = @_;
81 my $dbh = $self->schema->storage->dbh;
82 my $sth = $dbh->prepare(qq{SELECT CCU.CONSTRAINT_NAME, CCU.COLUMN_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU
83 JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC ON (CCU.CONSTRAINT_NAME = TC.CONSTRAINT_NAME)
84 JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU ON (CCU.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND CCU.COLUMN_NAME = KCU.COLUMN_NAME)
85 WHERE CCU.TABLE_NAME = '$table' AND CONSTRAINT_TYPE = 'UNIQUE' ORDER BY KCU.ORDINAL_POSITION});
88 while (my $row = $sth->fetchrow_hashref) {
89 my $name = lc $row->{CONSTRAINT_NAME};
90 my $col = lc $row->{COLUMN_NAME};
91 push @{$constraints->{$name}}, $col;
94 my @uniqs = map { [ $_ => $constraints->{$_} ] } keys %$constraints;
98 sub _extra_column_info {
99 my ($self, $info) = @_;
102 my ($table, $column) = @$info{qw/TABLE_NAME COLUMN_NAME/};
104 my $dbh = $self->schema->storage->dbh;
105 my $sth = $dbh->prepare(qq{SELECT COLUMN_NAME
106 FROM INFORMATION_SCHEMA.COLUMNS
107 WHERE COLUMNPROPERTY(object_id('$table', 'U'), '$column', 'IsIdentity') = 1 AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column'
111 if ($sth->fetchrow_array) {
112 $extra_info{is_auto_increment} = 1;
121 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
122 L<DBIx::Class::Schema::Loader::DBI>
126 Justin Hunter C<justin.d.hunter@gmail.com>