Stephan Austermühle wrote:
> 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

good :-)

> Okay, SELECTing works (unless "use encoding 'utf8'" is given).

What do you mean by that? Select stops working it you stipulate your
perl script is utf-8?

> 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();
>     ...

You need to use utf8 to have utf-8 encoded data in your Perl script.

> 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
> 

Your setup looks ok except I am not familiar with a "unicode built"
FreeTDS (what does that mean and what does it change in FreeTDS).

I have a default build of freeTDS here and it passes the unicode tests
in DBD::OBDC's t dir. Does your setup pass the DBD::ODBC tests?

Martin
-- 
Martin J. Evans
Easysoft Limited
http://www.easysoft.com

Reply via email to