On Thu, 26 Apr 2007 09:11:50 +0100, Tim Bunce <[EMAIL PROTECTED]> wrote:

> On Wed, Apr 25, 2007 at 10:40:41PM +0100, Tim Bunce wrote:
> > On Wed, Apr 25, 2007 at 01:18:08PM +0200, H.Merijn Brand wrote:
> > > > ---
> > > > Don't use DBIS or dbis when you can use DBIc_STATE (imp_xxh).
> > > > DBIS is much slower, especially on perls built with threads enabled.
> > > > It's a macro that expands to a function call, whereas
> > > > DBIc_STATE (imp_xxh) is just accessing a field in the handle structure.
> > > 
> > > This does not apply to?:
> > > 
> > >     av = DBIS->get_fbav (imp_sth);
> > >     num_fields = AvFILL (av) + 1;
> > 
> > Yes. Ideally the code should have no DBIS (or dbis) in it at all. The only
> > exception would be any code that doesn't have a handle/imp_xxh handy.
> 
>  ... and can't be modified to have a handle/imp_xxh passed in.

I've lost you here. Is there a sane way to prevent DBIS in the tail of
the following snippet?
--8<---
AV *dbd_st_fetch (SV *sth, imp_sth_t *imp_sth)
{
    int    num_fields, i;
    AV     *av;
    SV     *dbh = (SV *)DBIc_PARENT_H (imp_sth);

    D_imp_dbh_from_sth;

    unless (use_sth_id (dbh, imp_dbh->id, imp_sth->id))
        return (Nullav);
    dbg (2, "DBD::Unify::st_fetch %s\n", u_sql_nm);

    unless (DBIc_ACTIVE (imp_sth)) {
        error (sth, -7, "fetch without open cursor");
        return (Nullav);
        }

    /* In the next E/SQL a statement like
     *     "select code from table where field SHLIKE 'v_ab*'"
     * will dump core in sqldfch ()
     * affirmed for 6.3AB and 6.3BE
     */
    EXEC SQL
        FETCH                :c_sql_nm
        USING SQL DESCRIPTOR :o_sql_nm;

    av = DBIS->get_fbav (imp_sth);
    num_fields = AvFILL (av) + 1;
-->8---


I *can* change the other locations to pass a handle, but that would ruin
my code. Really. Changing all

        dbg (4, "     Field %3d: ", fix);
        dbg (5, "[%02X %02X %02X %02X %02X] ",
            (unsigned char)ftp, fln, fpr, fsc, fic);
        dbg (4, "%-.8s\n", fnm);

to include handles is beyond what it would return. Maintainability is
also very important for code one doesn't visit on a daily basis.

I changed the error () function to use

 DBIh_SET_ERR_CHAR (h, imp_xxh, Nullch, error_num, text, SQLSTATE, Nullch);

and behold! my DBD now supports SQLSTATE throughout :)
It's a shame that UNIFY didn't even document SQLSTATE, apart from
  "The SQLSTATE variable is provided for compatibility to the
   ANSI SQL2 draft standard."

So I have no idea how to extend my tests to see if the states make sense

-- 
H.Merijn Brand         Amsterdam Perl Mongers (http://amsterdam.pm.org/)
using & porting perl 5.6.2, 5.8.x, 5.9.x   on HP-UX 10.20, 11.00, 11.11,
& 11.23, SuSE 10.0 & 10.2, AIX 4.3 & 5.2, and Cygwin. http://qa.perl.org
http://mirrors.develooper.com/hpux/            http://www.test-smoke.org
                        http://www.goldmark.org/jeff/stupid-disclaimers/

Reply via email to