Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/SQLite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,14 @@ end
#int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*);

# get julia type for given column of the given statement
function juliatype(handle, col)
function juliatype(handle, col, scanrows::Bool = false)
stored_typeid = C.sqlite3_column_type(handle, col - 1)
did_row_scan = false
while stored_typeid == C.SQLITE_NULL
while scanrows && stored_typeid == C.SQLITE_NULL
# Scan forward through the rows until we find a non-NULL value for this column
st = C.sqlite3_step(handle)
did_row_scan = true
if st == C.SQLITE_DONE
break
end
st == C.SQLITE_ROW || break
stored_typeid = C.sqlite3_column_type(handle, col - 1)
if stored_typeid != C.SQLITE_NULL
break
Expand Down
2 changes: 1 addition & 1 deletion src/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function DBInterface.execute(
nm = newnm
end
header[i] = nm
types[i] = Union{juliatype(handle, i),Missing}
types[i] = Union{juliatype(handle, i, strict && status == C.SQLITE_ROW),Missing}
end
return Query{strict}(
stmt,
Expand Down
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,19 @@ end
end

@testset "strict mode" begin
@testset "Issue #353: ALTER TABLE on a STRICT table" begin
for strict in (false, true)
db = SQLite.DB()
DBInterface.execute(db, "CREATE TABLE t (a INTEGER) STRICT")
stmt = DBInterface.prepare(db, "ALTER TABLE t ADD COLUMN b INTEGER")
query = DBInterface.execute(stmt, (); strict = strict)

@test isempty(query)
info = DBInterface.execute(db, "PRAGMA table_info(t)") |> columntable
@test info.name == ["a", "b"]
end
end

@testset "PR #343: strict (and only strict) tables should error if types don't match" begin
db = SQLite.DB()

Expand Down
Loading