@@ -5070,6 +5070,86 @@ def test_cursor_buffered(self):
5070
5070
cur_pure_buffered .close ()
5071
5071
cur_cext_buffered .close ()
5072
5072
5073
+ def test_cursor_dictionary (self ):
5074
+ """Test results from cursor buffered are the same in pure or c-ext"""
5075
+ cur_pure_dictionary = self .cnx_pure .cursor (dictionary = True )
5076
+ cur_cext_dictionary = self .cnx_cext .cursor (dictionary = True )
5077
+ self ._test_fetchone (cur_pure_dictionary , cur_cext_dictionary )
5078
+ self ._test_fetchmany (cur_pure_dictionary , cur_cext_dictionary )
5079
+ self ._test_fetch_fetchall (cur_pure_dictionary , cur_cext_dictionary )
5080
+ cur_pure_dictionary .close ()
5081
+ cur_cext_dictionary .close ()
5082
+
5083
+ def test_cursor_dictionary_buf (self ):
5084
+ """Test results from cursor buffered are the same in pure or c-ext"""
5085
+ cur_pure = self .cnx_pure .cursor (dictionary = True ,
5086
+ buffered = True )
5087
+ cur_cext = self .cnx_cext .cursor (dictionary = True ,
5088
+ buffered = True )
5089
+ self ._test_fetchone (cur_pure , cur_cext )
5090
+ self ._test_fetchmany (cur_pure , cur_cext )
5091
+ self ._test_fetch_fetchall (cur_pure , cur_cext )
5092
+ cur_pure .close ()
5093
+ cur_cext .close ()
5094
+
5095
+
5096
+ class BugOra28239074 (tests .MySQLConnectorTests ):
5097
+ """BUG#28239074: CURSOR DICTIONARY DOES NOT RETURN DICTIONARY TYPE RESULTS
5098
+ """
5099
+ table = "bug28239074"
5100
+
5101
+ def setUp (self ):
5102
+ config_pure = tests .get_mysql_config ()
5103
+ config_pure ["use_pure" ] = True
5104
+ self .cnx = mysql .connector .connect (** config_pure )
5105
+ cur = self .cnx .cursor (dictionary = True )
5106
+
5107
+ cur .execute ("DROP TABLE IF EXISTS {0}" .format (self .table ))
5108
+ cur .execute ("CREATE TABLE {0}(a char(50) ,b int) "
5109
+ "DEFAULT CHARSET utf8" .format (self .table ))
5110
+ data = [(chr (1 ), 1 ),('s' , 2 ),(chr (120 ), 3 ),(chr (121 ), 4 ),(chr (127 ), 5 )]
5111
+ cur .executemany ("INSERT INTO {0} (a, b) VALUES "
5112
+ "(%s, %s)" .format (self .table ), data )
5113
+
5114
+ def tearDown (self ):
5115
+ self .cnx .cmd_query ("DROP TABLE IF EXISTS {}" .format (self .table ))
5116
+ self .cnx .close ()
5117
+
5118
+ def test_cursor_dict (self ):
5119
+ exp = [
5120
+ {u'a' : u'\x01 ' , u'b' : 1 },
5121
+ {u'a' : u's' , u'b' : 2 },
5122
+ {u'a' : u'\x78 ' , u'b' : 3 },
5123
+ {u'a' : u'\x79 ' , u'b' : 4 },
5124
+ {u'a' : u'\x7f ' , u'b' : 5 }
5125
+ ]
5126
+ cur = self .cnx .cursor (dictionary = True )
5127
+
5128
+ # Test fetchone
5129
+ cur .execute ("SELECT * FROM {}" .format (self .table ))
5130
+ i = 0
5131
+ row = cur .fetchone ()
5132
+ while row is not None :
5133
+ self .assertTrue (isinstance (row , dict ))
5134
+ self .assertEqual (exp [i ], row , "row {} is not equal to expected row"
5135
+ " {}" .format (row , exp [i ]))
5136
+ row = cur .fetchone ()
5137
+ i += 1
5138
+
5139
+ # Test fetchall
5140
+ cur .execute ("SELECT * FROM {}" .format (self .table ))
5141
+ rows = cur .fetchall ()
5142
+ self .assertEqual (exp , rows , "rows {} is not equal to expected row" )
5143
+
5144
+ # Test for each in cursor
5145
+ cur .execute ("SELECT * FROM {}" .format (self .table ))
5146
+ i = 0
5147
+ for row in cur :
5148
+ self .assertTrue (isinstance (row , dict ))
5149
+ self .assertEqual (exp [i ], row , "row {} is not equal to expected row"
5150
+ " {}" .format (row , exp [i ]))
5151
+ i += 1
5152
+
5073
5153
5074
5154
class BugOra27364914 (tests .MySQLConnectorTests ):
5075
5155
"""BUG#27364914: CURSOR PREPARED STATEMENTS DO NOT CONVERT STRINGS
0 commit comments