use strict;
use DBI;
use Devel::Peek;
use bytes;
no bytes;
my ($txt_de, $txt_ru);
{
use utf8;
$txt_de = 'Käse';
$txt_ru = 'Москва';
}
binmode STDOUT, ':utf8';
my @dsn = qw/DBI:ODBC:xxx xx xx/;
my %opt = (PrintError => 0, RaiseError => 1, AutoCommit => 1, ChopBlanks => 1);
my $dbh = DBI->connect( @dsn, \%opt );
$dbh->{LongReadLen} = 4000;
$dbh->{LongTruncOk} = 1;
my $sth_ins = $dbh->prepare(
'INSERT INTO T2 (a, u, x) VALUES (?, ?, CAST( ? AS XML) )' );
foreach my $row ([$txt_de, $txt_de, "$txt_de"],
[$txt_ru, $txt_ru, "$txt_ru"]) {
$sth_ins->bind_param(1, $row->[0]);
$sth_ins->bind_param(2, $row->[1]);
$sth_ins->bind_param(3, $row->[2], {TYPE => -8});
$sth_ins->execute;
}
#$sth_ins->execute( $txt_de, $txt_de, "$txt_de" );
#$sth_ins->execute( $txt_ru, $txt_ru, "$txt_ru" );
my $sth_sel = $dbh->prepare( 'SELECT u, x FROM T2' );
$sth_sel->execute;
$sth_sel->bind_col(1, \my $txt, {TYPE => -8});
$sth_sel->bind_col(2, \my $xml, {TYPE => -8});
#$sth_sel->bind_columns( \my( $txt, $xml ) );
my $i = 0;
while ( $sth_sel->fetch ) {
printf "%3u %3u %3u %s [%s] [%s]\n",
++$i, length($txt), bytes::length($txt),
(utf8::is_utf8($txt) ? ' utf8' : '!utf8'), $txt, $xml;
# NOTE, if I don't reset $txt each iteration the length() call returns
# the wrong answer.
#$txt = ''; this line fixes it
# http://code.activestate.com/lists/perl5-porters/153703/
Dump($txt);
}
$dbh->disconnect;