Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-gyp support #58

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"targets": [
{
"target_name": "oracle_bindings",
"sources": [
"lib/node-db/binding.cc",
"lib/node-db/connection.cc",
"lib/node-db/events.cc",
"lib/node-db/exception.cc",
"lib/node-db/query.cc",
"lib/node-db/result.cc",
"src/connection.cc",
"src/oracle.cc",
"src/query.cc",
"src/result.cc",
"src/oracle_bindings.cc"
],
"conditions": [
["OS==\"mac\"", {
"xcode_settings": {
"GCC_ENABLE_CPP_EXCEPTIONS": "YES"
}
}],
["OS!=\"win\"", {
"variables": {
"oci_include_dir%": "<!(if [ -z $OCI_INCLUDE_DIR ]; then echo \"/opt/instantclient/sdk/include/\"; else echo $OCI_INCLUDE_DIR; fi)",
"oci_lib_dir%": "<!(if [ -z $OCI_LIB_DIR ]; then echo \"/opt/instantclient/\"; else echo $OCI_LIB_DIR; fi)",
"oci_version%": "<!(if [ -z $OCI_VERSION ]; then echo 11; else echo $OCI_VERSION; fi)"
},
"libraries": ["-locci", "-lclntsh", "-lnnz<(oci_version)"],
"link_settings": {"libraries": [ "-L<(oci_lib_dir)"] }
}],
["OS==\"win\"", {
"configurations": {
"Release": {
"msvs_settings": {
"VCCLCompilerTool": {
"RuntimeLibrary": "2"
}
}
},
"Debug": {
"msvs_settings": {
"VCCLCompilerTool": {
"RuntimeLibrary": "3"
}
}
}
},
"variables": {
"oci_include_dir%": "<!(IF DEFINED OCI_INCLUDE_DIR (echo %OCI_INCLUDE_DIR%) ELSE (echo C:\oracle\instantclient\sdk\include))",
"oci_lib_dir%": "<!(IF DEFINED OCI_LIB_DIR (echo %OCI_LIB_DIR%) ELSE (echo C:\oracle\instantclient\sdk\lib\msvc))",
"oci_version%": "<!(IF DEFINED OCI_VERSION (echo %OCI_VERSION%) ELSE (echo 11))"
}
}]
],
"include_dirs": [
"lib",
"<(oci_include_dir)",
],
"cflags!": [ "-fno-exceptions" ],
"cflags_cc!": [ "-fno-exceptions" ]
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
]
, "main" : "./db-oracle"
, "scripts" :
{ "install": "node-waf configure build"
{ "install": "node-gyp configure build"
, "preuninstall": "rm -rf build/*"
, "test" : "node-waf test"
, "doc" : "node-waf doc"
Expand Down
13 changes: 12 additions & 1 deletion src/connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ node_db_oracle::Connection::~Connection() {
}
}

void node_db_oracle::Connection::setTns(const std::string& iTns) throw() {
this->tns = iTns;
}

void node_db_oracle::Connection::setCharset(const std::string& charset) throw() {
this->charset = charset;
}
Expand Down Expand Up @@ -44,7 +48,14 @@ void node_db_oracle::Connection::open() throw(node_db::Exception&) {
}

std::ostringstream connection;
connection << "//" << this->hostname << ":" << this->port << "/" << this->database;
if(this->tns != "")
{
connection << this->tns;
}
else
{
connection << "//" << this->hostname << ":" << this->port << "/" << this->database;
}
try {
this->connection = this->environment->createConnection(this->user, this->password, connection.str());
this->alive = true;
Expand Down
2 changes: 2 additions & 0 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Connection : public node_db::Connection {
public:
Connection();
~Connection();
void setTns(const std::string& iTns) throw();
void setCharset(const std::string& charset) throw();
void setNCharset(const std::string& charset) throw();
bool isAlive(bool ping) throw();
Expand All @@ -23,6 +24,7 @@ class Connection : public node_db::Connection {
node_db::Result* query(const std::string& query) const throw(node_db::Exception&);

protected:
std::string tns;
std::string charset;
std::string ncharset;

Expand Down
6 changes: 6 additions & 0 deletions src/oracle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ v8::Handle<v8::Value> node_db_oracle::Oracle::New(const v8::Arguments& args) {
}

v8::Handle<v8::Value> node_db_oracle::Oracle::set(const v8::Local<v8::Object> options) {
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, tns);
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, hostname);
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, user);
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, password);
Expand All @@ -60,11 +61,16 @@ v8::Handle<v8::Value> node_db_oracle::Oracle::set(const v8::Local<v8::Object> op

node_db_oracle::Connection* connection = static_cast<node_db_oracle::Connection*>(this->connection);

v8::String::Utf8Value tns(options->Get(tns_key)->ToString());
v8::String::Utf8Value hostname(options->Get(hostname_key)->ToString());
v8::String::Utf8Value user(options->Get(user_key)->ToString());
v8::String::Utf8Value password(options->Get(password_key)->ToString());
v8::String::Utf8Value database(options->Get(database_key)->ToString());

if (options->Has(tns_key)) {
connection->setTns(*tns);
}

if (options->Has(hostname_key)) {
connection->setHostname(*hostname);
}
Expand Down