Skip to content

Commit a61b38e

Browse files
committed
Fix #193 by detecting case-insensitive column names before loading data and throw informative error
1 parent e9b3b4c commit a61b38e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/tables.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,11 @@ function load!(itr, db::DB, name::AbstractString="sqlitejl_"*Random.randstring(5
141141
return load!(sch, rows, db, nm, name, status == SQLITE_DONE; kwargs...)
142142
end
143143

144+
checkdupnames(names) = length(unique(map(x->lowercase(String(x)), names))) == length(names) || error("duplicate case-insensitive column names detected; sqlite doesn't allow duplicate column names and treats them case insensitive")
145+
144146
function load!(sch::Tables.Schema, rows, db::DB, nm::AbstractString, name, shouldcreate; temp::Bool=false, ifnotexists::Bool=false)
147+
# check for case-insensitive duplicate column names (sqlite doesn't allow)
148+
checkdupnames(sch.names)
145149
# create table if needed
146150
shouldcreate && createtable!(db, nm, sch; temp=temp, ifnotexists=ifnotexists)
147151
# build insert statement
@@ -168,6 +172,7 @@ function load!(::Nothing, rows, db::DB, nm::AbstractString, name, shouldcreate;
168172
row, st = state
169173
names = propertynames(row)
170174
sch = Tables.Schema(names, nothing)
175+
checkdupnames(sch.names)
171176
# create table if needed
172177
shouldcreate && createtable!(db, nm, sch; temp=temp, ifnotexists=ifnotexists)
173178
# build insert statement

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,7 @@ SQLite.load!(nothing, Tables.rows(r), db, "T2", "T2", true)
289289
r2 = DBInterface.execute(db, "SELECT * FROM T2") |> columntable
290290
@test r == r2
291291

292+
# throw informative error on duplicate column names #193
293+
@test_throws ErrorException SQLite.load!((a=[1,2,3], A=[1,2,3]), db)
294+
292295
end # @testset

0 commit comments

Comments
 (0)