question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inserting Buffers for Oracle CLOBs silently fails

See original GitHub issue

Environment

Knex version: 0.95.11 Database + version: Oracle 18c OS: Ubuntu Linux

If issue is about oracledb support, tag @atiertant.

Bug

Behavior

Explain what kind of behavior you are getting and how you think it should do

The oracle-node driver clearly documents that the best way to insert a large string for a CLOB is to simply hand a buffer of that string to the driver for the insert parameter (reference: https://blogs.oracle.com/opal/post/node-oracledb-112-working-with-lobs-as-string-and-buffer-connection-pinging). However, today when you do this Knex silently replaces the Buffer reference with the query string EMPTY_BLOB(). Effectively causing a silent failure which inserts no data! 😢

Error message

None, silent failure.

Reduced test code

// Generate insert SQL
const b = Buffer.from('hello', 'utf-8')
const query = knex('table1').insert({ value: b })
const queryText = query.toSQL().toNative()
console.log(query)

Suggested fixes

Initial tests seem to indicate that this can easily be resolved by changing this code:

https://github.com/knex/knex/blob/bfdece3cdc9a029589cee1c8907d1930edace2cc/lib/dialects/oracledb/index.js#L106-L118

It appears that some work has been done to support this but never completed. A quick test by myself found that the following code worked:

  parameter(value, builder, formatter) {
    if (typeof value === 'function') {
      ...
    } else if (value instanceof BlobHelper) {
      formatter.bindings.push(value.value);
      return '?';
    }
    ...
  }

It’s unclear to me whether or not this is an elegant solution. I suspect you may want to tinker with the Buffer object slightly so that it “pretty prints” better when the query is logged like I did for the example code to reproduce above. Currently it just prints the u8 array which should probably just be replaced by something like [ Buffer of length ${X}].

Additional information

Of important note is that the fallback for using Buffer is to_clob([4000 chars])||to_clob([4000 chars])||... which is around 2,000% slower that using Buffer for inserting a 2MB payload.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
code-apecommented, Dec 7, 2021

I have a working system for standing up Oracle on GitHub actions. A bit swamped today and tomorrow but should have it in my this weekend if that’s alright?

1reaction
kibertoadcommented, Dec 7, 2021

@OlivierCavadenti I’m 95% done with pr for the issue. @code-ape promised to fix CI for oracle, waiting on that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ora-22835 - CLOB Larger Than 4000 Inserted Into Varchar2 ...
My Oracle Support Banner. Ora-22835 - CLOB Larger Than 4000 Inserted Into Varchar2(4000) Column Is Silently Truncated (Doc ID 388512.1).
Read more >
node-oracledb 1.12: Working with LOBs as String and Buffer ...
Adding to the existing support for using CLOBs and BLOBs as Node. js Streams, now Strings and Buffers can be bound to CLOBs...
Read more >
writeappend issue when data is more than 32K — oracle-tech
There is no input for a CLOB. When your CLOB was less than 32k, it was silently being transformed into a VARCHAR2. You'll...
Read more >
Inserting clob performance issue: enable vs disable strorage...
We tried several different storage options (basicfile/securefile, cache / no cache/ cache reads disable/enable in row) but still could not eliminate the buffer...
Read more >
Converting CLOBS TO VARCHAR - Ask TOM
put_line( 'length = ' || length(l_data) ); 6 end; 7 / declare * ERROR at line 1: ORA-06502: PL/SQL: numeric or value error:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found