File: 02-trigger.t

package info (click to toggle)
libdbix-runsql-perl 0.26-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 248 kB
  • sloc: perl: 825; sql: 26; makefile: 10
file content (51 lines) | stat: -rw-r--r-- 1,305 bytes parent folder | download
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
#!perl -w
use strict;
use Test2::V0 '-no_srand';

use DBIx::RunSQL;

my $can_run = eval {
    require DBD::SQLite;
    1
};

if (not $can_run) {
    plan skip_all => "SQLite not installed";
}

plan tests => 2;

my $sql = do { local (@ARGV,$/) = 't/trigger.sql'; <> };
my @statements;
while( defined( my $frag = DBIx::RunSQL->split_sql( $sql ))) {
    push @statements, $frag;
}
is \@statements, [
  '-- This commented-out statement will not get passed through',
  "-- SECRET PRAGMA #foo will get passed through with the next statement\r\n"
  . "create table test (\r\n"
  . "    id integer unique not null,\r\n"
  . "    descr text default '',\r\n"
  . "    ts text\r\n"
  . ")",
    "CREATE TRIGGER trg_test_1 AFTER INSERT ON test\r\n"
  . "     BEGIN\r\n"
  . "      UPDATE test SET ts = DATETIME('NOW')  WHERE rowid = new.rowid;\n"
  . "END",
    "CREATE TRIGGER trg_test_2 AFTER INSERT ON test BEGIN\r\n"
  . "      UPDATE test SET ts = DATETIME('NOW')  WHERE rowid = new.rowid;\n"
  . "END",
], "We split the statements in the expected fashion";

my $lives = eval {
    my $test_dbh = DBIx::RunSQL->create(
        dsn     => 'dbi:SQLite:dbname=:memory:',
        sql     => 't/trigger.sql',
        #verbose => 1,
    );
    1;
};
my $err = $@;
ok $lives, "We can parse triggers"
    or diag $err;