Before I file an RT ticket, I want to verify that I didn't miss the obvious …

When I use bind_param on a char (4) field in DBD::Pg, it only loads the
first character:
--8<---
use 5.016;
use warnings;

use DBI;
use Data::Peek;

my $dbh = DBI->connect ("dbi:Pg:", undef, undef, {
    PrintError          => 1,
    RaiseError          => 1,
    AutoCommit          => 1,
    ShowErrorStatement  => 1,
    }) or die "Connection failed";

my $tt = "testbind";

$dbh->do ("drop table if exists $tt");

$dbh->do ("create table $tt (c_test int4, test char (4))");

my $sts = $dbh->prepare ("select * from $tt");
   $sts->execute;
my @stt = @{$sts->{TYPE}};

DDumper {
    type => $sts->{TYPE},
    tpnm => [ map { $dbh->type_info ($_)->{TYPE_NAME} } @{$sts->{TYPE}} ],
    name => $sts->{NAME_lc},
    size => $sts->{PRECISION},
    };

my $sti = $dbh->prepare ("insert into $tt values (?, ?)");
   $sti->bind_param ($_ + 1, undef, $stt[$_]) for 0 .. $#stt;

$sti->execute (0, "0301");

$sts->execute;
while (my $row = $sts->fetch) {
    DDumper $row;
    }

$dbh->do ("drop table $tt");
-->8---

=>

{   name             => [
        'c_test',
        'test'
        ],
    size             => [
        4,
        8
        ],
    tpnm             => [
        'int4',
        'bpchar'
        ],
    type             => [
        4,
        1
        ]
    }
[   0,
    '0   '
    ]

The field attributes for c_test:

{   LINK             => undef,
    NAME             => 'c_test',
    NAME_lc          => 'c_test',
    NAME_uc          => 'C_TEST',
    NULLABLE         => 1,
    PRECISION        => 4,
    SCALE            => undef,
    TYPE             => 4,
    TYPE_NAME        => 'int4',
    dbd_type         => 'int4',
    pg_async         => undef,
    pg_bound         => undef,
    pg_cmd_status    => undef,
    pg_current_row   => undef,
    pg_direct        => undef,
    pg_numbound      => undef,
    pg_oid_status    => undef,
    pg_placeholder_dollaronly => undef,
    pg_prepare_name  => undef,
    pg_prepare_now   => undef,
    pg_segments      => 'select * from testbind where 0 = 1',
    pg_server_prepare => undef,
    pg_size          => 4,
    pg_type          => 'int4'
    }

the field attributes for test:

{   LINK             => undef,
    NAME             => 'test',
    NAME_lc          => 'test',
    NAME_uc          => 'TEST',
    NULLABLE         => 1,
    PRECISION        => 4,
    SCALE            => undef,
    TYPE             => 1,
    TYPE_NAME        => 'bpchar',
    dbd_type         => 'bpchar',
    pg_async         => undef,
    pg_bound         => undef,
    pg_cmd_status    => undef,
    pg_current_row   => undef,
    pg_direct        => undef,
    pg_numbound      => undef,
    pg_oid_status    => undef,
    pg_placeholder_dollaronly => undef,
    pg_prepare_name  => undef,
    pg_prepare_now   => undef,
    pg_segments      => undef,
    pg_server_prepare => undef,
    pg_size          => -1,
    pg_type          => 'bpchar'
    }

-- 
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.17   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/        http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

Reply via email to