|
Packit Service |
b125fd |
/*
|
|
Packit Service |
b125fd |
# $Id$
|
|
Packit Service |
b125fd |
# Copyright (c) 2002 Tim Bunce Ireland
|
|
Packit Service |
b125fd |
#
|
|
Packit Service |
b125fd |
# You may distribute under the terms of either the GNU General Public
|
|
Packit Service |
b125fd |
# License or the Artistic License, as specified in the Perl README file.
|
|
Packit Service |
b125fd |
*/
|
|
Packit Service |
b125fd |
|
|
Packit Service |
b125fd |
|
|
Packit Service |
b125fd |
/* This is really just a workaround for SUPER:: not working right for XS code.
|
|
Packit Service |
b125fd |
* It would be better if we setup perl's context so SUPER:: did the right thing
|
|
Packit Service |
b125fd |
* (borrowing the relevant magic from pp_entersub in perl pp_hot.c).
|
|
Packit Service |
b125fd |
* Then we could just use call_method("SUPER::foo") instead.
|
|
Packit Service |
b125fd |
* XXX remember to call SPAGAIN in the calling code after calling this!
|
|
Packit Service |
b125fd |
*/
|
|
Packit Service |
b125fd |
static SV *
|
|
Packit Service |
b125fd |
dbixst_bounce_method(char *methname, int params)
|
|
Packit Service |
b125fd |
{
|
|
Packit Service |
b125fd |
dTHX;
|
|
Packit Service |
b125fd |
/* XXX this 'magic' undoes the dMARK embedded in the dXSARGS of our caller */
|
|
Packit Service |
b125fd |
/* so that the dXSARGS below can set things up as they were for our caller */
|
|
Packit Service |
b125fd |
void *xxx = PL_markstack_ptr++;
|
|
Packit Service |
b125fd |
dXSARGS; /* declares sp, ax, mark, items */
|
|
Packit Service |
b125fd |
int i;
|
|
Packit Service |
b125fd |
SV *sv;
|
|
Packit Service |
b125fd |
int debug = 0;
|
|
Packit Service |
b125fd |
D_imp_xxh(ST(0));
|
|
Packit Service |
b125fd |
if (debug >= 3) {
|
|
Packit Service |
b125fd |
PerlIO_printf(DBIc_LOGPIO(imp_xxh),
|
|
Packit Service |
b125fd |
" -> %s (trampoline call with %d (%ld) params)\n", methname, params, (long)items);
|
|
Packit Service |
b125fd |
PERL_UNUSED_VAR(xxx);
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
EXTEND(SP, params);
|
|
Packit Service |
b125fd |
PUSHMARK(SP);
|
|
Packit Service |
b125fd |
for (i=0; i < params; ++i) {
|
|
Packit Service |
b125fd |
sv = (i >= items) ? &PL_sv_undef : ST(i);
|
|
Packit Service |
b125fd |
PUSHs(sv);
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
PUTBACK;
|
|
Packit Service |
b125fd |
i = call_method(methname, G_SCALAR);
|
|
Packit Service |
b125fd |
SPAGAIN;
|
|
Packit Service |
b125fd |
sv = (i) ? POPs : &PL_sv_undef;
|
|
Packit Service |
b125fd |
PUTBACK;
|
|
Packit Service |
b125fd |
if (debug >= 3)
|
|
Packit Service |
b125fd |
PerlIO_printf(DBIc_LOGPIO(imp_xxh),
|
|
Packit Service |
b125fd |
" <- %s= %s (trampoline call return)\n", methname, neatsvpv(sv,0));
|
|
Packit Service |
b125fd |
return sv;
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
|
|
Packit Service |
b125fd |
|
|
Packit Service |
b125fd |
static int
|
|
Packit Service |
b125fd |
dbdxst_bind_params(SV *sth, imp_sth_t *imp_sth, I32 items, I32 ax)
|
|
Packit Service |
b125fd |
{
|
|
Packit Service |
b125fd |
/* Handle binding supplied values to placeholders. */
|
|
Packit Service |
b125fd |
/* items = one greater than the number of params */
|
|
Packit Service |
b125fd |
/* ax = ax from calling sub, maybe adjusted to match items */
|
|
Packit Service |
b125fd |
dTHX;
|
|
Packit Service |
b125fd |
int i;
|
|
Packit Service |
b125fd |
SV *idx;
|
|
Packit Service |
b125fd |
if (items-1 != DBIc_NUM_PARAMS(imp_sth)
|
|
Packit Service |
b125fd |
&& DBIc_NUM_PARAMS(imp_sth) != DBIc_NUM_PARAMS_AT_EXECUTE
|
|
Packit Service |
b125fd |
) {
|
|
Packit Service |
b125fd |
char errmsg[99];
|
|
Packit Service |
b125fd |
/* clear any previous ParamValues before error is generated */
|
|
Packit Service |
b125fd |
SV **svp = hv_fetch((HV*)DBIc_MY_H(imp_sth),"ParamValues",11,FALSE);
|
|
Packit Service |
b125fd |
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) {
|
|
Packit Service |
b125fd |
HV *hv = (HV*)SvRV(*svp);
|
|
Packit Service |
b125fd |
hv_clear(hv);
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
sprintf(errmsg,"called with %d bind variables when %d are needed",
|
|
Packit Service |
b125fd |
(int)items-1, DBIc_NUM_PARAMS(imp_sth));
|
|
Packit Service |
b125fd |
DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch);
|
|
Packit Service |
b125fd |
return 0;
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
idx = sv_2mortal(newSViv(0));
|
|
Packit Service |
b125fd |
for(i=1; i < items ; ++i) {
|
|
Packit Service |
b125fd |
SV* value = ST(i);
|
|
Packit Service |
b125fd |
if (SvGMAGICAL(value))
|
|
Packit Service |
b125fd |
mg_get(value); /* trigger magic to FETCH the value */
|
|
Packit Service |
b125fd |
sv_setiv(idx, i);
|
|
Packit Service |
b125fd |
if (!dbd_bind_ph(sth, imp_sth, idx, value, 0, Nullsv, FALSE, 0)) {
|
|
Packit Service |
b125fd |
return 0; /* dbd_bind_ph already registered error */
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
return 1;
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
|
|
Packit Service |
b125fd |
#ifndef dbd_fetchall_arrayref
|
|
Packit Service |
b125fd |
static SV *
|
|
Packit Service |
b125fd |
dbdxst_fetchall_arrayref(SV *sth, SV *slice, SV *batch_row_count)
|
|
Packit Service |
b125fd |
{
|
|
Packit Service |
b125fd |
dTHX;
|
|
Packit Service |
b125fd |
D_imp_sth(sth);
|
|
Packit Service |
b125fd |
SV *rows_rvav;
|
|
Packit Service |
b125fd |
if (SvOK(slice)) { /* should never get here */
|
|
Packit Service |
b125fd |
char errmsg[99];
|
|
Packit Service |
b125fd |
sprintf(errmsg,"slice param not supported by XS version of fetchall_arrayref");
|
|
Packit Service |
b125fd |
DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch);
|
|
Packit Service |
b125fd |
return &PL_sv_undef;
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
else {
|
|
Packit Service |
b125fd |
IV maxrows = SvOK(batch_row_count) ? SvIV(batch_row_count) : -1;
|
|
Packit Service |
b125fd |
AV *fetched_av;
|
|
Packit Service |
b125fd |
AV *rows_av = newAV();
|
|
Packit Service |
b125fd |
if ( !DBIc_ACTIVE(imp_sth) && maxrows>0 ) {
|
|
Packit Service |
b125fd |
/* to simplify application logic we return undef without an error */
|
|
Packit Service |
b125fd |
/* if we've fetched all the rows and called with a batch_row_count */
|
|
Packit Service |
b125fd |
return &PL_sv_undef;
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
av_extend(rows_av, (maxrows>0) ? maxrows : 31);
|
|
Packit Service |
b125fd |
while ( (maxrows < 0 || maxrows-- > 0)
|
|
Packit Service |
b125fd |
&& (fetched_av = dbd_st_fetch(sth, imp_sth))
|
|
Packit Service |
b125fd |
) {
|
|
Packit Service |
b125fd |
AV *copy_row_av = av_make(AvFILL(fetched_av)+1, AvARRAY(fetched_av));
|
|
Packit Service |
b125fd |
av_push(rows_av, newRV_noinc((SV*)copy_row_av));
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
rows_rvav = sv_2mortal(newRV_noinc((SV *)rows_av));
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
return rows_rvav;
|
|
Packit Service |
b125fd |
}
|
|
Packit Service |
b125fd |
#endif
|
|
Packit Service |
b125fd |
|