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 36115 _cmp_number(const void *val1, const void *val2)
314 {
315 36115 UV first = ((str_uv_sort_pair_t *)val1)->numeric;
316 36115 UV second = ((str_uv_sort_pair_t *)val2)->numeric;
317  
318 36115 ▶ if (first > second)
Branch: 1 branch
BranchTrueFalseTotal
if (first > second) 18282 17833 36115
319 18282 return 1;
320 17833 ▶ if (first < second)
Branch: 1 branch
BranchTrueFalseTotal
if (first < second) 17781 52 17833
321 17781 return -1;
322 /* only likely to reach here if numeric sort forced for non-numeric keys */
323 /* fallback to comparing the key strings */
324 52 return strcmp(
325 52 ((str_uv_sort_pair_t *)val1)->key,
326 52 ((str_uv_sort_pair_t *)val2)->key
327 );
328 }
329  
330 static int
331 55768 _cmp_str (const void *val1, const void *val2)
332 {
333 55768 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 479369 err_hash(pTHX_ imp_xxh_t *imp_xxh)
839 {
840 479369 SV *err_sv = DBIc_ERR(imp_xxh);
841 SV *errstr_sv;
842 479369 I32 hash = 1;
843 479369 ▶ if (SvOK(err_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(err_sv)) { 4744 474625 479369
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 479369 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 907933 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 907933 ▶ if (SvROK(hrv)) /* must at least be a ref */
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(hrv)) /* must at least be a ref */ 888553 19380 907933
1144 888553 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 907927 ▶ if (SvRMAGICAL(sv) && (mg=SvMAGIC(sv))->mg_type == DBI_MAGIC) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvRMAGICAL(sv) && (mg=SvMAGIC(sv))->mg_type == DBI_MAGIC) { 907923 4 907927
if (SvRMAGICAL(sv) && (mg=SvMAGIC(sv))->mg_type == DBI_MAGIC) { 895571 12352 907923
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 907923 ▶ 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 907922 907923
1171 1 *mgp = mg;
1172  
1173 907923 ▶ if (!mg) /* may happen during global destruction */
Branch: 1 branch
BranchTrueFalseTotal
if (!mg) /* may happen during global destruction */ 0 907923 907923
1174 0 return (imp_xxh_t *) 0;
1175  
1176 907923 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  
1929 /* do nothing for undef (NULL) or non-string values */
1930 54 ▶ if (!sv || !SvOK(sv))
Branch: 2 branches
BranchTrueFalseTotal
if (!sv || !SvOK(sv)) 54 0 54
if (!sv || !SvOK(sv)) 2 52 54
1931 2 return -1;
1932  
1933 52 switch(sql_type) {
1934  
1935 4 default:
1936 4 return -2; /* not a recognised SQL TYPE, value unchanged */
1937  
1938 38 case SQL_INTEGER:
1939 /* sv_2iv is liberal, may return SvIV, SvUV, or SvNV */
1940 38 sv_2iv(sv);
1941 /* SvNOK will be set if value is out of range for IV/UV.
1942 * SvIOK should be set but won't if sv is not numeric (in which
1943 * case perl would have warn'd already if -w or warnings are in effect)
1944 */
1945 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
1946 38 break;
1947  
1948 6 case SQL_DOUBLE:
1949 6 sv_2nv(sv);
1950 /* SvNOK should be set but won't if sv is not numeric (in which
1951 * case perl would have warn'd already if -w or warnings are in effect)
1952 */
1953 6 cast_ok = SvNOK(sv);
1954 6 break;
1955  
1956 /* caller would like IV else UV else NV */
1957 /* else no error and sv is untouched */
1958 4 case SQL_NUMERIC:
1959 /* based on the code in perl's toke.c */
1960 STRLEN len;
1961 4 char *p = SvPV(sv, len); /* force stringify, handle magic */
1962 4 uv = 0;
1963 4 grok_flags = grok_number(p, len, &uv);
1964 4 cast_ok = 1;
1965 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
1966 0 ▶ if (uv <= IV_MAX) /* prefer IV over UV */
Branch: 1 branch
BranchTrueFalseTotal
if (uv <= IV_MAX) /* prefer IV over UV */ 0 0 0
1967 0 sv_2iv(sv);
1968 0 else sv_2uv(sv);
1969 }
1970 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
1971 0 ▶ && uv <= IV_MAX
Branch: 1 branch
BranchTrueFalseTotal
&& uv <= IV_MAX 0 0 0
1972 ) {
1973 0 sv_2iv(sv);
1974 }
1975 4 ▶ else if (grok_flags) { /* is numeric */
Branch: 1 branch
BranchTrueFalseTotal
else if (grok_flags) { /* is numeric */ 0 4 4
1976 0 sv_2nv(sv);
1977 }
1978 else
1979 4 cast_ok = 0;
1980 4 break;
1981  
1982 #if 0 /* XXX future possibilities */
1983 case SQL_BIGINT: /* use Math::BigInt if too large for IV/UV */
1984 #endif
1985 }
1986  
1987 48 ▶ if (cast_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (cast_ok) { 28 20 48
1988  
1989 28 ▶ if (flags & DBIstcf_DISCARD_STRING
Branch: 1 branch
BranchTrueFalseTotal
if (flags & DBIstcf_DISCARD_STRING 4 24 28
1990 4 ▶ && SvNIOK(sv) /* we set a numeric value */
Branch: 1 branch
BranchTrueFalseTotal
&& SvNIOK(sv) /* we set a numeric value */ 4 0 4
1991 4 ▶ && SvPVX(sv) /* we have a buffer to discard */
Branch: 1 branch
BranchTrueFalseTotal
&& SvPVX(sv) /* we have a buffer to discard */ 2 2 4
1992 ) {
1993 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
1994 2 sv_force_normal(sv);
1995 2 ▶ if (SvLEN(sv))
Branch: 1 branch
BranchTrueFalseTotal
if (SvLEN(sv)) 2 0 2
1996 2 Safefree(SvPVX(sv));
1997 2 SvPOK_off(sv);
1998 2 SvPV_set(sv, NULL);
1999 2 SvLEN_set(sv, 0);
2000 2 SvCUR_set(sv, 0);
2001 }
2002 }
2003  
2004 48 ▶ if (cast_ok)
Branch: 1 branch
BranchTrueFalseTotal
if (cast_ok) 28 20 48
2005 28 return 2;
2006 20 ▶ else if (flags & DBIstcf_STRICT)
Branch: 1 branch
BranchTrueFalseTotal
else if (flags & DBIstcf_STRICT) 10 10 20
2007 10 return 0;
2008 10 else return 1;
2009 }
2010  
2011  
2012  
2013 /* --- Generic Handle Attributes (for all handle types) --- */
2014  
2015 static int
2016 79870 dbih_set_attr_k(SV *h, SV *keysv, int dbikey, SV *valuesv)
2017 {
2018 dTHX;
2019 dTHR;
2020 79870 D_imp_xxh(h);
2021 STRLEN keylen;
2022 79870 const char *key = SvPV(keysv, keylen);
2023 79870 const int htype = DBIc_TYPE(imp_xxh);
2024 79870 int on = (SvTRUE(valuesv));
2025 79870 int internal = 1; /* DBIh_IN_PERL_DBD(imp_xxh); -- for DBD's in perl */
2026 79870 int cacheit = 0;
2027 79870 int weakenit = 0; /* eg for CachedKids ref */
2028 (void)dbikey;
2029  
2030 79870 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 3) 51 79819 79870
2031 51 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," STORE %s %s => %s\n",
2032 neatsvpv(h,0), neatsvpv(keysv,0), neatsvpv(valuesv,0));
2033  
2034 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
2035 14242 ▶ if (on) {
Branch: 1 branch
BranchTrueFalseTotal
if (on) { 9244 4998 14242
2036 9244 D_imp_sth(h);
2037 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
2038 /* for pure-perl drivers on second and subsequent */
2039 /* execute()'s, else row count keeps rising. */
2040 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
2041 3684 DBIc_ROW_COUNT(imp_sth) = 0;
2042 }
2043 else {
2044 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
2045 }
2046 }
2047 65628 ▶ else if (strEQ(key, "FetchHashKeyName")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "FetchHashKeyName")) { 20 65608 65628
2048 20 ▶ if (htype >= DBIt_ST)
Branch: 1 branch
BranchTrueFalseTotal
if (htype >= DBIt_ST) 0 20 20
2049 0 croak("Can't set FetchHashKeyName for a statement handle, set in parent before prepare()");
2050 20 cacheit = 1; /* just save it */
2051 }
2052 65608 ▶ else if (strEQ(key, "CompatMode")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "CompatMode")) { 12 65596 65608
2053 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
2054 }
2055 65596 ▶ else if (strEQ(key, "Warn")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "Warn")) { 6 65590 65596
2056 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
2057 }
2058 65590 ▶ else if (strEQ(key, "AutoInactiveDestroy")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "AutoInactiveDestroy")) { 12 65578 65590
2059 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
2060 }
2061 65578 ▶ else if (strEQ(key, "InactiveDestroy")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "InactiveDestroy")) { 8 65570 65578
2062 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
2063 }
2064 65570 ▶ else if (strEQ(key, "RootClass")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "RootClass")) { 14 65556 65570
2065 14 cacheit = 1; /* just save it */
2066 }
2067 65556 ▶ else if (strEQ(key, "RowCacheSize")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "RowCacheSize")) { 0 65556 65556
2068 0 cacheit = 0; /* ignore it */
2069 }
2070 65556 ▶ else if (strEQ(key, "Executed")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "Executed")) { 6080 59476 65556
2071 6080 ▶ DBIc_set(imp_xxh, DBIcf_Executed, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh, DBIcf_Executed, on); 0 6080 6080
2072 }
2073 59476 ▶ else if (strEQ(key, "ChopBlanks")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ChopBlanks")) { 10 59466 59476
2074 10 ▶ DBIc_set(imp_xxh, DBIcf_ChopBlanks, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh, DBIcf_ChopBlanks, on); 6 4 10
2075 }
2076 59466 ▶ else if (strEQ(key, "ErrCount")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ErrCount")) { 2 59464 59466
2077 2 DBIc_ErrCount(imp_xxh) = SvUV(valuesv);
2078 }
2079 59464 ▶ else if (strEQ(key, "LongReadLen")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "LongReadLen")) { 0 59464 59464
2080 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
2081 0 croak("Can't set LongReadLen < 0 or > %ld",MAX_LongReadLen);
2082 0 DBIc_LongReadLen(imp_xxh) = SvIV(valuesv);
2083 0 cacheit = 1; /* save it for clone */
2084 }
2085 59464 ▶ else if (strEQ(key, "LongTruncOk")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "LongTruncOk")) { 4 59460 59464
2086 4 ▶ DBIc_set(imp_xxh,DBIcf_LongTruncOk, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_LongTruncOk, on); 0 4 4
2087 }
2088 59460 ▶ else if (strEQ(key, "RaiseError")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "RaiseError")) { 6390 53070 59460
2089 6390 ▶ DBIc_set(imp_xxh,DBIcf_RaiseError, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_RaiseError, on); 6291 99 6390
2090 }
2091 53070 ▶ else if (strEQ(key, "PrintError")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "PrintError")) { 6503 46567 53070
2092 6503 ▶ DBIc_set(imp_xxh,DBIcf_PrintError, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_PrintError, on); 194 6309 6503
2093 }
2094 46567 ▶ else if (strEQ(key, "RaiseWarn")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "RaiseWarn")) { 32 46535 46567
2095 32 ▶ DBIc_set(imp_xxh,DBIcf_RaiseWarn, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_RaiseWarn, on); 14 18 32
2096 }
2097 46535 ▶ else if (strEQ(key, "PrintWarn")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "PrintWarn")) { 6084 40451 46535
2098 6084 ▶ DBIc_set(imp_xxh,DBIcf_PrintWarn, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_PrintWarn, on); 8 6076 6084
2099 }
2100 40451 ▶ else if (strEQ(key, "HandleError")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "HandleError")) { 6 40445 40451
2101 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
2102 0 croak("Can't set %s to '%s'", "HandleError", neatsvpv(valuesv,0));
2103 }
2104 6 ▶ DBIc_set(imp_xxh,DBIcf_HandleError, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_HandleError, on); 4 2 6
2105 6 cacheit = 1; /* child copy setup by dbih_setup_handle() */
2106 }
2107 40445 ▶ else if (strEQ(key, "HandleSetErr")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "HandleSetErr")) { 2 40443 40445
2108 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
2109 0 croak("Can't set %s to '%s'","HandleSetErr",neatsvpv(valuesv,0));
2110 }
2111 2 ▶ DBIc_set(imp_xxh,DBIcf_HandleSetErr, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_HandleSetErr, on); 2 0 2
2112 2 cacheit = 1; /* child copy setup by dbih_setup_handle() */
2113 }
2114 40443 ▶ else if (strEQ(key, "ChildHandles")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ChildHandles")) { 0 40443 40443
2115 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
2116 0 croak("Can't set %s to '%s'", "ChildHandles", neatsvpv(valuesv,0));
2117 }
2118 0 cacheit = 1; /* just save it in the hash */
2119 }
2120 40443 ▶ else if (strEQ(key, "Profile")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "Profile")) { 51 40392 40443
2121 static const char profile_class[] = "DBI::Profile";
2122 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
2123 /* not a hash ref so use DBI::Profile to work out what to do */
2124 dTHR;
2125 28 dSP;
2126 I32 returns;
2127 28 TAINT_NOT; /* the require is presumed innocent till proven guilty */
2128 28 require_pv("DBI/Profile.pm");
2129 28 ▶ if (SvTRUE(ERRSV)) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTRUE(ERRSV)) { 28 0 28
if (SvTRUE(ERRSV)) { 0 28 28
2130 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
2131 0 valuesv = &PL_sv_undef;
2132 }
2133 else {
2134 28 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 28 28
2135 28 ▶ mXPUSHs(newSVpv(profile_class, 0));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpv(profile_class, 0)); 0 28 28
2136 28 ▶ XPUSHs(valuesv);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(valuesv); 0 28 28
2137 28 PUTBACK;
2138 28 returns = call_method("_auto_new", G_SCALAR);
2139 22 ▶ if (returns != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (returns != 1) 0 22 22
2140 0 croak("%s _auto_new", profile_class);
2141 22 SPAGAIN;
2142 22 valuesv = POPs;
2143 22 PUTBACK;
2144 }
2145 22 on = SvTRUE(valuesv); /* in case it returns undef */
2146 }
2147 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
2148 /* not blessed already - so default to DBI::Profile */
2149 HV *stash;
2150 16 require_pv(profile_class);
2151 16 stash = gv_stashpv(profile_class, GV_ADDWARN);
2152 16 sv_bless(valuesv, stash);
2153 }
2154 45 ▶ DBIc_set(imp_xxh,DBIcf_Profile, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_Profile, on); 39 6 45
2155 45 cacheit = 1; /* child copy setup by dbih_setup_handle() */
2156 }
2157 40392 ▶ else if (strEQ(key, "ShowErrorStatement")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ShowErrorStatement")) { 1087 39305 40392
2158 1087 ▶ DBIc_set(imp_xxh,DBIcf_ShowErrorStatement, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_ShowErrorStatement, on); 1081 6 1087
2159 }
2160 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
2161 /* here to allow pure-perl drivers to set MultiThread */
2162 0 ▶ DBIc_set(imp_xxh,DBIcf_MultiThread, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_MultiThread, on); 0 0 0
2163 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
2164 0 warn("MultiThread support not yet implemented in DBI");
2165 }
2166 }
2167 39305 ▶ else if (strEQ(key, "Taint")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "Taint")) { 22 39283 39305
2168 /* 'Taint' is a shortcut for both in and out mode */
2169 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
2170 }
2171 39283 ▶ else if (strEQ(key, "TaintIn")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "TaintIn")) { 8 39275 39283
2172 8 ▶ DBIc_set(imp_xxh,DBIcf_TaintIn, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_TaintIn, on); 2 6 8
2173 }
2174 39275 ▶ else if (strEQ(key, "TaintOut")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "TaintOut")) { 7 39268 39275
2175 7 ▶ DBIc_set(imp_xxh,DBIcf_TaintOut, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_TaintOut, on); 2 5 7
2176 }
2177 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
2178 /* only allow hash refs */
2179 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
2180 ) {
2181 9 cacheit = 1;
2182 9 weakenit = 1;
2183 }
2184 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
2185 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
2186 0 croak("Can't set Callbacks to '%s'",neatsvpv(valuesv,0));
2187 /* see also dbih_setup_handle for ChildCallbacks handling */
2188 29 ▶ DBIc_set(imp_xxh, DBIcf_Callbacks, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh, DBIcf_Callbacks, on); 25 4 29
2189 29 cacheit = 1;
2190 }
2191 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
2192 /* driver should have intercepted this and either handled it */
2193 /* or set valuesv to either the 'magic' on or off value. */
2194 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
2195 0 croak("DBD driver has not implemented the AutoCommit attribute");
2196 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
2197 }
2198 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
2199 2 ▶ DBIc_set(imp_xxh,DBIcf_BegunWork, on);
Branch: 1 branch
BranchTrueFalseTotal
DBIc_set(imp_xxh,DBIcf_BegunWork, on); 2 0 2
2200 }
2201 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
2202 98 set_trace(h, valuesv, Nullsv);
2203 }
2204 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
2205 0 set_trace_file(valuesv);
2206 }
2207 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
2208 7799 D_imp_sth(h);
2209 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
2210 7799 DBIc_NUM_FIELDS(imp_sth) = new_num_fields;
2211 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
2212 1845 dbih_setup_fbav(imp_sth);
2213 }
2214 7799 cacheit = 1;
2215 }
2216 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
2217 5239 D_imp_sth(h);
2218 5239 DBIc_NUM_PARAMS(imp_sth) = SvIV(valuesv);
2219 5239 cacheit = 1;
2220 }
2221 /* these are here due to clone() needing to set attribs through a public api */
2222 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
2223 20536 ▶ || strEQ(key,"ImplementorClass")
Branch: 1 branch
BranchTrueFalseTotal
|| strEQ(key,"ImplementorClass") 20532 4 20536
2224 20532 ▶ || strEQ(key,"ReadOnly")
Branch: 1 branch
BranchTrueFalseTotal
|| strEQ(key,"ReadOnly") 20253 279 20532
2225 20253 ▶ || strEQ(key,"Statement")
Branch: 1 branch
BranchTrueFalseTotal
|| strEQ(key,"Statement") 20249 4 20253
2226 20249 ▶ || strEQ(key,"Username")
Branch: 1 branch
BranchTrueFalseTotal
|| strEQ(key,"Username") 13870 6379 20249
2227 /* these are here for backwards histerical raisons */
2228 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
2229 ) ) {
2230 6670 cacheit = 1;
2231 }
2232 /* deal with: NAME_(uc|lc), NAME_hash, NAME_(uc|lc)_hash */
2233 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
2234 20 ▶ && strnEQ(key, "NAME_", 5)
Branch: 1 branch
BranchTrueFalseTotal
&& strnEQ(key, "NAME_", 5) 5 15 20
2235 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
2236 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
2237 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
2238 )
2239 ) {
2240 5 cacheit = 1;
2241 }
2242 else { /* XXX should really be an event ? */
2243 13874 ▶ if (isUPPER(*key)) {
Branch: 1 branch
BranchTrueFalseTotal
if (isUPPER(*key)) { 2 13872 13874
2244 2 char *msg = "Can't set %s->{%s}: unrecognised attribute name or invalid value%s";
2245 2 char *hint = "";
2246 2 ▶ if (strEQ(key, "NUM_FIELDS"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "NUM_FIELDS")) 0 2 2
2247 0 hint = ", perhaps you meant NUM_OF_FIELDS";
2248 2 warn(msg, neatsvpv(h,0), key, hint);
2249 2 return FALSE; /* don't store it */
2250 }
2251 /* Allow private_* attributes to be stored in the cache. */
2252 /* This is designed to make life easier for people subclassing */
2253 /* the DBI classes and may be of use to simple perl DBD's. */
2254 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
2255 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
2256 0 PerlIO_printf(DBIc_LOGPIO(imp_xxh),"$h->{%s}=%s ignored for invalid driver-specific attribute\n",
2257 neatsvpv(keysv,0), neatsvpv(valuesv,0));
2258 }
2259 48 return FALSE;
2260 }
2261 13824 cacheit = 1;
2262 }
2263 79814 ▶ if (cacheit) {
Branch: 1 branch
BranchTrueFalseTotal
if (cacheit) { 33662 46152 79814
2264 33662 SV *sv_for_cache = newSVsv(valuesv);
2265 33662 (void)hv_store((HV*)SvRV(h), key, keylen, sv_for_cache, 0);
2266 33662 ▶ if (weakenit) {
Branch: 1 branch
BranchTrueFalseTotal
if (weakenit) { 9 33653 33662
2267 #ifdef sv_rvweaken
2268 9 sv_rvweaken(sv_for_cache);
2269 #endif
2270 }
2271 }
2272 79814 return TRUE;
2273 }
2274  
2275  
2276 static SV *
2277 45163 dbih_get_attr_k(SV *h, SV *keysv, int dbikey)
2278 {
2279 dTHX;
2280 dTHR;
2281 45163 D_imp_xxh(h);
2282 STRLEN keylen;
2283 45163 char *key = SvPV(keysv, keylen);
2284 45163 int htype = DBIc_TYPE(imp_xxh);
2285 45163 SV *valuesv = Nullsv;
2286 45163 int cacheit = FALSE;
2287 char *p;
2288 int i;
2289 SV *sv;
2290 SV **svp;
2291 (void)dbikey;
2292  
2293 /* DBI quick_FETCH will service some requests (e.g., cached values) */
2294  
2295 45163 ▶ if (htype == DBIt_ST) {
Branch: 1 branch
BranchTrueFalseTotal
if (htype == DBIt_ST) { 6176 38987 45163
2296 6176 switch (*key) {
2297  
2298 18 case 'D':
2299 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
2300 18 D_imp_from_child(imp_dbh, imp_dbh_t, imp_xxh);
2301 18 valuesv = newRV_inc((SV*)DBIc_MY_H(imp_dbh));
2302 18 cacheit = FALSE; /* else creates ref loop */
2303 }
2304 18 break;
2305  
2306 2306 case 'N':
2307 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
2308 52 valuesv = &PL_sv_undef;
2309 52 break;
2310 }
2311  
2312 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
2313 56 valuesv = &PL_sv_undef;
2314 56 break;
2315 }
2316  
2317 /* deal with: NAME_(uc|lc), NAME_hash, NAME_(uc|lc)_hash */
2318 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
2319 2090 ▶ && strnEQ(key, "NAME_", 5)
Branch: 1 branch
BranchTrueFalseTotal
&& strnEQ(key, "NAME_", 5) 2090 0 2090
2320 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
2321 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
2322 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
2323 )
2324 2090 ) {
2325 2090 D_imp_sth(h);
2326 2090 valuesv = &PL_sv_undef;
2327  
2328 /* fetch from tied outer handle to trigger FETCH magic */
2329 2090 svp = hv_fetchs((HV*)DBIc_MY_H(imp_sth), "NAME", FALSE);
2330 2090 ▶ sv = (svp) ? *svp : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
sv = (svp) ? *svp : &PL_sv_undef; 2090 0 2090
2331 2090 ▶ if (SvGMAGICAL(sv)) /* call FETCH via magic */
Branch: 1 branch
BranchTrueFalseTotal
if (SvGMAGICAL(sv)) /* call FETCH via magic */ 2090 0 2090
2332 2090 mg_get(sv);
2333  
2334 2090 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 2080 10 2090
2335 2080 AV *name_av = (AV*)SvRV(sv);
2336 char *name;
2337 2080 int upcase = (key[5] == 'u');
2338 2080 AV *av = Nullav;
2339 2080 HV *hv = Nullhv;
2340 2080 int num_fields_mismatch = 0;
2341  
2342 2080 ▶ if (strEQ(&key[strlen(key)-5], "_hash"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(&key[strlen(key)-5], "_hash")) 60 2020 2080
2343 60 hv = newHV();
2344 2020 else av = newAV();
2345 2080 i = DBIc_NUM_FIELDS(imp_sth);
2346  
2347 /* catch invalid NUM_FIELDS */
2348 2080 ▶ if (i != AvFILL(name_av)+1) {
Branch: 1 branch
BranchTrueFalseTotal
if (i != AvFILL(name_av)+1) { 0 2080 2080
2349 /* flag as mismatch, except for "-1 and empty" case */
2350 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
2351 0 num_fields_mismatch = 1;
2352 0 i = AvFILL(name_av)+1; /* limit for safe iteration over array */
2353 }
2354  
2355 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
2356 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
2357 " and %ld entries in $h->{NAME}%s\n",
2358 0 neatsvpv(keysv,0), DBIc_NUM_FIELDS(imp_sth), AvFILL(name_av)+1,
2359 (num_fields_mismatch) ? " (possible bug in driver)" : "");
2360 }
2361  
2362 8170 ▶ while (--i >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (--i >= 0) { 6090 2080 8170
2363 6090 sv = newSVsv(AvARRAY(name_av)[i]);
2364 6090 name = SvPV_nolen(sv);
2365 6090 ▶ if (key[5] != 'h') { /* "NAME_hash" */
Branch: 1 branch
BranchTrueFalseTotal
if (key[5] != 'h') { /* "NAME_hash" */ 5990 100 6090
2366 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
2367 #ifdef toUPPER_LC
2368 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
2369 #else
2370 *p = (upcase) ? toUPPER(*p) : toLOWER(*p);
2371 #endif
2372 }
2373 }
2374 6090 ▶ if (av)
Branch: 1 branch
BranchTrueFalseTotal
if (av) 5952 138 6090
2375 5952 av_store(av, i, sv);
2376 else {
2377 138 (void)hv_store(hv, name, SvCUR(sv), newSViv(i), 0);
2378 138 sv_free(sv);
2379 }
2380 }
2381 2080 ▶ valuesv = newRV_noinc( (av ? (SV*)av : (SV*)hv) );
Branch: 1 branch
BranchTrueFalseTotal
valuesv = newRV_noinc( (av ? (SV*)av : (SV*)hv) ); 2020 60 2080
2382 2080 cacheit = TRUE; /* can't change */
2383 }
2384 }
2385 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
2386 51 D_imp_sth(h);
2387 51 IV num_fields = DBIc_NUM_FIELDS(imp_sth);
2388 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
2389 51 ▶ if (num_fields > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (num_fields > 0) 0 51 51
2390 0 cacheit = TRUE; /* can't change once set (XXX except for multiple result sets) */
2391 }
2392 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
2393 57 D_imp_sth(h);
2394 57 valuesv = newSViv(DBIc_NUM_PARAMS(imp_sth));
2395 57 cacheit = TRUE; /* can't change */
2396 }
2397 2198 break;
2398  
2399 152 case 'P':
2400 152 ▶ if (strEQ(key, "PRECISION"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "PRECISION")) 52 100 152
2401 52 valuesv = &PL_sv_undef;
2402 100 ▶ else if (strEQ(key, "ParamValues"))
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ParamValues")) 86 14 100
2403 86 valuesv = &PL_sv_undef;
2404 14 ▶ else if (strEQ(key, "ParamTypes"))
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ParamTypes")) 0 14 14
2405 0 valuesv = &PL_sv_undef;
2406 152 break;
2407  
2408 9 case 'R':
2409 9 ▶ if (strEQ(key, "RowsInCache"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "RowsInCache")) 4 5 9
2410 4 valuesv = &PL_sv_undef;
2411 9 break;
2412  
2413 376 case 'S':
2414 376 ▶ if (strEQ(key, "SCALE"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "SCALE")) 372 4 376
2415 372 valuesv = &PL_sv_undef;
2416 376 break;
2417  
2418 122 case 'T':
2419 122 ▶ if (strEQ(key, "TYPE"))
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "TYPE")) 52 70 122
2420 52 valuesv = &PL_sv_undef;
2421 122 break;
2422 }
2423  
2424 }
2425 else
2426 38987 ▶ if (htype == DBIt_DB) {
Branch: 1 branch
BranchTrueFalseTotal
if (htype == DBIt_DB) { 38868 119 38987
2427 /* this is here but is, sadly, not called because
2428 * not-preloading them into the handle attrib cache caused
2429 * wierdness in t/proxy.t that I never got to the bottom
2430 * of. One day maybe. */
2431 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
2432 2529 D_imp_from_child(imp_dbh, imp_dbh_t, imp_xxh);
2433 2529 valuesv = newRV_inc((SV*)DBIc_MY_H(imp_dbh));
2434 2529 cacheit = FALSE; /* else creates ref loop */
2435 }
2436 }
2437  
2438 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
2439 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
2440 12 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_AutoCommit));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_AutoCommit)); 11 1 12
2441 }
2442 }
2443  
2444 45163 ▶ if (valuesv == Nullsv) {
Branch: 1 branch
BranchTrueFalseTotal
if (valuesv == Nullsv) { 39732 5431 45163
2445 39732 switch (*key) {
2446 11310 case 'A':
2447 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
2448 11263 ▶ valuesv = boolSV(DBIc_ACTIVE(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_ACTIVE(imp_xxh)); 10070 1193 11263
2449 }
2450 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
2451 29 valuesv = newSViv(DBIc_ACTIVE_KIDS(imp_xxh));
2452 }
2453 18 ▶ else if (strEQ(key, "AutoInactiveDestroy")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "AutoInactiveDestroy")) { 18 0 18
2454 18 ▶ valuesv = boolSV(DBIc_AIADESTROY(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_AIADESTROY(imp_xxh)); 8 10 18
2455 }
2456 11310 break;
2457  
2458 6 case 'B':
2459 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
2460 4 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_BegunWork));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_BegunWork)); 1 3 4
2461 }
2462 6 break;
2463  
2464 9194 case 'C':
2465 9194 ▶ if (strEQ(key, "ChildHandles")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "ChildHandles")) { 42 9152 9194
2466 42 svp = hv_fetch((HV*)SvRV(h), key, keylen, FALSE);
2467 /* if something has been stored then return it.
2468 * otherwise return a dummy empty array if weakrefs are
2469 * available, else an undef to indicate that they're not */
2470 42 ▶ if (svp) {
Branch: 1 branch
BranchTrueFalseTotal
if (svp) { 0 42 42
2471 0 valuesv = newSVsv(*svp);
2472 } else {
2473 #ifdef sv_rvweaken
2474 42 valuesv = newRV_noinc((SV*)newAV());
2475 #else
2476 valuesv = &PL_sv_undef;
2477 #endif
2478 }
2479 }
2480 9152 ▶ else if (strEQ(key, "ChopBlanks")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ChopBlanks")) { 3039 6113 9152
2481 3039 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_ChopBlanks));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_ChopBlanks)); 2 3037 3039
2482 }
2483 6113 ▶ else if (strEQ(key, "CachedKids")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "CachedKids")) { 6080 33 6113
2484 6080 valuesv = &PL_sv_undef;
2485 }
2486 33 ▶ else if (strEQ(key, "CompatMode")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "CompatMode")) { 18 15 33
2487 18 ▶ valuesv = boolSV(DBIc_COMPAT(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_COMPAT(imp_xxh)); 10 8 18
2488 }
2489 9194 break;
2490  
2491 6106 case 'E':
2492 6106 ▶ if (strEQ(key, "Executed")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "Executed")) { 6092 14 6106
2493 6092 ▶ valuesv = boolSV(DBIc_is(imp_xxh, DBIcf_Executed));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_is(imp_xxh, DBIcf_Executed)); 3871 2221 6092
2494 }
2495 14 ▶ else if (strEQ(key, "ErrCount")) {
Branch: 1 branch
BranchTrueFalseTotal
else if (strEQ(key, "ErrCount")) { 14 0 14
2496 14 valuesv = newSVuv(DBIc_ErrCount(imp_xxh));
2497 }
2498 6106 break;
2499  
2500 14 case 'I':
2501 14 ▶ if (strEQ(key, "InactiveDestroy")) {
Branch: 1 branch
BranchTrueFalseTotal
if (strEQ(key, "InactiveDestroy")) { 14 0 14
2502 14 ▶ valuesv = boolSV(DBIc_IADESTROY(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_IADESTROY(imp_xxh)); 4 10 14
2503 }
2504 14 break;
2505  
2506 56 case 'K':
2507 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
2508 56 valuesv = newSViv(DBIc_KIDS(imp_xxh));
2509 }
2510 56 break;
2511  
2512 5651 case 'L':
2513 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
2514 2824 valuesv = newSVnv((NV)DBIc_LongReadLen(imp_xxh));
2515 }
2516 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
2517 2827 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_LongTruncOk));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_LongTruncOk)); 0 2827 2827
2518 }
2519 5651 break;
2520  
2521 0 case 'M':
2522 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
2523 0 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_MultiThread));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_MultiThread)); 0 0 0
2524 }
2525 0 break;
2526  
2527 130 case 'P':
2528 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
2529 42 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_PrintError));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_PrintError)); 22 20 42
2530 }
2531 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
2532 10 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_PrintWarn));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_PrintWarn)); 10 0 10
2533 }
2534 130 break;
2535  
2536 2920 case 'R':
2537 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
2538 100 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_RaiseError));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_RaiseError)); 84 16 100
2539 }
2540 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
2541 10 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_RaiseWarn));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_RaiseWarn)); 0 10 10
2542 }
2543 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
2544 2 valuesv = &PL_sv_undef;
2545 }
2546 2920 break;
2547  
2548 16 case 'S':
2549 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
2550 16 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_ShowErrorStatement));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_ShowErrorStatement)); 4 12 16
2551 }
2552 16 break;
2553  
2554 110 case 'T':
2555 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
2556 49 char *type = dbih_htype_name(htype);
2557 49 valuesv = newSVpv(type,0);
2558 49 cacheit = TRUE; /* can't change */
2559 }
2560 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
2561 0 valuesv = newSViv( DBIc_DEBUGIV(imp_xxh) );
2562 }
2563 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
2564 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
2565 DBIc_has(imp_xxh,DBIcf_TaintOut));
2566 }
2567 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
2568 16 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintIn));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintIn)); 4 12 16
2569 }
2570 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
2571 15 ▶ valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintOut));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_has(imp_xxh,DBIcf_TaintOut)); 2 13 15
2572 }
2573 110 break;
2574  
2575 16 case 'W':
2576 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
2577 16 ▶ valuesv = boolSV(DBIc_WARN(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
valuesv = boolSV(DBIc_WARN(imp_xxh)); 16 0 16
2578 }
2579 16 break;
2580 }
2581 }
2582  
2583 /* finally check the actual hash */
2584 45163 ▶ if (valuesv == Nullsv) {
Branch: 1 branch
BranchTrueFalseTotal
if (valuesv == Nullsv) { 7106 38057 45163
2585 7106 valuesv = &PL_sv_undef;
2586 7106 cacheit = 0;
2587 7106 svp = hv_fetch((HV*)SvRV(h), key, keylen, FALSE);
2588 7106 ▶ if (svp)
Branch: 1 branch
BranchTrueFalseTotal
if (svp) 5 7101 7106
2589 5 valuesv = newSVsv(*svp); /* take copy to mortalize */
2590 else /* warn unless it's known attribute name */
2591 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
2592 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
2593 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
2594 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
2595 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
2596 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
2597 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
2598 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
2599 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
2600 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
2601 4189 ▶ || !isUPPER(*key) /* dbd_*, private_* etc */
Branch: 1 branch
BranchTrueFalseTotal
|| !isUPPER(*key) /* dbd_*, private_* etc */ 2 4187 4189
2602 ))
2603 2 warn("Can't get %s->{%s}: unrecognised attribute name",neatsvpv(h,0),key);
2604 }
2605  
2606 45163 ▶ if (cacheit) {
Branch: 1 branch
BranchTrueFalseTotal
if (cacheit) { 2186 42977 45163
2607 2186 (void)hv_store((HV*)SvRV(h), key, keylen, newSVsv(valuesv), 0);
2608 }
2609 45163 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 3) 34 45129 45163
2610 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
2611 neatsvpv(keysv,0), neatsvpv(valuesv,0), cacheit?" (cached)":"");
2612 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
2613 37460 return valuesv; /* no need to mortalize yes or no */
2614 7703 return sv_2mortal(valuesv);
2615 }
2616  
2617  
2618  
2619 /* -------------------------------------------------------------------- */
2620 /* Functions implementing Error and Event Handling. */
2621  
2622  
2623 static SV *
2624 0 dbih_event(SV *hrv, const char *evtype, SV *a1, SV *a2)
2625 {
2626 dTHX;
2627 /* We arrive here via DBIh_EVENT* macros (see DBIXS.h) called from */
2628 /* DBD driver C code OR $h->event() method (in DBD::_::common) */
2629 /* XXX VERY OLD INTERFACE/CONCEPT MAY GO SOON */
2630 /* OR MAY EVOLVE INTO A WAY TO HANDLE 'SUCCESS_WITH_INFO'/'WARNINGS' from db */
2631 (void)hrv;
2632 (void)evtype;
2633 (void)a1;
2634 (void)a2;
2635 0 return &PL_sv_undef;
2636 }
2637  
2638  
2639 /* ----------------------------------------------------------------- */
2640  
2641  
2642 STATIC I32
2643 3287 dbi_dopoptosub_at(PERL_CONTEXT *cxstk, I32 startingblock)
2644 {
2645 dTHX;
2646 I32 i;
2647 register PERL_CONTEXT *cx;
2648 4239 ▶ for (i = startingblock; i >= 0; i--) {
Branch: 1 branch
BranchTrueFalseTotal
for (i = startingblock; i >= 0; i--) { 4080 159 4239
2649 4080 cx = &cxstk[i];
2650 4080 ▶ switch (CxTYPE(cx)) {
Branch: 1 branch
BranchTrueFalseTotal
switch (CxTYPE(cx)) { 952 3128 4080
2651 952 default:
2652 952 continue;
2653 3128 case CXt_EVAL:
2654 case CXt_SUB:
2655 #ifdef CXt_FORMAT
2656 case CXt_FORMAT:
2657 #endif
2658 DEBUG_l( Perl_deb(aTHX_ "(Found sub #%ld)\n", (long)i));
2659 3128 return i;
2660 }
2661 }
2662 159 return i;
2663 }
2664  
2665  
2666 static COP *
2667 312 dbi_caller_cop()
2668 {
2669 dTHX;
2670 register I32 cxix;
2671 register PERL_CONTEXT *cx;
2672 312 register PERL_CONTEXT *ccstack = cxstack;
2673 312 PERL_SI *top_si = PL_curstackinfo;
2674 char *stashname;
2675  
2676 1740 for ( cxix = dbi_dopoptosub_at(ccstack, cxstack_ix) ;; cxix = dbi_dopoptosub_at(ccstack, cxix - 1)) {
2677 /* we may be in a higher stacklevel, so dig down deeper */
2678 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
2679 119 top_si = top_si->si_prev;
2680 119 ccstack = top_si->si_cxstack;
2681 119 cxix = dbi_dopoptosub_at(ccstack, top_si->si_cxix);
2682 }
2683 1740 ▶ if (cxix < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (cxix < 0) { 15 1725 1740
2684 15 break;
2685 }
2686 /* skip the automatic calls to &DB::sub, as perl's pp_caller does */
2687 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
2688 0 continue;
2689 1725 cx = &ccstack[cxix];
2690 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
2691 1725 ▶ if (!stashname)
Branch: 1 branch
BranchTrueFalseTotal
if (!stashname) 0 1725 1725
2692 0 continue;
2693 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
2694 1428 ▶ && strchr("DI", stashname[2])
Branch: 1 branch
BranchTrueFalseTotal
&& strchr("DI", stashname[2]) 1428 0 1428
2695 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
2696 {
2697 297 return cx->blk_oldcop;
2698 }
2699 1428 cxix = dbi_dopoptosub_at(ccstack, cxix - 1);
2700 }
2701 15 return NULL;
2702 }
2703  
2704 static void
2705 664 dbi_caller_string(SV *buf, COP *cop, char *prefix, int show_line, int show_path)
2706 {
2707 dTHX;
2708 STRLEN len;
2709 664 long line = CopLINE(cop);
2710 664 char *file = SvPV(GvSV(CopFILEGV(cop)), len);
2711 664 ▶ if (!show_path) {
Branch: 1 branch
BranchTrueFalseTotal
if (!show_path) { 192 472 664
2712 char *sep;
2713 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
2714 192 file = sep+1;
2715 }
2716 664 ▶ if (show_line) {
Branch: 1 branch
BranchTrueFalseTotal
if (show_line) { 652 12 664
2717 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
2718 }
2719 else {
2720 12 ▶ sv_catpvf(buf, "%s%s", (prefix) ? prefix : "", file);
Branch: 1 branch
BranchTrueFalseTotal
sv_catpvf(buf, "%s%s", (prefix) ? prefix : "", file); 12 0 12
2721 }
2722 664 }
2723  
2724 static char *
2725 369 log_where(SV *buf, int append, char *prefix, char *suffix, int show_line, int show_caller, int show_path)
2726 {
2727 dTHX;
2728 dTHR;
2729 369 ▶ if (!buf)
Branch: 1 branch
BranchTrueFalseTotal
if (!buf) 369 0 369
2730 369 buf = sv_2mortal(newSVpvs(""));
2731 0 ▶ else if (!append)
Branch: 1 branch
BranchTrueFalseTotal
else if (!append) 0 0 0
2732 0 sv_setpv(buf,"");
2733 369 ▶ if (CopLINE(PL_curcop)) {
Branch: 1 branch
BranchTrueFalseTotal
if (CopLINE(PL_curcop)) { 367 2 369
2734 COP *cop;
2735 367 dbi_caller_string(buf, PL_curcop, prefix, show_line, show_path);
2736 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
2737 297 SV *via = sv_2mortal(newSVpvs(""));
2738 297 dbi_caller_string(via, cop, prefix, show_line, show_path);
2739 297 sv_catpvf(buf, " via %s", SvPV_nolen(via));
2740 }
2741 }
2742 369 ▶ if (PL_dirty)
Branch: 1 branch
BranchTrueFalseTotal
if (PL_dirty) 0 369 369
2743 0 sv_catpvf(buf, " during global destruction");
2744 369 ▶ if (suffix)
Branch: 1 branch
BranchTrueFalseTotal
if (suffix) 369 0 369
2745 369 sv_catpv(buf, suffix);
2746 369 return SvPVX(buf);
2747 }
2748  
2749  
2750 static void
2751 13324 clear_cached_kids(pTHX_ SV *h, imp_xxh_t *imp_xxh, const char *meth_name, int trace_level)
2752 {
2753 13324 ▶ if (DBIc_TYPE(imp_xxh) <= DBIt_DB) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TYPE(imp_xxh) <= DBIt_DB) { 7296 6028 13324
2754 7296 SV **svp = hv_fetchs((HV*)SvRV(h), "CachedKids", 0);
2755 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
2756 264 HV *hv = (HV*)SvRV(*svp);
2757 264 ▶ if (HvKEYS(hv)) {
Branch: 2 branches
BranchTrueFalseTotal
if (HvKEYS(hv)) { 0 264 264
if (HvKEYS(hv)) { 132 132 264
2758 132 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) > trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) > trace_level) 0 132 132
2759 0 trace_level = DBIc_TRACE_LEVEL(imp_xxh);
2760 132 ▶ if (trace_level >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 2) { 0 132 132
2761 0 PerlIO_printf(DBIc_LOGPIO(imp_xxh)," >> %s %s clearing %d CachedKids\n",
2762 0 ▶ meth_name, neatsvpv(h,0), (int)HvKEYS(hv));
Branch: 1 branch
BranchTrueFalseTotal
meth_name, neatsvpv(h,0), (int)HvKEYS(hv)); 0 0 0
2763 0 PerlIO_flush(DBIc_LOGPIO(imp_xxh));
2764 }
2765 /* This will probably recurse through dispatch to DESTROY the kids */
2766 /* For drh we should probably explicitly do dbh disconnects */
2767 132 hv_clear(hv);
2768 }
2769 }
2770 }
2771 13324 }
2772  
2773  
2774 static NV
2775 833712 dbi_time() {
2776 # ifdef HAS_GETTIMEOFDAY
2777 # ifdef PERL_IMPLICIT_SYS
2778 dTHX;
2779 # endif
2780 struct timeval when;
2781 833712 gettimeofday(&when, (struct timezone *) 0);
2782 833712 return when.tv_sec + (when.tv_usec / 1000000.0);
2783 # else /* per-second is almost useless */
2784 # ifdef _WIN32 /* use _ftime() on Win32 (MS Visual C++ 6.0) */
2785 # if defined(__BORLANDC__)
2786 # define _timeb timeb
2787 # define _ftime ftime
2788 # endif
2789 struct _timeb when;
2790 _ftime( &when );
2791 return when.time + (when.millitm / 1000.0);
2792 # else
2793 return time(NULL);
2794 # endif
2795 # endif
2796 }
2797  
2798  
2799 static SV *
2800 45075 _profile_next_node(SV *node, const char *name)
2801 {
2802 /* step one level down profile Data tree and auto-vivify if required */
2803 dTHX;
2804 45075 SV *orig_node = node;
2805 45075 ▶ if (SvROK(node))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(node)) 44823 252 45075
2806 44823 node = SvRV(node);
2807 45075 ▶ if (SvTYPE(node) != SVt_PVHV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(node) != SVt_PVHV) { 252 44823 45075
2808 252 HV *hv = newHV();
2809 252 ▶ if (SvOK(node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(node)) { 0 252 252
2810 0 char *key = "(demoted)";
2811 0 warn("Profile data element %s replaced with new hash ref (for %s) and original value stored with key '%s'",
2812 neatsvpv(orig_node,0), name, key);
2813 0 (void)hv_store(hv, key, strlen(key), SvREFCNT_inc(orig_node), 0);
2814 }
2815 252 sv_setsv(node, newRV_noinc((SV*)hv));
2816 252 node = (SV*)hv;
2817 }
2818 45075 node = *hv_fetch((HV*)node, name, strlen(name), 1);
2819 45075 return node;
2820 }
2821  
2822  
2823 static SV*
2824 61077 dbi_profile(SV *h, imp_xxh_t *imp_xxh, SV *statement_sv, SV *method, NV t1, NV t2)
2825 {
2826 #define DBIprof_MAX_PATH_ELEM 100
2827 #define DBIprof_COUNT 0
2828 #define DBIprof_TOTAL_TIME 1
2829 #define DBIprof_FIRST_TIME 2
2830 #define DBIprof_MIN_TIME 3
2831 #define DBIprof_MAX_TIME 4
2832 #define DBIprof_FIRST_CALLED 5
2833 #define DBIprof_LAST_CALLED 6
2834 #define DBIprof_max_index 6
2835 dTHX;
2836 61077 NV ti = t2 - t1;
2837 61077 int src_idx = 0;
2838 61077 HV *dbh_outer_hv = NULL;
2839 61077 HV *dbh_inner_hv = NULL;
2840 char *statement_pv;
2841 char *method_pv;
2842 SV *profile;
2843 SV *tmp;
2844 SV *dest_node;
2845 AV *av;
2846 HV *h_hv;
2847  
2848 61077 const int call_depth = DBIc_CALL_DEPTH(imp_xxh);
2849 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
2850 /* Only count calls originating from the application code */
2851 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
2852 44221 return &PL_sv_undef;
2853  
2854 16856 ▶ if (!DBIc_has(imp_xxh, DBIcf_Profile))
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIc_has(imp_xxh, DBIcf_Profile)) 3 16853 16856
2855 3 return &PL_sv_undef;
2856  
2857 15 method_pv = (SvTYPE(method)==SVt_PVCV) ? GvNAME(CvGV(method))
2858 33706 ▶ : isGV(method) ? GvNAME(method)
Branch: 1 branch
BranchTrueFalseTotal
: isGV(method) ? GvNAME(method) 15 16838 16853
2859 16844 ▶ : SvOK(method) ? SvPV_nolen(method)
Branch: 1 branch
BranchTrueFalseTotal
: SvOK(method) ? SvPV_nolen(method) 16832 6 16838
2860 6 ▶ : "";
Branch: 1 branch
BranchTrueFalseTotal
: ""; 6 0 6
2861  
2862 /* we don't profile DESTROY during global destruction */
2863 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
2864 4 return &PL_sv_undef;
2865  
2866 16849 h_hv = (HV*)SvRV(dbih_inner(aTHX_ h, "dbi_profile"));
2867  
2868 16849 profile = *hv_fetchs(h_hv, "Profile", 1);
2869 16849 ▶ if (profile && SvMAGICAL(profile))
Branch: 2 branches
BranchTrueFalseTotal
if (profile && SvMAGICAL(profile)) 16849 0 16849
if (profile && SvMAGICAL(profile)) 0 16849 16849
2870 0 mg_get(profile); /* FETCH */
2871 16849 ▶ if (!profile || !SvROK(profile)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!profile || !SvROK(profile)) { 16849 0 16849
if (!profile || !SvROK(profile)) { 1 16848 16849
2872 1 DBIc_set(imp_xxh, DBIcf_Profile, 0); /* disable */
2873 1 ▶ if (!PL_dirty) {
Branch: 1 branch
BranchTrueFalseTotal
if (!PL_dirty) { 0 1 1
2874 0 ▶ if (!profile)
Branch: 1 branch
BranchTrueFalseTotal
if (!profile) 0 0 0
2875 0 warn("Profile attribute does not exist");
2876 0 ▶ else if (SvOK(profile))
Branch: 1 branch
BranchTrueFalseTotal
else if (SvOK(profile)) 0 0 0
2877 0 warn("Profile attribute isn't a hash ref (%s,%ld)", neatsvpv(profile,0), (long)SvTYPE(profile));
2878 }
2879 1 return &PL_sv_undef;
2880 }
2881  
2882 /* statement_sv: undef = use $h->{Statement}, "" (&sv_no) = use empty string */
2883  
2884 16848 ▶ if (!SvOK(statement_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(statement_sv)) { 16584 264 16848
2885 16584 SV **psv = hv_fetchs(h_hv, "Statement", 0);
2886 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
2887 }
2888 16848 statement_pv = SvPV_nolen(statement_sv);
2889  
2890 16848 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 4)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 4) 0 16848 16848
2891 0 PerlIO_printf(DBIc_LOGPIO(imp_xxh), " dbi_profile +%" NVff "s %s %s\n",
2892 ti, method_pv, neatsvpv(statement_sv,0));
2893  
2894 16848 dest_node = _profile_next_node(profile, "Data");
2895  
2896 16848 tmp = *hv_fetchs((HV*)SvRV(profile), "Path", 1);
2897 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
2898 int len;
2899 16848 av = (AV*)SvRV(tmp);
2900 16848 len = av_len(av); /* -1=empty, 0=one element */
2901  
2902 45038 ▶ while ( src_idx <= len ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( src_idx <= len ) { 28255 16783 45038
2903 28255 SV *pathsv = AvARRAY(av)[src_idx++];
2904  
2905 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
2906 /* call sub, use returned list of values as path */
2907 /* returning a ref to undef vetos this profile data */
2908 164 dSP;
2909 I32 ax;
2910 164 SV *code_sv = SvRV(pathsv);
2911 I32 items;
2912 I32 item_idx;
2913 164 ▶ EXTEND(SP, 4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 4); 0 164 164
2914 164 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 164 164
2915 164 PUSHs(h); /* push inner handle, then others params */
2916 164 mPUSHs(newSVpv(method_pv, 0));
2917 164 PUTBACK;
2918 164 SAVE_DEFSV; /* local($_) = $statement */
2919 164 DEFSV_set(statement_sv);
2920 164 items = call_sv(code_sv, G_LIST);
2921 164 SPAGAIN;
2922 164 SP -= items ;
2923 164 ax = (SP - PL_stack_base) + 1 ;
2924 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
2925 201 SV *item_sv = ST(item_idx);
2926 201 ▶ if (SvROK(item_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(item_sv)) { 65 136 201
2927 65 ▶ if (!SvOK(SvRV(item_sv)))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(SvRV(item_sv))) 65 0 65
2928 65 items = -2; /* flag that we're rejecting this profile data */
2929 else /* other refs reserved */
2930 0 warn("Ignored ref returned by code ref in Profile Path");
2931 65 break;
2932 }
2933 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
2934 }
2935 164 PUTBACK;
2936 164 ▶ if (items == -2) /* this profile data was vetoed */
Branch: 1 branch
BranchTrueFalseTotal
if (items == -2) /* this profile data was vetoed */ 65 99 164
2937 65 return &PL_sv_undef;
2938 }
2939 28091 ▶ else if (SvROK(pathsv)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvROK(pathsv)) { 22 28069 28091
2940 /* only meant for refs to scalars currently */
2941 22 const char *p = SvPV_nolen(SvRV(pathsv));
2942 22 dest_node = _profile_next_node(dest_node, p);
2943 }
2944 28069 ▶ else if (SvOK(pathsv)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (SvOK(pathsv)) { 28069 0 28069
2945 STRLEN len;
2946 28069 const char *p = SvPV(pathsv,len);
2947 28069 ▶ if (p[0] == '!') { /* special cases */
Branch: 1 branch
BranchTrueFalseTotal
if (p[0] == '!') { /* special cases */ 27899 170 28069
2948 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
2949 16638 dest_node = _profile_next_node(dest_node, statement_pv);
2950 }
2951 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
2952 11229 dest_node = _profile_next_node(dest_node, method_pv);
2953 }
2954 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
2955 0 ▶ if (SvTYPE(method) == SVt_PVCV) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(method) == SVt_PVCV) { 0 0 0
2956 0 p = SvPV_nolen((SV*)CvGV(method));
2957 }
2958 0 ▶ else if (isGV(method)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (isGV(method)) { 0 0 0
2959 /* just using SvPV_nolen(method) sometimes causes an error: */
2960 /* "Can't coerce GLOB to string" so we use gv_efullname() */
2961 0 SV *tmpsv = sv_2mortal(newSVpvs(""));
2962 0 gv_efullname4(tmpsv, (GV*)method, "", TRUE);
2963 0 p = SvPV_nolen(tmpsv);
2964 0 ▶ if (*p == '*') ++p; /* skip past leading '*' glob sigil */
Branch: 1 branch
BranchTrueFalseTotal
if (*p == '*') ++p; /* skip past leading '*' glob sigil */ 0 0 0
2965 }
2966 else {
2967 0 p = method_pv;
2968 }
2969 0 dest_node = _profile_next_node(dest_node, p);
2970 }
2971 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
2972 4 dest_node = _profile_next_node(dest_node, log_where(0, 0, "", "", 0, 0, 0));
2973 }
2974 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
2975 4 dest_node = _profile_next_node(dest_node, log_where(0, 0, "", "", 0, 1, 0));
2976 }
2977 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
2978 4 dest_node = _profile_next_node(dest_node, log_where(0, 0, "", "", 1, 0, 0));
2979 }
2980 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
2981 12 dest_node = _profile_next_node(dest_node, log_where(0, 0, "", "", 1, 1, 0));
2982 }
2983 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
2984 char timebuf[20];
2985 8 int factor = 1;
2986 8 ▶ if (p[5] == '~') {
Branch: 1 branch
BranchTrueFalseTotal
if (p[5] == '~') { 4 4 8
2987 4 factor = atoi(&p[6]);
2988 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
2989 0 factor = 3600;
2990 }
2991 8 sprintf(timebuf, "%ld", ((long)(dbi_time()/factor))*factor);
2992 8 dest_node = _profile_next_node(dest_node, timebuf);
2993 }
2994 else {
2995 0 warn("Unknown ! element in DBI::Profile Path: %s", p);
2996 0 dest_node = _profile_next_node(dest_node, p);
2997 }
2998 }
2999 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
3000 SV **attr_svp;
3001 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
3002 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
3003 22 dbh_outer_hv = DBIc_MY_H(imp_dbh);
3004 22 ▶ if (SvTYPE(dbh_outer_hv) != SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(dbh_outer_hv) != SVt_PVHV) 0 22 22
3005 0 return &PL_sv_undef; /* presumably global destruction - bail */
3006 22 dbh_inner_hv = (HV*)SvRV(dbih_inner(aTHX_ (SV*)dbh_outer_hv, "profile"));
3007 22 ▶ if (SvTYPE(dbh_inner_hv) != SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(dbh_inner_hv) != SVt_PVHV) 0 22 22
3008 0 return &PL_sv_undef; /* presumably global destruction - bail */
3009 }
3010 /* fetch from inner first, then outer if key doesn't exist */
3011 /* (yes, this is an evil premature optimization) */
3012 22 p += 1; len -= 2; /* ignore the braces */
3013 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
3014 /* try outer (tied) hash - for things like AutoCommit */
3015 /* (will always return something even for unknowns) */
3016 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
3017 6 ▶ if (SvGMAGICAL(*attr_svp))
Branch: 1 branch
BranchTrueFalseTotal
if (SvGMAGICAL(*attr_svp)) 6 0 6
3018 6 mg_get(*attr_svp); /* FETCH */
3019 }
3020 }
3021 22 ▶ if (!attr_svp)
Branch: 1 branch
BranchTrueFalseTotal
if (!attr_svp) 0 22 22
3022 0 p -= 1; /* unignore the braces */
3023 22 ▶ else if (!SvOK(*attr_svp))
Branch: 1 branch
BranchTrueFalseTotal
else if (!SvOK(*attr_svp)) 6 16 22
3024 6 p = "";
3025 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
3026 0 p = "0"; /* catch &sv_no style special case */
3027 else
3028 32 p = SvPV_nolen(*attr_svp);
3029 22 dest_node = _profile_next_node(dest_node, p);
3030 }
3031 else {
3032 148 dest_node = _profile_next_node(dest_node, p);
3033 }
3034 }
3035 /* else undef, so ignore */
3036 }
3037 }
3038 else { /* a bad Path value is treated as a Path of just Statement */
3039 0 dest_node = _profile_next_node(dest_node, statement_pv);
3040 }
3041  
3042  
3043 16783 ▶ if (!SvOK(dest_node)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(dest_node)) { 412 16371 16783
3044 412 av = newAV();
3045 412 sv_setsv(dest_node, newRV_noinc((SV*)av));
3046 412 av_store(av, DBIprof_COUNT, newSViv(1));
3047 412 av_store(av, DBIprof_TOTAL_TIME, newSVnv(ti));
3048 412 av_store(av, DBIprof_FIRST_TIME, newSVnv(ti));
3049 412 av_store(av, DBIprof_MIN_TIME, newSVnv(ti));
3050 412 av_store(av, DBIprof_MAX_TIME, newSVnv(ti));
3051 412 av_store(av, DBIprof_FIRST_CALLED, newSVnv(t1));
3052 412 av_store(av, DBIprof_LAST_CALLED, newSVnv(t1));
3053 }
3054 else {
3055 16371 tmp = dest_node;
3056 16371 ▶ if (SvROK(tmp))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(tmp)) 16371 0 16371
3057 16371 tmp = SvRV(tmp);
3058 16371 ▶ if (SvTYPE(tmp) != SVt_PVAV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(tmp) != SVt_PVAV) 0 16371 16371
3059 0 croak("Invalid Profile data leaf element: %s (type %ld)",
3060 neatsvpv(tmp,0), (long)SvTYPE(tmp));
3061 16371 av = (AV*)tmp;
3062 16371 sv_inc( *av_fetch(av, DBIprof_COUNT, 1));
3063 16371 tmp = *av_fetch(av, DBIprof_TOTAL_TIME, 1);
3064 16371 sv_setnv(tmp, SvNV(tmp) + ti);
3065 16371 tmp = *av_fetch(av, DBIprof_MIN_TIME, 1);
3066 16371 ▶ if (ti < SvNV(tmp)) sv_setnv(tmp, ti);
Branch: 1 branch
BranchTrueFalseTotal
if (ti < SvNV(tmp)) sv_setnv(tmp, ti); 569 15802 16371
3067 16371 tmp = *av_fetch(av, DBIprof_MAX_TIME, 1);
3068 16371 ▶ if (ti > SvNV(tmp)) sv_setnv(tmp, ti);
Branch: 1 branch
BranchTrueFalseTotal
if (ti > SvNV(tmp)) sv_setnv(tmp, ti); 311 16060 16371
3069 16371 sv_setnv( *av_fetch(av, DBIprof_LAST_CALLED, 1), t1);
3070 }
3071 16783 return dest_node; /* use with caution - copy first, ie sv_mortalcopy() */
3072 }
3073  
3074  
3075 static void
3076 374 dbi_profile_merge_nodes(SV *dest, SV *increment)
3077 {
3078 dTHX;
3079 AV *d_av, *i_av;
3080 SV *tmp;
3081 SV *tmp2;
3082 NV i_nv;
3083 int i_is_earlier;
3084  
3085 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
3086 0 croak("dbi_profile_merge_nodes(%s, ...) requires array ref", neatsvpv(dest,0));
3087 374 d_av = (AV*)SvRV(dest);
3088  
3089 374 ▶ if (av_len(d_av) < DBIprof_max_index) {
Branch: 1 branch
BranchTrueFalseTotal
if (av_len(d_av) < DBIprof_max_index) { 48 326 374
3090 int idx;
3091 48 av_extend(d_av, DBIprof_max_index);
3092 384 ▶ for(idx=0; idx<=DBIprof_max_index; ++idx) {
Branch: 1 branch
BranchTrueFalseTotal
for(idx=0; idx<=DBIprof_max_index; ++idx) { 336 48 384
3093 336 tmp = *av_fetch(d_av, idx, 1);
3094 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
3095 240 sv_setnv(tmp, 0.0); /* leave 'min' values as undef */
3096 }
3097 }
3098  
3099 374 ▶ if (!SvOK(increment))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(increment)) 0 374 374
3100 0 return;
3101  
3102 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
3103 2 HV *hv = (HV*)SvRV(increment);
3104 char *key;
3105 2 I32 keylen = 0;
3106 2 hv_iterinit(hv);
3107 6 ▶ while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) { 4 2 6
3108 4 dbi_profile_merge_nodes(dest, tmp);
3109 };
3110 2 return;
3111 }
3112  
3113 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
3114 0 croak("dbi_profile_merge_nodes: increment %s not an array or hash ref", neatsvpv(increment,0));
3115 372 i_av = (AV*)SvRV(increment);
3116  
3117 372 tmp = *av_fetch(d_av, DBIprof_COUNT, 1);
3118 372 tmp2 = *av_fetch(i_av, DBIprof_COUNT, 1);
3119 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
3120 0 sv_setiv( tmp, SvIV(tmp) + SvIV(tmp2) );
3121 else
3122 372 sv_setnv( tmp, SvNV(tmp) + SvNV(tmp2) );
3123  
3124 372 tmp = *av_fetch(d_av, DBIprof_TOTAL_TIME, 1);
3125 372 sv_setnv( tmp, SvNV(tmp) + SvNV( *av_fetch(i_av, DBIprof_TOTAL_TIME, 1)) );
3126  
3127 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_MIN_TIME, 1));
3128 372 tmp = *av_fetch(d_av, DBIprof_MIN_TIME, 1);
3129 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); 42 282 324
3130  
3131 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_MAX_TIME, 1));
3132 372 tmp = *av_fetch(d_av, DBIprof_MAX_TIME, 1);
3133 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); 57 315 372
3134  
3135 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_FIRST_CALLED, 1));
3136 372 tmp = *av_fetch(d_av, DBIprof_FIRST_CALLED, 1);
3137 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
3138 372 ▶ if (i_is_earlier)
Branch: 1 branch
BranchTrueFalseTotal
if (i_is_earlier) 79 293 372
3139 79 sv_setnv(tmp, i_nv);
3140  
3141 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_FIRST_TIME, 1));
3142 372 tmp = *av_fetch(d_av, DBIprof_FIRST_TIME, 1);
3143 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
3144 /* If the increment has an earlier DBIprof_FIRST_CALLED
3145 then we set the DBIprof_FIRST_TIME from the increment */
3146 79 sv_setnv(tmp, i_nv);
3147 }
3148  
3149 372 i_nv = SvNV(*av_fetch(i_av, DBIprof_LAST_CALLED, 1));
3150 372 tmp = *av_fetch(d_av, DBIprof_LAST_CALLED, 1);
3151 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
3152 }
3153  
3154  
3155 /* ----------------------------------------------------------------- */
3156 /* --- The DBI dispatcher. The heart of the perl DBI. --- */
3157  
3158 XS(XS_DBI_dispatch); /* prototype to pass -Wmissing-prototypes */
3159 560425 XS(XS_DBI_dispatch)
3160 {
3161 560425 dXSARGS;
3162 560425 dORIGMARK;
3163 dMY_CXT;
3164  
3165 560425 SV *h = ST(0); /* the DBI handle we are working with */
3166 560425 SV *st1 = ST(1); /* used in debugging */
3167 560425 SV *st2 = ST(2); /* used in debugging */
3168 560425 SV *orig_h = h;
3169 SV *err_sv;
3170 SV **tmp_svp;
3171 560425 SV **hook_svp = 0;
3172 MAGIC *mg;
3173 560425 I32 gimme = GIMME_V;
3174 560425 I32 trace_flags = DBIS->debug; /* local copy may change during dispatch */
3175 560425 I32 trace_level = (trace_flags & DBIc_TRACE_LEVEL_MASK);
3176 int is_DESTROY;
3177 meth_types meth_type;
3178 560425 int is_unrelated_to_Statement = 0;
3179 560425 U32 keep_error = FALSE;
3180 560425 UV ErrCount = UV_MAX;
3181 int i, outitems;
3182 int call_depth;
3183 int is_nested_call;
3184 560425 NV profile_t1 = 0.0;
3185 560425 int is_orig_method_name = 1;
3186  
3187 560425 const char *meth_name = GvNAME(CvGV(cv));
3188 560425 dbi_ima_t *ima = (dbi_ima_t*)CvXSUBANY(cv).any_ptr;
3189 U32 ima_flags;
3190 560425 imp_xxh_t *imp_xxh = NULL;
3191 560425 SV *imp_msv = Nullsv;
3192 560425 SV *qsv = Nullsv; /* quick result from a shortcut method */
3193  
3194  
3195 560425 ima_flags = ima->flags;
3196 560425 meth_type = ima->meth_type;
3197 560425 ▶ if (trace_level >= 9) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 9) { 116 560309 560425
3198 116 PerlIO *logfp = DBILOGFP;
3199 116 PerlIO_printf(logfp,"%c >> %-11s DISPATCH (%s rc%ld/%ld @%ld g%x ima%lx pid#%ld)",
3200 116 ▶ (PL_dirty?'!':' '), meth_name, neatsvpv(h,0),
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), meth_name, neatsvpv(h,0), 0 116 116
3201 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
3202 116 (long)items, (int)gimme, (long)ima_flags, (long)PerlProc_getpid());
3203 116 PerlIO_puts(logfp, log_where(0, 0, " at ","\n", 1, (trace_level >= 3), (trace_level >= 4)));
3204 116 PerlIO_flush(logfp);
3205 }
3206  
3207 560425 ▶ if ( ( (is_DESTROY=(meth_type == methtype_DESTROY))) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( ( (is_DESTROY=(meth_type == methtype_DESTROY))) ) { 19380 541045 560425
3208 /* note that croak()'s won't propagate, only append to $@ */
3209 19380 keep_error = TRUE;
3210 }
3211  
3212 /* If h is a tied hash ref, switch to the inner ref 'behind' the tie.
3213 This means *all* DBI methods work with the inner (non-tied) ref.
3214 This makes it much easier for methods to access the real hash
3215 data (without having to go through FETCH and STORE methods) and
3216 for tie and non-tie methods to call each other.
3217 */
3218 560425 ▶ if (SvROK(h)
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(h) 560419 6 560425
3219 560419 ▶ && SvRMAGICAL(SvRV(h))
Branch: 1 branch
BranchTrueFalseTotal
&& SvRMAGICAL(SvRV(h)) 560417 2 560419
3220 560417 && (
3221 560417 ▶ ((mg=SvMAGIC(SvRV(h)))->mg_type == 'P')
Branch: 1 branch
BranchTrueFalseTotal
((mg=SvMAGIC(SvRV(h)))->mg_type == 'P') 442590 117827 560417
3222 442590 ▶ || ((mg=mg_find(SvRV(h),'P')) != NULL)
Branch: 1 branch
BranchTrueFalseTotal
|| ((mg=mg_find(SvRV(h),'P')) != NULL) 0 442590 442590
3223 )
3224 ) {
3225 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
3226 24 ▶ if (trace_level >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 3) 0 24 24
3227 0 PerlIO_printf(DBILOGFP,
3228 "%c <> %s for %s ignored (inner handle gone)\n",
3229 0 ▶ (PL_dirty?'!':' '), meth_name, neatsvpv(h,0));
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), meth_name, neatsvpv(h,0)); 0 0 0
3230 24 XSRETURN(0);
3231 }
3232 /* Distinguish DESTROY of tie (outer) from DESTROY of inner ref */
3233 /* This may one day be used to manually destroy extra internal */
3234 /* refs if the application ceases to use the handle. */
3235 117803 ▶ if (is_DESTROY) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_DESTROY) { 9664 108139 117803
3236 9664 imp_xxh = DBIh_COM(mg->mg_obj);
3237 #ifdef DBI_USE_THREADS
3238 if (imp_xxh && DBIc_THR_USER(imp_xxh) != my_perl) {
3239 goto is_DESTROY_wrong_thread;
3240 }
3241 #endif
3242 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
3243 3635 clear_cached_kids(aTHX_ mg->mg_obj, imp_xxh, meth_name, trace_level);
3244 /* XXX might be better to move this down to after call_depth has been
3245 * incremented and then also SvREFCNT_dec(mg->mg_obj) to force an immediate
3246 * DESTROY of the inner handle if there are no other refs to it.
3247 * That way the inner DESTROY is properly flagged as a nested call,
3248 * and the outer DESTROY gets profiled more accurately, and callbacks work.
3249 */
3250 9662 ▶ if (trace_level >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 3) { 4 9658 9662
3251 8 PerlIO_printf(DBILOGFP,
3252 "%c <> DESTROY(%s) ignored for outer handle (inner %s has ref cnt %ld)\n",
3253 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
3254 4 (long)SvREFCNT(SvRV(mg->mg_obj))
3255 );
3256 }
3257 /* for now we ignore it since it'll be followed soon by */
3258 /* a destroy of the inner hash and that'll do the real work */
3259  
3260 /* However, we must at least modify DBIc_MY_H() as that is */
3261 /* pointing (without a refcnt inc) to the scalar that is */
3262 /* being destroyed, so it'll contain random values later. */
3263 9662 ▶ if (imp_xxh)
Branch: 1 branch
BranchTrueFalseTotal
if (imp_xxh) 9661 1 9662
3264 9661 DBIc_MY_H(imp_xxh) = (HV*)SvRV(mg->mg_obj); /* inner (untied) HV */
3265  
3266 9662 XSRETURN(0);
3267 }
3268 108139 h = mg->mg_obj; /* switch h to inner ref */
3269 108139 ST(0) = h; /* switch handle on stack to inner ref */
3270 }
3271  
3272 550737 imp_xxh = dbih_getcom2(aTHX_ h, 0); /* get common Internal Handle Attributes */
3273 550735 ▶ if (!imp_xxh) {
Branch: 1 branch
BranchTrueFalseTotal
if (!imp_xxh) { 11 550724 550735
3274 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
3275 6 const char *can_meth = SvPV_nolen(st1);
3276 6 SV *rv = &PL_sv_undef;
3277 6 GV *gv = gv_fetchmethod_autoload(gv_stashsv(orig_h,FALSE), can_meth, FALSE);
3278 6 ▶ if (gv && isGV(gv))
Branch: 2 branches
BranchTrueFalseTotal
if (gv && isGV(gv)) 4 2 6
if (gv && isGV(gv)) 4 0 4
3279 4 rv = sv_2mortal(newRV_inc((SV*)GvCV(gv)));
3280 6 ▶ if (trace_level >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 1) { 0 6 6
3281 0 PerlIO_printf(DBILOGFP," <- %s(%s) = %p\n", meth_name, can_meth, neatsvpv(rv,0));
3282 }
3283 6 ST(0) = rv;
3284 6 XSRETURN(1);
3285 }
3286 5 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 5 5
3287 0 PerlIO_printf(DBILOGFP, "%c <> %s for %s ignored (no imp_data)\n",
3288 0 ▶ (PL_dirty?'!':' '), meth_name, neatsvpv(h,0));
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), meth_name, neatsvpv(h,0)); 0 0 0
3289 5 ▶ if (!is_DESTROY)
Branch: 1 branch
BranchTrueFalseTotal
if (!is_DESTROY) 4 1 5
3290 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
3291 SvROK(h) ? " after take_imp_data()" : " (not a reference)");
3292 5 XSRETURN(0);
3293 }
3294  
3295 550724 ▶ if (DBIc_has(imp_xxh,DBIcf_Profile)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh,DBIcf_Profile)) { 61221 489503 550724
3296 61221 profile_t1 = dbi_time(); /* just get start time here */
3297 }
3298  
3299 #ifdef DBI_USE_THREADS
3300 {
3301 PerlInterpreter * h_perl;
3302 is_DESTROY_wrong_thread:
3303 h_perl = DBIc_THR_USER(imp_xxh) ;
3304 if (h_perl != my_perl) {
3305 /* XXX could call a 'handle clone' method here?, for dbh's at least */
3306 if (is_DESTROY) {
3307 if (trace_level >= 3) {
3308 PerlIO_printf(DBILOGFP," DESTROY ignored because DBI %sh handle (%s) is owned by thread %p not current thread %p\n",
3309 dbih_htype_name(DBIc_TYPE(imp_xxh)), HvNAME(DBIc_IMP_STASH(imp_xxh)),
3310 (void*)DBIc_THR_USER(imp_xxh), (void*)my_perl) ;
3311 PerlIO_flush(DBILOGFP);
3312 }
3313 XSRETURN(0); /* don't DESTROY handle, if it is not our's !*/
3314 }
3315 croak("%s %s failed: handle %d is owned by thread %lx not current thread %lx (%s)",
3316 HvNAME(DBIc_IMP_STASH(imp_xxh)), meth_name, DBIc_TYPE(imp_xxh),
3317 (unsigned long)h_perl, (unsigned long)my_perl,
3318 "handles can't be shared between threads and your driver may need a CLONE method added");
3319 }
3320 }
3321 #endif
3322  
3323 550724 ▶ 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 550351 550724
3324 373 I32 h_trace_level = (i & DBIc_TRACE_LEVEL_MASK);
3325 373 ▶ if ( h_trace_level > trace_level )
Branch: 1 branch
BranchTrueFalseTotal
if ( h_trace_level > trace_level ) 44 329 373
3326 44 trace_level = h_trace_level;
3327 373 trace_flags = (trace_flags & ~DBIc_TRACE_LEVEL_MASK)
3328 373 | ( i & ~DBIc_TRACE_LEVEL_MASK)
3329 | trace_level;
3330 }
3331  
3332 /* Check method call against Internal Method Attributes */
3333 550724 ▶ if (ima_flags) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags) { 320065 230659 550724
3334  
3335 320065 ▶ 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)) { 253102 66963 320065
3336  
3337 253102 ▶ if (ima_flags & IMA_STUB) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_STUB) { 120 252982 253102
3338 120 ▶ if (meth_type == methtype_can) {
Branch: 1 branch
BranchTrueFalseTotal
if (meth_type == methtype_can) { 120 0 120
3339 120 const char *can_meth = SvPV_nolen(st1);
3340 120 SV *dbi_msv = Nullsv;
3341 /* find handle implementors method (GV or CV) */
3342 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
3343 /* return DBI's CV, not the implementors CV (else we'd bypass dispatch) */
3344 /* and anyway, we may have hit a private method not part of the DBI */
3345 2 GV *gv = gv_fetchmethod_autoload(SvSTASH(SvRV(orig_h)), can_meth, FALSE);
3346 2 ▶ if (gv && isGV(gv))
Branch: 2 branches
BranchTrueFalseTotal
if (gv && isGV(gv)) 2 0 2
if (gv && isGV(gv)) 2 0 2
3347 2 dbi_msv = (SV*)GvCV(gv);
3348 }
3349 120 ▶ if (trace_level >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 1) { 4 116 120
3350 4 PerlIO *logfp = DBILOGFP;
3351 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
3352 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
3353 }
3354 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
3355 120 XSRETURN(1);
3356 }
3357 0 XSRETURN(0);
3358 }
3359 252982 ▶ if (ima_flags & IMA_FUNC_REDIRECT) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_FUNC_REDIRECT) { 7531 245451 252982
3360 /* XXX this doesn't redispatch, nor consider the IMA of the new method */
3361 7531 SV *meth_name_sv = POPs;
3362 7531 PUTBACK;
3363 7531 --items;
3364 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
3365 0 croak("%s->%s() invalid redirect method name %s",
3366 neatsvpv(h,0), meth_name, neatsvpv(meth_name_sv,0));
3367 7531 meth_name = SvPV_nolen(meth_name_sv);
3368 7531 meth_type = get_meth_type(meth_name);
3369 7531 is_orig_method_name = 0;
3370 }
3371 252982 ▶ if (ima_flags & IMA_KEEP_ERR)
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_KEEP_ERR) 240432 12550 252982
3372 240432 keep_error = TRUE;
3373 252982 ▶ if ((ima_flags & IMA_KEEP_ERR_SUB)
Branch: 1 branch
BranchTrueFalseTotal
if ((ima_flags & IMA_KEEP_ERR_SUB) 94829 158153 252982
3374 94829 ▶ && !PL_dirty
Branch: 1 branch
BranchTrueFalseTotal
&& !PL_dirty 94307 522 94829
3375 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
3376 33025 keep_error = TRUE;
3377 252982 ▶ if (ima_flags & IMA_CLEAR_STMT) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_CLEAR_STMT) { 12550 240432 252982
3378 /* don't use SvOK_off: dbh's Statement may be ref to sth's */
3379 12550 (void)hv_stores((HV*)SvRV(h), "Statement", &PL_sv_undef);
3380 }
3381 252982 ▶ if (ima_flags & IMA_CLEAR_CACHED_KIDS)
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_CLEAR_CACHED_KIDS) 9689 243293 252982
3382 9689 clear_cached_kids(aTHX_ h, imp_xxh, meth_name, trace_flags);
3383  
3384 }
3385  
3386 319945 ▶ if (ima_flags & IMA_HAS_USAGE) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_HAS_USAGE) { 95091 224854 319945
3387 95091 SV *usage_err = Nullsv;
3388  
3389 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
3390 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
3391 2 usage_err = sv_2mortal(newSVpvf(
3392 "DBI %s: invalid number of arguments: got handle + %ld, expected handle + between %d and %d\n",
3393 meth_name, (long)items-1, (int)ima->minargs-1, (int)ima->maxargs-1));
3394 }
3395 /* arg type checking could be added here later */
3396 95091 ▶ if (usage_err) {
Branch: 1 branch
BranchTrueFalseTotal
if (usage_err) { 2 95089 95091
3397 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
3398 (ima->usage_msg) ? ima->usage_msg : "...?");
3399 }
3400 }
3401 }
3402  
3403 1101204 is_unrelated_to_Statement = ( (DBIc_TYPE(imp_xxh) == DBIt_ST) ? 0
3404 550602 ▶ : (DBIc_TYPE(imp_xxh) == DBIt_DR) ? 1
Branch: 2 branches
BranchTrueFalseTotal
: (DBIc_TYPE(imp_xxh) == DBIt_DR) ? 1 195900 354702 550602
: (DBIc_TYPE(imp_xxh) == DBIt_DR) ? 1 184332 11568 195900
3405 : (ima_flags & IMA_UNRELATED_TO_STMT) );
3406  
3407 550602 ▶ if (PL_tainting && items > 1 /* method call has args */
Branch: 2 branches
BranchTrueFalseTotal
if (PL_tainting && items > 1 /* method call has args */ 89 550513 550602
if (PL_tainting && items > 1 /* method call has args */ 72 17 89
3408 72 ▶ && DBIc_is(imp_xxh, DBIcf_TaintIn) /* taint checks requested */
Branch: 1 branch
BranchTrueFalseTotal
&& DBIc_is(imp_xxh, DBIcf_TaintIn) /* taint checks requested */ 35 37 72
3409 35 ▶ && !(ima_flags & IMA_NO_TAINT_IN)
Branch: 1 branch
BranchTrueFalseTotal
&& !(ima_flags & IMA_NO_TAINT_IN) 20 15 35
3410 ) {
3411 40 ▶ for(i=1; i < items; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=1; i < items; ++i) { 23 17 40
3412 23 ▶ if (SvTAINTED(ST(i))) {
Branch: 2 branches
BranchTrueFalseTotal
if (SvTAINTED(ST(i))) { 3 20 23
if (SvTAINTED(ST(i))) { 3 0 3
3413 3 SV *taint_msg = sv_2mortal(newSVpvf(
3414 "parameter %d of %s->%s method call",
3415 i, SvPV_nolen(h), meth_name));
3416 3 PL_tainted = 1; /* needed for TAINT_PROPER to work */
3417 6 ▶ TAINT_PROPER(SvPV_nolen(taint_msg)); /* die's */
Branch: 1 branch
BranchTrueFalseTotal
TAINT_PROPER(SvPV_nolen(taint_msg)); /* die's */ 3 0 3
3418 }
3419 }
3420 }
3421  
3422 /* record this inner handle for use by DBI::var::FETCH */
3423 550599 ▶ if (is_DESTROY) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_DESTROY) { 9689 540910 550599
3424  
3425 /* force destruction of any outstanding children */
3426 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
3427 3104 AV *av = (AV*)SvRV(*tmp_svp);
3428 I32 kidslots;
3429 3104 PerlIO *logfp = DBILOGFP;
3430  
3431 3104 ▶ for (kidslots = AvFILL(av); kidslots >= 0; --kidslots) {
Branch: 1 branch
BranchTrueFalseTotal
for (kidslots = AvFILL(av); kidslots >= 0; --kidslots) { 3104 0 3104
3432 3104 SV **hp = av_fetch(av, kidslots, FALSE);
3433 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
3434 break;
3435  
3436 0 ▶ if (trace_level >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 1) { 0 0 0
3437 0 PerlIO_printf(logfp, "on DESTROY handle %s still has child %s (refcnt %ld, obj %d, dirty=%d)\n",
3438 0 neatsvpv(h,0), neatsvpv(*hp, 0), (long)SvREFCNT(*hp), !!sv_isobject(*hp), PL_dirty);
3439 0 ▶ if (trace_level >= 9)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 9) 0 0 0
3440 0 sv_dump(SvRV(*hp));
3441 }
3442 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
3443 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
3444 0 ▶ XPUSHs(*hp);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(*hp); 0 0 0
3445 0 PUTBACK;
3446 0 call_method("DESTROY", G_VOID|G_EVAL|G_KEEPERR);
3447 0 MSPAGAIN;
3448 }
3449 else {
3450 0 imp_xxh_t *imp_xxh = dbih_getcom2(aTHX_ *hp, 0);
3451 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
3452 0 dbih_clearcom(imp_xxh);
3453 0 sv_setsv(*hp, &PL_sv_undef);
3454 }
3455 }
3456 }
3457 }
3458  
3459 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
3460 imp_xxh_t *parent_imp;
3461  
3462 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
3463 53 ▶ && !PL_dirty /* XXX - remove? */
Branch: 1 branch
BranchTrueFalseTotal
&& !PL_dirty /* XXX - remove? */ 50 3 53
3464 ) {
3465 /* copy err/errstr/state values to $DBI::err etc still work */
3466 50 sv_setsv(DBIc_ERR(parent_imp), DBIc_ERR(imp_xxh));
3467 50 sv_setsv(DBIc_ERRSTR(parent_imp), DBIc_ERRSTR(imp_xxh));
3468 50 sv_setsv(DBIc_STATE(parent_imp), DBIc_STATE(imp_xxh));
3469 }
3470 }
3471  
3472 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
3473 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
3474 4 DBIc_set(imp_xxh, DBIcf_IADESTROY, 1);
3475 }
3476 9689 ▶ if (DBIc_IADESTROY(imp_xxh)) { /* wants ineffective destroy */
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_IADESTROY(imp_xxh)) { /* wants ineffective destroy */ 8 9681 9689
3477 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
3478 }
3479 9689 call_depth = 0;
3480 9689 is_nested_call = 0;
3481 }
3482 else {
3483 540910 DBI_SET_LAST_HANDLE(h);
3484 540910 SAVEINT(DBIc_CALL_DEPTH(imp_xxh));
3485 540910 call_depth = ++DBIc_CALL_DEPTH(imp_xxh);
3486  
3487 540910 ▶ if (ima_flags & IMA_COPY_UP_STMT) { /* execute() */
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_COPY_UP_STMT) { /* execute() */ 8080 532830 540910
3488 8080 copy_statement_to_parent(aTHX_ h, imp_xxh);
3489 }
3490 540910 is_nested_call =
3491 (call_depth > 1
3492 756871 ▶ || (!PL_dirty /* not in global destruction [CPAN #75614] */
Branch: 2 branches
BranchTrueFalseTotal
|| (!PL_dirty /* not in global destruction [CPAN #75614] */ 215961 324949 540910
|| (!PL_dirty /* not in global destruction [CPAN #75614] */ 48592 167369 215961
3493 215420 ▶ && DBIc_PARENT_COM(imp_xxh)
Branch: 1 branch
BranchTrueFalseTotal
&& DBIc_PARENT_COM(imp_xxh) 204390 11030 215420
3494 431381 ▶ && DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh))) >= 1);
Branch: 2 branches
BranchTrueFalseTotal
&& DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh))) >= 1); 215420 541 215961
&& DBIc_CALL_DEPTH(DBIc_PARENT_COM(imp_xxh))) >= 1); 48592 155798 204390
3495  
3496 }
3497  
3498  
3499 /* --- dispatch --- */
3500  
3501 550599 ▶ if (!keep_error && meth_type != methtype_set_err) {
Branch: 2 branches
BranchTrueFalseTotal
if (!keep_error && meth_type != methtype_set_err) { 310168 240431 550599
if (!keep_error && meth_type != methtype_set_err) { 300636 9532 310168
3502 SV *err_sv;
3503 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
3504 0 PerlIO *logfp = DBILOGFP;
3505 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
3506 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
3507 0 neatsvpv(DBIc_ERR(imp_xxh),0), meth_name);
3508 }
3509 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
3510 }
3511 else { /* we check for change in ErrCount/err_hash during call */
3512 249963 ErrCount = DBIc_ErrCount(imp_xxh);
3513 249963 ▶ if (keep_error)
Branch: 1 branch
BranchTrueFalseTotal
if (keep_error) 240431 9532 249963
3514 240431 keep_error = err_hash(aTHX_ imp_xxh);
3515 }
3516  
3517 550599 ▶ if (DBIc_has(imp_xxh,DBIcf_Callbacks)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh,DBIcf_Callbacks) 64527 486072 550599
3518 64527 ▶ && (tmp_svp = hv_fetchs((HV*)SvRV(h), "Callbacks", 0))
Branch: 1 branch
BranchTrueFalseTotal
&& (tmp_svp = hv_fetchs((HV*)SvRV(h), "Callbacks", 0)) 64527 0 64527
3519 64527 ▶ && ( (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)) 61591 2936 64527
3520 /* the "*" fallback callback only applies to non-nested calls
3521 * and also doesn't apply to the 'set_err' or DESTROY methods.
3522 * Nor during global destruction.
3523 * Other restrictions may be added over time.
3524 * It's an undocumented hack.
3525 */
3526 61591 ▶ || (!is_nested_call && !PL_dirty && meth_type != methtype_set_err &&
Branch: 4 branches
BranchTrueFalseTotal
|| (!is_nested_call && !PL_dirty && meth_type != methtype_set_err && 43845 17746 61591
|| (!is_nested_call && !PL_dirty && meth_type != methtype_set_err && 43820 25 43845
|| (!is_nested_call && !PL_dirty && meth_type != methtype_set_err && 40920 2900 43820
|| (!is_nested_call && !PL_dirty && meth_type != methtype_set_err && 40908 12 40920
3527 40908 ▶ meth_type != methtype_DESTROY &&
Branch: 1 branch
BranchTrueFalseTotal
meth_type != methtype_DESTROY && 10 40898 40908
3528 40908 (hook_svp = hv_fetchs((HV*)SvRV(*tmp_svp), "*", 0))
3529 )
3530 )
3531 2946 ▶ && SvROK(*hook_svp)
Branch: 1 branch
BranchTrueFalseTotal
&& SvROK(*hook_svp) 2946 0 2946
3532 ) {
3533 SV *orig_defsv;
3534 SV *temp_defsv;
3535 2946 SV *code = SvRV(*hook_svp);
3536 2946 I32 skip_dispatch = 0;
3537 2946 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 2946 2946
3538 0 PerlIO_printf(DBILOGFP, "%c {{ %s callback %s being invoked with %ld args\n",
3539 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
3540  
3541 /* we don't use ENTER,SAVETMPS & FREETMPS,LEAVE because we may need mortal
3542 * results to live long enough to be returned to our caller
3543 */
3544 /* we want to localize $_ for the callback but can't just do that alone
3545 * because we're not using SAVETMPS & FREETMPS, so we have to get sneaky.
3546 * We still localize, so we're safe from the callback die-ing,
3547 * but after the callback we manually restore the original $_.
3548 */
3549 2946 ▶ orig_defsv = DEFSV; /* remember the current $_ */
Branch: 1 branch
BranchTrueFalseTotal
orig_defsv = DEFSV; /* remember the current $_ */ 2946 0 2946
3550 2946 SAVE_DEFSV; /* local($_) = $method_name */
3551 2946 temp_defsv = sv_2mortal(newSVpv(meth_name,0));
3552 # ifdef SvTEMP_off
3553 2946 SvTEMP_off(temp_defsv);
3554 # endif
3555 2946 DEFSV_set(temp_defsv);
3556  
3557 2946 ▶ EXTEND(SP, items+1);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, items+1); 2946 0 2946
EXTEND(SP, items+1); 2 2944 2946
3558 2946 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2946 2946
3559 2946 PUSHs(orig_h); /* push outer handle, then others params */
3560 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
3561 11822 PUSHs( ST(i) );
3562 }
3563 2946 PUTBACK;
3564 2946 outitems = call_sv(code, G_LIST); /* call the callback code */
3565 2944 MSPAGAIN;
3566  
3567 /* The callback code can undef $_ to indicate to skip dispatch */
3568 2944 ▶ skip_dispatch = !SvOK(DEFSV);
Branch: 1 branch
BranchTrueFalseTotal
skip_dispatch = !SvOK(DEFSV); 2944 0 2944
3569 /* put $_ back now */
3570 2944 DEFSV_set(orig_defsv);
3571  
3572 2944 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 2944 2944
3573 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
3574 0 ▶ (PL_dirty?'!':' '), meth_name, neatsvpv(*hook_svp,0),
Branch: 1 branch
BranchTrueFalseTotal
(PL_dirty?'!':' '), meth_name, neatsvpv(*hook_svp,0), 0 0 0
3575 skip_dispatch ? ", actual method will not be called" : ""
3576 );
3577 2944 ▶ if (skip_dispatch) { /* XXX experimental */
Branch: 1 branch
BranchTrueFalseTotal
if (skip_dispatch) { /* XXX experimental */ 1501 1443 2944
3578 1501 int ix = outitems;
3579 /* copy the new items down to the destination list */
3580 3000 ▶ while (ix-- > 0) {
Branch: 1 branch
BranchTrueFalseTotal
while (ix-- > 0) { 1499 1501 3000
3581 if(0)warn("\tcopy down %d: %s overwriting %s\n", ix, SvPV_nolen(TOPs), SvPV_nolen(ST(ix)) );
3582 1499 ST(ix) = POPs;
3583 }
3584 1501 imp_msv = *hook_svp; /* for trace and profile */
3585 1501 goto post_dispatch;
3586 }
3587 else {
3588 1443 ▶ if (outitems != 0)
Branch: 1 branch
BranchTrueFalseTotal
if (outitems != 0) 2 1441 1443
3589 2 die("Callback for %s returned %d values but must not return any (temporary restriction in current version)",
3590 meth_name, (int)outitems);
3591 /* POP's and PUTBACK? to clear stack */
3592 }
3593 }
3594  
3595 /* set Executed after Callbacks so it's not set if callback elects to skip the method */
3596 549094 ▶ if (ima_flags & IMA_EXECUTE) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_EXECUTE) { 12868 536226 549094
3597 12868 imp_xxh_t *parent = DBIc_PARENT_COM(imp_xxh);
3598 12868 DBIc_on(imp_xxh, DBIcf_Executed);
3599 12868 ▶ if (parent)
Branch: 1 branch
BranchTrueFalseTotal
if (parent) 12868 0 12868
3600 12868 DBIc_on(parent, DBIcf_Executed);
3601 }
3602  
3603 /* The "quick_FETCH" logic... */
3604 /* Shortcut for fetching attributes to bypass method call overheads */
3605 549094 ▶ if (meth_type == methtype_FETCH && !DBIc_COMPAT(imp_xxh)) {
Branch: 2 branches
BranchTrueFalseTotal
if (meth_type == methtype_FETCH && !DBIc_COMPAT(imp_xxh)) { 98702 450392 549094
if (meth_type == methtype_FETCH && !DBIc_COMPAT(imp_xxh)) { 98624 78 98702
3606 STRLEN kl;
3607 98624 const char *key = SvPV(st1, kl);
3608 SV **attr_svp;
3609 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
3610 49631 qsv = *attr_svp;
3611 /* disable FETCH from cache for special attributes */
3612 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
3613 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
3614 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
3615 ) {
3616 2547 qsv = Nullsv;
3617 }
3618 /* disable profiling of FETCH of Profile data */
3619 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
3620 158 profile_t1 = 0.0;
3621 }
3622 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
3623 47084 ST(0) = sv_mortalcopy(qsv);
3624 47084 outitems = 1;
3625 47084 goto post_dispatch;
3626 }
3627 }
3628  
3629 {
3630 CV *meth_cv;
3631 #ifdef DBI_save_hv_fetch_ent
3632 HE save_mh;
3633 if (meth_type == methtype_FETCH)
3634 save_mh = PL_hv_fetch_ent_mh; /* XXX nested tied FETCH bug17575 workaround */
3635 #endif
3636  
3637 502010 ▶ if (trace_flags) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_flags) { 1036 500974 502010
3638 1036 SAVEI32(DBIS->debug); /* fall back to orig value later */
3639 1036 DBIS->debug = trace_flags; /* make new value global (for now) */
3640 1036 ▶ if (ima) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima) { 1036 0 1036
3641 /* enabling trace via flags takes precedence over disabling due to min level */
3642 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
3643 24 trace_level = (trace_level < 2) ? 2 : trace_level; /* min */
3644 else
3645 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
3646 174 trace_level = 0; /* silence dispatch log for this method */
3647 }
3648 }
3649  
3650 502010 ▶ if (is_orig_method_name
Branch: 1 branch
BranchTrueFalseTotal
if (is_orig_method_name 494480 7530 502010
3651 494480 ▶ && ima->stash == DBIc_IMP_STASH(imp_xxh)
Branch: 1 branch
BranchTrueFalseTotal
&& ima->stash == DBIc_IMP_STASH(imp_xxh) 421736 72744 494480
3652 843472 && ima->generation == PL_sub_generation +
3653 421736 ▶ MY_cache_gen(DBIc_IMP_STASH(imp_xxh))
Branch: 2 branches
BranchTrueFalseTotal
MY_cache_gen(DBIc_IMP_STASH(imp_xxh)) 421736 0 421736
MY_cache_gen(DBIc_IMP_STASH(imp_xxh)) 421616 120 421736
3654 )
3655 421616 imp_msv = (SV*)ima->gv;
3656 else {
3657 80394 imp_msv = (SV*)gv_fetchmethod_autoload(DBIc_IMP_STASH(imp_xxh),
3658 meth_name, FALSE);
3659 80394 ▶ if (is_orig_method_name) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_orig_method_name) { 72864 7530 80394
3660 /* clear stale entry, if any */
3661 72864 SvREFCNT_dec(ima->stash);
3662 72864 SvREFCNT_dec(ima->gv);
3663 72864 ▶ if (!imp_msv) {
Branch: 1 branch
BranchTrueFalseTotal
if (!imp_msv) { 138 72726 72864
3664 138 ima->stash = NULL;
3665 138 ima->gv = NULL;
3666 }
3667 else {
3668 72726 ima->stash = (HV*)SvREFCNT_inc(DBIc_IMP_STASH(imp_xxh));
3669 72726 ima->gv = (GV*)SvREFCNT_inc(imp_msv);
3670 72726 ima->generation = PL_sub_generation +
3671 72726 ▶ MY_cache_gen(DBIc_IMP_STASH(imp_xxh));
Branch: 1 branch
BranchTrueFalseTotal
MY_cache_gen(DBIc_IMP_STASH(imp_xxh)); 72726 0 72726
3672 }
3673 }
3674 }
3675  
3676 /* if method was a 'func' then try falling back to real 'func' method */
3677 502010 ▶ if (!imp_msv && (ima_flags & IMA_FUNC_REDIRECT)) {
Branch: 2 branches
BranchTrueFalseTotal
if (!imp_msv && (ima_flags & IMA_FUNC_REDIRECT)) { 141 501869 502010
if (!imp_msv && (ima_flags & IMA_FUNC_REDIRECT)) { 3 138 141
3678 3 imp_msv = (SV*)gv_fetchmethod_autoload(DBIc_IMP_STASH(imp_xxh), "func", FALSE);
3679 3 ▶ if (imp_msv) {
Branch: 1 branch
BranchTrueFalseTotal
if (imp_msv) { 3 0 3
3680 /* driver does have func method so undo the earlier 'func' stack changes */
3681 3 mPUSHs(newSVpv(meth_name, 0));
3682 3 PUTBACK;
3683 3 ++items;
3684 3 meth_name = "func";
3685 3 meth_type = methtype_ordinary;
3686 }
3687 }
3688  
3689 502010 ▶ if (trace_level >= (is_nested_call ? 4 : 2)) {
Branch: 2 branches
BranchTrueFalseTotal
if (trace_level >= (is_nested_call ? 4 : 2)) { 338551 163459 502010
if (trace_level >= (is_nested_call ? 4 : 2)) { 167 501843 502010
3690 167 PerlIO *logfp = DBILOGFP;
3691 /* Full pkg method name (or just meth_name for ANON CODE) */
3692 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
3693 167 HV *imp_stash = DBIc_IMP_STASH(imp_xxh);
3694 297 ▶ PerlIO_printf(logfp, "%c -> %s ",
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp, "%c -> %s ", 37 130 167
3695 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
3696 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
3697 0 PerlIO_printf(logfp, "\"%s\" ", meth_name);
3698 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
3699 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
3700 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
3701 SvPV_nolen(orig_h));
3702 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
3703 57 PerlIO_printf(logfp, "~0x%lx", (long)SvRV(h));
3704 110 else PerlIO_printf(logfp, "~INNER");
3705 474 ▶ for(i=1; i<items; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=1; i<items; ++i) { 307 167 474
3706 614 ▶ PerlIO_printf(logfp," %s",
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp," %s", 307 0 307
3707 307 ▶ (ima && i==ima->hidearg) ? "****" : neatsvpv(ST(i),0));
Branch: 1 branch
BranchTrueFalseTotal
(ima && i==ima->hidearg) ? "****" : neatsvpv(ST(i),0)); 289 18 307
3708 }
3709 #ifdef DBI_USE_THREADS
3710 PerlIO_printf(logfp, ") thr#%p\n", (void*)DBIc_THR_USER(imp_xxh));
3711 #else
3712 167 PerlIO_printf(logfp, ")\n");
3713 #endif
3714 167 PerlIO_flush(logfp);
3715 }
3716  
3717 502010 ▶ if (!imp_msv || ! ((meth_cv = GvCV(imp_msv))) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (!imp_msv || ! ((meth_cv = GvCV(imp_msv))) ) { 501872 138 502010
if (!imp_msv || ! ((meth_cv = GvCV(imp_msv))) ) { 0 501872 501872
3718 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
3719 0 outitems = 0;
3720 0 goto post_dispatch;
3721 }
3722 138 ▶ if (ima_flags & IMA_NOT_FOUND_OKAY) {
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_NOT_FOUND_OKAY) { 134 4 138
3723 134 outitems = 0;
3724 134 goto post_dispatch;
3725 }
3726 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
3727 meth_name, HvNAME(DBIc_IMP_STASH(imp_xxh)));
3728 }
3729  
3730 501872 ▶ 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 501872 501872
3731  
3732 /* Note: the handle on the stack is still an object blessed into a
3733 * DBI::* class and not the DBD::*::* class whose method is being
3734 * invoked. This is correct and should be largely transparent.
3735 */
3736  
3737 /* SHORT-CUT ALERT! */
3738 501872 ▶ if (use_xsbypass && CvISXSUB(meth_cv) && CvXSUB(meth_cv)) {
Branch: 3 branches
BranchTrueFalseTotal
if (use_xsbypass && CvISXSUB(meth_cv) && CvXSUB(meth_cv)) { 501872 0 501872
if (use_xsbypass && CvISXSUB(meth_cv) && CvXSUB(meth_cv)) { 148271 353601 501872
if (use_xsbypass && CvISXSUB(meth_cv) && CvXSUB(meth_cv)) { 148271 0 148271
3739  
3740 /* If we are calling an XSUB we jump directly to its C code and
3741 * bypass perl_call_sv(), pp_entersub() etc. This is fast.
3742 * This code is based on a small section of pp_entersub().
3743 */
3744 148271 (void)(*CvXSUB(meth_cv))(aTHXo_ meth_cv); /* Call the C code directly */
3745  
3746 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
3747 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
3748 0 ST(0) =
3749 0 (ax > PL_stack_sp - PL_stack_base)
3750 ? &PL_sv_undef /* outitems == 0 */
3751 0 ▶ : *PL_stack_sp; /* outitems > 1 */
Branch: 1 branch
BranchTrueFalseTotal
: *PL_stack_sp; /* outitems > 1 */ 0 0 0
3752 0 PL_stack_sp = PL_stack_base + ax;
3753 }
3754 112749 outitems = 1;
3755 }
3756 else {
3757 35514 outitems = PL_stack_sp - (PL_stack_base + ax - 1);
3758 }
3759  
3760 }
3761 else {
3762 /* sv_dump(imp_msv); */
3763 353601 ▶ outitems = call_sv((SV*)meth_cv,
Branch: 1 branch
BranchTrueFalseTotal
outitems = call_sv((SV*)meth_cv, 3774 349827 353601
3764 (is_DESTROY ? gimme | G_EVAL | G_KEEPERR : gimme) );
3765 }
3766  
3767 501848 XSprePUSH; /* reset SP to base of stack frame */
3768  
3769 #ifdef DBI_save_hv_fetch_ent
3770 if (meth_type == methtype_FETCH)
3771 PL_hv_fetch_ent_mh = save_mh; /* see start of block */
3772 #endif
3773 }
3774  
3775 550567 post_dispatch:
3776  
3777 550567 ▶ 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 540882 550567
if (is_DESTROY && DBI_IS_LAST_HANDLE(h)) { /* if destroying _this_ handle */ 6728 2957 9685
3778 6728 SV *lhp = DBIc_PARENT_H(imp_xxh);
3779 6728 ▶ if (lhp && SvROK(lhp)) {
Branch: 2 branches
BranchTrueFalseTotal
if (lhp && SvROK(lhp)) { 6728 0 6728
if (lhp && SvROK(lhp)) { 6437 291 6728
3780 6437 DBI_SET_LAST_HANDLE(lhp);
3781 }
3782 else {
3783 291 DBI_UNSET_LAST_HANDLE;
3784 }
3785 }
3786  
3787 550567 ▶ if (keep_error) {
Branch: 1 branch
BranchTrueFalseTotal
if (keep_error) { 240421 310146 550567
3788 /* if we didn't clear err before the call, check to see if a new error
3789 * or warning has been recorded. If so, turn off keep_error so it gets acted on
3790 */
3791 240421 ▶ 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) { 238938 1483 240421
if (DBIc_ErrCount(imp_xxh) > ErrCount || err_hash(aTHX_ imp_xxh) != keep_error) { 14 238924 238938
3792 1497 keep_error = 0;
3793 }
3794 }
3795  
3796 550567 err_sv = DBIc_ERR(imp_xxh);
3797  
3798 550567 ▶ if (trace_level >= (is_nested_call ? 3 : 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if (trace_level >= (is_nested_call ? 3 : 1)) { 373538 177029 550567
if (trace_level >= (is_nested_call ? 3 : 1)) { 223 550344 550567
3799 223 PerlIO *logfp = DBILOGFP;
3800 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
3801 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
3802 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
3803 /* skip the 'middle' rows to reduce output */
3804 0 goto skip_meth_return_trace;
3805 }
3806 223 ▶ if (SvOK(err_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(err_sv)) { 0 223 223
3807 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
3808 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
3809 0 neatsvpv(err_sv,0), neatsvpv(DBIc_ERRSTR(imp_xxh),0), (long)DBIc_ErrCount(imp_xxh));
3810 }
3811 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
3812 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
3813 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
3814 (qsv) ? '>' : '-',
3815 meth_name);
3816 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
3817 /* we only have the first two parameters available here */
3818 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
3819 /* want to show outer handle so trace makes sense */
3820 /* but outer handle has been destroyed so we fake it */
3821 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
3822 else
3823 26 PerlIO_printf(logfp,"(%s", neatsvpv(st1,0));
3824 29 ▶ if (items >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items >= 3) 21 8 29
3825 21 PerlIO_printf(logfp,", %s", neatsvpv(st2,0));
3826 29 ▶ PerlIO_printf(logfp,"%s)", (items > 3) ? ", ..." : "");
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp,"%s)", (items > 3) ? ", ..." : ""); 3 26 29
3827 }
3828  
3829 223 ▶ if (gimme & G_LIST)
Branch: 1 branch
BranchTrueFalseTotal
if (gimme & G_LIST) 223 0 223
3830 223 PerlIO_printf(logfp,"= (");
3831 0 else PerlIO_printf(logfp,"=");
3832 448 ▶ for(i=0; i < outitems; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < outitems; ++i) { 225 223 448
3833 225 SV *s = ST(i);
3834 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
3835 0 AV *av = (AV*)SvRV(s);
3836 int avi;
3837 0 int avi_last = SvIV(DBIS->neatsvpvlen) / 10;
3838 0 ▶ if (avi_last < 39)
Branch: 1 branch
BranchTrueFalseTotal
if (avi_last < 39) 0 0 0
3839 0 avi_last = 39;
3840 0 PerlIO_printf(logfp, " [");
3841 0 ▶ for (avi=0; avi <= AvFILL(av); ++avi) {
Branch: 1 branch
BranchTrueFalseTotal
for (avi=0; avi <= AvFILL(av); ++avi) { 0 0 0
3842 0 PerlIO_printf(logfp, " %s", neatsvpv(AvARRAY(av)[avi],0));
3843 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
3844 0 PerlIO_printf(logfp, " ... %ld others skipped", AvFILL(av) - avi);
3845 0 break;
3846 }
3847 }
3848 0 PerlIO_printf(logfp, " ]");
3849 }
3850 else {
3851 225 PerlIO_printf(logfp, " %s", neatsvpv(s,0));
3852 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
3853 5 ▶ PerlIO_printf(logfp, "%ldkeys", (long)HvKEYS(SvRV(s)));
Branch: 1 branch
BranchTrueFalseTotal
PerlIO_printf(logfp, "%ldkeys", (long)HvKEYS(SvRV(s))); 0 5 5
3854 }
3855 }
3856 223 ▶ if (gimme & G_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if (gimme & G_LIST) { 223 0 223
3857 223 PerlIO_printf(logfp," ) [%d items]", outitems);
3858 }
3859 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
3860 0 PerlIO_printf(logfp," row%"IVdf, row_count);
3861 }
3862 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
3863 11 PerlIO_printf(logfp," (%s from cache)", neatsvpv(st1,0));
3864 212 ▶ else if (!imp_msv)
Branch: 1 branch
BranchTrueFalseTotal
else if (!imp_msv) 0 212 212
3865 0 PerlIO_printf(logfp," (not implemented)");
3866 /* XXX add flag to show pid here? */
3867 /* add file and line number information */
3868 223 PerlIO_puts(logfp, log_where(0, 0, " at ", "\n", 1, (trace_level >= 3), (trace_level >= 4)));
3869 223 skip_meth_return_trace:
3870 223 PerlIO_flush(logfp);
3871 }
3872  
3873 550567 ▶ if (ima_flags & IMA_END_WORK) { /* commit() or rollback() */
Branch: 1 branch
BranchTrueFalseTotal
if (ima_flags & IMA_END_WORK) { /* commit() or rollback() */ 4 550563 550567
3874 /* XXX does not consider if the method call actually worked or not */
3875 4 DBIc_off(imp_xxh, DBIcf_Executed);
3876  
3877 4 ▶ if (DBIc_has(imp_xxh, DBIcf_BegunWork)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_BegunWork)) { 2 2 4
3878 2 DBIc_off(imp_xxh, DBIcf_BegunWork);
3879 2 ▶ if (!DBIc_has(imp_xxh, DBIcf_AutoCommit)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIc_has(imp_xxh, DBIcf_AutoCommit)) { 2 0 2
3880 /* We only get here if the driver hasn't implemented their own code */
3881 /* for begin_work, or has but hasn't correctly turned AutoCommit */
3882 /* back on in their commit or rollback code. So we have to do it. */
3883 /* This is bad because it'll probably trigger a spurious commit() */
3884 /* and may mess up the error handling below for the commit/rollback */
3885 2 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2 2
3886 2 ▶ XPUSHs(h);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(h); 0 2 2
3887 2 ▶ mXPUSHs(newSVpvs("AutoCommit"));
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(newSVpvs("AutoCommit")); 0 2 2
3888 2 ▶ XPUSHs(&PL_sv_yes);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(&PL_sv_yes); 0 2 2
3889 2 PUTBACK;
3890 2 call_method("STORE", G_VOID);
3891 2 MSPAGAIN;
3892 }
3893 }
3894 }
3895  
3896 if (PL_tainting
3897 && DBIc_is(imp_xxh, DBIcf_TaintOut) /* taint checks requested */
3898 /* XXX this would taint *everything* being returned from *any* */
3899 /* method that doesn't have IMA_NO_TAINT_OUT set. */
3900 /* DISABLED: just tainting fetched data in get_fbav seems ok */
3901 && 0/* XXX disabled*/ /* !(ima_flags & IMA_NO_TAINT_OUT) */
3902 ) {
3903 dTHR;
3904 TAINT; /* affects sv_setsv()'s within same perl statement */
3905 for(i=0; i < outitems; ++i) {
3906 I32 avi;
3907 char *p;
3908 SV *s;
3909 SV *agg = ST(i);
3910 if ( !SvROK(agg) )
3911 continue;
3912 agg = SvRV(agg);
3913 #define DBI_OUT_TAINTABLE(s) (!SvREADONLY(s) && !SvTAINTED(s))
3914 switch (SvTYPE(agg)) {
3915 case SVt_PVAV:
3916 for(avi=0; avi <= AvFILL((AV*)agg); ++avi) {
3917 s = AvARRAY((AV*)agg)[avi];
3918 if (DBI_OUT_TAINTABLE(s))
3919 SvTAINTED_on(s);
3920 }
3921 break;
3922 case SVt_PVHV:
3923 hv_iterinit((HV*)agg);
3924 while( (s = hv_iternextsv((HV*)agg, &p, &avi)) ) {
3925 if (DBI_OUT_TAINTABLE(s))
3926 SvTAINTED_on(s);
3927 }
3928 break;
3929 default:
3930 if (DBIc_WARN(imp_xxh)) {
3931 PerlIO_printf(DBILOGFP,"Don't know how to taint contents of returned %s (type %d)\n",
3932 neatsvpv(agg,0), (int)SvTYPE(agg));
3933 }
3934 }
3935 }
3936 }
3937  
3938 /* if method returned a new handle, and that handle has an error on it
3939 * then copy the error up into the parent handle
3940 */
3941 550567 ▶ if (ima_flags & IMA_IS_FACTORY && SvROK(ST(0))) {
Branch: 2 branches
BranchTrueFalseTotal
if (ima_flags & IMA_IS_FACTORY && SvROK(ST(0))) { 12653 537914 550567
if (ima_flags & IMA_IS_FACTORY && SvROK(ST(0))) { 12316 337 12653
3942 12316 SV *h_new = ST(0);
3943 12316 D_impdata(imp_xxh_new, imp_xxh_t, h_new);
3944 12316 ▶ if (SvOK(DBIc_ERR(imp_xxh_new))) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(DBIc_ERR(imp_xxh_new))) { 0 12316 12316
3945 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);
3946 }
3947 }
3948  
3949 550567 ▶ if ( !keep_error /* is a new err/warn/info */
Branch: 1 branch
BranchTrueFalseTotal
if ( !keep_error /* is a new err/warn/info */ 311643 238924 550567
3950 311643 ▶ && !is_nested_call /* skip nested (internal) calls */
Branch: 1 branch
BranchTrueFalseTotal
&& !is_nested_call /* skip nested (internal) calls */ 64840 246803 311643
3951 64840 ▶ && (
Branch: 1 branch
BranchTrueFalseTotal
&& ( 3370 61470 64840
3952 /* is an error and has RaiseError|PrintError|HandleError set */
3953 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
3954 /* is a warn (not info) and has RaiseWarn|PrintWarn set */
3955 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
3956 )
3957 227 ) {
3958 SV *msg;
3959 3387 SV **statement_svp = NULL;
3960 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
3961 3387 const char *err_meth_name = meth_name;
3962  
3963 3387 ▶ if (meth_type == methtype_set_err) {
Branch: 1 branch
BranchTrueFalseTotal
if (meth_type == methtype_set_err) { 78 3309 3387
3964 78 SV **sem_svp = hv_fetchs((HV*)SvRV(h), "dbi_set_err_method", GV_ADDWARN);
3965 78 ▶ if (SvOK(*sem_svp))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(*sem_svp)) 8 70 78
3966 16 err_meth_name = SvPV_nolen(*sem_svp);
3967 }
3968  
3969 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
3970 SvTRUE(err_sv) ? "failed" : is_warning ? "warning" : "information"));
3971 3387 ▶ if (SvOK(DBIc_ERRSTR(imp_xxh)))
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(DBIc_ERRSTR(imp_xxh))) 3387 0 3387
3972 3387 sv_catsv(msg, DBIc_ERRSTR(imp_xxh));
3973 else
3974 0 sv_catpvf(msg, "(err=%s, errstr=undef, state=%s)",
3975 neatsvpv(DBIc_ERR(imp_xxh),0), neatsvpv(DBIc_STATE(imp_xxh),0) );
3976  
3977 3387 ▶ if ( DBIc_has(imp_xxh, DBIcf_ShowErrorStatement)
Branch: 1 branch
BranchTrueFalseTotal
if ( DBIc_has(imp_xxh, DBIcf_ShowErrorStatement) 196 3191 3387
3978 196 ▶ && !is_unrelated_to_Statement
Branch: 1 branch
BranchTrueFalseTotal
&& !is_unrelated_to_Statement 166 30 196
3979 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
3980 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
3981 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
3982 ) {
3983 166 SV **svp = 0;
3984 166 sv_catpv(msg, " [for Statement \"");
3985 166 sv_catsv(msg, *statement_svp);
3986  
3987 /* fetch from tied outer handle to trigger FETCH magic */
3988 /* could add DBIcf_ShowErrorParams (default to on?) */
3989 166 ▶ if (!(ima_flags & IMA_HIDE_ERR_PARAMVALUES)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!(ima_flags & IMA_HIDE_ERR_PARAMVALUES)) { 158 8 166
3990 158 svp = hv_fetchs((HV*)DBIc_MY_H(imp_xxh),"ParamValues",FALSE);
3991 158 ▶ if (svp && SvMAGICAL(*svp))
Branch: 2 branches
BranchTrueFalseTotal
if (svp && SvMAGICAL(*svp)) 158 0 158
if (svp && SvMAGICAL(*svp)) 158 0 158
3992 158 mg_get(*svp); /* XXX may recurse, may croak. could use eval */
3993 }
3994 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
3995 8 SV *param_values_sv = sv_2mortal(_join_hash_sorted((HV*)SvRV(*svp), "=",1, ", ",2, 1, -1));
3996 8 sv_catpv(msg, "\" with ParamValues: ");
3997 8 sv_catsv(msg, param_values_sv);
3998 8 sv_catpvn(msg, "]", 1);
3999 }
4000 else {
4001 158 sv_catpv(msg, "\"]");
4002 }
4003 }
4004  
4005 if (0) {
4006 COP *cop = dbi_caller_cop();
4007 if (cop && (CopLINE(cop) != CopLINE(PL_curcop) || CopFILEGV(cop) != CopFILEGV(PL_curcop))) {
4008 dbi_caller_string(msg, cop, " called via ", 1, 0);
4009 }
4010 }
4011  
4012 3387 hook_svp = NULL;
4013 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
4014 3378 ▶ && DBIc_has(imp_xxh, DBIcf_HandleError)
Branch: 1 branch
BranchTrueFalseTotal
&& DBIc_has(imp_xxh, DBIcf_HandleError) 30 3348 3378
4015 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
4016 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
4017 ) {
4018 30 dSP;
4019 30 PerlIO *logfp = DBILOGFP;
4020 IV items;
4021 SV *status;
4022 SV *result; /* point to result SV that's pointed to by the stack */
4023 30 ▶ if (outitems) {
Branch: 1 branch
BranchTrueFalseTotal
if (outitems) { 30 0 30
4024 30 result = *(sp-outitems+1);
4025 30 ▶ if (SvREADONLY(result)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvREADONLY(result)) { 22 8 30
4026 22 *(sp-outitems+1) = result = sv_2mortal(newSVsv(result));
4027 }
4028 }
4029 else {
4030 0 result = sv_newmortal();
4031 }
4032 30 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 30 30
4033 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
4034 neatsvpv(h,0), neatsvpv(*hook_svp,0),
4035 (!outitems ? "" : " ("),
4036 0 (!outitems ? "" : neatsvpv(result ,0)),
4037 (!outitems ? "" : ")")
4038 );
4039 30 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 30 30
4040 30 ▶ XPUSHs(msg);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(msg); 0 30 30
4041 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
4042 30 ▶ XPUSHs( result );
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( result ); 0 30 30
4043 30 PUTBACK;
4044 30 items = call_sv(*hook_svp, G_SCALAR);
4045 28 MSPAGAIN;
4046 28 ▶ status = (items) ? POPs : &PL_sv_undef;
Branch: 1 branch
BranchTrueFalseTotal
status = (items) ? POPs : &PL_sv_undef; 28 0 28
4047 28 PUTBACK;
4048 28 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 28 28
4049 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
4050 neatsvpv(status,0),
4051 (!outitems ? "" : " ("),
4052 0 (!outitems ? "" : neatsvpv(result,0)),
4053 (!outitems ? "" : ")")
4054 );
4055 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
4056 16 hook_svp = 0; /* pretend we didn't have a handler... */
4057 }
4058  
4059 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
4060 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
4061 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
4062 profile_t1, dbi_time());
4063 }
4064 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
4065 13 ▶ if (DBIc_has(imp_xxh, DBIcf_PrintWarn))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_PrintWarn)) 9 4 13
4066 9 warn_sv(msg);
4067 13 ▶ if (DBIc_has(imp_xxh, DBIcf_RaiseWarn))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_RaiseWarn)) 4 9 13
4068 4 croak_sv(msg);
4069 }
4070 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
4071 3360 ▶ if (DBIc_has(imp_xxh, DBIcf_PrintError))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_PrintError)) 26 3334 3360
4072 26 warn_sv(msg);
4073 3360 ▶ if (DBIc_has(imp_xxh, DBIcf_RaiseError))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_has(imp_xxh, DBIcf_RaiseError)) 3154 206 3360
4074 3154 croak_sv(msg);
4075 }
4076 }
4077 547180 ▶ 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 486117 547180
4078 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
4079 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
4080 profile_t1, dbi_time());
4081 }
4082 547407 XSRETURN(outitems);
4083 }
4084  
4085  
4086  
4087 /* -------------------------------------------------------------------- */
4088  
4089 /* comment and placeholder styles to accept and return */
4090  
4091 #define DBIpp_cm_cs 0x000001 /* C style */
4092 #define DBIpp_cm_hs 0x000002 /* # */
4093 #define DBIpp_cm_dd 0x000004 /* -- */
4094 #define DBIpp_cm_br 0x000008 /* {} */
4095 #define DBIpp_cm_dw 0x000010 /* '-- ' dash dash whitespace */
4096 #define DBIpp_cm_XX 0x00001F /* any of the above */
4097  
4098 #define DBIpp_ph_qm 0x000100 /* ? */
4099 #define DBIpp_ph_cn 0x000200 /* :1 */
4100 #define DBIpp_ph_cs 0x000400 /* :name */
4101 #define DBIpp_ph_sp 0x000800 /* %s (as return only, not accept) */
4102 #define DBIpp_ph_XX 0x000F00 /* any of the above */
4103  
4104 #define DBIpp_st_qq 0x010000 /* '' char escape */
4105 #define DBIpp_st_bs 0x020000 /* \ char escape */
4106 #define DBIpp_st_XX 0x030000 /* any of the above */
4107  
4108 #define DBIpp_L_BRACE '{'
4109 #define DBIpp_R_BRACE '}'
4110 #define PS_accept(flag) DBIbf_has(ps_accept,(flag))
4111 #define PS_return(flag) DBIbf_has(ps_return,(flag))
4112  
4113 SV *
4114 60 preparse(SV *dbh, const char *statement, IV ps_return, IV ps_accept, void *foo)
4115 {
4116 dTHX;
4117 60 D_imp_xxh(dbh);
4118 /*
4119 The idea here is that ps_accept defines which constructs to
4120 recognize (accept) as valid in the source string (other
4121 constructs are ignored), and ps_return defines which
4122 constructs are valid to return in the result string.
4123  
4124 If a construct that is valid in the input is also valid in the
4125 output then it's simply copied. If it's not valid in the output
4126 then it's editied into one of the valid forms (ideally the most
4127 'standard' and/or information preserving one).
4128  
4129 For example, if ps_accept includes '--' style comments but
4130 ps_return doesn't, but ps_return does include '#' style
4131 comments then any '--' style comments would be rewritten as '#'
4132 style comments.
4133  
4134 Similarly for placeholders. DBD::Oracle, for example, would say
4135 '?', ':1' and ':name' are all acceptable input, but only
4136 ':name' should be returned.
4137  
4138 (There's a tricky issue with the '--' comment style because it can
4139 clash with valid syntax, i.e., "... set foo=foo--1 ..." so it
4140 would be *bad* to misinterpret that as the start of a comment.
4141 Perhaps we need a DBIpp_cm_dw (for dash-dash-whitespace) style
4142 to allow for that.)
4143  
4144 Also, we'll only support DBIpp_cm_br as an input style. And
4145 even then, only with reluctance. We may (need to) drop it when
4146 we add support for odbc escape sequences.
4147 */
4148 60 int idx = 1;
4149 STRLEN sln;
4150  
4151 60 char in_quote = '\0';
4152 60 char in_comment = '\0';
4153 60 char rt_comment = '\0';
4154 char *dest, *start;
4155 const char *src;
4156 60 const char *style = "", *laststyle = NULL;
4157 SV *new_stmt_sv;
4158  
4159 (void)foo;
4160  
4161 if (!(ps_return | DBIpp_ph_XX)) { /* no return ph type specified */
4162 ps_return |= ps_accept | DBIpp_ph_XX; /* so copy from ps_accept */
4163 }
4164  
4165 /* XXX this allocation strategy won't work when we get to more advanced stuff */
4166 /* The 7 is for length increase from '?' (length 1) to :p99999 (length 7)
4167 * which imposes a limit of 99999 '?' placeholders POSIX style. Actual counts
4168 * are a bit higher:
4169 * using factor 5: :p1 .. :p1107
4170 * using factor 6: :p1 .. :p11106
4171 * using factor 7: :p1 .. :p111105
4172 * and that count is insane already */
4173 60 sln = strlen(statement);
4174 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
4175 char buf[99];
4176 0 sprintf(buf, "preparse statement length exceeds maximum length (306783375).");
4177 0 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4178 0 return &PL_sv_undef;
4179 }
4180 60 new_stmt_sv = newSV(sln * 7 + 16);
4181 60 sv_setpv(new_stmt_sv,"");
4182 60 src = statement;
4183 60 dest = SvPVX(new_stmt_sv);
4184  
4185 724 ▶ while( *src )
Branch: 1 branch
BranchTrueFalseTotal
while( *src ) 676 48 724
4186 {
4187 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
4188 0 *dest++ = '%';
4189  
4190 676 ▶ if (in_comment)
Branch: 1 branch
BranchTrueFalseTotal
if (in_comment) 116 560 676
4191 {
4192 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
4193 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
4194 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
4195 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
4196 ) {
4197 28 switch (rt_comment) {
4198 4 case '/': *dest++ = '*'; *dest++ = '/'; break;
4199 4 case '-': *dest++ = '\n'; break;
4200 2 case '#': *dest++ = '\n'; break;
4201 8 case DBIpp_L_BRACE: *dest++ = DBIpp_R_BRACE; break;
4202 10 case '\0': /* ensure deleting a comment doesn't join two tokens */
4203 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
4204 4 *dest++ = ' '; /* ('-' and '#' styles use the newline) */
4205 10 break;
4206 }
4207 28 ▶ if (in_comment == '/')
Branch: 1 branch
BranchTrueFalseTotal
if (in_comment == '/') 10 18 28
4208 10 src++;
4209 /* Only inspect the previously-emitted byte if one exists;
4210 when an initial line comment is deleted, dest is still at
4211 the start of the output buffer and *(dest-1) would read
4212 one byte before it (OOB read). */
4213 56 src += (*src != '\n'
4214 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
4215 42 ▶ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
? 1 : 0; 14 14 28
4216 28 in_comment = '\0';
4217 28 rt_comment = '\0';
4218 }
4219 else
4220 88 ▶ if (rt_comment)
Branch: 1 branch
BranchTrueFalseTotal
if (rt_comment) 76 12 88
4221 76 *dest++ = *src++;
4222 else
4223 12 src++; /* delete (don't copy) the comment */
4224 116 continue;
4225 }
4226  
4227 560 ▶ if (in_quote)
Branch: 1 branch
BranchTrueFalseTotal
if (in_quote) 100 460 560
4228 {
4229 100 ▶ if (*src == in_quote) {
Branch: 1 branch
BranchTrueFalseTotal
if (*src == in_quote) { 8 92 100
4230 8 in_quote = 0;
4231 }
4232 100 *dest++ = *src++;
4233 100 continue;
4234 }
4235  
4236 /* Look for comments */
4237 460 ▶ if (*src == '-' && *(src+1) == '-' &&
Branch: 2 branches
BranchTrueFalseTotal
if (*src == '-' && *(src+1) == '-' && 8 452 460
if (*src == '-' && *(src+1) == '-' && 8 0 8
4238 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
4239 )
4240 {
4241 8 in_comment = *src;
4242 8 src += 2; /* skip past 2nd char of double char delimiters */
4243 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
4244 0 *dest++ = rt_comment = '-';
4245 0 *dest++ = '-';
4246 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
4247 0 *dest++ = ' '; /* insert needed white space */
4248 }
4249 8 ▶ else if (PS_return(DBIpp_cm_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_cs)) { 0 8 8
4250 0 *dest++ = rt_comment = '/';
4251 0 *dest++ = '*';
4252 }
4253 8 ▶ else if (PS_return(DBIpp_cm_hs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_hs)) { 0 8 8
4254 0 *dest++ = rt_comment = '#';
4255 }
4256 8 ▶ else if (PS_return(DBIpp_cm_br)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_br)) { 4 4 8
4257 4 *dest++ = rt_comment = DBIpp_L_BRACE;
4258 }
4259 8 continue;
4260 }
4261 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
4262 {
4263 12 in_comment = *src;
4264 12 src += 2; /* skip past 2nd char of double char delimiters */
4265 12 ▶ if (PS_return(DBIpp_cm_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_cs)) { 2 10 12
4266 2 *dest++ = rt_comment = '/';
4267 2 *dest++ = '*';
4268 }
4269 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
4270 2 *dest++ = rt_comment = '-';
4271 2 *dest++ = '-';
4272 2 ▶ if (PS_return(DBIpp_cm_dw)) *dest++ = ' ';
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_dw)) *dest++ = ' '; 2 0 2
4273 }
4274 8 ▶ else if (PS_return(DBIpp_cm_hs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_hs)) { 2 6 8
4275 2 *dest++ = rt_comment = '#';
4276 }
4277 6 ▶ else if (PS_return(DBIpp_cm_br)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_br)) { 4 2 6
4278 4 *dest++ = rt_comment = DBIpp_L_BRACE;
4279 }
4280 12 continue;
4281 }
4282 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
4283 {
4284 6 in_comment = *src;
4285 6 src++;
4286 6 ▶ if (PS_return(DBIpp_cm_hs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_hs)) { 0 6 6
4287 0 *dest++ = rt_comment = '#';
4288 }
4289 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
4290 2 *dest++ = rt_comment = '-';
4291 2 *dest++ = '-';
4292 2 ▶ if (PS_return(DBIpp_cm_dw)) *dest++ = ' ';
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_dw)) *dest++ = ' '; 2 0 2
4293 }
4294 4 ▶ else if (PS_return(DBIpp_cm_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_cs)) { 2 2 4
4295 2 *dest++ = rt_comment = '/';
4296 2 *dest++ = '*';
4297 }
4298 2 ▶ else if (PS_return(DBIpp_cm_br)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_br)) { 0 2 2
4299 0 *dest++ = rt_comment = DBIpp_L_BRACE;
4300 }
4301 6 continue;
4302 }
4303 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
4304 {
4305 6 in_comment = *src;
4306 6 src++;
4307 6 ▶ if (PS_return(DBIpp_cm_br)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_br)) { 2 4 6
4308 2 *dest++ = rt_comment = DBIpp_L_BRACE;
4309 }
4310 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
4311 0 *dest++ = rt_comment = '-';
4312 0 *dest++ = '-';
4313 0 ▶ if (PS_return(DBIpp_cm_dw)) *dest++ = ' ';
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_cm_dw)) *dest++ = ' '; 0 0 0
4314 }
4315 4 ▶ else if (PS_return(DBIpp_cm_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_cs)) { 2 2 4
4316 2 *dest++ = rt_comment = '/';
4317 2 *dest++ = '*';
4318 }
4319 2 ▶ else if (PS_return(DBIpp_cm_hs)) {
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_cm_hs)) { 0 2 2
4320 0 *dest++ = rt_comment = '#';
4321 }
4322 6 continue;
4323 }
4324  
4325 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
4326 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
4327 ){
4328 370 ▶ if (*src == '\'' || *src == '"')
Branch: 2 branches
BranchTrueFalseTotal
if (*src == '\'' || *src == '"') 364 6 370
if (*src == '\'' || *src == '"') 6 358 364
4329 12 in_quote = *src;
4330 370 *dest++ = *src++;
4331 370 continue;
4332 }
4333  
4334 /* only here for : or ? outside of a comment or literal */
4335  
4336 58 start = dest; /* save name inc colon */
4337 58 *dest++ = *src++; /* copy and move past first char */
4338  
4339 58 ▶ if (*start == '?') /* X/Open Standard */
Branch: 1 branch
BranchTrueFalseTotal
if (*start == '?') /* X/Open Standard */ 34 24 58
4340 {
4341 34 style = "?";
4342  
4343 34 ▶ if (PS_return(DBIpp_ph_qm))
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_ph_qm)) 34 0 34
4344 ;
4345 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
4346 32 ▶ if (idx >= 99999) {
Branch: 1 branch
BranchTrueFalseTotal
if (idx >= 99999) { 0 32 32
4347 char buf[99];
4348 0 sprintf(buf, "preparse found more than 99999 '?' placeholders. Limit exceeded.");
4349 0 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4350 0 return &PL_sv_undef;
4351 }
4352 32 sprintf(start,":p%d", idx++);
4353 32 dest = start+strlen(start);
4354 }
4355 2 ▶ else if (PS_return(DBIpp_ph_sp)) { /* '?' -> '%s' */
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_ph_sp)) { /* '?' -> '%s' */ 2 0 2
4356 2 *start = '%';
4357 2 *dest++ = 's';
4358 }
4359 }
4360 24 ▶ else if (isDIGIT(*src)) { /* :1 */
Branch: 1 branch
BranchTrueFalseTotal
else if (isDIGIT(*src)) { /* :1 */ 18 6 24
4361 18 const int pln = atoi(src);
4362  
4363 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
4364 char buf[99];
4365 6 sprintf(buf, "preparse found :p%d which is outside the allowed range.", pln);
4366 6 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4367 6 return &PL_sv_undef;
4368 }
4369  
4370 12 style = ":1";
4371  
4372 12 ▶ if (PS_return(DBIpp_ph_cn)) { /* ':1'-> ':p1' */
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_ph_cn)) { /* ':1'-> ':p1' */ 0 12 12
4373 0 idx = pln;
4374 0 *dest++ = 'p';
4375 0 ▶ while(isDIGIT(*src))
Branch: 1 branch
BranchTrueFalseTotal
while(isDIGIT(*src)) 0 0 0
4376 0 *dest++ = *src++;
4377 }
4378 12 ▶ else if (PS_return(DBIpp_ph_qm) /* ':1' -> '?' */
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_ph_qm) /* ':1' -> '?' */ 2 10 12
4379 2 ▶ || PS_return(DBIpp_ph_sp) /* ':1' -> '%s' */
Branch: 1 branch
BranchTrueFalseTotal
|| PS_return(DBIpp_ph_sp) /* ':1' -> '%s' */ 2 0 2
4380 ) {
4381 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
4382 12 dest = start + strlen(start);
4383 12 ▶ if (pln != idx) {
Branch: 1 branch
BranchTrueFalseTotal
if (pln != idx) { 4 8 12
4384 char buf[99];
4385 4 sprintf(buf, "preparse found placeholder :%d out of sequence, expected :%d", pln, idx);
4386 4 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4387 4 return &PL_sv_undef;
4388 }
4389 16 ▶ while(isDIGIT(*src)) src++;
Branch: 1 branch
BranchTrueFalseTotal
while(isDIGIT(*src)) src++; 8 8 16
4390 8 idx++;
4391 }
4392 }
4393 6 ▶ else if (isALNUM(*src)) /* :name */
Branch: 1 branch
BranchTrueFalseTotal
else if (isALNUM(*src)) /* :name */ 6 0 6
4394 {
4395 6 style = ":name";
4396  
4397 6 ▶ if (PS_return(DBIpp_ph_cs)) {
Branch: 1 branch
BranchTrueFalseTotal
if (PS_return(DBIpp_ph_cs)) { 6 0 6
4398 ;
4399 }
4400 6 ▶ else if (PS_return(DBIpp_ph_qm) /* ':name' -> '?' */
Branch: 1 branch
BranchTrueFalseTotal
else if (PS_return(DBIpp_ph_qm) /* ':name' -> '?' */ 2 4 6
4401 2 ▶ || PS_return(DBIpp_ph_sp) /* ':name' -> '%s' */
Branch: 1 branch
BranchTrueFalseTotal
|| PS_return(DBIpp_ph_sp) /* ':name' -> '%s' */ 2 0 2
4402 ) {
4403 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
4404 6 dest = start + strlen(start);
4405 32 ▶ while (isALNUM(*src)) /* consume name, includes '_' */
Branch: 1 branch
BranchTrueFalseTotal
while (isALNUM(*src)) /* consume name, includes '_' */ 26 6 32
4406 26 src++;
4407 }
4408 }
4409 /* perhaps ':=' PL/SQL construct */
4410 0 else { continue; }
4411  
4412 48 *dest = '\0'; /* handy for debugging */
4413  
4414 48 ▶ if (laststyle && style != laststyle) {
Branch: 2 branches
BranchTrueFalseTotal
if (laststyle && style != laststyle) { 18 30 48
if (laststyle && style != laststyle) { 2 16 18
4415 char buf[99];
4416 2 sprintf(buf, "preparse found mixed placeholder styles (%s / %s)", style, laststyle);
4417 2 set_err_char(dbh, imp_xxh, "1", 1, buf, 0, "preparse");
4418 2 return &PL_sv_undef;
4419 }
4420 46 laststyle = style;
4421 }
4422 48 *dest = '\0';
4423  
4424 /* warn about probable parsing errors, but continue anyway (returning processed string) */
4425 48 switch (in_quote)
4426 {
4427 2 case '\'':
4428 2 set_err_char(dbh, imp_xxh, "1", 1, "preparse found unterminated single-quoted string", 0, "preparse");
4429 2 break;
4430 2 case '\"':
4431 2 set_err_char(dbh, imp_xxh, "1", 1, "preparse found unterminated double-quoted string", 0, "preparse");
4432 2 break;
4433 }
4434 48 switch (in_comment)
4435 {
4436 2 case DBIpp_L_BRACE:
4437 2 set_err_char(dbh, imp_xxh, "1", 1, "preparse found unterminated bracketed {...} comment", 0, "preparse");
4438 2 break;
4439 2 case '/':
4440 2 set_err_char(dbh, imp_xxh, "1", 1, "preparse found unterminated bracketed C-style comment", 0, "preparse");
4441 2 break;
4442 }
4443  
4444 48 SvCUR_set(new_stmt_sv, strlen(SvPVX(new_stmt_sv)));
4445 48 *SvEND(new_stmt_sv) = '\0';
4446 48 return new_stmt_sv;
4447 }
4448  
4449  
4450 /* -------------------------------------------------------------------- */
4451 /* The DBI Perl interface (via XS) starts here. Currently these are */
4452 /* all internal support functions. Note install_method and see DBI.pm */
4453  
4454 MODULE = DBI PACKAGE = DBI
4455  
4456 REQUIRE: 1.929
4457 PROTOTYPES: DISABLE
4458  
4459  
4460 BOOT:
4461 {
4462 MY_CXT_INIT;
4463 PERL_UNUSED_VAR(MY_CXT);
4464 }
4465 PERL_UNUSED_VAR(cv);
4466 PERL_UNUSED_VAR(items);
4467 301 dbi_bootinit(NULL);
4468 /* make this sub into a fake XS so it can bee seen by DBD::* modules;
4469 * never actually call it as an XS sub, or it will crash and burn! */
4470 301 (void) newXS("DBI::_dbi_state_lval", (XSUBADDR_t)(void (*) (void))_dbi_state_lval, __FILE__);
4471  
4472  
4473 I32
4474 constant()
4475 PROTOTYPE:
4476 ALIAS:
4477 SQL_ALL_TYPES = SQL_ALL_TYPES
4478 SQL_ARRAY = SQL_ARRAY
4479 SQL_ARRAY_LOCATOR = SQL_ARRAY_LOCATOR
4480 SQL_BIGINT = SQL_BIGINT
4481 SQL_BINARY = SQL_BINARY
4482 SQL_BIT = SQL_BIT
4483 SQL_BLOB = SQL_BLOB
4484 SQL_BLOB_LOCATOR = SQL_BLOB_LOCATOR
4485 SQL_BOOLEAN = SQL_BOOLEAN
4486 SQL_CHAR = SQL_CHAR
4487 SQL_CLOB = SQL_CLOB
4488 SQL_CLOB_LOCATOR = SQL_CLOB_LOCATOR
4489 SQL_DATE = SQL_DATE
4490 SQL_DATETIME = SQL_DATETIME
4491 SQL_DECIMAL = SQL_DECIMAL
4492 SQL_DOUBLE = SQL_DOUBLE
4493 SQL_FLOAT = SQL_FLOAT
4494 SQL_GUID = SQL_GUID
4495 SQL_INTEGER = SQL_INTEGER
4496 SQL_INTERVAL = SQL_INTERVAL
4497 SQL_INTERVAL_DAY = SQL_INTERVAL_DAY
4498 SQL_INTERVAL_DAY_TO_HOUR = SQL_INTERVAL_DAY_TO_HOUR
4499 SQL_INTERVAL_DAY_TO_MINUTE = SQL_INTERVAL_DAY_TO_MINUTE
4500 SQL_INTERVAL_DAY_TO_SECOND = SQL_INTERVAL_DAY_TO_SECOND
4501 SQL_INTERVAL_HOUR = SQL_INTERVAL_HOUR
4502 SQL_INTERVAL_HOUR_TO_MINUTE = SQL_INTERVAL_HOUR_TO_MINUTE
4503 SQL_INTERVAL_HOUR_TO_SECOND = SQL_INTERVAL_HOUR_TO_SECOND
4504 SQL_INTERVAL_MINUTE = SQL_INTERVAL_MINUTE
4505 SQL_INTERVAL_MINUTE_TO_SECOND = SQL_INTERVAL_MINUTE_TO_SECOND
4506 SQL_INTERVAL_MONTH = SQL_INTERVAL_MONTH
4507 SQL_INTERVAL_SECOND = SQL_INTERVAL_SECOND
4508 SQL_INTERVAL_YEAR = SQL_INTERVAL_YEAR
4509 SQL_INTERVAL_YEAR_TO_MONTH = SQL_INTERVAL_YEAR_TO_MONTH
4510 SQL_LONGVARBINARY = SQL_LONGVARBINARY
4511 SQL_LONGVARCHAR = SQL_LONGVARCHAR
4512 SQL_MULTISET = SQL_MULTISET
4513 SQL_MULTISET_LOCATOR = SQL_MULTISET_LOCATOR
4514 SQL_NUMERIC = SQL_NUMERIC
4515 SQL_REAL = SQL_REAL
4516 SQL_REF = SQL_REF
4517 SQL_ROW = SQL_ROW
4518 SQL_SMALLINT = SQL_SMALLINT
4519 SQL_TIME = SQL_TIME
4520 SQL_TIMESTAMP = SQL_TIMESTAMP
4521 SQL_TINYINT = SQL_TINYINT
4522 SQL_TYPE_DATE = SQL_TYPE_DATE
4523 SQL_TYPE_TIME = SQL_TYPE_TIME
4524 SQL_TYPE_TIMESTAMP = SQL_TYPE_TIMESTAMP
4525 SQL_TYPE_TIMESTAMP_WITH_TIMEZONE = SQL_TYPE_TIMESTAMP_WITH_TIMEZONE
4526 SQL_TYPE_TIME_WITH_TIMEZONE = SQL_TYPE_TIME_WITH_TIMEZONE
4527 SQL_UDT = SQL_UDT
4528 SQL_UDT_LOCATOR = SQL_UDT_LOCATOR
4529 SQL_UNKNOWN_TYPE = SQL_UNKNOWN_TYPE
4530 SQL_VARBINARY = SQL_VARBINARY
4531 SQL_VARCHAR = SQL_VARCHAR
4532 SQL_WCHAR = SQL_WCHAR
4533 SQL_WLONGVARCHAR = SQL_WLONGVARCHAR
4534 SQL_WVARCHAR = SQL_WVARCHAR
4535 SQL_CURSOR_FORWARD_ONLY = SQL_CURSOR_FORWARD_ONLY
4536 SQL_CURSOR_KEYSET_DRIVEN = SQL_CURSOR_KEYSET_DRIVEN
4537 SQL_CURSOR_DYNAMIC = SQL_CURSOR_DYNAMIC
4538 SQL_CURSOR_STATIC = SQL_CURSOR_STATIC
4539 SQL_CURSOR_TYPE_DEFAULT = SQL_CURSOR_TYPE_DEFAULT
4540 DBIpp_cm_cs = DBIpp_cm_cs
4541 DBIpp_cm_hs = DBIpp_cm_hs
4542 DBIpp_cm_dd = DBIpp_cm_dd
4543 DBIpp_cm_dw = DBIpp_cm_dw
4544 DBIpp_cm_br = DBIpp_cm_br
4545 DBIpp_cm_XX = DBIpp_cm_XX
4546 DBIpp_ph_qm = DBIpp_ph_qm
4547 DBIpp_ph_cn = DBIpp_ph_cn
4548 DBIpp_ph_cs = DBIpp_ph_cs
4549 DBIpp_ph_sp = DBIpp_ph_sp
4550 DBIpp_ph_XX = DBIpp_ph_XX
4551 DBIpp_st_qq = DBIpp_st_qq
4552 DBIpp_st_bs = DBIpp_st_bs
4553 DBIpp_st_XX = DBIpp_st_XX
4554 DBIstcf_DISCARD_STRING = DBIstcf_DISCARD_STRING
4555 DBIstcf_STRICT = DBIstcf_STRICT
4556 DBIf_TRACE_SQL = DBIf_TRACE_SQL
4557 DBIf_TRACE_CON = DBIf_TRACE_CON
4558 DBIf_TRACE_ENC = DBIf_TRACE_ENC
4559 DBIf_TRACE_DBD = DBIf_TRACE_DBD
4560 DBIf_TRACE_TXN = DBIf_TRACE_TXN
4561 CODE:
4562 1374 ▶ RETVAL = ix;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = ix; 288 1086 1374
4563 OUTPUT:
4564 RETVAL
4565  
4566  
4567 void
4568 _clone_dbis()
4569 CODE:
4570 dMY_CXT;
4571 0 dbistate_t * parent_dbis = DBIS;
4572  
4573 (void)cv;
4574 {
4575 MY_CXT_CLONE;
4576 }
4577 0 dbi_bootinit(parent_dbis);
4578  
4579  
4580 void
4581 _new_handle(class, parent, attr_ref, imp_datasv, imp_class)
4582 SV * class
4583 SV * parent
4584 SV * attr_ref
4585 SV * imp_datasv
4586 SV * imp_class
4587 PPCODE:
4588 dMY_CXT;
4589 HV *outer;
4590 SV *outer_ref;
4591 9692 HV *class_stash = gv_stashsv(class, GV_ADDWARN);
4592  
4593 9692 ▶ if (DBIS_TRACE_LEVEL >= 5) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIS_TRACE_LEVEL >= 5) { 3 9689 9692
4594 6 PerlIO_printf(DBILOGFP, " New %s (for %s, parent=%s, id=%s)\n",
4595 neatsvpv(class,0), SvPV_nolen(imp_class), neatsvpv(parent,0), neatsvpv(imp_datasv,0));
4596 PERL_UNUSED_VAR(cv);
4597 }
4598  
4599 9692 (void)hv_stores((HV*)SvRV(attr_ref), "ImplementorClass", SvREFCNT_inc(imp_class));
4600  
4601 /* make attr into inner handle by blessing it into class */
4602 9692 sv_bless(attr_ref, class_stash);
4603 /* tie new outer hash to inner handle */
4604 9692 outer = newHV(); /* create new hash to be outer handle */
4605 9692 outer_ref = newRV_noinc((SV*)outer);
4606 /* make outer hash into a handle by blessing it into class */
4607 9692 sv_bless(outer_ref, class_stash);
4608 /* tie outer handle to inner handle */
4609 9692 sv_magic((SV*)outer, attr_ref, PERL_MAGIC_tied, Nullch, 0);
4610  
4611 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
4612  
4613 /* return outer handle, plus inner handle if not in scalar context */
4614 9690 sv_2mortal(outer_ref);
4615 9690 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 9690 9690
4616 9690 PUSHs(outer_ref);
4617 9690 ▶ if (GIMME_V != G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_SCALAR) { 8378 1312 9690
4618 8378 PUSHs(attr_ref);
4619 }
4620  
4621  
4622 void
4623 _setup_handle(sv, imp_class, parent, imp_datasv)
4624 SV * sv
4625 char * imp_class
4626 SV * parent
4627 SV * imp_datasv
4628 CODE:
4629 (void)cv;
4630 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
4631 0 ST(0) = &PL_sv_undef;
4632  
4633  
4634 void
4635 _get_imp_data(sv)
4636 SV * sv
4637 CODE:
4638 2 D_imp_xxh(sv);
4639 (void)cv;
4640 2 ST(0) = sv_mortalcopy(DBIc_IMP_DATA(imp_xxh)); /* okay if NULL */
4641  
4642  
4643 void
4644 _handles(sv)
4645 SV * sv
4646 PPCODE:
4647 /* return the outer and inner handle for any given handle */
4648 14 D_imp_xxh(sv);
4649 14 SV *ih = sv_mortalcopy( dbih_inner(aTHX_ sv, "_handles") );
4650 14 SV *oh = sv_2mortal(newRV_inc((SV*)DBIc_MY_H(imp_xxh))); /* XXX dangerous */
4651 (void)cv;
4652 14 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 14 14
4653 14 PUSHs(oh); /* returns outer handle then inner */
4654 14 ▶ if (GIMME_V != G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V != G_SCALAR) { 14 0 14
4655 14 PUSHs(ih);
4656 }
4657  
4658  
4659 void
4660 neat(sv, maxlen=0)
4661 SV * sv
4662 U32 maxlen
4663 CODE:
4664 389 ST(0) = sv_2mortal(newSVpv(neatsvpv(sv, maxlen), 0));
4665 (void)cv;
4666  
4667  
4668 I32
4669 hash(key, type=0)
4670 const char *key
4671 long type
4672 CODE:
4673 (void)cv;
4674 10 RETVAL = dbi_hash(key, type);
4675 OUTPUT:
4676 RETVAL
4677  
4678 void
4679 looks_like_number(...)
4680 PPCODE:
4681 int i;
4682 734 ▶ EXTEND(SP, items);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, items); 734 0 734
EXTEND(SP, items); 0 734 734
4683 (void)cv;
4684 1480 ▶ for(i=0; i < items ; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < items ; ++i) { 746 734 1480
4685 746 SV *sv = ST(i);
4686 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
4687 20 PUSHs(&PL_sv_undef);
4688 726 ▶ else if ( looks_like_number(sv) )
Branch: 1 branch
BranchTrueFalseTotal
else if ( looks_like_number(sv) ) 411 315 726
4689 411 PUSHs(&PL_sv_yes);
4690 else
4691 315 PUSHs(&PL_sv_no);
4692 }
4693  
4694  
4695 void
4696 _install_method(dbi_class, meth_name, file, attribs=Nullsv)
4697 const char * dbi_class
4698 char * meth_name
4699 char * file
4700 SV * attribs
4701 CODE:
4702 {
4703 dMY_CXT;
4704 /* install another method name/interface for the DBI dispatcher */
4705 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
4706 CV *cv;
4707 SV **svp;
4708 dbi_ima_t *ima;
4709 MAGIC *mg;
4710 (void)dbi_class;
4711  
4712 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
4713 0 croak("install_method %s: invalid class", meth_name);
4714  
4715 29135 ▶ if (trace_msg)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_msg) 0 29135 29135
4716 0 sv_catpvf(trace_msg, "install_method %-21s", meth_name);
4717  
4718 29135 Newxz(ima, 1, dbi_ima_t);
4719  
4720 29135 ▶ if (attribs && SvOK(attribs)) {
Branch: 2 branches
BranchTrueFalseTotal
if (attribs && SvOK(attribs)) { 29135 0 29135
if (attribs && SvOK(attribs)) { 27329 1806 29135
4721 /* convert and store method attributes in a fast access form */
4722 27329 ▶ if (SvTYPE(SvRV(attribs)) != SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
if (SvTYPE(SvRV(attribs)) != SVt_PVHV) 0 27329 27329
4723 0 croak("install_method %s: bad attribs", meth_name);
4724  
4725 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
4726 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
4727 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
4728  
4729 27329 ▶ if (trace_msg) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_msg) { 0 27329 27329
4730 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
4731 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
4732 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
4733 }
4734 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
4735 19565 AV *av = (AV*)SvRV(*svp);
4736 19565 ima->minargs = (U8)SvIV(*av_fetch(av, 0, 1));
4737 19565 ima->maxargs = (U8)SvIV(*av_fetch(av, 1, 1));
4738 19565 svp = av_fetch(av, 2, 0);
4739 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
4740 19565 ima->flags |= IMA_HAS_USAGE;
4741 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
4742 0 sv_catpvf(trace_msg, ",\n usage: min %d, max %d, '%s'",
4743 ima->minargs, ima->maxargs, ima->usage_msg);
4744 }
4745 }
4746 29135 ▶ if (trace_msg)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_msg) 0 29135 29135
4747 0 PerlIO_printf(DBILOGFP,"%s\n", SvPV_nolen(trace_msg));
4748 29135 file = savepv(file);
4749 29135 cv = newXS(meth_name, XS_DBI_dispatch, file);
4750 29135 SvPVX((SV *)cv) = file;
4751 29135 SvLEN((SV *)cv) = 1;
4752 29135 CvXSUBANY(cv).any_ptr = ima;
4753 29135 ima->meth_type = get_meth_type(GvNAME(CvGV(cv)));
4754  
4755 /* Attach magic to handle duping and freeing of the dbi_ima_t struct.
4756 * Due to the poor interface of the mg dup function, sneak a pointer
4757 * to the original CV in the mg_ptr field (we get called with a
4758 * pointer to the mg, but not the SV) */
4759 29135 mg = sv_magicext((SV*)cv, NULL, DBI_MAGIC, &dbi_ima_vtbl,
4760 (char *)cv, 0);
4761 29135 mg->mg_flags |= MGf_DUP;
4762 29135 ST(0) = &PL_sv_yes;
4763 }
4764  
4765  
4766 int
4767 trace(class, level_sv=&PL_sv_undef, file=Nullsv)
4768 SV * class
4769 SV * level_sv
4770 SV * file
4771 ALIAS:
4772 _debug_dispatch = 1
4773 CODE:
4774 {
4775 dMY_CXT;
4776 IV level;
4777 26 ▶ if (!DBIS) {
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIS) { 0 26 26
4778 PERL_UNUSED_VAR(ix);
4779 0 croak("DBI not initialised");
4780 }
4781 /* Return old/current value. No change if new value not given. */
4782 26 ▶ RETVAL = (DBIS) ? DBIS->debug : 0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = (DBIS) ? DBIS->debug : 0; 26 0 26
4783 26 level = parse_trace_flags(class, level_sv, RETVAL);
4784 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
4785 6 set_trace_file(file);
4786 26 ▶ if (level != RETVAL) {
Branch: 1 branch
BranchTrueFalseTotal
if (level != RETVAL) { 12 14 26
4787 12 ▶ if ((level & DBIc_TRACE_LEVEL_MASK) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ((level & DBIc_TRACE_LEVEL_MASK) > 0) { 6 6 12
4788 12 PerlIO_printf(DBILOGFP," DBI %s%s default trace level set to 0x%lx/%ld (pid %d pi %p) at %s\n",
4789 XS_VERSION, dbi_build_opt,
4790 (long)(level & DBIc_TRACE_FLAGS_MASK),
4791 (long)(level & DBIc_TRACE_LEVEL_MASK),
4792 6 (int)PerlProc_getpid(),
4793 #ifdef MULTIPLICITY
4794 (void *)my_perl,
4795 #else
4796 (void*)NULL,
4797 #endif
4798 log_where(Nullsv, 0, "", "", 1, 1, 0)
4799 );
4800 6 ▶ if (!PL_dowarn)
Branch: 1 branch
BranchTrueFalseTotal
if (!PL_dowarn) 0 6 6
4801 0 PerlIO_printf(DBILOGFP," Note: perl is running without the recommended perl -w option\n");
4802 6 PerlIO_flush(DBILOGFP);
4803 }
4804 12 DBIS->debug = level;
4805 12 sv_setiv(get_sv("DBI::dbi_debug",0x5), level);
4806 }
4807 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
4808 20 set_trace_file(file);
4809 }
4810 OUTPUT:
4811 RETVAL
4812  
4813  
4814  
4815 void
4816 dump_handle(sv, msg="DBI::dump_handle", level=0)
4817 SV * sv
4818 const char *msg
4819 int level
4820 CODE:
4821 (void)cv;
4822 4 dbih_dumphandle(aTHX_ sv, msg, level);
4823  
4824  
4825  
4826 void
4827 _svdump(sv)
4828 SV * sv
4829 CODE:
4830 {
4831 dMY_CXT;
4832 (void)cv;
4833 0 PerlIO_printf(DBILOGFP, "DBI::_svdump(%s)", neatsvpv(sv,0));
4834 #ifdef DEBUGGING
4835 sv_dump(sv);
4836 #endif
4837 }
4838  
4839  
4840 NV
4841 dbi_time()
4842  
4843  
4844 void
4845 dbi_profile(h, statement, method, t1, t2)
4846 SV *h
4847 SV *statement
4848 SV *method
4849 NV t1
4850 NV t2
4851 CODE:
4852 6 SV *leaf = &PL_sv_undef;
4853 PERL_UNUSED_VAR(cv);
4854 6 ▶ if (SvROK(method))
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(method)) 0 6 6
4855 0 method = SvRV(method);
4856 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
4857 4 D_imp_xxh(h);
4858 4 leaf = dbi_profile(h, imp_xxh, statement, method, t1, t2);
4859 }
4860 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
4861 /* iterate over values %$h */
4862 2 HV *hv = (HV*)SvRV(h);
4863 SV *tmp;
4864 char *key;
4865 2 I32 keylen = 0;
4866 2 hv_iterinit(hv);
4867 8 ▶ while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) {
Branch: 1 branch
BranchTrueFalseTotal
while ( (tmp = hv_iternextsv(hv, &key, &keylen)) != NULL ) { 4 2 6
4868 4 ▶ if (SvOK(tmp)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(tmp)) { 2 2 4
4869 2 D_imp_xxh(tmp);
4870 2 leaf = dbi_profile(tmp, imp_xxh, statement, method, t1, t2);
4871 }
4872 };
4873 }
4874 else {
4875 0 croak("dbi_profile(%s,...) invalid handle argument", neatsvpv(h,0));
4876 }
4877 6 ▶ if (GIMME_V == G_VOID)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_VOID) 4 2 6
4878 4 ST(0) = &PL_sv_undef; /* skip sv_mortalcopy if not needed */
4879 else
4880 2 ST(0) = sv_mortalcopy(leaf);
4881  
4882  
4883  
4884 SV *
4885 dbi_profile_merge_nodes(dest, ...)
4886 SV * dest
4887 ALIAS:
4888 dbi_profile_merge = 1
4889 CODE:
4890 {
4891 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
4892 0 croak("dbi_profile_merge_nodes(%s,...) destination is not an array reference", neatsvpv(dest,0));
4893 256 ▶ if (items <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (items <= 1) { 0 256 256
4894 PERL_UNUSED_VAR(cv);
4895 PERL_UNUSED_VAR(ix);
4896 0 RETVAL = 0;
4897 }
4898 else {
4899 /* items==2 for dest + 1 arg, ST(0) is dest, ST(1) is first arg */
4900 626 ▶ while (--items >= 1) {
Branch: 1 branch
BranchTrueFalseTotal
while (--items >= 1) { 370 256 626
4901 370 SV *thingy = ST(items);
4902 370 dbi_profile_merge_nodes(dest, thingy);
4903 }
4904 256 RETVAL = newSVsv(*av_fetch((AV*)SvRV(dest), DBIprof_TOTAL_TIME, 1));
4905 }
4906 }
4907 OUTPUT:
4908 RETVAL
4909  
4910  
4911 SV *
4912 _concat_hash_sorted(hash_sv, kv_sep_sv, pair_sep_sv, use_neat_sv, num_sort_sv)
4913 SV *hash_sv
4914 SV *kv_sep_sv
4915 SV *pair_sep_sv
4916 SV *use_neat_sv
4917 SV *num_sort_sv
4918 PREINIT:
4919 char *kv_sep, *pair_sep;
4920 STRLEN kv_sep_len, pair_sep_len;
4921 CODE:
4922 3330 ▶ if (!SvOK(hash_sv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(hash_sv)) 19 3311 3330
4923 19 XSRETURN_UNDEF;
4924 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
4925 2 croak("hash is not a hash reference");
4926  
4927 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
4928 3309 pair_sep = SvPV(pair_sep_sv, pair_sep_len);
4929  
4930 6618 RETVAL = _join_hash_sorted( (HV*)SvRV(hash_sv),
4931 kv_sep, kv_sep_len,
4932 pair_sep, pair_sep_len,
4933 /* use_neat should be undef, 0 or 1, may allow sprintf format strings later */
4934 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
4935 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
4936 );
4937 OUTPUT:
4938 RETVAL
4939  
4940  
4941 int
4942 sql_type_cast(sv, sql_type, flags=0)
4943 SV * sv
4944 int sql_type
4945 U32 flags
4946 CODE:
4947 54 RETVAL = sql_type_cast_svpv(aTHX_ sv, sql_type, flags, 0);
4948 OUTPUT:
4949 RETVAL
4950  
4951  
4952  
4953 MODULE = DBI PACKAGE = DBI::var
4954  
4955 void
4956 FETCH(sv)
4957 SV * sv
4958 CODE:
4959 dMY_CXT;
4960 /* Note that we do not come through the dispatcher to get here. */
4961 19374 char *meth = SvPV_nolen(SvRV(sv)); /* what should this tie do ? */
4962 19374 char type = *meth++; /* is this a $ or & style */
4963 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
4964 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
4965 19374 NV profile_t1 = 0.0;
4966  
4967 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
4968 12 profile_t1 = dbi_time();
4969  
4970 19374 ▶ if (trace_level >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 2) { 12 19362 19374
4971 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
4972 12 (imp_xxh) ? neatsvpv(DBI_LAST_HANDLE,0): "none");
4973 }
4974  
4975 19374 ▶ if (type == '!') { /* special case for $DBI::lasth */
Branch: 1 branch
BranchTrueFalseTotal
if (type == '!') { /* special case for $DBI::lasth */ 0 19374 19374
4976 /* Currently we can only return the INNER handle. */
4977 /* This handle should only be used for true/false tests */
4978 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
4979 }
4980 19374 ▶ else if ( !imp_xxh ) {
Branch: 1 branch
BranchTrueFalseTotal
else if ( !imp_xxh ) { 0 19374 19374
4981 0 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 0 0 0
4982 0 warn("Can't read $DBI::%s, last handle unknown or destroyed", meth);
4983 0 ST(0) = &PL_sv_undef;
4984 }
4985 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
4986 6528 SV *errsv = DBIc_ERR(imp_xxh);
4987 6528 ST(0) = sv_mortalcopy(errsv);
4988 }
4989 12846 ▶ else if (type == '"') { /* special case for $DBI::state */
Branch: 1 branch
BranchTrueFalseTotal
else if (type == '"') { /* special case for $DBI::state */ 6271 6575 12846
4990 6271 SV *state = DBIc_STATE(imp_xxh);
4991 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
4992 }
4993 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
4994 0 const char *vname = mkvname(aTHX_ DBIc_IMP_STASH(imp_xxh), meth, 0);
4995 0 SV *vsv = get_sv(vname, 1);
4996 0 ST(0) = sv_mortalcopy(vsv);
4997 }
4998 else {
4999 /* default to method call via stash of implementor of DBI_LAST_HANDLE */
5000 GV *imp_gv;
5001 6575 HV *imp_stash = DBIc_IMP_STASH(imp_xxh);
5002 #ifdef DBI_save_hv_fetch_ent
5003 HE save_mh = PL_hv_fetch_ent_mh; /* XXX nested tied FETCH bug17575 workaround */
5004 #endif
5005 6575 profile_t1 = 0.0; /* profile this via dispatch only (else we'll double count) */
5006 6575 ▶ if (trace_level >= 3)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level >= 3) 4 6571 6575
5007 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
5008 6575 ST(0) = sv_2mortal(newRV_inc(DBI_LAST_HANDLE));
5009 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
5010 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
5011 meth, meth, HvNAME(imp_stash));
5012 }
5013 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
5014 6575 call_sv((SV*)GvCV(imp_gv), GIMME_V);
5015 6575 SPAGAIN;
5016 #ifdef DBI_save_hv_fetch_ent
5017 PL_hv_fetch_ent_mh = save_mh;
5018 #endif
5019 }
5020 19374 ▶ if (trace_level)
Branch: 1 branch
BranchTrueFalseTotal
if (trace_level) 15 19359 19374
5021 15 PerlIO_printf(DBILOGFP," <- $DBI::%s= %s\n", meth, neatsvpv(ST(0),0));
5022 19374 ▶ if (profile_t1) {
Branch: 1 branch
BranchTrueFalseTotal
if (profile_t1) { 8 19366 19374
5023 8 SV *h = sv_2mortal(newRV_inc(DBI_LAST_HANDLE));
5024 8 dbi_profile(h, imp_xxh, &PL_sv_undef, (SV*)cv, profile_t1, dbi_time());
5025 }
5026  
5027  
5028 MODULE = DBI PACKAGE = DBD::_::dr
5029  
5030 void
5031 dbixs_revision(h)
5032 SV * h
5033 CODE:
5034 PERL_UNUSED_VAR(h);
5035 4 ST(0) = sv_2mortal(newSViv(DBIXS_REVISION));
5036  
5037  
5038 MODULE = DBI PACKAGE = DBD::_::db
5039  
5040 void
5041 connected(...)
5042 CODE:
5043 /* defined here just to avoid AUTOLOAD */
5044 (void)cv;
5045 (void)items;
5046 5998 ST(0) = &PL_sv_undef;
5047  
5048  
5049 SV *
5050 preparse(dbh, statement, ps_return, ps_accept, foo=Nullch)
5051 SV * dbh
5052 char * statement
5053 IV ps_return
5054 IV ps_accept
5055 void *foo
5056  
5057  
5058 void
5059 take_imp_data(h)
5060 SV * h
5061 PREINIT:
5062 /* take_imp_data currently in DBD::_::db not DBD::_::common, so for dbh's only */
5063 1 D_imp_xxh(h);
5064 MAGIC *mg;
5065 SV *imp_xxh_sv;
5066 SV **tmp_svp;
5067 CODE:
5068 PERL_UNUSED_VAR(cv);
5069 /*
5070 * Remove and return the imp_xxh_t structure that's attached to the inner
5071 * hash of the handle. Effectively this removes the 'brain' of the handle
5072 * leaving it as an empty shell - brain dead. All method calls on it fail.
5073 *
5074 * The imp_xxh_t structure that's removed and returned is a plain scalar
5075 * (containing binary data). It can be passed to a new DBI->connect call
5076 * in order to have the new $dbh use the same 'connection' as the original
5077 * handle. In this way a multi-threaded connection pool can be implemented.
5078 *
5079 * If the drivers imp_xxh_t structure contains SV*'s, or other interpreter
5080 * specific items, they should be freed by the drivers own take_imp_data()
5081 * method before it then calls SUPER::take_imp_data() to finalize removal
5082 * of the imp_xxh_t structure.
5083 *
5084 * The driver needs to view the take_imp_data method as being nearly the
5085 * same as disconnect+DESTROY only not actually calling the database API to
5086 * disconnect. All that needs to remain valid in the imp_xxh_t structure
5087 * is the underlying database API connection data. Everything else should
5088 * in a 'clean' state such that if the drivers own DESTROY method was
5089 * called it would be able to properly handle the contents of the
5090 * structure. This is important in case a new handle created using this
5091 * imp_data, possibly in a new thread, might end up being DESTROY'd before
5092 * the driver has had a chance to 're-setup' the data. See dbih_setup_handle()
5093 *
5094 * All the above relates to the 'typical use case' for a compiled driver.
5095 * For a pure-perl driver using a socket pair, for example, the drivers
5096 * take_imp_data method might just return a string containing the fileno()
5097 * values of the sockets (without calling this SUPER::take_imp_data() code).
5098 * The key point is that the take_imp_data() method returns an opaque buffer
5099 * containing whatever the driver would need to reuse the same underlying
5100 * 'connection to the database' in a new handle.
5101 *
5102 * In all cases, care should be taken that driver attributes (such as
5103 * AutoCommit) match the state of the underlying connection.
5104 */
5105  
5106 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
5107 0 set_err_char(h, imp_xxh, "1", 1, "Can't take_imp_data from handle that's not Active", 0, "take_imp_data");
5108 0 XSRETURN(0);
5109 }
5110  
5111 /* Ideally there should be no child statement handles existing when
5112 * take_imp_data is called because when those statement handles are
5113 * destroyed they may need to interact with the 'zombie' parent dbh.
5114 * So we do our best to neautralize them (finish & rebless)
5115 */
5116 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
5117 1 AV *av = (AV*)SvRV(*tmp_svp);
5118 1 HV *zombie_stash = gv_stashpv("DBI::zombie", GV_ADDWARN);
5119 I32 kidslots;
5120 4 ▶ for (kidslots = AvFILL(av); kidslots >= 0; --kidslots) {
Branch: 1 branch
BranchTrueFalseTotal
for (kidslots = AvFILL(av); kidslots >= 0; --kidslots) { 3 1 4
5121 3 SV **hp = av_fetch(av, kidslots, FALSE);
5122 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
5123 2 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 2 2
5124 2 ▶ XPUSHs(*hp);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(*hp); 0 2 2
5125 2 PUTBACK;
5126 2 call_method("finish", G_VOID);
5127 2 SPAGAIN;
5128 2 PUTBACK;
5129 2 sv_unmagic(SvRV(*hp), 'P'); /* untie */
5130 2 sv_bless(*hp, zombie_stash); /* neutralise */
5131 }
5132 }
5133 }
5134 /* The above measures may not be sufficient if weakrefs aren't available
5135 * or something has a reference to the inner-handle of an sth.
5136 * We'll require no Active kids, but just warn about others.
5137 */
5138 1 ▶ if (DBIc_ACTIVE_KIDS(imp_xxh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_ACTIVE_KIDS(imp_xxh)) { 0 1 1
5139 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");
5140 0 XSRETURN(0);
5141 }
5142 1 ▶ if (DBIc_KIDS(imp_xxh))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_KIDS(imp_xxh)) 0 1 1
5143 0 warn("take_imp_data from handle while it still has kids");
5144  
5145 /* it may be better here to return a copy and poison the original
5146 * rather than detatching and returning the original
5147 */
5148  
5149 /* --- perform the surgery */
5150 1 dbih_getcom2(aTHX_ h, &mg); /* get the MAGIC so we can change it */
5151 1 imp_xxh_sv = mg->mg_obj; /* take local copy of the imp_data pointer */
5152 1 mg->mg_obj = Nullsv; /* sever the link from handle to imp_xxh */
5153 1 mg->mg_ptr = NULL; /* and sever the shortcut too */
5154 1 ▶ if (DBIc_TRACE_LEVEL(imp_xxh) >= 9)
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_xxh) >= 9) 0 1 1
5155 0 sv_dump(imp_xxh_sv);
5156 /* --- housekeeping */
5157 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
5158 1 DBIc_IMPSET_off(imp_xxh); /* silence warning from dbih_clearcom */
5159 1 dbih_clearcom(imp_xxh); /* free SVs like DBD::_mem::common::DESTROY */
5160 1 SvOBJECT_off(imp_xxh_sv); /* no longer needs DESTROY via dbih_clearcom */
5161 /* restore flags to mark fact imp data holds active connection */
5162 /* (don't use magical DBIc_ACTIVE_on here) */
5163 1 DBIc_FLAGS(imp_xxh) |= DBIcf_IMPSET | DBIcf_ACTIVE;
5164 /* --- tidy up the raw PV for life as a more normal string */
5165 1 SvPOK_on(imp_xxh_sv); /* SvCUR & SvEND were set at creation */
5166 /* --- return the actual imp_xxh_sv on the stack */
5167 1 ST(0) = imp_xxh_sv;
5168  
5169  
5170  
5171 MODULE = DBI PACKAGE = DBD::_::st
5172  
5173 void
5174 _get_fbav(sth)
5175 SV * sth
5176 CODE:
5177 6 D_imp_sth(sth);
5178 6 AV *av = dbih_get_fbav(imp_sth);
5179 (void)cv;
5180 6 ST(0) = sv_2mortal(newRV_inc((SV*)av));
5181  
5182 void
5183 _set_fbav(sth, src_rv)
5184 SV * sth
5185 SV * src_rv
5186 CODE:
5187 105951 D_imp_sth(sth);
5188 int i;
5189 AV *src_av;
5190 105951 AV *dst_av = dbih_get_fbav(imp_sth);
5191 105951 int dst_fields = AvFILL(dst_av)+1;
5192 int src_fields;
5193 (void)cv;
5194  
5195 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
5196 0 croak("_set_fbav(%s): not an array ref", neatsvpv(src_rv,0));
5197 105951 src_av = (AV*)SvRV(src_rv);
5198 105951 src_fields = AvFILL(src_av)+1;
5199 105951 ▶ if (src_fields != dst_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_fields != dst_fields) { 0 105951 105951
5200 0 ▶ if ( dst_fields == 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ( dst_fields == 0 ) 0 0 0
5201 0 croak("_set_fbav(%s): array has %d elements, but the statement handle row buffer has 0",
5202 neatsvpv(src_rv,0), src_fields);
5203 0 warn("_set_fbav(%s): array has %d elements, the statement handle row buffer has %d (and NUM_OF_FIELDS is %d)",
5204 neatsvpv(src_rv,0), src_fields, dst_fields, DBIc_NUM_FIELDS(imp_sth));
5205 0 SvREADONLY_off(dst_av);
5206 0 ▶ if (src_fields < dst_fields) {
Branch: 1 branch
BranchTrueFalseTotal
if (src_fields < dst_fields) { 0 0 0
5207 /* shrink the array - sadly this looses column bindings for the lost columns */
5208 0 av_fill(dst_av, src_fields-1);
5209 0 dst_fields = src_fields;
5210 }
5211 else {
5212 0 av_fill(dst_av, src_fields-1);
5213 /* av_fill pads with immutable undefs which we need to change */
5214 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
5215 0 sv_setsv(AvARRAY(dst_av)[i], newSV(0));
5216 }
5217 }
5218 0 SvREADONLY_on(dst_av);
5219 }
5220 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
5221 /* If we're given the values, then taint them if required */
5222 314811 ▶ if (DBIc_is(imp_sth, DBIcf_TaintOut))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_is(imp_sth, DBIcf_TaintOut)) 3 314808 314811
5223 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
5224 314811 sv_setsv(AvARRAY(dst_av)[i], AvARRAY(src_av)[i]);
5225 }
5226 105951 ST(0) = sv_2mortal(newRV_inc((SV*)dst_av));
5227  
5228  
5229 void
5230 bind_col(sth, col, ref, attribs=Nullsv)
5231 SV * sth
5232 SV * col
5233 SV * ref
5234 SV * attribs
5235 PREINIT:
5236 SV *ret;
5237 CODE:
5238 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
5239 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
5240 156 ST(0) = ret;
5241 (void)cv;
5242  
5243  
5244 void
5245 fetchrow_array(sth)
5246 SV * sth
5247 ALIAS:
5248 fetchrow = 1
5249 PPCODE:
5250 SV *retsv;
5251 7 ▶ if (CvDEPTH(cv) == 99) {
Branch: 1 branch
BranchTrueFalseTotal
if (CvDEPTH(cv) == 99) { 0 7 7
5252 PERL_UNUSED_VAR(ix);
5253 0 croak("Deep recursion, probably fetchrow-fetch-fetchrow loop");
5254 }
5255 7 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 7 7
5256 7 ▶ XPUSHs(sth);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sth); 0 7 7
5257 7 PUTBACK;
5258 7 ▶ if (call_method("fetch", G_SCALAR) != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (call_method("fetch", G_SCALAR) != 1) 0 7 7
5259 0 croak("panic: DBI fetch"); /* should never happen */
5260 7 SPAGAIN;
5261 7 retsv = POPs;
5262 7 PUTBACK;
5263 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
5264 7 D_imp_sth(sth);
5265 int num_fields, i;
5266 AV *bound_av;
5267 7 AV *av = (AV*)SvRV(retsv);
5268 7 num_fields = AvFILL(av)+1;
5269 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
5270  
5271 /* We now check for bind_col() having been called but fetch */
5272 /* not returning the fields_svav array. Probably because the */
5273 /* driver is implemented in perl. XXX This logic may change later. */
5274 7 bound_av = DBIc_FIELDS_AV(imp_sth); /* bind_col() called ? */
5275 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
5276 /* let dbih_get_fbav know what's going on */
5277 0 bound_av = dbih_get_fbav(imp_sth);
5278 0 ▶ if (DBIc_TRACE_LEVEL(imp_sth) >= 3) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth) >= 3) { 0 0 0
5279 0 PerlIO_printf(DBIc_LOGPIO(imp_sth),
5280 "fetchrow: updating fbav 0x%lx from 0x%lx\n",
5281 (long)bound_av, (long)av);
5282 }
5283 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
5284 0 sv_setsv(AvARRAY(bound_av)[i], AvARRAY(av)[i]);
5285 }
5286 }
5287 28 ▶ for(i=0; i < num_fields; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(i=0; i < num_fields; ++i) { 21 7 28
5288 21 PUSHs(AvARRAY(av)[i]);
5289 }
5290 }
5291  
5292  
5293 SV *
5294 fetchrow_hashref(sth, keyattrib=Nullch)
5295 SV * sth
5296 const char *keyattrib
5297 PREINIT:
5298 SV *rowavr;
5299 SV *ka_rv;
5300 8958 D_imp_sth(sth);
5301 CODE:
5302 (void)cv;
5303 8958 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 8958 8958
5304 8958 ▶ XPUSHs(sth);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sth); 0 8958 8958
5305 8958 PUTBACK;
5306 8958 ▶ if (!keyattrib || !*keyattrib) {
Branch: 2 branches
BranchTrueFalseTotal
if (!keyattrib || !*keyattrib) { 4 8954 8958
if (!keyattrib || !*keyattrib) { 0 4 4
5307 8954 SV *kn = DBIc_FetchHashKeyName(imp_sth);
5308 8954 ▶ if (kn && SvOK(kn))
Branch: 2 branches
BranchTrueFalseTotal
if (kn && SvOK(kn)) 8954 0 8954
if (kn && SvOK(kn)) 8954 0 8954
5309 8954 keyattrib = SvPV_nolen(kn); /* Also force stringification */
5310 else
5311 0 keyattrib = "NAME";
5312 }
5313 8958 ka_rv = *hv_fetch((HV*)DBIc_MY_H(imp_sth), keyattrib,strlen(keyattrib), TRUE);
5314 /* we copy to invoke FETCH magic, and we do that before fetch() so if tainting */
5315 /* then the taint triggered by the fetch won't then apply to the fetched name */
5316 8958 ka_rv = newSVsv(ka_rv);
5317 8958 ▶ if (call_method("fetch", G_SCALAR) != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (call_method("fetch", G_SCALAR) != 1) 0 8958 8958
5318 0 croak("panic: DBI fetch"); /* should never happen */
5319 8958 SPAGAIN;
5320 8958 rowavr = POPs;
5321 8958 PUTBACK;
5322 /* have we got an array ref in rowavr */
5323 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
5324 int i;
5325 8854 AV *rowav = (AV*)SvRV(rowavr);
5326 8854 const int num_fields = AvFILL(rowav)+1;
5327 HV *hv;
5328 AV *ka_av;
5329 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
5330 4 sv_setiv(DBIc_ERR(imp_sth), 1);
5331 4 sv_setpvf(DBIc_ERRSTR(imp_sth),
5332 "Can't use attribute '%s' because it doesn't contain a reference to an array (%s)",
5333 keyattrib, neatsvpv(ka_rv,0));
5334 4 XSRETURN_UNDEF;
5335 }
5336 8850 ka_av = (AV*)SvRV(ka_rv);
5337 8850 hv = newHV();
5338 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
5339 26522 SV **field_name_svp = av_fetch(ka_av, i, 1);
5340 26522 (void)hv_store_ent(hv, *field_name_svp, newSVsv((SV*)(AvARRAY(rowav)[i])), 0);
5341 }
5342 8850 RETVAL = newRV_inc((SV*)hv);
5343 8850 SvREFCNT_dec(hv); /* since newRV incremented it */
5344 }
5345 else {
5346 104 RETVAL = &PL_sv_undef;
5347 }
5348 8954 SvREFCNT_dec(ka_rv); /* since we created it */
5349 OUTPUT:
5350 RETVAL
5351  
5352  
5353 void
5354 fetch(sth)
5355 SV * sth
5356 ALIAS:
5357 fetchrow_arrayref = 1
5358 CODE:
5359 int num_fields;
5360 0 ▶ if (CvDEPTH(cv) == 99) {
Branch: 1 branch
BranchTrueFalseTotal
if (CvDEPTH(cv) == 99) { 0 0 0
5361 PERL_UNUSED_VAR(ix);
5362 0 croak("Deep recursion. Probably fetch-fetchrow-fetch loop.");
5363 }
5364 0 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 0 0
5365 0 ▶ XPUSHs(sth);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sth); 0 0 0
5366 0 PUTBACK;
5367 0 num_fields = call_method("fetchrow", G_LIST); /* XXX change the name later */
5368 0 SPAGAIN;
5369 0 ▶ if (num_fields == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (num_fields == 0) { 0 0 0
5370 0 ST(0) = &PL_sv_undef;
5371 } else {
5372 0 D_imp_sth(sth);
5373 0 AV *av = dbih_get_fbav(imp_sth);
5374 0 ▶ if (num_fields != AvFILL(av)+1)
Branch: 1 branch
BranchTrueFalseTotal
if (num_fields != AvFILL(av)+1) 0 0 0
5375 0 croak("fetchrow returned %d fields, expected %d",
5376 num_fields, (int)AvFILL(av)+1);
5377 0 SPAGAIN;
5378 0 ▶ while(--num_fields >= 0)
Branch: 1 branch
BranchTrueFalseTotal
while(--num_fields >= 0) 0 0 0
5379 0 sv_setsv(AvARRAY(av)[num_fields], POPs);
5380 0 PUTBACK;
5381 0 ST(0) = sv_2mortal(newRV_inc((SV*)av));
5382 }
5383  
5384  
5385 void
5386 rows(sth)
5387 SV * sth
5388 CODE:
5389 5 D_imp_sth(sth);
5390 5 const IV rows = DBIc_ROW_COUNT(imp_sth);
5391 5 ST(0) = sv_2mortal(newSViv(rows));
5392 (void)cv;
5393  
5394  
5395 void
5396 finish(sth)
5397 SV * sth
5398 CODE:
5399 14424 D_imp_sth(sth);
5400 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
5401 14424 ST(0) = &PL_sv_yes;
5402 (void)cv;
5403  
5404  
5405 void
5406 DESTROY(sth)
5407 SV * sth
5408 PPCODE:
5409 /* keep in sync with DESTROY in Driver.xst */
5410 5335 D_imp_sth(sth);
5411 5335 ST(0) = &PL_sv_yes;
5412 /* we don't test IMPSET here because this code applies to pure-perl drivers */
5413 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
5414 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
5415 0 ▶ if (DBIc_TRACE_LEVEL(imp_sth))
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_TRACE_LEVEL(imp_sth)) 0 0 0
5416 0 PerlIO_printf(DBIc_LOGPIO(imp_sth), " DESTROY %s skipped due to InactiveDestroy\n", SvPV_nolen(sth));
5417 }
5418 5335 ▶ if (DBIc_ACTIVE(imp_sth)) {
Branch: 1 branch
BranchTrueFalseTotal
if (DBIc_ACTIVE(imp_sth)) { 7 5328 5335
5419 7 D_imp_dbh_from_sth;
5420 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
5421 7 dSP;
5422 7 ▶ PUSHMARK(sp);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(sp); 0 7 7
5423 7 ▶ XPUSHs(sth);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sth); 0 7 7
5424 7 PUTBACK;
5425 7 call_method("finish", G_SCALAR);
5426 7 SPAGAIN;
5427 7 PUTBACK;
5428 }
5429 else {
5430 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
5431 }
5432 }
5433  
5434  
5435 MODULE = DBI PACKAGE = DBI::st
5436  
5437 void
5438 TIEHASH(class, inner_ref)
5439 SV * class
5440 SV * inner_ref
5441 CODE:
5442 0 HV *stash = gv_stashsv(class, GV_ADDWARN); /* a new hash is supplied to us, we just need to bless and apply tie magic */
5443 0 sv_bless(inner_ref, stash);
5444 0 ST(0) = inner_ref;
5445  
5446 MODULE = DBI PACKAGE = DBD::_::common
5447  
5448  
5449 void
5450 DESTROY(h)
5451 SV * h
5452 CODE:
5453 /* DESTROY defined here just to avoid AUTOLOAD */
5454 (void)cv;
5455 (void)h;
5456 580 ST(0) = &PL_sv_undef;
5457  
5458  
5459 void
5460 STORE(h, keysv, valuesv)
5461 SV * h
5462 SV * keysv
5463 SV * valuesv
5464 CODE:
5465 79870 ST(0) = &PL_sv_yes;
5466 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
5467 50 ST(0) = &PL_sv_no;
5468 (void)cv;
5469  
5470  
5471 void
5472 FETCH(h, keysv)
5473 SV * h
5474 SV * keysv
5475 PREINIT:
5476 SV *ret;
5477 CODE:
5478 45160 ret = dbih_get_attr_k(h, keysv, 0);
5479 45160 ST(0) = ret;
5480 (void)cv;
5481  
5482 void
5483 DELETE(h, keysv)
5484 SV * h
5485 SV * keysv
5486 PREINIT:
5487 SV *ret;
5488 CODE:
5489 /* only private_* keys can be deleted, for others DELETE acts like FETCH */
5490 /* because the DBI internals rely on certain handle attributes existing */
5491 5 ▶ if (strnEQ(SvPV_nolen(keysv),"private_",8))
Branch: 1 branch
BranchTrueFalseTotal
if (strnEQ(SvPV_nolen(keysv),"private_",8)) 2 3 5
5492 2 ret = hv_delete_ent((HV*)SvRV(h), keysv, 0, 0);
5493 else
5494 3 ret = dbih_get_attr_k(h, keysv, 0);
5495 5 ST(0) = ret;
5496 (void)cv;
5497  
5498  
5499 void
5500 private_data(h)
5501 SV * h
5502 CODE:
5503 0 D_imp_xxh(h);
5504 (void)cv;
5505 0 ST(0) = sv_mortalcopy(DBIc_IMP_DATA(imp_xxh));
5506  
5507  
5508 void
5509 err(h)
5510 SV * h
5511 CODE:
5512 101 D_imp_xxh(h);
5513 101 SV *errsv = DBIc_ERR(imp_xxh);
5514 (void)cv;
5515 101 ST(0) = sv_mortalcopy(errsv);
5516  
5517 void
5518 state(h)
5519 SV * h
5520 CODE:
5521 10 D_imp_xxh(h);
5522 10 SV *state = DBIc_STATE(imp_xxh);
5523 (void)cv;
5524 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
5525  
5526 void
5527 errstr(h)
5528 SV * h
5529 CODE:
5530 6691 D_imp_xxh(h);
5531 6691 SV *errstr = DBIc_ERRSTR(imp_xxh);
5532 SV *err;
5533 /* If there's no errstr but there is an err then use err */
5534 (void)cv;
5535 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
5536 0 errstr = err;
5537 6691 ST(0) = sv_mortalcopy(errstr);
5538  
5539  
5540 void
5541 set_err(h, err, errstr=&PL_sv_no, state=&PL_sv_undef, method=&PL_sv_undef, result=Nullsv)
5542 SV * h
5543 SV * err
5544 SV * errstr
5545 SV * state
5546 SV * method
5547 SV * result
5548 PPCODE:
5549 {
5550 9532 D_imp_xxh(h);
5551 SV **sem_svp;
5552 (void)cv;
5553  
5554 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
5555 38 method = sv_mortalcopy(method); /* HandleSetErr may want to change it */
5556  
5557 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
5558 /* set_err was canceled by HandleSetErr, */
5559 /* don't set "dbi_set_err_method", return an empty list */
5560 }
5561 else {
5562 /* store provided method name so handler code can find it */
5563 9530 sem_svp = hv_fetchs((HV*)SvRV(h), "dbi_set_err_method", 1);
5564 9530 ▶ if (SvOK(method)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvOK(method)) { 6 9524 9530
5565 6 sv_setpv(*sem_svp, SvPV_nolen(method));
5566 }
5567 else
5568 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
5569 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
5570 }
5571 /* We don't check RaiseError and call die here because that must be */
5572 /* done by returning through dispatch and letting the DBI handle it */
5573 }
5574  
5575  
5576 int
5577 trace(h, level=&PL_sv_undef, file=Nullsv)
5578 SV *h
5579 SV *level
5580 SV *file
5581 ALIAS:
5582 debug = 1
5583 CODE:
5584 66 RETVAL = set_trace(h, level, file);
5585 (void)cv; /* Unused variables */
5586 (void)ix;
5587 OUTPUT:
5588 RETVAL
5589  
5590  
5591 void
5592 trace_msg(sv, msg, this_trace=1)
5593 SV *sv
5594 const char *msg
5595 int this_trace
5596 PREINIT:
5597 int current_trace;
5598 PerlIO *pio;
5599 CODE:
5600 {
5601 dMY_CXT;
5602 (void)cv;
5603 27584 ▶ if (SvROK(sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvROK(sv)) { 5522 22062 27584
5604 5522 D_imp_xxh(sv);
5605 5522 current_trace = DBIc_TRACE_LEVEL(imp_xxh);
5606 5522 pio = DBIc_LOGPIO(imp_xxh);
5607 }
5608 else { /* called as a static method */
5609 22062 current_trace = DBIS_TRACE_FLAGS;
5610 22062 pio = DBILOGFP;
5611 }
5612 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
5613 100 PerlIO_puts(pio, msg);
5614 100 ST(0) = &PL_sv_yes;
5615 }
5616 else {
5617 27484 ST(0) = &PL_sv_no;
5618 }
5619 }
5620  
5621  
5622 void
5623 rows(h)
5624 SV * h
5625 CODE:
5626 /* fallback esp for $DBI::rows after $drh was last used */
5627 0 ST(0) = sv_2mortal(newSViv(-1));
5628 (void)h;
5629 (void)cv;
5630  
5631  
5632 void
5633 swap_inner_handle(rh1, rh2, allow_reparent=0)
5634 SV * rh1
5635 SV * rh2
5636 IV allow_reparent
5637 CODE:
5638 {
5639 14 D_impdata(imp_xxh1, imp_xxh_t, rh1);
5640 14 D_impdata(imp_xxh2, imp_xxh_t, rh2);
5641 14 SV *h1i = dbih_inner(aTHX_ rh1, "swap_inner_handle");
5642 14 SV *h2i = dbih_inner(aTHX_ rh2, "swap_inner_handle");
5643 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
5644 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
5645 (void)cv;
5646  
5647 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
5648 char buf[99];
5649 6 sprintf(buf, "Can't swap_inner_handle between %sh and %sh",
5650 2 dbih_htype_name(DBIc_TYPE(imp_xxh1)), dbih_htype_name(DBIc_TYPE(imp_xxh2)));
5651 2 DBIh_SET_ERR_CHAR(rh1, imp_xxh1, "1", 1, buf, Nullch, Nullch);
5652 2 XSRETURN_NO;
5653 }
5654 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
5655 2 DBIh_SET_ERR_CHAR(rh1, imp_xxh1, "1", 1,
5656 "Can't swap_inner_handle with handle from different parent",
5657 Nullch, Nullch);
5658 2 XSRETURN_NO;
5659 }
5660  
5661 10 (void)SvREFCNT_inc(h1i);
5662 10 (void)SvREFCNT_inc(h2i);
5663  
5664 10 sv_unmagic(h1, 'P'); /* untie(%$h1) */
5665 10 sv_unmagic(h2, 'P'); /* untie(%$h2) */
5666  
5667 10 sv_magic(h1, h2i, 'P', Nullch, 0); /* tie %$h1, $h2i */
5668 10 DBIc_MY_H(imp_xxh2) = (HV*)h1;
5669  
5670 10 sv_magic(h2, h1i, 'P', Nullch, 0); /* tie %$h2, $h1i */
5671 10 DBIc_MY_H(imp_xxh1) = (HV*)h2;
5672  
5673 10 SvREFCNT_dec(h1i);
5674 10 SvREFCNT_dec(h2i);
5675  
5676 10 ST(0) = &PL_sv_yes;
5677 }
5678  
5679  
5680 MODULE = DBI PACKAGE = DBD::_mem::common
5681  
5682 void
5683 DESTROY(imp_xxh_rv)
5684 SV * imp_xxh_rv
5685 CODE:
5686 /* ignore 'cast increases required alignment' warning */
5687 9685 imp_xxh_t *imp_xxh = (imp_xxh_t*)SvPVX(SvRV(imp_xxh_rv));
5688 9685 DBIc_DBISTATE(imp_xxh)->clearcom(imp_xxh);
5689 (void)cv;
5690  
5691 # end
« dbilogstrip.PL ↑ Summary blib/lib/DBI/ProfileSubs.pm »