livehelpnow / tds_ecto

TDS Adapter for Ecto
57 stars 34 forks source link

Stored procedure return no results #52

Closed drowzy closed 7 years ago

drowzy commented 7 years ago

I'm trying to run a stored procedure using the Ecto.Adapters.SQL.query function.

query =  """
    declare @Foo uniqueidentifier = 'C9DED692-1E44-42EC-8411-7C1A813FC7EB'
    declare @Pointer aggregate.Pointer
    insert into @Pointer values (@Foo, null)
    exec aggregate.[Read] @Pointer
"""
Ecto.Adapters.SQL.query(Repo, query, [])

Result returned is:

{:ok, %Tds.Result{columns: nil, command: nil, num_rows: 1, rows: nil}}

I've tested to run the same code elsewhere and it works fine, it returns the two rows I expected.

What do I do?

mjaric commented 7 years ago

The way you use it is not supported yet, that is multi resultset query you wrote. First result (which you got) is number of rows you inserted into table, and that is the point where tds driver will stop parsing result (you can see num_rows == 1), second result should be rows, which I'm sure they were received when you executed, but they were not parsed since ECTO "doesn't like" multiple results, the module function Ecto.Adapters.SQL.query is built in ecto library which will always return single result.

drowzy commented 7 years ago

Alright, thanks for the response! I'll use a different approach.