From: Rafael Kitover Date: Mon, 12 Apr 2010 22:56:58 +0000 (-0400) Subject: fix loading MySQL views on older MySQL versions (RT#47399) X-Git-Tag: 0.07000~72 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3de915bcc13aef740372ed107c3076f1a8062d3d;p=dbsrgits%2FDBIx-Class-Schema-Loader.git fix loading MySQL views on older MySQL versions (RT#47399) --- diff --git a/Changes b/Changes index a083d48..4253b04 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - fix loading MySQL views on older MySQL versions (RT#47399) + 0.06001 2010-04-10 01:31:12 - fix type info for MSSQL - fix MSSQL collation detection on freetds tds version 8.0 diff --git a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm index 60530b3..79515a7 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/mysql.pm @@ -37,9 +37,14 @@ sub _table_fk_info { my ($self, $table) = @_; my $dbh = $self->schema->storage->dbh; - my $table_def_ref = $dbh->selectrow_arrayref("SHOW CREATE TABLE `$table`") - or croak ("Cannot get table definition for $table"); - my $table_def = $table_def_ref->[1] || ''; + + local $dbh->{RaiseError} = 0; + local $dbh->{PrintError} = 0; + + my $table_def_ref = eval { $dbh->selectrow_arrayref("SHOW CREATE TABLE `$table`") }; + my $table_def = $table_def_ref->[1]; + + return [] if not $table_def; my $qt = qr/["`]/; diff --git a/t/11mysql_common.t b/t/11mysql_common.t index 01ce661..a895fcf 100644 --- a/t/11mysql_common.t +++ b/t/11mysql_common.t @@ -121,6 +121,30 @@ my $tester = dbixcsl_common_tests->new( "set('foo', 'bar', 'baz')" => { data_type => 'set', extra => { list => [qw/foo bar baz/] } }, }, + extra => { + create => [ + q{ + CREATE TABLE mysql_loader_test1 ( + id INT AUTO_INCREMENT PRIMARY KEY, + value varchar(100) + ) + }, + q{ + CREATE VIEW mysql_loader_test2 AS SELECT * FROM mysql_loader_test1 + }, + ], + pre_drop_ddl => [ 'DROP VIEW mysql_loader_test2', ], + drop => [ 'mysql_loader_test1', ], + count => 1, + run => sub { + my ($schema, $monikers, $classes) = @_; + + my $rsrc = $schema->resultset($monikers->{mysql_loader_test2})->result_source; + + is $rsrc->column_info('value')->{data_type}, 'varchar', + 'view introspected successfully'; + }, + }, ); if( !$dsn || !$user ) {