Mercurial > p > mysql-python > mysqldb-2
annotate src/results.c @ 74:80164eb2f090 MySQLdb
This passes all test, yet is still broken and ugly in many ways.
However, a lot of ugliness has been removed.
author | adustman |
---|---|
date | Sat, 20 Feb 2010 04:27:21 +0000 |
parents | 24fa6a40c706 |
children | 3b03cb566032 |
rev | line source |
---|---|
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
1 /* -*- mode: C; indent-tabs-mode: t; c-basic-offset: 8; -*- */ |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
2 |
55
e606fd52e866
make things a little cleaner by moving to a src directory for the C code
kylev
parents:
53
diff
changeset
|
3 #include "mysqlmod.h" |
0 | 4 |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
5 static PyObject * |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
6 _mysql_ResultObject_get_fields( |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
7 _mysql_ResultObject *self, |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
8 PyObject *unused) |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
9 { |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
10 PyObject *arglist=NULL, *kwarglist=NULL; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
11 PyObject *fields=NULL; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
12 _mysql_FieldObject *field=NULL; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
13 unsigned int i, n; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
14 |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
15 check_result_connection(self); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
16 kwarglist = PyDict_New(); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
17 if (!kwarglist) goto error; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
18 n = mysql_num_fields(self->result); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
19 if (!(fields = PyTuple_New(n))) return NULL; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
20 for (i=0; i<n; i++) { |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
21 arglist = Py_BuildValue("(Oi)", self, i); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
22 if (!arglist) goto error; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
23 field = MyAlloc(_mysql_FieldObject, _mysql_FieldObject_Type); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
24 if (!field) goto error; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
25 if (_mysql_FieldObject_Initialize(field, arglist, kwarglist)) |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
26 goto error; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
27 Py_DECREF(arglist); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
28 PyTuple_SET_ITEM(fields, i, (PyObject *) field); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
29 } |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
30 Py_DECREF(kwarglist); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
31 return fields; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
32 error: |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
33 Py_XDECREF(arglist); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
34 Py_XDECREF(kwarglist); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
35 Py_XDECREF(fields); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
36 return NULL; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
37 } |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
38 |
0 | 39 static char _mysql_ResultObject__doc__[] = |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
40 "result(connection, use=0, decoder_stack=[]) -- Result set from a query.\n\ |
0 | 41 \n\ |
42 Creating instances of this class directly is an excellent way to\n\ | |
43 shoot yourself in the foot. If using _mysql.connection directly,\n\ | |
44 use connection.store_result() or connection.use_result() instead.\n\ | |
45 If using MySQLdb.Connection, this is done by the cursor class.\n\ | |
46 Just forget you ever saw this. Forget... FOR-GET..."; | |
47 | |
2
c0d1fc0429ce
Smashed _mysql.c with a great big hammer and got some smaller,
adustman
parents:
1
diff
changeset
|
48 int |
0 | 49 _mysql_ResultObject_Initialize( |
50 _mysql_ResultObject *self, | |
51 PyObject *args, | |
52 PyObject *kwargs) | |
53 { | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
54 static char *kwlist[] = {"connection", "use", "decoder_stack", NULL}; |
45 | 55 MYSQL_RES *result; |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
56 _mysql_ConnectionObject *conn = NULL; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
57 int use = 0; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
58 PyObject *decoder_stack = NULL; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
59 int n, ns, i, j; |
0 | 60 |
61 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|iO", kwlist, | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
62 &conn, &use, &decoder_stack)) |
0 | 63 return -1; |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
64 if (!decoder_stack) decoder_stack = PyList_New(0); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
65 if (!decoder_stack) return -1; |
0 | 66 self->conn = (PyObject *) conn; |
67 Py_INCREF(conn); | |
68 self->use = use; | |
69 Py_BEGIN_ALLOW_THREADS ; | |
70 if (use) | |
71 result = mysql_use_result(&(conn->connection)); | |
72 else | |
73 result = mysql_store_result(&(conn->connection)); | |
74 self->result = result; | |
75 Py_END_ALLOW_THREADS ; | |
76 if (!result) { | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
77 self->decoders = PyTuple_New(0); |
0 | 78 return 0; |
79 } | |
80 n = mysql_num_fields(result); | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
81 ns = PySequence_Length(decoder_stack); |
0 | 82 self->nfields = n; |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
83 if (!(self->decoders = PyTuple_New(n))) return -1; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
84 self->fields = _mysql_ResultObject_get_fields(self, NULL); |
0 | 85 for (i=0; i<n; i++) { |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
86 PyObject *field = PyTuple_GET_ITEM(self->fields, i); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
87 for (j=0; j<ns; j++) { |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
88 PyObject *df = PySequence_GetItem(decoder_stack, j); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
89 if (!df) goto error; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
90 PyObject *f = PyObject_CallFunctionObjArgs(df, field, NULL); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
91 Py_DECREF(df); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
92 if (!f) goto error; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
93 if (f != Py_None) { |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
94 PyTuple_SET_ITEM(self->decoders, i, f); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
95 break; |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
96 } |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
97 Py_DECREF(f); |
0 | 98 } |
99 } | |
100 return 0; | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
101 error: |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
102 return -1; |
0 | 103 } |
104 | |
45 | 105 static int |
106 _mysql_ResultObject_traverse( | |
0 | 107 _mysql_ResultObject *self, |
108 visitproc visit, | |
109 void *arg) | |
110 { | |
111 int r; | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
112 if (self->decoders) { |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
113 if (!(r = visit(self->decoders, arg))) return r; |
0 | 114 } |
115 if (self->conn) | |
116 return visit(self->conn, arg); | |
117 return 0; | |
118 } | |
119 | |
45 | 120 static int |
121 _mysql_ResultObject_clear( | |
0 | 122 _mysql_ResultObject *self) |
123 { | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
124 Py_XDECREF(self->decoders); |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
125 self->decoders = NULL; |
0 | 126 Py_XDECREF(self->conn); |
127 self->conn = NULL; | |
128 return 0; | |
129 } | |
26 | 130 |
0 | 131 static char _mysql_ResultObject_describe__doc__[] = |
132 "Returns the sequence of 7-tuples required by the DB-API for\n\ | |
133 the Cursor.description attribute.\n\ | |
134 "; | |
135 | |
136 static PyObject * | |
137 _mysql_ResultObject_describe( | |
138 _mysql_ResultObject *self, | |
26 | 139 PyObject *unused) |
0 | 140 { |
141 PyObject *d; | |
142 MYSQL_FIELD *fields; | |
143 unsigned int i, n; | |
26 | 144 |
0 | 145 check_result_connection(self); |
146 n = mysql_num_fields(self->result); | |
147 fields = mysql_fetch_fields(self->result); | |
148 if (!(d = PyTuple_New(n))) return NULL; | |
149 for (i=0; i<n; i++) { | |
150 PyObject *t; | |
151 t = Py_BuildValue("(siiiiii)", | |
152 fields[i].name, | |
153 (long) fields[i].type, | |
154 (long) fields[i].max_length, | |
155 (long) fields[i].length, | |
156 (long) fields[i].length, | |
157 (long) fields[i].decimals, | |
158 (long) !(IS_NOT_NULL(fields[i].flags))); | |
159 if (!t) goto error; | |
160 PyTuple_SET_ITEM(d, i, t); | |
161 } | |
162 return d; | |
163 error: | |
164 Py_XDECREF(d); | |
165 return NULL; | |
166 } | |
18
d55bfb1a4701
Tons of changes from major refactoring/cleanup. This is all really broken
adustman
parents:
2
diff
changeset
|
167 |
0 | 168 static char _mysql_ResultObject_field_flags__doc__[] = |
169 "Returns a tuple of field flags, one for each column in the result.\n\ | |
170 " ; | |
171 | |
172 static PyObject * | |
173 _mysql_ResultObject_field_flags( | |
174 _mysql_ResultObject *self, | |
26 | 175 PyObject *unused) |
0 | 176 { |
177 PyObject *d; | |
178 MYSQL_FIELD *fields; | |
179 unsigned int i, n; | |
26 | 180 |
0 | 181 check_result_connection(self); |
182 n = mysql_num_fields(self->result); | |
183 fields = mysql_fetch_fields(self->result); | |
184 if (!(d = PyTuple_New(n))) return NULL; | |
185 for (i=0; i<n; i++) { | |
186 PyObject *f; | |
187 if (!(f = PyInt_FromLong((long)fields[i].flags))) goto error; | |
188 PyTuple_SET_ITEM(d, i, f); | |
189 } | |
190 return d; | |
191 error: | |
192 Py_XDECREF(d); | |
193 return NULL; | |
194 } | |
195 | |
196 static PyObject * | |
197 _mysql_field_to_python( | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
198 PyObject *decoder, |
0 | 199 char *rowitem, |
200 unsigned long length) | |
201 { | |
202 PyObject *v; | |
203 if (rowitem) { | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
204 if (decoder != Py_None) |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
205 v = PyObject_CallFunction(decoder, |
0 | 206 "s#", |
207 rowitem, | |
208 (int)length); | |
209 else | |
210 v = PyString_FromStringAndSize(rowitem, | |
211 (int)length); | |
212 if (!v) | |
213 return NULL; | |
214 } else { | |
215 Py_INCREF(Py_None); | |
216 v = Py_None; | |
217 } | |
218 return v; | |
219 } | |
220 | |
221 static PyObject * | |
222 _mysql_row_to_tuple( | |
223 _mysql_ResultObject *self, | |
224 MYSQL_ROW row) | |
225 { | |
226 unsigned int n, i; | |
227 unsigned long *length; | |
228 PyObject *r, *c; | |
229 | |
230 n = mysql_num_fields(self->result); | |
231 if (!(r = PyTuple_New(n))) return NULL; | |
232 length = mysql_fetch_lengths(self->result); | |
233 for (i=0; i<n; i++) { | |
234 PyObject *v; | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
235 c = PyTuple_GET_ITEM(self->decoders, i); |
0 | 236 v = _mysql_field_to_python(c, row[i], length[i]); |
237 if (!v) goto error; | |
238 PyTuple_SET_ITEM(r, i, v); | |
239 } | |
240 return r; | |
241 error: | |
242 Py_XDECREF(r); | |
243 return NULL; | |
244 } | |
245 | |
246 static PyObject * | |
247 _mysql_row_to_dict( | |
248 _mysql_ResultObject *self, | |
249 MYSQL_ROW row) | |
250 { | |
251 unsigned int n, i; | |
252 unsigned long *length; | |
253 PyObject *r, *c; | |
254 MYSQL_FIELD *fields; | |
255 | |
256 n = mysql_num_fields(self->result); | |
257 if (!(r = PyDict_New())) return NULL; | |
258 length = mysql_fetch_lengths(self->result); | |
259 fields = mysql_fetch_fields(self->result); | |
260 for (i=0; i<n; i++) { | |
261 PyObject *v; | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
262 c = PyTuple_GET_ITEM(self->decoders, i); |
0 | 263 v = _mysql_field_to_python(c, row[i], length[i]); |
264 if (!v) goto error; | |
265 if (!PyMapping_HasKeyString(r, fields[i].name)) { | |
266 PyMapping_SetItemString(r, fields[i].name, v); | |
267 } else { | |
268 int len; | |
269 char buf[256]; | |
270 strncpy(buf, fields[i].table, 256); | |
271 len = strlen(buf); | |
272 strncat(buf, ".", 256-len); | |
273 len = strlen(buf); | |
274 strncat(buf, fields[i].name, 256-len); | |
275 PyMapping_SetItemString(r, buf, v); | |
276 } | |
277 Py_DECREF(v); | |
278 } | |
279 return r; | |
280 error: | |
281 Py_XDECREF(r); | |
282 return NULL; | |
283 } | |
284 | |
285 static PyObject * | |
286 _mysql_row_to_dict_old( | |
287 _mysql_ResultObject *self, | |
288 MYSQL_ROW row) | |
289 { | |
290 unsigned int n, i; | |
291 unsigned long *length; | |
292 PyObject *r, *c; | |
293 MYSQL_FIELD *fields; | |
294 | |
295 n = mysql_num_fields(self->result); | |
296 if (!(r = PyDict_New())) return NULL; | |
297 length = mysql_fetch_lengths(self->result); | |
298 fields = mysql_fetch_fields(self->result); | |
299 for (i=0; i<n; i++) { | |
300 PyObject *v; | |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
301 c = PyTuple_GET_ITEM(self->decoders, i); |
0 | 302 v = _mysql_field_to_python(c, row[i], length[i]); |
303 if (!v) goto error; | |
304 { | |
305 int len=0; | |
306 char buf[256]=""; | |
307 if (strlen(fields[i].table)) { | |
308 strncpy(buf, fields[i].table, 256); | |
309 len = strlen(buf); | |
310 strncat(buf, ".", 256-len); | |
311 len = strlen(buf); | |
312 } | |
313 strncat(buf, fields[i].name, 256-len); | |
314 PyMapping_SetItemString(r, buf, v); | |
315 } | |
316 Py_DECREF(v); | |
317 } | |
318 return r; | |
319 error: | |
320 Py_XDECREF(r); | |
321 return NULL; | |
322 } | |
323 | |
324 typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_ROW); | |
325 | |
326 int | |
327 _mysql__fetch_row( | |
328 _mysql_ResultObject *self, | |
329 PyObject **r, | |
330 int skiprows, | |
331 int maxrows, | |
332 _PYFUNC *convert_row) | |
333 { | |
334 unsigned int i; | |
335 MYSQL_ROW row; | |
336 | |
337 for (i = skiprows; i<(skiprows+maxrows); i++) { | |
338 PyObject *v; | |
339 if (!self->use) | |
340 row = mysql_fetch_row(self->result); | |
341 else { | |
342 Py_BEGIN_ALLOW_THREADS; | |
343 row = mysql_fetch_row(self->result); | |
344 Py_END_ALLOW_THREADS; | |
345 } | |
346 if (!row && mysql_errno(&(((_mysql_ConnectionObject *)(self->conn))->connection))) { | |
347 _mysql_Exception((_mysql_ConnectionObject *)self->conn); | |
348 goto error; | |
349 } | |
350 if (!row) { | |
44
2b9a9814daab
_PyTuple_Resize is stable since 2.2, so we don't need the macro MyTuple_Resize
kylev
parents:
42
diff
changeset
|
351 if (_PyTuple_Resize(r, i) == -1) goto error; |
0 | 352 break; |
353 } | |
354 v = convert_row(self, row); | |
355 if (!v) goto error; | |
356 PyTuple_SET_ITEM(*r, i, v); | |
357 } | |
358 return i-skiprows; | |
359 error: | |
360 return -1; | |
361 } | |
362 | |
363 static char _mysql_ResultObject_fetch_row__doc__[] = | |
364 "fetch_row([maxrows, how]) -- Fetches up to maxrows as a tuple.\n\ | |
365 The rows are formatted according to how:\n\ | |
366 \n\ | |
367 0 -- tuples (default)\n\ | |
368 1 -- dictionaries, key=column or table.column if duplicated\n\ | |
369 2 -- dictionaries, key=table.column\n\ | |
370 "; | |
371 | |
372 static PyObject * | |
373 _mysql_ResultObject_fetch_row( | |
374 _mysql_ResultObject *self, | |
375 PyObject *args, | |
376 PyObject *kwargs) | |
377 { | |
378 typedef PyObject *_PYFUNC(_mysql_ResultObject *, MYSQL_ROW); | |
379 static char *kwlist[] = { "maxrows", "how", NULL }; | |
380 static _PYFUNC *row_converters[] = | |
381 { | |
382 _mysql_row_to_tuple, | |
383 _mysql_row_to_dict, | |
384 _mysql_row_to_dict_old | |
385 }; | |
386 _PYFUNC *convert_row; | |
387 unsigned int maxrows=1, how=0, skiprows=0, rowsadded; | |
388 PyObject *r=NULL; | |
389 | |
390 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ii:fetch_row", kwlist, | |
391 &maxrows, &how)) | |
392 return NULL; | |
393 check_result_connection(self); | |
394 if (how < 0 || how >= sizeof(row_converters)) { | |
395 PyErr_SetString(PyExc_ValueError, "how out of range"); | |
396 return NULL; | |
397 } | |
398 convert_row = row_converters[how]; | |
399 if (maxrows) { | |
400 if (!(r = PyTuple_New(maxrows))) goto error; | |
44
2b9a9814daab
_PyTuple_Resize is stable since 2.2, so we don't need the macro MyTuple_Resize
kylev
parents:
42
diff
changeset
|
401 rowsadded = _mysql__fetch_row(self, &r, skiprows, maxrows, |
0 | 402 convert_row); |
403 if (rowsadded == -1) goto error; | |
404 } else { | |
405 if (self->use) { | |
406 maxrows = 1000; | |
407 if (!(r = PyTuple_New(maxrows))) goto error; | |
408 while (1) { | |
409 rowsadded = _mysql__fetch_row(self, &r, skiprows, | |
410 maxrows, convert_row); | |
411 if (rowsadded == -1) goto error; | |
412 skiprows += rowsadded; | |
413 if (rowsadded < maxrows) break; | |
44
2b9a9814daab
_PyTuple_Resize is stable since 2.2, so we don't need the macro MyTuple_Resize
kylev
parents:
42
diff
changeset
|
414 if (_PyTuple_Resize(&r, skiprows + maxrows) == -1) |
0 | 415 goto error; |
416 } | |
417 } else { | |
418 /* XXX if overflow, maxrows<0? */ | |
419 maxrows = (int) mysql_num_rows(self->result); | |
420 if (!(r = PyTuple_New(maxrows))) goto error; | |
421 rowsadded = _mysql__fetch_row(self, &r, 0, | |
422 maxrows, convert_row); | |
423 if (rowsadded == -1) goto error; | |
424 } | |
425 } | |
426 return r; | |
427 error: | |
428 Py_XDECREF(r); | |
429 return NULL; | |
430 } | |
431 | |
73
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
432 static char _mysql_ResultObject_simple_fetch_row__doc__[] = |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
433 "simple_fetchrow()\n\ |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
434 Fetches one row as a tuple of strings.\n\ |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
435 NULL is returned as None.\n\ |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
436 "; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
437 |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
438 static PyObject * |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
439 _mysql_ResultObject_simple_fetch_row( |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
440 _mysql_ResultObject *self, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
441 PyObject *unused) |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
442 { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
443 unsigned int n, i; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
444 unsigned long *length; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
445 PyObject *r=NULL; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
446 MYSQL_ROW row; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
447 |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
448 check_result_connection(self); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
449 |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
450 if (!self->use) |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
451 row = mysql_fetch_row(self->result); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
452 else { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
453 Py_BEGIN_ALLOW_THREADS; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
454 row = mysql_fetch_row(self->result); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
455 Py_END_ALLOW_THREADS; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
456 } |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
457 if (!row && mysql_errno(&(((_mysql_ConnectionObject *)(self->conn))->connection))) { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
458 _mysql_Exception((_mysql_ConnectionObject *)self->conn); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
459 goto error; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
460 } |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
461 if (!row) { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
462 Py_INCREF(Py_None); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
463 return Py_None; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
464 } |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
465 |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
466 n = mysql_num_fields(self->result); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
467 if (!(r = PyTuple_New(n))) return NULL; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
468 length = mysql_fetch_lengths(self->result); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
469 for (i=0; i<n; i++) { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
470 PyObject *v; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
471 if (row[i]) { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
472 v = PyString_FromStringAndSize(row[i], length[i]); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
473 if (!v) goto error; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
474 } else /* NULL */ { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
475 v = Py_None; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
476 Py_INCREF(v); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
477 } |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
478 PyTuple_SET_ITEM(r, i, v); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
479 } |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
480 return r; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
481 error: |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
482 Py_XDECREF(r); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
483 return NULL; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
484 } |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
485 |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
486 static PyObject * |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
487 _mysql_ResultObject__iter__( |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
488 _mysql_ResultObject *self, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
489 PyObject *unused) |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
490 { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
491 check_result_connection(self); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
492 Py_INCREF(self); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
493 return (PyObject *)self; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
494 } |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
495 |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
496 static PyObject * |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
497 _mysql_ResultObject_next( |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
498 _mysql_ResultObject *self, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
499 PyObject *unused) |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
500 { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
501 PyObject *row; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
502 check_result_connection(self); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
503 row = _mysql_ResultObject_simple_fetch_row(self, NULL); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
504 if (row == Py_None) { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
505 Py_DECREF(row); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
506 PyErr_SetString(PyExc_StopIteration, ""); |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
507 return NULL; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
508 } |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
509 return row; |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
510 } |
0 | 511 |
512 static char _mysql_ResultObject_num_fields__doc__[] = | |
513 "Returns the number of fields (column) in the result." ; | |
514 | |
515 static PyObject * | |
516 _mysql_ResultObject_num_fields( | |
517 _mysql_ResultObject *self, | |
26 | 518 PyObject *unused) |
0 | 519 { |
520 check_result_connection(self); | |
521 return PyInt_FromLong((long)mysql_num_fields(self->result)); | |
26 | 522 } |
0 | 523 |
524 static char _mysql_ResultObject_num_rows__doc__[] = | |
525 "Returns the number of rows in the result set. Note that if\n\ | |
526 use=1, this will not return a valid value until the entire result\n\ | |
527 set has been read.\n\ | |
528 "; | |
529 | |
530 static PyObject * | |
531 _mysql_ResultObject_num_rows( | |
532 _mysql_ResultObject *self, | |
26 | 533 PyObject *unused) |
0 | 534 { |
535 check_result_connection(self); | |
536 return PyLong_FromUnsignedLongLong(mysql_num_rows(self->result)); | |
26 | 537 } |
0 | 538 |
539 | |
540 static char _mysql_ResultObject_data_seek__doc__[] = | |
541 "data_seek(n) -- seek to row n of result set"; | |
542 static PyObject * | |
543 _mysql_ResultObject_data_seek( | |
544 _mysql_ResultObject *self, | |
545 PyObject *args) | |
546 { | |
547 unsigned int row; | |
548 if (!PyArg_ParseTuple(args, "i:data_seek", &row)) return NULL; | |
549 check_result_connection(self); | |
550 mysql_data_seek(self->result, row); | |
551 Py_INCREF(Py_None); | |
552 return Py_None; | |
553 } | |
554 | |
555 static char _mysql_ResultObject_row_seek__doc__[] = | |
556 "row_seek(n) -- seek by offset n rows of result set"; | |
557 static PyObject * | |
558 _mysql_ResultObject_row_seek( | |
559 _mysql_ResultObject *self, | |
560 PyObject *args) | |
561 { | |
562 int offset; | |
563 MYSQL_ROW_OFFSET r; | |
564 if (!PyArg_ParseTuple(args, "i:row_seek", &offset)) return NULL; | |
565 check_result_connection(self); | |
566 if (self->use) { | |
567 PyErr_SetString(_mysql_ProgrammingError, | |
568 "cannot be used with connection.use_result()"); | |
569 return NULL; | |
570 } | |
571 r = mysql_row_tell(self->result); | |
572 mysql_row_seek(self->result, r+offset); | |
573 Py_INCREF(Py_None); | |
574 return Py_None; | |
575 } | |
576 | |
577 static char _mysql_ResultObject_row_tell__doc__[] = | |
578 "row_tell() -- return the current row number of the result set."; | |
579 static PyObject * | |
580 _mysql_ResultObject_row_tell( | |
581 _mysql_ResultObject *self, | |
26 | 582 PyObject *unused) |
0 | 583 { |
584 MYSQL_ROW_OFFSET r; | |
26 | 585 |
0 | 586 check_result_connection(self); |
587 if (self->use) { | |
588 PyErr_SetString(_mysql_ProgrammingError, | |
589 "cannot be used with connection.use_result()"); | |
590 return NULL; | |
591 } | |
592 r = mysql_row_tell(self->result); | |
593 return PyInt_FromLong(r-self->result->data->data); | |
594 } | |
595 | |
596 static void | |
597 _mysql_ResultObject_dealloc( | |
598 _mysql_ResultObject *self) | |
599 { | |
600 PyObject_GC_UnTrack((PyObject *)self); | |
601 mysql_free_result(self->result); | |
602 _mysql_ResultObject_clear(self); | |
603 MyFree(self); | |
604 } | |
605 | |
606 static PyObject * | |
607 _mysql_ResultObject_repr( | |
608 _mysql_ResultObject *self) | |
609 { | |
610 char buf[300]; | |
611 sprintf(buf, "<_mysql.result object at %lx>", | |
612 (long)self); | |
613 return PyString_FromString(buf); | |
614 } | |
615 | |
616 static PyMethodDef _mysql_ResultObject_methods[] = { | |
617 { | |
618 "data_seek", | |
619 (PyCFunction)_mysql_ResultObject_data_seek, | |
620 METH_VARARGS, | |
621 _mysql_ResultObject_data_seek__doc__ | |
622 }, | |
623 { | |
624 "row_seek", | |
625 (PyCFunction)_mysql_ResultObject_row_seek, | |
626 METH_VARARGS, | |
627 _mysql_ResultObject_row_seek__doc__ | |
628 }, | |
629 { | |
630 "row_tell", | |
631 (PyCFunction)_mysql_ResultObject_row_tell, | |
26 | 632 METH_NOARGS, |
0 | 633 _mysql_ResultObject_row_tell__doc__ |
634 }, | |
635 { | |
636 "describe", | |
637 (PyCFunction)_mysql_ResultObject_describe, | |
26 | 638 METH_NOARGS, |
0 | 639 _mysql_ResultObject_describe__doc__ |
640 }, | |
641 { | |
642 "fetch_row", | |
643 (PyCFunction)_mysql_ResultObject_fetch_row, | |
644 METH_VARARGS | METH_KEYWORDS, | |
645 _mysql_ResultObject_fetch_row__doc__ | |
646 }, | |
647 { | |
73
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
648 "simple_fetch_row", |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
649 (PyCFunction)_mysql_ResultObject_simple_fetch_row, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
650 METH_VARARGS | METH_KEYWORDS, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
651 _mysql_ResultObject_simple_fetch_row__doc__ |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
652 }, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
653 |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
654 { |
0 | 655 "field_flags", |
656 (PyCFunction)_mysql_ResultObject_field_flags, | |
26 | 657 METH_NOARGS, |
0 | 658 _mysql_ResultObject_field_flags__doc__ |
659 }, | |
660 { | |
661 "num_fields", | |
662 (PyCFunction)_mysql_ResultObject_num_fields, | |
26 | 663 METH_NOARGS, |
0 | 664 _mysql_ResultObject_num_fields__doc__ |
665 }, | |
666 { | |
667 "num_rows", | |
668 (PyCFunction)_mysql_ResultObject_num_rows, | |
26 | 669 METH_NOARGS, |
0 | 670 _mysql_ResultObject_num_rows__doc__ |
671 }, | |
672 {NULL, NULL} /* sentinel */ | |
673 }; | |
674 | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
675 static struct PyMemberDef _mysql_ResultObject_memberlist[] = { |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
676 { |
66
5a7c30cd9de2
By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents:
55
diff
changeset
|
677 "connection", |
5a7c30cd9de2
By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents:
55
diff
changeset
|
678 T_OBJECT, |
5a7c30cd9de2
By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents:
55
diff
changeset
|
679 offsetof(_mysql_ConnectionObject, connection), |
5a7c30cd9de2
By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents:
55
diff
changeset
|
680 RO, |
5a7c30cd9de2
By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents:
55
diff
changeset
|
681 "Connection associated with result" |
5a7c30cd9de2
By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents:
55
diff
changeset
|
682 }, |
5a7c30cd9de2
By exposing connection on result, decoders can be simplified: Only the field object is needed. Turned on leak testing and found a leak writing BLOBs. removed one of the old stubs in Cursor.
adustman
parents:
55
diff
changeset
|
683 { |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
684 "decoders", |
0 | 685 T_OBJECT, |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
686 offsetof(_mysql_ResultObject, decoders), |
0 | 687 RO, |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
688 "Field decoders for result set" |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
689 }, |
67
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
690 { |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
691 "fields", |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
692 T_OBJECT, |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
693 offsetof(_mysql_ResultObject, fields), |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
694 RO, |
98d968f5af11
Reimplement MySQL->Python type conversion in C; much simpler and easier to deal with now. Hey, all my tests pass, so I guess that means I need to write some more tests.
adustman
parents:
66
diff
changeset
|
695 "Field metadata for result set" |
73
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
696 }, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
697 { |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
698 "use", |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
699 T_INT, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
700 offsetof(_mysql_ResultObject, use), |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
701 RO, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
702 "True if mysql_use_result() was used; False if mysql_store_result() was used" |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
703 }, |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
704 {NULL} /* Sentinel */ |
0 | 705 }; |
706 | |
707 static PyObject * | |
708 _mysql_ResultObject_getattr( | |
709 _mysql_ResultObject *self, | |
710 char *name) | |
711 { | |
712 PyObject *res; | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
713 struct PyMemberDef *l; |
0 | 714 |
715 res = Py_FindMethod(_mysql_ResultObject_methods, (PyObject *)self, name); | |
716 if (res != NULL) | |
717 return res; | |
718 PyErr_Clear(); | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
719 |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
720 for (l = _mysql_ResultObject_memberlist; l->name != NULL; l++) { |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
721 if (strcmp(l->name, name) == 0) |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
722 return PyMember_GetOne((char *)self, l); |
0 | 723 } |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
724 |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
725 PyErr_SetString(PyExc_AttributeError, name); |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
726 return NULL; |
0 | 727 } |
728 | |
729 static int | |
730 _mysql_ResultObject_setattr( | |
731 _mysql_ResultObject *self, | |
732 char *name, | |
733 PyObject *v) | |
734 { | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
735 struct PyMemberDef *l; |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
736 |
0 | 737 if (v == NULL) { |
738 PyErr_SetString(PyExc_AttributeError, | |
739 "can't delete connection attributes"); | |
740 return -1; | |
741 } | |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
742 |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
743 for (l = _mysql_ResultObject_memberlist; l->name != NULL; l++) |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
744 if (strcmp(l->name, name) == 0) |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
745 return PyMember_SetOne((char *)self, l, v); |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
746 |
0 | 747 PyErr_SetString(PyExc_AttributeError, name); |
748 return -1; | |
749 } | |
750 | |
751 PyTypeObject _mysql_ResultObject_Type = { | |
752 PyObject_HEAD_INIT(NULL) | |
753 0, | |
754 "_mysql.result", | |
755 sizeof(_mysql_ResultObject), | |
756 0, | |
757 (destructor)_mysql_ResultObject_dealloc, /* tp_dealloc */ | |
758 0, /*tp_print*/ | |
759 (getattrfunc)_mysql_ResultObject_getattr, /* tp_getattr */ | |
760 (setattrfunc)_mysql_ResultObject_setattr, /* tp_setattr */ | |
761 0, /*tp_compare*/ | |
762 (reprfunc)_mysql_ResultObject_repr, /* tp_repr */ | |
45 | 763 |
0 | 764 /* Method suites for standard classes */ |
45 | 765 |
0 | 766 0, /* (PyNumberMethods *) tp_as_number */ |
767 0, /* (PySequenceMethods *) tp_as_sequence */ | |
768 0, /* (PyMappingMethods *) tp_as_mapping */ | |
45 | 769 |
0 | 770 /* More standard operations (here for binary compatibility) */ |
45 | 771 |
0 | 772 0, /* (hashfunc) tp_hash */ |
773 0, /* (ternaryfunc) tp_call */ | |
774 0, /* (reprfunc) tp_str */ | |
775 0, /* (getattrofunc) tp_getattro */ | |
776 0, /* (setattrofunc) tp_setattro */ | |
45 | 777 |
0 | 778 /* Functions to access object as input/output buffer */ |
779 0, /* (PyBufferProcs *) tp_as_buffer */ | |
45 | 780 |
0 | 781 /* Flags to define presence of optional/expanded features */ |
45 | 782 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, /* (long) tp_flags */ |
783 | |
0 | 784 _mysql_ResultObject__doc__, /* (char *) tp_doc Documentation string */ |
785 /* call function for all accessible objects */ | |
45 | 786 (traverseproc)_mysql_ResultObject_traverse, /* tp_traverse */ |
0 | 787 /* delete references to contained objects */ |
45 | 788 (inquiry)_mysql_ResultObject_clear, /* tp_clear */ |
789 | |
0 | 790 /* rich comparisons */ |
791 0, /* (richcmpfunc) tp_richcompare */ | |
45 | 792 |
0 | 793 /* weak reference enabler */ |
794 0, /* (long) tp_weaklistoffset */ | |
45 | 795 |
0 | 796 /* Iterators */ |
73
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
797 (getiterfunc) _mysql_ResultObject__iter__, /* (getiterfunc) tp_iter */ |
24fa6a40c706
Added a simple_fetch_row() to the result object that simply returns one row
adustman
parents:
67
diff
changeset
|
798 (iternextfunc) _mysql_ResultObject_next, /* (iternextfunc) tp_iternext */ |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
799 |
0 | 800 /* Attribute descriptor and subclassing stuff */ |
42
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
801 (struct PyMethodDef *)_mysql_ResultObject_methods, /* tp_methods */ |
fdf0cabb27be
Member stuff is stable post py2.2, so remove the MyMember* workarounds
kylev
parents:
26
diff
changeset
|
802 (struct PyMemberDef *)_mysql_ResultObject_memberlist, /*tp_members */ |
0 | 803 0, /* (struct getsetlist *) tp_getset; */ |
804 0, /* (struct _typeobject *) tp_base; */ | |
805 0, /* (PyObject *) tp_dict */ | |
806 0, /* (descrgetfunc) tp_descr_get */ | |
807 0, /* (descrsetfunc) tp_descr_set */ | |
808 0, /* (long) tp_dictoffset */ | |
809 (initproc)_mysql_ResultObject_Initialize, /* tp_init */ | |
810 NULL, /* tp_alloc */ | |
811 NULL, /* tp_new */ | |
812 NULL, /* tp_free Low-level free-memory routine */ | |
813 0, /* (PyObject *) tp_bases */ | |
814 0, /* (PyObject *) tp_mro method resolution order */ | |
815 0, /* (PyObject *) tp_defined */ | |
816 }; |