[Bast-commits] r8247 - in branches/DBIx-Class-Schema-Loader/current:
lib/DBIx/Class/Schema/Loader lib/DBIx/Class/Schema/Loader/DBI
lib/DBIx/Class/Schema/Loader/DBI/Sybase
t/backcompat/0.04006/lib t/lib
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Thu Jan 7 08:28:45 GMT 2010
Author: caelum
Date: 2010-01-07 08:28:44 +0000 (Thu, 07 Jan 2010)
New Revision: 8247
Modified:
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm
branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/lib/dbixcsl_common_tests.pm
branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
Log:
clean up the query from table stuff
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm 2010-01-07 01:26:26 UTC (rev 8246)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/MSSQL.pm 2010-01-07 08:28:44 UTC (rev 8247)
@@ -38,36 +38,6 @@
$self->_set_quote_char_and_name_sep;
}
-# drop bad tables when constructing list
-sub _tables_list {
- my $self = shift;
-
- my @tables = $self->next::method(@_);
- my @filtered_tables;
-
- for my $table (@tables) {
- my $full_quoted_table;
- if($self->{db_schema}) {
- $full_quoted_table = $self->{db_schema} . $self->{_namesep} .
- $self->_quote_table_name($table);
- } else {
- $full_quoted_table = $self->_quote_table_name($table);
- }
- my $dbh = $self->schema->storage->dbh;
- my $sth = $dbh->prepare($self->schema->storage->sql_maker
- ->select(\$full_quoted_table, undef, \'1 = 0'));
- eval { $sth->execute };
- if (not $@) {
- push @filtered_tables, $table;
- }
- else {
- warn "Bad table or view '$table', ignoring.\n";
- }
- }
-
- return @filtered_tables;
-}
-
# remove 'IDENTITY' from column data_type
sub _columns_info_for {
my $self = shift;
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm 2010-01-07 01:26:26 UTC (rev 8246)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Oracle.pm 2010-01-07 08:28:44 UTC (rev 8247)
@@ -46,15 +46,10 @@
}
}
-
-sub _table_columns {
+sub _table_as_sql {
my ($self, $table) = @_;
- my $dbh = $self->schema->storage->dbh;
-
- my $sth = $dbh->prepare($self->schema->storage->sql_maker->select($table, undef, \'1 = 0'));
- $sth->execute;
- return \@{$sth->{NAME_lc}};
+ return $self->_quote_table_name($table);
}
sub _tables_list {
@@ -75,7 +70,7 @@
push @tables, $1
if $table =~ /\A(\w+)\z/;
}
- return @tables;
+ return $self->_filter_tables(@tables);
}
sub _table_uniq_info {
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm 2010-01-07 01:26:26 UTC (rev 8246)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/Sybase/Microsoft_SQL_Server.pm 2010-01-07 08:28:44 UTC (rev 8247)
@@ -30,7 +30,7 @@
my $dbh = $self->schema->storage->dbh;
my @tables = $dbh->tables(undef, $self->db_schema, $table, $type);
- return @tables;
+ return $self->_filter_tables(@tables);
}
=head1 SEE ALSO
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm 2010-01-07 01:26:26 UTC (rev 8246)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm 2010-01-07 08:28:44 UTC (rev 8247)
@@ -77,7 +77,7 @@
if(!exists($self->{_cache}->{_mysql_keys}->{$table})) {
my %keydata;
my $dbh = $self->schema->storage->dbh;
- my $sth = $dbh->prepare("SHOW INDEX FROM `$table`");
+ my $sth = $dbh->prepare('SHOW INDEX FROM '.$self->_table_as_sql($table));
$sth->execute;
while(my $row = $sth->fetchrow_hashref) {
next if $row->{Non_unique};
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm 2010-01-07 01:26:26 UTC (rev 8246)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/DBI.pm 2010-01-07 08:28:44 UTC (rev 8247)
@@ -99,9 +99,29 @@
}
s/$qt//g for @tables;
- return @tables;
+ return $self->_filter_tables(@tables);
}
+# ignore bad tables and views
+sub _filter_tables {
+ my ($self, @tables) = @_;
+
+ my @filtered_tables;
+
+ for my $table (@tables) {
+ my $sth = $self->_sth_for($table, undef, \'1 = 0');
+ eval { $sth->execute };
+ if (not $@) {
+ push @filtered_tables, $table;
+ }
+ else {
+ warn "Bad table or view '$table', ignoring: $@\n";
+ }
+ }
+
+ return @filtered_tables;
+}
+
=head2 load
We override L<DBIx::Class::Schema::Loader::Base/load> here to hook in our localized settings for C<$dbh> error handling.
@@ -116,12 +136,9 @@
$self->next::method(@_);
}
-# Returns an arrayref of column names
-sub _table_columns {
+sub _table_as_sql {
my ($self, $table) = @_;
- my $dbh = $self->schema->storage->dbh;
-
if($self->{db_schema}) {
$table = $self->{db_schema} . $self->{_namesep} .
$self->_quote_table_name($table);
@@ -129,7 +146,25 @@
$table = $self->_quote_table_name($table);
}
- my $sth = $dbh->prepare($self->schema->storage->sql_maker->select(\$table, undef, \'1 = 0'));
+ return $table;
+}
+
+sub _sth_for {
+ my ($self, $table, $fields, $where) = @_;
+
+ my $dbh = $self->schema->storage->dbh;
+
+ my $sth = $dbh->prepare($self->schema->storage->sql_maker
+ ->select(\$self->_table_as_sql($table), $fields, $where));
+
+ return $sth;
+}
+
+# Returns an arrayref of column names
+sub _table_columns {
+ my ($self, $table) = @_;
+
+ my $sth = $self->_sth_for($table, undef, \'1 = 0');
$sth->execute;
my $retval = \@{$sth->{NAME_lc}};
$sth->finish;
@@ -252,11 +287,8 @@
return \%result if !$@ && scalar keys %result;
}
- if($self->db_schema) {
- $table = $self->db_schema . $self->{_namesep} . $table;
- }
my %result;
- my $sth = $dbh->prepare($self->schema->storage->sql_maker->select($table, undef, \'1 = 0'));
+ my $sth = $self->_sth_for($table, undef, \'1 = 0');
$sth->execute;
my @columns = @{$sth->{NAME_lc}};
for my $i ( 0 .. $#columns ){
Modified: branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/lib/dbixcsl_common_tests.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/lib/dbixcsl_common_tests.pm 2010-01-07 01:26:26 UTC (rev 8246)
+++ branches/DBIx-Class-Schema-Loader/current/t/backcompat/0.04006/lib/dbixcsl_common_tests.pm 2010-01-07 08:28:44 UTC (rev 8247)
@@ -89,6 +89,7 @@
my $warn_count = 0;
$warn_count++ if grep /ResultSetManager/, @loader_warnings;
$warn_count++ if grep /Dynamic schema detected/, @loader_warnings;
+ $warn_count++ for grep /^Bad table or view/, @loader_warnings;
if($self->{skip_rels}) {
is(scalar(@loader_warnings), $warn_count)
Modified: branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm 2010-01-07 01:26:26 UTC (rev 8246)
+++ branches/DBIx-Class-Schema-Loader/current/t/lib/dbixcsl_common_tests.pm 2010-01-07 08:28:44 UTC (rev 8247)
@@ -137,6 +137,8 @@
my $warn_count = 2;
$warn_count++ if grep /ResultSetManager/, @loader_warnings;
+ $warn_count++ for grep /^Bad table or view/, @loader_warnings;
+
if($self->{skip_rels}) {
SKIP: {
is(scalar(@loader_warnings), $warn_count, "No loader warnings")
More information about the Bast-commits
mailing list