Preview release of node-oracledb
This commit is contained in:
parent
c272b6647d
commit
ffca4ce828
|
@ -0,0 +1,15 @@
|
|||
# General Ignores
|
||||
*~
|
||||
*.o
|
||||
\#*#
|
||||
core
|
||||
build
|
||||
|
||||
# Other Ignores
|
||||
npm-debug.log
|
||||
|
||||
# Oracle Ignores
|
||||
sqlnet.log
|
||||
sqlnet.ora
|
||||
tnsnames.ora
|
||||
oraaccess.xml
|
|
@ -0,0 +1,27 @@
|
|||
# Contributing to node-oracledb
|
||||
|
||||
*Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.*
|
||||
|
||||
Pull requests can be made under
|
||||
[The Oracle Contributor Agreement](https://www.oracle.com/technetwork/community/oca-486395.html)
|
||||
(OCA).
|
||||
|
||||
We have a list of great things we want to implement. If you have
|
||||
ideas, get in touch so we don't duplicate efforts.
|
||||
|
||||
For pull requests to be accepted into node-oracledb, the bottom of
|
||||
your commit message must have the following line using your name and
|
||||
e-mail address as it appears in the OCA Signatories list.
|
||||
|
||||
```
|
||||
Signed-off-by: Your Name <you@example.org>
|
||||
```
|
||||
|
||||
This can be automatically added to pull requests by committing with:
|
||||
|
||||
```
|
||||
git commit --signoff
|
||||
````
|
||||
|
||||
Only pull requests from committers that can be verified as having
|
||||
signed the OCA can be accepted.
|
|
@ -0,0 +1,348 @@
|
|||
# Installing node-oracledb
|
||||
|
||||
*Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.*
|
||||
|
||||
You may not use the identified files except in compliance with the Apache
|
||||
License, Version 2.0 (the "License.")
|
||||
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
## Contents
|
||||
|
||||
1. [Overview](#installation)
|
||||
2. [Installation with Instant Client RPMs](#instrpm)
|
||||
3. [Installation with Instant Client ZIP files](#instzip)
|
||||
4. [Installation with a local database](#instoh)
|
||||
|
||||
## <a name="overview"></a> 1. Overview
|
||||
|
||||
The steps below create a standalone Node.js installation for testing.
|
||||
Adjust the steps for your environment.
|
||||
|
||||
The node-oracledb 0.2 release has been tested with Node.js 0.10.35 on
|
||||
64-bit Oracle Linux. The driver can also build in some 32-bit Linux,
|
||||
Solaris and Mac OS X environments, but these architectures have not
|
||||
been fully tested. Installation on those platforms is similar to the
|
||||
steps described in this document.
|
||||
|
||||
Node-oracledb is currently only available on GitHub.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
This installation requires Oracle 11.2 or 12.1 client libraries.
|
||||
These are included in Oracle Instant Client RPMs or ZIPs, a full
|
||||
Oracle Client, or a database on the same machine. Oracle's standard
|
||||
client-server network compatibility applies, which enables connection
|
||||
to databases with different versions.
|
||||
|
||||
Python 2.7 is needed for node-gyp. Gcc is needed on Linux. On OS X,
|
||||
install Xcode.
|
||||
|
||||
### Which Instructions to Follow
|
||||
|
||||
Instructions may need to be adjusted for your platform and environment.
|
||||
|
||||
|
||||
I have ... | Follow this ...
|
||||
----------|-----------------
|
||||
Linux. My database is on another machine. | [Installation with Instant Client RPMs](#instrpm)
|
||||
Solaris. My database is on another machine. | [Installation with Instant Client ZIP files](#instzip)
|
||||
Linux or Solaris, with a database on the same machine. | [Installation with a local database](#instoh)
|
||||
Linux or Solaris, with the full Oracle client (installed via runInstaller) on the same machine. | [Installation with a local database](#instoh)
|
||||
Mac OS X. | [Installation with Instant Client ZIP files](#instzip)
|
||||
Another OS with Oracle 11.2 or 12.1 libraries available | Update binding.gyp and make any code changes required, sign the [OCA](https://www.oracle.com/technetwork/community/oca-486395.html), and submit a pull request with your patch (Windows support is already being worked on).
|
||||
|
||||
Node-oracledb can be installed on the pre-built
|
||||
[*Database App Development VM*](http://www.oracle.com/technetwork/community/developer-vm/index.html#dbapp) for [VirtualBox](https://www.virtualbox.org),
|
||||
which has Oracle Database 12c pre-installed on Oracle Linux. If you want to install your
|
||||
own database, installing the free
|
||||
[Oracle Database 11.2 'XE' Express Edition](http://www.oracle.com/technetwork/database/database-technologies/express-edition/overview/index.html)
|
||||
is quick and easy. Other database editions may be downloaded
|
||||
[here](http://www.oracle.com/technetwork/database/enterprise-edition/downloads/index-092322.html). If you want to
|
||||
install Oracle Linux yourself, it is free from
|
||||
[here](http://public-yum.oracle.com/).
|
||||
|
||||
## <a name="instrpm"></a> 2. Installation with Instant Client RPMs
|
||||
|
||||
### 2.1 Clone [this repository](https://github.com/oracle/node-oracledb)
|
||||
|
||||
```
|
||||
git clone https://github.com/oracle/node-oracledb.git
|
||||
```
|
||||
|
||||
### 2.2 Install Node.js
|
||||
|
||||
Download the
|
||||
[Node.js Linux 64-bit binaries](http://nodejs.org/download/) and
|
||||
extract the file, for example into `$HOME/Desktop`:
|
||||
|
||||
```
|
||||
cd $HOME/Desktop
|
||||
tar -zxf node-v0.10.35-linux-x64.tar.gz
|
||||
```
|
||||
|
||||
Set the PATH variable to include Node.js:
|
||||
|
||||
```
|
||||
export PATH=$HOME/Desktop/node-v0.10.35-linux-x64/bin:$PATH
|
||||
```
|
||||
|
||||
### 2.3 Install the free Oracle Instant Client RPMs
|
||||
|
||||
Download the free 'Basic' and 'SDK' RPMs from [Oracle Technology Network](http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html) and
|
||||
[install them](http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html#ic_x64_inst) as the root user:
|
||||
|
||||
```
|
||||
rpm -ivh oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm
|
||||
rpm -ivh oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm
|
||||
```
|
||||
|
||||
If you have a [ULN](https://linux.oracle.com) subscription, you can
|
||||
alternatively use `yum` to install these packages from the appropriate
|
||||
*Oracle Software for Oracle Linux* channel.
|
||||
|
||||
To run applications, you will need to set the link path:
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=/usr/lib/oracle/12.1/client64/lib
|
||||
```
|
||||
|
||||
Alternatively, if there is no other Oracle software on the machine
|
||||
that will be impacted, permanently add Instant Client to the run-time
|
||||
link path. Do this by creating a file
|
||||
`/etc/ld.so.conf.d/oracle-instantclient.conf` that contains the library
|
||||
location `/usr/lib/oracle/12.1/client64/lib`, and then run `ldconfig`
|
||||
as the root user.
|
||||
|
||||
### 2.4 Install the driver
|
||||
|
||||
If you use a version of the RPMs other than 12.1.0.2, you need to
|
||||
set `OCI_LIB_DIR` and `OCI_INC_DIR` during installation, as shown in
|
||||
the [ZIP instructions](#instzip).
|
||||
|
||||
Run the installer:
|
||||
|
||||
```
|
||||
cd node-oracledb
|
||||
npm install -g
|
||||
```
|
||||
|
||||
### 2.5 Run an example program
|
||||
|
||||
Set `NODE_PATH` to include the newly installed node-oracledb driver:
|
||||
|
||||
```
|
||||
export NODE_PATH=$HOME/Desktop/node-v0.10.35-linux-x64/lib/node_modules
|
||||
```
|
||||
|
||||
Edit `dbconfig.js` in the `examples` directory and set the database
|
||||
credentials to your environment.
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
user : "hr",
|
||||
password : "welcome",
|
||||
connectString : "localhost/XE"
|
||||
};
|
||||
```
|
||||
|
||||
Run one of the examples:
|
||||
|
||||
```
|
||||
node examples/select1.js
|
||||
```
|
||||
|
||||
Remember to set `LD_LIBRARY_PATH` or equivalent first.
|
||||
|
||||
## <a name="instzip"></a> 3. Installation with Instant Client ZIP files
|
||||
|
||||
### 3.1 Clone [this repository](https://github.com/oracle/node-oracledb)
|
||||
|
||||
```
|
||||
git clone https://github.com/oracle/node-oracledb.git
|
||||
```
|
||||
|
||||
### 3.2 Install Node.js
|
||||
|
||||
Download the
|
||||
[Node.js Linux 64-bit binaries](http://nodejs.org/download/) and
|
||||
extract the file, for example into `$HOME/Desktop`:
|
||||
|
||||
```
|
||||
cd $HOME/Desktop
|
||||
tar -zxf node-v0.10.35-linux-x64.tar.gz
|
||||
```
|
||||
|
||||
Set your PATH to include Node.js:
|
||||
|
||||
```
|
||||
export PATH=$HOME/Desktop/node-v0.10.35-linux-x64/bin:$PATH
|
||||
```
|
||||
|
||||
### 3.3 Install the free Oracle Instant Client ZIPs
|
||||
|
||||
Download the free 'Basic' and 'SDK' ZIPs from
|
||||
[Oracle Technology Network](http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html)
|
||||
and
|
||||
[install them](http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html#ic_x64_inst):
|
||||
|
||||
```
|
||||
cd /opt/oracle
|
||||
unzip instantclient-basic-linux.x64-12.1.0.2.0.zip
|
||||
unzip instantclient-sdk-linux.x64-12.1.0.2.0.zip
|
||||
cd instantclient_12_1
|
||||
ln -s libclntsh.so.12.1 libclntsh.so
|
||||
ln -s libocci.so.12.1 libocci.so
|
||||
```
|
||||
|
||||
Make sure that `libaio` is installed.
|
||||
|
||||
To run applications, you will need to set the link path:
|
||||
|
||||
```
|
||||
export LD_LIBRARY_PATH=/opt/oracle/instantclient_12_1
|
||||
```
|
||||
|
||||
Alternatively, if there is no other Oracle software on the machine
|
||||
that will be impacted, permanently add Instant Client to the run-time
|
||||
link path. Do this on Linux by creating a file
|
||||
`/etc/ld.so.conf.d/oracle-instantclient.conf` that contains the library
|
||||
location `/opt/oracle/instantclient_12_1`, and then run `ldconfig` as
|
||||
the root user.
|
||||
|
||||
### 3.4 Install the driver
|
||||
|
||||
Tell the installer where you installed Instant Client:
|
||||
|
||||
```
|
||||
export OCI_LIB_DIR=/opt/oracle/instantclient_12_1
|
||||
export OCI_INC_DIR=/opt/oracle/instantclient_12_1/sdk/include
|
||||
```
|
||||
|
||||
Run the installer:
|
||||
|
||||
```
|
||||
cd node-oracledb
|
||||
npm install -g
|
||||
```
|
||||
|
||||
### 3.5 Run an example program
|
||||
|
||||
Set `NODE_PATH` to include the newly installed node-oracledb driver:
|
||||
|
||||
```
|
||||
export NODE_PATH=$HOME/Desktop/node-v0.10.35-linux-x64/lib/node_modules
|
||||
```
|
||||
|
||||
Edit `dbconfig.js` in the `examples` directory and set the database
|
||||
credentials to your environment.
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
user : "hr",
|
||||
password : "welcome",
|
||||
connectString : "localhost/XE"
|
||||
};
|
||||
```
|
||||
|
||||
Run one of the examples:
|
||||
|
||||
```
|
||||
node examples/select1.js
|
||||
```
|
||||
|
||||
*Note:* Remember to set `LD_LIBRARY_PATH` or equivalent first.
|
||||
|
||||
## <a name="instoh"></a> 4. Installation with a local database
|
||||
|
||||
The ORACLE_HOME can be either a database home or a full Oracle client installation.
|
||||
Make sure Node.js has permissions to read the libraries and other Oracle files.
|
||||
|
||||
For easy development, the free
|
||||
[Oracle XE](http://www.oracle.com/technetwork/database/database-technologies/express-edition/overview/index.html)
|
||||
version of the database is available on Linux. Node.js applications
|
||||
developed with XE may be immediately used with other editions of the
|
||||
Oracle Database.
|
||||
|
||||
### 4.1 Clone [this repository](https://github.com/oracle/node-oracledb)
|
||||
|
||||
```
|
||||
git clone https://github.com/oracle/node-oracledb.git
|
||||
```
|
||||
|
||||
### 4.2 Install Node.js
|
||||
|
||||
Download the
|
||||
[Node.js Linux 64-bit binaries](http://nodejs.org/download/) and
|
||||
extract the file, for example into `$HOME/Desktop`:
|
||||
|
||||
```
|
||||
cd $HOME/Desktop
|
||||
tar -zxf node-v0.10.35-linux-x64.tar.gz
|
||||
```
|
||||
|
||||
Set your PATH variable to include Node.js:
|
||||
|
||||
```
|
||||
export PATH=$HOME/Desktop/node-v0.10.35-linux-x64/bin:$PATH
|
||||
```
|
||||
|
||||
### 4.3 Install the driver
|
||||
|
||||
Tell the installer where to find the Oracle client:
|
||||
|
||||
```
|
||||
export OCI_LIB_DIR=$ORACLE_HOME/lib
|
||||
export OCI_INC_DIR=$ORACLE_HOME/rdbms/public
|
||||
```
|
||||
|
||||
Run the installer:
|
||||
|
||||
```
|
||||
cd node-oracledb
|
||||
npm install -g
|
||||
```
|
||||
|
||||
### 4.4 Run an example program
|
||||
|
||||
Set `NODE_PATH` to include the newly installed node-oracledb driver:
|
||||
|
||||
```
|
||||
export NODE_PATH=$HOME/Desktop/node-v0.10.35-linux-x64/lib/node_modules
|
||||
```
|
||||
|
||||
Set `LD_LIBRARY_PATH` to the Oracle library directory. This variable,
|
||||
and other variables used by Oracle clients, are typically set in a
|
||||
shell by executing:
|
||||
```
|
||||
source /usr/local/bin/oraenv
|
||||
```
|
||||
|
||||
If you are using Oracle XE, execute `source
|
||||
/u01/app/oracle/product/11.2.0/xe/bin/oracle_env.sh`.
|
||||
|
||||
Edit `dbconfig.js` in the `examples` directory and set the database
|
||||
credentials to your environment.
|
||||
|
||||
```
|
||||
module.exports = {
|
||||
user : "hr",
|
||||
password : "welcome",
|
||||
connectString : "localhost/XE"
|
||||
};
|
||||
```
|
||||
|
||||
Run one of the examples:
|
||||
|
||||
```
|
||||
node examples/select1.js
|
||||
```
|
||||
|
202
LICENSE
202
LICENSE
|
@ -1,202 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
|
@ -0,0 +1,219 @@
|
|||
You may not use the identified files except in compliance with the
|
||||
Apache License, Version 2.0 (the "License.")
|
||||
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0. A copy of the license is
|
||||
also reproduced below.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
|
||||
```
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
```
|
117
README.md
117
README.md
|
@ -0,0 +1,117 @@
|
|||
# node-oracledb version 0.2
|
||||
|
||||
## <a name="about"></a> 1. About node-oracledb
|
||||
|
||||
The Oracle Database Node.js driver powers high performance
|
||||
Node.js applications.
|
||||
|
||||
Node-oracledb 0.2 supports basic and advanced Oracle features, including:
|
||||
|
||||
- SQL and PL/SQL Execution
|
||||
- Binding using JavaScript objects or arrays
|
||||
- Query results as JavaScript objects or array
|
||||
- Conversion between JavaScript and Oracle types
|
||||
- Transaction Management
|
||||
- Connection Pooling
|
||||
- [Statement Caching](http://docs.oracle.com/database/121/LNOCI/oci09adv.htm#i471377)
|
||||
- [Client Result Caching](http://docs.oracle.com/database/121/ADFNS/adfns_perf_scale.htm#ADFNS464)
|
||||
- [End-to-end tracing](http://docs.oracle.com/database/121/TGSQL/tgsql_trace.htm#CHDBDGIJ)
|
||||
- High Availability Features
|
||||
- [Fast Application Notification](http://docs.oracle.com/database/121/ADFNS/adfns_avail.htm#ADFNS538) (FAN)
|
||||
- [Runtime Load Balancing](http://docs.oracle.com/database/121/ADFNS/adfns_perf_scale.htm#ADFNS515) (RLB)
|
||||
- [Transparent Application Failover](http://docs.oracle.com/database/121/ADFNS/adfns_avail.htm#ADFNS534) (TAF)
|
||||
|
||||
Node-oracledb 0.2 is a preview release. We are actively working on
|
||||
adding features including Windows platform support, LOB support, batch
|
||||
fetching / streaming of large query result sets, and
|
||||
[DRCP](#http://docs.oracle.com/database/121/ADFNS/adfns_perf_scale.htm#ADFNS228)
|
||||
support.
|
||||
|
||||
Send us your feedback so we can incorporate any fixes and "must-haves"
|
||||
into a 1.0 release soon.
|
||||
|
||||
Issues with node-oracledb can be reported
|
||||
[here](https://github.com/oracle/node-oracledb/issues).
|
||||
|
||||
The driver is maintained by Oracle Corp.
|
||||
|
||||
The node-oracledb home page is on the
|
||||
[Oracle Technology Network](http://www.oracle.com/technetwork/database/database-technologies/node_js/index.html).
|
||||
|
||||
### Example: Simple SELECT statement implementation in node-oracledb
|
||||
|
||||
```javascript
|
||||
var oracledb = require('oracledb');
|
||||
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : "hr",
|
||||
password : "welcome",
|
||||
connectString : "localhost/XE"
|
||||
},
|
||||
function(err, connection)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
connection.execute(
|
||||
"SELECT department_id, department_name "
|
||||
+ "FROM departments "
|
||||
+ "WHERE department_id = :did",
|
||||
[180],
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.log('%s', err.message);
|
||||
return;
|
||||
}
|
||||
console.log(result.rows);
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
With Oracle's sample HR schema, the output is:
|
||||
|
||||
```
|
||||
[ [ 180, 'Construction' ] ]
|
||||
```
|
||||
|
||||
There are more examples in the [examples](examples) directory.
|
||||
|
||||
## <a name="installation"></a> 2. Installation
|
||||
|
||||
The current release of node-oracledb is available only on GitHub. The basic install steps are:
|
||||
|
||||
- Install the small, free [Oracle Instant Client](http://www.oracle.com/technetwork/database/features/instant-client/index-100365.html) libraries, or have a local database such as the free [Oracle XE](http://www.oracle.com/technetwork/database/database-technologies/express-edition/overview/index.html) release.
|
||||
- Clone this repository
|
||||
- Run `npm install`
|
||||
|
||||
See [INSTALL](INSTALL.md) for details.
|
||||
|
||||
## <a name="doc"></a> 3. Documentation
|
||||
|
||||
See [API Documentation](doc/api.md)
|
||||
|
||||
## <a name="contrib"></a> 4. Contributing
|
||||
|
||||
Node-oracledb is an open source project. See
|
||||
[CONTRIBUTING](CONTRIBUTING.md)
|
||||
for details.
|
||||
|
||||
## <a name="license"></a> 5. Licence
|
||||
|
||||
Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
You may not use the identified files except in compliance with the Apache
|
||||
License, Version 2.0 (the "License.")
|
||||
|
||||
You may obtain a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name" : "oracledb",
|
||||
"sources" : [
|
||||
"src/njs/src/njsOracle.cpp",
|
||||
"src/njs/src/njsPool.cpp",
|
||||
"src/njs/src/njsConnection.cpp",
|
||||
"src/njs/src/njsMessages.cpp",
|
||||
"src/dpi/src/dpiEnv.cpp",
|
||||
"src/dpi/src/dpiEnvImpl.cpp",
|
||||
"src/dpi/src/dpiException.cpp",
|
||||
"src/dpi/src/dpiExceptionImpl.cpp",
|
||||
"src/dpi/src/dpiConnImpl.cpp",
|
||||
"src/dpi/src/dpiDateTimeArrayImpl.cpp",
|
||||
"src/dpi/src/dpiPoolImpl.cpp",
|
||||
"src/dpi/src/dpiStmtImpl.cpp",
|
||||
"src/dpi/src/dpiUtils.cpp"
|
||||
],
|
||||
"conditions" : [
|
||||
[
|
||||
'OS=="linux"', {
|
||||
"variables" : {
|
||||
"oci_inc_dir%" : "<!(if [ -z $OCI_INC_DIR ]; then echo \"/usr/include/oracle/12.1/client64/\"; else echo $OCI_INC_DIR; fi)",
|
||||
"oci_lib_dir%" : "<!(if [ -z $OCI_LIB_DIR ]; then echo \"/usr/lib/oracle/12.1/client64/lib/\"; else echo $OCI_LIB_DIR; fi)",
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'OS=="mac"', {
|
||||
"xcode_settings": {
|
||||
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
||||
"GCC_ENABLE_CPP_RTTI": "YES"
|
||||
},
|
||||
"variables" : {
|
||||
"oci_inc_dir%" : "<!(if [ -z $OCI_INC_DIR ]; then echo \"/opt/oracle/instantclient_11_2/sdk/include/\"; else echo $OCI_INC_DIR; fi)",
|
||||
"oci_lib_dir%" : "<!(if [ -z $OCI_LIB_DIR ]; then echo \"/opt/oracle/instantclient_11_2/\"; else echo $OCI_LIB_DIR; fi)",
|
||||
}
|
||||
}
|
||||
],
|
||||
[
|
||||
'OS=="solaris"', {
|
||||
"variables" : {
|
||||
"oci_inc_dir%" : "<!(if [ -z $OCI_INC_DIR ]; then echo \"/opt/oracle/instantclient_12_1/sdk/include/\"; else echo $OCI_INC_DIR; fi)",
|
||||
"oci_lib_dir%" : "<!(if [ -z $OCI_LIB_DIR ]; then echo \"/opt/oracle/instantclient_12_1/\"; else echo $OCI_LIB_DIR; fi)",
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"cflags" : ['-fexceptions'],
|
||||
"cflags_cc" : ['-fexceptions'],
|
||||
"include_dirs" : [ "<(oci_inc_dir)",
|
||||
"src/dpi/src/",
|
||||
"src/dpi/include/"
|
||||
],
|
||||
"libraries" : ["-lclntsh"],
|
||||
"link_settings" : {
|
||||
"libraries" : ['-L<(oci_lib_dir)']
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,53 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* connect.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Tests a basic connection to the database.
|
||||
* See dbconfig.js for information on connectString formats.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString
|
||||
},
|
||||
function(err, connection)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Connection was successful!');
|
||||
|
||||
connection.release(
|
||||
function(err)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,164 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* date.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Insert and query DATE and TIMESTAMP columns.
|
||||
*
|
||||
* When bound in an INSERT, JavaScript Dates are inserted using
|
||||
* TIMESTAMP WITH LOCAL TIMEZONE. Similarly for queries, TIMESTAMP
|
||||
* and DATE columns are fetched as TIMESTAMP WITH LOCAL TIMEZONE.
|
||||
*
|
||||
* This demo also shows rollback.
|
||||
*
|
||||
*****************************************************************************///
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
var connection;
|
||||
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString
|
||||
},
|
||||
createTable
|
||||
);
|
||||
|
||||
function createTable(err, conn) {
|
||||
var script;
|
||||
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
connection = conn;
|
||||
script = getCreateTableScript();
|
||||
|
||||
connection.execute(
|
||||
script,
|
||||
insertTestData
|
||||
);
|
||||
}
|
||||
|
||||
function insertTestData(err) {
|
||||
var date;
|
||||
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
date = new Date();
|
||||
|
||||
console.log("Inserting JavaScript date: " + date);
|
||||
|
||||
// When bound, JavaScript Dates are inserted using TIMESTAMP WITH LOCAL TIMEZONE
|
||||
connection.execute(
|
||||
"INSERT INTO datetest (timestampcol, datecol) VALUES (:ts, :td)",
|
||||
{
|
||||
ts: date,
|
||||
td: date
|
||||
},
|
||||
{isAutoCommit : false},
|
||||
selectData
|
||||
);
|
||||
}
|
||||
|
||||
function selectData(err, result) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("----- Insertion Done --------");
|
||||
console.log('rowsAffected = %d', result.rowsAffected);
|
||||
|
||||
connection.execute(
|
||||
"SELECT timestampcol, datecol FROM datetest",
|
||||
processResults
|
||||
);
|
||||
}
|
||||
|
||||
function processResults(err, result) {
|
||||
var ts;
|
||||
var d;
|
||||
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("----- Query Results --------");
|
||||
console.log(result.rows);
|
||||
|
||||
console.log("----- JavaScript Date Manipulation --------");
|
||||
// Show the queried dates are of type Date
|
||||
ts = result.rows[0][0];
|
||||
ts.setDate(ts.getDate() + 5);
|
||||
console.log(ts);
|
||||
|
||||
d = result.rows[0][1];
|
||||
d.setDate(d.getDate() - 5);
|
||||
console.log(d);
|
||||
|
||||
connection.rollback(releaseConnection); // don't actually commit the new row on exit
|
||||
}
|
||||
|
||||
function releaseConnection(err) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("----- Rollback complete --------");
|
||||
connection.release(logReleaseError); // close the connection
|
||||
}
|
||||
|
||||
function logReleaseError(err) {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function getCreateTableScript() {
|
||||
var script =
|
||||
"BEGIN " +
|
||||
" DECLARE " +
|
||||
" e_table_exists EXCEPTION; " +
|
||||
" PRAGMA EXCEPTION_INIT(e_table_exists, -00942); " +
|
||||
" BEGIN " +
|
||||
" EXECUTE IMMEDIATE ('DROP TABLE datetest'); " +
|
||||
" EXCEPTION " +
|
||||
" WHEN e_table_exists " +
|
||||
" THEN NULL; " +
|
||||
" END; " +
|
||||
" EXECUTE IMMEDIATE (' " +
|
||||
" CREATE TABLE datetest ( " +
|
||||
" timestampcol TIMESTAMP, " +
|
||||
" datecol DATE " +
|
||||
" )" +
|
||||
" '); " +
|
||||
"END; ";
|
||||
|
||||
return script;
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dbconfig.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Holds the credentials used by node-oracledb examples to connect
|
||||
* to the database.
|
||||
*
|
||||
* The connectString here uses the Easy Connect syntax
|
||||
* "localhost/XE". This connects to the database service XE on the
|
||||
* the local machine.
|
||||
*
|
||||
* Applications can set the connectString value to an Easy Connect
|
||||
* string, or a Connect Name from a tnsnames.ora file, or the name
|
||||
* of a local Oracle database instance.
|
||||
*
|
||||
* The full Easy Connect syntax is:
|
||||
* [//]host_name[:port][/service_name][:server_type][/instance_name]
|
||||
* see https://docs.oracle.com/database/121/NETAG/naming.htm#i498306
|
||||
*
|
||||
* If a tnsnames.ora file is used, set the TNS_ADMIN environment
|
||||
* variable such that $TNS_ADMIN/tnsnames.ora is read.
|
||||
* Alternatively use $ORACLE_HOME/network/admin/tnsnames.ora or
|
||||
* /etc/tnsnames.ora.
|
||||
*
|
||||
* If connectString is not specified, the empty string "" is used
|
||||
* which indicates to connect to the local, default database.
|
||||
*
|
||||
* Errors like:
|
||||
* ORA-12541: TNS:no listener
|
||||
* or
|
||||
* ORA-12154: TNS:could not resolve the connect identifier specified
|
||||
* indicate connectString is invalid.
|
||||
*
|
||||
* The error:
|
||||
* ORA-12514: TNS:listener does not currently know of requested in connect descriptor
|
||||
* indicates connectString is invalid. You are reaching a computer
|
||||
* with Oracle installed but the service name isn't known.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
module.exports = {
|
||||
user : "hr",
|
||||
password : "welcome",
|
||||
connectString : "localhost/XE"
|
||||
};
|
|
@ -0,0 +1,35 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* demo.sql
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Create database objects for the examples
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
SET ECHO ON
|
||||
|
||||
CREATE OR REPLACE PROCEDURE testproc (p_in IN VARCHAR2, p_inout IN OUT VARCHAR2, p_out OUT NUMBER)
|
||||
AS
|
||||
BEGIN
|
||||
p_inout := p_in || p_inout;
|
||||
p_out := 101;
|
||||
END;
|
||||
/
|
||||
show errors
|
|
@ -0,0 +1,91 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* insert1.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Creates a table and inserts data. Shows DDL and DML
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString
|
||||
},
|
||||
function(err, connection)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
connection.execute(
|
||||
"CREATE TABLE test (id NUMBER, name VARCHAR2(20))",
|
||||
function(err)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
console.log("Table created");
|
||||
|
||||
connection.execute(
|
||||
"INSERT INTO test VALUES (:id, :nm)",
|
||||
[1, 'Chris'], // Bind values
|
||||
function(err, result)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
console.log("Rows inserted: " + result.rowsAffected); // 1
|
||||
|
||||
connection.execute(
|
||||
"INSERT INTO test VALUES (:id, :nm)",
|
||||
[2, 'Alison'], // Bind values
|
||||
function(err, result)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
console.log("Rows inserted: " + result.rowsAffected); // 1
|
||||
|
||||
connection.execute(
|
||||
"UPDATE test SET name = 'Bambi'",
|
||||
function(err, result)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
console.log("Rows updated: " + result.rowsAffected); // 2
|
||||
|
||||
connection.execute(
|
||||
"DROP TABLE test",
|
||||
function(err)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
console.log("Table dropped");
|
||||
|
||||
connection.release(
|
||||
function(err)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,123 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* insert2.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Show the auto commit behavior.
|
||||
*
|
||||
* By default, node-oracledb does not commit on execute.
|
||||
* The driver also has commit() and rollback() methods to explicitly control transactions.
|
||||
*
|
||||
* Note: when a connection is closed, any open transaction will be committed.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString
|
||||
},
|
||||
function(err, connection1)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
connection1.execute(
|
||||
"CREATE TABLE test (id NUMBER, name VARCHAR2(20))",
|
||||
function(err)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
console.log("Table created");
|
||||
|
||||
connection1.execute(
|
||||
"INSERT INTO test VALUES (:id, :nm)",
|
||||
[1, 'Chris'], // Bind values
|
||||
{ isAutoCommit: true}, // Override the default non-autocommit behavior
|
||||
function(err, result)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
console.log("Rows inserted: " + result.rowsAffected); // 1
|
||||
|
||||
connection1.execute(
|
||||
"INSERT INTO test VALUES (:id, :nm)",
|
||||
[2, 'Alison'], // Bind values
|
||||
// { isAutoCommit: true}, // Since this isn't set, operations using a second connection won't see this row
|
||||
function(err, result)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
console.log("Rows inserted: " + result.rowsAffected); // 1
|
||||
|
||||
// Create a second connection
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString
|
||||
},
|
||||
function(err, connection2)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
connection2.execute(
|
||||
"SELECT * FROM test",
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
// This will only show 'Chris' because inserting 'Alison' is not commited by default.
|
||||
// Uncomment the isAutoCommit option above and you will see both rows
|
||||
console.log(result.rows);
|
||||
|
||||
connection1.execute(
|
||||
"DROP TABLE test",
|
||||
function(err)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
console.log("Table dropped");
|
||||
|
||||
connection2.release(
|
||||
function(err)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
connection1.release(
|
||||
function(err)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,61 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* plsql.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Show calling a PL/SQL procedure and binding parameters in various ways
|
||||
* Use demo.sql to create the required procedure or do:
|
||||
*
|
||||
* CREATE OR REPLACE PROCEDURE testproc (p_in IN VARCHAR2, p_inout IN OUT VARCHAR2, p_out OUT NUMBER)
|
||||
* AS
|
||||
* BEGIN
|
||||
* p_inout := p_in || p_inout;
|
||||
* p_out := 101;
|
||||
* END;
|
||||
* /
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString
|
||||
},
|
||||
function (err, connection)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
|
||||
var bindvars = {
|
||||
i: 'Chris', // bind type is determined from the data type
|
||||
io: { val: 'Jones', dir : oracledb.BIND_INOUT },
|
||||
o: { type: oracledb.NUMBER, dir : oracledb.BIND_OUT },
|
||||
}
|
||||
connection.execute(
|
||||
"BEGIN testproc(:i, :io, :o); END;",
|
||||
bindvars,
|
||||
function (err, result)
|
||||
{
|
||||
if (err) { console.error(err.message); return; }
|
||||
console.log(result.outBinds);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,124 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* rowlimit.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Shows ways to limit the number of records fetched by queries.
|
||||
* Uses Oracle's sample HR schema.
|
||||
*
|
||||
* By default, node-oracledb has a maxRows attribute that limits the
|
||||
* number of records fetched from a query to 100. Although
|
||||
* adjusting maxRows can be used to control the number of rows
|
||||
* available to the application, it is more efficient for the
|
||||
* database if the SQL query syntax limits the number of rows
|
||||
* queried. Use maxRows only to prevent badly coded queries from
|
||||
* consuming too many Node.js resources.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
|
||||
// Properties are applicable to all connections and SQL executions.
|
||||
// They can also be set or overridden at the individual execute() call level
|
||||
//
|
||||
// This script sets maxRows in the execute() call but it could be set here instead
|
||||
// oracledb.maxRows = 200; // Note the default value is 100
|
||||
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString
|
||||
},
|
||||
function(err, connection)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Returns 100 records although the table has 107 rows. Node-oracledb's default maxRows is 100
|
||||
connection.execute(
|
||||
"SELECT employee_id, last_name "
|
||||
+ "FROM employees "
|
||||
+ "ORDER BY employee_id",
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
console.log("----- Number of employee rows returned with default maxRow limit of 100 --------");
|
||||
console.log(result.rows.length);
|
||||
//console.log(result.rows);
|
||||
});
|
||||
|
||||
// Increasing maxRows from the default returns all 107 rows
|
||||
connection.execute(
|
||||
"SELECT employee_id, last_name "
|
||||
+ "FROM employees "
|
||||
+ "ORDER BY employee_id",
|
||||
{}, // A bind variable parameter is needed to disambiguate the following options parameter
|
||||
// otherwise you will get Error: ORA-01036: illegal variable name/number
|
||||
{maxRows: 150},
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
console.log("----- Number of employee rows returned with increased maxRow value --------");
|
||||
console.log(result.rows.length);
|
||||
//console.log(result.rows);
|
||||
});
|
||||
|
||||
// Oracle 12c syntax for fetching rows 6-10 from a query (won't work with 11g)
|
||||
connection.execute(
|
||||
"SELECT employee_id, last_name "
|
||||
+ "FROM employees "
|
||||
+ "ORDER BY employee_id "
|
||||
+ "OFFSET 5 ROWS FETCH NEXT 5 ROWS ONLY",
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
console.log("----- Five employees (12c query syntax) --------");
|
||||
console.log(result.rows);
|
||||
});
|
||||
|
||||
// Oracle 11g syntax for fetching rows 6-10 from a query
|
||||
connection.execute(
|
||||
"SELECT employee_id, last_name "
|
||||
+ "FROM (SELECT a.*, ROWNUM AS rnum "
|
||||
+ "FROM (SELECT employee_id, last_name FROM employees ORDER BY employee_id) a "
|
||||
+ "WHERE ROWNUM <= 10) "
|
||||
+ "WHERE rnum > 5",
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
console.log("----- Five employees (pre 12c query syntax) --------");
|
||||
console.log(result.rows);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,55 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* select1.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Executes a basic query.
|
||||
* Uses Oracle's sample HR schema.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString
|
||||
},
|
||||
function(err, connection)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
connection.execute(
|
||||
"SELECT department_id, department_name "
|
||||
+ "FROM departments "
|
||||
+ "WHERE department_id = :did",
|
||||
[180],
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
console.log(result.rows);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,89 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* select2.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Executes queries to show array and object output formats.
|
||||
* Uses Oracle's sample HR schema.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
|
||||
// Properties are applicable to all connections and SQL executions.
|
||||
// They can also be set or overridden at the individual execute() call level
|
||||
//
|
||||
// This script sets outFormat in the execute() call but it could be set here instead
|
||||
// oracledb.outFormat = oracledb.OBJECT;
|
||||
|
||||
oracledb.getConnection(
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString
|
||||
},
|
||||
function(err, connection)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
connection.execute(
|
||||
"SELECT location_id, city "
|
||||
+ "FROM locations "
|
||||
+ "WHERE city LIKE 'S%' "
|
||||
+ "ORDER BY city",
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
console.log("----- Cities beginning with 'S' (default ARRAY output format) --------");
|
||||
console.log(result.rows);
|
||||
|
||||
connection.execute(
|
||||
"SELECT location_id, city "
|
||||
+ "FROM locations "
|
||||
+ "WHERE city LIKE 'S%' "
|
||||
+ "ORDER BY city",
|
||||
{}, // A bind variable parameter is needed to disambiguate the following options parameter
|
||||
// otherwise you will get Error: ORA-01036: illegal variable name/number
|
||||
{outFormat: oracledb.OBJECT}, // outFormat can be OBJECT and ARRAY. The default is ARRAY
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
console.log("----- Cities beginning with 'S' (OBJECT output format) --------");
|
||||
console.log(result.rows);
|
||||
|
||||
connection.release(
|
||||
function(err)
|
||||
{
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
return;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,33 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* version.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Shows the oracledb version attribute
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var oracledb = require('oracledb');
|
||||
|
||||
console.log("Driver version number is " + oracledb.version);
|
||||
|
||||
major = Math.floor(oracledb.version/10000);
|
||||
minor = Math.floor(oracledb.version/100) % 100;
|
||||
patch = oracledb.version % 100;
|
||||
console.log("Driver version text is " + major + "." + minor + "." + patch);
|
|
@ -0,0 +1,228 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* webapp.js
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Shows a web based query using connections from connection pool.
|
||||
*
|
||||
* This displays a table of employees in the specified department.
|
||||
*
|
||||
* The script creates an HTTP server listening on port 7000 and
|
||||
* accepts a URL parameter for the department ID, for example:
|
||||
* http://localhost:7000/90
|
||||
*
|
||||
* Uses Oracle's sample HR schema.
|
||||
*
|
||||
* The connection pool should not be terminated as long as the server is up.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var sys = require('sys');
|
||||
var http = require('http');
|
||||
var url = require('url');
|
||||
var oracledb = require('oracledb');
|
||||
var dbConfig = require('./dbconfig.js');
|
||||
|
||||
var portid = 7000; // HTTP listening port number
|
||||
|
||||
// Main entry point. Creates a connection pool, on callback creates an
|
||||
// HTTP server and executes a query based on the URL parameter given
|
||||
// The pool values are arbitrary for the sake of showing how to set the properties.
|
||||
oracledb.createPool (
|
||||
{
|
||||
user : dbConfig.user,
|
||||
password : dbConfig.password,
|
||||
connectString : dbConfig.connectString,
|
||||
poolMax : 44,
|
||||
poolMin : 2,
|
||||
poolIncrement : 5,
|
||||
poolTimeout : 4
|
||||
},
|
||||
function(err, pool)
|
||||
{
|
||||
if (err) {
|
||||
console.error('createPool() callback: ' + err.message);
|
||||
return;
|
||||
}
|
||||
|
||||
// Create HTTP server and listen on port - portid
|
||||
hs = http.createServer (
|
||||
function(req, res) // Callback gets HTTP request & response object
|
||||
{
|
||||
var urlparts = req.url.split("/");
|
||||
var deptid = urlparts[1];
|
||||
|
||||
if (deptid != parseInt(deptid)) {
|
||||
console.error('Argument "' + deptid + '" is not an integer');
|
||||
return;
|
||||
}
|
||||
|
||||
htmlheader(res,
|
||||
"Oracle Database Driver for Node.js" ,
|
||||
"Example using node-oracledb driver");
|
||||
|
||||
// Checkout a connection from the pool
|
||||
pool.getConnection (
|
||||
function(err, connection)
|
||||
{
|
||||
if (err) {
|
||||
console.error('getConnection() callback: ' + err.message);
|
||||
htmlerror(res, "getConnection() failed ", err);
|
||||
return;
|
||||
}
|
||||
|
||||
//console.log('Connections open: ' + pool.connectionsOpen);
|
||||
//console.log('Connections in use: ' + pool.connectionsInUse);
|
||||
|
||||
connection.execute(
|
||||
"SELECT employee_id, first_name, last_name "
|
||||
+ "FROM employees "
|
||||
+ "WHERE department_id = :id",
|
||||
[deptid], // bind variable value
|
||||
function(err, result)
|
||||
{
|
||||
if (err) {
|
||||
console.error('execute() callback: ' + err.message);
|
||||
htmlerror(res, "execute() callback", err);
|
||||
return;
|
||||
}
|
||||
|
||||
// Employee table title
|
||||
htmlh2title(res, "Employees in Department " + deptid);
|
||||
|
||||
// Output as table
|
||||
htmltablestart(res);
|
||||
|
||||
// Column Title
|
||||
htmlrowstart(res);
|
||||
htmlcell(res, "Employee id");
|
||||
htmlcell(res, "First Name");
|
||||
htmlcell(res, "Last Name");
|
||||
|
||||
for (i = 0; i < result.rows.length; i ++) {
|
||||
htmlrowstart(res);
|
||||
for (j = 0; j < result.rows[i].length; j ++) {
|
||||
htmlcell(res, result.rows[i][j]);
|
||||
}
|
||||
htmlrowend(res);
|
||||
}
|
||||
htmltableend(res);
|
||||
|
||||
/* Release the connection back to the connection pool */
|
||||
connection.release(
|
||||
function(err)
|
||||
{
|
||||
if (err) {
|
||||
console.error('release() callback: ' + err.message);
|
||||
htmlerror(res, "release() callback", err);
|
||||
return;
|
||||
}
|
||||
htmlfooter(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
process.on('SIGTERM', function () {
|
||||
console.log('Received SIGTERM');
|
||||
pool.terminate(
|
||||
function(err)
|
||||
{
|
||||
if (err) {
|
||||
console.error('terminate() callback: ' + err.message);
|
||||
process.exit(0);
|
||||
}
|
||||
console.log('Closed Oracle connection pool');
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
|
||||
hs.listen(portid, "localhost");
|
||||
|
||||
sys.puts("Server running at http://localhost:" + portid);
|
||||
});
|
||||
|
||||
// To prepare HTML header
|
||||
function htmlheader(res, title, caption)
|
||||
{
|
||||
res.writeHead (200, {'Content-Type' : 'text/html' });
|
||||
res.write ("<!DOCTYPE html>");
|
||||
res.write ("<html>");
|
||||
res.write ("<head>");
|
||||
res.write ("<style>"
|
||||
+ "body {background:#FFFFFF;color:#000000;font-family:Arial,sans-serif;margin:40px;padding:10px;font-size:12px;text-align:center;}"
|
||||
+ "h1 {margin:0px;margin-bottom:12px;background:#FF0000;text-align:center;color:#FFFFFF;font-size:28px;}"
|
||||
+ "table {border-collapse: collapse; margin-left:auto; margin-right:auto;}"
|
||||
+ "td {padding:8px;border-style:solid}"
|
||||
+ "</style>\n");
|
||||
res.write ("<title>" + caption + "</title>");
|
||||
res.write ("</head>");
|
||||
res.write ("<body>");
|
||||
res.write ("<h1>" + title + "</h1>");
|
||||
}
|
||||
|
||||
// To prepare HTML footer
|
||||
function htmlfooter(res)
|
||||
{
|
||||
res.write("</body>\n</html>");
|
||||
res.end();
|
||||
}
|
||||
|
||||
// To display error in HTML
|
||||
function htmlerror(res, text, err)
|
||||
{
|
||||
res.write("<p>ERROR " + text + " " + err.message + "</p>");
|
||||
htmlfooter(res);
|
||||
}
|
||||
|
||||
// To start TABLE tag
|
||||
function htmltablestart(res)
|
||||
{
|
||||
res.write("<table>");
|
||||
}
|
||||
|
||||
// To end the TABLE tag
|
||||
function htmltableend(res)
|
||||
{
|
||||
res.write("</table>");
|
||||
}
|
||||
|
||||
// To add h2 title
|
||||
function htmlh2title(res, title)
|
||||
{
|
||||
res.write("<h2>" + title + "</h2>");
|
||||
}
|
||||
|
||||
// To add row in a table
|
||||
function htmlrowstart(res)
|
||||
{
|
||||
res.write("<tr>");
|
||||
}
|
||||
|
||||
// To end row in a table
|
||||
function htmlrowend(res)
|
||||
{
|
||||
res.write("</tr>");
|
||||
}
|
||||
|
||||
// To add a cell in the table
|
||||
function htmlcell(res, text)
|
||||
{
|
||||
res.write("<td>" + text + "</td>");
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
var oracledb = null;
|
||||
|
||||
try {
|
||||
oracledb = require("../build/Release/oracledb");
|
||||
} catch (err) {
|
||||
if (err.code === 'MODULE_NOT_FOUND') {
|
||||
oracledb = require("../build/Debug/oracledb");
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
var oracledb_ins = new oracledb.Oracledb();
|
||||
|
||||
oracledb_ins.STRING = 1;
|
||||
oracledb_ins.NUMBER = 2;
|
||||
oracledb_ins.DATE = 3;
|
||||
|
||||
oracledb_ins.ARRAY = 1;
|
||||
oracledb_ins.OBJECT = 2;
|
||||
|
||||
oracledb_ins.BIND_IN = 1;
|
||||
oracledb_ins.BIND_INOUT = 2;
|
||||
oracledb_ins.BIND_OUT = 3;
|
||||
|
||||
module.exports = oracledb_ins;
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
"name" : "oracledb",
|
||||
"version" : "0.2.4",
|
||||
"description" : "Node.js Driver for Oracle Database",
|
||||
"license" : "Apache 2.0",
|
||||
"homepage": "http://www.oracle.com/technetwork/database/database-technologies/node_js/index.html",
|
||||
"private" : true,
|
||||
"keywords" : [
|
||||
"nodejs", "Oracle", "Database"
|
||||
],
|
||||
"repository" : {
|
||||
"type" : "git",
|
||||
"url" : "git://github.com/oracle/node-oracledb.git"
|
||||
},
|
||||
"dependencies" : {
|
||||
},
|
||||
"engines" : {
|
||||
"node" : ">=0.10"
|
||||
},
|
||||
"maintainers" : [
|
||||
{
|
||||
"name" : "Oracle Corp."
|
||||
}
|
||||
],
|
||||
"bugs" : {
|
||||
"url" : "https://github.com/oracle/node-oracledb/issues"
|
||||
},
|
||||
"scripts" : {
|
||||
"install" : "node-gyp rebuild"
|
||||
},
|
||||
"main" : "./index.js"
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpi.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPI_ORACLE
|
||||
# define DPI_ORACLE
|
||||
|
||||
|
||||
#ifndef DPIEXCEPTION_ORACLE
|
||||
# include <dpiException.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIENV_ORACLE
|
||||
# include <dpiEnv.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIPOOL_ORACLE
|
||||
# include <dpiPool.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPICONN_ORACLE
|
||||
# include <dpiConn.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPISTMT_ORACLE
|
||||
# include <dpiStmt.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIDATETIMEARRAY_ORACLE
|
||||
# include <dpiDateTimeArray.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
COMMON PUBLIC CONSTANTS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* DPI_ORACLE */
|
|
@ -0,0 +1,93 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiconn.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPICONN_ORACLE
|
||||
# define DPICONN_ORACLE
|
||||
|
||||
#ifndef DPISTMT_ORACLE
|
||||
# include <dpiStmt.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
|
||||
namespace dpi
|
||||
{
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC CONSTANTS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
|
||||
class Conn
|
||||
{
|
||||
public:
|
||||
// termination
|
||||
|
||||
virtual void release() = 0;
|
||||
|
||||
// properties
|
||||
virtual void stmtCacheSize(unsigned int stmtCacheSize) = 0;
|
||||
virtual unsigned int stmtCacheSize() const = 0;
|
||||
|
||||
virtual void clientId(const string &clientId) = 0;
|
||||
|
||||
virtual void module(const string &module) = 0;
|
||||
|
||||
virtual void action(const string &action) = 0;
|
||||
|
||||
// methods
|
||||
virtual Stmt* getStmt (const string &sql) = 0;
|
||||
|
||||
virtual void commit() = 0;
|
||||
|
||||
virtual void rollback() = 0;
|
||||
|
||||
virtual void breakExecution() = 0;
|
||||
|
||||
protected:
|
||||
// clients cannot do new and delete
|
||||
Conn(){};
|
||||
|
||||
virtual ~Conn(){};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // end of namespace dpi
|
||||
|
||||
|
||||
#endif /* DPICONN_ORACLE */
|
|
@ -0,0 +1,74 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiDateTimeArray.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIDATETIMEARRAY_ORACLE
|
||||
# define DPIDATETIMEARRAY_ORACLE
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
namespace dpi
|
||||
{
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC CONSTANTS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
/*************************************************************************
|
||||
* Name DateTimeArray
|
||||
*
|
||||
* DESCRIPTION Interface definiton for DateTime as Array of Descriptors
|
||||
*
|
||||
* Methods
|
||||
* init - to allocate specified number of descritpors
|
||||
* release - deallocate the descriptors allocated and call the parent
|
||||
* object to destroy this object also. one time use only.
|
||||
* getDateTime to return a double value
|
||||
* setDateTime to set Date/Time from double value
|
||||
*
|
||||
************************************************************************/
|
||||
class DateTimeArray
|
||||
{
|
||||
public:
|
||||
// To allocate an array of descriptors
|
||||
virtual void* init ( int nCount ) = 0;
|
||||
// To dealloate the descriptors and this calss
|
||||
virtual void release () = 0 ;
|
||||
|
||||
// Date/time as double value # of seconds from 1970-1-1 00:00:00
|
||||
virtual long double getDateTime ( const int idx ) = 0;
|
||||
virtual void setDateTime ( const int idx, long double ms) = 0;
|
||||
|
||||
// Destructor
|
||||
virtual ~DateTimeArray() {};
|
||||
};
|
||||
|
||||
} // namespace dpi
|
||||
|
||||
#endif // ifdef DPIDATETIMEARRAY_ORACLE
|
|
@ -0,0 +1,114 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiEnv.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIENV_ORACLE
|
||||
# define DPIENV_ORACLE
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifndef DPI_ORACLE
|
||||
# include <dpi.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPIPOOL_ORACLE
|
||||
# include <dpiPool.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPICONN_ORACLE
|
||||
# include <dpiConn.h>
|
||||
#endif
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
namespace dpi
|
||||
{
|
||||
|
||||
class DateTimeArray;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
class Env
|
||||
{
|
||||
public:
|
||||
// creation/termination
|
||||
|
||||
static Env * createEnv();
|
||||
|
||||
virtual void terminate() = 0;
|
||||
|
||||
// properties
|
||||
virtual void poolMax(unsigned int poolMax) = 0;
|
||||
virtual unsigned int poolMax() const = 0;
|
||||
|
||||
virtual void poolMin(unsigned int poolMin) = 0;
|
||||
virtual unsigned int poolMin() const = 0;
|
||||
|
||||
virtual void poolIncrement(unsigned int poolMax) = 0;
|
||||
virtual unsigned int poolIncrement() const = 0;
|
||||
|
||||
virtual void poolTimeout(unsigned int poolTimeout) = 0;
|
||||
virtual unsigned int poolTimeout() const = 0;
|
||||
|
||||
virtual void isExternalAuth(bool isExternalAuth) = 0;
|
||||
virtual bool isExternalAuth() const = 0;
|
||||
|
||||
// methods
|
||||
virtual SPool * createPool(const string &user, const string &password,
|
||||
const string &connString,
|
||||
int poolMax = -1, int poolMin = -1,
|
||||
int poolIncrement = -1,
|
||||
int poolTimeout = -1,
|
||||
int stmtCacheSize = -1) = 0;
|
||||
|
||||
virtual Conn * getConnection(const string &user, const string &password,
|
||||
const string &connString,
|
||||
int stmtCacheSize) = 0;
|
||||
|
||||
// DateTime array.
|
||||
virtual DateTimeArray* getDateTimeArray( OCIError *errh ) const = 0;
|
||||
virtual void releaseDateTimeArray ( DateTimeArray *arr ) const = 0;
|
||||
|
||||
protected:
|
||||
// clients cannot do new and delete
|
||||
Env();
|
||||
|
||||
virtual ~Env();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // end of namespace dpi
|
||||
|
||||
|
||||
#endif /* DPIENV_ORACLE */
|
|
@ -0,0 +1,82 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiException.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIEXCEPTION_ORACLE
|
||||
# define DPIEXCEPTION_ORACLE
|
||||
|
||||
|
||||
#include <exception>
|
||||
|
||||
|
||||
using std::exception;
|
||||
|
||||
|
||||
|
||||
namespace dpi
|
||||
{
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC CONSTANTS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
enum DpiError // error type
|
||||
{
|
||||
DpiErrNoError = 000, // "DPI not an error"
|
||||
DpiErrInternal = 001, // "DPI internal error"
|
||||
DpiErrUnkOciError = 002, // "Could not get OCI Error message"
|
||||
DpiErrNoEnv = 003, // "No OCI environment handle created"
|
||||
DpiErrInvalidState = 004, // "Invalid state while working with timestamp"
|
||||
DpiErrUninitialized = 005, // "Uninitialized state while working with timestamp"
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
class Exception : public exception
|
||||
{
|
||||
public:
|
||||
// creation/termination
|
||||
Exception(){};
|
||||
|
||||
virtual ~Exception() throw();
|
||||
|
||||
virtual const char * what() const throw() = 0;
|
||||
|
||||
virtual int errno() const throw() = 0;
|
||||
|
||||
virtual const char * origin() const throw() = 0;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // end of namespace dpi
|
||||
|
||||
|
||||
#endif /* DPIEXCEPTION_ORACLE */
|
|
@ -0,0 +1,81 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiPool.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIPOOL_ORACLE
|
||||
# define DPIPOOL_ORACLE
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
#ifndef DPICONN_ORACLE
|
||||
# include <dpiConn.h>
|
||||
#endif
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
|
||||
namespace dpi
|
||||
{
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
class SPool
|
||||
{
|
||||
public:
|
||||
// termination
|
||||
virtual void terminate() = 0;
|
||||
|
||||
// readonly properties
|
||||
virtual unsigned int connectionsOpen() const = 0;
|
||||
|
||||
virtual unsigned int connectionsInUse() const = 0;
|
||||
|
||||
|
||||
// methods
|
||||
virtual Conn * getConnection() = 0;
|
||||
|
||||
|
||||
protected:
|
||||
// clients cannot do new and delete
|
||||
SPool(){};
|
||||
|
||||
virtual ~SPool(){};
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // end of namespace dpi
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* DPIPOOL_ORACLE */
|
|
@ -0,0 +1,182 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiStmt.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPISTMT_ORACLE
|
||||
# define DPISTMT_ORACLE
|
||||
|
||||
#ifndef OCI_ORACLE
|
||||
# include <oci.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace dpi
|
||||
{
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
enum DpiStmtType
|
||||
{
|
||||
DpiStmtUnknown = 0,
|
||||
DpiStmtSelect = 1,
|
||||
DpiStmtUpdate = 2,
|
||||
DpiStmtDelete = 3,
|
||||
DpiStmtInsert = 4,
|
||||
DpiStmtCreate = 5,
|
||||
DpiStmtDrop = 6,
|
||||
DpiStmtAlter = 7,
|
||||
DpiStmtBegin = 8,
|
||||
DpiStmtDeclare =9,
|
||||
DpiStmtCall = 10
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
DpiVarChar = 1,
|
||||
DpiNumber = 2,
|
||||
DpiInteger = 3, /* external only */
|
||||
DpiDouble = 4, /* external only */
|
||||
DpiString = 5, /* external only */
|
||||
DpiLong = 8,
|
||||
DpiDate = 12,
|
||||
DpiRaw = 23,
|
||||
DpiLongRaw = 24,
|
||||
DpiUnsignedInteger = 68,
|
||||
DpiRowid = 69, /* internal only */
|
||||
DpiFixedChar = 96,
|
||||
DpiBinaryFloat = 100, /* internal only */
|
||||
DpiBinaryDouble = 101, /* internal only */
|
||||
DpiUDT = 108, /* internal only */
|
||||
DpiRef = 111, /* internal only */
|
||||
DpiClob = 112,
|
||||
DpiBlob = 113,
|
||||
DpiBfile = 114,
|
||||
DpiYearMonth = 182, /* internal only */
|
||||
DpiDaySecond = 183, /* internal only */
|
||||
DpiTimestamp = 187, /* internal only */
|
||||
DpiTimestampTZ = 188, /* internal only */
|
||||
DpiURowid = 208, /* internal only */
|
||||
DpiTimestampLTZ = 232, /* internal only */
|
||||
|
||||
DpiTypeBase = 33 * 1024,
|
||||
DpiDateTimeArray, /* external only */
|
||||
DpiIntervalArray /* external only */
|
||||
} DpiDataType;
|
||||
|
||||
/*
|
||||
* For 11g/12c Compatability BIND/DEFINE calls expect ub8 in 12c & ub4 in 11g
|
||||
* Using this type makes is compile-time selction of 11g or 12c.
|
||||
*/
|
||||
#if OCI_MAJOR_VERSION >= 12
|
||||
#define DPI_SZ_TYPE sb8
|
||||
#define DPI_BUFLEN_TYPE ub4
|
||||
#define DPIBINDBYPOS OCIBindByPos2
|
||||
#define DPIBINDBYNAME OCIBindByName2
|
||||
#define DPIDEFINEBYPOS OCIDefineByPos2
|
||||
#define DPIATTRROWCOUNT OCI_ATTR_UB8_ROW_COUNT
|
||||
#else
|
||||
#define DPI_SZ_TYPE sb4
|
||||
#define DPI_BUFLEN_TYPE ub2
|
||||
#define DPIBINDBYPOS OCIBindByPos
|
||||
#define DPIBINDBYNAME OCIBindByName
|
||||
#define DPIDEFINEBYPOS OCIDefineByPos
|
||||
#define DPIATTRROWCOUNT OCI_ATTR_ROW_COUNT
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char *colName; // column name
|
||||
unsigned int colNameLen; // length of column name
|
||||
unsigned short dbType; // database server type
|
||||
unsigned short dbSize; // size at database
|
||||
unsigned int precision; // precision
|
||||
char scale; // scale
|
||||
unsigned char isNullable; // is the column nullable?
|
||||
} MetaData;
|
||||
|
||||
|
||||
|
||||
class Stmt
|
||||
{
|
||||
public:
|
||||
// termination
|
||||
virtual void release() = 0;
|
||||
|
||||
// properties
|
||||
virtual DpiStmtType stmtType() const = 0;
|
||||
|
||||
virtual unsigned long rowsAffected() const = 0;
|
||||
|
||||
virtual unsigned int numCols() = 0;
|
||||
|
||||
// methods
|
||||
virtual void bind(unsigned int pos, unsigned short type, void *buf,
|
||||
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen) = 0;
|
||||
|
||||
virtual void bind(const unsigned char *name, int nameLen,
|
||||
unsigned short type, void *buf, DPI_SZ_TYPE bufSize,
|
||||
short *ind, DPI_BUFLEN_TYPE *bufLen) = 0;
|
||||
|
||||
virtual void executeDML(bool isAutoCommit) = 0;
|
||||
|
||||
virtual void executeMany(int numIterations, bool isAutoCommit ) = 0;
|
||||
|
||||
virtual void executeQuery() = 0;
|
||||
|
||||
virtual void define(unsigned int pos, unsigned short type, void *buf,
|
||||
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen) = 0;
|
||||
|
||||
virtual void fetch(unsigned int numRows = 1) = 0;
|
||||
|
||||
virtual const MetaData * getMetaData() = 0;
|
||||
|
||||
virtual unsigned int rowsFetched() const = 0;
|
||||
|
||||
virtual OCIError *getError () = 0;
|
||||
|
||||
|
||||
virtual ~Stmt(){};
|
||||
|
||||
protected:
|
||||
// clients cannot do new and delete
|
||||
Stmt(){};
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
|
||||
} // end of namespace dpi
|
||||
|
||||
|
||||
#endif /* DPISTMT_ORACLE */
|
|
@ -0,0 +1,487 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiConnImpl.cpp - ConnImpl class implementation
|
||||
*
|
||||
* DESCRIPTION
|
||||
* This file implements the ConnImpl class which provides the implemenation of
|
||||
* the Conn abstract class.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef ORATYPES
|
||||
# include <oratypes.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPICONNIMPL_ORACLE
|
||||
# include <dpiConnImpl.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPISTMTIMPL_ORACLE
|
||||
# include <dpiStmtImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIUTILS_ORACLE
|
||||
# include <dpiUtils.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Constructor for the ConnImpl class created from an Env object.
|
||||
|
||||
PARAMETERS:
|
||||
env - parent Env object
|
||||
envh - OCI envh
|
||||
stmtCacheSize - statement cache size
|
||||
user - userid
|
||||
password - password
|
||||
connString - connect string
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
*/
|
||||
|
||||
ConnImpl::ConnImpl(EnvImpl *env, OCIEnv *envh, bool isExternalAuth,
|
||||
unsigned int stmtCacheSize,
|
||||
const string &user, const string &password,
|
||||
const string &connString)
|
||||
|
||||
try : env_(env), pool_(NULL),
|
||||
envh_(envh), errh_(NULL), auth_(NULL), svch_(NULL), sessh_(NULL)
|
||||
{
|
||||
ub4 mode = isExternalAuth ? OCI_SESSGET_CREDEXT : OCI_DEFAULT;
|
||||
|
||||
ociCallEnv(OCIHandleAlloc((void *)envh_, (dvoid **)&errh_,
|
||||
OCI_HTYPE_ERROR, 0, (dvoid **)0), envh_);
|
||||
|
||||
ociCallEnv(OCIHandleAlloc((void *)envh_, (dvoid **)&auth_,
|
||||
OCI_HTYPE_AUTHINFO, 0, (dvoid **)0), envh_);
|
||||
|
||||
if (!isExternalAuth)
|
||||
{
|
||||
ociCall(OCIAttrSet((void *)auth_, OCI_HTYPE_AUTHINFO,
|
||||
(void *)user.data(), user.length(),
|
||||
OCI_ATTR_USERNAME, errh_), errh_);
|
||||
|
||||
ociCall(OCIAttrSet((void *)auth_, OCI_HTYPE_AUTHINFO,
|
||||
(void *)password.data(), password.length(),
|
||||
OCI_ATTR_PASSWORD, errh_), errh_);
|
||||
}
|
||||
|
||||
ociCall(OCISessionGet(envh_, errh_, &svch_, auth_,
|
||||
(OraText *)connString.data(),
|
||||
connString.length(), NULL, 0, NULL, NULL, NULL,
|
||||
mode), errh_);
|
||||
|
||||
ociCall(OCIAttrGet(svch_, OCI_HTYPE_SVCCTX, &sessh_, 0,
|
||||
OCI_ATTR_SESSION, errh_),errh_);
|
||||
|
||||
this->stmtCacheSize(stmtCacheSize);
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
cleanup();
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Constructor for the ConnImpl class created from a Pool object.
|
||||
|
||||
PARAMETERS:
|
||||
pool - parent Pool object
|
||||
envh - OCI envh
|
||||
stmtCacheSize - statement cache size
|
||||
poolName - name of the pool
|
||||
poolNameLen - length of pool name
|
||||
connectionClass - connection class.
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
This constructor to be used in session-pool scenarios.
|
||||
*/
|
||||
|
||||
ConnImpl::ConnImpl(PoolImpl *pool, OCIEnv *envh, bool isExternalAuth,
|
||||
OraText *poolName, ub4 poolNameLen
|
||||
)
|
||||
|
||||
try : env_(NULL), pool_(pool),
|
||||
envh_(envh), errh_(NULL), auth_(NULL),
|
||||
svch_(NULL), sessh_(NULL)
|
||||
{
|
||||
ub4 mode = isExternalAuth ? (OCI_SESSGET_CREDEXT | OCI_SESSGET_SPOOL) :
|
||||
OCI_SESSGET_SPOOL;
|
||||
ociCallEnv(OCIHandleAlloc((void *)envh_, (dvoid **)&errh_,
|
||||
OCI_HTYPE_ERROR, 0, (dvoid **)0), envh_);
|
||||
|
||||
ociCallEnv(OCIHandleAlloc((void *)envh_, (dvoid **)&auth_,
|
||||
OCI_HTYPE_AUTHINFO, 0, (dvoid **)0), envh_);
|
||||
ociCall(OCISessionGet(envh_, errh_, &svch_, auth_,
|
||||
poolName, poolNameLen,
|
||||
NULL, 0, NULL, NULL, NULL,
|
||||
mode), errh_);
|
||||
|
||||
ociCall(OCIAttrGet(svch_, OCI_HTYPE_SVCCTX, &sessh_, 0, OCI_ATTR_SESSION,
|
||||
errh_), errh_);
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
cleanup ();
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Destructor for the ConnImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
ConnImpl::~ConnImpl()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Release the connection.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void ConnImpl::release()
|
||||
{
|
||||
if (pool_)
|
||||
pool_->releaseConnection(this);
|
||||
else if (env_)
|
||||
env_->releaseConnection(this);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* NAME
|
||||
* releaseStmt
|
||||
*
|
||||
* DESCRIPTION
|
||||
* To release Stmt object created
|
||||
*
|
||||
* PARAMETERS
|
||||
* stmt - DPI stmt object
|
||||
*
|
||||
* RETURNS
|
||||
* -NONE-
|
||||
****************************************************************************/
|
||||
void ConnImpl::releaseStmt ( Stmt *stmt )
|
||||
{
|
||||
if (stmt )
|
||||
{
|
||||
delete stmt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set statement cache size.
|
||||
|
||||
PARAMETERS:
|
||||
stmtCacheSize - statement cache size
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void ConnImpl::stmtCacheSize(unsigned int stmtCacheSize)
|
||||
{
|
||||
ociCall(OCIAttrSet(svch_, OCI_HTYPE_SVCCTX, &stmtCacheSize, 0,
|
||||
OCI_ATTR_STMTCACHESIZE, errh_), errh_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get statement cache size.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
statement cache size
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
unsigned int ConnImpl::stmtCacheSize() const
|
||||
{
|
||||
unsigned int stmtCacheSize = 0;
|
||||
|
||||
ociCall(OCIAttrGet(svch_, OCI_HTYPE_SVCCTX, &stmtCacheSize, NULL,
|
||||
OCI_ATTR_STMTCACHESIZE, errh_), errh_);
|
||||
|
||||
return stmtCacheSize;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set client id.
|
||||
|
||||
PARAMETERS:
|
||||
clientId - client id
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void ConnImpl::clientId(const string &clientId)
|
||||
{
|
||||
ociCall(OCIAttrSet(sessh_, OCI_HTYPE_SESSION, (void *)clientId.data(),
|
||||
clientId.length(), OCI_ATTR_CLIENT_IDENTIFIER, errh_),
|
||||
errh_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set the module.
|
||||
|
||||
PARAMETERS:
|
||||
module - module
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void ConnImpl::module(const string &module)
|
||||
{
|
||||
ociCall(OCIAttrSet(sessh_, OCI_HTYPE_SESSION, (void *)module.data(),
|
||||
module.length(), OCI_ATTR_MODULE, errh_), errh_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set action.
|
||||
|
||||
PARAMETERS:
|
||||
action - action
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void ConnImpl::action(const string &action)
|
||||
{
|
||||
ociCall(OCIAttrSet(sessh_, OCI_HTYPE_SESSION, (void *)action.data(),
|
||||
action.length(), OCI_ATTR_ACTION, errh_), errh_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Prepare & return the dpiStatement object
|
||||
|
||||
PARAMETERS:
|
||||
sql - SQL statement
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
Stmt* ConnImpl::getStmt (const string &sql)
|
||||
{
|
||||
StmtImpl *stmt = new StmtImpl ( env_, envh_, this, svch_, sql);
|
||||
|
||||
return stmt;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Commit the transaction in progress
|
||||
|
||||
PARAMETERS:
|
||||
-NONE-
|
||||
|
||||
RETURNS
|
||||
-NONE_
|
||||
*/
|
||||
void ConnImpl::commit ()
|
||||
{
|
||||
ociCall (OCITransCommit (svch_, errh_, OCI_DEFAULT), errh_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Rollback the transaction in progress
|
||||
|
||||
PARAMETERS
|
||||
-NONE-
|
||||
|
||||
RETUNRS:
|
||||
-NONE_
|
||||
*/
|
||||
void ConnImpl::rollback ()
|
||||
{
|
||||
ociCall (OCITransRollback (svch_, errh_, OCI_DEFAULT), errh_);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
break (interrupt) the currently executing operation
|
||||
|
||||
PARAMETERS
|
||||
-NONE-
|
||||
|
||||
RETURNS:
|
||||
-NONE_
|
||||
*/
|
||||
void ConnImpl::breakExecution()
|
||||
{
|
||||
if(svch_)
|
||||
{
|
||||
ociCall (OCIBreak (svch_, errh_), errh_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PRIVATE METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Cleanup for the ConnImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
The free OCI handles are set to NULL to so that in case someone tries to
|
||||
use a release Conn handle, they will get a reproducible seg-fault.
|
||||
*/
|
||||
|
||||
void ConnImpl::cleanup()
|
||||
{
|
||||
if (svch_)
|
||||
{
|
||||
OCISessionRelease(svch_, errh_, NULL, 0, OCI_DEFAULT);
|
||||
svch_ = NULL;
|
||||
}
|
||||
|
||||
if (auth_)
|
||||
{
|
||||
OCIHandleFree (auth_, OCI_HTYPE_AUTHINFO);
|
||||
auth_ = NULL;
|
||||
}
|
||||
|
||||
if (errh_)
|
||||
{
|
||||
OCIHandleFree(errh_, OCI_HTYPE_ERROR);
|
||||
errh_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* end of file dpiConnImpl.cpp */
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiconnImpl.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPICONNIMPL_ORACLE
|
||||
# define DPICONNIMPL_ORACLE
|
||||
|
||||
|
||||
#ifndef OCI_ORACLE
|
||||
# include <oci.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPICONN_ORACLE
|
||||
# include <dpiConn.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIENVIMPL_ORACLE
|
||||
# include <dpiEnvImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIPOOLIMPL_ORACLE
|
||||
# include <dpiPoolImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
using namespace dpi;
|
||||
|
||||
|
||||
class EnvImpl;
|
||||
class PoolImpl;
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
class ConnImpl : public Conn
|
||||
{
|
||||
public:
|
||||
// creation/termination
|
||||
|
||||
ConnImpl(EnvImpl *env, OCIEnv *envh, bool isExternalAuth,
|
||||
unsigned int stmtCacheSize,
|
||||
const string &user, const string &password,
|
||||
const string &connString);
|
||||
|
||||
ConnImpl(PoolImpl *pool, OCIEnv *envh, bool isExternalAuth,
|
||||
OraText *poolName, ub4 poolNameLen
|
||||
);
|
||||
|
||||
virtual ~ConnImpl();
|
||||
|
||||
virtual void release();
|
||||
|
||||
// interface properties
|
||||
virtual void stmtCacheSize(unsigned int stmtCacheSize);
|
||||
virtual unsigned int stmtCacheSize() const;
|
||||
|
||||
virtual void clientId(const string &clientId);
|
||||
|
||||
virtual void module(const string &module);
|
||||
|
||||
virtual void action(const string &action);
|
||||
|
||||
|
||||
// interface methods
|
||||
virtual Stmt* getStmt(const string &sql);
|
||||
|
||||
virtual void releaseStmt(Stmt *stmt);
|
||||
|
||||
virtual void commit();
|
||||
|
||||
virtual void rollback();
|
||||
|
||||
virtual void breakExecution();
|
||||
|
||||
private:
|
||||
|
||||
void cleanup();
|
||||
|
||||
|
||||
EnvImpl *env_; // parent Env object
|
||||
PoolImpl *pool_; // parent pool object if created from a pool
|
||||
|
||||
OCIEnv *envh_; // OCI enviornment handle
|
||||
OCIError *errh_; // OCI error handle
|
||||
OCIAuthInfo *auth_; // OCI auth handle
|
||||
OCISvcCtx *svch_; // OCI service handle
|
||||
OCISession *sessh_; // OCI Session handle. Do not free this.
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* DPICONNIMPL_ORACLE */
|
|
@ -0,0 +1,346 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiDateTimeArrayImpl.cpp - DateTimeArrayImpl class Implemenation
|
||||
*
|
||||
* DESCRIPTION
|
||||
* This file implmenets the wrapper over Oracle Database type
|
||||
* DATE, TIMESTAMP, TIMESTAMP WITH TZ, TIMESTAMP WITH LOCAL TZ.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifndef ORATYPES
|
||||
# include <oratypes.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPIUTILS_ORACLE
|
||||
# include <dpiUtils.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPIDATEIMPL_ORACLE
|
||||
# include <dpiDateTimeArrayImpl.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPIEXCEPTIONIMPL_ORACLE
|
||||
# include "dpiExceptionImpl.h"
|
||||
#endif
|
||||
|
||||
#define DPI_UTC_TZ "+00:00"
|
||||
#define DPI_BASE_YEAR 1970
|
||||
#define DPI_BASE_MONTH 1
|
||||
#define DPI_BASE_DATE 1
|
||||
#define DPI_BASE_HOUR 0
|
||||
#define DPI_BASE_MIN 0
|
||||
#define DPI_BASE_SEC 0
|
||||
#define DPI_BASE_FS 0
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace dpi;
|
||||
|
||||
// Static member variable initialization - used to compute diff from
|
||||
// given date/time. The baseDate_ is 1970-1-1 0:0:0
|
||||
OCIDateTime * DateTimeArrayImpl::baseDate_ = NULL;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
/****************************************************************************
|
||||
* NAME DateTimeArrayImpl::DateTimeArrayImpl
|
||||
*
|
||||
* DESCRIPTION Constructor of DateTimeArrayImpl
|
||||
*
|
||||
* PARAMETERS
|
||||
* envh OCIEnv handle
|
||||
* errh OCIError handle
|
||||
* stmt dpi Stmt object
|
||||
*
|
||||
****************************************************************************/
|
||||
DateTimeArrayImpl::DateTimeArrayImpl (OCIEnv *envh, OCIError *errh,
|
||||
const Env* env)
|
||||
: env_(env), envh_ (envh), errh_ (errh), dbdatetime_(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* NAME DateTimeArrayImpl::~DateTimeArrayImpl
|
||||
*
|
||||
* DESCRIPTION Destructor of DateTimeArrayImpl
|
||||
*
|
||||
* PARAMETERS
|
||||
*
|
||||
****************************************************************************/
|
||||
DateTimeArrayImpl::~DateTimeArrayImpl ()
|
||||
{
|
||||
if ( dbdatetime_ )
|
||||
{
|
||||
// TO release OCI Descriptor handle array and this class too.
|
||||
this -> release ();
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* NAME DateTimeArrayImpl::init
|
||||
*
|
||||
* DESCRIPTION initialization function to allocate OCI Descriptor array
|
||||
*
|
||||
* PARAMETERS
|
||||
* nCount # of descriptors required
|
||||
*
|
||||
****************************************************************************/
|
||||
void *DateTimeArrayImpl::init (int nCount)
|
||||
{
|
||||
if ( !dbdatetime_ )
|
||||
{
|
||||
// allocate space to hold nCount pointers to OCIDateTime structure
|
||||
dbdatetime_ = (OCIDateTime**) new OCIDateTime*[nCount];
|
||||
sword rc;
|
||||
|
||||
rc = OCIArrayDescriptorAlloc ( (dvoid *)envh_, (void **)&dbdatetime_[0],
|
||||
OCI_DTYPE_TIMESTAMP_LTZ,
|
||||
nCount, 0, (void **)0);
|
||||
if ( rc != OCI_SUCCESS )
|
||||
throw ExceptionImpl ( DpiErrInternal ) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* descriptor array is to be allocated, if for some reason
|
||||
* it is non-null, then bail out.
|
||||
*/
|
||||
throw ExceptionImpl (DpiErrInvalidState);
|
||||
}
|
||||
|
||||
/* NOTE: OCI Descriptor array is returned as void * to be used in
|
||||
* bind, define calls, and methods of this class is used to set/get
|
||||
* timestamp
|
||||
*/
|
||||
return (void *)dbdatetime_;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* NAME DateTimeArrayImpl::release
|
||||
*
|
||||
* DESCRIPTION cleanup OCI Descriptor array and this class
|
||||
*
|
||||
* PARAMETERS
|
||||
*
|
||||
****************************************************************************/
|
||||
void DateTimeArrayImpl::release ()
|
||||
{
|
||||
// destroy OCI descriptor array if already allocated,
|
||||
// if not allocated, ignore.
|
||||
if ( dbdatetime_ )
|
||||
{
|
||||
OCIArrayDescriptorFree ((dvoid **)dbdatetime_, OCI_DTYPE_TIMESTAMP_LTZ);
|
||||
|
||||
delete [] dbdatetime_;
|
||||
dbdatetime_ = NULL;
|
||||
}
|
||||
env_->releaseDateTimeArray ( this ) ;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* NAME DateTimeArrayImpl::getDateTime
|
||||
*
|
||||
* DESCRIPTION To obtain date/time value from descriptor based on
|
||||
* given index as long double value
|
||||
*
|
||||
* PARAMETERS
|
||||
* idx index value.
|
||||
*
|
||||
****************************************************************************/
|
||||
long double DateTimeArrayImpl::getDateTime ( const int idx )
|
||||
{
|
||||
sword rc = 0;
|
||||
long double dbl = 0.0;
|
||||
|
||||
if ( dbdatetime_ )
|
||||
{
|
||||
OCIInterval *interval = NULL ;
|
||||
OCINumber ociNumber;
|
||||
|
||||
rc = OCIDescriptorAlloc ( (dvoid *) envh_, (dvoid **)&interval,
|
||||
OCI_DTYPE_INTERVAL_DS, 0, (dvoid **)0);
|
||||
if (rc)
|
||||
{
|
||||
throw ExceptionImpl ( DpiErrInternal );
|
||||
}
|
||||
|
||||
/* Get diff of date/timestamp */
|
||||
rc = OCIDateTimeSubtract ( envh_, errh_, dbdatetime_[idx], baseDate_,
|
||||
interval);
|
||||
ociCall ( rc, errh_ ) ;
|
||||
|
||||
/* Convert interval to number */
|
||||
ociCall ( OCIIntervalToNumber ( envh_, errh_, interval, &ociNumber ),
|
||||
errh_ ) ;
|
||||
|
||||
/* Convert interval number to long-double value */
|
||||
ociCall ( OCINumberToReal ( errh_, &ociNumber, sizeof (long double),
|
||||
(void *)&dbl), errh_);
|
||||
if ( interval )
|
||||
{
|
||||
OCIDescriptorFree ( interval, OCI_DTYPE_INTERVAL_DS );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// dbdatetime_ has to be allocated by now using init(),
|
||||
// if not bail out.
|
||||
throw ExceptionImpl ( DpiErrUninitialized );
|
||||
}
|
||||
return dbl;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* NAME DateTimeArrayImpl::setDateTime
|
||||
*
|
||||
* DESCRIPTION To set date/time value on descriptor based on
|
||||
* given index from long double value
|
||||
*
|
||||
* PARAMETERS
|
||||
* idx index value.
|
||||
*
|
||||
****************************************************************************/
|
||||
void DateTimeArrayImpl::setDateTime ( const int idx, long double days)
|
||||
{
|
||||
if ( dbdatetime_ )
|
||||
{
|
||||
OCIInterval *interval= NULL;
|
||||
OCINumber ociNumber;
|
||||
sword rc = OCI_SUCCESS ;
|
||||
|
||||
rc = OCIDescriptorAlloc ( (dvoid *) envh_, (dvoid **)&interval,
|
||||
OCI_DTYPE_INTERVAL_DS, 0, (dvoid **)0);
|
||||
if (rc)
|
||||
{
|
||||
throw ExceptionImpl ( DpiErrInternal );
|
||||
}
|
||||
|
||||
// Convert the given long-double value to OCINumber
|
||||
ociCall ( OCINumberFromReal ( errh_, &days, sizeof ( long double ),
|
||||
&ociNumber ), errh_);
|
||||
|
||||
// Convert the number value to interval
|
||||
ociCall ( OCIIntervalFromNumber ( envh_, errh_, interval, &ociNumber ),
|
||||
errh_);
|
||||
|
||||
// Add the interval to the basedate.
|
||||
ociCall ( OCIDateTimeIntervalAdd ( envh_, errh_, baseDate_, interval,
|
||||
dbdatetime_[idx] ), errh_ ) ;
|
||||
|
||||
if ( interval )
|
||||
{
|
||||
OCIDescriptorFree ( interval, OCI_DTYPE_INTERVAL_DS );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ExceptionImpl ( DpiErrUninitialized );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* NAME DateTimeArrayImpl::initBaseDate
|
||||
*
|
||||
* DESCRIPTION To initialize one time initialization of basedate, interval
|
||||
*
|
||||
* PARAMETERS
|
||||
* envh OCI Env Handle
|
||||
*
|
||||
* NOTE:
|
||||
* v8::Date uses # of milliseconds counted from 1970-1-1 0:0:0. To compute
|
||||
* # of seconds, need to find the difference from basedate, and compute
|
||||
* to milliseconds. This baseDate is used for execution cycle, instead of
|
||||
* creating every time, create it one time and use it.
|
||||
****************************************************************************/
|
||||
void DateTimeArrayImpl::initBaseDate ( OCIEnv *envh )
|
||||
{
|
||||
sword rc = OCI_SUCCESS ;
|
||||
OCIError *errh = (OCIError *)0;
|
||||
|
||||
// If baseDate is not allocated, allocate and init
|
||||
if ( !baseDate_ )
|
||||
{
|
||||
rc = OCIDescriptorAlloc ( (dvoid *)envh, (dvoid **)&baseDate_,
|
||||
OCI_DTYPE_TIMESTAMP_LTZ, 0,
|
||||
(dvoid **)0);
|
||||
|
||||
if ( !rc ) // OCI_SUCCESS case
|
||||
{
|
||||
/*
|
||||
* NOTE:
|
||||
* This is one time initialization expected to be done along with
|
||||
* OCI Env creation(one time). At this point of time, errh is not yet
|
||||
* created by OCI Env, create a local one, use and destroy
|
||||
*/
|
||||
ociCallEnv(OCIHandleAlloc((void *)envh, (dvoid **)&errh,
|
||||
OCI_HTYPE_ERROR, 0, (dvoid **)0), envh);
|
||||
// Base date is 1970-1-1 00:00:00
|
||||
ociCall ( OCIDateTimeConstruct (envh, errh, baseDate_,
|
||||
DPI_BASE_YEAR, DPI_BASE_MONTH,
|
||||
DPI_BASE_DATE, DPI_BASE_HOUR,
|
||||
DPI_BASE_MIN, DPI_BASE_SEC, DPI_BASE_FS,
|
||||
(OraText * )DPI_UTC_TZ,
|
||||
strlen ( DPI_UTC_TZ ) ),
|
||||
errh);
|
||||
|
||||
// Free the allocated error handle
|
||||
if (errh)
|
||||
{
|
||||
OCIHandleFree(errh, OCI_HTYPE_ERROR);
|
||||
errh = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ExceptionImpl ( DpiErrInternal ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* NAME DateTimeArrayImpl::cleanBaseDate
|
||||
*
|
||||
* DESCRIPTION To cleanup OCI descriptors for baseDate/interval.
|
||||
*
|
||||
* PARAMETERS
|
||||
*
|
||||
*
|
||||
****************************************************************************/
|
||||
void DateTimeArrayImpl::cleanBaseDate ()
|
||||
{
|
||||
if ( baseDate_ )
|
||||
{
|
||||
OCIDescriptorFree ( baseDate_, OCI_DTYPE_TIMESTAMP_LTZ );
|
||||
baseDate_ = NULL ;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* end of dpiDateTimeArrayImpl.cpp */
|
|
@ -0,0 +1,87 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiDateTimeImpl.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIDATETIMEARRAYIMPL_ORACLE
|
||||
# define DPIDATEARRAYIMPL_ORACLE
|
||||
#endif
|
||||
|
||||
#ifndef DPISTMT_ORACLE
|
||||
# include <dpiEnv.h>
|
||||
#endif
|
||||
|
||||
#ifndef OCIDATETIMEARRAY_ORACLE
|
||||
# include <dpiDateTimeArray.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
namespace dpi
|
||||
{
|
||||
|
||||
class Env;
|
||||
|
||||
|
||||
/********************************************************************
|
||||
* Name : DateTimeArrayImpl
|
||||
*
|
||||
* Descriptoin : Implementation of DateTimeArray interface
|
||||
*
|
||||
* NOTE: One time use only, once release() called the class will be
|
||||
* destroyed
|
||||
*/
|
||||
class DateTimeArrayImpl : public DateTimeArray
|
||||
{
|
||||
public:
|
||||
DateTimeArrayImpl ( OCIEnv *envh, OCIError *err, const Env* env);
|
||||
virtual ~DateTimeArrayImpl ();
|
||||
|
||||
//DateTimeArray methods
|
||||
virtual void* init (int nCount) ;
|
||||
virtual void release ();
|
||||
|
||||
// Date/Time as double value # of seconds from 1970-1-1 00:00:00
|
||||
virtual long double getDateTime ( const int idx ) ;
|
||||
virtual void setDateTime ( const int idx, long double ms);
|
||||
|
||||
public:
|
||||
static void initBaseDate ( OCIEnv *envh);
|
||||
static void cleanBaseDate ();
|
||||
|
||||
private:
|
||||
static OCIDateTime *baseDate_; // Base date 1970-1-1 0:0:0
|
||||
|
||||
private:
|
||||
// DPI parent object
|
||||
const Env *env_;
|
||||
|
||||
// OCI Handles
|
||||
OCIEnv *envh_;
|
||||
OCIError *errh_;
|
||||
|
||||
// OCI Descriptor array
|
||||
OCIDateTime **dbdatetime_;
|
||||
|
||||
};
|
||||
|
||||
};
|
|
@ -0,0 +1,99 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiEnv.cpp
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIENVIMPL_ORACLE
|
||||
# include <dpiEnvImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Constructor for the Env class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
Env::Env()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Destructor for the Env class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
Env::~Env()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Create the Env object.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
*/
|
||||
|
||||
Env * Env::createEnv()
|
||||
{
|
||||
return EnvImpl::createEnvImpl();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* end of file dpiEnv.cpp */
|
||||
|
|
@ -0,0 +1,659 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiEnvImpl.cpp - EnvImpl class implementation
|
||||
*
|
||||
* DESCRIPTION
|
||||
* This file implements the EnvImpl class which provides the implemenation of
|
||||
* the Env abstract class.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef ORATYPES
|
||||
# include <oratypes.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIENVIMPL_ORACLE
|
||||
# include <dpiEnvImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIPOOLIMPL_ORACLE
|
||||
# include <dpiPoolImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPICONNIMPL_ORACLE
|
||||
# include <dpiConnImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIEXCEPTIONIMPL_ORACLE
|
||||
# include <dpiExceptionImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIDATETIMEARRAYIMPL_ORACLE
|
||||
# include <dpiDateTimeArrayImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIUTILS_ORACLE
|
||||
# include <dpiUtils.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PRIVATE CONSTANTS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
static const int kPoolMax = 10;
|
||||
static const int kPoolMin = 1;
|
||||
static const int kPoolIncrement = 1;
|
||||
static const int kPoolTimeout = 120;
|
||||
static const int kStmtCacheSize = 60;
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Constructor for the EnvImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
EnvImpl::EnvImpl()
|
||||
|
||||
try : envh_(NULL), poolMax_(kPoolMax), poolMin_(kPoolMin),
|
||||
poolIncrement_(kPoolIncrement), poolTimeout_(kPoolTimeout),
|
||||
isExternalAuth_(false), stmtCacheSize_(kStmtCacheSize)
|
||||
{
|
||||
|
||||
sword rc = OCIEnvCreate (&envh_, OCI_THREADED, NULL, NULL, NULL,
|
||||
NULL, 0, NULL);
|
||||
if (rc)
|
||||
{
|
||||
if (envh_)
|
||||
ociCallEnv(rc, envh_);
|
||||
else
|
||||
throw ExceptionImpl(DpiErrNoEnv);
|
||||
}
|
||||
|
||||
DateTimeArrayImpl::initBaseDate ( envh_ ) ;
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
cleanup();
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Destructor for the EnvImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
EnvImpl::~EnvImpl()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Create the Env object.
|
||||
|
||||
PARAMETERS:
|
||||
envAttrs - environment attributes
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
*/
|
||||
|
||||
EnvImpl * EnvImpl::createEnvImpl()
|
||||
{
|
||||
return new EnvImpl();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Terminate the Env object.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::terminate()
|
||||
{
|
||||
EnvImpl::terminateEnvImpl(this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set the maximum pool size.
|
||||
|
||||
PARAMETERS:
|
||||
poolMax - maximum pool size
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::poolMax(unsigned int poolMax)
|
||||
{
|
||||
poolMax_ = poolMax;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get the maximum pool size.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
maximum pool size
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
unsigned int EnvImpl::poolMax() const
|
||||
{
|
||||
return poolMax_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set the minumum pool size.
|
||||
|
||||
PARAMETERS:
|
||||
poolMin - minimum pool size
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::poolMin(unsigned int poolMin)
|
||||
{
|
||||
poolMin_ = poolMin;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get the minimum pool size.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
mainimum pool size
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
unsigned int EnvImpl::poolMin() const
|
||||
{
|
||||
return poolMin_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set the pool increment.
|
||||
|
||||
PARAMETERS:
|
||||
poolIncrement - pool increment
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::poolIncrement(unsigned int poolIncrement)
|
||||
{
|
||||
poolIncrement_= poolIncrement;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get the pool increment.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
pool increment
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
unsigned int EnvImpl::poolIncrement() const
|
||||
{
|
||||
return poolIncrement_;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set the pool timeout.
|
||||
|
||||
PARAMETERS:
|
||||
poolTimeout - pool timeout
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::poolTimeout(unsigned int poolTimeout)
|
||||
{
|
||||
poolTimeout_ = poolTimeout;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get the pool timeout.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
pool timeout
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
unsigned int EnvImpl::poolTimeout() const
|
||||
{
|
||||
return poolTimeout_;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Specify external authentication.
|
||||
|
||||
PARAMETERS:
|
||||
isExternalAuth - true if using external authentication
|
||||
false if not useing external authentication
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::isExternalAuth(bool isExternalAuth)
|
||||
{
|
||||
isExternalAuth_ = isExternalAuth;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Is external authentication being used?
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
true if using external authentication
|
||||
false otherwise
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
bool EnvImpl::isExternalAuth() const
|
||||
{
|
||||
return isExternalAuth_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Specify EVENTS mode.
|
||||
|
||||
PARAMETERS:
|
||||
isEventEnabled - true if EVENTS mode enabled
|
||||
false if EVENTS mode not enabled
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
*/
|
||||
|
||||
void EnvImpl::isEventEnabled(bool isEventEnabled)
|
||||
{
|
||||
isEventEnabled_ = isEventEnabled;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Is EVENTS mode enabled?
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
true if EVENTS mode enabled
|
||||
false otherwise
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
bool EnvImpl::isEventEnabled() const
|
||||
{
|
||||
return isEventEnabled_;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Create the Pool object.
|
||||
|
||||
PARAMETERS:
|
||||
user - userid
|
||||
password - password
|
||||
connString - connect string
|
||||
poolMax - Max number of connections for session pool
|
||||
poolMin - Min number of connections for session pool
|
||||
poolIncrement - Increment count for session pool
|
||||
|
||||
RETURNS:
|
||||
created pool
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
SPool * EnvImpl::createPool(const string &user, const string &password,
|
||||
const string &connString,
|
||||
int poolMax, int poolMin, int poolIncrement,
|
||||
int poolTimeout, int stmtCacheSize)
|
||||
{
|
||||
return new PoolImpl(this, envh_, user, password, connString,
|
||||
(poolMax == -1) ? poolMax_ : poolMax,
|
||||
(poolMin == -1) ? poolMin_ : poolMin,
|
||||
(poolIncrement == -1) ? poolIncrement_ :
|
||||
poolIncrement,
|
||||
(poolTimeout == -1) ? poolTimeout_ :
|
||||
poolTimeout,
|
||||
isExternalAuth_,
|
||||
(stmtCacheSize == -1) ? stmtCacheSize_ :
|
||||
stmtCacheSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get connection.
|
||||
|
||||
PARAMETERS:
|
||||
user - userid
|
||||
password - password
|
||||
connString - connect string
|
||||
connAttrs - connection attributes
|
||||
|
||||
RETURNS:
|
||||
created connection
|
||||
*/
|
||||
|
||||
Conn * EnvImpl::getConnection(const string &user, const string &password,
|
||||
const string &connString,
|
||||
int stmtCacheSize)
|
||||
{
|
||||
return (Conn *)new ConnImpl(this, envh_, isExternalAuth_,
|
||||
(stmtCacheSize == -1) ? stmtCacheSize_ :
|
||||
stmtCacheSize,
|
||||
user, password,
|
||||
connString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Terminated the pool.
|
||||
|
||||
PARAMETERS:
|
||||
pool - connectionpool to be terminated.
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::terminatePool(PoolImpl *pool)
|
||||
{
|
||||
delete pool;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Release the connection.
|
||||
|
||||
PARAMETERS:
|
||||
conn - connection to be terminated.
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::releaseConnection(ConnImpl *conn)
|
||||
{
|
||||
delete conn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PRIVATE METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Terminated the Env object.
|
||||
|
||||
PARAMETERS:
|
||||
env - Env object to be terminated.
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::terminateEnvImpl(EnvImpl *env)
|
||||
{
|
||||
DateTimeArrayImpl::cleanBaseDate ();
|
||||
delete env;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Cleanup for the EnvImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void EnvImpl::cleanup()
|
||||
{
|
||||
if (envh_)
|
||||
{
|
||||
OCIHandleFree(envh_, OCI_HTYPE_ENV);
|
||||
envh_ = NULL; // reproducible seg-faults in case someone uses
|
||||
// a deleted Env
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/*
|
||||
NAME
|
||||
getDateTimeArray
|
||||
|
||||
DESCRIPTION
|
||||
To obtain an DPI class which represents date/timestamp as descriptor
|
||||
array
|
||||
|
||||
RETURNS:
|
||||
DateTimeArray * -
|
||||
|
||||
NOTE:
|
||||
DatetimeArray uses error object created in StmtImpl instead of creating
|
||||
separate one, this is ok, as the date/timestamp will be part of SQL
|
||||
statement execution only.
|
||||
*/
|
||||
DateTimeArray* EnvImpl::getDateTimeArray (OCIError *errh) const
|
||||
{
|
||||
return new DateTimeArrayImpl ( envh_, errh, this ) ;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/*
|
||||
NAME
|
||||
releaseDateTimeArray
|
||||
|
||||
DESCRIPTION
|
||||
To release datetimeArray object and related resources
|
||||
|
||||
RETURNS:
|
||||
NONE
|
||||
*/
|
||||
void EnvImpl::releaseDateTimeArray ( DateTimeArray *arr ) const
|
||||
{
|
||||
if ( arr )
|
||||
delete arr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* end of file dpiEnvImpl.cpp */
|
||||
|
|
@ -0,0 +1,134 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiEnvImpl.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIENVIMPL_ORACLE
|
||||
# define DPIENVIMPL_ORACLE
|
||||
|
||||
|
||||
#ifndef OCI_ORACLE
|
||||
# include <oci.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIENV_ORACLE
|
||||
# include <dpiEnv.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIPOOLIMPL_ORACLE
|
||||
# include <dpiPoolImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPICONNIMPL_ORACLE
|
||||
# include <dpiConnImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
using namespace dpi;
|
||||
|
||||
|
||||
class ConnImpl;
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
class EnvImpl : public Env
|
||||
{
|
||||
public:
|
||||
// creation/termination
|
||||
EnvImpl();
|
||||
|
||||
virtual ~EnvImpl();
|
||||
|
||||
static EnvImpl * createEnvImpl();
|
||||
|
||||
virtual void terminate();
|
||||
|
||||
// interface properties
|
||||
virtual void poolMax(unsigned int poolMax);
|
||||
virtual unsigned int poolMax() const;
|
||||
|
||||
virtual void poolMin(unsigned int poolMin);
|
||||
virtual unsigned int poolMin() const;
|
||||
|
||||
virtual void poolIncrement(unsigned int poolIncrement);
|
||||
virtual unsigned int poolIncrement() const;
|
||||
|
||||
virtual void poolTimeout(unsigned int poolTimeout);
|
||||
virtual unsigned int poolTimeout() const;
|
||||
|
||||
virtual void isExternalAuth(bool isExternalAuth);
|
||||
virtual bool isExternalAuth() const;
|
||||
|
||||
virtual void isEventEnabled(bool isEventEnabled);
|
||||
virtual bool isEventEnabled() const;
|
||||
|
||||
// interface methods
|
||||
virtual SPool * createPool(const string &user, const string &password,
|
||||
const string &connString,
|
||||
int poolMax = -1, int poolMin = -1,
|
||||
int poolIncrement = -1,
|
||||
int poolTimeout = -1,
|
||||
int stmtCacheSize = -1);
|
||||
|
||||
virtual Conn * getConnection(const string &user, const string &password,
|
||||
const string &connString, int stmtCacheSize);
|
||||
|
||||
// internal methods
|
||||
virtual void terminatePool(PoolImpl *pool);
|
||||
|
||||
virtual void releaseConnection(ConnImpl *conn);
|
||||
|
||||
// DateTime array.
|
||||
virtual DateTimeArray* getDateTimeArray ( OCIError *errh ) const ;
|
||||
virtual void releaseDateTimeArray ( DateTimeArray *arr ) const ;
|
||||
|
||||
private:
|
||||
|
||||
static void terminateEnvImpl(EnvImpl *env);
|
||||
|
||||
void cleanup();
|
||||
|
||||
OCIEnv *envh_; // OCI enviornment handle
|
||||
unsigned int poolMax_; // max pool size
|
||||
unsigned int poolMin_; // min pool size
|
||||
unsigned int poolIncrement_; // pool increment
|
||||
unsigned int poolTimeout_; // pool timeout
|
||||
|
||||
bool isExternalAuth_; // doing external authentication
|
||||
bool isEventEnabled_; // EVENTS are enabled
|
||||
|
||||
unsigned int stmtCacheSize_; // statement cache size
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* DPIENVIMPL_ORACLE */
|
|
@ -0,0 +1,63 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiException.cpp
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIEXCEPTION_ORACLE
|
||||
# include <dpiException.h>
|
||||
#endif
|
||||
|
||||
|
||||
using namespace dpi;
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Destructor for the Exception class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
*/
|
||||
|
||||
Exception::~Exception() throw ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* end of file dpiException.cpp */
|
||||
|
|
@ -0,0 +1,208 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiExceptionImpl.cpp - ExceptionImpl class implementation
|
||||
*
|
||||
* DESCRIPTION
|
||||
* This file implements the ExceptionImpl class which provides the
|
||||
* implemenation of the Exception abstract class.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#ifndef DPIEXCEPTIONIMPL_ORACLE
|
||||
# include <dpiExceptionImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PRIVATE DATA
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
static const char *dpiErrors[] =
|
||||
{
|
||||
"not an error", // DpiErrNoError
|
||||
"internal error", // DpiErrInternal
|
||||
"could not get OCI error message", // DpiErrUnkOciError
|
||||
"no OCI environment handle created" // DpiErrNoEnv
|
||||
"invalid state while working with timestamp" // DpiErrInvalidState
|
||||
"uninitialized state while working with timestamp" // DpiErrUninitialized
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Constructor for the ExceptionImpl class for DPI errors only.
|
||||
|
||||
PARAMETERS:
|
||||
errno - DPI error number
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
ExceptionImpl::ExceptionImpl(DpiError errno):
|
||||
origin_("DPI"), errno_(errno)
|
||||
{
|
||||
stringstream strstream;
|
||||
|
||||
strstream << origin_ << "-" <<setfill('0')<<setw(3)<<errno_ <<": ";
|
||||
strstream << dpiErrors[errno - DpiErrNoError];
|
||||
|
||||
message_ = strstream.str();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Constructor for the ExceptionImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
origin - error origin
|
||||
errno - error number
|
||||
message - error message
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
ExceptionImpl::ExceptionImpl(const char *origin, int errno,
|
||||
const char *message):
|
||||
origin_(origin), errno_(errno), message_(message)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Destructor for the ExceptionImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
ExceptionImpl::~ExceptionImpl() throw ()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Returns error message.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
Error message
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
const char * ExceptionImpl::what() const throw()
|
||||
{
|
||||
return message_.data();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Returns error number.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
Error number
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
int ExceptionImpl::errno() const throw()
|
||||
{
|
||||
return errno_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Returns the origin of the error
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
Error origin
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
const char * ExceptionImpl::origin() const throw()
|
||||
{
|
||||
return origin_.data();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* end of file dpiExceptionImpl.cpp */
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiExceptionImpl.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIEXCEPTIONIMPL_ORACLE
|
||||
# define DPIEXCEPTIONIMPL_ORACLE
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
#ifndef DPIEXCEPTION_ORACLE
|
||||
# include <dpiException.h>
|
||||
#endif
|
||||
|
||||
|
||||
using std::string;
|
||||
|
||||
using namespace dpi;
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
class ExceptionImpl : public Exception
|
||||
{
|
||||
public:
|
||||
// creation/termination
|
||||
ExceptionImpl(DpiError errno);
|
||||
|
||||
ExceptionImpl(const char *origin, int errno, const char *message);
|
||||
|
||||
virtual ~ExceptionImpl() throw();
|
||||
|
||||
virtual const char * what() const throw();
|
||||
|
||||
virtual int errno() const throw();
|
||||
|
||||
virtual const char * origin() const throw();
|
||||
|
||||
private:
|
||||
string origin_;
|
||||
int errno_;
|
||||
string message_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* DPIEXCEPTIONIMPL_ORACLE */
|
|
@ -0,0 +1,369 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiPoolImpl.cpp - PoolImpl class implementation
|
||||
*
|
||||
* DESCRIPTION
|
||||
* This file implements the PoolImpl class which provides the implemenation
|
||||
* of the Pool abstract class.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
#ifndef ORATYPES
|
||||
# include <oratypes.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIENVIMPL_ORACLE
|
||||
# include <dpiEnvImpl.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPIPOOLIMPL_ORACLE
|
||||
# include <dpiPoolImpl.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPICONNIMPL_ORACLE
|
||||
# include <dpiConnImpl.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPIUTILS_ORACLE
|
||||
# include <dpiUtils.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPIEXCEPTIONIMPL_ORACLE
|
||||
# include <dpiExceptionImpl.h>
|
||||
#endif
|
||||
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Constructor for the PoolImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
env - parent Environment object
|
||||
envh - OCI envh
|
||||
user - userid
|
||||
password - password
|
||||
connString - connect string
|
||||
poolMax - maximum pool size
|
||||
poolMin - minimum pool size
|
||||
poolIncrement - pool increment
|
||||
poolTimeout - pool timeout
|
||||
stmtCacheSize - statement cache size
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
PoolImpl::PoolImpl(EnvImpl *env, OCIEnv *envh,
|
||||
const string &user, const string &password,
|
||||
const string &connString, int poolMax,
|
||||
int poolMin, int poolIncrement,
|
||||
int poolTimeout, bool isExternalAuth, int stmtCacheSize)
|
||||
try : env_(env), isExternalAuth_(isExternalAuth), envh_(envh), errh_(NULL),
|
||||
spoolh_(NULL), poolName_(NULL)
|
||||
{
|
||||
unsigned int spoolMode = OCI_SPOOL_ATTRVAL_NOWAIT;
|
||||
|
||||
ociCallEnv(OCIHandleAlloc((void *)envh_, (dvoid **)&errh_,
|
||||
OCI_HTYPE_ERROR, 0, (dvoid **)0), envh_);
|
||||
|
||||
ociCall(OCIHandleAlloc((void *)envh_, (dvoid **)&spoolh_,
|
||||
OCI_HTYPE_SPOOL, 0, (dvoid **)0), errh_);
|
||||
|
||||
ociCall(OCISessionPoolCreate(envh_, errh_, spoolh_,
|
||||
&poolName_, &poolNameLen_,
|
||||
(OraText *)connString.data (),
|
||||
connString.length(),
|
||||
poolMin, poolMax,
|
||||
poolIncrement,
|
||||
(OraText *)user.data (), user.length(),
|
||||
(OraText *)password.data (),
|
||||
password.length(),
|
||||
OCI_SPC_HOMOGENEOUS), errh_ );
|
||||
|
||||
this->poolTimeout(poolTimeout);
|
||||
this->stmtCacheSize(stmtCacheSize);
|
||||
|
||||
/* In case of no free connections available, report error */
|
||||
ociCall (OCIAttrSet (spoolh_, OCI_HTYPE_SPOOL, &spoolMode,
|
||||
sizeof (spoolMode), OCI_ATTR_SPOOL_GETMODE, errh_ ),
|
||||
errh_ ) ;
|
||||
}
|
||||
|
||||
catch (...)
|
||||
{
|
||||
cleanup();
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Destructor for the PoolImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
PoolImpl::~PoolImpl()
|
||||
{
|
||||
cleanup();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Terminate the Pool object.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void PoolImpl::terminate()
|
||||
{
|
||||
env_->terminatePool(this);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set the pool timeout.
|
||||
|
||||
PARAMETERS:
|
||||
poolTimeout - pool timeout
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void PoolImpl::poolTimeout(unsigned int poolTimeout)
|
||||
{
|
||||
ociCall(OCIAttrSet(spoolh_, OCI_HTYPE_SPOOL, &poolTimeout, 0,
|
||||
OCI_ATTR_SPOOL_TIMEOUT, errh_), errh_);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set statement cache size.
|
||||
|
||||
PARAMETERS:
|
||||
stmtCacheSize - statement cache size
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void PoolImpl::stmtCacheSize(unsigned int stmtCacheSize)
|
||||
{
|
||||
ociCall(OCIAttrSet(spoolh_, OCI_HTYPE_SPOOL, &stmtCacheSize, 0,
|
||||
OCI_ATTR_SPOOL_STMTCACHESIZE, errh_), errh_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get the number of currently open connections.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
number of currently open connections
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
unsigned int PoolImpl::connectionsOpen() const
|
||||
{
|
||||
ub4 openConnections = 0;
|
||||
|
||||
ociCall(OCIAttrGet(spoolh_, OCI_HTYPE_SPOOL, &openConnections, 0,
|
||||
OCI_ATTR_SPOOL_OPEN_COUNT, errh_), errh_);
|
||||
return openConnections;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get the number of currently in use (checked-out) connections.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
number of currently in use (checked-out) connections
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
unsigned int PoolImpl::connectionsInUse() const
|
||||
{
|
||||
ub4 inUse = 0;
|
||||
|
||||
ociCall(OCIAttrGet(spoolh_, OCI_HTYPE_SPOOL, &inUse, 0,
|
||||
OCI_ATTR_SPOOL_BUSY_COUNT, errh_), errh_);
|
||||
return inUse;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get connection.
|
||||
|
||||
PARAMETERS:
|
||||
connectionClass - connection class.
|
||||
If specified as empty string, then no connection class
|
||||
|
||||
RETURNS:
|
||||
created connection
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
Conn * PoolImpl::getConnection ()
|
||||
{
|
||||
Conn *conn = new ConnImpl(this, envh_, isExternalAuth_,
|
||||
poolName_, poolNameLen_
|
||||
);
|
||||
return conn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Release the connection.
|
||||
|
||||
PARAMETERS:
|
||||
conn - connection to be release.
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void PoolImpl::releaseConnection(ConnImpl *conn)
|
||||
{
|
||||
delete conn;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PRIVATE METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Cleanup for the PoolImpl class.
|
||||
|
||||
PARAMETERS:
|
||||
none
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
The free OCI handles are set to NULL to so that in case someone tries to
|
||||
use a released Pool handle, they will get a reproducible seg-fault.
|
||||
*/
|
||||
|
||||
void PoolImpl::cleanup()
|
||||
{
|
||||
|
||||
if (poolName_)
|
||||
{
|
||||
ociCall( OCISessionPoolDestroy( spoolh_, errh_, OCI_DEFAULT), errh_);
|
||||
poolName_ = NULL;
|
||||
}
|
||||
|
||||
if (spoolh_)
|
||||
{
|
||||
OCIHandleFree ( errh_, OCI_HTYPE_SPOOL);
|
||||
spoolh_ = NULL;
|
||||
}
|
||||
|
||||
if (errh_)
|
||||
{
|
||||
OCIHandleFree ( errh_, OCI_HTYPE_ERROR );
|
||||
errh_ = NULL ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* end of file dpiPoolImpl.cpp */
|
||||
|
|
@ -0,0 +1,99 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiPoolImpl.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIPOOLIMPL_ORACLE
|
||||
# define DPIPOOLIMPL_ORACLE
|
||||
|
||||
|
||||
#ifndef DPIPOOL_ORACLE
|
||||
# include <dpiPool.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIENVIMPL_ORACLE
|
||||
# include <dpiEnvImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPICONNIMPL_ORACLE
|
||||
# include <dpiConnImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
using namespace dpi;
|
||||
|
||||
|
||||
class EnvImpl;
|
||||
class ConnImpl;
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
class PoolImpl : public SPool
|
||||
{
|
||||
public:
|
||||
|
||||
// creation/termination
|
||||
PoolImpl(EnvImpl *env, OCIEnv *envh,
|
||||
const string &user, const string &password,
|
||||
const string &connString,
|
||||
int poolMax, int poolMin, int poolIncrement, int poolTimeout,
|
||||
bool isExternalAuth, int stmtCacheSize);
|
||||
|
||||
virtual ~PoolImpl();
|
||||
|
||||
virtual void terminate();
|
||||
|
||||
// interface properties
|
||||
virtual void poolTimeout( unsigned int poolTimeout);
|
||||
virtual void stmtCacheSize( unsigned int stmtCacheSize );
|
||||
virtual unsigned int connectionsOpen() const;
|
||||
virtual unsigned int connectionsInUse() const;
|
||||
|
||||
// interface methods
|
||||
virtual Conn * getConnection();
|
||||
|
||||
// internal methods
|
||||
virtual void releaseConnection(ConnImpl *conn);
|
||||
|
||||
private:
|
||||
|
||||
void cleanup();
|
||||
|
||||
EnvImpl *env_; // parent Env object
|
||||
bool isExternalAuth_; // doing external authentication
|
||||
OCIEnv *envh_; // OCI enviornment handle
|
||||
OCIError *errh_; // OCI error handle
|
||||
OCISPool *spoolh_; // OCI session pool handle
|
||||
OraText *poolName_; // pool name
|
||||
ub4 poolNameLen_; // pool name length
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* DPIPOOLIMPL_ORACLE */
|
|
@ -0,0 +1,501 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiConnImpl.cpp - ConnImpl class implementation
|
||||
*
|
||||
* DESCRIPTION
|
||||
* This file implements the ConnImpl class which provides the implemenation
|
||||
* of the Conn abstract class.
|
||||
*
|
||||
* NOTES
|
||||
* DPI layer encapsulating OCIStmt object to allow multiple parallel sql
|
||||
* execution from same connection to go through. Each dpiStmtImpl will have
|
||||
* its own OCIError object and this will be destroyed at the end of execution
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef ORATYPES
|
||||
# include <oratypes.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPISTMTIMPL_ORACLE
|
||||
# include <dpiStmtImpl.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPICONNIMPL_ORACLE
|
||||
# include <dpiConnImpl.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPIDATETIMEARRAYIMPL_ORACLE
|
||||
#include <dpiDateTimeArrayImpl.h>
|
||||
#endif
|
||||
|
||||
#ifndef DPIUTILS_ORACLE
|
||||
# include <dpiUtils.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Constructor for StmtImpl class created by Connection object.
|
||||
|
||||
PARAMETERS:
|
||||
env - global env object
|
||||
envh - OCIEnv handle
|
||||
conn - parent connImpl object
|
||||
svch - OCISvcCtx handle
|
||||
sql - sql statement to execute
|
||||
|
||||
RETURN
|
||||
-NONE-
|
||||
|
||||
NOTE:
|
||||
wrapper of OCIStmt handle to allow multiple executions to go through
|
||||
single connection parent object from multiple thread(s).
|
||||
Each StmtImpl creates and uses OCIError handle and this will be destroyed
|
||||
at the end of the execution.
|
||||
# of parallel threads can be configured at nodejs level.
|
||||
*/
|
||||
StmtImpl::StmtImpl (EnvImpl *env, OCIEnv *envh, ConnImpl *conn,
|
||||
OCISvcCtx *svch, const string &sql)
|
||||
|
||||
try : conn_(conn), errh_(NULL), svch_(svch),
|
||||
stmth_(NULL), numCols_ (0),meta_(NULL)
|
||||
|
||||
{
|
||||
// create an OCIError object for this execution
|
||||
ociCallEnv (OCIHandleAlloc ((void *)envh, (dvoid **)&errh_,
|
||||
OCI_HTYPE_ERROR, 0, (dvoid **)0), envh);
|
||||
|
||||
// Prepare OCIStmt object with given sql statement.
|
||||
ociCall (OCIStmtPrepare2 (svch_, &stmth_, errh_, (oratext *)sql.data(),
|
||||
sql.length(), NULL, 0, OCI_NTV_SYNTAX, OCI_DEFAULT),
|
||||
errh_);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cleanup ();
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Destructor for the StmtImpl class.
|
||||
|
||||
PARAMETERS
|
||||
-NONE-
|
||||
|
||||
RETURNS:
|
||||
-NONE_
|
||||
|
||||
*/
|
||||
StmtImpl::~StmtImpl ()
|
||||
{
|
||||
cleanup ();
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Statement type
|
||||
|
||||
PARAMETERS
|
||||
-NONE_
|
||||
|
||||
RETURNS
|
||||
DpiStmtType enum
|
||||
*/
|
||||
DpiStmtType StmtImpl::stmtType () const
|
||||
{
|
||||
ub2 stmtType ;
|
||||
|
||||
ociCall (OCIAttrGet (stmth_, OCI_HTYPE_STMT, &stmtType, NULL,
|
||||
OCI_ATTR_STMT_TYPE, errh_), errh_);
|
||||
|
||||
return (DpiStmtType)stmtType;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get the numbers of rows affected by the DML operation.
|
||||
|
||||
PARAMETERS
|
||||
-None-
|
||||
|
||||
RETURNS:
|
||||
number of rows affected by the DML operation
|
||||
|
||||
*/
|
||||
unsigned long StmtImpl::rowsAffected () const
|
||||
{
|
||||
DPI_SZ_TYPE rowsAffected = 0;
|
||||
|
||||
ociCall (OCIAttrGet (stmth_, OCI_HTYPE_STMT, &rowsAffected, NULL,
|
||||
DPIATTRROWCOUNT, errh_), errh_);
|
||||
|
||||
return rowsAffected;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Number of columns that will be returned by this statement execution
|
||||
|
||||
PARAMETERS
|
||||
-NONE-
|
||||
|
||||
RETURNS
|
||||
# of columns
|
||||
|
||||
*/
|
||||
unsigned int StmtImpl::numCols ()
|
||||
{
|
||||
if (numCols_)
|
||||
return numCols_;
|
||||
|
||||
ociCall (OCIAttrGet (stmth_, OCI_HTYPE_STMT, &numCols_, 0,
|
||||
OCI_ATTR_PARAM_COUNT, errh_), errh_);
|
||||
|
||||
return numCols_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
bind the variable(s) by pdpition
|
||||
|
||||
PARAMETERS
|
||||
pos - pdpition of the variable 1 based
|
||||
type - Data type
|
||||
buf (IN/OUT) - data buffer for the variable's value
|
||||
bufSize - size of the buffer
|
||||
ind (OUT) - indicator
|
||||
bufLen (OUT) - size of data reutnred
|
||||
|
||||
RETURNS
|
||||
-NONE-
|
||||
*/
|
||||
void StmtImpl::bind (unsigned int pos, unsigned short type, void *buf,
|
||||
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen)
|
||||
{
|
||||
OCIBind *b = (OCIBind *)0;
|
||||
|
||||
ociCall (DPIBINDBYPOS (stmth_, &b, errh_, pos, buf, bufSize, type, ind,
|
||||
bufLen, NULL, 0, NULL, OCI_DEFAULT),
|
||||
errh_);
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Bind the variable by name
|
||||
|
||||
PARAMETERS
|
||||
name - name of the variable
|
||||
nameLen - len of name.
|
||||
type - data type
|
||||
buf (IN/OUT) - data buffer for value
|
||||
bufSize - size of buffer
|
||||
ind - indicator
|
||||
bufLen - returned buffer size
|
||||
*/
|
||||
void StmtImpl::bind (const unsigned char *name, int nameLen,
|
||||
unsigned short type, void *buf, DPI_SZ_TYPE bufSize,
|
||||
short *ind, DPI_BUFLEN_TYPE *bufLen)
|
||||
{
|
||||
OCIBind *b = (OCIBind *)0;
|
||||
|
||||
ociCall (DPIBINDBYNAME (stmth_, &b, errh_, name, nameLen,
|
||||
buf, bufSize, type, ind, bufLen,
|
||||
NULL, 0, NULL, OCI_DEFAULT), errh_);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Execute the DML statement.
|
||||
|
||||
PARAMETERS
|
||||
isAutoCommit - true/false - autocommit enabled or not
|
||||
|
||||
RETURNS:
|
||||
-None-
|
||||
*/
|
||||
void StmtImpl::executeDML (bool isAutoCommit )
|
||||
{
|
||||
executeMany ( 1 , isAutoCommit ); // Use execute Many special case only one iteration.
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Execute the DML statement multiple times.
|
||||
|
||||
PARAMETERS:
|
||||
numIterations - number of times to execute
|
||||
isAutoCommit - true/false - autocommit enabled or not
|
||||
|
||||
RETURNS
|
||||
-None-
|
||||
*/
|
||||
void StmtImpl::executeMany (int numIterations, bool isAutoCommit )
|
||||
{
|
||||
ub4 mode = isAutoCommit ? OCI_COMMIT_ON_SUCCESS : OCI_DEFAULT ;
|
||||
|
||||
ociCall (OCIStmtExecute (svch_, stmth_, errh_, (ub4)numIterations, (ub4)0,
|
||||
(OCISnapshot *)NULL, (OCISnapshot *)NULL, mode),
|
||||
errh_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Execute the SELECT statement
|
||||
|
||||
PARAMETERS
|
||||
-None-
|
||||
|
||||
RETURNS:
|
||||
-None-
|
||||
*/
|
||||
void StmtImpl::executeQuery ()
|
||||
{
|
||||
ociCall (OCIStmtExecute (svch_, stmth_, errh_, 0, (ub4)0,
|
||||
(OCISnapshot *)NULL, (OCISnapshot *)NULL,
|
||||
OCI_DEFAULT), errh_);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Release the SQL statement
|
||||
|
||||
PARAMETERS
|
||||
-None-
|
||||
|
||||
RETURNS
|
||||
-None-
|
||||
*/
|
||||
void StmtImpl::release ()
|
||||
{
|
||||
conn_->releaseStmt ( this ) ;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Define the variable by pdpition
|
||||
|
||||
PARAMETERS
|
||||
pos - pdpition of the variable
|
||||
type - data type
|
||||
buf - data buffer for the value
|
||||
bufSize - size of the buffer
|
||||
ind - indicator
|
||||
bufLen - returned buffer size
|
||||
|
||||
RETURNS
|
||||
-None-
|
||||
*/
|
||||
void StmtImpl::define (unsigned int pos, unsigned short type, void *buf,
|
||||
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen)
|
||||
{
|
||||
OCIDefine *d = (OCIDefine *)0;
|
||||
ociCall (DPIDEFINEBYPOS (stmth_, &d, errh_, pos, buf, bufSize, type,
|
||||
(void *)ind, bufLen, NULL,
|
||||
OCI_DEFAULT),
|
||||
errh_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Fetch specified number of rows
|
||||
|
||||
PARAMETERS
|
||||
numRows - number of Rows to fetch
|
||||
|
||||
RETURNS
|
||||
-None-
|
||||
*/
|
||||
void StmtImpl::fetch (unsigned int numRows)
|
||||
{
|
||||
sword rc = OCIStmtFetch2 (stmth_, errh_, numRows, OCI_FETCH_NEXT, 0,
|
||||
OCI_DEFAULT);
|
||||
|
||||
if ( rc && rc != OCI_NO_DATA )
|
||||
{
|
||||
ociCall ( rc, errh_);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
To obtain number of rows fetched in the last fetch call
|
||||
|
||||
PARAMETERS
|
||||
-NONE-
|
||||
|
||||
RETURNS
|
||||
unsigned int - # of rows fetched.
|
||||
*/
|
||||
unsigned int StmtImpl::rowsFetched () const
|
||||
{
|
||||
unsigned int rowsFetched = 0 ;
|
||||
|
||||
ociCall (OCIAttrGet (stmth_, OCI_HTYPE_STMT, &rowsFetched,
|
||||
0, OCI_ATTR_ROWS_FETCHED, errh_), errh_);
|
||||
|
||||
return rowsFetched;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
obtains column meta data
|
||||
|
||||
PARAMETERS
|
||||
-None-
|
||||
|
||||
RETURNS
|
||||
-None-
|
||||
*/
|
||||
const MetaData* StmtImpl::getMetaData ()
|
||||
{
|
||||
numCols();
|
||||
|
||||
if (!numCols_)
|
||||
return NULL;
|
||||
|
||||
ub4 col = 0;
|
||||
OCIParam *colDesc = (OCIParam *) 0;
|
||||
|
||||
meta_ = new MetaData[numCols_];
|
||||
|
||||
while (col < numCols_)
|
||||
{
|
||||
ociCall(OCIParamGet((void *)stmth_, OCI_HTYPE_STMT, errh_,
|
||||
(void **)&colDesc, (ub4) (col+1)), errh_ );
|
||||
ociCall(OCIAttrGet((void*) colDesc, (ub4) OCI_DTYPE_PARAM,
|
||||
(void**) &(meta_[col].colName),
|
||||
(ub4 *) &(meta_[col].colNameLen),
|
||||
(ub4) OCI_ATTR_NAME,errh_ ), errh_ );
|
||||
ociCall(OCIAttrGet((void*) colDesc, (ub4) OCI_DTYPE_PARAM,
|
||||
(void*) &(meta_[col].dbType),(ub4 *) 0,
|
||||
(ub4) OCI_ATTR_DATA_TYPE,
|
||||
errh_ ), errh_ );
|
||||
ociCall(OCIAttrGet((void*) colDesc, (ub4) OCI_DTYPE_PARAM,
|
||||
(void*) &(meta_[col].dbSize),(ub4 *) 0,
|
||||
(ub4) OCI_ATTR_DATA_SIZE,
|
||||
errh_ ), errh_ );
|
||||
ociCall(OCIAttrGet((void*) colDesc, (ub4) OCI_DTYPE_PARAM,
|
||||
(void*) &(meta_[col].isNullable),(ub4*) 0,
|
||||
(ub4) OCI_ATTR_IS_NULL,
|
||||
errh_ ), errh_ );
|
||||
if (meta_[col].dbType == DpiNumber || meta_[col].dbType == DpiBinaryFloat
|
||||
||meta_[col].dbType == DpiBinaryDouble )
|
||||
{
|
||||
ociCall(OCIAttrGet((void*) colDesc, (ub4) OCI_DTYPE_PARAM,
|
||||
(void*) &(meta_[col].precision),(ub4* ) 0,
|
||||
(ub4) OCI_ATTR_PRECISION,
|
||||
errh_ ), errh_ );
|
||||
ociCall(OCIAttrGet((void*) colDesc, (ub4) OCI_DTYPE_PARAM,
|
||||
(void*) &(meta_[col].scale),(ub4*) 0,
|
||||
(ub4) OCI_ATTR_SCALE,
|
||||
errh_ ), errh_ );
|
||||
}
|
||||
OCIDescriptorFree( colDesc, OCI_DTYPE_PARAM);
|
||||
col++;
|
||||
}
|
||||
|
||||
return meta_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PRIVATE METHODS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Cleanup routine for the StmtImpl class.
|
||||
|
||||
PARAMETERS
|
||||
-NONE_
|
||||
|
||||
RETURNS
|
||||
void
|
||||
*/
|
||||
void StmtImpl::cleanup ()
|
||||
{
|
||||
if(meta_)
|
||||
{
|
||||
delete [] meta_;
|
||||
meta_ = NULL;
|
||||
}
|
||||
if ( stmth_)
|
||||
{
|
||||
ociCall ( OCIStmtRelease (stmth_, errh_, NULL, 0, OCI_DEFAULT), errh_ );
|
||||
stmth_ = NULL;
|
||||
}
|
||||
if ( errh_)
|
||||
{
|
||||
OCIHandleFree (errh_, OCI_HTYPE_ERROR);
|
||||
errh_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* end of file dpiStmtImpl.cpp */
|
|
@ -0,0 +1,101 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiStmtImpl.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPISTMTIMPL_ORACLE
|
||||
# define DPISTMTIMPL_ORACLE
|
||||
|
||||
#ifndef DPISTMT_ORACLE
|
||||
# include <dpiStmt.h>
|
||||
#endif
|
||||
|
||||
#ifndef OCI_ORACLE
|
||||
# include <oci.h>
|
||||
#endif
|
||||
|
||||
|
||||
using namespace dpi;
|
||||
|
||||
|
||||
class EnvImpl;
|
||||
class ConnImpl;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
class StmtImpl : public Stmt
|
||||
{
|
||||
public:
|
||||
// Constructor & Destructor
|
||||
StmtImpl (EnvImpl *env, OCIEnv *envh, ConnImpl *conn, OCISvcCtx *svch,
|
||||
const string &sql);
|
||||
virtual ~StmtImpl ();
|
||||
|
||||
// Attributes
|
||||
virtual DpiStmtType stmtType () const;
|
||||
virtual unsigned long rowsAffected () const;
|
||||
virtual unsigned int numCols() ;
|
||||
virtual unsigned int rowsFetched () const ;
|
||||
|
||||
// Methods
|
||||
virtual void release ();
|
||||
|
||||
virtual void bind (unsigned int pos, unsigned short type, void *buf,
|
||||
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen ) ;
|
||||
virtual void bind (const unsigned char *name, int nameLen,
|
||||
unsigned short type, void *buf, DPI_SZ_TYPE bufSize, short *ind,
|
||||
DPI_BUFLEN_TYPE *bufLen);
|
||||
|
||||
virtual void executeDML ( bool isAutoCommit );
|
||||
virtual void executeMany (int numIterations, bool isAutoCommit );
|
||||
virtual void executeQuery ();
|
||||
|
||||
virtual void define (unsigned int pos, unsigned short type, void *buf,
|
||||
DPI_SZ_TYPE bufSize, short *ind, DPI_BUFLEN_TYPE *bufLen);
|
||||
virtual void fetch (unsigned int numRows = 1);
|
||||
|
||||
virtual const MetaData *getMetaData ();
|
||||
|
||||
virtual OCIError * getError () { return errh_; }
|
||||
|
||||
private:
|
||||
void cleanup ();
|
||||
|
||||
|
||||
private:
|
||||
// DPI objects
|
||||
ConnImpl *conn_; // parent Connection object
|
||||
|
||||
// OCI Objects
|
||||
OCIError *errh_; // OCI Error object for this stmt execution
|
||||
OCISvcCtx *svch_; // OCI service handle
|
||||
OCIStmt *stmth_; // OCI Stmt handle
|
||||
|
||||
unsigned int numCols_; // # of cols this stmt execution will return
|
||||
MetaData *meta_; // Meta data array
|
||||
};
|
||||
|
||||
|
||||
#endif /* DPISTMTIMPL_ORACLE */
|
|
@ -0,0 +1,124 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiUtils.cpp - ConnImpl class implementation
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifndef DPIUTILS_ORACLE
|
||||
# include <dpiUtils.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef DPIEXCEPTIONIMPL_ORACLE
|
||||
# include <dpiExceptionImpl.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC FUNCTIONS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
This routine retrives the error information from the OCI error handle and
|
||||
throws ExceptionImpl with the information contained in the error handle.
|
||||
|
||||
PARAMETERS:
|
||||
rc - OCI return code
|
||||
errh - OCI error hanlde
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
*/
|
||||
|
||||
void ociCall(sword rc, OCIError *errh)
|
||||
{
|
||||
if (!rc)
|
||||
return;
|
||||
|
||||
OraText ociErrorMsg[OCI_ERROR_MAXMSG_SIZE];
|
||||
sb4 ociErrorNo = 0;
|
||||
memset(ociErrorMsg, 0, OCI_ERROR_MAXMSG_SIZE);
|
||||
|
||||
rc = OCIErrorGet(errh, 1, NULL, &ociErrorNo, ociErrorMsg,
|
||||
OCI_ERROR_MAXMSG_SIZE-1, OCI_HTYPE_ERROR);
|
||||
if (rc)
|
||||
throw ExceptionImpl(DpiErrUnkOciError);
|
||||
else
|
||||
{
|
||||
ociErrorMsg[strlen((char*)ociErrorMsg)-1]=0; //strip off newline
|
||||
throw ExceptionImpl("ORA", ociErrorNo, (const char *)ociErrorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
This routine retrives the error information from the OCI environment
|
||||
handle and throws ExceptionImpl with the information contained in the
|
||||
error handle.
|
||||
|
||||
PARAMETERS:
|
||||
rc - OCI return code
|
||||
envh - OCI environment hanlde
|
||||
|
||||
RETURNS:
|
||||
nothing
|
||||
|
||||
NOTES:
|
||||
|
||||
*/
|
||||
|
||||
void ociCallEnv(sword rc, OCIEnv *envh)
|
||||
{
|
||||
if (!rc)
|
||||
return;
|
||||
|
||||
OraText ociErrorMsg[OCI_ERROR_MAXMSG_SIZE];
|
||||
sb4 ociErrorNo = 0;
|
||||
memset(ociErrorMsg, 0, OCI_ERROR_MAXMSG_SIZE);
|
||||
|
||||
rc = OCIErrorGet(envh, 1, NULL, &ociErrorNo, ociErrorMsg,
|
||||
OCI_ERROR_MAXMSG_SIZE-1, OCI_HTYPE_ENV);
|
||||
if (rc)
|
||||
throw ExceptionImpl(DpiErrUnkOciError);
|
||||
else
|
||||
{
|
||||
ociErrorMsg[strlen((char*)ociErrorMsg)-1]=0; //strip off newline
|
||||
throw ExceptionImpl("ORA", ociErrorNo, (const char *)ociErrorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* end of file dpiUtils.cpp */
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* dpiUtils.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef DPIUTILS_ORACLE
|
||||
# define DPIUTILS_ORACLE
|
||||
|
||||
|
||||
#ifndef OCI_ORACLE
|
||||
# include <oci.h>
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC CONSTANTS AND MACROS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
#define TBSIZE(textBuffer) (sizeof(textBuffer) - 1)
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC TYPES
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------
|
||||
PUBLIC FUNCTIONS
|
||||
---------------------------------------------------------------------------*/
|
||||
|
||||
void ociCall(sword rc, OCIError *errh);
|
||||
|
||||
void ociCallEnv(sword rc, OCIEnv *envh);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* DPIUTILS_ORACLE */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,240 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* njsConnection.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Connection class
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __NJSCONNECTION_H__
|
||||
#define __NJSCONNECTION_H__
|
||||
|
||||
#include <node.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "dpi.h"
|
||||
#include "njsUtils.h"
|
||||
#include "njsOracle.h"
|
||||
|
||||
using namespace v8;
|
||||
using namespace node;
|
||||
using namespace dpi;
|
||||
|
||||
/**
|
||||
* Structure used for binds
|
||||
**/
|
||||
typedef struct Bind
|
||||
{
|
||||
std::string key;
|
||||
void* value;
|
||||
void* extvalue;
|
||||
DPI_BUFLEN_TYPE len;
|
||||
DPI_SZ_TYPE maxSize;
|
||||
unsigned short type;
|
||||
short ind;
|
||||
bool isOut;
|
||||
dpi::DateTimeArray *dttmarr;
|
||||
|
||||
Bind () : key(""), value(NULL), extvalue (NULL), len(0), maxSize(0),
|
||||
type(0), ind(0), isOut(false), dttmarr ( NULL )
|
||||
{}
|
||||
}Bind;
|
||||
|
||||
/**
|
||||
* Structure used for Query result
|
||||
**/
|
||||
typedef struct Define
|
||||
{
|
||||
|
||||
unsigned short fetchType;
|
||||
DPI_SZ_TYPE maxSize;
|
||||
void *buf; // will have the values from DB
|
||||
void *extbuf; // this field will be DPI calls
|
||||
DPI_BUFLEN_TYPE *len;
|
||||
short *ind;
|
||||
dpi::DateTimeArray *dttmarr; // DPI Date time array of descriptor
|
||||
|
||||
Define () :fetchType(0), maxSize(0), buf(NULL), extbuf(NULL),
|
||||
len(0), ind(0), dttmarr(NULL)
|
||||
{}
|
||||
} Define;
|
||||
|
||||
/**
|
||||
* Baton for Asynchronous Connection methods
|
||||
**/
|
||||
typedef struct eBaton
|
||||
{
|
||||
uv_work_t req;
|
||||
std::string sql;
|
||||
std::string error;
|
||||
dpi::Env* dpienv;
|
||||
dpi::Conn* dpiconn;
|
||||
unsigned int rowsAffected;
|
||||
unsigned int maxRows;
|
||||
bool isAutoCommit;
|
||||
unsigned int rowsFetched;
|
||||
unsigned int outFormat;
|
||||
unsigned int numCols;
|
||||
dpi::Stmt *dpistmt;
|
||||
dpi::DpiStmtType st;
|
||||
std::vector<Bind*> binds;
|
||||
std::string *columnNames;
|
||||
Define *defines;
|
||||
Persistent<Function> cb;
|
||||
|
||||
eBaton() : sql(""), error(""), dpienv(NULL), dpiconn(NULL),
|
||||
rowsAffected(0), maxRows(0), isAutoCommit(false),
|
||||
rowsFetched(0), outFormat(0), numCols(0), dpistmt(NULL),
|
||||
st(DpiStmtUnknown), columnNames(NULL), defines(NULL)
|
||||
{}
|
||||
|
||||
~eBaton ()
|
||||
{
|
||||
cb.Dispose();
|
||||
if( !binds.empty() )
|
||||
{
|
||||
for( unsigned int index = 0 ;index < binds.size(); index++ )
|
||||
{
|
||||
// donot free date value here, it is done in DateTimeArray functions
|
||||
if(binds[index]->type != DpiTimestampLTZ )
|
||||
{
|
||||
if( binds[index]->value )
|
||||
{
|
||||
free(binds[index]->value);
|
||||
}
|
||||
if ( binds[index]->extvalue )
|
||||
{
|
||||
free ( binds[index]->value );
|
||||
}
|
||||
}
|
||||
delete binds[index];
|
||||
}
|
||||
}
|
||||
if( columnNames )
|
||||
delete [] columnNames;
|
||||
if( defines )
|
||||
{
|
||||
for( unsigned int i=0; i<numCols; i++ )
|
||||
{
|
||||
free(defines[i].buf);
|
||||
free(defines[i].len);
|
||||
free(defines[i].ind);
|
||||
}
|
||||
delete [] defines;
|
||||
}
|
||||
}
|
||||
}eBaton;
|
||||
|
||||
class Connection: public ObjectWrap
|
||||
{
|
||||
public:
|
||||
|
||||
void setConnection (dpi::Conn*, Oracledb* oracledb);
|
||||
// Define Connection Constructor
|
||||
static Persistent<FunctionTemplate> connectionTemplate_s;
|
||||
static void Init (Handle<Object> target);
|
||||
|
||||
private:
|
||||
static Handle<Value> New (const Arguments& args);
|
||||
|
||||
// Execute Method on Connection class
|
||||
static Handle<Value> Execute (const Arguments& args);
|
||||
static void Async_Execute (uv_work_t *req);
|
||||
static void Async_AfterExecute (uv_work_t *req);
|
||||
|
||||
// Release Method on Connection class
|
||||
static Handle<Value> Release (const Arguments& args);
|
||||
static void Async_Release (uv_work_t *req);
|
||||
static void Async_AfterRelease (uv_work_t *req);
|
||||
|
||||
// Commit Method on Connection class
|
||||
static Handle<Value> Commit (const Arguments& args);
|
||||
static void Async_Commit (uv_work_t *req);
|
||||
static void Async_AfterCommit (uv_work_t *req);
|
||||
|
||||
// Rollback Method on Connection class
|
||||
static Handle<Value> Rollback (const Arguments& args);
|
||||
static void Async_Rollback (uv_work_t *req);
|
||||
static void Async_AfterRollback (uv_work_t *req);
|
||||
|
||||
// BreakMethod on Connection class
|
||||
static Handle<Value> Break (const Arguments& args);
|
||||
static void Async_Break (uv_work_t *req);
|
||||
static void Async_AfterBreak (uv_work_t *req);
|
||||
|
||||
// Define Getter Accessors to properties
|
||||
static Handle<Value> GetStmtCacheSize (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetClientId (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetModule (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetAction (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
|
||||
// Define Setter Accessors to properties
|
||||
static void SetStmtCacheSize (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetClientId (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetModule (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetAction (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
|
||||
Connection ();
|
||||
~Connection ();
|
||||
|
||||
|
||||
static void PrepareAndBind (eBaton* executeBaton);
|
||||
static void GetDefines (eBaton* executeBaton);
|
||||
static void ProcessBinds (const Arguments& args, unsigned int index,
|
||||
eBaton* executeBaton);
|
||||
static void ProcessOptions (const Arguments& args, unsigned int index,
|
||||
eBaton* executeBaton);
|
||||
static void ProcessCallback (const Arguments& args, unsigned int index,
|
||||
eBaton* executeBaton);
|
||||
static void GetExecuteBaton (const Arguments& args, eBaton* executeBaton);
|
||||
static void GetOptions (Handle<Object> options, eBaton* executeBaton);
|
||||
static void GetBinds (Handle<Object> bindobj, eBaton* executeBaton);
|
||||
static void GetBinds (Handle<Array> bindarray, eBaton* executeBaton);
|
||||
static void GetBindUnit (Handle<Value> bindtypes, Bind* bind,
|
||||
eBaton* executeBaton);
|
||||
static void GetInBindParams (Handle<Value> bindtypes, Bind* bind,
|
||||
eBaton* executeBaton, BindType bindType);
|
||||
static void GetOutBindParams (unsigned short dataType, Bind* bind,
|
||||
eBaton* executeBaton);
|
||||
static Handle<Value> GetOutBinds (eBaton* executeBaton);
|
||||
static Handle<Value> GetOutBindArray ( std::vector<Bind*> binds, unsigned int outCount);
|
||||
static Handle<Value> GetOutBindObject (std::vector<Bind*> binds);
|
||||
static Handle<Value> GetRows (eBaton* executeBaton);
|
||||
static Handle<Value> GetValue (short ind, unsigned short type, void* val,
|
||||
DPI_BUFLEN_TYPE len);
|
||||
static void UpdateDateValue ( eBaton *executeBaton );
|
||||
static void v8Date2OraDate ( v8::Handle<v8::Value>, Bind *bind);
|
||||
|
||||
dpi::Conn* dpiconn_;
|
||||
bool isValid_;
|
||||
Oracledb* oracledb_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /** __NJSCONNECTION_H__ **/
|
|
@ -0,0 +1,76 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* njsMessages.cpp
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Static function composes a displayable (error) string with replacements
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
#include "njsMessages.h"
|
||||
|
||||
// Maximum buffer size to compose error message
|
||||
#define MAX_ERROR_MSG_LEN 1024
|
||||
|
||||
static const char *errMsg[] =
|
||||
{
|
||||
"NJS-001: expected callback as last parameter",
|
||||
"NJS-002: invalid pool",
|
||||
"NJS-003: invalid connection",
|
||||
"NJS-004: invalid value for property %s",
|
||||
"NJS-005: invalid value for parameter %d",
|
||||
"NJS-006: invalid type for parameter %d",
|
||||
"NJS-007: invalid value for \"%s\" in parameter %d",
|
||||
"NJS-008: invalid type for \"%s\" in parameter %d",
|
||||
"NJS-009: invalid number of parameters",
|
||||
"NJS-010: specified datatype is not supported",
|
||||
"NJS-011: encountered bind value and type mismatch in parameter %d",
|
||||
"NJS-012: encountered invalid bind datatype in parameter %d",
|
||||
"NJS-013: invalid bind direction",
|
||||
"NJS-014: %s is a read-only property",
|
||||
"NJS-015: %s is a write-only property"
|
||||
};
|
||||
|
||||
string NJSMessages::getErrorMsg ( NJSErrorType err, ... )
|
||||
{
|
||||
char msg[MAX_ERROR_MSG_LEN + 1]; // buffer to get formatted/substituted error msg
|
||||
va_list vlist; // variable argument list
|
||||
std::string str;
|
||||
|
||||
if ( err > 0 && err < errMaxErrors )
|
||||
{
|
||||
// print all specified arguments
|
||||
va_start (vlist, err);
|
||||
vsnprintf (msg, MAX_ERROR_MSG_LEN, errMsg[err-1], vlist);
|
||||
va_end (vlist);
|
||||
|
||||
str = msg;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//end of NJSMessages.cpp
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* njsMessages.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Error message consolidation and composing
|
||||
* All error messages are stored in variable now and is displayed after
|
||||
* any substitution. These messages can be exported to a text file for
|
||||
* localization later
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __NJSMESSAGES_H__
|
||||
#define __NJSMESSAGES_H__
|
||||
|
||||
#include <string>
|
||||
using namespace std;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
errMissingCallback = 1,
|
||||
errInvalidPool,
|
||||
errInvalidConnection,
|
||||
errInvalidPropertyValue,
|
||||
errInvalidParameterValue,
|
||||
errInvalidParameterType,
|
||||
errInvalidPropertyValueInParam,
|
||||
errInvalidPropertyTypeInParam,
|
||||
errInvalidNumberOfParameters,
|
||||
errUnsupportedDatType,
|
||||
errBindValueAndTypeMismatch,
|
||||
errInvalidBindDataType,
|
||||
errInvalidBindDirection,
|
||||
errReadOnly,
|
||||
errWriteOnly,
|
||||
|
||||
// New ones should be added here
|
||||
|
||||
errMaxErrors // Max # of errors plus one
|
||||
} NJSErrorType;
|
||||
|
||||
class NJSMessages
|
||||
{
|
||||
public:
|
||||
static string getErrorMsg ( NJSErrorType err, ... );
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* __NJSMESSAGES_H__ */
|
||||
|
|
@ -0,0 +1,685 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* njsOracle.cpp
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Oracledb class implementation.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "njsOracle.h"
|
||||
#include "njsConnection.h"
|
||||
#include "njsPool.h"
|
||||
#include "njsMessages.h"
|
||||
//peristent Oracledb class handle
|
||||
Persistent<FunctionTemplate> Oracledb::oracledbTemplate_s;
|
||||
|
||||
#define MAX_ROWS 100
|
||||
#define STMT_CACHE_SIZE 30
|
||||
#define POOL_MIN 0
|
||||
#define POOL_MAX 4
|
||||
#define POOL_INCR 1
|
||||
#define POOL_TIMEOUT 60
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Constructor for the Oracledb class.
|
||||
*/
|
||||
Oracledb::Oracledb()
|
||||
{
|
||||
dpienv_ = dpi::Env::createEnv();
|
||||
outFormat_ = ROWS_ARRAY;
|
||||
maxRows_ = MAX_ROWS;
|
||||
isAutoCommit_ = false;
|
||||
stmtCacheSize_ = STMT_CACHE_SIZE;
|
||||
poolMax_ = POOL_MAX;
|
||||
poolMin_ = POOL_MIN;
|
||||
poolIncrement_ = POOL_INCR;
|
||||
poolTimeout_ = POOL_TIMEOUT;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Destructor for the Oracledb class.
|
||||
*/
|
||||
Oracledb::~Oracledb()
|
||||
{
|
||||
|
||||
if (this->dpienv_)
|
||||
{
|
||||
dpienv_->terminate();
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Init function of the Oracledb class.
|
||||
Initiates and maps the functions and properties of Oracledb class.
|
||||
*/
|
||||
void Oracledb::Init(Handle<Object> target)
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
Local<FunctionTemplate> temp = FunctionTemplate::New(New);
|
||||
oracledbTemplate_s = Persistent<FunctionTemplate>::New(temp);
|
||||
oracledbTemplate_s->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
oracledbTemplate_s->SetClassName(String::New("Oracledb"));
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(oracledbTemplate_s, "getConnection", GetConnection);
|
||||
NODE_SET_PROTOTYPE_METHOD(oracledbTemplate_s, "createPool", CreatePool);
|
||||
|
||||
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("poolMax"),
|
||||
Oracledb::GetPoolMax,
|
||||
Oracledb::SetPoolMax );
|
||||
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("poolMin"),
|
||||
Oracledb::GetPoolMin,
|
||||
Oracledb::SetPoolMin );
|
||||
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("poolIncrement"),
|
||||
Oracledb::GetPoolIncrement,
|
||||
Oracledb::SetPoolIncrement );
|
||||
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("poolTimeout"),
|
||||
Oracledb::GetPoolTimeout,
|
||||
Oracledb::SetPoolTimeout );
|
||||
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("stmtCacheSize"),
|
||||
Oracledb::GetStmtCacheSize,
|
||||
Oracledb::SetStmtCacheSize );
|
||||
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("isAutoCommit"),
|
||||
Oracledb::GetIsAutoCommit,
|
||||
Oracledb::SetIsAutoCommit );
|
||||
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("maxRows"),
|
||||
Oracledb::GetMaxRows,
|
||||
Oracledb::SetMaxRows );
|
||||
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("outFormat"),
|
||||
Oracledb::GetOutFormat,
|
||||
Oracledb::SetOutFormat );
|
||||
oracledbTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("version"),
|
||||
Oracledb::GetVersion,
|
||||
Oracledb::SetVersion );
|
||||
|
||||
target->Set(String::New("Oracledb"),oracledbTemplate_s->GetFunction());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Invoked when new of oracledb is called from JS
|
||||
|
||||
*/
|
||||
Handle<Value> Oracledb::New(const Arguments& args)
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
Oracledb *oracledb = new Oracledb();
|
||||
oracledb->Wrap(args.This());
|
||||
|
||||
return args.This();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of poolMin Property
|
||||
*/
|
||||
Handle<Value> Oracledb::GetPoolMin ( Local<String> property,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
Local<Integer> value = v8::Integer::New(oracledb->poolMin_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of poolMin Property
|
||||
*/
|
||||
void Oracledb::SetPoolMin ( Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
NJS_SET_PROP_UINT(oracledb->poolMin_, value, "poolMin");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of poolMax Property
|
||||
*/
|
||||
Handle<Value> Oracledb::GetPoolMax ( Local<String> property,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
Local<Integer> value = v8::Integer::New(oracledb->poolMax_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of poolMax Property
|
||||
*/
|
||||
void Oracledb::SetPoolMax ( Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
NJS_SET_PROP_UINT(oracledb->poolMax_, value, "poolMax");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of poolIncrement Property
|
||||
*/
|
||||
Handle<Value> Oracledb::GetPoolIncrement ( Local<String> property,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
Local<Integer> value = v8::Integer::New(oracledb->poolIncrement_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of poolIncrement Property
|
||||
*/
|
||||
void Oracledb::SetPoolIncrement ( Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
NJS_SET_PROP_UINT(oracledb->poolIncrement_, value, "poolIncrement");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of poolTimeout Property
|
||||
*/
|
||||
Handle<Value> Oracledb::GetPoolTimeout ( Local<String> property,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
Local<Integer> value = v8::Integer::New(oracledb->poolTimeout_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of poolTimeout Property
|
||||
*/
|
||||
void Oracledb::SetPoolTimeout ( Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
NJS_SET_PROP_UINT(oracledb->poolTimeout_ , value, "poolTimeout");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of maxRows property
|
||||
*/
|
||||
Handle<Value> Oracledb::GetMaxRows ( Local<String> property,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
Local<Integer> value = v8::Integer::New(oracledb->maxRows_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of maxRows property
|
||||
*/
|
||||
void Oracledb::SetMaxRows ( Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
NJS_SET_PROP_UINT(oracledb->maxRows_, value, "maxRows");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of outFormat property
|
||||
*/
|
||||
Handle<Value> Oracledb::GetOutFormat ( Local<String> property,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
Handle<Value> value = v8::Integer::New(oracledb->outFormat_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of outFormat property
|
||||
*/
|
||||
void Oracledb::SetOutFormat ( Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
NJS_SET_PROP_UINT(oracledb->outFormat_, value, "outFormat");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of stmtCacheSize property
|
||||
*/
|
||||
Handle<Value> Oracledb::GetStmtCacheSize ( Local<String> property,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
Local<Integer> value = v8::Integer::New(oracledb->stmtCacheSize_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of stmtCacheSize property
|
||||
*/
|
||||
void Oracledb::SetStmtCacheSize ( Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
NJS_SET_PROP_UINT(oracledb->stmtCacheSize_, value, "stmtCacheSize");
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of isAutoCommit property
|
||||
*/
|
||||
Handle<Value> Oracledb::GetIsAutoCommit ( Local<String> property,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
Handle<Boolean> value = v8::Boolean::New(oracledb->isAutoCommit_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of isAutoCommit property
|
||||
*/
|
||||
void Oracledb::SetIsAutoCommit ( Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb>(info.Holder());
|
||||
oracledb->isAutoCommit_ = value->ToBoolean()->Value();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of version property
|
||||
*/
|
||||
Handle<Value> Oracledb::GetVersion ( Local<String> property,
|
||||
const AccessorInfo& info )
|
||||
{
|
||||
HandleScope scope;
|
||||
int version = NJSORACLE_VERSION;
|
||||
Local<Integer> value = v8::Integer::New(version);
|
||||
return scope.Close(value);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of version property
|
||||
*/
|
||||
void Oracledb::SetVersion ( Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
std::string msg;
|
||||
msg = NJSMessages::getErrorMsg(errReadOnly, "version");
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Connection method on Oracledb class.
|
||||
|
||||
PARAMETERS:
|
||||
Arguments - Connection attributes as JSON object,
|
||||
Callback
|
||||
*/
|
||||
Handle<Value> Oracledb::GetConnection(const Arguments& args)
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
JSONValueIndicator ind;
|
||||
Local<Function> callback;
|
||||
Local<Object> connProps;
|
||||
NJS_GET_CALLBACK ( callback, args );
|
||||
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb> ( args.This() );
|
||||
connectionBaton *connBaton = new connectionBaton ();
|
||||
connBaton->cb = Persistent<Function>::New( callback );
|
||||
|
||||
NJS_CHECK_NUMBER_OF_ARGS ( connBaton->error, args, 2, 2, exitGetConnection );
|
||||
NJS_GET_ARG_V8OBJECT ( connProps, connBaton->error, args, 0,
|
||||
exitGetConnection );
|
||||
NJS_GET_STRING_FROM_JSON ( connBaton->user, connBaton->error,
|
||||
ind, connProps, "user", 0, exitGetConnection );
|
||||
NJS_GET_STRING_FROM_JSON ( connBaton->pswrd, connBaton->error,
|
||||
ind, connProps, "password", 0, exitGetConnection );
|
||||
NJS_GET_STRING_FROM_JSON ( connBaton->connStr, connBaton->error,
|
||||
ind, connProps, "connectString", 0, exitGetConnection );
|
||||
|
||||
connBaton->stmtCacheSize = oracledb->stmtCacheSize_;
|
||||
NJS_GET_UINT_FROM_JSON ( connBaton->stmtCacheSize, connBaton->error,
|
||||
ind, connProps, "stmtCacheSize", 0, exitGetConnection );
|
||||
connBaton->oracledb = oracledb;
|
||||
connBaton->dpienv = oracledb->dpienv_;
|
||||
|
||||
exitGetConnection :
|
||||
connBaton->req.data = (void*) connBaton;
|
||||
// This needs to be called even in error case to make the control
|
||||
// fall through uv_after_work_cb. In case of error being present in
|
||||
// baton, the worker thread anyway returns
|
||||
uv_queue_work( uv_default_loop(), &connBaton->req, Async_GetConnection,
|
||||
(uv_after_work_cb) Async_AfterGetConnection );
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Worker function of Get Connection method
|
||||
|
||||
PARAMETERS:
|
||||
UV queue work block
|
||||
|
||||
NOTES:
|
||||
DPI call execution.
|
||||
*/
|
||||
void Oracledb::Async_GetConnection (uv_work_t *req)
|
||||
{
|
||||
connectionBaton *connBaton = (connectionBaton*)req->data;
|
||||
|
||||
if(!(connBaton->error).empty()) goto exitAsync_GetConnection;
|
||||
try
|
||||
{
|
||||
connBaton->dpiconn = connBaton-> dpienv ->
|
||||
getConnection( connBaton->user,
|
||||
connBaton->pswrd,
|
||||
connBaton->connStr,
|
||||
connBaton->stmtCacheSize );
|
||||
|
||||
}
|
||||
catch (dpi::Exception& e)
|
||||
{
|
||||
connBaton->error = std::string(e.what());
|
||||
}
|
||||
exitAsync_GetConnection:
|
||||
;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Callback function of Get Connection method
|
||||
|
||||
PARAMETERS:
|
||||
UV queue work block
|
||||
|
||||
NOTES:
|
||||
Connection handle is formed and handed over to JS.
|
||||
|
||||
*/
|
||||
void Oracledb::Async_AfterGetConnection (uv_work_t *req)
|
||||
{
|
||||
HandleScope scope;
|
||||
connectionBaton *connBaton = (connectionBaton*)req->data;
|
||||
|
||||
v8::TryCatch tc;
|
||||
Handle<Value> argv[2];
|
||||
if( !(connBaton->error).empty() )
|
||||
{
|
||||
argv[0] = v8::Exception::Error(String::New( (connBaton->error).c_str() ));
|
||||
argv[1] = Null();
|
||||
}
|
||||
else
|
||||
{
|
||||
argv[0] = Undefined();
|
||||
Handle<Object> connection = Connection::connectionTemplate_s->
|
||||
GetFunction()-> NewInstance();
|
||||
(ObjectWrap::Unwrap<Connection> (connection))->
|
||||
setConnection( connBaton->dpiconn,
|
||||
connBaton->oracledb );
|
||||
argv[1] = connection;
|
||||
}
|
||||
Local<Function> callback = Local<Function>::New(connBaton->cb);
|
||||
delete connBaton;
|
||||
node::MakeCallback( Context::GetCurrent()->Global(),
|
||||
callback, 2, argv );
|
||||
if(tc.HasCaught())
|
||||
node::FatalException(tc);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
CreatePool method on Oracledb class.
|
||||
|
||||
PARAMETERS:
|
||||
Arguments - Pool attributes as JSON object,
|
||||
Callback
|
||||
*/
|
||||
Handle<Value> Oracledb::CreatePool (const Arguments &args)
|
||||
{
|
||||
HandleScope scope ;
|
||||
|
||||
JSONValueIndicator ind;
|
||||
Local<Function> callback;
|
||||
Local<Object> poolProps;
|
||||
NJS_GET_CALLBACK ( callback, args );
|
||||
|
||||
Oracledb* oracledb = ObjectWrap::Unwrap<Oracledb> ( args.This() );
|
||||
connectionBaton *poolBaton = new connectionBaton ();
|
||||
poolBaton->cb = Persistent<Function>::New( callback );
|
||||
|
||||
NJS_CHECK_NUMBER_OF_ARGS ( poolBaton->error, args, 2, 2, exitCreatePool );
|
||||
NJS_GET_ARG_V8OBJECT ( poolProps, poolBaton->error, args, 0,
|
||||
exitCreatePool );
|
||||
NJS_GET_STRING_FROM_JSON ( poolBaton->user, poolBaton->error,
|
||||
ind, poolProps, "user", 0, exitCreatePool );
|
||||
NJS_GET_STRING_FROM_JSON ( poolBaton->pswrd, poolBaton->error,
|
||||
ind, poolProps, "password", 0, exitCreatePool );
|
||||
NJS_GET_STRING_FROM_JSON ( poolBaton->connStr, poolBaton->error,
|
||||
ind, poolProps, "connectString", 0, exitCreatePool );
|
||||
|
||||
poolBaton->poolMax = oracledb->poolMax_;
|
||||
poolBaton->poolMin = oracledb->poolMin_;
|
||||
poolBaton->poolIncrement = oracledb->poolIncrement_;
|
||||
poolBaton->poolTimeout = oracledb->poolTimeout_;
|
||||
poolBaton->stmtCacheSize = oracledb->stmtCacheSize_;
|
||||
|
||||
NJS_GET_UINT_FROM_JSON ( poolBaton->poolMax, poolBaton->error,
|
||||
ind, poolProps, "poolMax", 0, exitCreatePool );
|
||||
NJS_GET_UINT_FROM_JSON ( poolBaton->poolMin, poolBaton->error,
|
||||
ind, poolProps, "poolMin", 0, exitCreatePool );
|
||||
NJS_GET_UINT_FROM_JSON ( poolBaton->poolIncrement, poolBaton->error,
|
||||
ind, poolProps, "poolIncrement", 0, exitCreatePool );
|
||||
NJS_GET_UINT_FROM_JSON ( poolBaton->poolTimeout, poolBaton->error,
|
||||
ind, poolProps, "poolTimeout", 0, exitCreatePool );
|
||||
NJS_GET_UINT_FROM_JSON ( poolBaton->stmtCacheSize, poolBaton->error,
|
||||
ind, poolProps, "stmtCacheSize", 0, exitCreatePool );
|
||||
|
||||
poolBaton->oracledb = oracledb;
|
||||
poolBaton->dpienv = oracledb->dpienv_;
|
||||
|
||||
exitCreatePool:
|
||||
poolBaton->req.data = (void *)poolBaton;
|
||||
|
||||
uv_queue_work(uv_default_loop(),
|
||||
&poolBaton->req,
|
||||
Async_CreatePool,
|
||||
(uv_after_work_cb) Async_AfterCreatePool);
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Worker Function of CreatePool.
|
||||
|
||||
PARAMETERS:
|
||||
UV queue work block
|
||||
|
||||
NOTES:
|
||||
DPI call execution.
|
||||
*/
|
||||
void Oracledb::Async_CreatePool (uv_work_t *req)
|
||||
{
|
||||
connectionBaton *poolBaton = (connectionBaton *)req->data;
|
||||
|
||||
if(!(poolBaton->error).empty()) goto exitAsyncCreatePool;
|
||||
|
||||
try
|
||||
{
|
||||
poolBaton->dpipool = poolBaton-> dpienv ->
|
||||
createPool ( poolBaton->user,
|
||||
poolBaton->pswrd,
|
||||
poolBaton->connStr,
|
||||
poolBaton->poolMax,
|
||||
poolBaton->poolMin,
|
||||
poolBaton->poolIncrement,
|
||||
poolBaton->poolTimeout,
|
||||
poolBaton->stmtCacheSize );
|
||||
}
|
||||
catch (dpi::Exception &e)
|
||||
{
|
||||
poolBaton->error = std::string (e.what() );
|
||||
}
|
||||
exitAsyncCreatePool:
|
||||
;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Worker Function of CreatePool.
|
||||
|
||||
PARAMETERS:
|
||||
UV queue work block
|
||||
|
||||
NOTES:
|
||||
Pool handle is created and handed over to JS.
|
||||
*/
|
||||
void Oracledb::Async_AfterCreatePool (uv_work_t *req)
|
||||
{
|
||||
HandleScope scope ;
|
||||
connectionBaton *poolBaton = (connectionBaton *)req->data;
|
||||
|
||||
v8::TryCatch tc;
|
||||
Handle<Value> argv[2];
|
||||
|
||||
if (!poolBaton->error.empty())
|
||||
{
|
||||
argv[0] = v8::Exception::Error(String::New(( poolBaton->error).c_str() ));
|
||||
argv[1] = Undefined();
|
||||
}
|
||||
else
|
||||
{
|
||||
argv[0] = Undefined () ;
|
||||
Handle<Object> njsPool = Pool::poolTemplate_s->
|
||||
GetFunction() ->NewInstance();
|
||||
(ObjectWrap::Unwrap<Pool> (njsPool))-> setPool ( poolBaton->dpipool,
|
||||
poolBaton->oracledb,
|
||||
poolBaton->poolMax,
|
||||
poolBaton->poolMin,
|
||||
poolBaton->poolIncrement,
|
||||
poolBaton->poolTimeout,
|
||||
poolBaton->stmtCacheSize );
|
||||
argv[1] = njsPool;
|
||||
}
|
||||
Local<Function> callback = Local<Function>::New(poolBaton->cb);
|
||||
delete poolBaton;
|
||||
node::MakeCallback ( Context::GetCurrent()->Global(),
|
||||
callback, 2, argv);
|
||||
if(tc.HasCaught())
|
||||
{
|
||||
node::FatalException (tc);
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Invoked when require on oracledb is called
|
||||
|
||||
PARAMETERS:
|
||||
Target Object
|
||||
*/
|
||||
extern "C"
|
||||
{
|
||||
static void init(Handle<Object> target)
|
||||
{
|
||||
Oracledb::Init(target);
|
||||
Connection::Init(target);
|
||||
Pool::Init(target);
|
||||
}
|
||||
|
||||
NODE_MODULE(oracledb, init)
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* end of file njsOracle.cpp */
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* njsOracle.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Oracledb class
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __NJSORACLE_H__
|
||||
#define __NJSORACLE_H__
|
||||
|
||||
#include <v8.h>
|
||||
#include <node.h>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "dpi.h"
|
||||
#include "njsUtils.h"
|
||||
|
||||
using namespace node;
|
||||
using namespace v8;
|
||||
|
||||
#define NJSORACLE_VERSION 204; /* 0.2.4. Keep the version in sync with package.json */
|
||||
/* Formula: 10000 x majorversion + 100 x minorversion +
|
||||
patchreleasenumber */
|
||||
|
||||
class Oracledb: public ObjectWrap
|
||||
{
|
||||
public:
|
||||
|
||||
// Oracledb class
|
||||
static void Init(Handle<Object> target);
|
||||
|
||||
dpi::Env* getDpiEnv () const { return dpienv_; }
|
||||
bool getIsAutoCommit () const { return isAutoCommit_; }
|
||||
unsigned int getOutFormat () const { return outFormat_; }
|
||||
unsigned int getMaxRows () const { return maxRows_; }
|
||||
unsigned int getStmtCacheSize () const { return stmtCacheSize_; }
|
||||
unsigned int getPoolMin () const { return poolMin_; }
|
||||
unsigned int getPoolMax () const { return poolMax_; }
|
||||
unsigned int getPoolIncrement () const { return poolIncrement_; }
|
||||
unsigned int getPoolTimeout () const { return poolTimeout_; }
|
||||
|
||||
private:
|
||||
// Define Oracledb Constructor
|
||||
static Persistent<FunctionTemplate> oracledbTemplate_s;
|
||||
|
||||
static Handle<Value> New(const Arguments& args);
|
||||
|
||||
// Get Connection Methods
|
||||
static Handle<Value> GetConnection(const Arguments& args);
|
||||
static void Async_GetConnection(uv_work_t *req);
|
||||
static void Async_AfterGetConnection(uv_work_t *req);
|
||||
|
||||
// Create Pool Methods
|
||||
static Handle<Value> CreatePool (const Arguments& args);
|
||||
static void Async_CreatePool (uv_work_t *req );
|
||||
static void Async_AfterCreatePool (uv_work_t *req );
|
||||
|
||||
// Define Getter Accessors to Properties
|
||||
static Handle<Value> GetPoolMin(Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetPoolMax(Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetPoolIncrement(Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetPoolTimeout(Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetStmtCacheSize(Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetIsAutoCommit(Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetMaxRows(Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetOutFormat(Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetVersion(Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
// Define Setter Accessors to Properties
|
||||
static void SetPoolMin(Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetPoolMax(Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetPoolIncrement(Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetPoolTimeout(Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetStmtCacheSize(Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetIsAutoCommit(Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetMaxRows(Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetOutFormat(Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetVersion(Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
|
||||
Oracledb();
|
||||
~Oracledb();
|
||||
|
||||
dpi::Env* dpienv_;
|
||||
unsigned int outFormat_;
|
||||
bool isAutoCommit_;
|
||||
unsigned int maxRows_;
|
||||
unsigned int stmtCacheSize_;
|
||||
unsigned int poolMin_;
|
||||
unsigned int poolMax_;
|
||||
unsigned int poolIncrement_;
|
||||
unsigned int poolTimeout_;
|
||||
};
|
||||
|
||||
/**
|
||||
* Baton for Asynchronous Get Connection Call
|
||||
**/
|
||||
class Pool;
|
||||
|
||||
typedef struct connectionBaton
|
||||
{
|
||||
uv_work_t req;
|
||||
std::string user;
|
||||
std::string pswrd;
|
||||
std::string connStr;
|
||||
std::string connClass;
|
||||
std::string error;
|
||||
|
||||
int poolMax;
|
||||
int poolMin;
|
||||
int poolIncrement;
|
||||
int poolTimeout;
|
||||
int stmtCacheSize;
|
||||
|
||||
unsigned int maxRows;
|
||||
unsigned int outFormat;
|
||||
Persistent<Function> cb;
|
||||
dpi::Env* dpienv;
|
||||
dpi::Conn* dpiconn;
|
||||
dpi::SPool* dpipool;
|
||||
|
||||
Oracledb *oracledb;
|
||||
|
||||
connectionBaton() : poolMax(0), poolMin(0), poolIncrement(0),
|
||||
poolTimeout(0), stmtCacheSize(0), maxRows(0),
|
||||
outFormat(0), dpienv(NULL),
|
||||
dpiconn(NULL), dpipool(NULL)
|
||||
{}
|
||||
|
||||
~connectionBaton()
|
||||
{
|
||||
cb.Dispose();
|
||||
}
|
||||
|
||||
}connectionBaton;
|
||||
|
||||
|
||||
|
||||
#endif /* __NJSORACLE_H__ */
|
||||
|
||||
|
|
@ -0,0 +1,638 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* njsPool.cpp
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Pool class implementation.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#include "njsOracle.h"
|
||||
#include "njsPool.h"
|
||||
#include "njsConnection.h"
|
||||
#include "njsUtils.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace node;
|
||||
using namespace v8;
|
||||
//peristent Pool class handle
|
||||
Persistent<FunctionTemplate> Pool::poolTemplate_s;
|
||||
|
||||
Pool::Pool(){}
|
||||
Pool::~Pool(){}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Store the config in pool instance.
|
||||
*/
|
||||
void Pool::setPool( dpi::SPool *dpipool, Oracledb* oracledb, unsigned int poolMax,
|
||||
unsigned int poolMin, unsigned int poolIncrement,
|
||||
unsigned int poolTimeout, unsigned stmtCacheSize )
|
||||
{
|
||||
this->dpipool_ = dpipool;
|
||||
this->isValid_ = true;
|
||||
this->oracledb_ = oracledb;
|
||||
this->poolMax_ = poolMax;
|
||||
this->poolMin_ = poolMin;
|
||||
this->poolIncrement_ = poolIncrement;
|
||||
this->poolTimeout_ = poolTimeout;
|
||||
this->stmtCacheSize_ = stmtCacheSize;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Init function of the Pool class.
|
||||
Initiates and maps the functions and properties of Pool class.
|
||||
*/
|
||||
void Pool::Init(Handle<Object> target)
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
Local<FunctionTemplate> temp = FunctionTemplate::New(New);
|
||||
poolTemplate_s = Persistent<FunctionTemplate>::New(temp);
|
||||
poolTemplate_s->InstanceTemplate()->SetInternalFieldCount(1);
|
||||
poolTemplate_s->SetClassName(String::New("Pool"));
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(poolTemplate_s, "terminate", Terminate);
|
||||
NODE_SET_PROTOTYPE_METHOD(poolTemplate_s, "getConnection", GetConnection);
|
||||
|
||||
poolTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("poolMax"),
|
||||
Pool::GetPoolMax,
|
||||
Pool::SetPoolMax );
|
||||
poolTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("poolMin"),
|
||||
Pool::GetPoolMin,
|
||||
Pool::SetPoolMin );
|
||||
poolTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("poolIncrement"),
|
||||
Pool::GetPoolIncrement,
|
||||
Pool::SetPoolIncrement );
|
||||
poolTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("poolTimeout"),
|
||||
Pool::GetPoolTimeout,
|
||||
Pool::SetPoolTimeout );
|
||||
poolTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("connectionsOpen"),
|
||||
Pool::GetConnectionsOpen,
|
||||
Pool::SetConnectionsOpen );
|
||||
poolTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("connectionsInUse"),
|
||||
Pool::GetConnectionsInUse,
|
||||
Pool::SetConnectionsInUse );
|
||||
poolTemplate_s->InstanceTemplate()->SetAccessor(
|
||||
String::New("stmtCacheSize"),
|
||||
Pool::GetStmtCacheSize,
|
||||
Pool::SetStmtCacheSize );
|
||||
|
||||
target->Set(String::New("Pool"),poolTemplate_s->GetFunction());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Invoked when new of pool is called from JS
|
||||
|
||||
*/
|
||||
Handle<Value> Pool::New(const Arguments& args)
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
Pool *njsPool = new Pool();
|
||||
njsPool->Wrap(args.This());
|
||||
|
||||
return args.This();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of poolMin Property
|
||||
*/
|
||||
Handle<Value> Pool::GetPoolMin (Local<String> property,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
if(!njsPool->isValid_)
|
||||
{
|
||||
string msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
return Undefined();
|
||||
}
|
||||
else
|
||||
{
|
||||
Local<Integer> value = v8::Integer::New(njsPool->poolMin_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of poolMax Property
|
||||
*/
|
||||
Handle<Value> Pool::GetPoolMax (Local<String> property,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
if(!njsPool->isValid_)
|
||||
{
|
||||
string msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
return Undefined();
|
||||
}
|
||||
else
|
||||
{
|
||||
Local<Integer> value = v8::Integer::New(njsPool->poolMax_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of poolIncrement Property
|
||||
*/
|
||||
Handle<Value> Pool::GetPoolIncrement (Local<String> property,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
if(!njsPool->isValid_)
|
||||
{
|
||||
string msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
return Undefined();
|
||||
}
|
||||
else
|
||||
{
|
||||
Local<Integer> value = v8::Integer::New(njsPool->poolIncrement_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of poolTimeout Property
|
||||
*/
|
||||
Handle<Value> Pool::GetPoolTimeout (Local<String> property,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
if(!njsPool->isValid_)
|
||||
{
|
||||
string msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
return Undefined();
|
||||
}
|
||||
else
|
||||
{
|
||||
Local<Integer> value = v8::Integer::New(njsPool->poolTimeout_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of connectionsOpen Property
|
||||
*/
|
||||
Handle<Value> Pool::GetConnectionsOpen (Local<String> property,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
if(!njsPool->isValid_)
|
||||
{
|
||||
string error = NJSMessages::getErrorMsg ( errInvalidPool );
|
||||
NJS_SET_EXCEPTION(error.c_str(), error.length());
|
||||
return scope.Close(Undefined());
|
||||
}
|
||||
try
|
||||
{
|
||||
Local<Integer> value = v8::Integer::New(njsPool->dpipool_->
|
||||
connectionsOpen());
|
||||
return scope.Close(value);
|
||||
}
|
||||
catch(dpi::Exception &e)
|
||||
{
|
||||
NJS_SET_EXCEPTION(e.what(), strlen(e.what()));
|
||||
return Undefined();
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of connectionsInUse Property
|
||||
*/
|
||||
Handle<Value> Pool::GetConnectionsInUse (Local<String> property,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
Local<Integer> value;
|
||||
if(!njsPool->isValid_)
|
||||
{
|
||||
string error = NJSMessages::getErrorMsg ( errInvalidPool );
|
||||
NJS_SET_EXCEPTION(error.c_str(), error.length());
|
||||
return scope.Close(Undefined());
|
||||
}
|
||||
try
|
||||
{
|
||||
Local<Integer> value = v8::Integer::New(njsPool->dpipool_->
|
||||
connectionsInUse());
|
||||
return scope.Close(value);
|
||||
}
|
||||
catch(dpi::Exception &e)
|
||||
{
|
||||
NJS_SET_EXCEPTION(e.what(), strlen(e.what()));
|
||||
return Undefined();
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Accessor of stmtCacheSize Property
|
||||
*/
|
||||
Handle<Value> Pool::GetStmtCacheSize (Local<String> property,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
if(!njsPool->isValid_)
|
||||
{
|
||||
string msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
return Undefined();
|
||||
}
|
||||
else
|
||||
{
|
||||
Local<Integer> value = v8::Integer::New(njsPool->stmtCacheSize_);
|
||||
return scope.Close(value);
|
||||
}
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of poolMin Property - throws error
|
||||
*/
|
||||
void Pool::SetPoolMin (Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
string msg;
|
||||
if(!njsPool->isValid_)
|
||||
msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
else
|
||||
msg = NJSMessages::getErrorMsg(errReadOnly, "poolMin");
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of poolMax Property - throws error
|
||||
*/
|
||||
void Pool::SetPoolMax (Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
string msg;
|
||||
if(!njsPool->isValid_)
|
||||
msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
else
|
||||
msg = NJSMessages::getErrorMsg(errReadOnly, "poolMax");
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of poolIncrement Property - throws error
|
||||
*/
|
||||
void Pool::SetPoolIncrement (Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
string msg;
|
||||
if(!njsPool->isValid_)
|
||||
msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
else
|
||||
msg = NJSMessages::getErrorMsg(errReadOnly, "poolIncrement");
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of poolTimeout Property - throws error
|
||||
*/
|
||||
void Pool::SetPoolTimeout (Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
string msg;
|
||||
if(!njsPool->isValid_)
|
||||
msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
else
|
||||
msg = NJSMessages::getErrorMsg(errReadOnly, "poolTimeout");
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of connectionsOpen Property - throws error
|
||||
*/
|
||||
void Pool::SetConnectionsOpen (Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
string msg;
|
||||
if(!njsPool->isValid_)
|
||||
msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
else
|
||||
msg = NJSMessages::getErrorMsg(errReadOnly, "connectionsOpen");
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of connectionsInUse Property - throws error
|
||||
*/
|
||||
void Pool::SetConnectionsInUse (Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
string msg;
|
||||
if(!njsPool->isValid_)
|
||||
msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
else
|
||||
msg = NJSMessages::getErrorMsg(errReadOnly, "connectionsInUse");
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Set Accessor of stmtCacheSize Property - throws error
|
||||
*/
|
||||
void Pool::SetStmtCacheSize(Local<String> property, Local<Value> value,
|
||||
const AccessorInfo& info)
|
||||
{
|
||||
HandleScope scope;
|
||||
Pool* njsPool = ObjectWrap::Unwrap<Pool>(info.Holder());
|
||||
string msg;
|
||||
if(!njsPool->isValid_)
|
||||
msg = NJSMessages::getErrorMsg(errInvalidPool);
|
||||
else
|
||||
msg = NJSMessages::getErrorMsg(errReadOnly, "stmtCacheSize");
|
||||
NJS_SET_EXCEPTION(msg.c_str(), msg.length());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Get Connection method on Pool class.
|
||||
|
||||
PARAMETERS:
|
||||
Arguments - Callback
|
||||
*/
|
||||
Handle<Value> Pool::GetConnection(const Arguments& args)
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
Local<Function> callback;
|
||||
NJS_GET_CALLBACK ( callback, args );
|
||||
|
||||
Pool *njsPool = ObjectWrap::Unwrap<Pool>(args.This());
|
||||
connectionBaton *connBaton = new connectionBaton ();
|
||||
connBaton->cb = Persistent<Function>::New( callback );
|
||||
|
||||
NJS_CHECK_NUMBER_OF_ARGS ( connBaton->error, args, 1, 1, exitGetConnection );
|
||||
|
||||
if(!njsPool->isValid_)
|
||||
{
|
||||
connBaton->error = NJSMessages::getErrorMsg ( errInvalidPool );
|
||||
goto exitGetConnection;
|
||||
}
|
||||
connBaton->dpipool = njsPool->dpipool_;
|
||||
connBaton->oracledb = njsPool->oracledb_;
|
||||
exitGetConnection:
|
||||
connBaton->req.data = (void *)connBaton;
|
||||
|
||||
uv_queue_work(uv_default_loop(), &connBaton->req, Async_GetConnection,
|
||||
(uv_after_work_cb)Async_AfterGetConnection);
|
||||
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Worker function of Get Connection method
|
||||
|
||||
PARAMETERS:
|
||||
UV queue work block
|
||||
|
||||
NOTES:
|
||||
DPI call execution.
|
||||
*/
|
||||
void Pool::Async_GetConnection(uv_work_t *req)
|
||||
{
|
||||
connectionBaton *connBaton = (connectionBaton *)req->data;
|
||||
if(!(connBaton->error).empty()) goto exitAsyncGetConnection;
|
||||
|
||||
try
|
||||
{
|
||||
connBaton->dpiconn = connBaton-> dpipool -> getConnection ();
|
||||
}
|
||||
catch (dpi::Exception &e)
|
||||
{
|
||||
connBaton->error = std::string (e.what());
|
||||
}
|
||||
exitAsyncGetConnection:
|
||||
;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Callback function of Get Connection method
|
||||
|
||||
PARAMETERS:
|
||||
UV queue work block
|
||||
|
||||
NOTES:
|
||||
Connection handle is formed and handed over to JS.
|
||||
*/
|
||||
Handle<Value> Pool::Async_AfterGetConnection(uv_work_t *req)
|
||||
{
|
||||
HandleScope scope;
|
||||
connectionBaton *connBaton = (connectionBaton*)req->data;
|
||||
v8::TryCatch tc;
|
||||
Handle<Value> argv[2];
|
||||
if(!(connBaton->error).empty())
|
||||
{
|
||||
argv[0] = v8::Exception::Error(String::New((connBaton->error).c_str()));
|
||||
argv[1] = Undefined();
|
||||
}
|
||||
else
|
||||
{
|
||||
argv[0] = Undefined();
|
||||
Handle<Object> connection = Connection::connectionTemplate_s->
|
||||
GetFunction()-> NewInstance();
|
||||
(ObjectWrap::Unwrap<Connection> (connection))->
|
||||
setConnection( connBaton->dpiconn,
|
||||
connBaton->oracledb );
|
||||
argv[1] = connection;
|
||||
}
|
||||
node::MakeCallback(Context::GetCurrent()->Global(),
|
||||
connBaton->cb, 2, argv);
|
||||
if(tc.HasCaught())
|
||||
{
|
||||
node::FatalException(tc);
|
||||
}
|
||||
delete connBaton;
|
||||
return Undefined();
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Terminate method
|
||||
|
||||
PARAMETERS:
|
||||
Arguments - Callback
|
||||
*/
|
||||
Handle<Value> Pool::Terminate(const Arguments& args )
|
||||
{
|
||||
HandleScope scope;
|
||||
|
||||
Local<Function> callback;
|
||||
NJS_GET_CALLBACK ( callback, args );
|
||||
|
||||
Pool *njsPool = ObjectWrap::Unwrap<Pool>(args.This());
|
||||
connectionBaton *terminateBaton = new connectionBaton ();
|
||||
terminateBaton->cb = Persistent<Function>::New( callback );
|
||||
|
||||
NJS_CHECK_NUMBER_OF_ARGS ( terminateBaton->error, args, 1, 1, exitTerminate );
|
||||
|
||||
if(!njsPool->isValid_)
|
||||
{
|
||||
terminateBaton->error = NJSMessages::getErrorMsg( errInvalidPool );
|
||||
goto exitTerminate;
|
||||
}
|
||||
terminateBaton->dpipool = njsPool->dpipool_;
|
||||
njsPool->isValid_ = false;
|
||||
|
||||
exitTerminate:
|
||||
terminateBaton->req.data = (void *)terminateBaton;
|
||||
|
||||
uv_queue_work(uv_default_loop(), &terminateBaton->req, Async_Terminate,
|
||||
(uv_after_work_cb)Async_AfterTerminate);
|
||||
|
||||
return scope.Close(Undefined());
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Worker function of terminate.
|
||||
|
||||
PARAMETERS:
|
||||
UV queue work block
|
||||
|
||||
NOTES:
|
||||
DPI call execution.
|
||||
*/
|
||||
void Pool::Async_Terminate(uv_work_t *req)
|
||||
{
|
||||
connectionBaton *terminateBaton = (connectionBaton*)req->data;
|
||||
if(!terminateBaton->error.empty()) goto exitAsyncTerminate;
|
||||
|
||||
try
|
||||
{
|
||||
terminateBaton-> dpipool-> terminate ();
|
||||
}
|
||||
catch(dpi::Exception& e)
|
||||
{
|
||||
terminateBaton->error = std::string(e.what());
|
||||
}
|
||||
exitAsyncTerminate:
|
||||
;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
/*
|
||||
DESCRIPTION
|
||||
Callback function of terminate
|
||||
|
||||
PARAMETERS:
|
||||
UV queue work block
|
||||
*/
|
||||
void Pool::Async_AfterTerminate(uv_work_t *req)
|
||||
{
|
||||
HandleScope scope;
|
||||
connectionBaton *terminateBaton = (connectionBaton*)req->data;
|
||||
|
||||
v8::TryCatch tc;
|
||||
|
||||
Handle<Value> argv[1];
|
||||
|
||||
if(!(terminateBaton->error).empty())
|
||||
argv[0] = v8::Exception::Error(String::New((terminateBaton->error).c_str()));
|
||||
else
|
||||
argv[0] = Undefined();
|
||||
|
||||
node::MakeCallback( Context::GetCurrent()->Global(),
|
||||
terminateBaton->cb, 1, argv );
|
||||
if(tc.HasCaught())
|
||||
{
|
||||
node::FatalException(tc);
|
||||
}
|
||||
delete terminateBaton;
|
||||
}
|
||||
|
||||
|
||||
/* end of file njsPool.cpp */
|
||||
|
|
@ -0,0 +1,110 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* njsPool.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Pool class
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __NJSPOOL_H__
|
||||
#define __NJSPOOL_H__
|
||||
|
||||
#include "dpi.h"
|
||||
#include <node.h>
|
||||
#include <string>
|
||||
|
||||
using namespace v8;
|
||||
using namespace node;
|
||||
|
||||
|
||||
class Pool: public ObjectWrap {
|
||||
public:
|
||||
|
||||
static void Init(Handle<Object> target);
|
||||
|
||||
void setPool ( dpi::SPool *, Oracledb* oracledb, unsigned int poolMax,
|
||||
unsigned int poolMin, unsigned int poolIncrement,
|
||||
unsigned int poolTimeout, unsigned stmtCacheSize );
|
||||
|
||||
// Define Pool Constructor
|
||||
static Persistent<FunctionTemplate> poolTemplate_s ;
|
||||
|
||||
private:
|
||||
|
||||
static Handle<Value> New(const Arguments& args);
|
||||
|
||||
// Get Connection Methods
|
||||
static Handle<Value> GetConnection(const Arguments& args);
|
||||
static void Async_GetConnection(uv_work_t* req);
|
||||
static Handle<Value> Async_AfterGetConnection(uv_work_t* req);
|
||||
|
||||
// Terminate Methods
|
||||
static Handle<Value> Terminate(const Arguments& args);
|
||||
static void Async_Terminate(uv_work_t* req);
|
||||
static void Async_AfterTerminate(uv_work_t* req);
|
||||
|
||||
// Define Getter Accessors to properties
|
||||
static Handle<Value> GetPoolMax (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetPoolMin (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetPoolIncrement (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetPoolTimeout (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetConnectionsOpen (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetConnectionsInUse (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
static Handle<Value> GetStmtCacheSize (Local<String> property,
|
||||
const AccessorInfo& info);
|
||||
|
||||
// Define Setter Accessors to properties
|
||||
static void SetPoolMax (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetPoolMin (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetPoolIncrement (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetPoolTimeout (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetConnectionsOpen (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetConnectionsInUse (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
static void SetStmtCacheSize (Local<String> property,Local<Value> value,
|
||||
const AccessorInfo& info);
|
||||
|
||||
|
||||
Pool();
|
||||
~Pool();
|
||||
|
||||
dpi::SPool *dpipool_;
|
||||
bool isValid_;
|
||||
|
||||
Oracledb* oracledb_;
|
||||
unsigned int poolMin_;
|
||||
unsigned int poolMax_;
|
||||
unsigned int poolIncrement_;
|
||||
unsigned int poolTimeout_;
|
||||
unsigned int stmtCacheSize_;
|
||||
};
|
||||
|
||||
#endif /* __NJSPOOL_H__ */
|
|
@ -0,0 +1,281 @@
|
|||
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* You may not use the identified files except in compliance with the Apache
|
||||
* License, Version 2.0 (the "License.")
|
||||
*
|
||||
* You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/LICENSE-2.0.
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
*
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* NAME
|
||||
* njsUtils.h
|
||||
*
|
||||
* DESCRIPTION
|
||||
* Utilities
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
#ifndef __NJSUTILS_H__
|
||||
#define __NJSUTILS_H__
|
||||
|
||||
#include "njsMessages.h"
|
||||
|
||||
// User specified data types for binds and defines.
|
||||
typedef enum
|
||||
{
|
||||
DATA_UNKNOWN = -1,
|
||||
DATA_STR = 1,
|
||||
DATA_NUM = 2,
|
||||
DATA_DATE = 3
|
||||
}DataType;
|
||||
|
||||
// User specified bind types.
|
||||
typedef enum
|
||||
{
|
||||
BIND_UNKNOWN = -1,
|
||||
BIND_IN = 1,
|
||||
BIND_INOUT = 2,
|
||||
BIND_OUT = 3
|
||||
}BindType;
|
||||
|
||||
// outFormat types.
|
||||
typedef enum
|
||||
{
|
||||
ROWS_UNKNOWN = -1,
|
||||
ROWS_ARRAY = 1,
|
||||
ROWS_OBJECT = 2
|
||||
}RowsType;
|
||||
|
||||
// args
|
||||
typedef enum
|
||||
{
|
||||
ARGS_ZERO = 0,
|
||||
ARGS_ONE = 1,
|
||||
ARGS_TWO = 2,
|
||||
ARGS_THREE = 3,
|
||||
ARGS_FOUR = 4
|
||||
}ArgsType;
|
||||
|
||||
|
||||
// To be used by NJS_GET_JSON_* macros.
|
||||
typedef enum
|
||||
{
|
||||
VALIDVALUE = 0 , // Valid value found for the given key.
|
||||
UNDEFINEDVALUE , // key is missing or value is undefined.
|
||||
NULLVALUE , // Null value provided.
|
||||
INVALIDTYPE // Invalid type
|
||||
}JSONValueIndicator;
|
||||
|
||||
/*
|
||||
* Get the callback from the last argument.
|
||||
* If no args or last arg is not callback, throw exception
|
||||
*/
|
||||
#define NJS_GET_CALLBACK( cb, args ) \
|
||||
{ \
|
||||
string msg; \
|
||||
if( !args.Length() || !args[(args.Length()-1)]->IsFunction() ) \
|
||||
{ \
|
||||
msg = NJSMessages::getErrorMsg ( errMissingCallback ); \
|
||||
NJS_SET_EXCEPTION( msg.c_str(), msg.length() ); \
|
||||
return Undefined(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
cb = Local<Function>::Cast(args[args.Length()-1]); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Set v8 exception using passed in char*.
|
||||
* Caller is expected to return from the function after calling this macro
|
||||
* for the exception to be thrown.
|
||||
*/
|
||||
#define NJS_SET_EXCEPTION( str, len ) \
|
||||
ThrowException(v8::Exception::Error(String::New( str, len )));
|
||||
|
||||
/*
|
||||
* If arguments are not in given range, set the error.
|
||||
*/
|
||||
#define NJS_CHECK_NUMBER_OF_ARGS( err, args, minargs, maxargs, exitCode ) \
|
||||
{ \
|
||||
if( args.Length() < (minargs) || args.Length() > (maxargs) ) \
|
||||
{ \
|
||||
err = NJSMessages::getErrorMsg ( errInvalidNumberOfParameters ) ; \
|
||||
goto exitCode ; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert v8 String to std string
|
||||
*/
|
||||
#define NJSString( str, v8value ) \
|
||||
{ \
|
||||
v8::String::Utf8Value utfstr( v8value->ToString() ); \
|
||||
str = std::string( *utfstr, utfstr.length() ); \
|
||||
}
|
||||
|
||||
/*
|
||||
* Get v8 string from provided argument.
|
||||
* If it is not a v8 string, set the error for the given index &
|
||||
* val is nullified.
|
||||
*/
|
||||
#define NJS_GET_ARG_V8STRING( v8val, err, args, index, exitCode) \
|
||||
{ \
|
||||
if( args[index]->IsString() ) \
|
||||
{ \
|
||||
v8val = args[index]->ToString(); \
|
||||
err.clear(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
err = NJSMessages::getErrorMsg ( errInvalidParameterType, index+1 ) ; \
|
||||
goto exitCode; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Get v8 object from provided argument.
|
||||
* If it is not a v8 object, set the error for the given index &
|
||||
* val is nullified.
|
||||
*/
|
||||
#define NJS_GET_ARG_V8OBJECT( v8val, err, args, index, exitCode) \
|
||||
{ \
|
||||
if( args[index]->IsObject() ) \
|
||||
{ \
|
||||
v8val = args[index]->ToObject(); \
|
||||
err.clear(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
err = NJSMessages::getErrorMsg ( errInvalidParameterType, index+1 ) ; \
|
||||
goto exitCode ; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the std string value from JSON for the given key.
|
||||
* If val is undefined or null or key is missing, return ind.
|
||||
* index is the argument index in the caller.
|
||||
* ind will have the state based on the value
|
||||
* DO NOT SET ANY VALUE to val IF NULL OR UNDEFINED
|
||||
*/
|
||||
#define NJS_GET_STRING_FROM_JSON( val, err, ind, obj, key, index, exitCode ) \
|
||||
{ \
|
||||
Local<Value> v8value = obj->Get(String::New(key)); \
|
||||
err.clear(); \
|
||||
if( v8value->IsString() ) \
|
||||
{ \
|
||||
NJSString( val, v8value ); \
|
||||
ind = VALIDVALUE; \
|
||||
} \
|
||||
else if( v8value->IsNull() ) \
|
||||
{ \
|
||||
ind = NULLVALUE; \
|
||||
} \
|
||||
else if( v8value->IsUndefined() ) \
|
||||
{ \
|
||||
ind = UNDEFINEDVALUE; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
ind = INVALIDTYPE; \
|
||||
err = NJSMessages::getErrorMsg ( errInvalidPropertyTypeInParam, \
|
||||
key, index+1 ); \
|
||||
goto exitCode; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the uint value from JSON for the given key.
|
||||
* If val is undefined or null or key is missing, return ind.
|
||||
* index is the argument index in the caller.
|
||||
* ind will have the state based on the value
|
||||
* DO NOT SET ANY VALUE to val IF NULL OR UNDEFINED
|
||||
*/
|
||||
#define NJS_GET_UINT_FROM_JSON( val, err, ind, obj, key, index, exitCode ) \
|
||||
{ \
|
||||
Local<Value> v8value = obj->Get(String::New(key)); \
|
||||
err.clear(); \
|
||||
if( v8value->IsUint32() ) \
|
||||
{ \
|
||||
val = v8value->ToUint32()->Value(); \
|
||||
ind = VALIDVALUE; \
|
||||
} \
|
||||
else if( v8value->IsNull() ) \
|
||||
{ \
|
||||
ind = NULLVALUE; \
|
||||
} \
|
||||
else if( v8value->IsUndefined() ) \
|
||||
{ \
|
||||
ind = UNDEFINEDVALUE; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
err = NJSMessages::getErrorMsg ( errInvalidPropertyTypeInParam, \
|
||||
key, index+1 ); \
|
||||
goto exitCode; \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the boolean value from JSON for the given key.
|
||||
* index is the argument index in the caller.
|
||||
*/
|
||||
#define NJS_GET_BOOL_FROM_JSON( val, err, ind, obj, key, index, exitCode ) \
|
||||
{ \
|
||||
Local<Value> v8value = obj->Get(String::New(key)); \
|
||||
val = v8value->ToBoolean()->Value(); \
|
||||
ind = VALIDVALUE; \
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert v8value to std string for properties.
|
||||
* If it not a v8 string, throw exception.
|
||||
* prop is the name of the property
|
||||
*/
|
||||
#define NJS_SET_PROP_STR( val, v8value, prop ) \
|
||||
{ \
|
||||
string msg; \
|
||||
if( v8value->IsString() ) \
|
||||
{ \
|
||||
NJSString( val, v8value ); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
msg = NJSMessages::getErrorMsg ( errInvalidParameterType, \
|
||||
prop ); \
|
||||
NJS_SET_EXCEPTION( msg.c_str(), msg.length() ); \
|
||||
} \
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert v8value to unsigned int for properties.
|
||||
* If it not a v8 uint, throw exception.
|
||||
* prop is the name of the property
|
||||
*/
|
||||
#define NJS_SET_PROP_UINT( val, v8value, prop ) \
|
||||
{ \
|
||||
string msg; \
|
||||
if( v8value->IsUint32() ) \
|
||||
{ \
|
||||
val = v8value->ToUint32()->Value(); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
msg = NJSMessages::getErrorMsg ( errInvalidParameterType, \
|
||||
prop ); \
|
||||
NJS_SET_EXCEPTION( msg.c_str(), msg.length() ); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
#endif // ifdef__NJSUTILS_H__
|
||||
|
Loading…
Reference in New Issue