Add fu->redirect, change $st->row behavior on 0 results, minor fixes
And with this, I have a working rewrite of the manned.org backend into FU. \o/ The $st->row methods are very useful even for queries that may not return anything, so their old behavior was unhelpful. Interestingly enough, the error-on-multiple-rows did catch an actual bug in Manned.org, so I'm keeping that behavior.
This commit is contained in:
parent
fbbaa23842
commit
06e2f950fe
9 changed files with 62 additions and 34 deletions
14
c/pgst.c
14
c/pgst.c
|
|
@ -363,23 +363,23 @@ static SV *fupg_st_val(pTHX_ fupg_st *st) {
|
|||
static I32 fupg_st_rowl(pTHX_ fupg_st *st, I32 ax) {
|
||||
dSP;
|
||||
fupg_st_execute(aTHX_ st);
|
||||
if (PQntuples(st->result) == 0) fu_confess("Invalid use of $st->rowl() on query returning zero rows");
|
||||
if (PQntuples(st->result) > 1) fu_confess("Invalid use of $st->rowl() on query returning more than one row");
|
||||
int nfields = PQntuples(st->result) == 0 ? 0 : st->nfields;
|
||||
if (GIMME_V != G_LIST) {
|
||||
ST(0) = sv_2mortal(newSViv(st->nfields));
|
||||
ST(0) = sv_2mortal(newSViv(nfields));
|
||||
return 1;
|
||||
}
|
||||
(void)POPs;
|
||||
EXTEND(SP, st->nfields);
|
||||
EXTEND(SP, nfields);
|
||||
int i;
|
||||
for (i=0; i<st->nfields; i++) mPUSHs(fupg_st_getval(aTHX_ st, 0, i));
|
||||
return st->nfields;
|
||||
for (i=0; i<nfields; i++) mPUSHs(fupg_st_getval(aTHX_ st, 0, i));
|
||||
return nfields;
|
||||
}
|
||||
|
||||
static SV *fupg_st_rowa(pTHX_ fupg_st *st) {
|
||||
fupg_st_execute(aTHX_ st);
|
||||
if (PQntuples(st->result) == 0) fu_confess("Invalid use of $st->rowl() on query returning zero rows");
|
||||
if (PQntuples(st->result) > 1) fu_confess("Invalid use of $st->rowl() on query returning more than one row");
|
||||
if (PQntuples(st->result) == 0) return &PL_sv_undef;
|
||||
AV *av = st->nfields == 0 ? newAV() : newAV_alloc_x(st->nfields);
|
||||
SV *sv = sv_2mortal(newRV_noinc((SV *)av));
|
||||
int i;
|
||||
|
|
@ -390,8 +390,8 @@ static SV *fupg_st_rowa(pTHX_ fupg_st *st) {
|
|||
static SV *fupg_st_rowh(pTHX_ fupg_st *st) {
|
||||
fupg_st_execute(aTHX_ st);
|
||||
fupg_st_check_dupcols(aTHX_ st, 0);
|
||||
if (PQntuples(st->result) == 0) fu_confess("Invalid use of $st->rowh() on query returning zero rows");
|
||||
if (PQntuples(st->result) > 1) fu_confess("Invalid use of $st->rowh() on query returning more than one row");
|
||||
if (PQntuples(st->result) == 0) return &PL_sv_undef;
|
||||
HV *hv = newHV();
|
||||
SV *sv = sv_2mortal(newRV_noinc((SV *)hv));
|
||||
int i;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue