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
|
use lib 't';
BEGIN {
# to handle systems with no installed Test module
# we include the t dir (where a copy of Test.pm is located)
# as a fallback
eval { require Test; };
use Test;
use DBStagTest;
plan tests => 4;
}
use DBIx::DBStag;
use DBI;
use Data::Stag;
use FileHandle;
use strict;
drop();
my $f = "t/data/bond.el";
my $spydata = Data::Stag->parse($f);
my $dbh = dbh();
my $ddl = $dbh->autoddl($spydata);
$dbh->do($ddl);
my @kids = $spydata->kids;
foreach (@kids) {
$dbh->storenode($_);
}
$dbh->add_template(agent =>
q/
SELECT *
FROM agent
NATURAL JOIN mission
NATURAL JOIN mission_gizmo
NATURAL JOIN mission_to_person
NATURAL JOIN person
WHERE lastname = ?
/);
$dbh->add_template(agent_by_mission =>
q/
SELECT *
FROM agent
NATURAL JOIN mission
NATURAL JOIN mission_gizmo
NATURAL JOIN mission_to_person
NATURAL JOIN person
WHERE agent_id IN
(SELECT agent_id
FROM MISSION
WHERE codename = ?)
/);
# use 'agent' template
my $bond = $dbh->fetch_agent("Bond");
$bond = $dbh->fetch_agent("mission.codename" => "goldfinger");
# use 'agent_by_mission' template
$bond = $dbh->fetch_agent_by_mission(codename => "goldfinger");
$dbh->disconnect;
|