Skip to content

Commit 9ac2093

Browse files
committed
Documentation and Test updates for the latest changes and feature additions
1 parent 6b029fe commit 9ac2093

10 files changed

+162
-64
lines changed

doc/src/api_manual/connection.rst

+15-6
Original file line numberDiff line numberDiff line change
@@ -672,11 +672,12 @@ Connection Methods
672672
**Promise**::
673673

674674
promise = execute(String sql [, Object bindParams [, Object options]]);
675+
promise = execute(Object sql [, Object options]);
675676

676-
Executes a single SQL or PL/SQL statement. See :ref:`SQL
677-
Execution <sqlexecution>` for examples. Also see
678-
:meth:`connection.queryStream()` for an alternative way of executing
679-
queries.
677+
Executes a single SQL statement, PL/SQL statement, or the SQL statement
678+
in the object that was returned by the ``sql`` function of the third-party
679+
`sql-template-tag <https://www.npmjs.com/package/sql-template-tag#
680+
oracledb>`__ module. See :ref:`SQL Execution <sqlexecution>` for examples.
680681

681682
The statement to be executed may contain :ref:`IN binds <inbind>`,
682683
:ref:`OUT or IN OUT <outbind>` bind values or variables, which are bound
@@ -699,10 +700,18 @@ Connection Methods
699700
- Data Type
700701
- Description
701702
* - ``sql``
702-
- String
703+
- String or Object
703704
- .. _executesqlparam:
704705

705-
The SQL statement that is executed. The statement may contain bind parameters.
706+
This function parameter can either be a string or an object.
707+
708+
If the parameter is a string, then it is the SQL statement that is executed. The statement may contain bind parameters.
709+
710+
If the parameter is an object, then it is the object that is returned from the ``sql`` function of the third-party `sql-template-tag <https://www.npmjs.com/package/sql-template-tag#oracledb>`__ module. This object exposes the SQL statement and values properties to retrieve the SQL string and bind values. See :ref:`example <executeobj>`. If the object returned by the ``sql`` function contains a SQL statement with a ``RETURNING INTO`` clause, then :meth:`connection.execute()` will not work and an error will be thrown.
711+
712+
.. versionchanged:: 6.4
713+
714+
The ability to accept an object (returned from the ``sql`` function of the third-party ``sql-template-tag`` module) as an input parameter was added to :meth:`connection.execute()`.
706715
* - ``bindParams``
707716
- Object or Array
708717
- .. _executebindParams:

doc/src/api_manual/dbobject.rst

+8
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ it is to convert that DbObject to and from a JavaScript object.
168168

169169
Returns an array of element values as a JavaScript array in key order.
170170

171+
.. method:: dbObject.toMap()
172+
173+
Returns a map object for the collection types indexed by PLS_INTEGER where
174+
the collection’s indexes are the keys and the elements are its values. See
175+
:ref:`indexbyplsinteger` for example.
176+
177+
.. versionadded:: 6.4
178+
171179
.. method:: dbObject.trim(count)
172180

173181
Trims the specified number of elements from the end of the collection.

doc/src/release_notes.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ Common Changes
2121
which returns a map object.
2222
See `Issue #1627 <https://github.com/oracle/node-oracledb/issues/1627>`__.
2323

24-
#) Accept an object as an input parameter for :meth:`connection.execute()`
25-
as per GitHub user request.
24+
#) Added support to accept an object as an input parameter in the
25+
:meth:`connection.execute()` method. This object is returned from the
26+
third-party `sql-template-tag <https://www.npmjs.com/package/sql-template-
27+
tag#oracledb>`__ module and exposes statement and values properties to
28+
retrieve SQL string and bind values.
2629
See `Issue #1629 <https://github.com/oracle/node-oracledb/issues/1629>`__.
27-
This object is returned from the 3rd party ``sql-template-tag`` module and
28-
exposes statement and values properties to retrieve sql string
29-
and bind values.
3030

3131
#) Added new extended :ref:`metadata <execmetadata>` information attribute
3232
``isOson`` for a fetched column.

doc/src/user_guide/objects.rst

+60
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,66 @@ Parameters <executebindParams>` for more information about binding.
421421
See `plsqlarray.js <https://github.com/oracle/node-oracledb/tree/
422422
main/examples/plsqlarray.js>`__ for a runnable example.
423423

424+
.. _indexbyplsinteger:
425+
426+
Associative Array Indexed By PLS_INTEGER
427+
++++++++++++++++++++++++++++++++++++++++
428+
429+
The following example defines an associative array indexed by PLS_INTEGER and
430+
a function that returns an associative array of that type.
431+
432+
.. code-block:: sql
433+
434+
DROP TABLE mytable;
435+
436+
CREATE TABLE mytable (id NUMBER, numcol NUMBER);
437+
438+
CREATE OR REPLACE PACKAGE mypkg IS
439+
TYPE numtype IS TABLE OF NUMBER INDEX BY PLS_INTEGER;
440+
FUNCTION F1 RETURN numtype;
441+
END;
442+
/
443+
444+
CREATE OR REPLACE PACKAGE BODY mypkg AS
445+
FUNCTION F1 RETURN numtype IS
446+
R numtype;
447+
BEGIN
448+
R(2):=22;
449+
R(5):=55;
450+
RETURN R;
451+
END;
452+
END;
453+
/
454+
455+
To return a map object for collection types indexed by PLS_INTEGER to
456+
get the keys along with values, you can use the :meth:`dbObject.toMap()`
457+
method:
458+
459+
.. code-block:: javascript
460+
461+
const connection = await oracledb.getConnection({
462+
user : "hr",
463+
password : mypw, // contains the hr schema password
464+
connectString : "localhost/FREEPDB1"
465+
});
466+
467+
const result = await connection.execute(
468+
`BEGIN
469+
:ret := mypkg.f1;
470+
END;`,
471+
{
472+
ret: {
473+
dir: oracledb.BIND_OUT,
474+
type: `mypkg.numtype`
475+
}
476+
});
477+
const res = result.outBinds.ret;
478+
console.log(res.toMap());
479+
480+
This will print::
481+
482+
Map(2) { 2 => 22, 5 => 55 }
483+
424484
.. _plsqlvarray:
425485

426486
PL/SQL Collection VARRAY Types

doc/src/user_guide/sql_execution.rst

+22
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,28 @@ cases:
9292
In both cases, use a :ref:`ResultSet <resultsethandling>` or :ref:`Query
9393
Stream <streamingresults>` instead of a direct fetch.
9494

95+
.. _executeobj:
96+
97+
If you are using the ``sql`` function of the third-party `sql-template-tag
98+
<https://www.npmjs.com/package/sql-template-tag#oracledb>`__ module, then you
99+
can pass the object returned by this function in :meth:`connection.execute()`.
100+
This object exposes the SQL statement and values properties to retrieve the
101+
SQL string and bind values.
102+
103+
.. code-block:: javascript
104+
105+
import sql from sql-template-tag;
106+
107+
const id = 20;
108+
let options = { maxRows: 1 };
109+
query = sql`SELECT * FROM departments WHERE department_id = ${id}`;
110+
result = await connection.execute(query, options);
111+
console.log(result.rows);
112+
113+
If the object returned by the ``sql`` function contains a SQL statement with a
114+
``RETURNING INTO`` clause, then :meth:`connection.execute()` will not work and
115+
an error will be thrown.
116+
95117
.. _resultsethandling:
96118

97119
Fetching Rows with Result Sets

test/implicitResults.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const oracledb = require('oracledb');
3535
const assert = require('assert');
3636
const dbConfig = require('./dbconfig.js');
3737
const testsUtil = require('./testsUtil.js');
38-
const util = require('util');
3938

4039
describe('192. implicitResults.js', function() {
4140

@@ -162,7 +161,7 @@ describe('192. implicitResults.js', function() {
162161
rs = await results.implicitResults[1];
163162
let row, len = 0;
164163
while ((row = await rs.getRow())) {
165-
assert(util.isDate(row[1]));
164+
assert(testsUtil.isDate(row[1]));
166165
len++;
167166
}
168167
const tab2Len = 5;
@@ -185,7 +184,7 @@ describe('192. implicitResults.js', function() {
185184
rs = await results.implicitResults[1];
186185
let row, len = 0;
187186
while ((row = await rs.getRow())) {
188-
assert(util.isDate(row.TSVAL));
187+
assert(testsUtil.isDate(row.TSVAL));
189188
len++;
190189
}
191190
const tab2Len = 5;

test/instanceof1.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const dbConfig = require('./dbconfig.js');
3737

3838
describe('45. instanceof1.js', function() {
3939

40-
it('45.2 instanceof works for pool instances', async function() {
40+
it('45.1 instanceof works for pool instances', async function() {
4141
const config = {
4242
...dbConfig,
4343
poolMin: 0,
@@ -47,34 +47,34 @@ describe('45. instanceof1.js', function() {
4747
const pool = await oracledb.createPool(config);
4848
assert(pool instanceof oracledb.Pool);
4949
await pool.close(0);
50-
});
50+
}); // 45.1
5151

52-
it('45.3 instanceof works for connection instances', async function() {
52+
it('45.2 instanceof works for connection instances', async function() {
5353
const conn = await oracledb.getConnection(dbConfig);
5454
assert(conn instanceof oracledb.Connection);
5555
await conn.close();
56-
});
56+
}); // 45.2
5757

58-
it('45.4 instanceof works for resultset instances', async function() {
58+
it('45.3 instanceof works for resultset instances', async function() {
5959
const conn = await oracledb.getConnection(dbConfig);
6060
const sql = 'select 1 from dual union select 2 from dual';
6161
const binds = [];
6262
const options = {
6363
resultSet: true
64-
};
64+
}; // 45.3
6565
const result = await conn.execute(sql, binds, options);
6666
assert(result.resultSet instanceof oracledb.ResultSet);
6767
await result.resultSet.close();
6868
await conn.close();
6969
});
7070

71-
it('45.5 instanceof works for lob instances', async function() {
71+
it('45.4 instanceof works for lob instances', async function() {
7272
const conn = await oracledb.getConnection(dbConfig);
7373
const result = await conn.execute('select to_clob(dummy) from dual');
7474
const lob = result.rows[0][0];
7575
assert(lob instanceof oracledb.Lob);
7676
lob.destroy();
7777
await conn.close();
78-
}); // 45.5
78+
}); // 45.4
7979

8080
});

test/list.txt

+13-13
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,10 @@ Overview of node-oracledb functional tests
736736
44.8 maxSize option applies to each elements of an array
737737

738738
45. instanceof1.js
739-
45.2 instanceof works for pool instances
740-
45.3 instanceof works for connection instances
741-
45.4 instanceof works for resultset instances
742-
45.5 instanceof works for lob instances
739+
45.1 instanceof works for pool instances
740+
45.2 instanceof works for connection instances
741+
45.3 instanceof works for resultset instances
742+
45.4 instanceof works for lob instances
743743

744744
51. poolClose.js
745745
51.1 can not get connections from the terminated pool
@@ -800,16 +800,16 @@ Overview of node-oracledb functional tests
800800
55.7 getting multiple resultSets
801801
55.7.1 can access multiple resultSet on one connection
802802
55.7.2 can access multiple REF Cursor
803-
55.9 test querying a PL/SQL function
803+
55.8 test querying a PL/SQL function
804+
55.8.1
805+
55.9 calls getRows() once and then close RS before getting more rows
804806
55.9.1
805-
55.10 calls getRows() once and then close RS before getting more rows
806-
55.10.1
807-
55.11 result set with unsupported data types
808-
55.11.1 INTERVAL YEAR TO MONTH data type
809-
55.12 bind a cursor BIND_INOUT
810-
55.12.1 has not supported binding a cursor with BIND_INOUT
811-
55.13 Invalid Ref Cursor
812-
55.13.1
807+
55.10 result set with unsupported data types
808+
55.10.1 INTERVAL YEAR TO MONTH data type
809+
55.11 bind a cursor BIND_INOUT
810+
55.11.1 has not supported binding a cursor with BIND_INOUT
811+
55.12 Invalid Ref Cursor
812+
55.12.1
813813

814814
56. fetchAs.js
815815
56.1 property value check

test/resultSet1.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe('12. resultSet1.js', function() {
187187
);
188188
});
189189

190-
});
190+
}); // 12.1
191191

192192
describe('12.2 Testing fetchArraySize option', function() {
193193
it('12.2.1 negative - negative value', async function() {
@@ -255,7 +255,7 @@ describe('12. resultSet1.js', function() {
255255
);
256256
});
257257

258-
});
258+
}); // 12.2
259259

260260
describe('12.3 Testing function getRows()', function() {
261261
it('12.3.1 retrieved set is exactly the size of result', async function() {
@@ -457,7 +457,7 @@ describe('12. resultSet1.js', function() {
457457
);
458458
});
459459

460-
});
460+
}); // 12.3
461461

462462
describe('12.4 Testing function getRow()', function() {
463463
it('12.4.1 works well with all correct setting', async function() {
@@ -545,7 +545,7 @@ describe('12. resultSet1.js', function() {
545545
await rs.close();
546546
});
547547

548-
});
548+
}); // 12.4
549549

550550
describe('12.5 Testing function close()', function() {
551551
it('12.5.1 does not call close()', async function() {
@@ -622,7 +622,7 @@ describe('12. resultSet1.js', function() {
622622

623623
});
624624

625-
});
625+
}); // 12.5
626626

627627
describe('12.6 Testing metaData', function() {
628628

@@ -767,7 +767,7 @@ describe('12. resultSet1.js', function() {
767767
await rs.close();
768768
await conn.execute("DROP TABLE " + tableName + " PURGE");
769769
});
770-
});
770+
}); // 12.6
771771

772772
describe('12.7 Testing maxRows', function() {
773773
it('12.7.1 maxRows option is ignored when resultSet option is true', async function() {

0 commit comments

Comments
 (0)