File: stag-bulkload.pl

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 (99 lines) | stat: -rwxr-xr-x 1,826 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/usr/local/bin/perl -w

# POD docs at end

use strict;

use Carp;
use Data::Stag qw(:all);
use DBIx::DBStag::SimpleBulkload;
use Getopt::Long;

my $parser = "";
my $handler = "";
my $debug;
my $help;
my $loadrecord;
GetOptions(
           "help|h"=>\$help,
           "parser|format|p=s" => \$parser,
           "handler|writer|w=s" => \$handler,
           "loadrecord|l=s" => \$loadrecord,
           "debug"=>\$debug,
          );
if ($help) {
    system("perldoc $0");
    exit 0;
}


my @files = @ARGV;
foreach my $fn (@files) {

    $handler = DBIx::DBStag::SimpleBulkload->new;
    $handler->load_on_event($loadrecord) if $loadrecord;
    my @pargs = (-file=>$fn, -format=>$parser, -handler=>$handler);
    if ($fn eq '-') {
	if (!$parser) {
	    $parser = 'xml';
	}
	@pargs = (-format=>$parser, -handler=>$handler, -fh=>\*STDIN);
    }
    my $tree = 
      Data::Stag->parse(@pargs);

}
exit 0;

__END__

=head1 NAME 

stag-bulkload.pl - creates bulkload SQL for input data

=head1 SYNOPSIS

  # convert XML to IText
  stag-bulkload.pl -l person file1.xml file2.xml

  # use a custom parser/generator and a custom writer/generator
  stag-bulkload.pl -p MyMod::MyParser file.txt

=head1 DESCRIPTION

Creates bulkload SQL statements for an input file

Works only with certain kinds of schemas, where the FK relations make
a tree (not a graph); i.e. the only FKs are to the parent

You do not need a connection to the DB

It is of no use for incremental loading - it assumes integer surrogate
promary keys and starts these from 1

=head1 ARGUMENTS

=over

=item -p|parser FORMAT

FORMAT is one of xml, sxpr or itext, or the name of a perl module

xml assumed as default

=item -l|loadrecord NODE

adds a COMMIT statement after the INSERTs for this node

=back


=head1 SEE ALSO

L<Data::Stag>

L<DBIx::DBStag>


=cut