|
1 | 1 | # ----------------------------------------------------------------------------- |
2 | | -# Copyright (c) 2021, 2023, Oracle and/or its affiliates. |
| 2 | +# Copyright (c) 2021, 2024, Oracle and/or its affiliates. |
3 | 3 | # |
4 | 4 | # This software is dual-licensed to you under the Universal Permissive License |
5 | 5 | # (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License |
@@ -683,6 +683,44 @@ def type_handler(cursor, name, default_type, size, precision, scale): |
683 | 683 | cursor.execute("select 1 from dual") |
684 | 684 | self.assertEqual(cursor.fetchall(), [("1",)]) |
685 | 685 |
|
| 686 | + def test_3676_reexecute_no_rows(self): |
| 687 | + "3676 - re-execute query with second fetch returning no rows" |
| 688 | + |
| 689 | + self.cursor.execute("truncate table TestTempTable") |
| 690 | + data = [(i + 1,) for i in range(5)] |
| 691 | + self.cursor.executemany( |
| 692 | + "insert into TestTempTable (IntCol) values (:1)", data |
| 693 | + ) |
| 694 | + self.conn.commit() |
| 695 | + |
| 696 | + def type_handler_1(cursor, metadata): |
| 697 | + return cursor.var( |
| 698 | + str, |
| 699 | + arraysize=cursor.arraysize, |
| 700 | + outconverter=lambda x: f"_{x}_", |
| 701 | + ) |
| 702 | + |
| 703 | + def type_handler_2(cursor, metadata): |
| 704 | + return cursor.var( |
| 705 | + str, |
| 706 | + arraysize=cursor.arraysize, |
| 707 | + outconverter=lambda x: f"={x}=", |
| 708 | + ) |
| 709 | + |
| 710 | + self.cursor.outputtypehandler = type_handler_1 |
| 711 | + self.cursor.arraysize = 6 |
| 712 | + self.cursor.prefetchrows = 6 |
| 713 | + sql = "select IntCol from TestTempTable where rownum <= :1" |
| 714 | + self.cursor.execute(sql, [6]) |
| 715 | + expected_value = [(f"_{x}_",) for x, in data] |
| 716 | + self.assertEqual(self.cursor.fetchall(), expected_value) |
| 717 | + |
| 718 | + self.cursor.outputtypehandler = type_handler_2 |
| 719 | + self.cursor.prefetchrows = 2 |
| 720 | + self.cursor.arraysize = 2 |
| 721 | + self.cursor.execute(sql, [0]) |
| 722 | + self.assertEqual(self.cursor.fetchall(), []) |
| 723 | + |
686 | 724 |
|
687 | 725 | if __name__ == "__main__": |
688 | 726 | test_env.run_test_cases() |
0 commit comments