I'm trying to retrieve some string value from a clickhouse database. My script is:
use DBI qw':sql_types';
use utf8;
use open ':encoding(utf8)', ':std';
use Encode;
my $dbh = DBI->connect(
'dbi:ODBC:clickhouse'
);
if ($DBI::errstr) {
die <<ERR;
Could not connect to database
$DBI::errstr
ERR
}
$dbh->{PrintError} = 1;
$dbh->{RaiseError} = 1;
# long truncated DBI attribute LongTruncOk not set and/or LongReadLen
+too small
# for fetching milion of rows
$dbh->{LongReadLen} = 255 * 255;
$dbh->{LongTruncOk} = 1;
$dbh->{pg_enable_utf8} = 1;
$dbh->{odbc_utf8_on} = 1;
# prepare SQL statement
# my $sth = $dbh->prepare("$_[0]")
my $sth = $dbh->prepare("select CAST('STARTEND' AS String) as COLA, 'S
+TARTEND' PEPSI")
or die "prepare statement failed: $dbh->errstr()";
$sth->execute() or die "execution failed: ".$dbh->errstr();
# get column list definition
#my @cols = @{$sth->{NAME}};
my @row;
print "Fields: $sth->{NUM_OF_FIELDS}\n";
print "Params: $sth->{NUM_OF_PARAMS}\n\n";
print join("\t\t", @{$sth->{NAME}}), "\n\n";
while($row = $sth->fetchrow_arrayref) {
print join("\t\t", @$row), "\n";
}
$sth = undef;
When I execute it return two columns but the values of them are "STA". If the return string is wider then it always truncating last few characters. I don't know what is happening here. Is that an ODBC driver issue?