Tim Bunce wrote:
> 
> You have _way_ too much free time Steffen!

Since I'm using perl, DBI, ...
 
> The only things that comes to mind are that there's a specific api
> call for require'ing a file that should be used to avoid static's
> and threading issues.

I used eval_pv() because of it's builtin error handling. Unfortunately,
require_pv() is very silent about error conditions. Now I use the hash
itself as indicator of successful load:

    hv = get_hv("DBI::Const::GetInfo", FALSE);
    if (!hv) {
        require_pv("DBI/Const.pm");
        hv = get_hv("DBI::Const::GetInfo", FALSE);
        if (!hv)
            croak("Can't get %s", "%DBI::Const::GetInfo");
    }
    if (hv_exists(hv, key, keylen)) {
        meth_name = "get_info";
    }
    else {
        croak("Can't get %s->{%s}: unrecognised attribute", neatsvpv(h,0), key);
    }

> And the return value probably needs to be
> made mortal (sv_2mortal(...)).

I changed

    return newSVsv(valuesv);

to

    return sv_2mortal(newSVsv(valuesv));

However, I got:

  Attempt to free unreferenced scalar ...

I think the call to dbih_get_attr_k_sql_ needs to be changed too:

        valuesv = dbih_get_attr_k_sql_(h, keysv, key, keylen);

is now:

        valuesv = newSVsv(dbih_get_attr_k_sql_(h, keysv, key, keylen));


Steffen
*** DBI-1.20.orig/DBI.xs        Sat Aug 25 00:10:48 2001
--- DBI-1.20/DBI.xs     Thu Nov 29 10:02:26 2001
***************
*** 1243,1248 ****
--- 1243,1285 ----
  
  
  static SV *
+ dbih_get_attr_k_sql_(SV *h, SV *keysv, char *key, STRLEN keylen)
+ {
+     dPERINTERP;
+     dSP;
+     HV    *hv;
+     char  *meth_name;
+     SV    *valuesv;
+ 
+     hv = get_hv("DBI::Const::GetInfo", FALSE);
+     if (!hv) {
+       require_pv("DBI/Const.pm");
+       hv = get_hv("DBI::Const::GetInfo", FALSE);
+       if (!hv)
+           croak("Can't get %s", "%DBI::Const::GetInfo");
+     }
+     if (hv_exists(hv, key, keylen)) {
+       meth_name = "get_info";
+     }
+     else {
+       croak("Can't get %s->{%s}: unrecognised attribute", neatsvpv(h,0), key);
+     }
+ 
+     PUSHMARK(SP);
+     XPUSHs(h);
+     XPUSHs(keysv);
+     PUTBACK;
+     if (call_method(meth_name, G_SCALAR) != 1)
+       croak("Can't locate DBI object method \"%s\"", meth_name);
+     SPAGAIN;
+     valuesv = POPs;
+     PUTBACK;
+ 
+     return sv_2mortal(newSVsv(valuesv));
+ }
+ 
+ 
+ static SV *
  dbih_get_attr_k(h, keysv, dbikey)                     /* XXX split into dr/db/st 
funcs */
      SV *h;
      SV *keysv;
***************
*** 1407,1412 ****
--- 1444,1452 ----
      else if (keylen==9  && strEQ(key, "BegunWork")) {
        valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_BegunWork));
      }
+     else if (htype==DBIt_DB && strnEQ(key, "SQL_", 4)) {
+       valuesv = newSVsv(dbih_get_attr_k_sql_(h, keysv, key, keylen));
+     }
      else {    /* finally check the actual hash just in case   */
        svp = hv_fetch((HV*)SvRV(h), key, keylen, FALSE);
        if (svp)

Reply via email to