Skip to content

Reading FBBlob crashes when using manual transaction #116

@Kagu-chan

Description

@Kagu-chan

Following Code:

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

const isFBBlob = (obj) => {
  return (
    obj &&
    typeof obj === 'object' &&
    'isReadable' in obj &&
    'inAsyncCall' in obj
  );
};

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

const query = "SELECT AMSIDNR, INFO, GRUND FROM TERMIN WHERE AMSIDNR = ?;";
const args = [
  "ITE000000225314",
]

const obj = con;
// const obj = con.startNewTransactionSync();

const result = obj.prepareSync(query);

// result.execInTransSync(obj, ...(args || []));
result.execSync(...(args || []));

const res = result.fetchSync('all', true);

function getData(rows) {
  return Promise.all(
    rows.map(async row => {
      let key;
  
      for (key in row) {
        if (row[key]) {
          const val = row[key];
  
          if (isFBBlob(val)) {
            row[key] = await new Promise((resolve, reject) => {
              val._readAll((err, bf) => {
                if (err) {
                  reject(err);
                }
  
                resolve(bf);
              });
            });
          }
        }
      }
  
      return row;
    }),
  )
}

getData(res).then((rows) => {
  obj.commitSync();
  console.log(rows);
});

This code runs through just fine. In the sample here, the field INFO is a BLOB_SUBTYPE_TEXT.
As soon as i switch the lines 25 / 26 and 30 / 31 to use a manual created transaction, the code just stops and the process dies without a word.

After some testing i can say that the code crashes as soon as FBBlob._openSync() (index.js#L105 in this repo) is called - the same when trying to use the stream class (index.js#L162).

Is there (again #115 ) a method / parameter i missed or is this a limitation at any point?

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions