@@ -52,7 +52,8 @@ limitations under the License.
52
52
- 3.2.14 [ queueRequests] ( #propdbqueuerequests )
53
53
- 3.2.15 [ queueTimeout] ( #propdbqueuetimeout )
54
54
- 3.2.16 [ stmtCacheSize] ( #propdbstmtcachesize )
55
- - 3.2.17 [ version] ( #propdbversion )
55
+ - 3.2.17 [ streamNumRows] ( #propdbstreamnumrows )
56
+ - 3.2.18 [ version] ( #propdbversion )
56
57
- 3.3 [ Oracledb Methods] ( #oracledbmethods )
57
58
- 3.3.1 [ createPool()] ( #createpool )
58
59
- 3.3.2 [ getConnection()] ( #getconnectiondb )
@@ -71,8 +72,9 @@ limitations under the License.
71
72
- 4.2.3.2 [ execute(): Bind Parameters] ( #executebindParams )
72
73
- 4.2.3.3 [ execute(): Options] ( #executeoptions )
73
74
- 4.2.3.4 [ execute(): Callback Function] ( #executecallback )
74
- - 4.2.4 [ release()] ( #release )
75
- - 4.2.5 [ rollback()] ( #rollback )
75
+ - 4.2.4 [ queryStream()] ( #querystream )
76
+ - 4.2.5 [ release()] ( #release )
77
+ - 4.2.6 [ rollback()] ( #rollback )
76
78
5 . [ Lob Class] ( #lobclass )
77
79
- 5.1 [ Lob Properties] ( #lobproperties )
78
80
- 5.1.1 [ chunkSize] ( #proplobchunksize )
@@ -113,10 +115,11 @@ limitations under the License.
113
115
- 9.1 [ SELECT Statements] ( #select )
114
116
- 9.1.1 [ Fetching Rows] ( #fetchingrows )
115
117
- 9.1.2 [ Result Set Handling] ( #resultsethandling )
116
- - 9.1.3 [ Query Output Formats] ( #queryoutputformats )
117
- - 9.1.4 [ Query Column Metadata] ( #querymeta )
118
- - 9.1.5 [ Result Type Mapping] ( #typemap )
119
- - 9.1.6 [ Row Prefetching] ( #rowprefetching )
118
+ - 9.1.3 [ Streaming Query Results] ( #streamingresults )
119
+ - 9.1.4 [ Query Output Formats] ( #queryoutputformats )
120
+ - 9.1.5 [ Query Column Metadata] ( #querymeta )
121
+ - 9.1.6 [ Result Type Mapping] ( #typemap )
122
+ - 9.1.7 [ Row Prefetching] ( #rowprefetching )
120
123
10 . [ PL/SQL Execution] ( #plsqlexecution )
121
124
- 10.1 [ PL/SQL Stored Procedures] ( #plsqlproc )
122
125
- 10.2 [ PL/SQL Stored Functions] ( #plsqlfunc )
@@ -744,7 +747,26 @@ var oracledb = require('oracledb');
744
747
oracledb .stmtCacheSize = 30 ;
745
748
```
746
749
747
- #### <a name =" propdbversion " ></a > 3.2.17 version
750
+ #### <a name =" propdbstreamnumrows " ></a > 3.2.17 streamNumRows
751
+
752
+ A value used when streaming rows with [ ` queryStream() ` ] ( #querystream ) .
753
+ It does not limit the total number of rows returned by the stream.
754
+ The value is passed to internal [ getRows()] ( #getrows ) calls and is
755
+ used only for tuning because ` getRows() ` may be internally called one
756
+ or more times when streaming results.
757
+
758
+ The default value is 100.
759
+
760
+ This property may be overridden in a [ ` queryStream() ` ] ( #querystream ) call.
761
+
762
+ ##### Example
763
+
764
+ ``` javascript
765
+ var oracledb = require (' oracledb' );
766
+ oracledb .streamNumRows = 100 ;
767
+ ```
768
+
769
+ #### <a name =" propdbversion " ></a > 3.2.18 version
748
770
```
749
771
readonly Number version
750
772
```
@@ -1402,7 +1424,35 @@ rows affected, for example the number of rows inserted. For non-DML
1402
1424
statements such as queries, or if no rows are affected, then
1403
1425
` rowsAffected ` will be zero.
1404
1426
1405
- #### <a name =" release " ></a > 4.2.4 release()
1427
+ #### <a name =" querystream " ></a > 4.2.4 queryStream()
1428
+
1429
+ ##### Prototype
1430
+
1431
+ ```
1432
+ stream.Readable queryStream(String sql, [Object bindParams, [Object options]]);
1433
+ ```
1434
+
1435
+ ##### Return Value
1436
+
1437
+ This function will return a readable stream for queries.
1438
+
1439
+ ##### Description
1440
+
1441
+ This function provides query streaming support. The input of this
1442
+ function is same as ` execute() ` however a callback is not used.
1443
+ Instead this function returns a stream used to fetch data. See
1444
+ [ Streaming Results] ( #streamingresults ) for more information.
1445
+
1446
+ The connection must remain open until the stream is completely read.
1447
+
1448
+ ##### Parameters
1449
+
1450
+ See [ connection.execute()] ( #execute ) .
1451
+
1452
+ An additional options attribute ` streamNumRows ` can be set. This
1453
+ overrides * Oracledb* [ ` streamNumRows ` ] ( #propdbstreamnumrows ) .
1454
+
1455
+ #### <a name =" release " ></a > 4.2.5 release()
1406
1456
1407
1457
##### Prototype
1408
1458
@@ -1445,7 +1495,7 @@ Callback function parameter | Description
1445
1495
----------------------------|-------------
1446
1496
* Error error* | If ` release() ` succeeds, ` error ` is NULL. If an error occurs, then ` error ` contains the [ error message] ( #errorobj ) .
1447
1497
1448
- #### <a name =" rollback " ></a > 4.2.5 rollback()
1498
+ #### <a name =" rollback " ></a > 4.2.6 rollback()
1449
1499
1450
1500
##### Prototype
1451
1501
@@ -2218,6 +2268,9 @@ A SQL or PL/SQL statement may be executed using the *Connection*
2218
2268
After all database calls on the connection complete, the application
2219
2269
should use the [` release ()` ](#release) call to release the connection.
2220
2270
2271
+ Queries may optionally be streamed using the *Connection*
2272
+ [` queryStream ()` ](#querystream) method.
2273
+
2221
2274
### <a name="select"></a> 9.1 SELECT Statements
2222
2275
2223
2276
#### <a name="fetchingrows"></a> 9.1.1 Fetching Rows
@@ -2244,8 +2297,10 @@ restricted to [`maxRows`](#propdbmaxrows):
2244
2297
#### <a name="resultsethandling"></a> 9.1.2 Result Set Handling
2245
2298
2246
2299
When the number of query rows is relatively big, or can't be
2247
- predicted, it is recommended to use a [` ResultSet` ](#resultsetclass).
2248
- This prevents query results being unexpectedly truncated by the
2300
+ predicted, it is recommended to use a [` ResultSet` ](#resultsetclass)
2301
+ with callbacks, as described in this section, or via the ResultSet
2302
+ stream wrapper, as described [later](#streamingresults). This
2303
+ prevents query results being unexpectedly truncated by the
2249
2304
[` maxRows` ](#propdbmaxrows) limit and removes the need to oversize
2250
2305
` maxRows` to avoid such truncation. Otherwise, for queries that
2251
2306
return a known small number of rows, non-result set queries may have
@@ -2343,7 +2398,65 @@ function fetchRowsFromRS(connection, resultSet, numRows)
2343
2398
}
2344
2399
` ` `
2345
2400
2346
- #### <a name="queryoutputformats"></a> 9.1.3 Query Output Formats
2401
+ #### <a name="streamingresults"></a> 9.1.3 Streaming Query Results
2402
+
2403
+ Streaming query results allows data to be piped to other streams, for
2404
+ example when dealing with HTTP responses.
2405
+
2406
+ Use [` connection .queryStream ()` ](#querystream) to create a stream and
2407
+ listen for events. Each row is returned as a ` data` event. Query
2408
+ metadata is available via a ` metadata` event. The ` end` event
2409
+ indicates the end of the query results.
2410
+
2411
+ The connection must remain open until the stream is completely read.
2412
+
2413
+ Query results must be fetched to completion to avoid resource leaks.
2414
+
2415
+ The query stream implementation is a wrapper over the
2416
+ [ResultSet Class](#resultsetclass). In particular, calls to
2417
+ [getRows()](#getrows) are made internally to fetch each successive
2418
+ subset of data, each row of which will generate a ` data` event. The
2419
+ number of rows fetched from the database by each ` getRows ()` call is
2420
+ specified by the [` oracledb .streamNumRows ` ](#propdbstreamnumrows)
2421
+ value or the ` queryStream ()` option attribute ` streamNumRows` . This
2422
+ value does not alter the number of rows returned by the stream since
2423
+ ` getRows ()` will be called each time more rows are needed. However
2424
+ the value can be used to tune performance.
2425
+
2426
+ There is no explicit ResultSet ` close ()` call for streaming query
2427
+ results. This call will be executed internally when all data has been
2428
+ fetched. If you need to be able to stop a query before retrieving all
2429
+ data, use a [ResultSet with callbacks](#resultsethandling).
2430
+
2431
+ An example of streaming query results is:
2432
+
2433
+ ` ` ` javascript
2434
+ var stream = connection .queryStream (' SELECT employees_name FROM employees' ,
2435
+ [], // no bind variables
2436
+ { streamNumRows: 100 } // Used for tuning. Does not affect how many rows are returned.
2437
+ // Default is 100
2438
+ );
2439
+
2440
+ stream .on (' error' , function (error ) {
2441
+ // handle any error...
2442
+ });
2443
+
2444
+ stream .on (' data' , function (data ) {
2445
+ // handle data row...
2446
+ });
2447
+
2448
+ stream .on (' end' , function () {
2449
+ // release connection...
2450
+ });
2451
+
2452
+ stream .on (' metadata' , function (metadata ) {
2453
+ // access metadata of query
2454
+ });
2455
+
2456
+ // listen to any other standard stream events...
2457
+ ` ` `
2458
+
2459
+ #### <a name="queryoutputformats"></a> 9.1.4 Query Output Formats
2347
2460
2348
2461
Query rows may be returned as an array of column values, or as
2349
2462
Javascript objects, depending on the values of
@@ -2413,7 +2526,7 @@ names follow Oracle's standard name-casing rules. They will commonly
2413
2526
be uppercase, since most applications create tables using unquoted,
2414
2527
case-insensitive names.
2415
2528
2416
- #### <a name="querymeta"></a> 9.1.4 Query Column Metadata
2529
+ #### <a name="querymeta"></a> 9.1.5 Query Column Metadata
2417
2530
2418
2531
The column names of a query are returned in the
2419
2532
[` execute ()` ](#execute) callback's ` result .metaData ` parameter
@@ -2446,7 +2559,7 @@ The names are in uppercase. This is the default casing behavior for
2446
2559
Oracle client programs when a database table is created with unquoted,
2447
2560
case-insensitive column names.
2448
2561
2449
- #### <a name="typemap"></a> 9.1.5 Result Type Mapping
2562
+ #### <a name="typemap"></a> 9.1.6 Result Type Mapping
2450
2563
2451
2564
Oracle character, number and date columns can be selected. Data types
2452
2565
that are currently unsupported give a "datatype is not supported"
@@ -2617,7 +2730,7 @@ you may want to bind using `type: oracledb.STRING`. Output would be:
2617
2730
{ x: ' -71.48923' , y: ' 42.72347' }
2618
2731
` ` `
2619
2732
2620
- #### <a name="rowprefetching"></a> 9.1.6 Row Prefetching
2733
+ #### <a name="rowprefetching"></a> 9.1.7 Row Prefetching
2621
2734
2622
2735
[Prefetching](http://docs.oracle.com/database/121/LNOCI/oci04sql.htm#LNOCI16355) is a query tuning feature allowing resource usage to be
2623
2736
optimized. It allows multiple rows to be returned in each network
@@ -2850,7 +2963,7 @@ connection.execute(
2850
2963
` ` `
2851
2964
2852
2965
The query rows can be handled using a
2853
- [ResultSet](http://localhost:8899/doc/api.md #resultsethandling).
2966
+ [ResultSet](#resultsethandling).
2854
2967
2855
2968
Remember to first enable output using ` DBMS_OUTPUT .ENABLE (NULL )` .
2856
2969
0 commit comments