Coder Social home page Coder Social logo

Support for multiple result sets about tds HOT 7 CLOSED

ekstrom avatar ekstrom commented on August 16, 2024
Support for multiple result sets

from tds.

Comments (7)

josevalim avatar josevalim commented on August 16, 2024 2

Perhaps the best option is to introduce a separate function, such as query_multi or query_many or similar. So users can explicitly opt-in into it.

from tds.

mjaric avatar mjaric commented on August 16, 2024 1

Released in v2.1.1.

Thank you!

from tds.

mjaric avatar mjaric commented on August 16, 2024

Last year I refactored decoder part, it reads and keeps all results until it must hadoff result to user code. Reason is that ecto expects only single result, so Tds.Protocol pulls out last result here.

Since ecto adapter does not use Tds.query/3 nor Tds.query/4 it is possible to pass additional flag in options that should tell internally Tds.Protocol module to rather return all results. For instance, here it could be something like:

  def query(pid, statement, params, opts \\ []) do
    query = %Query{statement: statement}
    opts = 
      opts
      |> Keyword.put_new(:parameters, params)
      |> Keyword.put(:resultset, true) # <-----   THE FLAG!

    case DBConnection.prepare_execute(pid, query, params, opts) do
      {:ok, _query, result} -> {:ok, result}
      {:error, err} -> {:error, err}
    end
  end

Then it could pack among all results additional info, like messages server returned (info, error ...), num_results, and result set count.

It is worth mentioning that results are in reverse order so they need to be Enum.reversed before they are handed to user code.

from tds.

mjaric avatar mjaric commented on August 16, 2024

One more note, since unit tests also expect single Tds.Result, all must be refactored to pass with this change

from tds.

mjaric avatar mjaric commented on August 16, 2024

@josevalim, @ekstrom , I think this is going to work for any multi batch script for MSSQL Server. It even follows inserts without output. We were lucky I refactored decoder last winter so this was easy to expose

from tds.

mjaric avatar mjaric commented on August 16, 2024

@ekstrom BTW, please point your fork to tds master and run test, but there shouldn't be anything broken

from tds.

ekstrom avatar ekstrom commented on August 16, 2024

Tested it and it works as expected. Thanks for the good work 😄

from tds.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.