| 1 |
# 2015-05-11 |
| 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 |
# Quick tests for the sqldiff tool |
| 13 |
# |
| 14 |
set testdir [file dirname $argv0] |
| 15 |
source $testdir/tester.tcl |
| 16 |
|
| 17 |
set PROG [test_find_sqldiff] |
| 18 |
|
| 19 |
db close |
| 20 |
forcedelete test.db test2.db |
| 21 |
sqlite3 db test.db |
| 22 |
|
| 23 |
do_test sqldiff-1.0 { |
| 24 |
db eval { |
| 25 |
CREATE TABLE t1(a INTEGER PRIMARY KEY, b); |
| 26 |
CREATE TABLE t2(a INT PRIMARY KEY, b) WITHOUT ROWID; |
| 27 |
WITH RECURSIVE c(x) AS (VALUES(1) UNION ALL SELECT x+1 FROM c WHERE x<100) |
| 28 |
INSERT INTO t1(a,b) SELECT x, printf('abc-%d-xyz',x) FROM c; |
| 29 |
INSERT INTO t2(a,b) SELECT a, b FROM t1; |
| 30 |
} |
| 31 |
db backup test2.db |
| 32 |
db eval { |
| 33 |
ATTACH 'test2.db' AS x2; |
| 34 |
DELETE FROM x2.t1 WHERE a=49; |
| 35 |
DELETE FROM x2.t2 WHERE a=48; |
| 36 |
INSERT INTO x2.t1(a,b) VALUES(1234,'hello'); |
| 37 |
INSERT INTO x2.t2(a,b) VALUES(50.5,'xyzzy'); |
| 38 |
INSERT INTO x2.t2(a,b) VALUES(51.5,''); |
| 39 |
INSERT INTO x2.t2(a,b) VALUES(52.5,''||X'0d0a'); |
| 40 |
INSERT INTO x2.t2(a,b) VALUES(53.5,'one'||X'0a0d'); |
| 41 |
INSERT INTO x2.t2(a,b) VALUES(54.5,'one'||X'0a'||'two'); |
| 42 |
CREATE TABLE x2.t3(a,b,c); |
| 43 |
INSERT INTO x2.t3 VALUES(111,222,333); |
| 44 |
CREATE TABLE main.t4(x,y,z); |
| 45 |
INSERT INTO t4 SELECT * FROM t3; |
| 46 |
} |
| 47 |
set line "exec $PROG test.db test2.db" |
| 48 |
unset -nocomplain ::MSG |
| 49 |
catch {eval $line} ::MSG |
| 50 |
} {0} |
| 51 |
do_test sqldiff-1.1 { |
| 52 |
set ::MSG |
| 53 |
} {DELETE FROM t1 WHERE a=49; |
| 54 |
INSERT INTO t1(a,b) VALUES(1234,'hello'); |
| 55 |
DELETE FROM t2 WHERE a=48; |
| 56 |
INSERT INTO t2(a,b) VALUES(50.5,'xyzzy'); |
| 57 |
INSERT INTO t2(a,b) VALUES(51.5,''); |
| 58 |
INSERT INTO t2(a,b) VALUES(52.5,''||X'0d0a'); |
| 59 |
INSERT INTO t2(a,b) VALUES(53.5,'one'||X'0a0d'); |
| 60 |
INSERT INTO t2(a,b) VALUES(54.5,'one'||X'0a' |
| 61 |
||'two'); |
| 62 |
CREATE TABLE t3(a,b,c); |
| 63 |
INSERT INTO t3(rowid,a,b,c) VALUES(1,111,222,333); |
| 64 |
DROP TABLE t4;} |
| 65 |
|
| 66 |
db close |
| 67 |
forcedelete test.db test2.db |
| 68 |
sqlite3 db test.db |
| 69 |
|
| 70 |
do_test sqldiff-2.0 { |
| 71 |
db eval { |
| 72 |
CREATE TABLE t1(a INTEGER PRIMARY KEY); |
| 73 |
} |
| 74 |
db close |
| 75 |
sqlite3 db test2.db |
| 76 |
db eval { |
| 77 |
CREATE TABLE t1(a INTEGER PRIMARY KEY, b); |
| 78 |
} |
| 79 |
db close |
| 80 |
set line "exec $PROG test.db test2.db" |
| 81 |
unset -nocomplain ::MSG |
| 82 |
catch {eval $line} ::MSG |
| 83 |
} {0} |
| 84 |
do_test sqldiff-2.1 { |
| 85 |
set ::MSG |
| 86 |
} {ALTER TABLE t1 ADD COLUMN b;} |
| 87 |
|
| 88 |
finish_test |