| 114 | |
| 115 | |
| 116 | def test_dictcursor(): |
| 117 | conn = connect() |
| 118 | cursor = conn.cursor(MySQLdb.cursors.DictCursor) |
| 119 | |
| 120 | cursor.execute("CREATE TABLE t1 (a int, b int, c int)") |
| 121 | _tables.append("t1") |
| 122 | cursor.execute("INSERT INTO t1 (a,b,c) VALUES (1,1,47), (2,2,47)") |
| 123 | |
| 124 | cursor.execute("CREATE TABLE t2 (b int, c int)") |
| 125 | _tables.append("t2") |
| 126 | cursor.execute("INSERT INTO t2 (b,c) VALUES (1,1), (2,2)") |
| 127 | |
| 128 | cursor.execute("SELECT * FROM t1 JOIN t2 ON t1.b=t2.b") |
| 129 | rows = cursor.fetchall() |
| 130 | |
| 131 | assert len(rows) == 2 |
| 132 | assert rows[0] == {"a": 1, "b": 1, "c": 47, "t2.b": 1, "t2.c": 1} |
| 133 | assert rows[1] == {"a": 2, "b": 2, "c": 47, "t2.b": 2, "t2.c": 2} |
| 134 | |
| 135 | names1 = sorted(rows[0]) |
| 136 | names2 = sorted(rows[1]) |
| 137 | for a, b in zip(names1, names2): |
| 138 | assert a is b |
| 139 | |
| 140 | # Old fetchtype |
| 141 | cursor._fetch_type = 2 |
| 142 | cursor.execute("SELECT * FROM t1 JOIN t2 ON t1.b=t2.b") |
| 143 | rows = cursor.fetchall() |
| 144 | |
| 145 | assert len(rows) == 2 |
| 146 | assert rows[0] == {"t1.a": 1, "t1.b": 1, "t1.c": 47, "t2.b": 1, "t2.c": 1} |
| 147 | assert rows[1] == {"t1.a": 2, "t1.b": 2, "t1.c": 47, "t2.b": 2, "t2.c": 2} |
| 148 | |
| 149 | names1 = sorted(rows[0]) |
| 150 | names2 = sorted(rows[1]) |
| 151 | for a, b in zip(names1, names2): |
| 152 | assert a is b |
| 153 | |
| 154 | |
| 155 | def test_mogrify_without_args(): |