Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 1 | /* statement.c - the statement type |
| 2 | * |
| 3 | * Copyright (C) 2005-2006 Gerhard Häring <gh@ghaering.de> |
| 4 | * |
| 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" |
| 29 | #include "sqlitecompat.h" |
| 30 | |
| 31 | /* prototypes */ |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 32 | static int pysqlite_check_remaining_sql(const char* tail); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 33 | |
| 34 | typedef enum { |
| 35 | LINECOMMENT_1, |
| 36 | IN_LINECOMMENT, |
| 37 | COMMENTSTART_1, |
| 38 | IN_COMMENT, |
| 39 | COMMENTEND_1, |
| 40 | NORMAL |
| 41 | } parse_remaining_sql_state; |
| 42 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 43 | int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* connection, PyObject* sql) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 44 | { |
| 45 | const char* tail; |
| 46 | int rc; |
Guido van Rossum | 83857e3 | 2007-05-09 23:37:01 +0000 | [diff] [blame] | 47 | const char* sql_cstr; |
| 48 | Py_ssize_t sql_cstr_len; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 49 | |
| 50 | self->st = NULL; |
| 51 | self->in_use = 0; |
| 52 | |
Guido van Rossum | 7d1df6c | 2007-08-29 13:53:23 +0000 | [diff] [blame] | 53 | sql_cstr = PyUnicode_AsStringAndSize(sql, &sql_cstr_len); |
Guido van Rossum | fa9a121 | 2007-08-29 03:34:29 +0000 | [diff] [blame] | 54 | if (sql_cstr == NULL) { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 55 | rc = PYSQLITE_SQL_WRONG_TYPE; |
| 56 | return rc; |
| 57 | } |
| 58 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 59 | self->in_weakreflist = NULL; |
Guido van Rossum | 83857e3 | 2007-05-09 23:37:01 +0000 | [diff] [blame] | 60 | Py_INCREF(sql); |
| 61 | self->sql = sql; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 62 | |
| 63 | rc = sqlite3_prepare(connection->db, |
| 64 | sql_cstr, |
| 65 | -1, |
| 66 | &self->st, |
| 67 | &tail); |
| 68 | |
| 69 | self->db = connection->db; |
| 70 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 71 | if (rc == SQLITE_OK && pysqlite_check_remaining_sql(tail)) { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 72 | (void)sqlite3_finalize(self->st); |
| 73 | self->st = NULL; |
| 74 | rc = PYSQLITE_TOO_MUCH_SQL; |
| 75 | } |
| 76 | |
| 77 | return rc; |
| 78 | } |
| 79 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 80 | int pysqlite_statement_bind_parameter(pysqlite_Statement* self, int pos, PyObject* parameter) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 81 | { |
| 82 | int rc = SQLITE_OK; |
| 83 | long longval; |
| 84 | #ifdef HAVE_LONG_LONG |
| 85 | PY_LONG_LONG longlongval; |
| 86 | #endif |
| 87 | const char* buffer; |
| 88 | char* string; |
| 89 | Py_ssize_t buflen; |
| 90 | PyObject* stringval; |
| 91 | |
| 92 | if (parameter == Py_None) { |
| 93 | rc = sqlite3_bind_null(self->st, pos); |
Guido van Rossum | 523d4f9 | 2007-01-15 00:31:49 +0000 | [diff] [blame] | 94 | } else if (PyInt_CheckExact(parameter)) { |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 95 | longval = PyInt_AsLong(parameter); |
| 96 | rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval); |
| 97 | #ifdef HAVE_LONG_LONG |
| 98 | } else if (PyLong_Check(parameter)) { |
| 99 | longlongval = PyLong_AsLongLong(parameter); |
| 100 | /* in the overflow error case, longlongval is -1, and an exception is set */ |
| 101 | rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval); |
| 102 | #endif |
| 103 | } else if (PyFloat_Check(parameter)) { |
| 104 | rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 105 | } else if PyString_Check(parameter) { |
| 106 | string = PyString_AsString(parameter); |
| 107 | rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); |
| 108 | } else if PyUnicode_Check(parameter) { |
| 109 | stringval = PyUnicode_AsUTF8String(parameter); |
Gerhard Häring | 6d21456 | 2007-08-10 18:15:11 +0000 | [diff] [blame] | 110 | string = PyBytes_AsString(stringval); |
| 111 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 112 | rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); |
| 113 | Py_DECREF(stringval); |
Guido van Rossum | bae07c9 | 2007-10-08 02:46:15 +0000 | [diff] [blame] | 114 | } else if (PyObject_CheckBuffer(parameter)) { |
| 115 | if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) { |
| 116 | rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT); |
| 117 | } else { |
| 118 | PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); |
| 119 | rc = -1; |
| 120 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 121 | } else { |
| 122 | rc = -1; |
| 123 | } |
| 124 | |
| 125 | return rc; |
| 126 | } |
| 127 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 128 | void pysqlite_statement_bind_parameters(pysqlite_Statement* self, PyObject* parameters) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 129 | { |
| 130 | PyObject* current_param; |
| 131 | PyObject* adapted; |
| 132 | const char* binding_name; |
| 133 | int i; |
| 134 | int rc; |
| 135 | int num_params_needed; |
| 136 | int num_params; |
| 137 | |
| 138 | Py_BEGIN_ALLOW_THREADS |
| 139 | num_params_needed = sqlite3_bind_parameter_count(self->st); |
| 140 | Py_END_ALLOW_THREADS |
| 141 | |
| 142 | if (PyDict_Check(parameters)) { |
| 143 | /* parameters passed as dictionary */ |
| 144 | for (i = 1; i <= num_params_needed; i++) { |
| 145 | Py_BEGIN_ALLOW_THREADS |
| 146 | binding_name = sqlite3_bind_parameter_name(self->st, i); |
| 147 | Py_END_ALLOW_THREADS |
| 148 | if (!binding_name) { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 149 | PyErr_Format(pysqlite_ProgrammingError, "Binding %d has no name, but you supplied a dictionary (which has only names).", i); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 150 | return; |
| 151 | } |
| 152 | |
| 153 | binding_name++; /* skip first char (the colon) */ |
| 154 | current_param = PyDict_GetItemString(parameters, binding_name); |
| 155 | if (!current_param) { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 156 | PyErr_Format(pysqlite_ProgrammingError, "You did not supply a value for binding %d.", i); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 157 | return; |
| 158 | } |
| 159 | |
| 160 | Py_INCREF(current_param); |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 161 | adapted = microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 162 | if (adapted) { |
| 163 | Py_DECREF(current_param); |
| 164 | } else { |
| 165 | PyErr_Clear(); |
| 166 | adapted = current_param; |
| 167 | } |
| 168 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 169 | rc = pysqlite_statement_bind_parameter(self, i, adapted); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 170 | Py_DECREF(adapted); |
| 171 | |
| 172 | if (rc != SQLITE_OK) { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 173 | PyErr_Format(pysqlite_InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 174 | return; |
| 175 | } |
| 176 | } |
| 177 | } else { |
| 178 | /* parameters passed as sequence */ |
| 179 | num_params = PySequence_Length(parameters); |
| 180 | if (num_params != num_params_needed) { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 181 | PyErr_Format(pysqlite_ProgrammingError, "Incorrect number of bindings supplied. The current statement uses %d, and there are %d supplied.", |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 182 | num_params_needed, num_params); |
| 183 | return; |
| 184 | } |
| 185 | for (i = 0; i < num_params; i++) { |
| 186 | current_param = PySequence_GetItem(parameters, i); |
| 187 | if (!current_param) { |
| 188 | return; |
| 189 | } |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 190 | adapted = microprotocols_adapt(current_param, (PyObject*)&pysqlite_PrepareProtocolType, NULL); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 191 | |
| 192 | if (adapted) { |
| 193 | Py_DECREF(current_param); |
| 194 | } else { |
| 195 | PyErr_Clear(); |
| 196 | adapted = current_param; |
| 197 | } |
| 198 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 199 | rc = pysqlite_statement_bind_parameter(self, i + 1, adapted); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 200 | Py_DECREF(adapted); |
| 201 | |
| 202 | if (rc != SQLITE_OK) { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 203 | PyErr_Format(pysqlite_InterfaceError, "Error binding parameter %d - probably unsupported type.", i); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 204 | return; |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | } |
| 209 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 210 | int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 211 | { |
| 212 | const char* tail; |
| 213 | int rc; |
Guido van Rossum | 83857e3 | 2007-05-09 23:37:01 +0000 | [diff] [blame] | 214 | const char* sql_cstr; |
| 215 | Py_ssize_t sql_len; |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 216 | sqlite3_stmt* new_st; |
| 217 | |
Guido van Rossum | 7d1df6c | 2007-08-29 13:53:23 +0000 | [diff] [blame] | 218 | sql_cstr = PyUnicode_AsStringAndSize(self->sql, &sql_len); |
Guido van Rossum | fa9a121 | 2007-08-29 03:34:29 +0000 | [diff] [blame] | 219 | if (sql_cstr == NULL) { |
Guido van Rossum | 83857e3 | 2007-05-09 23:37:01 +0000 | [diff] [blame] | 220 | rc = PYSQLITE_SQL_WRONG_TYPE; |
| 221 | return rc; |
| 222 | } |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 223 | |
| 224 | rc = sqlite3_prepare(self->db, |
| 225 | sql_cstr, |
| 226 | -1, |
| 227 | &new_st, |
| 228 | &tail); |
| 229 | |
| 230 | if (rc == SQLITE_OK) { |
| 231 | /* The efficient sqlite3_transfer_bindings is only available in SQLite |
| 232 | * version 3.2.2 or later. For older SQLite releases, that might not |
| 233 | * even define SQLITE_VERSION_NUMBER, we do it the manual way. |
| 234 | */ |
| 235 | #ifdef SQLITE_VERSION_NUMBER |
| 236 | #if SQLITE_VERSION_NUMBER >= 3002002 |
| 237 | (void)sqlite3_transfer_bindings(self->st, new_st); |
| 238 | #endif |
| 239 | #else |
| 240 | statement_bind_parameters(self, params); |
| 241 | #endif |
| 242 | |
| 243 | (void)sqlite3_finalize(self->st); |
| 244 | self->st = new_st; |
| 245 | } |
| 246 | |
| 247 | return rc; |
| 248 | } |
| 249 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 250 | int pysqlite_statement_finalize(pysqlite_Statement* self) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 251 | { |
| 252 | int rc; |
| 253 | |
| 254 | rc = SQLITE_OK; |
| 255 | if (self->st) { |
| 256 | Py_BEGIN_ALLOW_THREADS |
| 257 | rc = sqlite3_finalize(self->st); |
| 258 | Py_END_ALLOW_THREADS |
| 259 | self->st = NULL; |
| 260 | } |
| 261 | |
| 262 | self->in_use = 0; |
| 263 | |
| 264 | return rc; |
| 265 | } |
| 266 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 267 | int pysqlite_statement_reset(pysqlite_Statement* self) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 268 | { |
| 269 | int rc; |
| 270 | |
| 271 | rc = SQLITE_OK; |
| 272 | |
| 273 | if (self->in_use && self->st) { |
| 274 | Py_BEGIN_ALLOW_THREADS |
| 275 | rc = sqlite3_reset(self->st); |
| 276 | Py_END_ALLOW_THREADS |
| 277 | |
| 278 | if (rc == SQLITE_OK) { |
| 279 | self->in_use = 0; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | return rc; |
| 284 | } |
| 285 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 286 | void pysqlite_statement_mark_dirty(pysqlite_Statement* self) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 287 | { |
| 288 | self->in_use = 1; |
| 289 | } |
| 290 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 291 | void pysqlite_statement_dealloc(pysqlite_Statement* self) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 292 | { |
| 293 | int rc; |
| 294 | |
| 295 | if (self->st) { |
| 296 | Py_BEGIN_ALLOW_THREADS |
| 297 | rc = sqlite3_finalize(self->st); |
| 298 | Py_END_ALLOW_THREADS |
| 299 | } |
| 300 | |
| 301 | self->st = NULL; |
| 302 | |
| 303 | Py_XDECREF(self->sql); |
| 304 | |
Thomas Wouters | 477c8d5 | 2006-05-27 19:21:47 +0000 | [diff] [blame] | 305 | if (self->in_weakreflist != NULL) { |
| 306 | PyObject_ClearWeakRefs((PyObject*)self); |
| 307 | } |
| 308 | |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 309 | Py_Type(self)->tp_free((PyObject*)self); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | /* |
| 313 | * Checks if there is anything left in an SQL string after SQLite compiled it. |
| 314 | * This is used to check if somebody tried to execute more than one SQL command |
| 315 | * with one execute()/executemany() command, which the DB-API and we don't |
| 316 | * allow. |
| 317 | * |
| 318 | * Returns 1 if there is more left than should be. 0 if ok. |
| 319 | */ |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 320 | static int pysqlite_check_remaining_sql(const char* tail) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 321 | { |
| 322 | const char* pos = tail; |
| 323 | |
| 324 | parse_remaining_sql_state state = NORMAL; |
| 325 | |
| 326 | for (;;) { |
| 327 | switch (*pos) { |
| 328 | case 0: |
| 329 | return 0; |
| 330 | case '-': |
| 331 | if (state == NORMAL) { |
| 332 | state = LINECOMMENT_1; |
| 333 | } else if (state == LINECOMMENT_1) { |
| 334 | state = IN_LINECOMMENT; |
| 335 | } |
| 336 | break; |
| 337 | case ' ': |
| 338 | case '\t': |
| 339 | break; |
| 340 | case '\n': |
| 341 | case 13: |
| 342 | if (state == IN_LINECOMMENT) { |
| 343 | state = NORMAL; |
| 344 | } |
| 345 | break; |
| 346 | case '/': |
| 347 | if (state == NORMAL) { |
| 348 | state = COMMENTSTART_1; |
| 349 | } else if (state == COMMENTEND_1) { |
| 350 | state = NORMAL; |
| 351 | } else if (state == COMMENTSTART_1) { |
| 352 | return 1; |
| 353 | } |
| 354 | break; |
| 355 | case '*': |
| 356 | if (state == NORMAL) { |
| 357 | return 1; |
| 358 | } else if (state == LINECOMMENT_1) { |
| 359 | return 1; |
| 360 | } else if (state == COMMENTSTART_1) { |
| 361 | state = IN_COMMENT; |
| 362 | } else if (state == IN_COMMENT) { |
| 363 | state = COMMENTEND_1; |
| 364 | } |
| 365 | break; |
| 366 | default: |
| 367 | if (state == COMMENTEND_1) { |
| 368 | state = IN_COMMENT; |
| 369 | } else if (state == IN_LINECOMMENT) { |
| 370 | } else if (state == IN_COMMENT) { |
| 371 | } else { |
| 372 | return 1; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | pos++; |
| 377 | } |
| 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 382 | PyTypeObject pysqlite_StatementType = { |
Martin v. Löwis | 9f2e346 | 2007-07-21 17:22:18 +0000 | [diff] [blame] | 383 | PyVarObject_HEAD_INIT(NULL, 0) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 384 | MODULE_NAME ".Statement", /* tp_name */ |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 385 | sizeof(pysqlite_Statement), /* tp_basicsize */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 386 | 0, /* tp_itemsize */ |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 387 | (destructor)pysqlite_statement_dealloc, /* tp_dealloc */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 388 | 0, /* tp_print */ |
| 389 | 0, /* tp_getattr */ |
| 390 | 0, /* tp_setattr */ |
| 391 | 0, /* tp_compare */ |
| 392 | 0, /* tp_repr */ |
| 393 | 0, /* tp_as_number */ |
| 394 | 0, /* tp_as_sequence */ |
| 395 | 0, /* tp_as_mapping */ |
| 396 | 0, /* tp_hash */ |
| 397 | 0, /* tp_call */ |
| 398 | 0, /* tp_str */ |
| 399 | 0, /* tp_getattro */ |
| 400 | 0, /* tp_setattro */ |
| 401 | 0, /* tp_as_buffer */ |
Guido van Rossum | 3cf5b1e | 2006-07-27 21:53:35 +0000 | [diff] [blame] | 402 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 403 | 0, /* tp_doc */ |
| 404 | 0, /* tp_traverse */ |
| 405 | 0, /* tp_clear */ |
| 406 | 0, /* tp_richcompare */ |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 407 | offsetof(pysqlite_Statement, in_weakreflist), /* tp_weaklistoffset */ |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 408 | 0, /* tp_iter */ |
| 409 | 0, /* tp_iternext */ |
| 410 | 0, /* tp_methods */ |
| 411 | 0, /* tp_members */ |
| 412 | 0, /* tp_getset */ |
| 413 | 0, /* tp_base */ |
| 414 | 0, /* tp_dict */ |
| 415 | 0, /* tp_descr_get */ |
| 416 | 0, /* tp_descr_set */ |
| 417 | 0, /* tp_dictoffset */ |
| 418 | (initproc)0, /* tp_init */ |
| 419 | 0, /* tp_alloc */ |
| 420 | 0, /* tp_new */ |
| 421 | 0 /* tp_free */ |
| 422 | }; |
| 423 | |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 424 | extern int pysqlite_statement_setup_types(void) |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 425 | { |
Thomas Wouters | fc7bb8c | 2007-01-15 15:49:28 +0000 | [diff] [blame] | 426 | pysqlite_StatementType.tp_new = PyType_GenericNew; |
| 427 | return PyType_Ready(&pysqlite_StatementType); |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 428 | } |