talexb has asked for the wisdom of the Perl Monks concerning the following question:

I'm getting a weird error from DBI by way of DBD::DB2. The code I'm executing is

warn "SessionId: $session_id"; $self->{sth_get}->execute($session_id) or die "Get failed with sessionId: $session_id: " . $self->{sth_get}->errstr;
and in the Apache error log I see
[Thu Feb 18 11:17:12 2010] null: SessionId: 0141b97a2b7b743db5de4feb6f +0990654954b556 at (file) line 288 [Thu Feb 18 11:17:12 2010] [error] [Thu Feb 18 11:17:12 2010] null: DB +D::DB2::st execute failed: Bind failed at (file) line 289
The problem is, I'm not doing a bind -- I'm passing the session ID in as a variable.

Suggestions?

Alex / talexb / Toronto

Team website: Forex Chart Monkey, Forex Technical Analysis and Pickpocket Prevention

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re: DBD::DB2::st execute failed: Bind failed
by kennethk (Abbot) on Feb 18, 2010 at 16:50 UTC
    From execute in DBI:

    If any arguments are given, then execute will effectively call "bind_param" for each value before executing the statement. Values bound in this way are usually treated as SQL_VARCHAR types unless the driver can determine the correct type (which is rare), or unless bind_param (or bind_param_inout) has already been used to specify the type.

    I think the more pertinent question is what is the statement you are accessing with $self->{sth_get}?

      I'm using the query

      select session_id, ctime, atime, data from schema.session where sessio +n_id = ?
      and the describe table shows
      Column Type Type name schema name Length Scale Nulls --------------- --------- ------------------ -------- ----- ------ SESSION_ID SYSIBM CHARACTER 40 0 No CTIME SYSIBM INTEGER 4 0 Yes ATIME SYSIBM INTEGER 4 0 Yes DATA SYSIBM VARCHAR 1024 0 Yes
      It's pretty straightforward.

      Alex / talexb / Toronto

      Team website: Forex Chart Monkey, Forex Technical Analysis and Pickpocket Prevention

      "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

        To debug why not call bind_param(1, $session_id) yourself and omit it from execute (I don't really understand why you don't get a better error and this might help). I'd also try taking one chr off the end of the session_id as your ids are exactly 40 chrs and so is the field (so nothing wrong but try it).

        I certainly agree that there are no red flags in what you've posted. What happens when you sub the following for your execute command:

        my $sth = $self->{sth_get}; $sth->bind_param(1, $session_id) or die "Bind failure:" . $sth->errstr +; $sth->execute() or die "Execute failure:" . $sth->errstr;

        I'm also a little curious why the binding failure dies in the DBD code as opposed to bubbling up to the user as a simple execute failure. Not so curious as to go source diving, but still...