DBD-PgSPI
view release on metacpan or search on metacpan
CODE:
D_imp_dbh(dbh);
if ( !DBIc_ACTIVE(imp_dbh) ) {
XSRETURN_YES;
}
/* pre-disconnect checks and tidy-ups */
if (DBIc_CACHED_KIDS(imp_dbh)) {
SvREFCNT_dec(DBIc_CACHED_KIDS(imp_dbh));
DBIc_CACHED_KIDS(imp_dbh) = Nullhv;
}
/* Check for disconnect() being called whilst refs to cursors */
/* still exists. This possibly needs some more thought. */
if (DBIc_ACTIVE_KIDS(imp_dbh) && DBIc_WARN(imp_dbh) && !PL_dirty) {
char *plural = (DBIc_ACTIVE_KIDS(imp_dbh)==1) ? "" : "s";
warn("disconnect(%s) invalidates %d active statement%s. %s",
SvPV(dbh,PL_na), (int)DBIc_ACTIVE_KIDS(imp_dbh), plural,
"Either destroy statement handles or call finish on them before disconnecting.");
}
ST(0) = dbd_db_disconnect(dbh, imp_dbh) ? &PL_sv_yes : &PL_sv_no;
my @ar=$pg_dbh->selectrow_array(''select current_user'');
return $ar[0];
' language 'plperlu';
TODO:
Actual support for prepare. (Currently, SPI_prepare is never done,
instead, on $pg_dbh->execute(), after all parameters are known,
it will execute whole thing as a statement)
Use cursors (portals) for SELECT statements (currently the whole
dataset must be retrieved before it execute() will return).
Support for cursors as input and output values (to be coordinated
with plperl code)
Support for returning rows and sets of rows (lotsa magic).
Support for writing trigger handlers.
BUGS:
Error handling needs _major_ work.
AUTHOR:
sprintf(namebuf, ":p%d", (int)SvIV(ph_namesv));
name = namebuf;
name_len = strlen(name);
}
assert(name != Nullch);
if (SvTYPE(newvalue) > SVt_PVLV) { /* hook for later array logic */
croak("Can't bind a non-scalar value (%s)", neatsvpv(newvalue,0));
}
if (SvROK(newvalue) && !IS_DBI_HANDLE(newvalue)) {
/* dbi handle allowed for cursor variables */
croak("Can't bind a reference (%s)", neatsvpv(newvalue,0));
}
if (is_inout) { /* may allow later */
croak("inout parameters not supported");
}
if (dbis->debug >= 2) {
PerlIO_printf(DBILOGFP, " bind %s <== %s (type %ld", name, neatsvpv(newvalue,0), (long)sql_type);
if (attribs) {
PerlIO_printf(DBILOGFP, ", attribs: %s", neatsvpv(attribs,0));
imp_sth->cur_tuple = 0;
/* XXX: probably we should consider sth closed here. check latest DBD::Pg */
return Nullav; /* we reached the last tuple */
}
tup = imp_sth->tuples[imp_sth->cur_tuple];
tupdesc = imp_sth->tupdesc;
av = DBIS->get_fbav(imp_sth);
num_fields = AvFILL(av)+1;
/* maybe we should use portals and cursor here? maybe later */
for(i = 0; i < num_fields; ++i) {
attdesc = imp_sth->tupdesc->attrs[i];
attname = NameStr(imp_sth->tupdesc->attrs[i]->attname);
attr = heap_getattr(tup, i +1, tupdesc, &isnull);
sv = AvARRAY(av)[i];
if (isnull) {
sv_setsv(sv, &PL_sv_undef);
} else {
( run in 0.503 second using v1.01-cache-2.11-cpan-4d50c553e7e )