@@ -63,10 +63,10 @@ class Connection(_mysql.connection):
63
63
"""MySQL Database Connection Object"""
64
64
65
65
default_cursor = cursors .Cursor
66
+ waiter = None
66
67
67
68
def __init__ (self , * args , ** kwargs ):
68
69
"""
69
-
70
70
Create a connection to the database. It is strongly recommended
71
71
that you only use keyword parameters. Consult the MySQL C API
72
72
documentation for more information.
@@ -150,9 +150,13 @@ class object, used to create cursors (keyword only)
150
150
If True, autocommit is enabled.
151
151
If None, autocommit isn't set and server default is used.
152
152
153
+ waiter
154
+ Callable accepts fd as an argument. It is called after sending
155
+ query and before reading response.
156
+ This is useful when using with greenlet and async io.
157
+
153
158
There are a number of undocumented, non-standard methods. See the
154
159
documentation for the MySQL C API for some hints on what they do.
155
-
156
160
"""
157
161
from MySQLdb .constants import CLIENT , FIELD_TYPE
158
162
from MySQLdb .converters import conversions
@@ -195,6 +199,7 @@ class object, used to create cursors (keyword only)
195
199
196
200
# PEP-249 requires autocommit to be initially off
197
201
autocommit = kwargs2 .pop ('autocommit' , False )
202
+ self .waiter = kwargs2 .pop ('waiter' , None )
198
203
199
204
super (Connection , self ).__init__ (* args , ** kwargs2 )
200
205
self .cursorclass = cursorclass
@@ -266,6 +271,14 @@ def cursor(self, cursorclass=None):
266
271
"""
267
272
return (cursorclass or self .cursorclass )(self )
268
273
274
+ def query (self , query ):
275
+ if self .waiter is not None :
276
+ self .send_query (query )
277
+ self .waiter (self .fileno ())
278
+ self .read_query_result ()
279
+ else :
280
+ _mysql .connection .query (self , query )
281
+
269
282
def __enter__ (self ):
270
283
if self .get_autocommit ():
271
284
self .query ("BEGIN" )
0 commit comments