File Coverage

dbdimp.h
Criterion Covered Total %
statement 0 9 0.0
branch n/a
condition n/a
subroutine n/a
pod n/a
total 0 9 0.0


line stmt bran cond sub pod time code
1              
2             #ifndef _DBDIMP_H
3             #define _DBDIMP_H 1
4              
5             #include "SQLiteXS.h"
6             #include "sqlite3.h"
7              
8             #define MY_CXT_KEY "DBD::SQLite::_guts" XS_VERSION
9              
10             typedef enum {
11             DBD_SQLITE_STRING_MODE_PV,
12             DBD_SQLITE_STRING_MODE_BYTES,
13              
14             /* Leave space here so that we can use DBD_SQLITE_STRING_MODE_UNICODE_ANY
15             as a means of checking for any unicode mode. */
16              
17             DBD_SQLITE_STRING_MODE_UNICODE_NAIVE = 4,
18             DBD_SQLITE_STRING_MODE_UNICODE_FALLBACK,
19             DBD_SQLITE_STRING_MODE_UNICODE_STRICT,
20              
21             _DBD_SQLITE_STRING_MODE_COUNT,
22             } dbd_sqlite_string_mode_t;
23              
24             #define DBD_SQLITE_STRING_MODE_UNICODE_ANY DBD_SQLITE_STRING_MODE_UNICODE_NAIVE
25              
26             typedef struct {
27             dbd_sqlite_string_mode_t last_dbh_string_mode;
28             } my_cxt_t;
29              
30             #define PERL_UNICODE_DOES_NOT_WORK_WELL \
31             (PERL_REVISION <= 5) && ((PERL_VERSION < 8) \
32             || (PERL_VERSION == 8 && PERL_SUBVERSION < 5))
33              
34             /* 30 second timeout by default */
35             #define SQL_TIMEOUT 30000
36              
37             #ifndef sqlite3_int64
38             #define sqlite3_int64 sqlite_int64
39             #endif
40              
41             #define DBD_SQLITE_UTF8_DECODE_NAIVE(sv) SvUTF8_on(sv)
42              
43             #define DBD_SQLITE_UTF8_DECODE_CHECKED(sv, onfail) ( \
44             is_utf8_string((U8*) SvPVX(sv), SvCUR(sv)) \
45             ? SvUTF8_on(sv) \
46             : onfail("Received invalid UTF-8 from SQLite; cannot decode!") \
47             )
48              
49             #define DBD_SQLITE_UTF8_DECODE_WITH_FALLBACK(sv) ( \
50             DBD_SQLITE_UTF8_DECODE_CHECKED(sv, warn) \
51             )
52              
53             #define DBD_SQLITE_UTF8_DECODE_STRICT(sv) ( \
54             DBD_SQLITE_UTF8_DECODE_CHECKED(sv, croak) \
55             )
56              
57             #define DBD_SQLITE_PREP_SV_FOR_SQLITE(sv, string_mode) STMT_START { \
58             if (string_mode & DBD_SQLITE_STRING_MODE_UNICODE_ANY) { \
59             sv_utf8_upgrade(sv); \
60             } \
61             else if (string_mode == DBD_SQLITE_STRING_MODE_BYTES) { \
62             sv_utf8_downgrade(sv, 0); \
63             } \
64             } STMT_END
65              
66             #define DBD_SQLITE_UTF8_DECODE_IF_NEEDED(sv, string_mode) ( \
67             string_mode == DBD_SQLITE_STRING_MODE_UNICODE_NAIVE \
68             ? DBD_SQLITE_UTF8_DECODE_NAIVE(sv) \
69             : string_mode == DBD_SQLITE_STRING_MODE_UNICODE_FALLBACK \
70             ? DBD_SQLITE_UTF8_DECODE_WITH_FALLBACK(sv) \
71             : string_mode == DBD_SQLITE_STRING_MODE_UNICODE_STRICT \
72             ? DBD_SQLITE_UTF8_DECODE_STRICT(sv) \
73             : 0 \
74             )
75              
76             /* A linked list of statements prepared by this module */
77             typedef struct stmt_list_s stmt_list_s;
78              
79             struct stmt_list_s {
80             sqlite3_stmt * stmt;
81             stmt_list_s * prev;
82             };
83              
84             /* Driver Handle */
85             struct imp_drh_st {
86             dbih_drc_t com;
87             /* sqlite specific bits */
88             };
89              
90             /* Database Handle */
91             struct imp_dbh_st {
92             dbih_dbc_t com;
93             /* sqlite specific bits */
94             sqlite3 *db;
95             dbd_sqlite_string_mode_t string_mode;
96             bool handle_binary_nulls;
97             int timeout;
98             AV *functions;
99             AV *aggregates;
100             SV *collation_needed_callback;
101             bool allow_multiple_statements;
102             bool use_immediate_transaction;
103             bool see_if_its_a_number;
104             int extended_result_codes;
105             stmt_list_s * stmt_list;
106             bool began_transaction;
107             bool prefer_numeric_type;
108             };
109              
110             /* Statement Handle */
111             struct imp_sth_st {
112             dbih_stc_t com;
113             /* sqlite specific bits */
114             sqlite3_stmt *stmt;
115             /*
116             char **results;
117             char **coldata;
118             */
119             int retval;
120             int nrow;
121             AV *params;
122             AV *col_types;
123             const char *unprepared_statements;
124             };
125              
126             #define dbd_init sqlite_init
127             #define dbd_discon_all sqlite_discon_all
128             #define dbd_db_login6 sqlite_db_login6
129             #define dbd_db_commit sqlite_db_commit
130             #define dbd_db_rollback sqlite_db_rollback
131             #define dbd_db_disconnect sqlite_db_disconnect
132             #define dbd_db_destroy sqlite_db_destroy
133             #define dbd_db_STORE_attrib sqlite_db_STORE_attrib
134             #define dbd_db_FETCH_attrib sqlite_db_FETCH_attrib
135             #define dbd_db_last_insert_id sqlite_db_last_insert_id
136             #define dbd_st_prepare_sv sqlite_st_prepare_sv
137             #define dbd_st_rows sqlite_st_rows
138             #define dbd_st_execute sqlite_st_execute
139             #define dbd_st_fetch sqlite_st_fetch
140             #define dbd_st_finish3 sqlite_st_finish3
141             #define dbd_st_finish sqlite_st_finish
142             #define dbd_st_destroy sqlite_st_destroy
143             #define dbd_st_blob_read sqlite_st_blob_read
144             #define dbd_st_STORE_attrib sqlite_st_STORE_attrib
145             #define dbd_st_FETCH_attrib sqlite_st_FETCH_attrib
146             #define dbd_bind_ph sqlite_bind_ph
147             #define dbd_st_bind_col sqlite_bind_col
148              
149             typedef struct aggrInfo aggrInfo;
150             struct aggrInfo {
151             SV *aggr_inst;
152             SV *err;
153             int inited;
154             };
155              
156              
157             int sqlite_db_create_function(pTHX_ SV *dbh, const char *name, int argc, SV *func, int flags);
158              
159             #ifndef SQLITE_OMIT_LOAD_EXTENSION
160             int sqlite_db_enable_load_extension(pTHX_ SV *dbh, int onoff);
161             int sqlite_db_load_extension(pTHX_ SV *dbh, const char *file, const char *proc);
162             #endif
163              
164             int sqlite_db_create_aggregate(pTHX_ SV *dbh, const char *name, int argc, SV *aggr, int flags );
165             int sqlite_db_create_collation(pTHX_ SV *dbh, const char *name, SV *func);
166             int sqlite_db_progress_handler(pTHX_ SV *dbh, int n_opcodes, SV *handler);
167             int sqlite_bind_col( SV *sth, imp_sth_t *imp_sth, SV *col, SV *ref, IV sql_type, SV *attribs );
168             int sqlite_db_busy_timeout (pTHX_ SV *dbh, SV *timeout );
169             int sqlite_db_backup_from_file(pTHX_ SV *dbh, char *filename);
170             int sqlite_db_backup_to_file(pTHX_ SV *dbh, char *filename);
171             int sqlite_db_backup_from_dbh(pTHX_ SV *dbh, SV *from);
172             int sqlite_db_backup_to_dbh(pTHX_ SV *dbh, SV *to);
173             void sqlite_db_collation_needed(pTHX_ SV *dbh, SV *callback );
174             SV* sqlite_db_commit_hook( pTHX_ SV *dbh, SV *hook );
175             SV* sqlite_db_rollback_hook( pTHX_ SV *dbh, SV *hook );
176             SV* sqlite_db_update_hook( pTHX_ SV *dbh, SV *hook );
177             int sqlite_db_set_authorizer( pTHX_ SV *dbh, SV *authorizer );
178             AV* sqlite_compile_options();
179             int sqlite_db_trace(pTHX_ SV *dbh, SV *func);
180             int sqlite_db_profile(pTHX_ SV *dbh, SV *func);
181             HV* sqlite_db_table_column_metadata(pTHX_ SV *dbh, SV *dbname, SV *tablename, SV *columnname);
182             HV* _sqlite_db_status(pTHX_ SV *dbh, int reset);
183             SV* sqlite_db_filename(pTHX_ SV *dbh);
184             int sqlite_db_register_fts3_perl_tokenizer(pTHX_ SV *dbh);
185             HV* _sqlite_status(int reset);
186             HV* _sqlite_st_status(pTHX_ SV *sth, int reset);
187             int sqlite_db_create_module(pTHX_ SV *dbh, const char *name, const char *perl_class);
188             int sqlite_db_limit(pTHX_ SV *dbh, int id, int new_value);
189             int sqlite_db_config(pTHX_ SV *dbh, int id, int new_value);
190             int sqlite_db_get_autocommit(pTHX_ SV *dbh);
191             int sqlite_db_txn_state(pTHX_ SV *dbh, SV *schema);
192             int sqlite_db_do_sv(SV *dbh, imp_dbh_t *imp_dbh, SV *sv_statement);
193             void init_cxt();
194              
195              
196             #ifdef SvUTF8_on
197              
198             static SV *
199 0           newUTF8SVpv(char *s, STRLEN len) {
200             dTHX;
201             register SV *sv;
202              
203 0           sv = newSVpv(s, len);
204 0           SvUTF8_on(sv);
205 0           return sv;
206             }
207              
208             static SV *
209 0           newUTF8SVpvn(char *s, STRLEN len) {
210             dTHX;
211             register SV *sv;
212              
213 0           sv = newSV(0);
214 0           sv_setpvn(sv, s, len);
215 0           SvUTF8_on(sv);
216 0           return sv;
217             }
218              
219             #else /* #ifdef SvUTF8_on */
220              
221             #define newUTF8SVpv newSVpv
222             #define newUTF8SVpvn newSVpvn
223             #define SvUTF8_on(a) (a)
224             #define SvUTF8_off(a) (a)
225             #define sv_utf8_upgrade(a) (a)
226              
227             #endif /* #ifdef SvUTF8_on */
228              
229             #ifdef _MSC_VER
230             # define atoll _atoi64
231             #endif
232              
233             #endif /* #ifndef _DBDIMP_H */