From: Peter Rabbitson Date: Thu, 24 Dec 2009 08:59:52 +0000 (+0000) Subject: Fix deployment_statements context sensitivity regression X-Git-Tag: v0.08116~81 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=30ae562b00055d0d5943022b1ffd6cc78736ea43;p=dbsrgits%2FDBIx-Class.git Fix deployment_statements context sensitivity regression --- diff --git a/Changes b/Changes index 569803f..cdebd93 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,7 @@ Revision history for DBIx::Class - Views without a view_definition will throw an exception when parsed by SQL::Translator::Parser::DBIx::Class - Schema POD improvement for dclone + - Fix regression in context sensitiveness of deployment_statements 0.08115 2009-12-10 09:02:00 (CST) - Real limit/offset support for MSSQL server (via Row_Number) diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index c11dbab..405041c 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -2373,10 +2373,19 @@ sub deployment_statements { data => $schema, ); - my $ret = $tr->translate - or $self->throw_exception( 'Unable to produce deployment statements: ' . $tr->error); + my @ret; + my $wa = wantarray; + if ($wa) { + @ret = $tr->translate; + } + else { + $ret[0] = $tr->translate; + } + + $self->throw_exception( 'Unable to produce deployment statements: ' . $tr->error) + unless (@ret && defined $ret[0]); - return $ret; + return $wa ? @ret : $ret[0]; } sub deploy { diff --git a/t/86sqlt.t b/t/86sqlt.t index 4327cef..e710ec1 100644 --- a/t/86sqlt.t +++ b/t/86sqlt.t @@ -14,6 +14,36 @@ BEGIN { my $schema = DBICTest->init_schema (no_deploy => 1); + +# Check deployment statements ctx sensitivity +{ + my $not_first_table_creation_re = qr/CREATE TABLE fourkeys_to_twokeys/; + + + my $statements = $schema->deployment_statements; + like ( + $statements, + $not_first_table_creation_re, + 'All create statements returned in 1 string in scalar ctx' + ); + + my @statements = $schema->deployment_statements; + cmp_ok (scalar @statements, '>', 1, 'Multiple statement lines in array ctx'); + + my $i = 0; + while ($i <= $#statements) { + last if $statements[$i] =~ $not_first_table_creation_re; + $i++; + } + + ok ( + ($i > 0) && ($i <= $#statements), + "Creation statement was found somewherere within array ($i)" + ); +} + + + # replace the sqlt calback with a custom version ading an index $schema->source('Track')->sqlt_deploy_callback(sub { my ($self, $sqlt_table) = @_;