# Multiple Dispatch on input file type?

**URL:** <https://discourse.julialang.org/t/multiple-dispatch-on-input-file-type/3159>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 11, 2017, 3:25am UTC](https://discourse.julialang.org/t/multiple-dispatch-on-input-file-type/3159 "2017-04-11T03:25:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crghilardi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/crghilardi/32/3738_2.png) [@Crghilardi](https://discourse.julialang.org/u/Crghilardi)\
**Post date:** [April 11, 2017, 3:25am UTC](https://discourse.julialang.org/t/multiple-dispatch-on-input-file-type/3159/1 "2017-04-11T03:25:22Z")

</div>

Hi,  
I am looking to write some code that starts with loading some data from a file database. I know it will be either an access database or SQLite database. Since the general mechanism is the same with only the connection string changing,if my understanding is correct I can use multiple dispatch to write a generic LoadDB() function that will choose the appropriate method based on input type. This is more an exercise in wrapping my head around how Julia design works than useful code.

I have the code working mechanically, but I am not sure if this is necessary or even appropriate use of multiple dispatch.

I create a holder type for each possible file type. I then have a file check function that creates an instance of whichever type which is then passed to the loading function.

Is this a reasonable way to accommodate file type on input using the type system or am I over complicating things trying to wedge using multiple dispatch in?

My thoughts are that the types I make seem arbitrary just so I can pass them to the loading function. It seems like I could just write a LoadSQLite() and LoadAccess() function separately in just as many lines. Right now I am just working with 2 possibilities, but it seems like it may be more useful in a situation where I had a whole lot of possibilities.

Thank you

Code:

```julia
using Gtk 
using SQLite
using ODBC

#make holder types with some file info
type SQLitefile
  path::String
  filename::String
  extension::String
end

type Accessfile
  path::String
  filename::String
  extension::String
end

#load functions with conn. strings
function LoadInputDB(x::Accessfile) #add pass file by variable later...
  cnxn_str=ODBC.DSN("Driver={Microsoft Access Driver (*.mdb, *.accdb)};
  DBQ=C:Users/Path/To/Scrap.accdb")
  somedata=ODBC.query(cnxn_str,"SELECT * FROM Table1")
end

function LoadInputDB(x::SQLitefile)
  db = SQLite.DB("Scrap.db")
  somedata= SQLite.query(db,"SELECT * FROM Table1")
end

# initial file check logic
function FindType()
  x=open_dialog("Pick a winner",multiple=true)
  if splitext(x)[2] == ".db"
    infile=SQLitefile(dirname(x),basename(x),splitext(x)[2])
  elseif splitext(x)[2] == ".mdb" || splitext(x)[2] == ".accdb"
    infile=Accessfile(dirname(x),basename(x),splitext(x)[2])
  end
end

LoadInputDB(FindType()) 

```
