xdenser / node-firebird-libfbclient

Firebird SQL binding
MIT License
82 stars 34 forks source link

updating in a transaction has no effect #117

Closed sqllyw closed 3 years ago

sqllyw commented 3 years ago

Hi,

I have some code as following, if I use the connection object's prepareSync, it works, but if I startNewTransaction, the update did not happen in the database, any idea? Thanks.

var fb  = require("firebird");
sys = require("sys"); 
var con = fb.createConnection();
con.connectSync("10.114.173.149://opt/firebird/examples/employee.fdb", 'sysdba', 'masterkey', '');

var sql = `update country set currency = 'Lira9' where country = 'Italy'`

// working code
const result = con.prepareSync(sql );
result.execSync()
con.commitSync()

/* not working
con.startNewTransaction( (err, tx) => {

    const result = tx.prepareSync(sql );
    result.execSync()
    tx.commitSync()

})*/
sqllyw commented 3 years ago

if con.disconnect(), it works, but the code is used in a web app, and con.disconnect after every update does not seems a good approach

con.startNewTransaction( (err, tx) => {

    const result = tx.prepareSync(sql );
    result.execSync()
    tx.commitSync()
    con.disconnect()  // adding this works
})
xdenser commented 3 years ago

See execInTransSync/execInTrans

sqllyw commented 3 years ago

execInTransSync works, thanks