Skip to Main Content

Programming Languages & Frameworks

oracledb node driver clob output with \n in place of chr(10)

Pollocks01Aug 4 2017 — edited Aug 25 2017

Any way to override apparent default behaviour where carraige return and line feed are substituted in string results with /r, /n?

Same behaviour can be seen for varchar2 and clob columns...which is not surprising since I'm saying oracledb.fetchAsString = [oracledb.CLOB];

test case:

create table otn_clob (id number generated always as identity,

                       clob_column clob);

insert into otn_clob (clob_column)

values('this sentance has a

new line in it');

const oracledb = require('oracledb');

oracledb.createPool(

  {

poolAlias: 'defaultPoo'l,

user: username,

password: password,

connectString: connstring

  })

  .then((pool) => {

pool.getConnection()

  .then((connection) => {

oracledb.fetchAsString = [oracledb.CLOB];

connection.execute('select id, clob_column from otn_clob', // sql

  { }, // binds

  { }) // options

  .then((result) => {

connection.close()

  .then(() => { console.log(result.rows); });

  })

  .catch((queryErr) => {

console.error('create pool: ' + queryErr.message);

connection.close();

  });

  })

  .catch((connectionErr) => {

console.error('create pool: ' + connectionErr.message);

  });

  })

  .catch((poolErr) => {

console.error('create pool: ' + poolErr.message);

  });

output:

[ [ 1, 'this sentance has a\nnew line in it' ] ]

I can understand why oracledb does this - control characters not allowed in JSON.

I have some code that takes these results and converts them to csv using json2csv. The CSV is generated with \n.

Question is: is there a way to override this default behaviour or do I need to parse the json before passing it to the csv converter? ...

This post has been answered by danmcghan-Oracle on Aug 5 2017
Jump to Answer
Comments
Post Details
Added on Aug 4 2017
4 comments
2,095 views