use strict; use DBI; use charnames ':full'; use vars qw($trace); print "Perl version is $]\n"; # Output is "Perl version is 5.008008" my $text1 = 'Priorit' . "\N{LATIN SMALL LETTER A WITH DIAERESIS}" . 't'; my $text2 = 'Priorität'; if ($text1 eq $text2) {print 'Equal '}; if ($text1 ne $text2) {print 'Different '}; print length($text1) . ' ' . length($text2) . "\n"; # Output is "Equal 9 9" # Connect to the database and create a database handler my $dbh = DBI->connect('dbi:ODBC:dataSource', 'userID', 'password', { RaiseError => 0, AutoCommit => 0 } ) || die $DBI::errstr; do_sql(<<'--------'); CREATE TABLE dummy1 ( id1 int NOT NULL, str1 varchar(50) NOT NULL ) ON [PRIMARY] -------- do_sql("INSERT INTO dummy1 (id1, str1) VALUES(1, '$text1')"); do_sql("INSERT INTO dummy1 (id1, str1) VALUES(2, '$text2')"); # According to the SQL Query Analyzer program, the table contains: # 1, 'Priorität' (a 10 character value) # 2, 'Priorität' (a 9 character value) my $array_ref = $dbh->selectall_arrayref('SELECT * FROM dummy1'); for my $r (@$array_ref) { print ${$r}[0] . ': ' . length(${$r}[1]) . "\n"; } # Output is # 1: 10 # 2: 9 $dbh->commit; $dbh->disconnect || warn $dbh->errstr; sub do_sql { $dbh->do($_[0]); if ($dbh->errstr()) { print STDERR 'error number = ' . $dbh->err() . "\n"; print STDERR "The following SQL statement failed:\n$_[0]\n"; $dbh->disconnect || warn $dbh->errstr; die; } }