Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue retrieving BLOB from database (oracle) - iLob attribute undefined #3467

Closed
matthieu-1989 opened this issue Oct 7, 2019 · 12 comments
Closed

Comments

@matthieu-1989
Copy link

Knex version: 0.19.5
Objection version: 1.6.0
Database + version: Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
OS: Windows 10 Professional

@atiertant

While retrieving data from database, if at least one of the result column type is BLOB, the query fails.
Error message:
Cannot read property 'type' of undefined",
"stack":"TypeError: Cannot read property 'type' of undefined
at readStream (my_node_modules\knex\lib\dialects\oracledb\index.js:355:19

Checking "knex\lib\dialects\oracledb\index.js" code. The "stream" input attribute passed to the readStream function (line 355) doesn't have a "iLob" attribute.

Regards,
Matthieu

@kibertoad
Copy link
Collaborator

What version of Oracle driver (nodejs dependency) are you using? There was a major update lately that knex is not compatible with yet.
Does it work better with older knex?

@matthieu-1989
Copy link
Author

We are now using the 4.0.1 version of oracledb. That's true there was no issue with the old 1.13.1 version of oracledb and the 0.13.0 version of knex.

@kibertoad
Copy link
Collaborator

I think it is #3396

@kibertoad
Copy link
Collaborator

@matthieu-1989 Could you please try with 0.20.0?

@lvjkumar
Copy link

lvjkumar commented Nov 4, 2019

Fix doesn't seem to work with BLOB data type.

Checked with knex v0.20.1: CLOB data can be retrieved successfully but knex hangs when retrieving data from a BLOB column. Debugging shows the execution waiting forever at line #353 when trying to concatenate two buffers:
data = Buffer.concat([data, chunk]);
in knex\lib\dialects\oracledb\index.js"

I have oracledb v4.0.1 installed with 'Oracle Database 19c Enterprise Edition Release 19.0.0.0.0'. And I have node running on mac.

@robmcguinness
Copy link

robmcguinness commented Nov 27, 2019

I'm seeing the same results as @lpillai

  • knex v0.20.2
  • instant client v19.3.0
  • oracledb v4.0.1
  • node v12.11.1

investigating 🤔

@robmcguinness
Copy link

robmcguinness commented Nov 27, 2019

Modifying the readStream function at

function readStream(stream, type) {
to

function readStream(stream, type) {
  return new Promise((resolve, reject) => {
    let data;

    if (type === 'string') {
      data = '';
    } else {
      data = Buffer.alloc(0); // allocate to empty Buffer when not string
    }

    stream.on('error', function(err) {
      reject(err);
    });
    stream.on('data', function(chunk) {
      if (type === 'string') {
        data += chunk;
      } else {
        // handle non-string chunking 
        const blobLength = data.length + chunk.length;
        data = Buffer.concat([data, chunk], blobLength);
      }
    });
    stream.on('end', function() {
      resolve(data);
    });
  });
}

resolves the issue. This essentially splits the code to handle streams of type string differently from non-strings.

I'll try and submit a PR when possible.

@kibertoad
Copy link
Collaborator

@robmcguinness Is is the same as https://github.com/knex/knex/pull/3545/files?

If you can confirm that fix is sufficient, I can release a new version with fix.

@robmcguinness
Copy link

@kibertoad it does appear to be the same and more concisely written 😄

@kibertoad
Copy link
Collaborator

Released in 0.20.3

@kibertoad
Copy link
Collaborator

@robmcguinness Please let me know if new version fixes the issue for you!

@robmcguinness
Copy link

the fix appears to work. much appreciated @kibertoad! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants