blob: 575ac69d9030efcc0d1cf4de1fbeb39ca10d4522 [file] [log] [blame]
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00001/* statement.c - the statement type
2 *
Florent Xiclunac934f322010-09-03 23:47:32 +00003 * Copyright (C) 2005-2010 Gerhard Häring <gh@ghaering.de>
Thomas Wouters49fd7fa2006-04-21 10:40:58 +00004 *
5 * This file is part of pysqlite.
6 *
7 * This software is provided 'as-is', without any express or implied
8 * warranty. In no event will the authors be held liable for any damages
9 * arising from the use of this software.
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute it
13 * freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not
16 * claim that you wrote the original software. If you use this software
17 * in a product, an acknowledgment in the product documentation would be
18 * appreciated but is not required.
19 * 2. Altered source versions must be plainly marked as such, and must not be
20 * misrepresented as being the original software.
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#include "statement.h"
25#include "cursor.h"
26#include "connection.h"
27#include "microprotocols.h"
28#include "prepare_protocol.h"
Serhiy Storchaka3cf96ac2013-02-07 17:01:47 +020029#include "util.h"
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000030
31/* prototypes */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +000032static int pysqlite_check_remaining_sql(const char* tail);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000033
34typedef enum {
35 LINECOMMENT_1,
36 IN_LINECOMMENT,
37 COMMENTSTART_1,
38 IN_COMMENT,
39 COMMENTEND_1,
40 NORMAL
41} parse_remaining_sql_state;
42
Gerhard Häringe7ea7452008-03-29 00:45:29 +000043typedef enum {
44 TYPE_LONG,
45 TYPE_FLOAT,
Gerhard Häringe7ea7452008-03-29 00:45:29 +000046 TYPE_UNICODE,
47 TYPE_BUFFER,
48 TYPE_UNKNOWN
49} parameter_type;
50
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +000051int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000052{
53 const char* tail;
54 int rc;
Guido van Rossum83857e32007-05-09 23:37:01 +000055 const char* sql_cstr;
56 Py_ssize_t sql_cstr_len;
Berker Peksagab994ed2016-09-11 12:57:15 +030057 const char* p;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000058
59 self->st = NULL;
60 self->in_use = 0;
61
Serhiy Storchaka06515832016-11-20 09:13:07 +020062 sql_cstr = PyUnicode_AsUTF8AndSize(sql, &sql_cstr_len);
Guido van Rossumfa9a1212007-08-29 03:34:29 +000063 if (sql_cstr == NULL) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000064 rc = PYSQLITE_SQL_WRONG_TYPE;
65 return rc;
66 }
Serhiy Storchaka42d67af2014-09-11 13:29:05 +030067 if (strlen(sql_cstr) != (size_t)sql_cstr_len) {
68 PyErr_SetString(PyExc_ValueError, "the query contains a null character");
69 return PYSQLITE_SQL_WRONG_TYPE;
70 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000071
Thomas Wouters477c8d52006-05-27 19:21:47 +000072 self->in_weakreflist = NULL;
Guido van Rossum83857e32007-05-09 23:37:01 +000073 Py_INCREF(sql);
74 self->sql = sql;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000075
Berker Peksag4a926ca2017-02-26 18:22:38 +030076 /* Determine if the statement is a DML statement.
77 SELECT is the only exception. See #9924. */
78 self->is_dml = 0;
Berker Peksagab994ed2016-09-11 12:57:15 +030079 for (p = sql_cstr; *p != 0; p++) {
80 switch (*p) {
81 case ' ':
82 case '\r':
83 case '\n':
84 case '\t':
85 continue;
86 }
87
Berker Peksag8d1e1902018-09-20 14:10:49 +030088 self->is_dml = (PyOS_strnicmp(p, "insert", 6) == 0)
89 || (PyOS_strnicmp(p, "update", 6) == 0)
90 || (PyOS_strnicmp(p, "delete", 6) == 0)
91 || (PyOS_strnicmp(p, "replace", 7) == 0);
Berker Peksagab994ed2016-09-11 12:57:15 +030092 break;
93 }
94
Benjamin Petersond7b03282008-09-13 15:58:53 +000095 Py_BEGIN_ALLOW_THREADS
Benjamin Peterson52526942017-09-20 07:36:18 -070096 rc = sqlite3_prepare_v2(connection->db,
97 sql_cstr,
98 -1,
99 &self->st,
100 &tail);
Benjamin Petersond7b03282008-09-13 15:58:53 +0000101 Py_END_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000102
103 self->db = connection->db;
104
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000105 if (rc == SQLITE_OK && pysqlite_check_remaining_sql(tail)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000106 (void)sqlite3_finalize(self->st);
107 self->st = NULL;
108 rc = PYSQLITE_TOO_MUCH_SQL;
109 }
110
111 return rc;
112}
113
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200114int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000115{
116 int rc = SQLITE_OK;
Serhiy Storchaka85b0f5b2016-11-20 10:16:47 +0200117 const char *string;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000118 Py_ssize_t buflen;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000119 parameter_type paramtype;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000120
121 if (parameter == Py_None) {
122 rc = sqlite3_bind_null(self->st, pos);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000123 goto final;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000124 }
125
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000126 if (PyLong_CheckExact(parameter)) {
127 paramtype = TYPE_LONG;
128 } else if (PyFloat_CheckExact(parameter)) {
129 paramtype = TYPE_FLOAT;
130 } else if (PyUnicode_CheckExact(parameter)) {
131 paramtype = TYPE_UNICODE;
132 } else if (PyLong_Check(parameter)) {
133 paramtype = TYPE_LONG;
134 } else if (PyFloat_Check(parameter)) {
135 paramtype = TYPE_FLOAT;
136 } else if (PyUnicode_Check(parameter)) {
Gerhard Häring6117f422008-09-22 06:04:51 +0000137 paramtype = TYPE_UNICODE;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000138 } else if (PyObject_CheckBuffer(parameter)) {
139 paramtype = TYPE_BUFFER;
140 } else {
141 paramtype = TYPE_UNKNOWN;
142 }
143
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000144 switch (paramtype) {
Serhiy Storchaka3cf96ac2013-02-07 17:01:47 +0200145 case TYPE_LONG: {
146 sqlite_int64 value = _pysqlite_long_as_int64(parameter);
147 if (value == -1 && PyErr_Occurred())
148 rc = -1;
149 else
150 rc = sqlite3_bind_int64(self->st, pos, value);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000151 break;
Serhiy Storchaka3cf96ac2013-02-07 17:01:47 +0200152 }
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000153 case TYPE_FLOAT:
154 rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
155 break;
156 case TYPE_UNICODE:
Serhiy Storchaka06515832016-11-20 09:13:07 +0200157 string = PyUnicode_AsUTF8AndSize(parameter, &buflen);
Victor Stinner3f658be2013-11-18 01:36:29 +0100158 if (string == NULL)
159 return -1;
160 if (buflen > INT_MAX) {
161 PyErr_SetString(PyExc_OverflowError,
162 "string longer than INT_MAX bytes");
163 return -1;
164 }
165 rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000166 break;
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200167 case TYPE_BUFFER: {
168 Py_buffer view;
169 if (PyObject_GetBuffer(parameter, &view, PyBUF_SIMPLE) != 0) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000170 PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
Victor Stinner3f658be2013-11-18 01:36:29 +0100171 return -1;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000172 }
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200173 if (view.len > INT_MAX) {
Victor Stinner3f658be2013-11-18 01:36:29 +0100174 PyErr_SetString(PyExc_OverflowError,
175 "BLOB longer than INT_MAX bytes");
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200176 PyBuffer_Release(&view);
Victor Stinner3f658be2013-11-18 01:36:29 +0100177 return -1;
178 }
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200179 rc = sqlite3_bind_blob(self->st, pos, view.buf, (int)view.len, SQLITE_TRANSIENT);
180 PyBuffer_Release(&view);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000181 break;
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200182 }
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000183 case TYPE_UNKNOWN:
184 rc = -1;
185 }
186
187final:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000188 return rc;
189}
190
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000191/* returns 0 if the object is one of Python's internal ones that don't need to be adapted */
192static int _need_adapt(PyObject* obj)
193{
194 if (pysqlite_BaseTypeAdapted) {
195 return 1;
196 }
197
198 if (PyLong_CheckExact(obj) || PyFloat_CheckExact(obj)
Christian Heimes9c4756e2008-05-26 13:22:05 +0000199 || PyUnicode_CheckExact(obj) || PyByteArray_CheckExact(obj)) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000200 return 0;
201 } else {
202 return 1;
203 }
204}
205
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200206void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000207{
208 PyObject* current_param;
209 PyObject* adapted;
210 const char* binding_name;
211 int i;
212 int rc;
213 int num_params_needed;
Victor Stinnerafccb0a2013-11-18 02:07:29 +0100214 Py_ssize_t num_params;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000215
216 Py_BEGIN_ALLOW_THREADS
217 num_params_needed = sqlite3_bind_parameter_count(self->st);
218 Py_END_ALLOW_THREADS
219
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000220 if (PyTuple_CheckExact(parameters) || PyList_CheckExact(parameters) || (!PyDict_Check(parameters) && PySequence_Check(parameters))) {
221 /* parameters passed as sequence */
222 if (PyTuple_CheckExact(parameters)) {
223 num_params = PyTuple_GET_SIZE(parameters);
224 } else if (PyList_CheckExact(parameters)) {
225 num_params = PyList_GET_SIZE(parameters);
226 } else {
227 num_params = PySequence_Size(parameters);
228 }
229 if (num_params != num_params_needed) {
Victor Stinnerafccb0a2013-11-18 02:07:29 +0100230 PyErr_Format(pysqlite_ProgrammingError,
231 "Incorrect number of bindings supplied. The current "
232 "statement uses %d, and there are %zd supplied.",
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000233 num_params_needed, num_params);
234 return;
235 }
236 for (i = 0; i < num_params; i++) {
237 if (PyTuple_CheckExact(parameters)) {
238 current_param = PyTuple_GET_ITEM(parameters, i);
239 Py_XINCREF(current_param);
240 } else if (PyList_CheckExact(parameters)) {
241 current_param = PyList_GET_ITEM(parameters, i);
242 Py_XINCREF(current_param);
243 } else {
244 current_param = PySequence_GetItem(parameters, i);
245 }
246 if (!current_param) {
247 return;
248 }
249
250 if (!_need_adapt(current_param)) {
251 adapted = current_param;
252 } else {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200253 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
254 Py_DECREF(current_param);
255 if (!adapted) {
256 return;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000257 }
258 }
259
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200260 rc = pysqlite_statement_bind_parameter(self, i + 1, adapted);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000261 Py_DECREF(adapted);
262
263 if (rc != SQLITE_OK) {
264 if (!PyErr_Occurred()) {
265 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
266 }
267 return;
268 }
269 }
270 } else if (PyDict_Check(parameters)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000271 /* parameters passed as dictionary */
272 for (i = 1; i <= num_params_needed; i++) {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200273 PyObject *binding_name_obj;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000274 Py_BEGIN_ALLOW_THREADS
275 binding_name = sqlite3_bind_parameter_name(self->st, i);
276 Py_END_ALLOW_THREADS
277 if (!binding_name) {
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000278 PyErr_Format(pysqlite_ProgrammingError, "Binding %d has no name, but you supplied a dictionary (which has only names).", i);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000279 return;
280 }
281
282 binding_name++; /* skip first char (the colon) */
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200283 binding_name_obj = PyUnicode_FromString(binding_name);
284 if (!binding_name_obj) {
285 return;
286 }
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000287 if (PyDict_CheckExact(parameters)) {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200288 current_param = PyDict_GetItemWithError(parameters, binding_name_obj);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000289 Py_XINCREF(current_param);
290 } else {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200291 current_param = PyObject_GetItem(parameters, binding_name_obj);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000292 }
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200293 Py_DECREF(binding_name_obj);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000294 if (!current_param) {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200295 if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) {
296 PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i);
297 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000298 return;
299 }
300
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000301 if (!_need_adapt(current_param)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000302 adapted = current_param;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000303 } else {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200304 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
305 Py_DECREF(current_param);
306 if (!adapted) {
307 return;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000308 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000309 }
310
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200311 rc = pysqlite_statement_bind_parameter(self, i, adapted);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000312 Py_DECREF(adapted);
313
314 if (rc != SQLITE_OK) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000315 if (!PyErr_Occurred()) {
316 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
317 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000318 return;
319 }
320 }
321 } else {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000322 PyErr_SetString(PyExc_ValueError, "parameters are of unsupported type");
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000323 }
324}
325
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000326int pysqlite_statement_finalize(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000327{
328 int rc;
329
330 rc = SQLITE_OK;
331 if (self->st) {
332 Py_BEGIN_ALLOW_THREADS
333 rc = sqlite3_finalize(self->st);
334 Py_END_ALLOW_THREADS
335 self->st = NULL;
336 }
337
338 self->in_use = 0;
339
340 return rc;
341}
342
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000343int pysqlite_statement_reset(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000344{
345 int rc;
346
347 rc = SQLITE_OK;
348
349 if (self->in_use && self->st) {
350 Py_BEGIN_ALLOW_THREADS
351 rc = sqlite3_reset(self->st);
352 Py_END_ALLOW_THREADS
353
354 if (rc == SQLITE_OK) {
355 self->in_use = 0;
356 }
357 }
358
359 return rc;
360}
361
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000362void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000363{
364 self->in_use = 1;
365}
366
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000367void pysqlite_statement_dealloc(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000368{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000369 if (self->st) {
370 Py_BEGIN_ALLOW_THREADS
Brett Cannonb94767f2011-02-22 20:15:44 +0000371 sqlite3_finalize(self->st);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000372 Py_END_ALLOW_THREADS
373 }
374
375 self->st = NULL;
376
377 Py_XDECREF(self->sql);
378
Thomas Wouters477c8d52006-05-27 19:21:47 +0000379 if (self->in_weakreflist != NULL) {
380 PyObject_ClearWeakRefs((PyObject*)self);
381 }
382
Christian Heimes90aa7642007-12-19 02:45:37 +0000383 Py_TYPE(self)->tp_free((PyObject*)self);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000384}
385
386/*
387 * Checks if there is anything left in an SQL string after SQLite compiled it.
388 * This is used to check if somebody tried to execute more than one SQL command
389 * with one execute()/executemany() command, which the DB-API and we don't
390 * allow.
391 *
392 * Returns 1 if there is more left than should be. 0 if ok.
393 */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000394static int pysqlite_check_remaining_sql(const char* tail)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000395{
396 const char* pos = tail;
397
398 parse_remaining_sql_state state = NORMAL;
399
400 for (;;) {
401 switch (*pos) {
402 case 0:
403 return 0;
404 case '-':
405 if (state == NORMAL) {
406 state = LINECOMMENT_1;
407 } else if (state == LINECOMMENT_1) {
408 state = IN_LINECOMMENT;
409 }
410 break;
411 case ' ':
412 case '\t':
413 break;
414 case '\n':
415 case 13:
416 if (state == IN_LINECOMMENT) {
417 state = NORMAL;
418 }
419 break;
420 case '/':
421 if (state == NORMAL) {
422 state = COMMENTSTART_1;
423 } else if (state == COMMENTEND_1) {
424 state = NORMAL;
425 } else if (state == COMMENTSTART_1) {
426 return 1;
427 }
428 break;
429 case '*':
430 if (state == NORMAL) {
431 return 1;
432 } else if (state == LINECOMMENT_1) {
433 return 1;
434 } else if (state == COMMENTSTART_1) {
435 state = IN_COMMENT;
436 } else if (state == IN_COMMENT) {
437 state = COMMENTEND_1;
438 }
439 break;
440 default:
441 if (state == COMMENTEND_1) {
442 state = IN_COMMENT;
443 } else if (state == IN_LINECOMMENT) {
444 } else if (state == IN_COMMENT) {
445 } else {
446 return 1;
447 }
448 }
449
450 pos++;
451 }
452
453 return 0;
454}
455
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000456PyTypeObject pysqlite_StatementType = {
Martin v. Löwis9f2e3462007-07-21 17:22:18 +0000457 PyVarObject_HEAD_INIT(NULL, 0)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000458 MODULE_NAME ".Statement", /* tp_name */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000459 sizeof(pysqlite_Statement), /* tp_basicsize */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000460 0, /* tp_itemsize */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000461 (destructor)pysqlite_statement_dealloc, /* tp_dealloc */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000462 0, /* tp_print */
463 0, /* tp_getattr */
464 0, /* tp_setattr */
Mark Dickinsone94c6792009-02-02 20:36:42 +0000465 0, /* tp_reserved */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000466 0, /* tp_repr */
467 0, /* tp_as_number */
468 0, /* tp_as_sequence */
469 0, /* tp_as_mapping */
470 0, /* tp_hash */
471 0, /* tp_call */
472 0, /* tp_str */
473 0, /* tp_getattro */
474 0, /* tp_setattro */
475 0, /* tp_as_buffer */
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000476 Py_TPFLAGS_DEFAULT, /* tp_flags */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000477 0, /* tp_doc */
478 0, /* tp_traverse */
479 0, /* tp_clear */
480 0, /* tp_richcompare */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000481 offsetof(pysqlite_Statement, in_weakreflist), /* tp_weaklistoffset */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000482 0, /* tp_iter */
483 0, /* tp_iternext */
484 0, /* tp_methods */
485 0, /* tp_members */
486 0, /* tp_getset */
487 0, /* tp_base */
488 0, /* tp_dict */
489 0, /* tp_descr_get */
490 0, /* tp_descr_set */
491 0, /* tp_dictoffset */
492 (initproc)0, /* tp_init */
493 0, /* tp_alloc */
494 0, /* tp_new */
495 0 /* tp_free */
496};
497
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000498extern int pysqlite_statement_setup_types(void)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000499{
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000500 pysqlite_StatementType.tp_new = PyType_GenericNew;
501 return PyType_Ready(&pysqlite_StatementType);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000502}