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
|
#!/usr/bin/env tarantool
test = require("sqltester")
test:plan(14)
--!./tcltestrunner.lua
-- 2005 August 24
--
-- The author disclaims copyright to this source code. In place of
-- a legal notice, here is a blessing:
--
-- May you do good and not evil.
-- May you find forgiveness for yourself and forgive others.
-- May you share freely, never taking more than you give.
--
-------------------------------------------------------------------------
-- This file implements regression tests for sql library. The
-- focus of this script is a test of the DELETE command.
--
-- ["set","testdir",[["file","dirname",["argv0"]]]]
-- ["source",[["testdir"],"\/tester.tcl"]]
testprefix = "delete4"
test:do_execsql_test(
1.1,
[[
CREATE TABLE t1(x INTEGER PRIMARY KEY, y INT );
INSERT INTO t1 VALUES(1, 0);
INSERT INTO t1 VALUES(2, 1);
INSERT INTO t1 VALUES(3, 0);
INSERT INTO t1 VALUES(4, 1);
INSERT INTO t1 VALUES(5, 0);
INSERT INTO t1 VALUES(6, 1);
INSERT INTO t1 VALUES(7, 0);
INSERT INTO t1 VALUES(8, 1);
]])
test:do_execsql_test(
1.2,
[[
DELETE FROM t1 WHERE y=1;
]])
test:do_execsql_test(
1.3,
[[
SELECT x FROM t1;
]], {
-- <1.3>
1, 3, 5, 7
-- </1.3>
})
---------------------------------------------------------------------------
--
--reset_db
test:do_execsql_test(
2.1,
[[
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(x INTEGER PRIMARY KEY, y INT , z SCALAR);
INSERT INTO t1 VALUES(1, 0, randomblob(200));
INSERT INTO t1 VALUES(2, 1, randomblob(200));
INSERT INTO t1 VALUES(3, 0, randomblob(200));
INSERT INTO t1 VALUES(4, 1, randomblob(200));
INSERT INTO t1 VALUES(5, 0, randomblob(200));
INSERT INTO t1 VALUES(6, 1, randomblob(200));
INSERT INTO t1 VALUES(7, 0, randomblob(200));
INSERT INTO t1 VALUES(8, 1, randomblob(200));
]])
test:do_execsql_test(
2.2,
[[
DELETE FROM t1 WHERE y=1;
]])
test:do_execsql_test(
2.3,
[[
SELECT x FROM t1;
]], {
-- <2.3>
1, 3, 5, 7
-- </2.3>
})
---------------------------------------------------------------------------
--
--reset_db
test:do_execsql_test(
3.1,
[[
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a INT , b INT , PRIMARY KEY(a, b));
INSERT INTO t1 VALUES(1, 2);
INSERT INTO t1 VALUES(2, 4);
INSERT INTO t1 VALUES(1, 5);
DELETE FROM t1 WHERE a=1;
SELECT * FROM t1;
]], {
-- <3.1>
2, 4
-- </3.1>
})
---------------------------------------------------------------------------
-- DELETE statement that uses the OR optimization
--
--reset_db
test:do_execsql_test(
3.1,
[[
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(i INTEGER PRIMARY KEY, a TEXT, b TEXT);
CREATE INDEX i1a ON t1(a);
CREATE INDEX i1b ON t1(b);
INSERT INTO t1 VALUES(1, 'one', 'i');
INSERT INTO t1 VALUES(2, 'two', 'ii');
INSERT INTO t1 VALUES(3, 'three', 'iii');
INSERT INTO t1 VALUES(4, 'four', 'iv');
INSERT INTO t1 VALUES(5, 'one', 'i');
INSERT INTO t1 VALUES(6, 'two', 'ii');
INSERT INTO t1 VALUES(7, 'three', 'iii');
INSERT INTO t1 VALUES(8, 'four', 'iv');
]], {
-- <3.1>
-- </3.1>
})
test:do_execsql_test(
3.2,
[[
DELETE FROM t1 WHERE a='two' OR b='iv';
]])
test:do_execsql_test(
3.3,
[[
SELECT i FROM t1 ORDER BY i;
]], {
-- <3.3>
1, 3, 5, 7
-- </3.3>
})
-- do_execsql_test 3.4 {
-- PRAGMA integrity_check;
-- } {ok}
-- Between 2015-09-14 and 2015-09-28, the following test cases would result
-- in corruption (wrong # of entries in index) due to a bug in the ONEPASS
-- optimization.
--
test:do_execsql_test(
4.1,
[[
DROP TABLE IF EXISTS t4;
CREATE TABLE t4(col0 INT PRIMARY KEY, col1 TEXT);
INSERT INTO t4 VALUES(14, 'abcde');
CREATE INDEX idx_t4_0 ON t4 (col1, col0);
DELETE FROM t4 WHERE col0=69 OR col0>7;
]], {
-- <4.1>
-- </4.1>
})
test:do_execsql_test(
4.2,
[[
DROP TABLE IF EXISTS t4;
CREATE TABLE t4(col0 INT PRIMARY KEY, col1 TEXT);
INSERT INTO t4 VALUES(14, 'abcde');
CREATE INDEX idx_t4_0 ON t4 (col1, col0);
DELETE FROM t4 WHERE col0=69 OR col0>7;
]], {
-- <4.2>
-- </4.2>
})
test:do_execsql_test(
4.11,
[[
DROP TABLE IF EXISTS t4;
CREATE TABLE t4(col0 INT , col1 TEXT, pk TEXT PRIMARY KEY);
INSERT INTO t4 VALUES(14, 'abcde','xyzzy');
CREATE INDEX idx_t4_0 ON t4 (col1, col0);
CREATE INDEX idx_t4_3 ON t4 (col0);
DELETE FROM t4 WHERE col0=69 OR col0>7;
]], {
-- <4.11>
-- </4.11>
})
test:do_execsql_test(
4.12,
[[
DROP TABLE IF EXISTS t4;
CREATE TABLE t4(col0 INT , col1 TEXT, pk TEXT PRIMARY KEY);
INSERT INTO t4 VALUES(14, 'abcde','xyzzy');
CREATE INDEX idx_t4_3 ON t4 (col0);
CREATE INDEX idx_t4_0 ON t4 (col1, col0);
DELETE FROM t4 WHERE col0=69 OR col0>7;
]], {
-- <4.12>
-- </4.12>
})
test:finish_test()
|