DBI.xs

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