File: autoddl.t

package info (click to toggle)
libdbix-dbstag-perl 0.12-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,420 kB
  • sloc: perl: 6,152; sql: 588; xml: 221; lisp: 59; makefile: 20
file content (56 lines) | stat: -rw-r--r-- 1,498 bytes parent folder | download | duplicates (3)
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
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 => 2;
}
use DBIx::DBStag;
use DBI;
use Data::Stag;
use FileHandle;
use strict;

drop();
my $f = "t/data/game.el";
my $data = Data::Stag->parse($f);
$data->where('seq',
	     sub {
		 my $s = shift;
		 my @dbxref = $s->get_dbxref;
		 $s->unset_dbxref;
		 foreach (@dbxref) {
		     my $sx = Data::Stag->new(seq_dbxref=>[$_]);
		     $s->add_seq_dbxref($sx);
		 }
	     });
$data->where('annot',
	     sub {
		 my $s = shift;
		 my @dbxref = $s->get_dbxref;
		 $s->unset_dbxref;
		 foreach (@dbxref) {
		     my $sx = Data::Stag->new(annot_dbxref=>[$_]);
		     $s->add_annot_dbxref($sx);
		 }
	     });
print $data->sxpr;
my $dbh = dbh();
my $ddl = $dbh->autoddl($data, [qw(seq_dbxref annot_dbxref)]);
print $ddl;

$dbh->do($ddl);
$dbh->storenode($data);
my $out = $dbh->selectall_stag('SELECT * FROM game NATURAL JOIN seq NATURAL JOIN seq_dbxref NATURAL JOIN dbxref');
print $out->sxpr;
my @dbxrefs = $out->get("game/seq/seq_dbxref/dbxref");
ok(@dbxrefs ==1);
ok($dbxrefs[0]->get_db eq 'x');

$out = $dbh->selectall_stag('SELECT * FROM annot NATURAL JOIN fset NATURAL JOIN fspan NATURAL JOIN game NATURAL JOIN seq NATURAL JOIN seq_dbxref NATURAL JOIN dbxref USE NESTING (annotset (annot (game(seq(seq_dbxref(dbxref)))) (fset(fspan))))');

$dbh->disconnect;