Skip to content
Snippets Groups Projects
Commit 93ce700a authored by Tomáš Plesník's avatar Tomáš Plesník
Browse files

inteligentnejsi vytahovani dat z DB pomoci hashe

parent b4d67f47
No related branches found
No related tags found
No related merge requests found
......@@ -93,26 +93,23 @@ our $DBH = DBI->connect("DBI:mysql:database=$DB_NAME;host=$DB_HOST", $DB_USER, $
# obtain data from DB
my $sth = $DBH->prepare("SELECT * FROM clients ORDER BY client_id ASC;") or die "Cannot prepare statement: " . $DBH->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my @clients = $sth->fetchall_arrayref();
my $hash_ref = $sth->fetchall_hashref("client_id");
# print table of clients
print "+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n";
print "| Client ID | Hostname | Registered | Requestor | Service | CT | Type | ROE | Description tags | IP Net Client |\n";
print "+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n";
foreach (@clients) {
my @client = @$_;
foreach (@client) {
printf("| %-10s ", @$_[0] || "unknown");
printf("| %-30s ", @$_[1] || "unknown");
printf("| %19s ", @$_[2] || "unknown");
printf("| %-23s ", @$_[3] || "unknown");
printf("| %-25s ", @$_[4] || "-");
printf("| %-2s ", @$_[5] || "unknown");
printf("| %-15s ", @$_[6] || "-");
printf("| %-4s ", @$_[7] || "-");
printf("| %-50s ", @$_[8] || "-");
printf("| %-18s |\n", @$_[9] || "unknown");
}
foreach my $key (sort {$a<=>$b} keys %$hash_ref) {
printf("| %-10s ", $hash_ref->{$key}->{client_id} || "unknown");
printf("| %-30s ", $hash_ref->{$key}->{hostname} || "unknown");
printf("| %19s ", $hash_ref->{$key}->{registered} || "unknown");
printf("| %-23s ", $hash_ref->{$key}->{requestor} || "unknown");
printf("| %-25s ", $hash_ref->{$key}->{service} || "-");
printf("| %-2s ", $hash_ref->{$key}->{client_type} || "unknown");
printf("| %-15s ", $hash_ref->{$key}->{type} || "-");
printf("| %-4s ", $hash_ref->{$key}->{receive_own_events} || "-");
printf("| %-50s ", $hash_ref->{$key}->{description_tags} || "-");
printf("| %-18s |\n", $hash_ref->{$key}->{ip_net_client}|| "unknown");
}
print "+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+\n";
print "\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment