[Bast-commits] r6901 -
branches/DBIx-Class-Schema-Loader/mssql_tweaks/lib/DBIx/Class/Schema/Loader/DBI
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Wed Jul 1 04:03:13 GMT 2009
Author: caelum
Date: 2009-07-01 04:03:12 +0000 (Wed, 01 Jul 2009)
New Revision: 6901
Modified:
branches/DBIx-Class-Schema-Loader/mssql_tweaks/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm
Log:
determine db_schema for mssql if not supplied
Modified: branches/DBIx-Class-Schema-Loader/mssql_tweaks/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/mssql_tweaks/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm 2009-06-30 20:27:54 UTC (rev 6900)
+++ branches/DBIx-Class-Schema-Loader/mssql_tweaks/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm 2009-07-01 04:03:12 UTC (rev 6901)
@@ -41,9 +41,38 @@
my $self = shift;
$self->next::method(@_);
- $self->{db_schema} ||= 'dbo';
+
+ $self->{db_schema} ||= $self->_determine_db_schema;
}
+sub _determine_db_schema {
+ my $self = shift;
+ my $dbh = $self->schema->storage->dbh;
+
+ my $test_table = "_loader_test_$$";
+ $dbh->do("create table $test_table (id integer)");
+
+ my $db_schema = 'dbo'; # default
+
+ eval {
+ my $sth = $dbh->prepare('sp_tables');
+ $sth->execute;
+ while (my $row = $sth->fetchrow_hashref) {
+ next unless $row->{TABLE_NAME} eq $test_table;
+
+ $db_schema = $row->{TABLE_OWNER};
+ last;
+ }
+ $sth->finish;
+ };
+ my $exception = $@;
+ $dbh->do("drop table $test_table");
+ croak $exception if $exception;
+
+ return $db_schema;
+}
+
+
# DBD::Sybase doesn't implement get_info properly
#sub _build_quoter { [qw/[ ]/] }
sub _build_quoter { '"' }
More information about the Bast-commits
mailing list