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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
|
ij> --
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You 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
--
-- http://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.
--
-- create a table
create table t1(c11 int, c12 int);
0 rows inserted/updated/deleted
ij> -- insert data into tables
insert into t1 values(1,1);
1 row inserted/updated/deleted
ij> insert into t1 values(2,2);
1 row inserted/updated/deleted
ij> -- set autocommit off
autocommit off;
ij> -- first test - make sure that only cursors created with holdability true
-- have open resultsets after commit
-- declare 3 different kind of cursors one for each jdbc release so far
get with nohold cursor jdk1 as 'SELECT * FROM t1';
ij> get scroll insensitive with nohold cursor jdk2 as 'SELECT * FROM t1';
ij> get with hold cursor jdk4 as 'SELECT * FROM t1';
ij> -- do fetches from these cursors
next jdk1;
C11 |C12
-----------------------
1 |1
ij> next jdk2;
C11 |C12
-----------------------
1 |1
ij> next jdk4;
C11 |C12
-----------------------
1 |1
ij> --commit
commit;
ij> -- now try the fetch on cursors again after commit
-- cursors jdk1 and jdk2 will give errors
next jdk1;
ERROR XCL16: ResultSet not open. Operation 'next' not permitted. Verify that autocommit is off.
ij> next jdk2;
ERROR XCL16: ResultSet not open. Operation 'next' not permitted. Verify that autocommit is off.
ij> next jdk4;
C11 |C12
-----------------------
2 |2
ij> -- end of resultset for jdk4, but try next again
next jdk4;
No current row
ij> close jdk4;
ij> next jdk4;
IJ ERROR: Unable to establish cursor JDK4@CONNECTION0
ij> -- clean up.
close jdk1;
ij> close jdk2;
ij> -- second test - make sure that all the cursors (including holdability true)
-- have their resultsets closed after rollback.
-- declare the cursors again, this time, try with rollback
get with nohold cursor jdk1 as 'SELECT * FROM t1';
ij> get scroll insensitive with nohold cursor jdk2 as 'SELECT * FROM t1';
ij> get with hold cursor jdk4 as 'SELECT * FROM t1';
ij> -- do fetches from these cursors
next jdk1;
C11 |C12
-----------------------
1 |1
ij> next jdk2;
C11 |C12
-----------------------
1 |1
ij> next jdk4;
C11 |C12
-----------------------
1 |1
ij> --rollback
rollback;
ij> -- now try the fetch on cursors again after rollback
-- all the cursors will give errors
next jdk1;
ERROR XCL16: ResultSet not open. Operation 'next' not permitted. Verify that autocommit is off.
ij> next jdk2;
ERROR XCL16: ResultSet not open. Operation 'next' not permitted. Verify that autocommit is off.
ij> next jdk4;
ERROR XCL16: ResultSet not open. Operation 'next' not permitted. Verify that autocommit is off.
ij> -- clean up.
close jdk1;
ij> close jdk2;
ij> close jdk4;
ij> drop table t1;
0 rows inserted/updated/deleted
ij> -- recreate and populate the table for next test
create table t1(c11 int, c12 int);
0 rows inserted/updated/deleted
ij> insert into t1 values(1,1);
1 row inserted/updated/deleted
ij> insert into t1 values(2,2);
1 row inserted/updated/deleted
ij> -- fourth test - try to change the isolation level while there are
-- held cursors
get with nohold cursor jdk1 as 'SELECT * FROM t1';
ij> get with hold cursor jdk4 as 'SELECT * FROM t1';
ij> next jdk1;
C11 |C12
-----------------------
1 |1
ij> next jdk4;
C11 |C12
-----------------------
1 |1
ij> -- changing isolation while cursor is open would fail;
-- but for client/server, with small data set, the server would already be
-- closed. See discussion re DERBY-3801.
-- close jdk4 and then should be able to change isolation
close jdk4;
ij> set isolation to serializable;
0 rows inserted/updated/deleted
ij> -- clean up.
close jdk1;
ij> -- fifth test - try isolation level change alongwith changing the isolation
-- level of just one statement
get with hold cursor jdk4 as 'SELECT * FROM t1';
ij> get with nohold cursor jdk1 as 'SELECT * FROM t1 WITH CS';
ij> next jdk4;
C11 |C12
-----------------------
1 |1
ij> next jdk1;
C11 |C12
-----------------------
1 |1
ij> close jdk4;
ij> -- should be able to change the isolation now
set isolation READ UNCOMMITTED;
0 rows inserted/updated/deleted
ij> set isolation RS;
0 rows inserted/updated/deleted
ij> -- clean up.
close jdk1;
ij> -- sixth test - try positioned update with hold cursor
get with hold cursor jdk4 as 'SELECT * FROM t1 FOR UPDATE';
ij> -- following should give error because cursor is not positioned on any row
update t1 set c12=12 where current of jdk4;
ERROR 24000: Invalid cursor state - no current row.
ij> select * from t1;
C11 |C12
-----------------------
1 |1
2 |2
ij> next jdk4;
C11 |C12
-----------------------
1 |1
ij> update t1 set c12=12 where current of jdk4;
1 row inserted/updated/deleted
ij> select * from t1;
C11 |C12
-----------------------
1 |12
2 |2
ij> commit;
ij> -- after commit, the next transaction should do a fetch again before doing
-- any positioned update
update t1 set c12=123 where current of jdk4;
ERROR 24000: Invalid cursor state - no current row.
ij> select * from t1;
C11 |C12
-----------------------
1 |12
2 |2
ij> next jdk4;
C11 |C12
-----------------------
2 |2
ij> update t1 set c12=23 where current of jdk4;
1 row inserted/updated/deleted
ij> select * from t1;
C11 |C12
-----------------------
1 |12
2 |23
ij> close jdk4;
ij> update t1 set c12=234 where current of jdk4;
ERROR 42X30: Cursor 'JDK4' not found. Verify that autocommit is off.
ij> select * from t1;
C11 |C12
-----------------------
1 |12
2 |23
ij> -- seventh test - try positioned delete with hold cursor
get with hold cursor jdk4 as 'SELECT * FROM t1 FOR UPDATE';
ij> -- following should give error because cursor is not positioned on any row
delete from t1 where current of jdk4;
ERROR 24000: Invalid cursor state - no current row.
ij> select * from t1;
C11 |C12
-----------------------
1 |12
2 |23
ij> next jdk4;
C11 |C12
-----------------------
1 |12
ij> delete from t1 where current of jdk4;
1 row inserted/updated/deleted
ij> select * from t1;
C11 |C12
-----------------------
2 |23
ij> commit;
ij> -- after commit, the next transaction should do a fetch again before doing
-- any positioned delete
delete from t1 where current of jdk4;
ERROR 24000: Invalid cursor state - no current row.
ij> select * from t1;
C11 |C12
-----------------------
2 |23
ij> next jdk4;
C11 |C12
-----------------------
2 |23
ij> delete from t1 where current of jdk4;
1 row inserted/updated/deleted
ij> select * from t1;
C11 |C12
-----------------------
ij> close jdk4;
ij> delete from t1 where current of jdk4;
ERROR 42X30: Cursor 'JDK4' not found. Verify that autocommit is off.
ij> select * from t1;
C11 |C12
-----------------------
ij> -- populate the table for next test
insert into t1 values(1,1);
1 row inserted/updated/deleted
ij> insert into t1 values(2,2);
1 row inserted/updated/deleted
ij> -- eighth test - scrollable cursors
get scroll insensitive with hold cursor jdk4 as 'SELECT * FROM t1';
ij> commit;
ij> previous jdk4;
No current row
ij> after last jdk4;
No current row
ij> before first jdk4;
No current row
ij> first jdk4;
C11 |C12
-----------------------
1 |1
ij> last jdk4;
C11 |C12
-----------------------
2 |2
ij> next jdk4;
No current row
ij> previous jdk4;
C11 |C12
-----------------------
2 |2
ij> next jdk4;
No current row
ij> close jdk4;
ij> first jdk4;
IJ ERROR: Unable to establish cursor JDK4@CONNECTION0
ij> -- ninth test - close the updateable holdable cursor after commit
-- we get npe
get with hold cursor jdk4 as 'SELECT * FROM T1 FOR UPDATE';
ij> next jdk4;
C11 |C12
-----------------------
1 |1
ij> commit;
ij> close jdk4;
ij> -- tenth test - bug 4515 - have a more useful message
-- update where current of fails in autocommit=true, held open cursor
autocommit on;
ij> get with hold cursor scrollCursor as 'select * from t1 for update of c12';
ij> next scrollCursor;
C11 |C12
-----------------------
1 |1
ij> -- commented out for DERBY-4778
-- update t1 set c12=c12+1 where current of scrollCursor;
-- clean up.
close scrollCursor;
ij> drop table t1;
0 rows inserted/updated/deleted
ij>
|