File: unicode_sql.pl

package info (click to toggle)
libdbd-odbc-perl 1.61-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,424 kB
  • sloc: perl: 8,928; ansic: 6,456; makefile: 33; sql: 8
file content (50 lines) | stat: -rw-r--r-- 1,052 bytes parent folder | download | duplicates (6)
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
48
49
50
# $Id$
#
# Small example showing how you can insert unicode inline in the SQL
#
# expected output:
#Has unicode: 1
#$VAR1 = [
#          [
#            "\x{20ac}"
#          ]
#        ];
#$VAR1 = [
#          [
#            "\x{20ac}"
#          ],
#          [
#            "\x{20ac}"
#          ]
#        ];
#
use DBI;
use strict;
use warnings;
use Data::Dumper;

my $h = DBI->connect();
#$h->{odbc_default_bind_type} = 12;

warn "Warning DBD::ODBC not built for unicode - this will not work as expected" if !$h->{'odbc_has_unicode'};

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

print "Has unicode: " . $h->{odbc_has_unicode} . "\n";

$h->do(q/create table martin (a nvarchar(100))/);

my $s = $h->prepare(q/insert into martin values(?)/);
$s->execute("\x{20ac}");

my $r = $h->selectall_arrayref(q/select * from martin/);
print Dumper($r);

my $sql = 'insert into martin values(' . $h->quote("\x{20ac}") . ')';
$h->do($sql);

$r = $h->selectall_arrayref(q/select * from martin/);
print Dumper($r);

#--with-iconv-char-enc=
#--with-iconv-ucode-enc=enc