At the first glance you may be using a non-unicode database connection. In
this case
$dbh->do ("set names 'utf8'");
may help.
Hendrik
Am Di, 29.09.2009, 16:39, schrieb Stephan Austermühle:
> Hi all,
>
> maybe I do not to see the wood for the trees...
>
> All I want to do is to process strings with special characters (e.g.,
> Umlauts), i.e. INSERT and SELECT them from my database (SQL
> Server 2008).
>
> Querying strings with special characters works fine now:
>
> $ locale |grep ^LC_CTYPE
> LC_CTYPE="en_US.UTF-8"
>
> Perl code:
>
> binmode(STDIN, ':utf8');
> binmode(STDOUT, ':utf8');
> binmode(STDERR, ':utf8');
> ...
>
> $st = $dbh->prepare(q/SELECT id, name FROM foo/);
> $st->execute() || croak("Cannot SELECT");
>
> while (my $r = $st->fetchrow_hashref()) {
> printf("%3d %s\n", $r->{'id'}, $r->{'name'});
> }
> $dbh->commit();
>
> Result:
>
> 1 Gänz vüle Ã*mläute und Ã*eugs
>
> Okay, SELECTing works (unless "use encoding 'utf8'" is given).
>
> Now the other way. Insert a row and fill a column with a string containing
> special characters:
>
> $st = $dbh->prepare(q/INSERT INTO foo (name) VALUES (?)/);
> $st->execute("süÃ*") || croak("Cannot INSERT");
> $dbh->commit();
> ...
>
> Result: Column 'name' is empty (but not NULL). Tracing shows
>
> Unicode login6
> dbname=DSN=XXX;MARS_Connection=Yes, uid='XXX', pwd=XXX
> Now using dbname = DSN=XXX;MARS_Connection=Yes;UID=XXX;PWD=XXX;
> SQLDriverConnect 'DSN=XXX;MARS_Connection=Yes;UID=XXX;PWD=XXX;',
> ''XXX'', 'XXX'
> Out connection string: DSN=XXX;MARS_Connection=Yes;UID=XXX;PWD=XXX;
> Turning autocommit on
> DRIVER_ODBC_VER = 03.00
> DRIVER_NAME = libtdsodbc.so
> DRIVER_VERSION = 0.82.1.dev.20090904
> MAX_COLUMN_NAME_LEN = 128
> DBD::ODBC is unicode built : YES
> Deferring Binding
> SQL_DBMS_NAME = Microsoft SQL Server
> SQLMoreResults supported: 1
> SQLDescribeParam supported: 0
> SQLDescribeParam supported: 0
> unicode support = 1
> Processing non-utf8 sql in unicode mode
> Processing non-utf8 sql in unicode mode
>
> Can you give me a hint how to handle special characters with Perl and
> DBD::ODBC?
>
> Setup:
>
> - Perl 5.8.9
> - FreeTDS v0.82.1.dev.20090904 (Unicode build)
> - unixODBC 2.2.14
> - DBD::ODBC 1.23 (Unicode build)
>
> Thanks and regards,
>
> Stephan
>
>