@@ -2256,6 +2256,8 @@ The default query result type mappings for Oracle Database types to JavaScript t
2256
2256
When binding a JavaScript Date value in an ` INSERT ` statement, the date is also inserted as ` TIMESTAMP WITH
2257
2257
LOCAL TIMEZONE ` using OCIDateTime.
2258
2258
2259
+ ##### Fetching as String
2260
+
2259
2261
The global [` fetchAsString` ](#propdbfetchasstring) property can be
2260
2262
used to force all number or date columns queried by an application to
2261
2263
be fetched as strings instead of in native format. Allowing data to
@@ -2339,6 +2341,70 @@ represented as numbers:
2339
2341
To map columns returned from REF CURSORS, use ` fetchAsString` . The
2340
2342
` fetchInfo` settings do not apply.
2341
2343
2344
+ ##### Mapping Custom Types
2345
+
2346
+ Datatypes such as an Oracle Locator ` SDO_GEOMETRY ` , or your own custom
2347
+ types, cannot be fetched directly in node-oracledb. Instead, utilize
2348
+ techniques such as using an intermediary PL/SQL procedure to map the
2349
+ type components to scalar values, or use a pipelined table.
2350
+
2351
+ For example, consider a ` CUSTOMERS ` table having a ` CUST_GEO_LOCATION `
2352
+ column of type ` SDO_GEOMETRY ` , as created in this [example
2353
+ schema](http://docs.oracle.com/cd/E17781_01/appdev.112/e18750/xe_locator.htm#XELOC560):
2354
+
2355
+ ` ` ` sql
2356
+ CREATE TABLE customers (
2357
+ customer_id NUMBER ,
2358
+ last_name VARCHAR2 (30 ),
2359
+ cust_geo_location SDO_GEOMETRY );
2360
+
2361
+ INSERT INTO customers VALUES
2362
+ (1001 , ' Nichols' , SDO_GEOMETRY (2001 , 8307 , SDO_POINT_TYPE (- 71.48923 ,42.72347 ,NULL ), NULL , NULL ));
2363
+
2364
+ COMMIT ;
2365
+ ` ` `
2366
+
2367
+ Instead of attempting to get ` CUST_GEO_LOCATION ` by directly calling a
2368
+ PL/SQL procedure that returns an ` SDO_GEOMETRY ` parameter, you could
2369
+ instead get the scalar coordinates by using an intermediary PL/SQL
2370
+ block that decomposes the geometry:
2371
+
2372
+ ` ` ` javascript
2373
+ . . .
2374
+ var sql =
2375
+ " BEGIN " +
2376
+ " SELECT t.x, t.y" +
2377
+ " INTO :x, :y" +
2378
+ " FROM customers, TABLE(sdo_util.getvertices(customers.cust_geo_location)) t" +
2379
+ " WHERE customer_id = :id;" +
2380
+ " END; " ;
2381
+ var bindvars = {
2382
+ id: 1001 ,
2383
+ x: { type: oracledb .NUMBER , dir : oracledb .BIND_OUT },
2384
+ y: { type: oracledb .NUMBER , dir : oracledb .BIND_OUT }
2385
+ }
2386
+ connection .execute (
2387
+ sql,
2388
+ bindvars,
2389
+ function (err , result ) {
2390
+ if (err) { console .error (err .message ); return ; }
2391
+ console .log (result .outBinds );
2392
+ });
2393
+ ` ` `
2394
+
2395
+ The output is:
2396
+
2397
+ ` ` `
2398
+ { x: - 71.48922999999999 , y: 42.72347 }
2399
+ ` ` `
2400
+
2401
+ Note the JavaScript precision difference. In this particular example,
2402
+ you may want to bind using ` type: oracledb .STRING ` . Output would be:
2403
+
2404
+ ` ` `
2405
+ { x: ' -71.48923' , y: ' 42.72347' }
2406
+ ` ` `
2407
+
2342
2408
#### <a name="rowprefetching"></a> 9.1.6 Row Prefetching
2343
2409
2344
2410
[Prefetching](http://docs.oracle.com/database/121/LNOCI/oci04sql.htm#LNOCI16355) is a query tuning feature allowing resource usage to be
@@ -2568,7 +2634,7 @@ connection.execute(
2568
2634
[],
2569
2635
{ resultSet: true },
2570
2636
function (err , result ) {
2571
- . . .
2637
+ . . .
2572
2638
` ` `
2573
2639
2574
2640
The query rows can be handled using a
@@ -2710,7 +2776,7 @@ connection.execute(
2710
2776
if (result .rows .length === 0 ) { console .log (" No results" ); return ; }
2711
2777
2712
2778
var lob = result .rows [0 ][0 ];
2713
- if (lob === null ) { console .log (" CLOB was NULL" ); return ; }
2779
+ if (lob === null ) { console .log (" CLOB was NULL" ); return ; }
2714
2780
2715
2781
lob .setEncoding (' utf8' ); // we want text, not binary output
2716
2782
lob .on (' error' , function (err ) { console .error (err); });
0 commit comments