1: # 2009 Nov 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: # The focus of this file is testing the CLI shell tool.
13: #
14: # $Id: shell1.test,v 1.1.1.1 2012/02/21 17:04:17 misho Exp $
15: #
16:
17: # Test plan:
18: #
19: # shell1-1.*: Basic command line option handling.
20: # shell1-2.*: Basic "dot" command token parsing.
21: # shell1-3.*: Basic test that "dot" command can be called.
22: #
23:
24: package require sqlite3
25:
26: set CLI "./sqlite3"
27:
28: proc do_test {name cmd expected} {
29: puts -nonewline "$name ..."
30: set res [uplevel $cmd]
31: if {$res eq $expected} {
32: puts Ok
33: } else {
34: puts Error
35: puts " Got: $res"
36: puts " Expected: $expected"
37: exit
38: }
39: }
40:
41: proc execsql {sql} {
42: uplevel [list db eval $sql]
43: }
44:
45: proc catchsql {sql} {
46: set rc [catch {uplevel [list db eval $sql]} msg]
47: list $rc $msg
48: }
49:
50: proc catchcmd {db {cmd ""}} {
51: global CLI
52: set out [open cmds.txt w]
53: puts $out $cmd
54: close $out
55: set line "exec $CLI $db < cmds.txt"
56: set rc [catch { eval $line } msg]
57: list $rc $msg
58: }
59:
60: file delete -force test.db test.db.journal
61: sqlite3 db test.db
62:
63: #----------------------------------------------------------------------------
64: # Test cases shell1-1.*: Basic command line option handling.
65: #
66:
67: # invalid option
68: do_test shell1-1.1.1 {
69: set res [catchcmd "-bad test.db" ""]
70: set rc [lindex $res 0]
71: list $rc \
72: [regexp {Error: unknown option: -bad} $res]
73: } {1 1}
74: # error on extra options
75: do_test shell1-1.1.2 {
76: set res [catchcmd "-bad test.db \"select 3\" \"select 4\"" ""]
77: set rc [lindex $res 0]
78: list $rc \
79: [regexp {Error: too many options: "select 4"} $res]
80: } {1 1}
81: # error on extra options
82: do_test shell1-1.1.3 {
83: set res [catchcmd "-bad FOO test.db BAD" ".quit"]
84: set rc [lindex $res 0]
85: list $rc \
86: [regexp {Error: too many options: "BAD"} $res]
87: } {1 1}
88:
89: # -help
90: do_test shell1-1.2.1 {
91: set res [catchcmd "-help test.db" ""]
92: set rc [lindex $res 0]
93: list $rc \
94: [regexp {Usage} $res] \
95: [regexp {\-init} $res] \
96: [regexp {\-version} $res]
97: } {1 1 1 1}
98:
99: # -init filename read/process named file
100: do_test shell1-1.3.1 {
101: catchcmd "-init FOO test.db" ""
102: } {0 {}}
103: do_test shell1-1.3.2 {
104: set res [catchcmd "-init FOO test.db .quit BAD" ""]
105: set rc [lindex $res 0]
106: list $rc \
107: [regexp {Error: too many options: "BAD"} $res]
108: } {1 1}
109:
110: # -echo print commands before execution
111: do_test shell1-1.4.1 {
112: catchcmd "-echo test.db" ""
113: } {0 {}}
114:
115: # -[no]header turn headers on or off
116: do_test shell1-1.5.1 {
117: catchcmd "-header test.db" ""
118: } {0 {}}
119: do_test shell1-1.5.2 {
120: catchcmd "-noheader test.db" ""
121: } {0 {}}
122:
123: # -bail stop after hitting an error
124: do_test shell1-1.6.1 {
125: catchcmd "-bail test.db" ""
126: } {0 {}}
127:
128: # -interactive force interactive I/O
129: do_test shell1-1.7.1 {
130: set res [catchcmd "-interactive test.db" ".quit"]
131: set rc [lindex $res 0]
132: list $rc \
133: [regexp {SQLite version} $res] \
134: [regexp {Enter SQL statements} $res]
135: } {0 1 1}
136:
137: # -batch force batch I/O
138: do_test shell1-1.8.1 {
139: catchcmd "-batch test.db" ""
140: } {0 {}}
141:
142: # -column set output mode to 'column'
143: do_test shell1-1.9.1 {
144: catchcmd "-column test.db" ""
145: } {0 {}}
146:
147: # -csv set output mode to 'csv'
148: do_test shell1-1.10.1 {
149: catchcmd "-csv test.db" ""
150: } {0 {}}
151:
152: # -html set output mode to HTML
153: do_test shell1-1.11.1 {
154: catchcmd "-html test.db" ""
155: } {0 {}}
156:
157: # -line set output mode to 'line'
158: do_test shell1-1.12.1 {
159: catchcmd "-line test.db" ""
160: } {0 {}}
161:
162: # -list set output mode to 'list'
163: do_test shell1-1.13.1 {
164: catchcmd "-list test.db" ""
165: } {0 {}}
166:
167: # -separator 'x' set output field separator (|)
168: do_test shell1-1.14.1 {
169: catchcmd "-separator 'x' test.db" ""
170: } {0 {}}
171: do_test shell1-1.14.2 {
172: catchcmd "-separator x test.db" ""
173: } {0 {}}
174: do_test shell1-1.14.3 {
175: set res [catchcmd "-separator" ""]
176: set rc [lindex $res 0]
177: list $rc \
178: [regexp {Error: missing argument for option: -separator} $res]
179: } {1 1}
180:
181: # -stats print memory stats before each finalize
182: do_test shell1-1.14b.1 {
183: catchcmd "-stats test.db" ""
184: } {0 {}}
185:
186: # -nullvalue 'text' set text string for NULL values
187: do_test shell1-1.15.1 {
188: catchcmd "-nullvalue 'x' test.db" ""
189: } {0 {}}
190: do_test shell1-1.15.2 {
191: catchcmd "-nullvalue x test.db" ""
192: } {0 {}}
193: do_test shell1-1.15.3 {
194: set res [catchcmd "-nullvalue" ""]
195: set rc [lindex $res 0]
196: list $rc \
197: [regexp {Error: missing argument for option: -nullvalue} $res]
198: } {1 1}
199:
200: # -version show SQLite version
201: do_test shell1-1.16.1 {
202: set x [catchcmd "-version test.db" ""]
203: regexp {0 \{3.\d.\d+ 20\d\d-[01]\d-\d\d \d\d:\d\d:\d\d [0-9a-f]+\}} $x
204: } 1
205:
206: #----------------------------------------------------------------------------
207: # Test cases shell1-2.*: Basic "dot" command token parsing.
208: #
209:
210: # check first token handling
211: do_test shell1-2.1.1 {
212: catchcmd "test.db" ".foo"
213: } {1 {Error: unknown command or invalid arguments: "foo". Enter ".help" for help}}
214: do_test shell1-2.1.2 {
215: catchcmd "test.db" ".\"foo OFF\""
216: } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
217: do_test shell1-2.1.3 {
218: catchcmd "test.db" ".\'foo OFF\'"
219: } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
220:
221: # unbalanced quotes
222: do_test shell1-2.2.1 {
223: catchcmd "test.db" ".\"foo OFF"
224: } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
225: do_test shell1-2.2.2 {
226: catchcmd "test.db" ".\'foo OFF"
227: } {1 {Error: unknown command or invalid arguments: "foo OFF". Enter ".help" for help}}
228: do_test shell1-2.2.3 {
229: catchcmd "test.db" ".explain \"OFF"
230: } {0 {}}
231: do_test shell1-2.2.4 {
232: catchcmd "test.db" ".explain \'OFF"
233: } {0 {}}
234: do_test shell1-2.2.5 {
235: catchcmd "test.db" ".mode \"insert FOO"
236: } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
237: do_test shell1-2.2.6 {
238: catchcmd "test.db" ".mode \'insert FOO"
239: } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
240:
241: # check multiple tokens, and quoted tokens
242: do_test shell1-2.3.1 {
243: catchcmd "test.db" ".explain 1"
244: } {0 {}}
245: do_test shell1-2.3.2 {
246: catchcmd "test.db" ".explain on"
247: } {0 {}}
248: do_test shell1-2.3.3 {
249: catchcmd "test.db" ".explain \"1 2 3\""
250: } {0 {}}
251: do_test shell1-2.3.4 {
252: catchcmd "test.db" ".explain \"OFF\""
253: } {0 {}}
254: do_test shell1-2.3.5 {
255: catchcmd "test.db" ".\'explain\' \'OFF\'"
256: } {0 {}}
257: do_test shell1-2.3.6 {
258: catchcmd "test.db" ".explain \'OFF\'"
259: } {0 {}}
260: do_test shell1-2.3.7 {
261: catchcmd "test.db" ".\'explain\' \'OFF\'"
262: } {0 {}}
263:
264: # check quoted args are unquoted
265: do_test shell1-2.4.1 {
266: catchcmd "test.db" ".mode FOO"
267: } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
268: do_test shell1-2.4.2 {
269: catchcmd "test.db" ".mode csv"
270: } {0 {}}
271: do_test shell1-2.4.2 {
272: catchcmd "test.db" ".mode \"csv\""
273: } {0 {}}
274:
275:
276: #----------------------------------------------------------------------------
277: # Test cases shell1-3.*: Basic test that "dot" command can be called.
278: #
279:
280: # .backup ?DB? FILE Backup DB (default "main") to FILE
281: do_test shell1-3.1.1 {
282: catchcmd "test.db" ".backup"
283: } {1 {Error: unknown command or invalid arguments: "backup". Enter ".help" for help}}
284: do_test shell1-3.1.2 {
285: catchcmd "test.db" ".backup FOO"
286: } {0 {}}
287: do_test shell1-3.1.3 {
288: catchcmd "test.db" ".backup FOO BAR"
289: } {1 {Error: unknown database FOO}}
290: do_test shell1-3.1.4 {
291: # too many arguments
292: catchcmd "test.db" ".backup FOO BAR BAD"
293: } {1 {Error: unknown command or invalid arguments: "backup". Enter ".help" for help}}
294:
295: # .bail ON|OFF Stop after hitting an error. Default OFF
296: do_test shell1-3.2.1 {
297: catchcmd "test.db" ".bail"
298: } {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}}
299: do_test shell1-3.2.2 {
300: catchcmd "test.db" ".bail ON"
301: } {0 {}}
302: do_test shell1-3.2.3 {
303: catchcmd "test.db" ".bail OFF"
304: } {0 {}}
305: do_test shell1-3.2.4 {
306: # too many arguments
307: catchcmd "test.db" ".bail OFF BAD"
308: } {1 {Error: unknown command or invalid arguments: "bail". Enter ".help" for help}}
309:
310: # .databases List names and files of attached databases
311: do_test shell1-3.3.1 {
312: set res [catchcmd "test.db" ".databases"]
313: regexp {0.*main.*test\.db} $res
314: } {1}
315: do_test shell1-3.3.2 {
316: # too many arguments
317: catchcmd "test.db" ".databases BAD"
318: } {1 {Error: unknown command or invalid arguments: "databases". Enter ".help" for help}}
319:
320: # .dump ?TABLE? ... Dump the database in an SQL text format
321: # If TABLE specified, only dump tables matching
322: # LIKE pattern TABLE.
323: do_test shell1-3.4.1 {
324: set res [catchcmd "test.db" ".dump"]
325: list [regexp {BEGIN TRANSACTION;} $res] \
326: [regexp {COMMIT;} $res]
327: } {1 1}
328: do_test shell1-3.4.2 {
329: set res [catchcmd "test.db" ".dump FOO"]
330: list [regexp {BEGIN TRANSACTION;} $res] \
331: [regexp {COMMIT;} $res]
332: } {1 1}
333: do_test shell1-3.4.3 {
334: # too many arguments
335: catchcmd "test.db" ".dump FOO BAD"
336: } {1 {Error: unknown command or invalid arguments: "dump". Enter ".help" for help}}
337:
338: # .echo ON|OFF Turn command echo on or off
339: do_test shell1-3.5.1 {
340: catchcmd "test.db" ".echo"
341: } {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}}
342: do_test shell1-3.5.2 {
343: catchcmd "test.db" ".echo ON"
344: } {0 {}}
345: do_test shell1-3.5.3 {
346: catchcmd "test.db" ".echo OFF"
347: } {0 {}}
348: do_test shell1-3.5.4 {
349: # too many arguments
350: catchcmd "test.db" ".echo OFF BAD"
351: } {1 {Error: unknown command or invalid arguments: "echo". Enter ".help" for help}}
352:
353: # .exit Exit this program
354: do_test shell1-3.6.1 {
355: catchcmd "test.db" ".exit"
356: } {0 {}}
357: do_test shell1-3.6.2 {
358: # too many arguments
359: catchcmd "test.db" ".exit BAD"
360: } {1 {Error: unknown command or invalid arguments: "exit". Enter ".help" for help}}
361:
362: # .explain ON|OFF Turn output mode suitable for EXPLAIN on or off.
363: do_test shell1-3.7.1 {
364: catchcmd "test.db" ".explain"
365: # explain is the exception to the booleans. without an option, it turns it on.
366: } {0 {}}
367: do_test shell1-3.7.2 {
368: catchcmd "test.db" ".explain ON"
369: } {0 {}}
370: do_test shell1-3.7.3 {
371: catchcmd "test.db" ".explain OFF"
372: } {0 {}}
373: do_test shell1-3.7.4 {
374: # too many arguments
375: catchcmd "test.db" ".explain OFF BAD"
376: } {1 {Error: unknown command or invalid arguments: "explain". Enter ".help" for help}}
377:
378:
379: # .header(s) ON|OFF Turn display of headers on or off
380: do_test shell1-3.9.1 {
381: catchcmd "test.db" ".header"
382: } {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}}
383: do_test shell1-3.9.2 {
384: catchcmd "test.db" ".header ON"
385: } {0 {}}
386: do_test shell1-3.9.3 {
387: catchcmd "test.db" ".header OFF"
388: } {0 {}}
389: do_test shell1-3.9.4 {
390: # too many arguments
391: catchcmd "test.db" ".header OFF BAD"
392: } {1 {Error: unknown command or invalid arguments: "header". Enter ".help" for help}}
393:
394: do_test shell1-3.9.5 {
395: catchcmd "test.db" ".headers"
396: } {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}}
397: do_test shell1-3.9.6 {
398: catchcmd "test.db" ".headers ON"
399: } {0 {}}
400: do_test shell1-3.9.7 {
401: catchcmd "test.db" ".headers OFF"
402: } {0 {}}
403: do_test shell1-3.9.8 {
404: # too many arguments
405: catchcmd "test.db" ".headers OFF BAD"
406: } {1 {Error: unknown command or invalid arguments: "headers". Enter ".help" for help}}
407:
408: # .help Show this message
409: do_test shell1-3.10.1 {
410: set res [catchcmd "test.db" ".help"]
411: # look for a few of the possible help commands
412: list [regexp {.help} $res] \
413: [regexp {.quit} $res] \
414: [regexp {.show} $res]
415: } {1 1 1}
416: do_test shell1-3.10.2 {
417: # we allow .help to take extra args (it is help after all)
418: set res [catchcmd "test.db" ".help BAD"]
419: # look for a few of the possible help commands
420: list [regexp {.help} $res] \
421: [regexp {.quit} $res] \
422: [regexp {.show} $res]
423: } {1 1 1}
424:
425: # .import FILE TABLE Import data from FILE into TABLE
426: do_test shell1-3.11.1 {
427: catchcmd "test.db" ".import"
428: } {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
429: do_test shell1-3.11.2 {
430: catchcmd "test.db" ".import FOO"
431: } {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
432: do_test shell1-3.11.2 {
433: catchcmd "test.db" ".import FOO BAR"
434: } {1 {Error: no such table: BAR}}
435: do_test shell1-3.11.3 {
436: # too many arguments
437: catchcmd "test.db" ".import FOO BAR BAD"
438: } {1 {Error: unknown command or invalid arguments: "import". Enter ".help" for help}}
439:
440: # .indices ?TABLE? Show names of all indices
441: # If TABLE specified, only show indices for tables
442: # matching LIKE pattern TABLE.
443: do_test shell1-3.12.1 {
444: catchcmd "test.db" ".indices"
445: } {0 {}}
446: do_test shell1-3.12.2 {
447: catchcmd "test.db" ".indices FOO"
448: } {0 {}}
449: do_test shell1-3.12.3 {
450: # too many arguments
451: catchcmd "test.db" ".indices FOO BAD"
452: } {1 {Error: unknown command or invalid arguments: "indices". Enter ".help" for help}}
453:
454: # .mode MODE ?TABLE? Set output mode where MODE is one of:
455: # csv Comma-separated values
456: # column Left-aligned columns. (See .width)
457: # html HTML <table> code
458: # insert SQL insert statements for TABLE
459: # line One value per line
460: # list Values delimited by .separator string
461: # tabs Tab-separated values
462: # tcl TCL list elements
463: do_test shell1-3.13.1 {
464: catchcmd "test.db" ".mode"
465: } {1 {Error: unknown command or invalid arguments: "mode". Enter ".help" for help}}
466: do_test shell1-3.13.2 {
467: catchcmd "test.db" ".mode FOO"
468: } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
469: do_test shell1-3.13.3 {
470: catchcmd "test.db" ".mode csv"
471: } {0 {}}
472: do_test shell1-3.13.4 {
473: catchcmd "test.db" ".mode column"
474: } {0 {}}
475: do_test shell1-3.13.5 {
476: catchcmd "test.db" ".mode html"
477: } {0 {}}
478: do_test shell1-3.13.6 {
479: catchcmd "test.db" ".mode insert"
480: } {0 {}}
481: do_test shell1-3.13.7 {
482: catchcmd "test.db" ".mode line"
483: } {0 {}}
484: do_test shell1-3.13.8 {
485: catchcmd "test.db" ".mode list"
486: } {0 {}}
487: do_test shell1-3.13.9 {
488: catchcmd "test.db" ".mode tabs"
489: } {0 {}}
490: do_test shell1-3.13.10 {
491: catchcmd "test.db" ".mode tcl"
492: } {0 {}}
493: do_test shell1-3.13.11 {
494: # too many arguments
495: catchcmd "test.db" ".mode tcl BAD"
496: } {1 {Error: invalid arguments: "BAD". Enter ".help" for help}}
497:
498: # don't allow partial mode type matches
499: do_test shell1-3.13.12 {
500: catchcmd "test.db" ".mode l"
501: } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
502: do_test shell1-3.13.13 {
503: catchcmd "test.db" ".mode li"
504: } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
505: do_test shell1-3.13.14 {
506: catchcmd "test.db" ".mode lin"
507: } {1 {Error: mode should be one of: column csv html insert line list tabs tcl}}
508:
509: # .nullvalue STRING Print STRING in place of NULL values
510: do_test shell1-3.14.1 {
511: catchcmd "test.db" ".nullvalue"
512: } {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}}
513: do_test shell1-3.14.2 {
514: catchcmd "test.db" ".nullvalue FOO"
515: } {0 {}}
516: do_test shell1-3.14.3 {
517: # too many arguments
518: catchcmd "test.db" ".nullvalue FOO BAD"
519: } {1 {Error: unknown command or invalid arguments: "nullvalue". Enter ".help" for help}}
520:
521: # .output FILENAME Send output to FILENAME
522: do_test shell1-3.15.1 {
523: catchcmd "test.db" ".output"
524: } {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
525: do_test shell1-3.15.2 {
526: catchcmd "test.db" ".output FOO"
527: } {0 {}}
528: do_test shell1-3.15.3 {
529: # too many arguments
530: catchcmd "test.db" ".output FOO BAD"
531: } {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
532:
533: # .output stdout Send output to the screen
534: do_test shell1-3.16.1 {
535: catchcmd "test.db" ".output stdout"
536: } {0 {}}
537: do_test shell1-3.16.2 {
538: # too many arguments
539: catchcmd "test.db" ".output stdout BAD"
540: } {1 {Error: unknown command or invalid arguments: "output". Enter ".help" for help}}
541:
542: # .prompt MAIN CONTINUE Replace the standard prompts
543: do_test shell1-3.17.1 {
544: catchcmd "test.db" ".prompt"
545: } {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}}
546: do_test shell1-3.17.2 {
547: catchcmd "test.db" ".prompt FOO"
548: } {0 {}}
549: do_test shell1-3.17.3 {
550: catchcmd "test.db" ".prompt FOO BAR"
551: } {0 {}}
552: do_test shell1-3.17.4 {
553: # too many arguments
554: catchcmd "test.db" ".prompt FOO BAR BAD"
555: } {1 {Error: unknown command or invalid arguments: "prompt". Enter ".help" for help}}
556:
557: # .quit Exit this program
558: do_test shell1-3.18.1 {
559: catchcmd "test.db" ".quit"
560: } {0 {}}
561: do_test shell1-3.18.2 {
562: # too many arguments
563: catchcmd "test.db" ".quit BAD"
564: } {1 {Error: unknown command or invalid arguments: "quit". Enter ".help" for help}}
565:
566: # .read FILENAME Execute SQL in FILENAME
567: do_test shell1-3.19.1 {
568: catchcmd "test.db" ".read"
569: } {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}}
570: do_test shell1-3.19.2 {
571: file delete -force FOO
572: catchcmd "test.db" ".read FOO"
573: } {1 {Error: cannot open "FOO"}}
574: do_test shell1-3.19.3 {
575: # too many arguments
576: catchcmd "test.db" ".read FOO BAD"
577: } {1 {Error: unknown command or invalid arguments: "read". Enter ".help" for help}}
578:
579: # .restore ?DB? FILE Restore content of DB (default "main") from FILE
580: do_test shell1-3.20.1 {
581: catchcmd "test.db" ".restore"
582: } {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}}
583: do_test shell1-3.20.2 {
584: catchcmd "test.db" ".restore FOO"
585: } {0 {}}
586: do_test shell1-3.20.3 {
587: catchcmd "test.db" ".restore FOO BAR"
588: } {1 {Error: unknown database FOO}}
589: do_test shell1-3.20.4 {
590: # too many arguments
591: catchcmd "test.db" ".restore FOO BAR BAD"
592: } {1 {Error: unknown command or invalid arguments: "restore". Enter ".help" for help}}
593:
594: # .schema ?TABLE? Show the CREATE statements
595: # If TABLE specified, only show tables matching
596: # LIKE pattern TABLE.
597: do_test shell1-3.21.1 {
598: catchcmd "test.db" ".schema"
599: } {0 {}}
600: do_test shell1-3.21.2 {
601: catchcmd "test.db" ".schema FOO"
602: } {0 {}}
603: do_test shell1-3.21.3 {
604: # too many arguments
605: catchcmd "test.db" ".schema FOO BAD"
606: } {1 {Error: unknown command or invalid arguments: "schema". Enter ".help" for help}}
607:
608: # .separator STRING Change separator used by output mode and .import
609: do_test shell1-3.22.1 {
610: catchcmd "test.db" ".separator"
611: } {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
612: do_test shell1-3.22.2 {
613: catchcmd "test.db" ".separator FOO"
614: } {0 {}}
615: do_test shell1-3.22.3 {
616: # too many arguments
617: catchcmd "test.db" ".separator FOO BAD"
618: } {1 {Error: unknown command or invalid arguments: "separator". Enter ".help" for help}}
619:
620: # .show Show the current values for various settings
621: do_test shell1-3.23.1 {
622: set res [catchcmd "test.db" ".show"]
623: list [regexp {echo:} $res] \
624: [regexp {explain:} $res] \
625: [regexp {headers:} $res] \
626: [regexp {mode:} $res] \
627: [regexp {nullvalue:} $res] \
628: [regexp {output:} $res] \
629: [regexp {separator:} $res] \
630: [regexp {stats:} $res] \
631: [regexp {width:} $res]
632: } {1 1 1 1 1 1 1 1 1}
633: do_test shell1-3.23.2 {
634: # too many arguments
635: catchcmd "test.db" ".show BAD"
636: } {1 {Error: unknown command or invalid arguments: "show". Enter ".help" for help}}
637:
638: # .stats ON|OFF Turn stats on or off
639: do_test shell1-3.23b.1 {
640: catchcmd "test.db" ".stats"
641: } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
642: do_test shell1-3.23b.2 {
643: catchcmd "test.db" ".stats ON"
644: } {0 {}}
645: do_test shell1-3.23b.3 {
646: catchcmd "test.db" ".stats OFF"
647: } {0 {}}
648: do_test shell1-3.23b.4 {
649: # too many arguments
650: catchcmd "test.db" ".stats OFF BAD"
651: } {1 {Error: unknown command or invalid arguments: "stats". Enter ".help" for help}}
652:
653: # .tables ?TABLE? List names of tables
654: # If TABLE specified, only list tables matching
655: # LIKE pattern TABLE.
656: do_test shell1-3.24.1 {
657: catchcmd "test.db" ".tables"
658: } {0 {}}
659: do_test shell1-3.24.2 {
660: catchcmd "test.db" ".tables FOO"
661: } {0 {}}
662: do_test shell1-3.24.3 {
663: # too many arguments
664: catchcmd "test.db" ".tables FOO BAD"
665: } {1 {Error: unknown command or invalid arguments: "tables". Enter ".help" for help}}
666:
667: # .timeout MS Try opening locked tables for MS milliseconds
668: do_test shell1-3.25.1 {
669: catchcmd "test.db" ".timeout"
670: } {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}}
671: do_test shell1-3.25.2 {
672: catchcmd "test.db" ".timeout zzz"
673: # this should be treated the same as a '0' timeout
674: } {0 {}}
675: do_test shell1-3.25.3 {
676: catchcmd "test.db" ".timeout 1"
677: } {0 {}}
678: do_test shell1-3.25.4 {
679: # too many arguments
680: catchcmd "test.db" ".timeout 1 BAD"
681: } {1 {Error: unknown command or invalid arguments: "timeout". Enter ".help" for help}}
682:
683: # .width NUM NUM ... Set column widths for "column" mode
684: do_test shell1-3.26.1 {
685: catchcmd "test.db" ".width"
686: } {1 {Error: unknown command or invalid arguments: "width". Enter ".help" for help}}
687: do_test shell1-3.26.2 {
688: catchcmd "test.db" ".width xxx"
689: # this should be treated the same as a '0' width for col 1
690: } {0 {}}
691: do_test shell1-3.26.3 {
692: catchcmd "test.db" ".width xxx yyy"
693: # this should be treated the same as a '0' width for col 1 and 2
694: } {0 {}}
695: do_test shell1-3.26.4 {
696: catchcmd "test.db" ".width 1 1"
697: # this should be treated the same as a '1' width for col 1 and 2
698: } {0 {}}
699:
700: # .timer ON|OFF Turn the CPU timer measurement on or off
701: do_test shell1-3.27.1 {
702: catchcmd "test.db" ".timer"
703: } {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}}
704: do_test shell1-3.27.2 {
705: catchcmd "test.db" ".timer ON"
706: } {0 {}}
707: do_test shell1-3.27.3 {
708: catchcmd "test.db" ".timer OFF"
709: } {0 {}}
710: do_test shell1-3.27.4 {
711: # too many arguments
712: catchcmd "test.db" ".timer OFF BAD"
713: } {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}}
714:
715: do_test shell1-3-28.1 {
716: catchcmd test.db \
717: ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');"
718: } "0 {(123) hello\n456}"
719:
720: puts "CLI tests completed successfully"
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>