Search code examples
node.jsoracle-databasenode-oracledb

Writing utf8 strings in oracle CLOB stream gives additional spaces (node.js)


I use node.js, oracle and oracledb module. Also I have a simple PL/SQL procedure like this

    procedure mock_lobs(
        P_CLOB  IN OUT CLOB,
        P_BLOB  IN OUT BLOB
    )
    AS
    BEGIN
      NULL;
    END mock_lobs;

It returns exactly what has been passed.

Then I create a temporary CLOB object using API clob = connection.createLob(oracledb.CLOB) and populate it with some unicode string chunks (several iterations) like this clob.write(chunk)

After the clob is passed to procedure execution I receive resulting CLOB object and try to read it. I see my chunks were written with additional spaces after each one. When I write a string like "abcЩ" with length of 4 symbols it's written as "abcЩ " (tailing spaces for each non-ASCII symbol). In other words size of written chunk equals the number of bytes the original strings takes.

I've tried to specify utf8 encoding for clob like this: clob.setEncoding('utf8') and even while writing clob.write(chunk, 'utf8') but result is always the same.

What's the problem explanation? What am I missing?


Solution

  • node-oracledb mantainers confirmed it is a bug. So, we'll be up for next releases!