xdenser / node-firebird-libfbclient

Firebird SQL binding
MIT License
82 stars 34 forks source link

Insert not comitted properly using FBTransaction object #115

Closed Kagu-chan closed 3 years ago

Kagu-chan commented 3 years ago

Hi, following Code:

const { createConnection } = require('firebird');

const con = createConnection();
con.connectSync(
  '127.0.0.1/3050:database',
  'sysdba',
  'masterkey',
  ''
);

const query = "INSERT INTO TEST (FOO, ID) VALUES (?, ?)";
const args = [
  "BAR",
  "052160010660508",
];

const transaction = con.startNewTransactionSync();
const result = transaction.prepareSync(query);

result.execSync(...args);
transaction.commitSync();

const res = con.querySync(`SELECT * FROM TEST WHERE ID = '052160010660508'`);
const rows = res.fetchSync('all', true);

console.log('DONE', rows);

If i query the result afterwards from anywhere else, the record is not stored in the database.

If i change the script to use no manual transaction:

const result = con.prepareSync(query);

result.execSync(...args);
con.commitSync();

It works and the result is in the database.

Same behavior with update statements.

Am I doing something wrong?

node -v
=> v12.16.2

package.json:
{
  "name": "fbtest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "firebird": "^0.1.4"
  }
}
xdenser commented 3 years ago

try execInTransSync

Kagu-chan commented 3 years ago

With this it works. Totally not seen the method. Thanks