Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: third_party/sqlite/src/test/insert4.test

Issue 901033002: Import SQLite 3.8.7.4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Chromium changes to support SQLite 3.8.7.4. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # 2007 January 24 1 # 2007 January 24
2 # 2 #
3 # The author disclaims copyright to this source code. In place of 3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing: 4 # a legal notice, here is a blessing:
5 # 5 #
6 # May you do good and not evil. 6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others. 7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give. 8 # May you share freely, never taking more than you give.
9 # 9 #
10 #*********************************************************************** 10 #***********************************************************************
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 do_test insert4-1.1 { 47 do_test insert4-1.1 {
48 set sqlite3_xferopt_count 0 48 set sqlite3_xferopt_count 0
49 execsql { 49 execsql {
50 DELETE FROM t1; 50 DELETE FROM t1;
51 DELETE FROM t2; 51 DELETE FROM t2;
52 INSERT INTO t2 VALUES(9,1); 52 INSERT INTO t2 VALUES(9,1);
53 } 53 }
54 catchsql { 54 catchsql {
55 INSERT INTO t1 SELECT * FROM t2; 55 INSERT INTO t1 SELECT * FROM t2;
56 } 56 }
57 } {1 {constraint failed}} 57 } {1 {CHECK constraint failed: t1}}
58 xferopt_test insert4-1.2 0 58 xferopt_test insert4-1.2 0
59 do_test insert4-1.3 { 59 do_test insert4-1.3 {
60 execsql { 60 execsql {
61 SELECT * FROM t1; 61 SELECT * FROM t1;
62 } 62 }
63 } {} 63 } {}
64 64
65 # Tests to make sure that the transfer optimization is not occurring 65 # Tests to make sure that the transfer optimization is not occurring
66 # when it is not a valid optimization. 66 # when it is not a valid optimization.
67 # 67 #
(...skipping 26 matching lines...) Expand all
94 SELECT * FROM t3; 94 SELECT * FROM t3;
95 } 95 }
96 } {9 1} 96 } {9 1}
97 xferopt_test insert4-2.3.2 0 97 xferopt_test insert4-2.3.2 0
98 do_test insert4-2.3.3 { 98 do_test insert4-2.3.3 {
99 catchsql { 99 catchsql {
100 DELETE FROM t1; 100 DELETE FROM t1;
101 INSERT INTO t1 SELECT * FROM t2 LIMIT 1; 101 INSERT INTO t1 SELECT * FROM t2 LIMIT 1;
102 SELECT * FROM t1; 102 SELECT * FROM t1;
103 } 103 }
104 } {1 {constraint failed}} 104 } {1 {CHECK constraint failed: t1}}
105 xferopt_test insert4-2.3.4 0 105 xferopt_test insert4-2.3.4 0
106 106
107 # Do not run the transfer optimization if there is a DISTINCT 107 # Do not run the transfer optimization if there is a DISTINCT
108 # 108 #
109 do_test insert4-2.4.1 { 109 do_test insert4-2.4.1 {
110 execsql { 110 execsql {
111 DELETE FROM t3; 111 DELETE FROM t3;
112 INSERT INTO t3 SELECT DISTINCT * FROM t2; 112 INSERT INTO t3 SELECT DISTINCT * FROM t2;
113 SELECT * FROM t3; 113 SELECT * FROM t3;
114 } 114 }
115 } {1 9 9 1} 115 } {9 1 1 9}
116 xferopt_test insert4-2.4.2 0 116 xferopt_test insert4-2.4.2 0
117 do_test insert4-2.4.3 { 117 do_test insert4-2.4.3 {
118 catchsql { 118 catchsql {
119 DELETE FROM t1; 119 DELETE FROM t1;
120 INSERT INTO t1 SELECT DISTINCT * FROM t2; 120 INSERT INTO t1 SELECT DISTINCT * FROM t2;
121 } 121 }
122 } {1 {constraint failed}} 122 } {1 {CHECK constraint failed: t1}}
123 xferopt_test insert4-2.4.4 0 123 xferopt_test insert4-2.4.4 0
124 124
125 # The following procedure constructs two tables then tries to transfer 125 # The following procedure constructs two tables then tries to transfer
126 # data from one table to the other. Checks are made to make sure the 126 # data from one table to the other. Checks are made to make sure the
127 # transfer is successful and that the transfer optimization was used or 127 # transfer is successful and that the transfer optimization was used or
128 # not, as appropriate. 128 # not, as appropriate.
129 # 129 #
130 # xfer_check TESTID XFER-USED INIT-DATA DEST-SCHEMA SRC-SCHEMA 130 # xfer_check TESTID XFER-USED INIT-DATA DEST-SCHEMA SRC-SCHEMA
131 # 131 #
132 # The TESTID argument is the symbolic name for this test. The XFER-USED 132 # The TESTID argument is the symbolic name for this test. The XFER-USED
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 INSERT INTO t4 VALUES(NULL,1); 246 INSERT INTO t4 VALUES(NULL,1);
247 VACUUM; 247 VACUUM;
248 } 248 }
249 } {} 249 } {}
250 } 250 }
251 251
252 # Check some error conditions: 252 # Check some error conditions:
253 # 253 #
254 do_test insert4-5.1 { 254 do_test insert4-5.1 {
255 # Table does not exist. 255 # Table does not exist.
256 catchsql { INSERT INTO t2 SELECT * FROM nosuchtable } 256 catchsql { INSERT INTO t2 SELECT a, b FROM nosuchtable }
257 } {1 {no such table: nosuchtable}} 257 } {1 {no such table: nosuchtable}}
258 do_test insert4-5.2 { 258 do_test insert4-5.2 {
259 # Number of columns does not match. 259 # Number of columns does not match.
260 catchsql { 260 catchsql {
261 CREATE TABLE t5(a, b, c); 261 CREATE TABLE t5(a, b, c);
262 INSERT INTO t4 SELECT * FROM t5; 262 INSERT INTO t4 SELECT * FROM t5;
263 } 263 }
264 } {1 {table t4 has 2 columns but 3 values were supplied}} 264 } {1 {table t4 has 2 columns but 3 values were supplied}}
265 265
266 do_test insert4-6.1 { 266 do_test insert4-6.1 {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 SELECT * FROM t6a; 308 SELECT * FROM t6a;
309 } 309 }
310 } {ABC} 310 } {ABC}
311 do_test insert4-6.6 { 311 do_test insert4-6.6 {
312 execsql { 312 execsql {
313 CREATE TABLE t6b(x CHECK( x<>'abc' COLLATE nocase )); 313 CREATE TABLE t6b(x CHECK( x<>'abc' COLLATE nocase ));
314 } 314 }
315 catchsql { 315 catchsql {
316 INSERT INTO t6b SELECT * FROM t6a; 316 INSERT INTO t6b SELECT * FROM t6a;
317 } 317 }
318 } {1 {constraint failed}} 318 } {1 {CHECK constraint failed: t6b}}
319 do_test insert4-6.7 { 319 do_test insert4-6.7 {
320 execsql { 320 execsql {
321 DROP TABLE t6b; 321 DROP TABLE t6b;
322 CREATE TABLE t6b(x CHECK( x COLLATE nocase <>'abc' )); 322 CREATE TABLE t6b(x CHECK( x COLLATE nocase <>'abc' ));
323 } 323 }
324 catchsql { 324 catchsql {
325 INSERT INTO t6b SELECT * FROM t6a; 325 INSERT INTO t6b SELECT * FROM t6a;
326 } 326 }
327 } {1 {constraint failed}} 327 } {1 {CHECK constraint failed: t6b}}
328
329 # Ticket [6284df89debdfa61db8073e062908af0c9b6118e]
330 # Disable the xfer optimization if the destination table contains
331 # a foreign key constraint
332 #
333 ifcapable foreignkey {
334 do_test insert4-7.1 {
335 set ::sqlite3_xferopt_count 0
336 execsql {
337 CREATE TABLE t7a(x INTEGER PRIMARY KEY); INSERT INTO t7a VALUES(123);
338 CREATE TABLE t7b(y INTEGER REFERENCES t7a);
339 CREATE TABLE t7c(z INT); INSERT INTO t7c VALUES(234);
340 INSERT INTO t7b SELECT * FROM t7c;
341 SELECT * FROM t7b;
342 }
343 } {234}
344 do_test insert4-7.2 {
345 set ::sqlite3_xferopt_count
346 } {1}
347 do_test insert4-7.3 {
348 set ::sqlite3_xferopt_count 0
349 execsql {
350 DELETE FROM t7b;
351 PRAGMA foreign_keys=ON;
352 }
353 catchsql {
354 INSERT INTO t7b SELECT * FROM t7c;
355 }
356 } {1 {FOREIGN KEY constraint failed}}
357 do_test insert4-7.4 {
358 execsql {SELECT * FROM t7b}
359 } {}
360 do_test insert4-7.5 {
361 set ::sqlite3_xferopt_count
362 } {0}
363 do_test insert4-7.6 {
364 set ::sqlite3_xferopt_count 0
365 execsql {
366 DELETE FROM t7b; DELETE FROM t7c;
367 INSERT INTO t7c VALUES(123);
368 INSERT INTO t7b SELECT * FROM t7c;
369 SELECT * FROM t7b;
370 }
371 } {123}
372 do_test insert4-7.7 {
373 set ::sqlite3_xferopt_count
374 } {0}
375 do_test insert4-7.7 {
376 set ::sqlite3_xferopt_count 0
377 execsql {
378 PRAGMA foreign_keys=OFF;
379 DELETE FROM t7b;
380 INSERT INTO t7b SELECT * FROM t7c;
381 SELECT * FROM t7b;
382 }
383 } {123}
384 do_test insert4-7.8 {
385 set ::sqlite3_xferopt_count
386 } {1}
387 }
388
389 # Ticket [676bc02b87176125635cb174d110b431581912bb]
390 # Make sure INTEGER PRIMARY KEY ON CONFLICT ... works with the xfer
391 # optimization.
392 #
393 do_test insert4-8.1 {
394 execsql {
395 DROP TABLE IF EXISTS t1;
396 DROP TABLE IF EXISTS t2;
397 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
398 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT REPLACE, y);
399 INSERT INTO t1 VALUES(1,2);
400 INSERT INTO t2 VALUES(1,3);
401 INSERT INTO t1 SELECT * FROM t2;
402 SELECT * FROM t1;
403 }
404 } {1 3}
405 do_test insert4-8.2 {
406 execsql {
407 DROP TABLE IF EXISTS t1;
408 DROP TABLE IF EXISTS t2;
409 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
410 CREATE TABLE t2(x, y);
411 INSERT INTO t1 VALUES(1,2);
412 INSERT INTO t2 VALUES(1,3);
413 INSERT INTO t1 SELECT * FROM t2;
414 SELECT * FROM t1;
415 }
416 } {1 3}
417 do_test insert4-8.3 {
418 execsql {
419 DROP TABLE IF EXISTS t1;
420 DROP TABLE IF EXISTS t2;
421 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE, b);
422 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT IGNORE, y);
423 INSERT INTO t1 VALUES(1,2);
424 INSERT INTO t2 VALUES(1,3);
425 INSERT INTO t1 SELECT * FROM t2;
426 SELECT * FROM t1;
427 }
428 } {1 2}
429 do_test insert4-8.4 {
430 execsql {
431 DROP TABLE IF EXISTS t1;
432 DROP TABLE IF EXISTS t2;
433 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE, b);
434 CREATE TABLE t2(x, y);
435 INSERT INTO t1 VALUES(1,2);
436 INSERT INTO t2 VALUES(1,3);
437 INSERT INTO t1 SELECT * FROM t2;
438 SELECT * FROM t1;
439 }
440 } {1 2}
441 do_test insert4-8.5 {
442 execsql {
443 DROP TABLE IF EXISTS t1;
444 DROP TABLE IF EXISTS t2;
445 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT FAIL, b);
446 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT FAIL, y);
447 INSERT INTO t1 VALUES(1,2);
448 INSERT INTO t2 VALUES(-99,100);
449 INSERT INTO t2 VALUES(1,3);
450 SELECT * FROM t1;
451 }
452 catchsql {
453 INSERT INTO t1 SELECT * FROM t2;
454 }
455 } {1 {UNIQUE constraint failed: t1.a}}
456 do_test insert4-8.6 {
457 execsql {
458 SELECT * FROM t1;
459 }
460 } {-99 100 1 2}
461 do_test insert4-8.7 {
462 execsql {
463 DROP TABLE IF EXISTS t1;
464 DROP TABLE IF EXISTS t2;
465 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ABORT, b);
466 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ABORT, y);
467 INSERT INTO t1 VALUES(1,2);
468 INSERT INTO t2 VALUES(-99,100);
469 INSERT INTO t2 VALUES(1,3);
470 SELECT * FROM t1;
471 }
472 catchsql {
473 INSERT INTO t1 SELECT * FROM t2;
474 }
475 } {1 {UNIQUE constraint failed: t1.a}}
476 do_test insert4-8.8 {
477 execsql {
478 SELECT * FROM t1;
479 }
480 } {1 2}
481 do_test insert4-8.9 {
482 execsql {
483 DROP TABLE IF EXISTS t1;
484 DROP TABLE IF EXISTS t2;
485 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, b);
486 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, y);
487 INSERT INTO t1 VALUES(1,2);
488 INSERT INTO t2 VALUES(-99,100);
489 INSERT INTO t2 VALUES(1,3);
490 SELECT * FROM t1;
491 }
492 catchsql {
493 BEGIN;
494 INSERT INTO t1 VALUES(2,3);
495 INSERT INTO t1 SELECT * FROM t2;
496 }
497 } {1 {UNIQUE constraint failed: t1.a}}
498 do_test insert4-8.10 {
499 catchsql {COMMIT}
500 } {1 {cannot commit - no transaction is active}}
501 do_test insert4-8.11 {
502 execsql {
503 SELECT * FROM t1;
504 }
505 } {1 2}
506
507 do_test insert4-8.21 {
508 execsql {
509 DROP TABLE IF EXISTS t1;
510 DROP TABLE IF EXISTS t2;
511 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT REPLACE, b);
512 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT REPLACE, y);
513 INSERT INTO t2 VALUES(1,3);
514 INSERT INTO t1 SELECT * FROM t2;
515 SELECT * FROM t1;
516 }
517 } {1 3}
518 do_test insert4-8.22 {
519 execsql {
520 DROP TABLE IF EXISTS t1;
521 DROP TABLE IF EXISTS t2;
522 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT IGNORE, b);
523 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT IGNORE, y);
524 INSERT INTO t2 VALUES(1,3);
525 INSERT INTO t1 SELECT * FROM t2;
526 SELECT * FROM t1;
527 }
528 } {1 3}
529 do_test insert4-8.23 {
530 execsql {
531 DROP TABLE IF EXISTS t1;
532 DROP TABLE IF EXISTS t2;
533 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ABORT, b);
534 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ABORT, y);
535 INSERT INTO t2 VALUES(1,3);
536 INSERT INTO t1 SELECT * FROM t2;
537 SELECT * FROM t1;
538 }
539 } {1 3}
540 do_test insert4-8.24 {
541 execsql {
542 DROP TABLE IF EXISTS t1;
543 DROP TABLE IF EXISTS t2;
544 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT FAIL, b);
545 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT FAIL, y);
546 INSERT INTO t2 VALUES(1,3);
547 INSERT INTO t1 SELECT * FROM t2;
548 SELECT * FROM t1;
549 }
550 } {1 3}
551 do_test insert4-8.25 {
552 execsql {
553 DROP TABLE IF EXISTS t1;
554 DROP TABLE IF EXISTS t2;
555 CREATE TABLE t1(a INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, b);
556 CREATE TABLE t2(x INTEGER PRIMARY KEY ON CONFLICT ROLLBACK, y);
557 INSERT INTO t2 VALUES(1,3);
558 INSERT INTO t1 SELECT * FROM t2;
559 SELECT * FROM t1;
560 }
561 } {1 3}
562
328 563
329 finish_test 564 finish_test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698