mirror of
https://github.com/sqlite/sqlite.git
synced 2026-01-06 08:01:16 +03:00
CLI .import can auto-rename non-unique column names when it creates a new table
FossilOrigin-Name: 4b5d07ea7e6f5d6f1279c88bc474ee4bc8bd2cebe38a268f211f47e44569e4b1
This commit is contained in:
@@ -476,4 +476,53 @@ CREATE TABLE t8(a, b, c);
|
||||
db eval { SELECT * FROM t8 }
|
||||
} {1 2 3}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests for the shell automatic column rename.
|
||||
#
|
||||
|
||||
# Import columns containing duplicates
|
||||
do_test shell5-5.1 {
|
||||
set out [open shell5.csv w]
|
||||
fconfigure $out -translation lf
|
||||
puts $out {"","x","x","y","z","z_0","z_5","z"}
|
||||
puts $out {0,"x2","x3","y4","z5","z6","z7","z8"}
|
||||
close $out
|
||||
forcedelete test.db
|
||||
catchcmd test.db {.import -csv shell5.csv t1
|
||||
.mode line
|
||||
SELECT * FROM t1;}
|
||||
} {1 { ? = 0
|
||||
x_02 = x2
|
||||
x_03 = x3
|
||||
y = y4
|
||||
z_05 = z5
|
||||
z_0 = z6
|
||||
z_5 = z7
|
||||
z_08 = z8
|
||||
Columns renamed during .import shell5.csv due to duplicates:
|
||||
"x" to "x_02",
|
||||
"x" to "x_03",
|
||||
"z" to "z_05",
|
||||
"z" to "z_08"}}
|
||||
|
||||
do_test shell5-5.1 {
|
||||
set out [open shell5.csv w]
|
||||
fconfigure $out -translation lf
|
||||
puts $out {"COW","cow","CoW","cOw"}
|
||||
puts $out {"uuu","lll","ulu","lul"}
|
||||
close $out
|
||||
forcedelete test.db
|
||||
catchcmd test.db {.import -csv shell5.csv t1
|
||||
.mode line
|
||||
SELECT * FROM t1;}
|
||||
} {1 {COW_1 = uuu
|
||||
cow_2 = lll
|
||||
CoW_3 = ulu
|
||||
cOw_4 = lul
|
||||
Columns renamed during .import shell5.csv due to duplicates:
|
||||
"COW" to "COW_1",
|
||||
"cow" to "cow_2",
|
||||
"CoW" to "CoW_3",
|
||||
"cOw" to "cOw_4"}}
|
||||
|
||||
finish_test
|
||||
|
||||
Reference in New Issue
Block a user