Skip to content

Queries are not executed after transaction rolled back #248

Closed
bartkowiakmateusz opened this Issue Jul 16, 2012 · 1 comment

2 participants

@bartkowiakmateusz

I want to execute transactions in node-mysql (by exetucing queries BEGIN, ROLLBACK, COMMIT). I have that piece of code:

conn.query("START TRANSACTION");
conn.query("INSERT INTO users (id, name, age) VALUES (1, 'Mat', '24')", function(e){
    if (e){
        conn.query("ROLLBACK", callback);
    }
    else{
        conn.query("COMMIT", callback);
    }
});

conn.query("INSERT INTO users (name, age) VALUES ('Mat', '24')", function(e, r){
    console.log(e); // null
    console.log(r); // {fieldCount: 0, affectedRows: 1, insertId: 2, serverStatus: 3, warningCount: 0, message: ''}
});

To test rollback case I have intentionally set id to 1, which causes index duplicate error. The transaction is rolled back, but the problem is that the second insert, which is outside the transaction is not executed. There is no error logged, and - what is strange for me - when I select whole table just after that second insert, there is new row in results. But in another connections it disappears. So it looks like at the end of connection newly created row is deleted. The problem doesn't appear when transaction is commited.

@Sannis
Sannis commented Jul 23, 2012

It runs in same transaction, because conn.query("INSERT... callback executes after conn.query("INSERT... Mat....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.