[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3-unattended/var/se3/unattended/install/linuxaux/opt/perl/lib/site_perl/5.10.0/i586-linux-thread-multi/auto/DBI/ -> Driver_xst.h (source)

   1  /*
   2  #  $Id: Driver_xst.h 10378 2007-12-06 10:48:17Z timbo $
   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  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      void *xxx = PL_markstack_ptr++;
  23      dXSARGS; /* declares sp, ax, mark, items */
  24      int i;
  25      SV *sv;
  26      int debug = 0;
  27      D_imp_xxh(ST(0));
  28      if (debug >= 3) {
  29      PerlIO_printf(DBIc_LOGPIO(imp_xxh),
  30          "    -> %s (trampoline call with %d (%ld) params)\n", methname, params, (long)items);
  31      xxx = xxx; /* avoid unused var warning */
  32      }
  33      EXTEND(SP, params);
  34      PUSHMARK(SP);
  35      for (i=0; i < params; ++i) {
  36      sv = (i >= items) ? &sv_undef : ST(i);
  37          PUSHs(sv);
  38      }
  39      PUTBACK;
  40      i = perl_call_method(methname, G_SCALAR);
  41      SPAGAIN;
  42      sv = (i) ? POPs : &sv_undef;
  43      PUTBACK;
  44      if (debug >= 3)
  45      PerlIO_printf(DBIc_LOGPIO(imp_xxh),
  46          "    <- %s= %s (trampoline call return)\n", methname, neatsvpv(sv,0));
  47      return sv;
  48  }
  49  
  50  
  51  static int
  52  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      if (items-1 != DBIc_NUM_PARAMS(imp_sth)
  61      && DBIc_NUM_PARAMS(imp_sth) != DBIc_NUM_PARAMS_AT_EXECUTE
  62      ) {
  63      char errmsg[99];
  64      sprintf(errmsg,"called with %d bind variables when %d are needed",
  65          (int)items-1, DBIc_NUM_PARAMS(imp_sth));
  66      sv_setpv(DBIc_ERRSTR(imp_sth), errmsg);
  67      sv_setiv(DBIc_ERR(imp_sth), (IV)-1);
  68      return 0;
  69      }
  70      idx = sv_2mortal(newSViv(0));
  71      for(i=1; i < items ; ++i) {
  72      SV* value = ST(i);
  73      if (SvGMAGICAL(value))
  74          mg_get(value);    /* trigger magic to FETCH the value     */
  75      sv_setiv(idx, i);
  76      if (!dbd_bind_ph(sth, imp_sth, idx, value, 0, Nullsv, FALSE, 0)) {
  77          return 0;    /* dbd_bind_ph already registered error    */
  78      }
  79      }
  80      return 1;
  81  }
  82  
  83  #ifndef dbd_fetchall_arrayref
  84  static SV *
  85  dbdxst_fetchall_arrayref(SV *sth, SV *slice, SV *batch_row_count)
  86  {
  87      dTHX;
  88      D_imp_sth(sth);
  89      SV *rows_rvav;
  90      if (SvOK(slice)) {  /* should never get here */
  91      char errmsg[99];
  92      sprintf(errmsg,"slice param not supported by XS version of fetchall_arrayref");
  93      sv_setpv(DBIc_ERRSTR(imp_sth), errmsg);
  94      sv_setiv(DBIc_ERR(imp_sth), (IV)-1);
  95      return &sv_undef;
  96      }
  97      else {
  98      IV maxrows = SvOK(batch_row_count) ? SvIV(batch_row_count) : -1;
  99      AV *fetched_av;
 100      AV *rows_av = newAV();
 101      if ( !DBIc_ACTIVE(imp_sth) && maxrows>0 ) {
 102          /* to simplify application logic we return undef without an error    */
 103          /* if we've fetched all the rows and called with a batch_row_count    */
 104          return &sv_undef;
 105      }
 106      av_extend(rows_av, (maxrows>0) ? maxrows : 31);
 107      while ( (maxrows < 0 || maxrows-- > 0)
 108          && (fetched_av = dbd_st_fetch(sth, imp_sth))
 109      ) {
 110          AV *copy_row_av = av_make(AvFILL(fetched_av)+1, AvARRAY(fetched_av));
 111          av_push(rows_av, newRV_noinc((SV*)copy_row_av));
 112      }
 113      rows_rvav = sv_2mortal(newRV_noinc((SV *)rows_av));
 114      }
 115      return rows_rvav;
 116  }
 117  #endif
 118  


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1