forked from perl5-dbi/DBD-MariaDB
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MariaDB.xs
315 lines (263 loc) · 6.81 KB
/
MariaDB.xs
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
/* Hej, Emacs, this is -*- C -*- mode!
Copyright (c) 2018 GoodData Corporation
Copyright (c) 2015-2022 Pali Rohár
Copyright (c) 2004-2017 Patrick Galbraith
Copyright (c) 2013-2017 Michiel Beijen
Copyright (c) 2004-2007 Alexey Stroganov
Copyright (c) 2003-2005 Rudolf Lippan
Copyright (c) 1997-2003 Jochen Wiedmann
You may distribute under the terms of either the GNU General Public
License or the Artistic License, as specified in the Perl README file.
*/
#include "dbdimp.h"
#define ASYNC_CHECK_XS(h)\
if(imp_dbh->async_query_in_flight) {\
mariadb_dr_do_error(h, CR_UNKNOWN_ERROR, "Calling a synchronous function on an asynchronous handle", "HY000");\
XSRETURN_UNDEF;\
}
DBISTATE_DECLARE;
MODULE = DBD::MariaDB PACKAGE = DBD::MariaDB
INCLUDE: MariaDB.xsi
MODULE = DBD::MariaDB PACKAGE = DBD::MariaDB
BOOT:
{
HV *stash = gv_stashpvs("DBD::MariaDB", GV_ADD);
#define newTypeSub(stash, type) newCONSTSUB((stash), #type + sizeof("MYSQL_")-1, newSViv(type))
newTypeSub(stash, MYSQL_TYPE_DECIMAL);
newTypeSub(stash, MYSQL_TYPE_TINY);
newTypeSub(stash, MYSQL_TYPE_SHORT);
newTypeSub(stash, MYSQL_TYPE_LONG);
newTypeSub(stash, MYSQL_TYPE_FLOAT);
newTypeSub(stash, MYSQL_TYPE_DOUBLE);
newTypeSub(stash, MYSQL_TYPE_NULL);
newTypeSub(stash, MYSQL_TYPE_TIMESTAMP);
newTypeSub(stash, MYSQL_TYPE_LONGLONG);
newTypeSub(stash, MYSQL_TYPE_INT24);
newTypeSub(stash, MYSQL_TYPE_DATE);
newTypeSub(stash, MYSQL_TYPE_TIME);
newTypeSub(stash, MYSQL_TYPE_DATETIME);
newTypeSub(stash, MYSQL_TYPE_YEAR);
newTypeSub(stash, MYSQL_TYPE_NEWDATE);
newTypeSub(stash, MYSQL_TYPE_VARCHAR);
newTypeSub(stash, MYSQL_TYPE_BIT);
newTypeSub(stash, MYSQL_TYPE_NEWDECIMAL);
newTypeSub(stash, MYSQL_TYPE_ENUM);
newTypeSub(stash, MYSQL_TYPE_SET);
newTypeSub(stash, MYSQL_TYPE_TINY_BLOB);
newTypeSub(stash, MYSQL_TYPE_MEDIUM_BLOB);
newTypeSub(stash, MYSQL_TYPE_LONG_BLOB);
newTypeSub(stash, MYSQL_TYPE_BLOB);
newTypeSub(stash, MYSQL_TYPE_VAR_STRING);
newTypeSub(stash, MYSQL_TYPE_STRING);
#undef newTypeSub
#if defined(HAVE_DEINITIALIZE_SSL) && defined(HAVE_PROBLEM_WITH_OPENSSL)
/* Do not deinitialize OpenSSL library after mysql_server_end()
* See: https://github.com/perl5-dbi/DBD-MariaDB/issues/119 */
mariadb_deinitialize_ssl = 0;
#endif
#ifndef _WIN32
/* Calling mysql_thread_init() on WIN32 cause crash */
mysql_thread_init();
#endif
}
MODULE = DBD::MariaDB PACKAGE = DBD::MariaDB::db
void
connected(dbh, ...)
SV* dbh
PPCODE:
/* Called by DBI when connect method finished */
D_imp_dbh(dbh);
imp_dbh->connected = TRUE;
XSRETURN_EMPTY;
void
type_info_all(dbh)
SV* dbh
PPCODE:
{
PERL_UNUSED_VAR(dbh);
ST(0) = sv_2mortal(newRV_noinc((SV*) mariadb_db_type_info_all()));
XSRETURN(1);
}
#ifndef HAVE_DBI_1_642
IV
do(dbh, statement, attr=Nullsv, ...)
SV *dbh
SV *statement
SV *attr
CODE:
{
/* Compatibility for DBI version prior to 1.642 which does not support dbd_db_do6 API */
D_imp_dbh(dbh);
RETVAL = mariadb_db_do6(dbh, imp_dbh, statement, attr, items-3, ax+3);
if (RETVAL == 0) /* ok with no rows affected */
XSRETURN_PV("0E0"); /* (true but zero) */
else if (RETVAL < -1) /* -1 == unknown number of rows */
XSRETURN_UNDEF;
}
OUTPUT:
RETVAL
#endif
bool
ping(dbh)
SV* dbh;
CODE:
{
D_imp_dbh(dbh);
ASYNC_CHECK_XS(dbh);
if (!imp_dbh->pmysql)
XSRETURN_NO;
RETVAL = (mysql_ping(imp_dbh->pmysql) == 0);
if (!RETVAL)
{
if (mariadb_db_reconnect(dbh, NULL))
RETVAL = (mysql_ping(imp_dbh->pmysql) == 0);
}
}
OUTPUT:
RETVAL
void
quote(dbh, str, type=NULL)
SV* dbh
SV* str
SV* type
PPCODE:
{
SV* quoted;
D_imp_dbh(dbh);
ASYNC_CHECK_XS(dbh);
quoted = mariadb_db_quote(dbh, str, type);
ST(0) = quoted ? sv_2mortal(quoted) : str;
XSRETURN(1);
}
SV *
mariadb_sockfd(dbh)
SV* dbh
CODE:
D_imp_dbh(dbh);
RETVAL = (imp_dbh->sock_fd >= 0) ? newSViv(imp_dbh->sock_fd) : &PL_sv_undef;
OUTPUT:
RETVAL
SV *
mariadb_async_result(dbh)
SV* dbh
CODE:
{
my_ulonglong retval;
retval = mariadb_db_async_result(dbh, NULL);
if (retval == 0)
XSRETURN_PV("0E0");
else if (retval == (my_ulonglong)-1)
XSRETURN_UNDEF;
else if (retval == (my_ulonglong)-2)
XSRETURN_IV(-1);
RETVAL = my_ulonglong2sv(retval);
}
OUTPUT:
RETVAL
void mariadb_async_ready(dbh)
SV* dbh
PPCODE:
{
int retval;
retval = mariadb_db_async_ready(dbh);
if(retval > 0) {
XSRETURN_YES;
} else if(retval == 0) {
XSRETURN_NO;
} else {
XSRETURN_UNDEF;
}
}
void _async_check(dbh)
SV* dbh
PPCODE:
{
D_imp_dbh(dbh);
ASYNC_CHECK_XS(dbh);
XSRETURN_YES;
}
MODULE = DBD::MariaDB PACKAGE = DBD::MariaDB::st
bool
more_results(sth)
SV * sth
CODE:
{
D_imp_sth(sth);
RETVAL = mariadb_st_more_results(sth, imp_sth);
}
OUTPUT:
RETVAL
SV *
rows(sth)
SV* sth
CODE:
D_imp_sth(sth);
D_imp_dbh_from_sth;
if(imp_dbh->async_query_in_flight) {
if (mariadb_db_async_result(sth, &imp_sth->result) == (my_ulonglong)-1) {
XSRETURN_UNDEF;
}
}
if (imp_sth->row_num == (my_ulonglong)-1 || imp_sth->row_num == (my_ulonglong)-2)
XSRETURN_IV(-1);
RETVAL = my_ulonglong2sv(imp_sth->row_num);
OUTPUT:
RETVAL
#ifndef HAVE_DBI_1_642
void
last_insert_id(sth, catalog=&PL_sv_undef, schema=&PL_sv_undef, table=&PL_sv_undef, field=&PL_sv_undef, attr=Nullsv)
SV *sth
SV *catalog
SV *schema
SV *table
SV *field
SV *attr
PPCODE:
{
/* Compatibility for DBI version prior to 1.642 which does not support dbd_st_last_insert_id API */
D_imp_sth(sth);
ST(0) = mariadb_st_last_insert_id(sth, imp_sth, catalog, schema, table, field, attr);
XSRETURN(1);
}
#endif
SV *
mariadb_async_result(sth)
SV* sth
CODE:
{
D_imp_sth(sth);
my_ulonglong retval;
retval= mariadb_db_async_result(sth, &imp_sth->result);
if (retval == (my_ulonglong)-1)
XSRETURN_UNDEF;
if (retval == (my_ulonglong)-2)
XSRETURN_IV(-1);
if (retval == 0)
XSRETURN_PV("0E0");
RETVAL = my_ulonglong2sv(retval);
}
OUTPUT:
RETVAL
void mariadb_async_ready(sth)
SV* sth
PPCODE:
{
int retval;
retval = mariadb_db_async_ready(sth);
if(retval > 0) {
XSRETURN_YES;
} else if(retval == 0) {
XSRETURN_NO;
} else {
XSRETURN_UNDEF;
}
}
void _async_check(sth)
SV* sth
PPCODE:
{
D_imp_sth(sth);
D_imp_dbh_from_sth;
ASYNC_CHECK_XS(sth);
XSRETURN_YES;
}