DBI.xs

filter: Statementstmt 84.0% 2237 / 2661 Branchbran 65.9% 1987 / 3012 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.4% 4224 / 5673 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« dbilogstrip.PL ↑ Summary blib/lib/DBI/ProfileSubs.pm »
1 /* vim: ts=8:sw=4:expandtab
2 *
3 * $Id$
4 *
5 * Copyright (c) 2024-2026 DBI Team
6 * Copyright (c) 1994-2024 Tim Bunce Ireland.
7 *
8 * See COPYRIGHT section in DBI.pm for usage and distribution rights.
9 */
10  
11 #define IN_DBI_XS 1 /* see DBIXS.h */
12 #define PERL_NO_GET_CONTEXT
13  
14 #include "DBIXS.h" /* DBI public interface for DBD's written in C */
15  
16 # if (defined(_WIN32) && (! defined(HAS_GETTIMEOFDAY)))
17 #include <sys/timeb.h>
18 # endif
19  
20 /* The XS dispatcher code can optimize calls to XS driver methods,
21 * bypassing the usual call_sv() and argument handling overheads.
22 * Just-in-case it causes problems there's an (undocumented) way
23 * to disable it by setting an env var.
24 */
25 static int use_xsbypass = 1; /* set in dbi_bootinit() */
26  
27 #ifndef CvISXSUB
28 #define CvISXSUB(sv) CvXSUB(sv)
29 #endif
30  
31 #define DBI_MAGIC '~'
32  
33 #define MY_cache_gen(stash) HvMROMETA(stash)->cache_gen
34  
35 /* If the tests fail with errors about 'setlinebuf' then try */
36 /* deleting the lines in the block below except the setvbuf one */
37 #ifndef PerlIO_setlinebuf
38 # ifdef HAS_SETLINEBUF
39 # define PerlIO_setlinebuf(f) setlinebuf(f)
40 # else
41 # ifndef USE_PERLIO
42 # define PerlIO_setlinebuf(f) setvbuf(f, Nullch, _IOLBF, 0)
43 # endif
44 # endif
45 #endif
46  
47 #if (PERL_REVISION == 5)
48 # if (PERL_VERSION < 8) || ((PERL_VERSION == 8) && (PERL_SUBVERSION == 0))
49 # define DBI_save_hv_fetch_ent
50 # endif
51  
52 #endif
53  
54 /* types of method name */
55  
56 typedef enum {
57 methtype_ordinary, /* nothing special about this method name */
58 methtype_DESTROY,
59 methtype_FETCH,
60 methtype_can,
61 methtype_fetch_star, /* fetch*, i.e. fetch() or fetch_...() */
62 methtype_set_err
63 } meth_types;
64  
65  
66 static imp_xxh_t *dbih_getcom _((SV *h));
67 static imp_xxh_t *dbih_getcom2 _((pTHX_ SV *h, MAGIC **mgp));
68 static void dbih_clearcom _((imp_xxh_t *imp_xxh));
69 static int dbih_logmsg _((imp_xxh_t *imp_xxh, const char *fmt, ...));
70 static SV *dbih_make_com _((SV *parent_h, imp_xxh_t *p_imp_xxh, const char *imp_class, STRLEN imp_size, STRLEN extra, SV *copy));
71 static SV *dbih_make_fdsv _((SV *sth, const char *imp_class, STRLEN imp_size, const char *col_name));
72 static AV *dbih_get_fbav _((imp_sth_t *imp_sth));
73 static SV *dbih_event _((SV *h, const char *name, SV*, SV*));
74 static int dbih_set_attr_k _((SV *h, SV *keysv, int dbikey, SV *valuesv));
75 static SV *dbih_get_attr_k _((SV *h, SV *keysv, int dbikey));
76 static int dbih_sth_bind_col _((SV *sth, SV *col, SV *ref, SV *attribs));
77  
78 static int set_err_char _((SV *h, imp_xxh_t *imp_xxh, const char *err_c, IV err_i, const char *errstr, const char *state, const char *method));
79 static int set_err_sv _((SV *h, imp_xxh_t *imp_xxh, SV *err, SV *errstr, SV *state, SV *method));
80 static int quote_type _((int sql_type, int p, int s, int *base_type, void *v));
81 static int sql_type_cast_svpv _((pTHX_ SV *sv, int sql_type, U32 flags, void *v));
82 static I32 dbi_hash _((const char *string, long i));
83 static void dbih_dumphandle _((pTHX_ SV *h, const char *msg, int level));
84 static int dbih_dumpcom _((pTHX_ imp_xxh_t *imp_xxh, const char *msg, int level));
85 static int dbi_ima_free(pTHX_ SV* sv, MAGIC* mg);
86 #if defined(USE_ITHREADS)
87 static int dbi_ima_dup(pTHX_ MAGIC* mg, CLONE_PARAMS *param);
88 #endif
89 char *neatsvpv _((SV *sv, STRLEN maxlen));
90 SV * preparse(SV *dbh, const char *statement, IV ps_return, IV ps_accept, void *foo);
91 static meth_types get_meth_type(const char * const name);
92  
93 struct imp_drh_st { dbih_drc_t com; };
94 struct imp_dbh_st { dbih_dbc_t com; };
95 struct imp_sth_st { dbih_stc_t com; };
96 struct imp_fdh_st { dbih_fdc_t com; };
97  
98 /* identify the type of a method name for dispatch behaviour */
99 /* (should probably be folded into the IMA flags mechanism) */
100  
101 static meth_types
102 36666 get_meth_type(const char * const name)
103 {
104 36666 switch (name[0]) {
105 602 case 'D':
106 602 ▶ if strEQ(name,"DESTROY")
Branch: 1 branch
BranchTrueFalseTotal
if strEQ(name,"DESTROY") 301 301 602
107 301 return methtype_DESTROY;
108 301 break;
109 903 case 'F':
110 903 ▶ if strEQ(name,"FETCH")
Branch: 1 branch
BranchTrueFalseTotal
if strEQ(name,"FETCH") 301 602 903
111 301 return methtype_FETCH;
112 602 break;
113 2408 case 'c':
114 2408 ▶ if strEQ(name,"can")
Branch: 1 branch
BranchTrueFalseTotal
if strEQ(name,"can") 301 2107 2408
115 301 return methtype_can;
116 2107 break;
117 3059 case 'f':
118 3059 ▶ if strnEQ(name,"fetch", 5) /* fetch* */
Branch: 1 branch
BranchTrueFalseTotal
if strnEQ(name,"fetch", 5) /* fetch* */ 2107 952 3059
119 2107 return methtype_fetch_star;
120 952 break;
121 4192 case 's':
122 4192 ▶ if strEQ(name,"set_err")
Branch: 1 branch
BranchTrueFalseTotal
if strEQ(name,"set_err") 301 3891 4192
123 301 return methtype_set_err;
124 3891 break;
125 }
126 33355 return methtype_ordinary;
127 }
128  
129  
130 /* Internal Method Attributes (attached to dispatch methods when installed) */
131 /* NOTE: when adding SVs to dbi_ima_t, update dbi_ima_dup() dbi_ima_free()
132 * to ensure that they are duped and correctly ref-counted */
133  
134 typedef struct dbi_ima_st {
135 U8 minargs;
136 U8 maxargs;
137 IV hidearg;
138 /* method_trace controls tracing of method calls in the dispatcher:
139 - if the current trace flags include a trace flag in method_trace
140 then set trace_level to min(2,trace_level) for duration of the call.
141 - else, if trace_level < (method_trace & DBIc_TRACE_LEVEL_MASK)
142 then don't trace the call
143 */
144 U32 method_trace;
145 const char *usage_msg;
146 U32 flags;
147 meth_types meth_type;
148  
149 /* cached outer to inner method mapping */
150 HV *stash; /* the stash we found the GV in */
151 GV *gv; /* the GV containing the inner sub */
152 U32 generation; /* cache invalidation */
153  
154 } dbi_ima_t;
155  
156 /* These values are embedded in the data passed to install_method */
157 #define IMA_HAS_USAGE 0x00000001 /* check parameter usage */
158 #define IMA_FUNC_REDIRECT 0x00000002 /* is $h->func(..., "method") */
159 #define IMA_KEEP_ERR 0x00000004 /* don't reset err & errstr */
160 #define IMA_KEEP_ERR_SUB 0x00000008 /* '' if in a nested call */
161 #define IMA_NO_TAINT_IN 0x00000010 /* don't check for PL_tainted args */
162 #define IMA_NO_TAINT_OUT 0x00000020 /* don't taint results */
163 #define IMA_COPY_UP_STMT 0x00000040 /* copy sth Statement to dbh */
164 #define IMA_END_WORK 0x00000080 /* method is commit or rollback */
165 #define IMA_STUB 0x00000100 /* donothing eg $dbh->connected */
166 #define IMA_CLEAR_STMT 0x00000200 /* clear Statement before call */
167 #define IMA_UNRELATED_TO_STMT 0x00000400 /* profile as empty Statement */
168 #define IMA_NOT_FOUND_OKAY 0x00000800 /* no error if not found */
169 #define IMA_EXECUTE 0x00001000 /* do/execute: DBIcf_Executed */
170 #define IMA_SHOW_ERR_STMT 0x00002000 /* dbh meth relates to Statement*/
171 #define IMA_HIDE_ERR_PARAMVALUES 0x00004000 /* ParamValues are not relevant */
172 #define IMA_IS_FACTORY 0x00008000 /* new h ie connect and prepare */
173 #define IMA_CLEAR_CACHED_KIDS 0x00010000 /* clear CachedKids before call */
174  
175 #define DBIc_STATE_adjust(imp_xxh, state) \
176 (SvOK(state) /* SQLSTATE is implemented by driver */ \
177 ? (strEQ(SvPV_nolen(state),"00000") ? &PL_sv_no : sv_mortalcopy(state))\
178 : (SvTRUE(DBIc_ERR(imp_xxh)) \
179 ? sv_2mortal(newSVpvs("S1000")) /* General error */ \
180 : &PL_sv_no) /* Success ("00000") */ \
181 )
182  
183 #define DBI_LAST_HANDLE g_dbi_last_h /* special fake inner handle */
184 #define DBI_IS_LAST_HANDLE(h) ((DBI_LAST_HANDLE) == SvRV(h))
185 #define DBI_SET_LAST_HANDLE(h) ((DBI_LAST_HANDLE) = SvRV(h))
186 #define DBI_UNSET_LAST_HANDLE ((DBI_LAST_HANDLE) = &PL_sv_undef)
187 #define DBI_LAST_HANDLE_OK ((DBI_LAST_HANDLE) != &PL_sv_undef)
188  
189 #define DBIS_TRACE_LEVEL (DBIS->debug & DBIc_TRACE_LEVEL_MASK)
190 #define DBIS_TRACE_FLAGS (DBIS->debug) /* includes level */
191  
192 #ifdef PERL_LONG_MAX
193 #define MAX_LongReadLen PERL_LONG_MAX
194 #else
195 #define MAX_LongReadLen 2147483647L
196 #endif
197  
198 #ifdef DBI_USE_THREADS
199 static char *dbi_build_opt = "-ithread";
200 #else
201 static char *dbi_build_opt = "-nothread";
202 #endif
203  
204 /* 32 bit magic FNV-0 and FNV-1 prime */
205 #define FNV_32_PRIME ((UV)0x01000193)
206  
207  
208 /* perl doesn't know anything about the dbi_ima_t struct attached to the
209 * CvXSUBANY(cv).any_ptr slot, so add some magic to the CV to handle
210 * duping and freeing.
211 */
212  
213 static MGVTBL dbi_ima_vtbl = { 0, 0, 0, 0, dbi_ima_free,
214 0,
215 #if defined(USE_ITHREADS)
216 dbi_ima_dup
217 #else
218 0
219 #endif
220 #if (PERL_REVISION == 5)
221 # if (PERL_VERSION > 8) || ((PERL_VERSION == 8) && (PERL_SUBVERSION >= 9))
222 , 0
223 # endif
224 #endif
225 };
226  
227 0 static int dbi_ima_free(pTHX_ SV* sv, PERL_UNUSED_DECL MAGIC* mg)
228 {
229 0 dbi_ima_t *ima = (dbi_ima_t *)(CvXSUBANY((CV*)sv).any_ptr);
230 0 SvREFCNT_dec(ima->stash);
231 0 SvREFCNT_dec(ima->gv);
232 0 Safefree(ima);
233 0 return 0;
234 }
235  
236 #if defined(USE_ITHREADS)
237 static int dbi_ima_dup(pTHX_ MAGIC* mg, CLONE_PARAMS *param)
238 {
239 dbi_ima_t *ima, *nima;
240 CV *cv = (CV*) mg->mg_ptr;
241 CV *ncv = (CV*)ptr_table_fetch(PL_ptr_table, (cv));
242  
243 PERL_UNUSED_VAR(param);
244 mg->mg_ptr = (char *)ncv;
245 ima = (dbi_ima_t*) CvXSUBANY(cv).any_ptr;
246 Newx(nima, 1, dbi_ima_t);
247 *nima = *ima; /* structure copy */
248 CvXSUBANY(ncv).any_ptr = nima;
249 nima->stash = NULL;
250 nima->gv = NULL;
251 return 0;
252 }
253 #endif
254  
255  
256  
257 /* --- make DBI safe for multiple perl interpreters --- */
258 /* Originally contributed by Murray Nesbitt of ActiveState, */
259 /* but later updated to use MY_CTX */
260  
261 #define MY_CXT_KEY "DBI::_guts" XS_VERSION
262  
263 typedef struct {
264 SV *dbi_last_h; /* maybe better moved into dbistate_t? */
265 dbistate_t* dbi_state;
266 } my_cxt_t;
267  
268 START_MY_CXT
269  
270 #undef DBIS
271 #define DBIS (MY_CXT.dbi_state)
272  
273 #define g_dbi_last_h (MY_CXT.dbi_last_h)
274  
275 /* allow the 'static' dbi_state struct to be accessed from other files */
276 dbistate_t**
277 0 _dbi_state_lval(pTHX)
278 {
279 dMY_CXT;
280 0 return &(MY_CXT.dbi_state);
281 }
282  
283  
284 /* --- */
285  
286 static void *
287 16254 malloc_using_sv(STRLEN len)
288 {
289 dTHX;
290 16254 ▶ SV *sv = newSV(len ? len : 1);
Branch: 1 branch
BranchTrueFalseTotal
SV *sv = newSV(len ? len : 1); 16254 0 16254
291 16254 void *p = SvPVX(sv);
292 16254 memzero(p, len);
293 16254 return p;
294 }
295  
296 static char *
297 15953 savepv_using_sv(char *str)
298 {
299 15953 char *buf = malloc_using_sv(strlen(str));
300 15953 strcpy(buf, str);
301 15953 return buf;
302 }
303  
304  
305 /* --- support functions for concat_hash_sorted --- */
306  
307 typedef struct str_uv_sort_pair_st {
308 char *key;
309 UV numeric;
310 } str_uv_sort_pair_t;
311  
312 static int
313 36272 _cmp_number(const void *val1, const void *val2)
314 {
315 36272 UV first = ((str_uv_sort_pair_t *)val1)->numeric;
316 36272 UV second = ((str_uv_sort_pair_t *)val2)->numeric;
317  
318 36272 ▶ if (first > second)
Branch: 1 branch
BranchTrueFalseTotal
if (first > second) 18275 17997 36272
319 18275 return 1;
320 17997 ▶ if (first < second)
Branch: 1 branch
BranchTrueFalseTotal
if (first < second) 17937 60 17997
321 17937 return -1;
322 /* only likely to reach here if numeric sort forced for non-numeric keys */
323 /* fallback to comparing the key strings */
324 60 return strcmp(
325 60 ((str_uv_sort_pair_t *)val1)->key,
326 60 ((str_uv_sort_pair_t *)val2)->key
327 );
328 }
329  
330 static int
331 52011 _cmp_str (const void *val1, const void *val2)
332 {
333 52011 return strcmp( *(char **)val1, *(char **)val2);
334 }
335  
336 static char **
337 3317 _sort_hash_keys (HV *hash, int num_sort, STRLEN *total_length)
338 {
339 dTHX;
340 I32 hv_len, key_len;
341 HE *entry;
342 char **keys;
343 3317 unsigned int idx = 0;
344 3317 STRLEN tot_len = 0;
345 3317 bool has_non_numerics = 0;
346 str_uv_sort_pair_t *numbers;
347  
348 3317 hv_len = hv_iterinit(hash);
349 3317 ▶ if (!hv_len)
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_len) 8 3309 3317
350 8 return 0;
351  
352 3309 Newz(0, keys, hv_len, char *);
353 3309 Newz(0, numbers, hv_len, str_uv_sort_pair_t);
354  
355 34237 ▶ while ((entry = hv_iternext(hash))) {
Branch: 1 branch
BranchTrueFalseTotal
while ((entry = hv_iternext(hash))) { 30928 3309 34237
356 30928 *(keys+idx) = hv_iterkey(entry, &key_len);
357 30928 tot_len += key_len;
358
359 30928 ▶ if (grok_number(*(keys+idx), key_len, &(numbers+idx)->numeric) != IS_NUMBER_IN_UV) {
Branch: 1 branch
BranchTrueFalseTotal
if (grok_number(*(keys+idx), key_len, &(numbers+idx)->numeric) != IS_NUMBER_IN_UV) { 26512 4416 30928
360 26512 has_non_numerics = 1;
361 26512 (numbers+idx)->numeric = 0;
362 }
363  
364 30928 (numbers+idx)->key = *(keys+idx);
365 30928 ++idx;
366 }
367  
368 3309 ▶ if (total_length)
Branch: 1 branch
BranchTrueFalseTotal
if (total_length) 3309 0 3309
369 3309 *total_length = tot_len;
370  
371 3309 ▶ if (num_sort < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (num_sort < 0) 42 3267 3309
372 42 num_sort = (has_non_numerics) ? 0 : 1;
373  
374 3309 ▶ if (!num_sort) {
Branch: 1 branch
BranchTrueFalseTotal
if (!num_sort) { 3267 42 3309
375 3267 qsort(keys, hv_len, sizeof(char*), _cmp_str);
376 }
377 else {
378 42 qsort(numbers, hv_len, sizeof(str_uv_sort_pair_t), _cmp_number);
379 4430 ▶ for (idx = 0; idx < hv_len; ++idx)
Branch: 1 branch
BranchTrueFalseTotal
for (idx = 0; idx < hv_len; ++idx) 4388 42 4430
380 4388 *(keys+idx) = (numbers+idx)->key;
381 }
382  
383 3309 Safefree(numbers);
384 3309 return keys;
385 }
386  
387  
388 static SV *
389 3317 _join_hash_sorted(HV *hash, char *kv_sep, STRLEN kv_sep_len, char *pair_sep, STRLEN pair_sep_len, int use_neat, int num_sort)
390 {
391 dTHX;
392 I32 hv_len;
393 3317 STRLEN total_len = 0;
394 char **keys;
395 3317 unsigned int i = 0;
396 SV *return_sv;
397  
398 3317 keys = _sort_hash_keys(hash, num_sort, &total_len);
399 3317 ▶ if (!keys)
Branch: 1 branch
BranchTrueFalseTotal
if (!keys) 8 3309 3317
400 8 return newSVpvs("");
401  
402 3309 ▶ if (!kv_sep_len)
Branch: 1 branch
BranchTrueFalseTotal
if (!kv_sep_len) 0 3309 3309
403 0 kv_sep_len = strlen(kv_sep);
404 3309 ▶ if (!pair_sep_len)
Branch: 1 branch
BranchTrueFalseTotal
if (!pair_sep_len) 0 3309 3309
405 0 pair_sep_len = strlen(pair_sep);
406  
407 3309 hv_len = hv_iterinit(hash);
408 /* total_len += Separators + quotes + term null */
409 3309 total_len += kv_sep_len*hv_len + pair_sep_len*hv_len+2*hv_len+1;
410 3309 return_sv = newSV(total_len);
411 3309 sv_setpv(return_sv, ""); /* quell undef warnings */
412  
413 34237 ▶ for (i=0; i<hv_len; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<hv_len; ++i) { 30928 3309 34237
414 30928 SV **hash_svp = hv_fetch(hash, keys[i], strlen(keys[i]), 0);
415  
416 30928 sv_catpv(return_sv, keys[i]); /* XXX keys can't contain nul chars */
417 30928 sv_catpvn(return_sv, kv_sep, kv_sep_len);
418  
419 30928 ▶ if (!hash_svp) { /* should never happen */
Branch: 1 branch
BranchTrueFalseTotal
if (!hash_svp) { /* should never happen */ 0 30928 30928
420 0 warn("No hash entry with key '%s'", keys[i]);
421 0 sv_catpvs(return_sv, "???");
422 0 continue;
423 }
424  
425 30928 ▶ if (use_neat) {
Branch: 1 branch
BranchTrueFalseTotal
if (use_neat) { 4412 26516 30928
426 4412 sv_catpv(return_sv, neatsvpv(*hash_svp,0));
427 }
428 else {
429 26516 ▶ if (SvOK(*hash_svp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(*hash_svp)) { 19757 6759 26516
430 STRLEN hv_val_len;
431 19757 char *hv_val = SvPV(*hash_svp, hv_val_len);
432 19757 sv_catpvs(return_sv, "'");
433 19757 sv_catpvn(return_sv, hv_val, hv_val_len);
434 19757 sv_catpvs(return_sv, "'");
435 }
436 6759 else sv_catpvs(return_sv, "undef");
437 }
438  
439 30928 ▶ if (i < hv_len-1)
Branch: 1 branch
BranchTrueFalseTotal
if (i < hv_len-1) 27619 3309 30928
440 27619 sv_catpvn(return_sv, pair_sep, pair_sep_len);
441 }
442  
443 3309 Safefree(keys);
444  
445 3309 return return_sv;
446 }
447  
448  
449  
450 /* handy for embedding into condition expression for debugging */
451 /*
452 static int warn1(char *s) { warn("%s", s); return 1; }
453 static int dump1(SV *sv) { dTHX; sv_dump(sv); return 1; }
454 */
455  
456  
457 /* --- */
458  
459 static void
460 0 check_version(const char *name, int dbis_cv, int dbis_cs, int need_dbixs_cv, int drc_s,
461 int dbc_s, int stc_s, int fdc_s)
462 {
463 dTHX;
464 dMY_CXT;
465 static const char msg[] = "you probably need to rebuild the DBD driver (or possibly the DBI)";
466 (void)need_dbixs_cv;
467 0 ▶ if (dbis_cv != DBISTATE_VERSION || dbis_cs != sizeof(*DBIS))
Branch: 2 branches
BranchTrueFalseTotal
if (dbis_cv != DBISTATE_VERSION || dbis_cs != sizeof(*DBIS)) 0 0 0
if (dbis_cv != DBISTATE_VERSION || dbis_cs != sizeof(*DBIS)) 0 0 0
468 0 croak("DBI/DBD internal version mismatch (DBI is v%d/s%lu, DBD %s expected v%d/s%d) %s.\n",
469 DBISTATE_VERSION, (long unsigned int)sizeof(*DBIS), name, dbis_cv, dbis_cs, msg);
470 /* Catch structure size changes - We should probably force a recompile if the DBI */
471 /* runtime version is different from the build time. That would be harsh but safe. */
472 0 ▶ if (drc_s != sizeof(dbih_drc_t) || dbc_s != sizeof(dbih_dbc_t) ||
Branch: 3 branches
BranchTrueFalseTotal
if (drc_s != sizeof(dbih_drc_t) || dbc_s != sizeof(dbih_dbc_t) || 0 0 0
if (drc_s != sizeof(dbih_drc_t) || dbc_s != sizeof(dbih_dbc_t) || 0 0 0
if (drc_s != sizeof(dbih_drc_t) || dbc_s != sizeof(dbih_dbc_t) || 0 0 0
473 0 ▶ stc_s != sizeof(dbih_stc_t) || fdc_s != sizeof(dbih_fdc_t) )
Branch: 1 branch
BranchTrueFalseTotal
stc_s != sizeof(dbih_stc_t) || fdc_s != sizeof(dbih_fdc_t) ) 0 0 0
474 0 croak("%s (dr:%d/%ld, db:%d/%ld, st:%d/%ld, fd:%d/%ld), %s.\n",
475 "DBI/DBD internal structure mismatch",
476 drc_s, (long)sizeof(dbih_drc_t), dbc_s, (long)sizeof(dbih_dbc_t),
477 stc_s, (long)sizeof(dbih_stc_t), fdc_s, (long)sizeof(dbih_fdc_t), msg);
478 0 }
479  
480 static void
481 301 dbi_bootinit(dbistate_t * parent_dbis)
482 {
483 dTHX;
484 dMY_CXT;
485 dbistate_t* DBISx;
486  
487 301 DBISx = (struct dbistate_st*)malloc_using_sv(sizeof(struct dbistate_st));
488 301 DBIS = DBISx;
489  
490 /* make DBIS available to DBD modules the "old" (<= 1.618) way,
491 * so that unrecompiled DBD's will still work against a newer DBI */
492 301 sv_setiv(get_sv("DBI::_dbistate", GV_ADDMULTI),
493 PTR2IV(MY_CXT.dbi_state));
494  
495 /* store version and size so we can spot DBI/DBD version mismatch */
496 301 DBIS->check_version = check_version;
497 301 DBIS->version = DBISTATE_VERSION;
498 301 DBIS->size = sizeof(*DBIS);
499 301 DBIS->xs_version = DBIXS_VERSION;
500  
501 301 DBIS->logmsg = dbih_logmsg;
502 301 DBIS->logfp = PerlIO_stderr();
503 602 ▶ DBIS->debug = (parent_dbis) ? parent_dbis->debug
Branch: 1 branch
BranchTrueFalseTotal
DBIS->debug = (parent_dbis) ? parent_dbis->debug 0 301 301
504 301 : SvIV(get_sv("DBI::dbi_debug",0x5));
505 301 DBIS->neatsvpvlen = (parent_dbis) ? parent_dbis->neatsvpvlen
506 301 ▶ : get_sv("DBI::neat_maxlen", GV_ADDMULTI);
Branch: 1 branch
BranchTrueFalseTotal
: get_sv("DBI::neat_maxlen", GV_ADDMULTI); 0 301 301
507 #ifdef DBI_USE_THREADS
508 DBIS->thr_owner = PERL_GET_THX;
509 #endif
510  
511 /* store some function pointers so DBD's can call our functions */
512 301 DBIS->getcom = dbih_getcom;
513 301 DBIS->clearcom = dbih_clearcom;
514 301 DBIS->event = dbih_event;
515 301 DBIS->set_attr_k = dbih_set_attr_k;
516 301 DBIS->get_attr_k = dbih_get_attr_k;
517 301 DBIS->get_fbav = dbih_get_fbav;
518 301 DBIS->make_fdsv = dbih_make_fdsv;
519 301 DBIS->neat_svpv = neatsvpv;
520 301 DBIS->bind_as_num = quote_type; /* XXX deprecated */
521 301 DBIS->hash = dbi_hash;
522 301 DBIS->set_err_sv = set_err_sv;
523 301 DBIS->set_err_char= set_err_char;
524 301 DBIS->bind_col = dbih_sth_bind_col;
525 301 DBIS->sql_type_cast_svpv = sql_type_cast_svpv;
526  
527  
528 /* Remember the last handle used. BEWARE! Sneaky stuff here! */
529 /* We want a handle reference but we don't want to increment */
530 /* the handle's reference count and we don't want perl to try */
531 /* to destroy it during global destruction. Take care! */
532 301 DBI_UNSET_LAST_HANDLE; /* ensure setup the correct way */
533  
534 /* trick to avoid 'possible typo' warnings */
535 301 gv_fetchpv("DBI::state", GV_ADDMULTI, SVt_PV);
536 301 gv_fetchpv("DBI::err", GV_ADDMULTI, SVt_PV);
537 301 gv_fetchpv("DBI::errstr", GV_ADDMULTI, SVt_PV);
538 301 gv_fetchpv("DBI::lasth", GV_ADDMULTI, SVt_PV);
539 301 gv_fetchpv("DBI::rows", GV_ADDMULTI, SVt_PV);
540  
541 /* we only need to check the env var on the initial boot
542 * which is handy because it can core dump during CLONE on windows
543 */
544 301 ▶ if (!parent_dbis && getenv("PERL_DBI_XSBYPASS"))
Branch: 2 branches
BranchTrueFalseTotal
if (!parent_dbis && getenv("PERL_DBI_XSBYPASS")) 301 0 301
if (!parent_dbis && getenv("PERL_DBI_XSBYPASS")) 0 301 301
545 0 use_xsbypass = atoi(getenv("PERL_DBI_XSBYPASS"));
546 301 }
547  
548  
549 /* ----------------------------------------------------------------- */
550 /* Utility functions */
551  
552  
553 static char *
554 60 dbih_htype_name(int htype)
555 {
556 60 switch(htype) {
557 3 case DBIt_DR: return "dr";
558 11 case DBIt_DB: return "db";
559 46 case DBIt_ST: return "st";
560 0 case DBIt_FD: return "fd";
561 0 default: return "??";
562 }
563 }
564  
565  
566 char *
567 5996 neatsvpv(SV *sv, STRLEN maxlen) /* return a tidy ascii value, for debugging only */
568 {
569 dTHX;
570 dMY_CXT;
571 STRLEN len;
572 5996 SV *nsv = Nullsv;
573 5996 SV *infosv = Nullsv;
574 char *v, *quote;
575  
576 /* We take care not to alter the supplied sv in any way at all. */
577 /* (but if it is SvGMAGICAL we have to call mg_get and that can */
578 /* have side effects, especially as it may be called twice overall.) */
579  
580 5996 ▶ if (!sv)
Branch: 1 branch
BranchTrueFalseTotal
if (!sv) 3 5993 5996
581 3 return "Null!"; /* should never happen */
582  
583 /* try to do the right thing with magical values */
584 5993 ▶ if (SvMAGICAL(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvMAGICAL(sv)) { 97 5896 5993
585 97 ▶ if (DBIS_TRACE_LEVEL >= 5) { /* add magic details to help debugging */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIS_TRACE_LEVEL >= 5) { /* add magic details to help debugging */ 33 64 97
586 MAGIC* mg;
587 33 infosv = sv_2mortal(newSVpvs(" (magic-"));
588 33 ▶ if (SvSMAGICAL(sv)) sv_catpvs(infosv, "s");
Branch: 1 branch
BranchTrueFalseTotal
if (SvSMAGICAL(sv)) sv_catpvs(infosv, "s"); 0 33 33
589 33 ▶ if (SvGMAGICAL(sv)) sv_catpvs(infosv, "g");
Branch: 1 branch
BranchTrueFalseTotal
if (SvGMAGICAL(sv)) sv_catpvs(infosv, "g"); 0 33 33
590 33 ▶ if (SvRMAGICAL(sv)) sv_catpvs(infosv, "r");
Branch: 1 branch
BranchTrueFalseTotal
if (SvRMAGICAL(sv)) sv_catpvs(infosv, "r"); 33 0 33
591 33 sv_catpvs(infosv, ":");
592 66 ▶ for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic)
Branch: 1 branch
BranchTrueFalseTotal
for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) 33 33 66
593 33 sv_catpvn(infosv, &mg->mg_type, 1);
594 33 sv_catpvs(infosv, ")");
595 }
596 97 ▶ if (SvGMAGICAL(sv) && !PL_dirty)
Branch: 2 branches
BranchTrueFalseTotal
if (SvGMAGICAL(sv) && !PL_dirty) 36 61 97
if (SvGMAGICAL(sv) && !PL_dirty) 36 0 36
597 36 mg_get(sv); /* trigger magic to FETCH the value */
598 }
599  
600 5993 ▶ if (!SvOK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(sv)) { 4455 1538 5993
601 4455 ▶ if (SvTYPE(sv) >= SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(sv) >= SVt_PVAV) 12 4443 4455
602 12 return (char *)sv_reftype(sv,0); /* raw AV/HV etc, not via a ref */
603 4443 ▶ if (!infosv)
Branch: 1 branch
BranchTrueFalseTotal
if (!infosv) 4434 9 4443
604 4434 return "undef";
605 9 sv_insert(infosv, 0,0, "undef",5);
606 9 return SvPVX(infosv);
607 }
608  
609 1538 ▶ if (SvNIOK(sv)) { /* is a numeric value - so no surrounding quotes */
Branch: 1 branch
BranchTrueFalseTotal
if (SvNIOK(sv)) { /* is a numeric value - so no surrounding quotes */ 357 1181 1538
610 357 ▶ if (SvPOK(sv)) { /* already has string version of the value, so use it */
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(sv)) { /* already has string version of the value, so use it */ 122 235 357
611 122 v = SvPV(sv,len);
612 122 ▶ if (len == 0) { v="''"; len=2; } /* catch &sv_no style special case */
Branch: 1 branch
BranchTrueFalseTotal
if (len == 0) { v="''"; len=2; } /* catch &sv_no style special case */ 47 75 122
613 122 ▶ if (!infosv)
Branch: 1 branch
BranchTrueFalseTotal
if (!infosv) 122 0 122
614 122 return v;
615 0 sv_insert(infosv, 0,0, v, len);
616 0 return SvPVX(infosv);
617 }
618 /* we don't use SvPV here since we don't want to alter sv in _any_ way */
619 235 ▶ if (SvUOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvUOK(sv)) 0 235 235
620 0 nsv = newSVpvf("%"UVuf, SvUVX(sv));
621 235 ▶ else if (SvIOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
else if (SvIOK(sv)) 222 13 235
622 222 nsv = newSVpvf("%"IVdf, SvIVX(sv));
623 13 else nsv = newSVpvf("%"NVgf, SvNVX(sv));
624 235 ▶ if (infosv)
Branch: 1 branch
BranchTrueFalseTotal
if (infosv) 6 229 235
625 6 sv_catsv(nsv, infosv);
626 235 return SvPVX(sv_2mortal(nsv));
627 }
628  
629 1181 nsv = sv_newmortal();
630 1181 sv_upgrade(nsv, SVt_PV);
631  
632 1181 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 445 736 1181
633 445 ▶ if (!SvAMAGIC(sv)) /* (un-amagic'd) refs get no special treatment */
Branch: 3 branches
BranchTrueFalseTotal
if (!SvAMAGIC(sv)) /* (un-amagic'd) refs get no special treatment */ 445 0 445
if (!SvAMAGIC(sv)) /* (un-amagic'd) refs get no special treatment */ 326 119 445
if (!SvAMAGIC(sv)) /* (un-amagic'd) refs get no special treatment */ 319 7 326
634 438 v = SvPV(sv,len);
635 else {
636 /* handle Overload magic refs */
637 7 (void)SvAMAGIC_off(sv); /* should really be done via local scoping */
638 7 v = SvPV(sv,len); /* XXX how does this relate to SvGMAGIC? */
639 7 SvAMAGIC_on(sv);
640 }
641 445 sv_setpvn(nsv, v, len);
642 445 ▶ if (infosv)
Branch: 1 branch
BranchTrueFalseTotal
if (infosv) 3 442 445
643 3 sv_catsv(nsv, infosv);
644 445 return SvPV(nsv, len);
645 }
646  
647 736 ▶ if (SvPOK(sv)) /* usual simple string case */
Branch: 1 branch
BranchTrueFalseTotal
if (SvPOK(sv)) /* usual simple string case */ 736 0 736
648 736 v = SvPV(sv,len);
649 else /* handles all else via sv_2pv() */
650 0 v = SvPV(sv,len); /* XXX how does this relate to SvGMAGIC? */
651  
652 /* for strings we limit the length and translate codes */
653 736 ▶ if (maxlen == 0)
Branch: 1 branch
BranchTrueFalseTotal
if (maxlen == 0) 629 107 736
654 629 maxlen = SvIV(DBIS->neatsvpvlen);
655 736 ▶ if (maxlen < 6) /* handle daft values */
Branch: 1 branch
BranchTrueFalseTotal
if (maxlen < 6) /* handle daft values */ 0 736 736
656 0 maxlen = 6;
657 736 maxlen -= 2; /* account for quotes */
658  
659 736 ▶ quote = (SvUTF8(sv)) ? "\"" : "'";
Branch: 1 branch
BranchTrueFalseTotal
quote = (SvUTF8(sv)) ? "\"" : "'"; 0 736 736
660 736 ▶ if (len > maxlen) {
Branch: 1 branch
BranchTrueFalseTotal
if (len > maxlen) { 10 726 736
661 10 ▶ SvGROW(nsv, (1+maxlen+1+1));
Branch: 2 branches
BranchTrueFalseTotal
SvGROW(nsv, (1+maxlen+1+1)); 10 0 10
SvGROW(nsv, (1+maxlen+1+1)); 10 0 10
662 10 sv_setpvn(nsv, quote, 1);
663 10 sv_catpvn(nsv, v, maxlen-3); /* account for three dots */
664 10 sv_catpvs(nsv, "...");
665 } else {
666 726 ▶ SvGROW(nsv, (1+len+1+1));
Branch: 2 branches
BranchTrueFalseTotal
SvGROW(nsv, (1+len+1+1)); 726 0 726
SvGROW(nsv, (1+len+1+1)); 726 0 726
667 726 sv_setpvn(nsv, quote, 1);
668 726 sv_catpvn(nsv, v, len);
669 }
670 736 sv_catpvn(nsv, quote, 1);
671 736 ▶ if (infosv)
Branch: 1 branch
BranchTrueFalseTotal
if (infosv) 6 730 736
672 6 sv_catsv(nsv, infosv);
673 736 v = SvPV(nsv, len);
674 736 ▶ if (!SvUTF8(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvUTF8(sv)) { 736 0 736
675 8939 ▶ while(len-- > 0) { /* cleanup string (map control chars to ascii etc) */
Branch: 1 branch
BranchTrueFalseTotal
while(len-- > 0) { /* cleanup string (map control chars to ascii etc) */ 8203 736 8939
676 8203 const char c = v[len] & 0x7F; /* ignore top bit for multinational chars */
677 8203 ▶ if (!isPRINT(c) && !isSPACE(c))
Branch: 2 branches
BranchTrueFalseTotal
if (!isPRINT(c) && !isSPACE(c)) 9 8194 8203
if (!isPRINT(c) && !isSPACE(c)) 2 7 9
678 2 v[len] = '.';
679 }
680 }
681 736 return v;
682 }
683  
684  
685 static void
686 11483 copy_statement_to_parent(pTHX_ SV *h, imp_xxh_t *imp_xxh)
687 {
688 SV *parent;
689 11483 ▶ if (PL_dirty)
Branch: 1 branch
BranchTrueFalseTotal
if (PL_dirty) 0 11483 11483
690 0 return;
691 11483 parent = DBIc_PARENT_H(imp_xxh);
692 11483 ▶ if (parent && SvROK(parent)) {
Branch: 2 branches
BranchTrueFalseTotal
if (parent && SvROK(parent)) { 11483 0 11483
if (parent && SvROK(parent)) { 11441 42 11483
693 11441 SV *tmp_sv = *hv_fetchs((HV*)SvRV(h), "Statement", 1);
694 11441 ▶ if (SvOK(tmp_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(tmp_sv)) 9832 1609 11441
695 9832 (void)hv_stores((HV*)SvRV(parent), "Statement", SvREFCNT_inc(tmp_sv));
696 }
697 }
698  
699  
700 static int
701 24 set_err_char(SV *h, imp_xxh_t *imp_xxh, const char *err_c, IV err_i, const char *errstr, const char *state, const char *method)
702 {
703 dTHX;
704 char err_buf[28];
705 SV *err_sv, *errstr_sv, *state_sv, *method_sv;
706 24 ▶ if (!err_c) {
Branch: 1 branch
BranchTrueFalseTotal
if (!err_c) { 0 24 24
707 0 sprintf(err_buf, "%ld", (long)err_i);
708 0 err_c = &err_buf[0];
709 }
710 24 ▶ err_sv = (strEQ(err_c,"1")) ? &PL_sv_yes : sv_2mortal(newSVpvn(err_c, strlen(err_c)));
Branch: 1 branch
BranchTrueFalseTotal
err_sv = (strEQ(err_c,"1")) ? &PL_sv_yes : sv_2mortal(newSVpvn(err_c, strlen(err_c))); 0 24 24
711 24 errstr_sv = sv_2mortal(newSVpvn(errstr, strlen(errstr)));
712 24 ▶ state_sv = (state && *state) ? sv_2mortal(newSVpvn(state, strlen(state))) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
state_sv = (state && *state) ? sv_2mortal(newSVpvn(state, strlen(state))) : &PL_sv_undef; 0 24 24
state_sv = (state && *state) ? sv_2mortal(newSVpvn(state, strlen(state))) : &PL_sv_undef; 0 0 0
713 24 ▶ method_sv = (method && *method) ? sv_2mortal(newSVpvn(method, strlen(method))) : &PL_sv_undef;
Branch: 2 branches
BranchTrueFalseTotal
method_sv = (method && *method) ? sv_2mortal(newSVpvn(method, strlen(method))) : &PL_sv_undef; 20 4 24
method_sv = (method && *method) ? sv_2mortal(newSVpvn(method, strlen(method))) : &PL_sv_undef; 20 0 20
714 24 return set_err_sv(h, imp_xxh, err_sv, errstr_sv, state_sv, method_sv);
715 }
716  
717  
718 static int
719 9556 set_err_sv(SV *h, imp_xxh_t *imp_xxh, SV *err, SV *errstr, SV *state, SV *method)
720 {
721 dTHX;
722 SV *h_err;
723 SV *h_errstr;
724 SV *h_state;
725 SV **hook_svp;
726 9556 int err_changed = 0;
727  
728 9556 ▶ if ( DBIc_has(imp_xxh, DBIcf_HandleSetErr)
Branch: 1 branch
BranchTrueFalseTotal
if ( DBIc_has(imp_xxh, DBIcf_HandleSetErr) 38 9518 9556
729 38 ▶ && (hook_svp = hv_fetchs((HV*)SvRV(h),"HandleSetErr",0))
Branch: 1 branch
BranchTrueFalseTotal
&& (hook_svp = hv_fetchs((HV*)SvRV(h),"HandleSetErr",0)) 38 0 38
730 38 ▶ && hook_svp
Branch: 1 branch
BranchTrueFalseTotal
&& hook_svp 38 0 38
731 38 ▶ && ((void)(SvGMAGICAL(*hook_svp) && mg_get(*hook_svp)), SvOK(*hook_svp))
Branch: 3 branches
BranchTrueFalseTotal
&& ((void)(SvGMAGICAL(*hook_svp) && mg_get(*hook_svp)), SvOK(*hook_svp)) 0 38 38
&& ((void)(SvGMAGICAL(*hook_svp) && mg_get(*hook_svp)), SvOK(*hook_svp)) 0 0 0
&& ((void)(SvGMAGICAL(*hook_svp) && mg_get(*hook_svp)), SvOK(*hook_svp)) 38 0 38
732 36 ) {
733 38 dSP;
734 IV items;
735 SV *response_sv;
736 38 ▶ if (SvREADONLY(err)) err = sv_mortalcopy(err);
Branch: 1 branch
BranchTrueFalseTotal
if (SvREADONLY(err)) err = sv_mortalcopy(err); 36 2 38
737 38 ▶ if (SvREADONLY(errstr)) errstr = sv_mortalcopy(errstr);
Branch: 1 branch
BranchTrueFalseTotal
if (SvREADONLY(errstr)) errstr = sv_mortalcopy(errstr); 36 2 38
738 38 ▶ if (SvREADONLY(state)) state = sv_mortalcopy(state);
Branch: 1 branch
BranchTrueFalseTotal
if (SvREADONLY(state)) state = sv_mortalcopy(state); 38 0 38
739 38 ▶ if (SvREADONLY(method)) method = sv_mortalcopy(method);
Branch: 1 branch
BranchTrueFalseTotal
if (SvREADONLY(method)) method = sv_mortalcopy(method); 0 38 38
740 38 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) 0 38 38
741 0 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," -> HandleSetErr(%s, err=%s, errstr=%s, state=%s, %s)\n",
742 neatsvpv(h,0), neatsvpv(err,0), neatsvpv(errstr,0), neatsvpv(state,0),
743 neatsvpv(method,0)
744 );
745 38 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 38 38
746 38 ▶ mXPUSHs(newRV_inc((SV*)DBIc_MY_H(imp_xxh)));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newRV_inc((SV*)DBIc_MY_H(imp_xxh))); 0 38 38
747 38 ▶ XPUSHs(err);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(err); 0 38 38
748 38 ▶ XPUSHs(errstr);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(errstr); 0 38 38
749 38 ▶ XPUSHs(state);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(state); 0 38 38
750 38 ▶ XPUSHs(method);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(method); 0 38 38
751 38 PUTBACK;
752 38 items = call_sv(*hook_svp, G_SCALAR);
753 38 SPAGAIN;
754 38 ▶ response_sv = (items) ? POPs : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
response_sv = (items) ? POPs : &PL_sv_undef; 38 0 38
755 38 PUTBACK;
756 38 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 1)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 1) 0 38 38
757 0 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," <- HandleSetErr= %s (err=%s, errstr=%s, state=%s, %s)\n",
758 neatsvpv(response_sv,0), neatsvpv(err,0), neatsvpv(errstr,0), neatsvpv(state,0),
759 neatsvpv(method,0)
760 );
761 38 ▶ if (SvTRUE(response_sv)) /* handler says it has handled it, so... */
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(response_sv)) /* handler says it has handled it, so... */ 2 36 38
762 2 return 0;
763 }
764 else {
765 9518 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2) 4 9514 9518
766 4 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," -- HandleSetErr err=%s, errstr=%s, state=%s, %s\n",
767 neatsvpv(err,0), neatsvpv(errstr,0), neatsvpv(state,0), neatsvpv(method,0)
768 );
769 }
770  
771 9554 ▶ if (!SvOK(err)) { /* clear err / errstr / state */
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(err)) { /* clear err / errstr / state */ 6142 3412 9554
772 6142 ▶ DBIh_CLEAR_ERROR(imp_xxh);
Branch: 12 branches
BranchTrueFalseTotal
DBIh_CLEAR_ERROR(imp_xxh); 0 6142 6142
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 6142 6142
DBIh_CLEAR_ERROR(imp_xxh); 0 6142 6142
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 6142 6142
DBIh_CLEAR_ERROR(imp_xxh); 0 6142 6142
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 6142 6142
773 6142 return 1;
774 }
775  
776 /* fetch these after calling HandleSetErr */
777 3412 h_err = DBIc_ERR(imp_xxh);
778 3412 h_errstr = DBIc_ERRSTR(imp_xxh);
779 3412 h_state = DBIc_STATE(imp_xxh);
780  
781 3412 ▶ if (SvTRUE(h_errstr)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(h_errstr)) { 27 3385 3412
782 /* append current err, if any, to errstr if it's going to change */
783 55 ▶ if (SvTRUE(h_err) && SvTRUE(err) && strNE(SvPV_nolen(h_err), SvPV_nolen(err)))
Branch: 4 branches
BranchTrueFalseTotal
if (SvTRUE(h_err) && SvTRUE(err) && strNE(SvPV_nolen(h_err), SvPV_nolen(err))) 21 6 27
if (SvTRUE(h_err) && SvTRUE(err) && strNE(SvPV_nolen(h_err), SvPV_nolen(err))) 14 7 21
if (SvTRUE(h_err) && SvTRUE(err) && strNE(SvPV_nolen(h_err), SvPV_nolen(err))) 4 10 14
if (SvTRUE(h_err) && SvTRUE(err) && strNE(SvPV_nolen(h_err), SvPV_nolen(err))) 10 4 14
784 20 ▶ sv_catpvf(h_errstr, " [err was %s now %s]", SvPV_nolen(h_err), SvPV_nolen(err));
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(h_errstr, " [err was %s now %s]", SvPV_nolen(h_err), SvPV_nolen(err)); 4 6 10
785 39 ▶ if (SvTRUE(h_state) && SvTRUE(state) && strNE(SvPV_nolen(h_state), SvPV_nolen(state)))
Branch: 4 branches
BranchTrueFalseTotal
if (SvTRUE(h_state) && SvTRUE(state) && strNE(SvPV_nolen(h_state), SvPV_nolen(state))) 14 13 27
if (SvTRUE(h_state) && SvTRUE(state) && strNE(SvPV_nolen(h_state), SvPV_nolen(state))) 6 8 14
if (SvTRUE(h_state) && SvTRUE(state) && strNE(SvPV_nolen(h_state), SvPV_nolen(state))) 6 0 6
if (SvTRUE(h_state) && SvTRUE(state) && strNE(SvPV_nolen(h_state), SvPV_nolen(state))) 4 2 6
786 8 ▶ sv_catpvf(h_errstr, " [state was %s now %s]", SvPV_nolen(h_state), SvPV_nolen(state));
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(h_errstr, " [state was %s now %s]", SvPV_nolen(h_state), SvPV_nolen(state)); 4 0 4
787 54 ▶ if (strNE(SvPV_nolen(h_errstr), SvPV_nolen(errstr))) {
Branch: 2 branches
BranchTrueFalseTotal
if (strNE(SvPV_nolen(h_errstr), SvPV_nolen(errstr))) { 27 0 27
if (strNE(SvPV_nolen(h_errstr), SvPV_nolen(errstr))) { 25 2 27
788 25 sv_catpvs(h_errstr, "\n");
789 25 sv_catsv(h_errstr, errstr);
790 }
791 }
792 else
793 3385 sv_setsv(h_errstr, errstr);
794  
795 /* SvTRUE(err) > "0" > "" > undef */
796 3412 ▶ if (SvTRUE(err) /* new error: so assign */
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(err) /* new error: so assign */ 49 3363 3412
797 49 ▶ || !SvOK(h_err) /* no existing warn/info: so assign */
Branch: 1 branch
BranchTrueFalseTotal
|| !SvOK(h_err) /* no existing warn/info: so assign */ 12 37 49
798 /* new warn ("0" len 1) > info ("" len 0): so assign */
799 36 ▶ || (SvOK(err) && strlen(SvPV_nolen(err)) > strlen(SvPV_nolen(h_err)))
Branch: 3 branches
BranchTrueFalseTotal
|| (SvOK(err) && strlen(SvPV_nolen(err)) > strlen(SvPV_nolen(h_err))) 12 0 12
|| (SvOK(err) && strlen(SvPV_nolen(err)) > strlen(SvPV_nolen(h_err))) 7 5 12
|| (SvOK(err) && strlen(SvPV_nolen(err)) > strlen(SvPV_nolen(h_err))) 3 9 12
800 ) {
801 3403 sv_setsv(h_err, err);
802 3403 err_changed = 1;
803 3403 ▶ if (SvTRUE(h_err)) /* new error */
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(h_err)) /* new error */ 3363 40 3403
804 3363 ++DBIc_ErrCount(imp_xxh);
805 }
806  
807 3412 ▶ if (err_changed) {
Branch: 1 branch
BranchTrueFalseTotal
if (err_changed) { 3403 9 3412
808 3403 ▶ if (SvTRUE(state)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(state)) { 1506 1897 3403
809 1506 ▶ if (strlen(SvPV_nolen(state)) != 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (strlen(SvPV_nolen(state)) != 5) { 0 1506 1506
810 0 warn("set_err: state (%s) is not a 5 character string, using 'S1000' instead", neatsvpv(state,0));
811 0 sv_setpv(h_state, "S1000");
812 }
813 else
814 1506 sv_setsv(h_state, state);
815 }
816 else
817 1897 ▶ (void)SvOK_off(h_state); /* see DBIc_STATE_adjust */
Branch: 4 branches
BranchTrueFalseTotal
(void)SvOK_off(h_state); /* see DBIc_STATE_adjust */ 0 1897 1897
(void)SvOK_off(h_state); /* see DBIc_STATE_adjust */ 0 0 0
(void)SvOK_off(h_state); /* see DBIc_STATE_adjust */ 0 0 0
(void)SvOK_off(h_state); /* see DBIc_STATE_adjust */ 0 1897 1897
818  
819 /* ensure that the parent's Statement attribute reflects the latest error */
820 /* so that ShowErrorStatement is reliable */
821 3403 copy_statement_to_parent(aTHX_ h, imp_xxh);
822 }
823  
824 3412 return 1;
825 }
826  
827  
828 /* err_hash returns a U32 'hash' value representing the current err 'level'
829 * (err/warn/info) and errstr. It's used by the dispatcher as a way to detect
830 * a new or changed warning during a 'keep err' method like STORE. Always returns >0.
831 * The value is 1 for no err/warn/info and guarantees that err > warn > info.
832 * (It's a bit of a hack but the original approach in 70fe6bd76 using a new
833 * ErrChangeCount attribute would break binary compatibility with drivers.)
834 * The chance that two realistic errstr values would hash the same, even with
835 * only 30 bits, is deemed to small to even bother documenting.
836 */
837 static U32
838 479381 err_hash(pTHX_ imp_xxh_t *imp_xxh)
839 {
840 479381 SV *err_sv = DBIc_ERR(imp_xxh);
841 SV *errstr_sv;
842 479381 I32 hash = 1;
843 479381 ▶ if (SvOK(err_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(err_sv)) { 4744 474637 479381
844 4744 errstr_sv = DBIc_ERRSTR(imp_xxh);
845 4744 ▶ if (SvOK(errstr_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(errstr_sv)) 4744 0 4744
846 4744 hash = -dbi_hash(SvPV_nolen(errstr_sv), 0); /* make positive */
847 0 else hash = 0;
848 4744 hash >>= 1; /* free up extra bit (top bit is already free) */
849 4744 hash |= (SvTRUE(err_sv)) ? 0x80000000 /* err */
850 4994 ▶ : (SvPOK(err_sv) && !SvCUR(err_sv)) ? 0x20000000 /* '' = info */
Branch: 2 branches
BranchTrueFalseTotal
: (SvPOK(err_sv) && !SvCUR(err_sv)) ? 0x20000000 /* '' = info */ 157 4587 4744
: (SvPOK(err_sv) && !SvCUR(err_sv)) ? 0x20000000 /* '' = info */ 84 9 93
851 250 ▶ : 0x40000000;/* 0 or '0' = warn */
Branch: 1 branch
BranchTrueFalseTotal
: 0x40000000;/* 0 or '0' = warn */ 93 64 157
852 }
853 479381 return hash;
854 }
855  
856  
857 static char *
858 9690 mkvname(pTHX_ HV *stash, const char *item, int uplevel) /* construct a variable name */
859 {
860 9690 SV *sv = sv_newmortal();
861 9690 ▶ sv_setpv(sv, HvNAME(stash));
Branch: 6 branches
BranchTrueFalseTotal
sv_setpv(sv, HvNAME(stash)); 9690 0 9690
sv_setpv(sv, HvNAME(stash)); 9690 0 9690
sv_setpv(sv, HvNAME(stash)); 0 9690 9690
sv_setpv(sv, HvNAME(stash)); 0 0 0
sv_setpv(sv, HvNAME(stash)); 9690 0 9690
sv_setpv(sv, HvNAME(stash)); 0 9690 9690
862 9690 ▶ if(uplevel) {
Branch: 1 branch
BranchTrueFalseTotal
if(uplevel) { 0 9690 9690
863 0 ▶ while(SvCUR(sv) && *SvEND(sv)!=':')
Branch: 2 branches
BranchTrueFalseTotal
while(SvCUR(sv) && *SvEND(sv)!=':') 0 0 0
while(SvCUR(sv) && *SvEND(sv)!=':') 0 0 0
864 0 --SvCUR(sv);
865 0 ▶ if (SvCUR(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(sv)) 0 0 0
866 0 --SvCUR(sv);
867 }
868 9690 sv_catpv(sv, "::");
869 9690 sv_catpv(sv, item);
870 9690 return SvPV_nolen(sv);
871 }
872  
873 /* 32 bit magic FNV-0 and FNV-1 prime */
874 #define FNV_32_PRIME ((UV)0x01000193)
875  
876 static I32
877 4754 dbi_hash(const char *key, long type)
878 {
879 4754 ▶ if (type == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (type == 0) { 4750 4 4754
880 4750 STRLEN klen = strlen(key);
881 4750 U32 hash = 0;
882 384968 ▶ while (klen--)
Branch: 1 branch
BranchTrueFalseTotal
while (klen--) 380218 4750 384968
883 380218 hash = hash * 33 + *key++;
884 4750 hash &= 0x7FFFFFFF; /* limit to 31 bits */
885 4750 hash |= 0x40000000; /* set bit 31 */
886 4750 return -(I32)hash; /* return negative int */
887 }
888 4 ▶ else if (type == 1) { /* Fowler/Noll/Vo hash */
Branch: 1 branch
BranchTrueFalseTotal
else if (type == 1) { /* Fowler/Noll/Vo hash */ 4 0 4
889 /* see http://www.isthe.com/chongo/tech/comp/fnv/ */
890 4 U32 hash = 0x811c9dc5;
891 4 const unsigned char *s = (unsigned char *)key; /* unsigned string */
892 20 ▶ while (*s) {
Branch: 1 branch
BranchTrueFalseTotal
while (*s) { 16 4 20
893 /* multiply by the 32 bit FNV magic prime mod 2^32 */
894 16 hash *= FNV_32_PRIME;
895 /* xor the bottom with the current octet */
896 16 hash ^= (U32)*s++;
897 }
898 4 return hash;
899 }
900 0 croak("DBI::hash(%ld): invalid type", type);
901 return 0; /* NOT REACHED */
902 }
903  
904  
905 static int
906 0 dbih_logmsg(imp_xxh_t *imp_xxh, const char *fmt, ...)
907 {
908 dTHX;
909 va_list args;
910 #ifdef I_STDARG
911 0 va_start(args, fmt);
912 #else
913 va_start(args);
914 #endif
915 0 (void) PerlIO_vprintf(DBIc_DBISTATE(imp_xxh)->logfp, fmt, args);
916 0 va_end(args);
917 (void)imp_xxh;
918 0 return 1;
919 }
920  
921 static void
922 40 close_trace_file(pTHX)
923 {
924 dMY_CXT;
925 40 ▶ if (DBILOGFP == PerlIO_stderr() || DBILOGFP == PerlIO_stdout())
Branch: 2 branches
BranchTrueFalseTotal
if (DBILOGFP == PerlIO_stderr() || DBILOGFP == PerlIO_stdout()) 24 16 40
if (DBILOGFP == PerlIO_stderr() || DBILOGFP == PerlIO_stdout()) 6 18 24
926 22 return;
927  
928 18 ▶ if (DBIS->logfp_ref == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIS->logfp_ref == NULL) 8 10 18
929 8 PerlIO_close(DBILOGFP);
930 else {
931 /* DAA dec refcount and discard */
932 10 SvREFCNT_dec(DBIS->logfp_ref);
933 10 DBIS->logfp_ref = NULL;
934 }
935 }
936  
937 static int
938 190 set_trace_file(SV *file)
939 {
940 dTHX;
941 dMY_CXT;
942 const char *filename;
943 190 PerlIO *fp = Nullfp;
944 IO *io;
945  
946 190 ▶ if (!file) /* no arg == no change */
Branch: 1 branch
BranchTrueFalseTotal
if (!file) /* no arg == no change */ 150 40 190
947 150 return 0;
948  
949 /* DAA check for a filehandle */
950 40 ▶ if (SvROK(file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(file)) { 8 32 40
951 8 io = sv_2io(file);
952 8 ▶ if (!io || !(fp = IoOFP(io))) {
Branch: 2 branches
BranchTrueFalseTotal
if (!io || !(fp = IoOFP(io))) { 8 0 8
if (!io || !(fp = IoOFP(io))) { 0 8 8
953 0 warn("DBI trace filehandle is not valid");
954 0 return 0;
955 }
956 8 close_trace_file(aTHX);
957 8 (void)SvREFCNT_inc(io);
958 8 DBIS->logfp_ref = io;
959 }
960 32 ▶ else if (isGV_with_GP(file)) {
Branch: 3 branches
BranchTrueFalseTotal
else if (isGV_with_GP(file)) { 4 28 32
else if (isGV_with_GP(file)) { 0 4 4
else if (isGV_with_GP(file)) { 0 0 0
961 4 ▶ io = GvIO(file);
Branch: 4 branches
BranchTrueFalseTotal
io = GvIO(file); 4 0 4
io = GvIO(file); 0 4 4
io = GvIO(file); 0 0 0
io = GvIO(file); 4 0 4
962 4 ▶ if (!io || !(fp = IoOFP(io))) {
Branch: 2 branches
BranchTrueFalseTotal
if (!io || !(fp = IoOFP(io))) { 4 0 4
if (!io || !(fp = IoOFP(io))) { 0 4 4
963 0 warn("DBI trace filehandle from GLOB is not valid");
964 0 return 0;
965 }
966 4 close_trace_file(aTHX);
967 4 (void)SvREFCNT_inc(io);
968 4 DBIS->logfp_ref = io;
969 }
970 else {
971 52 ▶ filename = (SvOK(file)) ? SvPV_nolen(file) : Nullch;
Branch: 1 branch
BranchTrueFalseTotal
filename = (SvOK(file)) ? SvPV_nolen(file) : Nullch; 24 4 28
972 /* undef arg == reset back to stderr */
973 28 ▶ if (!filename || strEQ(filename,"STDERR")
Branch: 2 branches
BranchTrueFalseTotal
if (!filename || strEQ(filename,"STDERR") 24 4 28
if (!filename || strEQ(filename,"STDERR") 22 2 24
974 22 ▶ || strEQ(filename,"*main::STDERR")) {
Branch: 1 branch
BranchTrueFalseTotal
|| strEQ(filename,"*main::STDERR")) { 0 22 22
975 6 close_trace_file(aTHX);
976 6 DBILOGFP = PerlIO_stderr();
977 6 return 1;
978 }
979 22 ▶ if (strEQ(filename,"STDOUT")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(filename,"STDOUT")) { 12 10 22
980 12 close_trace_file(aTHX);
981 12 DBILOGFP = PerlIO_stdout();
982 12 return 1;
983 }
984 10 fp = PerlIO_open(filename, "a+");
985 10 ▶ if (fp == Nullfp) {
Branch: 1 branch
BranchTrueFalseTotal
if (fp == Nullfp) { 0 10 10
986 0 warn("Can't open trace file %s: %s", filename, Strerror(errno));
987 0 return 0;
988 }
989 10 close_trace_file(aTHX);
990 }
991 22 DBILOGFP = fp;
992 /* if this line causes your compiler or linker to choke */
993 /* then just comment it out, it's not essential. */
994 22 PerlIO_setlinebuf(fp); /* force line buffered output */
995 22 return 1;
996 }
997  
998 static IV
999 190 parse_trace_flags(SV *h, SV *level_sv, IV old_level)
1000 {
1001 dTHX;
1002 IV level;
1003 190 ▶ if (!level_sv || !SvOK(level_sv))
Branch: 2 branches
BranchTrueFalseTotal
if (!level_sv || !SvOK(level_sv)) 190 0 190
if (!level_sv || !SvOK(level_sv)) 46 144 190
1004 46 level = old_level; /* undef: no change */
1005 else
1006 144 ▶ if (SvTRUE(level_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(level_sv)) { 84 60 144
1007 84 ▶ if (looks_like_number(level_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (looks_like_number(level_sv)) 58 26 84
1008 58 level = SvIV(level_sv); /* number: number */
1009 else { /* string: parse it */
1010 26 dSP;
1011 26 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 26 26
1012 26 ▶ XPUSHs(h);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(h); 0 26 26
1013 26 ▶ XPUSHs(level_sv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(level_sv); 0 26 26
1014 26 PUTBACK;
1015 26 ▶ if (call_method("parse_trace_flags", G_SCALAR) != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (call_method("parse_trace_flags", G_SCALAR) != 1) 0 26 26
1016 0 croak("panic: parse_trace_flags");/* should never happen */
1017 26 SPAGAIN;
1018 26 level = POPi;
1019 26 PUTBACK;
1020 }
1021 }
1022 else /* defined but false: 0 */
1023 60 level = 0;
1024 190 return level;
1025 }
1026  
1027  
1028 static int
1029 164 set_trace(SV *h, SV *level_sv, SV *file)
1030 {
1031 dTHX;
1032 164 D_imp_xxh(h);
1033 164 int RETVAL = DBIc_DBISTATE(imp_xxh)->debug; /* Return trace level in effect now */
1034 164 IV level = parse_trace_flags(h, level_sv, RETVAL);
1035 164 set_trace_file(file);
1036 164 ▶ if (level != RETVAL) { /* set value */
Branch: 1 branch
BranchTrueFalseTotal
if (level != RETVAL) { /* set value */ 80 84 164
1037 80 ▶ if ((level & DBIc_TRACE_LEVEL_MASK) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((level & DBIc_TRACE_LEVEL_MASK) > 0) { 8 72 80
1038 8 PerlIO_printf(DBIc_LOGPIO(imp_xxh),
1039 " %s trace level set to 0x%lx/%ld (DBI @ 0x%lx/%ld) in DBI %s%s (pid %d)\n",
1040 neatsvpv(h,0),
1041 (long)(level & DBIc_TRACE_FLAGS_MASK),
1042 (long)(level & DBIc_TRACE_LEVEL_MASK),
1043 8 (long)DBIc_TRACE_FLAGS(imp_xxh), (long)DBIc_TRACE_LEVEL(imp_xxh),
1044 8 XS_VERSION, dbi_build_opt, (int)PerlProc_getpid());
1045 8 ▶ if (!PL_dowarn)
Branch: 1 branch
BranchTrueFalseTotal
if (!PL_dowarn) 0 8 8
1046 0 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," Note: perl is running without the recommended perl -w option\n");
1047 8 PerlIO_flush(DBIc_LOGPIO(imp_xxh));
1048 }
1049 80 sv_setiv(DBIc_DEBUG(imp_xxh), level);
1050 }
1051 164 return RETVAL;
1052 }
1053  
1054  
1055 static SV *
1056 48666 dbih_inner(pTHX_ SV *orv, const char *what)
1057 { /* convert outer to inner handle else croak(what) if what is not NULL */
1058 /* if what is NULL then return NULL for invalid handles */
1059 MAGIC *mg;
1060 SV *ohv; /* outer HV after derefing the RV */
1061 SV *hrv; /* dbi inner handle RV-to-HV */
1062  
1063 /* enable a raw HV (not ref-to-HV) to be passed in, eg DBIc_MY_H */
1064 48666 ▶ ohv = SvROK(orv) ? SvRV(orv) : orv;
Branch: 1 branch
BranchTrueFalseTotal
ohv = SvROK(orv) ? SvRV(orv) : orv; 48290 376 48666
1065  
1066 48666 ▶ if (!ohv || SvTYPE(ohv) != SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (!ohv || SvTYPE(ohv) != SVt_PVHV) { 48666 0 48666
if (!ohv || SvTYPE(ohv) != SVt_PVHV) { 347 48319 48666
1067 347 ▶ if (!what)
Branch: 1 branch
BranchTrueFalseTotal
if (!what) 347 0 347
1068 347 return NULL;
1069 if (1) {
1070 dMY_CXT;
1071 0 ▶ if (DBIS_TRACE_LEVEL)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIS_TRACE_LEVEL) 0 0 0
1072 0 sv_dump(orv);
1073 }
1074 0 ▶ if (!SvOK(orv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(orv)) 0 0 0
1075 0 croak("%s given an undefined handle %s",
1076 what, "(perhaps returned from a previous call which failed)");
1077 0 croak("%s handle %s is not a DBI handle", what, neatsvpv(orv,0));
1078 }
1079 48319 ▶ if (!SvMAGICAL(ohv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvMAGICAL(ohv)) { 6 48313 48319
1080 6 ▶ if (!what)
Branch: 1 branch
BranchTrueFalseTotal
if (!what) 2 4 6
1081 2 return NULL;
1082 4 ▶ if (!hv_fetchs((HV*)ohv,"_NO_DESTRUCT_WARN",0))
Branch: 1 branch
BranchTrueFalseTotal
if (!hv_fetchs((HV*)ohv,"_NO_DESTRUCT_WARN",0)) 0 4 4
1083 0 sv_dump(orv);
1084 4 croak("%s handle %s is not a DBI handle (has no magic)",
1085 what, neatsvpv(orv,0));
1086 }
1087  
1088 48313 ▶ if ( (mg=mg_find(ohv,'P')) == NULL) { /* hash tie magic */
Branch: 1 branch
BranchTrueFalseTotal
if ( (mg=mg_find(ohv,'P')) == NULL) { /* hash tie magic */ 26205 22108 48313
1089 /* not tied, maybe it's already an inner handle... */
1090 26205 ▶ if (mg_find(ohv, DBI_MAGIC) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if (mg_find(ohv, DBI_MAGIC) == NULL) { 0 26205 26205
1091 0 ▶ if (!what)
Branch: 1 branch
BranchTrueFalseTotal
if (!what) 0 0 0
1092 0 return NULL;
1093 0 sv_dump(orv);
1094 0 croak("%s handle %s is not a valid DBI handle",
1095 what, neatsvpv(orv,0));
1096 }
1097 26205 hrv = orv; /* was already a DBI handle inner hash */
1098 }
1099 else {
1100 22108 hrv = mg->mg_obj; /* inner hash of tie */
1101 }
1102  
1103 48313 return hrv;
1104 }
1105  
1106  
1107  
1108 /* -------------------------------------------------------------------- */
1109 /* Functions to manage a DBI handle (magic and attributes etc). */
1110  
1111 static imp_xxh_t *
1112 0 dbih_getcom(SV *hrv) /* used by drivers via DBIS func ptr */
1113 {
1114 MAGIC *mg;
1115 SV *sv;
1116  
1117 /* short-cut common case */
1118 0 ▶ if ( SvROK(hrv)
Branch: 1 branch
BranchTrueFalseTotal
if ( SvROK(hrv) 0 0 0
1119 0 ▶ && (sv = SvRV(hrv))
Branch: 1 branch
BranchTrueFalseTotal
&& (sv = SvRV(hrv)) 0 0 0
1120 0 ▶ && SvRMAGICAL(sv)
Branch: 1 branch
BranchTrueFalseTotal
&& SvRMAGICAL(sv) 0 0 0
1121 0 ▶ && (mg = SvMAGIC(sv))
Branch: 1 branch
BranchTrueFalseTotal
&& (mg = SvMAGIC(sv)) 0 0 0
1122 0 ▶ && mg->mg_type == DBI_MAGIC
Branch: 1 branch
BranchTrueFalseTotal
&& mg->mg_type == DBI_MAGIC 0 0 0
1123 0 ▶ && mg->mg_ptr
Branch: 1 branch
BranchTrueFalseTotal
&& mg->mg_ptr 0 0 0
1124 )
1125 0 return (imp_xxh_t *) mg->mg_ptr;
1126  
1127 {
1128 dTHX;
1129 0 imp_xxh_t *imp_xxh = dbih_getcom2(aTHX_ hrv, 0);
1130 0 ▶ if (!imp_xxh) /* eg after take_imp_data */
Branch: 1 branch
BranchTrueFalseTotal
if (!imp_xxh) /* eg after take_imp_data */ 0 0 0
1131 0 croak("Invalid DBI handle %s, has no dbi_imp_data", neatsvpv(hrv,0));
1132 0 return imp_xxh;
1133 }
1134 }
1135  
1136 static imp_xxh_t *
1137 907939 dbih_getcom2(pTHX_ SV *hrv, MAGIC **mgp) /* Get com struct for handle. Must be fast. */
1138 {
1139 MAGIC *mg;
1140 SV *sv;
1141  
1142 /* important and quick sanity check (esp non-'safe' Oraperl) */
1143 907939 ▶ if (SvROK(hrv)) /* must at least be a ref */
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(hrv)) /* must at least be a ref */ 888559 19380 907939
1144 888559 sv = SvRV(hrv);
1145 else {
1146 dMY_CXT;
1147 19380 ▶ if (hrv == DBI_LAST_HANDLE) /* special for var::FETCH */
Branch: 1 branch
BranchTrueFalseTotal
if (hrv == DBI_LAST_HANDLE) /* special for var::FETCH */ 19374 6 19380
1148 19374 sv = DBI_LAST_HANDLE;
1149 6 ▶ else if (sv_derived_from(hrv, "DBI::common")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (sv_derived_from(hrv, "DBI::common")) { 6 0 6
1150 /* probably a class name, if ref($h)->foo() */
1151 6 return 0;
1152 }
1153 else {
1154 0 sv_dump(hrv);
1155 0 croak("Invalid DBI handle %s", neatsvpv(hrv,0));
1156 sv = &PL_sv_undef; /* avoid "might be used uninitialized" warning */
1157 }
1158 }
1159  
1160 /* Short cut for common case. We assume that a magic var always */
1161 /* has magic and that DBI_MAGIC, if present, will be the first. */
1162 907933 ▶ if (SvRMAGICAL(sv) && (mg=SvMAGIC(sv))->mg_type == DBI_MAGIC) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvRMAGICAL(sv) && (mg=SvMAGIC(sv))->mg_type == DBI_MAGIC) { 907929 4 907933
if (SvRMAGICAL(sv) && (mg=SvMAGIC(sv))->mg_type == DBI_MAGIC) { 895577 12352 907929
1163 /* nothing to do here */
1164 }
1165 else {
1166 /* Validate handle (convert outer to inner if required) */
1167 12356 hrv = dbih_inner(aTHX_ hrv, "dbih_getcom");
1168 12352 mg = mg_find(SvRV(hrv), DBI_MAGIC);
1169 }
1170 907929 ▶ if (mgp) /* let caller pickup magic struct for this handle */
Branch: 1 branch
BranchTrueFalseTotal
if (mgp) /* let caller pickup magic struct for this handle */ 1 907928 907929
1171 1 *mgp = mg;
1172  
1173 907929 ▶ if (!mg) /* may happen during global destruction */
Branch: 1 branch
BranchTrueFalseTotal
if (!mg) /* may happen during global destruction */ 0 907929 907929
1174 0 return (imp_xxh_t *) 0;
1175  
1176 907929 return (imp_xxh_t *) mg->mg_ptr;
1177 }
1178  
1179  
1180 static SV *
1181 85830 dbih_setup_attrib(pTHX_ SV *h, imp_xxh_t *imp_xxh, char *attrib, SV *parent, int read_only, int optional)
1182 {
1183 85830 STRLEN len = strlen(attrib);
1184 SV **asvp;
1185  
1186 85830 ▶ asvp = hv_fetch((HV*)SvRV(h), attrib, len, !optional);
Branch: 1 branch
BranchTrueFalseTotal
asvp = hv_fetch((HV*)SvRV(h), attrib, len, !optional); 48450 37380 85830
1187 /* we assume that we won't have any existing 'undef' attributes here */
1188 /* (or, alternately, we take undef to mean 'copy from parent') */
1189 85830 ▶ if (!(asvp && SvOK(*asvp))) { /* attribute doesn't already exists (the common case) */
Branch: 2 branches
BranchTrueFalseTotal
if (!(asvp && SvOK(*asvp))) { /* attribute doesn't already exists (the common case) */ 48450 37380 85830
if (!(asvp && SvOK(*asvp))) { /* attribute doesn't already exists (the common case) */ 36774 11676 48450
1190 SV **psvp;
1191 74154 ▶ if ((!parent || !SvROK(parent)) && !optional) {
Branch: 3 branches
BranchTrueFalseTotal
if ((!parent || !SvROK(parent)) && !optional) { 74154 0 74154
if ((!parent || !SvROK(parent)) && !optional) { 0 74154 74154
if ((!parent || !SvROK(parent)) && !optional) { 0 0 0
1192 0 croak("dbih_setup_attrib(%s): %s not set and no parent supplied",
1193 neatsvpv(h,0), attrib);
1194 }
1195 74154 psvp = hv_fetch((HV*)SvRV(parent), attrib, len, 0);
1196 74154 ▶ if (psvp) {
Branch: 1 branch
BranchTrueFalseTotal
if (psvp) { 37470 36684 74154
1197 37470 ▶ if (!asvp)
Branch: 1 branch
BranchTrueFalseTotal
if (!asvp) 696 36774 37470
1198 696 asvp = hv_fetch((HV*)SvRV(h), attrib, len, 1);
1199 37470 sv_setsv(*asvp, *psvp); /* copy attribute from parent to handle */
1200 }
1201 else {
1202 36684 ▶ if (!optional)
Branch: 1 branch
BranchTrueFalseTotal
if (!optional) 0 36684 36684
1203 0 croak("dbih_setup_attrib(%s): %s not set and not in parent",
1204 neatsvpv(h,0), attrib);
1205 }
1206 }
1207 85830 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 5) { 27 85803 85830
1208 27 PerlIO *logfp = DBIc_LOGPIO(imp_xxh);
1209 27 PerlIO_printf(logfp," dbih_setup_attrib(%s, %s, %s)",
1210 neatsvpv(h,0), attrib, neatsvpv(parent,0));
1211 27 ▶ if (!asvp)
Branch: 1 branch
BranchTrueFalseTotal
if (!asvp) 12 15 27
1212 12 PerlIO_printf(logfp," undef (not defined)\n");
1213 else
1214 15 ▶ if (SvOK(*asvp))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(*asvp)) 15 0 15
1215 15 PerlIO_printf(logfp," %s (already defined)\n", neatsvpv(*asvp,0));
1216 0 else PerlIO_printf(logfp," %s (copied from parent)\n", neatsvpv(*asvp,0));
1217 }
1218 85830 ▶ if (read_only && asvp)
Branch: 2 branches
BranchTrueFalseTotal
if (read_only && asvp) 29070 56760 85830
if (read_only && asvp) 29070 0 29070
1219 29070 SvREADONLY_on(*asvp);
1220 85830 ▶ return asvp ? *asvp : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
return asvp ? *asvp : &PL_sv_undef; 49146 36684 85830
1221 }
1222  
1223  
1224 static SV *
1225 0 dbih_make_fdsv(SV *sth, const char *imp_class, STRLEN imp_size, const char *col_name)
1226 {
1227 dTHX;
1228 0 D_imp_sth(sth);
1229 0 const STRLEN cn_len = strlen(col_name);
1230 imp_fdh_t *imp_fdh;
1231 SV *fdsv;
1232 0 ▶ if (imp_size < sizeof(imp_fdh_t) || cn_len<10 || strNE("::fd",&col_name[cn_len-4]))
Branch: 3 branches
BranchTrueFalseTotal
if (imp_size < sizeof(imp_fdh_t) || cn_len<10 || strNE("::fd",&col_name[cn_len-4])) 0 0 0
if (imp_size < sizeof(imp_fdh_t) || cn_len<10 || strNE("::fd",&col_name[cn_len-4])) 0 0 0
if (imp_size < sizeof(imp_fdh_t) || cn_len<10 || strNE("::fd",&col_name[cn_len-4])) 0 0 0
1233 0 croak("panic: dbih_makefdsv %s '%s' imp_size %ld invalid",
1234 imp_class, col_name, (long)imp_size);
1235 0 ▶ if (DBIc_TRACE_LEVEL(imp_sth) >= 5)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth) >= 5) 0 0 0
1236 0 PerlIO_printf(DBIc_LOGPIO(imp_sth)," dbih_make_fdsv(%s, %s, %ld, '%s')\n",
1237 neatsvpv(sth,0), imp_class, (long)imp_size, col_name);
1238 0 fdsv = dbih_make_com(sth, (imp_xxh_t*)imp_sth, imp_class, imp_size, cn_len+2, 0);
1239 0 imp_fdh = (imp_fdh_t*)(void*)SvPVX(fdsv);
1240 0 imp_fdh->com.col_name = ((char*)imp_fdh) + imp_size;
1241 0 strcpy(imp_fdh->com.col_name, col_name);
1242 0 return fdsv;
1243 }
1244  
1245  
1246 static SV *
1247 9690 dbih_make_com(SV *p_h, imp_xxh_t *p_imp_xxh, const char *imp_class, STRLEN imp_size, STRLEN extra, SV* imp_templ)
1248 {
1249 dTHX;
1250 static const char *errmsg = "Can't make DBI com handle for %s: %s";
1251 HV *imp_stash;
1252 SV *dbih_imp_sv;
1253 imp_xxh_t *imp;
1254 int trace_level;
1255 PERL_UNUSED_VAR(extra);
1256  
1257 9690 ▶ if ( (imp_stash = gv_stashpv(imp_class, FALSE)) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if ( (imp_stash = gv_stashpv(imp_class, FALSE)) == NULL) 0 9690 9690
1258 0 croak(errmsg, imp_class, "unknown package");
1259  
1260 9690 ▶ if (imp_size == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (imp_size == 0) { 9690 0 9690
1261 /* get size of structure to allocate for common and imp specific data */
1262 9690 const char *imp_size_name = mkvname(aTHX_ imp_stash, "imp_data_size", 0);
1263 9690 imp_size = SvIV(get_sv(imp_size_name, 0x05));
1264 9690 ▶ if (imp_size == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (imp_size == 0) { 9690 0 9690
1265 9690 imp_size = sizeof(imp_sth_t);
1266 9690 ▶ if (sizeof(imp_dbh_t) > imp_size)
Branch: 1 branch
BranchTrueFalseTotal
if (sizeof(imp_dbh_t) > imp_size) 0 9690 9690
1267 0 imp_size = sizeof(imp_dbh_t);
1268 9690 ▶ if (sizeof(imp_drh_t) > imp_size)
Branch: 1 branch
BranchTrueFalseTotal
if (sizeof(imp_drh_t) > imp_size) 0 9690 9690
1269 0 imp_size = sizeof(imp_drh_t);
1270 9690 imp_size += 4;
1271 }
1272 }
1273  
1274 9690 ▶ if (p_imp_xxh) {
Branch: 1 branch
BranchTrueFalseTotal
if (p_imp_xxh) { 9345 345 9690
1275 9345 trace_level = DBIc_TRACE_LEVEL(p_imp_xxh);
1276 }
1277 else {
1278 dMY_CXT;
1279 345 trace_level = DBIS_TRACE_LEVEL;
1280 }
1281 9690 ▶ if (trace_level >= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 5) { 3 9687 9690
1282 dMY_CXT;
1283 3 PerlIO_printf(DBILOGFP," dbih_make_com(%s, %p, %s, %ld, %p) thr#%p\n",
1284 neatsvpv(p_h,0), (void*)p_imp_xxh, imp_class, (long)imp_size, (void*)imp_templ, (void*)PERL_GET_THX);
1285 }
1286  
1287 9690 ▶ if (imp_templ && SvOK(imp_templ)) {
Branch: 2 branches
BranchTrueFalseTotal
if (imp_templ && SvOK(imp_templ)) { 0 9690 9690
if (imp_templ && SvOK(imp_templ)) { 0 0 0
1288 U32 imp_templ_flags;
1289 /* validate the supplied dbi_imp_data looks reasonable, */
1290 0 ▶ if (SvCUR(imp_templ) != imp_size)
Branch: 1 branch
BranchTrueFalseTotal
if (SvCUR(imp_templ) != imp_size) 0 0 0
1291 0 croak("Can't use dbi_imp_data of wrong size (%ld not %ld)",
1292 (long)SvCUR(imp_templ), (long)imp_size);
1293  
1294 /* copy the whole template */
1295 0 dbih_imp_sv = newSVsv(imp_templ);
1296 0 imp = (imp_xxh_t*)(void*)SvPVX(dbih_imp_sv);
1297  
1298 /* sanity checks on the supplied imp_data */
1299 0 ▶ if (DBIc_TYPE(imp) != ((p_imp_xxh) ? DBIc_TYPE(p_imp_xxh)+1 :1) )
Branch: 2 branches
BranchTrueFalseTotal
if (DBIc_TYPE(imp) != ((p_imp_xxh) ? DBIc_TYPE(p_imp_xxh)+1 :1) ) 0 0 0
if (DBIc_TYPE(imp) != ((p_imp_xxh) ? DBIc_TYPE(p_imp_xxh)+1 :1) ) 0 0 0
1300 0 croak("Can't use dbi_imp_data from different type of handle");
1301 0 ▶ if (!DBIc_has(imp, DBIcf_IMPSET))
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIc_has(imp, DBIcf_IMPSET)) 0 0 0
1302 0 croak("Can't use dbi_imp_data that not from a setup handle");
1303  
1304 /* copy flags, zero out our imp_xxh struct, restore some flags */
1305 0 imp_templ_flags = DBIc_FLAGS(imp);
1306 0 ▶ switch ( (p_imp_xxh) ? DBIc_TYPE(p_imp_xxh)+1 : DBIt_DR ) {
Branch: 1 branch
BranchTrueFalseTotal
switch ( (p_imp_xxh) ? DBIc_TYPE(p_imp_xxh)+1 : DBIt_DR ) { 0 0 0
1307 0 case DBIt_DR: memzero((char*)imp, sizeof(imp_drh_t)); break;
1308 0 case DBIt_DB: memzero((char*)imp, sizeof(imp_dbh_t)); break;
1309 0 case DBIt_ST: memzero((char*)imp, sizeof(imp_sth_t)); break;
1310 0 default: croak("dbih_make_com dbi_imp_data bad h type");
1311 }
1312 /* Only pass on DBIcf_IMPSET to indicate to driver that the imp */
1313 /* structure has been copied and it doesn't need to reconnect. */
1314 /* Similarly DBIcf_ACTIVE is also passed along but isn't key. */
1315 0 DBIc_FLAGS(imp) = imp_templ_flags & (DBIcf_IMPSET|DBIcf_ACTIVE);
1316 }
1317 else {
1318 9690 dbih_imp_sv = newSV(imp_size); /* is grown to at least imp_size+1 */
1319 9690 imp = (imp_xxh_t*)(void*)SvPVX(dbih_imp_sv);
1320 9690 memzero((char*)imp, imp_size);
1321 /* set up SV with SvCUR set ready for take_imp_data */
1322 9690 SvCUR_set(dbih_imp_sv, imp_size);
1323 9690 *SvEND(dbih_imp_sv) = '\0';
1324 }
1325  
1326 9690 ▶ if (p_imp_xxh) {
Branch: 1 branch
BranchTrueFalseTotal
if (p_imp_xxh) { 9345 345 9690
1327 9345 DBIc_DBISTATE(imp) = DBIc_DBISTATE(p_imp_xxh);
1328 }
1329 else {
1330 dMY_CXT;
1331 345 DBIc_DBISTATE(imp) = DBIS;
1332 }
1333 9690 DBIc_IMP_STASH(imp) = imp_stash;
1334  
1335 9690 ▶ if (!p_h) { /* only a driver (drh) has no parent */
Branch: 1 branch
BranchTrueFalseTotal
if (!p_h) { /* only a driver (drh) has no parent */ 345 9345 9690
1336 345 DBIc_PARENT_H(imp) = &PL_sv_undef;
1337 345 DBIc_PARENT_COM(imp) = NULL;
1338 345 DBIc_TYPE(imp) = DBIt_DR;
1339 345 DBIc_on(imp,DBIcf_WARN /* set only here, children inherit */
1340 |DBIcf_ACTIVE /* drivers are 'Active' by default */
1341 |DBIcf_AutoCommit /* advisory, driver must manage this */
1342 );
1343 345 DBIc_set(imp, DBIcf_PrintWarn, 1);
1344 }
1345 else {
1346 9345 DBIc_PARENT_H(imp) = (SV*)SvREFCNT_inc(p_h); /* ensure it lives */
1347 9345 DBIc_PARENT_COM(imp) = p_imp_xxh; /* shortcut for speed */
1348 9345 DBIc_TYPE(imp) = DBIc_TYPE(p_imp_xxh) + 1;
1349 /* inherit some flags from parent and carry forward some from template */
1350 9345 DBIc_FLAGS(imp) = (DBIc_FLAGS(p_imp_xxh) & ~DBIcf_INHERITMASK)
1351 9345 | (DBIc_FLAGS(imp) & (DBIcf_IMPSET|DBIcf_ACTIVE));
1352 9345 ++DBIc_KIDS(p_imp_xxh);
1353 }
1354 #ifdef DBI_USE_THREADS
1355 DBIc_THR_USER(imp) = PERL_GET_THX ;
1356 #endif
1357  
1358 9690 ▶ if (DBIc_TYPE(imp) == DBIt_ST) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp) == DBIt_ST) { 6028 3662 9690
1359 6028 imp_sth_t *imp_sth = (imp_sth_t*)imp;
1360 6028 DBIc_ROW_COUNT(imp_sth) = -1;
1361 }
1362  
1363 9690 DBIc_COMSET_on(imp); /* common data now set up */
1364  
1365 /* The implementor should DBIc_IMPSET_on(imp) when setting up */
1366 /* any private data which will need clearing/freeing later. */
1367  
1368 9690 return dbih_imp_sv;
1369 }
1370  
1371  
1372 static void
1373 9692 dbih_setup_handle(pTHX_ SV *orv, char *imp_class, SV *parent, SV *imp_datasv)
1374 {
1375 SV *h;
1376 9692 char *errmsg = "Can't setup DBI handle of %s to %s: %s";
1377 SV *dbih_imp_sv;
1378 SV *dbih_imp_rv;
1379 9692 SV *dbi_imp_data = Nullsv;
1380 SV **svp;
1381 SV *imp_mem_name;
1382 HV *imp_mem_stash;
1383 imp_xxh_t *imp;
1384 imp_xxh_t *parent_imp;
1385 int trace_level;
1386  
1387 9692 h = dbih_inner(aTHX_ orv, "dbih_setup_handle");
1388 9692 parent = dbih_inner(aTHX_ parent, NULL); /* check parent valid (& inner) */
1389 9692 ▶ if (parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (parent) { 9345 347 9692
1390 9345 parent_imp = DBIh_COM(parent);
1391 9345 trace_level = DBIc_TRACE_LEVEL(parent_imp);
1392 }
1393 else {
1394 dMY_CXT;
1395 347 parent_imp = NULL;
1396 347 trace_level = DBIS_TRACE_LEVEL;
1397 }
1398  
1399 9692 ▶ if (trace_level >= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 5) { 3 9689 9692
1400 dMY_CXT;
1401 3 PerlIO_printf(DBILOGFP," dbih_setup_handle(%s=>%s, %s, %lx, %s)\n",
1402 neatsvpv(orv,0), neatsvpv(h,0), imp_class, (long)parent, neatsvpv(imp_datasv,0));
1403 }
1404  
1405 9692 ▶ if (mg_find(SvRV(h), DBI_MAGIC) != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (mg_find(SvRV(h), DBI_MAGIC) != NULL) 0 9692 9692
1406 0 croak(errmsg, neatsvpv(orv,0), imp_class, "already a DBI (or ~magic) handle");
1407  
1408 9692 imp_mem_name = sv_2mortal(newSVpvf("%s_mem", imp_class));
1409 9692 ▶ if ( (imp_mem_stash = gv_stashsv(imp_mem_name, FALSE)) == NULL)
Branch: 1 branch
BranchTrueFalseTotal
if ( (imp_mem_stash = gv_stashsv(imp_mem_name, FALSE)) == NULL) 2 9690 9692
1410 2 croak(errmsg, neatsvpv(orv,0), SvPVbyte_nolen(imp_mem_name), "unknown _mem package");
1411  
1412 9690 ▶ if ((svp = hv_fetchs((HV*)SvRV(h), "dbi_imp_data", 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((svp = hv_fetchs((HV*)SvRV(h), "dbi_imp_data", 0))) { 0 9690 9690
1413 0 dbi_imp_data = *svp;
1414 0 ▶ if (SvGMAGICAL(dbi_imp_data)) /* call FETCH via magic */
Branch: 1 branch
BranchTrueFalseTotal
if (SvGMAGICAL(dbi_imp_data)) /* call FETCH via magic */ 0 0 0
1415 0 mg_get(dbi_imp_data);
1416 }
1417  
1418 DBI_LOCK;
1419  
1420 9690 dbih_imp_sv = dbih_make_com(parent, parent_imp, imp_class, 0, 0, dbi_imp_data);
1421 9690 imp = (imp_xxh_t*)(void*)SvPVX(dbih_imp_sv);
1422  
1423 9690 dbih_imp_rv = newRV_inc(dbih_imp_sv); /* just needed for sv_bless */
1424 9690 sv_bless(dbih_imp_rv, imp_mem_stash);
1425 9690 sv_free(dbih_imp_rv);
1426  
1427 9690 DBIc_MY_H(imp) = (HV*)SvRV(orv); /* take _copy_ of pointer, not new ref */
1428 9690 ▶ DBIc_IMP_DATA(imp) = (imp_datasv) ? newSVsv(imp_datasv) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
DBIc_IMP_DATA(imp) = (imp_datasv) ? newSVsv(imp_datasv) : &PL_sv_undef; 4648 5042 9690
1429 9690 _imp2com(imp, std.pid) = (U32)PerlProc_getpid();
1430  
1431 9690 ▶ if (DBIc_TYPE(imp) <= DBIt_ST) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp) <= DBIt_ST) { 9690 0 9690
1432 SV **tmp_svp;
1433 /* Copy some attributes from parent if not defined locally and */
1434 /* also take address of attributes for speed of direct access. */
1435 /* parent is null for drh, in which case h must hold the values */
1436 #define COPY_PARENT(name,ro,opt) SvREFCNT_inc(dbih_setup_attrib(aTHX_ h,imp,(name),parent,ro,opt))
1437 #define DBIc_ATTR(imp, f) _imp2com(imp, attr.f)
1438 /* XXX we should validate that these are the right type (refs etc) */
1439 9690 DBIc_ATTR(imp, Err) = COPY_PARENT("Err",1,0); /* scalar ref */
1440 9690 DBIc_ATTR(imp, State) = COPY_PARENT("State",1,0); /* scalar ref */
1441 9690 DBIc_ATTR(imp, Errstr) = COPY_PARENT("Errstr",1,0); /* scalar ref */
1442 9690 DBIc_ATTR(imp, TraceLevel)=COPY_PARENT("TraceLevel",0,0);/* scalar (int)*/
1443 9690 DBIc_ATTR(imp, FetchHashKeyName) = COPY_PARENT("FetchHashKeyName",0,0); /* scalar ref */
1444  
1445 9690 ▶ if (parent) {
Branch: 1 branch
BranchTrueFalseTotal
if (parent) { 9345 345 9690
1446 9345 dbih_setup_attrib(aTHX_ h,imp,"HandleSetErr",parent,0,1);
1447 9345 dbih_setup_attrib(aTHX_ h,imp,"HandleError",parent,0,1);
1448 9345 dbih_setup_attrib(aTHX_ h,imp,"ReadOnly",parent,0,1);
1449 9345 dbih_setup_attrib(aTHX_ h,imp,"Profile",parent,0,1);
1450  
1451 /* setup Callbacks from parents' ChildCallbacks */
1452 9345 ▶ if (DBIc_has(parent_imp, DBIcf_Callbacks)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(parent_imp, DBIcf_Callbacks) 1415 7930 9345
1453 1415 ▶ && (tmp_svp = hv_fetchs((HV*)SvRV(parent), "Callbacks", 0))
Branch: 1 branch
BranchTrueFalseTotal
&& (tmp_svp = hv_fetchs((HV*)SvRV(parent), "Callbacks", 0)) 1415 0 1415
1454 1415 ▶ && SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV
Branch: 2 branches
BranchTrueFalseTotal
&& SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV 1415 0 1415
&& SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV 1415 0 1415
1455 1415 ▶ && (tmp_svp = hv_fetchs((HV*)SvRV(*tmp_svp), "ChildCallbacks", 0))
Branch: 1 branch
BranchTrueFalseTotal
&& (tmp_svp = hv_fetchs((HV*)SvRV(*tmp_svp), "ChildCallbacks", 0)) 2 1413 1415
1456 2 ▶ && SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV
Branch: 2 branches
BranchTrueFalseTotal
&& SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV 2 0 2
&& SvROK(*tmp_svp) && SvTYPE(SvRV(*tmp_svp)) == SVt_PVHV 2 0 2
1457 ) {
1458 /* XXX mirrors behaviour of dbih_set_attr_k() of Callbacks */
1459 2 (void)hv_stores((HV*)SvRV(h), "Callbacks", newRV_inc(SvRV(*tmp_svp)));
1460 2 DBIc_set(imp, DBIcf_Callbacks, 1);
1461 }
1462  
1463 9345 DBIc_LongReadLen(imp) = DBIc_LongReadLen(parent_imp);
1464 #ifdef sv_rvweaken
1465 if (1) {
1466 AV *av;
1467 /* add weakref to new (outer) handle into parents ChildHandles array */
1468 9345 tmp_svp = hv_fetchs((HV*)SvRV(parent), "ChildHandles", 1);
1469 9345 ▶ if (!SvROK(*tmp_svp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvROK(*tmp_svp)) { 3107 6238 9345
1470 3107 SV *ChildHandles_rvav = newRV_noinc((SV*)newAV());
1471 3107 sv_setsv(*tmp_svp, ChildHandles_rvav);
1472 3107 sv_free(ChildHandles_rvav);
1473 }
1474 9345 av = (AV*)SvRV(*tmp_svp);
1475 9345 av_push(av, (SV*)sv_rvweaken(newRV_inc((SV*)SvRV(orv))));
1476 9345 ▶ if (av_len(av) % 120 == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(av) % 120 == 0) { 3142 6203 9345
1477 /* time to do some housekeeping to remove dead handles */
1478 3142 I32 i = av_len(av); /* 0 = 1 element */
1479 10484 ▶ while (i-- >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (i-- >= 0) { 7342 3142 10484
1480 7342 SV *sv = av_shift(av);
1481 7342 ▶ if (SvOK(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(sv)) 3144 4198 7342
1482 3144 av_push(av, sv);
1483 else
1484 4198 sv_free(sv); /* keep it leak-free by Doru Petrescu pdoru.dbi@from.ro */
1485 }
1486 }
1487 }
1488 #endif
1489 }
1490 else {
1491 345 DBIc_LongReadLen(imp) = DBIc_LongReadLen_init;
1492 }
1493  
1494 9690 switch (DBIc_TYPE(imp)) {
1495 3317 case DBIt_DB:
1496 /* cache _inner_ handle, but also see quick_FETCH */
1497 3317 (void)hv_stores((HV*)SvRV(h), "Driver", newRV_inc(SvRV(parent)));
1498 3317 (void)hv_fetchs((HV*)SvRV(h), "Statement", 1); /* store writable undef */
1499 3317 break;
1500 6028 case DBIt_ST:
1501 6028 DBIc_NUM_FIELDS((imp_sth_t*)imp) = -1;
1502 /* cache _inner_ handle, but also see quick_FETCH */
1503 6028 (void)hv_stores((HV*)SvRV(h), "Database", newRV_inc(SvRV(parent)));
1504 /* copy (alias) Statement from the sth up into the dbh */
1505 6028 tmp_svp = hv_fetchs((HV*)SvRV(h), "Statement", 1);
1506 6028 (void)hv_stores((HV*)SvRV(parent), "Statement", SvREFCNT_inc(*tmp_svp));
1507 6028 break;
1508 }
1509 }
1510 else
1511 0 die("panic: invalid DBIc_TYPE");
1512  
1513 /* Use DBI magic on inner handle to carry handle attributes */
1514 /* Note that we store the imp_sv in mg_obj, but as a shortcut, */
1515 /* also store a direct pointer to imp, aka PVX(dbih_imp_sv), */
1516 /* in mg_ptr (with mg_len set to null, so it wont be freed) */
1517 9690 sv_magic(SvRV(h), dbih_imp_sv, DBI_MAGIC, (char*)imp, 0);
1518 9690 SvREFCNT_dec(dbih_imp_sv); /* since sv_magic() incremented it */
1519 9690 SvRMAGICAL_on(SvRV(h)); /* so DBI magic gets sv_clear'd ok */
1520  
1521 {
1522 dMY_CXT; /* XXX would be nice to get rid of this */
1523 9690 DBI_SET_LAST_HANDLE(h);
1524 }
1525  
1526 if (1) {
1527 /* This is a hack to work-around the fast but poor way old versions of
1528 * DBD::Oracle (and possibly other drivers) check for a valid handle
1529 * using (SvMAGIC(SvRV(h)))->mg_type == 'P'). That doesn't work now
1530 * because the weakref magic is inserted ahead of the tie magic.
1531 * So here we swap the tie and weakref magic so the tie comes first.
1532 */
1533 9690 MAGIC *tie_mg = mg_find(SvRV(orv),'P');
1534 9690 MAGIC *first = SvMAGIC(SvRV(orv));
1535 9690 ▶ if (tie_mg && first->mg_moremagic == tie_mg && !tie_mg->mg_moremagic) {
Branch: 3 branches
BranchTrueFalseTotal
if (tie_mg && first->mg_moremagic == tie_mg && !tie_mg->mg_moremagic) { 9690 0 9690
if (tie_mg && first->mg_moremagic == tie_mg && !tie_mg->mg_moremagic) { 0 9690 9690
if (tie_mg && first->mg_moremagic == tie_mg && !tie_mg->mg_moremagic) { 0 0 0
1536 0 MAGIC *next = tie_mg->mg_moremagic;
1537 0 SvMAGIC(SvRV(orv)) = tie_mg;
1538 0 tie_mg->mg_moremagic = first;
1539 0 first->mg_moremagic = next;
1540 }
1541 }
1542  
1543 DBI_UNLOCK;
1544 9690 }
1545  
1546  
1547 static void
1548 4 dbih_dumphandle(pTHX_ SV *h, const char *msg, int level)
1549 {
1550 4 D_imp_xxh(h);
1551 4 ▶ if (level >= 9) {
Branch: 1 branch
BranchTrueFalseTotal
if (level >= 9) { 0 4 4
1552 0 sv_dump(h);
1553 }
1554 4 dbih_dumpcom(aTHX_ imp_xxh, msg, level);
1555 4 }
1556  
1557 static int
1558 7 dbih_dumpcom(pTHX_ imp_xxh_t *imp_xxh, const char *msg, int level)
1559 {
1560 dMY_CXT;
1561 7 SV *flags = sv_2mortal(newSVpvs(""));
1562 SV *inner;
1563 static const char pad[] = " ";
1564 7 ▶ if (!msg)
Branch: 1 branch
BranchTrueFalseTotal
if (!msg) 0 7 7
1565 0 msg = "dbih_dumpcom";
1566 14 PerlIO_printf(DBILOGFP," %s (%sh 0x%lx, com 0x%lx, imp %s):\n",
1567 7 msg, dbih_htype_name(DBIc_TYPE(imp_xxh)),
1568 7 (long)DBIc_MY_H(imp_xxh), (long)imp_xxh,
1569 7 ▶ (PL_dirty) ? "global destruction" : HvNAME(DBIc_IMP_STASH(imp_xxh)));
Branch: 7 branches
BranchTrueFalseTotal
(PL_dirty) ? "global destruction" : HvNAME(DBIc_IMP_STASH(imp_xxh))); 7 0 7
(PL_dirty) ? "global destruction" : HvNAME(DBIc_IMP_STASH(imp_xxh))); 7 0 7
(PL_dirty) ? "global destruction" : HvNAME(DBIc_IMP_STASH(imp_xxh))); 7 0 7
(PL_dirty) ? "global destruction" : HvNAME(DBIc_IMP_STASH(imp_xxh))); 0 7 7
(PL_dirty) ? "global destruction" : HvNAME(DBIc_IMP_STASH(imp_xxh))); 0 0 0
(PL_dirty) ? "global destruction" : HvNAME(DBIc_IMP_STASH(imp_xxh))); 7 0 7
(PL_dirty) ? "global destruction" : HvNAME(DBIc_IMP_STASH(imp_xxh))); 0 7 7
1570 7 ▶ if (DBIc_COMSET(imp_xxh)) sv_catpv(flags,"COMSET ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_COMSET(imp_xxh)) sv_catpv(flags,"COMSET "); 7 0 7
1571 7 ▶ if (DBIc_IMPSET(imp_xxh)) sv_catpv(flags,"IMPSET ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_IMPSET(imp_xxh)) sv_catpv(flags,"IMPSET "); 0 7 7
1572 7 ▶ if (DBIc_ACTIVE(imp_xxh)) sv_catpv(flags,"Active ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_ACTIVE(imp_xxh)) sv_catpv(flags,"Active "); 4 3 7
1573 7 ▶ if (DBIc_WARN(imp_xxh)) sv_catpv(flags,"Warn ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_WARN(imp_xxh)) sv_catpv(flags,"Warn "); 7 0 7
1574 7 ▶ if (DBIc_COMPAT(imp_xxh)) sv_catpv(flags,"CompatMode ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_COMPAT(imp_xxh)) sv_catpv(flags,"CompatMode "); 0 7 7
1575 7 ▶ if (DBIc_is(imp_xxh, DBIcf_ChopBlanks)) sv_catpv(flags,"ChopBlanks ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_ChopBlanks)) sv_catpv(flags,"ChopBlanks "); 0 7 7
1576 7 ▶ if (DBIc_is(imp_xxh, DBIcf_HandleSetErr)) sv_catpv(flags,"HandleSetErr ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_HandleSetErr)) sv_catpv(flags,"HandleSetErr "); 0 7 7
1577 7 ▶ if (DBIc_is(imp_xxh, DBIcf_HandleError)) sv_catpv(flags,"HandleError ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_HandleError)) sv_catpv(flags,"HandleError "); 0 7 7
1578 7 ▶ if (DBIc_is(imp_xxh, DBIcf_RaiseError)) sv_catpv(flags,"RaiseError ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_RaiseError)) sv_catpv(flags,"RaiseError "); 3 4 7
1579 7 ▶ if (DBIc_is(imp_xxh, DBIcf_PrintError)) sv_catpv(flags,"PrintError ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_PrintError)) sv_catpv(flags,"PrintError "); 4 3 7
1580 7 ▶ if (DBIc_is(imp_xxh, DBIcf_RaiseWarn)) sv_catpv(flags,"RaiseWarn ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_RaiseWarn)) sv_catpv(flags,"RaiseWarn "); 0 7 7
1581 7 ▶ if (DBIc_is(imp_xxh, DBIcf_PrintWarn)) sv_catpv(flags,"PrintWarn ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_PrintWarn)) sv_catpv(flags,"PrintWarn "); 4 3 7
1582 7 ▶ if (DBIc_is(imp_xxh, DBIcf_ShowErrorStatement)) sv_catpv(flags,"ShowErrorStatement ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_ShowErrorStatement)) sv_catpv(flags,"ShowErrorStatement "); 0 7 7
1583 7 ▶ if (DBIc_is(imp_xxh, DBIcf_AutoCommit)) sv_catpv(flags,"AutoCommit ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_AutoCommit)) sv_catpv(flags,"AutoCommit "); 7 0 7
1584 7 ▶ if (DBIc_is(imp_xxh, DBIcf_BegunWork)) sv_catpv(flags,"BegunWork ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_BegunWork)) sv_catpv(flags,"BegunWork "); 0 7 7
1585 7 ▶ if (DBIc_is(imp_xxh, DBIcf_LongTruncOk)) sv_catpv(flags,"LongTruncOk ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_LongTruncOk)) sv_catpv(flags,"LongTruncOk "); 0 7 7
1586 7 ▶ if (DBIc_is(imp_xxh, DBIcf_MultiThread)) sv_catpv(flags,"MultiThread ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_MultiThread)) sv_catpv(flags,"MultiThread "); 0 7 7
1587 7 ▶ if (DBIc_is(imp_xxh, DBIcf_TaintIn)) sv_catpv(flags,"TaintIn ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_TaintIn)) sv_catpv(flags,"TaintIn "); 0 7 7
1588 7 ▶ if (DBIc_is(imp_xxh, DBIcf_TaintOut)) sv_catpv(flags,"TaintOut ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_TaintOut)) sv_catpv(flags,"TaintOut "); 0 7 7
1589 7 ▶ if (DBIc_is(imp_xxh, DBIcf_Profile)) sv_catpv(flags,"Profile ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_Profile)) sv_catpv(flags,"Profile "); 0 7 7
1590 7 ▶ if (DBIc_is(imp_xxh, DBIcf_Callbacks)) sv_catpv(flags,"Callbacks ");
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_xxh, DBIcf_Callbacks)) sv_catpv(flags,"Callbacks "); 0 7 7
1591 7 PerlIO_printf(DBILOGFP,"%s FLAGS 0x%lx: %s\n", pad, (long)DBIc_FLAGS(imp_xxh), SvPV_nolen(flags));
1592 7 ▶ if (SvOK(DBIc_ERR(imp_xxh)))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(DBIc_ERR(imp_xxh))) 0 7 7
1593 0 PerlIO_printf(DBILOGFP,"%s ERR %s\n", pad, neatsvpv((SV*)DBIc_ERR(imp_xxh),0));
1594 7 ▶ if (SvOK(DBIc_ERR(imp_xxh)))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(DBIc_ERR(imp_xxh))) 0 7 7
1595 0 PerlIO_printf(DBILOGFP,"%s ERRSTR %s\n", pad, neatsvpv((SV*)DBIc_ERRSTR(imp_xxh),0));
1596 7 PerlIO_printf(DBILOGFP,"%s PARENT %s\n", pad, neatsvpv((SV*)DBIc_PARENT_H(imp_xxh),0));
1597 7 PerlIO_printf(DBILOGFP,"%s KIDS %ld (%ld Active)\n", pad,
1598 7 (long)DBIc_KIDS(imp_xxh), (long)DBIc_ACTIVE_KIDS(imp_xxh));
1599 7 ▶ if (DBIc_IMP_DATA(imp_xxh) && SvOK(DBIc_IMP_DATA(imp_xxh)))
Branch: 2 branches
BranchTrueFalseTotal
if (DBIc_IMP_DATA(imp_xxh) && SvOK(DBIc_IMP_DATA(imp_xxh))) 7 0 7
if (DBIc_IMP_DATA(imp_xxh) && SvOK(DBIc_IMP_DATA(imp_xxh))) 0 7 7
1600 0 PerlIO_printf(DBILOGFP,"%s IMP_DATA %s\n", pad, neatsvpv(DBIc_IMP_DATA(imp_xxh),0));
1601 7 ▶ if (DBIc_LongReadLen(imp_xxh) != DBIc_LongReadLen_init)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_LongReadLen(imp_xxh) != DBIc_LongReadLen_init) 0 7 7
1602 0 PerlIO_printf(DBILOGFP,"%s LongReadLen %ld\n", pad, (long)DBIc_LongReadLen(imp_xxh));
1603  
1604 7 ▶ if (DBIc_TYPE(imp_xxh) == DBIt_ST) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp_xxh) == DBIt_ST) { 0 7 7
1605 0 const imp_sth_t *imp_sth = (imp_sth_t*)imp_xxh;
1606 0 PerlIO_printf(DBILOGFP,"%s NUM_OF_FIELDS %d\n", pad, DBIc_NUM_FIELDS(imp_sth));
1607 0 PerlIO_printf(DBILOGFP,"%s NUM_OF_PARAMS %d\n", pad, DBIc_NUM_PARAMS(imp_sth));
1608 }
1609 7 inner = dbih_inner(aTHX_ (SV*)DBIc_MY_H(imp_xxh), msg);
1610 7 ▶ if (!inner || !SvROK(inner))
Branch: 2 branches
BranchTrueFalseTotal
if (!inner || !SvROK(inner)) 7 0 7
if (!inner || !SvROK(inner)) 3 4 7
1611 3 return 1;
1612 4 ▶ if (DBIc_TYPE(imp_xxh) <= DBIt_DB) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp_xxh) <= DBIt_DB) { 4 0 4
1613 4 SV **svp = hv_fetchs((HV*)SvRV(inner), "CachedKids", 0);
1614 4 ▶ if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 0 4 4
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 0 0 0
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 0 0 0
1615 0 HV *hv = (HV*)SvRV(*svp);
1616 0 ▶ PerlIO_printf(DBILOGFP,"%s CachedKids %d\n", pad, (int)HvKEYS(hv));
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(DBILOGFP,"%s CachedKids %d\n", pad, (int)HvKEYS(hv)); 0 0 0
1617 }
1618 }
1619 4 ▶ if (level > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (level > 0) { 4 0 4
1620 SV* value;
1621 char *key;
1622 I32 keylen;
1623 4 PerlIO_printf(DBILOGFP,"%s cached attributes:\n", pad);
1624 82 ▶ while ( (value = hv_iternextsv((HV*)SvRV(inner), &key, &keylen)) ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( (value = hv_iternextsv((HV*)SvRV(inner), &key, &keylen)) ) { 78 4 82
1625 78 PerlIO_printf(DBILOGFP,"%s '%s' => %s\n", pad, key, neatsvpv(value,0));
1626 }
1627 }
1628 0 ▶ else if (DBIc_TYPE(imp_xxh) == DBIt_DB) {
Branch: 1 branch
BranchTrueFalseTotal
else if (DBIc_TYPE(imp_xxh) == DBIt_DB) { 0 0 0
1629 0 SV **svp = hv_fetchs((HV*)SvRV(inner), "Name", 0);
1630 0 ▶ if (svp && SvOK(*svp))
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp)) 0 0 0
if (svp && SvOK(*svp)) 0 0 0
1631 0 PerlIO_printf(DBILOGFP,"%s Name %s\n", pad, neatsvpv(*svp,0));
1632 }
1633 0 ▶ else if (DBIc_TYPE(imp_xxh) == DBIt_ST) {
Branch: 1 branch
BranchTrueFalseTotal
else if (DBIc_TYPE(imp_xxh) == DBIt_ST) { 0 0 0
1634 0 SV **svp = hv_fetchs((HV*)SvRV(inner), "Statement", 0);
1635 0 ▶ if (svp && SvOK(*svp))
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvOK(*svp)) 0 0 0
if (svp && SvOK(*svp)) 0 0 0
1636 0 PerlIO_printf(DBILOGFP,"%s Statement %s\n", pad, neatsvpv(*svp,0));
1637 }
1638 4 return 1;
1639 }
1640  
1641  
1642 static void
1643 9686 dbih_clearcom(imp_xxh_t *imp_xxh)
1644 {
1645 dTHX;
1646 dTHR;
1647 9686 int dump = FALSE;
1648 9686 int debug = DBIc_TRACE_LEVEL(imp_xxh);
1649 9686 int auto_dump = (debug >= 6);
1650 9686 imp_xxh_t * const parent_xxh = DBIc_PARENT_COM(imp_xxh);
1651 /* Note that we're very much on our own here. DBIc_MY_H(imp_xxh) almost */
1652 /* certainly points to memory which has been freed. Don't use it! */
1653  
1654 /* --- pre-clearing sanity checks --- */
1655  
1656 #ifdef DBI_USE_THREADS
1657 if (DBIc_THR_USER(imp_xxh) != my_perl) { /* don't clear handle that belongs to another thread */
1658 if (debug >= 3) {
1659 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," skipped dbih_clearcom: DBI handle (type=%d, %s) is owned by thread %p not current thread %p\n",
1660 DBIc_TYPE(imp_xxh), HvNAME(DBIc_IMP_STASH(imp_xxh)), (void*)DBIc_THR_USER(imp_xxh), (void*)my_perl) ;
1661 PerlIO_flush(DBIc_LOGPIO(imp_xxh));
1662 }
1663 return;
1664 }
1665 #endif
1666  
1667 9686 ▶ if (!DBIc_COMSET(imp_xxh)) { /* should never happen */
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIc_COMSET(imp_xxh)) { /* should never happen */ 0 9686 9686
1668 0 dbih_dumpcom(aTHX_ imp_xxh, "dbih_clearcom: DBI handle already cleared", 0);
1669 0 return;
1670 }
1671  
1672 9686 ▶ if (auto_dump)
Branch: 1 branch
BranchTrueFalseTotal
if (auto_dump) 3 9683 9686
1673 3 dbih_dumpcom(aTHX_ imp_xxh,"DESTROY (dbih_clearcom)", 0);
1674  
1675 9686 ▶ if (!PL_dirty) {
Branch: 1 branch
BranchTrueFalseTotal
if (!PL_dirty) { 8787 899 9686
1676  
1677 8787 ▶ if (DBIc_ACTIVE(imp_xxh)) { /* bad news, potentially */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_ACTIVE(imp_xxh)) { /* bad news, potentially */ 337 8450 8787
1678 /* warn for sth, warn for dbh only if it has active sth or isn't AutoCommit */
1679 337 ▶ if (DBIc_TYPE(imp_xxh) >= DBIt_ST
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp_xxh) >= DBIt_ST 337 0 337
1680 337 ▶ || (DBIc_ACTIVE_KIDS(imp_xxh) || !DBIc_has(imp_xxh, DBIcf_AutoCommit))
Branch: 2 branches
BranchTrueFalseTotal
|| (DBIc_ACTIVE_KIDS(imp_xxh) || !DBIc_has(imp_xxh, DBIcf_AutoCommit)) 337 0 337
|| (DBIc_ACTIVE_KIDS(imp_xxh) || !DBIc_has(imp_xxh, DBIcf_AutoCommit)) 0 337 337
1681 ) {
1682 0 warn("DBI %s handle 0x%lx cleared whilst still active",
1683 dbih_htype_name(DBIc_TYPE(imp_xxh)), (unsigned long)DBIc_MY_H(imp_xxh));
1684 0 dump = TRUE;
1685 }
1686 }
1687  
1688 /* check that the implementor has done its own housekeeping */
1689 8787 ▶ if (DBIc_IMPSET(imp_xxh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_IMPSET(imp_xxh)) { 0 8787 8787
1690 0 warn("DBI %s handle 0x%lx has uncleared implementors data",
1691 dbih_htype_name(DBIc_TYPE(imp_xxh)), (unsigned long)DBIc_MY_H(imp_xxh));
1692 0 dump = TRUE;
1693 }
1694  
1695 8787 ▶ if (DBIc_KIDS(imp_xxh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_KIDS(imp_xxh)) { 0 8787 8787
1696 0 warn("DBI %s handle 0x%lx has %d uncleared child handles",
1697 dbih_htype_name(DBIc_TYPE(imp_xxh)),
1698 (unsigned long)DBIc_MY_H(imp_xxh), (int)DBIc_KIDS(imp_xxh));
1699 0 dump = TRUE;
1700 }
1701 }
1702  
1703 9686 ▶ if (dump && !auto_dump) /* else was already dumped above */
Branch: 2 branches
BranchTrueFalseTotal
if (dump && !auto_dump) /* else was already dumped above */ 0 9686 9686
if (dump && !auto_dump) /* else was already dumped above */ 0 0 0
1704 0 dbih_dumpcom(aTHX_ imp_xxh, "dbih_clearcom", 0);
1705  
1706 /* --- pre-clearing adjustments --- */
1707  
1708 9686 ▶ if (!PL_dirty) {
Branch: 1 branch
BranchTrueFalseTotal
if (!PL_dirty) { 8787 899 9686
1709 8787 ▶ if (parent_xxh) {
Branch: 1 branch
BranchTrueFalseTotal
if (parent_xxh) { 8785 2 8787
1710 8785 ▶ if (DBIc_ACTIVE(imp_xxh)) /* see also DBIc_ACTIVE_off */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_ACTIVE(imp_xxh)) /* see also DBIc_ACTIVE_off */ 335 8450 8785
1711 335 --DBIc_ACTIVE_KIDS(parent_xxh);
1712 8785 --DBIc_KIDS(parent_xxh);
1713 }
1714 }
1715  
1716 /* --- clear fields (may invoke object destructors) --- */
1717  
1718 9686 ▶ if (DBIc_TYPE(imp_xxh) == DBIt_ST) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp_xxh) == DBIt_ST) { 6028 3658 9686
1719 6028 imp_sth_t *imp_sth = (imp_sth_t*)imp_xxh;
1720 6028 sv_free((SV*)DBIc_FIELDS_AV(imp_sth));
1721 }
1722  
1723 9686 sv_free(DBIc_IMP_DATA(imp_xxh)); /* do this first */
1724 9686 ▶ if (DBIc_TYPE(imp_xxh) <= DBIt_ST) { /* DBIt_FD doesn't have attr */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp_xxh) <= DBIt_ST) { /* DBIt_FD doesn't have attr */ 9686 0 9686
1725 9686 sv_free(_imp2com(imp_xxh, attr.TraceLevel));
1726 9686 sv_free(_imp2com(imp_xxh, attr.State));
1727 9686 sv_free(_imp2com(imp_xxh, attr.Err));
1728 9686 sv_free(_imp2com(imp_xxh, attr.Errstr));
1729 9686 sv_free(_imp2com(imp_xxh, attr.FetchHashKeyName));
1730 }
1731  
1732  
1733 9686 sv_free((SV*)DBIc_PARENT_H(imp_xxh)); /* do this last */
1734  
1735 9686 DBIc_COMSET_off(imp_xxh);
1736  
1737 9686 ▶ if (debug >= 4)
Branch: 1 branch
BranchTrueFalseTotal
if (debug >= 4) 3 9683 9686
1738 3 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," dbih_clearcom 0x%lx (com 0x%lx, type %d) done.\n\n",
1739 3 (long)DBIc_MY_H(imp_xxh), (long)imp_xxh, DBIc_TYPE(imp_xxh));
1740 }
1741  
1742  
1743 /* --- Functions for handling field buffer arrays --- */
1744  
1745 static AV *
1746 4045 dbih_setup_fbav(imp_sth_t *imp_sth)
1747 {
1748 /* Usually called to setup the row buffer for new sth.
1749 * Also called if the value of NUM_OF_FIELDS is altered,
1750 * in which case it adjusts the row buffer to match NUM_OF_FIELDS.
1751 */
1752 dTHX;
1753 4045 I32 i = DBIc_NUM_FIELDS(imp_sth);
1754 4045 AV *av = DBIc_FIELDS_AV(imp_sth);
1755  
1756 4045 ▶ if (i < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (i < 0) 0 4045 4045
1757 0 i = 0;
1758  
1759 4045 ▶ if (av) {
Branch: 1 branch
BranchTrueFalseTotal
if (av) { 1845 2200 4045
1760 1845 ▶ if (av_len(av)+1 == i) /* is existing array the right size? */
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(av)+1 == i) /* is existing array the right size? */ 1841 4 1845
1761 1841 return av;
1762 /* we need to adjust the size of the array */
1763 4 ▶ if (DBIc_TRACE_LEVEL(imp_sth) >= 2)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth) >= 2) 0 4 4
1764 0 PerlIO_printf(DBIc_LOGPIO(imp_sth)," dbih_setup_fbav realloc from %ld to %ld fields\n", (long)(av_len(av)+1), (long)i);
1765 4 SvREADONLY_off(av);
1766 4 ▶ if (i < av_len(av)+1) /* trim to size if too big */
Branch: 1 branch
BranchTrueFalseTotal
if (i < av_len(av)+1) /* trim to size if too big */ 2 2 4
1767 2 av_fill(av, i-1);
1768 }
1769 else {
1770 2200 ▶ if (DBIc_TRACE_LEVEL(imp_sth) >= 5)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth) >= 5) 0 2200 2200
1771 0 PerlIO_printf(DBIc_LOGPIO(imp_sth)," dbih_setup_fbav alloc for %ld fields\n", (long)i);
1772 2200 av = newAV();
1773 2200 DBIc_FIELDS_AV(imp_sth) = av;
1774  
1775 /* row_count will need to be manually reset by the driver if the */
1776 /* sth is re-executed (since this code won't get rerun) */
1777 2200 DBIc_ROW_COUNT(imp_sth) = 0;
1778 }
1779  
1780 /* load array with writeable SV's. Do this backwards so */
1781 /* the array only gets extended once. */
1782 8606 ▶ while(i--) /* field 1 stored at index 0 */
Branch: 1 branch
BranchTrueFalseTotal
while(i--) /* field 1 stored at index 0 */ 6402 2204 8606
1783 6402 av_store(av, i, newSV(0));
1784 2204 ▶ if (DBIc_TRACE_LEVEL(imp_sth) >= 6)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth) >= 6) 0 2204 2204
1785 0 PerlIO_printf(DBIc_LOGPIO(imp_sth)," dbih_setup_fbav now %ld fields\n", (long)(av_len(av)+1));
1786 2204 SvREADONLY_on(av); /* protect against shift @$row etc */
1787 2204 return av;
1788 }
1789  
1790  
1791 static AV *
1792 105957 dbih_get_fbav(imp_sth_t *imp_sth)
1793 {
1794 AV *av;
1795  
1796 105957 ▶ if ( (av = DBIc_FIELDS_AV(imp_sth)) == Nullav) {
Branch: 1 branch
BranchTrueFalseTotal
if ( (av = DBIc_FIELDS_AV(imp_sth)) == Nullav) { 2142 103815 105957
1797 2142 av = dbih_setup_fbav(imp_sth);
1798 }
1799 else {
1800 dTHX;
1801 103815 int i = av_len(av) + 1;
1802 103815 ▶ if (i != DBIc_NUM_FIELDS(imp_sth)) {
Branch: 1 branch
BranchTrueFalseTotal
if (i != DBIc_NUM_FIELDS(imp_sth)) { 0 103815 103815
1803 /*SV *sth = dbih_inner(aTHX_ (SV*)DBIc_MY_H(imp_sth), "_get_fbav");*/
1804 /* warn via PrintWarn */
1805 0 set_err_char(SvRV(DBIc_MY_H(imp_sth)), (imp_xxh_t*)imp_sth,
1806 "0", 0, "Number of row fields inconsistent with NUM_OF_FIELDS (driver bug)", "", "_get_fbav");
1807 /*
1808 DBIc_NUM_FIELDS(imp_sth) = i;
1809 hv_deletes((HV*)SvRV(sth), "NUM_OF_FIELDS", G_DISCARD);
1810 */
1811 }
1812 /* don't let SvUTF8 flag persist from one row to the next */
1813 /* (only affects drivers that use sv_setpv, but most XS do) */
1814 /* XXX turn into option later (force on/force off/ignore) */
1815 412392 ▶ while(i--) /* field 1 stored at index 0 */
Branch: 1 branch
BranchTrueFalseTotal
while(i--) /* field 1 stored at index 0 */ 308577 103815 412392
1816 308577 SvUTF8_off(AvARRAY(av)[i]);
1817 }
1818  
1819 105957 ▶ if (DBIc_is(imp_sth, DBIcf_TaintOut)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_sth, DBIcf_TaintOut)) { 1 105956 105957
1820 dTHX;
1821 dTHR;
1822 1 TAINT; /* affects sv_setsv()'s called within same perl statement */
1823 }
1824  
1825 /* XXX fancy stuff to happen here later (re scrolling etc) */
1826 105957 ++DBIc_ROW_COUNT(imp_sth);
1827 105957 return av;
1828 }
1829  
1830  
1831 static int
1832 162 dbih_sth_bind_col(SV *sth, SV *col, SV *ref, SV *attribs)
1833 {
1834 dTHX;
1835 162 D_imp_sth(sth);
1836 AV *av;
1837 162 int idx = SvIV(col);
1838 162 int fields = DBIc_NUM_FIELDS(imp_sth);
1839  
1840 162 ▶ if (fields <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (fields <= 0) { 0 162 162
1841 PERL_UNUSED_VAR(attribs);
1842 0 ▶ croak("Statement has no result columns to bind%s",
Branch: 1 branch
BranchTrueFalseTotal
croak("Statement has no result columns to bind%s", 0 0 0
1843 DBIc_ACTIVE(imp_sth)
1844 ? "" : " (perhaps you need to successfully call execute first, or again)");
1845 }
1846  
1847 162 ▶ if ( (av = DBIc_FIELDS_AV(imp_sth)) == Nullav)
Branch: 1 branch
BranchTrueFalseTotal
if ( (av = DBIc_FIELDS_AV(imp_sth)) == Nullav) 58 104 162
1848 58 av = dbih_setup_fbav(imp_sth);
1849  
1850 162 ▶ if (DBIc_TRACE_LEVEL(imp_sth) >= 5)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth) >= 5) 0 162 162
1851 0 PerlIO_printf(DBIc_LOGPIO(imp_sth)," dbih_sth_bind_col %s => %s %s\n",
1852 neatsvpv(col,0), neatsvpv(ref,0), neatsvpv(attribs,0));
1853  
1854 162 ▶ if (idx < 1 || idx > fields)
Branch: 2 branches
BranchTrueFalseTotal
if (idx < 1 || idx > fields) 160 2 162
if (idx < 1 || idx > fields) 4 156 160
1855 6 croak("bind_col: column %d is not a valid column (1..%d)",
1856 idx, fields);
1857  
1858 156 ▶ if (!SvOK(ref) && SvREADONLY(ref)) { /* binding to literal undef */
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(ref) && SvREADONLY(ref)) { /* binding to literal undef */ 2 154 156
if (!SvOK(ref) && SvREADONLY(ref)) { /* binding to literal undef */ 2 0 2
1859 /* presumably the call is just setting the TYPE or other atribs */
1860 /* but this default method ignores attribs, so we just return */
1861 2 return 1;
1862 }
1863  
1864 /* Write this as > SVt_PVMG because in 5.8.x the next type */
1865 /* is SVt_PVBM, whereas in 5.9.x it's SVt_PVGV. */
1866 154 ▶ if (!SvROK(ref) || SvTYPE(SvRV(ref)) > SVt_PVMG) /* XXX LV */
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(ref) || SvTYPE(SvRV(ref)) > SVt_PVMG) /* XXX LV */ 154 0 154
if (!SvROK(ref) || SvTYPE(SvRV(ref)) > SVt_PVMG) /* XXX LV */ 0 154 154
1867 0 croak("Can't %s->bind_col(%s, %s,...), need a reference to a scalar",
1868 neatsvpv(sth,0), neatsvpv(col,0), neatsvpv(ref,0));
1869  
1870 /* use supplied scalar as storage for this column */
1871 154 SvREADONLY_off(av);
1872 154 av_store(av, idx-1, SvREFCNT_inc(SvRV(ref)) );
1873 154 SvREADONLY_on(av);
1874 154 return 1;
1875 }
1876  
1877  
1878 static int
1879 0 quote_type(int sql_type, int p, int s, int *t, void *v)
1880 {
1881 /* Returns true if type should be bound as a number else */
1882 /* false implying that binding as a string should be okay. */
1883 /* The true value is either SQL_INTEGER or SQL_DOUBLE which */
1884 /* can be used as a hint if desired. */
1885 (void)p;
1886 (void)s;
1887 (void)t;
1888 (void)v;
1889 /* looks like it's never been used, and doesn't make much sense anyway */
1890 0 warn("Use of DBI internal bind_as_num/quote_type function is deprecated");
1891 0 switch(sql_type) {
1892 0 case SQL_INTEGER:
1893 case SQL_SMALLINT:
1894 case SQL_TINYINT:
1895 case SQL_BIGINT:
1896 0 return 0;
1897 0 case SQL_FLOAT:
1898 case SQL_REAL:
1899 case SQL_DOUBLE:
1900 0 return 0;
1901 0 case SQL_NUMERIC:
1902 case SQL_DECIMAL:
1903 0 return 0; /* bind as string to attempt to retain precision */
1904 }
1905 0 return 1;
1906 }
1907  
1908  
1909 /* Convert a simple string representation of a value into a more specific
1910 * perl type based on an sql_type value.
1911 * The semantics of SQL standard TYPE values are interpreted _very_ loosely
1912 * on the basis of "be liberal in what you accept and let's throw in some
1913 * extra semantics while we're here" :)
1914 * Returns:
1915 * -2: sql_type isn't handled, value unchanged
1916 * -1: sv is undef, value unchanged
1917 * 0: sv couldn't be cast cleanly and DBIstcf_STRICT was used
1918 * 1: sv couldn't be cast cleanly and DBIstcf_STRICT was not used
1919 * 2: sv was cast ok
1920 */
1921  
1922 int
1923 54 sql_type_cast_svpv(pTHX_ SV *sv, int sql_type, U32 flags, PERL_UNUSED_DECL void *v)
1924 {
1925 54 int cast_ok = 0;
1926 int grok_flags;
1927 UV uv;
1928 STRLEN len;
1929 char *p;
1930  
1931 /* do nothing for undef (NULL) or non-string values */
1932 54 ▶ if (!sv || !SvOK(sv))
Branch: 2 branches
BranchTrueFalseTotal
if (!sv || !SvOK(sv)) 54 0 54
if (!sv || !SvOK(sv)) 2 52 54
1933 2 return -1;
1934  
1935 52 switch(sql_type) {
1936  
1937 4 default:
1938 4 return -2; /* not a recognised SQL TYPE, value unchanged */
1939  
1940 38 case SQL_INTEGER:
1941 /* sv_2iv is liberal, may return SvIV, SvUV, or SvNV */
1942 38 sv_2iv(sv);
1943 /* SvNOK will be set if value is out of range for IV/UV.
1944 * SvIOK should be set but won't if sv is not numeric (in which
1945 * case perl would have warn'd already if -w or warnings are in effect)
1946 */
1947 38 ▶ cast_ok = (SvIOK(sv) && !SvNOK(sv));
Branch: 2 branches
BranchTrueFalseTotal
cast_ok = (SvIOK(sv) && !SvNOK(sv)); 26 12 38
cast_ok = (SvIOK(sv) && !SvNOK(sv)); 26 0 26
1948 38 break;
1949  
1950 6 case SQL_DOUBLE:
1951 6 sv_2nv(sv);
1952 /* SvNOK should be set but won't if sv is not numeric (in which
1953 * case perl would have warn'd already if -w or warnings are in effect)
1954 */
1955 6 cast_ok = SvNOK(sv);
1956 6 break;
1957  
1958 /* caller would like IV else UV else NV */
1959 /* else no error and sv is untouched */
1960 4 case SQL_NUMERIC:
1961 /* based on the code in perl's toke.c */
1962 4 p = SvPV(sv, len); /* force stringify, handle magic */
1963 4 uv = 0;
1964 4 grok_flags = grok_number(p, len, &uv);
1965 4 cast_ok = 1;
1966 4 ▶ if (grok_flags == IS_NUMBER_IN_UV) { /* +ve int */
Branch: 1 branch
BranchTrueFalseTotal
if (grok_flags == IS_NUMBER_IN_UV) { /* +ve int */ 0 4 4
1967 0 ▶ if (uv <= IV_MAX) /* prefer IV over UV */
Branch: 1 branch
BranchTrueFalseTotal
if (uv <= IV_MAX) /* prefer IV over UV */ 0 0 0
1968 0 sv_2iv(sv);
1969 0 else sv_2uv(sv);
1970 }
1971 4 ▶ else if (grok_flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG)
Branch: 1 branch
BranchTrueFalseTotal
else if (grok_flags == (IS_NUMBER_IN_UV | IS_NUMBER_NEG) 0 4 4
1972 0 ▶ && uv <= IV_MAX
Branch: 1 branch
BranchTrueFalseTotal
&& uv <= IV_MAX 0 0 0
1973 ) {
1974 0 sv_2iv(sv);
1975 }
1976 4 ▶ else if (grok_flags) { /* is numeric */
Branch: 1 branch
BranchTrueFalseTotal
else if (grok_flags) { /* is numeric */ 0 4 4
1977 0 sv_2nv(sv);
1978 }
1979 else
1980 4 cast_ok = 0;
1981 4 break;
1982  
1983 #if 0 /* XXX future possibilities */
1984 case SQL_BIGINT: /* use Math::BigInt if too large for IV/UV */
1985 #endif
1986 }
1987  
1988 48 ▶ if (cast_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (cast_ok) { 28 20 48
1989  
1990 28 ▶ if (flags & DBIstcf_DISCARD_STRING
Branch: 1 branch
BranchTrueFalseTotal
if (flags & DBIstcf_DISCARD_STRING 4 24 28
1991 4 ▶ && SvNIOK(sv) /* we set a numeric value */
Branch: 1 branch
BranchTrueFalseTotal
&& SvNIOK(sv) /* we set a numeric value */ 4 0 4
1992 4 ▶ && SvPVX(sv) /* we have a buffer to discard */
Branch: 1 branch
BranchTrueFalseTotal
&& SvPVX(sv) /* we have a buffer to discard */ 2 2 4
1993 ) {
1994 2 ▶ SvOOK_off(sv);
Branch: 4 branches
BranchTrueFalseTotal
SvOOK_off(sv); 0 2 2
SvOOK_off(sv); 0 0 0
SvOOK_off(sv); 0 0 0
SvOOK_off(sv); 0 2 2
1995 2 sv_force_normal(sv);
1996 2 ▶ if (SvLEN(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvLEN(sv)) 2 0 2
1997 2 Safefree(SvPVX(sv));
1998 2 SvPOK_off(sv);
1999 2 SvPV_set(sv, NULL);
2000 2 SvLEN_set(sv, 0);
2001 2 SvCUR_set(sv, 0);
2002 }
2003 }
2004  
2005 48 ▶ if (cast_ok)
Branch: 1 branch
BranchTrueFalseTotal
if (cast_ok) 28 20 48
2006 28 return 2;
2007 20 ▶ else if (flags & DBIstcf_STRICT)
Branch: 1 branch
BranchTrueFalseTotal
else if (flags & DBIstcf_STRICT) 10 10 20
2008 10 return 0;
2009 10 else return 1;
2010 }
2011  
2012  
2013  
2014 /* --- Generic Handle Attributes (for all handle types) --- */
2015  
2016 static int
2017 79870 dbih_set_attr_k(SV *h, SV *keysv, int dbikey, SV *valuesv)
2018 {
2019 dTHX;
2020 dTHR;
2021 79870 D_imp_xxh(h);
2022 STRLEN keylen;
2023 79870 const char *key = SvPV(keysv, keylen);
2024 79870 const int htype = DBIc_TYPE(imp_xxh);
2025 79870 int on = (SvTRUE(valuesv));
2026 79870 int internal = 1; /* DBIh_IN_PERL_DBD(imp_xxh); -- for DBD's in perl */
2027 79870 int cacheit = 0;
2028 79870 int weakenit = 0; /* eg for CachedKids ref */
2029 (void)dbikey;
2030  
2031 79870 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 3) 51 79819 79870
2032 51 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," STORE %s %s => %s\n",
2033 neatsvpv(h,0), neatsvpv(keysv,0), neatsvpv(valuesv,0));
2034  
2035 79870 ▶ if (internal && strEQ(key, "Active")) {
Branch: 2 branches
BranchTrueFalseTotal
if (internal && strEQ(key, "Active")) { 79870 0 79870
if (internal && strEQ(key, "Active")) { 14242 65628 79870
2036 14242 ▶ if (on) {
Branch: 1 branch
BranchTrueFalseTotal
if (on) { 9244 4998 14242
2037 9244 D_imp_sth(h);
2038 9244 ▶ DBIc_ACTIVE_on(imp_xxh);
Branch: 4 branches
BranchTrueFalseTotal
DBIc_ACTIVE_on(imp_xxh); 9241 3 9244
DBIc_ACTIVE_on(imp_xxh); 9241 0 9241
DBIc_ACTIVE_on(imp_xxh); 9241 0 9241
DBIc_ACTIVE_on(imp_xxh); 0 9241 9241
2039 /* for pure-perl drivers on second and subsequent */
2040 /* execute()'s, else row count keeps rising. */
2041 9244 ▶ if (htype==DBIt_ST && DBIc_FIELDS_AV(imp_sth))
Branch: 2 branches
BranchTrueFalseTotal
if (htype==DBIt_ST && DBIc_FIELDS_AV(imp_sth)) 5992 3252 9244
if (htype==DBIt_ST && DBIc_FIELDS_AV(imp_sth)) 3684 2308 5992
2042 3684 DBIc_ROW_COUNT(imp_sth) = 0;
2043 }
2044 else {
2045 4998 ▶ DBIc_ACTIVE_off(imp_xxh);
Branch: 5 branches
BranchTrueFalseTotal
DBIc_ACTIVE_off(imp_xxh); 3038 1960 4998
DBIc_ACTIVE_off(imp_xxh); 3038 0 3038
DBIc_ACTIVE_off(imp_xxh); 2516 522 3038
DBIc_ACTIVE_off(imp_xxh); 2516 0 2516
DBIc_ACTIVE_off(imp_xxh); 0 2516 2516
2046 }
2047 }
2048 65628 ▶ else if (strEQ(key, "FetchHashKeyName")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "FetchHashKeyName")) { 20 65608 65628
2049 20 ▶ if (htype >= DBIt_ST)
Branch: 1 branch
BranchTrueFalseTotal
if (htype >= DBIt_ST) 0 20 20
2050 0 croak("Can't set FetchHashKeyName for a statement handle, set in parent before prepare()");
2051 20 cacheit = 1; /* just save it */
2052 }
2053 65608 ▶ else if (strEQ(key, "CompatMode")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "CompatMode")) { 12 65596 65608
2054 12 ▶ (on) ? DBIc_COMPAT_on(imp_xxh) : DBIc_COMPAT_off(imp_xxh);
Branch: 1 branch
BranchTrueFalseTotal
(on) ? DBIc_COMPAT_on(imp_xxh) : DBIc_COMPAT_off(imp_xxh); 10 2 12
2055 }
2056 65596 ▶ else if (strEQ(key, "Warn")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "Warn")) { 6 65590 65596
2057 6 ▶ (on) ? DBIc_WARN_on(imp_xxh) : DBIc_WARN_off(imp_xxh);
Branch: 1 branch
BranchTrueFalseTotal
(on) ? DBIc_WARN_on(imp_xxh) : DBIc_WARN_off(imp_xxh); 4 2 6
2058 }
2059 65590 ▶ else if (strEQ(key, "AutoInactiveDestroy")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "AutoInactiveDestroy")) { 12 65578 65590
2060 12 ▶ (on) ? DBIc_AIADESTROY_on(imp_xxh) : DBIc_AIADESTROY_off(imp_xxh);
Branch: 1 branch
BranchTrueFalseTotal
(on) ? DBIc_AIADESTROY_on(imp_xxh) : DBIc_AIADESTROY_off(imp_xxh); 8 4 12
2061 }
2062 65578 ▶ else if (strEQ(key, "InactiveDestroy")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "InactiveDestroy")) { 8 65570 65578
2063 8 ▶ (on) ? DBIc_IADESTROY_on(imp_xxh) : DBIc_IADESTROY_off(imp_xxh);
Branch: 1 branch
BranchTrueFalseTotal
(on) ? DBIc_IADESTROY_on(imp_xxh) : DBIc_IADESTROY_off(imp_xxh); 4 4 8
2064 }
2065 65570 ▶ else if (strEQ(key, "RootClass")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "RootClass")) { 14 65556 65570
2066 14 cacheit = 1; /* just save it */
2067 }
2068 65556 ▶ else if (strEQ(key, "RowCacheSize")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "RowCacheSize")) { 0 65556 65556
2069 0 cacheit = 0; /* ignore it */
2070 }
2071 65556 ▶ else if (strEQ(key, "Executed")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "Executed")) { 6080 59476 65556
2072 6080 ▶ DBIc_set(imp_xxh, DBIcf_Executed, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh, DBIcf_Executed, on); 0 6080 6080
2073 }
2074 59476 ▶ else if (strEQ(key, "ChopBlanks")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ChopBlanks")) { 10 59466 59476
2075 10 ▶ DBIc_set(imp_xxh, DBIcf_ChopBlanks, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh, DBIcf_ChopBlanks, on); 6 4 10
2076 }
2077 59466 ▶ else if (strEQ(key, "ErrCount")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ErrCount")) { 2 59464 59466
2078 2 DBIc_ErrCount(imp_xxh) = SvUV(valuesv);
2079 }
2080 59464 ▶ else if (strEQ(key, "LongReadLen")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "LongReadLen")) { 0 59464 59464
2081 0 ▶ if (SvNV(valuesv) < 0 || SvNV(valuesv) > MAX_LongReadLen)
Branch: 2 branches
BranchTrueFalseTotal
if (SvNV(valuesv) < 0 || SvNV(valuesv) > MAX_LongReadLen) 0 0 0
if (SvNV(valuesv) < 0 || SvNV(valuesv) > MAX_LongReadLen) 0 0 0
2082 0 croak("Can't set LongReadLen < 0 or > %ld",MAX_LongReadLen);
2083 0 DBIc_LongReadLen(imp_xxh) = SvIV(valuesv);
2084 0 cacheit = 1; /* save it for clone */
2085 }
2086 59464 ▶ else if (strEQ(key, "LongTruncOk")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "LongTruncOk")) { 4 59460 59464
2087 4 ▶ DBIc_set(imp_xxh,DBIcf_LongTruncOk, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_LongTruncOk, on); 0 4 4
2088 }
2089 59460 ▶ else if (strEQ(key, "RaiseError")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "RaiseError")) { 6390 53070 59460
2090 6390 ▶ DBIc_set(imp_xxh,DBIcf_RaiseError, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_RaiseError, on); 6291 99 6390
2091 }
2092 53070 ▶ else if (strEQ(key, "PrintError")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "PrintError")) { 6503 46567 53070
2093 6503 ▶ DBIc_set(imp_xxh,DBIcf_PrintError, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_PrintError, on); 194 6309 6503
2094 }
2095 46567 ▶ else if (strEQ(key, "RaiseWarn")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "RaiseWarn")) { 32 46535 46567
2096 32 ▶ DBIc_set(imp_xxh,DBIcf_RaiseWarn, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_RaiseWarn, on); 14 18 32
2097 }
2098 46535 ▶ else if (strEQ(key, "PrintWarn")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "PrintWarn")) { 6084 40451 46535
2099 6084 ▶ DBIc_set(imp_xxh,DBIcf_PrintWarn, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_PrintWarn, on); 8 6076 6084
2100 }
2101 40451 ▶ else if (strEQ(key, "HandleError")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "HandleError")) { 6 40445 40451
2102 6 ▶ if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVCV)) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVCV)) ) { 4 2 6
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVCV)) ) { 4 0 4
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVCV)) ) { 0 4 4
2103 0 croak("Can't set %s to '%s'", "HandleError", neatsvpv(valuesv,0));
2104 }
2105 6 ▶ DBIc_set(imp_xxh,DBIcf_HandleError, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_HandleError, on); 4 2 6
2106 6 cacheit = 1; /* child copy setup by dbih_setup_handle() */
2107 }
2108 40445 ▶ else if (strEQ(key, "HandleSetErr")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "HandleSetErr")) { 2 40443 40445
2109 2 ▶ if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVCV)) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVCV)) ) { 2 0 2
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVCV)) ) { 2 0 2
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVCV)) ) { 0 2 2
2110 0 croak("Can't set %s to '%s'","HandleSetErr",neatsvpv(valuesv,0));
2111 }
2112 2 ▶ DBIc_set(imp_xxh,DBIcf_HandleSetErr, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_HandleSetErr, on); 2 0 2
2113 2 cacheit = 1; /* child copy setup by dbih_setup_handle() */
2114 }
2115 40443 ▶ else if (strEQ(key, "ChildHandles")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ChildHandles")) { 0 40443 40443
2116 0 ▶ if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVAV)) ) {
Branch: 3 branches
BranchTrueFalseTotal
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVAV)) ) { 0 0 0
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVAV)) ) { 0 0 0
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVAV)) ) { 0 0 0
2117 0 croak("Can't set %s to '%s'", "ChildHandles", neatsvpv(valuesv,0));
2118 }
2119 0 cacheit = 1; /* just save it in the hash */
2120 }
2121 40443 ▶ else if (strEQ(key, "Profile")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "Profile")) { 51 40392 40443
2122 static const char profile_class[] = "DBI::Profile";
2123 51 ▶ if (on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVHV)) ) {
Branch: 3 branches
BranchTrueFalseTotal
if (on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVHV)) ) { 45 6 51
if (on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVHV)) ) { 17 28 45
if (on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVHV)) ) { 0 17 17
2124 /* not a hash ref so use DBI::Profile to work out what to do */
2125 dTHR;
2126 28 dSP;
2127 I32 returns;
2128 28 TAINT_NOT; /* the require is presumed innocent till proven guilty */
2129 28 require_pv("DBI/Profile.pm");
2130 28 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 28 0 28
if (SvTRUE(ERRSV)) { 0 28 28
2131 0 ▶ warn("Can't load %s: %s", profile_class, SvPV_nolen(ERRSV));
Branch: 1 branch
BranchTrueFalseTotal
warn("Can't load %s: %s", profile_class, SvPV_nolen(ERRSV)); 0 0 0
2132 0 valuesv = &PL_sv_undef;
2133 }
2134 else {
2135 28 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 28 28
2136 28 ▶ mXPUSHs(newSVpv(profile_class, 0));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpv(profile_class, 0)); 0 28 28
2137 28 ▶ XPUSHs(valuesv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(valuesv); 0 28 28
2138 28 PUTBACK;
2139 28 returns = call_method("_auto_new", G_SCALAR);
2140 22 ▶ if (returns != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (returns != 1) 0 22 22
2141 0 croak("%s _auto_new", profile_class);
2142 22 SPAGAIN;
2143 22 valuesv = POPs;
2144 22 PUTBACK;
2145 }
2146 22 on = SvTRUE(valuesv); /* in case it returns undef */
2147 }
2148 45 ▶ if (on && !sv_isobject(valuesv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (on && !sv_isobject(valuesv)) { 39 6 45
if (on && !sv_isobject(valuesv)) { 16 23 39
2149 /* not blessed already - so default to DBI::Profile */
2150 HV *stash;
2151 16 require_pv(profile_class);
2152 16 stash = gv_stashpv(profile_class, GV_ADDWARN);
2153 16 sv_bless(valuesv, stash);
2154 }
2155 45 ▶ DBIc_set(imp_xxh,DBIcf_Profile, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_Profile, on); 39 6 45
2156 45 cacheit = 1; /* child copy setup by dbih_setup_handle() */
2157 }
2158 40392 ▶ else if (strEQ(key, "ShowErrorStatement")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ShowErrorStatement")) { 1087 39305 40392
2159 1087 ▶ DBIc_set(imp_xxh,DBIcf_ShowErrorStatement, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_ShowErrorStatement, on); 1081 6 1087
2160 }
2161 39305 ▶ else if (strEQ(key, "MultiThread") && internal) {
Branch: 2 branches
BranchTrueFalseTotal
else if (strEQ(key, "MultiThread") && internal) { 0 39305 39305
else if (strEQ(key, "MultiThread") && internal) { 0 0 0
2162 /* here to allow pure-perl drivers to set MultiThread */
2163 0 ▶ DBIc_set(imp_xxh,DBIcf_MultiThread, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_MultiThread, on); 0 0 0
2164 0 ▶ if (on && DBIc_WARN(imp_xxh)) {
Branch: 2 branches
BranchTrueFalseTotal
if (on && DBIc_WARN(imp_xxh)) { 0 0 0
if (on && DBIc_WARN(imp_xxh)) { 0 0 0
2165 0 warn("MultiThread support not yet implemented in DBI");
2166 }
2167 }
2168 39305 ▶ else if (strEQ(key, "Taint")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "Taint")) { 22 39283 39305
2169 /* 'Taint' is a shortcut for both in and out mode */
2170 22 ▶ DBIc_set(imp_xxh,DBIcf_TaintIn|DBIcf_TaintOut, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_TaintIn|DBIcf_TaintOut, on); 3 19 22
2171 }
2172 39283 ▶ else if (strEQ(key, "TaintIn")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "TaintIn")) { 8 39275 39283
2173 8 ▶ DBIc_set(imp_xxh,DBIcf_TaintIn, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_TaintIn, on); 2 6 8
2174 }
2175 39275 ▶ else if (strEQ(key, "TaintOut")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "TaintOut")) { 7 39268 39275
2176 7 ▶ DBIc_set(imp_xxh,DBIcf_TaintOut, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_TaintOut, on); 2 5 7
2177 }
2178 39268 ▶ else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "CachedKids")
Branch: 3 branches
BranchTrueFalseTotal
else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "CachedKids") 26219 13049 39268
else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "CachedKids") 5656 20563 26219
else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "CachedKids") 9 5647 5656
2179 /* only allow hash refs */
2180 9 ▶ && SvROK(valuesv) && SvTYPE(SvRV(valuesv))==SVt_PVHV
Branch: 2 branches
BranchTrueFalseTotal
&& SvROK(valuesv) && SvTYPE(SvRV(valuesv))==SVt_PVHV 9 0 9
&& SvROK(valuesv) && SvTYPE(SvRV(valuesv))==SVt_PVHV 9 0 9
2181 ) {
2182 9 cacheit = 1;
2183 9 weakenit = 1;
2184 }
2185 39259 ▶ else if (keylen==9 && strEQ(key, "Callbacks")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==9 && strEQ(key, "Callbacks")) { 39 39220 39259
else if (keylen==9 && strEQ(key, "Callbacks")) { 29 10 39
2186 29 ▶ if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVHV)) )
Branch: 3 branches
BranchTrueFalseTotal
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVHV)) ) 25 4 29
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVHV)) ) 25 0 25
if ( on && (!SvROK(valuesv) || (SvTYPE(SvRV(valuesv)) != SVt_PVHV)) ) 0 25 25
2187 0 croak("Can't set Callbacks to '%s'",neatsvpv(valuesv,0));
2188 /* see also dbih_setup_handle for ChildCallbacks handling */
2189 29 ▶ DBIc_set(imp_xxh, DBIcf_Callbacks, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh, DBIcf_Callbacks, on); 25 4 29
2190 29 cacheit = 1;
2191 }
2192 39230 ▶ else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "AutoCommit")) {
Branch: 3 branches
BranchTrueFalseTotal
else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "AutoCommit")) { 26183 13047 39230
else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "AutoCommit")) { 5647 20536 26183
else if (htype<=DBIt_DB && keylen==10 && strEQ(key, "AutoCommit")) { 5543 104 5647
2193 /* driver should have intercepted this and either handled it */
2194 /* or set valuesv to either the 'magic' on or off value. */
2195 5543 ▶ if (SvIV(valuesv) != -900 && SvIV(valuesv) != -901)
Branch: 2 branches
BranchTrueFalseTotal
if (SvIV(valuesv) != -900 && SvIV(valuesv) != -901) 5541 2 5543
if (SvIV(valuesv) != -900 && SvIV(valuesv) != -901) 0 5541 5541
2196 0 croak("DBD driver has not implemented the AutoCommit attribute");
2197 5543 ▶ DBIc_set(imp_xxh,DBIcf_AutoCommit, (SvIV(valuesv)==-901));
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_AutoCommit, (SvIV(valuesv)==-901)); 5541 2 5543
2198 }
2199 33687 ▶ else if (htype==DBIt_DB && keylen==9 && strEQ(key, "BegunWork")) {
Branch: 3 branches
BranchTrueFalseTotal
else if (htype==DBIt_DB && keylen==9 && strEQ(key, "BegunWork")) { 20635 13052 33687
else if (htype==DBIt_DB && keylen==9 && strEQ(key, "BegunWork")) { 9 20626 20635
else if (htype==DBIt_DB && keylen==9 && strEQ(key, "BegunWork")) { 2 7 9
2200 2 ▶ DBIc_set(imp_xxh,DBIcf_BegunWork, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_BegunWork, on); 2 0 2
2201 }
2202 33685 ▶ else if (keylen==10 && strEQ(key, "TraceLevel")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==10 && strEQ(key, "TraceLevel")) { 104 33581 33685
else if (keylen==10 && strEQ(key, "TraceLevel")) { 98 6 104
2203 98 set_trace(h, valuesv, Nullsv);
2204 }
2205 33587 ▶ else if (keylen==9 && strEQ(key, "TraceFile")) { /* XXX undocumented and readonly */
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==9 && strEQ(key, "TraceFile")) { /* XXX undocumented and readonly */ 8 33579 33587
else if (keylen==9 && strEQ(key, "TraceFile")) { /* XXX undocumented and readonly */ 0 8 8
2206 0 set_trace_file(valuesv);
2207 }
2208 33587 ▶ else if (htype==DBIt_ST && strEQ(key, "NUM_OF_FIELDS")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (htype==DBIt_ST && strEQ(key, "NUM_OF_FIELDS")) { 13047 20540 33587
else if (htype==DBIt_ST && strEQ(key, "NUM_OF_FIELDS")) { 7799 5248 13047
2209 7799 D_imp_sth(h);
2210 7799 ▶ int new_num_fields = (SvOK(valuesv)) ? SvIV(valuesv) : -1;
Branch: 1 branch
BranchTrueFalseTotal
int new_num_fields = (SvOK(valuesv)) ? SvIV(valuesv) : -1; 7749 50 7799
2211 7799 DBIc_NUM_FIELDS(imp_sth) = new_num_fields;
2212 7799 ▶ if (DBIc_FIELDS_AV(imp_sth)) { /* modify existing fbav */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_FIELDS_AV(imp_sth)) { /* modify existing fbav */ 1845 5954 7799
2213 1845 dbih_setup_fbav(imp_sth);
2214 }
2215 7799 cacheit = 1;
2216 }
2217 25788 ▶ else if (htype==DBIt_ST && strEQ(key, "NUM_OF_PARAMS")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (htype==DBIt_ST && strEQ(key, "NUM_OF_PARAMS")) { 5248 20540 25788
else if (htype==DBIt_ST && strEQ(key, "NUM_OF_PARAMS")) { 5239 9 5248
2218 5239 D_imp_sth(h);
2219 5239 DBIc_NUM_PARAMS(imp_sth) = SvIV(valuesv);
2220 5239 cacheit = 1;
2221 }
2222 /* these are here due to clone() needing to set attribs through a public api */
2223 20549 ▶ else if (htype<=DBIt_DB && (strEQ(key, "Name")
Branch: 2 branches
BranchTrueFalseTotal
else if (htype<=DBIt_DB && (strEQ(key, "Name") 20540 9 20549
else if (htype<=DBIt_DB && (strEQ(key, "Name") 20536 4 20540
2224 20536 ▶ || strEQ(key,"ImplementorClass")
Branch: 1 branch
BranchTrueFalseTotal
|| strEQ(key,"ImplementorClass") 20532 4 20536
2225 20532 ▶ || strEQ(key,"ReadOnly")
Branch: 1 branch
BranchTrueFalseTotal
|| strEQ(key,"ReadOnly") 20253 279 20532
2226 20253 ▶ || strEQ(key,"Statement")
Branch: 1 branch
BranchTrueFalseTotal
|| strEQ(key,"Statement") 20249 4 20253
2227 20249 ▶ || strEQ(key,"Username")
Branch: 1 branch
BranchTrueFalseTotal
|| strEQ(key,"Username") 13870 6379 20249
2228 /* these are here for backwards histerical raisons */
2229 13870 ▶ || strEQ(key,"USER") || strEQ(key,"CURRENT_USER")
Branch: 2 branches
BranchTrueFalseTotal
|| strEQ(key,"USER") || strEQ(key,"CURRENT_USER") 13870 0 13870
|| strEQ(key,"USER") || strEQ(key,"CURRENT_USER") 0 13870 13870
2230 ) ) {
2231 6670 cacheit = 1;
2232 }
2233 /* deal with: NAME_(uc|lc), NAME_hash, NAME_(uc|lc)_hash */
2234 13879 ▶ else if ((keylen==7 || keylen==9 || keylen==12)
Branch: 3 branches
BranchTrueFalseTotal
else if ((keylen==7 || keylen==9 || keylen==12) 13867 12 13879
else if ((keylen==7 || keylen==9 || keylen==12) 13863 4 13867
else if ((keylen==7 || keylen==9 || keylen==12) 4 13859 13863
2235 20 ▶ && strnEQ(key, "NAME_", 5)
Branch: 1 branch
BranchTrueFalseTotal
&& strnEQ(key, "NAME_", 5) 5 15 20
2236 5 ▶ && ( (keylen==9 && strEQ(key, "NAME_hash"))
Branch: 2 branches
BranchTrueFalseTotal
&& ( (keylen==9 && strEQ(key, "NAME_hash")) 1 4 5
&& ( (keylen==9 && strEQ(key, "NAME_hash")) 0 1 1
2237 4 ▶ || ((key[5]=='u' || key[5]=='l') && key[6] == 'c'
Branch: 3 branches
BranchTrueFalseTotal
|| ((key[5]=='u' || key[5]=='l') && key[6] == 'c' 2 2 4
|| ((key[5]=='u' || key[5]=='l') && key[6] == 'c' 2 0 2
|| ((key[5]=='u' || key[5]=='l') && key[6] == 'c' 4 0 4
2238 4 ▶ && (!key[7] || strnEQ(&key[7], "_hash", 5)))
Branch: 2 branches
BranchTrueFalseTotal
&& (!key[7] || strnEQ(&key[7], "_hash", 5))) 2 2 4
&& (!key[7] || strnEQ(&key[7], "_hash", 5))) 2 0 2
2239 )
2240 ) {
2241 5 cacheit = 1;
2242 }
2243 else { /* XXX should really be an event ? */
2244 13874 ▶ if (isUPPER(*key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (isUPPER(*key)) { 2 13872 13874
2245 2 char *msg = "Can't set %s->{%s}: unrecognised attribute name or invalid value%s";
2246 2 char *hint = "";
2247 2 ▶ if (strEQ(key, "NUM_FIELDS"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "NUM_FIELDS")) 0 2 2
2248 0 hint = ", perhaps you meant NUM_OF_FIELDS";
2249 2 warn(msg, neatsvpv(h,0), key, hint);
2250 2 return FALSE; /* don't store it */
2251 }
2252 /* Allow private_* attributes to be stored in the cache. */
2253 /* This is designed to make life easier for people subclassing */
2254 /* the DBI classes and may be of use to simple perl DBD's. */
2255 13872 ▶ if (strnNE(key,"private_",8) && strnNE(key,"dbd_",4) && strnNE(key,"dbi_",4)) {
Branch: 3 branches
BranchTrueFalseTotal
if (strnNE(key,"private_",8) && strnNE(key,"dbd_",4) && strnNE(key,"dbi_",4)) { 13861 11 13872
if (strnNE(key,"private_",8) && strnNE(key,"dbd_",4) && strnNE(key,"dbi_",4)) { 13857 4 13861
if (strnNE(key,"private_",8) && strnNE(key,"dbd_",4) && strnNE(key,"dbi_",4)) { 48 13809 13857
2256 48 ▶ if (DBIc_TRACE_LEVEL(imp_xxh)) { /* change to DBIc_WARN(imp_xxh) once we can validate prefix against registry */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh)) { /* change to DBIc_WARN(imp_xxh) once we can validate prefix against registry */ 0 48 48
2257 0 PerlIO_printf(DBIc_LOGPIO(imp_xxh),"$h->{%s}=%s ignored for invalid driver-specific attribute\n",
2258 neatsvpv(keysv,0), neatsvpv(valuesv,0));
2259 }
2260 48 return FALSE;
2261 }
2262 13824 cacheit = 1;
2263 }
2264 79814 ▶ if (cacheit) {
Branch: 1 branch
BranchTrueFalseTotal
if (cacheit) { 33662 46152 79814
2265 33662 SV *sv_for_cache = newSVsv(valuesv);
2266 33662 (void)hv_store((HV*)SvRV(h), key, keylen, sv_for_cache, 0);
2267 33662 ▶ if (weakenit) {
Branch: 1 branch
BranchTrueFalseTotal
if (weakenit) { 9 33653 33662
2268 #ifdef sv_rvweaken
2269 9 sv_rvweaken(sv_for_cache);
2270 #endif
2271 }
2272 }
2273 79814 return TRUE;
2274 }
2275  
2276  
2277 static SV *
2278 45163 dbih_get_attr_k(SV *h, SV *keysv, int dbikey)
2279 {
2280 dTHX;
2281 dTHR;
2282 45163 D_imp_xxh(h);
2283 STRLEN keylen;
2284 45163 char *key = SvPV(keysv, keylen);
2285 45163 int htype = DBIc_TYPE(imp_xxh);
2286 45163 SV *valuesv = Nullsv;
2287 45163 int cacheit = FALSE;
2288 char *p;
2289 int i;
2290 SV *sv;
2291 SV **svp;
2292 (void)dbikey;
2293  
2294 /* DBI quick_FETCH will service some requests (e.g., cached values) */
2295  
2296 45163 ▶ if (htype == DBIt_ST) {
Branch: 1 branch
BranchTrueFalseTotal
if (htype == DBIt_ST) { 6176 38987 45163
2297 6176 switch (*key) {
2298  
2299 18 case 'D':
2300 18 ▶ if (keylen==8 && strEQ(key, "Database")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==8 && strEQ(key, "Database")) { 18 0 18
if (keylen==8 && strEQ(key, "Database")) { 18 0 18
2301 18 D_imp_from_child(imp_dbh, imp_dbh_t, imp_xxh);
2302 18 valuesv = newRV_inc((SV*)DBIc_MY_H(imp_dbh));
2303 18 cacheit = FALSE; /* else creates ref loop */
2304 }
2305 18 break;
2306  
2307 2306 case 'N':
2308 2306 ▶ if (keylen==8 && strEQ(key, "NULLABLE")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==8 && strEQ(key, "NULLABLE")) { 52 2254 2306
if (keylen==8 && strEQ(key, "NULLABLE")) { 52 0 52
2309 52 valuesv = &PL_sv_undef;
2310 52 break;
2311 }
2312  
2313 2254 ▶ if (keylen==4 && strEQ(key, "NAME")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==4 && strEQ(key, "NAME")) { 56 2198 2254
if (keylen==4 && strEQ(key, "NAME")) { 56 0 56
2314 56 valuesv = &PL_sv_undef;
2315 56 break;
2316 }
2317  
2318 /* deal with: NAME_(uc|lc), NAME_hash, NAME_(uc|lc)_hash */
2319 2198 ▶ if ((keylen==7 || keylen==9 || keylen==12)
Branch: 3 branches
BranchTrueFalseTotal
if ((keylen==7 || keylen==9 || keylen==12) 174 2024 2198
if ((keylen==7 || keylen==9 || keylen==12) 126 48 174
if ((keylen==7 || keylen==9 || keylen==12) 18 108 126
2320 2090 ▶ && strnEQ(key, "NAME_", 5)
Branch: 1 branch
BranchTrueFalseTotal
&& strnEQ(key, "NAME_", 5) 2090 0 2090
2321 2090 ▶ && ( (keylen==9 && strEQ(key, "NAME_hash"))
Branch: 2 branches
BranchTrueFalseTotal
&& ( (keylen==9 && strEQ(key, "NAME_hash")) 48 2042 2090
&& ( (keylen==9 && strEQ(key, "NAME_hash")) 0 48 48
2322 2042 ▶ || ((key[5]=='u' || key[5]=='l') && key[6] == 'c'
Branch: 3 branches
BranchTrueFalseTotal
|| ((key[5]=='u' || key[5]=='l') && key[6] == 'c' 2019 23 2042
|| ((key[5]=='u' || key[5]=='l') && key[6] == 'c' 2019 0 2019
|| ((key[5]=='u' || key[5]=='l') && key[6] == 'c' 2042 0 2042
2323 2042 ▶ && (!key[7] || strnEQ(&key[7], "_hash", 5)))
Branch: 2 branches
BranchTrueFalseTotal
&& (!key[7] || strnEQ(&key[7], "_hash", 5))) 18 2024 2042
&& (!key[7] || strnEQ(&key[7], "_hash", 5))) 18 0 18
2324 )
2325 2090 ) {
2326 2090 D_imp_sth(h);
2327 2090 valuesv = &PL_sv_undef;
2328  
2329 /* fetch from tied outer handle to trigger FETCH magic */
2330 2090 svp = hv_fetchs((HV*)DBIc_MY_H(imp_sth), "NAME", FALSE);
2331 2090 ▶ sv = (svp) ? *svp : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
sv = (svp) ? *svp : &PL_sv_undef; 2090 0 2090
2332 2090 ▶ if (SvGMAGICAL(sv)) /* call FETCH via magic */
Branch: 1 branch
BranchTrueFalseTotal
if (SvGMAGICAL(sv)) /* call FETCH via magic */ 2090 0 2090
2333 2090 mg_get(sv);
2334  
2335 2090 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 2080 10 2090
2336 2080 AV *name_av = (AV*)SvRV(sv);
2337 char *name;
2338 2080 int upcase = (key[5] == 'u');
2339 2080 AV *av = Nullav;
2340 2080 HV *hv = Nullhv;
2341 2080 int num_fields_mismatch = 0;
2342  
2343 2080 ▶ if (strEQ(&key[strlen(key)-5], "_hash"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(&key[strlen(key)-5], "_hash")) 60 2020 2080
2344 60 hv = newHV();
2345 2020 else av = newAV();
2346 2080 i = DBIc_NUM_FIELDS(imp_sth);
2347  
2348 /* catch invalid NUM_FIELDS */
2349 2080 ▶ if (i != AvFILL(name_av)+1) {
Branch: 1 branch
BranchTrueFalseTotal
if (i != AvFILL(name_av)+1) { 0 2080 2080
2350 /* flag as mismatch, except for "-1 and empty" case */
2351 0 ▶ if ( ! (i == -1 && 0 == AvFILL(name_av)+1) )
Branch: 2 branches
BranchTrueFalseTotal
if ( ! (i == -1 && 0 == AvFILL(name_av)+1) ) 0 0 0
if ( ! (i == -1 && 0 == AvFILL(name_av)+1) ) 0 0 0
2352 0 num_fields_mismatch = 1;
2353 0 i = AvFILL(name_av)+1; /* limit for safe iteration over array */
2354 }
2355  
2356 2080 ▶ if (DBIc_TRACE_LEVEL(imp_sth) >= 10 || (num_fields_mismatch && DBIc_WARN(imp_xxh))) {
Branch: 3 branches
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth) >= 10 || (num_fields_mismatch && DBIc_WARN(imp_xxh))) { 2080 0 2080
if (DBIc_TRACE_LEVEL(imp_sth) >= 10 || (num_fields_mismatch && DBIc_WARN(imp_xxh))) { 0 2080 2080
if (DBIc_TRACE_LEVEL(imp_sth) >= 10 || (num_fields_mismatch && DBIc_WARN(imp_xxh))) { 0 0 0
2357 0 ▶ PerlIO_printf(DBIc_LOGPIO(imp_sth)," FETCH $h->{%s} from $h->{NAME} with $h->{NUM_OF_FIELDS} = %d"
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(DBIc_LOGPIO(imp_sth)," FETCH $h->{%s} from $h->{NAME} with $h->{NUM_OF_FIELDS} = %d" 0 0 0
2358 " and %ld entries in $h->{NAME}%s\n",
2359 0 neatsvpv(keysv,0), DBIc_NUM_FIELDS(imp_sth), AvFILL(name_av)+1,
2360 (num_fields_mismatch) ? " (possible bug in driver)" : "");
2361 }
2362  
2363 8170 ▶ while (--i >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (--i >= 0) { 6090 2080 8170
2364 6090 sv = newSVsv(AvARRAY(name_av)[i]);
2365 6090 name = SvPV_nolen(sv);
2366 6090 ▶ if (key[5] != 'h') { /* "NAME_hash" */
Branch: 1 branch
BranchTrueFalseTotal
if (key[5] != 'h') { /* "NAME_hash" */ 5990 100 6090
2367 30011 ▶ for (p = name; p && *p; ++p) {
Branch: 2 branches
BranchTrueFalseTotal
for (p = name; p && *p; ++p) { 30011 0 30011
for (p = name; p && *p; ++p) { 24021 5990 30011
2368 #ifdef toUPPER_LC
2369 24021 ▶ *p = (upcase) ? toUPPER_LC(*p) : toLOWER_LC(*p);
Branch: 6 branches
BranchTrueFalseTotal
*p = (upcase) ? toUPPER_LC(*p) : toLOWER_LC(*p); 251 23770 24021
*p = (upcase) ? toUPPER_LC(*p) : toLOWER_LC(*p); 251 0 251
*p = (upcase) ? toUPPER_LC(*p) : toLOWER_LC(*p); 0 0 0
*p = (upcase) ? toUPPER_LC(*p) : toLOWER_LC(*p); 0 0 0
*p = (upcase) ? toUPPER_LC(*p) : toLOWER_LC(*p); 0 0 0
*p = (upcase) ? toUPPER_LC(*p) : toLOWER_LC(*p); 0 23770 23770
2370 #else
2371 *p = (upcase) ? toUPPER(*p) : toLOWER(*p);
2372 #endif
2373 }
2374 }
2375 6090 ▶ if (av)
Branch: 1 branch
BranchTrueFalseTotal
if (av) 5952 138 6090
2376 5952 av_store(av, i, sv);
2377 else {
2378 138 (void)hv_store(hv, name, SvCUR(sv), newSViv(i), 0);
2379 138 sv_free(sv);
2380 }
2381 }
2382 2080 ▶ valuesv = newRV_noinc( (av ? (SV*)av : (SV*)hv) );
Branch: 1 branch
BranchTrueFalseTotal
valuesv = newRV_noinc( (av ? (SV*)av : (SV*)hv) ); 2020 60 2080
2383 2080 cacheit = TRUE; /* can't change */
2384 }
2385 }
2386 159 ▶ else if (keylen==13 && strEQ(key, "NUM_OF_FIELDS")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==13 && strEQ(key, "NUM_OF_FIELDS")) { 108 0 108
else if (keylen==13 && strEQ(key, "NUM_OF_FIELDS")) { 51 57 108
2387 51 D_imp_sth(h);
2388 51 IV num_fields = DBIc_NUM_FIELDS(imp_sth);
2389 51 ▶ valuesv = (num_fields < 0) ? &PL_sv_undef : newSViv(num_fields);
Branch: 1 branch
BranchTrueFalseTotal
valuesv = (num_fields < 0) ? &PL_sv_undef : newSViv(num_fields); 0 51 51
2390 51 ▶ if (num_fields > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (num_fields > 0) 0 51 51
2391 0 cacheit = TRUE; /* can't change once set (XXX except for multiple result sets) */
2392 }
2393 57 ▶ else if (keylen==13 && strEQ(key, "NUM_OF_PARAMS")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==13 && strEQ(key, "NUM_OF_PARAMS")) { 57 0 57
else if (keylen==13 && strEQ(key, "NUM_OF_PARAMS")) { 57 0 57
2394 57 D_imp_sth(h);
2395 57 valuesv = newSViv(DBIc_NUM_PARAMS(imp_sth));
2396 57 cacheit = TRUE; /* can't change */
2397 }
2398 2198 break;
2399  
2400 152 case 'P':
2401 152 ▶ if (strEQ(key, "PRECISION"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "PRECISION")) 52 100 152
2402 52 valuesv = &PL_sv_undef;
2403 100 ▶ else if (strEQ(key, "ParamValues"))
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ParamValues")) 86 14 100
2404 86 valuesv = &PL_sv_undef;
2405 14 ▶ else if (strEQ(key, "ParamTypes"))
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ParamTypes")) 0 14 14
2406 0 valuesv = &PL_sv_undef;
2407 152 break;
2408  
2409 9 case 'R':
2410 9 ▶ if (strEQ(key, "RowsInCache"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "RowsInCache")) 4 5 9
2411 4 valuesv = &PL_sv_undef;
2412 9 break;
2413  
2414 376 case 'S':
2415 376 ▶ if (strEQ(key, "SCALE"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "SCALE")) 372 4 376
2416 372 valuesv = &PL_sv_undef;
2417 376 break;
2418  
2419 122 case 'T':
2420 122 ▶ if (strEQ(key, "TYPE"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "TYPE")) 52 70 122
2421 52 valuesv = &PL_sv_undef;
2422 122 break;
2423 }
2424  
2425 }
2426 else
2427 38987 ▶ if (htype == DBIt_DB) {
Branch: 1 branch
BranchTrueFalseTotal
if (htype == DBIt_DB) { 38868 119 38987
2428 /* this is here but is, sadly, not called because
2429 * not-preloading them into the handle attrib cache caused
2430 * wierdness in t/proxy.t that I never got to the bottom
2431 * of. One day maybe. */
2432 38868 ▶ if (keylen==6 && strEQ(key, "Driver")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==6 && strEQ(key, "Driver")) { 13040 25828 38868
if (keylen==6 && strEQ(key, "Driver")) { 2529 10511 13040
2433 2529 D_imp_from_child(imp_dbh, imp_dbh_t, imp_xxh);
2434 2529 valuesv = newRV_inc((SV*)DBIc_MY_H(imp_dbh));
2435 2529 cacheit = FALSE; /* else creates ref loop */
2436 }
2437 }
2438  
2439 45163 ▶ if (valuesv == Nullsv && htype <= DBIt_DB) {
Branch: 2 branches
BranchTrueFalseTotal
if (valuesv == Nullsv && htype <= DBIt_DB) { 39744 5419 45163
if (valuesv == Nullsv && htype <= DBIt_DB) { 36458 3286 39744
2440 36458 ▶ if (keylen==10 && strEQ(key, "AutoCommit")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==10 && strEQ(key, "AutoCommit")) { 9086 27372 36458
if (keylen==10 && strEQ(key, "AutoCommit")) { 12 9074 9086
2441 12 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_AutoCommit));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_AutoCommit)); 11 1 12
2442 }
2443 }
2444  
2445 45163 ▶ if (valuesv == Nullsv) {
Branch: 1 branch
BranchTrueFalseTotal
if (valuesv == Nullsv) { 39732 5431 45163
2446 39732 switch (*key) {
2447 11310 case 'A':
2448 11310 ▶ if (keylen==6 && strEQ(key, "Active")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==6 && strEQ(key, "Active")) { 11263 47 11310
if (keylen==6 && strEQ(key, "Active")) { 11263 0 11263
2449 11263 ▶ valuesv = boolSV(DBIc_ACTIVE(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_ACTIVE(imp_xxh)); 10070 1193 11263
2450 }
2451 47 ▶ else if (keylen==10 && strEQ(key, "ActiveKids")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==10 && strEQ(key, "ActiveKids")) { 29 18 47
else if (keylen==10 && strEQ(key, "ActiveKids")) { 29 0 29
2452 29 valuesv = newSViv(DBIc_ACTIVE_KIDS(imp_xxh));
2453 }
2454 18 ▶ else if (strEQ(key, "AutoInactiveDestroy")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "AutoInactiveDestroy")) { 18 0 18
2455 18 ▶ valuesv = boolSV(DBIc_AIADESTROY(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_AIADESTROY(imp_xxh)); 8 10 18
2456 }
2457 11310 break;
2458  
2459 6 case 'B':
2460 6 ▶ if (keylen==9 && strEQ(key, "BegunWork")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==9 && strEQ(key, "BegunWork")) { 4 2 6
if (keylen==9 && strEQ(key, "BegunWork")) { 4 0 4
2461 4 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_BegunWork));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_BegunWork)); 1 3 4
2462 }
2463 6 break;
2464  
2465 9194 case 'C':
2466 9194 ▶ if (strEQ(key, "ChildHandles")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "ChildHandles")) { 42 9152 9194
2467 42 svp = hv_fetch((HV*)SvRV(h), key, keylen, FALSE);
2468 /* if something has been stored then return it.
2469 * otherwise return a dummy empty array if weakrefs are
2470 * available, else an undef to indicate that they're not */
2471 42 ▶ if (svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (svp) { 0 42 42
2472 0 valuesv = newSVsv(*svp);
2473 } else {
2474 #ifdef sv_rvweaken
2475 42 valuesv = newRV_noinc((SV*)newAV());
2476 #else
2477 valuesv = &PL_sv_undef;
2478 #endif
2479 }
2480 }
2481 9152 ▶ else if (strEQ(key, "ChopBlanks")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ChopBlanks")) { 3039 6113 9152
2482 3039 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_ChopBlanks));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_ChopBlanks)); 2 3037 3039
2483 }
2484 6113 ▶ else if (strEQ(key, "CachedKids")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "CachedKids")) { 6080 33 6113
2485 6080 valuesv = &PL_sv_undef;
2486 }
2487 33 ▶ else if (strEQ(key, "CompatMode")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "CompatMode")) { 18 15 33
2488 18 ▶ valuesv = boolSV(DBIc_COMPAT(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_COMPAT(imp_xxh)); 10 8 18
2489 }
2490 9194 break;
2491  
2492 6106 case 'E':
2493 6106 ▶ if (strEQ(key, "Executed")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "Executed")) { 6092 14 6106
2494 6092 ▶ valuesv = boolSV(DBIc_is(imp_xxh, DBIcf_Executed));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_is(imp_xxh, DBIcf_Executed)); 3871 2221 6092
2495 }
2496 14 ▶ else if (strEQ(key, "ErrCount")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ErrCount")) { 14 0 14
2497 14 valuesv = newSVuv(DBIc_ErrCount(imp_xxh));
2498 }
2499 6106 break;
2500  
2501 14 case 'I':
2502 14 ▶ if (strEQ(key, "InactiveDestroy")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "InactiveDestroy")) { 14 0 14
2503 14 ▶ valuesv = boolSV(DBIc_IADESTROY(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_IADESTROY(imp_xxh)); 4 10 14
2504 }
2505 14 break;
2506  
2507 56 case 'K':
2508 56 ▶ if (keylen==4 && strEQ(key, "Kids")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==4 && strEQ(key, "Kids")) { 56 0 56
if (keylen==4 && strEQ(key, "Kids")) { 56 0 56
2509 56 valuesv = newSViv(DBIc_KIDS(imp_xxh));
2510 }
2511 56 break;
2512  
2513 5651 case 'L':
2514 5651 ▶ if (keylen==11 && strEQ(key, "LongReadLen")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==11 && strEQ(key, "LongReadLen")) { 5651 0 5651
if (keylen==11 && strEQ(key, "LongReadLen")) { 2824 2827 5651
2515 2824 valuesv = newSVnv((NV)DBIc_LongReadLen(imp_xxh));
2516 }
2517 2827 ▶ else if (keylen==11 && strEQ(key, "LongTruncOk")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==11 && strEQ(key, "LongTruncOk")) { 2827 0 2827
else if (keylen==11 && strEQ(key, "LongTruncOk")) { 2827 0 2827
2518 2827 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_LongTruncOk));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_LongTruncOk)); 0 2827 2827
2519 }
2520 5651 break;
2521  
2522 0 case 'M':
2523 0 ▶ if (keylen==10 && strEQ(key, "MultiThread")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==10 && strEQ(key, "MultiThread")) { 0 0 0
if (keylen==10 && strEQ(key, "MultiThread")) { 0 0 0
2524 0 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_MultiThread));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_MultiThread)); 0 0 0
2525 }
2526 0 break;
2527  
2528 130 case 'P':
2529 130 ▶ if (keylen==10 && strEQ(key, "PrintError")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==10 && strEQ(key, "PrintError")) { 42 88 130
if (keylen==10 && strEQ(key, "PrintError")) { 42 0 42
2530 42 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_PrintError));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_PrintError)); 22 20 42
2531 }
2532 88 ▶ else if (keylen==9 && strEQ(key, "PrintWarn")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==9 && strEQ(key, "PrintWarn")) { 10 78 88
else if (keylen==9 && strEQ(key, "PrintWarn")) { 10 0 10
2533 10 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_PrintWarn));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_PrintWarn)); 10 0 10
2534 }
2535 130 break;
2536  
2537 2920 case 'R':
2538 2920 ▶ if (keylen==10 && strEQ(key, "RaiseError")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==10 && strEQ(key, "RaiseError")) { 100 2820 2920
if (keylen==10 && strEQ(key, "RaiseError")) { 100 0 100
2539 100 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_RaiseError));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_RaiseError)); 84 16 100
2540 }
2541 2820 ▶ else if (keylen==9 && strEQ(key, "RaiseWarn")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==9 && strEQ(key, "RaiseWarn")) { 10 2810 2820
else if (keylen==9 && strEQ(key, "RaiseWarn")) { 10 0 10
2542 10 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_RaiseWarn));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_RaiseWarn)); 0 10 10
2543 }
2544 2810 ▶ else if (keylen==12 && strEQ(key, "RowCacheSize")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==12 && strEQ(key, "RowCacheSize")) { 2 2808 2810
else if (keylen==12 && strEQ(key, "RowCacheSize")) { 2 0 2
2545 2 valuesv = &PL_sv_undef;
2546 }
2547 2920 break;
2548  
2549 16 case 'S':
2550 16 ▶ if (keylen==18 && strEQ(key, "ShowErrorStatement")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==18 && strEQ(key, "ShowErrorStatement")) { 16 0 16
if (keylen==18 && strEQ(key, "ShowErrorStatement")) { 16 0 16
2551 16 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_ShowErrorStatement));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_ShowErrorStatement)); 4 12 16
2552 }
2553 16 break;
2554  
2555 110 case 'T':
2556 110 ▶ if (keylen==4 && strEQ(key, "Type")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==4 && strEQ(key, "Type")) { 49 61 110
if (keylen==4 && strEQ(key, "Type")) { 49 0 49
2557 49 char *type = dbih_htype_name(htype);
2558 49 valuesv = newSVpv(type,0);
2559 49 cacheit = TRUE; /* can't change */
2560 }
2561 61 ▶ else if (keylen==10 && strEQ(key, "TraceLevel")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==10 && strEQ(key, "TraceLevel")) { 0 61 61
else if (keylen==10 && strEQ(key, "TraceLevel")) { 0 0 0
2562 0 valuesv = newSViv( DBIc_DEBUGIV(imp_xxh) );
2563 }
2564 61 ▶ else if (keylen==5 && strEQ(key, "Taint")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==5 && strEQ(key, "Taint")) { 30 31 61
else if (keylen==5 && strEQ(key, "Taint")) { 30 0 30
2565 30 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintIn) &&
Branch: 2 branches
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintIn) && 5 25 30
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintIn) && 3 2 5
2566 DBIc_has(imp_xxh,DBIcf_TaintOut));
2567 }
2568 31 ▶ else if (keylen==7 && strEQ(key, "TaintIn")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==7 && strEQ(key, "TaintIn")) { 16 15 31
else if (keylen==7 && strEQ(key, "TaintIn")) { 16 0 16
2569 16 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintIn));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintIn)); 4 12 16
2570 }
2571 15 ▶ else if (keylen==8 && strEQ(key, "TaintOut")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (keylen==8 && strEQ(key, "TaintOut")) { 15 0 15
else if (keylen==8 && strEQ(key, "TaintOut")) { 15 0 15
2572 15 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintOut));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintOut)); 2 13 15
2573 }
2574 110 break;
2575  
2576 16 case 'W':
2577 16 ▶ if (keylen==4 && strEQ(key, "Warn")) {
Branch: 2 branches
BranchTrueFalseTotal
if (keylen==4 && strEQ(key, "Warn")) { 16 0 16
if (keylen==4 && strEQ(key, "Warn")) { 16 0 16
2578 16 ▶ valuesv = boolSV(DBIc_WARN(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_WARN(imp_xxh)); 16 0 16
2579 }
2580 16 break;
2581 }
2582 }
2583  
2584 /* finally check the actual hash */
2585 45163 ▶ if (valuesv == Nullsv) {
Branch: 1 branch
BranchTrueFalseTotal
if (valuesv == Nullsv) { 7106 38057 45163
2586 7106 valuesv = &PL_sv_undef;
2587 7106 cacheit = 0;
2588 7106 svp = hv_fetch((HV*)SvRV(h), key, keylen, FALSE);
2589 7106 ▶ if (svp)
Branch: 1 branch
BranchTrueFalseTotal
if (svp) 5 7101 7106
2590 5 valuesv = newSVsv(*svp); /* take copy to mortalize */
2591 else /* warn unless it's known attribute name */
2592 7101 ▶ if ( !( (*key=='H' && strEQ(key, "HandleError"))
Branch: 2 branches
BranchTrueFalseTotal
if ( !( (*key=='H' && strEQ(key, "HandleError")) 8 7093 7101
if ( !( (*key=='H' && strEQ(key, "HandleError")) 0 8 8
2593 7093 ▶ || (*key=='H' && strEQ(key, "HandleSetErr"))
Branch: 2 branches
BranchTrueFalseTotal
|| (*key=='H' && strEQ(key, "HandleSetErr")) 0 7093 7093
|| (*key=='H' && strEQ(key, "HandleSetErr")) 0 0 0
2594 7093 ▶ || (*key=='S' && strEQ(key, "Statement"))
Branch: 2 branches
BranchTrueFalseTotal
|| (*key=='S' && strEQ(key, "Statement")) 0 7093 7093
|| (*key=='S' && strEQ(key, "Statement")) 0 0 0
2595 7093 ▶ || (*key=='P' && strEQ(key, "ParamArrays"))
Branch: 2 branches
BranchTrueFalseTotal
|| (*key=='P' && strEQ(key, "ParamArrays")) 76 7017 7093
|| (*key=='P' && strEQ(key, "ParamArrays")) 76 0 76
2596 7093 ▶ || (*key=='P' && strEQ(key, "ParamValues"))
Branch: 2 branches
BranchTrueFalseTotal
|| (*key=='P' && strEQ(key, "ParamValues")) 76 7017 7093
|| (*key=='P' && strEQ(key, "ParamValues")) 10 66 76
2597 7027 ▶ || (*key=='P' && strEQ(key, "Profile"))
Branch: 2 branches
BranchTrueFalseTotal
|| (*key=='P' && strEQ(key, "Profile")) 10 7017 7027
|| (*key=='P' && strEQ(key, "Profile")) 0 10 10
2598 7017 ▶ || (*key=='R' && strEQ(key, "ReadOnly"))
Branch: 2 branches
BranchTrueFalseTotal
|| (*key=='R' && strEQ(key, "ReadOnly")) 2807 4210 7017
|| (*key=='R' && strEQ(key, "ReadOnly")) 0 2807 2807
2599 4210 ▶ || (*key=='C' && strEQ(key, "CursorName"))
Branch: 2 branches
BranchTrueFalseTotal
|| (*key=='C' && strEQ(key, "CursorName")) 15 4195 4210
|| (*key=='C' && strEQ(key, "CursorName")) 13 2 15
2600 4208 ▶ || (*key=='C' && strEQ(key, "Callbacks"))
Branch: 2 branches
BranchTrueFalseTotal
|| (*key=='C' && strEQ(key, "Callbacks")) 13 4195 4208
|| (*key=='C' && strEQ(key, "Callbacks")) 0 13 13
2601 4195 ▶ || (*key=='U' && strEQ(key, "Username"))
Branch: 2 branches
BranchTrueFalseTotal
|| (*key=='U' && strEQ(key, "Username")) 6 4189 4195
|| (*key=='U' && strEQ(key, "Username")) 0 6 6
2602 4189 ▶ || !isUPPER(*key) /* dbd_*, private_* etc */
Branch: 1 branch
BranchTrueFalseTotal
|| !isUPPER(*key) /* dbd_*, private_* etc */ 2 4187 4189
2603 ))
2604 2 warn("Can't get %s->{%s}: unrecognised attribute name",neatsvpv(h,0),key);
2605 }
2606  
2607 45163 ▶ if (cacheit) {
Branch: 1 branch
BranchTrueFalseTotal
if (cacheit) { 2186 42977 45163
2608 2186 (void)hv_store((HV*)SvRV(h), key, keylen, newSVsv(valuesv), 0);
2609 }
2610 45163 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 3) 34 45129 45163
2611 34 ▶ PerlIO_printf(DBIc_LOGPIO(imp_xxh)," .. FETCH %s %s = %s%s\n", neatsvpv(h,0),
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(DBIc_LOGPIO(imp_xxh)," .. FETCH %s %s = %s%s\n", neatsvpv(h,0), 0 34 34
2612 neatsvpv(keysv,0), neatsvpv(valuesv,0), cacheit?" (cached)":"");
2613 45163 ▶ if (valuesv == &PL_sv_yes || valuesv == &PL_sv_no || valuesv == &PL_sv_undef)
Branch: 3 branches
BranchTrueFalseTotal
if (valuesv == &PL_sv_yes || valuesv == &PL_sv_no || valuesv == &PL_sv_undef) 31041 14122 45163
if (valuesv == &PL_sv_yes || valuesv == &PL_sv_no || valuesv == &PL_sv_undef) 21621 9420 31041
if (valuesv == &PL_sv_yes || valuesv == &PL_sv_no || valuesv == &PL_sv_undef) 13918 7703 21621
2614 37460 return valuesv; /* no need to mortalize yes or no */
2615 7703 return sv_2mortal(valuesv);
2616 }
2617  
2618  
2619  
2620 /* -------------------------------------------------------------------- */
2621 /* Functions implementing Error and Event Handling. */
2622  
2623  
2624 static SV *
2625 0 dbih_event(SV *hrv, const char *evtype, SV *a1, SV *a2)
2626 {
2627 dTHX;
2628 /* We arrive here via DBIh_EVENT* macros (see DBIXS.h) called from */
2629 /* DBD driver C code OR $h->event() method (in DBD::_::common) */
2630 /* XXX VERY OLD INTERFACE/CONCEPT MAY GO SOON */
2631 /* OR MAY EVOLVE INTO A WAY TO HANDLE 'SUCCESS_WITH_INFO'/'WARNINGS' from db */
2632 (void)hrv;
2633 (void)evtype;
2634 (void)a1;
2635 (void)a2;
2636 0 return &PL_sv_undef;
2637 }
2638  
2639  
2640 /* ----------------------------------------------------------------- */
2641  
2642  
2643 STATIC I32
2644 3287 dbi_dopoptosub_at(PERL_CONTEXT *cxstk, I32 startingblock)
2645 {
2646 dTHX;
2647 I32 i;
2648 register PERL_CONTEXT *cx;
2649 4239 ▶ for (i = startingblock; i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = startingblock; i >= 0; i--) { 4080 159 4239
2650 4080 cx = &cxstk[i];
2651 4080 ▶ switch (CxTYPE(cx)) {
Branch: 1 branch
BranchTrueFalseTotal
switch (CxTYPE(cx)) { 952 3128 4080
2652 952 default:
2653 952 continue;
2654 3128 case CXt_EVAL:
2655 case CXt_SUB:
2656 #ifdef CXt_FORMAT
2657 case CXt_FORMAT:
2658 #endif
2659 DEBUG_l( Perl_deb(aTHX_ "(Found sub #%ld)\n", (long)i));
2660 3128 return i;
2661 }
2662 }
2663 159 return i;
2664 }
2665  
2666  
2667 static COP *
2668 312 dbi_caller_cop()
2669 {
2670 dTHX;
2671 register I32 cxix;
2672 register PERL_CONTEXT *cx;
2673 312 register PERL_CONTEXT *ccstack = cxstack;
2674 312 PERL_SI *top_si = PL_curstackinfo;
2675 char *stashname;
2676  
2677 1740 for ( cxix = dbi_dopoptosub_at(ccstack, cxstack_ix) ;; cxix = dbi_dopoptosub_at(ccstack, cxix - 1)) {
2678 /* we may be in a higher stacklevel, so dig down deeper */
2679 1859 ▶ while (cxix < 0 && top_si->si_type != PERLSI_MAIN) {
Branch: 2 branches
BranchTrueFalseTotal
while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { 134 1725 1859
while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { 119 15 134
2680 119 top_si = top_si->si_prev;
2681 119 ccstack = top_si->si_cxstack;
2682 119 cxix = dbi_dopoptosub_at(ccstack, top_si->si_cxix);
2683 }
2684 1740 ▶ if (cxix < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (cxix < 0) { 15 1725 1740
2685 15 break;
2686 }
2687 /* skip the automatic calls to &DB::sub, as perl's pp_caller does */
2688 1725 ▶ if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub))
Branch: 4 branches
BranchTrueFalseTotal
if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) 1725 0 1725
if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) 0 1725 1725
if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) 0 0 0
if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) 0 0 0
2689 0 continue;
2690 1725 cx = &ccstack[cxix];
2691 1725 ▶ stashname = CopSTASHPV(cx->blk_oldcop);
Branch: 7 branches
BranchTrueFalseTotal
stashname = CopSTASHPV(cx->blk_oldcop); 1725 0 1725
stashname = CopSTASHPV(cx->blk_oldcop); 1725 0 1725
stashname = CopSTASHPV(cx->blk_oldcop); 1725 0 1725
stashname = CopSTASHPV(cx->blk_oldcop); 0 1725 1725
stashname = CopSTASHPV(cx->blk_oldcop); 0 0 0
stashname = CopSTASHPV(cx->blk_oldcop); 1725 0 1725
stashname = CopSTASHPV(cx->blk_oldcop); 0 1725 1725
2692 1725 ▶ if (!stashname)
Branch: 1 branch
BranchTrueFalseTotal
if (!stashname) 0 1725 1725
2693 0 continue;
2694 1725 ▶ if (!(stashname[0] == 'D' && stashname[1] == 'B'
Branch: 2 branches
BranchTrueFalseTotal
if (!(stashname[0] == 'D' && stashname[1] == 'B' 1428 297 1725
if (!(stashname[0] == 'D' && stashname[1] == 'B' 1428 0 1428
2695 1428 ▶ && strchr("DI", stashname[2])
Branch: 1 branch
BranchTrueFalseTotal
&& strchr("DI", stashname[2]) 1428 0 1428
2696 1428 ▶ && (!stashname[3] || (stashname[3] == ':' && stashname[4] == ':'))))
Branch: 3 branches
BranchTrueFalseTotal
&& (!stashname[3] || (stashname[3] == ':' && stashname[4] == ':')))) 1312 116 1428
&& (!stashname[3] || (stashname[3] == ':' && stashname[4] == ':')))) 1312 0 1312
&& (!stashname[3] || (stashname[3] == ':' && stashname[4] == ':')))) 0 1312 1312
2697 {
2698 297 return cx->blk_oldcop;
2699 }
2700 1428 cxix = dbi_dopoptosub_at(ccstack, cxix - 1);
2701 }
2702 15 return NULL;
2703 }
2704  
2705 static void
2706 664 dbi_caller_string(SV *buf, COP *cop, char *prefix, int show_line, int show_path)
2707 {
2708 dTHX;
2709 STRLEN len;
2710 664 long line = CopLINE(cop);
2711 664 char *file = SvPV(GvSV(CopFILEGV(cop)), len);
2712 664 ▶ if (!show_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (!show_path) { 192 472 664
2713 char *sep;
2714 192 ▶ if ( (sep=strrchr(file,'/')) || (sep=strrchr(file,'\\')))
Branch: 2 branches
BranchTrueFalseTotal
if ( (sep=strrchr(file,'/')) || (sep=strrchr(file,'\\'))) 0 192 192
if ( (sep=strrchr(file,'/')) || (sep=strrchr(file,'\\'))) 0 0 0
2715 192 file = sep+1;
2716 }
2717 664 ▶ if (show_line) {
Branch: 1 branch
BranchTrueFalseTotal
if (show_line) { 652 12 664
2718 652 ▶ sv_catpvf(buf, "%s%s line %ld", (prefix) ? prefix : "", file, line);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(buf, "%s%s line %ld", (prefix) ? prefix : "", file, line); 652 0 652
2719 }
2720 else {
2721 12 ▶ sv_catpvf(buf, "%s%s", (prefix) ? prefix : "", file);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(buf, "%s%s", (prefix) ? prefix : "", file); 12 0 12
2722 }
2723 664 }
2724  
2725 static char *
2726 369 log_where(SV *buf, int append, char *prefix, char *suffix, int show_line, int show_caller, int show_path)
2727 {
2728 dTHX;
2729 dTHR;
2730 369 ▶ if (!buf)
Branch: 1 branch
BranchTrueFalseTotal
if (!buf) 369 0 369
2731 369 buf = sv_2mortal(newSVpvs(""));
2732 0 ▶ else if (!append)
Branch: 1 branch
BranchTrueFalseTotal
else if (!append) 0 0 0
2733 0 sv_setpv(buf,"");
2734 369 ▶ if (CopLINE(PL_curcop)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CopLINE(PL_curcop)) { 367 2 369
2735 COP *cop;
2736 367 dbi_caller_string(buf, PL_curcop, prefix, show_line, show_path);
2737 367 ▶ if (show_caller && (cop = dbi_caller_cop())) {
Branch: 2 branches
BranchTrueFalseTotal
if (show_caller && (cop = dbi_caller_cop())) { 312 55 367
if (show_caller && (cop = dbi_caller_cop())) { 297 15 312
2738 297 SV *via = sv_2mortal(newSVpvs(""));
2739 297 dbi_caller_string(via, cop, prefix, show_line, show_path);
2740 297 sv_catpvf(buf, " via %s", SvPV_nolen(via));
2741 }
2742 }
2743 369 ▶ if (PL_dirty)
Branch: 1 branch
BranchTrueFalseTotal
if (PL_dirty) 0 369 369
2744 0 sv_catpvf(buf, " during global destruction");
2745 369 ▶ if (suffix)
Branch: 1 branch
BranchTrueFalseTotal
if (suffix) 369 0 369
2746 369 sv_catpv(buf, suffix);
2747 369 return SvPVX(buf);
2748 }
2749  
2750  
2751 static void
2752 13324 clear_cached_kids(pTHX_ SV *h, imp_xxh_t *imp_xxh, const char *meth_name, int trace_level)
2753 {
2754 13324 ▶ if (DBIc_TYPE(imp_xxh) <= DBIt_DB) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp_xxh) <= DBIt_DB) { 7296 6028 13324
2755 7296 SV **svp = hv_fetchs((HV*)SvRV(h), "CachedKids", 0);
2756 7296 ▶ if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) {
Branch: 3 branches
BranchTrueFalseTotal
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 272 7024 7296
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 264 8 272
if (svp && SvROK(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV) { 264 0 264
2757 264 HV *hv = (HV*)SvRV(*svp);
2758 264 ▶ if (HvKEYS(hv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (HvKEYS(hv)) { 0 264 264
if (HvKEYS(hv)) { 132 132 264
2759 132 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) > trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) > trace_level) 0 132 132
2760 0 trace_level = DBIc_TRACE_LEVEL(imp_xxh);
2761 132 ▶ if (trace_level >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 2) { 0 132 132
2762 0 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," >> %s %s clearing %d CachedKids\n",
2763 0 ▶ meth_name, neatsvpv(h,0), (int)HvKEYS(hv));
Branch: 1 branch
BranchTrueFalseTotal
meth_name, neatsvpv(h,0), (int)HvKEYS(hv)); 0 0 0
2764 0 PerlIO_flush(DBIc_LOGPIO(imp_xxh));
2765 }
2766 /* This will probably recurse through dispatch to DESTROY the kids */
2767 /* For drh we should probably explicitly do dbh disconnects */
2768 132 hv_clear(hv);
2769 }
2770 }
2771 }
2772 13324 }
2773  
2774  
2775 static NV
2776 2672715 dbi_time() {
2777 # ifdef HAS_GETTIMEOFDAY
2778 # ifdef PERL_IMPLICIT_SYS
2779 dTHX;
2780 # endif
2781 struct timeval when;
2782 2672715 gettimeofday(&when, (struct timezone *) 0);
2783 2672715 return when.tv_sec + (when.tv_usec / 1000000.0);
2784 # else /* per-second is almost useless */
2785 # ifdef _WIN32 /* use _ftime() on Win32 (MS Visual C++ 6.0) */
2786 # if defined(__BORLANDC__)
2787 # define _timeb timeb
2788 # define _ftime ftime
2789 # endif
2790 struct _timeb when;
2791 _ftime( &when );
2792 return when.time + (when.millitm / 1000.0);
2793 # else
2794 return time(NULL);
2795 # endif
2796 # endif
2797 }
2798  
2799  
2800 static SV *
2801 45075 _profile_next_node(SV *node, const char *name)
2802 {
2803 /* step one level down profile Data tree and auto-vivify if required */
2804 dTHX;
2805 45075 SV *orig_node = node;
2806 45075 ▶ if (SvROK(node))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(node)) 44823 252 45075
2807 44823 node = SvRV(node);
2808 45075 ▶ if (SvTYPE(node) != SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(node) != SVt_PVHV) { 252 44823 45075
2809 252 HV *hv = newHV();
2810 252 ▶ if (SvOK(node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(node)) { 0 252 252
2811 0 char *key = "(demoted)";
2812 0 warn("Profile data element %s replaced with new hash ref (for %s) and original value stored with key '%s'",
2813 neatsvpv(orig_node,0), name, key);
2814 0 (void)hv_store(hv, key, strlen(key), SvREFCNT_inc(orig_node), 0);
2815 }
2816 252 sv_setsv(node, newRV_noinc((SV*)hv));
2817 252 node = (SV*)hv;
2818 }
2819 45075 node = *hv_fetch((HV*)node, name, strlen(name), 1);
2820 45075 return node;
2821 }
2822  
2823  
2824 static SV*
2825 61077 dbi_profile(SV *h, imp_xxh_t *imp_xxh, SV *statement_sv, SV *method, NV t1, NV t2)
2826 {
2827 #define DBIprof_MAX_PATH_ELEM 100
2828 #define DBIprof_COUNT 0
2829 #define DBIprof_TOTAL_TIME 1
2830 #define DBIprof_FIRST_TIME 2
2831 #define DBIprof_MIN_TIME 3
2832 #define DBIprof_MAX_TIME 4
2833 #define DBIprof_FIRST_CALLED 5
2834 #define DBIprof_LAST_CALLED 6
2835 #define DBIprof_max_index 6
2836 dTHX;
2837 61077 NV ti = t2 - t1;
2838 61077 int src_idx = 0;
2839 61077 HV *dbh_outer_hv = NULL;
2840 61077 HV *dbh_inner_hv = NULL;
2841 char *statement_pv;
2842 char *method_pv;
2843 SV *profile;
2844 SV *tmp;
2845 SV *dest_node;
2846 AV *av;
2847 HV *h_hv;
2848  
2849 61077 const int call_depth = DBIc_CALL_DEPTH(imp_xxh);
2850 61077 ▶ const int parent_call_depth = DBIc_PARENT_COM(imp_xxh) ? DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh)) : 0;
Branch: 1 branch
BranchTrueFalseTotal
const int parent_call_depth = DBIc_PARENT_COM(imp_xxh) ? DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh)) : 0; 61063 14 61077
2851 /* Only count calls originating from the application code */
2852 61077 ▶ if (call_depth > 1 || parent_call_depth > 0)
Branch: 2 branches
BranchTrueFalseTotal
if (call_depth > 1 || parent_call_depth > 0) 17240 43837 61077
if (call_depth > 1 || parent_call_depth > 0) 384 16856 17240
2853 44221 return &PL_sv_undef;
2854  
2855 16856 ▶ if (!DBIc_has(imp_xxh, DBIcf_Profile))
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIc_has(imp_xxh, DBIcf_Profile)) 3 16853 16856
2856 3 return &PL_sv_undef;
2857  
2858 15 method_pv = (SvTYPE(method)==SVt_PVCV) ? GvNAME(CvGV(method))
2859 33706 ▶ : isGV(method) ? GvNAME(method)
Branch: 1 branch
BranchTrueFalseTotal
: isGV(method) ? GvNAME(method) 15 16838 16853
2860 16844 ▶ : SvOK(method) ? SvPV_nolen(method)
Branch: 1 branch
BranchTrueFalseTotal
: SvOK(method) ? SvPV_nolen(method) 16832 6 16838
2861 6 ▶ : "";
Branch: 1 branch
BranchTrueFalseTotal
: ""; 6 0 6
2862  
2863 /* we don't profile DESTROY during global destruction */
2864 16853 ▶ if (PL_dirty && instr(method_pv, "DESTROY"))
Branch: 2 branches
BranchTrueFalseTotal
if (PL_dirty && instr(method_pv, "DESTROY")) 5 16848 16853
if (PL_dirty && instr(method_pv, "DESTROY")) 4 1 5
2865 4 return &PL_sv_undef;
2866  
2867 16849 h_hv = (HV*)SvRV(dbih_inner(aTHX_ h, "dbi_profile"));
2868  
2869 16849 profile = *hv_fetchs(h_hv, "Profile", 1);
2870 16849 ▶ if (profile && SvMAGICAL(profile))
Branch: 2 branches
BranchTrueFalseTotal
if (profile && SvMAGICAL(profile)) 16849 0 16849
if (profile && SvMAGICAL(profile)) 0 16849 16849
2871 0 mg_get(profile); /* FETCH */
2872 16849 ▶ if (!profile || !SvROK(profile)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!profile || !SvROK(profile)) { 16849 0 16849
if (!profile || !SvROK(profile)) { 1 16848 16849
2873 1 DBIc_set(imp_xxh, DBIcf_Profile, 0); /* disable */
2874 1 ▶ if (!PL_dirty) {
Branch: 1 branch
BranchTrueFalseTotal
if (!PL_dirty) { 0 1 1
2875 0 ▶ if (!profile)
Branch: 1 branch
BranchTrueFalseTotal
if (!profile) 0 0 0
2876 0 warn("Profile attribute does not exist");
2877 0 ▶ else if (SvOK(profile))
Branch: 1 branch
BranchTrueFalseTotal
else if (SvOK(profile)) 0 0 0
2878 0 warn("Profile attribute isn't a hash ref (%s,%ld)", neatsvpv(profile,0), (long)SvTYPE(profile));
2879 }
2880 1 return &PL_sv_undef;
2881 }
2882  
2883 /* statement_sv: undef = use $h->{Statement}, "" (&sv_no) = use empty string */
2884  
2885 16848 ▶ if (!SvOK(statement_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(statement_sv)) { 16584 264 16848
2886 16584 SV **psv = hv_fetchs(h_hv, "Statement", 0);
2887 16584 ▶ statement_sv = (psv && SvOK(*psv)) ? *psv : &PL_sv_no;
Branch: 2 branches
BranchTrueFalseTotal
statement_sv = (psv && SvOK(*psv)) ? *psv : &PL_sv_no; 16584 0 16584
statement_sv = (psv && SvOK(*psv)) ? *psv : &PL_sv_no; 16530 54 16584
2888 }
2889 16848 statement_pv = SvPV_nolen(statement_sv);
2890  
2891 16848 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 4)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 4) 0 16848 16848
2892 0 PerlIO_printf(DBIc_LOGPIO(imp_xxh), " dbi_profile +%" NVff "s %s %s\n",
2893 ti, method_pv, neatsvpv(statement_sv,0));
2894  
2895 16848 dest_node = _profile_next_node(profile, "Data");
2896  
2897 16848 tmp = *hv_fetchs((HV*)SvRV(profile), "Path", 1);
2898 33631 ▶ if (SvROK(tmp) && SvTYPE(SvRV(tmp))==SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(tmp) && SvTYPE(SvRV(tmp))==SVt_PVAV) { 16848 0 16848
if (SvROK(tmp) && SvTYPE(SvRV(tmp))==SVt_PVAV) { 16848 0 16848
2899 int len;
2900 16848 av = (AV*)SvRV(tmp);
2901 16848 len = av_len(av); /* -1=empty, 0=one element */
2902  
2903 45038 ▶ while ( src_idx <= len ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( src_idx <= len ) { 28255 16783 45038
2904 28255 SV *pathsv = AvARRAY(av)[src_idx++];
2905  
2906 28354 ▶ if (SvROK(pathsv) && SvTYPE(SvRV(pathsv))==SVt_PVCV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(pathsv) && SvTYPE(SvRV(pathsv))==SVt_PVCV) { 186 28069 28255
if (SvROK(pathsv) && SvTYPE(SvRV(pathsv))==SVt_PVCV) { 164 22 186
2907 /* call sub, use returned list of values as path */
2908 /* returning a ref to undef vetos this profile data */
2909 164 dSP;
2910 I32 ax;
2911 164 SV *code_sv = SvRV(pathsv);
2912 I32 items;
2913 I32 item_idx;
2914 164 ▶ EXTEND(SP, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 4); 0 164 164
2915 164 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 164 164
2916 164 PUSHs(h); /* push inner handle, then others params */
2917 164 mPUSHs(newSVpv(method_pv, 0));
2918 164 PUTBACK;
2919 164 SAVE_DEFSV; /* local($_) = $statement */
2920 164 DEFSV_set(statement_sv);
2921 164 items = call_sv(code_sv, G_LIST);
2922 164 SPAGAIN;
2923 164 SP -= items ;
2924 164 ax = (SP - PL_stack_base) + 1 ;
2925 300 ▶ for (item_idx=0; item_idx < items; ++item_idx) {
Branch: 1 branch
BranchTrueFalseTotal
for (item_idx=0; item_idx < items; ++item_idx) { 201 99 300
2926 201 SV *item_sv = ST(item_idx);
2927 201 ▶ if (SvROK(item_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(item_sv)) { 65 136 201
2928 65 ▶ if (!SvOK(SvRV(item_sv)))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(SvRV(item_sv))) 65 0 65
2929 65 items = -2; /* flag that we're rejecting this profile data */
2930 else /* other refs reserved */
2931 0 warn("Ignored ref returned by code ref in Profile Path");
2932 65 break;
2933 }
2934 272 ▶ dest_node = _profile_next_node(dest_node, (SvOK(item_sv) ? SvPV_nolen(item_sv) : "undef"));
Branch: 1 branch
BranchTrueFalseTotal
dest_node = _profile_next_node(dest_node, (SvOK(item_sv) ? SvPV_nolen(item_sv) : "undef")); 136 0 136
2935 }
2936 164 PUTBACK;
2937 164 ▶ if (items == -2) /* this profile data was vetoed */
Branch: 1 branch
BranchTrueFalseTotal
if (items == -2) /* this profile data was vetoed */ 65 99 164
2938 65 return &PL_sv_undef;
2939 }
2940 28091 ▶ else if (SvROK(pathsv)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvROK(pathsv)) { 22 28069 28091
2941 /* only meant for refs to scalars currently */
2942 22 const char *p = SvPV_nolen(SvRV(pathsv));
2943 22 dest_node = _profile_next_node(dest_node, p);
2944 }
2945 28069 ▶ else if (SvOK(pathsv)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvOK(pathsv)) { 28069 0 28069
2946 STRLEN len;
2947 28069 const char *p = SvPV(pathsv,len);
2948 28069 ▶ if (p[0] == '!') { /* special cases */
Branch: 1 branch
BranchTrueFalseTotal
if (p[0] == '!') { /* special cases */ 27899 170 28069
2949 27899 ▶ if (p[1] == 'S' && strEQ(p, "!Statement")) {
Branch: 2 branches
BranchTrueFalseTotal
if (p[1] == 'S' && strEQ(p, "!Statement")) { 16638 11261 27899
if (p[1] == 'S' && strEQ(p, "!Statement")) { 16638 0 16638
2950 16638 dest_node = _profile_next_node(dest_node, statement_pv);
2951 }
2952 11261 ▶ else if (p[1] == 'M' && strEQ(p, "!MethodName")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (p[1] == 'M' && strEQ(p, "!MethodName")) { 11229 32 11261
else if (p[1] == 'M' && strEQ(p, "!MethodName")) { 11229 0 11229
2953 11229 dest_node = _profile_next_node(dest_node, method_pv);
2954 }
2955 32 ▶ else if (p[1] == 'M' && strEQ(p, "!MethodClass")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (p[1] == 'M' && strEQ(p, "!MethodClass")) { 0 32 32
else if (p[1] == 'M' && strEQ(p, "!MethodClass")) { 0 0 0
2956 0 ▶ if (SvTYPE(method) == SVt_PVCV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(method) == SVt_PVCV) { 0 0 0
2957 0 p = SvPV_nolen((SV*)CvGV(method));
2958 }
2959 0 ▶ else if (isGV(method)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (isGV(method)) { 0 0 0
2960 /* just using SvPV_nolen(method) sometimes causes an error: */
2961 /* "Can't coerce GLOB to string" so we use gv_efullname() */
2962 0 SV *tmpsv = sv_2mortal(newSVpvs(""));
2963 0 gv_efullname4(tmpsv, (GV*)method, "", TRUE);
2964 0 p = SvPV_nolen(tmpsv);
2965 0 ▶ if (*p == '*') ++p; /* skip past leading '*' glob sigil */
Branch: 1 branch
BranchTrueFalseTotal
if (*p == '*') ++p; /* skip past leading '*' glob sigil */ 0 0 0
2966 }
2967 else {
2968 0 p = method_pv;
2969 }
2970 0 dest_node = _profile_next_node(dest_node, p);
2971 }
2972 32 ▶ else if (p[1] == 'F' && strEQ(p, "!File")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (p[1] == 'F' && strEQ(p, "!File")) { 8 24 32
else if (p[1] == 'F' && strEQ(p, "!File")) { 4 4 8
2973 4 dest_node = _profile_next_node(dest_node, log_where(0, 0, "", "", 0, 0, 0));
2974 }
2975 28 ▶ else if (p[1] == 'F' && strEQ(p, "!File2")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (p[1] == 'F' && strEQ(p, "!File2")) { 4 24 28
else if (p[1] == 'F' && strEQ(p, "!File2")) { 4 0 4
2976 4 dest_node = _profile_next_node(dest_node, log_where(0, 0, "", "", 0, 1, 0));
2977 }
2978 24 ▶ else if (p[1] == 'C' && strEQ(p, "!Caller")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (p[1] == 'C' && strEQ(p, "!Caller")) { 16 8 24
else if (p[1] == 'C' && strEQ(p, "!Caller")) { 4 12 16
2979 4 dest_node = _profile_next_node(dest_node, log_where(0, 0, "", "", 1, 0, 0));
2980 }
2981 20 ▶ else if (p[1] == 'C' && strEQ(p, "!Caller2")) {
Branch: 2 branches
BranchTrueFalseTotal
else if (p[1] == 'C' && strEQ(p, "!Caller2")) { 12 8 20
else if (p[1] == 'C' && strEQ(p, "!Caller2")) { 12 0 12
2982 12 dest_node = _profile_next_node(dest_node, log_where(0, 0, "", "", 1, 1, 0));
2983 }
2984 16 ▶ else if (p[1] == 'T' && (strEQ(p, "!Time") || strnEQ(p, "!Time~", 6))) {
Branch: 3 branches
BranchTrueFalseTotal
else if (p[1] == 'T' && (strEQ(p, "!Time") || strnEQ(p, "!Time~", 6))) { 8 0 8
else if (p[1] == 'T' && (strEQ(p, "!Time") || strnEQ(p, "!Time~", 6))) { 4 4 8
else if (p[1] == 'T' && (strEQ(p, "!Time") || strnEQ(p, "!Time~", 6))) { 4 0 4
2985 char timebuf[20];
2986 8 int factor = 1;
2987 8 ▶ if (p[5] == '~') {
Branch: 1 branch
BranchTrueFalseTotal
if (p[5] == '~') { 4 4 8
2988 4 factor = atoi(&p[6]);
2989 4 ▶ if (factor == 0) /* sanity check to avoid div by zero error */
Branch: 1 branch
BranchTrueFalseTotal
if (factor == 0) /* sanity check to avoid div by zero error */ 0 4 4
2990 0 factor = 3600;
2991 }
2992 8 sprintf(timebuf, "%ld", ((long)(dbi_time()/factor))*factor);
2993 8 dest_node = _profile_next_node(dest_node, timebuf);
2994 }
2995 else {
2996 0 warn("Unknown ! element in DBI::Profile Path: %s", p);
2997 0 dest_node = _profile_next_node(dest_node, p);
2998 }
2999 }
3000 192 ▶ else if (p[0] == '{' && p[len-1] == '}') { /* treat as name of dbh attribute to use */
Branch: 2 branches
BranchTrueFalseTotal
else if (p[0] == '{' && p[len-1] == '}') { /* treat as name of dbh attribute to use */ 22 148 170
else if (p[0] == '{' && p[len-1] == '}') { /* treat as name of dbh attribute to use */ 22 0 22
3001 SV **attr_svp;
3002 22 ▶ if (!dbh_inner_hv) { /* cache dbh handles the first time we need them */
Branch: 1 branch
BranchTrueFalseTotal
if (!dbh_inner_hv) { /* cache dbh handles the first time we need them */ 22 0 22
3003 22 ▶ imp_dbh_t *imp_dbh = (DBIc_TYPE(imp_xxh) <= DBIt_DB) ? (imp_dbh_t*)imp_xxh : (imp_dbh_t*)DBIc_PARENT_COM(imp_xxh);
Branch: 1 branch
BranchTrueFalseTotal
imp_dbh_t *imp_dbh = (DBIc_TYPE(imp_xxh) <= DBIt_DB) ? (imp_dbh_t*)imp_xxh : (imp_dbh_t*)DBIc_PARENT_COM(imp_xxh); 8 14 22
3004 22 dbh_outer_hv = DBIc_MY_H(imp_dbh);
3005 22 ▶ if (SvTYPE(dbh_outer_hv) != SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(dbh_outer_hv) != SVt_PVHV) 0 22 22
3006 0 return &PL_sv_undef; /* presumably global destruction - bail */
3007 22 dbh_inner_hv = (HV*)SvRV(dbih_inner(aTHX_ (SV*)dbh_outer_hv, "profile"));
3008 22 ▶ if (SvTYPE(dbh_inner_hv) != SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(dbh_inner_hv) != SVt_PVHV) 0 22 22
3009 0 return &PL_sv_undef; /* presumably global destruction - bail */
3010 }
3011 /* fetch from inner first, then outer if key doesn't exist */
3012 /* (yes, this is an evil premature optimization) */
3013 22 p += 1; len -= 2; /* ignore the braces */
3014 22 ▶ if ((attr_svp = hv_fetch(dbh_inner_hv, p, len, 0)) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ((attr_svp = hv_fetch(dbh_inner_hv, p, len, 0)) == NULL) { 6 16 22
3015 /* try outer (tied) hash - for things like AutoCommit */
3016 /* (will always return something even for unknowns) */
3017 6 ▶ if ((attr_svp = hv_fetch(dbh_outer_hv, p, len, 0))) {
Branch: 1 branch
BranchTrueFalseTotal
if ((attr_svp = hv_fetch(dbh_outer_hv, p, len, 0))) { 6 0 6
3018 6 ▶ if (SvGMAGICAL(*attr_svp))
Branch: 1 branch
BranchTrueFalseTotal
if (SvGMAGICAL(*attr_svp)) 6 0 6
3019 6 mg_get(*attr_svp); /* FETCH */
3020 }
3021 }
3022 22 ▶ if (!attr_svp)
Branch: 1 branch
BranchTrueFalseTotal
if (!attr_svp) 0 22 22
3023 0 p -= 1; /* unignore the braces */
3024 22 ▶ else if (!SvOK(*attr_svp))
Branch: 1 branch
BranchTrueFalseTotal
else if (!SvOK(*attr_svp)) 6 16 22
3025 6 p = "";
3026 16 ▶ else if (!SvTRUE(*attr_svp) && SvPOK(*attr_svp) && SvNIOK(*attr_svp))
Branch: 3 branches
BranchTrueFalseTotal
else if (!SvTRUE(*attr_svp) && SvPOK(*attr_svp) && SvNIOK(*attr_svp)) 0 16 16
else if (!SvTRUE(*attr_svp) && SvPOK(*attr_svp) && SvNIOK(*attr_svp)) 0 0 0
else if (!SvTRUE(*attr_svp) && SvPOK(*attr_svp) && SvNIOK(*attr_svp)) 0 0 0
3027 0 p = "0"; /* catch &sv_no style special case */
3028 else
3029 32 p = SvPV_nolen(*attr_svp);
3030 22 dest_node = _profile_next_node(dest_node, p);
3031 }
3032 else {
3033 148 dest_node = _profile_next_node(dest_node, p);
3034 }
3035 }
3036 /* else undef, so ignore */
3037 }
3038 }
3039 else { /* a bad Path value is treated as a Path of just Statement */
3040 0 dest_node = _profile_next_node(dest_node, statement_pv);
3041 }
3042  
3043  
3044 16783 ▶ if (!SvOK(dest_node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(dest_node)) { 412 16371 16783
3045 412 av = newAV();
3046 412 sv_setsv(dest_node, newRV_noinc((SV*)av));
3047 412 av_store(av, DBIprof_COUNT, newSViv(1));
3048 412 av_store(av, DBIprof_TOTAL_TIME, newSVnv(ti));
3049 412 av_store(av, DBIprof_FIRST_TIME, newSVnv(ti));
3050 412 av_store(av, DBIprof_MIN_TIME, newSVnv(ti));
3051 412 av_store(av, DBIprof_MAX_TIME, newSVnv(ti));
3052 412 av_store(av, DBIprof_FIRST_CALLED, newSVnv(t1));
3053 412 av_store(av, DBIprof_LAST_CALLED, newSVnv(t1));
3054 }
3055 else {
3056 16371 tmp = dest_node;
3057 16371 ▶ if (SvROK(tmp))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(tmp)) 16371 0 16371
3058 16371 tmp = SvRV(tmp);
3059 16371 ▶ if (SvTYPE(tmp) != SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(tmp) != SVt_PVAV) 0 16371 16371
3060 0 croak("Invalid Profile data leaf element: %s (type %ld)",
3061 neatsvpv(tmp,0), (long)SvTYPE(tmp));
3062 16371 av = (AV*)tmp;
3063 16371 sv_inc( *av_fetch(av, DBIprof_COUNT, 1));
3064 16371 tmp = *av_fetch(av, DBIprof_TOTAL_TIME, 1);
3065 16371 sv_setnv(tmp, SvNV(tmp) + ti);
3066 16371 tmp = *av_fetch(av, DBIprof_MIN_TIME, 1);
3067 16371 ▶ if (ti < SvNV(tmp)) sv_setnv(tmp, ti);
Branch: 1 branch
BranchTrueFalseTotal
if (ti < SvNV(tmp)) sv_setnv(tmp, ti); 570 15801 16371
3068 16371 tmp = *av_fetch(av, DBIprof_MAX_TIME, 1);
3069 16371 ▶ if (ti > SvNV(tmp)) sv_setnv(tmp, ti);
Branch: 1 branch
BranchTrueFalseTotal
if (ti > SvNV(tmp)) sv_setnv(tmp, ti); 357 16014 16371
3070 16371 sv_setnv( *av_fetch(av, DBIprof_LAST_CALLED, 1), t1);
3071 }
3072 16783 return dest_node; /* use with caution - copy first, ie sv_mortalcopy() */
3073 }
3074  
3075  
3076 static void
3077 374 dbi_profile_merge_nodes(SV *dest, SV *increment)
3078 {
3079 dTHX;
3080 AV *d_av, *i_av;
3081 SV *tmp;
3082 SV *tmp2;
3083 NV i_nv;
3084 int i_is_earlier;
3085  
3086 374 ▶ if (!SvROK(dest) || SvTYPE(SvRV(dest)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(dest) || SvTYPE(SvRV(dest)) != SVt_PVAV) 374 0 374
if (!SvROK(dest) || SvTYPE(SvRV(dest)) != SVt_PVAV) 0 374 374
3087 0 croak("dbi_profile_merge_nodes(%s, ...) requires array ref", neatsvpv(dest,0));
3088 374 d_av = (AV*)SvRV(dest);
3089  
3090 374 ▶ if (av_len(d_av) < DBIprof_max_index) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(d_av) < DBIprof_max_index) { 48 326 374
3091 int idx;
3092 48 av_extend(d_av, DBIprof_max_index);
3093 384 ▶ for(idx=0; idx<=DBIprof_max_index; ++idx) {
Branch: 1 branch
BranchTrueFalseTotal
for(idx=0; idx<=DBIprof_max_index; ++idx) { 336 48 384
3094 336 tmp = *av_fetch(d_av, idx, 1);
3095 336 ▶ if (!SvOK(tmp) && idx != DBIprof_MIN_TIME && idx != DBIprof_FIRST_CALLED)
Branch: 3 branches
BranchTrueFalseTotal
if (!SvOK(tmp) && idx != DBIprof_MIN_TIME && idx != DBIprof_FIRST_CALLED) 336 0 336
if (!SvOK(tmp) && idx != DBIprof_MIN_TIME && idx != DBIprof_FIRST_CALLED) 288 48 336
if (!SvOK(tmp) && idx != DBIprof_MIN_TIME && idx != DBIprof_FIRST_CALLED) 240 48 288
3096 240 sv_setnv(tmp, 0.0); /* leave 'min' values as undef */
3097 }
3098 }
3099  
3100 374 ▶ if (!SvOK(increment))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(increment)) 0 374 374
3101 0 return;
3102  
3103 374 ▶ if (SvROK(increment) && SvTYPE(SvRV(increment)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(increment) && SvTYPE(SvRV(increment)) == SVt_PVHV) { 374 0 374
if (SvROK(increment) && SvTYPE(SvRV(increment)) == SVt_PVHV) { 2 372 374
3104 2 HV *hv = (HV*)SvRV(increment);
3105 char *key;
3106 2 I32 keylen = 0;
3107 2 hv_iterinit(hv);
3108 6 ▶ while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) { 4 2 6
3109 4 dbi_profile_merge_nodes(dest, tmp);
3110 };
3111 2 return;
3112 }
3113  
3114 372 ▶ if (!SvROK(increment) || SvTYPE(SvRV(increment)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(increment) || SvTYPE(SvRV(increment)) != SVt_PVAV) 372 0 372
if (!SvROK(increment) || SvTYPE(SvRV(increment)) != SVt_PVAV) 0 372 372
3115 0 croak("dbi_profile_merge_nodes: increment %s not an array or hash ref", neatsvpv(increment,0));
3116 372 i_av = (AV*)SvRV(increment);
3117  
3118 372 tmp = *av_fetch(d_av, DBIprof_COUNT, 1);
3119 372 tmp2 = *av_fetch(i_av, DBIprof_COUNT, 1);
3120 372 ▶ if (SvIOK(tmp) && SvIOK(tmp2))
Branch: 2 branches
BranchTrueFalseTotal
if (SvIOK(tmp) && SvIOK(tmp2)) 0 372 372
if (SvIOK(tmp) && SvIOK(tmp2)) 0 0 0
3121 0 sv_setiv( tmp, SvIV(tmp) + SvIV(tmp2) );
3122 else
3123 372 sv_setnv( tmp, SvNV(tmp) + SvNV(tmp2) );
3124  
3125 372 tmp = *av_fetch(d_av, DBIprof_TOTAL_TIME, 1);
3126 372 sv_setnv( tmp, SvNV(tmp) + SvNV( *av_fetch(i_av, DBIprof_TOTAL_TIME, 1)) );
3127  
3128 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_MIN_TIME, 1));
3129 372 tmp = *av_fetch(d_av, DBIprof_MIN_TIME, 1);
3130 372 ▶ if (!SvOK(tmp) || i_nv < SvNV(tmp)) sv_setnv(tmp, i_nv);
Branch: 2 branches
BranchTrueFalseTotal
if (!SvOK(tmp) || i_nv < SvNV(tmp)) sv_setnv(tmp, i_nv); 324 48 372
if (!SvOK(tmp) || i_nv < SvNV(tmp)) sv_setnv(tmp, i_nv); 40 284 324
3131  
3132 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_MAX_TIME, 1));
3133 372 tmp = *av_fetch(d_av, DBIprof_MAX_TIME, 1);
3134 372 ▶ if (i_nv > SvNV(tmp)) sv_setnv(tmp, i_nv);
Branch: 1 branch
BranchTrueFalseTotal
if (i_nv > SvNV(tmp)) sv_setnv(tmp, i_nv); 63 309 372
3135  
3136 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_FIRST_CALLED, 1));
3137 372 tmp = *av_fetch(d_av, DBIprof_FIRST_CALLED, 1);
3138 372 ▶ i_is_earlier = (!SvOK(tmp) || i_nv < SvNV(tmp));
Branch: 2 branches
BranchTrueFalseTotal
i_is_earlier = (!SvOK(tmp) || i_nv < SvNV(tmp)); 324 48 372
i_is_earlier = (!SvOK(tmp) || i_nv < SvNV(tmp)); 31 293 324
3139 372 ▶ if (i_is_earlier)
Branch: 1 branch
BranchTrueFalseTotal
if (i_is_earlier) 79 293 372
3140 79 sv_setnv(tmp, i_nv);
3141  
3142 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_FIRST_TIME, 1));
3143 372 tmp = *av_fetch(d_av, DBIprof_FIRST_TIME, 1);
3144 372 ▶ if (i_is_earlier || !SvOK(tmp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (i_is_earlier || !SvOK(tmp)) { 293 79 372
if (i_is_earlier || !SvOK(tmp)) { 0 293 293
3145 /* If the increment has an earlier DBIprof_FIRST_CALLED
3146 then we set the DBIprof_FIRST_TIME from the increment */
3147 79 sv_setnv(tmp, i_nv);
3148 }
3149  
3150 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_LAST_CALLED, 1));
3151 372 tmp = *av_fetch(d_av, DBIprof_LAST_CALLED, 1);
3152 372 ▶ if (i_nv > SvNV(tmp)) sv_setnv(tmp, i_nv);
Branch: 1 branch
BranchTrueFalseTotal
if (i_nv > SvNV(tmp)) sv_setnv(tmp, i_nv); 255 117 372
3153 }
3154  
3155  
3156 /* ----------------------------------------------------------------- */
3157 /* --- The DBI dispatcher. The heart of the perl DBI. --- */
3158  
3159 XS(XS_DBI_dispatch); /* prototype to pass -Wmissing-prototypes */
3160 560431 XS(XS_DBI_dispatch)
3161 {
3162 560431 dXSARGS;
3163 560431 dORIGMARK;
3164 dMY_CXT;
3165  
3166 560431 SV *h = ST(0); /* the DBI handle we are working with */
3167 560431 SV *st1 = ST(1); /* used in debugging */
3168 560431 SV *st2 = ST(2); /* used in debugging */
3169 560431 SV *orig_h = h;
3170 SV *err_sv;
3171 SV **tmp_svp;
3172 560431 SV **hook_svp = 0;
3173 MAGIC *mg;
3174 560431 I32 gimme = GIMME_V;
3175 560431 I32 trace_flags = DBIS->debug; /* local copy may change during dispatch */
3176 560431 I32 trace_level = (trace_flags & DBIc_TRACE_LEVEL_MASK);
3177 int is_DESTROY;
3178 meth_types meth_type;
3179 560431 int is_unrelated_to_Statement = 0;
3180 560431 U32 keep_error = FALSE;
3181 560431 UV ErrCount = UV_MAX;
3182 int i, outitems;
3183 int call_depth;
3184 int is_nested_call;
3185 560431 NV profile_t1 = 0.0;
3186 560431 int is_orig_method_name = 1;
3187  
3188 560431 const char *meth_name = GvNAME(CvGV(cv));
3189 560431 dbi_ima_t *ima = (dbi_ima_t*)CvXSUBANY(cv).any_ptr;
3190 U32 ima_flags;
3191 560431 imp_xxh_t *imp_xxh = NULL;
3192 560431 SV *imp_msv = Nullsv;
3193 560431 SV *qsv = Nullsv; /* quick result from a shortcut method */
3194  
3195  
3196 560431 ima_flags = ima->flags;
3197 560431 meth_type = ima->meth_type;
3198 560431 ▶ if (trace_level >= 9) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 9) { 116 560315 560431
3199 116 PerlIO *logfp = DBILOGFP;
3200 116 PerlIO_printf(logfp,"%c >> %-11s DISPATCH (%s rc%ld/%ld @%ld g%x ima%lx pid#%ld)",
3201 116 ▶ (PL_dirty?'!':' '), meth_name, neatsvpv(h,0),
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), meth_name, neatsvpv(h,0), 0 116 116
3202 116 ▶ (long)SvREFCNT(h), (SvROK(h) ? (long)SvREFCNT(SvRV(h)) : (long)-1),
Branch: 1 branch
BranchTrueFalseTotal
(long)SvREFCNT(h), (SvROK(h) ? (long)SvREFCNT(SvRV(h)) : (long)-1), 116 0 116
3203 116 (long)items, (int)gimme, (long)ima_flags, (long)PerlProc_getpid());
3204 116 PerlIO_puts(logfp, log_where(0, 0, " at ","\n", 1, (trace_level >= 3), (trace_level >= 4)));
3205 116 PerlIO_flush(logfp);
3206 }
3207  
3208 560431 ▶ if ( ( (is_DESTROY=(meth_type == methtype_DESTROY))) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ( (is_DESTROY=(meth_type == methtype_DESTROY))) ) { 19380 541051 560431
3209 /* note that croak()'s won't propagate, only append to $@ */
3210 19380 keep_error = TRUE;
3211 }
3212  
3213 /* If h is a tied hash ref, switch to the inner ref 'behind' the tie.
3214 This means *all* DBI methods work with the inner (non-tied) ref.
3215 This makes it much easier for methods to access the real hash
3216 data (without having to go through FETCH and STORE methods) and
3217 for tie and non-tie methods to call each other.
3218 */
3219 560431 ▶ if (SvROK(h)
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(h) 560425 6 560431
3220 560425 ▶ && SvRMAGICAL(SvRV(h))
Branch: 1 branch
BranchTrueFalseTotal
&& SvRMAGICAL(SvRV(h)) 560423 2 560425
3221 560423 && (
3222 560423 ▶ ((mg=SvMAGIC(SvRV(h)))->mg_type == 'P')
Branch: 1 branch
BranchTrueFalseTotal
((mg=SvMAGIC(SvRV(h)))->mg_type == 'P') 442596 117827 560423
3223 442596 ▶ || ((mg=mg_find(SvRV(h),'P')) != NULL)
Branch: 1 branch
BranchTrueFalseTotal
|| ((mg=mg_find(SvRV(h),'P')) != NULL) 0 442596 442596
3224 )
3225 ) {
3226 117827 ▶ if (mg->mg_obj==NULL || !SvOK(mg->mg_obj) || SvRV(mg->mg_obj)==NULL) { /* maybe global destruction */
Branch: 3 branches
BranchTrueFalseTotal
if (mg->mg_obj==NULL || !SvOK(mg->mg_obj) || SvRV(mg->mg_obj)==NULL) { /* maybe global destruction */ 117827 0 117827
if (mg->mg_obj==NULL || !SvOK(mg->mg_obj) || SvRV(mg->mg_obj)==NULL) { /* maybe global destruction */ 117803 24 117827
if (mg->mg_obj==NULL || !SvOK(mg->mg_obj) || SvRV(mg->mg_obj)==NULL) { /* maybe global destruction */ 0 117803 117803
3227 24 ▶ if (trace_level >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 3) 0 24 24
3228 0 PerlIO_printf(DBILOGFP,
3229 "%c <> %s for %s ignored (inner handle gone)\n",
3230 0 ▶ (PL_dirty?'!':' '), meth_name, neatsvpv(h,0));
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), meth_name, neatsvpv(h,0)); 0 0 0
3231 24 XSRETURN(0);
3232 }
3233 /* Distinguish DESTROY of tie (outer) from DESTROY of inner ref */
3234 /* This may one day be used to manually destroy extra internal */
3235 /* refs if the application ceases to use the handle. */
3236 117803 ▶ if (is_DESTROY) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_DESTROY) { 9664 108139 117803
3237 9664 imp_xxh = DBIh_COM(mg->mg_obj);
3238 #ifdef DBI_USE_THREADS
3239 if (imp_xxh && DBIc_THR_USER(imp_xxh) != my_perl) {
3240 goto is_DESTROY_wrong_thread;
3241 }
3242 #endif
3243 9662 ▶ if (imp_xxh && DBIc_TYPE(imp_xxh) <= DBIt_DB)
Branch: 2 branches
BranchTrueFalseTotal
if (imp_xxh && DBIc_TYPE(imp_xxh) <= DBIt_DB) 9661 1 9662
if (imp_xxh && DBIc_TYPE(imp_xxh) <= DBIt_DB) 3635 6026 9661
3244 3635 clear_cached_kids(aTHX_ mg->mg_obj, imp_xxh, meth_name, trace_level);
3245 /* XXX might be better to move this down to after call_depth has been
3246 * incremented and then also SvREFCNT_dec(mg->mg_obj) to force an immediate
3247 * DESTROY of the inner handle if there are no other refs to it.
3248 * That way the inner DESTROY is properly flagged as a nested call,
3249 * and the outer DESTROY gets profiled more accurately, and callbacks work.
3250 */
3251 9662 ▶ if (trace_level >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 3) { 4 9658 9662
3252 8 PerlIO_printf(DBILOGFP,
3253 "%c <> DESTROY(%s) ignored for outer handle (inner %s has ref cnt %ld)\n",
3254 4 ▶ (PL_dirty?'!':' '), neatsvpv(h,0), neatsvpv(mg->mg_obj,0),
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), neatsvpv(h,0), neatsvpv(mg->mg_obj,0), 0 4 4
3255 4 (long)SvREFCNT(SvRV(mg->mg_obj))
3256 );
3257 }
3258 /* for now we ignore it since it'll be followed soon by */
3259 /* a destroy of the inner hash and that'll do the real work */
3260  
3261 /* However, we must at least modify DBIc_MY_H() as that is */
3262 /* pointing (without a refcnt inc) to the scalar that is */
3263 /* being destroyed, so it'll contain random values later. */
3264 9662 ▶ if (imp_xxh)
Branch: 1 branch
BranchTrueFalseTotal
if (imp_xxh) 9661 1 9662
3265 9661 DBIc_MY_H(imp_xxh) = (HV*)SvRV(mg->mg_obj); /* inner (untied) HV */
3266  
3267 9662 XSRETURN(0);
3268 }
3269 108139 h = mg->mg_obj; /* switch h to inner ref */
3270 108139 ST(0) = h; /* switch handle on stack to inner ref */
3271 }
3272  
3273 550743 imp_xxh = dbih_getcom2(aTHX_ h, 0); /* get common Internal Handle Attributes */
3274 550741 ▶ if (!imp_xxh) {
Branch: 1 branch
BranchTrueFalseTotal
if (!imp_xxh) { 11 550730 550741
3275 11 ▶ if (meth_type == methtype_can) { /* ref($h)->can("foo") */
Branch: 1 branch
BranchTrueFalseTotal
if (meth_type == methtype_can) { /* ref($h)->can("foo") */ 6 5 11
3276 6 const char *can_meth = SvPV_nolen(st1);
3277 6 SV *rv = &PL_sv_undef;
3278 6 GV *gv = gv_fetchmethod_autoload(gv_stashsv(orig_h,FALSE), can_meth, FALSE);
3279 6 ▶ if (gv && isGV(gv))
Branch: 2 branches
BranchTrueFalseTotal
if (gv && isGV(gv)) 4 2 6
if (gv && isGV(gv)) 4 0 4
3280 4 rv = sv_2mortal(newRV_inc((SV*)GvCV(gv)));
3281 6 ▶ if (trace_level >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 1) { 0 6 6
3282 0 PerlIO_printf(DBILOGFP," <- %s(%s) = %p\n", meth_name, can_meth, neatsvpv(rv,0));
3283 }
3284 6 ST(0) = rv;
3285 6 XSRETURN(1);
3286 }
3287 5 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 5 5
3288 0 PerlIO_printf(DBILOGFP, "%c <> %s for %s ignored (no imp_data)\n",
3289 0 ▶ (PL_dirty?'!':' '), meth_name, neatsvpv(h,0));
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), meth_name, neatsvpv(h,0)); 0 0 0
3290 5 ▶ if (!is_DESTROY)
Branch: 1 branch
BranchTrueFalseTotal
if (!is_DESTROY) 4 1 5
3291 4 ▶ warn("Can't call %s method on handle %s%s", meth_name, neatsvpv(h,0),
Branch: 1 branch
BranchTrueFalseTotal
warn("Can't call %s method on handle %s%s", meth_name, neatsvpv(h,0), 4 0 4
3292 SvROK(h) ? " after take_imp_data()" : " (not a reference)");
3293 5 XSRETURN(0);
3294 }
3295  
3296 550730 ▶ if (DBIc_has(imp_xxh,DBIcf_Profile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh,DBIcf_Profile)) { 61221 489509 550730
3297 61221 profile_t1 = dbi_time(); /* just get start time here */
3298 }
3299  
3300 #ifdef DBI_USE_THREADS
3301 {
3302 PerlInterpreter * h_perl;
3303 is_DESTROY_wrong_thread:
3304 h_perl = DBIc_THR_USER(imp_xxh) ;
3305 if (h_perl != my_perl) {
3306 /* XXX could call a 'handle clone' method here?, for dbh's at least */
3307 if (is_DESTROY) {
3308 if (trace_level >= 3) {
3309 PerlIO_printf(DBILOGFP," DESTROY ignored because DBI %sh handle (%s) is owned by thread %p not current thread %p\n",
3310 dbih_htype_name(DBIc_TYPE(imp_xxh)), HvNAME(DBIc_IMP_STASH(imp_xxh)),
3311 (void*)DBIc_THR_USER(imp_xxh), (void*)my_perl) ;
3312 PerlIO_flush(DBILOGFP);
3313 }
3314 XSRETURN(0); /* don't DESTROY handle, if it is not our's !*/
3315 }
3316 croak("%s %s failed: handle %d is owned by thread %lx not current thread %lx (%s)",
3317 HvNAME(DBIc_IMP_STASH(imp_xxh)), meth_name, DBIc_TYPE(imp_xxh),
3318 (unsigned long)h_perl, (unsigned long)my_perl,
3319 "handles can't be shared between threads and your driver may need a CLONE method added");
3320 }
3321 }
3322 #endif
3323  
3324 550730 ▶ if ((i = DBIc_DEBUGIV(imp_xxh))) { /* merge handle into global */
Branch: 1 branch
BranchTrueFalseTotal
if ((i = DBIc_DEBUGIV(imp_xxh))) { /* merge handle into global */ 373 550357 550730
3325 373 I32 h_trace_level = (i & DBIc_TRACE_LEVEL_MASK);
3326 373 ▶ if ( h_trace_level > trace_level )
Branch: 1 branch
BranchTrueFalseTotal
if ( h_trace_level > trace_level ) 44 329 373
3327 44 trace_level = h_trace_level;
3328 373 trace_flags = (trace_flags & ~DBIc_TRACE_LEVEL_MASK)
3329 373 | ( i & ~DBIc_TRACE_LEVEL_MASK)
3330 | trace_level;
3331 }
3332  
3333 /* Check method call against Internal Method Attributes */
3334 550730 ▶ if (ima_flags) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags) { 320071 230659 550730
3335  
3336 320071 ▶ if (ima_flags & (IMA_STUB|IMA_FUNC_REDIRECT|IMA_KEEP_ERR|IMA_KEEP_ERR_SUB|IMA_CLEAR_STMT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & (IMA_STUB|IMA_FUNC_REDIRECT|IMA_KEEP_ERR|IMA_KEEP_ERR_SUB|IMA_CLEAR_STMT)) { 253108 66963 320071
3337  
3338 253108 ▶ if (ima_flags & IMA_STUB) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_STUB) { 120 252988 253108
3339 120 ▶ if (meth_type == methtype_can) {
Branch: 1 branch
BranchTrueFalseTotal
if (meth_type == methtype_can) { 120 0 120
3340 120 const char *can_meth = SvPV_nolen(st1);
3341 120 SV *dbi_msv = Nullsv;
3342 /* find handle implementors method (GV or CV) */
3343 120 ▶ if ( (imp_msv = (SV*)gv_fetchmethod_autoload(DBIc_IMP_STASH(imp_xxh), can_meth, FALSE)) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( (imp_msv = (SV*)gv_fetchmethod_autoload(DBIc_IMP_STASH(imp_xxh), can_meth, FALSE)) ) { 2 118 120
3344 /* return DBI's CV, not the implementors CV (else we'd bypass dispatch) */
3345 /* and anyway, we may have hit a private method not part of the DBI */
3346 2 GV *gv = gv_fetchmethod_autoload(SvSTASH(SvRV(orig_h)), can_meth, FALSE);
3347 2 ▶ if (gv && isGV(gv))
Branch: 2 branches
BranchTrueFalseTotal
if (gv && isGV(gv)) 2 0 2
if (gv && isGV(gv)) 2 0 2
3348 2 dbi_msv = (SV*)GvCV(gv);
3349 }
3350 120 ▶ if (trace_level >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 1) { 4 116 120
3351 4 PerlIO *logfp = DBILOGFP;
3352 4 ▶ PerlIO_printf(logfp," <- %s(%s) = %p (%s %p)\n", meth_name, can_meth, (void*)dbi_msv,
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp," <- %s(%s) = %p (%s %p)\n", meth_name, can_meth, (void*)dbi_msv, 0 4 4
3353 0 ▶ (imp_msv && isGV(imp_msv)) ? HvNAME(GvSTASH(imp_msv)) : "?", (void*)imp_msv);
Branch: 7 branches
BranchTrueFalseTotal
(imp_msv && isGV(imp_msv)) ? HvNAME(GvSTASH(imp_msv)) : "?", (void*)imp_msv); 0 0 0
(imp_msv && isGV(imp_msv)) ? HvNAME(GvSTASH(imp_msv)) : "?", (void*)imp_msv); 0 0 0
(imp_msv && isGV(imp_msv)) ? HvNAME(GvSTASH(imp_msv)) : "?", (void*)imp_msv); 0 0 0
(imp_msv && isGV(imp_msv)) ? HvNAME(GvSTASH(imp_msv)) : "?", (void*)imp_msv); 0 0 0
(imp_msv && isGV(imp_msv)) ? HvNAME(GvSTASH(imp_msv)) : "?", (void*)imp_msv); 0 0 0
(imp_msv && isGV(imp_msv)) ? HvNAME(GvSTASH(imp_msv)) : "?", (void*)imp_msv); 0 0 0
(imp_msv && isGV(imp_msv)) ? HvNAME(GvSTASH(imp_msv)) : "?", (void*)imp_msv); 0 0 0
3354 }
3355 120 ▶ ST(0) = (dbi_msv) ? sv_2mortal(newRV_inc(dbi_msv)) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = (dbi_msv) ? sv_2mortal(newRV_inc(dbi_msv)) : &PL_sv_undef; 2 118 120
3356 120 XSRETURN(1);
3357 }
3358 0 XSRETURN(0);
3359 }
3360 252988 ▶ if (ima_flags & IMA_FUNC_REDIRECT) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_FUNC_REDIRECT) { 7531 245457 252988
3361 /* XXX this doesn't redispatch, nor consider the IMA of the new method */
3362 7531 SV *meth_name_sv = POPs;
3363 7531 PUTBACK;
3364 7531 --items;
3365 7531 ▶ if (!SvPOK(meth_name_sv) || SvNIOK(meth_name_sv))
Branch: 2 branches
BranchTrueFalseTotal
if (!SvPOK(meth_name_sv) || SvNIOK(meth_name_sv)) 7531 0 7531
if (!SvPOK(meth_name_sv) || SvNIOK(meth_name_sv)) 0 7531 7531
3366 0 croak("%s->%s() invalid redirect method name %s",
3367 neatsvpv(h,0), meth_name, neatsvpv(meth_name_sv,0));
3368 7531 meth_name = SvPV_nolen(meth_name_sv);
3369 7531 meth_type = get_meth_type(meth_name);
3370 7531 is_orig_method_name = 0;
3371 }
3372 252988 ▶ if (ima_flags & IMA_KEEP_ERR)
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_KEEP_ERR) 240438 12550 252988
3373 240438 keep_error = TRUE;
3374 252988 ▶ if ((ima_flags & IMA_KEEP_ERR_SUB)
Branch: 1 branch
BranchTrueFalseTotal
if ((ima_flags & IMA_KEEP_ERR_SUB) 94829 158159 252988
3375 94829 ▶ && !PL_dirty
Branch: 1 branch
BranchTrueFalseTotal
&& !PL_dirty 94307 522 94829
3376 94307 ▶ && DBIc_PARENT_COM(imp_xxh) && DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh)) > 0)
Branch: 2 branches
BranchTrueFalseTotal
&& DBIc_PARENT_COM(imp_xxh) && DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh)) > 0) 94061 246 94307
&& DBIc_PARENT_COM(imp_xxh) && DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh)) > 0) 33025 61036 94061
3377 33025 keep_error = TRUE;
3378 252988 ▶ if (ima_flags & IMA_CLEAR_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_CLEAR_STMT) { 12550 240438 252988
3379 /* don't use SvOK_off: dbh's Statement may be ref to sth's */
3380 12550 (void)hv_stores((HV*)SvRV(h), "Statement", &PL_sv_undef);
3381 }
3382 252988 ▶ if (ima_flags & IMA_CLEAR_CACHED_KIDS)
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_CLEAR_CACHED_KIDS) 9689 243299 252988
3383 9689 clear_cached_kids(aTHX_ h, imp_xxh, meth_name, trace_flags);
3384  
3385 }
3386  
3387 319951 ▶ if (ima_flags & IMA_HAS_USAGE) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_HAS_USAGE) { 95091 224860 319951
3388 95091 SV *usage_err = Nullsv;
3389  
3390 95091 ▶ if (ima->minargs && (items < ima->minargs
Branch: 2 branches
BranchTrueFalseTotal
if (ima->minargs && (items < ima->minargs 95091 0 95091
if (ima->minargs && (items < ima->minargs 95091 0 95091
3391 95091 ▶ || (ima->maxargs>0 && items > ima->maxargs))) {
Branch: 2 branches
BranchTrueFalseTotal
|| (ima->maxargs>0 && items > ima->maxargs))) { 74231 20860 95091
|| (ima->maxargs>0 && items > ima->maxargs))) { 2 74229 74231
3392 2 usage_err = sv_2mortal(newSVpvf(
3393 "DBI %s: invalid number of arguments: got handle + %ld, expected handle + between %d and %d\n",
3394 meth_name, (long)items-1, (int)ima->minargs-1, (int)ima->maxargs-1));
3395 }
3396 /* arg type checking could be added here later */
3397 95091 ▶ if (usage_err) {
Branch: 1 branch
BranchTrueFalseTotal
if (usage_err) { 2 95089 95091
3398 4 ▶ croak("%sUsage: %s->%s(%s)", SvPV_nolen(usage_err), "$h", meth_name,
Branch: 1 branch
BranchTrueFalseTotal
croak("%sUsage: %s->%s(%s)", SvPV_nolen(usage_err), "$h", meth_name, 2 0 2
3399 (ima->usage_msg) ? ima->usage_msg : "...?");
3400 }
3401 }
3402 }
3403  
3404 1101216 is_unrelated_to_Statement = ( (DBIc_TYPE(imp_xxh) == DBIt_ST) ? 0
3405 550608 ▶ : (DBIc_TYPE(imp_xxh) == DBIt_DR) ? 1
Branch: 2 branches
BranchTrueFalseTotal
: (DBIc_TYPE(imp_xxh) == DBIt_DR) ? 1 195906 354702 550608
: (DBIc_TYPE(imp_xxh) == DBIt_DR) ? 1 184338 11568 195906
3406 : (ima_flags & IMA_UNRELATED_TO_STMT) );
3407  
3408 550608 ▶ if (PL_tainting && items > 1 /* method call has args */
Branch: 2 branches
BranchTrueFalseTotal
if (PL_tainting && items > 1 /* method call has args */ 89 550519 550608
if (PL_tainting && items > 1 /* method call has args */ 72 17 89
3409 72 ▶ && DBIc_is(imp_xxh, DBIcf_TaintIn) /* taint checks requested */
Branch: 1 branch
BranchTrueFalseTotal
&& DBIc_is(imp_xxh, DBIcf_TaintIn) /* taint checks requested */ 34 38 72
3410 34 ▶ && !(ima_flags & IMA_NO_TAINT_IN)
Branch: 1 branch
BranchTrueFalseTotal
&& !(ima_flags & IMA_NO_TAINT_IN) 20 14 34
3411 ) {
3412 40 ▶ for(i=1; i < items; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=1; i < items; ++i) { 23 17 40
3413 23 ▶ if (SvTAINTED(ST(i))) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTAINTED(ST(i))) { 3 20 23
if (SvTAINTED(ST(i))) { 3 0 3
3414 3 SV *taint_msg = sv_2mortal(newSVpvf(
3415 "parameter %d of %s->%s method call",
3416 i, SvPV_nolen(h), meth_name));
3417 3 PL_tainted = 1; /* needed for TAINT_PROPER to work */
3418 6 ▶ TAINT_PROPER(SvPV_nolen(taint_msg)); /* die's */
Branch: 1 branch
BranchTrueFalseTotal
TAINT_PROPER(SvPV_nolen(taint_msg)); /* die's */ 3 0 3
3419 }
3420 }
3421 }
3422  
3423 /* record this inner handle for use by DBI::var::FETCH */
3424 550605 ▶ if (is_DESTROY) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_DESTROY) { 9689 540916 550605
3425  
3426 /* force destruction of any outstanding children */
3427 9689 ▶ if ((tmp_svp = hv_fetchs((HV*)SvRV(h), "ChildHandles", FALSE)) && SvROK(*tmp_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((tmp_svp = hv_fetchs((HV*)SvRV(h), "ChildHandles", FALSE)) && SvROK(*tmp_svp)) { 3104 6585 9689
if ((tmp_svp = hv_fetchs((HV*)SvRV(h), "ChildHandles", FALSE)) && SvROK(*tmp_svp)) { 3104 0 3104
3428 3104 AV *av = (AV*)SvRV(*tmp_svp);
3429 I32 kidslots;
3430 3104 PerlIO *logfp = DBILOGFP;
3431  
3432 3104 ▶ for (kidslots = AvFILL(av); kidslots >= 0; --kidslots) {
Branch: 1 branch
BranchTrueFalseTotal
for (kidslots = AvFILL(av); kidslots >= 0; --kidslots) { 3104 0 3104
3433 3104 SV **hp = av_fetch(av, kidslots, FALSE);
3434 3104 ▶ if (!hp || !SvROK(*hp) || SvTYPE(SvRV(*hp))!=SVt_PVHV)
Branch: 3 branches
BranchTrueFalseTotal
if (!hp || !SvROK(*hp) || SvTYPE(SvRV(*hp))!=SVt_PVHV) 3104 0 3104
if (!hp || !SvROK(*hp) || SvTYPE(SvRV(*hp))!=SVt_PVHV) 0 3104 3104
if (!hp || !SvROK(*hp) || SvTYPE(SvRV(*hp))!=SVt_PVHV) 0 0 0
3435 break;
3436  
3437 0 ▶ if (trace_level >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 1) { 0 0 0
3438 0 PerlIO_printf(logfp, "on DESTROY handle %s still has child %s (refcnt %ld, obj %d, dirty=%d)\n",
3439 0 neatsvpv(h,0), neatsvpv(*hp, 0), (long)SvREFCNT(*hp), !!sv_isobject(*hp), PL_dirty);
3440 0 ▶ if (trace_level >= 9)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 9) 0 0 0
3441 0 sv_dump(SvRV(*hp));
3442 }
3443 0 ▶ if (sv_isobject(*hp)) { /* call DESTROY on the handle */
Branch: 1 branch
BranchTrueFalseTotal
if (sv_isobject(*hp)) { /* call DESTROY on the handle */ 0 0 0
3444 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
3445 0 ▶ XPUSHs(*hp);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(*hp); 0 0 0
3446 0 PUTBACK;
3447 0 call_method("DESTROY", G_VOID|G_EVAL|G_KEEPERR);
3448 0 MSPAGAIN;
3449 }
3450 else {
3451 0 imp_xxh_t *imp_xxh = dbih_getcom2(aTHX_ *hp, 0);
3452 0 ▶ if (imp_xxh && DBIc_COMSET(imp_xxh)) {
Branch: 2 branches
BranchTrueFalseTotal
if (imp_xxh && DBIc_COMSET(imp_xxh)) { 0 0 0
if (imp_xxh && DBIc_COMSET(imp_xxh)) { 0 0 0
3453 0 dbih_clearcom(imp_xxh);
3454 0 sv_setsv(*hp, &PL_sv_undef);
3455 }
3456 }
3457 }
3458 }
3459  
3460 9689 ▶ if (DBIc_TYPE(imp_xxh) <= DBIt_DB ) { /* is dbh or drh */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp_xxh) <= DBIt_DB ) { /* is dbh or drh */ 3661 6028 9689
3461 imp_xxh_t *parent_imp;
3462  
3463 3661 ▶ if (SvOK(DBIc_ERR(imp_xxh)) && (parent_imp = DBIc_PARENT_COM(imp_xxh))
Branch: 2 branches
BranchTrueFalseTotal
if (SvOK(DBIc_ERR(imp_xxh)) && (parent_imp = DBIc_PARENT_COM(imp_xxh)) 53 3608 3661
if (SvOK(DBIc_ERR(imp_xxh)) && (parent_imp = DBIc_PARENT_COM(imp_xxh)) 53 0 53
3464 53 ▶ && !PL_dirty /* XXX - remove? */
Branch: 1 branch
BranchTrueFalseTotal
&& !PL_dirty /* XXX - remove? */ 50 3 53
3465 ) {
3466 /* copy err/errstr/state values to $DBI::err etc still work */
3467 50 sv_setsv(DBIc_ERR(parent_imp), DBIc_ERR(imp_xxh));
3468 50 sv_setsv(DBIc_ERRSTR(parent_imp), DBIc_ERRSTR(imp_xxh));
3469 50 sv_setsv(DBIc_STATE(parent_imp), DBIc_STATE(imp_xxh));
3470 }
3471 }
3472  
3473 9689 ▶ if (DBIc_AIADESTROY(imp_xxh)) { /* wants ineffective destroy after fork */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_AIADESTROY(imp_xxh)) { /* wants ineffective destroy after fork */ 10 9679 9689
3474 10 ▶ if ((U32)PerlProc_getpid() != _imp2com(imp_xxh, std.pid))
Branch: 1 branch
BranchTrueFalseTotal
if ((U32)PerlProc_getpid() != _imp2com(imp_xxh, std.pid)) 4 6 10
3475 4 DBIc_set(imp_xxh, DBIcf_IADESTROY, 1);
3476 }
3477 9689 ▶ if (DBIc_IADESTROY(imp_xxh)) { /* wants ineffective destroy */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_IADESTROY(imp_xxh)) { /* wants ineffective destroy */ 8 9681 9689
3478 8 ▶ DBIc_ACTIVE_off(imp_xxh);
Branch: 5 branches
BranchTrueFalseTotal
DBIc_ACTIVE_off(imp_xxh); 6 2 8
DBIc_ACTIVE_off(imp_xxh); 6 0 6
DBIc_ACTIVE_off(imp_xxh); 6 0 6
DBIc_ACTIVE_off(imp_xxh); 6 0 6
DBIc_ACTIVE_off(imp_xxh); 0 6 6
3479 }
3480 9689 call_depth = 0;
3481 9689 is_nested_call = 0;
3482 }
3483 else {
3484 540916 DBI_SET_LAST_HANDLE(h);
3485 540916 SAVEINT(DBIc_CALL_DEPTH(imp_xxh));
3486 540916 call_depth = ++DBIc_CALL_DEPTH(imp_xxh);
3487  
3488 540916 ▶ if (ima_flags & IMA_COPY_UP_STMT) { /* execute() */
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_COPY_UP_STMT) { /* execute() */ 8080 532836 540916
3489 8080 copy_statement_to_parent(aTHX_ h, imp_xxh);
3490 }
3491 540916 is_nested_call =
3492 (call_depth > 1
3493 756883 ▶ || (!PL_dirty /* not in global destruction [CPAN #75614] */
Branch: 2 branches
BranchTrueFalseTotal
|| (!PL_dirty /* not in global destruction [CPAN #75614] */ 215967 324949 540916
|| (!PL_dirty /* not in global destruction [CPAN #75614] */ 48592 167375 215967
3494 215426 ▶ && DBIc_PARENT_COM(imp_xxh)
Branch: 1 branch
BranchTrueFalseTotal
&& DBIc_PARENT_COM(imp_xxh) 204396 11030 215426
3495 431393 ▶ && DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh))) >= 1);
Branch: 2 branches
BranchTrueFalseTotal
&& DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh))) >= 1); 215426 541 215967
&& DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh))) >= 1); 48592 155804 204396
3496  
3497 }
3498  
3499  
3500 /* --- dispatch --- */
3501  
3502 550605 ▶ if (!keep_error && meth_type != methtype_set_err) {
Branch: 2 branches
BranchTrueFalseTotal
if (!keep_error && meth_type != methtype_set_err) { 310168 240437 550605
if (!keep_error && meth_type != methtype_set_err) { 300636 9532 310168
3503 SV *err_sv;
3504 300636 ▶ if (trace_level && SvOK(err_sv=DBIc_ERR(imp_xxh))) {
Branch: 2 branches
BranchTrueFalseTotal
if (trace_level && SvOK(err_sv=DBIc_ERR(imp_xxh))) { 25 300611 300636
if (trace_level && SvOK(err_sv=DBIc_ERR(imp_xxh))) { 0 25 25
3505 0 PerlIO *logfp = DBILOGFP;
3506 0 ▶ PerlIO_printf(logfp, " !! The %s '%s' was CLEARED by call to %s method\n",
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp, " !! The %s '%s' was CLEARED by call to %s method\n", 0 0 0
3507 0 ▶ SvTRUE(err_sv) ? "ERROR" : strlen(SvPV_nolen(err_sv)) ? "warn" : "info",
Branch: 1 branch
BranchTrueFalseTotal
SvTRUE(err_sv) ? "ERROR" : strlen(SvPV_nolen(err_sv)) ? "warn" : "info", 0 0 0
3508 0 neatsvpv(DBIc_ERR(imp_xxh),0), meth_name);
3509 }
3510 300636 ▶ DBIh_CLEAR_ERROR(imp_xxh);
Branch: 12 branches
BranchTrueFalseTotal
DBIh_CLEAR_ERROR(imp_xxh); 0 300636 300636
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 300636 300636
DBIh_CLEAR_ERROR(imp_xxh); 0 300636 300636
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 300636 300636
DBIh_CLEAR_ERROR(imp_xxh); 0 300636 300636
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 0 0
DBIh_CLEAR_ERROR(imp_xxh); 0 300636 300636
3511 }
3512 else { /* we check for change in ErrCount/err_hash during call */
3513 249969 ErrCount = DBIc_ErrCount(imp_xxh);
3514 249969 ▶ if (keep_error)
Branch: 1 branch
BranchTrueFalseTotal
if (keep_error) 240437 9532 249969
3515 240437 keep_error = err_hash(aTHX_ imp_xxh);
3516 }
3517  
3518 550605 ▶ if (DBIc_has(imp_xxh,DBIcf_Callbacks)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh,DBIcf_Callbacks) 64529 486076 550605
3519 64529 ▶ && (tmp_svp = hv_fetchs((HV*)SvRV(h), "Callbacks", 0))
Branch: 1 branch
BranchTrueFalseTotal
&& (tmp_svp = hv_fetchs((HV*)SvRV(h), "Callbacks", 0)) 64529 0 64529
3520 64529 ▶ && ( (hook_svp = hv_fetch((HV*)SvRV(*tmp_svp), meth_name, strlen(meth_name), 0))
Branch: 1 branch
BranchTrueFalseTotal
&& ( (hook_svp = hv_fetch((HV*)SvRV(*tmp_svp), meth_name, strlen(meth_name), 0)) 61593 2936 64529
3521 /* the "*" fallback callback only applies to non-nested calls
3522 * and also doesn't apply to the 'set_err' or DESTROY methods.
3523 * Nor during global destruction.
3524 * Other restrictions may be added over time.
3525 * It's an undocumented hack.
3526 */
3527 61593 ▶ || (!is_nested_call && !PL_dirty && meth_type != methtype_set_err &&
Branch: 4 branches
BranchTrueFalseTotal
|| (!is_nested_call && !PL_dirty && meth_type != methtype_set_err && 43846 17747 61593
|| (!is_nested_call && !PL_dirty && meth_type != methtype_set_err && 43821 25 43846
|| (!is_nested_call && !PL_dirty && meth_type != methtype_set_err && 40921 2900 43821
|| (!is_nested_call && !PL_dirty && meth_type != methtype_set_err && 40909 12 40921
3528 40909 ▶ meth_type != methtype_DESTROY &&
Branch: 1 branch
BranchTrueFalseTotal
meth_type != methtype_DESTROY && 10 40899 40909
3529 40909 (hook_svp = hv_fetchs((HV*)SvRV(*tmp_svp), "*", 0))
3530 )
3531 )
3532 2946 ▶ && SvROK(*hook_svp)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(*hook_svp) 2946 0 2946
3533 ) {
3534 SV *orig_defsv;
3535 SV *temp_defsv;
3536 2946 SV *code = SvRV(*hook_svp);
3537 2946 I32 skip_dispatch = 0;
3538 2946 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 2946 2946
3539 0 PerlIO_printf(DBILOGFP, "%c {{ %s callback %s being invoked with %ld args\n",
3540 0 ▶ (PL_dirty?'!':' '), meth_name, neatsvpv(*hook_svp,0), (long)items);
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), meth_name, neatsvpv(*hook_svp,0), (long)items); 0 0 0
3541  
3542 /* we don't use ENTER,SAVETMPS & FREETMPS,LEAVE because we may need mortal
3543 * results to live long enough to be returned to our caller
3544 */
3545 /* we want to localize $_ for the callback but can't just do that alone
3546 * because we're not using SAVETMPS & FREETMPS, so we have to get sneaky.
3547 * We still localize, so we're safe from the callback die-ing,
3548 * but after the callback we manually restore the original $_.
3549 */
3550 2946 ▶ orig_defsv = DEFSV; /* remember the current $_ */
Branch: 1 branch
BranchTrueFalseTotal
orig_defsv = DEFSV; /* remember the current $_ */ 2946 0 2946
3551 2946 SAVE_DEFSV; /* local($_) = $method_name */
3552 2946 temp_defsv = sv_2mortal(newSVpv(meth_name,0));
3553 # ifdef SvTEMP_off
3554 2946 SvTEMP_off(temp_defsv);
3555 # endif
3556 2946 DEFSV_set(temp_defsv);
3557  
3558 2946 ▶ EXTEND(SP, items+1);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, items+1); 2946 0 2946
EXTEND(SP, items+1); 2 2944 2946
3559 2946 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2946 2946
3560 2946 PUSHs(orig_h); /* push outer handle, then others params */
3561 14768 ▶ for (i=1; i < items; ++i) { /* start at 1 to skip handle */
Branch: 1 branch
BranchTrueFalseTotal
for (i=1; i < items; ++i) { /* start at 1 to skip handle */ 11822 2946 14768
3562 11822 PUSHs( ST(i) );
3563 }
3564 2946 PUTBACK;
3565 2946 outitems = call_sv(code, G_LIST); /* call the callback code */
3566 2944 MSPAGAIN;
3567  
3568 /* The callback code can undef $_ to indicate to skip dispatch */
3569 2944 ▶ skip_dispatch = !SvOK(DEFSV);
Branch: 1 branch
BranchTrueFalseTotal
skip_dispatch = !SvOK(DEFSV); 2944 0 2944
3570 /* put $_ back now */
3571 2944 DEFSV_set(orig_defsv);
3572  
3573 2944 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 2944 2944
3574 0 ▶ PerlIO_printf(DBILOGFP, "%c }} %s callback %s returned%s\n",
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(DBILOGFP, "%c }} %s callback %s returned%s\n", 0 0 0
3575 0 ▶ (PL_dirty?'!':' '), meth_name, neatsvpv(*hook_svp,0),
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), meth_name, neatsvpv(*hook_svp,0), 0 0 0
3576 skip_dispatch ? ", actual method will not be called" : ""
3577 );
3578 2944 ▶ if (skip_dispatch) { /* XXX experimental */
Branch: 1 branch
BranchTrueFalseTotal
if (skip_dispatch) { /* XXX experimental */ 1501 1443 2944
3579 1501 int ix = outitems;
3580 /* copy the new items down to the destination list */
3581 3000 ▶ while (ix-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (ix-- > 0) { 1499 1501 3000
3582 if(0)warn("\tcopy down %d: %s overwriting %s\n", ix, SvPV_nolen(TOPs), SvPV_nolen(ST(ix)) );
3583 1499 ST(ix) = POPs;
3584 }
3585 1501 imp_msv = *hook_svp; /* for trace and profile */
3586 1501 goto post_dispatch;
3587 }
3588 else {
3589 1443 ▶ if (outitems != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (outitems != 0) 2 1441 1443
3590 2 die("Callback for %s returned %d values but must not return any (temporary restriction in current version)",
3591 meth_name, (int)outitems);
3592 /* POP's and PUTBACK? to clear stack */
3593 }
3594 }
3595  
3596 /* set Executed after Callbacks so it's not set if callback elects to skip the method */
3597 549100 ▶ if (ima_flags & IMA_EXECUTE) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_EXECUTE) { 12868 536232 549100
3598 12868 imp_xxh_t *parent = DBIc_PARENT_COM(imp_xxh);
3599 12868 DBIc_on(imp_xxh, DBIcf_Executed);
3600 12868 ▶ if (parent)
Branch: 1 branch
BranchTrueFalseTotal
if (parent) 12868 0 12868
3601 12868 DBIc_on(parent, DBIcf_Executed);
3602 }
3603  
3604 /* The "quick_FETCH" logic... */
3605 /* Shortcut for fetching attributes to bypass method call overheads */
3606 549100 ▶ if (meth_type == methtype_FETCH && !DBIc_COMPAT(imp_xxh)) {
Branch: 2 branches
BranchTrueFalseTotal
if (meth_type == methtype_FETCH && !DBIc_COMPAT(imp_xxh)) { 98702 450398 549100
if (meth_type == methtype_FETCH && !DBIc_COMPAT(imp_xxh)) { 98624 78 98702
3607 STRLEN kl;
3608 98624 const char *key = SvPV(st1, kl);
3609 SV **attr_svp;
3610 98624 ▶ if (*key != '_' && (attr_svp=hv_fetch((HV*)SvRV(h), key, kl, 0))) {
Branch: 2 branches
BranchTrueFalseTotal
if (*key != '_' && (attr_svp=hv_fetch((HV*)SvRV(h), key, kl, 0))) { 98624 0 98624
if (*key != '_' && (attr_svp=hv_fetch((HV*)SvRV(h), key, kl, 0))) { 49631 48993 98624
3611 49631 qsv = *attr_svp;
3612 /* disable FETCH from cache for special attributes */
3613 49631 ▶ if (SvROK(qsv) && SvTYPE(SvRV(qsv))==SVt_PVHV && *key=='D' &&
Branch: 3 branches
BranchTrueFalseTotal
if (SvROK(qsv) && SvTYPE(SvRV(qsv))==SVt_PVHV && *key=='D' && 30038 19593 49631
if (SvROK(qsv) && SvTYPE(SvRV(qsv))==SVt_PVHV && *key=='D' && 10505 19533 30038
if (SvROK(qsv) && SvTYPE(SvRV(qsv))==SVt_PVHV && *key=='D' && 2547 7958 10505
3614 2547 ▶ ( (kl==6 && DBIc_TYPE(imp_xxh)==DBIt_DB && strEQ(key,"Driver"))
Branch: 3 branches
BranchTrueFalseTotal
( (kl==6 && DBIc_TYPE(imp_xxh)==DBIt_DB && strEQ(key,"Driver")) 2529 18 2547
( (kl==6 && DBIc_TYPE(imp_xxh)==DBIt_DB && strEQ(key,"Driver")) 2529 0 2529
( (kl==6 && DBIc_TYPE(imp_xxh)==DBIt_DB && strEQ(key,"Driver")) 0 2529 2529
3615 18 ▶ || (kl==8 && DBIc_TYPE(imp_xxh)==DBIt_ST && strEQ(key,"Database")) )
Branch: 3 branches
BranchTrueFalseTotal
|| (kl==8 && DBIc_TYPE(imp_xxh)==DBIt_ST && strEQ(key,"Database")) ) 18 0 18
|| (kl==8 && DBIc_TYPE(imp_xxh)==DBIt_ST && strEQ(key,"Database")) ) 18 0 18
|| (kl==8 && DBIc_TYPE(imp_xxh)==DBIt_ST && strEQ(key,"Database")) ) 18 0 18
3616 ) {
3617 2547 qsv = Nullsv;
3618 }
3619 /* disable profiling of FETCH of Profile data */
3620 49631 ▶ if (*key == 'P' && strEQ(key, "Profile"))
Branch: 2 branches
BranchTrueFalseTotal
if (*key == 'P' && strEQ(key, "Profile")) 261 49370 49631
if (*key == 'P' && strEQ(key, "Profile")) 158 103 261
3621 158 profile_t1 = 0.0;
3622 }
3623 98624 ▶ if (qsv) { /* skip real method call if we already have a 'quick' value */
Branch: 1 branch
BranchTrueFalseTotal
if (qsv) { /* skip real method call if we already have a 'quick' value */ 47084 51540 98624
3624 47084 ST(0) = sv_mortalcopy(qsv);
3625 47084 outitems = 1;
3626 47084 goto post_dispatch;
3627 }
3628 }
3629  
3630 {
3631 CV *meth_cv;
3632 #ifdef DBI_save_hv_fetch_ent
3633 HE save_mh;
3634 if (meth_type == methtype_FETCH)
3635 save_mh = PL_hv_fetch_ent_mh; /* XXX nested tied FETCH bug17575 workaround */
3636 #endif
3637  
3638 502016 ▶ if (trace_flags) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_flags) { 1036 500980 502016
3639 1036 SAVEI32(DBIS->debug); /* fall back to orig value later */
3640 1036 DBIS->debug = trace_flags; /* make new value global (for now) */
3641 1036 ▶ if (ima) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima) { 1036 0 1036
3642 /* enabling trace via flags takes precedence over disabling due to min level */
3643 1036 ▶ if ((trace_flags & DBIc_TRACE_FLAGS_MASK) & (ima->method_trace & DBIc_TRACE_FLAGS_MASK))
Branch: 1 branch
BranchTrueFalseTotal
if ((trace_flags & DBIc_TRACE_FLAGS_MASK) & (ima->method_trace & DBIc_TRACE_FLAGS_MASK)) 24 1012 1036
3644 24 trace_level = (trace_level < 2) ? 2 : trace_level; /* min */
3645 else
3646 1012 ▶ if (trace_level < (DBIc_TRACE_LEVEL_MASK & ima->method_trace))
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level < (DBIc_TRACE_LEVEL_MASK & ima->method_trace)) 174 838 1012
3647 174 trace_level = 0; /* silence dispatch log for this method */
3648 }
3649 }
3650  
3651 502016 ▶ if (is_orig_method_name
Branch: 1 branch
BranchTrueFalseTotal
if (is_orig_method_name 494486 7530 502016
3652 494486 ▶ && ima->stash == DBIc_IMP_STASH(imp_xxh)
Branch: 1 branch
BranchTrueFalseTotal
&& ima->stash == DBIc_IMP_STASH(imp_xxh) 421741 72745 494486
3653 843482 && ima->generation == PL_sub_generation +
3654 421741 ▶ MY_cache_gen(DBIc_IMP_STASH(imp_xxh))
Branch: 2 branches
BranchTrueFalseTotal
MY_cache_gen(DBIc_IMP_STASH(imp_xxh)) 421741 0 421741
MY_cache_gen(DBIc_IMP_STASH(imp_xxh)) 421621 120 421741
3655 )
3656 421621 imp_msv = (SV*)ima->gv;
3657 else {
3658 80395 imp_msv = (SV*)gv_fetchmethod_autoload(DBIc_IMP_STASH(imp_xxh),
3659 meth_name, FALSE);
3660 80395 ▶ if (is_orig_method_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_orig_method_name) { 72865 7530 80395
3661 /* clear stale entry, if any */
3662 72865 SvREFCNT_dec(ima->stash);
3663 72865 SvREFCNT_dec(ima->gv);
3664 72865 ▶ if (!imp_msv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!imp_msv) { 138 72727 72865
3665 138 ima->stash = NULL;
3666 138 ima->gv = NULL;
3667 }
3668 else {
3669 72727 ima->stash = (HV*)SvREFCNT_inc(DBIc_IMP_STASH(imp_xxh));
3670 72727 ima->gv = (GV*)SvREFCNT_inc(imp_msv);
3671 72727 ima->generation = PL_sub_generation +
3672 72727 ▶ MY_cache_gen(DBIc_IMP_STASH(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
MY_cache_gen(DBIc_IMP_STASH(imp_xxh)); 72727 0 72727
3673 }
3674 }
3675 }
3676  
3677 /* if method was a 'func' then try falling back to real 'func' method */
3678 502016 ▶ if (!imp_msv && (ima_flags & IMA_FUNC_REDIRECT)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!imp_msv && (ima_flags & IMA_FUNC_REDIRECT)) { 141 501875 502016
if (!imp_msv && (ima_flags & IMA_FUNC_REDIRECT)) { 3 138 141
3679 3 imp_msv = (SV*)gv_fetchmethod_autoload(DBIc_IMP_STASH(imp_xxh), "func", FALSE);
3680 3 ▶ if (imp_msv) {
Branch: 1 branch
BranchTrueFalseTotal
if (imp_msv) { 3 0 3
3681 /* driver does have func method so undo the earlier 'func' stack changes */
3682 3 mPUSHs(newSVpv(meth_name, 0));
3683 3 PUTBACK;
3684 3 ++items;
3685 3 meth_name = "func";
3686 3 meth_type = methtype_ordinary;
3687 }
3688 }
3689  
3690 502016 ▶ if (trace_level >= (is_nested_call ? 4 : 2)) {
Branch: 2 branches
BranchTrueFalseTotal
if (trace_level >= (is_nested_call ? 4 : 2)) { 338551 163465 502016
if (trace_level >= (is_nested_call ? 4 : 2)) { 167 501849 502016
3691 167 PerlIO *logfp = DBILOGFP;
3692 /* Full pkg method name (or just meth_name for ANON CODE) */
3693 167 ▶ const char *imp_meth_name = (imp_msv && isGV(imp_msv)) ? GvNAME(imp_msv) : meth_name;
Branch: 2 branches
BranchTrueFalseTotal
const char *imp_meth_name = (imp_msv && isGV(imp_msv)) ? GvNAME(imp_msv) : meth_name; 167 0 167
const char *imp_meth_name = (imp_msv && isGV(imp_msv)) ? GvNAME(imp_msv) : meth_name; 167 0 167
3694 167 HV *imp_stash = DBIc_IMP_STASH(imp_xxh);
3695 297 ▶ PerlIO_printf(logfp, "%c -> %s ",
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp, "%c -> %s ", 37 130 167
3696 130 ▶ call_depth>1 ? '0'+call_depth-1 : (PL_dirty?'!':' '), imp_meth_name);
Branch: 1 branch
BranchTrueFalseTotal
call_depth>1 ? '0'+call_depth-1 : (PL_dirty?'!':' '), imp_meth_name); 0 130 130
3697 167 ▶ if (imp_meth_name[0] == 'A' && strEQ(imp_meth_name,"AUTOLOAD"))
Branch: 2 branches
BranchTrueFalseTotal
if (imp_meth_name[0] == 'A' && strEQ(imp_meth_name,"AUTOLOAD")) 0 167 167
if (imp_meth_name[0] == 'A' && strEQ(imp_meth_name,"AUTOLOAD")) 0 0 0
3698 0 PerlIO_printf(logfp, "\"%s\" ", meth_name);
3699 167 ▶ if (imp_msv && isGV(imp_msv) && GvSTASH(imp_msv) != imp_stash)
Branch: 3 branches
BranchTrueFalseTotal
if (imp_msv && isGV(imp_msv) && GvSTASH(imp_msv) != imp_stash) 167 0 167
if (imp_msv && isGV(imp_msv) && GvSTASH(imp_msv) != imp_stash) 167 0 167
if (imp_msv && isGV(imp_msv) && GvSTASH(imp_msv) != imp_stash) 24 143 167
3700 24 ▶ PerlIO_printf(logfp, "in %s ", HvNAME(GvSTASH(imp_msv)));
Branch: 6 branches
BranchTrueFalseTotal
PerlIO_printf(logfp, "in %s ", HvNAME(GvSTASH(imp_msv))); 24 0 24
PerlIO_printf(logfp, "in %s ", HvNAME(GvSTASH(imp_msv))); 24 0 24
PerlIO_printf(logfp, "in %s ", HvNAME(GvSTASH(imp_msv))); 0 24 24
PerlIO_printf(logfp, "in %s ", HvNAME(GvSTASH(imp_msv))); 0 0 0
PerlIO_printf(logfp, "in %s ", HvNAME(GvSTASH(imp_msv))); 24 0 24
PerlIO_printf(logfp, "in %s ", HvNAME(GvSTASH(imp_msv))); 0 24 24
3701 167 ▶ PerlIO_printf(logfp, "for %s (%s", HvNAME(imp_stash),
Branch: 6 branches
BranchTrueFalseTotal
PerlIO_printf(logfp, "for %s (%s", HvNAME(imp_stash), 167 0 167
PerlIO_printf(logfp, "for %s (%s", HvNAME(imp_stash), 167 0 167
PerlIO_printf(logfp, "for %s (%s", HvNAME(imp_stash), 0 167 167
PerlIO_printf(logfp, "for %s (%s", HvNAME(imp_stash), 0 0 0
PerlIO_printf(logfp, "for %s (%s", HvNAME(imp_stash), 167 0 167
PerlIO_printf(logfp, "for %s (%s", HvNAME(imp_stash), 0 167 167
3702 SvPV_nolen(orig_h));
3703 167 ▶ if (h != orig_h) /* show inner handle to aid tracing */
Branch: 1 branch
BranchTrueFalseTotal
if (h != orig_h) /* show inner handle to aid tracing */ 57 110 167
3704 57 PerlIO_printf(logfp, "~0x%lx", (long)SvRV(h));
3705 110 else PerlIO_printf(logfp, "~INNER");
3706 474 ▶ for(i=1; i<items; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=1; i<items; ++i) { 307 167 474
3707 614 ▶ PerlIO_printf(logfp," %s",
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp," %s", 307 0 307
3708 307 ▶ (ima && i==ima->hidearg) ? "****" : neatsvpv(ST(i),0));
Branch: 1 branch
BranchTrueFalseTotal
(ima && i==ima->hidearg) ? "****" : neatsvpv(ST(i),0)); 289 18 307
3709 }
3710 #ifdef DBI_USE_THREADS
3711 PerlIO_printf(logfp, ") thr#%p\n", (void*)DBIc_THR_USER(imp_xxh));
3712 #else
3713 167 PerlIO_printf(logfp, ")\n");
3714 #endif
3715 167 PerlIO_flush(logfp);
3716 }
3717  
3718 502016 ▶ if (!imp_msv || ! ((meth_cv = GvCV(imp_msv))) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (!imp_msv || ! ((meth_cv = GvCV(imp_msv))) ) { 501878 138 502016
if (!imp_msv || ! ((meth_cv = GvCV(imp_msv))) ) { 0 501878 501878
3719 138 ▶ if (PL_dirty || is_DESTROY) {
Branch: 2 branches
BranchTrueFalseTotal
if (PL_dirty || is_DESTROY) { 138 0 138
if (PL_dirty || is_DESTROY) { 0 138 138
3720 0 outitems = 0;
3721 0 goto post_dispatch;
3722 }
3723 138 ▶ if (ima_flags & IMA_NOT_FOUND_OKAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_NOT_FOUND_OKAY) { 134 4 138
3724 134 outitems = 0;
3725 134 goto post_dispatch;
3726 }
3727 4 ▶ croak("Can't locate DBI object method \"%s\" via package \"%s\"",
Branch: 6 branches
BranchTrueFalseTotal
croak("Can't locate DBI object method \"%s\" via package \"%s\"", 4 0 4
croak("Can't locate DBI object method \"%s\" via package \"%s\"", 4 0 4
croak("Can't locate DBI object method \"%s\" via package \"%s\"", 0 4 4
croak("Can't locate DBI object method \"%s\" via package \"%s\"", 0 0 0
croak("Can't locate DBI object method \"%s\" via package \"%s\"", 4 0 4
croak("Can't locate DBI object method \"%s\" via package \"%s\"", 0 4 4
3728 meth_name, HvNAME(DBIc_IMP_STASH(imp_xxh)));
3729 }
3730  
3731 501878 ▶ PUSHMARK(mark); /* mark arguments again so we can pass them on */
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(mark); /* mark arguments again so we can pass them on */ 0 501878 501878
3732  
3733 /* Note: the handle on the stack is still an object blessed into a
3734 * DBI::* class and not the DBD::*::* class whose method is being
3735 * invoked. This is correct and should be largely transparent.
3736 */
3737  
3738 /* SHORT-CUT ALERT! */
3739 501878 ▶ if (use_xsbypass && CvISXSUB(meth_cv) && CvXSUB(meth_cv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (use_xsbypass && CvISXSUB(meth_cv) && CvXSUB(meth_cv)) { 501878 0 501878
if (use_xsbypass && CvISXSUB(meth_cv) && CvXSUB(meth_cv)) { 148271 353607 501878
if (use_xsbypass && CvISXSUB(meth_cv) && CvXSUB(meth_cv)) { 148271 0 148271
3740  
3741 /* If we are calling an XSUB we jump directly to its C code and
3742 * bypass perl_call_sv(), pp_entersub() etc. This is fast.
3743 * This code is based on a small section of pp_entersub().
3744 */
3745 148271 (void)(*CvXSUB(meth_cv))(aTHXo_ meth_cv); /* Call the C code directly */
3746  
3747 148263 ▶ if (gimme == G_SCALAR) { /* Enforce sanity in scalar context */
Branch: 1 branch
BranchTrueFalseTotal
if (gimme == G_SCALAR) { /* Enforce sanity in scalar context */ 112749 35514 148263
3748 112749 ▶ if (ax != PL_stack_sp - PL_stack_base ) { /* outitems != 1 */
Branch: 1 branch
BranchTrueFalseTotal
if (ax != PL_stack_sp - PL_stack_base ) { /* outitems != 1 */ 0 112749 112749
3749 0 ST(0) =
3750 0 (ax > PL_stack_sp - PL_stack_base)
3751 ? &PL_sv_undef /* outitems == 0 */
3752 0 ▶ : *PL_stack_sp; /* outitems > 1 */
Branch: 1 branch
BranchTrueFalseTotal
: *PL_stack_sp; /* outitems > 1 */ 0 0 0
3753 0 PL_stack_sp = PL_stack_base + ax;
3754 }
3755 112749 outitems = 1;
3756 }
3757 else {
3758 35514 outitems = PL_stack_sp - (PL_stack_base + ax - 1);
3759 }
3760  
3761 }
3762 else {
3763 /* sv_dump(imp_msv); */
3764 353607 ▶ outitems = call_sv((SV*)meth_cv,
Branch: 1 branch
BranchTrueFalseTotal
outitems = call_sv((SV*)meth_cv, 3774 349833 353607
3765 (is_DESTROY ? gimme | G_EVAL | G_KEEPERR : gimme) );
3766 }
3767  
3768 501854 XSprePUSH; /* reset SP to base of stack frame */
3769  
3770 #ifdef DBI_save_hv_fetch_ent
3771 if (meth_type == methtype_FETCH)
3772 PL_hv_fetch_ent_mh = save_mh; /* see start of block */
3773 #endif
3774 }
3775  
3776 550573 post_dispatch:
3777  
3778 550573 ▶ if (is_DESTROY && DBI_IS_LAST_HANDLE(h)) { /* if destroying _this_ handle */
Branch: 2 branches
BranchTrueFalseTotal
if (is_DESTROY && DBI_IS_LAST_HANDLE(h)) { /* if destroying _this_ handle */ 9685 540888 550573
if (is_DESTROY && DBI_IS_LAST_HANDLE(h)) { /* if destroying _this_ handle */ 6731 2954 9685
3779 6731 SV *lhp = DBIc_PARENT_H(imp_xxh);
3780 6731 ▶ if (lhp && SvROK(lhp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (lhp && SvROK(lhp)) { 6731 0 6731
if (lhp && SvROK(lhp)) { 6438 293 6731
3781 6438 DBI_SET_LAST_HANDLE(lhp);
3782 }
3783 else {
3784 293 DBI_UNSET_LAST_HANDLE;
3785 }
3786 }
3787  
3788 550573 ▶ if (keep_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (keep_error) { 240427 310146 550573
3789 /* if we didn't clear err before the call, check to see if a new error
3790 * or warning has been recorded. If so, turn off keep_error so it gets acted on
3791 */
3792 240427 ▶ if (DBIc_ErrCount(imp_xxh) > ErrCount || err_hash(aTHX_ imp_xxh) != keep_error) {
Branch: 2 branches
BranchTrueFalseTotal
if (DBIc_ErrCount(imp_xxh) > ErrCount || err_hash(aTHX_ imp_xxh) != keep_error) { 238944 1483 240427
if (DBIc_ErrCount(imp_xxh) > ErrCount || err_hash(aTHX_ imp_xxh) != keep_error) { 14 238930 238944
3793 1497 keep_error = 0;
3794 }
3795 }
3796  
3797 550573 err_sv = DBIc_ERR(imp_xxh);
3798  
3799 550573 ▶ if (trace_level >= (is_nested_call ? 3 : 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if (trace_level >= (is_nested_call ? 3 : 1)) { 373538 177035 550573
if (trace_level >= (is_nested_call ? 3 : 1)) { 223 550350 550573
3800 223 PerlIO *logfp = DBILOGFP;
3801 223 ▶ const int is_fetch = (meth_type == methtype_fetch_star && DBIc_TYPE(imp_xxh)==DBIt_ST);
Branch: 2 branches
BranchTrueFalseTotal
const int is_fetch = (meth_type == methtype_fetch_star && DBIc_TYPE(imp_xxh)==DBIt_ST); 0 223 223
const int is_fetch = (meth_type == methtype_fetch_star && DBIc_TYPE(imp_xxh)==DBIt_ST); 0 0 0
3802 223 ▶ const IV row_count = (is_fetch) ? DBIc_ROW_COUNT((imp_sth_t*)imp_xxh) : 0;
Branch: 1 branch
BranchTrueFalseTotal
const IV row_count = (is_fetch) ? DBIc_ROW_COUNT((imp_sth_t*)imp_xxh) : 0; 0 223 223
3803 223 ▶ if (is_fetch && row_count>=2 && trace_level<=4 && SvOK(ST(0))) {
Branch: 4 branches
BranchTrueFalseTotal
if (is_fetch && row_count>=2 && trace_level<=4 && SvOK(ST(0))) { 0 223 223
if (is_fetch && row_count>=2 && trace_level<=4 && SvOK(ST(0))) { 0 0 0
if (is_fetch && row_count>=2 && trace_level<=4 && SvOK(ST(0))) { 0 0 0
if (is_fetch && row_count>=2 && trace_level<=4 && SvOK(ST(0))) { 0 0 0
3804 /* skip the 'middle' rows to reduce output */
3805 0 goto skip_meth_return_trace;
3806 }
3807 223 ▶ if (SvOK(err_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(err_sv)) { 0 223 223
3808 0 ▶ PerlIO_printf(logfp, " %s %s %s %s (err#%ld)\n", (keep_error) ? " " : "!!",
Branch: 2 branches
BranchTrueFalseTotal
PerlIO_printf(logfp, " %s %s %s %s (err#%ld)\n", (keep_error) ? " " : "!!", 0 0 0
PerlIO_printf(logfp, " %s %s %s %s (err#%ld)\n", (keep_error) ? " " : "!!", 0 0 0
3809 0 ▶ SvTRUE(err_sv) ? "ERROR:" : strlen(SvPV_nolen(err_sv)) ? "warn:" : "info:",
Branch: 1 branch
BranchTrueFalseTotal
SvTRUE(err_sv) ? "ERROR:" : strlen(SvPV_nolen(err_sv)) ? "warn:" : "info:", 0 0 0
3810 0 neatsvpv(err_sv,0), neatsvpv(DBIc_ERRSTR(imp_xxh),0), (long)DBIc_ErrCount(imp_xxh));
3811 }
3812 619 ▶ PerlIO_printf(logfp,"%c%c <%c %s",
Branch: 2 branches
BranchTrueFalseTotal
PerlIO_printf(logfp,"%c%c <%c %s", 11 212 223
PerlIO_printf(logfp,"%c%c <%c %s", 50 173 223
3813 173 ▶ (call_depth > 1) ? '0'+call_depth-1 : (PL_dirty?'!':' '),
Branch: 1 branch
BranchTrueFalseTotal
(call_depth > 1) ? '0'+call_depth-1 : (PL_dirty?'!':' '), 0 173 173
3814 223 ▶ (DBIc_is(imp_xxh, DBIcf_TaintIn|DBIcf_TaintOut)) ? 'T' : ' ',
Branch: 1 branch
BranchTrueFalseTotal
(DBIc_is(imp_xxh, DBIcf_TaintIn|DBIcf_TaintOut)) ? 'T' : ' ', 0 223 223
3815 (qsv) ? '>' : '-',
3816 meth_name);
3817 223 ▶ if (trace_level==1 && (items>=2||is_DESTROY)) { /* make level 1 more useful */
Branch: 3 branches
BranchTrueFalseTotal
if (trace_level==1 && (items>=2||is_DESTROY)) { /* make level 1 more useful */ 33 190 223
if (trace_level==1 && (items>=2||is_DESTROY)) { /* make level 1 more useful */ 7 26 33
if (trace_level==1 && (items>=2||is_DESTROY)) { /* make level 1 more useful */ 3 4 7
3818 /* we only have the first two parameters available here */
3819 29 ▶ if (is_DESTROY) /* show handle as first arg to DESTROY */
Branch: 1 branch
BranchTrueFalseTotal
if (is_DESTROY) /* show handle as first arg to DESTROY */ 3 26 29
3820 /* want to show outer handle so trace makes sense */
3821 /* but outer handle has been destroyed so we fake it */
3822 3 ▶ PerlIO_printf(logfp,"(%s=HASH(0x%p)", HvNAME(SvSTASH(SvRV(orig_h))), (void*)DBIc_MY_H(imp_xxh));
Branch: 6 branches
BranchTrueFalseTotal
PerlIO_printf(logfp,"(%s=HASH(0x%p)", HvNAME(SvSTASH(SvRV(orig_h))), (void*)DBIc_MY_H(imp_xxh)); 3 0 3
PerlIO_printf(logfp,"(%s=HASH(0x%p)", HvNAME(SvSTASH(SvRV(orig_h))), (void*)DBIc_MY_H(imp_xxh)); 3 0 3
PerlIO_printf(logfp,"(%s=HASH(0x%p)", HvNAME(SvSTASH(SvRV(orig_h))), (void*)DBIc_MY_H(imp_xxh)); 0 3 3
PerlIO_printf(logfp,"(%s=HASH(0x%p)", HvNAME(SvSTASH(SvRV(orig_h))), (void*)DBIc_MY_H(imp_xxh)); 0 0 0
PerlIO_printf(logfp,"(%s=HASH(0x%p)", HvNAME(SvSTASH(SvRV(orig_h))), (void*)DBIc_MY_H(imp_xxh)); 3 0 3
PerlIO_printf(logfp,"(%s=HASH(0x%p)", HvNAME(SvSTASH(SvRV(orig_h))), (void*)DBIc_MY_H(imp_xxh)); 0 3 3
3823 else
3824 26 PerlIO_printf(logfp,"(%s", neatsvpv(st1,0));
3825 29 ▶ if (items >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items >= 3) 21 8 29
3826 21 PerlIO_printf(logfp,", %s", neatsvpv(st2,0));
3827 29 ▶ PerlIO_printf(logfp,"%s)", (items > 3) ? ", ..." : "");
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp,"%s)", (items > 3) ? ", ..." : ""); 3 26 29
3828 }
3829  
3830 223 ▶ if (gimme & G_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if (gimme & G_LIST) 223 0 223
3831 223 PerlIO_printf(logfp,"= (");
3832 0 else PerlIO_printf(logfp,"=");
3833 448 ▶ for(i=0; i < outitems; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < outitems; ++i) { 225 223 448
3834 225 SV *s = ST(i);
3835 225 ▶ if ( SvROK(s) && SvTYPE(SvRV(s))==SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if ( SvROK(s) && SvTYPE(SvRV(s))==SVt_PVAV) { 15 210 225
if ( SvROK(s) && SvTYPE(SvRV(s))==SVt_PVAV) { 0 15 15
3836 0 AV *av = (AV*)SvRV(s);
3837 int avi;
3838 0 int avi_last = SvIV(DBIS->neatsvpvlen) / 10;
3839 0 ▶ if (avi_last < 39)
Branch: 1 branch
BranchTrueFalseTotal
if (avi_last < 39) 0 0 0
3840 0 avi_last = 39;
3841 0 PerlIO_printf(logfp, " [");
3842 0 ▶ for (avi=0; avi <= AvFILL(av); ++avi) {
Branch: 1 branch
BranchTrueFalseTotal
for (avi=0; avi <= AvFILL(av); ++avi) { 0 0 0
3843 0 PerlIO_printf(logfp, " %s", neatsvpv(AvARRAY(av)[avi],0));
3844 0 ▶ if (avi >= avi_last && AvFILL(av) - avi > 1) {
Branch: 2 branches
BranchTrueFalseTotal
if (avi >= avi_last && AvFILL(av) - avi > 1) { 0 0 0
if (avi >= avi_last && AvFILL(av) - avi > 1) { 0 0 0
3845 0 PerlIO_printf(logfp, " ... %ld others skipped", AvFILL(av) - avi);
3846 0 break;
3847 }
3848 }
3849 0 PerlIO_printf(logfp, " ]");
3850 }
3851 else {
3852 225 PerlIO_printf(logfp, " %s", neatsvpv(s,0));
3853 225 ▶ if ( SvROK(s) && SvTYPE(SvRV(s))==SVt_PVHV && !SvOBJECT(SvRV(s)) )
Branch: 3 branches
BranchTrueFalseTotal
if ( SvROK(s) && SvTYPE(SvRV(s))==SVt_PVHV && !SvOBJECT(SvRV(s)) ) 15 210 225
if ( SvROK(s) && SvTYPE(SvRV(s))==SVt_PVHV && !SvOBJECT(SvRV(s)) ) 15 0 15
if ( SvROK(s) && SvTYPE(SvRV(s))==SVt_PVHV && !SvOBJECT(SvRV(s)) ) 5 10 15
3854 5 ▶ PerlIO_printf(logfp, "%ldkeys", (long)HvKEYS(SvRV(s)));
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp, "%ldkeys", (long)HvKEYS(SvRV(s))); 0 5 5
3855 }
3856 }
3857 223 ▶ if (gimme & G_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if (gimme & G_LIST) { 223 0 223
3858 223 PerlIO_printf(logfp," ) [%d items]", outitems);
3859 }
3860 223 ▶ if (is_fetch && row_count) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_fetch && row_count) { 0 223 223
if (is_fetch && row_count) { 0 0 0
3861 0 PerlIO_printf(logfp," row%"IVdf, row_count);
3862 }
3863 223 ▶ if (qsv) /* flag as quick and peek at the first arg (still on the stack) */
Branch: 1 branch
BranchTrueFalseTotal
if (qsv) /* flag as quick and peek at the first arg (still on the stack) */ 11 212 223
3864 11 PerlIO_printf(logfp," (%s from cache)", neatsvpv(st1,0));
3865 212 ▶ else if (!imp_msv)
Branch: 1 branch
BranchTrueFalseTotal
else if (!imp_msv) 0 212 212
3866 0 PerlIO_printf(logfp," (not implemented)");
3867 /* XXX add flag to show pid here? */
3868 /* add file and line number information */
3869 223 PerlIO_puts(logfp, log_where(0, 0, " at ", "\n", 1, (trace_level >= 3), (trace_level >= 4)));
3870 223 skip_meth_return_trace:
3871 223 PerlIO_flush(logfp);
3872 }
3873  
3874 550573 ▶ if (ima_flags & IMA_END_WORK) { /* commit() or rollback() */
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_END_WORK) { /* commit() or rollback() */ 4 550569 550573
3875 /* XXX does not consider if the method call actually worked or not */
3876 4 DBIc_off(imp_xxh, DBIcf_Executed);
3877  
3878 4 ▶ if (DBIc_has(imp_xxh, DBIcf_BegunWork)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_BegunWork)) { 2 2 4
3879 2 DBIc_off(imp_xxh, DBIcf_BegunWork);
3880 2 ▶ if (!DBIc_has(imp_xxh, DBIcf_AutoCommit)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIc_has(imp_xxh, DBIcf_AutoCommit)) { 2 0 2
3881 /* We only get here if the driver hasn't implemented their own code */
3882 /* for begin_work, or has but hasn't correctly turned AutoCommit */
3883 /* back on in their commit or rollback code. So we have to do it. */
3884 /* This is bad because it'll probably trigger a spurious commit() */
3885 /* and may mess up the error handling below for the commit/rollback */
3886 2 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2 2
3887 2 ▶ XPUSHs(h);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(h); 0 2 2
3888 2 ▶ mXPUSHs(newSVpvs("AutoCommit"));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvs("AutoCommit")); 0 2 2
3889 2 ▶ XPUSHs(&PL_sv_yes);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(&PL_sv_yes); 0 2 2
3890 2 PUTBACK;
3891 2 call_method("STORE", G_VOID);
3892 2 MSPAGAIN;
3893 }
3894 }
3895 }
3896  
3897 if (PL_tainting
3898 && DBIc_is(imp_xxh, DBIcf_TaintOut) /* taint checks requested */
3899 /* XXX this would taint *everything* being returned from *any* */
3900 /* method that doesn't have IMA_NO_TAINT_OUT set. */
3901 /* DISABLED: just tainting fetched data in get_fbav seems ok */
3902 && 0/* XXX disabled*/ /* !(ima_flags & IMA_NO_TAINT_OUT) */
3903 ) {
3904 dTHR;
3905 TAINT; /* affects sv_setsv()'s within same perl statement */
3906 for(i=0; i < outitems; ++i) {
3907 I32 avi;
3908 char *p;
3909 SV *s;
3910 SV *agg = ST(i);
3911 if ( !SvROK(agg) )
3912 continue;
3913 agg = SvRV(agg);
3914 #define DBI_OUT_TAINTABLE(s) (!SvREADONLY(s) && !SvTAINTED(s))
3915 switch (SvTYPE(agg)) {
3916 case SVt_PVAV:
3917 for(avi=0; avi <= AvFILL((AV*)agg); ++avi) {
3918 s = AvARRAY((AV*)agg)[avi];
3919 if (DBI_OUT_TAINTABLE(s))
3920 SvTAINTED_on(s);
3921 }
3922 break;
3923 case SVt_PVHV:
3924 hv_iterinit((HV*)agg);
3925 while( (s = hv_iternextsv((HV*)agg, &p, &avi)) ) {
3926 if (DBI_OUT_TAINTABLE(s))
3927 SvTAINTED_on(s);
3928 }
3929 break;
3930 default:
3931 if (DBIc_WARN(imp_xxh)) {
3932 PerlIO_printf(DBILOGFP,"Don't know how to taint contents of returned %s (type %d)\n",
3933 neatsvpv(agg,0), (int)SvTYPE(agg));
3934 }
3935 }
3936 }
3937 }
3938  
3939 /* if method returned a new handle, and that handle has an error on it
3940 * then copy the error up into the parent handle
3941 */
3942 550573 ▶ if (ima_flags & IMA_IS_FACTORY && SvROK(ST(0))) {
Branch: 2 branches
BranchTrueFalseTotal
if (ima_flags & IMA_IS_FACTORY && SvROK(ST(0))) { 12653 537920 550573
if (ima_flags & IMA_IS_FACTORY && SvROK(ST(0))) { 12316 337 12653
3943 12316 SV *h_new = ST(0);
3944 12316 D_impdata(imp_xxh_new, imp_xxh_t, h_new);
3945 12316 ▶ if (SvOK(DBIc_ERR(imp_xxh_new))) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(DBIc_ERR(imp_xxh_new))) { 0 12316 12316
3946 0 set_err_sv(h, imp_xxh, DBIc_ERR(imp_xxh_new), DBIc_ERRSTR(imp_xxh_new), DBIc_STATE(imp_xxh_new), &PL_sv_no);
3947 }
3948 }
3949  
3950 550573 ▶ if ( !keep_error /* is a new err/warn/info */
Branch: 1 branch
BranchTrueFalseTotal
if ( !keep_error /* is a new err/warn/info */ 311643 238930 550573
3951 311643 ▶ && !is_nested_call /* skip nested (internal) calls */
Branch: 1 branch
BranchTrueFalseTotal
&& !is_nested_call /* skip nested (internal) calls */ 64840 246803 311643
3952 64840 ▶ && (
Branch: 1 branch
BranchTrueFalseTotal
&& ( 3370 61470 64840
3953 /* is an error and has RaiseError|PrintError|HandleError set */
3954 68210 ▶ (SvTRUE(err_sv) && DBIc_has(imp_xxh, DBIcf_RaiseError|DBIcf_PrintError|DBIcf_HandleError))
Branch: 1 branch
BranchTrueFalseTotal
(SvTRUE(err_sv) && DBIc_has(imp_xxh, DBIcf_RaiseError|DBIcf_PrintError|DBIcf_HandleError)) 174 3196 3370
3955 /* is a warn (not info) and has RaiseWarn|PrintWarn set */
3956 61860 ▶ || ( SvOK(err_sv) && strlen(SvPV_nolen(err_sv)) && DBIc_has(imp_xxh, DBIcf_RaiseWarn|DBIcf_PrintWarn))
Branch: 3 branches
BranchTrueFalseTotal
|| ( SvOK(err_sv) && strlen(SvPV_nolen(err_sv)) && DBIc_has(imp_xxh, DBIcf_RaiseWarn|DBIcf_PrintWarn)) 216 61428 61644
|| ( SvOK(err_sv) && strlen(SvPV_nolen(err_sv)) && DBIc_has(imp_xxh, DBIcf_RaiseWarn|DBIcf_PrintWarn)) 197 19 216
|| ( SvOK(err_sv) && strlen(SvPV_nolen(err_sv)) && DBIc_has(imp_xxh, DBIcf_RaiseWarn|DBIcf_PrintWarn)) 191 6 197
3957 )
3958 227 ) {
3959 SV *msg;
3960 3387 SV **statement_svp = NULL;
3961 3404 ▶ const int is_warning = (!SvTRUE(err_sv) && strlen(SvPV_nolen(err_sv))==1);
Branch: 2 branches
BranchTrueFalseTotal
const int is_warning = (!SvTRUE(err_sv) && strlen(SvPV_nolen(err_sv))==1); 17 3370 3387
const int is_warning = (!SvTRUE(err_sv) && strlen(SvPV_nolen(err_sv))==1); 17 0 17
3962 3387 const char *err_meth_name = meth_name;
3963  
3964 3387 ▶ if (meth_type == methtype_set_err) {
Branch: 1 branch
BranchTrueFalseTotal
if (meth_type == methtype_set_err) { 78 3309 3387
3965 78 SV **sem_svp = hv_fetchs((HV*)SvRV(h), "dbi_set_err_method", GV_ADDWARN);
3966 78 ▶ if (SvOK(*sem_svp))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(*sem_svp)) 8 70 78
3967 16 err_meth_name = SvPV_nolen(*sem_svp);
3968 }
3969  
3970 3387 ▶ msg = sv_2mortal(newSVpvf("%s %s %s: ", HvNAME(DBIc_IMP_STASH(imp_xxh)), err_meth_name,
Branch: 8 branches
BranchTrueFalseTotal
msg = sv_2mortal(newSVpvf("%s %s %s: ", HvNAME(DBIc_IMP_STASH(imp_xxh)), err_meth_name, 17 3370 3387
msg = sv_2mortal(newSVpvf("%s %s %s: ", HvNAME(DBIc_IMP_STASH(imp_xxh)), err_meth_name, 17 0 17
msg = sv_2mortal(newSVpvf("%s %s %s: ", HvNAME(DBIc_IMP_STASH(imp_xxh)), err_meth_name, 3387 0 3387
msg = sv_2mortal(newSVpvf("%s %s %s: ", HvNAME(DBIc_IMP_STASH(imp_xxh)), err_meth_name, 3387 0 3387
msg = sv_2mortal(newSVpvf("%s %s %s: ", HvNAME(DBIc_IMP_STASH(imp_xxh)), err_meth_name, 0 3387 3387
msg = sv_2mortal(newSVpvf("%s %s %s: ", HvNAME(DBIc_IMP_STASH(imp_xxh)), err_meth_name, 0 0 0
msg = sv_2mortal(newSVpvf("%s %s %s: ", HvNAME(DBIc_IMP_STASH(imp_xxh)), err_meth_name, 3387 0 3387
msg = sv_2mortal(newSVpvf("%s %s %s: ", HvNAME(DBIc_IMP_STASH(imp_xxh)), err_meth_name, 0 3387 3387
3971 SvTRUE(err_sv) ? "failed" : is_warning ? "warning" : "information"));
3972 3387 ▶ if (SvOK(DBIc_ERRSTR(imp_xxh)))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(DBIc_ERRSTR(imp_xxh))) 3387 0 3387
3973 3387 sv_catsv(msg, DBIc_ERRSTR(imp_xxh));
3974 else
3975 0 sv_catpvf(msg, "(err=%s, errstr=undef, state=%s)",
3976 neatsvpv(DBIc_ERR(imp_xxh),0), neatsvpv(DBIc_STATE(imp_xxh),0) );
3977  
3978 3387 ▶ if ( DBIc_has(imp_xxh, DBIcf_ShowErrorStatement)
Branch: 1 branch
BranchTrueFalseTotal
if ( DBIc_has(imp_xxh, DBIcf_ShowErrorStatement) 196 3191 3387
3979 196 ▶ && !is_unrelated_to_Statement
Branch: 1 branch
BranchTrueFalseTotal
&& !is_unrelated_to_Statement 166 30 196
3980 166 ▶ && (DBIc_TYPE(imp_xxh) == DBIt_ST || ima_flags & IMA_SHOW_ERR_STMT)
Branch: 2 branches
BranchTrueFalseTotal
&& (DBIc_TYPE(imp_xxh) == DBIt_ST || ima_flags & IMA_SHOW_ERR_STMT) 66 100 166
&& (DBIc_TYPE(imp_xxh) == DBIt_ST || ima_flags & IMA_SHOW_ERR_STMT) 66 0 66
3981 166 ▶ && (statement_svp = hv_fetchs((HV*)SvRV(h), "Statement", 0))
Branch: 1 branch
BranchTrueFalseTotal
&& (statement_svp = hv_fetchs((HV*)SvRV(h), "Statement", 0)) 166 0 166
3982 166 ▶ && statement_svp && SvOK(*statement_svp)
Branch: 2 branches
BranchTrueFalseTotal
&& statement_svp && SvOK(*statement_svp) 166 0 166
&& statement_svp && SvOK(*statement_svp) 166 0 166
3983 ) {
3984 166 SV **svp = 0;
3985 166 sv_catpv(msg, " [for Statement \"");
3986 166 sv_catsv(msg, *statement_svp);
3987  
3988 /* fetch from tied outer handle to trigger FETCH magic */
3989 /* could add DBIcf_ShowErrorParams (default to on?) */
3990 166 ▶ if (!(ima_flags & IMA_HIDE_ERR_PARAMVALUES)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(ima_flags & IMA_HIDE_ERR_PARAMVALUES)) { 158 8 166
3991 158 svp = hv_fetchs((HV*)DBIc_MY_H(imp_xxh),"ParamValues",FALSE);
3992 158 ▶ if (svp && SvMAGICAL(*svp))
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvMAGICAL(*svp)) 158 0 158
if (svp && SvMAGICAL(*svp)) 158 0 158
3993 158 mg_get(*svp); /* XXX may recurse, may croak. could use eval */
3994 }
3995 174 ▶ if (svp && SvRV(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV && HvKEYS(SvRV(*svp))>0 ) {
Branch: 5 branches
BranchTrueFalseTotal
if (svp && SvRV(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV && HvKEYS(SvRV(*svp))>0 ) { 158 8 166
if (svp && SvRV(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV && HvKEYS(SvRV(*svp))>0 ) { 8 150 158
if (svp && SvRV(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV && HvKEYS(SvRV(*svp))>0 ) { 8 0 8
if (svp && SvRV(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV && HvKEYS(SvRV(*svp))>0 ) { 0 8 8
if (svp && SvRV(*svp) && SvTYPE(SvRV(*svp)) == SVt_PVHV && HvKEYS(SvRV(*svp))>0 ) { 8 0 8
3996 8 SV *param_values_sv = sv_2mortal(_join_hash_sorted((HV*)SvRV(*svp), "=",1, ", ",2, 1, -1));
3997 8 sv_catpv(msg, "\" with ParamValues: ");
3998 8 sv_catsv(msg, param_values_sv);
3999 8 sv_catpvn(msg, "]", 1);
4000 }
4001 else {
4002 158 sv_catpv(msg, "\"]");
4003 }
4004 }
4005  
4006 if (0) {
4007 COP *cop = dbi_caller_cop();
4008 if (cop && (CopLINE(cop) != CopLINE(PL_curcop) || CopFILEGV(cop) != CopFILEGV(PL_curcop))) {
4009 dbi_caller_string(msg, cop, " called via ", 1, 0);
4010 }
4011 }
4012  
4013 3387 hook_svp = NULL;
4014 3387 ▶ if ( (SvTRUE(err_sv) || (is_warning && DBIc_has(imp_xxh, DBIcf_RaiseWarn)))
Branch: 3 branches
BranchTrueFalseTotal
if ( (SvTRUE(err_sv) || (is_warning && DBIc_has(imp_xxh, DBIcf_RaiseWarn))) 17 3370 3387
if ( (SvTRUE(err_sv) || (is_warning && DBIc_has(imp_xxh, DBIcf_RaiseWarn))) 17 0 17
if ( (SvTRUE(err_sv) || (is_warning && DBIc_has(imp_xxh, DBIcf_RaiseWarn))) 8 9 17
4015 3378 ▶ && DBIc_has(imp_xxh, DBIcf_HandleError)
Branch: 1 branch
BranchTrueFalseTotal
&& DBIc_has(imp_xxh, DBIcf_HandleError) 30 3348 3378
4016 30 ▶ && (hook_svp = hv_fetchs((HV*)SvRV(h),"HandleError",0))
Branch: 1 branch
BranchTrueFalseTotal
&& (hook_svp = hv_fetchs((HV*)SvRV(h),"HandleError",0)) 30 0 30
4017 30 ▶ && hook_svp && SvOK(*hook_svp)
Branch: 2 branches
BranchTrueFalseTotal
&& hook_svp && SvOK(*hook_svp) 30 0 30
&& hook_svp && SvOK(*hook_svp) 30 0 30
4018 ) {
4019 30 dSP;
4020 30 PerlIO *logfp = DBILOGFP;
4021 IV items;
4022 SV *status;
4023 SV *result; /* point to result SV that's pointed to by the stack */
4024 30 ▶ if (outitems) {
Branch: 1 branch
BranchTrueFalseTotal
if (outitems) { 30 0 30
4025 30 result = *(sp-outitems+1);
4026 30 ▶ if (SvREADONLY(result)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvREADONLY(result)) { 22 8 30
4027 22 *(sp-outitems+1) = result = sv_2mortal(newSVsv(result));
4028 }
4029 }
4030 else {
4031 0 result = sv_newmortal();
4032 }
4033 30 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 30 30
4034 0 ▶ PerlIO_printf(logfp," -> HandleError on %s via %s%s%s%s\n",
Branch: 3 branches
BranchTrueFalseTotal
PerlIO_printf(logfp," -> HandleError on %s via %s%s%s%s\n", 0 0 0
PerlIO_printf(logfp," -> HandleError on %s via %s%s%s%s\n", 0 0 0
PerlIO_printf(logfp," -> HandleError on %s via %s%s%s%s\n", 0 0 0
4035 neatsvpv(h,0), neatsvpv(*hook_svp,0),
4036 (!outitems ? "" : " ("),
4037 0 (!outitems ? "" : neatsvpv(result ,0)),
4038 (!outitems ? "" : ")")
4039 );
4040 30 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 30 30
4041 30 ▶ XPUSHs(msg);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(msg); 0 30 30
4042 30 ▶ mXPUSHs(newRV_inc((SV*)DBIc_MY_H(imp_xxh)));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newRV_inc((SV*)DBIc_MY_H(imp_xxh))); 0 30 30
4043 30 ▶ XPUSHs( result );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( result ); 0 30 30
4044 30 PUTBACK;
4045 30 items = call_sv(*hook_svp, G_SCALAR);
4046 28 MSPAGAIN;
4047 28 ▶ status = (items) ? POPs : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
status = (items) ? POPs : &PL_sv_undef; 28 0 28
4048 28 PUTBACK;
4049 28 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 28 28
4050 0 ▶ PerlIO_printf(logfp," <- HandleError= %s%s%s%s\n",
Branch: 3 branches
BranchTrueFalseTotal
PerlIO_printf(logfp," <- HandleError= %s%s%s%s\n", 0 0 0
PerlIO_printf(logfp," <- HandleError= %s%s%s%s\n", 0 0 0
PerlIO_printf(logfp," <- HandleError= %s%s%s%s\n", 0 0 0
4051 neatsvpv(status,0),
4052 (!outitems ? "" : " ("),
4053 0 (!outitems ? "" : neatsvpv(result,0)),
4054 (!outitems ? "" : ")")
4055 );
4056 28 ▶ if (!SvTRUE(status)) /* handler says it didn't handle it, so... */
Branch: 1 branch
BranchTrueFalseTotal
if (!SvTRUE(status)) /* handler says it didn't handle it, so... */ 16 12 28
4057 16 hook_svp = 0; /* pretend we didn't have a handler... */
4058 }
4059  
4060 3385 ▶ if (profile_t1) { /* see also dbi_profile() call a few lines below */
Branch: 1 branch
BranchTrueFalseTotal
if (profile_t1) { /* see also dbi_profile() call a few lines below */ 0 3385 3385
4061 0 ▶ SV *statement_sv = (is_unrelated_to_Statement) ? &PL_sv_no : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *statement_sv = (is_unrelated_to_Statement) ? &PL_sv_no : &PL_sv_undef; 0 0 0
4062 0 ▶ dbi_profile(h, imp_xxh, statement_sv, imp_msv ? imp_msv : (SV*)cv,
Branch: 1 branch
BranchTrueFalseTotal
dbi_profile(h, imp_xxh, statement_sv, imp_msv ? imp_msv : (SV*)cv, 0 0 0
4063 profile_t1, dbi_time());
4064 }
4065 3385 ▶ if (!hook_svp && is_warning) {
Branch: 2 branches
BranchTrueFalseTotal
if (!hook_svp && is_warning) { 3373 12 3385
if (!hook_svp && is_warning) { 13 3360 3373
4066 13 ▶ if (DBIc_has(imp_xxh, DBIcf_PrintWarn))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_PrintWarn)) 9 4 13
4067 9 warn_sv(msg);
4068 13 ▶ if (DBIc_has(imp_xxh, DBIcf_RaiseWarn))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_RaiseWarn)) 4 9 13
4069 4 croak_sv(msg);
4070 }
4071 3372 ▶ else if (!hook_svp && SvTRUE(err_sv)) {
Branch: 2 branches
BranchTrueFalseTotal
else if (!hook_svp && SvTRUE(err_sv)) { 3360 12 3372
else if (!hook_svp && SvTRUE(err_sv)) { 3360 0 3360
4072 3360 ▶ if (DBIc_has(imp_xxh, DBIcf_PrintError))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_PrintError)) 26 3334 3360
4073 26 warn_sv(msg);
4074 3360 ▶ if (DBIc_has(imp_xxh, DBIcf_RaiseError))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_RaiseError)) 3154 206 3360
4075 3154 croak_sv(msg);
4076 }
4077 }
4078 547186 ▶ else if (profile_t1) { /* see also dbi_profile() call a few lines above */
Branch: 1 branch
BranchTrueFalseTotal
else if (profile_t1) { /* see also dbi_profile() call a few lines above */ 61063 486123 547186
4079 61063 ▶ SV *statement_sv = (is_unrelated_to_Statement) ? &PL_sv_no : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
SV *statement_sv = (is_unrelated_to_Statement) ? &PL_sv_no : &PL_sv_undef; 396 60667 61063
4080 61063 ▶ dbi_profile(h, imp_xxh, statement_sv, imp_msv ? imp_msv : (SV*)cv,
Branch: 1 branch
BranchTrueFalseTotal
dbi_profile(h, imp_xxh, statement_sv, imp_msv ? imp_msv : (SV*)cv, 52122 8941 61063
4081 profile_t1, dbi_time());
4082 }
4083 547413 XSRETURN(outitems);
4084 }
4085  
4086  
4087  
4088 /* -------------------------------------------------------------------- */
4089  
4090 /* comment and placeholder styles to accept and return */
4091  
4092 #define DBIpp_cm_cs 0x000001 /* C style */
4093 #define DBIpp_cm_hs 0x000002 /* # */
4094 #define DBIpp_cm_dd 0x000004 /* -- */
4095 #define DBIpp_cm_br 0x000008 /* {} */
4096 #define DBIpp_cm_dw 0x000010 /* '-- ' dash dash whitespace */
4097 #define DBIpp_cm_XX 0x00001F /* any of the above */
4098  
4099 #define DBIpp_ph_qm 0x000100 /* ? */
4100 #define DBIpp_ph_cn 0x000200 /* :1 */
4101 #define DBIpp_ph_cs 0x000400 /* :name */
4102 #define DBIpp_ph_sp 0x000800 /* %s (as return only, not accept) */
4103 #define DBIpp_ph_XX 0x000F00 /* any of the above */
4104  
4105 #define DBIpp_st_qq 0x010000 /* '' char escape */
4106 #define DBIpp_st_bs 0x020000 /* \ char escape */
4107 #define DBIpp_st_XX 0x030000 /* any of the above */
4108  
4109 #define DBIpp_L_BRACE '{'
4110 #define DBIpp_R_BRACE '}'
4111 #define PS_accept(flag) DBIbf_has(ps_accept,(flag))
4112 #define PS_return(flag) DBIbf_has(ps_return,(flag))
4113  
4114 SV *
4115 60 preparse(SV *dbh, const char *statement, IV ps_return, IV ps_accept, void *foo)
4116 {
4117 dTHX;
4118 60 D_imp_xxh(dbh);
4119 /*
4120 The idea here is that ps_accept defines which constructs to
4121 recognize (accept) as valid in the source string (other
4122 constructs are ignored), and ps_return defines which
4123 constructs are valid to return in the result string.
4124  
4125 If a construct that is valid in the input is also valid in the
4126 output then it's simply copied. If it's not valid in the output
4127 then it's editied into one of the valid forms (ideally the most
4128 'standard' and/or information preserving one).
4129  
4130 For example, if ps_accept includes '--' style comments but
4131 ps_return doesn't, but ps_return does include '#' style
4132 comments then any '--' style comments would be rewritten as '#'
4133 style comments.
4134  
4135 Similarly for placeholders. DBD::Oracle, for example, would say
4136 '?', ':1' and ':name' are all acceptable input, but only
4137 ':name' should be returned.
4138  
4139 (There's a tricky issue with the '--' comment style because it can
4140 clash with valid syntax, i.e., "... set foo=foo--1 ..." so it
4141 would be *bad* to misinterpret that as the start of a comment.
4142 Perhaps we need a DBIpp_cm_dw (for dash-dash-whitespace) style
4143 to allow for that.)
4144  
4145 Also, we'll only support DBIpp_cm_br as an input style. And
4146 even then, only with reluctance. We may (need to) drop it when
4147 we add support for odbc escape sequences.
4148 */
4149 60 int idx = 1;
4150 STRLEN sln;
4151  
4152 60 char in_quote = '\0';
4153 60 char in_comment = '\0';
4154 60 char rt_comment = '\0';
4155 char *dest, *start;
4156 const char *src;
4157 60 const char *style = "", *laststyle = NULL;
4158 SV *new_stmt_sv;
4159  
4160 (void)foo;
4161  
4162 if (!(ps_return | DBIpp_ph_XX)) { /* no return ph type specified */
4163 ps_return |= ps_accept | DBIpp_ph_XX; /* so copy from ps_accept */
4164 }
4165  
4166 /* XXX this allocation strategy won't work when we get to more advanced stuff */
4167 /* The 7 is for length increase from '?' (length 1) to :p99999 (length 7)
4168 * which imposes a limit of 99999 '?' placeholders POSIX style. Actual counts
4169 * are a bit higher:
4170 * using factor 5: :p1 .. :p1107
4171 * using factor 6: :p1 .. :p11106
4172 * using factor 7: :p1 .. :p111105
4173 * and that count is insane already */
4174 60 sln = strlen(statement);
4175 60 ▶ if (sln > 306783375) { /* x * 7 + 16 would overflow maxint on 32bit ints */
Branch: 1 branch
BranchTrueFalseTotal
if (sln > 306783375) { /* x * 7 + 16 would overflow maxint on 32bit ints */ 0 60 60
4176 char buf[99];
4177 0 sprintf(buf, "preparse statement length exceeds maximum length (306783375).");
4178 0 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4179 0 return &PL_sv_undef;
4180 }
4181 60 new_stmt_sv = newSV(sln * 7 + 16);
4182 60 sv_setpv(new_stmt_sv,"");
4183 60 src = statement;
4184 60 dest = SvPVX(new_stmt_sv);
4185  
4186 724 ▶ while( *src )
Branch: 1 branch
BranchTrueFalseTotal
while( *src ) 676 48 724
4187 {
4188 676 ▶ if (*src == '%' && PS_return(DBIpp_ph_sp))
Branch: 2 branches
BranchTrueFalseTotal
if (*src == '%' && PS_return(DBIpp_ph_sp)) 0 676 676
if (*src == '%' && PS_return(DBIpp_ph_sp)) 0 0 0
4189 0 *dest++ = '%';
4190  
4191 676 ▶ if (in_comment)
Branch: 1 branch
BranchTrueFalseTotal
if (in_comment) 116 560 676
4192 {
4193 116 ▶ if ( (in_comment == '-' && (*src == '\n' || *(src+1) == '\0'))
Branch: 3 branches
BranchTrueFalseTotal
if ( (in_comment == '-' && (*src == '\n' || *(src+1) == '\0')) 20 96 116
if ( (in_comment == '-' && (*src == '\n' || *(src+1) == '\0')) 12 8 20
if ( (in_comment == '-' && (*src == '\n' || *(src+1) == '\0')) 12 0 12
4194 108 ▶ || (in_comment == '#' && (*src == '\n' || *(src+1) == '\0'))
Branch: 3 branches
BranchTrueFalseTotal
|| (in_comment == '#' && (*src == '\n' || *(src+1) == '\0')) 12 96 108
|| (in_comment == '#' && (*src == '\n' || *(src+1) == '\0')) 6 6 12
|| (in_comment == '#' && (*src == '\n' || *(src+1) == '\0')) 6 0 6
4195 102 ▶ || (in_comment == DBIpp_L_BRACE && *src == DBIpp_R_BRACE) /* XXX nesting? */
Branch: 2 branches
BranchTrueFalseTotal
|| (in_comment == DBIpp_L_BRACE && *src == DBIpp_R_BRACE) /* XXX nesting? */ 24 78 102
|| (in_comment == DBIpp_L_BRACE && *src == DBIpp_R_BRACE) /* XXX nesting? */ 20 4 24
4196 98 ▶ || (in_comment == '/' && *src == '*' && *(src+1) == '/')
Branch: 3 branches
BranchTrueFalseTotal
|| (in_comment == '/' && *src == '*' && *(src+1) == '/') 60 38 98
|| (in_comment == '/' && *src == '*' && *(src+1) == '/') 10 50 60
|| (in_comment == '/' && *src == '*' && *(src+1) == '/') 10 0 10
4197 ) {
4198 28 switch (rt_comment) {
4199 4 case '/': *dest++ = '*'; *dest++ = '/'; break;
4200 4 case '-': *dest++ = '\n'; break;
4201 2 case '#': *dest++ = '\n'; break;
4202 8 case DBIpp_L_BRACE: *dest++ = DBIpp_R_BRACE; break;
4203 10 case '\0': /* ensure deleting a comment doesn't join two tokens */
4204 10 ▶ if (in_comment=='/' || in_comment==DBIpp_L_BRACE)
Branch: 2 branches
BranchTrueFalseTotal
if (in_comment=='/' || in_comment==DBIpp_L_BRACE) 8 2 10
if (in_comment=='/' || in_comment==DBIpp_L_BRACE) 2 6 8
4205 4 *dest++ = ' '; /* ('-' and '#' styles use the newline) */
4206 10 break;
4207 }
4208 28 ▶ if (in_comment == '/')
Branch: 1 branch
BranchTrueFalseTotal
if (in_comment == '/') 10 18 28
4209 10 src++;
4210 /* Only inspect the previously-emitted byte if one exists;
4211 when an initial line comment is deleted, dest is still at
4212 the start of the output buffer and *(dest-1) would read
4213 one byte before it (OOB read). */
4214 56 src += (*src != '\n'
4215 14 ▶ || (dest > SvPVX(new_stmt_sv) && *(dest-1)=='\n'))
Branch: 2 branches
BranchTrueFalseTotal
|| (dest > SvPVX(new_stmt_sv) && *(dest-1)=='\n')) 14 0 14
|| (dest > SvPVX(new_stmt_sv) && *(dest-1)=='\n')) 2 12 14
4216 42 ▶ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
? 1 : 0; 14 14 28
4217 28 in_comment = '\0';
4218 28 rt_comment = '\0';
4219 }
4220 else
4221 88 ▶ if (rt_comment)
Branch: 1 branch
BranchTrueFalseTotal
if (rt_comment) 76 12 88
4222 76 *dest++ = *src++;
4223 else
4224 12 src++; /* delete (don't copy) the comment */
4225 116 continue;
4226 }
4227  
4228 560 ▶ if (in_quote)
Branch: 1 branch
BranchTrueFalseTotal
if (in_quote) 100 460 560
4229 {
4230 100 ▶ if (*src == in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if (*src == in_quote) { 8 92 100
4231 8 in_quote = 0;
4232 }
4233 100 *dest++ = *src++;
4234 100 continue;
4235 }
4236  
4237 /* Look for comments */
4238 460 ▶ if (*src == '-' && *(src+1) == '-' &&
Branch: 2 branches
BranchTrueFalseTotal
if (*src == '-' && *(src+1) == '-' && 8 452 460
if (*src == '-' && *(src+1) == '-' && 8 0 8
4239 8 ▶ (PS_accept(DBIpp_cm_dd) || (*(src+2) == ' ' && PS_accept(DBIpp_cm_dw)))
Branch: 3 branches
BranchTrueFalseTotal
(PS_accept(DBIpp_cm_dd) || (*(src+2) == ' ' && PS_accept(DBIpp_cm_dw))) 2 6 8
(PS_accept(DBIpp_cm_dd) || (*(src+2) == ' ' && PS_accept(DBIpp_cm_dw))) 2 0 2
(PS_accept(DBIpp_cm_dd) || (*(src+2) == ' ' && PS_accept(DBIpp_cm_dw))) 2 0 2
4240 )
4241 {
4242 8 in_comment = *src;
4243 8 src += 2; /* skip past 2nd char of double char delimiters */
4244 8 ▶ if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) {
Branch: 2 branches
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) { 8 0 8
if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) { 0 8 8
4245 0 *dest++ = rt_comment = '-';
4246 0 *dest++ = '-';
4247 0 ▶ if (PS_return(DBIpp_cm_dw) && *src!=' ')
Branch: 2 branches
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_dw) && *src!=' ') 0 0 0
if (PS_return(DBIpp_cm_dw) && *src!=' ') 0 0 0
4248 0 *dest++ = ' '; /* insert needed white space */
4249 }
4250 8 ▶ else if (PS_return(DBIpp_cm_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_cs)) { 0 8 8
4251 0 *dest++ = rt_comment = '/';
4252 0 *dest++ = '*';
4253 }
4254 8 ▶ else if (PS_return(DBIpp_cm_hs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_hs)) { 0 8 8
4255 0 *dest++ = rt_comment = '#';
4256 }
4257 8 ▶ else if (PS_return(DBIpp_cm_br)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_br)) { 4 4 8
4258 4 *dest++ = rt_comment = DBIpp_L_BRACE;
4259 }
4260 8 continue;
4261 }
4262 452 ▶ else if (*src == '/' && *(src+1) == '*' && PS_accept(DBIpp_cm_cs))
Branch: 3 branches
BranchTrueFalseTotal
else if (*src == '/' && *(src+1) == '*' && PS_accept(DBIpp_cm_cs)) 12 440 452
else if (*src == '/' && *(src+1) == '*' && PS_accept(DBIpp_cm_cs)) 12 0 12
else if (*src == '/' && *(src+1) == '*' && PS_accept(DBIpp_cm_cs)) 12 0 12
4263 {
4264 12 in_comment = *src;
4265 12 src += 2; /* skip past 2nd char of double char delimiters */
4266 12 ▶ if (PS_return(DBIpp_cm_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_cs)) { 2 10 12
4267 2 *dest++ = rt_comment = '/';
4268 2 *dest++ = '*';
4269 }
4270 10 ▶ else if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) {
Branch: 2 branches
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) { 10 0 10
else if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) { 2 8 10
4271 2 *dest++ = rt_comment = '-';
4272 2 *dest++ = '-';
4273 2 ▶ if (PS_return(DBIpp_cm_dw)) *dest++ = ' ';
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_dw)) *dest++ = ' '; 2 0 2
4274 }
4275 8 ▶ else if (PS_return(DBIpp_cm_hs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_hs)) { 2 6 8
4276 2 *dest++ = rt_comment = '#';
4277 }
4278 6 ▶ else if (PS_return(DBIpp_cm_br)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_br)) { 4 2 6
4279 4 *dest++ = rt_comment = DBIpp_L_BRACE;
4280 }
4281 12 continue;
4282 }
4283 440 ▶ else if (*src == '#' && PS_accept(DBIpp_cm_hs))
Branch: 2 branches
BranchTrueFalseTotal
else if (*src == '#' && PS_accept(DBIpp_cm_hs)) 6 434 440
else if (*src == '#' && PS_accept(DBIpp_cm_hs)) 6 0 6
4284 {
4285 6 in_comment = *src;
4286 6 src++;
4287 6 ▶ if (PS_return(DBIpp_cm_hs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_hs)) { 0 6 6
4288 0 *dest++ = rt_comment = '#';
4289 }
4290 6 ▶ else if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) {
Branch: 2 branches
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) { 6 0 6
else if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) { 2 4 6
4291 2 *dest++ = rt_comment = '-';
4292 2 *dest++ = '-';
4293 2 ▶ if (PS_return(DBIpp_cm_dw)) *dest++ = ' ';
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_dw)) *dest++ = ' '; 2 0 2
4294 }
4295 4 ▶ else if (PS_return(DBIpp_cm_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_cs)) { 2 2 4
4296 2 *dest++ = rt_comment = '/';
4297 2 *dest++ = '*';
4298 }
4299 2 ▶ else if (PS_return(DBIpp_cm_br)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_br)) { 0 2 2
4300 0 *dest++ = rt_comment = DBIpp_L_BRACE;
4301 }
4302 6 continue;
4303 }
4304 434 ▶ else if (*src == DBIpp_L_BRACE && PS_accept(DBIpp_cm_br))
Branch: 2 branches
BranchTrueFalseTotal
else if (*src == DBIpp_L_BRACE && PS_accept(DBIpp_cm_br)) 6 428 434
else if (*src == DBIpp_L_BRACE && PS_accept(DBIpp_cm_br)) 6 0 6
4305 {
4306 6 in_comment = *src;
4307 6 src++;
4308 6 ▶ if (PS_return(DBIpp_cm_br)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_br)) { 2 4 6
4309 2 *dest++ = rt_comment = DBIpp_L_BRACE;
4310 }
4311 4 ▶ else if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) {
Branch: 2 branches
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) { 4 0 4
else if (PS_return(DBIpp_cm_dd) || PS_return(DBIpp_cm_dw)) { 0 4 4
4312 0 *dest++ = rt_comment = '-';
4313 0 *dest++ = '-';
4314 0 ▶ if (PS_return(DBIpp_cm_dw)) *dest++ = ' ';
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_dw)) *dest++ = ' '; 0 0 0
4315 }
4316 4 ▶ else if (PS_return(DBIpp_cm_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_cs)) { 2 2 4
4317 2 *dest++ = rt_comment = '/';
4318 2 *dest++ = '*';
4319 }
4320 2 ▶ else if (PS_return(DBIpp_cm_hs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_hs)) { 0 2 2
4321 0 *dest++ = rt_comment = '#';
4322 }
4323 6 continue;
4324 }
4325  
4326 428 ▶ if ( !(*src==':' && (PS_accept(DBIpp_ph_cn) || PS_accept(DBIpp_ph_cs)))
Branch: 3 branches
BranchTrueFalseTotal
if ( !(*src==':' && (PS_accept(DBIpp_ph_cn) || PS_accept(DBIpp_ph_cs))) 24 404 428
if ( !(*src==':' && (PS_accept(DBIpp_ph_cn) || PS_accept(DBIpp_ph_cs))) 4 20 24
if ( !(*src==':' && (PS_accept(DBIpp_ph_cn) || PS_accept(DBIpp_ph_cs))) 0 4 4
4327 404 ▶ && !(*src=='?' && PS_accept(DBIpp_ph_qm))
Branch: 2 branches
BranchTrueFalseTotal
&& !(*src=='?' && PS_accept(DBIpp_ph_qm)) 34 370 404
&& !(*src=='?' && PS_accept(DBIpp_ph_qm)) 0 34 34
4328 ){
4329 370 ▶ if (*src == '\'' || *src == '"')
Branch: 2 branches
BranchTrueFalseTotal
if (*src == '\'' || *src == '"') 364 6 370
if (*src == '\'' || *src == '"') 6 358 364
4330 12 in_quote = *src;
4331 370 *dest++ = *src++;
4332 370 continue;
4333 }
4334  
4335 /* only here for : or ? outside of a comment or literal */
4336  
4337 58 start = dest; /* save name inc colon */
4338 58 *dest++ = *src++; /* copy and move past first char */
4339  
4340 58 ▶ if (*start == '?') /* X/Open Standard */
Branch: 1 branch
BranchTrueFalseTotal
if (*start == '?') /* X/Open Standard */ 34 24 58
4341 {
4342 34 style = "?";
4343  
4344 34 ▶ if (PS_return(DBIpp_ph_qm))
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_ph_qm)) 34 0 34
4345 ;
4346 34 ▶ else if (PS_return(DBIpp_ph_cn)) { /* '?' -> ':p1' (etc) */
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_ph_cn)) { /* '?' -> ':p1' (etc) */ 32 2 34
4347 32 ▶ if (idx >= 99999) {
Branch: 1 branch
BranchTrueFalseTotal
if (idx >= 99999) { 0 32 32
4348 char buf[99];
4349 0 sprintf(buf, "preparse found more than 99999 '?' placeholders. Limit exceeded.");
4350 0 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4351 0 return &PL_sv_undef;
4352 }
4353 32 sprintf(start,":p%d", idx++);
4354 32 dest = start+strlen(start);
4355 }
4356 2 ▶ else if (PS_return(DBIpp_ph_sp)) { /* '?' -> '%s' */
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_ph_sp)) { /* '?' -> '%s' */ 2 0 2
4357 2 *start = '%';
4358 2 *dest++ = 's';
4359 }
4360 }
4361 24 ▶ else if (isDIGIT(*src)) { /* :1 */
Branch: 1 branch
BranchTrueFalseTotal
else if (isDIGIT(*src)) { /* :1 */ 18 6 24
4362 18 const int pln = atoi(src);
4363  
4364 18 ▶ if (strspn(src, "0123456789") > 5 || pln > 99999 || pln <= 0) {
Branch: 3 branches
BranchTrueFalseTotal
if (strspn(src, "0123456789") > 5 || pln > 99999 || pln <= 0) { 12 6 18
if (strspn(src, "0123456789") > 5 || pln > 99999 || pln <= 0) { 12 0 12
if (strspn(src, "0123456789") > 5 || pln > 99999 || pln <= 0) { 0 12 12
4365 char buf[99];
4366 6 sprintf(buf, "preparse found :p%d which is outside the allowed range.", pln);
4367 6 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4368 6 return &PL_sv_undef;
4369 }
4370  
4371 12 style = ":1";
4372  
4373 12 ▶ if (PS_return(DBIpp_ph_cn)) { /* ':1'-> ':p1' */
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_ph_cn)) { /* ':1'-> ':p1' */ 0 12 12
4374 0 idx = pln;
4375 0 *dest++ = 'p';
4376 0 ▶ while(isDIGIT(*src))
Branch: 1 branch
BranchTrueFalseTotal
while(isDIGIT(*src)) 0 0 0
4377 0 *dest++ = *src++;
4378 }
4379 12 ▶ else if (PS_return(DBIpp_ph_qm) /* ':1' -> '?' */
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_ph_qm) /* ':1' -> '?' */ 2 10 12
4380 2 ▶ || PS_return(DBIpp_ph_sp) /* ':1' -> '%s' */
Branch: 1 branch
BranchTrueFalseTotal
|| PS_return(DBIpp_ph_sp) /* ':1' -> '%s' */ 2 0 2
4381 ) {
4382 12 ▶ PS_return(DBIpp_ph_qm) ? sprintf(start,"?") : sprintf(start,"%%s");
Branch: 1 branch
BranchTrueFalseTotal
PS_return(DBIpp_ph_qm) ? sprintf(start,"?") : sprintf(start,"%%s"); 10 2 12
4383 12 dest = start + strlen(start);
4384 12 ▶ if (pln != idx) {
Branch: 1 branch
BranchTrueFalseTotal
if (pln != idx) { 4 8 12
4385 char buf[99];
4386 4 sprintf(buf, "preparse found placeholder :%d out of sequence, expected :%d", pln, idx);
4387 4 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4388 4 return &PL_sv_undef;
4389 }
4390 16 ▶ while(isDIGIT(*src)) src++;
Branch: 1 branch
BranchTrueFalseTotal
while(isDIGIT(*src)) src++; 8 8 16
4391 8 idx++;
4392 }
4393 }
4394 6 ▶ else if (isALNUM(*src)) /* :name */
Branch: 1 branch
BranchTrueFalseTotal
else if (isALNUM(*src)) /* :name */ 6 0 6
4395 {
4396 6 style = ":name";
4397  
4398 6 ▶ if (PS_return(DBIpp_ph_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_ph_cs)) { 6 0 6
4399 ;
4400 }
4401 6 ▶ else if (PS_return(DBIpp_ph_qm) /* ':name' -> '?' */
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_ph_qm) /* ':name' -> '?' */ 2 4 6
4402 2 ▶ || PS_return(DBIpp_ph_sp) /* ':name' -> '%s' */
Branch: 1 branch
BranchTrueFalseTotal
|| PS_return(DBIpp_ph_sp) /* ':name' -> '%s' */ 2 0 2
4403 ) {
4404 6 ▶ PS_return(DBIpp_ph_qm) ? sprintf(start,"?") : sprintf(start,"%%s");
Branch: 1 branch
BranchTrueFalseTotal
PS_return(DBIpp_ph_qm) ? sprintf(start,"?") : sprintf(start,"%%s"); 4 2 6
4405 6 dest = start + strlen(start);
4406 32 ▶ while (isALNUM(*src)) /* consume name, includes '_' */
Branch: 1 branch
BranchTrueFalseTotal
while (isALNUM(*src)) /* consume name, includes '_' */ 26 6 32
4407 26 src++;
4408 }
4409 }
4410 /* perhaps ':=' PL/SQL construct */
4411 0 else { continue; }
4412  
4413 48 *dest = '\0'; /* handy for debugging */
4414  
4415 48 ▶ if (laststyle && style != laststyle) {
Branch: 2 branches
BranchTrueFalseTotal
if (laststyle && style != laststyle) { 18 30 48
if (laststyle && style != laststyle) { 2 16 18
4416 char buf[99];
4417 2 sprintf(buf, "preparse found mixed placeholder styles (%s / %s)", style, laststyle);
4418 2 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4419 2 return &PL_sv_undef;
4420 }
4421 46 laststyle = style;
4422 }
4423 48 *dest = '\0';
4424  
4425 /* warn about probable parsing errors, but continue anyway (returning processed string) */
4426 48 switch (in_quote)
4427 {
4428 2 case '\'':
4429 2 set_err_char(dbh, imp_xxh, "1", 1, "preparse found unterminated single-quoted string", 0, "preparse");
4430 2 break;
4431 2 case '\"':
4432 2 set_err_char(dbh, imp_xxh, "1", 1, "preparse found unterminated double-quoted string", 0, "preparse");
4433 2 break;
4434 }
4435 48 switch (in_comment)
4436 {
4437 2 case DBIpp_L_BRACE:
4438 2 set_err_char(dbh, imp_xxh, "1", 1, "preparse found unterminated bracketed {...} comment", 0, "preparse");
4439 2 break;
4440 2 case '/':
4441 2 set_err_char(dbh, imp_xxh, "1", 1, "preparse found unterminated bracketed C-style comment", 0, "preparse");
4442 2 break;
4443 }
4444  
4445 48 SvCUR_set(new_stmt_sv, strlen(SvPVX(new_stmt_sv)));
4446 48 *SvEND(new_stmt_sv) = '\0';
4447 48 return new_stmt_sv;
4448 }
4449  
4450  
4451 /* -------------------------------------------------------------------- */
4452 /* The DBI Perl interface (via XS) starts here. Currently these are */
4453 /* all internal support functions. Note install_method and see DBI.pm */
4454  
4455 MODULE = DBI PACKAGE = DBI
4456  
4457 REQUIRE: 1.929
4458 PROTOTYPES: DISABLE
4459  
4460  
4461 BOOT:
4462 {
4463 MY_CXT_INIT;
4464 PERL_UNUSED_VAR(MY_CXT);
4465 }
4466 PERL_UNUSED_VAR(cv);
4467 PERL_UNUSED_VAR(items);
4468 301 dbi_bootinit(NULL);
4469 /* make this sub into a fake XS so it can bee seen by DBD::* modules;
4470 * never actually call it as an XS sub, or it will crash and burn! */
4471 301 (void) newXS("DBI::_dbi_state_lval", (XSUBADDR_t)(void (*) (void))_dbi_state_lval, __FILE__);
4472  
4473  
4474 I32
4475 constant()
4476 PROTOTYPE:
4477 ALIAS:
4478 SQL_ALL_TYPES = SQL_ALL_TYPES
4479 SQL_ARRAY = SQL_ARRAY
4480 SQL_ARRAY_LOCATOR = SQL_ARRAY_LOCATOR
4481 SQL_BIGINT = SQL_BIGINT
4482 SQL_BINARY = SQL_BINARY
4483 SQL_BIT = SQL_BIT
4484 SQL_BLOB = SQL_BLOB
4485 SQL_BLOB_LOCATOR = SQL_BLOB_LOCATOR
4486 SQL_BOOLEAN = SQL_BOOLEAN
4487 SQL_CHAR = SQL_CHAR
4488 SQL_CLOB = SQL_CLOB
4489 SQL_CLOB_LOCATOR = SQL_CLOB_LOCATOR
4490 SQL_DATE = SQL_DATE
4491 SQL_DATETIME = SQL_DATETIME
4492 SQL_DECIMAL = SQL_DECIMAL
4493 SQL_DOUBLE = SQL_DOUBLE
4494 SQL_FLOAT = SQL_FLOAT
4495 SQL_GUID = SQL_GUID
4496 SQL_INTEGER = SQL_INTEGER
4497 SQL_INTERVAL = SQL_INTERVAL
4498 SQL_INTERVAL_DAY = SQL_INTERVAL_DAY
4499 SQL_INTERVAL_DAY_TO_HOUR = SQL_INTERVAL_DAY_TO_HOUR
4500 SQL_INTERVAL_DAY_TO_MINUTE = SQL_INTERVAL_DAY_TO_MINUTE
4501 SQL_INTERVAL_DAY_TO_SECOND = SQL_INTERVAL_DAY_TO_SECOND
4502 SQL_INTERVAL_HOUR = SQL_INTERVAL_HOUR
4503 SQL_INTERVAL_HOUR_TO_MINUTE = SQL_INTERVAL_HOUR_TO_MINUTE
4504 SQL_INTERVAL_HOUR_TO_SECOND = SQL_INTERVAL_HOUR_TO_SECOND
4505 SQL_INTERVAL_MINUTE = SQL_INTERVAL_MINUTE
4506 SQL_INTERVAL_MINUTE_TO_SECOND = SQL_INTERVAL_MINUTE_TO_SECOND
4507 SQL_INTERVAL_MONTH = SQL_INTERVAL_MONTH
4508 SQL_INTERVAL_SECOND = SQL_INTERVAL_SECOND
4509 SQL_INTERVAL_YEAR = SQL_INTERVAL_YEAR
4510 SQL_INTERVAL_YEAR_TO_MONTH = SQL_INTERVAL_YEAR_TO_MONTH
4511 SQL_LONGVARBINARY = SQL_LONGVARBINARY
4512 SQL_LONGVARCHAR = SQL_LONGVARCHAR
4513 SQL_MULTISET = SQL_MULTISET
4514 SQL_MULTISET_LOCATOR = SQL_MULTISET_LOCATOR
4515 SQL_NUMERIC = SQL_NUMERIC
4516 SQL_REAL = SQL_REAL
4517 SQL_REF = SQL_REF
4518 SQL_ROW = SQL_ROW
4519 SQL_SMALLINT = SQL_SMALLINT
4520 SQL_TIME = SQL_TIME
4521 SQL_TIMESTAMP = SQL_TIMESTAMP
4522 SQL_TINYINT = SQL_TINYINT
4523 SQL_TYPE_DATE = SQL_TYPE_DATE
4524 SQL_TYPE_TIME = SQL_TYPE_TIME
4525 SQL_TYPE_TIMESTAMP = SQL_TYPE_TIMESTAMP
4526 SQL_TYPE_TIMESTAMP_WITH_TIMEZONE = SQL_TYPE_TIMESTAMP_WITH_TIMEZONE
4527 SQL_TYPE_TIME_WITH_TIMEZONE = SQL_TYPE_TIME_WITH_TIMEZONE
4528 SQL_UDT = SQL_UDT
4529 SQL_UDT_LOCATOR = SQL_UDT_LOCATOR
4530 SQL_UNKNOWN_TYPE = SQL_UNKNOWN_TYPE
4531 SQL_VARBINARY = SQL_VARBINARY
4532 SQL_VARCHAR = SQL_VARCHAR
4533 SQL_WCHAR = SQL_WCHAR
4534 SQL_WLONGVARCHAR = SQL_WLONGVARCHAR
4535 SQL_WVARCHAR = SQL_WVARCHAR
4536 SQL_CURSOR_FORWARD_ONLY = SQL_CURSOR_FORWARD_ONLY
4537 SQL_CURSOR_KEYSET_DRIVEN = SQL_CURSOR_KEYSET_DRIVEN
4538 SQL_CURSOR_DYNAMIC = SQL_CURSOR_DYNAMIC
4539 SQL_CURSOR_STATIC = SQL_CURSOR_STATIC
4540 SQL_CURSOR_TYPE_DEFAULT = SQL_CURSOR_TYPE_DEFAULT
4541 DBIpp_cm_cs = DBIpp_cm_cs
4542 DBIpp_cm_hs = DBIpp_cm_hs
4543 DBIpp_cm_dd = DBIpp_cm_dd
4544 DBIpp_cm_dw = DBIpp_cm_dw
4545 DBIpp_cm_br = DBIpp_cm_br
4546 DBIpp_cm_XX = DBIpp_cm_XX
4547 DBIpp_ph_qm = DBIpp_ph_qm
4548 DBIpp_ph_cn = DBIpp_ph_cn
4549 DBIpp_ph_cs = DBIpp_ph_cs
4550 DBIpp_ph_sp = DBIpp_ph_sp
4551 DBIpp_ph_XX = DBIpp_ph_XX
4552 DBIpp_st_qq = DBIpp_st_qq
4553 DBIpp_st_bs = DBIpp_st_bs
4554 DBIpp_st_XX = DBIpp_st_XX
4555 DBIstcf_DISCARD_STRING = DBIstcf_DISCARD_STRING
4556 DBIstcf_STRICT = DBIstcf_STRICT
4557 DBIf_TRACE_SQL = DBIf_TRACE_SQL
4558 DBIf_TRACE_CON = DBIf_TRACE_CON
4559 DBIf_TRACE_ENC = DBIf_TRACE_ENC
4560 DBIf_TRACE_DBD = DBIf_TRACE_DBD
4561 DBIf_TRACE_TXN = DBIf_TRACE_TXN
4562 CODE:
4563 1374 ▶ RETVAL = ix;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ix; 288 1086 1374
4564 OUTPUT:
4565 RETVAL
4566  
4567  
4568 void
4569 _clone_dbis()
4570 CODE:
4571 dMY_CXT;
4572 0 dbistate_t * parent_dbis = DBIS;
4573  
4574 (void)cv;
4575 {
4576 MY_CXT_CLONE;
4577 }
4578 0 dbi_bootinit(parent_dbis);
4579  
4580  
4581 void
4582 _new_handle(class, parent, attr_ref, imp_datasv, imp_class)
4583 SV * class
4584 SV * parent
4585 SV * attr_ref
4586 SV * imp_datasv
4587 SV * imp_class
4588 PPCODE:
4589 dMY_CXT;
4590 HV *outer;
4591 SV *outer_ref;
4592 9692 HV *class_stash = gv_stashsv(class, GV_ADDWARN);
4593  
4594 9692 ▶ if (DBIS_TRACE_LEVEL >= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIS_TRACE_LEVEL >= 5) { 3 9689 9692
4595 6 PerlIO_printf(DBILOGFP, " New %s (for %s, parent=%s, id=%s)\n",
4596 neatsvpv(class,0), SvPV_nolen(imp_class), neatsvpv(parent,0), neatsvpv(imp_datasv,0));
4597 PERL_UNUSED_VAR(cv);
4598 }
4599  
4600 9692 (void)hv_stores((HV*)SvRV(attr_ref), "ImplementorClass", SvREFCNT_inc(imp_class));
4601  
4602 /* make attr into inner handle by blessing it into class */
4603 9692 sv_bless(attr_ref, class_stash);
4604 /* tie new outer hash to inner handle */
4605 9692 outer = newHV(); /* create new hash to be outer handle */
4606 9692 outer_ref = newRV_noinc((SV*)outer);
4607 /* make outer hash into a handle by blessing it into class */
4608 9692 sv_bless(outer_ref, class_stash);
4609 /* tie outer handle to inner handle */
4610 9692 sv_magic((SV*)outer, attr_ref, PERL_MAGIC_tied, Nullch, 0);
4611  
4612 19384 ▶ dbih_setup_handle(aTHX_ outer_ref, SvPV_nolen(imp_class), parent, SvOK(imp_datasv) ? imp_datasv : Nullsv);
Branch: 1 branch
BranchTrueFalseTotal
dbih_setup_handle(aTHX_ outer_ref, SvPV_nolen(imp_class), parent, SvOK(imp_datasv) ? imp_datasv : Nullsv); 4650 5042 9692
4613  
4614 /* return outer handle, plus inner handle if not in scalar context */
4615 9690 sv_2mortal(outer_ref);
4616 9690 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 9690 9690
4617 9690 PUSHs(outer_ref);
4618 9690 ▶ if (GIMME_V != G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_SCALAR) { 8378 1312 9690
4619 8378 PUSHs(attr_ref);
4620 }
4621  
4622  
4623 void
4624 _setup_handle(sv, imp_class, parent, imp_datasv)
4625 SV * sv
4626 char * imp_class
4627 SV * parent
4628 SV * imp_datasv
4629 CODE:
4630 (void)cv;
4631 0 ▶ dbih_setup_handle(aTHX_ sv, imp_class, parent, SvOK(imp_datasv) ? imp_datasv : Nullsv);
Branch: 1 branch
BranchTrueFalseTotal
dbih_setup_handle(aTHX_ sv, imp_class, parent, SvOK(imp_datasv) ? imp_datasv : Nullsv); 0 0 0
4632 0 ST(0) = &PL_sv_undef;
4633  
4634  
4635 void
4636 _get_imp_data(sv)
4637 SV * sv
4638 CODE:
4639 2 D_imp_xxh(sv);
4640 (void)cv;
4641 2 ST(0) = sv_mortalcopy(DBIc_IMP_DATA(imp_xxh)); /* okay if NULL */
4642  
4643  
4644 void
4645 _handles(sv)
4646 SV * sv
4647 PPCODE:
4648 /* return the outer and inner handle for any given handle */
4649 14 D_imp_xxh(sv);
4650 14 SV *ih = sv_mortalcopy( dbih_inner(aTHX_ sv, "_handles") );
4651 14 SV *oh = sv_2mortal(newRV_inc((SV*)DBIc_MY_H(imp_xxh))); /* XXX dangerous */
4652 (void)cv;
4653 14 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 14 14
4654 14 PUSHs(oh); /* returns outer handle then inner */
4655 14 ▶ if (GIMME_V != G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_SCALAR) { 14 0 14
4656 14 PUSHs(ih);
4657 }
4658  
4659  
4660 void
4661 neat(sv, maxlen=0)
4662 SV * sv
4663 U32 maxlen
4664 CODE:
4665 389 ST(0) = sv_2mortal(newSVpv(neatsvpv(sv, maxlen), 0));
4666 (void)cv;
4667  
4668  
4669 I32
4670 hash(key, type=0)
4671 const char *key
4672 long type
4673 CODE:
4674 (void)cv;
4675 10 RETVAL = dbi_hash(key, type);
4676 OUTPUT:
4677 RETVAL
4678  
4679 void
4680 looks_like_number(...)
4681 PPCODE:
4682 int i;
4683 734 ▶ EXTEND(SP, items);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, items); 734 0 734
EXTEND(SP, items); 0 734 734
4684 (void)cv;
4685 1480 ▶ for(i=0; i < items ; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < items ; ++i) { 746 734 1480
4686 746 SV *sv = ST(i);
4687 746 ▶ if (!SvOK(sv) || (SvPOK(sv) && SvCUR(sv)==0))
Branch: 3 branches
BranchTrueFalseTotal
if (!SvOK(sv) || (SvPOK(sv) && SvCUR(sv)==0)) 744 2 746
if (!SvOK(sv) || (SvPOK(sv) && SvCUR(sv)==0)) 608 136 744
if (!SvOK(sv) || (SvPOK(sv) && SvCUR(sv)==0)) 18 590 608
4688 20 PUSHs(&PL_sv_undef);
4689 726 ▶ else if ( looks_like_number(sv) )
Branch: 1 branch
BranchTrueFalseTotal
else if ( looks_like_number(sv) ) 411 315 726
4690 411 PUSHs(&PL_sv_yes);
4691 else
4692 315 PUSHs(&PL_sv_no);
4693 }
4694  
4695  
4696 void
4697 _install_method(dbi_class, meth_name, file, attribs=Nullsv)
4698 const char * dbi_class
4699 char * meth_name
4700 char * file
4701 SV * attribs
4702 CODE:
4703 {
4704 dMY_CXT;
4705 /* install another method name/interface for the DBI dispatcher */
4706 29135 ▶ SV *trace_msg = (DBIS_TRACE_LEVEL >= 10) ? sv_2mortal(newSVpvs("")) : Nullsv;
Branch: 1 branch
BranchTrueFalseTotal
SV *trace_msg = (DBIS_TRACE_LEVEL >= 10) ? sv_2mortal(newSVpvs("")) : Nullsv; 0 29135 29135
4707 CV *cv;
4708 SV **svp;
4709 dbi_ima_t *ima;
4710 MAGIC *mg;
4711 (void)dbi_class;
4712  
4713 29135 ▶ if (strnNE(meth_name, "DBI::", 5)) /* XXX m/^DBI::\w+::\w+$/ */
Branch: 1 branch
BranchTrueFalseTotal
if (strnNE(meth_name, "DBI::", 5)) /* XXX m/^DBI::\w+::\w+$/ */ 0 29135 29135
4714 0 croak("install_method %s: invalid class", meth_name);
4715  
4716 29135 ▶ if (trace_msg)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_msg) 0 29135 29135
4717 0 sv_catpvf(trace_msg, "install_method %-21s", meth_name);
4718  
4719 29135 Newxz(ima, 1, dbi_ima_t);
4720  
4721 29135 ▶ if (attribs && SvOK(attribs)) {
Branch: 2 branches
BranchTrueFalseTotal
if (attribs && SvOK(attribs)) { 29135 0 29135
if (attribs && SvOK(attribs)) { 27329 1806 29135
4722 /* convert and store method attributes in a fast access form */
4723 27329 ▶ if (SvTYPE(SvRV(attribs)) != SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(SvRV(attribs)) != SVt_PVHV) 0 27329 27329
4724 0 croak("install_method %s: bad attribs", meth_name);
4725  
4726 27329 ▶ DBD_ATTRIB_GET_IV(attribs, "O",1, svp, ima->flags);
Branch: 4 branches
BranchTrueFalseTotal
DBD_ATTRIB_GET_IV(attribs, "O",1, svp, ima->flags); 27329 0 27329
DBD_ATTRIB_GET_IV(attribs, "O",1, svp, ima->flags); 27329 0 27329
DBD_ATTRIB_GET_IV(attribs, "O",1, svp, ima->flags); 27329 0 27329
DBD_ATTRIB_GET_IV(attribs, "O",1, svp, ima->flags); 20046 7283 27329
4727 27329 ▶ DBD_ATTRIB_GET_UV(attribs, "T",1, svp, ima->method_trace);
Branch: 4 branches
BranchTrueFalseTotal
DBD_ATTRIB_GET_UV(attribs, "T",1, svp, ima->method_trace); 27329 0 27329
DBD_ATTRIB_GET_UV(attribs, "T",1, svp, ima->method_trace); 27329 0 27329
DBD_ATTRIB_GET_UV(attribs, "T",1, svp, ima->method_trace); 27329 0 27329
DBD_ATTRIB_GET_UV(attribs, "T",1, svp, ima->method_trace); 5418 21911 27329
4728 27329 ▶ DBD_ATTRIB_GET_IV(attribs, "H",1, svp, ima->hidearg);
Branch: 4 branches
BranchTrueFalseTotal
DBD_ATTRIB_GET_IV(attribs, "H",1, svp, ima->hidearg); 27329 0 27329
DBD_ATTRIB_GET_IV(attribs, "H",1, svp, ima->hidearg); 27329 0 27329
DBD_ATTRIB_GET_IV(attribs, "H",1, svp, ima->hidearg); 27329 0 27329
DBD_ATTRIB_GET_IV(attribs, "H",1, svp, ima->hidearg); 903 26426 27329
4729  
4730 27329 ▶ if (trace_msg) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_msg) { 0 27329 27329
4731 0 ▶ if (ima->flags) sv_catpvf(trace_msg, ", flags 0x%04x", (unsigned)ima->flags);
Branch: 1 branch
BranchTrueFalseTotal
if (ima->flags) sv_catpvf(trace_msg, ", flags 0x%04x", (unsigned)ima->flags); 0 0 0
4732 0 ▶ if (ima->method_trace)sv_catpvf(trace_msg, ", T 0x%08lx", (unsigned long)ima->method_trace);
Branch: 1 branch
BranchTrueFalseTotal
if (ima->method_trace)sv_catpvf(trace_msg, ", T 0x%08lx", (unsigned long)ima->method_trace); 0 0 0
4733 0 ▶ if (ima->hidearg) sv_catpvf(trace_msg, ", H %u", (unsigned)ima->hidearg);
Branch: 1 branch
BranchTrueFalseTotal
if (ima->hidearg) sv_catpvf(trace_msg, ", H %u", (unsigned)ima->hidearg); 0 0 0
4734 }
4735 27329 ▶ if ( (svp=DBD_ATTRIB_GET_SVP(attribs, "U",1)) != NULL) {
Branch: 4 branches
BranchTrueFalseTotal
if ( (svp=DBD_ATTRIB_GET_SVP(attribs, "U",1)) != NULL) { 27329 0 27329
if ( (svp=DBD_ATTRIB_GET_SVP(attribs, "U",1)) != NULL) { 27329 0 27329
if ( (svp=DBD_ATTRIB_GET_SVP(attribs, "U",1)) != NULL) { 27329 0 27329
if ( (svp=DBD_ATTRIB_GET_SVP(attribs, "U",1)) != NULL) { 19565 7764 27329
4736 19565 AV *av = (AV*)SvRV(*svp);
4737 19565 ima->minargs = (U8)SvIV(*av_fetch(av, 0, 1));
4738 19565 ima->maxargs = (U8)SvIV(*av_fetch(av, 1, 1));
4739 19565 svp = av_fetch(av, 2, 0);
4740 35518 ▶ ima->usage_msg = (svp) ? savepv_using_sv(SvPV_nolen(*svp)) : "";
Branch: 1 branch
BranchTrueFalseTotal
ima->usage_msg = (svp) ? savepv_using_sv(SvPV_nolen(*svp)) : ""; 15953 3612 19565
4741 19565 ima->flags |= IMA_HAS_USAGE;
4742 19565 ▶ if (trace_msg && DBIS_TRACE_LEVEL >= 11)
Branch: 2 branches
BranchTrueFalseTotal
if (trace_msg && DBIS_TRACE_LEVEL >= 11) 0 19565 19565
if (trace_msg && DBIS_TRACE_LEVEL >= 11) 0 0 0
4743 0 sv_catpvf(trace_msg, ",\n usage: min %d, max %d, '%s'",
4744 ima->minargs, ima->maxargs, ima->usage_msg);
4745 }
4746 }
4747 29135 ▶ if (trace_msg)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_msg) 0 29135 29135
4748 0 PerlIO_printf(DBILOGFP,"%s\n", SvPV_nolen(trace_msg));
4749 29135 file = savepv(file);
4750 29135 cv = newXS(meth_name, XS_DBI_dispatch, file);
4751 29135 SvPVX((SV *)cv) = file;
4752 29135 SvLEN((SV *)cv) = 1;
4753 29135 CvXSUBANY(cv).any_ptr = ima;
4754 29135 ima->meth_type = get_meth_type(GvNAME(CvGV(cv)));
4755  
4756 /* Attach magic to handle duping and freeing of the dbi_ima_t struct.
4757 * Due to the poor interface of the mg dup function, sneak a pointer
4758 * to the original CV in the mg_ptr field (we get called with a
4759 * pointer to the mg, but not the SV) */
4760 29135 mg = sv_magicext((SV*)cv, NULL, DBI_MAGIC, &dbi_ima_vtbl,
4761 (char *)cv, 0);
4762 29135 mg->mg_flags |= MGf_DUP;
4763 29135 ST(0) = &PL_sv_yes;
4764 }
4765  
4766  
4767 int
4768 trace(class, level_sv=&PL_sv_undef, file=Nullsv)
4769 SV * class
4770 SV * level_sv
4771 SV * file
4772 ALIAS:
4773 _debug_dispatch = 1
4774 CODE:
4775 {
4776 dMY_CXT;
4777 IV level;
4778 26 ▶ if (!DBIS) {
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIS) { 0 26 26
4779 PERL_UNUSED_VAR(ix);
4780 0 croak("DBI not initialised");
4781 }
4782 /* Return old/current value. No change if new value not given. */
4783 26 ▶ RETVAL = (DBIS) ? DBIS->debug : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (DBIS) ? DBIS->debug : 0; 26 0 26
4784 26 level = parse_trace_flags(class, level_sv, RETVAL);
4785 26 ▶ if (level) /* call before or after altering DBI trace level */
Branch: 1 branch
BranchTrueFalseTotal
if (level) /* call before or after altering DBI trace level */ 6 20 26
4786 6 set_trace_file(file);
4787 26 ▶ if (level != RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (level != RETVAL) { 12 14 26
4788 12 ▶ if ((level & DBIc_TRACE_LEVEL_MASK) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((level & DBIc_TRACE_LEVEL_MASK) > 0) { 6 6 12
4789 12 PerlIO_printf(DBILOGFP," DBI %s%s default trace level set to 0x%lx/%ld (pid %d pi %p) at %s\n",
4790 XS_VERSION, dbi_build_opt,
4791 (long)(level & DBIc_TRACE_FLAGS_MASK),
4792 (long)(level & DBIc_TRACE_LEVEL_MASK),
4793 6 (int)PerlProc_getpid(),
4794 #ifdef MULTIPLICITY
4795 (void *)my_perl,
4796 #else
4797 (void*)NULL,
4798 #endif
4799 log_where(Nullsv, 0, "", "", 1, 1, 0)
4800 );
4801 6 ▶ if (!PL_dowarn)
Branch: 1 branch
BranchTrueFalseTotal
if (!PL_dowarn) 0 6 6
4802 0 PerlIO_printf(DBILOGFP," Note: perl is running without the recommended perl -w option\n");
4803 6 PerlIO_flush(DBILOGFP);
4804 }
4805 12 DBIS->debug = level;
4806 12 sv_setiv(get_sv("DBI::dbi_debug",0x5), level);
4807 }
4808 26 ▶ if (!level) /* call before or after altering DBI trace level */
Branch: 1 branch
BranchTrueFalseTotal
if (!level) /* call before or after altering DBI trace level */ 20 6 26
4809 20 set_trace_file(file);
4810 }
4811 OUTPUT:
4812 RETVAL
4813  
4814  
4815  
4816 void
4817 dump_handle(sv, msg="DBI::dump_handle", level=0)
4818 SV * sv
4819 const char *msg
4820 int level
4821 CODE:
4822 (void)cv;
4823 4 dbih_dumphandle(aTHX_ sv, msg, level);
4824  
4825  
4826  
4827 void
4828 _svdump(sv)
4829 SV * sv
4830 CODE:
4831 {
4832 dMY_CXT;
4833 (void)cv;
4834 0 PerlIO_printf(DBILOGFP, "DBI::_svdump(%s)", neatsvpv(sv,0));
4835 #ifdef DEBUGGING
4836 sv_dump(sv);
4837 #endif
4838 }
4839  
4840  
4841 NV
4842 dbi_time()
4843  
4844  
4845 void
4846 dbi_profile(h, statement, method, t1, t2)
4847 SV *h
4848 SV *statement
4849 SV *method
4850 NV t1
4851 NV t2
4852 CODE:
4853 6 SV *leaf = &PL_sv_undef;
4854 PERL_UNUSED_VAR(cv);
4855 6 ▶ if (SvROK(method))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(method)) 0 6 6
4856 0 method = SvRV(method);
4857 6 ▶ if (dbih_inner(aTHX_ h, NULL)) { /* is a DBI handle */
Branch: 1 branch
BranchTrueFalseTotal
if (dbih_inner(aTHX_ h, NULL)) { /* is a DBI handle */ 4 2 6
4858 4 D_imp_xxh(h);
4859 4 leaf = dbi_profile(h, imp_xxh, statement, method, t1, t2);
4860 }
4861 4 ▶ else if (SvROK(h) && SvTYPE(SvRV(h)) == SVt_PVHV) {
Branch: 2 branches
BranchTrueFalseTotal
else if (SvROK(h) && SvTYPE(SvRV(h)) == SVt_PVHV) { 2 0 2
else if (SvROK(h) && SvTYPE(SvRV(h)) == SVt_PVHV) { 2 0 2
4862 /* iterate over values %$h */
4863 2 HV *hv = (HV*)SvRV(h);
4864 SV *tmp;
4865 char *key;
4866 2 I32 keylen = 0;
4867 2 hv_iterinit(hv);
4868 8 ▶ while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) { 4 2 6
4869 4 ▶ if (SvOK(tmp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(tmp)) { 2 2 4
4870 2 D_imp_xxh(tmp);
4871 2 leaf = dbi_profile(tmp, imp_xxh, statement, method, t1, t2);
4872 }
4873 };
4874 }
4875 else {
4876 0 croak("dbi_profile(%s,...) invalid handle argument", neatsvpv(h,0));
4877 }
4878 6 ▶ if (GIMME_V == G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_VOID) 4 2 6
4879 4 ST(0) = &PL_sv_undef; /* skip sv_mortalcopy if not needed */
4880 else
4881 2 ST(0) = sv_mortalcopy(leaf);
4882  
4883  
4884  
4885 SV *
4886 dbi_profile_merge_nodes(dest, ...)
4887 SV * dest
4888 ALIAS:
4889 dbi_profile_merge = 1
4890 CODE:
4891 {
4892 256 ▶ if (!SvROK(dest) || SvTYPE(SvRV(dest)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(dest) || SvTYPE(SvRV(dest)) != SVt_PVAV) 256 0 256
if (!SvROK(dest) || SvTYPE(SvRV(dest)) != SVt_PVAV) 0 256 256
4893 0 croak("dbi_profile_merge_nodes(%s,...) destination is not an array reference", neatsvpv(dest,0));
4894 256 ▶ if (items <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items <= 1) { 0 256 256
4895 PERL_UNUSED_VAR(cv);
4896 PERL_UNUSED_VAR(ix);
4897 0 RETVAL = 0;
4898 }
4899 else {
4900 /* items==2 for dest + 1 arg, ST(0) is dest, ST(1) is first arg */
4901 626 ▶ while (--items >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
while (--items >= 1) { 370 256 626
4902 370 SV *thingy = ST(items);
4903 370 dbi_profile_merge_nodes(dest, thingy);
4904 }
4905 256 RETVAL = newSVsv(*av_fetch((AV*)SvRV(dest), DBIprof_TOTAL_TIME, 1));
4906 }
4907 }
4908 OUTPUT:
4909 RETVAL
4910  
4911  
4912 SV *
4913 _concat_hash_sorted(hash_sv, kv_sep_sv, pair_sep_sv, use_neat_sv, num_sort_sv)
4914 SV *hash_sv
4915 SV *kv_sep_sv
4916 SV *pair_sep_sv
4917 SV *use_neat_sv
4918 SV *num_sort_sv
4919 PREINIT:
4920 char *kv_sep, *pair_sep;
4921 STRLEN kv_sep_len, pair_sep_len;
4922 CODE:
4923 3330 ▶ if (!SvOK(hash_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(hash_sv)) 19 3311 3330
4924 19 XSRETURN_UNDEF;
4925 3311 ▶ if (!SvROK(hash_sv) || SvTYPE(SvRV(hash_sv))!=SVt_PVHV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(hash_sv) || SvTYPE(SvRV(hash_sv))!=SVt_PVHV) 3311 0 3311
if (!SvROK(hash_sv) || SvTYPE(SvRV(hash_sv))!=SVt_PVHV) 2 3309 3311
4926 2 croak("hash is not a hash reference");
4927  
4928 3309 ▶ kv_sep = SvPV(kv_sep_sv, kv_sep_len);
Branch: 1 branch
BranchTrueFalseTotal
kv_sep = SvPV(kv_sep_sv, kv_sep_len); 3307 2 3309
4929 3309 pair_sep = SvPV(pair_sep_sv, pair_sep_len);
4930  
4931 6618 RETVAL = _join_hash_sorted( (HV*)SvRV(hash_sv),
4932 kv_sep, kv_sep_len,
4933 pair_sep, pair_sep_len,
4934 /* use_neat should be undef, 0 or 1, may allow sprintf format strings later */
4935 3309 ▶ (SvOK(use_neat_sv)) ? SvIV(use_neat_sv) : 0,
Branch: 1 branch
BranchTrueFalseTotal
(SvOK(use_neat_sv)) ? SvIV(use_neat_sv) : 0, 3303 6 3309
4936 3309 ▶ (SvOK(num_sort_sv)) ? SvIV(num_sort_sv) : -1
Branch: 1 branch
BranchTrueFalseTotal
(SvOK(num_sort_sv)) ? SvIV(num_sort_sv) : -1 3267 42 3309
4937 );
4938 OUTPUT:
4939 RETVAL
4940  
4941  
4942 int
4943 sql_type_cast(sv, sql_type, flags=0)
4944 SV * sv
4945 int sql_type
4946 U32 flags
4947 CODE:
4948 54 RETVAL = sql_type_cast_svpv(aTHX_ sv, sql_type, flags, 0);
4949 OUTPUT:
4950 RETVAL
4951  
4952  
4953  
4954 MODULE = DBI PACKAGE = DBI::var
4955  
4956 void
4957 FETCH(sv)
4958 SV * sv
4959 CODE:
4960 dMY_CXT;
4961 /* Note that we do not come through the dispatcher to get here. */
4962 19374 char *meth = SvPV_nolen(SvRV(sv)); /* what should this tie do ? */
4963 19374 char type = *meth++; /* is this a $ or & style */
4964 19374 ▶ imp_xxh_t *imp_xxh = (DBI_LAST_HANDLE_OK) ? DBIh_COM(DBI_LAST_HANDLE) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
imp_xxh_t *imp_xxh = (DBI_LAST_HANDLE_OK) ? DBIh_COM(DBI_LAST_HANDLE) : NULL; 19374 0 19374
4965 19374 ▶ int trace_level = (imp_xxh ? DBIc_TRACE_LEVEL(imp_xxh) : DBIS_TRACE_LEVEL);
Branch: 1 branch
BranchTrueFalseTotal
int trace_level = (imp_xxh ? DBIc_TRACE_LEVEL(imp_xxh) : DBIS_TRACE_LEVEL); 19374 0 19374
4966 19374 NV profile_t1 = 0.0;
4967  
4968 19374 ▶ if (imp_xxh && DBIc_has(imp_xxh,DBIcf_Profile))
Branch: 2 branches
BranchTrueFalseTotal
if (imp_xxh && DBIc_has(imp_xxh,DBIcf_Profile)) 19374 0 19374
if (imp_xxh && DBIc_has(imp_xxh,DBIcf_Profile)) 12 19362 19374
4969 12 profile_t1 = dbi_time();
4970  
4971 19374 ▶ if (trace_level >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 2) { 12 19362 19374
4972 24 ▶ PerlIO_printf(DBILOGFP," -> $DBI::%s (%c) FETCH from lasth=%s\n", meth, type,
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(DBILOGFP," -> $DBI::%s (%c) FETCH from lasth=%s\n", meth, type, 12 0 12
4973 12 (imp_xxh) ? neatsvpv(DBI_LAST_HANDLE,0): "none");
4974 }
4975  
4976 19374 ▶ if (type == '!') { /* special case for $DBI::lasth */
Branch: 1 branch
BranchTrueFalseTotal
if (type == '!') { /* special case for $DBI::lasth */ 0 19374 19374
4977 /* Currently we can only return the INNER handle. */
4978 /* This handle should only be used for true/false tests */
4979 0 ▶ ST(0) = (imp_xxh) ? sv_2mortal(newRV_inc(DBI_LAST_HANDLE)) : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
ST(0) = (imp_xxh) ? sv_2mortal(newRV_inc(DBI_LAST_HANDLE)) : &PL_sv_undef; 0 0 0
4980 }
4981 19374 ▶ else if ( !imp_xxh ) {
Branch: 1 branch
BranchTrueFalseTotal
else if ( !imp_xxh ) { 0 19374 19374
4982 0 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 0 0
4983 0 warn("Can't read $DBI::%s, last handle unknown or destroyed", meth);
4984 0 ST(0) = &PL_sv_undef;
4985 }
4986 19374 ▶ else if (type == '*') { /* special case for $DBI::err, see also err method */
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '*') { /* special case for $DBI::err, see also err method */ 6528 12846 19374
4987 6528 SV *errsv = DBIc_ERR(imp_xxh);
4988 6528 ST(0) = sv_mortalcopy(errsv);
4989 }
4990 12846 ▶ else if (type == '"') { /* special case for $DBI::state */
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '"') { /* special case for $DBI::state */ 6271 6575 12846
4991 6271 SV *state = DBIc_STATE(imp_xxh);
4992 6299 ▶ ST(0) = DBIc_STATE_adjust(imp_xxh, state);
Branch: 3 branches
BranchTrueFalseTotal
ST(0) = DBIc_STATE_adjust(imp_xxh, state); 28 6243 6271
ST(0) = DBIc_STATE_adjust(imp_xxh, state); 26 2 28
ST(0) = DBIc_STATE_adjust(imp_xxh, state); 1711 4532 6243
4993 }
4994 6575 ▶ else if (type == '$') { /* lookup scalar variable in implementors stash */
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '$') { /* lookup scalar variable in implementors stash */ 0 6575 6575
4995 0 const char *vname = mkvname(aTHX_ DBIc_IMP_STASH(imp_xxh), meth, 0);
4996 0 SV *vsv = get_sv(vname, 1);
4997 0 ST(0) = sv_mortalcopy(vsv);
4998 }
4999 else {
5000 /* default to method call via stash of implementor of DBI_LAST_HANDLE */
5001 GV *imp_gv;
5002 6575 HV *imp_stash = DBIc_IMP_STASH(imp_xxh);
5003 #ifdef DBI_save_hv_fetch_ent
5004 HE save_mh = PL_hv_fetch_ent_mh; /* XXX nested tied FETCH bug17575 workaround */
5005 #endif
5006 6575 profile_t1 = 0.0; /* profile this via dispatch only (else we'll double count) */
5007 6575 ▶ if (trace_level >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 3) 4 6571 6575
5008 4 ▶ PerlIO_printf(DBILOGFP," >> %s::%s\n", HvNAME(imp_stash), meth);
Branch: 6 branches
BranchTrueFalseTotal
PerlIO_printf(DBILOGFP," >> %s::%s\n", HvNAME(imp_stash), meth); 4 0 4
PerlIO_printf(DBILOGFP," >> %s::%s\n", HvNAME(imp_stash), meth); 4 0 4
PerlIO_printf(DBILOGFP," >> %s::%s\n", HvNAME(imp_stash), meth); 0 4 4
PerlIO_printf(DBILOGFP," >> %s::%s\n", HvNAME(imp_stash), meth); 0 0 0
PerlIO_printf(DBILOGFP," >> %s::%s\n", HvNAME(imp_stash), meth); 4 0 4
PerlIO_printf(DBILOGFP," >> %s::%s\n", HvNAME(imp_stash), meth); 0 4 4
5009 6575 ST(0) = sv_2mortal(newRV_inc(DBI_LAST_HANDLE));
5010 6575 ▶ if ((imp_gv = gv_fetchmethod(imp_stash,meth)) == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if ((imp_gv = gv_fetchmethod(imp_stash,meth)) == NULL) { 0 6575 6575
5011 0 ▶ croak("Can't locate $DBI::%s object method \"%s\" via package \"%s\"",
Branch: 6 branches
BranchTrueFalseTotal
croak("Can't locate $DBI::%s object method \"%s\" via package \"%s\"", 0 0 0
croak("Can't locate $DBI::%s object method \"%s\" via package \"%s\"", 0 0 0
croak("Can't locate $DBI::%s object method \"%s\" via package \"%s\"", 0 0 0
croak("Can't locate $DBI::%s object method \"%s\" via package \"%s\"", 0 0 0
croak("Can't locate $DBI::%s object method \"%s\" via package \"%s\"", 0 0 0
croak("Can't locate $DBI::%s object method \"%s\" via package \"%s\"", 0 0 0
5012 meth, meth, HvNAME(imp_stash));
5013 }
5014 6575 ▶ PUSHMARK(mark); /* reset mark (implies one arg as we were called with one arg?) */
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(mark); /* reset mark (implies one arg as we were called with one arg?) */ 0 6575 6575
5015 6575 call_sv((SV*)GvCV(imp_gv), GIMME_V);
5016 6575 SPAGAIN;
5017 #ifdef DBI_save_hv_fetch_ent
5018 PL_hv_fetch_ent_mh = save_mh;
5019 #endif
5020 }
5021 19374 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 15 19359 19374
5022 15 PerlIO_printf(DBILOGFP," <- $DBI::%s= %s\n", meth, neatsvpv(ST(0),0));
5023 19374 ▶ if (profile_t1) {
Branch: 1 branch
BranchTrueFalseTotal
if (profile_t1) { 8 19366 19374
5024 8 SV *h = sv_2mortal(newRV_inc(DBI_LAST_HANDLE));
5025 8 dbi_profile(h, imp_xxh, &PL_sv_undef, (SV*)cv, profile_t1, dbi_time());
5026 }
5027  
5028  
5029 MODULE = DBI PACKAGE = DBD::_::dr
5030  
5031 void
5032 dbixs_revision(h)
5033 SV * h
5034 CODE:
5035 PERL_UNUSED_VAR(h);
5036 4 ST(0) = sv_2mortal(newSViv(DBIXS_REVISION));
5037  
5038  
5039 MODULE = DBI PACKAGE = DBD::_::db
5040  
5041 void
5042 connected(...)
5043 CODE:
5044 /* defined here just to avoid AUTOLOAD */
5045 (void)cv;
5046 (void)items;
5047 5998 ST(0) = &PL_sv_undef;
5048  
5049  
5050 SV *
5051 preparse(dbh, statement, ps_return, ps_accept, foo=Nullch)
5052 SV * dbh
5053 char * statement
5054 IV ps_return
5055 IV ps_accept
5056 void *foo
5057  
5058  
5059 void
5060 take_imp_data(h)
5061 SV * h
5062 PREINIT:
5063 /* take_imp_data currently in DBD::_::db not DBD::_::common, so for dbh's only */
5064 1 D_imp_xxh(h);
5065 MAGIC *mg;
5066 SV *imp_xxh_sv;
5067 SV **tmp_svp;
5068 CODE:
5069 PERL_UNUSED_VAR(cv);
5070 /*
5071 * Remove and return the imp_xxh_t structure that's attached to the inner
5072 * hash of the handle. Effectively this removes the 'brain' of the handle
5073 * leaving it as an empty shell - brain dead. All method calls on it fail.
5074 *
5075 * The imp_xxh_t structure that's removed and returned is a plain scalar
5076 * (containing binary data). It can be passed to a new DBI->connect call
5077 * in order to have the new $dbh use the same 'connection' as the original
5078 * handle. In this way a multi-threaded connection pool can be implemented.
5079 *
5080 * If the drivers imp_xxh_t structure contains SV*'s, or other interpreter
5081 * specific items, they should be freed by the drivers own take_imp_data()
5082 * method before it then calls SUPER::take_imp_data() to finalize removal
5083 * of the imp_xxh_t structure.
5084 *
5085 * The driver needs to view the take_imp_data method as being nearly the
5086 * same as disconnect+DESTROY only not actually calling the database API to
5087 * disconnect. All that needs to remain valid in the imp_xxh_t structure
5088 * is the underlying database API connection data. Everything else should
5089 * in a 'clean' state such that if the drivers own DESTROY method was
5090 * called it would be able to properly handle the contents of the
5091 * structure. This is important in case a new handle created using this
5092 * imp_data, possibly in a new thread, might end up being DESTROY'd before
5093 * the driver has had a chance to 're-setup' the data. See dbih_setup_handle()
5094 *
5095 * All the above relates to the 'typical use case' for a compiled driver.
5096 * For a pure-perl driver using a socket pair, for example, the drivers
5097 * take_imp_data method might just return a string containing the fileno()
5098 * values of the sockets (without calling this SUPER::take_imp_data() code).
5099 * The key point is that the take_imp_data() method returns an opaque buffer
5100 * containing whatever the driver would need to reuse the same underlying
5101 * 'connection to the database' in a new handle.
5102 *
5103 * In all cases, care should be taken that driver attributes (such as
5104 * AutoCommit) match the state of the underlying connection.
5105 */
5106  
5107 1 ▶ if (!DBIc_ACTIVE(imp_xxh)) {/* sanity check, may be relaxed later */
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIc_ACTIVE(imp_xxh)) {/* sanity check, may be relaxed later */ 0 1 1
5108 0 set_err_char(h, imp_xxh, "1", 1, "Can't take_imp_data from handle that's not Active", 0, "take_imp_data");
5109 0 XSRETURN(0);
5110 }
5111  
5112 /* Ideally there should be no child statement handles existing when
5113 * take_imp_data is called because when those statement handles are
5114 * destroyed they may need to interact with the 'zombie' parent dbh.
5115 * So we do our best to neautralize them (finish & rebless)
5116 */
5117 1 ▶ if ((tmp_svp = hv_fetchs((HV*)SvRV(h), "ChildHandles", FALSE)) && SvROK(*tmp_svp)) {
Branch: 2 branches
BranchTrueFalseTotal
if ((tmp_svp = hv_fetchs((HV*)SvRV(h), "ChildHandles", FALSE)) && SvROK(*tmp_svp)) { 1 0 1
if ((tmp_svp = hv_fetchs((HV*)SvRV(h), "ChildHandles", FALSE)) && SvROK(*tmp_svp)) { 1 0 1
5118 1 AV *av = (AV*)SvRV(*tmp_svp);
5119 1 HV *zombie_stash = gv_stashpv("DBI::zombie", GV_ADDWARN);
5120 I32 kidslots;
5121 4 ▶ for (kidslots = AvFILL(av); kidslots >= 0; --kidslots) {
Branch: 1 branch
BranchTrueFalseTotal
for (kidslots = AvFILL(av); kidslots >= 0; --kidslots) { 3 1 4
5122 3 SV **hp = av_fetch(av, kidslots, FALSE);
5123 3 ▶ if (hp && SvROK(*hp) && SvMAGICAL(SvRV(*hp))) {
Branch: 3 branches
BranchTrueFalseTotal
if (hp && SvROK(*hp) && SvMAGICAL(SvRV(*hp))) { 3 0 3
if (hp && SvROK(*hp) && SvMAGICAL(SvRV(*hp))) { 2 1 3
if (hp && SvROK(*hp) && SvMAGICAL(SvRV(*hp))) { 2 0 2
5124 2 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 2 2
5125 2 ▶ XPUSHs(*hp);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(*hp); 0 2 2
5126 2 PUTBACK;
5127 2 call_method("finish", G_VOID);
5128 2 SPAGAIN;
5129 2 PUTBACK;
5130 2 sv_unmagic(SvRV(*hp), 'P'); /* untie */
5131 2 sv_bless(*hp, zombie_stash); /* neutralise */
5132 }
5133 }
5134 }
5135 /* The above measures may not be sufficient if weakrefs aren't available
5136 * or something has a reference to the inner-handle of an sth.
5137 * We'll require no Active kids, but just warn about others.
5138 */
5139 1 ▶ if (DBIc_ACTIVE_KIDS(imp_xxh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_ACTIVE_KIDS(imp_xxh)) { 0 1 1
5140 0 set_err_char(h, imp_xxh, "1", 1, "Can't take_imp_data from handle while it still has Active kids", 0, "take_imp_data");
5141 0 XSRETURN(0);
5142 }
5143 1 ▶ if (DBIc_KIDS(imp_xxh))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_KIDS(imp_xxh)) 0 1 1
5144 0 warn("take_imp_data from handle while it still has kids");
5145  
5146 /* it may be better here to return a copy and poison the original
5147 * rather than detatching and returning the original
5148 */
5149  
5150 /* --- perform the surgery */
5151 1 dbih_getcom2(aTHX_ h, &mg); /* get the MAGIC so we can change it */
5152 1 imp_xxh_sv = mg->mg_obj; /* take local copy of the imp_data pointer */
5153 1 mg->mg_obj = Nullsv; /* sever the link from handle to imp_xxh */
5154 1 mg->mg_ptr = NULL; /* and sever the shortcut too */
5155 1 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 9)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 9) 0 1 1
5156 0 sv_dump(imp_xxh_sv);
5157 /* --- housekeeping */
5158 1 ▶ DBIc_ACTIVE_off(imp_xxh); /* silence warning from dbih_clearcom */
Branch: 5 branches
BranchTrueFalseTotal
DBIc_ACTIVE_off(imp_xxh); /* silence warning from dbih_clearcom */ 1 0 1
DBIc_ACTIVE_off(imp_xxh); /* silence warning from dbih_clearcom */ 1 0 1
DBIc_ACTIVE_off(imp_xxh); /* silence warning from dbih_clearcom */ 1 0 1
DBIc_ACTIVE_off(imp_xxh); /* silence warning from dbih_clearcom */ 1 0 1
DBIc_ACTIVE_off(imp_xxh); /* silence warning from dbih_clearcom */ 0 1 1
5159 1 DBIc_IMPSET_off(imp_xxh); /* silence warning from dbih_clearcom */
5160 1 dbih_clearcom(imp_xxh); /* free SVs like DBD::_mem::common::DESTROY */
5161 1 SvOBJECT_off(imp_xxh_sv); /* no longer needs DESTROY via dbih_clearcom */
5162 /* restore flags to mark fact imp data holds active connection */
5163 /* (don't use magical DBIc_ACTIVE_on here) */
5164 1 DBIc_FLAGS(imp_xxh) |= DBIcf_IMPSET | DBIcf_ACTIVE;
5165 /* --- tidy up the raw PV for life as a more normal string */
5166 1 SvPOK_on(imp_xxh_sv); /* SvCUR & SvEND were set at creation */
5167 /* --- return the actual imp_xxh_sv on the stack */
5168 1 ST(0) = imp_xxh_sv;
5169  
5170  
5171  
5172 MODULE = DBI PACKAGE = DBD::_::st
5173  
5174 void
5175 _get_fbav(sth)
5176 SV * sth
5177 CODE:
5178 6 D_imp_sth(sth);
5179 6 AV *av = dbih_get_fbav(imp_sth);
5180 (void)cv;
5181 6 ST(0) = sv_2mortal(newRV_inc((SV*)av));
5182  
5183 void
5184 _set_fbav(sth, src_rv)
5185 SV * sth
5186 SV * src_rv
5187 CODE:
5188 105951 D_imp_sth(sth);
5189 int i;
5190 AV *src_av;
5191 105951 AV *dst_av = dbih_get_fbav(imp_sth);
5192 105951 int dst_fields = AvFILL(dst_av)+1;
5193 int src_fields;
5194 (void)cv;
5195  
5196 105951 ▶ if (!SvROK(src_rv) || SvTYPE(SvRV(src_rv)) != SVt_PVAV)
Branch: 2 branches
BranchTrueFalseTotal
if (!SvROK(src_rv) || SvTYPE(SvRV(src_rv)) != SVt_PVAV) 105951 0 105951
if (!SvROK(src_rv) || SvTYPE(SvRV(src_rv)) != SVt_PVAV) 0 105951 105951
5197 0 croak("_set_fbav(%s): not an array ref", neatsvpv(src_rv,0));
5198 105951 src_av = (AV*)SvRV(src_rv);
5199 105951 src_fields = AvFILL(src_av)+1;
5200 105951 ▶ if (src_fields != dst_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_fields != dst_fields) { 0 105951 105951
5201 0 ▶ if ( dst_fields == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ( dst_fields == 0 ) 0 0 0
5202 0 croak("_set_fbav(%s): array has %d elements, but the statement handle row buffer has 0",
5203 neatsvpv(src_rv,0), src_fields);
5204 0 warn("_set_fbav(%s): array has %d elements, the statement handle row buffer has %d (and NUM_OF_FIELDS is %d)",
5205 neatsvpv(src_rv,0), src_fields, dst_fields, DBIc_NUM_FIELDS(imp_sth));
5206 0 SvREADONLY_off(dst_av);
5207 0 ▶ if (src_fields < dst_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_fields < dst_fields) { 0 0 0
5208 /* shrink the array - sadly this looses column bindings for the lost columns */
5209 0 av_fill(dst_av, src_fields-1);
5210 0 dst_fields = src_fields;
5211 }
5212 else {
5213 0 av_fill(dst_av, src_fields-1);
5214 /* av_fill pads with immutable undefs which we need to change */
5215 0 ▶ for(i=dst_fields-1; i < src_fields; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=dst_fields-1; i < src_fields; ++i) { 0 0 0
5216 0 sv_setsv(AvARRAY(dst_av)[i], newSV(0));
5217 }
5218 }
5219 0 SvREADONLY_on(dst_av);
5220 }
5221 420762 ▶ for(i=0; i < dst_fields; ++i) { /* copy over the row */
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < dst_fields; ++i) { /* copy over the row */ 314811 105951 420762
5222 /* If we're given the values, then taint them if required */
5223 314811 ▶ if (DBIc_is(imp_sth, DBIcf_TaintOut))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_sth, DBIcf_TaintOut)) 3 314808 314811
5224 3 ▶ SvTAINT(AvARRAY(src_av)[i]);
Branch: 2 branches
BranchTrueFalseTotal
SvTAINT(AvARRAY(src_av)[i]); 3 0 3
SvTAINT(AvARRAY(src_av)[i]); 3 0 3
5225 314811 sv_setsv(AvARRAY(dst_av)[i], AvARRAY(src_av)[i]);
5226 }
5227 105951 ST(0) = sv_2mortal(newRV_inc((SV*)dst_av));
5228  
5229  
5230 void
5231 bind_col(sth, col, ref, attribs=Nullsv)
5232 SV * sth
5233 SV * col
5234 SV * ref
5235 SV * attribs
5236 PREINIT:
5237 SV *ret;
5238 CODE:
5239 162 ▶ DBD_ATTRIBS_CHECK("bind_col", sth, attribs);
Branch: 5 branches
BranchTrueFalseTotal
DBD_ATTRIBS_CHECK("bind_col", sth, attribs); 138 24 162
DBD_ATTRIBS_CHECK("bind_col", sth, attribs); 2 136 138
DBD_ATTRIBS_CHECK("bind_col", sth, attribs); 2 0 2
DBD_ATTRIBS_CHECK("bind_col", sth, attribs); 0 2 2
DBD_ATTRIBS_CHECK("bind_col", sth, attribs); 0 0 0
5240 162 ▶ ret = boolSV(dbih_sth_bind_col(sth, col, ref, attribs));
Branch: 1 branch
BranchTrueFalseTotal
ret = boolSV(dbih_sth_bind_col(sth, col, ref, attribs)); 156 0 156
5241 156 ST(0) = ret;
5242 (void)cv;
5243  
5244  
5245 void
5246 fetchrow_array(sth)
5247 SV * sth
5248 ALIAS:
5249 fetchrow = 1
5250 PPCODE:
5251 SV *retsv;
5252 7 ▶ if (CvDEPTH(cv) == 99) {
Branch: 1 branch
BranchTrueFalseTotal
if (CvDEPTH(cv) == 99) { 0 7 7
5253 PERL_UNUSED_VAR(ix);
5254 0 croak("Deep recursion, probably fetchrow-fetch-fetchrow loop");
5255 }
5256 7 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 7 7
5257 7 ▶ XPUSHs(sth);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sth); 0 7 7
5258 7 PUTBACK;
5259 7 ▶ if (call_method("fetch", G_SCALAR) != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (call_method("fetch", G_SCALAR) != 1) 0 7 7
5260 0 croak("panic: DBI fetch"); /* should never happen */
5261 7 SPAGAIN;
5262 7 retsv = POPs;
5263 7 PUTBACK;
5264 7 ▶ if (SvROK(retsv) && SvTYPE(SvRV(retsv)) == SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(retsv) && SvTYPE(SvRV(retsv)) == SVt_PVAV) { 7 0 7
if (SvROK(retsv) && SvTYPE(SvRV(retsv)) == SVt_PVAV) { 7 0 7
5265 7 D_imp_sth(sth);
5266 int num_fields, i;
5267 AV *bound_av;
5268 7 AV *av = (AV*)SvRV(retsv);
5269 7 num_fields = AvFILL(av)+1;
5270 7 ▶ EXTEND(sp, num_fields+1);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(sp, num_fields+1); 7 0 7
EXTEND(sp, num_fields+1); 0 7 7
5271  
5272 /* We now check for bind_col() having been called but fetch */
5273 /* not returning the fields_svav array. Probably because the */
5274 /* driver is implemented in perl. XXX This logic may change later. */
5275 7 bound_av = DBIc_FIELDS_AV(imp_sth); /* bind_col() called ? */
5276 7 ▶ if (bound_av && av != bound_av) {
Branch: 2 branches
BranchTrueFalseTotal
if (bound_av && av != bound_av) { 7 0 7
if (bound_av && av != bound_av) { 0 7 7
5277 /* let dbih_get_fbav know what's going on */
5278 0 bound_av = dbih_get_fbav(imp_sth);
5279 0 ▶ if (DBIc_TRACE_LEVEL(imp_sth) >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth) >= 3) { 0 0 0
5280 0 PerlIO_printf(DBIc_LOGPIO(imp_sth),
5281 "fetchrow: updating fbav 0x%lx from 0x%lx\n",
5282 (long)bound_av, (long)av);
5283 }
5284 0 ▶ for(i=0; i < num_fields; ++i) { /* copy over the row */
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < num_fields; ++i) { /* copy over the row */ 0 0 0
5285 0 sv_setsv(AvARRAY(bound_av)[i], AvARRAY(av)[i]);
5286 }
5287 }
5288 28 ▶ for(i=0; i < num_fields; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < num_fields; ++i) { 21 7 28
5289 21 PUSHs(AvARRAY(av)[i]);
5290 }
5291 }
5292  
5293  
5294 SV *
5295 fetchrow_hashref(sth, keyattrib=Nullch)
5296 SV * sth
5297 const char *keyattrib
5298 PREINIT:
5299 SV *rowavr;
5300 SV *ka_rv;
5301 8958 D_imp_sth(sth);
5302 CODE:
5303 (void)cv;
5304 8958 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 8958 8958
5305 8958 ▶ XPUSHs(sth);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sth); 0 8958 8958
5306 8958 PUTBACK;
5307 8958 ▶ if (!keyattrib || !*keyattrib) {
Branch: 2 branches
BranchTrueFalseTotal
if (!keyattrib || !*keyattrib) { 4 8954 8958
if (!keyattrib || !*keyattrib) { 0 4 4
5308 8954 SV *kn = DBIc_FetchHashKeyName(imp_sth);
5309 8954 ▶ if (kn && SvOK(kn))
Branch: 2 branches
BranchTrueFalseTotal
if (kn && SvOK(kn)) 8954 0 8954
if (kn && SvOK(kn)) 8954 0 8954
5310 8954 keyattrib = SvPV_nolen(kn); /* Also force stringification */
5311 else
5312 0 keyattrib = "NAME";
5313 }
5314 8958 ka_rv = *hv_fetch((HV*)DBIc_MY_H(imp_sth), keyattrib,strlen(keyattrib), TRUE);
5315 /* we copy to invoke FETCH magic, and we do that before fetch() so if tainting */
5316 /* then the taint triggered by the fetch won't then apply to the fetched name */
5317 8958 ka_rv = newSVsv(ka_rv);
5318 8958 ▶ if (call_method("fetch", G_SCALAR) != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (call_method("fetch", G_SCALAR) != 1) 0 8958 8958
5319 0 croak("panic: DBI fetch"); /* should never happen */
5320 8958 SPAGAIN;
5321 8958 rowavr = POPs;
5322 8958 PUTBACK;
5323 /* have we got an array ref in rowavr */
5324 17808 ▶ if (SvROK(rowavr) && SvTYPE(SvRV(rowavr)) == SVt_PVAV) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvROK(rowavr) && SvTYPE(SvRV(rowavr)) == SVt_PVAV) { 8854 104 8958
if (SvROK(rowavr) && SvTYPE(SvRV(rowavr)) == SVt_PVAV) { 8854 0 8854
5325 int i;
5326 8854 AV *rowav = (AV*)SvRV(rowavr);
5327 8854 const int num_fields = AvFILL(rowav)+1;
5328 HV *hv;
5329 AV *ka_av;
5330 8854 ▶ if (!(SvROK(ka_rv) && SvTYPE(SvRV(ka_rv))==SVt_PVAV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!(SvROK(ka_rv) && SvTYPE(SvRV(ka_rv))==SVt_PVAV)) { 8852 2 8854
if (!(SvROK(ka_rv) && SvTYPE(SvRV(ka_rv))==SVt_PVAV)) { 2 8850 8852
5331 4 sv_setiv(DBIc_ERR(imp_sth), 1);
5332 4 sv_setpvf(DBIc_ERRSTR(imp_sth),
5333 "Can't use attribute '%s' because it doesn't contain a reference to an array (%s)",
5334 keyattrib, neatsvpv(ka_rv,0));
5335 4 XSRETURN_UNDEF;
5336 }
5337 8850 ka_av = (AV*)SvRV(ka_rv);
5338 8850 hv = newHV();
5339 35372 ▶ for (i=0; i < num_fields; ++i) { /* honor the original order as sent by the database */
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i < num_fields; ++i) { /* honor the original order as sent by the database */ 26522 8850 35372
5340 26522 SV **field_name_svp = av_fetch(ka_av, i, 1);
5341 26522 (void)hv_store_ent(hv, *field_name_svp, newSVsv((SV*)(AvARRAY(rowav)[i])), 0);
5342 }
5343 8850 RETVAL = newRV_inc((SV*)hv);
5344 8850 SvREFCNT_dec(hv); /* since newRV incremented it */
5345 }
5346 else {
5347 104 RETVAL = &PL_sv_undef;
5348 }
5349 8954 SvREFCNT_dec(ka_rv); /* since we created it */
5350 OUTPUT:
5351 RETVAL
5352  
5353  
5354 void
5355 fetch(sth)
5356 SV * sth
5357 ALIAS:
5358 fetchrow_arrayref = 1
5359 CODE:
5360 int num_fields;
5361 0 ▶ if (CvDEPTH(cv) == 99) {
Branch: 1 branch
BranchTrueFalseTotal
if (CvDEPTH(cv) == 99) { 0 0 0
5362 PERL_UNUSED_VAR(ix);
5363 0 croak("Deep recursion. Probably fetch-fetchrow-fetch loop.");
5364 }
5365 0 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 0 0
5366 0 ▶ XPUSHs(sth);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sth); 0 0 0
5367 0 PUTBACK;
5368 0 num_fields = call_method("fetchrow", G_LIST); /* XXX change the name later */
5369 0 SPAGAIN;
5370 0 ▶ if (num_fields == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (num_fields == 0) { 0 0 0
5371 0 ST(0) = &PL_sv_undef;
5372 } else {
5373 0 D_imp_sth(sth);
5374 0 AV *av = dbih_get_fbav(imp_sth);
5375 0 ▶ if (num_fields != AvFILL(av)+1)
Branch: 1 branch
BranchTrueFalseTotal
if (num_fields != AvFILL(av)+1) 0 0 0
5376 0 croak("fetchrow returned %d fields, expected %d",
5377 num_fields, (int)AvFILL(av)+1);
5378 0 SPAGAIN;
5379 0 ▶ while(--num_fields >= 0)
Branch: 1 branch
BranchTrueFalseTotal
while(--num_fields >= 0) 0 0 0
5380 0 sv_setsv(AvARRAY(av)[num_fields], POPs);
5381 0 PUTBACK;
5382 0 ST(0) = sv_2mortal(newRV_inc((SV*)av));
5383 }
5384  
5385  
5386 void
5387 rows(sth)
5388 SV * sth
5389 CODE:
5390 5 D_imp_sth(sth);
5391 5 const IV rows = DBIc_ROW_COUNT(imp_sth);
5392 5 ST(0) = sv_2mortal(newSViv(rows));
5393 (void)cv;
5394  
5395  
5396 void
5397 finish(sth)
5398 SV * sth
5399 CODE:
5400 14424 D_imp_sth(sth);
5401 14424 ▶ DBIc_ACTIVE_off(imp_sth);
Branch: 5 branches
BranchTrueFalseTotal
DBIc_ACTIVE_off(imp_sth); 5856 8568 14424
DBIc_ACTIVE_off(imp_sth); 5856 0 5856
DBIc_ACTIVE_off(imp_sth); 5856 0 5856
DBIc_ACTIVE_off(imp_sth); 5856 0 5856
DBIc_ACTIVE_off(imp_sth); 0 5856 5856
5402 14424 ST(0) = &PL_sv_yes;
5403 (void)cv;
5404  
5405  
5406 void
5407 DESTROY(sth)
5408 SV * sth
5409 PPCODE:
5410 /* keep in sync with DESTROY in Driver.xst */
5411 5335 D_imp_sth(sth);
5412 5335 ST(0) = &PL_sv_yes;
5413 /* we don't test IMPSET here because this code applies to pure-perl drivers */
5414 5335 ▶ if (DBIc_IADESTROY(imp_sth)) { /* want's ineffective destroy */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_IADESTROY(imp_sth)) { /* want's ineffective destroy */ 0 5335 5335
5415 0 ▶ DBIc_ACTIVE_off(imp_sth);
Branch: 5 branches
BranchTrueFalseTotal
DBIc_ACTIVE_off(imp_sth); 0 0 0
DBIc_ACTIVE_off(imp_sth); 0 0 0
DBIc_ACTIVE_off(imp_sth); 0 0 0
DBIc_ACTIVE_off(imp_sth); 0 0 0
DBIc_ACTIVE_off(imp_sth); 0 0 0
5416 0 ▶ if (DBIc_TRACE_LEVEL(imp_sth))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth)) 0 0 0
5417 0 PerlIO_printf(DBIc_LOGPIO(imp_sth), " DESTROY %s skipped due to InactiveDestroy\n", SvPV_nolen(sth));
5418 }
5419 5335 ▶ if (DBIc_ACTIVE(imp_sth)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_ACTIVE(imp_sth)) { 7 5328 5335
5420 7 D_imp_dbh_from_sth;
5421 7 ▶ if (!PL_dirty && DBIc_ACTIVE(imp_dbh)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!PL_dirty && DBIc_ACTIVE(imp_dbh)) { 7 0 7
if (!PL_dirty && DBIc_ACTIVE(imp_dbh)) { 7 0 7
5422 7 dSP;
5423 7 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 7 7
5424 7 ▶ XPUSHs(sth);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sth); 0 7 7
5425 7 PUTBACK;
5426 7 call_method("finish", G_SCALAR);
5427 7 SPAGAIN;
5428 7 PUTBACK;
5429 }
5430 else {
5431 0 ▶ DBIc_ACTIVE_off(imp_sth);
Branch: 5 branches
BranchTrueFalseTotal
DBIc_ACTIVE_off(imp_sth); 0 0 0
DBIc_ACTIVE_off(imp_sth); 0 0 0
DBIc_ACTIVE_off(imp_sth); 0 0 0
DBIc_ACTIVE_off(imp_sth); 0 0 0
DBIc_ACTIVE_off(imp_sth); 0 0 0
5432 }
5433 }
5434  
5435  
5436 MODULE = DBI PACKAGE = DBI::st
5437  
5438 void
5439 TIEHASH(class, inner_ref)
5440 SV * class
5441 SV * inner_ref
5442 CODE:
5443 0 HV *stash = gv_stashsv(class, GV_ADDWARN); /* a new hash is supplied to us, we just need to bless and apply tie magic */
5444 0 sv_bless(inner_ref, stash);
5445 0 ST(0) = inner_ref;
5446  
5447 MODULE = DBI PACKAGE = DBD::_::common
5448  
5449  
5450 void
5451 DESTROY(h)
5452 SV * h
5453 CODE:
5454 /* DESTROY defined here just to avoid AUTOLOAD */
5455 (void)cv;
5456 (void)h;
5457 580 ST(0) = &PL_sv_undef;
5458  
5459  
5460 void
5461 STORE(h, keysv, valuesv)
5462 SV * h
5463 SV * keysv
5464 SV * valuesv
5465 CODE:
5466 79870 ST(0) = &PL_sv_yes;
5467 79870 ▶ if (!dbih_set_attr_k(h, keysv, 0, valuesv))
Branch: 1 branch
BranchTrueFalseTotal
if (!dbih_set_attr_k(h, keysv, 0, valuesv)) 50 79814 79864
5468 50 ST(0) = &PL_sv_no;
5469 (void)cv;
5470  
5471  
5472 void
5473 FETCH(h, keysv)
5474 SV * h
5475 SV * keysv
5476 PREINIT:
5477 SV *ret;
5478 CODE:
5479 45160 ret = dbih_get_attr_k(h, keysv, 0);
5480 45160 ST(0) = ret;
5481 (void)cv;
5482  
5483 void
5484 DELETE(h, keysv)
5485 SV * h
5486 SV * keysv
5487 PREINIT:
5488 SV *ret;
5489 CODE:
5490 /* only private_* keys can be deleted, for others DELETE acts like FETCH */
5491 /* because the DBI internals rely on certain handle attributes existing */
5492 5 ▶ if (strnEQ(SvPV_nolen(keysv),"private_",8))
Branch: 1 branch
BranchTrueFalseTotal
if (strnEQ(SvPV_nolen(keysv),"private_",8)) 2 3 5
5493 2 ret = hv_delete_ent((HV*)SvRV(h), keysv, 0, 0);
5494 else
5495 3 ret = dbih_get_attr_k(h, keysv, 0);
5496 5 ST(0) = ret;
5497 (void)cv;
5498  
5499  
5500 void
5501 private_data(h)
5502 SV * h
5503 CODE:
5504 0 D_imp_xxh(h);
5505 (void)cv;
5506 0 ST(0) = sv_mortalcopy(DBIc_IMP_DATA(imp_xxh));
5507  
5508  
5509 void
5510 err(h)
5511 SV * h
5512 CODE:
5513 101 D_imp_xxh(h);
5514 101 SV *errsv = DBIc_ERR(imp_xxh);
5515 (void)cv;
5516 101 ST(0) = sv_mortalcopy(errsv);
5517  
5518 void
5519 state(h)
5520 SV * h
5521 CODE:
5522 10 D_imp_xxh(h);
5523 10 SV *state = DBIc_STATE(imp_xxh);
5524 (void)cv;
5525 14 ▶ ST(0) = DBIc_STATE_adjust(imp_xxh, state);
Branch: 3 branches
BranchTrueFalseTotal
ST(0) = DBIc_STATE_adjust(imp_xxh, state); 4 6 10
ST(0) = DBIc_STATE_adjust(imp_xxh, state); 4 0 4
ST(0) = DBIc_STATE_adjust(imp_xxh, state); 4 2 6
5526  
5527 void
5528 errstr(h)
5529 SV * h
5530 CODE:
5531 6691 D_imp_xxh(h);
5532 6691 SV *errstr = DBIc_ERRSTR(imp_xxh);
5533 SV *err;
5534 /* If there's no errstr but there is an err then use err */
5535 (void)cv;
5536 6691 ▶ if (!SvTRUE(errstr) && (err=DBIc_ERR(imp_xxh)) && SvTRUE(err))
Branch: 3 branches
BranchTrueFalseTotal
if (!SvTRUE(errstr) && (err=DBIc_ERR(imp_xxh)) && SvTRUE(err)) 4580 2111 6691
if (!SvTRUE(errstr) && (err=DBIc_ERR(imp_xxh)) && SvTRUE(err)) 4580 0 4580
if (!SvTRUE(errstr) && (err=DBIc_ERR(imp_xxh)) && SvTRUE(err)) 0 4580 4580
5537 0 errstr = err;
5538 6691 ST(0) = sv_mortalcopy(errstr);
5539  
5540  
5541 void
5542 set_err(h, err, errstr=&PL_sv_no, state=&PL_sv_undef, method=&PL_sv_undef, result=Nullsv)
5543 SV * h
5544 SV * err
5545 SV * errstr
5546 SV * state
5547 SV * method
5548 SV * result
5549 PPCODE:
5550 {
5551 9532 D_imp_xxh(h);
5552 SV **sem_svp;
5553 (void)cv;
5554  
5555 9532 ▶ if (DBIc_has(imp_xxh, DBIcf_HandleSetErr) && SvREADONLY(method))
Branch: 2 branches
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_HandleSetErr) && SvREADONLY(method)) 38 9494 9532
if (DBIc_has(imp_xxh, DBIcf_HandleSetErr) && SvREADONLY(method)) 38 0 38
5556 38 method = sv_mortalcopy(method); /* HandleSetErr may want to change it */
5557  
5558 9532 ▶ if (!set_err_sv(h, imp_xxh, err, errstr, state, method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!set_err_sv(h, imp_xxh, err, errstr, state, method)) { 9530 2 9532
5559 /* set_err was canceled by HandleSetErr, */
5560 /* don't set "dbi_set_err_method", return an empty list */
5561 }
5562 else {
5563 /* store provided method name so handler code can find it */
5564 9530 sem_svp = hv_fetchs((HV*)SvRV(h), "dbi_set_err_method", 1);
5565 9530 ▶ if (SvOK(method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(method)) { 6 9524 9530
5566 6 sv_setpv(*sem_svp, SvPV_nolen(method));
5567 }
5568 else
5569 9524 ▶ (void)SvOK_off(*sem_svp);
Branch: 4 branches
BranchTrueFalseTotal
(void)SvOK_off(*sem_svp); 0 9524 9524
(void)SvOK_off(*sem_svp); 0 0 0
(void)SvOK_off(*sem_svp); 0 0 0
(void)SvOK_off(*sem_svp); 0 9524 9524
5570 9530 ▶ XPUSHs( result ? result : &PL_sv_undef );
Branch: 2 branches
BranchTrueFalseTotal
XPUSHs( result ? result : &PL_sv_undef ); 0 9530 9530
XPUSHs( result ? result : &PL_sv_undef ); 4 9526 9530
5571 }
5572 /* We don't check RaiseError and call die here because that must be */
5573 /* done by returning through dispatch and letting the DBI handle it */
5574 }
5575  
5576  
5577 int
5578 trace(h, level=&PL_sv_undef, file=Nullsv)
5579 SV *h
5580 SV *level
5581 SV *file
5582 ALIAS:
5583 debug = 1
5584 CODE:
5585 66 RETVAL = set_trace(h, level, file);
5586 (void)cv; /* Unused variables */
5587 (void)ix;
5588 OUTPUT:
5589 RETVAL
5590  
5591  
5592 void
5593 trace_msg(sv, msg, this_trace=1)
5594 SV *sv
5595 const char *msg
5596 int this_trace
5597 PREINIT:
5598 int current_trace;
5599 PerlIO *pio;
5600 CODE:
5601 {
5602 dMY_CXT;
5603 (void)cv;
5604 27584 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 5522 22062 27584
5605 5522 D_imp_xxh(sv);
5606 5522 current_trace = DBIc_TRACE_LEVEL(imp_xxh);
5607 5522 pio = DBIc_LOGPIO(imp_xxh);
5608 }
5609 else { /* called as a static method */
5610 22062 current_trace = DBIS_TRACE_FLAGS;
5611 22062 pio = DBILOGFP;
5612 }
5613 27584 ▶ if (DBIc_TRACE_MATCHES(this_trace, current_trace)) {
Branch: 2 branches
BranchTrueFalseTotal
if (DBIc_TRACE_MATCHES(this_trace, current_trace)) { 27484 100 27584
if (DBIc_TRACE_MATCHES(this_trace, current_trace)) { 0 27484 27484
5614 100 PerlIO_puts(pio, msg);
5615 100 ST(0) = &PL_sv_yes;
5616 }
5617 else {
5618 27484 ST(0) = &PL_sv_no;
5619 }
5620 }
5621  
5622  
5623 void
5624 rows(h)
5625 SV * h
5626 CODE:
5627 /* fallback esp for $DBI::rows after $drh was last used */
5628 0 ST(0) = sv_2mortal(newSViv(-1));
5629 (void)h;
5630 (void)cv;
5631  
5632  
5633 void
5634 swap_inner_handle(rh1, rh2, allow_reparent=0)
5635 SV * rh1
5636 SV * rh2
5637 IV allow_reparent
5638 CODE:
5639 {
5640 14 D_impdata(imp_xxh1, imp_xxh_t, rh1);
5641 14 D_impdata(imp_xxh2, imp_xxh_t, rh2);
5642 14 SV *h1i = dbih_inner(aTHX_ rh1, "swap_inner_handle");
5643 14 SV *h2i = dbih_inner(aTHX_ rh2, "swap_inner_handle");
5644 14 ▶ SV *h1 = (rh1 == h1i) ? (SV*)DBIc_MY_H(imp_xxh1) : SvRV(rh1);
Branch: 1 branch
BranchTrueFalseTotal
SV *h1 = (rh1 == h1i) ? (SV*)DBIc_MY_H(imp_xxh1) : SvRV(rh1); 14 0 14
5645 14 ▶ SV *h2 = (rh2 == h2i) ? (SV*)DBIc_MY_H(imp_xxh2) : SvRV(rh2);
Branch: 1 branch
BranchTrueFalseTotal
SV *h2 = (rh2 == h2i) ? (SV*)DBIc_MY_H(imp_xxh2) : SvRV(rh2); 0 14 14
5646 (void)cv;
5647  
5648 14 ▶ if (DBIc_TYPE(imp_xxh1) != DBIc_TYPE(imp_xxh2)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp_xxh1) != DBIc_TYPE(imp_xxh2)) { 2 12 14
5649 char buf[99];
5650 6 sprintf(buf, "Can't swap_inner_handle between %sh and %sh",
5651 2 dbih_htype_name(DBIc_TYPE(imp_xxh1)), dbih_htype_name(DBIc_TYPE(imp_xxh2)));
5652 2 DBIh_SET_ERR_CHAR(rh1, imp_xxh1, "1", 1, buf, Nullch, Nullch);
5653 2 XSRETURN_NO;
5654 }
5655 12 ▶ if (!allow_reparent && DBIc_PARENT_COM(imp_xxh1) != DBIc_PARENT_COM(imp_xxh2)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!allow_reparent && DBIc_PARENT_COM(imp_xxh1) != DBIc_PARENT_COM(imp_xxh2)) { 10 2 12
if (!allow_reparent && DBIc_PARENT_COM(imp_xxh1) != DBIc_PARENT_COM(imp_xxh2)) { 2 8 10
5656 2 DBIh_SET_ERR_CHAR(rh1, imp_xxh1, "1", 1,
5657 "Can't swap_inner_handle with handle from different parent",
5658 Nullch, Nullch);
5659 2 XSRETURN_NO;
5660 }
5661  
5662 10 (void)SvREFCNT_inc(h1i);
5663 10 (void)SvREFCNT_inc(h2i);
5664  
5665 10 sv_unmagic(h1, 'P'); /* untie(%$h1) */
5666 10 sv_unmagic(h2, 'P'); /* untie(%$h2) */
5667  
5668 10 sv_magic(h1, h2i, 'P', Nullch, 0); /* tie %$h1, $h2i */
5669 10 DBIc_MY_H(imp_xxh2) = (HV*)h1;
5670  
5671 10 sv_magic(h2, h1i, 'P', Nullch, 0); /* tie %$h2, $h1i */
5672 10 DBIc_MY_H(imp_xxh1) = (HV*)h2;
5673  
5674 10 SvREFCNT_dec(h1i);
5675 10 SvREFCNT_dec(h2i);
5676  
5677 10 ST(0) = &PL_sv_yes;
5678 }
5679  
5680  
5681 MODULE = DBI PACKAGE = DBD::_mem::common
5682  
5683 void
5684 DESTROY(imp_xxh_rv)
5685 SV * imp_xxh_rv
5686 CODE:
5687 /* ignore 'cast increases required alignment' warning */
5688 9685 imp_xxh_t *imp_xxh = (imp_xxh_t*)SvPVX(SvRV(imp_xxh_rv));
5689 9685 DBIc_DBISTATE(imp_xxh)->clearcom(imp_xxh);
5690 (void)cv;
5691  
5692 # end
« dbilogstrip.PL ↑ Summary blib/lib/DBI/ProfileSubs.pm »