Skip to content

Commit 2c8eb87

Browse files
authored
Make type affinity detection more robust (#264)
* Make type affinity detection more robust Fixes #242. * support TEXT(100)
1 parent 339cb22 commit 2c8eb87

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/SQLite.jl

+5-3
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,11 @@ juliatype(x::Integer) =
380380
function juliatype(decl_typestr::AbstractString,
381381
default::Type = Any)
382382
typeuc = uppercase(decl_typestr)
383-
if typeuc in ("INTEGER", "INT")
383+
# try to match the type affinities described in the "Affinity Name Examples" section
384+
# of https://www.sqlite.org/datatype3.html
385+
if typeuc in ("INTEGER", "INT", "TINYINT", "SMALLINT", "MEDIUMINT", "BIGINT", "UNSIGNED BIG INT", "INT2", "INT8")
384386
return Int64
385-
elseif typeuc in ("NUMERIC", "REAL", "FLOAT")
387+
elseif typeuc in ("NUMERIC", "REAL", "FLOAT", "DOUBLE", "DOUBLE PRECISION")
386388
return Float64
387389
elseif typeuc == "TEXT"
388390
return String
@@ -392,7 +394,7 @@ function juliatype(decl_typestr::AbstractString,
392394
return default # FIXME
393395
elseif typeuc == "TIMESTAMP"
394396
return default # FIXME
395-
elseif occursin(r"^(?:N?VAR)?CHAR\(\d+\)$", typeuc)
397+
elseif occursin(r"^N?V?A?R?Y?I?N?G?\s*CHARA?C?T?E?R?T?E?X?T?\s*\(?\d*\)?$"i, typeuc)
396398
return String
397399
elseif occursin(r"^NUMERIC\(\d+,\d+\)$", typeuc)
398400
return Float64

0 commit comments

Comments
 (0)