home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / Driver_xst.h < prev    next >
Encoding:
C/C++ Source or Header  |  2004-02-15  |  3.3 KB  |  109 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.     D_imp_xxh(ST(0));
  20.     if (debug >= 3) {
  21.     PerlIO_printf(DBIc_LOGPIO(imp_xxh),
  22.         "    -> %s (trampoline call with %d (%ld) params)\n", methname, params, (long)items);
  23.     xxx = xxx; /* avoid unused var warning */
  24.     }
  25.     EXTEND(SP, params);
  26.     PUSHMARK(SP);
  27.     for (i=0; i < params; ++i) {
  28.     sv = (i >= items) ? &sv_undef : ST(i);
  29.         PUSHs(sv);
  30.     }
  31.     PUTBACK;
  32.     i = perl_call_method(methname, G_SCALAR);
  33.     SPAGAIN;
  34.     sv = (i) ? POPs : &sv_undef;
  35.     PUTBACK;
  36.     if (debug >= 3)
  37.     PerlIO_printf(DBIc_LOGPIO(imp_xxh),
  38.         "    <- %s= %s (trampoline call return)\n", methname, neatsvpv(sv,0));
  39.     return sv;
  40. }
  41.  
  42.  
  43. static int
  44. dbdxst_bind_params(SV *sth, imp_sth_t *imp_sth, I32 items, I32 ax)
  45. {
  46.     /* Handle binding supplied values to placeholders.        */
  47.     /* items = one greater than the number of params        */
  48.     /* ax = ax from calling sub, maybe adjusted to match items    */
  49.     int i;
  50.     SV *idx;
  51.     if (items-1 != DBIc_NUM_PARAMS(imp_sth)
  52.     && DBIc_NUM_PARAMS(imp_sth) != DBIc_NUM_PARAMS_AT_EXECUTE
  53.     ) {
  54.     char errmsg[99];
  55.     sprintf(errmsg,"called with %d bind variables when %d are needed",
  56.         (int)items-1, DBIc_NUM_PARAMS(imp_sth));
  57.     sv_setpv(DBIc_ERRSTR(imp_sth), errmsg);
  58.     sv_setiv(DBIc_ERR(imp_sth), (IV)-1);
  59.     return 0;
  60.     }
  61.     idx = sv_2mortal(newSViv(0));
  62.     for(i=1; i < items ; ++i) {
  63.     SV* value = ST(i);
  64.     if (SvGMAGICAL(value))
  65.         mg_get(value);    /* trigger magic to FETCH the value     */
  66.     sv_setiv(idx, i);
  67.     if (!dbd_bind_ph(sth, imp_sth, idx, value, 0, Nullsv, FALSE, 0)) {
  68.         return 0;    /* dbd_bind_ph already registered error    */
  69.     }
  70.     }
  71.     return 1;
  72. }
  73.  
  74. #ifndef dbd_fetchall_arrayref
  75. static SV *
  76. dbdxst_fetchall_arrayref(SV *sth, SV *slice, SV *batch_row_count)
  77. {
  78.     D_imp_sth(sth);
  79.     SV *rows_rvav;
  80.     if (SvOK(slice)) {  /* should never get here */
  81.     char errmsg[99];
  82.     sprintf(errmsg,"slice param not supported by XS version of fetchall_arrayref");
  83.     sv_setpv(DBIc_ERRSTR(imp_sth), errmsg);
  84.     sv_setiv(DBIc_ERR(imp_sth), (IV)-1);
  85.     return &sv_undef;
  86.     }
  87.     else {
  88.     IV maxrows = SvOK(batch_row_count) ? SvIV(batch_row_count) : -1;
  89.     AV *fetched_av;
  90.     AV *rows_av = newAV();
  91.     if ( !DBIc_ACTIVE(imp_sth) && maxrows>0 ) {
  92.         /* to simplify application logic we return undef without an error    */
  93.         /* if we've fetched all the rows and called with a batch_row_count    */
  94.         return &sv_undef;
  95.     }
  96.     av_extend(rows_av, (maxrows>0) ? maxrows : 31);
  97.     while ( (maxrows < 0 || maxrows-- > 0)
  98.         && (fetched_av = dbd_st_fetch(sth, imp_sth))
  99.     ) {
  100.         AV *copy_row_av = av_make(AvFILL(fetched_av)+1, AvARRAY(fetched_av));
  101.         av_push(rows_av, newRV_noinc((SV*)copy_row_av));
  102.     }
  103.     rows_rvav = sv_2mortal(newRV_noinc((SV *)rows_av));
  104.     }
  105.     return rows_rvav;
  106. }
  107. #endif
  108.  
  109.