dbdimp_virtual_table.inc

filter: Statementstmt 83.7% 401 / 479 Branchbran 55.9% 142 / 254 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.0% 543 / 733 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« SQLite.xsi ↑ Summary dbdimp.c »
1 /***********************************************************************
2 ** The set of routines that implement the perl "module"
3 ** (i.e support for virtual tables written in Perl)
4 ************************************************************************/
5  
6 typedef struct perl_vtab {
7 sqlite3_vtab base;
8 SV *perl_vtab_obj;
9 HV *functions;
10 } perl_vtab;
11  
12 typedef struct perl_vtab_cursor {
13 sqlite3_vtab_cursor base;
14 SV *perl_cursor_obj;
15 } perl_vtab_cursor;
16  
17 typedef struct perl_vtab_init {
18 SV *dbh;
19 const char *perl_class;
20 } perl_vtab_init;
21  
22  
23  
24 /* auxiliary routine for generalized method calls. Arg "i" may be unused */
25 62 static int _call_perl_vtab_method(sqlite3_vtab *pVTab,
26 const char *method, int i) {
27 dTHX;
28 62 dSP;
29 int count;
30  
31 62 ENTER;
32 62 SAVETMPS;
33  
34 62 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 62 62
35 62 ▶ XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj); 0 62 62
36 62 ▶ XPUSHs(sv_2mortal(newSViv(i)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(i))); 0 62 62
37 62 PUTBACK;
38 62 count = call_method (method, G_VOID);
39 62 SPAGAIN;
40 62 SP -= count;
41  
42 62 PUTBACK;
43 62 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 62 0 62
44 62 LEAVE;
45  
46 62 return SQLITE_OK;
47 }
48  
49  
50 /* RT-124941: it seems better to prefer PV where appropriate */
51 static void
52 931 sqlite_set_result_for_vtable(pTHX_ sqlite3_context *context, SV *result, int is_error)
53 {
54 STRLEN len;
55 char *s;
56 sqlite3_int64 iv;
57  
58 931 ▶ if ( is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( is_error ) { 0 931 931
59 0 s = SvPV(result, len);
60 0 sqlite3_result_error( context, s, len );
61 0 return;
62 }
63  
64 /* warn("result: %s\n", SvPV_nolen(result)); */
65 931 ▶ if ( !SvOK(result) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !SvOK(result) ) { 5 926 931
66 5 sqlite3_result_null( context );
67 926 ▶ } else if ( SvPOK(result) ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( SvPOK(result) ) { 840 86 926
68 840 s = SvPV(result, len);
69 840 sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
70 86 ▶ } else if( SvIOK_UV(result) ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if( SvIOK_UV(result) ) { 0 86 86
71 if ((UV)(sqlite3_int64)UV_MAX == UV_MAX)
72 0 sqlite3_result_int64( context, (sqlite3_int64)SvUV(result));
73 else {
74 s = SvPV(result, len);
75 sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
76 }
77 86 ▶ } else if ( !_sqlite_atoi64(SvPV(result, len), &iv) ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( !_sqlite_atoi64(SvPV(result, len), &iv) ) { 86 0 86
78 86 sqlite3_result_int64( context, iv );
79 0 ▶ } else if ( SvNOK(result) && ( sizeof(NV) == sizeof(double) || SvNVX(result) == (double) SvNVX(result) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( SvNOK(result) && ( sizeof(NV) == sizeof(double) || SvNVX(result) == (double) SvNVX(result) ) ) { 0 0 0
80 0 sqlite3_result_double( context, SvNV(result));
81 } else {
82 0 s = SvPV(result, len);
83 0 sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
84 }
85 }
86  
87  
88  
89 19 static int perl_vt_New(const char *method,
90 sqlite3 *db, void *pAux,
91 int argc, const char *const *argv,
92 sqlite3_vtab **ppVTab, char **pzErr){
93 dTHX;
94 19 dSP;
95 perl_vtab *vt;
96 19 perl_vtab_init *init_data = (perl_vtab_init *)pAux;
97 int count, i;
98 19 int rc = SQLITE_ERROR;
99 SV *perl_vtab_obj;
100 SV *sql;
101  
102 /* allocate a perl_vtab structure */
103 19 vt = (perl_vtab *) sqlite3_malloc(sizeof(*vt));
104 19 ▶ if( vt==NULL ) return SQLITE_NOMEM;
Branch: 1 branch
BranchTrueFalseTotal
if( vt==NULL ) return SQLITE_NOMEM; 0 19 19
105 19 memset(vt, 0, sizeof(*vt));
106 19 vt->functions = newHV();
107  
108 19 ENTER;
109 19 SAVETMPS;
110  
111 /* call the ->CREATE/CONNECT() method */
112 19 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 19 19
113 19 ▶ XPUSHs(sv_2mortal(newSVpv(init_data->perl_class, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(init_data->perl_class, 0))); 0 19 19
114 19 ▶ XPUSHs(init_data->dbh);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(init_data->dbh); 0 19 19
115 127 ▶ for(i = 0; i < argc; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < argc; i++) { 108 19 127
116 108 ▶ XPUSHs(newSVpvn_flags(argv[i], strlen(argv[i]), SVs_TEMP|SVf_UTF8));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(newSVpvn_flags(argv[i], strlen(argv[i]), SVs_TEMP|SVf_UTF8)); 0 108 108
117 }
118 19 PUTBACK;
119 19 count = call_method (method, G_SCALAR);
120 19 SPAGAIN;
121  
122 /* check the return value */
123 19 ▶ if ( count != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( count != 1 ) { 0 19 19
124 0 *pzErr = sqlite3_mprintf("vtab->%s() should return one value, got %d",
125 method, count );
126 0 SP -= count; /* Clear the stack */
127 0 goto cleanup;
128 }
129  
130 /* get the VirtualTable instance */
131 19 perl_vtab_obj = POPs;
132 19 ▶ if ( !sv_isobject(perl_vtab_obj) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !sv_isobject(perl_vtab_obj) ) { 0 19 19
133 0 *pzErr = sqlite3_mprintf("vtab->%s() should return a blessed reference",
134 method);
135 0 goto cleanup;
136 }
137  
138 /* call the ->VTAB_TO_DECLARE() method */
139 19 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 19 19
140 19 ▶ XPUSHs(perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(perl_vtab_obj); 0 19 19
141 19 PUTBACK;
142 19 count = call_method ("VTAB_TO_DECLARE", G_SCALAR);
143 19 SPAGAIN;
144  
145 /* check the return value */
146 19 ▶ if (count != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1 ) { 0 19 19
147 0 *pzErr = sqlite3_mprintf("vtab->VTAB_TO_DECLARE() should return one value, got %d",
148 count );
149 0 SP -= count; /* Clear the stack */
150 0 goto cleanup;
151 }
152  
153 /* call sqlite3_declare_vtab with the sql returned from
154 method VTAB_TO_DECLARE(), converted to utf8 */
155 19 sql = POPs;
156 19 rc = sqlite3_declare_vtab(db, SvPVutf8_nolen(sql));
157  
158 19 cleanup:
159 19 ▶ if (rc == SQLITE_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rc == SQLITE_OK) { 19 0 19
160 /* record the VirtualTable perl instance within the vtab structure */
161 19 vt->perl_vtab_obj = SvREFCNT_inc(perl_vtab_obj);
162 19 *ppVTab = &vt->base;
163 }
164 else {
165 0 sqlite3_free(vt);
166 }
167  
168 19 PUTBACK;
169 19 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 19 0 19
170 19 LEAVE;
171  
172 19 return rc;
173 }
174  
175  
176 17 static int perl_vt_Create(sqlite3 *db, void *pAux,
177 int argc, const char *const *argv,
178 sqlite3_vtab **ppVTab, char **pzErr){
179 17 return perl_vt_New("CREATE", db, pAux, argc, argv, ppVTab, pzErr);
180 }
181  
182 2 static int perl_vt_Connect(sqlite3 *db, void *pAux,
183 int argc, const char *const *argv,
184 sqlite3_vtab **ppVTab, char **pzErr){
185 2 return perl_vt_New("CONNECT", db, pAux, argc, argv, ppVTab, pzErr);
186 }
187  
188  
189 19 static int _free_perl_vtab(perl_vtab *pVTab){
190 dTHX;
191  
192 19 SvREFCNT_dec(pVTab->perl_vtab_obj);
193  
194 /* deallocate coderefs that were declared through FindFunction() */
195 19 hv_undef(pVTab->functions);
196 19 SvREFCNT_dec(pVTab->functions);
197  
198 19 sqlite3_free(pVTab);
199 19 return SQLITE_OK;
200 }
201  
202 17 static int perl_vt_Disconnect(sqlite3_vtab *pVTab){
203 17 _call_perl_vtab_method(pVTab, "DISCONNECT", 0);
204 17 return _free_perl_vtab((perl_vtab *)pVTab);
205 }
206  
207 2 static int perl_vt_Drop(sqlite3_vtab *pVTab){
208 2 _call_perl_vtab_method(pVTab, "DROP", 0);
209 2 return _free_perl_vtab((perl_vtab *)pVTab);
210 }
211  
212  
213 static char *
214 62 _constraint_op_to_string(unsigned char op) {
215 62 switch (op) {
216 25 case SQLITE_INDEX_CONSTRAINT_EQ:
217 25 return "=";
218 2 case SQLITE_INDEX_CONSTRAINT_GT:
219 2 return ">";
220 1 case SQLITE_INDEX_CONSTRAINT_GE:
221 1 return ">=";
222 4 case SQLITE_INDEX_CONSTRAINT_LT:
223 4 return "<";
224 1 case SQLITE_INDEX_CONSTRAINT_LE:
225 1 return "<=";
226 20 case SQLITE_INDEX_CONSTRAINT_MATCH:
227 20 return "MATCH";
228 #if SQLITE_VERSION_NUMBER >= 3010000
229 2 case SQLITE_INDEX_CONSTRAINT_LIKE:
230 2 return "LIKE";
231 0 case SQLITE_INDEX_CONSTRAINT_GLOB:
232 0 return "GLOB";
233 1 case SQLITE_INDEX_CONSTRAINT_REGEXP:
234 1 return "REGEXP";
235 #endif
236 #if SQLITE_VERSION_NUMBER >= 3021000
237 0 case SQLITE_INDEX_CONSTRAINT_NE:
238 0 return "NE";
239 1 case SQLITE_INDEX_CONSTRAINT_ISNOT:
240 1 return "ISNOT";
241 2 case SQLITE_INDEX_CONSTRAINT_ISNOTNULL:
242 2 return "ISNOTNULL";
243 2 case SQLITE_INDEX_CONSTRAINT_ISNULL:
244 2 return "ISNULL";
245 1 case SQLITE_INDEX_CONSTRAINT_IS:
246 1 return "IS";
247 #endif
248 0 default:
249 0 return "unknown";
250 }
251 }
252  
253  
254 72 static int perl_vt_BestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pIdxInfo){
255 dTHX;
256 72 dSP;
257 int i, count;
258 int argvIndex;
259 AV *constraints;
260 AV *order_by;
261 SV *hashref;
262 SV **val;
263 HV *hv;
264 struct sqlite3_index_constraint_usage *pConsUsage;
265  
266 72 ENTER;
267 72 SAVETMPS;
268  
269 /* build the "where_constraints" datastructure */
270 72 constraints = newAV();
271 134 ▶ for (i=0; i<pIdxInfo->nConstraint; i++){
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<pIdxInfo->nConstraint; i++){ 62 72 134
272 62 struct sqlite3_index_constraint const *pCons = &pIdxInfo->aConstraint[i];
273 62 HV *constraint = newHV();
274 62 char *op_str = _constraint_op_to_string(pCons->op);
275 62 hv_stores(constraint, "col", newSViv(pCons->iColumn));
276 62 hv_stores(constraint, "op", newSVpv(op_str, 0));
277 62 ▶ hv_stores(constraint, "usable", pCons->usable ? &PL_sv_yes : &PL_sv_no);
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(constraint, "usable", pCons->usable ? &PL_sv_yes : &PL_sv_no); 58 4 62
278 62 av_push(constraints, newRV_noinc((SV*) constraint));
279 }
280  
281 /* build the "order_by" datastructure */
282 72 order_by = newAV();
283 93 ▶ for (i=0; i<pIdxInfo->nOrderBy; i++){
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<pIdxInfo->nOrderBy; i++){ 21 72 93
284 21 struct sqlite3_index_orderby const *pOrder = &pIdxInfo->aOrderBy[i];
285 21 HV *order = newHV();
286 21 hv_stores(order, "col", newSViv(pOrder->iColumn));
287 21 ▶ hv_stores(order, "desc", pOrder->desc ? &PL_sv_yes : &PL_sv_no);
Branch: 1 branch
BranchTrueFalseTotal
hv_stores(order, "desc", pOrder->desc ? &PL_sv_yes : &PL_sv_no); 2 19 21
288 21 av_push( order_by, newRV_noinc((SV*) order));
289 }
290  
291 /* call the ->BEST_INDEX() method */
292 72 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 72 72
293 72 ▶ XPUSHs( ((perl_vtab *) pVTab)->perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( ((perl_vtab *) pVTab)->perl_vtab_obj); 0 72 72
294 72 ▶ XPUSHs( sv_2mortal( newRV_noinc((SV*) constraints)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal( newRV_noinc((SV*) constraints))); 0 72 72
295 72 ▶ XPUSHs( sv_2mortal( newRV_noinc((SV*) order_by)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal( newRV_noinc((SV*) order_by))); 0 72 72
296 72 PUTBACK;
297 72 count = call_method ("BEST_INDEX", G_SCALAR);
298 72 SPAGAIN;
299  
300 /* get values back from the returned hashref */
301 72 ▶ if (count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) 0 72 72
302 0 croak("BEST_INDEX() method returned %d vals instead of 1", count);
303 72 hashref = POPs;
304 72 ▶ if (!(hashref && SvROK(hashref) && SvTYPE(SvRV(hashref)) == SVt_PVHV))
Branch: 3 branches
BranchTrueFalseTotal
if (!(hashref && SvROK(hashref) && SvTYPE(SvRV(hashref)) == SVt_PVHV)) 72 0 72
if (!(hashref && SvROK(hashref) && SvTYPE(SvRV(hashref)) == SVt_PVHV)) 72 0 72
if (!(hashref && SvROK(hashref) && SvTYPE(SvRV(hashref)) == SVt_PVHV)) 0 72 72
305 0 croak("BEST_INDEX() method did not return a hashref");
306 72 hv = (HV*)SvRV(hashref);
307 72 val = hv_fetch(hv, "idxNum", 6, FALSE);
308 72 ▶ pIdxInfo->idxNum = (val && SvOK(*val)) ? SvIV(*val) : 0;
Branch: 2 branches
BranchTrueFalseTotal
pIdxInfo->idxNum = (val && SvOK(*val)) ? SvIV(*val) : 0; 72 0 72
pIdxInfo->idxNum = (val && SvOK(*val)) ? SvIV(*val) : 0; 72 0 72
309 72 val = hv_fetch(hv, "idxStr", 6, FALSE);
310 72 ▶ if (val && SvOK(*val)) {
Branch: 2 branches
BranchTrueFalseTotal
if (val && SvOK(*val)) { 72 0 72
if (val && SvOK(*val)) { 72 0 72
311 STRLEN len;
312 72 char *str = SvPVutf8(*val, len);
313 72 pIdxInfo->idxStr = sqlite3_malloc(len+1);
314 72 memcpy(pIdxInfo->idxStr, str, len);
315 72 pIdxInfo->idxStr[len] = 0;
316 72 pIdxInfo->needToFreeIdxStr = 1;
317 }
318 72 val = hv_fetch(hv, "orderByConsumed", 15, FALSE);
319 72 ▶ pIdxInfo->orderByConsumed = (val && SvTRUE(*val)) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
pIdxInfo->orderByConsumed = (val && SvTRUE(*val)) ? 1 : 0; 72 0 72
pIdxInfo->orderByConsumed = (val && SvTRUE(*val)) ? 1 : 0; 0 72 72
320 72 val = hv_fetch(hv, "estimatedCost", 13, FALSE);
321 72 ▶ pIdxInfo->estimatedCost = (val && SvOK(*val)) ? SvNV(*val) : 0;
Branch: 2 branches
BranchTrueFalseTotal
pIdxInfo->estimatedCost = (val && SvOK(*val)) ? SvNV(*val) : 0; 72 0 72
pIdxInfo->estimatedCost = (val && SvOK(*val)) ? SvNV(*val) : 0; 72 0 72
322 #if SQLITE_VERSION_NUMBER >= 3008002
323 72 val = hv_fetch(hv, "estimatedRows", 13, FALSE);
324 72 ▶ pIdxInfo->estimatedRows = (val && SvOK(*val)) ? SvIV(*val) : 0;
Branch: 2 branches
BranchTrueFalseTotal
pIdxInfo->estimatedRows = (val && SvOK(*val)) ? SvIV(*val) : 0; 72 0 72
pIdxInfo->estimatedRows = (val && SvOK(*val)) ? SvIV(*val) : 0; 0 72 72
325 #endif
326  
327 /* loop over constraints to get back the "argvIndex" and "omit" keys
328 that shoud have been added by the best_index() method call */
329 134 ▶ for (i=0; i<pIdxInfo->nConstraint; i++){
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<pIdxInfo->nConstraint; i++){ 62 72 134
330 62 SV **rv = av_fetch(constraints, i, FALSE);
331 62 ▶ if (!(rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVHV))
Branch: 3 branches
BranchTrueFalseTotal
if (!(rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVHV)) 62 0 62
if (!(rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVHV)) 62 0 62
if (!(rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVHV)) 0 62 62
332 0 croak("the call to BEST_INDEX() has corrupted constraint data");
333 62 hv = (HV*)SvRV(*rv);
334 62 val = hv_fetch(hv, "argvIndex", 9, FALSE);
335 62 ▶ argvIndex = (val && SvOK(*val)) ? SvIV(*val) + 1: 0;
Branch: 2 branches
BranchTrueFalseTotal
argvIndex = (val && SvOK(*val)) ? SvIV(*val) + 1: 0; 57 5 62
argvIndex = (val && SvOK(*val)) ? SvIV(*val) + 1: 0; 57 0 57
336  
337 62 pConsUsage = &pIdxInfo->aConstraintUsage[i];
338 62 pConsUsage->argvIndex = argvIndex;
339 62 val = hv_fetch(hv, "omit", 4, FALSE);
340 62 ▶ pConsUsage->omit = (val && SvTRUE(*val)) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
pConsUsage->omit = (val && SvTRUE(*val)) ? 1 : 0; 57 5 62
pConsUsage->omit = (val && SvTRUE(*val)) ? 1 : 0; 57 0 57
341 }
342  
343 72 PUTBACK;
344 72 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 72 0 72
345 72 LEAVE;
346  
347 72 return SQLITE_OK;
348 }
349  
350  
351  
352 117 static int perl_vt_Open(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
353 dTHX;
354 117 dSP;
355 int count;
356 117 int rc = SQLITE_ERROR;
357 SV *perl_cursor;
358 perl_vtab_cursor *cursor;
359  
360 117 ENTER;
361 117 SAVETMPS;
362  
363 /* allocate a perl_vtab_cursor structure */
364 117 cursor = (perl_vtab_cursor *) sqlite3_malloc(sizeof(*cursor));
365 117 ▶ if( cursor==NULL ) return SQLITE_NOMEM;
Branch: 1 branch
BranchTrueFalseTotal
if( cursor==NULL ) return SQLITE_NOMEM; 0 117 117
366 117 memset(cursor, 0, sizeof(*cursor));
367  
368 /* call the ->OPEN() method */
369 117 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 117 117
370 117 ▶ XPUSHs( ((perl_vtab *) pVTab)->perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( ((perl_vtab *) pVTab)->perl_vtab_obj); 0 117 117
371 117 PUTBACK;
372 117 count = call_method ("OPEN", G_SCALAR);
373 117 SPAGAIN;
374 117 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 117 117
375 0 warn("vtab->OPEN() method returned %d vals instead of 1", count);
376 0 SP -= count;
377 0 goto cleanup;
378  
379 }
380 117 perl_cursor = POPs;
381 117 ▶ if ( !sv_isobject(perl_cursor) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !sv_isobject(perl_cursor) ) { 0 117 117
382 0 warn("vtab->OPEN() method did not return a blessed cursor");
383 0 goto cleanup;
384 }
385  
386 /* everything went OK */
387 117 rc = SQLITE_OK;
388  
389 117 cleanup:
390  
391 117 ▶ if (rc == SQLITE_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rc == SQLITE_OK) { 117 0 117
392 117 cursor->perl_cursor_obj = SvREFCNT_inc(perl_cursor);
393 117 *ppCursor = &cursor->base;
394 }
395 else {
396 0 sqlite3_free(cursor);
397 }
398  
399 117 PUTBACK;
400 117 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 117 0 117
401 117 LEAVE;
402  
403 117 return rc;
404 }
405  
406 117 static int perl_vt_Close(sqlite3_vtab_cursor *pVtabCursor){
407 dTHX;
408 117 dSP;
409 perl_vtab_cursor *perl_pVTabCursor;
410  
411 117 ENTER;
412 117 SAVETMPS;
413  
414 /* Note : there is no explicit call to a CLOSE() method; if
415 needed, the Perl class can implement a DESTROY() method */
416  
417 117 perl_pVTabCursor = (perl_vtab_cursor *) pVtabCursor;
418 117 SvREFCNT_dec(perl_pVTabCursor->perl_cursor_obj);
419 117 sqlite3_free(perl_pVTabCursor);
420  
421 117 PUTBACK;
422 117 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 55 62 117
423 117 LEAVE;
424  
425 117 return SQLITE_OK;
426 }
427  
428 126 static int perl_vt_Filter( sqlite3_vtab_cursor *pVtabCursor,
429 int idxNum, const char *idxStr,
430 int argc, sqlite3_value **argv ){
431 dTHX;
432 126 dSP;
433 dMY_CXT;
434 int i, count;
435 126 int is_unicode = MY_CXT.last_dbh_is_unicode;
436  
437 126 ENTER;
438 126 SAVETMPS;
439  
440 /* call the FILTER() method with ($idxNum, $idxStr, @args) */
441 126 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 126 126
442 126 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 126 126
443 126 ▶ XPUSHs(sv_2mortal(newSViv(idxNum)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(idxNum))); 0 126 126
444 126 ▶ XPUSHs(sv_2mortal(newSVpv(idxStr, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(idxStr, 0))); 0 126 126
445 240 ▶ for(i = 0; i < argc; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < argc; i++) { 114 126 240
446 114 ▶ XPUSHs(stacked_sv_from_sqlite3_value(aTHX_ argv[i], is_unicode));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(stacked_sv_from_sqlite3_value(aTHX_ argv[i], is_unicode)); 0 114 114
447 }
448 126 PUTBACK;
449 126 count = call_method("FILTER", G_VOID);
450 126 SPAGAIN;
451 126 SP -= count;
452  
453 126 PUTBACK;
454 126 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 126 0 126
455 126 LEAVE;
456  
457 126 return SQLITE_OK;
458 }
459  
460  
461 176 static int perl_vt_Next(sqlite3_vtab_cursor *pVtabCursor){
462 dTHX;
463 176 dSP;
464 int count;
465  
466 176 ENTER;
467 176 SAVETMPS;
468  
469 /* call the next() method */
470 176 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 176 176
471 176 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 176 176
472 176 PUTBACK;
473 176 count = call_method ("NEXT", G_VOID);
474 176 SPAGAIN;
475 176 SP -= count;
476  
477 176 PUTBACK;
478 176 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 176 0 176
479 176 LEAVE;
480  
481 176 return SQLITE_OK;
482 }
483  
484 302 static int perl_vt_Eof(sqlite3_vtab_cursor *pVtabCursor){
485 dTHX;
486 302 dSP;
487 int count, eof;
488  
489 302 ENTER;
490 302 SAVETMPS;
491  
492 /* call the eof() method */
493 302 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 302 302
494 302 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 302 302
495 302 PUTBACK;
496 302 count = call_method ("EOF", G_SCALAR);
497 302 SPAGAIN;
498 302 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 302 302
499 0 warn("cursor->EOF() method returned %d vals instead of 1", count);
500 0 SP -= count;
501 }
502 else {
503 302 SV *sv = POPs; /* need 2 lines, because this doesn't work : */
504 302 eof = SvTRUE(sv); /* eof = SvTRUE(POPs); # I don't understand why :-( */
505 }
506  
507 302 PUTBACK;
508 302 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 302 0 302
509 302 LEAVE;
510  
511 302 return eof;
512 }
513  
514  
515 931 static int perl_vt_Column(sqlite3_vtab_cursor *pVtabCursor,
516 sqlite3_context* context,
517 int col){
518 dTHX;
519 931 dSP;
520 int count;
521 931 int rc = SQLITE_ERROR;
522  
523 931 ENTER;
524 931 SAVETMPS;
525  
526 /* call the column() method */
527 931 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 931 931
528 931 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 931 931
529 931 ▶ XPUSHs(sv_2mortal(newSViv(col)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(col))); 0 931 931
530 931 PUTBACK;
531 931 count = call_method ("COLUMN", G_SCALAR);
532 931 SPAGAIN;
533 931 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 931 931
534 0 warn("cursor->COLUMN() method returned %d vals instead of 1", count);
535 0 SP -= count;
536 0 sqlite3_result_error(context, "column error", 12);
537 }
538 else {
539 931 SV *result = POPs;
540 931 sqlite_set_result_for_vtable(aTHX_ context, result, 0 );
541 931 rc = SQLITE_OK;
542 }
543  
544 931 PUTBACK;
545 931 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 931 0 931
546 931 LEAVE;
547  
548 931 return rc;
549 }
550  
551 93 static int perl_vt_Rowid( sqlite3_vtab_cursor *pVtabCursor,
552 sqlite3_int64 *pRowid ){
553 dTHX;
554 93 dSP;
555 int count;
556 93 int rc = SQLITE_ERROR;
557  
558 93 ENTER;
559 93 SAVETMPS;
560  
561 /* call the rowid() method */
562 93 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 93 93
563 93 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 93 93
564 93 PUTBACK;
565 93 count = call_method ("ROWID", G_SCALAR);
566 93 SPAGAIN;
567 93 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 93 93
568 0 warn("cursor->ROWID() returned %d vals instead of 1", count);
569 0 SP -= count;
570 }
571 else {
572 93 *pRowid =POPi;
573 93 rc = SQLITE_OK;
574 }
575  
576 93 PUTBACK;
577 93 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 93 0 93
578 93 LEAVE;
579  
580 93 return rc;
581 }
582  
583 5 static int perl_vt_Update( sqlite3_vtab *pVTab,
584 int argc, sqlite3_value **argv,
585 sqlite3_int64 *pRowid ){
586 dTHX;
587 5 dSP;
588 dMY_CXT;
589 int count, i;
590 5 int is_unicode = MY_CXT.last_dbh_is_unicode;
591 5 int rc = SQLITE_ERROR;
592 SV *rowidsv;
593  
594 5 ENTER;
595 5 SAVETMPS;
596  
597 /* call the _SQLITE_UPDATE() method */
598 5 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 5 5
599 5 ▶ XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj); 0 5 5
600 22 ▶ for(i = 0; i < argc; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < argc; i++) { 17 5 22
601 17 ▶ XPUSHs(stacked_sv_from_sqlite3_value(aTHX_ argv[i], is_unicode));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(stacked_sv_from_sqlite3_value(aTHX_ argv[i], is_unicode)); 0 17 17
602 }
603 5 PUTBACK;
604 5 count = call_method ("_SQLITE_UPDATE", G_SCALAR);
605 5 SPAGAIN;
606 5 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 5 5
607 0 warn("cursor->_SQLITE_UPDATE() returned %d vals instead of 1", count);
608 0 SP -= count;
609 }
610 else {
611 5 ▶ if (argc > 1 && sqlite3_value_type(argv[0]) == SQLITE_NULL
Branch: 2 branches
BranchTrueFalseTotal
if (argc > 1 && sqlite3_value_type(argv[0]) == SQLITE_NULL 5 0 5
if (argc > 1 && sqlite3_value_type(argv[0]) == SQLITE_NULL 5 0 5
612 5 ▶ && sqlite3_value_type(argv[1]) == SQLITE_NULL) {
Branch: 1 branch
BranchTrueFalseTotal
&& sqlite3_value_type(argv[1]) == SQLITE_NULL) { 5 0 5
613 /* this was an insert without any given rowid, so the result of
614 the method call must be passed in *pRowid*/
615 5 rowidsv = POPs;
616 5 ▶ if (!SvOK(rowidsv))
Branch: 1 branch
BranchTrueFalseTotal
if (!SvOK(rowidsv)) 0 5 5
617 0 *pRowid = 0;
618 5 ▶ else if (SvUOK(rowidsv))
Branch: 1 branch
BranchTrueFalseTotal
else if (SvUOK(rowidsv)) 0 5 5
619 0 *pRowid = SvUV(rowidsv);
620 5 ▶ else if (SvIOK(rowidsv))
Branch: 1 branch
BranchTrueFalseTotal
else if (SvIOK(rowidsv)) 5 0 5
621 5 *pRowid = SvIV(rowidsv);
622 else
623 0 *pRowid = (sqlite3_int64)SvNV(rowidsv);
624 }
625 5 rc = SQLITE_OK;
626 }
627  
628  
629 5 PUTBACK;
630 5 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 5 0 5
631 5 LEAVE;
632  
633 5 return rc;
634 }
635  
636 3 static int perl_vt_Begin(sqlite3_vtab *pVTab){
637 3 return _call_perl_vtab_method(pVTab, "BEGIN_TRANSACTION", 0);
638 }
639  
640 20 static int perl_vt_Sync(sqlite3_vtab *pVTab){
641 20 return _call_perl_vtab_method(pVTab, "SYNC_TRANSACTION", 0);
642 }
643  
644 20 static int perl_vt_Commit(sqlite3_vtab *pVTab){
645 20 return _call_perl_vtab_method(pVTab, "COMMIT_TRANSACTION", 0);
646 }
647  
648 0 static int perl_vt_Rollback(sqlite3_vtab *pVTab){
649 0 return _call_perl_vtab_method(pVTab, "ROLLBACK_TRANSACTION", 0);
650 }
651  
652 13 static int perl_vt_FindFunction(sqlite3_vtab *pVTab,
653 int nArg, const char *zName,
654 void (**pxFunc)(sqlite3_context*,int,sqlite3_value**),
655 void **ppArg){
656 dTHX;
657 13 dSP;
658 dMY_CXT;
659 int count;
660 13 int is_overloaded = 0;
661 13 char *func_name = sqlite3_mprintf("%s\t%d", zName, nArg);
662 13 STRLEN len = strlen(func_name);
663 13 HV *functions = ((perl_vtab *) pVTab)->functions;
664 13 SV* coderef = NULL;
665 SV** val;
666 SV *result;
667  
668 13 ENTER;
669 13 SAVETMPS;
670  
671 /* check if that function was already in cache */
672 13 ▶ if (hv_exists(functions, func_name, len)) {
Branch: 1 branch
BranchTrueFalseTotal
if (hv_exists(functions, func_name, len)) { 6 7 13
673 6 val = hv_fetch(functions, func_name, len, FALSE);
674 6 ▶ if (val && SvOK(*val)) {
Branch: 2 branches
BranchTrueFalseTotal
if (val && SvOK(*val)) { 6 0 6
if (val && SvOK(*val)) { 5 1 6
675 5 coderef = *val;
676 }
677 }
678 else {
679 /* call the FIND_FUNCTION() method */
680 7 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 7 7
681 7 ▶ XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj); 0 7 7
682 7 ▶ XPUSHs(sv_2mortal(newSViv(nArg)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(nArg))); 0 7 7
683 7 ▶ XPUSHs(sv_2mortal(newSVpv(zName, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(zName, 0))); 0 7 7
684 7 PUTBACK;
685 7 count = call_method ("FIND_FUNCTION", G_SCALAR);
686 7 SPAGAIN;
687 7 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 7 7
688 0 warn("vtab->FIND_FUNCTION() method returned %d vals instead of 1", count);
689 0 SP -= count;
690 0 goto cleanup;
691 }
692 7 result = POPs;
693 7 ▶ if (SvTRUE(result)) {
Branch: 1 branch
BranchTrueFalseTotal
if (SvTRUE(result)) { 4 3 7
694 /* the coderef must be valid for the lifetime of pVTab, so
695 make a copy */
696 4 coderef = newSVsv(result);
697 }
698  
699 /* store result in cache */
700 7 ▶ hv_store(functions, func_name, len, coderef ? coderef : &PL_sv_undef, 0);
Branch: 1 branch
BranchTrueFalseTotal
hv_store(functions, func_name, len, coderef ? coderef : &PL_sv_undef, 0); 4 3 7
701 }
702  
703 /* return function information for sqlite3 within *pxFunc and *ppArg */
704 13 ▶ is_overloaded = coderef && SvTRUE(coderef);
Branch: 2 branches
BranchTrueFalseTotal
is_overloaded = coderef && SvTRUE(coderef); 9 4 13
is_overloaded = coderef && SvTRUE(coderef); 9 0 9
705 13 ▶ if (is_overloaded) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_overloaded) { 4 9 13
706 18 *pxFunc = MY_CXT.last_dbh_is_unicode ? sqlite_db_func_dispatcher_unicode
707 9 ▶ : sqlite_db_func_dispatcher_no_unicode;
Branch: 1 branch
BranchTrueFalseTotal
: sqlite_db_func_dispatcher_no_unicode; 0 9 9
708 9 *ppArg = coderef;
709 }
710  
711 4 cleanup:
712 13 PUTBACK;
713 13 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 7 6 13
714 13 LEAVE;
715 13 sqlite3_free(func_name);
716 13 return is_overloaded;
717 }
718  
719  
720 0 static int perl_vt_Rename(sqlite3_vtab *pVTab, const char *zNew){
721 dTHX;
722 0 dSP;
723 int count;
724 0 int rc = SQLITE_ERROR;
725  
726 0 ENTER;
727 0 SAVETMPS;
728  
729 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
730 0 ▶ XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj); 0 0 0
731 0 ▶ XPUSHs(sv_2mortal(newSVpv(zNew, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(zNew, 0))); 0 0 0
732 0 PUTBACK;
733 0 count = call_method("RENAME", G_SCALAR);
734 0 SPAGAIN;
735 0 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 0 0
736 0 warn("vtab->RENAME() returned %d args instead of 1", count);
737 0 SP -= count;
738 }
739 else {
740 0 rc = POPi;
741 }
742  
743 0 PUTBACK;
744 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
745 0 LEAVE;
746  
747 0 return rc;
748 }
749  
750 0 static int perl_vt_Savepoint(sqlite3_vtab *pVTab, int point){
751 0 return _call_perl_vtab_method(pVTab, "SAVEPOINT", point);
752 }
753  
754 0 static int perl_vt_Release(sqlite3_vtab *pVTab, int point){
755 0 return _call_perl_vtab_method(pVTab, "RELEASE", point);
756 }
757  
758 0 static int perl_vt_RollbackTo(sqlite3_vtab *pVTab, int point){
759 0 return _call_perl_vtab_method(pVTab, "ROLLBACK_TO", point);
760 }
761  
762 static sqlite3_module perl_vt_Module = {
763 1, /* iVersion */
764 perl_vt_Create, /* xCreate */
765 perl_vt_Connect, /* xConnect */
766 perl_vt_BestIndex, /* xBestIndex */
767 perl_vt_Disconnect, /* xDisconnect */
768 perl_vt_Drop, /* xDestroy */
769 perl_vt_Open, /* xOpen - open a cursor */
770 perl_vt_Close, /* xClose - close a cursor */
771 perl_vt_Filter, /* xFilter - configure scan constraints */
772 perl_vt_Next, /* xNext - advance a cursor */
773 perl_vt_Eof, /* xEof - check for end of scan */
774 perl_vt_Column, /* xColumn - read data */
775 perl_vt_Rowid, /* xRowid - read data */
776 perl_vt_Update, /* xUpdate (optional) */
777 perl_vt_Begin, /* xBegin (optional) */
778 perl_vt_Sync, /* xSync (optional) */
779 perl_vt_Commit, /* xCommit (optional) */
780 perl_vt_Rollback, /* xRollback (optional) */
781 perl_vt_FindFunction, /* xFindFunction (optional) */
782 perl_vt_Rename, /* xRename */
783 #if SQLITE_VERSION_NUMBER >= 3007007
784 perl_vt_Savepoint, /* xSavepoint (optional) */
785 perl_vt_Release, /* xRelease (optional) */
786 perl_vt_RollbackTo /* xRollbackTo (optional) */
787 #endif
788 };
789  
790  
791 void
792 12 sqlite_db_destroy_module_data(void *pAux)
793 {
794 dTHX;
795 12 dSP;
796 int count;
797 12 int rc = SQLITE_ERROR;
798 perl_vtab_init *init_data;
799  
800 12 ENTER;
801 12 SAVETMPS;
802  
803 12 init_data = (perl_vtab_init *)pAux;
804  
805 /* call the DESTROY_MODULE() method */
806 12 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 12 12
807 12 ▶ XPUSHs(sv_2mortal(newSVpv(init_data->perl_class, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(init_data->perl_class, 0))); 0 12 12
808 12 PUTBACK;
809 12 count = call_method("DESTROY_MODULE", G_VOID);
810 12 SPAGAIN;
811 12 SP -= count;
812  
813 /* free module memory */
814 12 SvREFCNT_dec(init_data->dbh);
815 12 sqlite3_free((char *)init_data->perl_class);
816  
817 12 PUTBACK;
818 12 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 12 0 12
819 12 LEAVE;
820 12 }
821  
822  
823  
824 int
825 12 sqlite_db_create_module(pTHX_ SV *dbh, const char *name, const char *perl_class)
826 {
827 12 dSP;
828 12 D_imp_dbh(dbh);
829 12 int count, rc, retval = TRUE;
830 char *module_ISA;
831 char *loading_code;
832 perl_vtab_init *init_data;
833  
834 12 ENTER;
835 12 SAVETMPS;
836  
837 12 ▶ if (!DBIc_ACTIVE(imp_dbh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIc_ACTIVE(imp_dbh)) { 0 12 12
838 0 sqlite_error(dbh, -2, "attempt to create module on inactive database handle");
839 0 return FALSE;
840 }
841  
842 /* load the module if needed */
843 12 module_ISA = sqlite3_mprintf("%s::ISA", perl_class);
844 12 ▶ if (!get_av(module_ISA, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!get_av(module_ISA, 0)) { 6 6 12
845 6 loading_code = sqlite3_mprintf("use %s", perl_class);
846 6 eval_pv(loading_code, TRUE);
847 6 sqlite3_free(loading_code);
848 }
849 12 sqlite3_free(module_ISA);
850  
851 /* build the init datastructure that will be passed to perl_vt_New() */
852 12 init_data = sqlite3_malloc(sizeof(*init_data));
853 12 init_data->dbh = newRV(dbh);
854 12 sv_rvweaken(init_data->dbh);
855 12 init_data->perl_class = sqlite3_mprintf(perl_class);
856  
857 /* register within sqlite */
858 12 rc = sqlite3_create_module_v2( imp_dbh->db,
859 name,
860 &perl_vt_Module,
861 init_data,
862 sqlite_db_destroy_module_data
863 );
864 12 ▶ if ( rc != SQLITE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rc != SQLITE_OK ) { 0 12 12
865 0 sqlite_error(dbh, rc, form("sqlite_create_module failed with error %s",
866 sqlite3_errmsg(imp_dbh->db)));
867 0 retval = FALSE;
868 }
869  
870  
871 /* call the CREATE_MODULE() method */
872 12 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 12 12
873 12 ▶ XPUSHs(sv_2mortal(newSVpv(perl_class, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(perl_class, 0))); 0 12 12
874 12 ▶ XPUSHs(sv_2mortal(newSVpv(name, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(name, 0))); 0 12 12
875 12 PUTBACK;
876 12 count = call_method("CREATE_MODULE", G_VOID);
877 12 SPAGAIN;
878 12 SP -= count;
879  
880 12 PUTBACK;
881 12 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 12 0 12
882 12 LEAVE;
883  
884 12 return retval;
885 }
« SQLite.xsi ↑ Summary dbdimp.c »