I can not find any documentation or examples for this. So far I can successfully connect, but I do not know the syntax for selecting and returning data.
:odbc.start() {:ok, conn} = :odbc.connect('DSN=mydsn;UID=myuid;PWD=mypwd', []) :odbc.execute_stmt(conn, 'select count(*) from mytable') :odbc.stop()
** (UndefinedFunctionError) undefined function :: odbc.execute_stmt / 2 (odbc): odbc.execute_stmt (# PID <0.85.0>, 'select count (*) from mytable')
Update 10/6/2015
I have found how to do this. I believe that I could not find documentation about this for Elixir because Elixir simply passes the pass to the Erlang library.
In any case, it is sql_query , or select_count :
{:selected, colNames, rows} = :odbc.sql_query(conn, 'select count(*) from mytable')
{: selected, ['COUNT'], [{'182'}]}
{:ok, count} = :odbc.select_count(conn, 'select * from mytable')
{: ok, 182}
Update 10/7/2015
Here is my last code, which I believe is more idiomatic:
:odbc.start() case :odbc.connect('DSN=mydsn;UID=#{System.get_env("MY_UID")};PWD=#{System.get_env("MY_PASSWORD")}', []) do {:ok, conn} -> case :odbc.sql_query(conn, 'select count(*) from mytable') do {:selected, _colNames, [{count}]} -> IO.puts "count = #{count}" {:error, err} -> {:error, err} end {:error, err} -> {:error, err} end :odbc.stop()