Giter Site home page Giter Site logo

Comments (12)

KillWil avatar KillWil commented on June 16, 2024

Hello, I have a similar problem.
When connection "end" or request "done" is fired I can't call another request (same error as baoshan).
How can I run queries synchronously ?

from tedious.

pekim avatar pekim commented on June 16, 2024

Sorry for the lack of activity on this issue. I intend to take a proper look at it this weekend.

from tedious.

pekim avatar pekim commented on June 16, 2024

Because a request can execute multiple statements, multiple done events may be emitted for a single request.

select 4; select 'abc';

So the request's done event is not the right place to initiate another request. Another request can be intiated in the request's completion callback.

var request = new Request("select ...", function(err) {
  if (err) {
    console.log('err', err);
  }

  makeRequest(...);
});

There was also a bug in the Connection's state machine which prevented a new request from being initiated in the Request's completion callback. I've fixed that bug, and added a test to test/integration/connection-test.coffee to verify that a new Request can be initiated.

from tedious.

baoshan avatar baoshan commented on June 16, 2024

Thanks!

Does the current code provide output parameter support?

And, should multiple result sets be obtained through the done event? If I can provide multiple callback, as

new Request("select ...", 
  function processResult1(){}, 
  function processResult2(){}, 
  function completion(){} 
);

Great job!

from tedious.

pekim avatar pekim commented on June 16, 2024

Does the current code provide output parameter support?

No, I am afraid that it does not. I am looking to add support for parameterised requests next, and this will include input and output parameters.

And, should multiple result sets be obtained through the done event?
If I can provide multiple callback, as

No, multiple result sets are provided for with the existing API. Each result set will result in 0 or more row events, followed by a done event.

row
row
...
done
row
row
...
request-completion-callback called

In most use cases I imagine that it would be best to stick to requests with statements that cause only a single result set.

from tedious.

baoshan avatar baoshan commented on June 16, 2024

Enabling multiple result sets indeed satisfies some real needs which should not be ignored totally in my humble opinion :P

Great plan on supporting parameterised request!

from tedious.

pekim avatar pekim commented on June 16, 2024

Multiple result set are supported, as I mentioned previously. Are you suggesting that multiple results should be buffered and presented to (multiple) request completion callbacks?

What would be the advantage over the current events that provide the result sets? What would happen if the number of callbacks doesn't match the number of result sets?

Result set rows can't be buffered, as that might result in vast amounts of memory being consumed.

In general I'd prefer to keep the API relatively low level, and fairly close to the TDS protocol. A higher level API could always be built on top.

I'm sorry if I'm misunderstanding what you're asking for.

from tedious.

baoshan avatar baoshan commented on June 16, 2024

I'm sorry for making you feel confused.

I'm arguing for

In most use cases I imagine that it would be best to stick to requests with statements that cause only a single result set.

since in some real scenarios, multi result sets helps. The current implementation in supporting multiple result sets is so great that I have no idea how it could be improved :)

I'm also fond of the philosophy -- a TDS spec's counterpoint in JavaScript / coffee script.

I'll keep playing tedious :P

from tedious.

pekim avatar pekim commented on June 16, 2024

Thanks. I'm pleased that we're in broad agreement.

from tedious.

kimi23 avatar kimi23 commented on June 16, 2024

HI Pekim,

I am doing a simple insert in nodejs using tedious and when I am trying to put this in a transactions I am getting the error - "Invalid state; requests can only be made in the LoggedIn state, not the SentClientRequest state"

My Code:

var storedProcName = '[Employess].[dbo].[sp_InsertEmployee]';
var request = new Request(storedProcName, function(err, rowCount) {
if(err){
//console.log('Error on select');
}
else {
console.log(rowCount + ' rows');
}
connection.close();
});

request.addParameter('employee_name', TYPES.VarChar, 'Green Day');

request.on('row', function(columns) {
  columns.forEach(function(column) {
     if (column.value != null) {          
      console.log('Value Returned ' + column.value);
    }
  });
});

request.on('doneProc', function(rowCount, more, returnStatus) {      
});

connection.beginTransaction(function(err)
{    
  if(err){
    console.log('Error in transaction ' + err);
  }
  else
  {
    connection.callProcedure(request);
    connection.commitTransaction(function(err){
      if(err){
          console.log('Error in Commiting transaction ' + err);
      }
      else{
          console.log('Transactiuon commited successfully');
      }
    });
  }      
});

and the stored proc is a simple insert which return the @@IDENTITY when completed.

Can you please help ?

Thanks

from tedious.

kimi23 avatar kimi23 commented on June 16, 2024

Hi pekim,

One more question..

How do I call the request in a foreach loop as I need to insert multiple records./

SImple example.. Insert multiple locations for a customer ?

How would I do that?

Where do I call the foreach loop ?? In the callback of request?? How??

Thanks in advance.

Regards,

from tedious.

michelle-becker avatar michelle-becker commented on June 16, 2024

So, I am having the same issue as @kimi23 - was a solution to this ever found? Are there docs somewhere that detail exactly how the tedious transaction logic should work?

from tedious.

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.