added symbol hints
[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                 $data->{ $row->[0] } = $row->[1];
22         }
23
24         return $data;
25 }
26
27 my $names = lookup( qq{
28 select Id, texteEN from "SymbolNames"
29 });
30
31 #warn "# names = ",dump( $names );
32
33 my $hints = lookup( qq{
34 select Id, texteEN from "SymbolHints"
35 });
36
37 my $types = lookup( qq{
38 select TypeId, TypeName from "DataTyps"
39 });
40
41 my $units = lookup( qq{
42 select Id, TexteEN from "UnitNames"
43 });
44
45 my $sth = $dbh->prepare( qq{
46 select * from "ComuInfos"
47 order by adresse
48 });
49 $sth->execute;
50
51 while( my $row = $sth->fetchrow_hashref ) {
52         my $hint = $hints->{ $row->{texteid} };
53         $hint =~ s/[\r\n]+/ | /gs;
54         printf "%-3d %02x %-27s %-15s %s %s [ %s ]\n",
55                 $row->{adresse},
56                 $row->{adresse},
57                 $types->{ $row->{typid} },
58                 $units->{ $row->{id} },
59                 $row->{symbolname},
60                 $names->{ $row->{texteid} } || $row->{symbolname},
61                 $hint,
62         ;
63 }