PApp-SQL

 view release on metacpan or  search on metacpan

SQL.xs  view on Meta::CPAN

      lru_trim ();
    }
}

static GV *sql_exec;
static GV *DBH;

#define newconstpv(str) newSVpvn ((str), sizeof (str))

MODULE = PApp::SQL		PACKAGE = PApp::SQL

PROTOTYPES: DISABLE

BOOT:
{
   struct dbistate_st *dbis = DBIS_PUBLISHED_LVALUE;

   /* this is actually wrong, we should call the check member, apparently */
   assert (dbis->version == DBISTATE_VERSION);
   assert (dbis->xs_version == DBIXS_VERSION);

   tmp_iv = newSViv (0);

   sql_exec = gv_fetchpv ("PApp::SQL::sql_exec", TRUE, SVt_PV);
   DBH      = gv_fetchpv ("PApp::SQL::DBH"     , TRUE, SVt_PV);

   /* apache might BOOT: twice :( */
   if (lru_size)
     lru_cachesize (0);

   lru_init ();
   lru_cachesize (100);
}

void
boot2 (SV *t_str, SV *t_int, SV *t_dbl)
	CODE:
        sql_varchar = newSVsv (t_str);
        sql_integer = newSVsv (t_int);
        sql_double  = newSVsv (t_dbl);

int
cachesize(size = -1)
	int	size
	CODE:
        RETVAL = lru_maxsize;
        lru_cachesize (size);
        OUTPUT:
        RETVAL

void
sql_exec(...)
	ALIAS:
                sql_uexec     = 1
		sql_fetch     = 2
                sql_ufetch    = 3
                sql_fetchall  = 4
                sql_ufetchall = 5
                sql_exists    = 6
                sql_uexists   = 7
	PPCODE:
{
	if (items == 0)
          croak ("Usage: sql_exec [database-handle,] [bind-var-refs,... ] \"sql-statement\", [arguments, ...]");
        else
          {
            int i;
            int arg = 0;
            int bind_first, bind_last;
            int count;
            lru_node *lru;
            SV *dbh = ST(0);
            SV *sth;
            SV *sql;
            SV *execute;
            mc_node *mc;
            STRLEN dc, dd; /* dummy */
            I32 orig_stack = SP - PL_stack_base;

            /* save our arguments against destruction through function calls */
            SP += items;
            
            /* first check wether we should use an explicit db handle */
            if (!is_dbh (dbh))
              {
                /* the next line doesn't work - check why later maybe */
                /* dbh = get_sv ("DBH", FALSE);
                if (!is_dbh (dbh))
                  {*/
                    dbh = GvSV (DBH);
                    if (!is_dbh (dbh))
                      croak ("sql_exec: no $DBH argument and no fallback in $PApp::SQL::DBH");
                      /*croak ("sql_exec: no $DBH found in current package or in PApp::SQL::");
                  }*/
              }
            else
              arg++; /* we consumed one argument */

            /* be more Coro-friendly by keeping a copy, so different threads */
            /* can replace their global handles */
            dbh = sv_2mortal (newSVsv (dbh));

            /* count the remaining references (for bind_columns) */
            bind_first = arg;
            while (items > arg && SvROK (ST(arg)))
              arg++;

            bind_last = arg;

            /* consume the sql-statement itself */
            if (items <= arg)
              croak ("sql_exec: required argument \"sql-statement\" missing");

            if (!SvPOK (ST(arg)))
              croak ("sql_exec: sql-statement must be a string");

            sql = ST(arg); arg++;

            if ((ix & ~1) == 6)
              {
                SV *neu = sv_2mortal (newSVpv ("select count(*) > 0 from ", 0));



( run in 1.321 second using v1.01-cache-2.11-cpan-5511b514fd6 )