| OLD | NEW |
| (Empty) |
| 1 # 2008 Feb 19 | |
| 2 # | |
| 3 # The author disclaims copyright to this source code. In place of | |
| 4 # a legal notice, here is a blessing: | |
| 5 # | |
| 6 # May you do good and not evil. | |
| 7 # May you find forgiveness for yourself and forgive others. | |
| 8 # May you share freely, never taking more than you give. | |
| 9 # | |
| 10 #*********************************************************************** | |
| 11 # | |
| 12 # The focus of this file is testing the r-tree extension. | |
| 13 # | |
| 14 | |
| 15 if {![info exists testdir]} { | |
| 16 set testdir [file join [file dirname [info script]] .. .. test] | |
| 17 } | |
| 18 source [file join [file dirname [info script]] rtree_util.tcl] | |
| 19 source $testdir/tester.tcl | |
| 20 set testprefix rtree1 | |
| 21 | |
| 22 # Test plan: | |
| 23 # | |
| 24 # rtree-1.*: Creating/destroying r-tree tables. | |
| 25 # rtree-2.*: Test the implicit constraints - unique rowid and | |
| 26 # (coord[N]<=coord[N+1]) for even values of N. Also | |
| 27 # automatic assigning of rowid values. | |
| 28 # rtree-3.*: Linear scans of r-tree data. | |
| 29 # rtree-4.*: Test INSERT | |
| 30 # rtree-5.*: Test DELETE | |
| 31 # rtree-6.*: Test UPDATE | |
| 32 # rtree-7.*: Test renaming an r-tree table. | |
| 33 # rtree-8.*: Test constrained scans of r-tree data. | |
| 34 # | |
| 35 # rtree-12.*: Test that on-conflict clauses are supported. | |
| 36 # rtree-13.*: Test that bug [d2889096e7bdeac6d] has been fixed. | |
| 37 # rtree-14.*: Test if a non-integer is inserted into the PK column of an | |
| 38 # r-tree table, it is converted to an integer before being | |
| 39 # inserted. Also that if a non-numeric is inserted into one | |
| 40 # of the min/max dimension columns, it is converted to the | |
| 41 # required type before being inserted. | |
| 42 # | |
| 43 | |
| 44 ifcapable !rtree { | |
| 45 finish_test | |
| 46 return | |
| 47 } | |
| 48 | |
| 49 #---------------------------------------------------------------------------- | |
| 50 # Test cases rtree-1.* test CREATE and DROP table statements. | |
| 51 # | |
| 52 | |
| 53 # Test creating and dropping an rtree table. | |
| 54 # | |
| 55 do_test rtree-1.1.1 { | |
| 56 execsql { CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2) } | |
| 57 } {} | |
| 58 do_test rtree-1.1.2 { | |
| 59 execsql { SELECT name FROM sqlite_master ORDER BY name } | |
| 60 } {t1 t1_node t1_parent t1_rowid} | |
| 61 do_test rtree-1.1.3 { | |
| 62 execsql { | |
| 63 DROP TABLE t1; | |
| 64 SELECT name FROM sqlite_master ORDER BY name; | |
| 65 } | |
| 66 } {} | |
| 67 | |
| 68 # Test creating and dropping an rtree table with an odd name in | |
| 69 # an attached database. | |
| 70 # | |
| 71 do_test rtree-1.2.1 { | |
| 72 file delete -force test2.db | |
| 73 execsql { | |
| 74 ATTACH 'test2.db' AS aux; | |
| 75 CREATE VIRTUAL TABLE aux.'a" "b' USING rtree(ii, x1, x2, y1, y2); | |
| 76 } | |
| 77 } {} | |
| 78 do_test rtree-1.2.2 { | |
| 79 execsql { SELECT name FROM sqlite_master ORDER BY name } | |
| 80 } {} | |
| 81 do_test rtree-1.2.3 { | |
| 82 execsql { SELECT name FROM aux.sqlite_master ORDER BY name } | |
| 83 } {{a" "b} {a" "b_node} {a" "b_parent} {a" "b_rowid}} | |
| 84 do_test rtree-1.2.4 { | |
| 85 execsql { | |
| 86 DROP TABLE aux.'a" "b'; | |
| 87 SELECT name FROM aux.sqlite_master ORDER BY name; | |
| 88 } | |
| 89 } {} | |
| 90 | |
| 91 # Test that the logic for checking the number of columns specified | |
| 92 # for an rtree table. Acceptable values are odd numbers between 3 and | |
| 93 # 11, inclusive. | |
| 94 # | |
| 95 set cols [list i1 i2 i3 i4 i5 i6 i7 i8 i9 iA iB iC iD iE iF iG iH iI iJ iK] | |
| 96 for {set nCol 1} {$nCol<[llength $cols]} {incr nCol} { | |
| 97 | |
| 98 set columns [join [lrange $cols 0 [expr {$nCol-1}]] ,] | |
| 99 | |
| 100 set X {0 {}} | |
| 101 if {$nCol%2 == 0} { set X {1 {Wrong number of columns for an rtree table}} } | |
| 102 if {$nCol < 3} { set X {1 {Too few columns for an rtree table}} } | |
| 103 if {$nCol > 11} { set X {1 {Too many columns for an rtree table}} } | |
| 104 | |
| 105 do_test rtree-1.3.$nCol { | |
| 106 catchsql " | |
| 107 CREATE VIRTUAL TABLE t1 USING rtree($columns); | |
| 108 " | |
| 109 } $X | |
| 110 | |
| 111 catchsql { DROP TABLE t1 } | |
| 112 } | |
| 113 | |
| 114 # Like execsql except display output as integer where that can be | |
| 115 # done without loss of information. | |
| 116 # | |
| 117 proc execsql_intout {sql} { | |
| 118 set out {} | |
| 119 foreach term [execsql $sql] { | |
| 120 regsub {\.0$} $term {} term | |
| 121 lappend out $term | |
| 122 } | |
| 123 return $out | |
| 124 } | |
| 125 | |
| 126 # Test that it is possible to open an existing database that contains | |
| 127 # r-tree tables. | |
| 128 # | |
| 129 do_execsql_test rtree-1.4.1a { | |
| 130 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2); | |
| 131 INSERT INTO t1 VALUES(1, 5.0, 10.0); | |
| 132 SELECT substr(hex(data),1,40) FROM t1_node; | |
| 133 } {00000001000000000000000140A0000041200000} | |
| 134 do_execsql_test rtree-1.4.1b { | |
| 135 INSERT INTO t1 VALUES(2, 15.0, 20.0); | |
| 136 } {} | |
| 137 do_test rtree-1.4.2 { | |
| 138 db close | |
| 139 sqlite3 db test.db | |
| 140 execsql_intout { SELECT * FROM t1 ORDER BY ii } | |
| 141 } {1 5 10 2 15 20} | |
| 142 do_test rtree-1.4.3 { | |
| 143 execsql { DROP TABLE t1 } | |
| 144 } {} | |
| 145 | |
| 146 # Test that it is possible to create an r-tree table with ridiculous | |
| 147 # column names. | |
| 148 # | |
| 149 do_test rtree-1.5.1 { | |
| 150 execsql_intout { | |
| 151 CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim"); | |
| 152 INSERT INTO t1 VALUES(1, 2, 3); | |
| 153 SELECT "the key", "x dim.", "x2'dim" FROM t1; | |
| 154 } | |
| 155 } {1 2 3} | |
| 156 do_test rtree-1.5.1 { | |
| 157 execsql { DROP TABLE t1 } | |
| 158 } {} | |
| 159 | |
| 160 # Force the r-tree constructor to fail. | |
| 161 # | |
| 162 do_test rtree-1.6.1 { | |
| 163 execsql { CREATE TABLE t1_rowid(a); } | |
| 164 catchsql { | |
| 165 CREATE VIRTUAL TABLE t1 USING rtree("the key", "x dim.", "x2'dim"); | |
| 166 } | |
| 167 } {1 {table "t1_rowid" already exists}} | |
| 168 do_test rtree-1.6.1 { | |
| 169 execsql { DROP TABLE t1_rowid } | |
| 170 } {} | |
| 171 | |
| 172 #---------------------------------------------------------------------------- | |
| 173 # Test cases rtree-2.* | |
| 174 # | |
| 175 do_test rtree-2.1.1 { | |
| 176 execsql { | |
| 177 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2); | |
| 178 SELECT * FROM t1; | |
| 179 } | |
| 180 } {} | |
| 181 | |
| 182 do_test rtree-2.1.2 { | |
| 183 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) } | |
| 184 execsql_intout { SELECT * FROM t1 } | |
| 185 } {1 1 3 2 4} | |
| 186 do_test rtree-2.1.3 { | |
| 187 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) } | |
| 188 execsql { SELECT rowid FROM t1 ORDER BY rowid } | |
| 189 } {1 2} | |
| 190 do_test rtree-2.1.3 { | |
| 191 execsql { INSERT INTO t1 VALUES(NULL, 1, 3, 2, 4) } | |
| 192 execsql { SELECT ii FROM t1 ORDER BY ii } | |
| 193 } {1 2 3} | |
| 194 | |
| 195 do_test rtree-2.2.1 { | |
| 196 catchsql { INSERT INTO t1 VALUES(2, 1, 3, 2, 4) } | |
| 197 } {1 {constraint failed}} | |
| 198 do_test rtree-2.2.2 { | |
| 199 catchsql { INSERT INTO t1 VALUES(4, 1, 3, 4, 2) } | |
| 200 } {1 {constraint failed}} | |
| 201 do_test rtree-2.2.3 { | |
| 202 catchsql { INSERT INTO t1 VALUES(4, 3, 1, 2, 4) } | |
| 203 } {1 {constraint failed}} | |
| 204 do_test rtree-2.2.4 { | |
| 205 execsql { SELECT ii FROM t1 ORDER BY ii } | |
| 206 } {1 2 3} | |
| 207 | |
| 208 do_test rtree-2.X { | |
| 209 execsql { DROP TABLE t1 } | |
| 210 } {} | |
| 211 | |
| 212 #---------------------------------------------------------------------------- | |
| 213 # Test cases rtree-3.* test linear scans of r-tree table data. To test | |
| 214 # this we have to insert some data into an r-tree, but that is not the | |
| 215 # focus of these tests. | |
| 216 # | |
| 217 do_test rtree-3.1.1 { | |
| 218 execsql { | |
| 219 CREATE VIRTUAL TABLE t1 USING rtree(ii, x1, x2, y1, y2); | |
| 220 SELECT * FROM t1; | |
| 221 } | |
| 222 } {} | |
| 223 do_test rtree-3.1.2 { | |
| 224 execsql_intout { | |
| 225 INSERT INTO t1 VALUES(5, 1, 3, 2, 4); | |
| 226 SELECT * FROM t1; | |
| 227 } | |
| 228 } {5 1 3 2 4} | |
| 229 do_test rtree-3.1.3 { | |
| 230 execsql_intout { | |
| 231 INSERT INTO t1 VALUES(6, 2, 6, 4, 8); | |
| 232 SELECT * FROM t1; | |
| 233 } | |
| 234 } {5 1 3 2 4 6 2 6 4 8} | |
| 235 | |
| 236 # Test the constraint on the coordinates (c[i]<=c[i+1] where (i%2==0)): | |
| 237 do_test rtree-3.2.1 { | |
| 238 catchsql { INSERT INTO t1 VALUES(7, 2, 6, 4, 3) } | |
| 239 } {1 {constraint failed}} | |
| 240 do_test rtree-3.2.2 { | |
| 241 catchsql { INSERT INTO t1 VALUES(8, 2, 6, 3, 3) } | |
| 242 } {0 {}} | |
| 243 | |
| 244 #---------------------------------------------------------------------------- | |
| 245 # Test cases rtree-5.* test DELETE operations. | |
| 246 # | |
| 247 do_test rtree-5.1.1 { | |
| 248 execsql { CREATE VIRTUAL TABLE t2 USING rtree(ii, x1, x2) } | |
| 249 } {} | |
| 250 do_test rtree-5.1.2 { | |
| 251 execsql_intout { | |
| 252 INSERT INTO t2 VALUES(1, 10, 20); | |
| 253 INSERT INTO t2 VALUES(2, 30, 40); | |
| 254 INSERT INTO t2 VALUES(3, 50, 60); | |
| 255 SELECT * FROM t2 ORDER BY ii; | |
| 256 } | |
| 257 } {1 10 20 2 30 40 3 50 60} | |
| 258 do_test rtree-5.1.3 { | |
| 259 execsql_intout { | |
| 260 DELETE FROM t2 WHERE ii=2; | |
| 261 SELECT * FROM t2 ORDER BY ii; | |
| 262 } | |
| 263 } {1 10 20 3 50 60} | |
| 264 do_test rtree-5.1.4 { | |
| 265 execsql_intout { | |
| 266 DELETE FROM t2 WHERE ii=1; | |
| 267 SELECT * FROM t2 ORDER BY ii; | |
| 268 } | |
| 269 } {3 50 60} | |
| 270 do_test rtree-5.1.5 { | |
| 271 execsql { | |
| 272 DELETE FROM t2 WHERE ii=3; | |
| 273 SELECT * FROM t2 ORDER BY ii; | |
| 274 } | |
| 275 } {} | |
| 276 do_test rtree-5.1.6 { | |
| 277 execsql { SELECT * FROM t2_rowid } | |
| 278 } {} | |
| 279 | |
| 280 #---------------------------------------------------------------------------- | |
| 281 # Test cases rtree-5.* test UPDATE operations. | |
| 282 # | |
| 283 do_test rtree-6.1.1 { | |
| 284 execsql { CREATE VIRTUAL TABLE t3 USING rtree(ii, x1, x2, y1, y2) } | |
| 285 } {} | |
| 286 do_test rtree-6.1.2 { | |
| 287 execsql_intout { | |
| 288 INSERT INTO t3 VALUES(1, 2, 3, 4, 5); | |
| 289 UPDATE t3 SET x2=5; | |
| 290 SELECT * FROM t3; | |
| 291 } | |
| 292 } {1 2 5 4 5} | |
| 293 do_test rtree-6.1.3 { | |
| 294 execsql { UPDATE t3 SET ii = 2 } | |
| 295 execsql_intout { SELECT * FROM t3 } | |
| 296 } {2 2 5 4 5} | |
| 297 | |
| 298 #---------------------------------------------------------------------------- | |
| 299 # Test cases rtree-7.* test rename operations. | |
| 300 # | |
| 301 do_test rtree-7.1.1 { | |
| 302 execsql { | |
| 303 CREATE VIRTUAL TABLE t4 USING rtree(ii, x1, x2, y1, y2, z1, z2); | |
| 304 INSERT INTO t4 VALUES(1, 2, 3, 4, 5, 6, 7); | |
| 305 } | |
| 306 } {} | |
| 307 do_test rtree-7.1.2 { | |
| 308 execsql { ALTER TABLE t4 RENAME TO t5 } | |
| 309 execsql_intout { SELECT * FROM t5 } | |
| 310 } {1 2 3 4 5 6 7} | |
| 311 do_test rtree-7.1.3 { | |
| 312 db close | |
| 313 sqlite3 db test.db | |
| 314 execsql_intout { SELECT * FROM t5 } | |
| 315 } {1 2 3 4 5 6 7} | |
| 316 do_test rtree-7.1.4 { | |
| 317 execsql { ALTER TABLE t5 RENAME TO 'raisara "one"'''} | |
| 318 execsql_intout { SELECT * FROM "raisara ""one""'" } | |
| 319 } {1 2 3 4 5 6 7} | |
| 320 do_test rtree-7.1.5 { | |
| 321 execsql_intout { SELECT * FROM 'raisara "one"''' } | |
| 322 } {1 2 3 4 5 6 7} | |
| 323 do_test rtree-7.1.6 { | |
| 324 execsql { ALTER TABLE "raisara ""one""'" RENAME TO "abc 123" } | |
| 325 execsql_intout { SELECT * FROM "abc 123" } | |
| 326 } {1 2 3 4 5 6 7} | |
| 327 do_test rtree-7.1.7 { | |
| 328 db close | |
| 329 sqlite3 db test.db | |
| 330 execsql_intout { SELECT * FROM "abc 123" } | |
| 331 } {1 2 3 4 5 6 7} | |
| 332 | |
| 333 # An error midway through a rename operation. | |
| 334 do_test rtree-7.2.1 { | |
| 335 execsql { | |
| 336 CREATE TABLE t4_node(a); | |
| 337 } | |
| 338 catchsql { ALTER TABLE "abc 123" RENAME TO t4 } | |
| 339 } {1 {SQL logic error or missing database}} | |
| 340 do_test rtree-7.2.2 { | |
| 341 execsql_intout { SELECT * FROM "abc 123" } | |
| 342 } {1 2 3 4 5 6 7} | |
| 343 do_test rtree-7.2.3 { | |
| 344 execsql { | |
| 345 DROP TABLE t4_node; | |
| 346 CREATE TABLE t4_rowid(a); | |
| 347 } | |
| 348 catchsql { ALTER TABLE "abc 123" RENAME TO t4 } | |
| 349 } {1 {SQL logic error or missing database}} | |
| 350 do_test rtree-7.2.4 { | |
| 351 db close | |
| 352 sqlite3 db test.db | |
| 353 execsql_intout { SELECT * FROM "abc 123" } | |
| 354 } {1 2 3 4 5 6 7} | |
| 355 do_test rtree-7.2.5 { | |
| 356 execsql { DROP TABLE t4_rowid } | |
| 357 execsql { ALTER TABLE "abc 123" RENAME TO t4 } | |
| 358 execsql_intout { SELECT * FROM t4 } | |
| 359 } {1 2 3 4 5 6 7} | |
| 360 | |
| 361 | |
| 362 #---------------------------------------------------------------------------- | |
| 363 # Test cases rtree-8.* | |
| 364 # | |
| 365 | |
| 366 # Test that the function to determine if a leaf cell is part of the | |
| 367 # result set works. | |
| 368 do_test rtree-8.1.1 { | |
| 369 execsql { | |
| 370 CREATE VIRTUAL TABLE t6 USING rtree(ii, x1, x2); | |
| 371 INSERT INTO t6 VALUES(1, 3, 7); | |
| 372 INSERT INTO t6 VALUES(2, 4, 6); | |
| 373 } | |
| 374 } {} | |
| 375 do_test rtree-8.1.2 { execsql { SELECT ii FROM t6 WHERE x1>2 } } {1 2} | |
| 376 do_test rtree-8.1.3 { execsql { SELECT ii FROM t6 WHERE x1>3 } } {2} | |
| 377 do_test rtree-8.1.4 { execsql { SELECT ii FROM t6 WHERE x1>4 } } {} | |
| 378 do_test rtree-8.1.5 { execsql { SELECT ii FROM t6 WHERE x1>5 } } {} | |
| 379 do_test rtree-8.1.6 { execsql { SELECT ii FROM t6 WHERE x1<3 } } {} | |
| 380 do_test rtree-8.1.7 { execsql { SELECT ii FROM t6 WHERE x1<4 } } {1} | |
| 381 do_test rtree-8.1.8 { execsql { SELECT ii FROM t6 WHERE x1<5 } } {1 2} | |
| 382 | |
| 383 #---------------------------------------------------------------------------- | |
| 384 # Test cases rtree-9.* | |
| 385 # | |
| 386 # Test that ticket #3549 is fixed. | |
| 387 do_test rtree-9.1 { | |
| 388 execsql { | |
| 389 CREATE TABLE foo (id INTEGER PRIMARY KEY); | |
| 390 CREATE VIRTUAL TABLE bar USING rtree (id, minX, maxX, minY, maxY); | |
| 391 INSERT INTO foo VALUES (null); | |
| 392 INSERT INTO foo SELECT null FROM foo; | |
| 393 INSERT INTO foo SELECT null FROM foo; | |
| 394 INSERT INTO foo SELECT null FROM foo; | |
| 395 INSERT INTO foo SELECT null FROM foo; | |
| 396 INSERT INTO foo SELECT null FROM foo; | |
| 397 INSERT INTO foo SELECT null FROM foo; | |
| 398 DELETE FROM foo WHERE id > 40; | |
| 399 INSERT INTO bar SELECT NULL, 0, 0, 0, 0 FROM foo; | |
| 400 } | |
| 401 } {} | |
| 402 | |
| 403 # This used to crash. | |
| 404 do_test rtree-9.2 { | |
| 405 execsql { | |
| 406 SELECT count(*) FROM bar b1, bar b2, foo s1 WHERE s1.id = b1.id; | |
| 407 } | |
| 408 } {1600} | |
| 409 do_test rtree-9.3 { | |
| 410 execsql { | |
| 411 SELECT count(*) FROM bar b1, bar b2, foo s1 | |
| 412 WHERE b1.minX <= b2.maxX AND s1.id = b1.id; | |
| 413 } | |
| 414 } {1600} | |
| 415 | |
| 416 #------------------------------------------------------------------------- | |
| 417 # Ticket #3970: Check that the error message is meaningful when a | |
| 418 # keyword is used as a column name. | |
| 419 # | |
| 420 do_test rtree-10.1 { | |
| 421 catchsql { CREATE VIRTUAL TABLE t7 USING rtree(index, x1, y1, x2, y2) } | |
| 422 } {1 {near "index": syntax error}} | |
| 423 | |
| 424 #------------------------------------------------------------------------- | |
| 425 # Test last_insert_rowid(). | |
| 426 # | |
| 427 do_test rtree-11.1 { | |
| 428 execsql { | |
| 429 CREATE VIRTUAL TABLE t8 USING rtree(idx, x1, x2, y1, y2); | |
| 430 INSERT INTO t8 VALUES(1, 1.0, 1.0, 2.0, 2.0); | |
| 431 SELECT last_insert_rowid(); | |
| 432 } | |
| 433 } {1} | |
| 434 do_test rtree-11.2 { | |
| 435 execsql { | |
| 436 INSERT INTO t8 VALUES(NULL, 1.0, 1.0, 2.0, 2.0); | |
| 437 SELECT last_insert_rowid(); | |
| 438 } | |
| 439 } {2} | |
| 440 | |
| 441 #------------------------------------------------------------------------- | |
| 442 # Test on-conflict clause handling. | |
| 443 # | |
| 444 db_delete_and_reopen | |
| 445 do_execsql_test 12.0.1 { | |
| 446 CREATE VIRTUAL TABLE t1 USING rtree_i32(idx, x1, x2, y1, y2); | |
| 447 INSERT INTO t1 VALUES(1, 1, 2, 3, 4); | |
| 448 SELECT substr(hex(data),1,56) FROM t1_node; | |
| 449 } {00000001000000000000000100000001000000020000000300000004} | |
| 450 do_execsql_test 12.0.2 { | |
| 451 INSERT INTO t1 VALUES(2, 2, 3, 4, 5); | |
| 452 INSERT INTO t1 VALUES(3, 3, 4, 5, 6); | |
| 453 | |
| 454 CREATE TABLE source(idx, x1, x2, y1, y2); | |
| 455 INSERT INTO source VALUES(5, 8, 8, 8, 8); | |
| 456 INSERT INTO source VALUES(2, 7, 7, 7, 7); | |
| 457 } | |
| 458 db_save_and_close | |
| 459 foreach {tn sql_template testdata} { | |
| 460 1 "INSERT %CONF% INTO t1 VALUES(2, 7, 7, 7, 7)" { | |
| 461 ROLLBACK 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} | |
| 462 ABORT 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 463 IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 464 FAIL 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 465 REPLACE 0 0 {1 1 2 3 4 2 7 7 7 7 3 3 4 5 6 4 4 5 6 7} | |
| 466 } | |
| 467 | |
| 468 2 "INSERT %CONF% INTO t1 SELECT * FROM source" { | |
| 469 ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} | |
| 470 ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 471 IGNORE 1 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7 5 8 8 8 8} | |
| 472 FAIL 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7 5 8 8 8 8} | |
| 473 REPLACE 1 0 {1 1 2 3 4 2 7 7 7 7 3 3 4 5 6 4 4 5 6 7 5 8 8 8 8} | |
| 474 } | |
| 475 | |
| 476 3 "UPDATE %CONF% t1 SET idx = 2 WHERE idx = 4" { | |
| 477 ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} | |
| 478 ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 479 IGNORE 1 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 480 FAIL 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 481 REPLACE 1 0 {1 1 2 3 4 2 4 5 6 7 3 3 4 5 6} | |
| 482 } | |
| 483 | |
| 484 3 "UPDATE %CONF% t1 SET idx = ((idx+1)%5)+1 WHERE idx > 2" { | |
| 485 ROLLBACK 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} | |
| 486 ABORT 1 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 487 IGNORE 1 0 {1 1 2 3 4 2 2 3 4 5 4 4 5 6 7 5 3 4 5 6} | |
| 488 FAIL 1 1 {1 1 2 3 4 2 2 3 4 5 4 4 5 6 7 5 3 4 5 6} | |
| 489 REPLACE 1 0 {1 4 5 6 7 2 2 3 4 5 5 3 4 5 6} | |
| 490 } | |
| 491 | |
| 492 4 "INSERT %CONF% INTO t1 VALUES(2, 7, 6, 7, 7)" { | |
| 493 ROLLBACK 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6} | |
| 494 ABORT 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 495 IGNORE 0 0 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 496 FAIL 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 497 REPLACE 0 1 {1 1 2 3 4 2 2 3 4 5 3 3 4 5 6 4 4 5 6 7} | |
| 498 } | |
| 499 | |
| 500 } { | |
| 501 foreach {mode uses error data} $testdata { | |
| 502 db_restore_and_reopen | |
| 503 | |
| 504 set sql [string map [list %CONF% "OR $mode"] $sql_template] | |
| 505 set testname "12.$tn.[string tolower $mode]" | |
| 506 | |
| 507 execsql { | |
| 508 BEGIN; | |
| 509 INSERT INTO t1 VALUES(4, 4, 5, 6, 7); | |
| 510 } | |
| 511 | |
| 512 set res(0) {0 {}} | |
| 513 set res(1) {1 {constraint failed}} | |
| 514 do_catchsql_test $testname.1 $sql $res($error) | |
| 515 do_test $testname.2 [list sql_uses_stmt db $sql] $uses | |
| 516 do_execsql_test $testname.3 { SELECT * FROM t1 ORDER BY idx } $data | |
| 517 | |
| 518 do_test $testname.4 { rtree_check db t1 } 0 | |
| 519 db close | |
| 520 } | |
| 521 } | |
| 522 | |
| 523 #------------------------------------------------------------------------- | |
| 524 # Test that bug [d2889096e7bdeac6d] has been fixed. | |
| 525 # | |
| 526 reset_db | |
| 527 do_execsql_test 13.1 { | |
| 528 CREATE VIRTUAL TABLE t9 USING rtree(id, xmin, xmax); | |
| 529 INSERT INTO t9 VALUES(1,0,0); | |
| 530 INSERT INTO t9 VALUES(2,0,0); | |
| 531 SELECT * FROM t9 WHERE id IN (1, 2); | |
| 532 } {1 0.0 0.0 2 0.0 0.0} | |
| 533 | |
| 534 do_execsql_test 13.2 { | |
| 535 WITH r(x) AS ( | |
| 536 SELECT 1 UNION ALL | |
| 537 SELECT 2 UNION ALL | |
| 538 SELECT 3 | |
| 539 ) | |
| 540 SELECT * FROM r CROSS JOIN t9 WHERE id=x; | |
| 541 } {1 1 0.0 0.0 2 2 0.0 0.0} | |
| 542 | |
| 543 #------------------------------------------------------------------------- | |
| 544 # Test if a non-integer is inserted into the PK column of an r-tree | |
| 545 # table, it is converted to an integer before being inserted. Also | |
| 546 # that if a non-numeric is inserted into one of the min/max dimension | |
| 547 # columns, it is converted to the required type before being inserted. | |
| 548 # | |
| 549 do_execsql_test 14.1 { | |
| 550 CREATE VIRTUAL TABLE t10 USING rtree(ii, x1, x2); | |
| 551 } | |
| 552 | |
| 553 do_execsql_test 14.2 { | |
| 554 INSERT INTO t10 VALUES(NULL, 1, 2); | |
| 555 INSERT INTO t10 VALUES(NULL, 2, 3); | |
| 556 INSERT INTO t10 VALUES('4xxx', 3, 4); | |
| 557 INSERT INTO t10 VALUES(5.0, 4, 5); | |
| 558 INSERT INTO t10 VALUES(6.4, 5, 6); | |
| 559 } | |
| 560 do_execsql_test 14.3 { | |
| 561 SELECT * FROM t10; | |
| 562 } { | |
| 563 1 1.0 2.0 2 2.0 3.0 4 3.0 4.0 5 4.0 5.0 6 5.0 6.0 | |
| 564 } | |
| 565 | |
| 566 do_execsql_test 14.4 { | |
| 567 DELETE FROM t10; | |
| 568 INSERT INTO t10 VALUES(1, 'one', 'two'); | |
| 569 INSERT INTO t10 VALUES(2, '52xyz', '81...'); | |
| 570 } | |
| 571 do_execsql_test 14.5 { | |
| 572 SELECT * FROM t10; | |
| 573 } { | |
| 574 1 0.0 0.0 | |
| 575 2 52.0 81.0 | |
| 576 } | |
| 577 | |
| 578 do_execsql_test 14.4 { | |
| 579 DROP TABLE t10; | |
| 580 CREATE VIRTUAL TABLE t10 USING rtree_i32(ii, x1, x2); | |
| 581 INSERT INTO t10 VALUES(1, 'one', 'two'); | |
| 582 INSERT INTO t10 VALUES(2, '52xyz', '81...'); | |
| 583 INSERT INTO t10 VALUES(3, 42.3, 49.9); | |
| 584 } | |
| 585 do_execsql_test 14.5 { | |
| 586 SELECT * FROM t10; | |
| 587 } { | |
| 588 1 0 0 | |
| 589 2 52 81 | |
| 590 3 42 49 | |
| 591 } | |
| 592 | |
| 593 finish_test | |
| OLD | NEW |