File tree Expand file tree Collapse file tree 4 files changed +31
-9
lines changed
Expand file tree Collapse file tree 4 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ def test1(self):
1414 with connection .cursor () as cursor :
1515 yield cursor .execute (sql )
1616 datas = cursor .fetchall ()
17- print ( datas )
17+ self . assertTrue ( bool ( datas ) )
1818
1919
2020class TestAsyncCursor (BaseTestCase ):
@@ -34,8 +34,9 @@ class TestAsyncCursor(BaseTestCase):
3434 def test1 (self ):
3535 sql = "select 1 as test"
3636 with (yield self .pool .Connection ()) as connection :
37- with connection .cursor () as cursor :
38- yield cursor .execute (sql )
39- result = yield cursor .fetchone ()
40- self .assertTrue ('test' in result )
41- self .assertEqual (result ['test' ], 1 )
37+ cursor = connection .cursor ()
38+ yield cursor .execute (sql )
39+ result = yield cursor .fetchone ()
40+ yield cursor .close ()
41+ self .assertTrue ('test' in result )
42+ self .assertEqual (result ['test' ], 1 )
Original file line number Diff line number Diff line change @@ -70,6 +70,9 @@ def select_db(self, db):
7070 return async_call_method (self ._connection .select_db , db )
7171
7272 def cursor (self , cursor_cls = None ):
73+ if cursor_cls is None :
74+ cursor_cls = self ._connection .cursorclass
75+
7376 cursor = self ._connection .cursor (
7477 cursor_cls .__delegate_class__ if cursor_cls and issubclass (cursor_cls , Cursor ) else cursor_cls
7578 )
Original file line number Diff line number Diff line change @@ -34,6 +34,12 @@ def close(self):
3434 self ._cursor = None
3535 return future
3636
37+ def nextset (self ):
38+ return async_call_method (self ._cursor .nextset )
39+
40+ def mogrify (self , query , args = None ):
41+ return self ._cursor .mogrify (query , args )
42+
3743 def execute (self , query , args = None ):
3844 return async_call_method (self ._cursor .execute , query , args )
3945
@@ -83,6 +89,19 @@ class DictCursor(Cursor):
8389class SSCursor (Cursor ):
8490 __delegate_class__ = OriginSSCursor
8591
92+ def close (self ):
93+ if self ._cursor is None :
94+ self ._cursor .close ()
95+ future = Future ()
96+ future .set_result (None )
97+ else :
98+ future = async_call_method (self ._cursor .close )
99+ self ._cursor = None
100+ return future
101+
102+ def read_next (self ):
103+ return async_call_method (self ._cursor .read_next )
104+
86105 def fetchone (self ):
87106 return async_call_method (self ._cursor .fetchone )
88107
Original file line number Diff line number Diff line change 88
99def async_call_method (fun , * args , ** kwargs ):
1010 future = Future ()
11- io_loop = IOLoop .current ()
1211
1312 def finish ():
1413 try :
1514 result = fun (* args , ** kwargs )
1615 if future ._callbacks :
17- io_loop .add_callback (future .set_result , result )
16+ IOLoop . current () .add_callback (future .set_result , result )
1817 else :
1918 future .set_result (result )
2019 except :
2120 if future ._callbacks :
22- io_loop .add_callback (future .set_exc_info , sys .exc_info ())
21+ IOLoop . current () .add_callback (future .set_exc_info , sys .exc_info ())
2322 else :
2423 future .set_exc_info (sys .exc_info ())
2524
You can’t perform that action at this time.
0 commit comments