Skip to content

Commit

Permalink
feat: support Oracle Implicit Results (#8050)
Browse files Browse the repository at this point in the history
  • Loading branch information
adetante committed Aug 8, 2021
1 parent ab39066 commit fe78bee
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/driver/oracle/OracleQueryRunner.ts
Expand Up @@ -201,7 +201,7 @@ export class OracleQueryRunner extends BaseQueryRunner implements QueryRunner {

const result = new QueryResult();

result.raw = raw.rows || raw.outBinds || raw.rowsAffected;
result.raw = raw.rows || raw.outBinds || raw.rowsAffected || raw.implicitResults;

if (raw?.hasOwnProperty('rows') && Array.isArray(raw.rows)) {
result.records = raw.rows;
Expand All @@ -211,6 +211,10 @@ export class OracleQueryRunner extends BaseQueryRunner implements QueryRunner {
result.records = raw.outBinds;
}

if (raw?.hasOwnProperty('implicitResults') && Array.isArray(raw.implicitResults)) {
result.records = raw.implicitResults;
}

if (raw?.hasOwnProperty('rowsAffected')) {
result.affected = raw.rowsAffected;
}
Expand Down
57 changes: 57 additions & 0 deletions test/functional/query-runner/implicit-results.ts
@@ -0,0 +1,57 @@
import "reflect-metadata";
import { Connection } from "../../../src";
import { closeTestingConnections, createTestingConnections } from "../../utils/test-utils";
import { expect } from "chai";

describe("query runner > implicit results", () => {

let connections: Connection[];
before(async () => {
connections = await createTestingConnections({
entities: [__dirname + "/view/*{.js,.ts}"],
enabledDrivers: ["oracle"],
schemaCreate: true,
dropSchema: true,
});
});
after(() => closeTestingConnections(connections));

it("should return results for Oracle Stored Procedure with Implicit Results", () => Promise.all(connections.map(async connection => {
const queryRunner = connection.createQueryRunner();

// Create sample procedure with implicit results
await connection.query(`
CREATE OR REPLACE PROCEDURE TEST_IMPLICIT_RESULTS
AS
test_array dbms_sql.varchar2_table;
cur1 sys_refcursor;
BEGIN
test_array(1) := 'First';
test_array(2) := 'Second';
test_array(3) := 'Third';
OPEN cur1 FOR SELECT * FROM TABLE(test_array);
DBMS_SQL.return_result(cur1);
END;
`);

const result = await queryRunner.query(`
BEGIN
TEST_IMPLICIT_RESULTS;
END;
`);

expect(result).to.be.an('array');
expect(result).to.eql(
[
[
{ COLUMN_VALUE: 'First' },
{ COLUMN_VALUE: 'Second' },
{ COLUMN_VALUE: 'Third' },
]
]
);

await queryRunner.release();
})));

});

0 comments on commit fe78bee

Please sign in to comment.