54
54
- 5.2.3 [ execute()] ( #execute )
55
55
- 5.2.4 [ release()] ( #release )
56
56
- 5.2.5 [ rollback()] ( #rollback )
57
- - 5.3 [ SQL Execution] ( #sqlexecution )
58
- - 5.3.1 [ IN Bind Parameters] ( #inbind )
59
- - 5.3.2 [ OUT and IN OUT Bind Parameters] ( #outbind )
60
- - 5.3.3 [ SELECT Statements] ( #select )
61
- - [ Result Type Mapping] ( #typemap )
62
- - [ Statement Caching] ( #stmtcache )
63
- 6 . [ Transaction Management] ( #transactionmgt )
64
- 7 . [ Database Resident Connection Pooling] ( #drcp )
65
- 8 . [ External Configuration] ( #oraaccess )
57
+ 6 . [ SQL Execution] ( #sqlexecution )
58
+ - 6.1 [ SELECT Statements] ( #select )
59
+ - 6.1.1 [ Result Type Mapping] ( #typemap )
60
+ - 6.1.2 [ Statement Caching] ( #stmtcache )
61
+ - 6.2 [ Bind Parameters for Prepared Statements] ( #bind )
62
+ - 6.2.1 [ IN Bind Parameters] ( #inbind )
63
+ - 6.2.2 [ OUT and IN OUT Bind Parameters] ( #outbind )
64
+ 7 . [ Transaction Management] ( #transactionmgt )
65
+ 8 . [ Database Resident Connection Pooling] ( #drcp )
66
+ 9 . [ External Configuration] ( #oraaccess )
66
67
67
68
## <a name =" intro " ></a > 1. Introduction
68
69
69
70
The Oracle Database Node.js driver * node-oracledb* powers high
70
71
performance Node.js applications.
71
72
72
73
This document shows how to use node-oracledb. For how to install
73
- node-oracledb, see [ INSTALL] ( # ../INSTALL.md) .
74
+ node-oracledb, see [ INSTALL] ( ../INSTALL.md ) .
74
75
75
76
### Example: Simple SELECT statement implementation in Node.js
76
77
@@ -1093,26 +1094,135 @@ Callback function parameter | Description
1093
1094
----------------------------|-------------
1094
1095
* Error error* | If ` rollback() ` succeeds ` error ` is NULL. If an error occurs, then ` error ` contains the [ error message] ( #errorobj ) .
1095
1096
1096
- ### <a name =" sqlexecution " ></a > 5.3 SQL Execution
1097
+ ## <a name =" sqlexecution " ></a > 6. SQL Execution
1097
1098
1098
1099
A SQL or PL/SQL statement may be executed using the * Connection*
1099
1100
[ ` execute() ` ] ( #execute ) method.
1100
1101
1102
+ After all database calls on the connection complete, the application
1103
+ should use the [ ` release() ` ] ( #release ) call to release the connection.
1104
+
1101
1105
1102
1106
[ DML] ( https://docs.oracle.com/database/121/CNCPT/glossary.htm#CNCPT2042 )
1103
1107
statements are not committed unless the ` commit() ` call is issued or
1104
1108
the ` isAutoCommit ` property is * true* at the time of execution. Any
1105
1109
ongoing transaction will be rolled back when [ ` release() ` ] ( #release )
1106
1110
is called, or when the application ends.
1107
1111
1112
+ ### <a name =" select " ></a > 6.1 SELECT Statements
1113
+
1114
+ If the ` execute() ` method contains a SQL ` SELECT ` statement, it returns
1115
+ an array of rows. Each row, by default, is an array of column values.
1116
+ The rows array holds up to ` maxRows ` number of rows.
1117
+
1118
+ The following example shows how to obtain rows returned a ` SELECT `
1119
+ statement.
1120
+
1121
+ ``` javascript
1122
+ connection .execute (" SELECT first_name, salary, hire_date "
1123
+ + " FROM employees, departments "
1124
+ + " WHERE employees.department_id = departments.department_id "
1125
+ + " AND departments.department_name = 'Accounting'" ,
1126
+ function (err , result ) {
1127
+ if (err) { console .error (err .message ); return ; }
1128
+ var rows = result .rows ;
1129
+ for (var i = 0 ; i < rows .length ; i++ )
1130
+ console .log (" Row " + i + " : " + rows[i]);
1131
+ });
1132
+ ```
1133
+
1134
+ If run with Oracle's sample HR schema, the output is:
1135
+
1136
+ ```
1137
+ Row 0 : Shelley,12000,Tue Jun 07 1994 01:00:00 GMT-0700 (PDT)
1138
+ Row 1 : William,8300,Tue Jun 07 1994 01:00:00 GMT-0700 (PDT)
1139
+ ```
1140
+
1141
+ Using this format is recommended for efficiency.
1142
+
1143
+ Alternatively, rows may be fetched as JavaScript objects. To do so,
1144
+ specify the ` outFormat ` option to be ` OBJECT ` :
1145
+
1146
+ ``` javascript
1147
+ connection .execute (" SELECT first_name, salary, hire_date "
1148
+ + " FROM employees, departments "
1149
+ + " WHERE employees.department_id = departments.department_id "
1150
+ + " AND departments.department_name = 'Accounting'" ,
1151
+ [], // No bind variables
1152
+ {outFormat: oracledb .OBJECT },
1153
+ function (err , result ) {
1154
+ if (err) { console .error (err .message ); return ; }
1155
+ var rows = result .rows ;
1156
+ for (var i = 0 ; i < rows .length ; i++ )
1157
+ console .log (" Row " + i + " : " +
1158
+ rows[i].FIRST_NAME + " , " ,
1159
+ rows[i].SALARY + " , " , rows[i].HIRE_DATE );
1160
+ });
1161
+ ```
1162
+
1163
+ If run with Oracle's sample HR schema, the output is:
1164
+
1165
+ ```
1166
+ Row 0 : Shelley, 12000, Tue Jun 07 1994 01:00:00 GMT-0700 (PDT)
1167
+ Row 1 : William, 8300, Tue Jun 07 1994 01:00:00 GMT-0700 (PDT)
1168
+ ```
1169
+
1170
+ In the preceding example, each row is a JavaScript object that
1171
+ specifies column names and their respective values. Note that the
1172
+ property names are uppercase. This is the default casing behavior for
1173
+ Oracle client programs when a database table is created with
1174
+ case-insensitive column names.
1175
+
1176
+ ### <a name =" typemap " ></a > 6.1.1 Result Type Mapping
1177
+
1178
+ Oracle character, number and date columns can be selected. Data types
1179
+ that are currently unsupported give a "datatype is not supported"
1180
+ error.
1181
+
1182
+ Query result type mappings for Oracle Database types to JavaScript types are:
1183
+
1184
+ - Variable and fixed length character columns are mapped to JavaScript strings.
1185
+
1186
+ - All numeric columns are mapped to JavaScript numbers.
1187
+
1188
+ - Date and Timestamp columns are mapped to JavaScript dates.
1189
+ Note that JavaScript Date has millisecond precision.
1190
+ Therefore, timestamps having greater
1191
+ precision lose their sub-millisecond fractional part
1192
+ when fetched. Internally, ` TIMESTAMP ` and ` DATE `
1193
+ columns are fetched as ` TIMESTAMP WITH LOCAL TIMEZONE ` using
1194
+ [ OCIDateTime] ( https://docs.oracle.com/database/121/LNOCI/oci12oty.htm#LNOCI16840 ) .
1195
+ When binding a JavaScript Date value in an ` INSERT ` statement, the date is also inserted as `TIMESTAMP WITH
1196
+ LOCAL TIMEZONE` using
1197
+ [ OCIDateTime] ( https://docs.oracle.com/database/121/LNOCI/oci12oty.htm#LNOCI16840 ) .
1198
+
1199
+ ### <a name =" stmtcache " ></a > 6.1.2 Statement Caching
1200
+
1201
+ Node-oracledb uses the
1202
+ [ Oracle OCI statement cache] ( https://docs.oracle.com/database/121/LNOCI/oci09adv.htm#i471377 )
1203
+ which manages a cache of statements for each session. In the database
1204
+ server, statement caching lets cursors be used without reparsing the
1205
+ statement. This eliminates repetitive statement parsing and reduces
1206
+ meta data transfer costs between the driver and the database. This
1207
+ improve performance and scalability.
1208
+
1209
+ In general, set the statement cache to the size of the working set of
1210
+ statements being executed by the application.
1211
+
1212
+ The statement cache can be automatically tuned with the
1213
+ [ oraaccess.xml file] ( #oraaccess ) .
1214
+
1215
+
1216
+ ### <a name =" bind " ></a > 6.2 Bind Parameters for Prepared Statements
1217
+
1108
1218
Using bind variables in SQL statements is recommended in preference to
1109
1219
constructing SQL statements by string concatenation. This is for
1110
1220
performance and security. IN binds are values passed into the
1111
1221
database. OUT binds are used to retrieve data. IN OUT binds are
1112
1222
passed in, and may return a different value after the statement
1113
1223
executes.
1114
1224
1115
- #### <a name =" inbind " ></a > 5.3 .1 IN Bind Parameters
1225
+ #### <a name =" inbind " ></a > 6.2 .1 IN Bind Parameters
1116
1226
1117
1227
SQL and PL/SQL statements may contain bind parameters, indicated by
1118
1228
colon-prefixed identifiers or numerals. For example, this SQL
@@ -1158,7 +1268,7 @@ variables are used for the SQL execution.
1158
1268
With PL/SQL statements, only scalar parameters can be passed. An
1159
1269
array of values cannot be passed to a PL/SQL bind parameter.
1160
1270
1161
- #### <a name =" outbind " ></a > 5.3 .2 OUT and IN OUT Bind Parameters
1271
+ #### <a name =" outbind " ></a > 6.2 .2 OUT and IN OUT Bind Parameters
1162
1272
1163
1273
For OUT and IN OUT binds, the bind value is an object containing
1164
1274
` val ` , ` dir ` , ` type ` and ` maxSize ` properties. The ` results `
@@ -1236,117 +1346,11 @@ The output would be:
1236
1346
{ io: 'ChrisJones', o: 101 }
1237
1347
```
1238
1348
1239
- #### <a name =" select " ></a > 5.3.3 SELECT Statements
1240
-
1241
- If the the ` execute() ` method contains a SQL ` SELECT ` statement, it returns
1242
- an array of rows. Each row, by default, is an array of column values.
1243
- The rows array holds up to ` maxRows ` number of rows.
1244
-
1245
- The following example shows how to obtain rows returned a ` SELECT `
1246
- statement.
1247
-
1248
- ``` javascript
1249
- connection .execute (" SELECT first_name, salary, hire_date "
1250
- + " FROM employees, departments "
1251
- + " WHERE employees.department_id = departments.department_id "
1252
- + " AND departments.department_name = :1" ,
1253
- [" Accounting" ],
1254
- function (err , result ) {
1255
- if (err) { console .error (err .message ); return ; }
1256
- var rows = result .rows ;
1257
- for (var i = 0 ; i < rows .length ; i++ )
1258
- console .log (" Row " + i + " : " + rows[i]);
1259
- });
1260
-
1261
- ```
1262
-
1263
- If run with Oracle's sample HR schema, the output is:
1264
-
1265
- ```
1266
- Row 0 : Shelley,12000,Tue Jun 07 1994 01:00:00 GMT-0700 (PDT)
1267
- Row 1 : William,8300,Tue Jun 07 1994 01:00:00 GMT-0700 (PDT)
1268
- ```
1269
-
1270
- Using this format is recommended for efficiency.
1271
-
1272
- Alternatively, rows may be fetched as JavaScript objects. To do so,
1273
- specify the ` outFormat ` option to be ` OBJECT ` :
1274
-
1275
- ``` javascript
1276
- connection .execute (" SELECT first_name, salary, hire_date "
1277
- + " FROM employees, departments "
1278
- + " WHERE employees.department_id = departments.department_id "
1279
- + " AND departments.department_name = :1" ,
1280
- [" Accounting" ],
1281
- {outFormat: oracledb .OBJECT },
1282
- function (err , result ) {
1283
- if (err) { console .error (err .message ); return ; }
1284
- var rows = result .rows ;
1285
- for (var i = 0 ; i < rows .length ; i++ )
1286
- console .log (" Row " + i + " : " +
1287
- rows[i].FIRST_NAME + " , " ,
1288
- rows[i].SALARY + " , " , rows[i].HIRE_DATE );
1289
- });
1290
-
1291
- ```
1292
-
1293
- If run with Oracle's sample HR schema, the output is:
1294
-
1295
- ```
1296
- Row 0 : Shelley, 12000, Tue Jun 07 1994 01:00:00 GMT-0700 (PDT)
1297
- Row 1 : William, 8300, Tue Jun 07 1994 01:00:00 GMT-0700 (PDT)
1298
- ```
1299
-
1300
- In the preceding example, each row is a JavaScript object that
1301
- specifies column names and their respective values. Note that the
1302
- property names are uppercase. This is the default casing behavior for
1303
- Oracle client programs when a database table is created with
1304
- case-insensitive column names.
1305
-
1306
- #### <a name =" typemap " ></a > Result Type Mapping
1307
-
1308
- Oracle character, number and date columns can be selected. Data types
1309
- that are currently unsupported give a "datatype is not supported"
1310
- error.
1311
-
1312
- Query result type mappings for Oracle Database types to JavaScript types are:
1313
-
1314
- - Variable and fixed length character columns are mapped to JavaScript strings.
1315
-
1316
- - All numeric columns are mapped to JavaScript numbers.
1317
-
1318
- - Date and Timestamp columns are mapped to JavaScript dates.
1319
- Note that JavaScript Date has millisecond precision.
1320
- Therefore, timestamps having greater
1321
- precision lose their sub-millisecond fractional part
1322
- when fetched. Internally, ` TIMESTAMP ` and ` DATE `
1323
- columns are fetched as ` TIMESTAMP WITH LOCAL TIMEZONE ` using
1324
- [ OCIDateTime] ( https://docs.oracle.com/database/121/LNOCI/oci12oty.htm#LNOCI16840 ) .
1325
- When binding a JavaScript Date value in an ` INSERT ` statement, the date is also inserted as `TIMESTAMP WITH
1326
- LOCAL TIMEZONE` using
1327
- [ OCIDateTime] ( https://docs.oracle.com/database/121/LNOCI/oci12oty.htm#LNOCI16840 ) .
1328
-
1329
- #### <a name =" stmtcache " ></a > Statement Caching
1330
-
1331
- Node-oracledb uses the
1332
- [ Oracle OCI statement cache] ( https://docs.oracle.com/database/121/LNOCI/oci09adv.htm#i471377 )
1333
- which manages a cache of statements for each session. In the database
1334
- server, statement caching lets cursors be used without reparsing the
1335
- statement. This eliminates repetitive statement parsing and reduces
1336
- meta data transfer costs between the driver and the database. This
1337
- improve performance and scalability.
1338
-
1339
- In general, set the statement cache to the size of the working set of
1340
- statements being executed by the application.
1341
-
1342
- The statement cache can be automatically tuned with the
1343
- [ oraaccess.xml file] ( #oraaccess ) .
1344
-
1345
- ## <a name =" transactionmgt " ></a > 6. Transaction Management
1349
+ ## <a name =" transactionmgt " ></a > 7. Transaction Management
1346
1350
1347
1351
Node-oraclebd implements [ ` commit() ` ] ( #commit ) and
1348
- [ ` rollback() ` ] ( #rollback ) methods that can be used to control
1349
- transactions.
1352
+ [ ` rollback() ` ] ( #rollback ) methods that can be used to explicitly
1353
+ control transactions.
1350
1354
1351
1355
If the [ ` isAutoCommit ` ] ( #propdbisautocommit ) flag is set, then a
1352
1356
commit occurs at the end of each ` execute() ` call. This does not
@@ -1355,9 +1359,6 @@ For maximum efficiency, if a transaction consists of a number of
1355
1359
` execute() ` calls, then set ` isAutoCommit ` to true for the last call
1356
1360
in preference to using an additional, explicit ` commit() ` call.
1357
1361
1358
- After all database calls on the connection complete, the application
1359
- should use the [ ` release() ` ] ( #release ) call to release the connection.
1360
-
1361
1362
When a connection is released, it rolls back any ongoing
1362
1363
transaction. Therefore if a released, pooled connection is used by
1363
1364
a subsequent [ ` pool.getConnection() ` ] ( #getconnection2 ) call, then any
@@ -1368,7 +1369,7 @@ transaction.
1368
1369
When an application ends, any uncommitted transaction on a connection
1369
1370
will be rolled back if there is no explicit commit.
1370
1371
1371
- ## <a name =" drcp " ></a > 7 . Database Resident Connection Pooling
1372
+ ## <a name =" drcp " ></a > 8 . Database Resident Connection Pooling
1372
1373
1373
1374
[ Database Resident Connection Pooling] ( http://docs.oracle.com/database/121/ADFNS/adfns_perf_scale.htm#ADFNS228 )
1374
1375
enables database resource sharing for applications that run in
@@ -1411,7 +1412,7 @@ Oracle white paper
1411
1412
[ PHP Scalability and High Availability] ( http://www.oracle.com/technetwork/topics/php/php-scalability-ha-twp-128842.pdf ) .
1412
1413
This paper also gives more detail on configuring DRCP.
1413
1414
1414
- ## <a name =" oraaccess " ></a > 8 . External Configuration
1415
+ ## <a name =" oraaccess " ></a > 9 . External Configuration
1415
1416
1416
1417
When node-oracledb is linked with Oracle 12c client libraries, the Oracle
1417
1418
client-side configuration file
0 commit comments