Skip to content

Commit

Permalink
Work around a driver that report indcols incorrectly (#212)
Browse files Browse the repository at this point in the history
I am using an SQL Server 2008 with ODBC Driver 17 for SQL Server from Microsoft.
It seems for varchar(200) columns it sets indcols to a value larger than 201, causing
a BoundsError. Use the lessor one of elsize and indcols to work around this.
  • Loading branch information
cnliao authored and quinnj committed Oct 27, 2018
1 parent f65e45d commit f779b91
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Query.jl
Expand Up @@ -207,7 +207,7 @@ function cast!(::Type{Union{String, Missing}}, source, col)
elsize = source.sizes[col] + 1
inds = source.indcols[col]
@inbounds for i in 1:len
ind = inds[i]
ind = min(inds[i]|>Int, elsize|>Int)
length = bytes2codeunits(T, max(ind, 0))
c[i] = ind == API.SQL_NULL_DATA ? missing : (length == 0 ? "" : String(transcode(UInt8, data[cur:(cur + length - 1)])))
cur += elsize
Expand Down Expand Up @@ -304,4 +304,4 @@ end
function Source(dsn::DSN, query::AbstractString; weakrefstrings::Bool=true, noquery::Bool=false)
Base.depwarn("`ODBC.Source(dsn, query)` is deprecated in favor of `ODBC.Query(dsn, query)`", nothing)
return Query(dsn, query)
end
end

0 comments on commit f779b91

Please sign in to comment.