mirror of
https://github.com/PyMySQL/mysqlclient.git
synced 2025-08-15 11:10:58 +08:00
Fix member access problems
This commit is contained in:
@ -114,14 +114,14 @@ _mysql_Exception(_mysql_ConnectionObject *c)
|
|||||||
Py_DECREF(t);
|
Py_DECREF(t);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (!(c->open)) {
|
/* if (!(c->open)) { */
|
||||||
e = _mysql_InternalError;
|
/* e = _mysql_InternalError; */
|
||||||
PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L));
|
/* PyTuple_SET_ITEM(t, 0, PyInt_FromLong(-1L)); */
|
||||||
PyTuple_SET_ITEM(t, 1, PyString_FromString("connection is closed"));
|
/* PyTuple_SET_ITEM(t, 1, PyString_FromString("connection is closed")); */
|
||||||
PyErr_SetObject(e, t);
|
/* PyErr_SetObject(e, t); */
|
||||||
Py_DECREF(t);
|
/* Py_DECREF(t); */
|
||||||
return NULL;
|
/* return NULL; */
|
||||||
}
|
/* } */
|
||||||
merr = mysql_errno(&(c->connection));
|
merr = mysql_errno(&(c->connection));
|
||||||
if (!merr)
|
if (!merr)
|
||||||
e = _mysql_InterfaceError;
|
e = _mysql_InterfaceError;
|
||||||
@ -440,7 +440,6 @@ _mysql_ConnectionObject_Initialize(
|
|||||||
return -1;
|
return -1;
|
||||||
self->converter = conv;
|
self->converter = conv;
|
||||||
|
|
||||||
self->open = 1;
|
|
||||||
Py_BEGIN_ALLOW_THREADS ;
|
Py_BEGIN_ALLOW_THREADS ;
|
||||||
conn = mysql_init(&(self->connection));
|
conn = mysql_init(&(self->connection));
|
||||||
if (connect_timeout) {
|
if (connect_timeout) {
|
||||||
@ -474,6 +473,7 @@ _mysql_ConnectionObject_Initialize(
|
|||||||
be done here. tp_dealloc still needs to call PyObject_GC_UnTrack(),
|
be done here. tp_dealloc still needs to call PyObject_GC_UnTrack(),
|
||||||
however.
|
however.
|
||||||
*/
|
*/
|
||||||
|
self->open = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -544,6 +544,7 @@ _mysql_ConnectionObject_close(
|
|||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
PyObject *args)
|
PyObject *args)
|
||||||
{
|
{
|
||||||
|
if (!args) return NULL;
|
||||||
if (!PyArg_ParseTuple(args, "")) return NULL;
|
if (!PyArg_ParseTuple(args, "")) return NULL;
|
||||||
if (self->open) {
|
if (self->open) {
|
||||||
Py_BEGIN_ALLOW_THREADS
|
Py_BEGIN_ALLOW_THREADS
|
||||||
@ -1963,7 +1964,7 @@ static MyMemberlist(_mysql_ResultObject_memberlist)[] = {
|
|||||||
),
|
),
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
_mysql_ConnectionObject_getattr(
|
_mysql_ConnectionObject_getattr(
|
||||||
_mysql_ConnectionObject *self,
|
_mysql_ConnectionObject *self,
|
||||||
@ -1977,13 +1978,18 @@ _mysql_ConnectionObject_getattr(
|
|||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
if (strcmp(name, "closed") == 0)
|
if (strcmp(name, "closed") == 0)
|
||||||
return PyInt_FromLong((long)!(self->open));
|
return PyInt_FromLong((long)!(self->open));
|
||||||
/* if (strcmp(name, "__members__") == 0) */
|
|
||||||
/* return listmembers(_mysql_ConnectionObject_memberlist); */
|
|
||||||
#if PY_VERSION_HEX < 0x02020000
|
#if PY_VERSION_HEX < 0x02020000
|
||||||
return PyMember_Get((char *)self, _mysql_ConnectionObject_memberlist, name);
|
return PyMember_Get((char *)self, _mysql_ConnectionObject_memberlist, name);
|
||||||
#else
|
#else
|
||||||
PyErr_SetString(PyExc_AttributeError, name);
|
{
|
||||||
return NULL;
|
MyMemberlist(*l);
|
||||||
|
for (l = _mysql_ConnectionObject_memberlist; l->name != NULL; l++) {
|
||||||
|
if (strcmp(l->name, name) == 0)
|
||||||
|
return PyMember_GetOne((char *)self, l);
|
||||||
|
}
|
||||||
|
PyErr_SetString(PyExc_AttributeError, name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1999,12 +2005,17 @@ _mysql_ResultObject_getattr(
|
|||||||
return res;
|
return res;
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
#if PY_VERSION_HEX < 0x02020000
|
#if PY_VERSION_HEX < 0x02020000
|
||||||
/* if (strcmp(name, "__members__") == 0) */
|
|
||||||
/* return listmembers(_mysql_ResultObject_memberlist); */
|
|
||||||
return PyMember_Get((char *)self, _mysql_ResultObject_memberlist, name);
|
return PyMember_Get((char *)self, _mysql_ResultObject_memberlist, name);
|
||||||
#else
|
#else
|
||||||
PyErr_SetString(PyExc_AttributeError, name);
|
{
|
||||||
return NULL;
|
MyMemberlist(*l);
|
||||||
|
for (l = _mysql_ResultObject_memberlist; l->name != NULL; l++) {
|
||||||
|
if (strcmp(l->name, name) == 0)
|
||||||
|
return PyMember_GetOne((char *)self, l);
|
||||||
|
}
|
||||||
|
PyErr_SetString(PyExc_AttributeError, name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user