blob: 9de8f9b67228f5c13f6e402706d204061ab843e7 [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
Victor Stinnerc6a23202019-06-26 03:16:24 +020062 assert(PyUnicode_Check(sql));
63
Serhiy Storchaka06515832016-11-20 09:13:07 +020064 sql_cstr = PyUnicode_AsUTF8AndSize(sql, &sql_cstr_len);
Guido van Rossumfa9a1212007-08-29 03:34:29 +000065 if (sql_cstr == NULL) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000066 rc = PYSQLITE_SQL_WRONG_TYPE;
67 return rc;
68 }
Serhiy Storchaka42d67af2014-09-11 13:29:05 +030069 if (strlen(sql_cstr) != (size_t)sql_cstr_len) {
70 PyErr_SetString(PyExc_ValueError, "the query contains a null character");
71 return PYSQLITE_SQL_WRONG_TYPE;
72 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000073
Thomas Wouters477c8d52006-05-27 19:21:47 +000074 self->in_weakreflist = NULL;
Guido van Rossum83857e32007-05-09 23:37:01 +000075 Py_INCREF(sql);
76 self->sql = sql;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000077
Berker Peksag4a926ca2017-02-26 18:22:38 +030078 /* Determine if the statement is a DML statement.
79 SELECT is the only exception. See #9924. */
80 self->is_dml = 0;
Berker Peksagab994ed2016-09-11 12:57:15 +030081 for (p = sql_cstr; *p != 0; p++) {
82 switch (*p) {
83 case ' ':
84 case '\r':
85 case '\n':
86 case '\t':
87 continue;
88 }
89
Berker Peksag8d1e1902018-09-20 14:10:49 +030090 self->is_dml = (PyOS_strnicmp(p, "insert", 6) == 0)
91 || (PyOS_strnicmp(p, "update", 6) == 0)
92 || (PyOS_strnicmp(p, "delete", 6) == 0)
93 || (PyOS_strnicmp(p, "replace", 7) == 0);
Berker Peksagab994ed2016-09-11 12:57:15 +030094 break;
95 }
96
Benjamin Petersond7b03282008-09-13 15:58:53 +000097 Py_BEGIN_ALLOW_THREADS
Benjamin Peterson52526942017-09-20 07:36:18 -070098 rc = sqlite3_prepare_v2(connection->db,
99 sql_cstr,
100 -1,
101 &self->st,
102 &tail);
Benjamin Petersond7b03282008-09-13 15:58:53 +0000103 Py_END_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000104
105 self->db = connection->db;
106
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000107 if (rc == SQLITE_OK && pysqlite_check_remaining_sql(tail)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000108 (void)sqlite3_finalize(self->st);
109 self->st = NULL;
110 rc = PYSQLITE_TOO_MUCH_SQL;
111 }
112
113 return rc;
114}
115
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200116int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000117{
118 int rc = SQLITE_OK;
Serhiy Storchaka85b0f5b2016-11-20 10:16:47 +0200119 const char *string;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000120 Py_ssize_t buflen;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000121 parameter_type paramtype;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000122
123 if (parameter == Py_None) {
124 rc = sqlite3_bind_null(self->st, pos);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000125 goto final;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000126 }
127
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000128 if (PyLong_CheckExact(parameter)) {
129 paramtype = TYPE_LONG;
130 } else if (PyFloat_CheckExact(parameter)) {
131 paramtype = TYPE_FLOAT;
132 } else if (PyUnicode_CheckExact(parameter)) {
133 paramtype = TYPE_UNICODE;
134 } else if (PyLong_Check(parameter)) {
135 paramtype = TYPE_LONG;
136 } else if (PyFloat_Check(parameter)) {
137 paramtype = TYPE_FLOAT;
138 } else if (PyUnicode_Check(parameter)) {
Gerhard Häring6117f422008-09-22 06:04:51 +0000139 paramtype = TYPE_UNICODE;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000140 } else if (PyObject_CheckBuffer(parameter)) {
141 paramtype = TYPE_BUFFER;
142 } else {
143 paramtype = TYPE_UNKNOWN;
144 }
145
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000146 switch (paramtype) {
Serhiy Storchaka3cf96ac2013-02-07 17:01:47 +0200147 case TYPE_LONG: {
148 sqlite_int64 value = _pysqlite_long_as_int64(parameter);
149 if (value == -1 && PyErr_Occurred())
150 rc = -1;
151 else
152 rc = sqlite3_bind_int64(self->st, pos, value);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000153 break;
Serhiy Storchaka3cf96ac2013-02-07 17:01:47 +0200154 }
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000155 case TYPE_FLOAT:
156 rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
157 break;
158 case TYPE_UNICODE:
Serhiy Storchaka06515832016-11-20 09:13:07 +0200159 string = PyUnicode_AsUTF8AndSize(parameter, &buflen);
Victor Stinner3f658be2013-11-18 01:36:29 +0100160 if (string == NULL)
161 return -1;
162 if (buflen > INT_MAX) {
163 PyErr_SetString(PyExc_OverflowError,
164 "string longer than INT_MAX bytes");
165 return -1;
166 }
167 rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000168 break;
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200169 case TYPE_BUFFER: {
170 Py_buffer view;
171 if (PyObject_GetBuffer(parameter, &view, PyBUF_SIMPLE) != 0) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000172 PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
Victor Stinner3f658be2013-11-18 01:36:29 +0100173 return -1;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000174 }
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200175 if (view.len > INT_MAX) {
Victor Stinner3f658be2013-11-18 01:36:29 +0100176 PyErr_SetString(PyExc_OverflowError,
177 "BLOB longer than INT_MAX bytes");
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200178 PyBuffer_Release(&view);
Victor Stinner3f658be2013-11-18 01:36:29 +0100179 return -1;
180 }
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200181 rc = sqlite3_bind_blob(self->st, pos, view.buf, (int)view.len, SQLITE_TRANSIENT);
182 PyBuffer_Release(&view);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000183 break;
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200184 }
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000185 case TYPE_UNKNOWN:
186 rc = -1;
187 }
188
189final:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000190 return rc;
191}
192
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000193/* returns 0 if the object is one of Python's internal ones that don't need to be adapted */
194static int _need_adapt(PyObject* obj)
195{
196 if (pysqlite_BaseTypeAdapted) {
197 return 1;
198 }
199
200 if (PyLong_CheckExact(obj) || PyFloat_CheckExact(obj)
Christian Heimes9c4756e2008-05-26 13:22:05 +0000201 || PyUnicode_CheckExact(obj) || PyByteArray_CheckExact(obj)) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000202 return 0;
203 } else {
204 return 1;
205 }
206}
207
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200208void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000209{
210 PyObject* current_param;
211 PyObject* adapted;
212 const char* binding_name;
213 int i;
214 int rc;
215 int num_params_needed;
Victor Stinnerafccb0a2013-11-18 02:07:29 +0100216 Py_ssize_t num_params;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000217
218 Py_BEGIN_ALLOW_THREADS
219 num_params_needed = sqlite3_bind_parameter_count(self->st);
220 Py_END_ALLOW_THREADS
221
Gerhard Häringe7ea7452008-03-29 00:45:29 +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) {
Victor Stinnerafccb0a2013-11-18 02:07:29 +0100232 PyErr_Format(pysqlite_ProgrammingError,
233 "Incorrect number of bindings supplied. The current "
234 "statement uses %d, and there are %zd supplied.",
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000235 num_params_needed, num_params);
236 return;
237 }
238 for (i = 0; i < num_params; i++) {
239 if (PyTuple_CheckExact(parameters)) {
240 current_param = PyTuple_GET_ITEM(parameters, i);
241 Py_XINCREF(current_param);
242 } else if (PyList_CheckExact(parameters)) {
243 current_param = PyList_GET_ITEM(parameters, i);
244 Py_XINCREF(current_param);
245 } else {
246 current_param = PySequence_GetItem(parameters, i);
247 }
248 if (!current_param) {
249 return;
250 }
251
252 if (!_need_adapt(current_param)) {
253 adapted = current_param;
254 } else {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200255 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
256 Py_DECREF(current_param);
257 if (!adapted) {
258 return;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000259 }
260 }
261
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200262 rc = pysqlite_statement_bind_parameter(self, i + 1, adapted);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000263 Py_DECREF(adapted);
264
265 if (rc != SQLITE_OK) {
266 if (!PyErr_Occurred()) {
267 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
268 }
269 return;
270 }
271 }
272 } else if (PyDict_Check(parameters)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000273 /* parameters passed as dictionary */
274 for (i = 1; i <= num_params_needed; i++) {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200275 PyObject *binding_name_obj;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000276 Py_BEGIN_ALLOW_THREADS
277 binding_name = sqlite3_bind_parameter_name(self->st, i);
278 Py_END_ALLOW_THREADS
279 if (!binding_name) {
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000280 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 +0000281 return;
282 }
283
284 binding_name++; /* skip first char (the colon) */
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200285 binding_name_obj = PyUnicode_FromString(binding_name);
286 if (!binding_name_obj) {
287 return;
288 }
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000289 if (PyDict_CheckExact(parameters)) {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200290 current_param = PyDict_GetItemWithError(parameters, binding_name_obj);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000291 Py_XINCREF(current_param);
292 } else {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200293 current_param = PyObject_GetItem(parameters, binding_name_obj);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000294 }
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200295 Py_DECREF(binding_name_obj);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000296 if (!current_param) {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200297 if (!PyErr_Occurred() || PyErr_ExceptionMatches(PyExc_LookupError)) {
298 PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i);
299 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000300 return;
301 }
302
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000303 if (!_need_adapt(current_param)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000304 adapted = current_param;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000305 } else {
Serhiy Storchakafc662ac2018-12-10 16:06:08 +0200306 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, current_param);
307 Py_DECREF(current_param);
308 if (!adapted) {
309 return;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000310 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000311 }
312
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200313 rc = pysqlite_statement_bind_parameter(self, i, adapted);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000314 Py_DECREF(adapted);
315
316 if (rc != SQLITE_OK) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000317 if (!PyErr_Occurred()) {
318 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
319 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000320 return;
321 }
322 }
323 } else {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000324 PyErr_SetString(PyExc_ValueError, "parameters are of unsupported type");
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000325 }
326}
327
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000328int pysqlite_statement_finalize(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000329{
330 int rc;
331
332 rc = SQLITE_OK;
333 if (self->st) {
334 Py_BEGIN_ALLOW_THREADS
335 rc = sqlite3_finalize(self->st);
336 Py_END_ALLOW_THREADS
337 self->st = NULL;
338 }
339
340 self->in_use = 0;
341
342 return rc;
343}
344
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000345int pysqlite_statement_reset(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000346{
347 int rc;
348
349 rc = SQLITE_OK;
350
351 if (self->in_use && self->st) {
352 Py_BEGIN_ALLOW_THREADS
353 rc = sqlite3_reset(self->st);
354 Py_END_ALLOW_THREADS
355
356 if (rc == SQLITE_OK) {
357 self->in_use = 0;
358 }
359 }
360
361 return rc;
362}
363
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000364void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000365{
366 self->in_use = 1;
367}
368
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000369void pysqlite_statement_dealloc(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000370{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000371 if (self->st) {
372 Py_BEGIN_ALLOW_THREADS
Brett Cannonb94767f2011-02-22 20:15:44 +0000373 sqlite3_finalize(self->st);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000374 Py_END_ALLOW_THREADS
375 }
376
377 self->st = NULL;
378
379 Py_XDECREF(self->sql);
380
Thomas Wouters477c8d52006-05-27 19:21:47 +0000381 if (self->in_weakreflist != NULL) {
382 PyObject_ClearWeakRefs((PyObject*)self);
383 }
384
Christian Heimes90aa7642007-12-19 02:45:37 +0000385 Py_TYPE(self)->tp_free((PyObject*)self);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000386}
387
388/*
389 * Checks if there is anything left in an SQL string after SQLite compiled it.
390 * This is used to check if somebody tried to execute more than one SQL command
391 * with one execute()/executemany() command, which the DB-API and we don't
392 * allow.
393 *
394 * Returns 1 if there is more left than should be. 0 if ok.
395 */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000396static int pysqlite_check_remaining_sql(const char* tail)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000397{
398 const char* pos = tail;
399
400 parse_remaining_sql_state state = NORMAL;
401
402 for (;;) {
403 switch (*pos) {
404 case 0:
405 return 0;
406 case '-':
407 if (state == NORMAL) {
408 state = LINECOMMENT_1;
409 } else if (state == LINECOMMENT_1) {
410 state = IN_LINECOMMENT;
411 }
412 break;
413 case ' ':
414 case '\t':
415 break;
416 case '\n':
417 case 13:
418 if (state == IN_LINECOMMENT) {
419 state = NORMAL;
420 }
421 break;
422 case '/':
423 if (state == NORMAL) {
424 state = COMMENTSTART_1;
425 } else if (state == COMMENTEND_1) {
426 state = NORMAL;
427 } else if (state == COMMENTSTART_1) {
428 return 1;
429 }
430 break;
431 case '*':
432 if (state == NORMAL) {
433 return 1;
434 } else if (state == LINECOMMENT_1) {
435 return 1;
436 } else if (state == COMMENTSTART_1) {
437 state = IN_COMMENT;
438 } else if (state == IN_COMMENT) {
439 state = COMMENTEND_1;
440 }
441 break;
442 default:
443 if (state == COMMENTEND_1) {
444 state = IN_COMMENT;
445 } else if (state == IN_LINECOMMENT) {
446 } else if (state == IN_COMMENT) {
447 } else {
448 return 1;
449 }
450 }
451
452 pos++;
453 }
454
455 return 0;
456}
457
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000458PyTypeObject pysqlite_StatementType = {
Martin v. Löwis9f2e3462007-07-21 17:22:18 +0000459 PyVarObject_HEAD_INIT(NULL, 0)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000460 MODULE_NAME ".Statement", /* tp_name */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000461 sizeof(pysqlite_Statement), /* tp_basicsize */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000462 0, /* tp_itemsize */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000463 (destructor)pysqlite_statement_dealloc, /* tp_dealloc */
Jeroen Demeyer530f5062019-05-31 04:13:39 +0200464 0, /* tp_vectorcall_offset */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000465 0, /* tp_getattr */
466 0, /* tp_setattr */
Jeroen Demeyer530f5062019-05-31 04:13:39 +0200467 0, /* tp_as_async */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000468 0, /* tp_repr */
469 0, /* tp_as_number */
470 0, /* tp_as_sequence */
471 0, /* tp_as_mapping */
472 0, /* tp_hash */
473 0, /* tp_call */
474 0, /* tp_str */
475 0, /* tp_getattro */
476 0, /* tp_setattro */
477 0, /* tp_as_buffer */
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000478 Py_TPFLAGS_DEFAULT, /* tp_flags */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000479 0, /* tp_doc */
480 0, /* tp_traverse */
481 0, /* tp_clear */
482 0, /* tp_richcompare */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000483 offsetof(pysqlite_Statement, in_weakreflist), /* tp_weaklistoffset */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000484 0, /* tp_iter */
485 0, /* tp_iternext */
486 0, /* tp_methods */
487 0, /* tp_members */
488 0, /* tp_getset */
489 0, /* tp_base */
490 0, /* tp_dict */
491 0, /* tp_descr_get */
492 0, /* tp_descr_set */
493 0, /* tp_dictoffset */
494 (initproc)0, /* tp_init */
495 0, /* tp_alloc */
496 0, /* tp_new */
497 0 /* tp_free */
498};
499
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000500extern int pysqlite_statement_setup_types(void)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000501{
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000502 pysqlite_StatementType.tp_new = PyType_GenericNew;
503 return PyType_Ready(&pysqlite_StatementType);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000504}