from 0542ec57 and 4c2b30d6)
- Fix problems with M.A.D. under CGI::SpeedyCGI (RT#65131)
- Better error handling when prepare() fails silently
+ - Fixes skipped lines when a comment is followed by a statement
+ when deploying a schema via sql file
0.08127 2011-01-19 16:40 (UTC)
* New Features / Changes
michaelr: Michael Reddick <michael.reddick@gmail.com>
+milki: Jonathan Chu <milki@rescomp.berkeley.edu>
+
ned: Neil de Carteret
nigel: Nigel Metheringham <nigelm@cpan.org>
my $filename = $schema->ddl_filename($type, $version, $dir);
if(-f $filename)
{
+ # FIXME replace this block when a proper sane sql parser is available
my $file;
open($file, "<$filename")
or $self->throw_exception("Can't open $filename ($!)");
return wantarray ? @ret : $ret[0];
}
+# FIXME deploy() currently does not accurately report sql errors
+# Will always return true while errors are warned
sub deploy {
my ($self, $schema, $type, $sqltargs, $dir) = @_;
my $deploy = sub {
my $line = shift;
- return if($line =~ /^--/);
return if(!$line);
+ return if($line =~ /^--/);
# next if($line =~ /^DROP/m);
return if($line =~ /^BEGIN TRANSACTION/m);
return if($line =~ /^COMMIT/m);
}
}
elsif (@statements == 1) {
- foreach my $line ( split(";\n", $statements[0])) {
+ # split on single line comments and end of statements
+ foreach my $line ( split(/\s*--.*\n|;\n/, $statements[0])) {
$deploy->( $line );
}
}
--- /dev/null
+--
+-- This table line should not be skipped
+--
+CREATE TABLE artist (
+ artistid INTEGER PRIMARY KEY NOT NULL,
+ name varchar(100),
+ rank integer NOT NULL DEFAULT 13,
+ charfield char(10)
+);
+
+CREATE INDEX artist_name_hookidx ON artist (name); -- This line should error if artist was not parsed correctly
use warnings;
use Test::More;
+use Test::Exception;
use lib qw(t/lib);
use DBICTest;
use File::Spec;
use Path::Class qw/dir/;
use File::Path qw/make_path remove_tree/;
+
+lives_ok( sub {
+ my $parse_schema = DBICTest->init_schema(no_deploy => 1);
+ $parse_schema->deploy({},'t/lib/test_deploy');
+ $parse_schema->resultset("Artist")->all();
+}, 'artist table deployed correctly' );
+
my $schema = DBICTest->init_schema();
my $var = dir (qw| t var create_ddl_dir |);