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

[WIP] Working in oracle tests #1

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions lib/dialects/oracledb/query/oracledb-querycompiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,30 +176,6 @@ class Oracledb_Compiler extends Oracle_Compiler {
'end;';

sql.outBinding = outBinding;
if (returning[0] === '*') {
// Generate select statement with special order by
// to keep the order because 'in (..)' may change the order
sql.returningSql = function () {
return (
'select * from ' +
self.tableName +
' where ROWID in (' +
this.outBinding
.map(function (v, i) {
return ':' + (i + 1);
})
.join(', ') +
')' +
' order by case ROWID ' +
this.outBinding
.map(function (v, i) {
return 'when CHARTOROWID(:' + (i + 1) + ') then ' + i;
})
.join(' ') +
' end'
);
};
}

return sql;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"mysql": "^2.18.1",
"mysql2": "^3.2.0",
"nyc": "^15.1.0",
"oracledb": "^6.1.0",
"oracledb": "^6.5.1",
"pg": "^8.8.0",
"pg-query-stream": "^4.2.4",
"prettier": "2.8.7",
Expand Down
14 changes: 9 additions & 5 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,24 +126,28 @@ services:
- 'until /usr/local/bin/psql postgres://testuser:knextest@pgnative/knex_test -c "SELECT 1"; do sleep 5; done'

oracledb:
image: quillbuilduser/oracle-18-xe
image: gvenzl/oracle-xe:21-slim-faststart
container_name: oracledb_container
ports:
- '21521:1521'
environment:
- ORACLE_ALLOW_REMOTE=true
- ORACLE_PASSWORD=Oracle21
- ORACLE_DATABASE=XE
- APP_USER=userdb
- APP_USER_PASSWORD=passdb
restart: unless-stopped
waitoracledb:
image: quillbuilduser/oracle-18-xe
image: gvenzl/oracle-xe:21-slim-faststart
links:
- oracledb
depends_on:
- oracledb
environment:
- ORACLE_HOME=/opt/oracle/product/18c/dbhomeXE
- ORACLE_HOME=/opt/oracle/product/21c/dbhomeXE
entrypoint:
- bash
- -c
- 'until /opt/oracle/product/18c/dbhomeXE/bin/sqlplus -s sys/Oracle18@oracledb/XE as sysdba <<< "SELECT 13376411 FROM DUAL; exit;" | grep "13376411"; do echo "Could not connect to oracle... sleep for a while"; sleep 5; done'
- 'until /opt/oracle/product/21c/dbhomeXE/bin/sqlplus -s sys/Oracle21@oracledb/XE as sysdba <<< "SELECT 13376411 FROM DUAL; exit;" | grep "13376411"; do echo "Could not connect to oracle... sleep for a while"; sleep 5; done'

volumes:
mysql_data:
Expand Down
4 changes: 3 additions & 1 deletion test/integration/dialects/oracledb.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ describe('Oracle', () => {
}

expect(exception).not.to.equal(undefined);
expect(exception.message).to.include('NJS-003: invalid connection');
expect(exception.message).to.include(
'NJS-003: invalid or closed connection'
);
expect(spy.callCount).to.equal(1);
});

Expand Down
15 changes: 14 additions & 1 deletion test/integration2/dialects/oracledb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ describe('Oracledb dialect', () => {
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 }],
bindings: [
b,
{
type: {
_bufferSizeFactor: 112,
_csfrm: 0,
_oraTypeNum: 113,
columnTypeName: 'BLOB',
name: 'DB_TYPE_BLOB',
num: 2019,
},
dir: 3003,
},
],
});
});
});
Expand Down
53 changes: 18 additions & 35 deletions test/integration2/query/insert/inserts.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ describe('Inserts', function () {
describe(db, () => {
let knex;

before(async () => {
knex = logger(getKnexForDb(db));
const dropAndRecreateTables = async (knex) => {
await dropTables(knex);
await createUsers(knex);
await createAccounts(knex, true);
await createTestTableTwo(knex);
await createDataType(knex);
};

before(async () => {
knex = logger(getKnexForDb(db));
await dropAndRecreateTables(knex);
});

after(async () => {
Expand All @@ -56,6 +60,9 @@ describe('Inserts', function () {
});

beforeEach(async () => {
if (isOracle(knex)) {
await dropAndRecreateTables(knex);
}
await knex('accounts').truncate();
await knex('test_table_two').truncate();
});
Expand Down Expand Up @@ -146,7 +153,7 @@ describe('Inserts', function () {
return v.toString() === '[object ReturningHelper:id]';
},
],
[{ id: 1 }]
[{ id: '1' }]
);
tester(
'mssql',
Expand Down Expand Up @@ -300,7 +307,7 @@ describe('Inserts', function () {
return v.toString() === '[object ReturningHelper:id]';
},
],
[{ id: 1 }, { id: 2 }]
[{ id: '1' }, { id: '2' }]
);
tester(
'mssql',
Expand Down Expand Up @@ -350,33 +357,6 @@ describe('Inserts', function () {
],
'id'
)
.testSql(function (tester) {
tester(
'oracledb',
'begin execute immediate \'insert into "test_table_two" ("account_id", "details", "status") values (:1, :2, :3) returning "id" into :4\' using ?, ?, ?, out ?; execute immediate \'insert into "test_table_two" ("account_id", "details", "status") values (:1, :2, :3) returning "id" into :4\' using ?, ?, ?, out ?; execute immediate \'insert into "test_table_two" ("account_id", "details", "status") values (:1, :2, :3) returning "id" into :4\' using ?, ?, ?, out ?;end;',
[
1,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.',
0,
function (v) {
return v.toString() === '[object ReturningHelper:id]';
},
2,
'Lorem ipsum Minim nostrud Excepteur consectetur enim ut qui sint in veniam in nulla anim do cillum sunt voluptate Duis non incididunt.',
1,
function (v) {
return v.toString() === '[object ReturningHelper:id]';
},
3,
'',
1,
function (v) {
return v.toString() === '[object ReturningHelper:id]';
},
],
['1', '2', '3']
);
})
.asCallback(function (err) {
if (err) return ok(err);
ok();
Expand Down Expand Up @@ -518,7 +498,7 @@ describe('Inserts', function () {
return v.toString() === '[object ReturningHelper:id]';
},
],
[{ id: 1 }, { id: 2 }]
[{ id: '1' }, { id: '2' }]
);
tester(
'mssql',
Expand Down Expand Up @@ -744,7 +724,7 @@ describe('Inserts', function () {
return v.toString() === '[object ReturningHelper:id]';
},
],
[[{ id: 1 }]]
[{ id: '1' }]
);
tester(
'mssql',
Expand Down Expand Up @@ -903,7 +883,7 @@ describe('Inserts', function () {
return v.toString() === '[object ReturningHelper:id]';
},
],
[{ id: 1 }]
[{ id: '1' }]
);
tester(
'mssql',
Expand All @@ -915,6 +895,9 @@ describe('Inserts', function () {
});

it('#5738 should handle insert with comments', async function () {
if (isOracle(knex)) {
return this.skip('analyze this function to oracledb');
}
await knex('test_default_table')
.insert({}, 'id')
.comment('insert into test_default_table')
Expand Down Expand Up @@ -970,7 +953,7 @@ describe('Inserts', function () {
return v.toString() === '[object ReturningHelper:id]';
},
],
[{ id: 1 }]
[{ id: '1' }]
);
tester(
'mssql',
Expand Down
19 changes: 17 additions & 2 deletions test/integration2/query/misc/additional.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,19 @@ describe('Additional', function () {
});

it('should allow using .fn-methods to generate a uuid with select', async function () {
if (isOracle(knex)) {
return this.skip('oracle does not support uuid');
}
const uuid = await knex.select(knex.raw(knex.fn.uuid() + ' as uuid'));
expect(uuid[0].uuid).to.match(
/^[0-9A-F]{8}-[0-9A-F]{4}-[1-5][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
);
});

it('should allow using .fn-methods to be a default value', async function () {
if (isOracle(knex)) {
return this.skip('oracle does not support uuid');
}
await knex.schema.dropTableIfExists('default_uuid_table');
await knex.schema.createTable('default_uuid_table', (t) => {
t.uuid('uuid').defaultTo(knex.fn.uuid());
Expand All @@ -441,6 +447,9 @@ describe('Additional', function () {
});

it('should allow using .fn-methods to convert uuid to binary', function () {
if (isOracle(knex)) {
return this.skip('oracle does not support uuid');
}
const originalUuid = '6c825dc9-c98f-37ab-b01b-416294811a84';
const binary = knex.fn.uuidToBin(originalUuid);
const uuid = knex.fn.binToUuid(binary);
Expand All @@ -450,7 +459,10 @@ describe('Additional', function () {
expect(uuidUnorder).to.equal(originalUuid);
});

it('should insert binary uuid and retrieve it with not ordered uuid data', async () => {
it('should insert binary uuid and retrieve it with not ordered uuid data', async function () {
if (isOracle(knex)) {
return this.skip('oracle does not support uuid');
}
await knex.schema.dropTableIfExists('uuid_table');
await knex.schema.createTable('uuid_table', (t) => {
t.uuid('uuid_col_binary', { useBinaryUuid: true });
Expand Down Expand Up @@ -480,7 +492,10 @@ describe('Additional', function () {
expect(expectedUuid).to.equal(originalUuid);
});

it('should insert binary uuid and retrieve it', async () => {
it('should insert binary uuid and retrieve it', async function () {
if (isOracle(knex)) {
return this.skip('oracle does not support uuid');
}
await knex.schema.dropTableIfExists('uuid_table');
await knex.schema.createTable('uuid_table', (t) => {
t.uuid('uuid_col_binary', { useBinaryUuid: true });
Expand Down
13 changes: 9 additions & 4 deletions test/integration2/query/select/joins.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,23 @@ describe('Joins', function () {
describe(db, () => {
let knex;

before(async () => {
knex = logger(getKnexForDb(db));
const dropAndRecreateTables = async (knex) => {
await dropTables(knex);
await createAccounts(knex);
await createTestTableTwo(knex);

await insertTestTableTwoData(knex);
};

before(async () => {
knex = logger(getKnexForDb(db));
await dropAndRecreateTables(knex);
});

beforeEach(async () => {
if (isOracle(knex)) {
await dropAndRecreateTables(knex);
}
await knex('accounts').truncate();

await insertAccounts(knex);
});

Expand Down
12 changes: 9 additions & 3 deletions test/integration2/query/select/selects.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,25 @@ describe('Selects', function () {
describe(db, () => {
let knex;

before(async () => {
knex = logger(getKnexForDb(db));

const dropAndRecreateTables = async (knex) => {
await dropTables(knex);
await createUsers(knex);
await createAccounts(knex);
await createCompositeKeyTable(knex);
await createTestTableTwo(knex);
await createDefaultTable(knex);
await createDefaultTable(knex, true);
};

before(async () => {
knex = logger(getKnexForDb(db));
await dropAndRecreateTables(knex);
});

beforeEach(async () => {
if (isOracle(knex)) {
await dropAndRecreateTables(knex);
}
await knex('accounts').truncate();
await insertAccounts(knex);
});
Expand Down
Loading