home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Driver_xst.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-08-19  |  3.2 KB  |  106 lines

  1. /*
  2. #  $Id: Driver_xst.h,v 1.5 2003/08/20 00:15:24 timbo Exp $
  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. static SV *
  10. dbixst_bounce_method(char *methname, int params)
  11. {
  12.     /* XXX this 'magic' undoes the dMARK embedded in the dXSARGS of our caller    */
  13.     /* so that the dXSARGS below can set things up as they were for our caller    */
  14.     void *xxx = PL_markstack_ptr++;
  15.     dXSARGS; /* declares sp, ax, mark, items */
  16.     int i;
  17.     SV *sv;
  18.     int debug = 0;
  19.     if (debug >= 3) {
  20.     PerlIO_printf(DBILOGFP, "    -> %s (trampoline call with %d (%ld) params)\n", methname, params, (long)items);
  21.     xxx = xxx; /* avoid unused var warning */
  22.     }
  23.     EXTEND(SP, params);
  24.     PUSHMARK(SP);
  25.     for (i=0; i < params; ++i) {
  26.     sv = (i >= items) ? &sv_undef : ST(i);
  27.         PUSHs(sv);
  28.     }
  29.     PUTBACK;
  30.     i = perl_call_method(methname, G_SCALAR);
  31.     SPAGAIN;
  32.     sv = (i) ? POPs : &sv_undef;
  33.     PUTBACK;
  34.     if (debug >= 3)
  35.     PerlIO_printf(DBILOGFP, "    <- %s= %s (trampoline call return)\n", methname, neatsvpv(sv,0));
  36.     return sv;
  37. }
  38.  
  39.  
  40. static int
  41. dbdxst_bind_params(SV *sth, imp_sth_t *imp_sth, I32 items, I32 ax)
  42. {
  43.     /* Handle binding supplied values to placeholders.        */
  44.     /* items = one greater than the number of params        */
  45.     /* ax = ax from calling sub, maybe adjusted to match items    */
  46.     int i;
  47.     SV *idx;
  48.     if (items-1 != DBIc_NUM_PARAMS(imp_sth)
  49.     && DBIc_NUM_PARAMS(imp_sth) != DBIc_NUM_PARAMS_AT_EXECUTE
  50.     ) {
  51.     char errmsg[99];
  52.     sprintf(errmsg,"called with %d bind variables when %d are needed",
  53.         (int)items-1, DBIc_NUM_PARAMS(imp_sth));
  54.     sv_setpv(DBIc_ERRSTR(imp_sth), errmsg);
  55.     sv_setiv(DBIc_ERR(imp_sth), (IV)-1);
  56.     return 0;
  57.     }
  58.     idx = sv_2mortal(newSViv(0));
  59.     for(i=1; i < items ; ++i) {
  60.     SV* value = ST(i);
  61.     if (SvGMAGICAL(value))
  62.         mg_get(value);    /* trigger magic to FETCH the value     */
  63.     sv_setiv(idx, i);
  64.     if (!dbd_bind_ph(sth, imp_sth, idx, value, 0, Nullsv, FALSE, 0)) {
  65.         return 0;    /* dbd_bind_ph already registered error    */
  66.     }
  67.     }
  68.     return 1;
  69. }
  70.  
  71. #ifndef dbd_fetchall_arrayref
  72. static SV *
  73. dbdxst_fetchall_arrayref(SV *sth, SV *slice, SV *batch_row_count)
  74. {
  75.     D_imp_sth(sth);
  76.     SV *rows_rvav;
  77.     if (SvOK(slice)) {  /* should never get here */
  78.     char errmsg[99];
  79.     sprintf(errmsg,"slice param not supported by XS version of fetchall_arrayref");
  80.     sv_setpv(DBIc_ERRSTR(imp_sth), errmsg);
  81.     sv_setiv(DBIc_ERR(imp_sth), (IV)-1);
  82.     return &sv_undef;
  83.     }
  84.     else {
  85.     IV maxrows = SvOK(batch_row_count) ? SvIV(batch_row_count) : -1;
  86.     AV *fetched_av;
  87.     AV *rows_av = newAV();
  88.     if ( !DBIc_ACTIVE(imp_sth) && maxrows>0 ) {
  89.         /* to simplify application logic we return undef without an error    */
  90.         /* if we've fetched all the rows and called with a batch_row_count    */
  91.         return &sv_undef;
  92.     }
  93.     av_extend(rows_av, (maxrows>0) ? maxrows : 31);
  94.     while ( (maxrows < 0 || maxrows-- > 0)
  95.         && (fetched_av = dbd_st_fetch(sth, imp_sth))
  96.     ) {
  97.         AV *copy_row_av = av_make(AvFILL(fetched_av)+1, AvARRAY(fetched_av));
  98.         av_push(rows_av, newRV_noinc((SV*)copy_row_av));
  99.     }
  100.     rows_rvav = sv_2mortal(newRV_noinc((SV *)rows_av));
  101.     }
  102.     return rows_rvav;
  103. }
  104. #endif
  105.  
  106.