@parts = grep { $_ !~ /^(BEGIN|BEGIN TRANSACTION|COMMIT)/m } @parts;
## Some cleanup
@parts = map {
- $_=~s/;\s*?$comment.*?$//; ## trim off ending comments
- $_=~s/^\s*//g; ## trim leading whitespace
- $_=~s/\s*$//g; ## trim ending whitespace
+ $_=~s/;\s*?$comment.*?$//m; ## trim off ending comments
+ $_=~s/^\s*//mg; ## trim leading whitespace
+ $_=~s/\s*$//mg; ## trim ending whitespace
$_;
} @parts;
push @lines, @parts;
sub _split_line_into_statements {
my ($self, $line) = @_;
-
- my $deliminator=qr{;|$};
- my $quote=qr{['"]};
- my $quoted=qr{$quote.+?$quote};
- my $block=qr{$quoted|.};
- my @parts = ($line=~m/$block*?$deliminator/xg);
-
- return @parts;
-}
-
-sub _split_line_into_statements_new {
- my ($self, $line) = @_;
- my $deliminator=qr{;|$};
+ my $deliminator=qr/;|$/;
my $maybe_quoted = qr/
"[^"]+"
|
'[^']+'
|
.+?(?=$deliminator)
- /;
+ /x;
return ($line=~m/$maybe_quoted*?$deliminator/g);
}
-use Test::More tests => 16;
+use Test::More tests => 17;
use Test::Exception;
use lib qw(t/lib);
ok my $fh = $schema->storage->_normalize_fh_from_args(qw/t share basic.sql/),
'Got good filehandle';
-ok my @lines = $schema->storage->_normalize_lines(<$fh>), 'Got some lines';
+my $storage = $schema->storage;
+
+is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc")],["aaa;", "bbb;", "ccc", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements("aaa;'bb1;bb2';ccc")],["aaa;", "'bb1;bb2';", "ccc", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements(qq[aaa;"bb1;bb2";ccc])],["aaa;", '"bb1;bb2";', "ccc", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc;")],["aaa;", "bbb;", "ccc;", ""],
+ "Correctly split";
+
+is_deeply [$storage->_split_line_into_statements("insert into artist(artistid,name) values(888888,'xxx;yyy;zzz');")],
+ ["insert into artist(artistid,name) values(888888,'xxx;yyy;zzz');"],
+ "Correctly split";
+
+ok my @lines = $storage->_normalize_lines(<$fh>), 'Got some lines';
is_deeply [@lines], [
"CREATE TABLE cd_to_producer (",
");",
], 'Got expected lines';
-ok my @statements = $schema->storage->_normalize_statements_from_lines(@lines),
+ok my @statements = $storage->_normalize_statements_from_lines(@lines),
'Got Statements';
is_deeply [@statements], [
], 'Got expect Lines';
lives_ok {
- $schema->storage->_execute_single_statement('insert into artist( artistid,name) values( 777777,"--commented" );');
+ $storage->_execute_single_statement('insert into artist( artistid,name) values( 777777,"--commented" );');
} 'executed statement';
-ok $schema->storage->run_file_against_storage(qw/t share simple.sql/), 'executed the simple';
-ok $schema->storage->run_file_against_storage(qw/t share killer.sql/), 'executed the killer';
-
-my $storage = $schema->storage;
-
-is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc")],["aaa;", "bbb;", "ccc", ""],
- "Correctly split";
-
-is_deeply [$storage->_split_line_into_statements("aaa;'bb1;bb2';ccc")],["aaa;", "'bb1;bb2';", "ccc", ""],
- "Correctly split";
-
-is_deeply [$storage->_split_line_into_statements(qq[aaa;"bb1;bb2";ccc])],["aaa;", '"bb1;bb2";', "ccc", ""],
- "Correctly split";
-
-is_deeply [$storage->_split_line_into_statements("aaa;bbb;ccc;")],["aaa;", "bbb;", "ccc;", ""],
- "Correctly split";
+ok $storage->run_file_against_storage(qw/t share simple.sql/), 'executed the simple';
+ok $storage->run_file_against_storage(qw/t share killer.sql/), 'executed the killer';
use Data::Dump qw/dump/;
-warn dump $schema->storage->_split_line_into_statements_new("aaa;bbb;ccc");
+warn dump $storage->_split_line_into_statements("insert into artist(artistid,name) values(888888,'xxx;yyy;zzz');");