Skip to content

Commit 728bc5d

Browse files
committed
Added SUCCESS_WITH_INFO support for PL/SQL functions used in executeMany()
1 parent 89d5dbf commit 728bc5d

File tree

7 files changed

+50
-5
lines changed

7 files changed

+50
-5
lines changed

doc/src/api_manual/connection.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,15 @@ Connection Methods
13991399
It is only present if a DML statement was executed.
14001400

14011401
Due to Node.js type limitations, the largest value shown will be 232 - 1, even if more rows were affected. Larger values will wrap.
1402+
* - ``warning``
1403+
- Object
1404+
- .. _execmanywarning:
1405+
1406+
This property provides an :ref:`error <errorobj>` object that gives information about any database warnings (such as PL/SQL compilation warnings) that were generated during the last call to :meth:`connection.executeMany()`.
1407+
1408+
See :ref:`plsqlcompwarnings` for more information.
1409+
1410+
.. versionadded:: 6.4
14021411

14031412
.. method:: connection.getDbObjectClass()
14041413

doc/src/release_notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ node-oracledb `v6.4.0 <https://github.com/oracle/node-oracledb/compare/v6.3.0...
1313
Common Changes
1414
++++++++++++++
1515

16+
#) Added the :ref:`warning <execmanywarning>` property to the
17+
:ref:`result <resultobjproperties>` object of
18+
:meth:`connection.executeMany()`.
19+
1620
#) Attribute and element values of :ref:`DbObject Class
1721
<dbobjectclass>` objects that contain strings or bytes now have their
1822
maximum size constraints checked. Errors ``NJS-142`` and ``NJS-143`` are

doc/src/user_guide/plsql_execution.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ messages are sometimes known in Oracle as "success with info" messages). Your
453453
application can manually check for these messages using the
454454
:ref:`warning <execwarning>` property of the
455455
:ref:`result object <resultobject>` in :meth:`connection.execute()` or
456-
:meth:`connection.executemany()`. A subsequent query from a table like
456+
:meth:`connection.executeMany()`. A subsequent query from a table like
457457
``USER_ERRORS`` will show more details. For example:
458458

459459
.. code-block:: javascript

lib/connection.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2016, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2016, 2024, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -949,6 +949,11 @@ class Connection extends EventEmitter {
949949
const result = await this._impl.execute(sql, numIters, binds, options,
950950
true);
951951

952+
// convert ORA warnings to NJS
953+
if (result.warning) {
954+
result.warning = errors.transformErr(result.warning);
955+
}
956+
952957
// process output binds
953958
if (result.outBinds !== undefined) {
954959
for (let i = 0; i < result.outBinds.length; i++) {

src/njsConnection.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2015, 2023, Oracle and/or its affiliates.
1+
// Copyright (c) 2015, 2024, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -834,6 +834,7 @@ static bool njsConnection_executeManyAsync(njsBaton *baton)
834834
if (dpiStmt_executeMany(baton->dpiStmtHandle, mode,
835835
baton->bindArraySize) < 0)
836836
return njsBaton_setErrorDPI(baton);
837+
dpiContext_getError(baton->globals->context, &baton->warningInfo);
837838

838839
// process any LOBS for out binds, as needed
839840
if (dpiStmt_getRowCount(baton->dpiStmtHandle, &baton->rowsAffected) < 0)
@@ -878,7 +879,7 @@ static bool njsConnection_executeManyPostAsync(njsBaton *baton, napi_env env,
878879
napi_value *result)
879880
{
880881
uint32_t numOutBinds;
881-
napi_value temp;
882+
napi_value temp, error;
882883

883884
// set JavaScript values to simplify creation of returned objects
884885
if (!njsBaton_setJsValues(baton, env))
@@ -887,6 +888,14 @@ static bool njsConnection_executeManyPostAsync(njsBaton *baton, napi_env env,
887888
// create object for result
888889
NJS_CHECK_NAPI(env, napi_create_object(env, result))
889890

891+
// process warnings if any
892+
if (baton->warningInfo.isWarning) {
893+
if (!njsUtils_getError(env, &baton->warningInfo, NULL, &error))
894+
return false;
895+
NJS_CHECK_NAPI(env, napi_set_named_property(env, *result, "warning",
896+
error))
897+
}
898+
890899
// get out binds
891900
numOutBinds = njsBaton_getNumOutBinds(baton);
892901
if (numOutBinds > 0) {

test/list.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5637,3 +5637,5 @@ oracledb.OUT_FORMAT_OBJECT and resultSet = true
56375637
293.2 Warning from PL/SQL query on a non-existing table
56385638
293.3 Warning from function in a PLSQL query
56395639
293.4 with poolMin=0 with password in grace time with heterogeneous pool
5640+
293.5 Warning from executeMany
5641+

test/plsqlWarnings.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2023, Oracle and/or its affiliates. */
1+
/* Copyright (c) 2023, 2024, Oracle and/or its affiliates. */
22

33
/******************************************************************************
44
*
@@ -103,4 +103,20 @@ describe('293. plsqlWarnings.js', function() {
103103
end;`);
104104
assert.strictEqual(result.warning.code.startsWith("NJS-700"), true);
105105
}); // 293.4
106+
107+
it('293.5 Warning from executeMany', async () => {
108+
const plsql = `
109+
CREATE OR REPLACE PROCEDURE nodb_proc_em2() AS
110+
BEGIN
111+
NULL
112+
END nodb_proc_em2;
113+
`;
114+
const conn = await oracledb.getConnection(dbConfig);
115+
const result = await conn.executeMany(plsql, 1);
116+
117+
assert.strictEqual(result.warning.message.startsWith("NJS-700:"), true);
118+
119+
await conn.execute(`DROP PROCEDURE nodb_proc_em2`);
120+
await conn.close();
121+
}); // 293.5
106122
});

0 commit comments

Comments
 (0)