Skip to content

Commit

Permalink
Add support to fetch RAW types as string - Fix for Issue #1586
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadraju committed Aug 17, 2023
1 parent 9f36f27 commit 8239866
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
7 changes: 7 additions & 0 deletions doc/src/release_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ Common Changes
Oracle Database instance name associated with the connection. This returns the
same value as the SQL expression ``sys_context('userenv', 'instance_name')``.

Thin Mode Changes
+++++++++++++++++

#) Add support to fetch RAW types as string using
``oracledb.fetchAsString = [oracledb.DB_TYPE_RAW];``
`Issue #1586 <https://github.com/oracle/node-oracledb/issues/1586>`__.

node-oracledb `v6.0.3 <https://github.com/oracle/node-oracledb/compare/v6.0.2...v6.0.3>`__ (12 Jul 2023)
--------------------------------------------------------------------------------------------------------

Expand Down
11 changes: 7 additions & 4 deletions lib/impl/resultset.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,17 @@ class ResultSetImpl {
if (metadata.dbType === types.DB_TYPE_NUMBER &&
metadata.fetchType === types.DB_TYPE_NUMBER) {
converter = (v) => (v === null) ? null : parseFloat(v);
} else if (metadata.fetchType === types.DB_TYPE_VARCHAR &&
(metadata.dbType === types.DB_TYPE_BINARY_DOUBLE ||
} else if (metadata.fetchType === types.DB_TYPE_VARCHAR) {
if (metadata.dbType === types.DB_TYPE_BINARY_DOUBLE ||
metadata.dbType === types.DB_TYPE_BINARY_FLOAT ||
metadata.dbType === types.DB_TYPE_DATE ||
metadata.dbType === types.DB_TYPE_TIMESTAMP ||
metadata.dbType === types.DB_TYPE_TIMESTAMP_LTZ ||
metadata.dbType === types.DB_TYPE_TIMESTAMP_TZ)) {
converter = (v) => (v === null) ? null : v.toString();
metadata.dbType === types.DB_TYPE_TIMESTAMP_TZ) {
converter = (v) => (v === null) ? null : v.toString();
} else if (metadata.dbType === types.DB_TYPE_RAW) {
converter = (v) => (v === null) ? null : v.toString('hex').toUpperCase();
}
}
if (userConverter && converter) {
const internalConverter = converter;
Expand Down
31 changes: 31 additions & 0 deletions test/dataTypeRaw.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('42. dataTypeRaw.js', function() {
let connection = null;
let tableName = "nodb_raw";
let insertID = 1;
const bufferToHexString = (v) => (v === null) ? null : v.toString('hex').toUpperCase();

let bufLen = [10, 100, 1000, 2000]; // buffer length
let bufs = [];
Expand Down Expand Up @@ -316,6 +317,7 @@ describe('42. dataTypeRaw.js', function() {
after(async function() {
await connection.execute(
"DROP table " + tableName + " PURGE");
oracledb.fetchAsString = [];
});

beforeEach(function() {
Expand All @@ -340,6 +342,18 @@ describe('42. dataTypeRaw.js', function() {
await test1_default(insertedBuf);
});

it('42.5.4 works with default type/dir and fetch as string', async function() {
let insertedStr = random.getRandomLengthString(2000);
let insertedBuf = Buffer.from(insertedStr);
await test1_default_string(insertedBuf);
});

it('42.5.5 works with data size 2000 and fetch as string', async function() {
let insertedStr = random.getRandomLengthString(2000);
let insertedBuf = Buffer.from(insertedStr);
await test1_string(insertedBuf);
});

}); // 42.5

describe('42.6 UPDATE', function() {
Expand Down Expand Up @@ -388,13 +402,23 @@ describe('42. dataTypeRaw.js', function() {
await fetch(content);
};

let test1_string = async function(content) {
await insert(content);
await fetchString(bufferToHexString(content));
};

let test1_default = async function(content) {

await insert_default(content);

await fetch(content);
};

let test1_default_string = async function(content) {
await insert_default(content);
await fetchString(bufferToHexString(content));
};

let test2 = async function(insertedStr, updateStr) {

await insert(insertedStr);
Expand Down Expand Up @@ -466,4 +490,11 @@ describe('42. dataTypeRaw.js', function() {
let result = await connection.execute(sql);
assert.deepStrictEqual(result.rows[0][0], expected);
};

let fetchString = async function(expected) {
oracledb.fetchAsString = [oracledb.DB_TYPE_RAW];
let sql = "select content from " + tableName + " where num = " + insertID;
let result = await connection.execute(sql);
assert.deepStrictEqual(result.rows[0][0], expected);
};
});

0 comments on commit 8239866

Please sign in to comment.