line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id$ |
2
|
|
|
|
|
|
|
# Copyright (c) 1997-2002 Tim Bunce Ireland |
3
|
|
|
|
|
|
|
# Copyright (c) 2002 Jonathan Leffler |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public |
6
|
|
|
|
|
|
|
# License or the Artistic License, as specified in the Perl README file. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#include "Driver_xst.h" |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Historically dbd_db_do4, dbd_st_execute, and dbd_st_rows returned an 'int' type. |
12
|
|
|
|
|
|
|
# That's only 32 bits (31+sign) so isn't sufficient for very large row counts |
13
|
|
|
|
|
|
|
# So now instead of defining those macros, drivers can define dbd_db_do4_iv, |
14
|
|
|
|
|
|
|
# dbd_st_execute_iv, and dbd_st_rows_iv to be the names of functions that |
15
|
|
|
|
|
|
|
# return an 'IV' type. They could also set DBIc_ROW_COUNT(imp_sth). |
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# To save a mess of #ifdef's we arrange for dbd_st_execute (etc) to work |
18
|
|
|
|
|
|
|
# as dbd_st_execute_iv if that's defined |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
#if defined(dbd_st_execute_iv) |
21
|
|
|
|
|
|
|
#undef dbd_st_execute |
22
|
|
|
|
|
|
|
#define dbd_st_execute dbd_st_execute_iv |
23
|
|
|
|
|
|
|
#endif |
24
|
|
|
|
|
|
|
#if defined(dbd_st_rows_iv) |
25
|
|
|
|
|
|
|
#undef dbd_st_rows |
26
|
|
|
|
|
|
|
#define dbd_st_rows dbd_st_rows_iv |
27
|
|
|
|
|
|
|
#endif |
28
|
|
|
|
|
|
|
#if defined(dbd_db_do4_iv) |
29
|
|
|
|
|
|
|
#undef dbd_db_do4 |
30
|
|
|
|
|
|
|
#define dbd_db_do4 dbd_db_do4_iv |
31
|
|
|
|
|
|
|
#endif |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
MODULE = DBD::SQLite PACKAGE = DBD::SQLite |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
REQUIRE: 1.929 |
36
|
|
|
|
|
|
|
PROTOTYPES: DISABLE |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
BOOT: |
39
|
|
|
|
|
|
|
PERL_UNUSED_VAR(items); |
40
|
116
|
50
|
|
|
|
|
DBISTATE_INIT; |
41
|
|
|
|
|
|
|
/* XXX this interface will change: */ |
42
|
116
|
|
|
|
|
|
DBI_IMP_SIZE("DBD::SQLite::dr::imp_data_size", sizeof(imp_drh_t)); |
43
|
116
|
|
|
|
|
|
DBI_IMP_SIZE("DBD::SQLite::db::imp_data_size", sizeof(imp_dbh_t)); |
44
|
116
|
|
|
|
|
|
DBI_IMP_SIZE("DBD::SQLite::st::imp_data_size", sizeof(imp_sth_t)); |
45
|
116
|
|
|
|
|
|
dbd_init(DBIS); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# ------------------------------------------------------------ |
49
|
|
|
|
|
|
|
# driver level interface |
50
|
|
|
|
|
|
|
# ------------------------------------------------------------ |
51
|
|
|
|
|
|
|
MODULE = DBD::SQLite PACKAGE = DBD::SQLite::dr |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
void |
55
|
|
|
|
|
|
|
dbixs_revision(...) |
56
|
|
|
|
|
|
|
PPCODE: |
57
|
0
|
|
|
|
|
|
ST(0) = sv_2mortal(newSViv(DBIXS_REVISION)); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#ifdef dbd_discon_all |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# disconnect_all renamed and ALIAS'd to avoid length clash on VMS :-( |
63
|
|
|
|
|
|
|
bool |
64
|
|
|
|
|
|
|
discon_all_(drh) |
65
|
|
|
|
|
|
|
SV * drh |
66
|
|
|
|
|
|
|
ALIAS: |
67
|
|
|
|
|
|
|
disconnect_all = 1 |
68
|
|
|
|
|
|
|
CODE: |
69
|
110
|
|
|
|
|
|
D_imp_drh(drh); |
70
|
|
|
|
|
|
|
PERL_UNUSED_VAR(ix); |
71
|
110
|
|
|
|
|
|
RETVAL = dbd_discon_all(drh, imp_drh); |
72
|
|
|
|
|
|
|
OUTPUT: |
73
|
|
|
|
|
|
|
RETVAL |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
#endif /* dbd_discon_all */ |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#ifdef dbd_dr_data_sources |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
void |
81
|
|
|
|
|
|
|
data_sources(drh, attr = Nullsv) |
82
|
|
|
|
|
|
|
SV *drh |
83
|
|
|
|
|
|
|
SV *attr |
84
|
|
|
|
|
|
|
PPCODE: |
85
|
|
|
|
|
|
|
{ |
86
|
|
|
|
|
|
|
D_imp_drh(drh); |
87
|
|
|
|
|
|
|
AV *av = dbd_dr_data_sources(drh, imp_drh, attr); |
88
|
|
|
|
|
|
|
if (av) { |
89
|
|
|
|
|
|
|
int i; |
90
|
|
|
|
|
|
|
int n = AvFILL(av)+1; |
91
|
|
|
|
|
|
|
EXTEND(sp, n); |
92
|
|
|
|
|
|
|
for (i = 0; i < n; ++i) { |
93
|
|
|
|
|
|
|
PUSHs(AvARRAY(av)[i]); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
#endif |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# ------------------------------------------------------------ |
102
|
|
|
|
|
|
|
# database level interface |
103
|
|
|
|
|
|
|
# ------------------------------------------------------------ |
104
|
|
|
|
|
|
|
MODULE = DBD::SQLite PACKAGE = DBD::SQLite::db |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
bool |
108
|
|
|
|
|
|
|
_login(dbh, dbname, username, password, attribs=Nullsv) |
109
|
|
|
|
|
|
|
SV * dbh |
110
|
|
|
|
|
|
|
SV * dbname |
111
|
|
|
|
|
|
|
SV * username |
112
|
|
|
|
|
|
|
SV * password |
113
|
|
|
|
|
|
|
SV * attribs |
114
|
|
|
|
|
|
|
CODE: |
115
|
|
|
|
|
|
|
{ |
116
|
313
|
|
|
|
|
|
D_imp_dbh(dbh); |
117
|
|
|
|
|
|
|
#if !defined(dbd_db_login6_sv) |
118
|
|
|
|
|
|
|
STRLEN lna; |
119
|
313
|
100
|
|
|
|
|
char *u = (SvOK(username)) ? SvPV(username,lna) : (char*)""; |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
120
|
313
|
100
|
|
|
|
|
char *p = (SvOK(password)) ? SvPV(password,lna) : (char*)""; |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#endif |
122
|
|
|
|
|
|
|
#ifdef dbd_db_login6_sv |
123
|
|
|
|
|
|
|
RETVAL = dbd_db_login6_sv(dbh, imp_dbh, dbname, username, password, attribs); |
124
|
|
|
|
|
|
|
#elif defined(dbd_db_login6) |
125
|
313
|
50
|
|
|
|
|
RETVAL = dbd_db_login6(dbh, imp_dbh, SvPV_nolen(dbname), u, p, attribs); |
126
|
|
|
|
|
|
|
#else |
127
|
|
|
|
|
|
|
PERL_UNUSED_ARG(attribs); |
128
|
|
|
|
|
|
|
RETVAL = dbd_db_login( dbh, imp_dbh, SvPV_nolen(dbname), u, p); |
129
|
|
|
|
|
|
|
#endif |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
OUTPUT: |
132
|
|
|
|
|
|
|
RETVAL |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
void |
136
|
|
|
|
|
|
|
selectall_arrayref(...) |
137
|
|
|
|
|
|
|
PREINIT: |
138
|
|
|
|
|
|
|
SV *sth; |
139
|
|
|
|
|
|
|
SV **maxrows_svp; |
140
|
|
|
|
|
|
|
SV **tmp_svp; |
141
|
|
|
|
|
|
|
SV *tmp_sv; |
142
|
373
|
|
|
|
|
|
SV *attr = &PL_sv_undef; |
143
|
|
|
|
|
|
|
imp_sth_t *imp_sth; |
144
|
|
|
|
|
|
|
CODE: |
145
|
373
|
100
|
|
|
|
|
if (items > 2) { |
146
|
116
|
|
|
|
|
|
attr = ST(2); |
147
|
282
|
100
|
|
|
|
|
if (SvROK(attr) && |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
148
|
251
|
50
|
|
|
|
|
(DBD_ATTRIB_TRUE(attr,"Slice",5,tmp_svp) || DBD_ATTRIB_TRUE(attr,"Columns",7,tmp_svp)) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
149
|
|
|
|
|
|
|
) { |
150
|
|
|
|
|
|
|
/* fallback to perl implementation */ |
151
|
81
|
|
|
|
|
|
SV *tmp =dbixst_bounce_method("DBD::SQLite::db::SUPER::selectall_arrayref", items); |
152
|
81
|
|
|
|
|
|
SPAGAIN; |
153
|
81
|
|
|
|
|
|
ST(0) = tmp; |
154
|
81
|
|
|
|
|
|
XSRETURN(1); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
/* --- prepare --- */ |
158
|
292
|
50
|
|
|
|
|
if (SvROK(ST(1))) { |
159
|
|
|
|
|
|
|
MAGIC *mg; |
160
|
0
|
|
|
|
|
|
sth = ST(1); |
161
|
|
|
|
|
|
|
/* switch to inner handle if not already */ |
162
|
0
|
0
|
|
|
|
|
if ( (mg = mg_find(SvRV(sth),'P')) ) |
163
|
0
|
|
|
|
|
|
sth = mg->mg_obj; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
else { |
166
|
292
|
|
|
|
|
|
sth = dbixst_bounce_method("prepare", 3); |
167
|
292
|
|
|
|
|
|
SPAGAIN; SP -= items; /* because stack might have been realloc'd */ |
168
|
292
|
50
|
|
|
|
|
if (!SvROK(sth)) |
169
|
0
|
|
|
|
|
|
XSRETURN_UNDEF; |
170
|
|
|
|
|
|
|
/* switch to inner handle */ |
171
|
292
|
|
|
|
|
|
sth = mg_find(SvRV(sth),'P')->mg_obj; |
172
|
|
|
|
|
|
|
} |
173
|
292
|
|
|
|
|
|
imp_sth = (imp_sth_t*)(DBIh_COM(sth)); |
174
|
|
|
|
|
|
|
/* --- bind_param --- */ |
175
|
292
|
100
|
|
|
|
|
if (items > 3) { /* need to bind params before execute */ |
176
|
35
|
50
|
|
|
|
|
if (!dbdxst_bind_params(sth, imp_sth, items-2, ax+2) ) { |
177
|
0
|
|
|
|
|
|
XSRETURN_UNDEF; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
/* --- execute --- */ |
181
|
292
|
|
|
|
|
|
DBIc_ROW_COUNT(imp_sth) = 0; |
182
|
292
|
50
|
|
|
|
|
if ( dbd_st_execute(sth, imp_sth) <= -2 ) { /* -2 == error */ |
183
|
0
|
|
|
|
|
|
XSRETURN_UNDEF; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
/* --- fetchall --- */ |
186
|
292
|
50
|
|
|
|
|
maxrows_svp = DBD_ATTRIB_GET_SVP(attr, "MaxRows", 7); |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
187
|
292
|
50
|
|
|
|
|
tmp_sv = dbdxst_fetchall_arrayref(sth, &PL_sv_undef, (maxrows_svp) ? *maxrows_svp : &PL_sv_undef); |
188
|
292
|
|
|
|
|
|
SPAGAIN; |
189
|
292
|
|
|
|
|
|
ST(0) = tmp_sv; |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
void |
193
|
|
|
|
|
|
|
selectrow_arrayref(...) |
194
|
|
|
|
|
|
|
ALIAS: |
195
|
|
|
|
|
|
|
selectrow_array = 1 |
196
|
|
|
|
|
|
|
PREINIT: |
197
|
270
|
|
|
|
|
|
int is_selectrow_array = (ix == 1); |
198
|
|
|
|
|
|
|
imp_sth_t *imp_sth; |
199
|
|
|
|
|
|
|
SV *sth; |
200
|
|
|
|
|
|
|
AV *row_av; |
201
|
|
|
|
|
|
|
PPCODE: |
202
|
270
|
100
|
|
|
|
|
if (SvROK(ST(1))) { |
203
|
|
|
|
|
|
|
MAGIC *mg; |
204
|
4
|
|
|
|
|
|
sth = ST(1); |
205
|
|
|
|
|
|
|
/* switch to inner handle if not already */ |
206
|
4
|
50
|
|
|
|
|
if ( (mg = mg_find(SvRV(sth),'P')) ) |
207
|
4
|
|
|
|
|
|
sth = mg->mg_obj; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
else { |
210
|
|
|
|
|
|
|
/* --- prepare --- */ |
211
|
266
|
|
|
|
|
|
sth = dbixst_bounce_method("prepare", 3); |
212
|
266
|
|
|
|
|
|
SPAGAIN; SP -= items; /* because stack might have been realloc'd */ |
213
|
266
|
100
|
|
|
|
|
if (!SvROK(sth)) { |
214
|
8
|
50
|
|
|
|
|
if (is_selectrow_array) { XSRETURN_EMPTY; } else { XSRETURN_UNDEF; } |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
/* switch to inner handle */ |
217
|
258
|
|
|
|
|
|
sth = mg_find(SvRV(sth),'P')->mg_obj; |
218
|
|
|
|
|
|
|
} |
219
|
262
|
|
|
|
|
|
imp_sth = (imp_sth_t*)(DBIh_COM(sth)); |
220
|
|
|
|
|
|
|
/* --- bind_param --- */ |
221
|
262
|
100
|
|
|
|
|
if (items > 3) { /* need to bind params before execute */ |
222
|
35
|
50
|
|
|
|
|
if (!dbdxst_bind_params(sth, imp_sth, items-2, ax+2) ) { |
223
|
0
|
0
|
|
|
|
|
if (is_selectrow_array) { XSRETURN_EMPTY; } else { XSRETURN_UNDEF; } |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
/* --- execute --- */ |
227
|
262
|
|
|
|
|
|
DBIc_ROW_COUNT(imp_sth) = 0; |
228
|
262
|
100
|
|
|
|
|
if ( dbd_st_execute(sth, imp_sth) <= -2 ) { /* -2 == error */ |
229
|
6
|
50
|
|
|
|
|
if (is_selectrow_array) { XSRETURN_EMPTY; } else { XSRETURN_UNDEF; } |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
/* --- fetchrow_arrayref --- */ |
232
|
256
|
|
|
|
|
|
row_av = dbd_st_fetch(sth, imp_sth); |
233
|
256
|
100
|
|
|
|
|
if (!row_av) { |
234
|
4
|
50
|
|
|
|
|
if (GIMME == G_SCALAR) |
|
|
50
|
|
|
|
|
|
235
|
4
|
|
|
|
|
|
PUSHs(&PL_sv_undef); |
236
|
|
|
|
|
|
|
} |
237
|
252
|
100
|
|
|
|
|
else if (is_selectrow_array) { |
238
|
|
|
|
|
|
|
int i; |
239
|
43
|
50
|
|
|
|
|
int num_fields = AvFILL(row_av)+1; |
240
|
43
|
50
|
|
|
|
|
if (GIMME == G_SCALAR) |
|
|
100
|
|
|
|
|
|
241
|
5
|
|
|
|
|
|
num_fields = 1; /* return just first field */ |
242
|
43
|
50
|
|
|
|
|
EXTEND(sp, num_fields); |
|
|
50
|
|
|
|
|
|
243
|
87
|
100
|
|
|
|
|
for(i=0; i < num_fields; ++i) { |
244
|
44
|
|
|
|
|
|
PUSHs(AvARRAY(row_av)[i]); |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
else { |
248
|
209
|
|
|
|
|
|
PUSHs( sv_2mortal(newRV((SV *)row_av)) ); |
249
|
|
|
|
|
|
|
} |
250
|
|
|
|
|
|
|
/* --- finish --- */ |
251
|
|
|
|
|
|
|
#ifdef dbd_st_finish3 |
252
|
256
|
|
|
|
|
|
dbd_st_finish3(sth, imp_sth, 0); |
253
|
|
|
|
|
|
|
#else |
254
|
|
|
|
|
|
|
dbd_st_finish(sth, imp_sth); |
255
|
|
|
|
|
|
|
#endif |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
#if defined(dbd_db_do6) || defined(dbd_db_do4) |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
void |
261
|
|
|
|
|
|
|
do(dbh, statement, params = Nullsv, ...) |
262
|
|
|
|
|
|
|
SV * dbh |
263
|
|
|
|
|
|
|
SV * statement |
264
|
|
|
|
|
|
|
SV * params |
265
|
|
|
|
|
|
|
CODE: |
266
|
|
|
|
|
|
|
{ |
267
|
|
|
|
|
|
|
D_imp_dbh(dbh); |
268
|
|
|
|
|
|
|
IV retval; |
269
|
|
|
|
|
|
|
#ifdef dbd_db_do6 |
270
|
|
|
|
|
|
|
/* items is a number of arguments passed to XSUB, supplied by xsubpp compiler */ |
271
|
|
|
|
|
|
|
/* ax contains stack base offset used by ST() macro, supplied by xsubpp compiler */ |
272
|
|
|
|
|
|
|
I32 offset = (items >= 3) ? 3 : items; |
273
|
|
|
|
|
|
|
retval = dbd_db_do6(dbh, imp_dbh, statement, params, items-offset, ax+offset); |
274
|
|
|
|
|
|
|
#else |
275
|
|
|
|
|
|
|
if (items > 3) |
276
|
|
|
|
|
|
|
croak_xs_usage(cv, "dbh, statement, params = Nullsv"); |
277
|
|
|
|
|
|
|
retval = dbd_db_do4(dbh, imp_dbh, SvPV_nolen(statement), params); /* might be dbd_db_do4_iv via macro */ |
278
|
|
|
|
|
|
|
#endif |
279
|
|
|
|
|
|
|
/* remember that dbd_db_do* must return <= -2 for error */ |
280
|
|
|
|
|
|
|
if (retval == 0) /* ok with no rows affected */ |
281
|
|
|
|
|
|
|
XST_mPV(0, "0E0"); /* (true but zero) */ |
282
|
|
|
|
|
|
|
else if (retval < -1) /* -1 == unknown number of rows */ |
283
|
|
|
|
|
|
|
XST_mUNDEF(0); /* <= -2 means error */ |
284
|
|
|
|
|
|
|
else |
285
|
|
|
|
|
|
|
XST_mIV(0, retval); /* typically 1, rowcount or -1 */ |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
#endif |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
#ifdef dbd_db_last_insert_id |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
void |
294
|
|
|
|
|
|
|
last_insert_id(dbh, catalog=&PL_sv_undef, schema=&PL_sv_undef, table=&PL_sv_undef, field=&PL_sv_undef, attr=Nullsv) |
295
|
|
|
|
|
|
|
SV * dbh |
296
|
|
|
|
|
|
|
SV * catalog |
297
|
|
|
|
|
|
|
SV * schema |
298
|
|
|
|
|
|
|
SV * table |
299
|
|
|
|
|
|
|
SV * field |
300
|
|
|
|
|
|
|
SV * attr |
301
|
|
|
|
|
|
|
CODE: |
302
|
|
|
|
|
|
|
{ |
303
|
212
|
|
|
|
|
|
D_imp_dbh(dbh); |
304
|
212
|
|
|
|
|
|
SV *ret = dbd_db_last_insert_id(dbh, imp_dbh, catalog, schema, table, field, attr); |
305
|
212
|
|
|
|
|
|
ST(0) = ret; |
306
|
|
|
|
|
|
|
} |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
#endif |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
bool |
312
|
|
|
|
|
|
|
commit(dbh) |
313
|
|
|
|
|
|
|
SV * dbh |
314
|
|
|
|
|
|
|
CODE: |
315
|
82
|
|
|
|
|
|
D_imp_dbh(dbh); |
316
|
82
|
100
|
|
|
|
|
if (DBIc_has(imp_dbh,DBIcf_AutoCommit) && DBIc_WARN(imp_dbh)) |
|
|
50
|
|
|
|
|
|
317
|
2
|
|
|
|
|
|
warn("commit ineffective with AutoCommit enabled"); |
318
|
82
|
|
|
|
|
|
RETVAL = dbd_db_commit(dbh, imp_dbh); |
319
|
|
|
|
|
|
|
OUTPUT: |
320
|
|
|
|
|
|
|
RETVAL |
321
|
|
|
|
|
|
|
|
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
bool |
324
|
|
|
|
|
|
|
rollback(dbh) |
325
|
|
|
|
|
|
|
SV * dbh |
326
|
|
|
|
|
|
|
CODE: |
327
|
23
|
|
|
|
|
|
D_imp_dbh(dbh); |
328
|
23
|
100
|
|
|
|
|
if (DBIc_has(imp_dbh,DBIcf_AutoCommit) && DBIc_WARN(imp_dbh)) |
|
|
50
|
|
|
|
|
|
329
|
2
|
|
|
|
|
|
warn("rollback ineffective with AutoCommit enabled"); |
330
|
23
|
|
|
|
|
|
RETVAL = dbd_db_rollback(dbh, imp_dbh); |
331
|
|
|
|
|
|
|
OUTPUT: |
332
|
|
|
|
|
|
|
RETVAL |
333
|
|
|
|
|
|
|
|
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
bool |
336
|
|
|
|
|
|
|
disconnect(dbh) |
337
|
|
|
|
|
|
|
SV * dbh |
338
|
|
|
|
|
|
|
CODE: |
339
|
99
|
|
|
|
|
|
D_imp_dbh(dbh); |
340
|
99
|
100
|
|
|
|
|
if ( !DBIc_ACTIVE(imp_dbh) ) { |
341
|
2
|
|
|
|
|
|
XSRETURN_YES; |
342
|
|
|
|
|
|
|
} |
343
|
|
|
|
|
|
|
/* Check for disconnect() being called whilst refs to cursors */ |
344
|
|
|
|
|
|
|
/* still exists. This possibly needs some more thought. */ |
345
|
97
|
100
|
|
|
|
|
if (DBIc_ACTIVE_KIDS(imp_dbh) && DBIc_WARN(imp_dbh) && !PL_dirty) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
346
|
|
|
|
|
|
|
STRLEN lna; |
347
|
1
|
50
|
|
|
|
|
char *plural = (DBIc_ACTIVE_KIDS(imp_dbh)==1) ? (char*)"" : (char*)"s"; |
348
|
1
|
50
|
|
|
|
|
warn("%s->disconnect invalidates %d active statement handle%s %s", |
349
|
1
|
|
|
|
|
|
SvPV(dbh,lna), (int)DBIc_ACTIVE_KIDS(imp_dbh), plural, |
350
|
|
|
|
|
|
|
"(either destroy statement handles or call finish on them before disconnecting)"); |
351
|
|
|
|
|
|
|
} |
352
|
97
|
|
|
|
|
|
RETVAL = dbd_db_disconnect(dbh, imp_dbh); |
353
|
97
|
50
|
|
|
|
|
DBIc_ACTIVE_off(imp_dbh); /* ensure it's off, regardless */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
354
|
|
|
|
|
|
|
OUTPUT: |
355
|
|
|
|
|
|
|
RETVAL |
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
void |
359
|
|
|
|
|
|
|
STORE(dbh, keysv, valuesv) |
360
|
|
|
|
|
|
|
SV * dbh |
361
|
|
|
|
|
|
|
SV * keysv |
362
|
|
|
|
|
|
|
SV * valuesv |
363
|
|
|
|
|
|
|
CODE: |
364
|
1633
|
|
|
|
|
|
D_imp_dbh(dbh); |
365
|
1633
|
50
|
|
|
|
|
if (SvGMAGICAL(valuesv)) |
366
|
0
|
|
|
|
|
|
mg_get(valuesv); |
367
|
1633
|
|
|
|
|
|
ST(0) = &PL_sv_yes; |
368
|
1633
|
100
|
|
|
|
|
if (!dbd_db_STORE_attrib(dbh, imp_dbh, keysv, valuesv)) |
369
|
1198
|
100
|
|
|
|
|
if (!DBIc_DBISTATE(imp_dbh)->set_attr(dbh, keysv, valuesv)) |
370
|
19
|
|
|
|
|
|
ST(0) = &PL_sv_no; |
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
void |
374
|
|
|
|
|
|
|
FETCH(dbh, keysv) |
375
|
|
|
|
|
|
|
SV * dbh |
376
|
|
|
|
|
|
|
SV * keysv |
377
|
|
|
|
|
|
|
CODE: |
378
|
3302
|
|
|
|
|
|
D_imp_dbh(dbh); |
379
|
3302
|
|
|
|
|
|
SV *valuesv = dbd_db_FETCH_attrib(dbh, imp_dbh, keysv); |
380
|
3302
|
100
|
|
|
|
|
if (!valuesv) |
381
|
304
|
|
|
|
|
|
valuesv = DBIc_DBISTATE(imp_dbh)->get_attr(dbh, keysv); |
382
|
3302
|
|
|
|
|
|
ST(0) = valuesv; /* dbd_db_FETCH_attrib did sv_2mortal */ |
383
|
|
|
|
|
|
|
|
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
void |
386
|
|
|
|
|
|
|
DESTROY(dbh) |
387
|
|
|
|
|
|
|
SV * dbh |
388
|
|
|
|
|
|
|
PPCODE: |
389
|
|
|
|
|
|
|
/* keep in sync with default DESTROY in DBI.xs */ |
390
|
313
|
|
|
|
|
|
D_imp_dbh(dbh); |
391
|
313
|
|
|
|
|
|
ST(0) = &PL_sv_yes; |
392
|
313
|
100
|
|
|
|
|
if (!DBIc_IMPSET(imp_dbh)) { /* was never fully set up */ |
393
|
|
|
|
|
|
|
STRLEN lna; |
394
|
6
|
50
|
|
|
|
|
if (DBIc_WARN(imp_dbh) && !PL_dirty && DBIc_DBISTATE(imp_dbh)->debug >= 2) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
395
|
6
|
0
|
|
|
|
|
PerlIO_printf(DBIc_LOGPIO(imp_dbh), |
396
|
|
|
|
|
|
|
" DESTROY for %s ignored - handle not initialised\n", |
397
|
0
|
|
|
|
|
|
SvPV(dbh,lna)); |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
else { |
400
|
307
|
100
|
|
|
|
|
if (DBIc_IADESTROY(imp_dbh)) { /* wants ineffective destroy */ |
401
|
2
|
50
|
|
|
|
|
DBIc_ACTIVE_off(imp_dbh); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
402
|
2
|
50
|
|
|
|
|
if (DBIc_DBISTATE(imp_dbh)->debug) |
403
|
0
|
0
|
|
|
|
|
PerlIO_printf(DBIc_LOGPIO(imp_dbh), " DESTROY %s skipped due to InactiveDestroy\n", SvPV_nolen(dbh)); |
404
|
|
|
|
|
|
|
} |
405
|
307
|
100
|
|
|
|
|
if (DBIc_ACTIVE(imp_dbh)) { |
406
|
208
|
100
|
|
|
|
|
if (!DBIc_has(imp_dbh,DBIcf_AutoCommit)) { |
407
|
|
|
|
|
|
|
/* Application is using transactions and hasn't explicitly disconnected. |
408
|
|
|
|
|
|
|
Some databases will automatically commit on graceful disconnect. |
409
|
|
|
|
|
|
|
Since we're about to gracefully disconnect as part of the DESTROY |
410
|
|
|
|
|
|
|
we want to be sure we're not about to implicitly commit changes |
411
|
|
|
|
|
|
|
that are incomplete and should be rolled back. (The DESTROY may |
412
|
|
|
|
|
|
|
be due to a RaiseError, for example.) So we rollback here. |
413
|
|
|
|
|
|
|
This will be harmless if the application has issued a commit, |
414
|
|
|
|
|
|
|
XXX Could add an attribute flag to indicate that the driver |
415
|
|
|
|
|
|
|
doesn't have this problem. Patches welcome. |
416
|
|
|
|
|
|
|
*/ |
417
|
5
|
100
|
|
|
|
|
if (DBIc_WARN(imp_dbh) /* only warn if likely to be useful... */ |
418
|
4
|
50
|
|
|
|
|
&& DBIc_is(imp_dbh, DBIcf_Executed) /* has not just called commit/rollback */ |
419
|
|
|
|
|
|
|
/* && !DBIc_is(imp_dbh, DBIcf_ReadOnly) -- is not read only */ |
420
|
0
|
0
|
|
|
|
|
&& (!PL_dirty || DBIc_DBISTATE(imp_dbh)->debug >= 3) |
|
|
0
|
|
|
|
|
|
421
|
|
|
|
|
|
|
) { |
422
|
0
|
0
|
|
|
|
|
warn("Issuing rollback() due to DESTROY without explicit disconnect() of %s handle %s", |
|
|
0
|
|
|
|
|
|
423
|
0
|
|
|
|
|
|
SvPV_nolen(*hv_fetch((HV*)SvRV(dbh), "ImplementorClass", 16, 1)), |
424
|
0
|
|
|
|
|
|
SvPV_nolen(*hv_fetch((HV*)SvRV(dbh), "Name", 4, 1)) |
425
|
|
|
|
|
|
|
); |
426
|
|
|
|
|
|
|
} |
427
|
5
|
|
|
|
|
|
dbd_db_rollback(dbh, imp_dbh); /* ROLLBACK! */ |
428
|
|
|
|
|
|
|
} |
429
|
208
|
|
|
|
|
|
dbd_db_disconnect(dbh, imp_dbh); |
430
|
208
|
50
|
|
|
|
|
DBIc_ACTIVE_off(imp_dbh); /* ensure it's off, regardless */ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
431
|
|
|
|
|
|
|
} |
432
|
307
|
|
|
|
|
|
dbd_db_destroy(dbh, imp_dbh); |
433
|
|
|
|
|
|
|
} |
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
|
436
|
|
|
|
|
|
|
#ifdef dbd_take_imp_data |
437
|
|
|
|
|
|
|
|
438
|
|
|
|
|
|
|
void |
439
|
|
|
|
|
|
|
take_imp_data(h) |
440
|
|
|
|
|
|
|
SV * h |
441
|
|
|
|
|
|
|
CODE: |
442
|
|
|
|
|
|
|
D_imp_xxh(h); |
443
|
|
|
|
|
|
|
/* dbd_take_imp_data() returns &sv_no (or other defined but false value) |
444
|
|
|
|
|
|
|
* to indicate "preparations complete, now call SUPER::take_imp_data" for me. |
445
|
|
|
|
|
|
|
* Anything else is returned to the caller via sv_2mortal(sv), typically that |
446
|
|
|
|
|
|
|
* would be &sv_undef for error or an SV holding the imp_data. |
447
|
|
|
|
|
|
|
*/ |
448
|
|
|
|
|
|
|
SV *sv = dbd_take_imp_data(h, imp_xxh, NULL); |
449
|
|
|
|
|
|
|
if (SvOK(sv) && !SvTRUE(sv)) { |
450
|
|
|
|
|
|
|
SV *tmp = dbixst_bounce_method("DBD::SQLite::db::SUPER::take_imp_data", items); |
451
|
|
|
|
|
|
|
SPAGAIN; |
452
|
|
|
|
|
|
|
ST(0) = tmp; |
453
|
|
|
|
|
|
|
} else { |
454
|
|
|
|
|
|
|
ST(0) = sv_2mortal(sv); |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
#endif |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
#ifdef dbd_db_data_sources |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
void |
462
|
|
|
|
|
|
|
data_sources(dbh, attr = Nullsv) |
463
|
|
|
|
|
|
|
SV *dbh |
464
|
|
|
|
|
|
|
SV *attr |
465
|
|
|
|
|
|
|
PPCODE: |
466
|
|
|
|
|
|
|
{ |
467
|
|
|
|
|
|
|
D_imp_dbh(dbh); |
468
|
|
|
|
|
|
|
AV *av = dbd_db_data_sources(dbh, imp_dbh, attr); |
469
|
|
|
|
|
|
|
if (av) { |
470
|
|
|
|
|
|
|
int i; |
471
|
|
|
|
|
|
|
int n = AvFILL(av)+1; |
472
|
|
|
|
|
|
|
EXTEND(sp, n); |
473
|
|
|
|
|
|
|
for (i = 0; i < n; ++i) { |
474
|
|
|
|
|
|
|
PUSHs(AvARRAY(av)[i]); |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
} |
477
|
|
|
|
|
|
|
} |
478
|
|
|
|
|
|
|
|
479
|
|
|
|
|
|
|
#endif |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
# -- end of DBD::SQLite::db |
482
|
|
|
|
|
|
|
|
483
|
|
|
|
|
|
|
# ------------------------------------------------------------ |
484
|
|
|
|
|
|
|
# statement interface |
485
|
|
|
|
|
|
|
# ------------------------------------------------------------ |
486
|
|
|
|
|
|
|
MODULE = DBD::SQLite PACKAGE = DBD::SQLite::st |
487
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
bool |
490
|
|
|
|
|
|
|
_prepare(sth, statement, attribs=Nullsv) |
491
|
|
|
|
|
|
|
SV * sth |
492
|
|
|
|
|
|
|
SV * statement |
493
|
|
|
|
|
|
|
SV * attribs |
494
|
|
|
|
|
|
|
CODE: |
495
|
|
|
|
|
|
|
{ |
496
|
1380
|
|
|
|
|
|
D_imp_sth(sth); |
497
|
1380
|
100
|
|
|
|
|
DBD_ATTRIBS_CHECK("_prepare", sth, attribs); |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
498
|
|
|
|
|
|
|
#ifdef dbd_st_prepare_sv |
499
|
1380
|
|
|
|
|
|
RETVAL = dbd_st_prepare_sv(sth, imp_sth, statement, attribs); |
500
|
|
|
|
|
|
|
#else |
501
|
|
|
|
|
|
|
RETVAL = dbd_st_prepare(sth, imp_sth, SvPV_nolen(statement), attribs); |
502
|
|
|
|
|
|
|
#endif |
503
|
|
|
|
|
|
|
} |
504
|
|
|
|
|
|
|
OUTPUT: |
505
|
|
|
|
|
|
|
RETVAL |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
#ifdef dbd_st_rows |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
void |
511
|
|
|
|
|
|
|
rows(sth) |
512
|
|
|
|
|
|
|
SV * sth |
513
|
|
|
|
|
|
|
CODE: |
514
|
121
|
|
|
|
|
|
D_imp_sth(sth); |
515
|
121
|
|
|
|
|
|
XST_mIV(0, dbd_st_rows(sth, imp_sth)); |
516
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
#endif /* dbd_st_rows */ |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
|
520
|
|
|
|
|
|
|
#ifdef dbd_st_bind_col |
521
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
bool |
523
|
|
|
|
|
|
|
bind_col(sth, col, ref, attribs=Nullsv) |
524
|
|
|
|
|
|
|
SV * sth |
525
|
|
|
|
|
|
|
SV * col |
526
|
|
|
|
|
|
|
SV * ref |
527
|
|
|
|
|
|
|
SV * attribs |
528
|
|
|
|
|
|
|
CODE: |
529
|
|
|
|
|
|
|
{ |
530
|
450
|
|
|
|
|
|
IV sql_type = 0; |
531
|
450
|
|
|
|
|
|
D_imp_sth(sth); |
532
|
450
|
50
|
|
|
|
|
if (SvGMAGICAL(ref)) |
533
|
0
|
|
|
|
|
|
mg_get(ref); |
534
|
450
|
100
|
|
|
|
|
if (attribs) { |
535
|
285
|
100
|
|
|
|
|
if (SvNIOK(attribs)) { |
536
|
1
|
50
|
|
|
|
|
sql_type = SvIV(attribs); |
537
|
1
|
|
|
|
|
|
attribs = Nullsv; |
538
|
|
|
|
|
|
|
} |
539
|
|
|
|
|
|
|
else { |
540
|
|
|
|
|
|
|
SV **svp; |
541
|
284
|
50
|
|
|
|
|
DBD_ATTRIBS_CHECK("bind_col", sth, attribs); |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
542
|
|
|
|
|
|
|
/* XXX we should perhaps complain if TYPE is not SvNIOK */ |
543
|
284
|
100
|
|
|
|
|
DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
} |
546
|
450
|
|
|
|
|
|
switch(dbd_st_bind_col(sth, imp_sth, col, ref, sql_type, attribs)) { |
547
|
0
|
|
|
|
|
|
case 2: RETVAL = TRUE; /* job done completely */ |
548
|
0
|
|
|
|
|
|
break; |
549
|
|
|
|
|
|
|
case 1: /* fallback to DBI default */ |
550
|
450
|
|
|
|
|
|
RETVAL = DBIc_DBISTATE(imp_sth)->bind_col(sth, col, ref, attribs); |
551
|
450
|
|
|
|
|
|
break; |
552
|
0
|
|
|
|
|
|
default: RETVAL = FALSE; /* dbd_st_bind_col has called set_err */ |
553
|
0
|
|
|
|
|
|
break; |
554
|
|
|
|
|
|
|
} |
555
|
|
|
|
|
|
|
} |
556
|
|
|
|
|
|
|
OUTPUT: |
557
|
|
|
|
|
|
|
RETVAL |
558
|
|
|
|
|
|
|
|
559
|
|
|
|
|
|
|
#endif /* dbd_st_bind_col */ |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
bool |
562
|
|
|
|
|
|
|
bind_param(sth, param, value, attribs=Nullsv) |
563
|
|
|
|
|
|
|
SV * sth |
564
|
|
|
|
|
|
|
SV * param |
565
|
|
|
|
|
|
|
SV * value |
566
|
|
|
|
|
|
|
SV * attribs |
567
|
|
|
|
|
|
|
CODE: |
568
|
|
|
|
|
|
|
{ |
569
|
271
|
|
|
|
|
|
IV sql_type = 0; |
570
|
271
|
|
|
|
|
|
D_imp_sth(sth); |
571
|
271
|
50
|
|
|
|
|
if (SvGMAGICAL(value)) |
572
|
0
|
|
|
|
|
|
mg_get(value); |
573
|
271
|
100
|
|
|
|
|
if (attribs) { |
574
|
229
|
100
|
|
|
|
|
if (SvNIOK(attribs)) { |
575
|
162
|
50
|
|
|
|
|
sql_type = SvIV(attribs); |
576
|
162
|
|
|
|
|
|
attribs = Nullsv; |
577
|
|
|
|
|
|
|
} |
578
|
|
|
|
|
|
|
else { |
579
|
|
|
|
|
|
|
SV **svp; |
580
|
67
|
50
|
|
|
|
|
DBD_ATTRIBS_CHECK("bind_param", sth, attribs); |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
581
|
|
|
|
|
|
|
/* XXX we should perhaps complain if TYPE is not SvNIOK */ |
582
|
67
|
100
|
|
|
|
|
DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
583
|
|
|
|
|
|
|
} |
584
|
|
|
|
|
|
|
} |
585
|
271
|
|
|
|
|
|
RETVAL = dbd_bind_ph(sth, imp_sth, param, value, sql_type, attribs, FALSE, 0); |
586
|
|
|
|
|
|
|
} |
587
|
|
|
|
|
|
|
OUTPUT: |
588
|
|
|
|
|
|
|
RETVAL |
589
|
|
|
|
|
|
|
|
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
bool |
592
|
|
|
|
|
|
|
bind_param_inout(sth, param, value_ref, maxlen, attribs=Nullsv) |
593
|
|
|
|
|
|
|
SV * sth |
594
|
|
|
|
|
|
|
SV * param |
595
|
|
|
|
|
|
|
SV * value_ref |
596
|
|
|
|
|
|
|
IV maxlen |
597
|
|
|
|
|
|
|
SV * attribs |
598
|
|
|
|
|
|
|
CODE: |
599
|
|
|
|
|
|
|
{ |
600
|
0
|
|
|
|
|
|
IV sql_type = 0; |
601
|
0
|
|
|
|
|
|
D_imp_sth(sth); |
602
|
|
|
|
|
|
|
SV *value; |
603
|
0
|
0
|
|
|
|
|
if (!SvROK(value_ref) || SvTYPE(SvRV(value_ref)) > SVt_PVMG) |
|
|
0
|
|
|
|
|
|
604
|
0
|
|
|
|
|
|
croak("bind_param_inout needs a reference to a scalar value"); |
605
|
0
|
|
|
|
|
|
value = SvRV(value_ref); |
606
|
0
|
0
|
|
|
|
|
if (SvREADONLY(value)) |
607
|
0
|
|
|
|
|
|
croak("Modification of a read-only value attempted"); |
608
|
0
|
0
|
|
|
|
|
if (SvGMAGICAL(value)) |
609
|
0
|
|
|
|
|
|
mg_get(value); |
610
|
0
|
0
|
|
|
|
|
if (attribs) { |
611
|
0
|
0
|
|
|
|
|
if (SvNIOK(attribs)) { |
612
|
0
|
0
|
|
|
|
|
sql_type = SvIV(attribs); |
613
|
0
|
|
|
|
|
|
attribs = Nullsv; |
614
|
|
|
|
|
|
|
} |
615
|
|
|
|
|
|
|
else { |
616
|
|
|
|
|
|
|
SV **svp; |
617
|
0
|
0
|
|
|
|
|
DBD_ATTRIBS_CHECK("bind_param", sth, attribs); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
618
|
0
|
0
|
|
|
|
|
DBD_ATTRIB_GET_IV(attribs, "TYPE",4, svp, sql_type); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
619
|
|
|
|
|
|
|
} |
620
|
|
|
|
|
|
|
} |
621
|
0
|
|
|
|
|
|
RETVAL = dbd_bind_ph(sth, imp_sth, param, value, sql_type, attribs, TRUE, maxlen); |
622
|
|
|
|
|
|
|
} |
623
|
|
|
|
|
|
|
OUTPUT: |
624
|
|
|
|
|
|
|
RETVAL |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
void |
628
|
|
|
|
|
|
|
execute(sth, ...) |
629
|
|
|
|
|
|
|
SV * sth |
630
|
|
|
|
|
|
|
CODE: |
631
|
1186
|
|
|
|
|
|
D_imp_sth(sth); |
632
|
|
|
|
|
|
|
IV retval; |
633
|
1186
|
100
|
|
|
|
|
if (items > 1) { /* need to bind params */ |
634
|
529
|
50
|
|
|
|
|
if (!dbdxst_bind_params(sth, imp_sth, items, ax) ) { |
635
|
0
|
|
|
|
|
|
XSRETURN_UNDEF; |
636
|
|
|
|
|
|
|
} |
637
|
|
|
|
|
|
|
} |
638
|
|
|
|
|
|
|
/* XXX this code is duplicated in selectrow_arrayref above */ |
639
|
1186
|
|
|
|
|
|
DBIc_ROW_COUNT(imp_sth) = 0; |
640
|
1186
|
|
|
|
|
|
retval = dbd_st_execute(sth, imp_sth); /* might be dbd_st_execute_iv via macro */ |
641
|
|
|
|
|
|
|
/* remember that dbd_st_execute must return <= -2 for error */ |
642
|
1186
|
100
|
|
|
|
|
if (retval == 0) /* ok with no rows affected */ |
643
|
641
|
|
|
|
|
|
XST_mPV(0, "0E0"); /* (true but zero) */ |
644
|
545
|
100
|
|
|
|
|
else if (retval < -1) /* -1 == unknown number of rows */ |
645
|
11
|
|
|
|
|
|
XST_mUNDEF(0); /* <= -2 means error */ |
646
|
|
|
|
|
|
|
else |
647
|
534
|
|
|
|
|
|
XST_mIV(0, retval); /* typically 1, rowcount or -1 */ |
648
|
|
|
|
|
|
|
|
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
#ifdef dbd_st_execute_for_fetch |
651
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
void |
653
|
|
|
|
|
|
|
execute_for_fetch(sth, fetch_tuple_sub, tuple_status = Nullsv) |
654
|
|
|
|
|
|
|
SV * sth |
655
|
|
|
|
|
|
|
SV * fetch_tuple_sub |
656
|
|
|
|
|
|
|
SV * tuple_status |
657
|
|
|
|
|
|
|
CODE: |
658
|
|
|
|
|
|
|
{ |
659
|
|
|
|
|
|
|
D_imp_sth(sth); |
660
|
|
|
|
|
|
|
SV *ret = dbd_st_execute_for_fetch(sth, imp_sth, fetch_tuple_sub, tuple_status); |
661
|
|
|
|
|
|
|
ST(0) = ret; |
662
|
|
|
|
|
|
|
} |
663
|
|
|
|
|
|
|
|
664
|
|
|
|
|
|
|
#endif |
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
#ifdef dbd_st_last_insert_id |
668
|
|
|
|
|
|
|
|
669
|
|
|
|
|
|
|
void |
670
|
|
|
|
|
|
|
last_insert_id(sth, catalog=&PL_sv_undef, schema=&PL_sv_undef, table=&PL_sv_undef, field=&PL_sv_undef, attr=Nullsv) |
671
|
|
|
|
|
|
|
SV * sth |
672
|
|
|
|
|
|
|
SV * catalog |
673
|
|
|
|
|
|
|
SV * schema |
674
|
|
|
|
|
|
|
SV * table |
675
|
|
|
|
|
|
|
SV * field |
676
|
|
|
|
|
|
|
SV * attr |
677
|
|
|
|
|
|
|
CODE: |
678
|
|
|
|
|
|
|
{ |
679
|
|
|
|
|
|
|
D_imp_sth(sth); |
680
|
|
|
|
|
|
|
SV *ret = dbd_st_last_insert_id(sth, imp_sth, catalog, schema, table, field, attr); |
681
|
|
|
|
|
|
|
ST(0) = ret; |
682
|
|
|
|
|
|
|
} |
683
|
|
|
|
|
|
|
|
684
|
|
|
|
|
|
|
#endif |
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
void |
688
|
|
|
|
|
|
|
fetchrow_arrayref(sth) |
689
|
|
|
|
|
|
|
SV * sth |
690
|
|
|
|
|
|
|
ALIAS: |
691
|
|
|
|
|
|
|
fetch = 1 |
692
|
|
|
|
|
|
|
CODE: |
693
|
1638
|
|
|
|
|
|
D_imp_sth(sth); |
694
|
|
|
|
|
|
|
AV *av; |
695
|
|
|
|
|
|
|
PERL_UNUSED_VAR(ix); |
696
|
1638
|
|
|
|
|
|
av = dbd_st_fetch(sth, imp_sth); |
697
|
1638
|
100
|
|
|
|
|
ST(0) = (av) ? sv_2mortal(newRV((SV *)av)) : &PL_sv_undef; |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
void |
701
|
|
|
|
|
|
|
fetchrow_array(sth) |
702
|
|
|
|
|
|
|
SV * sth |
703
|
|
|
|
|
|
|
ALIAS: |
704
|
|
|
|
|
|
|
fetchrow = 1 |
705
|
|
|
|
|
|
|
PPCODE: |
706
|
44
|
|
|
|
|
|
D_imp_sth(sth); |
707
|
|
|
|
|
|
|
AV *av; |
708
|
44
|
|
|
|
|
|
av = dbd_st_fetch(sth, imp_sth); |
709
|
44
|
100
|
|
|
|
|
if (av) { |
710
|
|
|
|
|
|
|
int i; |
711
|
34
|
50
|
|
|
|
|
int num_fields = AvFILL(av)+1; |
712
|
34
|
50
|
|
|
|
|
EXTEND(sp, num_fields); |
|
|
50
|
|
|
|
|
|
713
|
84
|
100
|
|
|
|
|
for(i=0; i < num_fields; ++i) { |
714
|
50
|
|
|
|
|
|
PUSHs(AvARRAY(av)[i]); |
715
|
|
|
|
|
|
|
} |
716
|
|
|
|
|
|
|
PERL_UNUSED_VAR(ix); |
717
|
|
|
|
|
|
|
} |
718
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
void |
721
|
|
|
|
|
|
|
fetchall_arrayref(sth, slice=&PL_sv_undef, batch_row_count=&PL_sv_undef) |
722
|
|
|
|
|
|
|
SV * sth |
723
|
|
|
|
|
|
|
SV * slice |
724
|
|
|
|
|
|
|
SV * batch_row_count |
725
|
|
|
|
|
|
|
CODE: |
726
|
180
|
100
|
|
|
|
|
if (SvOK(slice)) { /* fallback to perl implementation */ |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
727
|
81
|
|
|
|
|
|
SV *tmp = dbixst_bounce_method("DBD::SQLite::st::SUPER::fetchall_arrayref", 3); |
728
|
81
|
|
|
|
|
|
SPAGAIN; |
729
|
81
|
|
|
|
|
|
ST(0) = tmp; |
730
|
|
|
|
|
|
|
} |
731
|
|
|
|
|
|
|
else { |
732
|
18
|
|
|
|
|
|
SV *tmp = dbdxst_fetchall_arrayref(sth, slice, batch_row_count); |
733
|
18
|
|
|
|
|
|
SPAGAIN; |
734
|
18
|
|
|
|
|
|
ST(0) = tmp; |
735
|
|
|
|
|
|
|
} |
736
|
|
|
|
|
|
|
|
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
bool |
739
|
|
|
|
|
|
|
finish(sth) |
740
|
|
|
|
|
|
|
SV * sth |
741
|
|
|
|
|
|
|
CODE: |
742
|
72
|
|
|
|
|
|
D_imp_sth(sth); |
743
|
72
|
|
|
|
|
|
D_imp_dbh_from_sth; |
744
|
72
|
100
|
|
|
|
|
if (!DBIc_ACTIVE(imp_sth)) { |
745
|
|
|
|
|
|
|
/* No active statement to finish */ |
746
|
50
|
|
|
|
|
|
XSRETURN_YES; |
747
|
|
|
|
|
|
|
} |
748
|
22
|
50
|
|
|
|
|
if (!DBIc_ACTIVE(imp_dbh)) { |
749
|
|
|
|
|
|
|
/* Either an explicit disconnect() or global destruction */ |
750
|
|
|
|
|
|
|
/* has disconnected us from the database. Finish is meaningless */ |
751
|
0
|
0
|
|
|
|
|
DBIc_ACTIVE_off(imp_sth); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
752
|
0
|
|
|
|
|
|
XSRETURN_YES; |
753
|
|
|
|
|
|
|
} |
754
|
|
|
|
|
|
|
#ifdef dbd_st_finish3 |
755
|
22
|
|
|
|
|
|
RETVAL = dbd_st_finish3(sth, imp_sth, 0); |
756
|
|
|
|
|
|
|
#else |
757
|
|
|
|
|
|
|
RETVAL = dbd_st_finish(sth, imp_sth); |
758
|
|
|
|
|
|
|
#endif |
759
|
|
|
|
|
|
|
OUTPUT: |
760
|
|
|
|
|
|
|
RETVAL |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
|
763
|
|
|
|
|
|
|
void |
764
|
|
|
|
|
|
|
blob_read(sth, field, offset, len, destrv=Nullsv, destoffset=0) |
765
|
|
|
|
|
|
|
SV * sth |
766
|
|
|
|
|
|
|
int field |
767
|
|
|
|
|
|
|
long offset |
768
|
|
|
|
|
|
|
long len |
769
|
|
|
|
|
|
|
SV * destrv |
770
|
|
|
|
|
|
|
long destoffset |
771
|
|
|
|
|
|
|
CODE: |
772
|
|
|
|
|
|
|
{ |
773
|
0
|
|
|
|
|
|
D_imp_sth(sth); |
774
|
0
|
0
|
|
|
|
|
if (!destrv) |
775
|
0
|
|
|
|
|
|
destrv = sv_2mortal(newRV(sv_2mortal(newSV(0)))); |
776
|
0
|
0
|
|
|
|
|
if (dbd_st_blob_read(sth, imp_sth, field, offset, len, destrv, destoffset)) |
777
|
0
|
|
|
|
|
|
ST(0) = SvRV(destrv); |
778
|
0
|
|
|
|
|
|
else ST(0) = &PL_sv_undef; |
779
|
|
|
|
|
|
|
} |
780
|
|
|
|
|
|
|
|
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
void |
783
|
|
|
|
|
|
|
STORE(sth, keysv, valuesv) |
784
|
|
|
|
|
|
|
SV * sth |
785
|
|
|
|
|
|
|
SV * keysv |
786
|
|
|
|
|
|
|
SV * valuesv |
787
|
|
|
|
|
|
|
CODE: |
788
|
5
|
|
|
|
|
|
D_imp_sth(sth); |
789
|
5
|
50
|
|
|
|
|
if (SvGMAGICAL(valuesv)) |
790
|
0
|
|
|
|
|
|
mg_get(valuesv); |
791
|
5
|
|
|
|
|
|
ST(0) = &PL_sv_yes; |
792
|
5
|
50
|
|
|
|
|
if (!dbd_st_STORE_attrib(sth, imp_sth, keysv, valuesv)) |
793
|
5
|
50
|
|
|
|
|
if (!DBIc_DBISTATE(imp_sth)->set_attr(sth, keysv, valuesv)) |
794
|
0
|
|
|
|
|
|
ST(0) = &PL_sv_no; |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
|
797
|
|
|
|
|
|
|
# FETCH renamed and ALIAS'd to avoid case clash on VMS :-( |
798
|
|
|
|
|
|
|
void |
799
|
|
|
|
|
|
|
FETCH_attrib(sth, keysv) |
800
|
|
|
|
|
|
|
SV * sth |
801
|
|
|
|
|
|
|
SV * keysv |
802
|
|
|
|
|
|
|
ALIAS: |
803
|
|
|
|
|
|
|
FETCH = 1 |
804
|
|
|
|
|
|
|
CODE: |
805
|
962
|
|
|
|
|
|
D_imp_sth(sth); |
806
|
|
|
|
|
|
|
SV *valuesv; |
807
|
|
|
|
|
|
|
PERL_UNUSED_VAR(ix); |
808
|
962
|
|
|
|
|
|
valuesv = dbd_st_FETCH_attrib(sth, imp_sth, keysv); |
809
|
962
|
100
|
|
|
|
|
if (!valuesv) |
810
|
200
|
|
|
|
|
|
valuesv = DBIc_DBISTATE(imp_sth)->get_attr(sth, keysv); |
811
|
962
|
|
|
|
|
|
ST(0) = valuesv; /* dbd_st_FETCH_attrib did sv_2mortal */ |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
void |
815
|
|
|
|
|
|
|
DESTROY(sth) |
816
|
|
|
|
|
|
|
SV * sth |
817
|
|
|
|
|
|
|
PPCODE: |
818
|
|
|
|
|
|
|
/* keep in sync with default DESTROY in DBI.xs */ |
819
|
1380
|
|
|
|
|
|
D_imp_sth(sth); |
820
|
1380
|
|
|
|
|
|
ST(0) = &PL_sv_yes; |
821
|
1380
|
100
|
|
|
|
|
if (!DBIc_IMPSET(imp_sth)) { /* was never fully set up */ |
822
|
|
|
|
|
|
|
STRLEN lna; |
823
|
21
|
50
|
|
|
|
|
if (DBIc_WARN(imp_sth) && !PL_dirty && DBIc_DBISTATE(imp_sth)->debug >= 2) |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
824
|
21
|
0
|
|
|
|
|
PerlIO_printf(DBIc_LOGPIO(imp_sth), |
825
|
|
|
|
|
|
|
" DESTROY for %s ignored - handle not initialised\n", |
826
|
0
|
|
|
|
|
|
SvPV(sth,lna)); |
827
|
|
|
|
|
|
|
} |
828
|
|
|
|
|
|
|
else { |
829
|
1359
|
50
|
|
|
|
|
if (DBIc_IADESTROY(imp_sth)) { /* wants ineffective destroy */ |
830
|
0
|
0
|
|
|
|
|
DBIc_ACTIVE_off(imp_sth); |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
831
|
0
|
0
|
|
|
|
|
if (DBIc_DBISTATE(imp_sth)->debug) |
832
|
0
|
0
|
|
|
|
|
PerlIO_printf(DBIc_LOGPIO(imp_sth), " DESTROY %s skipped due to InactiveDestroy\n", SvPV_nolen(sth)); |
833
|
|
|
|
|
|
|
} |
834
|
1359
|
100
|
|
|
|
|
if (DBIc_ACTIVE(imp_sth)) { |
835
|
115
|
|
|
|
|
|
D_imp_dbh_from_sth; |
836
|
115
|
50
|
|
|
|
|
if (!PL_dirty && DBIc_ACTIVE(imp_dbh)) { |
|
|
100
|
|
|
|
|
|
837
|
|
|
|
|
|
|
#ifdef dbd_st_finish3 |
838
|
114
|
|
|
|
|
|
dbd_st_finish3(sth, imp_sth, 1); |
839
|
|
|
|
|
|
|
#else |
840
|
|
|
|
|
|
|
dbd_st_finish(sth, imp_sth); |
841
|
|
|
|
|
|
|
#endif |
842
|
|
|
|
|
|
|
} |
843
|
|
|
|
|
|
|
else { |
844
|
1
|
50
|
|
|
|
|
DBIc_ACTIVE_off(imp_sth); |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
845
|
|
|
|
|
|
|
} |
846
|
|
|
|
|
|
|
} |
847
|
1359
|
|
|
|
|
|
dbd_st_destroy(sth, imp_sth); |
848
|
|
|
|
|
|
|
} |
849
|
|
|
|
|
|
|
|
850
|
|
|
|
|
|
|
# end of SQLite.xst |
851
|
|
|
|
|
|
|
# vim:ts=8:sw=4:et |