line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::XML_RDB; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
620
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %XMLCHARS $REXMLCHARS); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
100
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
@EXPORT = qw(); # Not exporting anything - this is OO. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$VERSION = '0.05'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
2110
|
use DBI; |
|
1
|
|
|
|
|
18273
|
|
|
1
|
|
|
|
|
737
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
17
|
0
|
|
0
|
|
|
|
my $class = ref($this) || $this; |
18
|
0
|
|
|
|
|
|
my $self = {}; |
19
|
0
|
|
|
|
|
|
bless $self, $class; |
20
|
0
|
0
|
|
|
|
|
$self->Initialise(@_) || return undef; |
21
|
0
|
|
|
|
|
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
%XMLCHARS = ( |
25
|
|
|
|
|
|
|
'&' => '&', |
26
|
|
|
|
|
|
|
'<' => '<', |
27
|
|
|
|
|
|
|
'>' => '>', |
28
|
|
|
|
|
|
|
'"' => '"', |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub xmlenc { |
32
|
0
|
|
|
0
|
0
|
|
my $str = shift; |
33
|
0
|
|
|
|
|
|
$str =~ s/([&<>"])/$XMLCHARS{$1}/ge; |
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $str; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub Initialise { |
38
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
39
|
0
|
|
|
|
|
|
$self->{datasource} = shift; |
40
|
0
|
|
|
|
|
|
my $driver = shift; |
41
|
0
|
|
|
|
|
|
my $userid = shift; |
42
|
0
|
|
|
|
|
|
my $password = shift; |
43
|
0
|
|
|
|
|
|
my $dbname = shift; |
44
|
0
|
|
|
|
|
|
$self->{verbose} = shift; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$self->{dbh} = DBI->connect("dbi:$driver:". $self->{datasource}, $userid, $password); |
47
|
0
|
0
|
|
|
|
|
if (!$self->{dbh}) { |
48
|
0
|
|
|
|
|
|
print STDERR "Connection failed\n"; |
49
|
0
|
|
|
|
|
|
return 0; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if ($dbname) { |
53
|
0
|
0
|
|
|
|
|
if(!$self->{dbh}->do("use $dbname")) { |
54
|
0
|
|
|
|
|
|
print STDERR "USE $dbname failed\n"; |
55
|
0
|
|
|
|
|
|
return 0; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->{output} = "\n"; |
60
|
0
|
|
|
|
|
|
$self->{output} .= "{datasource}) . "\">\n"; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return 1; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub DESTROY { |
66
|
0
|
|
|
0
|
|
|
my $self = shift; |
67
|
0
|
|
|
|
|
|
$self->{dbh}->disconnect; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub DoSql { |
71
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
72
|
0
|
|
|
|
|
|
my $sql = shift; |
73
|
0
|
|
0
|
|
|
|
$self->{sth} = $self->{dbh}->prepare($sql) || die $self->{dbh}->errstr; |
74
|
0
|
0
|
|
|
|
|
$self->{sth}->execute || die $self->{sth}->errstr; |
75
|
0
|
|
|
|
|
|
$self->_CreateOutput; |
76
|
0
|
|
|
|
|
|
$self->{sth}->finish; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _CreateOutput { |
80
|
0
|
|
|
0
|
|
|
my $self = shift; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $fields = $self->{sth}->{NAME}; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Now insert the actual data. |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
$self->{output} .= "\t{sth}->{Statement}) ."\">\n"; |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
my $row = 0; |
89
|
0
|
|
|
|
|
|
my @data; |
90
|
0
|
|
|
|
|
|
while (@data = $self->{sth}->fetchrow_array) { |
91
|
0
|
0
|
|
|
|
|
print STDERR "Row: ", $row++, "\n" if $self->{verbose}; |
92
|
0
|
|
|
|
|
|
my $i = 0; |
93
|
0
|
|
|
|
|
|
$self->{output} .= "\t\t\n"; |
94
|
0
|
|
|
|
|
|
foreach my $f (@data) { |
95
|
0
|
0
|
|
|
|
|
if (defined $f) { |
96
|
0
|
|
|
|
|
|
$self->{output} .= "\t\t\t<" . $fields->[$i] . '>' . xmlenc($f) . '' . $fields->[$i] . ">\n"; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
$i++; |
99
|
|
|
|
|
|
|
} |
100
|
0
|
|
|
|
|
|
$self->{output} .= "\t\t\n"; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
$self->{output} .= "\t\n"; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub GetData { |
106
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
107
|
0
|
|
|
|
|
|
my $output = $self->{output} . "\n"; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# Return output to starting state, in case we want to do more... |
110
|
0
|
|
|
|
|
|
$self->{output} = "\n"; |
111
|
0
|
|
|
|
|
|
$self->{output} .= "{datasource}) . "\">\n"; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return $output; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
__END__ |