Skip to content

Commit

Permalink
Fix #4869, oracledb correctlyINSERTS Buffer (#5167)
Browse files Browse the repository at this point in the history
  • Loading branch information
code-ape committed May 13, 2022
1 parent e2516cd commit ad62d90
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/dialects/oracledb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ class Client_Oracledb extends Client_Oracle {
this
);
} else if (value instanceof BlobHelper) {
return 'EMPTY_BLOB()';
formatter.bindings.push(value.value);
return '?';
}
return unwrapRaw(value, true, builder, this, formatter) || '?';
}
Expand Down
46 changes: 46 additions & 0 deletions test/integration2/dialects/oracledb.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { expect } = require('chai');
const { getAllDbs, getKnexForDb } = require('../util/knex-instance-provider');

describe('Oracledb dialect', () => {
describe('Connection configuration', () => {
const dbs = getAllDbs().filter((db) => db === 'oracledb');

dbs.forEach((db) => {
describe(db, () => {
let knex;
before(() => {
knex = getKnexForDb(db, {
connection: {
user: 'user',
password: 'password',
connectString: 'connect-string',
externalAuth: true,
host: 'host',
database: 'database',
},
});
});

after(() => {
return knex.destroy();
});

describe('#4869 inserting Buffer', async () => {
it('.toSQL().toNative() generates correct sql and bindings for INSERT of Buffer', async () => {
const b = Buffer.from('hello', 'utf-8')
const query = knex('table1').insert({ value: b })
const queryObj = query.toSQL().toNative()
// Ensure we have two bindings, before fix for #4869 there would only have been one due
// to silent dropping of the Buffer.
expect(queryObj.bindings.length).to.eql(2)
expect(queryObj).to.eql({
sql: 'insert into "table1" ("value") values (:1) returning "value" into :2',
bindings: [b, { type: 2019, dir: 3003 }],
});
});
});

});
});
});
});

0 comments on commit ad62d90

Please sign in to comment.