|
27 | 27 | """ |
28 | 28 |
|
29 | 29 | import datetime |
| 30 | +import unittest |
30 | 31 |
|
31 | 32 | import oracledb |
32 | 33 | import test_env |
@@ -84,5 +85,90 @@ def test_2903_select_rowids_as_urowids(self): |
84 | 85 | val=rowid) |
85 | 86 | self.assertEqual(self.cursor.fetchall(), [(int_val,)]) |
86 | 87 |
|
| 88 | + def test_2904_select_rowids_as_rowids(self): |
| 89 | + "2904 - test selecting regular rowids stored in a rowid column" |
| 90 | + self.cursor.execute("truncate table TestRowids") |
| 91 | + self.cursor.execute(""" |
| 92 | + insert into TestRowids (IntCol, RowidCol) |
| 93 | + select IntCol, rowid from TestNumbers""") |
| 94 | + self.connection.commit() |
| 95 | + self.cursor.execute("select IntCol, RowidCol from TestRowids") |
| 96 | + for int_val, rowid in self.cursor.fetchall(): |
| 97 | + self.cursor.execute(""" |
| 98 | + select IntCol |
| 99 | + from TestNumbers |
| 100 | + where rowid = :val""", |
| 101 | + val=rowid) |
| 102 | + self.assertEqual(self.cursor.fetchall(), [(int_val,)]) |
| 103 | + |
| 104 | + def test_2905_test_bind_and_insert_rowid(self): |
| 105 | + "2905 - binding and inserting a rowid" |
| 106 | + self.cursor.execute("truncate table TestRowids") |
| 107 | + insert_data = [ |
| 108 | + (1, "String #1"), (2, "String #2"), |
| 109 | + (3, "String #3"),(4, "String #4") |
| 110 | + ] |
| 111 | + self.cursor.execute("truncate table TestTempTable") |
| 112 | + sql = "insert into TestTempTable (IntCol, StringCol1) values (:1, :2)" |
| 113 | + self.cursor.executemany(sql, insert_data) |
| 114 | + self.connection.commit() |
| 115 | + ridvar = self.cursor.var(oracledb.ROWID) |
| 116 | + self.cursor.execute(""" |
| 117 | + begin |
| 118 | + select rowid into :rid from TestTempTable |
| 119 | + where IntCol = 3; |
| 120 | + end;""", |
| 121 | + rid=ridvar) |
| 122 | + self.cursor.setinputsizes(r1=oracledb.ROWID) |
| 123 | + self.cursor.execute(""" |
| 124 | + insert into TestRowids (IntCol, RowidCol) |
| 125 | + values(1, :r1)""", |
| 126 | + r1=ridvar) |
| 127 | + self.connection.commit() |
| 128 | + self.cursor.execute("select IntCol, RowidCol from TestRowids") |
| 129 | + int_val, rowid = self.cursor.fetchone() |
| 130 | + self.cursor.execute(""" |
| 131 | + select IntCol, StringCol1 from TestTempTable |
| 132 | + where rowid = :val""", |
| 133 | + val=rowid) |
| 134 | + self.assertEqual(self.cursor.fetchone(), (3, "String #3")) |
| 135 | + |
| 136 | + @unittest.skipIf(not test_env.get_is_thin(), |
| 137 | + "thick mode doesn't support DB_TYPE_UROWID") |
| 138 | + def test_2906_test_bind_and_insert_rowid_as_urowid(self): |
| 139 | + "2906 - binding and inserting a rowid as urowid" |
| 140 | + self.cursor.execute("truncate table TestRowids") |
| 141 | + insert_data = [ |
| 142 | + (1, "String #1", datetime.datetime(2017, 4, 4)), |
| 143 | + (2, "String #2", datetime.datetime(2017, 4, 5)), |
| 144 | + (3, "String #3", datetime.datetime(2017, 4, 6)), |
| 145 | + (4, "A" * 250, datetime.datetime(2017, 4, 7)) |
| 146 | + ] |
| 147 | + self.cursor.execute("truncate table TestUniversalRowids") |
| 148 | + sql = "insert into TestUniversalRowids values (:1, :2, :3)" |
| 149 | + self.cursor.executemany(sql, insert_data) |
| 150 | + self.connection.commit() |
| 151 | + ridvar = self.cursor.var(oracledb.DB_TYPE_UROWID) |
| 152 | + self.cursor.execute(""" |
| 153 | + begin |
| 154 | + select rowid into :rid from TestUniversalRowids |
| 155 | + where IntCol = 3; |
| 156 | + end;""", |
| 157 | + rid=ridvar) |
| 158 | + self.cursor.setinputsizes(r1=oracledb.DB_TYPE_UROWID) |
| 159 | + self.cursor.execute(""" |
| 160 | + insert into TestRowids (IntCol, UrowidCol) |
| 161 | + values(1, :r1)""", |
| 162 | + r1=ridvar) |
| 163 | + self.connection.commit() |
| 164 | + self.cursor.execute("select IntCol, UrowidCol from TestRowids") |
| 165 | + int_val, rowid = self.cursor.fetchone() |
| 166 | + self.cursor.execute(""" |
| 167 | + select IntCol, StringCol, DateCol from TestUniversalRowids |
| 168 | + where rowid = :val""", |
| 169 | + val=rowid) |
| 170 | + self.assertEqual(self.cursor.fetchone(), |
| 171 | + (3, "String #3", datetime.datetime(2017, 4, 6))) |
| 172 | + |
87 | 173 | if __name__ == "__main__": |
88 | 174 | test_env.run_test_cases() |
0 commit comments