2 select statements on a stored proc: how to get both results? #107

Open
abinop opened this Issue Jan 29, 2013 · 5 comments

Comments

Projects
None yet
3 participants

abinop commented Jan 29, 2013

I have a stored proc that has 2 queries:

CREATE PROCEDURE [dbo].[p_test]
AS
SET NOCOUNT ON;
BEGIN
SELECT 1 a
SELECT 2 b
END

If I call

var sqlstr="EXEC [p_test];
sql.query(conn, sqlstr, function(err, items) {
});

I only get the first result. Is there a way to get both?

Contributor

jkint commented Jan 29, 2013

Interesting. I used your test code (after creating the stored proc):

var sqlstr="EXEC [p_test]";

sql.query(conn, sqlstr, function(err, items, more) {

  assert.ifError( err );

  console.log( items );
  console.log( more );

});

and this is what I receive:

[ { a: 1 } ]
true
[ { b: 2 } ]
false

Queries that return multiple results currently call the callback multiple times. A third parameter, as shown in the example, is a flag that describes if there will be more results (true) or if this is the last result (false).

Hope this helps. And please leave feedback about this feature.

MRdNk commented Jan 29, 2013

Having a callback that returns multiple times, seems a bit odd to me.
@abinop I would suggest using events instead.

Although I notice the events method, gives you rows rather than tables - might be worth having an events function, that returns DataTables.

Contributor

jkint commented Jan 29, 2013

We have received similar feedback already. Thanks for your contribution. It definitely gives us things to consider for future updates.

MRdNk commented Jan 29, 2013

I was just working on a prototype using the current evented query for displaying in DataTables.
https://gist.github.com/4668128

I will add an Event Emitter to it, and take a look at the current implementation.

MRdNk commented Jan 29, 2013

Opened this as a new issue #108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment