blob: 34babfd7503bfafce43dd351613f232b08d6f88a [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;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000057
58 self->st = NULL;
59 self->in_use = 0;
60
Marc-André Lemburg4cc0f242008-08-07 18:54:33 +000061 sql_cstr = _PyUnicode_AsStringAndSize(sql, &sql_cstr_len);
Guido van Rossumfa9a1212007-08-29 03:34:29 +000062 if (sql_cstr == NULL) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000063 rc = PYSQLITE_SQL_WRONG_TYPE;
64 return rc;
65 }
Serhiy Storchaka42d67af2014-09-11 13:29:05 +030066 if (strlen(sql_cstr) != (size_t)sql_cstr_len) {
67 PyErr_SetString(PyExc_ValueError, "the query contains a null character");
68 return PYSQLITE_SQL_WRONG_TYPE;
69 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000070
Thomas Wouters477c8d52006-05-27 19:21:47 +000071 self->in_weakreflist = NULL;
Guido van Rossum83857e32007-05-09 23:37:01 +000072 Py_INCREF(sql);
73 self->sql = sql;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000074
Benjamin Petersond7b03282008-09-13 15:58:53 +000075 Py_BEGIN_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000076 rc = sqlite3_prepare(connection->db,
77 sql_cstr,
78 -1,
79 &self->st,
80 &tail);
Benjamin Petersond7b03282008-09-13 15:58:53 +000081 Py_END_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000082
83 self->db = connection->db;
84
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +000085 if (rc == SQLITE_OK && pysqlite_check_remaining_sql(tail)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000086 (void)sqlite3_finalize(self->st);
87 self->st = NULL;
88 rc = PYSQLITE_TOO_MUCH_SQL;
89 }
90
91 return rc;
92}
93
Petri Lehtinenbc35beb2012-02-09 21:09:03 +020094int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000095{
96 int rc = SQLITE_OK;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000097 const char* buffer;
98 char* string;
99 Py_ssize_t buflen;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000100 parameter_type paramtype;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000101
102 if (parameter == Py_None) {
103 rc = sqlite3_bind_null(self->st, pos);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000104 goto final;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000105 }
106
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000107 if (PyLong_CheckExact(parameter)) {
108 paramtype = TYPE_LONG;
109 } else if (PyFloat_CheckExact(parameter)) {
110 paramtype = TYPE_FLOAT;
111 } else if (PyUnicode_CheckExact(parameter)) {
112 paramtype = TYPE_UNICODE;
113 } else if (PyLong_Check(parameter)) {
114 paramtype = TYPE_LONG;
115 } else if (PyFloat_Check(parameter)) {
116 paramtype = TYPE_FLOAT;
117 } else if (PyUnicode_Check(parameter)) {
Gerhard Häring6117f422008-09-22 06:04:51 +0000118 paramtype = TYPE_UNICODE;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000119 } else if (PyObject_CheckBuffer(parameter)) {
120 paramtype = TYPE_BUFFER;
121 } else {
122 paramtype = TYPE_UNKNOWN;
123 }
124
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000125 switch (paramtype) {
Serhiy Storchaka3cf96ac2013-02-07 17:01:47 +0200126 case TYPE_LONG: {
127 sqlite_int64 value = _pysqlite_long_as_int64(parameter);
128 if (value == -1 && PyErr_Occurred())
129 rc = -1;
130 else
131 rc = sqlite3_bind_int64(self->st, pos, value);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000132 break;
Serhiy Storchaka3cf96ac2013-02-07 17:01:47 +0200133 }
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000134 case TYPE_FLOAT:
135 rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
136 break;
137 case TYPE_UNICODE:
Petri Lehtinen023fe332012-02-01 22:18:19 +0200138 string = _PyUnicode_AsStringAndSize(parameter, &buflen);
Victor Stinner3f658be2013-11-18 01:36:29 +0100139 if (string == NULL)
140 return -1;
141 if (buflen > INT_MAX) {
142 PyErr_SetString(PyExc_OverflowError,
143 "string longer than INT_MAX bytes");
144 return -1;
145 }
146 rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000147 break;
148 case TYPE_BUFFER:
Victor Stinner3f658be2013-11-18 01:36:29 +0100149 if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) != 0) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000150 PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
Victor Stinner3f658be2013-11-18 01:36:29 +0100151 return -1;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000152 }
Victor Stinner3f658be2013-11-18 01:36:29 +0100153 if (buflen > INT_MAX) {
154 PyErr_SetString(PyExc_OverflowError,
155 "BLOB longer than INT_MAX bytes");
156 return -1;
157 }
158 rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000159 break;
160 case TYPE_UNKNOWN:
161 rc = -1;
162 }
163
164final:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000165 return rc;
166}
167
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000168/* returns 0 if the object is one of Python's internal ones that don't need to be adapted */
169static int _need_adapt(PyObject* obj)
170{
171 if (pysqlite_BaseTypeAdapted) {
172 return 1;
173 }
174
175 if (PyLong_CheckExact(obj) || PyFloat_CheckExact(obj)
Christian Heimes9c4756e2008-05-26 13:22:05 +0000176 || PyUnicode_CheckExact(obj) || PyByteArray_CheckExact(obj)) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000177 return 0;
178 } else {
179 return 1;
180 }
181}
182
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200183void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000184{
185 PyObject* current_param;
186 PyObject* adapted;
187 const char* binding_name;
188 int i;
189 int rc;
190 int num_params_needed;
Victor Stinnerafccb0a2013-11-18 02:07:29 +0100191 Py_ssize_t num_params;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000192
193 Py_BEGIN_ALLOW_THREADS
194 num_params_needed = sqlite3_bind_parameter_count(self->st);
195 Py_END_ALLOW_THREADS
196
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000197 if (PyTuple_CheckExact(parameters) || PyList_CheckExact(parameters) || (!PyDict_Check(parameters) && PySequence_Check(parameters))) {
198 /* parameters passed as sequence */
199 if (PyTuple_CheckExact(parameters)) {
200 num_params = PyTuple_GET_SIZE(parameters);
201 } else if (PyList_CheckExact(parameters)) {
202 num_params = PyList_GET_SIZE(parameters);
203 } else {
204 num_params = PySequence_Size(parameters);
205 }
206 if (num_params != num_params_needed) {
Victor Stinnerafccb0a2013-11-18 02:07:29 +0100207 PyErr_Format(pysqlite_ProgrammingError,
208 "Incorrect number of bindings supplied. The current "
209 "statement uses %d, and there are %zd supplied.",
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000210 num_params_needed, num_params);
211 return;
212 }
213 for (i = 0; i < num_params; i++) {
214 if (PyTuple_CheckExact(parameters)) {
215 current_param = PyTuple_GET_ITEM(parameters, i);
216 Py_XINCREF(current_param);
217 } else if (PyList_CheckExact(parameters)) {
218 current_param = PyList_GET_ITEM(parameters, i);
219 Py_XINCREF(current_param);
220 } else {
221 current_param = PySequence_GetItem(parameters, i);
222 }
223 if (!current_param) {
224 return;
225 }
226
227 if (!_need_adapt(current_param)) {
228 adapted = current_param;
229 } else {
Benjamin Petersond7b03282008-09-13 15:58:53 +0000230 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000231 if (adapted) {
232 Py_DECREF(current_param);
233 } else {
234 PyErr_Clear();
235 adapted = current_param;
236 }
237 }
238
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200239 rc = pysqlite_statement_bind_parameter(self, i + 1, adapted);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000240 Py_DECREF(adapted);
241
242 if (rc != SQLITE_OK) {
243 if (!PyErr_Occurred()) {
244 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
245 }
246 return;
247 }
248 }
249 } else if (PyDict_Check(parameters)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000250 /* parameters passed as dictionary */
251 for (i = 1; i <= num_params_needed; i++) {
252 Py_BEGIN_ALLOW_THREADS
253 binding_name = sqlite3_bind_parameter_name(self->st, i);
254 Py_END_ALLOW_THREADS
255 if (!binding_name) {
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000256 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 +0000257 return;
258 }
259
260 binding_name++; /* skip first char (the colon) */
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000261 if (PyDict_CheckExact(parameters)) {
262 current_param = PyDict_GetItemString(parameters, binding_name);
263 Py_XINCREF(current_param);
264 } else {
Serhiy Storchakac6792272013-10-19 21:03:34 +0300265 current_param = PyMapping_GetItemString(parameters, binding_name);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000266 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000267 if (!current_param) {
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000268 PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000269 return;
270 }
271
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000272 if (!_need_adapt(current_param)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000273 adapted = current_param;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000274 } else {
Benjamin Petersond7b03282008-09-13 15:58:53 +0000275 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000276 if (adapted) {
277 Py_DECREF(current_param);
278 } else {
279 PyErr_Clear();
280 adapted = current_param;
281 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000282 }
283
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200284 rc = pysqlite_statement_bind_parameter(self, i, adapted);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000285 Py_DECREF(adapted);
286
287 if (rc != SQLITE_OK) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000288 if (!PyErr_Occurred()) {
289 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
290 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000291 return;
292 }
293 }
294 } else {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000295 PyErr_SetString(PyExc_ValueError, "parameters are of unsupported type");
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000296 }
297}
298
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000299int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000300{
301 const char* tail;
302 int rc;
Guido van Rossum83857e32007-05-09 23:37:01 +0000303 const char* sql_cstr;
304 Py_ssize_t sql_len;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000305 sqlite3_stmt* new_st;
306
Marc-André Lemburg4cc0f242008-08-07 18:54:33 +0000307 sql_cstr = _PyUnicode_AsStringAndSize(self->sql, &sql_len);
Guido van Rossumfa9a1212007-08-29 03:34:29 +0000308 if (sql_cstr == NULL) {
Guido van Rossum83857e32007-05-09 23:37:01 +0000309 rc = PYSQLITE_SQL_WRONG_TYPE;
310 return rc;
311 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000312
Benjamin Petersond7b03282008-09-13 15:58:53 +0000313 Py_BEGIN_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000314 rc = sqlite3_prepare(self->db,
315 sql_cstr,
316 -1,
317 &new_st,
318 &tail);
Benjamin Petersond7b03282008-09-13 15:58:53 +0000319 Py_END_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000320
321 if (rc == SQLITE_OK) {
322 /* The efficient sqlite3_transfer_bindings is only available in SQLite
323 * version 3.2.2 or later. For older SQLite releases, that might not
324 * even define SQLITE_VERSION_NUMBER, we do it the manual way.
325 */
326 #ifdef SQLITE_VERSION_NUMBER
327 #if SQLITE_VERSION_NUMBER >= 3002002
Christian Heimes38053212007-12-14 01:24:44 +0000328 /* The check for the number of parameters is necessary to not trigger a
329 * bug in certain SQLite versions (experienced in 3.2.8 and 3.3.4). */
330 if (sqlite3_bind_parameter_count(self->st) > 0) {
331 (void)sqlite3_transfer_bindings(self->st, new_st);
332 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000333 #endif
334 #else
335 statement_bind_parameters(self, params);
336 #endif
337
338 (void)sqlite3_finalize(self->st);
339 self->st = new_st;
340 }
341
342 return rc;
343}
344
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000345int pysqlite_statement_finalize(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000346{
347 int rc;
348
349 rc = SQLITE_OK;
350 if (self->st) {
351 Py_BEGIN_ALLOW_THREADS
352 rc = sqlite3_finalize(self->st);
353 Py_END_ALLOW_THREADS
354 self->st = NULL;
355 }
356
357 self->in_use = 0;
358
359 return rc;
360}
361
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000362int pysqlite_statement_reset(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000363{
364 int rc;
365
366 rc = SQLITE_OK;
367
368 if (self->in_use && self->st) {
369 Py_BEGIN_ALLOW_THREADS
370 rc = sqlite3_reset(self->st);
371 Py_END_ALLOW_THREADS
372
373 if (rc == SQLITE_OK) {
374 self->in_use = 0;
375 }
376 }
377
378 return rc;
379}
380
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000381void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000382{
383 self->in_use = 1;
384}
385
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000386void pysqlite_statement_dealloc(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000387{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000388 if (self->st) {
389 Py_BEGIN_ALLOW_THREADS
Brett Cannonb94767f2011-02-22 20:15:44 +0000390 sqlite3_finalize(self->st);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000391 Py_END_ALLOW_THREADS
392 }
393
394 self->st = NULL;
395
396 Py_XDECREF(self->sql);
397
Thomas Wouters477c8d52006-05-27 19:21:47 +0000398 if (self->in_weakreflist != NULL) {
399 PyObject_ClearWeakRefs((PyObject*)self);
400 }
401
Christian Heimes90aa7642007-12-19 02:45:37 +0000402 Py_TYPE(self)->tp_free((PyObject*)self);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000403}
404
405/*
406 * Checks if there is anything left in an SQL string after SQLite compiled it.
407 * This is used to check if somebody tried to execute more than one SQL command
408 * with one execute()/executemany() command, which the DB-API and we don't
409 * allow.
410 *
411 * Returns 1 if there is more left than should be. 0 if ok.
412 */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000413static int pysqlite_check_remaining_sql(const char* tail)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000414{
415 const char* pos = tail;
416
417 parse_remaining_sql_state state = NORMAL;
418
419 for (;;) {
420 switch (*pos) {
421 case 0:
422 return 0;
423 case '-':
424 if (state == NORMAL) {
425 state = LINECOMMENT_1;
426 } else if (state == LINECOMMENT_1) {
427 state = IN_LINECOMMENT;
428 }
429 break;
430 case ' ':
431 case '\t':
432 break;
433 case '\n':
434 case 13:
435 if (state == IN_LINECOMMENT) {
436 state = NORMAL;
437 }
438 break;
439 case '/':
440 if (state == NORMAL) {
441 state = COMMENTSTART_1;
442 } else if (state == COMMENTEND_1) {
443 state = NORMAL;
444 } else if (state == COMMENTSTART_1) {
445 return 1;
446 }
447 break;
448 case '*':
449 if (state == NORMAL) {
450 return 1;
451 } else if (state == LINECOMMENT_1) {
452 return 1;
453 } else if (state == COMMENTSTART_1) {
454 state = IN_COMMENT;
455 } else if (state == IN_COMMENT) {
456 state = COMMENTEND_1;
457 }
458 break;
459 default:
460 if (state == COMMENTEND_1) {
461 state = IN_COMMENT;
462 } else if (state == IN_LINECOMMENT) {
463 } else if (state == IN_COMMENT) {
464 } else {
465 return 1;
466 }
467 }
468
469 pos++;
470 }
471
472 return 0;
473}
474
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000475PyTypeObject pysqlite_StatementType = {
Martin v. Löwis9f2e3462007-07-21 17:22:18 +0000476 PyVarObject_HEAD_INIT(NULL, 0)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000477 MODULE_NAME ".Statement", /* tp_name */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000478 sizeof(pysqlite_Statement), /* tp_basicsize */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000479 0, /* tp_itemsize */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000480 (destructor)pysqlite_statement_dealloc, /* tp_dealloc */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000481 0, /* tp_print */
482 0, /* tp_getattr */
483 0, /* tp_setattr */
Mark Dickinsone94c6792009-02-02 20:36:42 +0000484 0, /* tp_reserved */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000485 0, /* tp_repr */
486 0, /* tp_as_number */
487 0, /* tp_as_sequence */
488 0, /* tp_as_mapping */
489 0, /* tp_hash */
490 0, /* tp_call */
491 0, /* tp_str */
492 0, /* tp_getattro */
493 0, /* tp_setattro */
494 0, /* tp_as_buffer */
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000495 Py_TPFLAGS_DEFAULT, /* tp_flags */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000496 0, /* tp_doc */
497 0, /* tp_traverse */
498 0, /* tp_clear */
499 0, /* tp_richcompare */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000500 offsetof(pysqlite_Statement, in_weakreflist), /* tp_weaklistoffset */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000501 0, /* tp_iter */
502 0, /* tp_iternext */
503 0, /* tp_methods */
504 0, /* tp_members */
505 0, /* tp_getset */
506 0, /* tp_base */
507 0, /* tp_dict */
508 0, /* tp_descr_get */
509 0, /* tp_descr_set */
510 0, /* tp_dictoffset */
511 (initproc)0, /* tp_init */
512 0, /* tp_alloc */
513 0, /* tp_new */
514 0 /* tp_free */
515};
516
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000517extern int pysqlite_statement_setup_types(void)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000518{
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000519 pysqlite_StatementType.tp_new = PyType_GenericNew;
520 return PyType_Ready(&pysqlite_StatementType);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000521}