OLD | NEW |
1 # 2010 August 4 | 1 # 2010 August 4 |
2 # | 2 # |
3 # The author disclaims copyright to this source code. In place of | 3 # The author disclaims copyright to this source code. In place of |
4 # a legal notice, here is a blessing: | 4 # a legal notice, here is a blessing: |
5 # | 5 # |
6 # May you do good and not evil. | 6 # May you do good and not evil. |
7 # May you find forgiveness for yourself and forgive others. | 7 # May you find forgiveness for yourself and forgive others. |
8 # May you share freely, never taking more than you give. | 8 # May you share freely, never taking more than you give. |
9 # | 9 # |
10 #*********************************************************************** | 10 #*********************************************************************** |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 # catchcmd "test.db" ".import FOO BAR" | 48 # catchcmd "test.db" ".import FOO BAR" |
49 #} {1 {Error: no such table: BAR}} | 49 #} {1 {Error: no such table: BAR}} |
50 do_test shell5-1.1.3 { | 50 do_test shell5-1.1.3 { |
51 # too many arguments | 51 # too many arguments |
52 catchcmd "test.db" ".import FOO BAR BAD" | 52 catchcmd "test.db" ".import FOO BAR BAD" |
53 } {1 {Usage: .import FILE TABLE}} | 53 } {1 {Usage: .import FILE TABLE}} |
54 | 54 |
55 # .separator STRING Change separator used by output mode and .import | 55 # .separator STRING Change separator used by output mode and .import |
56 do_test shell5-1.2.1 { | 56 do_test shell5-1.2.1 { |
57 catchcmd "test.db" ".separator" | 57 catchcmd "test.db" ".separator" |
58 } {1 {Usage: .separator SEPARATOR ?NEWLINE?}} | 58 } {1 {Usage: .separator COL ?ROW?}} |
59 do_test shell5-1.2.2 { | 59 do_test shell5-1.2.2 { |
60 catchcmd "test.db" ".separator ONE" | 60 catchcmd "test.db" ".separator ONE" |
61 } {0 {}} | 61 } {0 {}} |
62 do_test shell5-1.2.3 { | 62 do_test shell5-1.2.3 { |
63 catchcmd "test.db" ".separator ONE TWO" | 63 catchcmd "test.db" ".separator ONE TWO" |
64 } {0 {}} | 64 } {0 {}} |
65 do_test shell5-1.2.4 { | 65 do_test shell5-1.2.4 { |
66 # too many arguments | 66 # too many arguments |
67 catchcmd "test.db" ".separator ONE TWO THREE" | 67 catchcmd "test.db" ".separator ONE TWO THREE" |
68 } {1 {Usage: .separator SEPARATOR ?NEWLINE?}} | 68 } {1 {Usage: .separator COL ?ROW?}} |
69 | 69 |
70 # separator should default to "|" | 70 # column separator should default to "|" |
71 do_test shell5-1.3.1 { | 71 do_test shell5-1.3.1.1 { |
72 set res [catchcmd "test.db" ".show"] | 72 set res [catchcmd "test.db" ".show"] |
73 list [regexp {separator: \"\|\"} $res] | 73 list [regexp {colseparator: \"\|\"} $res] |
| 74 } {1} |
| 75 |
| 76 # row separator should default to "\n" |
| 77 do_test shell5-1.3.1.2 { |
| 78 set res [catchcmd "test.db" ".show"] |
| 79 list [regexp {rowseparator: \"\\n\"} $res] |
74 } {1} | 80 } {1} |
75 | 81 |
76 # set separator to different value. | 82 # set separator to different value. |
77 # check that .show reports new value | 83 # check that .show reports new value |
78 do_test shell5-1.3.2 { | 84 do_test shell5-1.3.2 { |
79 set res [catchcmd "test.db" {.separator , | 85 set res [catchcmd "test.db" {.separator , |
80 .show}] | 86 .show}] |
81 list [regexp {separator: \",\"} $res] | 87 list [regexp {separator: \",\"} $res] |
82 } {1} | 88 } {1} |
83 | 89 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 puts $fd {} | 371 puts $fd {} |
366 close $fd | 372 close $fd |
367 catchcmd test.db [string trim { | 373 catchcmd test.db [string trim { |
368 .mode csv | 374 .mode csv |
369 CREATE TABLE t4(a, b); | 375 CREATE TABLE t4(a, b); |
370 .import shell5.csv t4 | 376 .import shell5.csv t4 |
371 }] | 377 }] |
372 db eval { SELECT * FROM t4 } | 378 db eval { SELECT * FROM t4 } |
373 } {xy\" hello one 2 {} {}} | 379 } {xy\" hello one 2 {} {}} |
374 | 380 |
| 381 #---------------------------------------------------------------------------- |
| 382 # Tests for the shell "ascii" import/export mode. |
| 383 # |
| 384 do_test shell5-3.1 { |
| 385 set fd [open shell5.csv w] |
| 386 fconfigure $fd -encoding binary -translation binary |
| 387 puts -nonewline $fd "\"test 1\"\x1F,test 2\r\n\x1E" |
| 388 puts -nonewline $fd "test 3\x1Ftest 4\n" |
| 389 close $fd |
| 390 catchcmd test.db { |
| 391 .mode ascii |
| 392 CREATE TABLE t5(a, b); |
| 393 .import shell5.csv t5 |
| 394 } |
| 395 db eval { SELECT * FROM t5 } |
| 396 } "\{\"test 1\"} \{,test 2\r\n\} \{test 3\} \{test 4\n\}" |
| 397 |
| 398 do_test shell5-3.2 { |
| 399 set x [catchcmd test.db { |
| 400 .mode ascii |
| 401 SELECT * FROM t5; |
| 402 }] |
| 403 # Handle platform end-of-line differences |
| 404 regsub -all {[\n\r]?\n} $x <EOL> x |
| 405 set x |
| 406 } "0 \{\"test 1\"\x1F,test 2<EOL>\x1Etest 3\x1Ftest 4<EOL>\x1E\}" |
| 407 |
| 408 do_test shell5-4.1 { |
| 409 forcedelete shell5.csv |
| 410 set fd [open shell5.csv w] |
| 411 puts $fd "1,2,3" |
| 412 puts $fd "4,5" |
| 413 puts $fd "6,7,8" |
| 414 close $fd |
| 415 catchcmd test.db [string trim { |
| 416 .mode csv |
| 417 CREATE TABLE t6(a, b, c); |
| 418 .import shell5.csv t6 |
| 419 }] |
| 420 db eval { SELECT * FROM t6 ORDER BY a } |
| 421 } {1 2 3 4 5 {} 6 7 8} |
| 422 |
| 423 do_test shell5-4.2 { |
| 424 forcedelete shell5.csv |
| 425 set fd [open shell5.csv w] |
| 426 puts $fd "1,2,3" |
| 427 puts $fd "4,5" |
| 428 puts $fd "6,7,8,9" |
| 429 close $fd |
| 430 catchcmd test.db [string trim { |
| 431 .mode csv |
| 432 CREATE TABLE t7(a, b, c); |
| 433 .import shell5.csv t7 |
| 434 }] |
| 435 db eval { SELECT * FROM t7 ORDER BY a } |
| 436 } {1 2 3 4 5 {} 6 7 8} |
375 | 437 |
376 finish_test | 438 finish_test |
OLD | NEW |