blob: edcebddf9ae36ba3bfb2ee295f69b097d5dd9773 [file] [log] [blame]
Anthony Baxterc51ee692006-04-01 00:57:31 +00001/* statement.c - the statement type
2 *
Gerhard Häring3bbb6722010-03-05 09:12:37 +00003 * Copyright (C) 2005-2010 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"
Serhiy Storchaka35c52b62013-02-07 16:59:34 +020029#include "util.h"
Anthony Baxter72289a62006-04-04 06:29:05 +000030#include "sqlitecompat.h"
Anthony Baxterc51ee692006-04-01 00:57:31 +000031
32/* prototypes */
Gerhard Häring0741a602007-01-14 01:43:50 +000033static int pysqlite_check_remaining_sql(const char* tail);
Anthony Baxterc51ee692006-04-01 00:57:31 +000034
35typedef enum {
36 LINECOMMENT_1,
37 IN_LINECOMMENT,
38 COMMENTSTART_1,
39 IN_COMMENT,
40 COMMENTEND_1,
41 NORMAL
42} parse_remaining_sql_state;
43
Gerhard Häring1cc60ed2008-02-29 22:08:41 +000044typedef enum {
45 TYPE_INT,
46 TYPE_LONG,
47 TYPE_FLOAT,
48 TYPE_STRING,
49 TYPE_UNICODE,
50 TYPE_BUFFER,
51 TYPE_UNKNOWN
52} parameter_type;
53
Gerhard Häring0741a602007-01-14 01:43:50 +000054int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql)
Anthony Baxterc51ee692006-04-01 00:57:31 +000055{
56 const char* tail;
57 int rc;
58 PyObject* sql_str;
59 char* sql_cstr;
60
61 self->st = NULL;
Anthony Baxterc51ee692006-04-01 00:57:31 +000062 self->in_use = 0;
63
Gregory P. Smithdd96db62008-06-09 04:58:54 +000064 if (PyString_Check(sql)) {
Anthony Baxterc51ee692006-04-01 00:57:31 +000065 sql_str = sql;
66 Py_INCREF(sql_str);
67 } else if (PyUnicode_Check(sql)) {
68 sql_str = PyUnicode_AsUTF8String(sql);
69 if (!sql_str) {
70 rc = PYSQLITE_SQL_WRONG_TYPE;
71 return rc;
72 }
73 } else {
74 rc = PYSQLITE_SQL_WRONG_TYPE;
75 return rc;
76 }
Serhiy Storchaka0aa65622014-09-11 13:27:19 +030077 sql_cstr = PyString_AsString(sql_str);
78 if (strlen(sql_cstr) != (size_t)PyString_GET_SIZE(sql_str)) {
79 PyErr_SetString(PyExc_ValueError, "the query contains a null character");
80 return PYSQLITE_SQL_WRONG_TYPE;
81 }
Anthony Baxterc51ee692006-04-01 00:57:31 +000082
Gerhard Häring3e99c0a2006-04-23 15:24:26 +000083 self->in_weakreflist = NULL;
Anthony Baxterc51ee692006-04-01 00:57:31 +000084 self->sql = sql_str;
85
Gerhard Häringe6872eb2008-09-12 22:33:22 +000086 Py_BEGIN_ALLOW_THREADS
Anthony Baxterc51ee692006-04-01 00:57:31 +000087 rc = sqlite3_prepare(connection->db,
88 sql_cstr,
89 -1,
90 &self->st,
91 &tail);
Gerhard Häringe6872eb2008-09-12 22:33:22 +000092 Py_END_ALLOW_THREADS
Anthony Baxterc51ee692006-04-01 00:57:31 +000093
94 self->db = connection->db;
95
Gerhard Häring0741a602007-01-14 01:43:50 +000096 if (rc == SQLITE_OK && pysqlite_check_remaining_sql(tail)) {
Anthony Baxterc51ee692006-04-01 00:57:31 +000097 (void)sqlite3_finalize(self->st);
Neal Norwitz195e4e62006-04-16 03:37:19 +000098 self->st = NULL;
Anthony Baxterc51ee692006-04-01 00:57:31 +000099 rc = PYSQLITE_TOO_MUCH_SQL;
100 }
101
102 return rc;
103}
104
Gerhard Häring2a11c052008-03-28 20:08:36 +0000105int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter, int allow_8bit_chars)
Anthony Baxter07f5b352006-04-01 08:36:27 +0000106{
107 int rc = SQLITE_OK;
Anthony Baxter07f5b352006-04-01 08:36:27 +0000108 const char* buffer;
109 char* string;
Neal Norwitz95f0e4c2006-04-01 09:08:06 +0000110 Py_ssize_t buflen;
Anthony Baxter07f5b352006-04-01 08:36:27 +0000111 PyObject* stringval;
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000112 parameter_type paramtype;
Gerhard Häring2a11c052008-03-28 20:08:36 +0000113 char* c;
Anthony Baxter07f5b352006-04-01 08:36:27 +0000114
115 if (parameter == Py_None) {
116 rc = sqlite3_bind_null(self->st, pos);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000117 goto final;
Anthony Baxter07f5b352006-04-01 08:36:27 +0000118 }
119
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000120 if (PyInt_CheckExact(parameter)) {
121 paramtype = TYPE_INT;
122 } else if (PyLong_CheckExact(parameter)) {
123 paramtype = TYPE_LONG;
124 } else if (PyFloat_CheckExact(parameter)) {
125 paramtype = TYPE_FLOAT;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000126 } else if (PyString_CheckExact(parameter)) {
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000127 paramtype = TYPE_STRING;
128 } else if (PyUnicode_CheckExact(parameter)) {
129 paramtype = TYPE_UNICODE;
130 } else if (PyBuffer_Check(parameter)) {
131 paramtype = TYPE_BUFFER;
132 } else if (PyInt_Check(parameter)) {
133 paramtype = TYPE_INT;
134 } else if (PyLong_Check(parameter)) {
135 paramtype = TYPE_LONG;
136 } else if (PyFloat_Check(parameter)) {
137 paramtype = TYPE_FLOAT;
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000138 } else if (PyString_Check(parameter)) {
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000139 paramtype = TYPE_STRING;
140 } else if (PyUnicode_Check(parameter)) {
141 paramtype = TYPE_UNICODE;
142 } else {
143 paramtype = TYPE_UNKNOWN;
144 }
145
Gerhard Häring2a11c052008-03-28 20:08:36 +0000146 if (paramtype == TYPE_STRING && !allow_8bit_chars) {
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000147 string = PyString_AS_STRING(parameter);
Gerhard Häring2a11c052008-03-28 20:08:36 +0000148 for (c = string; *c != 0; c++) {
149 if (*c & 0x80) {
150 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.");
151 rc = -1;
152 goto final;
153 }
154 }
155 }
156
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000157 switch (paramtype) {
Serhiy Storchaka35c52b62013-02-07 16:59:34 +0200158 case TYPE_INT: {
159 long longval = PyInt_AsLong(parameter);
160 rc = sqlite3_bind_int64(self->st, pos, longval);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000161 break;
Serhiy Storchaka35c52b62013-02-07 16:59:34 +0200162 }
163 case TYPE_LONG: {
164 sqlite_int64 value = _pysqlite_long_as_int64(parameter);
165 if (value == -1 && PyErr_Occurred())
166 rc = -1;
167 else
168 rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)value);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000169 break;
Serhiy Storchaka35c52b62013-02-07 16:59:34 +0200170 }
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000171 case TYPE_FLOAT:
172 rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
173 break;
174 case TYPE_STRING:
Petri Lehtinen0518f472012-02-01 22:20:12 +0200175 PyString_AsStringAndSize(parameter, &string, &buflen);
176 rc = sqlite3_bind_text(self->st, pos, string, buflen, SQLITE_TRANSIENT);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000177 break;
178 case TYPE_UNICODE:
179 stringval = PyUnicode_AsUTF8String(parameter);
Petri Lehtinen0518f472012-02-01 22:20:12 +0200180 PyString_AsStringAndSize(stringval, &string, &buflen);
181 rc = sqlite3_bind_text(self->st, pos, string, buflen, SQLITE_TRANSIENT);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000182 Py_DECREF(stringval);
183 break;
184 case TYPE_BUFFER:
185 if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) {
186 rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT);
187 } else {
188 PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
189 rc = -1;
190 }
191 break;
192 case TYPE_UNKNOWN:
193 rc = -1;
194 }
195
196final:
Anthony Baxter07f5b352006-04-01 08:36:27 +0000197 return rc;
198}
199
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000200/* returns 0 if the object is one of Python's internal ones that don't need to be adapted */
201static int _need_adapt(PyObject* obj)
202{
203 if (pysqlite_BaseTypeAdapted) {
204 return 1;
205 }
206
Serhiy Storchaka35c52b62013-02-07 16:59:34 +0200207 if (PyInt_CheckExact(obj) || PyLong_CheckExact(obj)
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000208 || PyFloat_CheckExact(obj) || PyString_CheckExact(obj)
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000209 || PyUnicode_CheckExact(obj) || PyBuffer_Check(obj)) {
210 return 0;
211 } else {
212 return 1;
213 }
214}
215
Gerhard Häring2a11c052008-03-28 20:08:36 +0000216void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters, int allow_8bit_chars)
Anthony Baxter07f5b352006-04-01 08:36:27 +0000217{
218 PyObject* current_param;
219 PyObject* adapted;
220 const char* binding_name;
221 int i;
222 int rc;
223 int num_params_needed;
224 int num_params;
225
226 Py_BEGIN_ALLOW_THREADS
227 num_params_needed = sqlite3_bind_parameter_count(self->st);
228 Py_END_ALLOW_THREADS
229
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000230 if (PyTuple_CheckExact(parameters) || PyList_CheckExact(parameters) || (!PyDict_Check(parameters) && PySequence_Check(parameters))) {
231 /* parameters passed as sequence */
232 if (PyTuple_CheckExact(parameters)) {
233 num_params = PyTuple_GET_SIZE(parameters);
234 } else if (PyList_CheckExact(parameters)) {
235 num_params = PyList_GET_SIZE(parameters);
236 } else {
237 num_params = PySequence_Size(parameters);
238 }
239 if (num_params != num_params_needed) {
240 PyErr_Format(pysqlite_ProgrammingError, "Incorrect number of bindings supplied. The current statement uses %d, and there are %d supplied.",
241 num_params_needed, num_params);
242 return;
243 }
244 for (i = 0; i < num_params; i++) {
245 if (PyTuple_CheckExact(parameters)) {
246 current_param = PyTuple_GET_ITEM(parameters, i);
247 Py_XINCREF(current_param);
248 } else if (PyList_CheckExact(parameters)) {
249 current_param = PyList_GET_ITEM(parameters, i);
250 Py_XINCREF(current_param);
251 } else {
252 current_param = PySequence_GetItem(parameters, i);
253 }
254 if (!current_param) {
255 return;
256 }
257
258 if (!_need_adapt(current_param)) {
259 adapted = current_param;
260 } else {
Gerhard Häring6e1afcf2008-09-12 18:58:57 +0000261 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000262 if (adapted) {
263 Py_DECREF(current_param);
264 } else {
265 PyErr_Clear();
266 adapted = current_param;
267 }
268 }
269
Gerhard Häring2a11c052008-03-28 20:08:36 +0000270 rc = pysqlite_statement_bind_parameter(self, i + 1, adapted, allow_8bit_chars);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000271 Py_DECREF(adapted);
272
273 if (rc != SQLITE_OK) {
Gerhard Häring2a11c052008-03-28 20:08:36 +0000274 if (!PyErr_Occurred()) {
275 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i);
276 }
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000277 return;
278 }
279 }
280 } else if (PyDict_Check(parameters)) {
Anthony Baxter07f5b352006-04-01 08:36:27 +0000281 /* parameters passed as dictionary */
282 for (i = 1; i <= num_params_needed; i++) {
283 Py_BEGIN_ALLOW_THREADS
284 binding_name = sqlite3_bind_parameter_name(self->st, i);
285 Py_END_ALLOW_THREADS
286 if (!binding_name) {
Gerhard Häring0741a602007-01-14 01:43:50 +0000287 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 +0000288 return;
289 }
290
291 binding_name++; /* skip first char (the colon) */
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000292 if (PyDict_CheckExact(parameters)) {
293 current_param = PyDict_GetItemString(parameters, binding_name);
294 Py_XINCREF(current_param);
295 } else {
296 current_param = PyMapping_GetItemString(parameters, (char*)binding_name);
297 }
Anthony Baxter07f5b352006-04-01 08:36:27 +0000298 if (!current_param) {
Gerhard Häring0741a602007-01-14 01:43:50 +0000299 PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i);
Anthony Baxter07f5b352006-04-01 08:36:27 +0000300 return;
301 }
302
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000303 if (!_need_adapt(current_param)) {
Anthony Baxter07f5b352006-04-01 08:36:27 +0000304 adapted = current_param;
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000305 } else {
Gerhard Häring6e1afcf2008-09-12 18:58:57 +0000306 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000307 if (adapted) {
308 Py_DECREF(current_param);
309 } else {
310 PyErr_Clear();
311 adapted = current_param;
312 }
Anthony Baxter07f5b352006-04-01 08:36:27 +0000313 }
314
Gerhard Häring2a11c052008-03-28 20:08:36 +0000315 rc = pysqlite_statement_bind_parameter(self, i, adapted, allow_8bit_chars);
Anthony Baxter07f5b352006-04-01 08:36:27 +0000316 Py_DECREF(adapted);
317
318 if (rc != SQLITE_OK) {
Gerhard Häring2a11c052008-03-28 20:08:36 +0000319 if (!PyErr_Occurred()) {
320 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
321 }
Anthony Baxter07f5b352006-04-01 08:36:27 +0000322 return;
323 }
324 }
325 } else {
Gerhard Häring1cc60ed2008-02-29 22:08:41 +0000326 PyErr_SetString(PyExc_ValueError, "parameters are of unsupported type");
Anthony Baxter07f5b352006-04-01 08:36:27 +0000327 }
328}
329
Gerhard Häring0741a602007-01-14 01:43:50 +0000330int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000331{
332 const char* tail;
333 int rc;
334 char* sql_cstr;
335 sqlite3_stmt* new_st;
336
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000337 sql_cstr = PyString_AsString(self->sql);
Anthony Baxterc51ee692006-04-01 00:57:31 +0000338
Gerhard Häringe6872eb2008-09-12 22:33:22 +0000339 Py_BEGIN_ALLOW_THREADS
Anthony Baxterc51ee692006-04-01 00:57:31 +0000340 rc = sqlite3_prepare(self->db,
341 sql_cstr,
342 -1,
343 &new_st,
344 &tail);
Gerhard Häringe6872eb2008-09-12 22:33:22 +0000345 Py_END_ALLOW_THREADS
Anthony Baxterc51ee692006-04-01 00:57:31 +0000346
347 if (rc == SQLITE_OK) {
Anthony Baxter07f5b352006-04-01 08:36:27 +0000348 /* The efficient sqlite3_transfer_bindings is only available in SQLite
349 * version 3.2.2 or later. For older SQLite releases, that might not
350 * even define SQLITE_VERSION_NUMBER, we do it the manual way.
351 */
352 #ifdef SQLITE_VERSION_NUMBER
353 #if SQLITE_VERSION_NUMBER >= 3002002
Gerhard Häring99b9df82007-12-11 21:07:40 +0000354 /* The check for the number of parameters is necessary to not trigger a
355 * bug in certain SQLite versions (experienced in 3.2.8 and 3.3.4). */
356 if (sqlite3_bind_parameter_count(self->st) > 0) {
357 (void)sqlite3_transfer_bindings(self->st, new_st);
358 }
Anthony Baxter07f5b352006-04-01 08:36:27 +0000359 #endif
360 #else
361 statement_bind_parameters(self, params);
362 #endif
Anthony Baxterc51ee692006-04-01 00:57:31 +0000363
364 (void)sqlite3_finalize(self->st);
365 self->st = new_st;
366 }
367
368 return rc;
369}
370
Gerhard Häring0741a602007-01-14 01:43:50 +0000371int pysqlite_statement_finalize(pysqlite_Statement* self)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000372{
373 int rc;
374
375 rc = SQLITE_OK;
376 if (self->st) {
377 Py_BEGIN_ALLOW_THREADS
378 rc = sqlite3_finalize(self->st);
379 Py_END_ALLOW_THREADS
380 self->st = NULL;
381 }
382
383 self->in_use = 0;
384
385 return rc;
386}
387
Gerhard Häring0741a602007-01-14 01:43:50 +0000388int pysqlite_statement_reset(pysqlite_Statement* self)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000389{
390 int rc;
391
392 rc = SQLITE_OK;
393
394 if (self->in_use && self->st) {
395 Py_BEGIN_ALLOW_THREADS
396 rc = sqlite3_reset(self->st);
397 Py_END_ALLOW_THREADS
398
399 if (rc == SQLITE_OK) {
400 self->in_use = 0;
401 }
402 }
403
404 return rc;
405}
406
Gerhard Häring0741a602007-01-14 01:43:50 +0000407void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000408{
409 self->in_use = 1;
410}
411
Gerhard Häring0741a602007-01-14 01:43:50 +0000412void pysqlite_statement_dealloc(pysqlite_Statement* self)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000413{
414 int rc;
415
416 if (self->st) {
417 Py_BEGIN_ALLOW_THREADS
418 rc = sqlite3_finalize(self->st);
419 Py_END_ALLOW_THREADS
420 }
421
422 self->st = NULL;
423
424 Py_XDECREF(self->sql);
425
Gerhard Häring3e99c0a2006-04-23 15:24:26 +0000426 if (self->in_weakreflist != NULL) {
427 PyObject_ClearWeakRefs((PyObject*)self);
428 }
429
Christian Heimese93237d2007-12-19 02:37:44 +0000430 Py_TYPE(self)->tp_free((PyObject*)self);
Anthony Baxterc51ee692006-04-01 00:57:31 +0000431}
432
433/*
434 * Checks if there is anything left in an SQL string after SQLite compiled it.
435 * This is used to check if somebody tried to execute more than one SQL command
436 * with one execute()/executemany() command, which the DB-API and we don't
437 * allow.
438 *
439 * Returns 1 if there is more left than should be. 0 if ok.
440 */
Gerhard Häring0741a602007-01-14 01:43:50 +0000441static int pysqlite_check_remaining_sql(const char* tail)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000442{
443 const char* pos = tail;
444
445 parse_remaining_sql_state state = NORMAL;
446
447 for (;;) {
448 switch (*pos) {
449 case 0:
450 return 0;
451 case '-':
452 if (state == NORMAL) {
453 state = LINECOMMENT_1;
454 } else if (state == LINECOMMENT_1) {
455 state = IN_LINECOMMENT;
456 }
457 break;
458 case ' ':
459 case '\t':
460 break;
461 case '\n':
462 case 13:
463 if (state == IN_LINECOMMENT) {
464 state = NORMAL;
465 }
466 break;
467 case '/':
468 if (state == NORMAL) {
469 state = COMMENTSTART_1;
470 } else if (state == COMMENTEND_1) {
471 state = NORMAL;
472 } else if (state == COMMENTSTART_1) {
473 return 1;
474 }
475 break;
476 case '*':
477 if (state == NORMAL) {
478 return 1;
479 } else if (state == LINECOMMENT_1) {
480 return 1;
481 } else if (state == COMMENTSTART_1) {
482 state = IN_COMMENT;
483 } else if (state == IN_COMMENT) {
484 state = COMMENTEND_1;
485 }
486 break;
487 default:
488 if (state == COMMENTEND_1) {
489 state = IN_COMMENT;
490 } else if (state == IN_LINECOMMENT) {
491 } else if (state == IN_COMMENT) {
492 } else {
493 return 1;
494 }
495 }
496
497 pos++;
498 }
499
500 return 0;
501}
502
Gerhard Häring0741a602007-01-14 01:43:50 +0000503PyTypeObject pysqlite_StatementType = {
Martin v. Löwis68192102007-07-21 06:55:02 +0000504 PyVarObject_HEAD_INIT(NULL, 0)
Anthony Baxter8e7b4902006-04-05 18:25:33 +0000505 MODULE_NAME ".Statement", /* tp_name */
Gerhard Häring0741a602007-01-14 01:43:50 +0000506 sizeof(pysqlite_Statement), /* tp_basicsize */
Anthony Baxterc51ee692006-04-01 00:57:31 +0000507 0, /* tp_itemsize */
Gerhard Häring0741a602007-01-14 01:43:50 +0000508 (destructor)pysqlite_statement_dealloc, /* tp_dealloc */
Anthony Baxterc51ee692006-04-01 00:57:31 +0000509 0, /* tp_print */
510 0, /* tp_getattr */
511 0, /* tp_setattr */
512 0, /* tp_compare */
513 0, /* tp_repr */
514 0, /* tp_as_number */
515 0, /* tp_as_sequence */
516 0, /* tp_as_mapping */
517 0, /* tp_hash */
518 0, /* tp_call */
519 0, /* tp_str */
520 0, /* tp_getattro */
521 0, /* tp_setattro */
522 0, /* tp_as_buffer */
Gerhard Häring3e99c0a2006-04-23 15:24:26 +0000523 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_WEAKREFS, /* tp_flags */
Anthony Baxterc51ee692006-04-01 00:57:31 +0000524 0, /* tp_doc */
525 0, /* tp_traverse */
526 0, /* tp_clear */
527 0, /* tp_richcompare */
Gerhard Häring0741a602007-01-14 01:43:50 +0000528 offsetof(pysqlite_Statement, in_weakreflist), /* tp_weaklistoffset */
Anthony Baxterc51ee692006-04-01 00:57:31 +0000529 0, /* tp_iter */
530 0, /* tp_iternext */
531 0, /* tp_methods */
532 0, /* tp_members */
533 0, /* tp_getset */
534 0, /* tp_base */
535 0, /* tp_dict */
536 0, /* tp_descr_get */
537 0, /* tp_descr_set */
538 0, /* tp_dictoffset */
539 (initproc)0, /* tp_init */
540 0, /* tp_alloc */
541 0, /* tp_new */
542 0 /* tp_free */
543};
544
Gerhard Häring0741a602007-01-14 01:43:50 +0000545extern int pysqlite_statement_setup_types(void)
Anthony Baxterc51ee692006-04-01 00:57:31 +0000546{
Gerhard Häring0741a602007-01-14 01:43:50 +0000547 pysqlite_StatementType.tp_new = PyType_GenericNew;
548 return PyType_Ready(&pysqlite_StatementType);
Anthony Baxterc51ee692006-04-01 00:57:31 +0000549}