Possible "multiple dispatch" due to API differences between package versions?

hi there,
I am wondering whether it is possible to have one function having multiple dispatches simply due to the API changes between package versions.

For example, the newest version of ODBC.jl (v1.0.4), does no longer support ODBC.DSN and the assciated ODBC.query/ODBC.execute. To connect to databases, I need to use ODBC.Connection and DBInterface.execute. My question is that, if I have to maintain environments with different ODBC versions, how can I have one set of codes to accommodate that?

The following multiple dispatch did not work and errored out during initiation when running in the new ODBC environment(UndefVarError: DSN not defined).

function myfunction(dsn::ODBC.DSN)
#my codes
end

function myfunction(cnn::ODBC.Connection)
#my codes
end

Can anybody point out a way, or I have to write two set of codes?

thanks!

You can try something like:

if isdefined(ODBC, :DSN)
    function myfunction(dsn::ODBC.DSN)
    #my codes
    end
else
    function myfunction(cnn::ODBC.Connection)
    #my codes
    end
end
1 Like