limit to just my boiler model
[vrDialog] / db3-dump.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use DBI;
6 use Data::Dump qw(dump);
7
8 my $dbh = DBI->connect ("dbi:CSV:", "", "", {
9         f_dir => "./db3",
10         f_ext => ".csv",
11 });
12
13 sub lookup {
14         my $sql = shift;
15         my $data;
16
17         my $sth = $dbh->prepare( $sql );
18         $sth->execute;
19
20         while( my $row = $sth->fetchrow_arrayref ) {
21                 my @r = @$row;
22                 my $id = shift @r;
23                 $data->{ $row->[0] } = $#$row == 1 ? $row->[1] : join('', @r);
24         }
25
26         return $data;
27 }
28
29 my $names = lookup( qq{
30 select Id, texteEN from "SymbolNames"
31 });
32
33 #warn "# names = ",dump( $names );
34
35 my $hints = lookup( qq{
36 select Id, texteEN from "SymbolHints"
37 });
38
39 my $types = lookup( qq{
40 select TypeId, TypeName from "DataTyps"
41 });
42
43 my $units = lookup( qq{
44 select Id, TexteEN from "UnitNames"
45 });
46
47 my $diags = lookup( qq{
48 select Id,x0136,x0142,x0144,x0147,x0151,x0152,x0153,x0158,x0160,x0161 from "DiagnoseDaten"
49 where x0147 = 1
50 });
51 #warn "# diags = ",dump($diags);
52
53 my $sth = $dbh->prepare( qq{
54 select * from "ComuInfos"
55 order by adresse
56 });
57
58 $sth->execute;
59
60 while( my $row = $sth->fetchrow_hashref ) {
61         my $hint = $hints->{ $row->{texteid} };
62         $hint =~ s/[\r\n]+/ | /gs;
63         printf "%-3d %02x %-27s %-15s |%s| %s %s [ %s ]\n",
64                 $row->{adresse},
65                 $row->{adresse},
66                 $types->{ $row->{typid} },
67                 $units->{ $row->{id} },
68                 $diags->{ $row->{id} } || '          ',
69                 $row->{symbolname},
70                 $names->{ $row->{texteid} } || $row->{symbolname},
71                 $hint,
72         ;
73 }