dbdimp_virtual_table.inc

filter: Statementstmt 84.1% 403 / 479 Branchbran 55.9% 142 / 254 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 74.3% 545 / 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 65 static int _call_perl_vtab_method(sqlite3_vtab *pVTab,
26 const char *method, int i) {
27 dTHX;
28 65 dSP;
29 int count;
30  
31 65 ENTER;
32 65 SAVETMPS;
33  
34 65 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 65 65
35 65 ▶ XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab *) pVTab)->perl_vtab_obj); 0 65 65
36 65 ▶ XPUSHs(sv_2mortal(newSViv(i)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(i))); 0 65 65
37 65 PUTBACK;
38 65 count = call_method (method, G_VOID);
39 65 SPAGAIN;
40 65 SP -= count;
41  
42 65 PUTBACK;
43 65 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 65 0 65
44 65 LEAVE;
45  
46 65 return SQLITE_OK;
47 }
48  
49  
50 /* RT-124941: it seems better to prefer PV where appropriate */
51 static void
52 941 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 941 ▶ if ( is_error ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( is_error ) { 0 941 941
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 941 ▶ if ( !SvOK(result) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !SvOK(result) ) { 7 934 941
66 7 sqlite3_result_null( context );
67 934 ▶ } else if ( SvPOK(result) ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( SvPOK(result) ) { 830 104 934
68 830 s = SvPV(result, len);
69 830 sqlite3_result_text( context, s, len, SQLITE_TRANSIENT );
70 104 ▶ } else if( SvIOK_UV(result) ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if( SvIOK_UV(result) ) { 0 104 104
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 104 ▶ } else if ( !_sqlite_atoi64(SvPV(result, len), &iv) ) {
Branch: 1 branch
BranchTrueFalseTotal
} else if ( !_sqlite_atoi64(SvPV(result, len), &iv) ) { 104 0 104
78 104 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 20 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 20 dSP;
95 perl_vtab *vt;
96 20 perl_vtab_init *init_data = (perl_vtab_init *)pAux;
97 int count, i;
98 20 int rc = SQLITE_ERROR;
99 SV *perl_vtab_obj;
100 SV *sql;
101  
102 /* allocate a perl_vtab structure */
103 20 vt = (perl_vtab *) sqlite3_malloc(sizeof(*vt));
104 20 ▶ if( vt==NULL ) return SQLITE_NOMEM;
Branch: 1 branch
BranchTrueFalseTotal
if( vt==NULL ) return SQLITE_NOMEM; 0 20 20
105 20 memset(vt, 0, sizeof(*vt));
106 20 vt->functions = newHV();
107  
108 20 ENTER;
109 20 SAVETMPS;
110  
111 /* call the ->CREATE/CONNECT() method */
112 20 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 20 20
113 20 ▶ XPUSHs(sv_2mortal(newSVpv(init_data->perl_class, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(init_data->perl_class, 0))); 0 20 20
114 20 ▶ XPUSHs(init_data->dbh);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(init_data->dbh); 0 20 20
115 141 ▶ for(i = 0; i < argc; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < argc; i++) { 121 20 141
116 121 ▶ 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 121 121
117 }
118 20 PUTBACK;
119 20 count = call_method (method, G_SCALAR);
120 20 SPAGAIN;
121  
122 /* check the return value */
123 20 ▶ if ( count != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( count != 1 ) { 0 20 20
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 20 perl_vtab_obj = POPs;
132 20 ▶ if ( !sv_isobject(perl_vtab_obj) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !sv_isobject(perl_vtab_obj) ) { 0 20 20
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 20 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 20 20
140 20 ▶ XPUSHs(perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(perl_vtab_obj); 0 20 20
141 20 PUTBACK;
142 20 count = call_method ("VTAB_TO_DECLARE", G_SCALAR);
143 20 SPAGAIN;
144  
145 /* check the return value */
146 20 ▶ if (count != 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1 ) { 0 20 20
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 20 sql = POPs;
156 20 rc = sqlite3_declare_vtab(db, SvPVutf8_nolen(sql));
157  
158 20 cleanup:
159 20 ▶ if (rc == SQLITE_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rc == SQLITE_OK) { 20 0 20
160 /* record the VirtualTable perl instance within the vtab structure */
161 20 vt->perl_vtab_obj = SvREFCNT_inc(perl_vtab_obj);
162 20 *ppVTab = &vt->base;
163 }
164 else {
165 0 sqlite3_free(vt);
166 }
167  
168 20 PUTBACK;
169 20 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 20 0 20
170 20 LEAVE;
171  
172 20 return rc;
173 }
174  
175  
176 18 static int perl_vt_Create(sqlite3 *db, void *pAux,
177 int argc, const char *const *argv,
178 sqlite3_vtab **ppVTab, char **pzErr){
179 18 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 20 static int _free_perl_vtab(perl_vtab *pVTab){
190 dTHX;
191  
192 20 SvREFCNT_dec(pVTab->perl_vtab_obj);
193  
194 /* deallocate coderefs that were declared through FindFunction() */
195 20 hv_undef(pVTab->functions);
196 20 SvREFCNT_dec(pVTab->functions);
197  
198 20 sqlite3_free(pVTab);
199 20 return SQLITE_OK;
200 }
201  
202 18 static int perl_vt_Disconnect(sqlite3_vtab *pVTab){
203 18 _call_perl_vtab_method(pVTab, "DISCONNECT", 0);
204 18 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 73 _constraint_op_to_string(unsigned char op) {
215 73 switch (op) {
216 33 case SQLITE_INDEX_CONSTRAINT_EQ:
217 33 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 3 case SQLITE_INDEX_CONSTRAINT_ISNOTNULL:
242 3 return "ISNOTNULL";
243 3 case SQLITE_INDEX_CONSTRAINT_ISNULL:
244 3 return "ISNULL";
245 1 case SQLITE_INDEX_CONSTRAINT_IS:
246 1 return "IS";
247 #endif
248 1 default:
249 1 return "unknown";
250 }
251 }
252  
253  
254 85 static int perl_vt_BestIndex(sqlite3_vtab *pVTab, sqlite3_index_info *pIdxInfo){
255 dTHX;
256 85 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 85 ENTER;
267 85 SAVETMPS;
268  
269 /* build the "where_constraints" datastructure */
270 85 constraints = newAV();
271 158 ▶ for (i=0; i<pIdxInfo->nConstraint; i++){
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<pIdxInfo->nConstraint; i++){ 73 85 158
272 73 struct sqlite3_index_constraint const *pCons = &pIdxInfo->aConstraint[i];
273 73 HV *constraint = newHV();
274 73 char *op_str = _constraint_op_to_string(pCons->op);
275 73 hv_stores(constraint, "col", newSViv(pCons->iColumn));
276 73 hv_stores(constraint, "op", newSVpv(op_str, 0));
277 73 ▶ 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); 64 9 73
278 73 av_push(constraints, newRV_noinc((SV*) constraint));
279 }
280  
281 /* build the "order_by" datastructure */
282 85 order_by = newAV();
283 106 ▶ for (i=0; i<pIdxInfo->nOrderBy; i++){
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<pIdxInfo->nOrderBy; i++){ 21 85 106
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 85 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 85 85
293 85 ▶ XPUSHs( ((perl_vtab *) pVTab)->perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( ((perl_vtab *) pVTab)->perl_vtab_obj); 0 85 85
294 85 ▶ XPUSHs( sv_2mortal( newRV_noinc((SV*) constraints)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal( newRV_noinc((SV*) constraints))); 0 85 85
295 85 ▶ XPUSHs( sv_2mortal( newRV_noinc((SV*) order_by)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( sv_2mortal( newRV_noinc((SV*) order_by))); 0 85 85
296 85 PUTBACK;
297 85 count = call_method ("BEST_INDEX", G_SCALAR);
298 85 SPAGAIN;
299  
300 /* get values back from the returned hashref */
301 85 ▶ if (count != 1)
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) 0 85 85
302 0 croak("BEST_INDEX() method returned %d vals instead of 1", count);
303 85 hashref = POPs;
304 85 ▶ if (!(hashref && SvROK(hashref) && SvTYPE(SvRV(hashref)) == SVt_PVHV))
Branch: 3 branches
BranchTrueFalseTotal
if (!(hashref && SvROK(hashref) && SvTYPE(SvRV(hashref)) == SVt_PVHV)) 85 0 85
if (!(hashref && SvROK(hashref) && SvTYPE(SvRV(hashref)) == SVt_PVHV)) 85 0 85
if (!(hashref && SvROK(hashref) && SvTYPE(SvRV(hashref)) == SVt_PVHV)) 0 85 85
305 0 croak("BEST_INDEX() method did not return a hashref");
306 85 hv = (HV*)SvRV(hashref);
307 85 val = hv_fetch(hv, "idxNum", 6, FALSE);
308 85 ▶ pIdxInfo->idxNum = (val && SvOK(*val)) ? SvIV(*val) : 0;
Branch: 2 branches
BranchTrueFalseTotal
pIdxInfo->idxNum = (val && SvOK(*val)) ? SvIV(*val) : 0; 85 0 85
pIdxInfo->idxNum = (val && SvOK(*val)) ? SvIV(*val) : 0; 85 0 85
309 85 val = hv_fetch(hv, "idxStr", 6, FALSE);
310 85 ▶ if (val && SvOK(*val)) {
Branch: 2 branches
BranchTrueFalseTotal
if (val && SvOK(*val)) { 85 0 85
if (val && SvOK(*val)) { 85 0 85
311 STRLEN len;
312 85 char *str = SvPVutf8(*val, len);
313 85 pIdxInfo->idxStr = sqlite3_malloc(len+1);
314 85 memcpy(pIdxInfo->idxStr, str, len);
315 85 pIdxInfo->idxStr[len] = 0;
316 85 pIdxInfo->needToFreeIdxStr = 1;
317 }
318 85 val = hv_fetch(hv, "orderByConsumed", 15, FALSE);
319 85 ▶ pIdxInfo->orderByConsumed = (val && SvTRUE(*val)) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
pIdxInfo->orderByConsumed = (val && SvTRUE(*val)) ? 1 : 0; 85 0 85
pIdxInfo->orderByConsumed = (val && SvTRUE(*val)) ? 1 : 0; 0 85 85
320 85 val = hv_fetch(hv, "estimatedCost", 13, FALSE);
321 85 ▶ pIdxInfo->estimatedCost = (val && SvOK(*val)) ? SvNV(*val) : 0;
Branch: 2 branches
BranchTrueFalseTotal
pIdxInfo->estimatedCost = (val && SvOK(*val)) ? SvNV(*val) : 0; 85 0 85
pIdxInfo->estimatedCost = (val && SvOK(*val)) ? SvNV(*val) : 0; 85 0 85
322 #if SQLITE_VERSION_NUMBER >= 3008002
323 85 val = hv_fetch(hv, "estimatedRows", 13, FALSE);
324 85 ▶ pIdxInfo->estimatedRows = (val && SvOK(*val)) ? SvIV(*val) : 0;
Branch: 2 branches
BranchTrueFalseTotal
pIdxInfo->estimatedRows = (val && SvOK(*val)) ? SvIV(*val) : 0; 85 0 85
pIdxInfo->estimatedRows = (val && SvOK(*val)) ? SvIV(*val) : 0; 0 85 85
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 158 ▶ for (i=0; i<pIdxInfo->nConstraint; i++){
Branch: 1 branch
BranchTrueFalseTotal
for (i=0; i<pIdxInfo->nConstraint; i++){ 73 85 158
330 73 SV **rv = av_fetch(constraints, i, FALSE);
331 73 ▶ if (!(rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVHV))
Branch: 3 branches
BranchTrueFalseTotal
if (!(rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVHV)) 73 0 73
if (!(rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVHV)) 73 0 73
if (!(rv && SvROK(*rv) && SvTYPE(SvRV(*rv)) == SVt_PVHV)) 0 73 73
332 0 croak("the call to BEST_INDEX() has corrupted constraint data");
333 73 hv = (HV*)SvRV(*rv);
334 73 val = hv_fetch(hv, "argvIndex", 9, FALSE);
335 73 ▶ argvIndex = (val && SvOK(*val)) ? SvIV(*val) + 1: 0;
Branch: 2 branches
BranchTrueFalseTotal
argvIndex = (val && SvOK(*val)) ? SvIV(*val) + 1: 0; 62 11 73
argvIndex = (val && SvOK(*val)) ? SvIV(*val) + 1: 0; 62 0 62
336  
337 73 pConsUsage = &pIdxInfo->aConstraintUsage[i];
338 73 pConsUsage->argvIndex = argvIndex;
339 73 val = hv_fetch(hv, "omit", 4, FALSE);
340 73 ▶ pConsUsage->omit = (val && SvTRUE(*val)) ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
pConsUsage->omit = (val && SvTRUE(*val)) ? 1 : 0; 62 11 73
pConsUsage->omit = (val && SvTRUE(*val)) ? 1 : 0; 62 0 62
341 }
342  
343 85 PUTBACK;
344 85 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 85 0 85
345 85 LEAVE;
346  
347 85 return SQLITE_OK;
348 }
349  
350  
351  
352 122 static int perl_vt_Open(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor){
353 dTHX;
354 122 dSP;
355 int count;
356 122 int rc = SQLITE_ERROR;
357 SV *perl_cursor;
358 perl_vtab_cursor *cursor;
359  
360 122 ENTER;
361 122 SAVETMPS;
362  
363 /* allocate a perl_vtab_cursor structure */
364 122 cursor = (perl_vtab_cursor *) sqlite3_malloc(sizeof(*cursor));
365 122 ▶ if( cursor==NULL ) return SQLITE_NOMEM;
Branch: 1 branch
BranchTrueFalseTotal
if( cursor==NULL ) return SQLITE_NOMEM; 0 122 122
366 122 memset(cursor, 0, sizeof(*cursor));
367  
368 /* call the ->OPEN() method */
369 122 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 122 122
370 122 ▶ XPUSHs( ((perl_vtab *) pVTab)->perl_vtab_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs( ((perl_vtab *) pVTab)->perl_vtab_obj); 0 122 122
371 122 PUTBACK;
372 122 count = call_method ("OPEN", G_SCALAR);
373 122 SPAGAIN;
374 122 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 122 122
375 0 warn("vtab->OPEN() method returned %d vals instead of 1", count);
376 0 SP -= count;
377 0 goto cleanup;
378  
379 }
380 122 perl_cursor = POPs;
381 122 ▶ if ( !sv_isobject(perl_cursor) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( !sv_isobject(perl_cursor) ) { 0 122 122
382 0 warn("vtab->OPEN() method did not return a blessed cursor");
383 0 goto cleanup;
384 }
385  
386 /* everything went OK */
387 122 rc = SQLITE_OK;
388  
389 122 cleanup:
390  
391 122 ▶ if (rc == SQLITE_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (rc == SQLITE_OK) { 122 0 122
392 122 cursor->perl_cursor_obj = SvREFCNT_inc(perl_cursor);
393 122 *ppCursor = &cursor->base;
394 }
395 else {
396 0 sqlite3_free(cursor);
397 }
398  
399 122 PUTBACK;
400 122 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 122 0 122
401 122 LEAVE;
402  
403 122 return rc;
404 }
405  
406 122 static int perl_vt_Close(sqlite3_vtab_cursor *pVtabCursor){
407 dTHX;
408 122 dSP;
409 perl_vtab_cursor *perl_pVTabCursor;
410  
411 122 ENTER;
412 122 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 122 perl_pVTabCursor = (perl_vtab_cursor *) pVtabCursor;
418 122 SvREFCNT_dec(perl_pVTabCursor->perl_cursor_obj);
419 122 sqlite3_free(perl_pVTabCursor);
420  
421 122 PUTBACK;
422 122 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 62 60 122
423 122 LEAVE;
424  
425 122 return SQLITE_OK;
426 }
427  
428 132 static int perl_vt_Filter( sqlite3_vtab_cursor *pVtabCursor,
429 int idxNum, const char *idxStr,
430 int argc, sqlite3_value **argv ){
431 dTHX;
432 132 dSP;
433 dMY_CXT;
434 int i, count;
435 132 int is_unicode = MY_CXT.last_dbh_is_unicode;
436  
437 132 ENTER;
438 132 SAVETMPS;
439  
440 /* call the FILTER() method with ($idxNum, $idxStr, @args) */
441 132 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 132 132
442 132 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 132 132
443 132 ▶ XPUSHs(sv_2mortal(newSViv(idxNum)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(idxNum))); 0 132 132
444 132 ▶ XPUSHs(sv_2mortal(newSVpv(idxStr, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(idxStr, 0))); 0 132 132
445 248 ▶ for(i = 0; i < argc; i++) {
Branch: 1 branch
BranchTrueFalseTotal
for(i = 0; i < argc; i++) { 116 132 248
446 116 ▶ 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 116 116
447 }
448 132 PUTBACK;
449 132 count = call_method("FILTER", G_VOID);
450 132 SPAGAIN;
451 132 SP -= count;
452  
453 132 PUTBACK;
454 132 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 132 0 132
455 132 LEAVE;
456  
457 132 return SQLITE_OK;
458 }
459  
460  
461 183 static int perl_vt_Next(sqlite3_vtab_cursor *pVtabCursor){
462 dTHX;
463 183 dSP;
464 int count;
465  
466 183 ENTER;
467 183 SAVETMPS;
468  
469 /* call the next() method */
470 183 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 183 183
471 183 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 183 183
472 183 PUTBACK;
473 183 count = call_method ("NEXT", G_VOID);
474 183 SPAGAIN;
475 183 SP -= count;
476  
477 183 PUTBACK;
478 183 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 183 0 183
479 183 LEAVE;
480  
481 183 return SQLITE_OK;
482 }
483  
484 315 static int perl_vt_Eof(sqlite3_vtab_cursor *pVtabCursor){
485 dTHX;
486 315 dSP;
487 int count, eof;
488  
489 315 ENTER;
490 315 SAVETMPS;
491  
492 /* call the eof() method */
493 315 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 315 315
494 315 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 315 315
495 315 PUTBACK;
496 315 count = call_method ("EOF", G_SCALAR);
497 315 SPAGAIN;
498 315 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 315 315
499 0 warn("cursor->EOF() method returned %d vals instead of 1", count);
500 0 SP -= count;
501 }
502 else {
503 315 SV *sv = POPs; /* need 2 lines, because this doesn't work : */
504 315 eof = SvTRUE(sv); /* eof = SvTRUE(POPs); # I don't understand why :-( */
505 }
506  
507 315 PUTBACK;
508 315 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 315 0 315
509 315 LEAVE;
510  
511 315 return eof;
512 }
513  
514  
515 941 static int perl_vt_Column(sqlite3_vtab_cursor *pVtabCursor,
516 sqlite3_context* context,
517 int col){
518 dTHX;
519 941 dSP;
520 int count;
521 941 int rc = SQLITE_ERROR;
522  
523 941 ENTER;
524 941 SAVETMPS;
525  
526 /* call the column() method */
527 941 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 941 941
528 941 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 941 941
529 941 ▶ XPUSHs(sv_2mortal(newSViv(col)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSViv(col))); 0 941 941
530 941 PUTBACK;
531 941 count = call_method ("COLUMN", G_SCALAR);
532 941 SPAGAIN;
533 941 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 941 941
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 941 SV *result = POPs;
540 941 sqlite_set_result_for_vtable(aTHX_ context, result, 0 );
541 941 rc = SQLITE_OK;
542 }
543  
544 941 PUTBACK;
545 941 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 941 0 941
546 941 LEAVE;
547  
548 941 return rc;
549 }
550  
551 88 static int perl_vt_Rowid( sqlite3_vtab_cursor *pVtabCursor,
552 sqlite3_int64 *pRowid ){
553 dTHX;
554 88 dSP;
555 int count;
556 88 int rc = SQLITE_ERROR;
557  
558 88 ENTER;
559 88 SAVETMPS;
560  
561 /* call the rowid() method */
562 88 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 88 88
563 88 ▶ XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj);
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(((perl_vtab_cursor *) pVtabCursor)->perl_cursor_obj); 0 88 88
564 88 PUTBACK;
565 88 count = call_method ("ROWID", G_SCALAR);
566 88 SPAGAIN;
567 88 ▶ if (count != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (count != 1) { 0 88 88
568 0 warn("cursor->ROWID() returned %d vals instead of 1", count);
569 0 SP -= count;
570 }
571 else {
572 88 *pRowid =POPi;
573 88 rc = SQLITE_OK;
574 }
575  
576 88 PUTBACK;
577 88 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 88 0 88
578 88 LEAVE;
579  
580 88 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 21 static int perl_vt_Sync(sqlite3_vtab *pVTab){
641 21 return _call_perl_vtab_method(pVTab, "SYNC_TRANSACTION", 0);
642 }
643  
644 21 static int perl_vt_Commit(sqlite3_vtab *pVTab){
645 21 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 13 sqlite_db_destroy_module_data(void *pAux)
793 {
794 dTHX;
795 13 dSP;
796 int count;
797 13 int rc = SQLITE_ERROR;
798 perl_vtab_init *init_data;
799  
800 13 ENTER;
801 13 SAVETMPS;
802  
803 13 init_data = (perl_vtab_init *)pAux;
804  
805 /* call the DESTROY_MODULE() method */
806 13 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 13 13
807 13 ▶ XPUSHs(sv_2mortal(newSVpv(init_data->perl_class, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(init_data->perl_class, 0))); 0 13 13
808 13 PUTBACK;
809 13 count = call_method("DESTROY_MODULE", G_VOID);
810 13 SPAGAIN;
811 13 SP -= count;
812  
813 /* free module memory */
814 13 SvREFCNT_dec(init_data->dbh);
815 13 sqlite3_free((char *)init_data->perl_class);
816  
817 13 PUTBACK;
818 13 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 13 0 13
819 13 LEAVE;
820 13 }
821  
822  
823  
824 int
825 13 sqlite_db_create_module(pTHX_ SV *dbh, const char *name, const char *perl_class)
826 {
827 13 dSP;
828 13 D_imp_dbh(dbh);
829 13 int count, rc, retval = TRUE;
830 char *module_ISA;
831 char *loading_code;
832 perl_vtab_init *init_data;
833  
834 13 ENTER;
835 13 SAVETMPS;
836  
837 13 ▶ if (!DBIc_ACTIVE(imp_dbh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!DBIc_ACTIVE(imp_dbh)) { 0 13 13
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 13 module_ISA = sqlite3_mprintf("%s::ISA", perl_class);
844 13 ▶ if (!get_av(module_ISA, 0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!get_av(module_ISA, 0)) { 7 6 13
845 7 loading_code = sqlite3_mprintf("use %s", perl_class);
846 7 eval_pv(loading_code, TRUE);
847 7 sqlite3_free(loading_code);
848 }
849 13 sqlite3_free(module_ISA);
850  
851 /* build the init datastructure that will be passed to perl_vt_New() */
852 13 init_data = sqlite3_malloc(sizeof(*init_data));
853 13 init_data->dbh = newRV(dbh);
854 13 sv_rvweaken(init_data->dbh);
855 13 init_data->perl_class = sqlite3_mprintf(perl_class);
856  
857 /* register within sqlite */
858 13 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 13 ▶ if ( rc != SQLITE_OK ) {
Branch: 1 branch
BranchTrueFalseTotal
if ( rc != SQLITE_OK ) { 0 13 13
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 13 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 13 13
873 13 ▶ XPUSHs(sv_2mortal(newSVpv(perl_class, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(perl_class, 0))); 0 13 13
874 13 ▶ XPUSHs(sv_2mortal(newSVpv(name, 0)));
Branch: 1 branch
BranchTrueFalseTotal
XPUSHs(sv_2mortal(newSVpv(name, 0))); 0 13 13
875 13 PUTBACK;
876 13 count = call_method("CREATE_MODULE", G_VOID);
877 13 SPAGAIN;
878 13 SP -= count;
879  
880 13 PUTBACK;
881 13 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 13 0 13
882 13 LEAVE;
883  
884 13 return retval;
885 }
« SQLite.xsi ↑ Summary dbdimp.c »