-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsql_test.sh
executable file
·69 lines (65 loc) · 2.54 KB
/
sql_test.sh
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
# sqlite3 :memory: <<EOF
# CREATE TABLE IF NOT EXISTS ticks (time INTEGER PRIMARY KEY ASC, labels TEXT);
# CREATE TABLE IF NOT EXISTS watches (last_write INTEGER PRIMARY KEY ASC, dir TEXT, label TEXT);
#
# INSERT INTO watches (last_write, dir, label) VALUES (1, "/test", "label 1");
# SELECT * FROM watches;
# INSERT INTO ticks (time, labels) VALUES (1, "label 1");
#
# BEGIN TRANSACTION;
# INSERT INTO ticks (time, labels) VALUES (2, "label 1");
# UPDATE watches SET last_write = 2 WHERE dir = "/test";
# COMMIT;
#
# BEGIN TRANSACTION;
# INSERT INTO ticks (time, labels) VALUES (3, "label 2");
# UPDATE watches SET last_write = 3 WHERE dir = "/test2";
# COMMIT;
#
# SELECT "--------------------------------";
# SELECT * FROM watches;
# SELECT "--------------------------------";
# SELECT * FROM ticks;
# SELECT "--------------------------------";
# EOF
#
# sqlite3 :memory: <<EOF
# CREATE TABLE IF NOT EXISTS watches (last_write INTEGER PRIMARY KEY ASC, dir TEXT, label TEXT);
#
# INSERT INTO watches (last_write, dir, label) VALUES (1, "/test", "label 1");
# INSERT INTO watches (last_write, dir, label) VALUES (2, "/test2", "label 1");
# INSERT INTO watches (last_write, dir, label) VALUES (3, "/test3", "label 1");
# INSERT INTO watches (last_write, dir, label) VALUES (4, "/test4", "label 1");
# INSERT INTO watches (last_write, dir, label) VALUES (5, "/test5", "label 1");
# SELECT * FROM watches;
#
# DELETE FROM watches
# WHERE dir IN (
# SELECT dir FROM watches
# LIMIT (SELECT COUNT(*) FROM watches) - 3);
#
# SELECT "--------------------------------";
# SELECT * FROM watches;
# EOF
sqlite3 :memory: <<EOF
CREATE TABLE IF NOT EXISTS watches (last_write INTEGER PRIMARY KEY ASC, dir TEXT, label TEXT);
INSERT INTO watches (last_write, dir, label) VALUES (1, "/test", "label 1");
INSERT INTO watches (last_write, dir, label) VALUES (2, "/test2", "label 1");
INSERT INTO watches (last_write, dir, label) VALUES (3, "/test3", "label 1");
INSERT INTO watches (last_write, dir, label) VALUES (4, "/test4", "label 1");
INSERT INTO watches (last_write, dir, label) VALUES (5, "/test5", "label 1");
SELECT * FROM watches;
SELECT "--------------------------------";
SELECT COUNT(*) FROM watches;
SELECT ((SELECT COUNT(*) FROM watches) - 8);
SELECT MAX(0, (SELECT COUNT(*) FROM watches) - 8);
SELECT dir FROM watches LIMIT MAX(0, (SELECT COUNT(*) FROM watches) - 8);
SELECT "--------------------------------";
DELETE FROM watches
WHERE dir IN (
SELECT dir FROM watches
LIMIT MAX(0, (SELECT COUNT(*) FROM watches) - 8)
);
SELECT * FROM watches;
SELECT "--------------------------------";
EOF