[moving this to dbi-dev list so we get things archived]

To give others a quick background, 2 years ago Tim and I have developed a quick prototype of DBI::Pool (with hardcoded support for mysql), but there was no work done since then. I'll try to push it now for a working state and make it independent of mysql.

The latest version can be found here:
http://stason.org/tmp/DBI-Pool-0.02.tar.gz

Tim Bunce wrote:

the autogenerated mysql.xsi has

#ifdef dbd_take_imp_data

void
take_imp_data(h)
   SV * h
   CODE:
   D_imp_xxh(h);
   ST(0) = (dbd_take_imp_data(h, imp_xxh, NULL))
        ? dbixst_bounce_method("DBD::mysql::db::SUPER::take_imp_data", items)
        : &sv_undef;

#endif

shouldn't it be DBD::mysql::db::take_imp_data?


It could be, I think, but I don't think it's relevant here.

If the dbd_take_imp_data macro is defined it's meant to be the name
of the C code function that implements it. If that function returns
true then DBD::mysql::db::SUPER::take_imp_data is called (which will
invoke the DBI's default take_imp_data method.

The idea, as I recall, is that dbd_take_imp_data is given a chance
to 'get the ready imp_xxh structure ready' before then letting the
DBI's take_imp_data method do the rest of the work.

But my memory is fuzzy on that. Re-read the old email threads.
Since no one's using it yet I'd be happy to change the interface
if it's needed.

OK, here is what I had in the prototype. There are just two functions which need to be supported by DBD drivers, one that rips the heart out of dbh and the other that implants another heart into dbh:


/* The DBI dbh fixup functions */

static
void imp_dbh2dbh(pTHX_ SV *dbh, void *imp_dbh_new)
{
    D_imp_dbh(dbh);

    /* XXX: hardcoded data, should figure out how to extract only the
     * driver's private data in imp_dbh_t */
    imp_dbh->mysql = ((imp_dbh_t *)imp_dbh_new)->mysql;
}

static
void *dbh2imp_dbh(pTHX_ SV *dbh)
{
    D_imp_dbh(dbh);
    void *imp_dbh_copy;
    /* XXX: hardcoded mysdl */
    STRLEN imp_size = SvIV(perl_get_sv("DBD::mysql::db::imp_data_size",
                                       FALSE));

    /* spare the user complicating the interface, the following has
     * the same effect as connect(..., {InactiveDestroy => 1}
     */
    /* XXX: should use DBIc_ACTIVE_off(imp_dbh) once this is
     * backported to DBI */
    DBIc_FLAGS(imp_dbh) &=  ~DBIcf_ACTIVE;

    /* must deep copy imp_dbh, since:
     * - even though we tell DBI not to call disconnect on imp_dbh,
     *   somehow the data doesn't survive
     * - we need to copy it to avoid crashes when a thread that
     *   created imp_dbh quits and some other thread wants to use it
     */
    imp_dbh_copy = malloc(imp_size);
    memcpy(imp_dbh_copy, (void*)imp_dbh, imp_size);
    return imp_dbh_copy;
}

imp_dbh2dbh() installs the data returned by dbh2imp_dbh() (in your proposal take_imp_data) inside dbh. so unless I miss something we at least lack one more function, corresponding to imp_dbh2dbh (e.g. put_imp_data?). Or did you mean something else?

In any case what file should it live in? Is there an example of a similar method that is alread implemented by the mysql driver that I can model after?


Any of the dbd_(db|st)_*() in dbdimp.c should be okay to use.
Add a #define dbd_take_imp_data mysql_take_imp_data
to dbdimp.h alongside the others.

Cool. That part is now clear.

Thanks Tim.

--
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Reply via email to