@@ -67,24 +67,24 @@ limitations under the License.
6767 - 4.2.2 [ ` close() ` ] ( #connectionclose )
6868 - 4.2.3 [ ` commit() ` ] ( #commit )
6969 - 4.2.4 [ ` execute() ` ] ( #execute )
70- - 4.2.4.1 [ ` execute() ` : SQL Statement] ( #executesqlparam )
71- - 4.2.4.2 [ ` execute() ` : Bind Parameters] ( #executebindParams )
72- - [ ` dir ` ] ( #executebindParams ) , [ ` maxArraySize ` ] ( #executebindParams ) , [ ` maxSize ` ] ( #executebindParams ) , [ ` type ` ] ( #executebindParams ) , [ ` val ` ] ( #executebindParams )
73- - 4.2.4.3 [ ` execute() ` : Options] ( #executeoptions )
74- - 4.2.4.3.1 [ ` autoCommit ` ] ( #propexecautocommit )
75- - 4.2.4.3.2 [ ` extendedMetaData ` ] ( #propexecextendedmetadata )
76- - 4.2.4.3.3 [ ` fetchInfo ` ] ( #propexecfetchinfo )
77- - 4.2.4.3.4 [ ` maxRows ` ] ( #propexecmaxrows )
78- - 4.2.4.3.5 [ ` outFormat ` ] ( #propexecoutformat )
79- - 4.2.4.3.6 [ ` prefetchRows ` ] ( #propexecprefetchrows )
80- - 4.2.4.3.7 [ ` resultSet ` ] ( #propexecresultset )
81- - 4.2.4.4 [ ` execute() ` : Callback Function] ( #executecallback )
82- - 4.2.4.4.1 [ ` metaData ` ] ( #execmetadata )
83- - [ ` name ` ] ( #execmetadata ) , [ ` fetchType ` ] ( #execmetadata ) , [ ` dbType ` ] ( #execmetadata ) , [ ` byteSize ` ] ( #execmetadata ) , [ ` precision ` ] ( #execmetadata ) , [ ` scale ` ] ( #execmetadata ) , [ ` nullable ` ] ( #execmetadata )
84- - 4.2.4.4.2 [ ` outBinds ` ] ( #execoutbinds )
85- - 4.2.4.4.3 [ ` resultSet ` ] ( #execresultset )
86- - 4.2.4.4.4 [ ` rows ` ] ( #execrows )
87- - 4.2.4.4.5 [ ` rowsAffected ` ] ( #execrowsaffected )
70+ - 4.2.4.1 [ ` execute() ` : SQL Statement] ( #executesqlparam )
71+ - 4.2.4.2 [ ` execute() ` : Bind Parameters] ( #executebindParams )
72+ - [ ` dir ` ] ( #executebindParams ) , [ ` maxArraySize ` ] ( #executebindParams ) , [ ` maxSize ` ] ( #executebindParams ) , [ ` type ` ] ( #executebindParams ) , [ ` val ` ] ( #executebindParams )
73+ - 4.2.4.3 [ ` execute() ` : Options] ( #executeoptions )
74+ - 4.2.4.3.1 [ ` autoCommit ` ] ( #propexecautocommit )
75+ - 4.2.4.3.2 [ ` extendedMetaData ` ] ( #propexecextendedmetadata )
76+ - 4.2.4.3.3 [ ` fetchInfo ` ] ( #propexecfetchinfo )
77+ - 4.2.4.3.4 [ ` maxRows ` ] ( #propexecmaxrows )
78+ - 4.2.4.3.5 [ ` outFormat ` ] ( #propexecoutformat )
79+ - 4.2.4.3.6 [ ` prefetchRows ` ] ( #propexecprefetchrows )
80+ - 4.2.4.3.7 [ ` resultSet ` ] ( #propexecresultset )
81+ - 4.2.4.4 [ ` execute() ` : Callback Function] ( #executecallback )
82+ - 4.2.4.4.1 [ ` metaData ` ] ( #execmetadata )
83+ - [ ` name ` ] ( #execmetadata ) , [ ` fetchType ` ] ( #execmetadata ) , [ ` dbType ` ] ( #execmetadata ) , [ ` byteSize ` ] ( #execmetadata ) , [ ` precision ` ] ( #execmetadata ) , [ ` scale ` ] ( #execmetadata ) , [ ` nullable ` ] ( #execmetadata )
84+ - 4.2.4.4.2 [ ` outBinds ` ] ( #execoutbinds )
85+ - 4.2.4.4.3 [ ` resultSet ` ] ( #execresultset )
86+ - 4.2.4.4.4 [ ` rows ` ] ( #execrows )
87+ - 4.2.4.4.5 [ ` rowsAffected ` ] ( #execrowsaffected )
8888 - 4.2.5 [ ` queryStream() ` ] ( #querystream )
8989 - 4.2.6 [ ` release() ` ] ( #release )
9090 - 4.2.7 [ ` rollback() ` ] ( #rollback )
@@ -140,6 +140,11 @@ limitations under the License.
140140 - 9.1.4 [ Query Output Formats] ( #queryoutputformats )
141141 - 9.1.5 [ Query Column Metadata] ( #querymeta )
142142 - 9.1.6 [ Result Type Mapping] ( #typemap )
143+ - 9.1.6.1 [ Fetching Character Types] ( #stringhandling )
144+ - 9.1.6.2 [ Fetching Numbers] ( #numberhandling )
145+ - 9.1.6.3 [ Fetching Date and Timestamps] ( #datehandling )
146+ - 9.1.6.4 [ Fetching Numbers and Dates as String] ( #fetchasstringhandling )
147+ - 9.1.6.5 [ Mapping Custom Types] ( #customtypehandling )
143148 - 9.1.7 [ Row Prefetching] ( #rowprefetching )
14414910 . [ PL/SQL Execution] ( #plsqlexecution )
145150 - 10.1 [ PL/SQL Stored Procedures] ( #plsqlproc )
@@ -525,6 +530,7 @@ By default all columns are returned as native types.
525530
526531This property helps avoid situations where using JavaScript types can
527532lead to numeric precision loss, or where date conversion is unwanted.
533+ See [ Result Type Mapping] ( #typemap ) for more discussion.
528534
529535The valid types that can be mapped to strings are
530536[ ` DATE ` ] ( #oracledbconstantsnodbtype ) and
@@ -3306,29 +3312,88 @@ Description of the properties is given in the
33063312
33073313#### <a name="typemap"></a> 9.1.6 Result Type Mapping
33083314
3309- Oracle character, number and date columns can be selected. Datatypes
3310- that are currently unsupported give a "datatype is not supported"
3311- error .
3315+ Oracle character, number and date columns can be selected directly
3316+ into JavaScript strings and numbers. BLOBs and CLOBs can be fetched
3317+ into [Lobs](#lobclass) .
33123318
3313- The default query result type mappings for Oracle Database types to JavaScript types are:
3319+ Datatypes that are currently unsupported give a "datatype is not
3320+ supported" error.
3321+
3322+ ##### <a name="stringhandling"></a> 9.1.6.1 Fetching Character Types
33143323
3315- - Variable and fixed length character columns are mapped to JavaScript strings.
3324+ Variable and fixed length character columns are mapped to JavaScript strings.
33163325
3317- - All numeric columns are mapped to JavaScript numbers.
3326+ ##### <a name="numberhandling"></a> 9.1.6.2 Fetching Numbers
33183327
3319- - Date and timestamp columns are mapped to JavaScript dates.
3320- Note that JavaScript Date has millisecond precision.
3321- Therefore, timestamps having greater
3322- precision lose their sub-millisecond fractional part
3323- when fetched. Internally, ` TIMESTAMP ` and ` DATE `
3324- columns are fetched as ` TIMESTAMP WITH LOCAL TIME ZONE ` using
3325- [OCIDateTime](https://docs.oracle.com/database/122/LNOCI/object-relational-data-types-in-oci.htm#LNOCI16840).
3326- When binding a JavaScript Date value in an ` INSERT ` statement, the date is also inserted as ` TIMESTAMP WITH
3327- LOCAL TIME ZONE ` using OCIDateTime.
3328- See [Working with Dates Using the Node.js Driver](https://jsao.io/2016/09/working-with-dates-using-the-nodejs-driver/) for
3329- a discussion of date handling.
3328+ By default all numeric columns are mapped to JavaScript numbers.
33303329
3331- ##### Fetching as String
3330+ When numbers are fetched from the database, conversion to JavaScript's
3331+ less precise binary number format can result in "unexpected"
3332+ representations. For example:
3333+
3334+ ` ` ` javascript
3335+ conn .execute (
3336+ " select 38.73 from dual" ,
3337+ function (err , result ) {
3338+ if (err)
3339+ . . .
3340+ else
3341+ console .log (result .rows [0 ]); // gives 38.730000000000004
3342+ });
3343+ ` ` `
3344+
3345+ Similar issues can occur with binary floating-point arithmetic
3346+ purely in Node.js, for example:
3347+
3348+ ` ` ` javascript
3349+ console .log (0.2 + 0.7 ); // gives 0.8999999999999999
3350+ ` ` `
3351+
3352+ The primary recommendation for number handling is to use Oracle SQL or
3353+ PL/SQL for mathematical operations, particularly for currency
3354+ calculations. Alternatively you can use ` fetchAsString` or
3355+ ` fetchInfo` (see next section) to fetch numbers in string format, and
3356+ then use one of the available third-party JavaScript number libraries
3357+ that handles more precision.
3358+
3359+ When using ` fetchAsString` or ` fetchInfo` , you may need to
3360+ explicitly use ` NLS_NUMERIC_CHARACTERS ` to override your NLS
3361+ settings and force the decimal separator to be a period. This can
3362+ be done by executing:
3363+
3364+ ` ` `
3365+ ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ' .,'
3366+ ` ` `
3367+
3368+ Alternatively you can set the equivalent environment variable prior
3369+ to starting Node.js:
3370+
3371+ ` ` `
3372+ export NLS_NUMERIC_CHARACTERS = ' .,'
3373+ ` ` `
3374+
3375+ Note this environment variable is not used unless the ` NLS_LANG `
3376+ environment variable is also set.
3377+
3378+ ##### <a name="datehandling"></a> 9.1.6.3 Fetching Date and Timestamps
3379+
3380+ The default query result type mappings for Oracle Database types to JavaScript types are:
3381+
3382+ Date and timestamp columns are mapped to JavaScript dates. Note that
3383+ JavaScript Date has millisecond precision. Therefore, timestamps
3384+ having greater precision lose their sub-millisecond fractional part
3385+ when fetched. Internally, ` TIMESTAMP ` and ` DATE ` columns are fetched
3386+ as ` TIMESTAMP WITH LOCAL TIME ZONE `
3387+ using
3388+ [OCIDateTime](https://docs.oracle.com/database/122/LNOCI/object-relational-data-types-in-oci.htm#LNOCI16840).
3389+ When binding a JavaScript Date value in an ` INSERT ` statement, the
3390+ date is also inserted as ` TIMESTAMP WITH LOCAL TIME ZONE ` using
3391+ OCIDateTime.
3392+ See
3393+ [Working with Dates Using the Node.js Driver](https://jsao.io/2016/09/working-with-dates-using-the-nodejs-driver/) for
3394+ a discussion of date handling.
3395+
3396+ ##### <a name="fetchasstringhandling"></a> 9.1.6.4 Fetching Numbers and Dates as String
33323397
33333398The global [` fetchAsString` ](#propdbfetchasstring) property can be
33343399used to force all number or date columns queried by an application to
@@ -3409,11 +3474,10 @@ represented as numbers:
34093474[ [ ' Grant' , Thu May 24 2007 00 : 00 : 00 GMT + 1000 (AEST ), 7000 , 0.15 ] ]
34103475` ` `
34113476
3412-
34133477To map columns returned from REF CURSORS, use ` fetchAsString` . The
34143478` fetchInfo` settings do not apply.
34153479
3416- ##### Mapping Custom Types
3480+ ##### <a name="customtypehandling"></a> 9.1.6.5 Mapping Custom Types
34173481
34183482Datatypes such as an Oracle Locator ` SDO_GEOMETRY ` , or your own custom
34193483types, cannot be fetched directly in node-oracledb. Instead, utilize
0 commit comments