Skip to content

Commit 630f41e

Browse files
committed
Update Documentation for Binary Vectors and BFILE support
1 parent f31af6b commit 630f41e

File tree

6 files changed

+417
-41
lines changed

6 files changed

+417
-41
lines changed

doc/src/api_manual/connection.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,8 @@ Connection Methods
611611
LOBs created with ``createLob()`` can be bound for IN, IN OUT and OUT
612612
binds.
613613

614-
See :ref:`Working with CLOB, NCLOB and BLOB Data <lobhandling>` and :ref:`LOB
615-
Bind Parameters <lobbinds>` for more information.
614+
See :ref:`Working with CLOB, NCLOB, BLOB and BFILE Data <lobhandling>` and
615+
:ref:`LOB Bind Parameters <lobbinds>` for more information.
616616

617617
The parameters of the ``connection.createLob()`` method are:
618618

@@ -632,7 +632,7 @@ Connection Methods
632632
- Description
633633
* - ``type``
634634
- Number
635-
- One of the constants :ref:`oracledb.CLOB <oracledbconstantsnodbtype>`, :ref:`oracledb.BLOB <oracledbconstantsnodbtype>`, or :ref:`oracledb.NCLOB <oracledbconstantsnodbtype>` (or equivalent ``DB_TYPE_*`` constants).
635+
- One of the constants :ref:`oracledb.CLOB <oracledbconstantsnodbtype>`, :ref:`oracledb.BLOB <oracledbconstantsnodbtype>`, :ref:`oracledb.NCLOB <oracledbconstantsnodbtype>`, or :ref:`oracledb.BFILE <oracledbconstantsnodbtype>` (or equivalent ``DB_TYPE_*`` constants).
636636

637637
**Callback**:
638638

doc/src/api_manual/lob.rst

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,46 @@ Lob Methods
155155
* - Error ``error``
156156
- This optional parameter is used for the error emitted in an ``error`` event.
157157

158+
.. method:: lob.fileExists()
159+
160+
.. versionadded:: 6.6
161+
162+
**Promise**::
163+
164+
promise = fileExists();
165+
166+
Returns a boolean which indicates whether the file specified by the LOB
167+
exists in the directory alias or not. This method returns *true* if the
168+
file exists in the directory and *false* if it does not. If the directory
169+
that this method is trying to access does not exist, then this method
170+
returns an error. This method can only be used if the LOB type is BFILE.
171+
For all other LOB types, this method returns the ``NJS-156: operation is
172+
only supported on BFILE LOBs`` error.
173+
174+
**Callback**:
175+
176+
If you are using the callback programming style::
177+
178+
fileExists(function(Error error, Boolean val));
179+
180+
The parameters of the callback function
181+
``function(Error error, Boolean val)`` are:
182+
183+
.. list-table-with-summary::
184+
:header-rows: 1
185+
:class: wy-table-responsive
186+
:align: center
187+
:widths: 15 30
188+
:summary: The first column displays the callback function parameter.
189+
The second column displays the description of the parameter.
190+
191+
* - Callback Function Parameter
192+
- Description
193+
* - Error ``error``
194+
- If ``fileExists()`` succeeds, ``error`` is NULL. If an error occurs, then ``error`` contains the :ref:`error message <errorobj>`.
195+
* - Boolean ``val``
196+
- Indicates whether the file exists in the directory. This parameter will be *true* if the file exists in the directory and *false* if it does not.
197+
158198
.. method:: lob.getData()
159199

160200
.. versionadded:: 4.0
@@ -241,3 +281,49 @@ Lob Methods
241281
- If ``getData()`` succeeds, ``error`` is NULL. If an error occurs, then ``error`` contains the :ref:`error message <errorobj>`.
242282
* - String ``data`` or Buffer ``data``
243283
- The value of the LOB.
284+
285+
.. method:: lob.getDirFileName()
286+
287+
.. versionadded:: 6.6
288+
289+
.. code-block:: javascript
290+
291+
getDirFileName();
292+
293+
This synchronous method returns an object containing the directory alias
294+
and file name of the LOB object. This method can only be used if the LOB
295+
type is BFILE. For all other LOB types, this method returns the
296+
``NJS-156: operation is only supported on BFILE LOBs`` error.
297+
298+
.. method:: lob.setDirFileName()
299+
300+
.. versionadded:: 6.6
301+
302+
.. code-block:: javascript
303+
304+
setDirFileName(Object dirFileName);
305+
306+
This synchronous method sets the directory alias and file name of the LOB.
307+
This method can only be used if the LOB type is BFILE. For all other LOB
308+
types, this method returns the ``NJS-156: operation is only supported on
309+
BFILE LOBs`` error.
310+
311+
.. note::
312+
313+
This method can only be used in node-oracledb Thin mode.
314+
315+
The parameters of the ``lob.setDirFileName()`` method are:
316+
317+
.. list-table-with-summary:: lob.setDirFileName() Parameters
318+
:header-rows: 1
319+
:class: wy-table-responsive
320+
:align: center
321+
:widths: 10 10 30
322+
:summary: The first column displays the parameter. The second column displays the data type of the parameter. The third column displays the description of the parameter.
323+
324+
* - Parameter
325+
- Data Type
326+
- Description
327+
* - ``dirFileName``
328+
- Object
329+
- This parameter contains the directory alias and file name of the BFILE type LOB.

doc/src/api_manual/oracledb.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ for common :ref:`Oracle Database Type Constants <oracledbconstantsdbtype>`.
214214
- Value
215215
- ``DbType`` Object Equivalent
216216
- Notes
217+
* - ``oracledb.BFILE``
218+
- 2020
219+
- ``oracledb.DB_TYPE_BFILE``
220+
-
217221
* - ``oracledb.BLOB``
218222
- 2019
219223
- ``oracledb.DB_TYPE_BLOB``
@@ -874,6 +878,7 @@ Constants for two-phase commit (TPC) functions
874878

875879
Vector Type Constants
876880
---------------------
881+
877882
.. versionadded:: 6.5
878883

879884
Constants for the :ref:`vectorFormat <execmetadata>` attribute.
@@ -899,6 +904,13 @@ Constants for the :ref:`vectorFormat <execmetadata>` attribute.
899904
* - ``oracledb.VECTOR_FORMAT_INT8``
900905
- 4
901906
- The storage format of each dimension value in the VECTOR column is an 8-bit signed integer.
907+
* - ``oracledb.VECTOR_FORMAT_BINARY``
908+
- 5
909+
- The storage format of each dimension value in the VECTOR column is represented as a single bit. All the dimensions for the vector are stored as an array of 8-bit unsigned integers.
910+
911+
.. versionchanged:: 6.6
912+
913+
The ``oracledb.VECTOR_FORMAT_BINARY`` constant was added.
902914

903915
.. _oracledbproperties:
904916

doc/src/user_guide/appendix_a.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ node-oracledb Thin and Thick modes. For more details see :ref:`modediff`.
156156
- No
157157
- Yes
158158
* - SQL execution (see :ref:`sqlexecution`)
159-
- Yes - Bind and fetch all types except BFILE
159+
- Yes
160160
- Yes
161161
* - PL/SQL execution (see :ref:`plsqlexecution`)
162162
- Yes - For scalar types and collection types using array interface
@@ -297,8 +297,8 @@ node-oracledb Thin and Thick modes. For more details see :ref:`modediff`.
297297
- Yes
298298
- Yes - May need to fetch as CLOB
299299
* - BFILE data type
300-
- No
301-
- No
300+
- Yes
301+
- Yes
302302
* - TIMESTAMP WITH TIME ZONE data type (see :ref:`oracledbconstantsdbtype`)
303303
- Yes
304304
- Yes
@@ -734,7 +734,7 @@ when binding numeric values.
734734
- Yes
735735
* - BFILE
736736
- DB_TYPE_BFILE
737-
- No
737+
- Yes
738738
* - BLOB
739739
- DB_TYPE_BLOB
740740
- Yes

doc/src/user_guide/lob_data.rst

Lines changed: 157 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
.. _lobhandling:
22

3-
*******************************
4-
Using CLOB, NCLOB and BLOB Data
5-
*******************************
3+
***************************************
4+
Using CLOB, NCLOB, BLOB, and BFILE Data
5+
***************************************
66

77
Oracle Database uses LOB data types to store long objects. The CLOB type
88
is used for character data and the BLOB type is used for binary data.
99
NCLOB can hold character data in the database’s alternative `national
1010
character set <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID
11-
-AA8D783D-7337-4A61-BD7D-5DB580C46D9A>`__.
12-
In node-oracledb, LOBs can be represented by instances of the
13-
:ref:`Lob <lobclass>` class or as Strings and Buffers.
11+
-AA8D783D-7337-4A61-BD7D-5DB580C46D9A>`__. The `BFILE <https://www.oracle.com/
12+
pls/topic/lookup?ctx=dblatest&id=GUID-D4642C92-F343-4700-9F1F-486F82249FB8>`__
13+
type is used for referencing a file stored on the server operating system
14+
where Oracle Database is running, outside the database tablespace. The BFILE
15+
LOB type was introduced in node-oracledb 6.6.
16+
17+
node-oracledb uses :ref:`oracledb.CLOB <oracledbconstantsdbtype>`,
18+
:ref:`oracledb.BLOB <oracledbconstantsdbtype>`,
19+
:ref:`oracledb.NCLOB <oracledbconstantsdbtype>`, and
20+
:ref:`oracledb.BFILE <oracledbconstantsdbtype>` to represent CLOB, BLOB,
21+
NCLOB, and BFILE data types respectively. In node-oracledb, LOBs can be
22+
represented by instances of the :ref:`Lob <lobclass>` class or as Strings and
23+
Buffers.
1424

1525
There are runnable LOB examples in the GitHub
1626
`examples <https://github.com/oracle/node-oracledb/tree/main/examples>`__
@@ -25,6 +35,11 @@ Node.js String or Buffer types can be passed into PL/SQL blocks or
2535
inserted into the database by binding to LOB columns or PL/SQL
2636
parameters.
2737

38+
.. _insertclobblob:
39+
40+
Inserting CLOBs and BLOBs
41+
-------------------------
42+
2843
Given the table:
2944

3045
.. code-block:: sql
@@ -99,13 +114,105 @@ Node.js or node-oracledb, it will need to be streamed to a
99114
:ref:`Lob <lobclass>`, as discussed in :ref:`Streaming
100115
Lobs <streamsandlobs>`.
101116

117+
See :ref:`fetchinglob` for information on how to fetch CLOBs, BLOBs, and NCLOBs.
118+
119+
.. _insertbfile:
120+
121+
Inserting BFILEs
122+
----------------
123+
124+
The data of `BFILE <https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=
125+
GUID-D4642C92-F343-4700-9F1F-486F82249FB8>`__ type LOB is stored as files in a
126+
directory in the Oracle Database server. The column of type BFILE stores a
127+
reference to the file stored in the Oracle Database server file system.
128+
The BFILE column data cannot be updated from within your application since
129+
Oracle Database allows read-only access to the data stored in BFILE columns.
130+
131+
Before using the BFILE data type, ensure that you have created a directory in
132+
the database server file system to store the file. Each BFILE object is
133+
associated with:
134+
135+
- A DIRECTORY object which is an alias for the directory on the database
136+
server file system that stores the file with BFILE data. For example, if
137+
your server is running on a Linux machine, you can create a DIRECTORY object
138+
by using:
139+
140+
.. code-block:: sql
141+
142+
CREATE OR REPLACE DIRECTORY MYBFILEDIR AS '/tmp/my-bfile-dir'
143+
144+
``MYBFILEDIR`` is the directory alias.
145+
``/tmp/my-bfile-dir`` is the physical operating system directory in the
146+
database server file system. It is a string containing the full path name of
147+
the directory and follows the operating system rules.
148+
149+
This directory and alias are used in subsequent examples.
150+
- The file name of the physical file which is stored in the directory in the
151+
database server file system. For example, ``MYBFILE.JPG``. The file in this
152+
directory can be copied using operating system commands such as ``cp`` or
153+
``COPY``. This file name is used in subsequent examples.
154+
155+
Ensure that you have the required access permissions to the directory. For
156+
Windows platform, ensure that you have set the Access Control Lists (ACL) or
157+
Discretionary Access Control List (DACL) correctly to access the file.
158+
159+
The following table will be used in the subsequent examples to demonstrate
160+
using ``BFILE`` data with node-oracledb:
161+
162+
.. code-block:: sql
163+
164+
CREATE TABLE bfile_table(
165+
id NUMBER,
166+
bfilecol BFILE
167+
);
168+
169+
To insert data of BFILE data type:
170+
171+
.. code-block:: javascript
172+
173+
const result = await connection.execute(
174+
`INSERT INTO bfile_table VALUES (:id, BFILENAME(:BFILEDIR, :BFILENAME))`,
175+
[101, "MYBFILEDIR", "MYBFILE.JPG"]);
176+
177+
This example inserts a row in ``bfile_table`` with BFILE properties,
178+
directory alias ``MYBFILEDIR`` and file name ``MYBFILE.JPG``.
179+
180+
Note that the content in the BFILE column cannot be updated. You can only
181+
update the properties such as directory alias and the file name. Once updated,
182+
the LOB object references the new file name specified. To update the file name
183+
to ``NEWBFILE.JPG``, you can use:
184+
185+
.. code-block:: javascript
186+
187+
const result = await connection.execute(
188+
`UPDATE bfile_table SET bfilecol = BFILENAME("MYBFILEDIR", "NEWBFILE.JPG") WHERE id = :ID`,
189+
[101]);
190+
191+
In node-oracledb Thin mode, you can set the directory alias and file name
192+
using :meth:`lob.setDirFileName()`. For example:
193+
194+
.. code-block:: javascript
195+
196+
const result = await conn.execute(`
197+
SELECT bfilecol FROM bfile_table WHERE id = :id`, [101]);
198+
const lob = result.rows[0][0];
199+
const dirFile = lob.getDirFileName();
200+
lob.setDirFileName({dirName: "NEWALIASNAME", fileName: "NEWBFILENAME"});
201+
202+
This will update the directory alias to ``NEWALIASNAME`` and file name to
203+
``NEWBFILENAME``.
204+
205+
See :ref:`fetchbfile` for information on how to query a BFILE column.
206+
102207
.. _queryinglobs:
103208

104209
Simple LOB Queries and PL/SQL OUT Binds
105210
=======================================
106211

107-
Querying LOBs
108-
-------------
212+
.. _fetchinglob:
213+
214+
Fetching CLOBs, BLOBs, and NCLOBs
215+
---------------------------------
109216

110217
LOBs queried from the database that are shorter than 1 GB can be
111218
returned as Strings or Buffers by using
@@ -219,6 +326,48 @@ in Node.js or node-oracledb, it will need to be explicitly streamed to a
219326
Lobs <streamsandlobs>`. See :ref:`LOB Bind Parameters <lobbinds>` for
220327
size considerations regarding LOB binds.
221328

329+
.. _fetchbfile:
330+
331+
Fetching BFILEs
332+
---------------
333+
334+
To query the BFILE column of ``bfile_table``, you can use:
335+
336+
.. code-block:: javascript
337+
338+
const result = await connection.execute(
339+
`SELECT bfilecol FROM bfile_table WHERE id = :id`, [101]);
340+
const lob = result.rows[0][0];
341+
const dirFile = lob.getDirFileName();
342+
console.log("Directory Alias:", dirFile.dirName, "File Name:", dirFile.fileName);
343+
344+
This prints the following output::
345+
346+
MYBFILEDIR, MYBFILE.JPG
347+
348+
To query the metadata of a BFILE column, you can use:
349+
350+
.. code-block:: javascript
351+
352+
const result = await connection.execute(`SELECT bfilecol FROM bfile_table`);
353+
console.log("Metadata:", result.metaData);
354+
355+
This query prints the metadata for the ``bfilecol`` column and displays the
356+
dbType as ``DB_TYPE_BFILE``::
357+
358+
MetaData: [
359+
{
360+
name: 'BFILECOL',
361+
dbType: [DbType DB_TYPE_BFILE],
362+
nullable: false,
363+
isJson: false,
364+
isOson: false,
365+
dbTypeName: 'BFILE',
366+
fetchType: [DbType DB_TYPE_BFILE],
367+
converter: [Function: converter]
368+
},
369+
]
370+
222371
.. _streamsandlobs:
223372

224373
Streaming Lobs

0 commit comments

Comments
 (0)