| 1 |
|
| #ifndef DBIL_RUN_H |
| 2 |
|
| #define DBIL_RUN_H |
| 3 |
|
| |
| 4 |
|
| /* Running a DBI statement from C. |
| 5 |
|
| * |
| 6 |
|
| * DBI's prepare/execute/fetch and attribute reads are its Perl API - they |
| 7 |
|
| * cannot be bypassed - so we drive them with call_method under G_EVAL (so a |
| 8 |
|
| * RaiseError croak becomes a clean failure, not a longjmp out of C). This same |
| 9 |
|
| * executor is reused inside the forked pool worker in phase 02. */ |
| 10 |
|
| |
| 11 |
|
| /* When set (inside a pool worker process), statements go through DBI's |
| 12 |
|
| * prepare_cached - statement reuse was the ~5x lever in the DBD::SQLite |
| 13 |
|
| * bench, and a worker re-runs the same SQL constantly. */ |
| 14 |
|
| static int DBIL_PREPARE_CACHED = 0; |
| 15 |
|
| |
| 16 |
|
| /* $h->errstr as a mortal SV (best effort; `fallback` when the driver has |
| 17 |
|
| * nothing to say). Every backend needs this, because DBI's other way of |
| 18 |
|
| * reporting a failure - a false return from do or execute - only becomes a |
| 19 |
|
| * croak when the handle was opened with RaiseError, and a handle the |
| 20 |
|
| * application opened is the application's to configure. */ |
| 21 |
4 |
| static SV *dbil_errstr(pTHX_ SV *h, const char *fallback) { |
| 22 |
4 |
| dSP; int n; SV *r = NULL; |
| 23 |
4 |
▶ | ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
4 |
4 |
|
| 24 |
4 |
▶ | EXTEND(SP, 1); PUSHs(h); PUTBACK; |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); PUSHs(h); PUTBACK; |
0 |
4 |
4 |
|
| 25 |
4 |
| n = call_method("errstr", G_SCALAR | G_EVAL); |
| 26 |
4 |
| SPAGAIN; |
| 27 |
4 |
▶ | if (!SvTRUE(ERRSV) && n > 0) { SV *s = POPs; if (SvOK(s) && SvCUR(s)) r = newSVsv(s); } |
Branch: 5 branches
| Branch | True | False | Total |
| if (!SvTRUE(ERRSV) && n > 0) { SV *s = POPs; if (SvOK(s) && SvCUR(s)) r = newSVsv(s); } |
4 |
0 |
4 |
| if (!SvTRUE(ERRSV) && n > 0) { SV *s = POPs; if (SvOK(s) && SvCUR(s)) r = newSVsv(s); } |
4 |
0 |
4 |
| if (!SvTRUE(ERRSV) && n > 0) { SV *s = POPs; if (SvOK(s) && SvCUR(s)) r = newSVsv(s); } |
4 |
0 |
4 |
| if (!SvTRUE(ERRSV) && n > 0) { SV *s = POPs; if (SvOK(s) && SvCUR(s)) r = newSVsv(s); } |
4 |
0 |
4 |
| if (!SvTRUE(ERRSV) && n > 0) { SV *s = POPs; if (SvOK(s) && SvCUR(s)) r = newSVsv(s); } |
4 |
0 |
4 |
|
| 28 |
0 |
▶ | else if (n > 0) (void)POPs; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (n > 0) (void)POPs; |
0 |
0 |
0 |
|
| 29 |
4 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
4 |
0 |
4 |
|
| 30 |
4 |
▶ | return r ? sv_2mortal(r) : sv_2mortal(newSVpv(fallback, 0)); |
Branch: 1 branch
| Branch | True | False | Total |
| return r ? sv_2mortal(r) : sv_2mortal(newSVpv(fallback, 0)); |
4 |
0 |
4 |
|
| 31 |
|
| } |
| 32 |
|
| |
| 33 |
|
| /* $h->FETCH($attr): read a DBI handle attribute from C. Mortal SV, or NULL. */ |
| 34 |
57 |
| static SV *dbil_h_fetch(pTHX_ SV *h, const char *attr) { |
| 35 |
57 |
| dSP; |
| 36 |
|
| int n; |
| 37 |
57 |
| SV *ret = NULL; |
| 38 |
57 |
▶ | ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
57 |
57 |
|
| 39 |
57 |
▶ | EXTEND(SP, 2); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); |
0 |
57 |
57 |
|
| 40 |
57 |
| PUSHs(h); |
| 41 |
57 |
| mPUSHp(attr, strlen(attr)); |
| 42 |
57 |
| PUTBACK; |
| 43 |
57 |
| n = call_method("FETCH", G_SCALAR | G_EVAL); |
| 44 |
57 |
| SPAGAIN; |
| 45 |
57 |
▶ | if (!SvTRUE(ERRSV) && n > 0) { SV *v = POPs; if (SvOK(v)) ret = newSVsv(v); } |
Branch: 4 branches
| Branch | True | False | Total |
| if (!SvTRUE(ERRSV) && n > 0) { SV *v = POPs; if (SvOK(v)) ret = newSVsv(v); } |
57 |
0 |
57 |
| if (!SvTRUE(ERRSV) && n > 0) { SV *v = POPs; if (SvOK(v)) ret = newSVsv(v); } |
57 |
0 |
57 |
| if (!SvTRUE(ERRSV) && n > 0) { SV *v = POPs; if (SvOK(v)) ret = newSVsv(v); } |
57 |
0 |
57 |
| if (!SvTRUE(ERRSV) && n > 0) { SV *v = POPs; if (SvOK(v)) ret = newSVsv(v); } |
57 |
0 |
57 |
|
| 46 |
0 |
▶ | else if (n > 0) (void)POPs; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (n > 0) (void)POPs; |
0 |
0 |
0 |
|
| 47 |
57 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
57 |
0 |
57 |
|
| 48 |
57 |
▶ | return ret ? sv_2mortal(ret) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| return ret ? sv_2mortal(ret) : NULL; |
57 |
0 |
57 |
|
| 49 |
|
| } |
| 50 |
|
| |
| 51 |
|
| /* Run one statement. is_query!=0 -> SELECT-style (fetchall_arrayref). |
| 52 |
|
| * Returns a mortal result hashref, or NULL with *err (mortal) set: |
| 53 |
|
| * query -> { rows => [ [..], .. ], columns => [ name, .. ] } |
| 54 |
|
| * do -> { rows_affected => N } */ |
| 55 |
8 |
| static SV *dbil_run_dbi(pTHX_ SV *dbh, int is_query, SV *sql, AV *bind, SV **err) { |
| 56 |
8 |
▶ | SSize_t nb = bind ? (av_len(bind) + 1) : 0, i; |
Branch: 1 branch
| Branch | True | False | Total |
| SSize_t nb = bind ? (av_len(bind) + 1) : 0, i; |
8 |
0 |
8 |
|
| 57 |
8 |
| *err = NULL; |
| 58 |
|
| |
| 59 |
8 |
▶ | if (!is_query) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!is_query) { |
5 |
3 |
8 |
|
| 60 |
5 |
| dSP; |
| 61 |
5 |
| int n, failed = 0; |
| 62 |
5 |
| IV rows = 0; |
| 63 |
5 |
▶ | ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
5 |
5 |
|
| 64 |
5 |
▶ | EXTEND(SP, 3 + nb); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, 3 + nb); |
5 |
0 |
5 |
| EXTEND(SP, 3 + nb); |
0 |
5 |
5 |
|
| 65 |
5 |
| PUSHs(dbh); PUSHs(sql); PUSHs(&PL_sv_undef); /* do($sql, \%attr, @bind) */ |
| 66 |
9 |
▶ | for (i = 0; i < nb; i++) { SV **e = av_fetch(bind, i, 0); PUSHs(e && *e ? *e : &PL_sv_undef); } |
Branch: 3 branches
| Branch | True | False | Total |
| for (i = 0; i < nb; i++) { SV **e = av_fetch(bind, i, 0); PUSHs(e && *e ? *e : &PL_sv_undef); } |
4 |
0 |
4 |
| for (i = 0; i < nb; i++) { SV **e = av_fetch(bind, i, 0); PUSHs(e && *e ? *e : &PL_sv_undef); } |
4 |
0 |
4 |
| for (i = 0; i < nb; i++) { SV **e = av_fetch(bind, i, 0); PUSHs(e && *e ? *e : &PL_sv_undef); } |
4 |
5 |
9 |
|
| 67 |
5 |
| PUTBACK; |
| 68 |
5 |
| n = call_method("do", G_SCALAR | G_EVAL); |
| 69 |
5 |
| SPAGAIN; |
| 70 |
5 |
▶ | if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
Branch: 5 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
5 |
0 |
5 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
5 |
5 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
0 |
0 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
0 |
0 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
0 |
0 |
|
| 71 |
|
| /* do returns the row count ("0E0" for none, -1 for unknown) and |
| 72 |
|
| * UNDEF on failure. Without RaiseError that undef is the only word |
| 73 |
|
| * the driver gives, and it used to become rows_affected => 0 and a |
| 74 |
|
| * done future - a constraint violation reported as success. */ |
| 75 |
5 |
▶ | if (n > 0) { SV *r = POPs; if (!SvOK(r)) failed = 1; else rows = SvIV(r); } |
Branch: 2 branches
| Branch | True | False | Total |
| if (n > 0) { SV *r = POPs; if (!SvOK(r)) failed = 1; else rows = SvIV(r); } |
5 |
0 |
5 |
| if (n > 0) { SV *r = POPs; if (!SvOK(r)) failed = 1; else rows = SvIV(r); } |
1 |
4 |
5 |
|
| 76 |
0 |
| else failed = 1; |
| 77 |
5 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
5 |
0 |
5 |
|
| 78 |
5 |
▶ | if (failed) { *err = dbil_errstr(aTHX_ dbh, "do failed"); return NULL; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (failed) { *err = dbil_errstr(aTHX_ dbh, "do failed"); return NULL; } |
1 |
4 |
5 |
|
| 79 |
|
| { |
| 80 |
4 |
| HV *h = newHV(); |
| 81 |
4 |
| (void)hv_stores(h, "rows_affected", newSViv(rows)); |
| 82 |
|
| { /* best-effort insert id: $dbh->last_insert_id (drivers vary) */ |
| 83 |
4 |
| dSP; int n2; SV *lid = NULL; |
| 84 |
4 |
▶ | ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
4 |
4 |
|
| 85 |
4 |
▶ | EXTEND(SP, 5); |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 5); |
0 |
4 |
4 |
|
| 86 |
4 |
| PUSHs(dbh); |
| 87 |
4 |
| PUSHs(&PL_sv_undef); PUSHs(&PL_sv_undef); |
| 88 |
4 |
| PUSHs(&PL_sv_undef); PUSHs(&PL_sv_undef); |
| 89 |
4 |
| PUTBACK; |
| 90 |
4 |
| n2 = call_method("last_insert_id", G_SCALAR | G_EVAL); |
| 91 |
4 |
| SPAGAIN; |
| 92 |
4 |
▶ | if (!SvTRUE(ERRSV) && n2 > 0) { SV *v = POPs; if (SvOK(v)) lid = newSVsv(v); } |
Branch: 4 branches
| Branch | True | False | Total |
| if (!SvTRUE(ERRSV) && n2 > 0) { SV *v = POPs; if (SvOK(v)) lid = newSVsv(v); } |
4 |
0 |
4 |
| if (!SvTRUE(ERRSV) && n2 > 0) { SV *v = POPs; if (SvOK(v)) lid = newSVsv(v); } |
4 |
0 |
4 |
| if (!SvTRUE(ERRSV) && n2 > 0) { SV *v = POPs; if (SvOK(v)) lid = newSVsv(v); } |
4 |
0 |
4 |
| if (!SvTRUE(ERRSV) && n2 > 0) { SV *v = POPs; if (SvOK(v)) lid = newSVsv(v); } |
4 |
0 |
4 |
|
| 93 |
0 |
▶ | else if (n2 > 0) (void)POPs; |
Branch: 1 branch
| Branch | True | False | Total |
| else if (n2 > 0) (void)POPs; |
0 |
0 |
0 |
|
| 94 |
4 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
4 |
0 |
4 |
|
| 95 |
4 |
▶ | if (lid) (void)hv_stores(h, "insert_id", lid); |
Branch: 1 branch
| Branch | True | False | Total |
| if (lid) (void)hv_stores(h, "insert_id", lid); |
4 |
0 |
4 |
|
| 96 |
|
| } |
| 97 |
4 |
| return sv_2mortal(newRV_noinc((SV *)h)); |
| 98 |
|
| } |
| 99 |
|
| } |
| 100 |
|
| else { |
| 101 |
3 |
| SV *sth = NULL; |
| 102 |
3 |
| int failed = 0; |
| 103 |
|
| /* prepare */ |
| 104 |
|
| { |
| 105 |
3 |
| dSP; int n; |
| 106 |
3 |
▶ | ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
3 |
3 |
|
| 107 |
3 |
▶ | EXTEND(SP, 2); PUSHs(dbh); PUSHs(sql); PUTBACK; |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 2); PUSHs(dbh); PUSHs(sql); PUTBACK; |
0 |
3 |
3 |
|
| 108 |
3 |
▶ | n = call_method(DBIL_PREPARE_CACHED ? "prepare_cached" : "prepare", |
Branch: 1 branch
| Branch | True | False | Total |
| n = call_method(DBIL_PREPARE_CACHED ? "prepare_cached" : "prepare", |
0 |
3 |
3 |
|
| 109 |
|
| G_SCALAR | G_EVAL); |
| 110 |
3 |
| SPAGAIN; |
| 111 |
3 |
▶ | if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
Branch: 5 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
3 |
0 |
3 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
3 |
3 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
0 |
0 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
0 |
0 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
0 |
0 |
|
| 112 |
3 |
▶ | if (n > 0) { SV *s = POPs; if (SvROK(s)) sth = SvREFCNT_inc(s); } |
Branch: 2 branches
| Branch | True | False | Total |
| if (n > 0) { SV *s = POPs; if (SvROK(s)) sth = SvREFCNT_inc(s); } |
3 |
0 |
3 |
| if (n > 0) { SV *s = POPs; if (SvROK(s)) sth = SvREFCNT_inc(s); } |
2 |
1 |
3 |
|
| 113 |
3 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
3 |
0 |
3 |
|
| 114 |
|
| } |
| 115 |
|
| /* a prepare that fails on a handle without RaiseError returns undef |
| 116 |
|
| * rather than croaking, and the driver's reason is on the DBH - the |
| 117 |
|
| * same false-return the execute path reads off the STH below */ |
| 118 |
3 |
▶ | if (!sth) { *err = dbil_errstr(aTHX_ dbh, "prepare returned no statement handle"); return NULL; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sth) { *err = dbil_errstr(aTHX_ dbh, "prepare returned no statement handle"); return NULL; } |
1 |
2 |
3 |
|
| 119 |
2 |
| sv_2mortal(sth); |
| 120 |
|
| /* execute */ |
| 121 |
|
| { |
| 122 |
2 |
| dSP; int n; |
| 123 |
2 |
▶ | ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
2 |
2 |
|
| 124 |
2 |
▶ | EXTEND(SP, 1 + nb); PUSHs(sth); |
Branch: 2 branches
| Branch | True | False | Total |
| EXTEND(SP, 1 + nb); PUSHs(sth); |
2 |
0 |
2 |
| EXTEND(SP, 1 + nb); PUSHs(sth); |
0 |
2 |
2 |
|
| 125 |
3 |
▶ | for (i = 0; i < nb; i++) { SV **e = av_fetch(bind, i, 0); PUSHs(e && *e ? *e : &PL_sv_undef); } |
Branch: 3 branches
| Branch | True | False | Total |
| for (i = 0; i < nb; i++) { SV **e = av_fetch(bind, i, 0); PUSHs(e && *e ? *e : &PL_sv_undef); } |
1 |
0 |
1 |
| for (i = 0; i < nb; i++) { SV **e = av_fetch(bind, i, 0); PUSHs(e && *e ? *e : &PL_sv_undef); } |
1 |
0 |
1 |
| for (i = 0; i < nb; i++) { SV **e = av_fetch(bind, i, 0); PUSHs(e && *e ? *e : &PL_sv_undef); } |
1 |
2 |
3 |
|
| 126 |
2 |
| PUTBACK; |
| 127 |
2 |
| n = call_method("execute", G_SCALAR | G_EVAL); |
| 128 |
2 |
| SPAGAIN; |
| 129 |
2 |
▶ | if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
Branch: 5 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
2 |
0 |
2 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
2 |
2 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
0 |
0 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
0 |
0 |
| if (SvTRUE(ERRSV)) { SV *e = newSVsv(ERRSV); if (n > 0) (void)POPs; PUTBACK; FREETMPS; LEAVE; *err = sv_2mortal(e); return NULL; } |
0 |
0 |
0 |
|
| 130 |
|
| /* execute returns true ("0E0" for no rows) or false on failure */ |
| 131 |
2 |
▶ | if (n > 0) { SV *r = POPs; if (!SvTRUE(r)) failed = 1; } |
Branch: 2 branches
| Branch | True | False | Total |
| if (n > 0) { SV *r = POPs; if (!SvTRUE(r)) failed = 1; } |
2 |
0 |
2 |
| if (n > 0) { SV *r = POPs; if (!SvTRUE(r)) failed = 1; } |
1 |
1 |
2 |
|
| 132 |
0 |
| else failed = 1; |
| 133 |
2 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
2 |
0 |
2 |
|
| 134 |
2 |
▶ | if (failed) { *err = dbil_errstr(aTHX_ sth, "execute failed"); return NULL; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (failed) { *err = dbil_errstr(aTHX_ sth, "execute failed"); return NULL; } |
1 |
1 |
2 |
|
| 135 |
|
| } |
| 136 |
|
| { |
| 137 |
1 |
| SV *nfld = dbil_h_fetch(aTHX_ sth, "NUM_OF_FIELDS"); |
| 138 |
1 |
▶ | IV nf = (nfld && SvOK(nfld)) ? SvIV(nfld) : 0; |
Branch: 2 branches
| Branch | True | False | Total |
| IV nf = (nfld && SvOK(nfld)) ? SvIV(nfld) : 0; |
1 |
0 |
1 |
| IV nf = (nfld && SvOK(nfld)) ? SvIV(nfld) : 0; |
1 |
0 |
1 |
|
| 139 |
1 |
| HV *h = newHV(); |
| 140 |
1 |
▶ | if (nf > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (nf > 0) { |
1 |
0 |
1 |
|
| 141 |
1 |
| SV *names = dbil_h_fetch(aTHX_ sth, "NAME"); |
| 142 |
1 |
| SV *fa = NULL; |
| 143 |
|
| { |
| 144 |
1 |
| dSP; int n; |
| 145 |
1 |
▶ | ENTER; SAVETMPS; PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| ENTER; SAVETMPS; PUSHMARK(SP); |
0 |
1 |
1 |
|
| 146 |
1 |
▶ | EXTEND(SP, 1); PUSHs(sth); PUTBACK; |
Branch: 1 branch
| Branch | True | False | Total |
| EXTEND(SP, 1); PUSHs(sth); PUTBACK; |
0 |
1 |
1 |
|
| 147 |
1 |
| n = call_method("fetchall_arrayref", G_SCALAR | G_EVAL); |
| 148 |
1 |
| SPAGAIN; |
| 149 |
1 |
▶ | if (SvTRUE(ERRSV)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (SvTRUE(ERRSV)) { |
1 |
0 |
1 |
| if (SvTRUE(ERRSV)) { |
0 |
1 |
1 |
|
| 150 |
0 |
▶ | SV *e = newSVsv(ERRSV); /* copy before FREETMPS frees mortals */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV *e = newSVsv(ERRSV); /* copy before FREETMPS frees mortals */ |
0 |
0 |
0 |
|
| 151 |
0 |
▶ | if (n > 0) (void)POPs; |
Branch: 1 branch
| Branch | True | False | Total |
| if (n > 0) (void)POPs; |
0 |
0 |
0 |
|
| 152 |
0 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
0 |
0 |
0 |
|
| 153 |
0 |
| SvREFCNT_dec((SV *)h); |
| 154 |
0 |
| *err = sv_2mortal(e); |
| 155 |
0 |
| return NULL; |
| 156 |
|
| } |
| 157 |
1 |
▶ | if (n > 0) { SV *r = POPs; if (SvROK(r)) fa = SvREFCNT_inc(r); } |
Branch: 2 branches
| Branch | True | False | Total |
| if (n > 0) { SV *r = POPs; if (SvROK(r)) fa = SvREFCNT_inc(r); } |
1 |
0 |
1 |
| if (n > 0) { SV *r = POPs; if (SvROK(r)) fa = SvREFCNT_inc(r); } |
1 |
0 |
1 |
|
| 158 |
1 |
▶ | PUTBACK; FREETMPS; LEAVE; |
Branch: 1 branch
| Branch | True | False | Total |
| PUTBACK; FREETMPS; LEAVE; |
1 |
0 |
1 |
|
| 159 |
|
| } |
| 160 |
1 |
▶ | (void)hv_stores(h, "rows", fa ? fa : newRV_noinc((SV *)newAV())); |
Branch: 1 branch
| Branch | True | False | Total |
| (void)hv_stores(h, "rows", fa ? fa : newRV_noinc((SV *)newAV())); |
0 |
1 |
1 |
|
| 161 |
|
| { |
| 162 |
1 |
| AV *cols = newAV(); |
| 163 |
1 |
▶ | if (names && SvROK(names) && SvTYPE(SvRV(names)) == SVt_PVAV) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (names && SvROK(names) && SvTYPE(SvRV(names)) == SVt_PVAV) { |
1 |
0 |
1 |
| if (names && SvROK(names) && SvTYPE(SvRV(names)) == SVt_PVAV) { |
1 |
0 |
1 |
| if (names && SvROK(names) && SvTYPE(SvRV(names)) == SVt_PVAV) { |
1 |
0 |
1 |
|
| 164 |
1 |
| AV *na = (AV *)SvRV(names); |
| 165 |
1 |
| SSize_t j, m = av_len(na) + 1; |
| 166 |
3 |
▶ | for (j = 0; j < m; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < m; j++) { |
2 |
1 |
3 |
|
| 167 |
2 |
| SV **c = av_fetch(na, j, 0); |
| 168 |
2 |
▶ | av_push(cols, (c && *c) ? newSVsv(*c) : newSV(0)); |
Branch: 2 branches
| Branch | True | False | Total |
| av_push(cols, (c && *c) ? newSVsv(*c) : newSV(0)); |
2 |
0 |
2 |
| av_push(cols, (c && *c) ? newSVsv(*c) : newSV(0)); |
2 |
0 |
2 |
|
| 169 |
|
| } |
| 170 |
|
| } |
| 171 |
1 |
| (void)hv_stores(h, "columns", newRV_noinc((SV *)cols)); |
| 172 |
|
| } |
| 173 |
|
| } |
| 174 |
|
| else { |
| 175 |
0 |
| (void)hv_stores(h, "rows", newRV_noinc((SV *)newAV())); |
| 176 |
0 |
| (void)hv_stores(h, "columns", newRV_noinc((SV *)newAV())); |
| 177 |
|
| } |
| 178 |
1 |
| return sv_2mortal(newRV_noinc((SV *)h)); |
| 179 |
|
| } |
| 180 |
|
| } |
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
|
| #endif /* DBIL_RUN_H */ |