File tree Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Expand file tree Collapse file tree 2 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -706,6 +706,11 @@ def rollback(self):
706
706
self ._execute_command (COM_QUERY , "ROLLBACK" )
707
707
self ._read_ok_packet ()
708
708
709
+ def select_db (self , db ):
710
+ '''Set current db'''
711
+ self ._execute_command (COM_INIT_DB , db )
712
+ self ._read_ok_packet ()
713
+
709
714
def escape (self , obj ):
710
715
''' Escape whatever value you pass to it '''
711
716
if isinstance (obj , str_type ):
Original file line number Diff line number Diff line change @@ -41,6 +41,19 @@ def test_autocommit(self):
41
41
cur .execute ("SELECT @@AUTOCOMMIT" )
42
42
self .assertEqual (cur .fetchone ()[0 ], 0 )
43
43
44
+ def test_select_db (self ):
45
+ con = self .connections [0 ]
46
+ current_db = self .databases [0 ]['db' ]
47
+ other_db = self .databases [1 ]['db' ]
48
+
49
+ cur = con .cursor ()
50
+ cur .execute ('SELECT database()' )
51
+ self .assertEqual (cur .fetchone ()[0 ], current_db )
52
+
53
+ con .select_db (other_db )
54
+ cur .execute ('SELECT database()' )
55
+ self .assertEqual (cur .fetchone ()[0 ], other_db )
56
+
44
57
45
58
if __name__ == "__main__" :
46
59
try :
You can’t perform that action at this time.
0 commit comments