DBI
view release on metacpan or search on metacpan
#define DBIc_AIADESTROY_on(imp) (DBIc_FLAGS(imp) |= DBIcf_AIADESTROY)
#define DBIc_AIADESTROY_off(imp) (DBIc_FLAGS(imp) &= ~DBIcf_AIADESTROY)
#define DBIc_WARN(imp) (DBIc_FLAGS(imp) & DBIcf_WARN)
#define DBIc_WARN_on(imp) (DBIc_FLAGS(imp) |= DBIcf_WARN)
#define DBIc_WARN_off(imp) (DBIc_FLAGS(imp) &= ~DBIcf_WARN)
#define DBIc_COMPAT(imp) (DBIc_FLAGS(imp) & DBIcf_COMPAT)
#define DBIc_COMPAT_on(imp) (DBIc_FLAGS(imp) |= DBIcf_COMPAT)
#define DBIc_COMPAT_off(imp) (DBIc_FLAGS(imp) &= ~DBIcf_COMPAT)
#ifdef IN_DBI_XS /* get Handle Common Data Structure */
#define DBIh_COM(h) (dbih_getcom2(aTHX_ h, 0))
#else
#define DBIh_COM(h) (DBIS->getcom(h))
#define neatsvpv(sv,len) (DBIS->neat_svpv(sv,len))
#endif
/* --- For sql_type_cast_svpv() --- */
#define DBIstcf_DISCARD_STRING 0x0001
#define DBIstcf_STRICT 0x0002
/* --- Implementors Private Data Support --- */
#define D_impdata(name,type,h) type *name = (type*)(DBIh_COM(h))
#define D_imp_drh(h) D_impdata(imp_drh, imp_drh_t, h)
#define D_imp_dbh(h) D_impdata(imp_dbh, imp_dbh_t, h)
#define D_imp_sth(h) D_impdata(imp_sth, imp_sth_t, h)
#define D_imp_xxh(h) D_impdata(imp_xxh, imp_xxh_t, h)
#define D_imp_from_child(name,type,child) \
type *name = (type*)(DBIc_PARENT_COM(child))
#define D_imp_drh_from_dbh D_imp_from_child(imp_drh, imp_drh_t, imp_dbh)
#define D_imp_dbh_from_sth D_imp_from_child(imp_dbh, imp_dbh_t, imp_sth)
#define DBI_IMP_SIZE(n,s) sv_setiv(get_sv((n), GV_ADDMULTI), (s)) /* XXX */
/* --- Event Support (VERY LIABLE TO CHANGE) --- */
#define DBIh_EVENTx(h,t,a1,a2) /* deprecated XXX */ &PL_sv_no
#define DBIh_EVENT0(h,t) DBIh_EVENTx((h), (t), &PL_sv_undef, &PL_sv_undef)
#define DBIh_EVENT1(h,t, a1) DBIh_EVENTx((h), (t), (a1), &PL_sv_undef)
#define DBIh_EVENT2(h,t, a1,a2) DBIh_EVENTx((h), (t), (a1), (a2))
#define ERROR_event "ERROR"
#define WARN_event "WARN"
#define MSG_event "MESSAGE"
#define DBEVENT_event "DBEVENT"
#define UNKNOWN_event "UNKNOWN"
#define DBIh_SET_ERR_SV(h,i, err, errstr, state, method) \
(DBIc_DBISTATE(i)->set_err_sv(h,i, err, errstr, state, method))
#define DBIh_SET_ERR_CHAR(h,i, err_c, err_i, errstr, state, method) \
(DBIc_DBISTATE(i)->set_err_char(h,i, err_c, err_i, errstr, state, method))
/* --- Handy Macros --- */
#define DBIh_CLEAR_ERROR(imp_xxh) (void)( \
(void)SvOK_off(DBIc_ERR(imp_xxh)), \
(void)SvOK_off(DBIc_ERRSTR(imp_xxh)), \
(void)SvOK_off(DBIc_STATE(imp_xxh)) \
)
/* --- DBI State Structure --- */
struct dbistate_st {
/* DBISTATE_VERSION is checked at runtime via DBISTATE_INIT and check_version.
* It should be incremented on incompatible changes to dbistate_t structure.
* Additional function pointers being assigned from spare padding, where the
* size of the structure doesn't change, doesn't require an increment.
* Incrementing forces all XS drivers to need to be recompiled.
* (See also DBIXS_REVISION as a driver source compatibility tool.)
*/
#define DBISTATE_VERSION 94 /* ++ on incompatible dbistate_t changes */
/* this must be the first member in structure */
void (*check_version) _((const char *name,
int dbis_cv, int dbis_cs, int need_dbixs_cv,
int drc_s, int dbc_s, int stc_s, int fdc_s));
/* version and size are used to check for DBI/DBD version mis-match */
U16 version; /* version of this structure */
U16 size;
U16 xs_version; /* version of the overall DBIXS / DBD interface */
U16 spare_pad;
I32 debug;
PerlIO *logfp;
/* pointers to DBI functions which the DBD's will want to use */
char * (*neat_svpv) _((SV *sv, STRLEN maxlen));
imp_xxh_t * (*getcom) _((SV *h)); /* see DBIh_COM macro */
void (*clearcom) _((imp_xxh_t *imp_xxh));
SV * (*event) _((SV *h, const char *name, SV*, SV*));
int (*set_attr_k) _((SV *h, SV *keysv, int dbikey, SV *valuesv));
SV * (*get_attr_k) _((SV *h, SV *keysv, int dbikey));
AV * (*get_fbav) _((imp_sth_t *imp_sth));
SV * (*make_fdsv) _((SV *sth, const char *imp_class, STRLEN imp_size, const char *col_name));
int (*bind_as_num) _((int sql_type, int p, int s, int *t, void *v)); /* XXX deprecated */
I32 (*hash) _((const char *string, long i));
SV * (*preparse) _((SV *sth, char *statement, IV ps_return, IV ps_accept, void *foo));
SV *neatsvpvlen; /* only show dbgpvlen chars when debugging pv's */
PerlInterpreter * thr_owner; /* thread that owns this dbistate */
int (*logmsg) _((imp_xxh_t *imp_xxh, const char *fmt, ...));
int (*set_err_sv) _((SV *h, imp_xxh_t *imp_xxh, SV *err, SV *errstr, SV *state, SV *method));
int (*set_err_char) _((SV *h, imp_xxh_t *imp_xxh, const char *err, IV err_i, const char *errstr, const char *state, const char *method));
int (*bind_col) _((SV *sth, SV *col, SV *ref, SV *attribs));
IO *logfp_ref; /* keep ptr to filehandle for refcounting */
int (*sql_type_cast_svpv) _((pTHX_ SV *sv, int sql_type, U32 flags, void *v));
/* the memory footprint exactly the same */
void *pad2[3];
};
/* macros for backwards compatibility */
#define set_attr(h, k, v) set_attr_k(h, k, 0, v)
#define get_attr(h, k) get_attr_k(h, k, 0)
#define DBILOGFP (DBIS->logfp)
#ifdef IN_DBI_XS
#define DBILOGMSG (dbih_logmsg)
#else
#define DBILOGMSG (DBIS->logmsg)
#endif
/* --- perl object (ActiveState) / multiplicity hooks and hoops --- */
/* note that USE_ITHREADS implies MULTIPLICITY */
typedef dbistate_t** (*_dbi_state_lval_t)(pTHX);
# define _DBISTATE_DECLARE_COMMON \
static _dbi_state_lval_t dbi_state_lval_p = 0; \
static dbistate_t** dbi_get_state(pTHX) { \
if (!dbi_state_lval_p) { \
CV *cv = get_cv("DBI::_dbi_state_lval", 0); \
if (!cv) \
croak("Unable to get DBI state function. DBI not loaded."); \
dbi_state_lval_p = (_dbi_state_lval_t)CvXSUB(cv); \
} \
return dbi_state_lval_p(aTHX); \
} \
typedef int dummy_dbistate /* keep semicolon from feeling lonely */
#if defined(MULTIPLICITY) || defined(PERL_OBJECT) || defined(PERL_CAPI)
# define DBISTATE_DECLARE _DBISTATE_DECLARE_COMMON
# define _DBISTATE_INIT_DBIS
# undef DBIS
# define DBIS (*dbi_get_state(aTHX))
# define dbis DBIS /* temp for old drivers using 'dbis' instead of 'DBIS' */
#else /* plain and simple non perl object / multiplicity case */
# define DBISTATE_DECLARE \
static dbistate_t *DBIS; \
_DBISTATE_DECLARE_COMMON
# define _DBISTATE_INIT_DBIS DBIS = *dbi_get_state(aTHX);
#endif
# define DBISTATE_INIT { /* typically use in BOOT: of XS file */ \
_DBISTATE_INIT_DBIS \
if (DBIS == NULL) \
croak("Unable to get DBI state. DBI not loaded."); \
DBIS->check_version(__FILE__, DBISTATE_VERSION, sizeof(*DBIS), NEED_DBIXS_VERSION, \
sizeof(dbih_drc_t), sizeof(dbih_dbc_t), sizeof(dbih_stc_t), sizeof(dbih_fdc_t) \
); \
}
/* --- Assorted Utility Macros --- */
#define DBD_ATTRIB_OK(attribs) /* is this a usable attrib value */ \
(attribs && SvROK(attribs) && SvTYPE(SvRV(attribs))==SVt_PVHV)
/* If attribs value supplied then croak if it's not a hash ref. */
/* Also map undef to Null. Should always be called to pre-process the */
/* attribs value. One day we may add some extra magic in here. */
#define DBD_ATTRIBS_CHECK(func, h, attribs) \
if ((attribs) && SvOK(attribs)) { \
if (!SvROK(attribs) || SvTYPE(SvRV(attribs))!=SVt_PVHV) \
croak("%s->%s(...): attribute parameter '%s' is not a hash ref", \
SvPV_nolen(h), func, SvPV_nolen(attribs)); \
} else (attribs) = Nullsv
#define DBD_ATTRIB_GET_SVP(attribs, key,klen) \
(DBD_ATTRIB_OK(attribs) \
? hv_fetch((HV*)SvRV(attribs), key,klen, 0) \
: (SV **)Nullsv)
#define DBD_ATTRIB_GET_IV(attribs, key,klen, svp, var) \
if ((svp=DBD_ATTRIB_GET_SVP(attribs, key,klen)) != NULL) \
var = SvIV(*svp)
#define DBD_ATTRIB_GET_UV(attribs, key,klen, svp, var) \
if ((svp=DBD_ATTRIB_GET_SVP(attribs, key,klen)) != NULL) \
var = SvUV(*svp)
#define DBD_ATTRIB_GET_BOOL(attribs, key,klen, svp, var) \
if ((svp=DBD_ATTRIB_GET_SVP(attribs, key,klen)) != NULL) \
var = SvTRUE(*svp)
#define DBD_ATTRIB_TRUE(attribs, key,klen, svp) \
( ((svp=DBD_ATTRIB_GET_SVP(attribs, key,klen)) != NULL) \
? SvTRUE(*svp) : 0 )
#define DBD_ATTRIB_GET_PV(attribs, key,klen, svp, dflt) \
(((svp=DBD_ATTRIB_GET_SVP(attribs, key,klen)) != NULL) \
? SvPV_nolen(*svp) : (dflt))
#define DBD_ATTRIB_DELETE(attribs, key, klen) \
hv_delete((HV*)SvRV(attribs), key, klen, G_DISCARD)
#endif /* DBIXS_VERSION */
/* end of DBIXS.h */
( run in 0.721 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )