On Wed, Mar 26, 2008 at 03:01:54PM +0000, Martin Evans wrote:
> Hi,
>
> I was attempting to tidy up some code in DBD::ODBC and noticed quite a 
> number of tests using DBIc_ACTIVE which attempt to signal an error when the 
> database is not active (not connected). Having never seen these errors I 
> wrote a quick test script and got no errors when calling prepare, do etc 
> after disconnecting. Investigating, it appears there is a bug in DBD::ODBC 
> which fails to report these errors correctly but this led me to a few 
> questions:
>
> dbd_st_prepare, dbd_db_execdirect, dbd_st_tables, dbd_st_primary_keys and a 
> host of odbc private functions in dbdimp.c receive combinations of an sth, 
> dbh or both and do something like:
>
> if (!DBIc_ACTIVE(imp_dbh)) {
>   error code
> }
>
> I would like to commonise some of this. I know I can get my private sth 
> from an sth (D_imp_sth) and similarly for database handle (D_imp_dbh) and I 
> can get my private dbh from an sth with D_imp_dbh_from_sth but the  
> DBIh_SET_ERR_CHAR macros needs a handle - how do you get SV *dbh from 
> imp_dbh? (DBIc_PARENT_COM perhaps?)

You can use newRV_noinc((SV*)DBIc_MY_H(imp_dbh)) but there are some caveats.
I'd recommend just passing both the h and the imp_xxh to all functions.

> Also, who does DBI allow prepare in a driver to be called when the dbh was 
> disconnected?

s/who/why/? The presumption is that the underlying database API will
return an error in that situation (with a suitable native error message)
so the DBI needn't waste time being pedantic and second guessing what's
allowable. (Why just disallow prepare, for example?)

Tim.

Reply via email to