From: Johannes Plunien Date: Fri, 13 Feb 2009 10:27:36 +0000 (+0000) Subject: Refactored and re-added r5041: Split sql statements for deploy only if SQLT::Producer... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=11d8c7817105d31daa87e1753073bacb633c24de;p=dbsrgits%2FDBIx-Class-Historic.git Refactored and re-added r5041: Split sql statements for deploy only if SQLT::Producer returned a scalar containing all statements to be executed --- diff --git a/Changes b/Changes index 85f6076..9d7887b 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,9 @@ Revision history for DBIx::Class - Possible to set locale in IC::DateTime extra => {} config - Calling the accessor of a belongs_to when the foreign_key was NULL and the row was not stored would unexpectedly fail (groditi) + - Split sql statements for deploy only if SQLT::Producer returned a scalar + containing all statements to be executed + 0.08099_06 2009-01-23 07:30:00 (UTC) - Allow a scalarref to be supplied to the 'from' resultset attribute - Classes submitted as result_class for a resultsource are now diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 7bb576c..dd4dc63 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1775,22 +1775,32 @@ sub deployment_statements { sub deploy { my ($self, $schema, $type, $sqltargs, $dir) = @_; - foreach my $statement ( $self->deployment_statements($schema, $type, undef, $dir, { no_comments => 1, %{ $sqltargs || {} } } ) ) { - foreach my $line ( split(";\n", $statement)) { - next if($line =~ /^--/); - next if(!$line); -# next if($line =~ /^DROP/m); - next if($line =~ /^BEGIN TRANSACTION/m); - next if($line =~ /^COMMIT/m); - next if $line =~ /^\s+$/; # skip whitespace only - $self->_query_start($line); - eval { - $self->dbh->do($line); # shouldn't be using ->dbh ? - }; - if ($@) { - warn qq{$@ (running "${line}")}; - } - $self->_query_end($line); + my $deploy = sub { + my $line = shift; + return if($line =~ /^--/); + return if(!$line); + # next if($line =~ /^DROP/m); + return if($line =~ /^BEGIN TRANSACTION/m); + return if($line =~ /^COMMIT/m); + return if $line =~ /^\s+$/; # skip whitespace only + $self->_query_start($line); + eval { + $self->dbh->do($line); # shouldn't be using ->dbh ? + }; + if ($@) { + warn qq{$@ (running "${line}")}; + } + $self->_query_end($line); + }; + my @statements = $self->deployment_statements($schema, $type, undef, $dir, { no_comments => 1, %{ $sqltargs || {} } } ); + if (@statements > 1) { + foreach my $statement (@statements) { + $deploy->( $statement ); + } + } + elsif (@statements == 1) { + foreach my $line ( split(";\n", $statements[0])) { + $deploy->( $line ); } } }