Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding charset and ncharset connection options. Fixes #28

  • Loading branch information...
commit 328fae5e1a629cda82f02e1585607514a3ca3676 1 parent 0e972f4
@mariano authored
Showing with 41 additions and 6 deletions.
  1. +23 −6 src/connection.cc
  2. +6 −0 src/connection.h
  3. +12 −0 src/oracle.cc
View
29 src/connection.cc
@@ -6,15 +6,21 @@ node_db_oracle::Connection::Connection()
connection(NULL) {
this->port = 1521;
this->quoteName = '"';
- this->environment = oracle::occi::Environment::createEnvironment("AL32UTF8","AL32UTF8", oracle::occi::Environment::THREADED_MUTEXED);
- if (this->environment == NULL) {
- throw node_db::Exception("Cannot create environment");
- }
}
node_db_oracle::Connection::~Connection() {
this->close();
- oracle::occi::Environment::terminateEnvironment(this->environment);
+ if (this->environment) {
+ oracle::occi::Environment::terminateEnvironment(this->environment);
+ }
+}
+
+void node_db_oracle::Connection::setCharset(const std::string& charset) throw() {
+ this->charset = charset;
+}
+
+void node_db_oracle::Connection::setNCharset(const std::string& ncharset) throw() {
+ this->ncharset = ncharset;
}
bool node_db_oracle::Connection::isAlive(bool ping) throw() {
@@ -26,6 +32,17 @@ bool node_db_oracle::Connection::isAlive(bool ping) throw() {
void node_db_oracle::Connection::open() throw(node_db::Exception&) {
this->close();
+ if (!this->environment) {
+ if (!this->charset.empty() && !this->ncharset.empty()) {
+ this->environment = oracle::occi::Environment::createEnvironment(this->charset.c_str(), this->ncharset.c_str(), oracle::occi::Environment::THREADED_MUTEXED);
+ } else {
+ this->environment = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::THREADED_MUTEXED);
+ }
+ if (this->environment == NULL) {
+ throw node_db::Exception("Cannot create environment");
+ }
+ }
+
std::ostringstream connection;
connection << "//" << this->hostname << ":" << this->port << "/" << this->database;
try {
@@ -37,7 +54,7 @@ void node_db_oracle::Connection::open() throw(node_db::Exception&) {
}
void node_db_oracle::Connection::close() {
- if (this->alive) {
+ if (this->alive && this->environment) {
this->environment->terminateConnection(this->connection);
}
this->alive = false;
View
6 src/connection.h
@@ -13,6 +13,8 @@ class Connection : public node_db::Connection {
public:
Connection();
~Connection();
+ void setCharset(const std::string& charset) throw();
+ void setNCharset(const std::string& charset) throw();
bool isAlive(bool ping) throw();
void open() throw(node_db::Exception&);
void close();
@@ -20,6 +22,10 @@ class Connection : public node_db::Connection {
std::string version() const;
node_db::Result* query(const std::string& query) const throw(node_db::Exception&);
+ protected:
+ std::string charset;
+ std::string ncharset;
+
private:
oracle::occi::Environment* environment;
oracle::occi::Connection* connection;
View
12 src/oracle.cc
@@ -55,6 +55,8 @@ v8::Handle<v8::Value> node_db_oracle::Oracle::set(const v8::Local<v8::Object> op
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, password);
ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, database);
ARG_CHECK_OBJECT_ATTR_OPTIONAL_UINT32(options, port);
+ ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, charset);
+ ARG_CHECK_OBJECT_ATTR_OPTIONAL_STRING(options, ncharset);
node_db_oracle::Connection* connection = static_cast<node_db_oracle::Connection*>(this->connection);
@@ -83,6 +85,16 @@ v8::Handle<v8::Value> node_db_oracle::Oracle::set(const v8::Local<v8::Object> op
connection->setPort(options->Get(port_key)->ToInt32()->Value());
}
+ if (options->Has(charset_key)) {
+ v8::String::Utf8Value charset(options->Get(charset_key)->ToString());
+ connection->setCharset(*charset);
+ }
+
+ if (options->Has(ncharset_key)) {
+ v8::String::Utf8Value ncharset(options->Get(ncharset_key)->ToString());
+ connection->setNCharset(*ncharset);
+ }
+
return v8::Handle<v8::Value>();
}
Please sign in to comment.
Something went wrong with that request. Please try again.