added units
[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 $text = lookup( qq{
28 select Id, texteEN from "SymbolNames"
29 });
30
31 #warn "# text = ",dump( $text );
32
33 my $types = lookup( qq{
34 select TypeId, TypeName from "DataTyps"
35 });
36
37 my $units = lookup( qq{
38 select Id, TexteEN from "UnitNames"
39 });
40
41 my $sth = $dbh->prepare( qq{
42 select * from "ComuInfos"
43 order by adresse
44 });
45 $sth->execute;
46
47 while( my $row = $sth->fetchrow_hashref ) {
48         printf "%02x %-27s %-15s %s\n",
49                 $row->{adresse},
50                 $types->{ $row->{typid} },
51                 $units->{ $row->{id} },
52                 $text->{ $row->{id} } || $row->{symbolname};
53 }