blob: 0e7766804d9a2f8465b8f7626a6e8aa480c10987 [file] [log] [blame]
Anthony Baxterc51ee692006-04-01 00:57:31 +00001/* statement.c - the statement type
2 *
Gerhard Häring1cc60ed2008-02-29 22:08:41 +00003 * Copyright (C) 2005-2007 Gerhard Häring <gh@ghaering.de>
Anthony Baxterc51ee692006-04-01 00:57:31 +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"
Anthony Baxter07f5b352006-04-01 08:36:27 +000025#include "cursor.h"
Anthony Baxterc51ee692006-04-01 00:57:31 +000026#include "connection.h"
Anthony Baxter07f5b352006-04-01 08:36:27 +000027#include "microprotocols.h"
28#include "prepare_protocol.h"
Anthony Baxter72289a62006-04-04 06:29:05 +000029#include "sqlitecompat.h"
Anthony Baxterc51ee692006-04-01 00:57:31 +000030
31/* prototypes */
Gerhard Häring0741a602007-01-14 01:43:50 +000032static int pysqlite_check_remaining_sql(const char* tail);
Anthony Baxterc51ee692006-04-01 00:57:31 +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äring1cc60ed2008-02-29 22:08:41 +000043typedef enum {
44 TYPE_INT,
45 TYPE_LONG,
46 TYPE_FLOAT,
47 TYPE_STRING,
48 TYPE_UNICODE,
49 TYPE_BUFFER,
50 TYPE_UNKNOWN
51} parameter_type;
52
Gerhard Häring0741a602007-01-14 01:43:50 +000053int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql)
Anthony Baxterc51ee692006-04-01 00:57:31 +000054{
55 const char* tail;
56 int rc;
57 PyObject* sql_str;
58 char* sql_cstr;
59
60 self->st = NULL;
Anthony Baxterc51ee692006-04-01 00:57:31 +000061 self->in_use = 0;
62
Gregory P. Smithdd96db62008-06-09 04:58:54 +000063 if (PyString_Check(sql)) {
Anthony Baxterc51ee692006-04-01 00:57:31 +000064 sql_str = sql;
65 Py_INCREF(sql_str);
66 } else if (PyUnicode_Check(sql)) {
67 sql_str = PyUnicode_AsUTF8String(sql);
68 if (!sql_str) {
69 rc = PYSQLITE_SQL_WRONG_TYPE;
70 return rc;
71 }
72 } else {
73 rc = PYSQLITE_SQL_WRONG_TYPE;
74 return rc;
75 }
76
Gerhard Häring3e99c0a2006-04-23 15:24:26 +000077 self->in_weakreflist = NULL;
Anthony Baxterc51ee692006-04-01 00:57:31 +000078 self->sql = sql_str;
79
Gregory P. Smithdd96db62008-06-09 04:58:54 +000080 sql_cstr = PyString_AsString(sql_str);
Anthony Baxterc51ee692006-04-01 00:57:31 +000081
82 rc = sqlite3_prepare(connection->db,
83 sql_cstr,
84 -1,
85 &self->st,
86 &tail);
87
88 self->db = connection->db;
89
Gerhard Häring0741a602007-01-14 01:43:50 +000090 if (rc == SQLITE_OK && pysqlite_check_remaining_sql(tail)) {
Anthony Baxterc51ee692006-04-01 00:57:31 +000091 (void)sqlite3_finalize(self->st);
Neal Norwitz195e4e62006-04-16 03:37:19 +000092 self->st = NULL;
Anthony Baxterc51ee692006-04-01 00:57:31 +000093 rc = PYSQLITE_TOO_MUCH_SQL;
94 }
95
96 return rc;
97}
98
Gerhard Häring2a11c052008-03-28 20:08:36 +000099int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter, int allow_8bit_chars)
Anthony Baxter07f5b352006-04-01 08:36:27 +0000100{
101 int rc = SQLITE_OK;
102 long longval;
Anthony Baxter07f5b352006-04-01 08:36:27 +0000103 PY_LONG_LONG longlongval;
Anthony Baxter07f5b352006-04-01 08:36:27 +0000104 const char* buffer;
105 char* string;
Neal Norwitz95f0e4c2006-04-01 09:08:06 +0000106 Py_ssize_t buflen;
Anthony Baxter07f5b352006-04-01 08:36:27 +0000107 PyObject* stringval;
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000108 parameter_type paramtype;
Gerhard Häring2a11c052008-03-28 20:08:36 +0000109 char* c;
Anthony Baxter07f5b352006-04-01 08:36:27 +0000110
111 if (parameter == Py_None) {
112 rc = sqlite3_bind_null(self->st, pos);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000113 goto final;
Anthony Baxter07f5b352006-04-01 08:36:27 +0000114 }
115
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000116 if (PyInt_CheckExact(parameter)) {
117 paramtype = TYPE_INT;
118 } else if (PyLong_CheckExact(parameter)) {
119 paramtype = TYPE_LONG;
120 } else if (PyFloat_CheckExact(parameter)) {
121 paramtype = TYPE_FLOAT;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000122 } else if (PyString_CheckExact(parameter)) {
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000123 paramtype = TYPE_STRING;
124 } else if (PyUnicode_CheckExact(parameter)) {
125 paramtype = TYPE_UNICODE;
126 } else if (PyBuffer_Check(parameter)) {
127 paramtype = TYPE_BUFFER;
128 } else if (PyInt_Check(parameter)) {
129 paramtype = TYPE_INT;
130 } else if (PyLong_Check(parameter)) {
131 paramtype = TYPE_LONG;
132 } else if (PyFloat_Check(parameter)) {
133 paramtype = TYPE_FLOAT;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000134 } else if (PyString_Check(parameter)) {
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000135 paramtype = TYPE_STRING;
136 } else if (PyUnicode_Check(parameter)) {
137 paramtype = TYPE_UNICODE;
138 } else {
139 paramtype = TYPE_UNKNOWN;
140 }
141
Gerhard Häring2a11c052008-03-28 20:08:36 +0000142 if (paramtype == TYPE_STRING && !allow_8bit_chars) {
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000143 string = PyString_AS_STRING(parameter);
Gerhard Häring2a11c052008-03-28 20:08:36 +0000144 for (c = string; *c != 0; c++) {
145 if (*c & 0x80) {
146 PyErr_SetString(pysqlite_ProgrammingError, "You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.");
147 rc = -1;
148 goto final;
149 }
150 }
151 }
152
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000153 switch (paramtype) {
154 case TYPE_INT:
155 longval = PyInt_AsLong(parameter);
156 rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval);
157 break;
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000158 case TYPE_LONG:
159 longlongval = PyLong_AsLongLong(parameter);
160 /* in the overflow error case, longlongval is -1, and an exception is set */
161 rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval);
162 break;
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000163 case TYPE_FLOAT:
164 rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
165 break;
166 case TYPE_STRING:
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000167 string = PyString_AS_STRING(parameter);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000168 rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
169 break;
170 case TYPE_UNICODE:
171 stringval = PyUnicode_AsUTF8String(parameter);
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000172 string = PyString_AsString(stringval);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000173 rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT);
174 Py_DECREF(stringval);
175 break;
176 case TYPE_BUFFER:
177 if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) {
178 rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT);
179 } else {
180 PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
181 rc = -1;
182 }
183 break;
184 case TYPE_UNKNOWN:
185 rc = -1;
186 }
187
188final:
Anthony Baxter07f5b352006-04-01 08:36:27 +0000189 return rc;
190}
191
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000192/* returns 0 if the object is one of Python's internal ones that don't need to be adapted */
193static int _need_adapt(PyObject* obj)
194{
195 if (pysqlite_BaseTypeAdapted) {
196 return 1;
197 }
198
199 if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000200 || PyFloat_CheckExact(obj) || PyString_CheckExact(obj)
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000201 || PyUnicode_CheckExact(obj) || PyBuffer_Check(obj)) {
202 return 0;
203 } else {
204 return 1;
205 }
206}
207
Gerhard Häring2a11c052008-03-28 20:08:36 +0000208void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters, int allow_8bit_chars)
Anthony Baxter07f5b352006-04-01 08:36:27 +0000209{
210 PyObject* current_param;
211 PyObject* adapted;
212 const char* binding_name;
213 int i;
214 int rc;
215 int num_params_needed;
216 int num_params;
217
218 Py_BEGIN_ALLOW_THREADS
219 num_params_needed = sqlite3_bind_parameter_count(self->st);
220 Py_END_ALLOW_THREADS
221
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000222 if (PyTuple_CheckExact(parameters) || PyList_CheckExact(parameters) || (!PyDict_Check(parameters) && PySequence_Check(parameters))) {
223 /* parameters passed as sequence */
224 if (PyTuple_CheckExact(parameters)) {
225 num_params = PyTuple_GET_SIZE(parameters);
226 } else if (PyList_CheckExact(parameters)) {
227 num_params = PyList_GET_SIZE(parameters);
228 } else {
229 num_params = PySequence_Size(parameters);
230 }
231 if (num_params != num_params_needed) {
232 PyErr_Format(pysqlite_ProgrammingError, "Incorrect number of bindings supplied. The current statement uses %d, and there are %d supplied.",
233 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 {
253 adapted = microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
254 if (adapted) {
255 Py_DECREF(current_param);
256 } else {
257 PyErr_Clear();
258 adapted = current_param;
259 }
260 }
261
Gerhard Häring2a11c052008-03-28 20:08:36 +0000262 rc = pysqlite_statement_bind_parameter(self, i + 1, adapted, allow_8bit_chars);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000263 Py_DECREF(adapted);
264
265 if (rc != SQLITE_OK) {
Gerhard Häring2a11c052008-03-28 20:08:36 +0000266 if (!PyErr_Occurred()) {
267 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
268 }
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000269 return;
270 }
271 }
272 } else if (PyDict_Check(parameters)) {
Anthony Baxter07f5b352006-04-01 08:36:27 +0000273 /* parameters passed as dictionary */
274 for (i = 1; i <= num_params_needed; i++) {
275 Py_BEGIN_ALLOW_THREADS
276 binding_name = sqlite3_bind_parameter_name(self->st, i);
277 Py_END_ALLOW_THREADS
278 if (!binding_name) {
Gerhard Häring0741a602007-01-14 01:43:50 +0000279 PyErr_Format(pysqlite_ProgrammingError, "Binding %d has no name, but you supplied a dictionary (which has only names).", i);
Anthony Baxter07f5b352006-04-01 08:36:27 +0000280 return;
281 }
282
283 binding_name++; /* skip first char (the colon) */
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000284 if (PyDict_CheckExact(parameters)) {
285 current_param = PyDict_GetItemString(parameters, binding_name);
286 Py_XINCREF(current_param);
287 } else {
288 current_param = PyMapping_GetItemString(parameters, (char*)binding_name);
289 }
Anthony Baxter07f5b352006-04-01 08:36:27 +0000290 if (!current_param) {
Gerhard Häring0741a602007-01-14 01:43:50 +0000291 PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i);
Anthony Baxter07f5b352006-04-01 08:36:27 +0000292 return;
293 }
294
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000295 if (!_need_adapt(current_param)) {
Anthony Baxter07f5b352006-04-01 08:36:27 +0000296 adapted = current_param;
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000297 } else {
298 adapted = microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
299 if (adapted) {
300 Py_DECREF(current_param);
301 } else {
302 PyErr_Clear();
303 adapted = current_param;
304 }
Anthony Baxter07f5b352006-04-01 08:36:27 +0000305 }
306
Gerhard Häring2a11c052008-03-28 20:08:36 +0000307 rc = pysqlite_statement_bind_parameter(self, i, adapted, allow_8bit_chars);
Anthony Baxter07f5b352006-04-01 08:36:27 +0000308 Py_DECREF(adapted);
309
310 if (rc != SQLITE_OK) {
Gerhard Häring2a11c052008-03-28 20:08:36 +0000311 if (!PyErr_Occurred()) {
312 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
313 }
Anthony Baxter07f5b352006-04-01 08:36:27 +0000314 return;
315 }
316 }
317 } else {
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000318 PyErr_SetString(PyExc_ValueError, "parameters are of unsupported type");
Anthony Baxter07f5b352006-04-01 08:36:27 +0000319 }
320}
321
Gerhard Häring0741a602007-01-14 01:43:50 +0000322int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000323{
324 const char* tail;
325 int rc;
326 char* sql_cstr;
327 sqlite3_stmt* new_st;
328
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000329 sql_cstr = PyString_AsString(self->sql);
Anthony Baxterc51ee692006-04-01 00:57:31 +0000330
331 rc = sqlite3_prepare(self->db,
332 sql_cstr,
333 -1,
334 &new_st,
335 &tail);
336
337 if (rc == SQLITE_OK) {
Anthony Baxter07f5b352006-04-01 08:36:27 +0000338 /* The efficient sqlite3_transfer_bindings is only available in SQLite
339 * version 3.2.2 or later. For older SQLite releases, that might not
340 * even define SQLITE_VERSION_NUMBER, we do it the manual way.
341 */
342 #ifdef SQLITE_VERSION_NUMBER
343 #if SQLITE_VERSION_NUMBER >= 3002002
Gerhard Häring99b9df82007-12-11 21:07:40 +0000344 /* The check for the number of parameters is necessary to not trigger a
345 * bug in certain SQLite versions (experienced in 3.2.8 and 3.3.4). */
346 if (sqlite3_bind_parameter_count(self->st) > 0) {
347 (void)sqlite3_transfer_bindings(self->st, new_st);
348 }
Anthony Baxter07f5b352006-04-01 08:36:27 +0000349 #endif
350 #else
351 statement_bind_parameters(self, params);
352 #endif
Anthony Baxterc51ee692006-04-01 00:57:31 +0000353
354 (void)sqlite3_finalize(self->st);
355 self->st = new_st;
356 }
357
358 return rc;
359}
360
Gerhard Häring0741a602007-01-14 01:43:50 +0000361int pysqlite_statement_finalize(pysqlite_Statement* self)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000362{
363 int rc;
364
365 rc = SQLITE_OK;
366 if (self->st) {
367 Py_BEGIN_ALLOW_THREADS
368 rc = sqlite3_finalize(self->st);
369 Py_END_ALLOW_THREADS
370 self->st = NULL;
371 }
372
373 self->in_use = 0;
374
375 return rc;
376}
377
Gerhard Häring0741a602007-01-14 01:43:50 +0000378int pysqlite_statement_reset(pysqlite_Statement* self)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000379{
380 int rc;
381
382 rc = SQLITE_OK;
383
384 if (self->in_use && self->st) {
385 Py_BEGIN_ALLOW_THREADS
386 rc = sqlite3_reset(self->st);
387 Py_END_ALLOW_THREADS
388
389 if (rc == SQLITE_OK) {
390 self->in_use = 0;
391 }
392 }
393
394 return rc;
395}
396
Gerhard Häring0741a602007-01-14 01:43:50 +0000397void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000398{
399 self->in_use = 1;
400}
401
Gerhard Häring0741a602007-01-14 01:43:50 +0000402void pysqlite_statement_dealloc(pysqlite_Statement* self)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000403{
404 int rc;
405
406 if (self->st) {
407 Py_BEGIN_ALLOW_THREADS
408 rc = sqlite3_finalize(self->st);
409 Py_END_ALLOW_THREADS
410 }
411
412 self->st = NULL;
413
414 Py_XDECREF(self->sql);
415
Gerhard Häring3e99c0a2006-04-23 15:24:26 +0000416 if (self->in_weakreflist != NULL) {
417 PyObject_ClearWeakRefs((PyObject*)self);
418 }
419
Christian Heimese93237d2007-12-19 02:37:44 +0000420 Py_TYPE(self)->tp_free((PyObject*)self);
Anthony Baxterc51ee692006-04-01 00:57:31 +0000421}
422
423/*
424 * Checks if there is anything left in an SQL string after SQLite compiled it.
425 * This is used to check if somebody tried to execute more than one SQL command
426 * with one execute()/executemany() command, which the DB-API and we don't
427 * allow.
428 *
429 * Returns 1 if there is more left than should be. 0 if ok.
430 */
Gerhard Häring0741a602007-01-14 01:43:50 +0000431static int pysqlite_check_remaining_sql(const char* tail)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000432{
433 const char* pos = tail;
434
435 parse_remaining_sql_state state = NORMAL;
436
437 for (;;) {
438 switch (*pos) {
439 case 0:
440 return 0;
441 case '-':
442 if (state == NORMAL) {
443 state = LINECOMMENT_1;
444 } else if (state == LINECOMMENT_1) {
445 state = IN_LINECOMMENT;
446 }
447 break;
448 case ' ':
449 case '\t':
450 break;
451 case '\n':
452 case 13:
453 if (state == IN_LINECOMMENT) {
454 state = NORMAL;
455 }
456 break;
457 case '/':
458 if (state == NORMAL) {
459 state = COMMENTSTART_1;
460 } else if (state == COMMENTEND_1) {
461 state = NORMAL;
462 } else if (state == COMMENTSTART_1) {
463 return 1;
464 }
465 break;
466 case '*':
467 if (state == NORMAL) {
468 return 1;
469 } else if (state == LINECOMMENT_1) {
470 return 1;
471 } else if (state == COMMENTSTART_1) {
472 state = IN_COMMENT;
473 } else if (state == IN_COMMENT) {
474 state = COMMENTEND_1;
475 }
476 break;
477 default:
478 if (state == COMMENTEND_1) {
479 state = IN_COMMENT;
480 } else if (state == IN_LINECOMMENT) {
481 } else if (state == IN_COMMENT) {
482 } else {
483 return 1;
484 }
485 }
486
487 pos++;
488 }
489
490 return 0;
491}
492
Gerhard Häring0741a602007-01-14 01:43:50 +0000493PyTypeObject pysqlite_StatementType = {
Martin v. Löwis68192102007-07-21 06:55:02 +0000494 PyVarObject_HEAD_INIT(NULL, 0)
Anthony Baxter8e7b4902006-04-05 18:25:33 +0000495 MODULE_NAME ".Statement", /* tp_name */
Gerhard Häring0741a602007-01-14 01:43:50 +0000496 sizeof(pysqlite_Statement), /* tp_basicsize */
Anthony Baxterc51ee692006-04-01 00:57:31 +0000497 0, /* tp_itemsize */
Gerhard Häring0741a602007-01-14 01:43:50 +0000498 (destructor)pysqlite_statement_dealloc, /* tp_dealloc */
Anthony Baxterc51ee692006-04-01 00:57:31 +0000499 0, /* tp_print */
500 0, /* tp_getattr */
501 0, /* tp_setattr */
502 0, /* tp_compare */
503 0, /* tp_repr */
504 0, /* tp_as_number */
505 0, /* tp_as_sequence */
506 0, /* tp_as_mapping */
507 0, /* tp_hash */
508 0, /* tp_call */
509 0, /* tp_str */
510 0, /* tp_getattro */
511 0, /* tp_setattro */
512 0, /* tp_as_buffer */
Gerhard Häring3e99c0a2006-04-23 15:24:26 +0000513 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
Anthony Baxterc51ee692006-04-01 00:57:31 +0000514 0, /* tp_doc */
515 0, /* tp_traverse */
516 0, /* tp_clear */
517 0, /* tp_richcompare */
Gerhard Häring0741a602007-01-14 01:43:50 +0000518 offsetof(pysqlite_Statement, in_weakreflist), /* tp_weaklistoffset */
Anthony Baxterc51ee692006-04-01 00:57:31 +0000519 0, /* tp_iter */
520 0, /* tp_iternext */
521 0, /* tp_methods */
522 0, /* tp_members */
523 0, /* tp_getset */
524 0, /* tp_base */
525 0, /* tp_dict */
526 0, /* tp_descr_get */
527 0, /* tp_descr_set */
528 0, /* tp_dictoffset */
529 (initproc)0, /* tp_init */
530 0, /* tp_alloc */
531 0, /* tp_new */
532 0 /* tp_free */
533};
534
Gerhard Häring0741a602007-01-14 01:43:50 +0000535extern int pysqlite_statement_setup_types(void)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000536{
Gerhard Häring0741a602007-01-14 01:43:50 +0000537 pysqlite_StatementType.tp_new = PyType_GenericNew;
538 return PyType_Ready(&pysqlite_StatementType);
Anthony Baxterc51ee692006-04-01 00:57:31 +0000539}