Mercurial > cpython-lru_cache-weakref
annotate Modules/_sqlite/statement.c @ 37764:96addaa25869 legacy-trunk
Fix valgrind problem with invalid memory read
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Sun, 16 Apr 2006 03:37:19 +0000 |
| parents | d3969aeba777 |
| children | 7da4af95ebad |
| rev | line source |
|---|---|
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
1 /* statement.c - the statement type |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
2 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2005-2006 Gerhard Häring <gh@ghaering.de> |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
4 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
5 * This file is part of pysqlite. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
6 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
7 * This software is provided 'as-is', without any express or implied |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
8 * warranty. In no event will the authors be held liable for any damages |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
9 * arising from the use of this software. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
10 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
11 * Permission is granted to anyone to use this software for any purpose, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
12 * including commercial applications, and to alter it and redistribute it |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
13 * freely, subject to the following restrictions: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
14 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
15 * 1. The origin of this software must not be misrepresented; you must not |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
16 * claim that you wrote the original software. If you use this software |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
17 * in a product, an acknowledgment in the product documentation would be |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
18 * appreciated but is not required. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
19 * 2. Altered source versions must be plainly marked as such, and must not be |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
20 * misrepresented as being the original software. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
21 * 3. This notice may not be removed or altered from any source distribution. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
22 */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
23 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
24 #include "statement.h" |
|
37381
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
25 #include "cursor.h" |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
26 #include "connection.h" |
|
37381
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
27 #include "microprotocols.h" |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
28 #include "prepare_protocol.h" |
|
37458
d27058c409df
Update to pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37387
diff
changeset
|
29 #include "sqlitecompat.h" |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
30 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
31 /* prototypes */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
32 int check_remaining_sql(const char* tail); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
33 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
34 typedef enum { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
35 LINECOMMENT_1, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
36 IN_LINECOMMENT, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
37 COMMENTSTART_1, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
38 IN_COMMENT, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
39 COMMENTEND_1, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
40 NORMAL |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
41 } parse_remaining_sql_state; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
42 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
43 int statement_create(Statement* self, Connection* connection, PyObject* sql) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
44 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
45 const char* tail; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
46 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
47 PyObject* sql_str; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
48 char* sql_cstr; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
49 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
50 self->st = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
51 self->in_use = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
52 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
53 if (PyString_Check(sql)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
54 sql_str = sql; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
55 Py_INCREF(sql_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
56 } else if (PyUnicode_Check(sql)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
57 sql_str = PyUnicode_AsUTF8String(sql); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
58 if (!sql_str) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
59 rc = PYSQLITE_SQL_WRONG_TYPE; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
60 return rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
61 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
62 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
63 rc = PYSQLITE_SQL_WRONG_TYPE; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
64 return rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
65 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
66 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
67 self->sql = sql_str; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
68 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
69 sql_cstr = PyString_AsString(sql_str); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
70 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
71 rc = sqlite3_prepare(connection->db, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
72 sql_cstr, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
73 -1, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
74 &self->st, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
75 &tail); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
76 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
77 self->db = connection->db; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
78 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
79 if (rc == SQLITE_OK && check_remaining_sql(tail)) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
80 (void)sqlite3_finalize(self->st); |
|
37764
96addaa25869
Fix valgrind problem with invalid memory read
Neal Norwitz <nnorwitz@gmail.com>
parents:
37495
diff
changeset
|
81 self->st = NULL; |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
82 rc = PYSQLITE_TOO_MUCH_SQL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
83 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
84 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
85 return rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
86 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
87 |
|
37381
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
88 int statement_bind_parameter(Statement* self, int pos, PyObject* parameter) |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
89 { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
90 int rc = SQLITE_OK; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
91 long longval; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
92 #ifdef HAVE_LONG_LONG |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
93 PY_LONG_LONG longlongval; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
94 #endif |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
95 const char* buffer; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
96 char* string; |
| 37387 | 97 Py_ssize_t buflen; |
|
37381
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
98 PyObject* stringval; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
99 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
100 if (parameter == Py_None) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
101 rc = sqlite3_bind_null(self->st, pos); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
102 } else if (PyInt_Check(parameter)) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
103 longval = PyInt_AsLong(parameter); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
104 rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longval); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
105 #ifdef HAVE_LONG_LONG |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
106 } else if (PyLong_Check(parameter)) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
107 longlongval = PyLong_AsLongLong(parameter); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
108 /* in the overflow error case, longlongval is -1, and an exception is set */ |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
109 rc = sqlite3_bind_int64(self->st, pos, (sqlite_int64)longlongval); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
110 #endif |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
111 } else if (PyFloat_Check(parameter)) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
112 rc = sqlite3_bind_double(self->st, pos, PyFloat_AsDouble(parameter)); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
113 } else if (PyBuffer_Check(parameter)) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
114 if (PyObject_AsCharBuffer(parameter, &buffer, &buflen) == 0) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
115 rc = sqlite3_bind_blob(self->st, pos, buffer, buflen, SQLITE_TRANSIENT); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
116 } else { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
117 PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
118 rc = -1; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
119 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
120 } else if PyString_Check(parameter) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
121 string = PyString_AsString(parameter); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
122 rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
123 } else if PyUnicode_Check(parameter) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
124 stringval = PyUnicode_AsUTF8String(parameter); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
125 string = PyString_AsString(stringval); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
126 rc = sqlite3_bind_text(self->st, pos, string, -1, SQLITE_TRANSIENT); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
127 Py_DECREF(stringval); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
128 } else { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
129 rc = -1; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
130 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
131 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
132 return rc; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
133 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
134 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
135 void statement_bind_parameters(Statement* self, PyObject* parameters) |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
136 { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
137 PyObject* current_param; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
138 PyObject* adapted; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
139 const char* binding_name; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
140 int i; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
141 int rc; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
142 int num_params_needed; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
143 int num_params; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
144 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
145 Py_BEGIN_ALLOW_THREADS |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
146 num_params_needed = sqlite3_bind_parameter_count(self->st); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
147 Py_END_ALLOW_THREADS |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
148 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
149 if (PyDict_Check(parameters)) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
150 /* parameters passed as dictionary */ |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
151 for (i = 1; i <= num_params_needed; i++) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
152 Py_BEGIN_ALLOW_THREADS |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
153 binding_name = sqlite3_bind_parameter_name(self->st, i); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
154 Py_END_ALLOW_THREADS |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
155 if (!binding_name) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
156 PyErr_Format(ProgrammingError, "Binding %d has no name, but you supplied a dictionary (which has only names).", i); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
157 return; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
158 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
159 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
160 binding_name++; /* skip first char (the colon) */ |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
161 current_param = PyDict_GetItemString(parameters, binding_name); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
162 if (!current_param) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
163 PyErr_Format(ProgrammingError, "You did not supply a value for binding %d.", i); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
164 return; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
165 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
166 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
167 Py_INCREF(current_param); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
168 adapted = microprotocols_adapt(current_param, (PyObject*)&SQLitePrepareProtocolType, NULL); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
169 if (adapted) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
170 Py_DECREF(current_param); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
171 } else { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
172 PyErr_Clear(); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
173 adapted = current_param; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
174 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
175 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
176 rc = statement_bind_parameter(self, i, adapted); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
177 Py_DECREF(adapted); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
178 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
179 if (rc != SQLITE_OK) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
180 PyErr_Format(InterfaceError, "Error binding parameter :%s - probably unsupported type.", binding_name); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
181 return; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
182 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
183 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
184 } else { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
185 /* parameters passed as sequence */ |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
186 num_params = PySequence_Length(parameters); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
187 if (num_params != num_params_needed) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
188 PyErr_Format(ProgrammingError, "Incorrect number of bindings supplied. The current statement uses %d, and there are %d supplied.", |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
189 num_params_needed, num_params); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
190 return; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
191 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
192 for (i = 0; i < num_params; i++) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
193 current_param = PySequence_GetItem(parameters, i); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
194 if (!current_param) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
195 return; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
196 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
197 adapted = microprotocols_adapt(current_param, (PyObject*)&SQLitePrepareProtocolType, NULL); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
198 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
199 if (adapted) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
200 Py_DECREF(current_param); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
201 } else { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
202 PyErr_Clear(); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
203 adapted = current_param; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
204 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
205 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
206 rc = statement_bind_parameter(self, i + 1, adapted); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
207 Py_DECREF(adapted); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
208 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
209 if (rc != SQLITE_OK) { |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
210 PyErr_Format(InterfaceError, "Error binding parameter %d - probably unsupported type.", i); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
211 return; |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
212 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
213 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
214 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
215 } |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
216 |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
217 int statement_recompile(Statement* self, PyObject* params) |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
218 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
219 const char* tail; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
220 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
221 char* sql_cstr; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
222 sqlite3_stmt* new_st; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
223 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
224 sql_cstr = PyString_AsString(self->sql); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
225 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
226 rc = sqlite3_prepare(self->db, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
227 sql_cstr, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
228 -1, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
229 &new_st, |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
230 &tail); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
231 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
232 if (rc == SQLITE_OK) { |
|
37381
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
233 /* The efficient sqlite3_transfer_bindings is only available in SQLite |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
234 * version 3.2.2 or later. For older SQLite releases, that might not |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
235 * even define SQLITE_VERSION_NUMBER, we do it the manual way. |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
236 */ |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
237 #ifdef SQLITE_VERSION_NUMBER |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
238 #if SQLITE_VERSION_NUMBER >= 3002002 |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
239 (void)sqlite3_transfer_bindings(self->st, new_st); |
|
37381
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
240 #endif |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
241 #else |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
242 statement_bind_parameters(self, params); |
|
91e9fb5cfe14
backport r243 from the pysqlite2 svn repository - lowers the required version
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37362
diff
changeset
|
243 #endif |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
244 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
245 (void)sqlite3_finalize(self->st); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
246 self->st = new_st; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
247 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
248 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
249 return rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
250 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
251 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
252 int statement_finalize(Statement* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
253 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
254 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
255 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
256 rc = SQLITE_OK; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
257 if (self->st) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
258 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
259 rc = sqlite3_finalize(self->st); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
260 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
261 self->st = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
262 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
263 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
264 self->in_use = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
265 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
266 return rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
267 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
268 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
269 int statement_reset(Statement* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
270 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
271 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
272 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
273 rc = SQLITE_OK; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
274 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
275 if (self->in_use && self->st) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
276 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
277 rc = sqlite3_reset(self->st); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
278 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
279 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
280 if (rc == SQLITE_OK) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
281 self->in_use = 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
282 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
283 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
284 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
285 return rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
286 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
287 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
288 void statement_mark_dirty(Statement* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
289 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
290 self->in_use = 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
291 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
292 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
293 void statement_dealloc(Statement* self) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
294 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
295 int rc; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
296 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
297 if (self->st) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
298 Py_BEGIN_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
299 rc = sqlite3_finalize(self->st); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
300 Py_END_ALLOW_THREADS |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
301 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
302 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
303 self->st = NULL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
304 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
305 Py_XDECREF(self->sql); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
306 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
307 self->ob_type->tp_free((PyObject*)self); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
308 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
309 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
310 /* |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
311 * Checks if there is anything left in an SQL string after SQLite compiled it. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
312 * This is used to check if somebody tried to execute more than one SQL command |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
313 * with one execute()/executemany() command, which the DB-API and we don't |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
314 * allow. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
315 * |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
316 * Returns 1 if there is more left than should be. 0 if ok. |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
317 */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
318 int check_remaining_sql(const char* tail) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
319 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
320 const char* pos = tail; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
321 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
322 parse_remaining_sql_state state = NORMAL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
323 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
324 for (;;) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
325 switch (*pos) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
326 case 0: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
327 return 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
328 case '-': |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
329 if (state == NORMAL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
330 state = LINECOMMENT_1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
331 } else if (state == LINECOMMENT_1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
332 state = IN_LINECOMMENT; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
333 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
334 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
335 case ' ': |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
336 case '\t': |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
337 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
338 case '\n': |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
339 case 13: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
340 if (state == IN_LINECOMMENT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
341 state = NORMAL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
342 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
343 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
344 case '/': |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
345 if (state == NORMAL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
346 state = COMMENTSTART_1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
347 } else if (state == COMMENTEND_1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
348 state = NORMAL; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
349 } else if (state == COMMENTSTART_1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
350 return 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
351 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
352 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
353 case '*': |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
354 if (state == NORMAL) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
355 return 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
356 } else if (state == LINECOMMENT_1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
357 return 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
358 } else if (state == COMMENTSTART_1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
359 state = IN_COMMENT; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
360 } else if (state == IN_COMMENT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
361 state = COMMENTEND_1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
362 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
363 break; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
364 default: |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
365 if (state == COMMENTEND_1) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
366 state = IN_COMMENT; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
367 } else if (state == IN_LINECOMMENT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
368 } else if (state == IN_COMMENT) { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
369 } else { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
370 return 1; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
371 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
372 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
373 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
374 pos++; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
375 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
376 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
377 return 0; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
378 } |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
379 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
380 PyTypeObject StatementType = { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
381 PyObject_HEAD_INIT(NULL) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
382 0, /* ob_size */ |
|
37495
d3969aeba777
upgrade to final version of pysqlite 2.2.0
Anthony Baxter <anthonybaxter@gmail.com>
parents:
37458
diff
changeset
|
383 MODULE_NAME ".Statement", /* tp_name */ |
|
37362
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
384 sizeof(Statement), /* tp_basicsize */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
385 0, /* tp_itemsize */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
386 (destructor)statement_dealloc, /* tp_dealloc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
387 0, /* tp_print */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
388 0, /* tp_getattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
389 0, /* tp_setattr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
390 0, /* tp_compare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
391 0, /* tp_repr */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
392 0, /* tp_as_number */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
393 0, /* tp_as_sequence */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
394 0, /* tp_as_mapping */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
395 0, /* tp_hash */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
396 0, /* tp_call */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
397 0, /* tp_str */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
398 0, /* tp_getattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
399 0, /* tp_setattro */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
400 0, /* tp_as_buffer */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
401 Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
402 0, /* tp_doc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
403 0, /* tp_traverse */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
404 0, /* tp_clear */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
405 0, /* tp_richcompare */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
406 0, /* tp_weaklistoffset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
407 0, /* tp_iter */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
408 0, /* tp_iternext */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
409 0, /* tp_methods */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
410 0, /* tp_members */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
411 0, /* tp_getset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
412 0, /* tp_base */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
413 0, /* tp_dict */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
414 0, /* tp_descr_get */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
415 0, /* tp_descr_set */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
416 0, /* tp_dictoffset */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
417 (initproc)0, /* tp_init */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
418 0, /* tp_alloc */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
419 0, /* tp_new */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
420 0 /* tp_free */ |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
421 }; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
422 |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
423 extern int statement_setup_types(void) |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
424 { |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
425 StatementType.tp_new = PyType_GenericNew; |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
426 return PyType_Ready(&StatementType); |
|
e546274d6503
merged the sqlite-integration branch.
Anthony Baxter <anthonybaxter@gmail.com>
parents:
diff
changeset
|
427 } |
