DBD-SQLite
view release on metacpan or search on metacpan
dbdimp_virtual_table.inc view on Meta::CPAN
dSP;
int count;
int rc = SQLITE_ERROR;
perl_vtab_init *init_data;
ENTER;
SAVETMPS;
init_data = (perl_vtab_init *)pAux;
/* call the DESTROY_MODULE() method */
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(init_data->perl_class, 0)));
PUTBACK;
count = call_method("DESTROY_MODULE", G_VOID);
SPAGAIN;
SP -= count;
/* free module memory */
SvREFCNT_dec(init_data->dbh);
sqlite3_free((char *)init_data->perl_class);
sqlite3_free(init_data);
PUTBACK;
FREETMPS;
LEAVE;
}
int
sqlite_db_create_module(pTHX_ SV *dbh, const char *name, const char *perl_class)
{
dSP;
D_imp_dbh(dbh);
int count, rc, retval = TRUE;
char *module_ISA;
char *loading_code;
perl_vtab_init *init_data;
ENTER;
SAVETMPS;
if (!DBIc_ACTIVE(imp_dbh)) {
sqlite_error(dbh, -2, "attempt to create module on inactive database handle");
return FALSE;
}
/* load the module if needed */
module_ISA = sqlite3_mprintf("%s::ISA", perl_class);
if (!get_av(module_ISA, 0)) {
loading_code = sqlite3_mprintf("use %s", perl_class);
eval_pv(loading_code, TRUE);
sqlite3_free(loading_code);
}
sqlite3_free(module_ISA);
/* build the init datastructure that will be passed to perl_vt_New() */
init_data = sqlite3_malloc(sizeof(*init_data));
init_data->dbh = newRV(dbh);
sv_rvweaken(init_data->dbh);
init_data->perl_class = sqlite3_mprintf(perl_class);
/* register within sqlite */
rc = sqlite3_create_module_v2( imp_dbh->db,
name,
&perl_vt_Module,
init_data,
sqlite_db_destroy_module_data
);
if ( rc != SQLITE_OK ) {
sqlite_error(dbh, rc, form("sqlite_create_module failed with error %s",
sqlite3_errmsg(imp_dbh->db)));
retval = FALSE;
}
/* call the CREATE_MODULE() method */
PUSHMARK(SP);
XPUSHs(sv_2mortal(newSVpv(perl_class, 0)));
XPUSHs(sv_2mortal(newSVpv(name, 0)));
PUTBACK;
count = call_method("CREATE_MODULE", G_VOID);
SPAGAIN;
SP -= count;
PUTBACK;
FREETMPS;
LEAVE;
return retval;
}
( run in 0.662 second using v1.01-cache-2.11-cpan-39bf76dae61 )