File: unicode_params.pl

package info (click to toggle)
libdbd-odbc-perl 1.37-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,272 kB
  • sloc: perl: 7,932; ansic: 5,991; makefile: 33; sql: 8
file content (47 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# $Id: unicode_params.pl 14904 2011-07-11 13:21:06Z mjevans $
# Quick demo of inserting and retrieving unicode strings
# NOTE: your DBD::ODBC really needs to be built with unicode
# and this script will warn if not. You can comment the die out and it
# will work with some drivers without being built for unicode but you'll
# get slightly different output:
#
# with unicode:
# $VAR1 = [
#          [
#            "\x{20ac}" # note, is a unicode Perl string
#          ]
#        ];
# is utf8 1
#
# without unicode:
#
# $VAR1 = [
#          [
#            '€'   # note, not a unicode Perl string
#          ]
#        ];
# is utf8
#

use DBI;
use strict;
use Data::Dumper;
use utf8;

my $h = DBI->connect();
warn "Warning DBD::ODBC not built for unicode - you probably don't want to do this" if !$h->{'odbc_has_unicode'};

eval {
    $h->do(q/drop table mje/);
};

$h->do(q/create table mje (a nvarchar(20))/);

$h->do(q/insert into mje values(?)/, undef, "\x{20ac}");

my $s = $h->prepare(q/select * from mje/);
$s->execute;
my $f = $s->fetchall_arrayref;
print Dumper($f), "\n";

print "is utf8 ", utf8::is_utf8($f->[0][0]), "\n";