root/dan/perl/omoon_MyDBI.pm @ 2672

Revision 2392, 0.9 kB (checked in by omoon, 7 years ago)

dan/perl/omoon_MyDBI.pm Data::Visitor::Encodeで一部書き換え。

Line 
1package MyDBI;
2use strict;
3use warnings;
4use base qw(DBI);
5use Data::Visitor::Encode;
6
7package MyDBI::db;
8use base qw(DBI::db);
9
10my $dev = Data::Visitor::Encode->new();
11
12sub prepare {
13    my ( $dbh, @args ) = @_;
14
15    # sql文が入っている
16    @args = map { Encode::encode( 'cp932', $_ ) } @args;
17    return $dbh->SUPER::prepare(@args);
18}
19
20package MyDBI::st;
21use base qw(DBI::st);
22
23sub execute {
24    my ( $sth, @args ) = @_;
25
26    # プレースホルダの値が入っている
27    @args = map { Encode::encode( 'cp932', $_ ) } @args;
28    return $sth->SUPER::execute(@args);
29}
30
31sub fetch {
32    my ( $sth, @args ) = @_;
33    my $row = $sth->SUPER::fetch(@args) or return;
34    return $dev->decode( 'cp932', $row );
35}
36
37sub fetchrow_arrayref {
38    my ( $sth, @args ) = @_;
39    my $array_ref = $sth->SUPER::fetchrow_arrayref(@args) or return;
40    return $dev->decode( 'cp932', $array_ref );
41}
42
431;
Note: See TracBrowser for help on using the browser.