#!/usr/bin/perl use strict; use warnings; use DBI qw(:utils); my $data; my $host = 'somehost'; my $query = <<'END'; select someColumn from someDb.someSchema.someTable where id = someValue END $data = queryDb( 'host' => $host, 'query' => $query, 'longTruncOk' => 1, ); print $data->[0][0], "\n"; #Output as ASCII $data->[0][0] =~ s/(.)/sprintf("%x ",ord($1))/eg; print $data->[0][0], "\n"; #Output as hex sub queryDb { my %args = @_; my $connStr = 'DBI:ODBC:' . $args{host}; my $dbh = DBI->connect($connStr) or die "Couldn't connect to database: " . DBI->errstr . "\n"; my $table = []; $dbh->{LongReadLen} = defined $args{longReadLen} ? $args{longReadLen} : 80; $dbh->{LongTruncOk} = defined $args{longTruncOk} ? $args{longTruncOk} : 0; #Note - this seems to change strings to UTF-16? my $sth = $dbh->prepare($args{query}) or die "Couldn't prepare statement: " . $dbh->errstr . "\n"; $sth->execute( @{ $args{params} } ); while (my @row = $sth->fetchrow_array()) { push @$table, \@row; } return $table; }