/ Check-in [20e16fef]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add new file e_createtable.test.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 20e16fef55c355a1d7e97d0c390769b941e83fdb
User & Date: dan 2010-09-25 17:29:58
Context
2010-09-25
22:32
Enhance the ANALYZE command so that it gathers statistics in the sqlite_stat1 table even for tables that are empty or have no indices. check-in: a7645d29 user: drh tags: trunk
17:29
Add new file e_createtable.test. check-in: 20e16fef user: dan tags: trunk
14:13
Do not call gethostuuid() on MacOS 10.4 and earlier, since it is not supported there. check-in: 44deaaef user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added test/e_createtable.test.















































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
# 2010 September 25
#
# 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 tests to verify that the "testable statements" in 
# the lang_createtable.html document are correct.
#

set testdir [file dirname $argv0]
source $testdir/tester.tcl

proc do_createtable_tests {nm args} {
  uplevel do_select_tests [list e_createtable-$nm] $args
}

# EVIDENCE-OF: R-25262-01881 -- syntax diagram type-name
#
do_createtable_tests 0.1.1 -repair {
  drop_all_tables
} {
  1   "CREATE TABLE t1(c1 one)"                        {}
  2   "CREATE TABLE t1(c1 one two)"                    {}
  3   "CREATE TABLE t1(c1 one two three)"              {}
  4   "CREATE TABLE t1(c1 one two three four)"         {}
  5   "CREATE TABLE t1(c1 one two three four(14))"     {}
  6   "CREATE TABLE t1(c1 one two three four(14, 22))" {}
  7   "CREATE TABLE t1(c1 var(+14, -22.3))"            {}
  8   "CREATE TABLE t1(c1 var(1.0e10))"                {}
}
do_createtable_tests 0.1.2 -error {
  near "%s": syntax error
} {
  1   "CREATE TABLE t1(c1 one(number))"                {number}
}


# EVIDENCE-OF: R-18762-12428 -- syntax diagram column-constraint
#
#   Note: Not shown in the syntax diagram is the "NULL" constraint. This
#         is the opposite of "NOT NULL" - it implies that the column may
#         take a NULL value. This is the default anyway, so this type of
#         constraint is rarely used.
#
do_createtable_tests 0.2.1 -repair {
  drop_all_tables 
  execsql { CREATE TABLE t2(x PRIMARY KEY) }
} {
  1.1   "CREATE TABLE t1(c1 text PRIMARY KEY)"                         {}
  1.2   "CREATE TABLE t1(c1 text PRIMARY KEY ASC)"                     {}
  1.3   "CREATE TABLE t1(c1 text PRIMARY KEY DESC)"                    {}
  1.4   "CREATE TABLE t1(c1 text CONSTRAINT cons PRIMARY KEY DESC)"    {}

  2.1   "CREATE TABLE t1(c1 text NOT NULL)"                            {}
  2.2   "CREATE TABLE t1(c1 text CONSTRAINT nm NOT NULL)"              {}
  2.3   "CREATE TABLE t1(c1 text NULL)"                                {}
  2.4   "CREATE TABLE t1(c1 text CONSTRAINT nm NULL)"                  {}

  3.1   "CREATE TABLE t1(c1 text UNIQUE)"                              {}
  3.2   "CREATE TABLE t1(c1 text CONSTRAINT un UNIQUE)"                {}

  4.1   "CREATE TABLE t1(c1 text CHECK(c1!=0))"                        {}
  4.2   "CREATE TABLE t1(c1 text CONSTRAINT chk CHECK(c1!=0))"         {}

  5.1   "CREATE TABLE t1(c1 text DEFAULT 1)"                           {}
  5.2   "CREATE TABLE t1(c1 text DEFAULT -1)"                          {}
  5.3   "CREATE TABLE t1(c1 text DEFAULT +1)"                          {}
  5.4   "CREATE TABLE t1(c1 text DEFAULT -45.8e22)"                    {}
  5.5   "CREATE TABLE t1(c1 text DEFAULT (1+1))"                       {}
  5.6   "CREATE TABLE t1(c1 text CONSTRAINT \"1 2\" DEFAULT (1+1))"    {}

  6.1   "CREATE TABLE t1(c1 text COLLATE nocase)"        {}
  6.2   "CREATE TABLE t1(c1 text CONSTRAINT 'a x' COLLATE nocase)"     {}

  7.1   "CREATE TABLE t1(c1 REFERENCES t2)"                            {}
  7.2   "CREATE TABLE t1(c1 CONSTRAINT abc REFERENCES t2)"             {}

  8.1   {
    CREATE TABLE t1(c1 
      PRIMARY KEY NOT NULL UNIQUE CHECK(c1 IS 'ten') DEFAULT 123 REFERENCES t1
    );
  } {}
  8.2   {
    CREATE TABLE t1(c1 
      REFERENCES t1 DEFAULT 123 CHECK(c1 IS 'ten') UNIQUE NOT NULL PRIMARY KEY 
    );
  } {}
}

# EVIDENCE-OF: R-17905-31923 -- syntax diagram table-constraint
#
do_createtable_tests 0.3.1 -repair {
  drop_all_tables 
  execsql { CREATE TABLE t2(x PRIMARY KEY) }
} {
  1.1   "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1))"                         {}
  1.2   "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1, c2))"                     {}
  1.3   "CREATE TABLE t1(c1, c2, PRIMARY KEY(c1, c2) ON CONFLICT IGNORE)"  {}

  2.1   "CREATE TABLE t1(c1, c2, UNIQUE(c1))"                              {}
  2.2   "CREATE TABLE t1(c1, c2, UNIQUE(c1, c2))"                          {}
  2.3   "CREATE TABLE t1(c1, c2, UNIQUE(c1, c2) ON CONFLICT IGNORE)"       {}

  3.1   "CREATE TABLE t1(c1, c2, CHECK(c1 IS NOT c2))"                     {}

  4.1   "CREATE TABLE t1(c1, c2, FOREIGN KEY(c1) REFERENCES t2)"           {}
}

# EVIDENCE-OF: R-18765-31171 -- syntax diagram column-def
#
do_createtable_tests 0.4.1 -repair {
  drop_all_tables 
} {
  1     {CREATE TABLE t1(
           col1,
           col2 TEXT,
           col3 INTEGER UNIQUE,
           col4 VARCHAR(10, 10) PRIMARY KEY,
           "name with spaces" REFERENCES t1
         );
        } {}
}

# EVIDENCE-OF: R-59573-11075 -- syntax diagram create-table-stmt
#
do_createtable_tests 0.5.1 -repair {
  drop_all_tables 
  execsql { CREATE TABLE t2(a, b, c) }
} {
  1     "CREATE TABLE t1(a, b, c)"                                    {}
  2     "CREATE TEMP TABLE t1(a, b, c)"                               {}
  3     "CREATE TEMPORARY TABLE t1(a, b, c)"                          {}
  4     "CREATE TABLE IF NOT EXISTS t1(a, b, c)"                      {}
  5     "CREATE TEMP TABLE IF NOT EXISTS t1(a, b, c)"                 {}
  6     "CREATE TEMPORARY TABLE IF NOT EXISTS t1(a, b, c)"            {}

  7     "CREATE TABLE main.t1(a, b, c)"                               {}
  8     "CREATE TEMP TABLE temp.t1(a, b, c)"                          {}
  9     "CREATE TEMPORARY TABLE temp.t1(a, b, c)"                     {}
  10    "CREATE TABLE IF NOT EXISTS main.t1(a, b, c)"                 {}
  11    "CREATE TEMP TABLE IF NOT EXISTS temp.t1(a, b, c)"            {}
  12    "CREATE TEMPORARY TABLE IF NOT EXISTS temp.t1(a, b, c)"       {}

  13    "CREATE TABLE t1 AS SELECT * FROM t2"                         {}
  14    "CREATE TEMP TABLE t1 AS SELECT c, b, a FROM t2"              {}
  15    "CREATE TABLE t1 AS SELECT count(*), max(b), min(a) FROM t2"  {}
}

# EVIDENCE-OF: R-32138-02228 -- syntax diagram foreign-key-clause
#
#   1:         Explicit parent-key columns.
#   2:         Implicit child-key columns.
#
#   1:         MATCH FULL
#   2:         MATCH PARTIAL
#   3:         MATCH SIMPLE
#   4:         MATCH STICK
#   5:         
#
#   1:         ON DELETE SET NULL
#   2:         ON DELETE SET DEFAULT
#   3:         ON DELETE CASCADE
#   4:         ON DELETE RESTRICT
#   5:         ON DELETE NO ACTION
#   6:
#
#   1:         ON UPDATE SET NULL
#   2:         ON UPDATE SET DEFAULT
#   3:         ON UPDATE CASCADE
#   4:         ON UPDATE RESTRICT
#   5:         ON UPDATE NO ACTION
#   6:
#
#   1:         NOT DEFERRABLE INITIALLY DEFERRED
#   2:         NOT DEFERRABLE INITIALLY IMMEDIATE
#   3:         NOT DEFERRABLE
#   4:         DEFERRABLE INITIALLY DEFERRED
#   5:         DEFERRABLE INITIALLY IMMEDIATE
#   6:         DEFERRABLE
#   7:         
#
do_createtable_tests 0.6.1 -repair {
  drop_all_tables 
  execsql { CREATE TABLE t2(x PRIMARY KEY, y) }
  execsql { CREATE TABLE t3(i, j, UNIQUE(i, j) ) }
} {
  11146 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH FULL 
    ON DELETE SET NULL ON UPDATE RESTRICT DEFERRABLE
  )} {}
  11412 { CREATE TABLE t1(a 
    REFERENCES t2(x) 
    ON DELETE RESTRICT ON UPDATE SET NULL MATCH FULL 
    NOT DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  12135 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH PARTIAL 
    ON DELETE SET NULL ON UPDATE CASCADE DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  12427 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH PARTIAL 
    ON DELETE RESTRICT ON UPDATE SET DEFAULT 
  )} {}
  12446 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH PARTIAL 
    ON DELETE RESTRICT ON UPDATE RESTRICT DEFERRABLE
  )} {}
  12522 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH PARTIAL 
    ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  13133 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH SIMPLE 
    ON DELETE SET NULL ON UPDATE CASCADE NOT DEFERRABLE
  )} {}
  13216 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH SIMPLE 
    ON DELETE SET DEFAULT ON UPDATE SET NULL DEFERRABLE
  )} {}
  13263 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH SIMPLE 
    ON DELETE SET DEFAULT  NOT DEFERRABLE
  )} {}
  13421 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH SIMPLE 
    ON DELETE RESTRICT ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY DEFERRED
  )} {}
  13432 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH SIMPLE 
    ON DELETE RESTRICT ON UPDATE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  13523 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH SIMPLE 
    ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE
  )} {}
  14336 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH STICK 
    ON DELETE CASCADE ON UPDATE CASCADE DEFERRABLE
  )} {}
  14611 { CREATE TABLE t1(a 
    REFERENCES t2(x) MATCH STICK 
    ON UPDATE SET NULL NOT DEFERRABLE INITIALLY DEFERRED
  )} {}
  15155 { CREATE TABLE t1(a 
    REFERENCES t2(x)
    ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  15453 { CREATE TABLE t1(a 
    REFERENCES t2(x) ON DELETE RESTRICT ON UPDATE NO ACTION NOT DEFERRABLE
  )} {}
  15661 { CREATE TABLE t1(a 
    REFERENCES t2(x) NOT DEFERRABLE INITIALLY DEFERRED
  )} {}
  21115 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH FULL 
    ON DELETE SET NULL ON UPDATE SET NULL DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  21123 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH FULL 
    ON DELETE SET NULL ON UPDATE SET DEFAULT NOT DEFERRABLE
  )} {}
  21217 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH FULL ON DELETE SET DEFAULT ON UPDATE SET NULL 
  )} {}
  21362 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH FULL 
    ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  22143 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH PARTIAL 
    ON DELETE SET NULL ON UPDATE RESTRICT NOT DEFERRABLE
  )} {}
  22156 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH PARTIAL 
    ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE
  )} {}
  22327 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH PARTIAL ON DELETE CASCADE ON UPDATE SET DEFAULT 
  )} {}
  22663 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH PARTIAL NOT DEFERRABLE
  )} {}
  23236 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH SIMPLE 
    ON DELETE SET DEFAULT ON UPDATE CASCADE DEFERRABLE
  )} {}
  24155 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH STICK 
    ON DELETE SET NULL ON UPDATE NO ACTION DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  24522 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH STICK 
    ON DELETE NO ACTION ON UPDATE SET DEFAULT NOT DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  24625 { CREATE TABLE t1(a 
    REFERENCES t2 MATCH STICK 
    ON UPDATE SET DEFAULT DEFERRABLE INITIALLY IMMEDIATE
  )} {}
  25454 { CREATE TABLE t1(a 
    REFERENCES t2 
    ON DELETE RESTRICT ON UPDATE NO ACTION DEFERRABLE INITIALLY DEFERRED
  )} {}
}

finish_test

Changes to test/e_insert.test.

5
6
7
8
9
10
11
12
13



14
15
16
17
18
19
20
...
326
327
328
329
330
331
332







333
334
335
336
337
338
339
#
#    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 tests to verify that the "testable statements" in 
# the lang_insert.html document are correct.



#
set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Organization of tests:
#
#   e_insert-0.*: Test the syntax diagram.
................................................................................
# algorithm to use during this one INSERT command.
#
# EVIDENCE-OF: R-23110-47146 the parser allows the use of the single
# keyword REPLACE as an alias for "INSERT OR REPLACE".
#
#    The two requirements above are tested by e_select-4.1.* and
#    e_select-4.2.*, respectively.







#
do_execsql_test e_insert-4.1.0 {
  INSERT INTO a4 VALUES(1, 'a');
  INSERT INTO a4 VALUES(2, 'a');
  INSERT INTO a4 VALUES(3, 'a');
} {}
foreach {tn sql error ac data } {







|
|
>
>
>







 







>
>
>
>
>
>
>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
#
#    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.
#
#***********************************************************************
#
# The majority of this file implements tests to verify that the "testable
# statements" in the lang_insert.html document are correct.
#
# Also, it contains tests to verify the statements in (the very short)
# lang_replace.html.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Organization of tests:
#
#   e_insert-0.*: Test the syntax diagram.
................................................................................
# algorithm to use during this one INSERT command.
#
# EVIDENCE-OF: R-23110-47146 the parser allows the use of the single
# keyword REPLACE as an alias for "INSERT OR REPLACE".
#
#    The two requirements above are tested by e_select-4.1.* and
#    e_select-4.2.*, respectively.
#
# EVIDENCE-OF: R-03421-22330 The REPLACE command is an alias for the
# "INSERT OR REPLACE" variant of the INSERT command.
#
#    This is a dup of R-23110-47146. Therefore it is also verified 
#    by e_select-4.2.*. This requirement is the only one from
#    lang_replace.html.
#
do_execsql_test e_insert-4.1.0 {
  INSERT INTO a4 VALUES(1, 'a');
  INSERT INTO a4 VALUES(2, 'a');
  INSERT INTO a4 VALUES(3, 'a');
} {}
foreach {tn sql error ac data } {