| 1 |
|
| /* |
| 2 |
|
| # $Id$ |
| 3 |
|
| # Copyright (c) 2002 Tim Bunce Ireland |
| 4 |
|
| # |
| 5 |
|
| # You may distribute under the terms of either the GNU General Public |
| 6 |
|
| # License or the Artistic License, as specified in the Perl README file. |
| 7 |
|
| */ |
| 8 |
|
| |
| 9 |
|
| |
| 10 |
|
| /* This is really just a workaround for SUPER:: not working right for XS code. |
| 11 |
|
| * It would be better if we setup perl's context so SUPER:: did the right thing |
| 12 |
|
| * (borrowing the relevant magic from pp_entersub in perl pp_hot.c). |
| 13 |
|
| * Then we could just use call_method("SUPER::foo") instead. |
| 14 |
|
| * XXX remember to call SPAGAIN in the calling code after calling this! |
| 15 |
|
| */ |
| 16 |
|
| static SV * |
| 17 |
0 |
| dbixst_bounce_method(char *methname, int params) |
| 18 |
|
| { |
| 19 |
|
| dTHX; |
| 20 |
|
| /* XXX this 'magic' undoes the dMARK embedded in the dXSARGS of our caller */ |
| 21 |
|
| /* so that the dXSARGS below can set things up as they were for our caller */ |
| 22 |
0 |
| void *xxx = PL_markstack_ptr++; |
| 23 |
0 |
| dXSARGS; /* declares sp, ax, mark, items */ |
| 24 |
|
| int i; |
| 25 |
|
| SV *sv; |
| 26 |
0 |
| int debug = 0; |
| 27 |
0 |
| D_imp_xxh(ST(0)); |
| 28 |
0 |
▶ | if (debug >= 3) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (debug >= 3) { |
0 |
0 |
0 |
|
| 29 |
0 |
| PerlIO_printf(DBIc_LOGPIO(imp_xxh), |
| 30 |
|
| " -> %s (trampoline call with %d (%ld) params)\n", methname, params, (long)items); |
| 31 |
|
| PERL_UNUSED_VAR(xxx); |
| 32 |
|
| } |
| 33 |
0 |
▶ | EXTEND(SP, params); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, params); |
0 |
0 |
0 |
| EXTEND(SP, params); |
0 |
0 |
0 |
|
| 34 |
0 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
0 |
0 |
|
| 35 |
0 |
▶ | for (i=0; i < params; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i=0; i < params; ++i) { |
0 |
0 |
0 |
|
| 36 |
0 |
▶ | sv = (i >= items) ? &PL_sv_undef : ST(i); |
Branch: 1 branch
| Branch | True | False | Total |
| sv = (i >= items) ? &PL_sv_undef : ST(i); |
0 |
0 |
0 |
|
| 37 |
0 |
| PUSHs(sv); |
| 38 |
|
| } |
| 39 |
0 |
| PUTBACK; |
| 40 |
0 |
| i = call_method(methname, G_SCALAR); |
| 41 |
0 |
| SPAGAIN; |
| 42 |
0 |
▶ | sv = (i) ? POPs : &PL_sv_undef; |
Branch: 1 branch
| Branch | True | False | Total |
| sv = (i) ? POPs : &PL_sv_undef; |
0 |
0 |
0 |
|
| 43 |
0 |
| PUTBACK; |
| 44 |
0 |
▶ | if (debug >= 3) |
Branch: 1 branch
| Branch | True | False | Total |
| if (debug >= 3) |
0 |
0 |
0 |
|
| 45 |
0 |
| PerlIO_printf(DBIc_LOGPIO(imp_xxh), |
| 46 |
0 |
| " <- %s= %s (trampoline call return)\n", methname, neatsvpv(sv,0)); |
| 47 |
0 |
| return sv; |
| 48 |
|
| } |
| 49 |
|
| |
| 50 |
|
| |
| 51 |
|
| static int |
| 52 |
0 |
| dbdxst_bind_params(SV *sth, imp_sth_t *imp_sth, I32 items, I32 ax) |
| 53 |
|
| { |
| 54 |
|
| /* Handle binding supplied values to placeholders. */ |
| 55 |
|
| /* items = one greater than the number of params */ |
| 56 |
|
| /* ax = ax from calling sub, maybe adjusted to match items */ |
| 57 |
|
| dTHX; |
| 58 |
|
| int i; |
| 59 |
|
| SV *idx; |
| 60 |
0 |
▶ | if (items-1 != DBIc_NUM_PARAMS(imp_sth) |
Branch: 1 branch
| Branch | True | False | Total |
| if (items-1 != DBIc_NUM_PARAMS(imp_sth) |
0 |
0 |
0 |
|
| 61 |
0 |
▶ | && DBIc_NUM_PARAMS(imp_sth) != DBIc_NUM_PARAMS_AT_EXECUTE |
Branch: 1 branch
| Branch | True | False | Total |
| && DBIc_NUM_PARAMS(imp_sth) != DBIc_NUM_PARAMS_AT_EXECUTE |
0 |
0 |
0 |
|
| 62 |
|
| ) { |
| 63 |
|
| char errmsg[99]; |
| 64 |
|
| /* clear any previous ParamValues before error is generated */ |
| 65 |
0 |
| SV **svp = hv_fetchs((HV*)DBIc_MY_H(imp_sth),"ParamValues",FALSE); |
| 66 |
0 |
▶ | if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { |
0 |
0 |
0 |
| if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { |
0 |
0 |
0 |
| if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { |
0 |
0 |
0 |
|
| 67 |
0 |
| HV *hv = (HV*)SvRV(*svp); |
| 68 |
0 |
| hv_clear(hv); |
| 69 |
|
| } |
| 70 |
0 |
| sprintf(errmsg,"called with %d bind variables when %d are needed", |
| 71 |
|
| (int)items-1, DBIc_NUM_PARAMS(imp_sth)); |
| 72 |
0 |
▶ | DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
Branch: 4 branches
| Branch | True | False | Total |
| DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
0 |
0 |
0 |
| DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
0 |
0 |
0 |
| DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
0 |
0 |
0 |
| DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
0 |
0 |
0 |
|
| 73 |
0 |
| return 0; |
| 74 |
|
| } |
| 75 |
0 |
| idx = sv_2mortal(newSViv(0)); |
| 76 |
0 |
▶ | for(i=1; i < items ; ++i) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=1; i < items ; ++i) { |
0 |
0 |
0 |
|
| 77 |
0 |
| SV* value = ST(i); |
| 78 |
0 |
▶ | if (SvGMAGICAL(value)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvGMAGICAL(value)) |
0 |
0 |
0 |
|
| 79 |
0 |
| mg_get(value); /* trigger magic to FETCH the value */ |
| 80 |
0 |
| sv_setiv(idx, i); |
| 81 |
0 |
▶ | if (!dbd_bind_ph(sth, imp_sth, idx, value, 0, Nullsv, FALSE, 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!dbd_bind_ph(sth, imp_sth, idx, value, 0, Nullsv, FALSE, 0)) { |
0 |
0 |
0 |
|
| 82 |
0 |
| return 0; /* dbd_bind_ph already registered error */ |
| 83 |
|
| } |
| 84 |
|
| } |
| 85 |
0 |
| return 1; |
| 86 |
|
| } |
| 87 |
|
| |
| 88 |
|
| #ifndef dbd_fetchall_arrayref |
| 89 |
|
| static SV * |
| 90 |
0 |
| dbdxst_fetchall_arrayref(SV *sth, SV *slice, SV *batch_row_count) |
| 91 |
|
| { |
| 92 |
|
| dTHX; |
| 93 |
0 |
| D_imp_sth(sth); |
| 94 |
|
| SV *rows_rvav; |
| 95 |
0 |
▶ | if (SvOK(slice)) { /* should never get here */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(slice)) { /* should never get here */ |
0 |
0 |
0 |
|
| 96 |
|
| char errmsg[99]; |
| 97 |
0 |
| sprintf(errmsg,"slice param not supported by XS version of fetchall_arrayref"); |
| 98 |
0 |
▶ | DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
Branch: 4 branches
| Branch | True | False | Total |
| DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
0 |
0 |
0 |
| DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
0 |
0 |
0 |
| DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
0 |
0 |
0 |
| DBIh_SET_ERR_CHAR(sth, (imp_xxh_t*)imp_sth, "-1", -1, errmsg, Nullch, Nullch); |
0 |
0 |
0 |
|
| 99 |
0 |
| return &PL_sv_undef; |
| 100 |
|
| } |
| 101 |
|
| else { |
| 102 |
0 |
▶ | IV maxrows = SvOK(batch_row_count) ? SvIV(batch_row_count) : -1; |
Branch: 1 branch
| Branch | True | False | Total |
| IV maxrows = SvOK(batch_row_count) ? SvIV(batch_row_count) : -1; |
0 |
0 |
0 |
|
| 103 |
|
| AV *fetched_av; |
| 104 |
0 |
| AV *rows_av = newAV(); |
| 105 |
0 |
▶ | if ( !DBIc_ACTIVE(imp_sth) && maxrows>0 ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if ( !DBIc_ACTIVE(imp_sth) && maxrows>0 ) { |
0 |
0 |
0 |
| if ( !DBIc_ACTIVE(imp_sth) && maxrows>0 ) { |
0 |
0 |
0 |
|
| 106 |
|
| /* to simplify application logic we return undef without an error */ |
| 107 |
|
| /* if we've fetched all the rows and called with a batch_row_count */ |
| 108 |
0 |
| return &PL_sv_undef; |
| 109 |
|
| } |
| 110 |
0 |
▶ | av_extend(rows_av, (maxrows>0) ? maxrows : 31); |
Branch: 1 branch
| Branch | True | False | Total |
| av_extend(rows_av, (maxrows>0) ? maxrows : 31); |
0 |
0 |
0 |
|
| 111 |
0 |
▶ | while ( (maxrows < 0 || maxrows-- > 0) |
Branch: 1 branch
| Branch | True | False | Total |
| while ( (maxrows < 0 || maxrows-- > 0) |
0 |
0 |
0 |
|
| 112 |
0 |
▶ | && (fetched_av = dbd_st_fetch(sth, imp_sth)) |
Branch: 2 branches
| Branch | True | False | Total |
| && (fetched_av = dbd_st_fetch(sth, imp_sth)) |
0 |
0 |
0 |
| && (fetched_av = dbd_st_fetch(sth, imp_sth)) |
0 |
0 |
0 |
|
| 113 |
|
| ) { |
| 114 |
0 |
| AV *copy_row_av = av_make(AvFILL(fetched_av)+1, AvARRAY(fetched_av)); |
| 115 |
0 |
| av_push(rows_av, newRV_noinc((SV*)copy_row_av)); |
| 116 |
|
| } |
| 117 |
0 |
| rows_rvav = sv_2mortal(newRV_noinc((SV *)rows_av)); |
| 118 |
|
| } |
| 119 |
0 |
| return rows_rvav; |
| 120 |
|
| } |
| 121 |
|
| #endif |
| 122 |
|
| |