Mercurial > p > mysql-python > mysqldb-2
comparison src/mysqlmod.c @ 75:3b03cb566032 MySQLdb
More serious restructuring and cleaning, especially in the handling
of result sets. All tests pass.
author | adustman |
---|---|
date | Mon, 22 Feb 2010 03:56:44 +0000 |
parents | 98d968f5af11 |
children |
comparison
equal
deleted
inserted
replaced
74:80164eb2f090 | 75:3b03cb566032 |
---|---|
253 PyObject * | 253 PyObject * |
254 _mysql_escape( | 254 _mysql_escape( |
255 PyObject *self, | 255 PyObject *self, |
256 PyObject *args); | 256 PyObject *args); |
257 | 257 |
258 static char _mysql_escape_sequence__doc__[] = | |
259 "escape_sequence(seq, dict) -- escape any special characters in sequence\n\ | |
260 seq using mapping dict to provide quoting functions for each type.\n\ | |
261 Returns a tuple of escaped items."; | |
262 static PyObject * | |
263 _mysql_escape_sequence( | |
264 PyObject *self, | |
265 PyObject *args) | |
266 { | |
267 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted; | |
268 int i, n; | |
269 if (!PyArg_ParseTuple(args, "OO:escape_sequence", &o, &d)) | |
270 goto error; | |
271 if (!PyMapping_Check(d)) { | |
272 PyErr_SetString(PyExc_TypeError, | |
273 "argument 2 must be a mapping"); | |
274 return NULL; | |
275 } | |
276 if ((n = PyObject_Length(o)) == -1) goto error; | |
277 if (!(r = PyTuple_New(n))) goto error; | |
278 for (i=0; i<n; i++) { | |
279 item = PySequence_GetItem(o, i); | |
280 if (!item) goto error; | |
281 quoted = _escape_item(item, d); | |
282 Py_DECREF(item); | |
283 if (!quoted) goto error; | |
284 PyTuple_SET_ITEM(r, i, quoted); | |
285 } | |
286 return r; | |
287 error: | |
288 Py_XDECREF(r); | |
289 return NULL; | |
290 } | |
291 | |
292 static char _mysql_escape_dict__doc__[] = | |
293 "escape_sequence(d, dict) -- escape any special characters in\n\ | |
294 dictionary d using mapping dict to provide quoting functions for each type.\n\ | |
295 Returns a dictionary of escaped items."; | |
296 static PyObject * | |
297 _mysql_escape_dict( | |
298 PyObject *self, | |
299 PyObject *args) | |
300 { | |
301 PyObject *o=NULL, *d=NULL, *r=NULL, *item, *quoted, *pkey; | |
302 Py_ssize_t ppos = 0; | |
303 if (!PyArg_ParseTuple(args, "O!O:escape_dict", &PyDict_Type, &o, &d)) | |
304 goto error; | |
305 if (!PyMapping_Check(d)) { | |
306 PyErr_SetString(PyExc_TypeError, | |
307 "argument 2 must be a mapping"); | |
308 return NULL; | |
309 } | |
310 if (!(r = PyDict_New())) goto error; | |
311 while (PyDict_Next(o, &ppos, &pkey, &item)) { | |
312 quoted = _escape_item(item, d); | |
313 if (!quoted) goto error; | |
314 if (PyDict_SetItem(r, pkey, quoted)==-1) goto error; | |
315 Py_DECREF(quoted); | |
316 } | |
317 return r; | |
318 error: | |
319 Py_XDECREF(r); | |
320 return NULL; | |
321 } | |
322 | 258 |
323 static char _mysql_get_client_info__doc__[] = | 259 static char _mysql_get_client_info__doc__[] = |
324 "get_client_info() -- Returns a string that represents\n\ | 260 "get_client_info() -- Returns a string that represents\n\ |
325 the client library version."; | 261 the client library version."; |
326 static PyObject * | 262 static PyObject * |