Skip to content

Commit 5ba6080

Browse files
committed
Add low level APIs for semi-async query.
1 parent 8cc6261 commit 5ba6080

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

_mysql.c

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,16 @@ static int _mysql_ConnectionObject_clear(
756756
return 0;
757757
}
758758

759+
static char _mysql_ConnectionObject_fileno__doc__[] =
760+
"Return underlaying fd for connection";
761+
762+
static PyObject *
763+
_mysql_ConnectionObject_fileno(
764+
_mysql_ConnectionObject *self)
765+
{
766+
return PyInt_FromLong(self->connection.net.fd);
767+
}
768+
759769
static char _mysql_ConnectionObject_close__doc__[] =
760770
"Close the connection. No further activity possible.";
761771

@@ -1963,8 +1973,10 @@ _mysql_ConnectionObject_query(
19631973
{
19641974
char *query;
19651975
int len, r;
1976+
MYSQL *mysql = &(self->connection);
19661977
if (!PyArg_ParseTuple(args, "s#:query", &query, &len)) return NULL;
19671978
check_connection(self);
1979+
19681980
Py_BEGIN_ALLOW_THREADS
19691981
r = mysql_real_query(&(self->connection), query, len);
19701982
Py_END_ALLOW_THREADS
@@ -1974,6 +1986,50 @@ _mysql_ConnectionObject_query(
19741986
}
19751987

19761988

1989+
static char _mysql_ConnectionObject_send_query__doc__[] =
1990+
"Send a query. Same to query() except not wait response.\n\n\
1991+
Use read_query_result() before calling store_result() or use_result()\n";
1992+
1993+
static PyObject *
1994+
_mysql_ConnectionObject_send_query(
1995+
_mysql_ConnectionObject *self,
1996+
PyObject *args)
1997+
{
1998+
char *query;
1999+
int len, r;
2000+
MYSQL *mysql = &(self->connection);
2001+
if (!PyArg_ParseTuple(args, "s#:query", &query, &len)) return NULL;
2002+
check_connection(self);
2003+
2004+
Py_BEGIN_ALLOW_THREADS
2005+
r = mysql_send_query(mysql, query, len);
2006+
Py_END_ALLOW_THREADS
2007+
if (r) return _mysql_Exception(self);
2008+
Py_INCREF(Py_None);
2009+
return Py_None;
2010+
}
2011+
2012+
2013+
static char _mysql_ConnectionObject_read_query_result__doc__[] =
2014+
"Read result of query sent by send_query().\n";
2015+
2016+
static PyObject *
2017+
_mysql_ConnectionObject_read_query_result(
2018+
_mysql_ConnectionObject *self)
2019+
{
2020+
char *query;
2021+
int len, r;
2022+
MYSQL *mysql = &(self->connection);
2023+
check_connection(self);
2024+
2025+
Py_BEGIN_ALLOW_THREADS
2026+
r = (int)mysql_read_query_result(mysql);
2027+
Py_END_ALLOW_THREADS
2028+
if (r) return _mysql_Exception(self);
2029+
Py_INCREF(Py_None);
2030+
return Py_None;
2031+
}
2032+
19772033
static char _mysql_ConnectionObject_select_db__doc__[] =
19782034
"Causes the database specified by db to become the default\n\
19792035
(current) database on the connection specified by mysql. In subsequent\n\
@@ -2344,6 +2400,12 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
23442400
METH_VARARGS,
23452401
_mysql_ConnectionObject_close__doc__
23462402
},
2403+
{
2404+
"fileno",
2405+
(PyCFunction)_mysql_ConnectionObject_fileno,
2406+
METH_NOARGS,
2407+
_mysql_ConnectionObject_fileno__doc__
2408+
},
23472409
{
23482410
"dump_debug_info",
23492411
(PyCFunction)_mysql_ConnectionObject_dump_debug_info,
@@ -2428,6 +2490,18 @@ static PyMethodDef _mysql_ConnectionObject_methods[] = {
24282490
METH_VARARGS,
24292491
_mysql_ConnectionObject_query__doc__
24302492
},
2493+
{
2494+
"send_query",
2495+
(PyCFunction)_mysql_ConnectionObject_send_query,
2496+
METH_VARARGS,
2497+
_mysql_ConnectionObject_send_query__doc__,
2498+
},
2499+
{
2500+
"read_query_result",
2501+
(PyCFunction)_mysql_ConnectionObject_read_query_result,
2502+
METH_NOARGS,
2503+
_mysql_ConnectionObject_read_query_result__doc__,
2504+
},
24312505
{
24322506
"select_db",
24332507
(PyCFunction)_mysql_ConnectionObject_select_db,

0 commit comments

Comments
 (0)