Mercurial > p > mysql-python > mysqldb-2
diff src/connections.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 | f06381a47ab0 |
children |
line wrap: on
line diff
--- a/src/connections.c Sat Feb 20 04:27:21 2010 +0000 +++ b/src/connections.c Mon Feb 22 03:56:44 2010 +0000 @@ -9,7 +9,6 @@ PyObject *kwargs) { MYSQL *conn = NULL; - PyObject *decoder_stack = NULL; PyObject *ssl = NULL; #if HAVE_OPENSSL char *key = NULL, *cert = NULL, *ca = NULL, @@ -20,7 +19,7 @@ unsigned int port = 0; unsigned int client_flag = 0; static char *kwlist[] = { "host", "user", "passwd", "db", "port", - "unix_socket", "decoder_stack", + "unix_socket", "connect_timeout", "compress", "named_pipe", "init_command", "read_default_file", "read_default_group", @@ -33,13 +32,12 @@ *read_default_file=NULL, *read_default_group=NULL; - self->decoder_stack = NULL; self->open = 0; check_server_init(-1); - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ssssisOiiisssiOi:connect", + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ssssisiiisssiOi:connect", kwlist, &host, &user, &passwd, &db, - &port, &unix_socket, &decoder_stack, + &port, &unix_socket, &connect_timeout, &compress, &named_pipe, &init_command, &read_default_file, @@ -107,12 +105,6 @@ return -1; } - if (!decoder_stack) - decoder_stack = PyList_New(0); - else - Py_INCREF(decoder_stack); - self->decoder_stack = decoder_stack; - /* PyType_GenericAlloc() automatically sets up GC allocation and tracking for GC objects, at least in 2.2.1, so it does not need to @@ -195,16 +187,12 @@ visitproc visit, void *arg) { - if (self->decoder_stack) - return visit(self->decoder_stack, arg); return 0; } static int _mysql_ConnectionObject_clear( _mysql_ConnectionObject *self) { - Py_XDECREF(self->decoder_stack); - self->decoder_stack = NULL; return 0; } @@ -399,7 +387,7 @@ now call store_result(), warning_count(), affected_rows()\n\ , and so forth. \n\ \n\ -Returns 0 if there are more results; -1 if there are no more results\n\ +Returns True if there are more results.\n\ \n\ Non-standard.\n\ "; @@ -418,7 +406,7 @@ #endif Py_END_ALLOW_THREADS if (err > 0) return _mysql_Exception(self); - return PyInt_FromLong(err); + return PyInt_FromLong(err == 0); } #if MYSQL_VERSION_ID >= 40100 @@ -917,22 +905,25 @@ return PyString_FromString(s); } -static char _mysql_ConnectionObject_store_result__doc__[] = -"Returns a result object acquired by mysql_store_result\n\ -(results stored in the client). If no results are available,\n\ -None is returned. Non-standard.\n\ +static char _mysql_ConnectionObject_get_result__doc__[] = +"Returns a result object. If use is True, mysql_use_result()\n\ +is used; otherwise mysql_store_result() is used (the default).\n\ "; static PyObject * -_mysql_ConnectionObject_store_result( +_mysql_ConnectionObject_get_result( _mysql_ConnectionObject *self, - PyObject *unused) + PyObject *args, + PyObject *kwargs) { PyObject *arglist=NULL, *kwarglist=NULL, *result=NULL; + static char *kwlist[] = {"use", NULL}; _mysql_ResultObject *r=NULL; - + int use = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i:get_result", kwlist, &use)) return NULL; check_connection(self); - arglist = Py_BuildValue("(OiO)", self, 0, self->decoder_stack); + arglist = Py_BuildValue("(Oi)", self, use); if (!arglist) goto error; kwarglist = PyDict_New(); if (!kwarglist) goto error; @@ -977,41 +968,6 @@ return PyInt_FromLong((long)pid); } -static char _mysql_ConnectionObject_use_result__doc__[] = -"Returns a result object acquired by mysql_use_result\n\ -(results stored in the server). If no results are available,\n\ -None is returned. Non-standard.\n\ -"; - -static PyObject * -_mysql_ConnectionObject_use_result( - _mysql_ConnectionObject *self, - PyObject *unused) -{ - PyObject *arglist=NULL, *kwarglist=NULL, *result=NULL; - _mysql_ResultObject *r=NULL; - - check_connection(self); - arglist = Py_BuildValue("(OiO)", self, 1, self->decoder_stack); - if (!arglist) return NULL; - kwarglist = PyDict_New(); - if (!kwarglist) goto error; - r = MyAlloc(_mysql_ResultObject, _mysql_ResultObject_Type); - if (!r) goto error; - result = (PyObject *) r; - if (_mysql_ResultObject_Initialize(r, arglist, kwarglist)) - goto error; - if (!(r->result)) { - Py_DECREF(result); - Py_INCREF(Py_None); - result = Py_None; - } - error: - Py_DECREF(arglist); - Py_XDECREF(kwarglist); - return result; -} - static void _mysql_ConnectionObject_dealloc( _mysql_ConnectionObject *self) @@ -1171,6 +1127,12 @@ _mysql_ConnectionObject_get_proto_info__doc__ }, { + "get_result", + (PyCFunction)_mysql_ConnectionObject_get_result, + METH_VARARGS | METH_KEYWORDS, + _mysql_ConnectionObject_get_result__doc__ + }, + { "get_server_info", (PyCFunction)_mysql_ConnectionObject_get_server_info, METH_NOARGS, @@ -1225,12 +1187,6 @@ _mysql_ConnectionObject_stat__doc__ }, { - "store_result", - (PyCFunction)_mysql_ConnectionObject_store_result, - METH_NOARGS, - _mysql_ConnectionObject_store_result__doc__ - }, - { "string_literal", (PyCFunction)_mysql_string_literal, METH_VARARGS, @@ -1241,12 +1197,6 @@ METH_NOARGS, _mysql_ConnectionObject_thread_id__doc__ }, - { - "use_result", - (PyCFunction)_mysql_ConnectionObject_use_result, - METH_NOARGS, - _mysql_ConnectionObject_use_result__doc__ - }, {NULL, NULL} /* sentinel */ }; @@ -1259,13 +1209,6 @@ "True if connection is open" }, { - "decoder_stack", - T_OBJECT, - offsetof(_mysql_ConnectionObject, decoder_stack), - 0, - "Type decoder stack" - }, - { "server_capabilities", T_UINT, offsetof(_mysql_ConnectionObject, connection.server_capabilities),