diff --git a/binding.gyp b/binding.gyp new file mode 100644 index 0000000..d8fd4d1 --- /dev/null +++ b/binding.gyp @@ -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%": "tns = iTns; +} + void node_db_oracle::Connection::setCharset(const std::string& charset) throw() { this->charset = charset; } @@ -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; diff --git a/src/connection.h b/src/connection.h index aa57511..a4e2035 100644 --- a/src/connection.h +++ b/src/connection.h @@ -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(); @@ -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; diff --git a/src/oracle.cc b/src/oracle.cc index 946b0f1..9e33d6b 100644 --- a/src/oracle.cc +++ b/src/oracle.cc @@ -50,6 +50,7 @@ v8::Handle node_db_oracle::Oracle::New(const v8::Arguments& args) { } v8::Handle node_db_oracle::Oracle::set(const v8::Local 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); @@ -60,11 +61,16 @@ v8::Handle node_db_oracle::Oracle::set(const v8::Local op node_db_oracle::Connection* connection = static_cast(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); }