JuliaDatabases / ODBC.jl

An ODBC interface for the Julia programming language
https://odbc.juliadatabases.org/stable
Other
106 stars 63 forks source link

ODBC query request to MS SQL Server fails with ODBC v0.8.5, works with v0.8.1 #255

Closed ltf-canada closed 4 years ago

ltf-canada commented 4 years ago

I get the following error trying to run my function `ptdf = dbquery(ptdsn, ptabs, ptcols, NONE, ptwhere, NONE, ptorder)'

The error is 'MethodError: no method matching eachcolumn(::Tables.CopiedColumns{NamedTuple{(:CPUID, :Mfg, :Selector, :Processor, :MHz, :Cores, :Sockets, :Threads),Tuple{Array{Union{Missing, Int32},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1}}}}) Closest candidates are: eachcolumn(!Matched::Union{Function, Type}, !Matched::Tables.Schema{names,nothing}, !Matched::Any) where names at C:\Users\jsutherland.julia\packages\Tables\1IgAk\src\utils.jl:109 eachcolumn(!Matched::Union{Function, Type}, !Matched::Tables.Schema{names,types}, !Matched::Any) where {names, types} at C:\Users\jsutherland.julia\packages\Tables\1IgAk\src\utils.jl:66 fromcolumns(::Tables.CopiedColumns{NamedTuple{(:CPUID, :Mfg, :Selector, :Processor, :MHz, :Cores, :Sockets, :Threads),Tuple{Array{Union{Missing, Int32},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1}}}}; copycols::Bool) at tables.jl:13 (::DataFrames.var"#fromcolumns##kw")(::NamedTuple{(:copycols,),Tuple{Bool}}, ::typeof(DataFrames.fromcolumns), ::Tables.CopiedColumns{NamedTuple{(:CPUID, :Mfg, :Selector, :Processor, :MHz, :Cores, :Sockets, :Threads),Tuple{Array{Union{Missing, Int32},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1}}}}) at tables.jl:13 DataFrame(::ODBC.Query{missing,NamedTuple{(:CPUID, :Mfg, :Selector, :Processor, :MHz, :Cores, :Sockets, :Threads),Tuple{Union{Missing, Int32},Union{Missing, String},Union{Missing, String},Union{Missing, String},Union{Missing, Int16},Union{Missing, Int16},Union{Missing, Int16},Union{Missing, Int16}}},Tuple{Array{Union{Missing, Int32},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1}}}; copycols::Bool) at tables.jl:32 DataFrame(::ODBC.Query{missing,NamedTuple{(:CPUID, :Mfg, :Selector, :Processor, :MHz, :Cores, :Sockets, :Threads),Tuple{Union{Missing, Int32},Union{Missing, String},Union{Missing, String},Union{Missing, String},Union{Missing, Int16},Union{Missing, Int16},Union{Missing, Int16},Union{Missing, Int16}}},Tuple{Array{Union{Missing, Int32},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, String},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1},Array{Union{Missing, Int16},1}}}) at tables.jl:23 query(::ODBC.DSN, ::String, ::Type{DataFrame}; weakrefstrings::Bool, append::Bool, transforms::Dict{Int64,Function}) at Query.jl:390 query(::ODBC.DSN, ::String, ::Type{DataFrame}) at Query.jl:385 query(::ODBC.DSN, ::String) at Query.jl:376 dbquery(::ODBC.DSN, ::String, ::String, ::String, ::String, ::String, ::String) at dbfunctions.jl:23 top-level scope at GetSockets.jl:25 ' The created SQL query is 'SELECT ID as CPUID, Mfg, Selector, Processor, MHz, Cores, MaxCPUs as Sockets, Threads FROM dbo.Processors (nolock) WHERE Mfg in ('AMD', 'Intel') ORDER BY Mfg, Selector, Processor' which works without any problem from SQL Management Studio.

The exact code ran without any problem from ODBC v0.8.1

The function being called is '""" Run query on database. """ function dbquery(dsn::ODBC.DSN, dbtable::String, dbwhat::String, dbjoin::String=NONE, dbwhere::String=NONE, dbgroup::String=NONE, dborder::String=NONE)::DataFrame

locdbg = true
selstr = string("SELECT ", dbwhat)
fromstr = string(" FROM ", dbtable)
wherestr = ((dbwhere == NONE) ? NONE : string(" WHERE ", dbwhere))
groupstr = ((dbgroup == NONE) ? NONE : string(" GROUP BY ", dbgroup))
orderstr = ((dborder == NONE) ? NONE : string(" ORDER BY ", dborder))
querystr = string(selstr, fromstr, dbjoin, wherestr, groupstr, orderstr)
locdbg && println("Query: ", querystr)
dbresult = ODBC.query(dsn, querystr)
locdbg && pretty_table(describe(dbresult, :eltype, :nmissing, :first, :last))
return dbresult

end # dbquery '

NONE is defined as const NONE = ""

It appears that ODBC v0.8.5 forces DataFrames to v0.19.4.

Also ODBC v0.8.1 forces Tables to v0.2.11.

I have encountered a real clash of dependencies while trying to resolve this problem.

ltf-canada commented 4 years ago

Note that with ODBC v0.8.5, Tables is at v1.0.2.

ltf-canada commented 4 years ago

This issue is now resolved with the release of ODBC v0.9.0.