blob: 0df661b9c7ad315a0f2a76dfd939b8a0738867b3 [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 Peksagab994ed2016-09-11 12:57:15 +030076 /* determine if the statement is a DDL statement */
77 self->is_ddl = 0;
78 for (p = sql_cstr; *p != 0; p++) {
79 switch (*p) {
80 case ' ':
81 case '\r':
82 case '\n':
83 case '\t':
84 continue;
85 }
86
87 self->is_ddl = (PyOS_strnicmp(p, "create ", 7) == 0)
88 || (PyOS_strnicmp(p, "drop ", 5) == 0)
89 || (PyOS_strnicmp(p, "reindex ", 8) == 0);
90 break;
91 }
92
Benjamin Petersond7b03282008-09-13 15:58:53 +000093 Py_BEGIN_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +000094 rc = sqlite3_prepare(connection->db,
95 sql_cstr,
96 -1,
97 &self->st,
98 &tail);
Benjamin Petersond7b03282008-09-13 15:58:53 +000099 Py_END_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000100
101 self->db = connection->db;
102
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000103 if (rc == SQLITE_OK && pysqlite_check_remaining_sql(tail)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000104 (void)sqlite3_finalize(self->st);
105 self->st = NULL;
106 rc = PYSQLITE_TOO_MUCH_SQL;
107 }
108
109 return rc;
110}
111
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200112int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000113{
114 int rc = SQLITE_OK;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000115 char* string;
116 Py_ssize_t buflen;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000117 parameter_type paramtype;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000118
119 if (parameter == Py_None) {
120 rc = sqlite3_bind_null(self->st, pos);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000121 goto final;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000122 }
123
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000124 if (PyLong_CheckExact(parameter)) {
125 paramtype = TYPE_LONG;
126 } else if (PyFloat_CheckExact(parameter)) {
127 paramtype = TYPE_FLOAT;
128 } else if (PyUnicode_CheckExact(parameter)) {
129 paramtype = TYPE_UNICODE;
130 } else if (PyLong_Check(parameter)) {
131 paramtype = TYPE_LONG;
132 } else if (PyFloat_Check(parameter)) {
133 paramtype = TYPE_FLOAT;
134 } else if (PyUnicode_Check(parameter)) {
Gerhard Häring6117f422008-09-22 06:04:51 +0000135 paramtype = TYPE_UNICODE;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000136 } else if (PyObject_CheckBuffer(parameter)) {
137 paramtype = TYPE_BUFFER;
138 } else {
139 paramtype = TYPE_UNKNOWN;
140 }
141
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000142 switch (paramtype) {
Serhiy Storchaka3cf96ac2013-02-07 17:01:47 +0200143 case TYPE_LONG: {
144 sqlite_int64 value = _pysqlite_long_as_int64(parameter);
145 if (value == -1 && PyErr_Occurred())
146 rc = -1;
147 else
148 rc = sqlite3_bind_int64(self->st, pos, value);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000149 break;
Serhiy Storchaka3cf96ac2013-02-07 17:01:47 +0200150 }
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000151 case TYPE_FLOAT:
152 rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter));
153 break;
154 case TYPE_UNICODE:
Serhiy Storchaka06515832016-11-20 09:13:07 +0200155 string = PyUnicode_AsUTF8AndSize(parameter, &buflen);
Victor Stinner3f658be2013-11-18 01:36:29 +0100156 if (string == NULL)
157 return -1;
158 if (buflen > INT_MAX) {
159 PyErr_SetString(PyExc_OverflowError,
160 "string longer than INT_MAX bytes");
161 return -1;
162 }
163 rc = sqlite3_bind_text(self->st, pos, string, (int)buflen, SQLITE_TRANSIENT);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000164 break;
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200165 case TYPE_BUFFER: {
166 Py_buffer view;
167 if (PyObject_GetBuffer(parameter, &view, PyBUF_SIMPLE) != 0) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000168 PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
Victor Stinner3f658be2013-11-18 01:36:29 +0100169 return -1;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000170 }
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200171 if (view.len > INT_MAX) {
Victor Stinner3f658be2013-11-18 01:36:29 +0100172 PyErr_SetString(PyExc_OverflowError,
173 "BLOB longer than INT_MAX bytes");
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200174 PyBuffer_Release(&view);
Victor Stinner3f658be2013-11-18 01:36:29 +0100175 return -1;
176 }
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200177 rc = sqlite3_bind_blob(self->st, pos, view.buf, (int)view.len, SQLITE_TRANSIENT);
178 PyBuffer_Release(&view);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000179 break;
Serhiy Storchaka4fdb6842015-02-03 01:21:08 +0200180 }
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000181 case TYPE_UNKNOWN:
182 rc = -1;
183 }
184
185final:
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000186 return rc;
187}
188
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000189/* returns 0 if the object is one of Python's internal ones that don't need to be adapted */
190static int _need_adapt(PyObject* obj)
191{
192 if (pysqlite_BaseTypeAdapted) {
193 return 1;
194 }
195
196 if (PyLong_CheckExact(obj) || PyFloat_CheckExact(obj)
Christian Heimes9c4756e2008-05-26 13:22:05 +0000197 || PyUnicode_CheckExact(obj) || PyByteArray_CheckExact(obj)) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000198 return 0;
199 } else {
200 return 1;
201 }
202}
203
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200204void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000205{
206 PyObject* current_param;
207 PyObject* adapted;
208 const char* binding_name;
209 int i;
210 int rc;
211 int num_params_needed;
Victor Stinnerafccb0a2013-11-18 02:07:29 +0100212 Py_ssize_t num_params;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000213
214 Py_BEGIN_ALLOW_THREADS
215 num_params_needed = sqlite3_bind_parameter_count(self->st);
216 Py_END_ALLOW_THREADS
217
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000218 if (PyTuple_CheckExact(parameters) || PyList_CheckExact(parameters) || (!PyDict_Check(parameters) && PySequence_Check(parameters))) {
219 /* parameters passed as sequence */
220 if (PyTuple_CheckExact(parameters)) {
221 num_params = PyTuple_GET_SIZE(parameters);
222 } else if (PyList_CheckExact(parameters)) {
223 num_params = PyList_GET_SIZE(parameters);
224 } else {
225 num_params = PySequence_Size(parameters);
226 }
227 if (num_params != num_params_needed) {
Victor Stinnerafccb0a2013-11-18 02:07:29 +0100228 PyErr_Format(pysqlite_ProgrammingError,
229 "Incorrect number of bindings supplied. The current "
230 "statement uses %d, and there are %zd supplied.",
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000231 num_params_needed, num_params);
232 return;
233 }
234 for (i = 0; i < num_params; i++) {
235 if (PyTuple_CheckExact(parameters)) {
236 current_param = PyTuple_GET_ITEM(parameters, i);
237 Py_XINCREF(current_param);
238 } else if (PyList_CheckExact(parameters)) {
239 current_param = PyList_GET_ITEM(parameters, i);
240 Py_XINCREF(current_param);
241 } else {
242 current_param = PySequence_GetItem(parameters, i);
243 }
244 if (!current_param) {
245 return;
246 }
247
248 if (!_need_adapt(current_param)) {
249 adapted = current_param;
250 } else {
Benjamin Petersond7b03282008-09-13 15:58:53 +0000251 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000252 if (adapted) {
253 Py_DECREF(current_param);
254 } else {
255 PyErr_Clear();
256 adapted = current_param;
257 }
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++) {
273 Py_BEGIN_ALLOW_THREADS
274 binding_name = sqlite3_bind_parameter_name(self->st, i);
275 Py_END_ALLOW_THREADS
276 if (!binding_name) {
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000277 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 +0000278 return;
279 }
280
281 binding_name++; /* skip first char (the colon) */
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000282 if (PyDict_CheckExact(parameters)) {
283 current_param = PyDict_GetItemString(parameters, binding_name);
284 Py_XINCREF(current_param);
285 } else {
Serhiy Storchakac6792272013-10-19 21:03:34 +0300286 current_param = PyMapping_GetItemString(parameters, binding_name);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000287 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000288 if (!current_param) {
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000289 PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000290 return;
291 }
292
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000293 if (!_need_adapt(current_param)) {
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000294 adapted = current_param;
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000295 } else {
Benjamin Petersond7b03282008-09-13 15:58:53 +0000296 adapted = pysqlite_microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL);
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000297 if (adapted) {
298 Py_DECREF(current_param);
299 } else {
300 PyErr_Clear();
301 adapted = current_param;
302 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000303 }
304
Petri Lehtinenbc35beb2012-02-09 21:09:03 +0200305 rc = pysqlite_statement_bind_parameter(self, i, adapted);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000306 Py_DECREF(adapted);
307
308 if (rc != SQLITE_OK) {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000309 if (!PyErr_Occurred()) {
310 PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name);
311 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000312 return;
313 }
314 }
315 } else {
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000316 PyErr_SetString(PyExc_ValueError, "parameters are of unsupported type");
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000317 }
318}
319
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000320int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000321{
322 const char* tail;
323 int rc;
Guido van Rossum83857e32007-05-09 23:37:01 +0000324 const char* sql_cstr;
325 Py_ssize_t sql_len;
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000326 sqlite3_stmt* new_st;
327
Serhiy Storchaka06515832016-11-20 09:13:07 +0200328 sql_cstr = PyUnicode_AsUTF8AndSize(self->sql, &sql_len);
Guido van Rossumfa9a1212007-08-29 03:34:29 +0000329 if (sql_cstr == NULL) {
Guido van Rossum83857e32007-05-09 23:37:01 +0000330 rc = PYSQLITE_SQL_WRONG_TYPE;
331 return rc;
332 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000333
Benjamin Petersond7b03282008-09-13 15:58:53 +0000334 Py_BEGIN_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000335 rc = sqlite3_prepare(self->db,
336 sql_cstr,
337 -1,
338 &new_st,
339 &tail);
Benjamin Petersond7b03282008-09-13 15:58:53 +0000340 Py_END_ALLOW_THREADS
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000341
342 if (rc == SQLITE_OK) {
343 /* The efficient sqlite3_transfer_bindings is only available in SQLite
344 * version 3.2.2 or later. For older SQLite releases, that might not
345 * even define SQLITE_VERSION_NUMBER, we do it the manual way.
346 */
347 #ifdef SQLITE_VERSION_NUMBER
348 #if SQLITE_VERSION_NUMBER >= 3002002
Christian Heimes38053212007-12-14 01:24:44 +0000349 /* The check for the number of parameters is necessary to not trigger a
350 * bug in certain SQLite versions (experienced in 3.2.8 and 3.3.4). */
351 if (sqlite3_bind_parameter_count(self->st) > 0) {
352 (void)sqlite3_transfer_bindings(self->st, new_st);
353 }
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000354 #endif
355 #else
356 statement_bind_parameters(self, params);
357 #endif
358
359 (void)sqlite3_finalize(self->st);
360 self->st = new_st;
361 }
362
363 return rc;
364}
365
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000366int pysqlite_statement_finalize(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000367{
368 int rc;
369
370 rc = SQLITE_OK;
371 if (self->st) {
372 Py_BEGIN_ALLOW_THREADS
373 rc = sqlite3_finalize(self->st);
374 Py_END_ALLOW_THREADS
375 self->st = NULL;
376 }
377
378 self->in_use = 0;
379
380 return rc;
381}
382
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000383int pysqlite_statement_reset(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000384{
385 int rc;
386
387 rc = SQLITE_OK;
388
389 if (self->in_use && self->st) {
390 Py_BEGIN_ALLOW_THREADS
391 rc = sqlite3_reset(self->st);
392 Py_END_ALLOW_THREADS
393
394 if (rc == SQLITE_OK) {
395 self->in_use = 0;
396 }
397 }
398
399 return rc;
400}
401
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000402void pysqlite_statement_mark_dirty(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000403{
404 self->in_use = 1;
405}
406
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000407void pysqlite_statement_dealloc(pysqlite_Statement* self)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000408{
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000409 if (self->st) {
410 Py_BEGIN_ALLOW_THREADS
Brett Cannonb94767f2011-02-22 20:15:44 +0000411 sqlite3_finalize(self->st);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000412 Py_END_ALLOW_THREADS
413 }
414
415 self->st = NULL;
416
417 Py_XDECREF(self->sql);
418
Thomas Wouters477c8d52006-05-27 19:21:47 +0000419 if (self->in_weakreflist != NULL) {
420 PyObject_ClearWeakRefs((PyObject*)self);
421 }
422
Christian Heimes90aa7642007-12-19 02:45:37 +0000423 Py_TYPE(self)->tp_free((PyObject*)self);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000424}
425
426/*
427 * Checks if there is anything left in an SQL string after SQLite compiled it.
428 * This is used to check if somebody tried to execute more than one SQL command
429 * with one execute()/executemany() command, which the DB-API and we don't
430 * allow.
431 *
432 * Returns 1 if there is more left than should be. 0 if ok.
433 */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000434static int pysqlite_check_remaining_sql(const char* tail)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000435{
436 const char* pos = tail;
437
438 parse_remaining_sql_state state = NORMAL;
439
440 for (;;) {
441 switch (*pos) {
442 case 0:
443 return 0;
444 case '-':
445 if (state == NORMAL) {
446 state = LINECOMMENT_1;
447 } else if (state == LINECOMMENT_1) {
448 state = IN_LINECOMMENT;
449 }
450 break;
451 case ' ':
452 case '\t':
453 break;
454 case '\n':
455 case 13:
456 if (state == IN_LINECOMMENT) {
457 state = NORMAL;
458 }
459 break;
460 case '/':
461 if (state == NORMAL) {
462 state = COMMENTSTART_1;
463 } else if (state == COMMENTEND_1) {
464 state = NORMAL;
465 } else if (state == COMMENTSTART_1) {
466 return 1;
467 }
468 break;
469 case '*':
470 if (state == NORMAL) {
471 return 1;
472 } else if (state == LINECOMMENT_1) {
473 return 1;
474 } else if (state == COMMENTSTART_1) {
475 state = IN_COMMENT;
476 } else if (state == IN_COMMENT) {
477 state = COMMENTEND_1;
478 }
479 break;
480 default:
481 if (state == COMMENTEND_1) {
482 state = IN_COMMENT;
483 } else if (state == IN_LINECOMMENT) {
484 } else if (state == IN_COMMENT) {
485 } else {
486 return 1;
487 }
488 }
489
490 pos++;
491 }
492
493 return 0;
494}
495
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000496PyTypeObject pysqlite_StatementType = {
Martin v. Löwis9f2e3462007-07-21 17:22:18 +0000497 PyVarObject_HEAD_INIT(NULL, 0)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000498 MODULE_NAME ".Statement", /* tp_name */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000499 sizeof(pysqlite_Statement), /* tp_basicsize */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000500 0, /* tp_itemsize */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000501 (destructor)pysqlite_statement_dealloc, /* tp_dealloc */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000502 0, /* tp_print */
503 0, /* tp_getattr */
504 0, /* tp_setattr */
Mark Dickinsone94c6792009-02-02 20:36:42 +0000505 0, /* tp_reserved */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000506 0, /* tp_repr */
507 0, /* tp_as_number */
508 0, /* tp_as_sequence */
509 0, /* tp_as_mapping */
510 0, /* tp_hash */
511 0, /* tp_call */
512 0, /* tp_str */
513 0, /* tp_getattro */
514 0, /* tp_setattro */
515 0, /* tp_as_buffer */
Gerhard Häringe7ea7452008-03-29 00:45:29 +0000516 Py_TPFLAGS_DEFAULT, /* tp_flags */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000517 0, /* tp_doc */
518 0, /* tp_traverse */
519 0, /* tp_clear */
520 0, /* tp_richcompare */
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000521 offsetof(pysqlite_Statement, in_weakreflist), /* tp_weaklistoffset */
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000522 0, /* tp_iter */
523 0, /* tp_iternext */
524 0, /* tp_methods */
525 0, /* tp_members */
526 0, /* tp_getset */
527 0, /* tp_base */
528 0, /* tp_dict */
529 0, /* tp_descr_get */
530 0, /* tp_descr_set */
531 0, /* tp_dictoffset */
532 (initproc)0, /* tp_init */
533 0, /* tp_alloc */
534 0, /* tp_new */
535 0 /* tp_free */
536};
537
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000538extern int pysqlite_statement_setup_types(void)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000539{
Thomas Woutersfc7bb8c2007-01-15 15:49:28 +0000540 pysqlite_StatementType.tp_new = PyType_GenericNew;
541 return PyType_Ready(&pysqlite_StatementType);
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000542}