#!/usr/bin/perl
use warnings;
use strict;

use DBI;
use Data::Dump qw(dump);

my $dbh = DBI->connect ("dbi:CSV:", "", "", {
	f_dir => "./db3",
	f_ext => ".csv",
});

sub lookup {
	my $sql = shift;
	my $data;

	my $sth = $dbh->prepare( $sql );
	$sth->execute;

	while( my $row = $sth->fetchrow_arrayref ) {
		$data->{ $row->[0] } = $row->[1];
	}

	return $data;
}

my $text = lookup( qq{
select Id, texteEN from "SymbolNames"
});

#warn "# text = ",dump( $text );

my $types = lookup( qq{
select TypeId, TypeName from "DataTyps"
});

my $units = lookup( qq{
select Id, TexteEN from "UnitNames"
});

my $sth = $dbh->prepare( qq{
select * from "ComuInfos"
order by adresse
});
$sth->execute;

while( my $row = $sth->fetchrow_hashref ) {
	printf "%02x %-27s %-15s %s\n",
		$row->{adresse},
		$types->{ $row->{typid} },
		$units->{ $row->{id} },
		$text->{ $row->{id} } || $row->{symbolname};
}
