- Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathtest_2900_rowid.py
230 lines (214 loc) · 7.74 KB
/
test_2900_rowid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# -----------------------------------------------------------------------------
# Copyright (c) 2020, 2024, Oracle and/or its affiliates.
#
# This software is dual-licensed to you under the Universal Permissive License
# (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl and Apache License
# 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose
# either license.
#
# If you elect to accept the software under the Apache License, Version 2.0,
# the following applies:
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# -----------------------------------------------------------------------------
"""
2900 - Module for testing Rowids
"""
importdatetime
importunittest
importoracledb
importtest_env
classTestCase(test_env.BaseTestCase):
def__populate_test_universal_rowids(self):
self.cursor.execute("truncate table TestUniversalRowids")
data= [
(1, "ABC"*75, datetime.datetime(2017, 4, 11)),
(2, "DEF"*80, datetime.datetime(2017, 4, 12)),
]
self.cursor.executemany(
"insert into TestUniversalRowids values (:1, :2, :3)",
data,
)
self.conn.commit()
def__test_select_rowids(self, table_name):
self.cursor.execute(f"select rowid, IntCol from {table_name}")
sql=f"select IntCol from {table_name} where rowid = :val"
forrowid, int_valinself.cursor.fetchall():
self.cursor.execute(sql, val=rowid)
self.assertEqual(self.cursor.fetchall(), [(int_val,)])
deftest_2900(self):
"2900 - test selecting all rowids from a regular table"
self.__test_select_rowids("TestNumbers")
deftest_2901(self):
"2901 - test selecting all rowids from an index organised table"
self.__populate_test_universal_rowids()
self.__test_select_rowids("TestUniversalRowids")
deftest_2902(self):
"2902 - test inserting an invalid rowid"
sql="insert into TestRowids (IntCol, RowidCol) values (1, :rid)"
withself.assertRaisesFullCode("ORA-00932"):
self.cursor.execute(sql, rid=12345)
withself.assertRaisesFullCode("ORA-01410"):
self.cursor.execute(sql, rid="523lkhlf")
deftest_2903(self):
"2903 - test selecting regular rowids stored in a urowid column"
self.cursor.execute("truncate table TestRowids")
self.cursor.execute(
"""
insert into TestRowids (IntCol, UrowidCol)
select IntCol, rowid
from TestNumbers
"""
)
self.conn.commit()
self.cursor.execute("select IntCol, UrowidCol from TestRowids")
forint_val, rowidinself.cursor.fetchall():
self.cursor.execute(
"select IntCol from TestNumbers where rowid = :val",
val=rowid,
)
self.assertEqual(self.cursor.fetchall(), [(int_val,)])
deftest_2904(self):
"2904 - test selecting regular rowids stored in a rowid column"
self.cursor.execute("truncate table TestRowids")
self.cursor.execute(
"""
insert into TestRowids (IntCol, RowidCol)
select IntCol, rowid
from TestNumbers
"""
)
self.conn.commit()
self.cursor.execute("select IntCol, RowidCol from TestRowids")
forint_val, rowidinself.cursor.fetchall():
self.cursor.execute(
"""
select IntCol
from TestNumbers
where rowid = :val
""",
val=rowid,
)
self.assertEqual(self.cursor.fetchall(), [(int_val,)])
deftest_2905(self):
"2905 - binding and inserting a rowid"
self.cursor.execute("truncate table TestRowids")
insert_data= [
(1, "String #1"),
(2, "String #2"),
(3, "String #3"),
(4, "String #4"),
]
self.cursor.execute("truncate table TestTempTable")
self.cursor.executemany(
"""
insert into TestTempTable (IntCol, StringCol1)
values (:1, :2)
""",
insert_data,
)
self.conn.commit()
ridvar=self.cursor.var(oracledb.ROWID)
self.cursor.execute(
"""
begin
select rowid into :rid
from TestTempTable
where IntCol = 3;
end;
""",
rid=ridvar,
)
self.cursor.setinputsizes(r1=oracledb.ROWID)
self.cursor.execute(
"""
insert into TestRowids (IntCol, RowidCol)
values(1, :r1)
""",
r1=ridvar,
)
self.conn.commit()
self.cursor.execute("select IntCol, RowidCol from TestRowids")
int_val, rowid=self.cursor.fetchone()
self.cursor.execute(
"""
select IntCol, StringCol1 from TestTempTable
where rowid = :val
""",
val=rowid,
)
self.assertEqual(self.cursor.fetchone(), (3, "String #3"))
@unittest.skipIf(
nottest_env.get_is_thin(), "thick mode doesn't support DB_TYPE_UROWID"
)
deftest_2906(self):
"2906 - binding and inserting a rowid as urowid"
self.cursor.execute("truncate table TestRowids")
insert_data= [
(1, "String #1", datetime.datetime(2017, 4, 4)),
(2, "String #2", datetime.datetime(2017, 4, 5)),
(3, "String #3", datetime.datetime(2017, 4, 6)),
(4, "A"*250, datetime.datetime(2017, 4, 7)),
]
self.cursor.execute("truncate table TestUniversalRowids")
self.cursor.executemany(
"""
insert into TestUniversalRowids
values (:1, :2, :3)
""",
insert_data,
)
self.conn.commit()
ridvar=self.cursor.var(oracledb.DB_TYPE_UROWID)
self.cursor.execute(
"""
begin
select rowid into :rid
from TestUniversalRowids
where IntCol = 3;
end;
""",
rid=ridvar,
)
self.cursor.setinputsizes(r1=oracledb.DB_TYPE_UROWID)
self.cursor.execute(
"""
insert into TestRowids (IntCol, UrowidCol)
values(1, :r1)
""",
r1=ridvar,
)
self.conn.commit()
self.cursor.execute("select IntCol, UrowidCol from TestRowids")
int_val, rowid=self.cursor.fetchone()
self.cursor.execute(
"""
select IntCol, StringCol, DateCol
from TestUniversalRowids
where rowid = :val
""",
val=rowid,
)
self.assertEqual(
self.cursor.fetchone(),
(3, "String #3", datetime.datetime(2017, 4, 6)),
)
deftest_2907(self):
"2907 - fetching a null rowid"
self.cursor.execute("truncate table TestRowids")
self.cursor.execute("insert into TestRowids (IntCol) values (1)")
self.conn.commit()
self.cursor.execute("select * from TestRowids")
self.assertEqual(self.cursor.fetchone(), (1, None, None))
if__name__=="__main__":
test_env.run_test_cases()