1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#!/usr/bin/env perl
use strict;
use warnings;
use SQL::SplitStatement;
use Test::More tests => 6;
my $sql = <<'SQL';
/* Multiline
C-Style
Comment! */
CREATE TABLE t1 (a, b); --inline comment; with semicolons;
-- standalone comment
CREATE TABLE t2 (a, b);
-- standalone comment w/ trailing spaces
CREATE TABLE t3 (a, b) /* inlined C-style comments... */
/* ... before terminator */ ;
CREATE TABLE last;
-- Trailing standalone comment
SQL
my $splitter;
my @statements;
$splitter = SQL::SplitStatement->new;
@statements = $splitter->split($sql);
cmp_ok (
scalar(@statements), '==', 4,
'number of atomic statements w/o comments'
);
isnt (
join( '', @statements ), $sql,
q[SQL code don't rebuild w/o comments]
);
$splitter = SQL::SplitStatement->new({
keep_comments => 1
});
@statements = $splitter->split($sql);
# We have an extra statement made solely by comments.
# It's not recognized as an empty statement, that's right.
cmp_ok (
scalar(@statements), '==', 5,
'number of atomic statements w/ comments'
);
isnt (
join( '', @statements ), $sql,
q[SQL code don't rebuild only w/ comments]
);
$splitter = SQL::SplitStatement->new({
keep_terminator => 1,
keep_extra_spaces => 1,
keep_comments => 1
});
@statements = $splitter->split($sql);
cmp_ok (
scalar(@statements), '==', 5,
'number of atomic statements w/ comments'
);
is (
join( '', @statements ), $sql,
q[SQL code rebuilt w/ comments, semicolon and spaces]
);
|