jonswar / perl-chi-driver-dbi

Perl CHI::Driver::DBI distribution
4 stars 8 forks source link

error when use with Postgresql #1

Open ChinaXing opened 11 years ago

ChinaXing commented 11 years ago
#!/bin/env perl                                                                                                   

use CHI;
use DBI;
use utf8;

my $data_source = "dbi:Pg:dbname=pesystem";
my $username = "pesystem";
my $auth = "pesystem_213456";
my $dbh = DBI->connect($data_source, $username, $auth  );
my $cache = CHI->new( driver => 'DBI',
                  dbh => $dbh,
                  $serializer => 'Data::Dumper',
);

$cache->set( a => 'b' );

the error is :
Use of uninitialized value $_[5] in list assignment at /usr/local/lib/perl5/site_perl/5.16.2/CHI.pm line 63. DBD::Pg::st execute failed: ERROR: invalid byte sequence for encoding "UTF8": 0x8b at /usr/local/lib/perl5/site_perl/5.16.2/CHI/Driver/DBI.pm line 115. DBD::Pg::st execute failed: ERROR: invalid byte sequence for encoding "UTF8": 0x8b at /usr/local/lib/perl5/site_perl/5.16.2/CHI/Driver/DBI.pm line 119.

ChinaXing commented 11 years ago

the solution maybe (but not pretty ) following:

when create table, the value column should have type of bytea ; which in pgsql means binary data;

when insert or update, execute bind_param before execute:

$sth->bind_param(2,undef,{ pg_type => PG_BYTEA}); # need use DBD::Pg qw(:pg_types);

# then
$sth->execute("a" , "b" );
jonswar commented 11 years ago

Thanks. If you send me a pull request (and make sure the code only takes effect when using postgres) I'll merge it in.

On Mar 19, 2013, at 12:33 AM, chinaxing notifications@github.com wrote:

the solution maybe (but not pretty ) following:

when create table, the value column should have type of bytea ; which in pgsql means binary data;

when insert or update, execute bind_param before execute:

$sth->bind_param(2,undef,{ pg_type => PG_BYTEA}); # need use DBD::Pg qw(:pg_types);

then

$sth->execute("a" , "b" ); — Reply to this email directly or view it on GitHub.

ChinaXing commented 11 years ago

i have make pull request #2

jonswar commented 11 years ago

released - let me know if it works for you - thanks

On Mar 20, 2013, at 1:58 AM, chinaxing notifications@github.com wrote:

i have make pull request #2

— Reply to this email directly or view it on GitHub.