| 42 | pass |
| 43 | |
| 44 | def test_DictCursor(self): |
| 45 | bob, jim, fred = self.bob.copy(), self.jim.copy(), self.fred.copy() |
| 46 | # all assert test compare to the structure as would come out from MySQLdb |
| 47 | conn = self.conn |
| 48 | c = conn.cursor(self.cursor_type) |
| 49 | |
| 50 | # try an update which should return no rows |
| 51 | c.execute("update dictcursor set age=20 where name='bob'") |
| 52 | bob["age"] = 20 |
| 53 | # pull back the single row dict for bob and check |
| 54 | c.execute("SELECT * from dictcursor where name='bob'") |
| 55 | r = c.fetchone() |
| 56 | self.assertEqual(bob, r, "fetchone via DictCursor failed") |
| 57 | self._ensure_cursor_expired(c) |
| 58 | |
| 59 | # same again, but via fetchall => tuple) |
| 60 | c.execute("SELECT * from dictcursor where name='bob'") |
| 61 | r = c.fetchall() |
| 62 | self.assertEqual( |
| 63 | [bob], r, "fetch a 1 row result via fetchall failed via DictCursor" |
| 64 | ) |
| 65 | # same test again but iterate over the |
| 66 | c.execute("SELECT * from dictcursor where name='bob'") |
| 67 | for r in c: |
| 68 | self.assertEqual( |
| 69 | bob, r, "fetch a 1 row result via iteration failed via DictCursor" |
| 70 | ) |
| 71 | # get all 3 row via fetchall |
| 72 | c.execute("SELECT * from dictcursor") |
| 73 | r = c.fetchall() |
| 74 | self.assertEqual([bob, jim, fred], r, "fetchall failed via DictCursor") |
| 75 | # same test again but do a list comprehension |
| 76 | c.execute("SELECT * from dictcursor") |
| 77 | r = list(c) |
| 78 | self.assertEqual([bob, jim, fred], r, "DictCursor should be iterable") |
| 79 | # get all 2 row via fetchmany |
| 80 | c.execute("SELECT * from dictcursor") |
| 81 | r = c.fetchmany(2) |
| 82 | self.assertEqual([bob, jim], r, "fetchmany failed via DictCursor") |
| 83 | self._ensure_cursor_expired(c) |
| 84 | |
| 85 | def test_custom_dict(self): |
| 86 | class MyDict(dict): |