summaryrefslogtreecommitdiff
path: root/test/dotcmd01.sql
blob: 70b96e3f831528b0b0fcf4cd94aac3440802d211 (plain) (blame)
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
#!sqlite3
#
# 2026-01-30
#
# 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.
#
#***********************************************************************
#
# Miscellaneous tests for dot-commands
#
#   ./sqlite3 test/dotcmd01.sql
#
.open :memory:
.mode -reset quote
.if NOT capable('vtab')
.testcase setup
.check
.exit
.endif

.testcase setup
.open :memory:
.mode tty
.check

# The ".eqp on" setting does not affect the output from .fullschema
# and similar.
#
.testctrl opt -Stat4
.testcase 100
CREATE TABLE t1(a,b,c);
WITH RECURSIVE c(n) AS (VALUES(1) UNION ALL SELECT n+1 FROM c WHERE n<300)
  INSERT INTO t1(a,b,c)
    SELECT n%10, n%30, n%100 FROM c;
CREATE INDEX t1a ON t1(a);
CREATE INDEX t1b ON t1(b);
ANALYZE;
.eqp on
.fullschema
.check <<END
CREATE TABLE t1(a,b,c);
CREATE INDEX t1a ON t1(a);
CREATE INDEX t1b ON t1(b);
ANALYZE sqlite_schema;
INSERT INTO sqlite_stat1 VALUES('t1','t1b','300 10'),
  ('t1','t1a','300 30');
ANALYZE sqlite_schema;
END

.testcase 110
.schema
.check <<END
CREATE TABLE t1(a,b,c);
CREATE INDEX t1a ON t1(a);
CREATE INDEX t1b ON t1(b);
CREATE TABLE sqlite_stat1(tbl,idx,stat);
END

.testcase 120
.tables
.check --glob t1

.testcase 130
.indexes
.check --glob t1a*t1b

# The default comparison for ".check" ignores leading and trailing
# whitespace.  Each interior whitespace character compares equal to exactly
# one whitespace character at the same position in the other string.  A
# whitespace character never matches a character that is not whitespace.
#
.mode --reset list
.testcase 200
SELECT 'a'||char(10)||'b';
.check a b --keep
.check ' a b '
.testcase 201
SELECT '  a'||char(9)||'b  '||char(10);
.check a b
.testcase 202
SELECT 'a   b';
.check --not 'a b'
.testcase 203
SELECT 'a b';
.check --not 'a   b'
.testcase 204
SELECT 'a b';
.check --not 'a/b'
.testcase 205
SELECT 'a/b';
.check --not a b
.testcase 206
SELECT 'ab';
.check --not 'a b'
.testcase 207
SELECT 'a b';
.check --not 'ab'
.testcase 208
SELECT 'a b';
.check --not 'a b c'
.testcase 209
SELECT 'a b c';
.check --not 'a b'

# The --glob option matches a pattern against any substring of the output.
# Leading and trailing whitespace on the pattern is ignored.
#
.testcase 220
SELECT 'abcdefghi';
.check --glob 'cde' --keep
.check --glob 'c?e' --keep
.check --glob 'a*i' --keep
.check --glob '[c]d' --keep
.check --glob '  cde  ' --keep
.check --not --glob 'x' --keep
.check --notglob 'ce'
.testcase 221
SELECT 'a   b'||char(10)||'c';
.check --glob 'a b' --keep
.check --glob 'b c' --keep
.check --not --glob 'a/b'
.testcase 222
SELECT 'x -12 y';
.check --glob 'x # y' --keep
.check --glob '# y' --keep
.check --not --glob 'x a y'

# The --allglob option matches a pattern against the entire output, except
# for leading and trailing whitespace.
#
.testcase 230
SELECT 'abcdefghi';
.check --allglob 'a*i' --keep
.check --allglob '  abc*  ' --keep
.check --not --allglob 'abcdefg?' --keep
.check --not --allglob '?bcdefgh' --keep
.check --not --allglob 'c*e'
.testcase 230a
SELECT 'abc';
.check --allglob 'abc' --keep
.check --not --allglob 'ab' --keep
.check --not --allglob 'bc'
.testcase 231
SELECT '  a   b'||char(10)||'c  '||char(10);
.check --allglob 'a b c' --keep
.check --allglob 'a b c*' --keep
.check --allglob 'a*c' --keep
.check --not --allglob 'a b' --keep
.check --not --allglob 'a b?' --keep
.check --not --allglob 'b c*'
.testcase 232
SELECT 'x +12 y';
.check --allglob 'x # y' --keep
.check --not --allglob 'x # z'

# A "*" in a GLOB pattern may be followed directly by whitespace or by "#".
#
.testcase 233
SELECT 'a'||char(9)||'b 12';
.check --allglob 'a* b #' --keep
.check --allglob 'a*#' --keep
.check --glob 'a*b' --keep
.check --not --allglob 'a*#x'

# The --nowhere option passes if the pattern is not a substring of the
# output.  It is the same as "--not --any".
#
.testcase 240
SELECT 'abcdefghi';
.check --nowhere 'x' --keep
.check --nowhere 'ce' --keep
.check --not --nowhere 'cde' --keep
.check --not --any 'x' --keep
.check --any 'cde'
.mode --reset quote

# Bug 2026-11-13T12:52:21Z sqlite.org/bugs/info/4a5ca8d0693363ae
# CLI: ".open --deserialize" with no FILE passes NULL to fopen() in readFile()
# By: newwin01
#
.testcase 300
CREATE TABLE t300(x);
.open --deserialize
.databases
.check 'main: "" r/w'