1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Add --schema S option to .import

FossilOrigin-Name: 38d9dbca166078013a44214c88805fc7cca578976ceed9fc62f5159a38ec96a7
This commit is contained in:
larrybr
2022-01-13 21:22:54 +00:00
parent 8efc6a8c09
commit 738d7b9fc0
4 changed files with 34 additions and 23 deletions

View File

@ -88,8 +88,9 @@ do_test shell5-1.4.2 {
forcedelete shell5.csv
set in [open shell5.csv w]
close $in
set res [catchcmd "test.db" {.import shell5.csv t1
SELECT COUNT(*) FROM t1;}]
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
.import -schema test shell5.csv t1
SELECT COUNT(*) FROM test.t1;}]
} {0 0}
# import file with 1 row, 1 column (expecting 2 cols)
@ -97,7 +98,8 @@ do_test shell5-1.4.3 {
set in [open shell5.csv w]
puts $in "1"
close $in
set res [catchcmd "test.db" {.import shell5.csv t1}]
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
.import -schema test shell5.csv t1}]
} {1 {shell5.csv:1: expected 2 columns but found 1 - filling the rest with NULL}}
# import file with 1 row, 3 columns (expecting 2 cols)
@ -105,7 +107,8 @@ do_test shell5-1.4.4 {
set in [open shell5.csv w]
puts $in "1|2|3"
close $in
set res [catchcmd "test.db" {.import shell5.csv t1}]
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
.import --schema test shell5.csv t1}]
} {1 {shell5.csv:1: expected 2 columns but found 3 - extras ignored}}
# import file with 1 row, 2 columns
@ -126,8 +129,9 @@ do_test shell5-1.4.6 {
puts $in "2|3"
puts $in "3|4"
close $in
set res [catchcmd "test.db" {.import shell5.csv t1
SELECT COUNT(*) FROM t1;}]
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
.import -schema test shell5.csv t1
SELECT COUNT(*) FROM test.t1;}]
} {0 3}
# import file with 1 row, 2 columns, using a comma
@ -135,9 +139,10 @@ do_test shell5-1.4.7 {
set in [open shell5.csv w]
puts $in "4,5"
close $in
set res [catchcmd "test.db" {.separator ,
.import shell5.csv t1
SELECT COUNT(*) FROM t1;}]
set res [catchcmd ":memory:" {ATTACH 'test.db' AS test;
.separator ,
.import --schema test shell5.csv t1
SELECT COUNT(*) FROM test.t1;}]
} {0 4}
# import file with 1 row, 2 columns, text data