Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix batch inserts with DEFAULT values with OracleDB (#2592) #5037

Merged
merged 1 commit into from Feb 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/dialects/oracledb/query/oracledb-querycompiler.js
Expand Up @@ -156,8 +156,8 @@ class Oracledb_Compiler extends Oracle_Compiler {
// later position binding will only convert the ? params
subSql = self.formatter.client.positionBindings(subSql);
const parameterizedValuesWithoutDefaultAndBlob = parameterizedValues
.replace('DEFAULT, ', '')
.replace(', DEFAULT', '')
.replace(/DEFAULT, /g, '')
.replace(/, DEFAULT/g, '')
.replace('EMPTY_BLOB(), ', '')
.replace(', EMPTY_BLOB()', '');
return (
Expand Down
16 changes: 16 additions & 0 deletions test/integration/dialects/oracledb.js
Expand Up @@ -55,6 +55,22 @@ describe('Oracle', () => {
returning: ['id'],
});
});

it('correctly handles default values in batch inserts', async () => {
const qb = knexInstance.client.queryBuilder();
qb.insert([
{ value1: 1, value2: 2, value3: 3, value4: 4 },
{ value1: 1 },
]).into('fakeTable');
const compiler = knexInstance.client.queryCompiler(qb);
const sql = compiler.insert();
expect(sql.sql).to.eql(
'begin execute immediate \'insert into "fakeTable" ("value1", "value2", "value3", "value4") values ' +
'(:1, :2, :3, :4)\' using ?, ?, ?, ?; ' +
'execute immediate \'insert into "fakeTable" ("value1", "value2", "value3", "value4") values ' +
'(:1, DEFAULT, DEFAULT, DEFAULT)\' using ?;end;'
);
});
});

describe('OracleDb externalAuth', function () {
Expand Down
3 changes: 3 additions & 0 deletions test/integration/query/trigger-inserts.js
Expand Up @@ -1228,8 +1228,11 @@ module.exports = function (knex) {
.insert(
[
{
first_name: 'TestUser',
last_name: 'First Item',
phone: '01',
email: 'single-test1@example.com',
balance: 1.23,
about: 'Lorem ipsum Dolore labore incididunt enim.',
created_at: new Date(),
updated_at: new Date(),
Expand Down