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