On Thu, 12 Sep 2002, Tim Bunce wrote:

> On Wed, Sep 11, 2002 at 08:50:51PM -0400, Steven N. Hirsch wrote:
> > Tim,
> > 
> > Two fixes and a suggestion follow. To be applied over my most recent 
> > diffs.
> > 
> > The fixes ensure that $db_obj->state always gets called with a string of 
> > exactly five chars (it complains otherwise.)

> >  sub proxy_set_err {
> >    my ($h,$errmsg) = @_;
> >    my ($err,$state) = 
> > -    ($errmsg =~ s/ \[err=(.*?),state=(.*?)\]//) ? ($1,$2) : (1,5 x ' ');
> > +    ($errmsg =~ s/ \[err=(.*?),state=(.*?)\]//) ? ($1,$2) : (1,'     ');
> >    return DBI::set_err($h, $err, $errmsg, $state);
> >  }
> 
> I think a better fix is to use   ... : (1,'')
> which is what I suggested originally. Was there a problem with that?
> 
> If state is '' but err is non-zero then the DBI will return state
> as 'S1000' (general error).

Tim,

If state is 'undef', no error is raised.  I think I may see what's going 
on.  There appear to be two 'set_err' routines in the DBI.xs.  One of them 
has:

    if (state && *state) {
        if (strlen(state) != 5)
            croak("set_err: state must be 5 character string");
        sv_setpv(DBIc_STATE(imp_xxh), state);
    }
    else {
        (void)SvOK_off(DBIc_STATE(imp_xxh));
    }

which will tolerate a null string, since the outer if() conditional fails.  
The second appearance looks like:

    if (SvOK(state)) {
        STRLEN len;
        if (SvPV(state, len) && len != 5)
            croak("set_err: state must be 5 character string");
        sv_setsv(DBIc_STATE(imp_xxh), state);
    }
    else {
        (void)SvOK_off(DBIc_STATE(imp_xxh));
    }

Here, a zero-length string will clearly be trapped as an error.

I'll leave the solution in your capable hands.. <g>.

Steve

-- 
----------------------------------------------------------------
Steven N. Hirsch       tie-line: 446-6557     ext: 802-769-6557

Staff Engineer                     Methodology Integration Team
ASIC Product Development           IBM Microelectronics
----------------------------------------------------------------

Reply via email to