bminer / node-mysql-queues

Wraps 'node-mysql' to provide mulitple query queues, allowing support for multiple statements and transactions.
MIT License
92 stars 11 forks source link

Transaction no longer working #15

Closed pixelfreak closed 12 years ago

pixelfreak commented 12 years ago

I upgraded to 0.3.5 and transaction is no longer working...any idea? 0.3.4 worked fine.

bminer commented 12 years ago

No idea. What is the intended behavior vs. actual behavior?

I would need a bit more information to be able to help. Just a quick snippet of the relevant code might do along with a description of your problem. Thanks.

pixelfreak commented 12 years ago

I'll review my code and get back to you. But what essentially happened was, the transaction is getting rolled back even though there is no error whatsoever. What changes from 0.3.4 to 0.3.5 anyway? Is there a way to get a diff between the two easily on github?

Thanks!

pixelfreak commented 12 years ago

My node-mysql version is @0.9.6 btw

pixelfreak commented 12 years ago

Looks like the only difference between 0.3.4 and 0.3.5 is the this.executing flag was removed?

bminer commented 12 years ago

0.3.4 had a bug where sometimes transactions were auto-committed "too early". It was a really weird bug, and it's hard to explain. Please feel free to review your code and let me know what you think. Commit 7c66cd4eb7c52c435ad8137e6bd05601ed04186a is the only real change between 0.3.4 and 0.3.5

bminer commented 12 years ago

Well, yes, but backwards. The this.executing flag was added in 0.3.5. That's it.

Don't stress over that flag too much. It's possible that your code was "broken" in 0.3.4, as well, but it happened to work because of the bug in 0.3.4. If you want to shoot something my way, I'd be happy to check it out.

pixelfreak commented 12 years ago

@bminer, here's the gist of my code. I am still in process of pinpointing why it is breaking, but I want to make sure I'm not doing something that's obviously wrong.

var dbTransaction = this.db.startTransaction();
dbTransaction.query('SELECT * FROM foo', fooFunctionCallback);
dbTransaction.execute();

function fooFunctionCallback(e, results)
{
        if (e)
    {
        dbTransaction.rollback();
        // Handle error here...
        return;
    }

       dbTransaction.query('SELECT * FROM bar', barFunctionCallback);
}

function barFunctionCallback(e, results)
{
     if (e)
    {
        dbTransaction.rollback();
        // Handle error here...
        return;
    }
     dbTransaction.commit();

     // Handle success here
}
bminer commented 12 years ago

Your code looks good. You said that the transaction does not get committed, right? Are you calling db.end() anywhere in your code? What sort of code do you have under Handle success here?

pixelfreak commented 12 years ago

Yes, Handle success does call db.end(). Sorry, I am still occupied with something else. :( I'll get to debugging this soon!

bminer commented 12 years ago

Yeah, that's your problem, and no worries; take your time. You are calling client.end() before the transaction completes. You need to pass this into the callback of the commit().

trans.commit(function() {client.end();});
//instead of...
trans.commit();
client.end();

Someone else had this exact same issue when upgrading to 0.3.5.

bminer commented 12 years ago

Closing...

pixelfreak commented 12 years ago

Oh, didn't know that. Thanks! I'll give it a try!

bminer commented 12 years ago

No problem! Let me know if you still have issues, and I will re-open this issue. Thanks.