| 1 | package DBIx::Class::Loader::ADO; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw( DBIx::Class::Loader::Generic ); | ||
| 5 | |||
| 6 | use Carp; | ||
| 7 | |||
| 8 | our $VERSION = '0.07'; | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | DBIx::Class::Loader::ADO - DBIx::Class::Loader ADO Implementation. | ||
| 13 | |||
| 14 | =head1 SYNOPSIS | ||
| 15 | |||
| 16 | use DBIx::Class::Loader; | ||
| 17 | |||
| 18 | # $loader is a DBIx::Class::Loader::ADO | ||
| 19 | my $loader = DBIx::Class::Loader->new( | ||
| 20 | dsn => "dbi:ADO:$DSN", | ||
| 21 | namespace => "Data", | ||
| 22 | ); | ||
| 23 | my $class = $loader->find_class('film'); # $class => Data::Film | ||
| 24 | my $obj = $class->retrieve(1); | ||
| 25 | |||
| 26 | =head1 DESCRIPTION | ||
| 27 | |||
| 28 | See L<DBIx::Class::Loader>. | ||
| 29 | |||
| 30 | =head1 INSTALLATION | ||
| 31 | |||
| 32 | To install this module via Module::Build: | ||
| 33 | |||
| 34 | perl Build.PL | ||
| 35 | ./Build # or `perl Build` | ||
| 36 | ./Build test # or `perl Build test` | ||
| 37 | ./Build install # or `perl Build install` | ||
| 38 | |||
| 39 | To install this module via ExtUtils::MakeMaker: | ||
| 40 | |||
| 41 | perl Makefile.PL | ||
| 42 | make | ||
| 43 | make test | ||
| 44 | make install | ||
| 45 | |||
| 46 | =cut | ||
| 47 | |||
| 48 | sub _db_classes{ | ||
| 49 | return qw( DBIx::Class::PK::Auto::MSSQL ); | ||
| 50 | } | ||
| 51 | |||
| 52 | sub _relationships { | ||
| 53 | my $self = shift; | ||
| 54 | my @tables = $self->tables; | ||
| 55 | my $dbh = $self->find_class( $tables[ 0 ] )->storage->dbh; | ||
| 56 | my $sth = $dbh->foreign_key_info( undef, undef, undef, undef, undef, undef ); | ||
| 57 | |||
| 58 | # needs testing and a way to detect relationships | ||
| 59 | # other than one to many | ||
| 60 | while ( my $row = $sth->fetch ) { | ||
| 61 | my( @args ) = ( lc $row->[ 2 ], $row->[ 3 ], lc $row->[ 6 ], $row->[ 7 ] ); | ||
| 62 | eval { $self->_belongs_to_many( @args ) }; | ||
| 63 | warn qq/\# belongs_to_many failed "$@"\n\n/ if $@ && $self->debug; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | sub _tables { | ||
| 68 | my $self = shift; | ||
| 69 | my $dbh = $self->{ storage }->dbh; | ||
| 70 | my $sth = $dbh->table_info( undef, undef, undef, "TABLE" ); | ||
| 71 | |||
| 72 | my @tables; | ||
| 73 | while ( my $row = $sth->fetch ) { | ||
| 74 | push @tables, $row->[ 2 ]; | ||
| 75 | } | ||
| 76 | |||
| 77 | return @tables; | ||
| 78 | } | ||
| 79 | |||
| 80 | sub _table_info { | ||
| 81 | my( $self, $table ) = @_; | ||
| 82 | my $dbh = $self->{ storage }->dbh; | ||
| 83 | my $sth = $dbh->column_info( undef, undef, $table, undef ); | ||
| 84 | |||
| 85 | my( @cols, @pri ); | ||
| 86 | while( my $row = $sth->fetch ) { | ||
| 87 | push @cols, $row->[ 3 ]; | ||
| 88 | } | ||
| 89 | |||
| 90 | $sth = $dbh->primary_key_info( undef, undef, $table ); | ||
| 91 | while( my $row = $sth->fetch ) { | ||
| 92 | push @pri, $row->[ 3 ]; | ||
| 93 | } | ||
| 94 | |||
| 95 | croak("$table has no primary key") unless @pri; | ||
| 96 | |||
| 97 | return( \@cols, \@pri ); | ||
| 98 | } | ||
| 99 | |||
| 100 | =head1 SEE ALSO | ||
| 101 | |||
| 102 | =over 4 | ||
| 103 | |||
| 104 | =item * L<DBIx::Class::Loader> | ||
| 105 | |||
| 106 | =item * L<DBD::ADO> | ||
| 107 | |||
| 108 | =back | ||
| 109 | |||
| 110 | =head1 AUTHOR | ||
| 111 | |||
| 112 | =over 4 | ||
| 113 | |||
| 114 | =item * Brian Cassidy E<lt>bricas@cpan.orgE<gt> | ||
| 115 | |||
| 116 | =back | ||
| 117 | |||
| 118 | =head1 COPYRIGHT AND LICENSE | ||
| 119 | |||
| 120 | Copyright 2007 by Brian Cassidy | ||
| 121 | |||
| 122 | This library is free software; you can redistribute it and/or modify | ||
| 123 | it under the same terms as Perl itself. | ||
| 124 | |||
| 125 | =cut | ||
| 126 | |||
| 127 | 1; |