File: SQLite.xs

package info (click to toggle)
libdbd-sqlite3-perl 1.62-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 9,708 kB
  • sloc: ansic: 140,930; perl: 8,458; pascal: 286; makefile: 7
file content (438 lines) | stat: -rw-r--r-- 8,814 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#define PERL_NO_GET_CONTEXT

#include "SQLiteXS.h"

DBISTATE_DECLARE;

MODULE = DBD::SQLite          PACKAGE = DBD::SQLite::db

PROTOTYPES: DISABLE

BOOT:
    init_cxt();
    sv_setpv(get_sv("DBD::SQLite::sqlite_version",        TRUE|GV_ADDMULTI), SQLITE_VERSION);
    sv_setiv(get_sv("DBD::SQLite::sqlite_version_number", TRUE|GV_ADDMULTI), SQLITE_VERSION_NUMBER);

void
_do(dbh, statement)
    SV *dbh
    SV *statement
    CODE:
    {
        D_imp_dbh(dbh);
        IV retval;
        retval = sqlite_db_do_sv(dbh, imp_dbh, statement);
        /* remember that dbd_db_do_sv must return <= -2 for error     */
        if (retval == 0)            /* ok with no rows affected     */
            XST_mPV(0, "0E0");      /* (true but zero)              */
        else if (retval < -1)       /* -1 == unknown number of rows */
            XST_mUNDEF(0);          /* <= -2 means error            */
        else
            XST_mIV(0, retval);     /* typically 1, rowcount or -1  */
    }

IV
last_insert_rowid(dbh)
    SV *dbh
    ALIAS:
        DBD::SQLite::db::sqlite_last_insert_rowid = 1
    CODE:
    {
        D_imp_dbh(dbh);
        RETVAL = (IV)sqlite3_last_insert_rowid(imp_dbh->db);
    }
    OUTPUT:
        RETVAL

static int
create_function(dbh, name, argc, func, flags = 0)
    SV *dbh
    char *name
    int argc
    SV *func
    int flags
    ALIAS:
        DBD::SQLite::db::sqlite_create_function = 1
    CODE:
    {
        RETVAL = sqlite_db_create_function(aTHX_ dbh, name, argc, func, flags );
    }
    OUTPUT:
        RETVAL

#ifndef SQLITE_OMIT_LOAD_EXTENSION

static int
enable_load_extension(dbh, onoff)
    SV *dbh
    int onoff
    ALIAS:
        DBD::SQLite::db::sqlite_enable_load_extension = 1
    CODE:
    {
        RETVAL = sqlite_db_enable_load_extension(aTHX_ dbh, onoff );
    }
    OUTPUT:
        RETVAL

static int
load_extension(dbh, file, proc = 0)
    SV *dbh
    const char *file
    const char *proc
    ALIAS:
        DBD::SQLite::db::sqlite_load_extension = 1
    CODE:
    {
        RETVAL = sqlite_db_load_extension(aTHX_ dbh, file, proc);
    }
    OUTPUT:
        RETVAL

#endif

static int
create_aggregate(dbh, name, argc, aggr, flags = 0)
    SV *dbh
    char *name
    int argc
    SV *aggr
    int flags
    ALIAS:
        DBD::SQLite::db::sqlite_create_aggregate = 1
    CODE:
    {
        RETVAL = sqlite_db_create_aggregate(aTHX_ dbh, name, argc, aggr, flags );
    }
    OUTPUT:
        RETVAL

static int
create_collation(dbh, name, func)
    SV *dbh
    char *name
    SV *func
    ALIAS:
        DBD::SQLite::db::sqlite_create_collation = 1
    CODE:
    {
        RETVAL = sqlite_db_create_collation(aTHX_ dbh, name, func );
    }
    OUTPUT:
        RETVAL


static void
collation_needed(dbh, callback)
    SV *dbh
    SV *callback
    ALIAS:
        DBD::SQLite::db::sqlite_collation_needed = 1
    CODE:
    {
        sqlite_db_collation_needed(aTHX_ dbh, callback );
    }


static int
progress_handler(dbh, n_opcodes, handler)
    SV *dbh
    int n_opcodes
    SV *handler
    ALIAS:
        DBD::SQLite::db::sqlite_progress_handler = 1
    CODE:
    {
        RETVAL = sqlite_db_progress_handler(aTHX_ dbh, n_opcodes, handler );
    }
    OUTPUT:
        RETVAL

static int
sqlite_trace(dbh, callback)
    SV *dbh
    SV *callback
    CODE:
    {
        RETVAL = sqlite_db_trace(aTHX_ dbh, callback );
    }
    OUTPUT:
        RETVAL

static int
profile(dbh, callback)
    SV *dbh
    SV *callback
    ALIAS:
        DBD::SQLite::db::sqlite_profile = 1
    CODE:
    {
        RETVAL = sqlite_db_profile(aTHX_ dbh, callback );
    }
    OUTPUT:
        RETVAL

SV*
commit_hook(dbh, hook)
    SV *dbh
    SV *hook
    ALIAS:
        DBD::SQLite::db::sqlite_commit_hook = 1
    CODE:
    {
        RETVAL = (SV*) sqlite_db_commit_hook( aTHX_ dbh, hook );
    }
    OUTPUT:
        RETVAL

SV*
rollback_hook(dbh, hook)
    SV *dbh
    SV *hook
    ALIAS:
        DBD::SQLite::db::sqlite_rollback_hook = 1
    CODE:
    {
        RETVAL = (SV*) sqlite_db_rollback_hook( aTHX_ dbh, hook );
    }
    OUTPUT:
        RETVAL

SV*
update_hook(dbh, hook)
    SV *dbh
    SV *hook
    ALIAS:
        DBD::SQLite::db::sqlite_update_hook = 1
    CODE:
    {
        RETVAL = (SV*) sqlite_db_update_hook( aTHX_ dbh, hook );
    }
    OUTPUT:
        RETVAL


static int
set_authorizer(dbh, authorizer)
    SV *dbh
    SV *authorizer
    ALIAS:
        DBD::SQLite::db::sqlite_set_authorizer = 1
    CODE:
    {
        RETVAL = sqlite_db_set_authorizer( aTHX_ dbh, authorizer );
    }
    OUTPUT:
        RETVAL


int
busy_timeout(dbh, timeout=NULL)
    SV *dbh
    SV *timeout
    ALIAS:
        DBD::SQLite::db::sqlite_busy_timeout = 1
    CODE:
        RETVAL = sqlite_db_busy_timeout(aTHX_ dbh, timeout );
    OUTPUT:
        RETVAL

static int
backup_from_file(dbh, filename)
    SV *dbh
    char *filename
    ALIAS:
        DBD::SQLite::db::sqlite_backup_from_file = 1
    CODE:
        RETVAL = sqlite_db_backup_from_file(aTHX_ dbh, filename);
    OUTPUT:
        RETVAL

static int
backup_to_file(dbh, filename)
    SV *dbh
    char *filename
    ALIAS:
        DBD::SQLite::db::sqlite_backup_to_file = 1
    CODE:
        RETVAL = sqlite_db_backup_to_file(aTHX_ dbh, filename);
    OUTPUT:
        RETVAL

static int
backup_from_dbh(dbh, from)
    SV *dbh
    SV *from
    ALIAS:
        DBD::SQLite::db::sqlite_backup_from_dbh = 1
    CODE:
        RETVAL = sqlite_db_backup_from_dbh(aTHX_ dbh, from);
    OUTPUT:
        RETVAL

static int
backup_to_dbh(dbh, to)
    SV *dbh
    SV *to
    ALIAS:
        DBD::SQLite::db::sqlite_backup_to_dbh = 1
    CODE:
        RETVAL = sqlite_db_backup_to_dbh(aTHX_ dbh, to);
    OUTPUT:
        RETVAL

HV*
table_column_metadata(dbh, dbname, tablename, columnname)
    SV* dbh
    SV* dbname
    SV* tablename
    SV* columnname
    ALIAS:
        DBD::SQLite::db::sqlite_table_column_metadata = 1
    CODE:
        RETVAL = sqlite_db_table_column_metadata(aTHX_ dbh, dbname, tablename, columnname);
    OUTPUT:
        RETVAL

SV*
db_filename(dbh)
    SV* dbh
    ALIAS:
        DBD::SQLite::db::sqlite_db_filename = 1
    CODE:
        RETVAL = sqlite_db_filename(aTHX_ dbh);
    OUTPUT:
        RETVAL

static int
register_fts3_perl_tokenizer(dbh)
    SV *dbh
    ALIAS:
        DBD::SQLite::db::sqlite_register_fts3_perl_tokenizer = 1
    CODE:
        RETVAL = sqlite_db_register_fts3_perl_tokenizer(aTHX_ dbh);
    OUTPUT:
        RETVAL

HV*
db_status(dbh, reset = 0)
    SV* dbh
    int reset
    ALIAS:
        DBD::SQLite::db::sqlite_db_status = 1
    CODE:
        RETVAL = (HV*)_sqlite_db_status(aTHX_ dbh, reset);
    OUTPUT:
        RETVAL


static int
create_module(dbh, name, perl_class)
    SV *dbh
    char *name
    char *perl_class
    ALIAS:
        DBD::SQLite::db::sqlite_create_module = 1
    CODE:
    {
        RETVAL = sqlite_db_create_module(aTHX_ dbh, name, perl_class);
    }
    OUTPUT:
        RETVAL

static int
limit(dbh, id, new_value = -1)
    SV *dbh
    int id
    int new_value
    ALIAS:
        DBD::SQLite::db::sqlite_limit = 1
    CODE:
    {
        RETVAL = sqlite_db_limit(aTHX_ dbh, id, new_value);
    }
    OUTPUT:
        RETVAL

static int
db_config(dbh, id, new_value = -1)
    SV *dbh
    int id
    int new_value
    ALIAS:
        DBD::SQLite::db::sqlite_db_config = 1
    CODE:
    {
        RETVAL = sqlite_db_config(aTHX_ dbh, id, new_value);
    }
    OUTPUT:
        RETVAL

MODULE = DBD::SQLite          PACKAGE = DBD::SQLite::st

PROTOTYPES: DISABLE

HV*
st_status(sth, reset = 0)
    SV* sth
    int reset
    ALIAS:
        DBD::SQLite::st::sqlite_st_status = 1
    CODE:
        RETVAL = (HV*)_sqlite_st_status(aTHX_ sth, reset);
    OUTPUT:
        RETVAL

MODULE = DBD::SQLite          PACKAGE = DBD::SQLite

# a couple of constants exported from sqlite3.h

PROTOTYPES: DISABLE

static int
compile_options()
    CODE:
        int n = 0;
        AV* av = (AV*)sqlite_compile_options();
        if (av) {
            int i;
            n = av_len(av) + 1;
            EXTEND(sp, n);
            for (i = 0; i < n; i++) {
                PUSHs(AvARRAY(av)[i]);
            }
        }
        XSRETURN(n);

HV*
sqlite_status(reset = 0)
    int reset
    CODE:
        RETVAL = (HV*)_sqlite_status(reset);
    OUTPUT:
        RETVAL

#if SQLITE_VERSION_NUMBER >= 3010000

int
strglob(const char *zglob, const char *zstr)
    CODE:
        RETVAL = sqlite3_strglob(zglob, zstr);
    OUTPUT:
        RETVAL

int
strlike(const char *zglob, const char *zstr, const char *esc = NULL)
    CODE:
        if (esc) {
            RETVAL = sqlite3_strlike(zglob, zstr, (unsigned int)(*esc));
        } else {
            RETVAL = sqlite3_strlike(zglob, zstr, 0);
        }
    OUTPUT:
        RETVAL

#endif

INCLUDE: constants.inc
INCLUDE: SQLite.xsi