(self)
| 622 | con.close() |
| 623 | |
| 624 | def test_fetchall(self): |
| 625 | con = self._connect() |
| 626 | try: |
| 627 | cur = con.cursor() |
| 628 | # cursor.fetchall should raise an Error if called |
| 629 | # without executing a query that may return rows (such |
| 630 | # as a select) |
| 631 | self.assertRaises(self.driver.Error, cur.fetchall) |
| 632 | |
| 633 | self.executeDDL1(cur) |
| 634 | for sql in self._populate(): |
| 635 | cur.execute(sql) |
| 636 | |
| 637 | # cursor.fetchall should raise an Error if called |
| 638 | # after executing a statement that cannot return rows |
| 639 | self.assertRaises(self.driver.Error, cur.fetchall) |
| 640 | |
| 641 | cur.execute("select name from %sbooze" % self.table_prefix) |
| 642 | rows = cur.fetchall() |
| 643 | self.assertTrue(cur.rowcount in (-1, len(self.samples))) |
| 644 | self.assertEqual( |
| 645 | len(rows), |
| 646 | len(self.samples), |
| 647 | "cursor.fetchall did not retrieve all rows", |
| 648 | ) |
| 649 | rows = [r[0] for r in rows] |
| 650 | rows.sort() |
| 651 | for i in range(0, len(self.samples)): |
| 652 | self.assertEqual( |
| 653 | rows[i], self.samples[i], "cursor.fetchall retrieved incorrect rows" |
| 654 | ) |
| 655 | rows = cur.fetchall() |
| 656 | self.assertEqual( |
| 657 | len(rows), |
| 658 | 0, |
| 659 | "cursor.fetchall should return an empty list if called " |
| 660 | "after the whole result set has been fetched", |
| 661 | ) |
| 662 | self.assertTrue(cur.rowcount in (-1, len(self.samples))) |
| 663 | |
| 664 | self.executeDDL2(cur) |
| 665 | cur.execute("select name from %sbarflys" % self.table_prefix) |
| 666 | rows = cur.fetchall() |
| 667 | self.assertTrue(cur.rowcount in (-1, 0)) |
| 668 | self.assertEqual( |
| 669 | len(rows), |
| 670 | 0, |
| 671 | "cursor.fetchall should return an empty list if " |
| 672 | "a select query returns no rows", |
| 673 | ) |
| 674 | |
| 675 | finally: |
| 676 | con.close() |
| 677 | |
| 678 | def test_mixedfetch(self): |
| 679 | con = self._connect() |
nothing calls this directly
no test coverage detected