diff --git a/src/connection.cpp b/src/connection.cpp index d061fbe..bb26a79 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -29,6 +29,7 @@ void Connection::Init(Handle target) { NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "isConnected", IsConnected); NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "setAutoCommit", SetAutoCommit); NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "setPrefetchRowCount", SetPrefetchRowCount); + NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "setNumberStringFormat", setNumberStringFormat); NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "commit", Commit); NODE_SET_PROTOTYPE_METHOD(uni::Deref(constructorTemplate), "rollback", Rollback); @@ -43,7 +44,7 @@ uni::CallbackType Connection::New(const uni::FunctionCallbackInfo& args) { UNI_RETURN(scope, args, args.This()); } -Connection::Connection():m_connection(NULL), m_environment(NULL), m_autoCommit(true), m_prefetchRowCount(0) { +Connection::Connection():m_connection(NULL), m_environment(NULL), m_autoCommit(true), m_prefetchRowCount(0), m_numberStringFormat(NULL) { } Connection::~Connection() { @@ -184,6 +185,18 @@ uni::CallbackType Connection::SetPrefetchRowCount(const uni::FunctionCallbackInf UNI_RETURN(scope, args, Undefined()); } +uni::CallbackType Connection::setNumberStringFormat(const uni::FunctionCallbackInfo& args) { + UNI_SCOPE(scope); + Connection* connection = ObjectWrap::Unwrap(args.This()); + REQ_STRING_ARG(0, fmt ); + String::Utf8Value uFmt(fmt); + + if (connection->m_numberStringFormat != NULL) delete connection->m_numberStringFormat; + + connection->m_numberStringFormat = (uFmt.length( ) != 0)? new std::string( *uFmt ):NULL; + UNI_RETURN(scope, args, Undefined()); +} + void Connection::closeConnection() { if(m_environment && m_connection) { try { @@ -317,9 +330,11 @@ void Connection::CreateColumnsFromResultSet(oracle::occi::ResultSet* rs, Execute case oracle::occi::OCCI_TYPECODE_DOUBLE: case oracle::occi::OCCI_TYPECODE_REAL: case oracle::occi::OCCI_TYPECODE_DECIMAL: + col->type = VALUE_TYPE_NUMBER; + break; case oracle::occi::OCCI_TYPECODE_INTEGER: case oracle::occi::OCCI_TYPECODE_SMALLINT: - col->type = VALUE_TYPE_NUMBER; + col->type = VALUE_TYPE_INUMBER; break; case oracle::occi::OCCI_TYPECODE_VARCHAR2: case oracle::occi::OCCI_TYPECODE_VARCHAR: @@ -373,6 +388,7 @@ row_t* Connection::CreateRowFromCurrentResultSetRow(oracle::occi::ResultSet* rs, case VALUE_TYPE_STRING: row->values.push_back(new string(rs->getString(colIndex))); break; + case VALUE_TYPE_INUMBER: case VALUE_TYPE_NUMBER: row->values.push_back(new oracle::occi::Number(rs->getNumber(colIndex))); break; @@ -623,13 +639,23 @@ Local Connection::CreateV8ObjectFromRow(ExecuteBaton* baton, vectorSet(String::New(col->name.c_str()), Number::New((double)(*v))); delete v; } break; + case VALUE_TYPE_NUMBER: + { + oracle::occi::Number* v = (oracle::occi::Number*)val; + if (baton->connection->getNumberStringFormat() == NULL) + obj->Set(String::New(col->name.c_str()), Number::New((double)(*v))); + else + obj->Set(String::New(col->name.c_str()), String::New(v->toText(baton->connection->getEnvironment(), baton->connection->getNumberStringFormat()->c_str()).c_str())); + delete v; + } + break; case VALUE_TYPE_DATE: { oracle::occi::Date* v = (oracle::occi::Date*)val; diff --git a/src/connection.h b/src/connection.h index b59d5be..72e5953 100644 --- a/src/connection.h +++ b/src/connection.h @@ -92,6 +92,7 @@ class Connection : public ObjectWrap { static uni::CallbackType Rollback(const uni::FunctionCallbackInfo& args); static uni::CallbackType SetAutoCommit(const uni::FunctionCallbackInfo& args); static uni::CallbackType SetPrefetchRowCount(const uni::FunctionCallbackInfo& args); + static uni::CallbackType setNumberStringFormat(const uni::FunctionCallbackInfo& args); static Persistent constructorTemplate; static void EIO_Execute(uv_work_t* req); static void EIO_AfterExecute(uv_work_t* req, int status); @@ -106,6 +107,7 @@ class Connection : public ObjectWrap { void setConnection(oracle::occi::Environment* environment, oracle::occi::Connection* connection); oracle::occi::Environment* getEnvironment() { return m_environment; } + std::string* getNumberStringFormat( ) { return m_numberStringFormat; } protected: // shared with Statement @@ -130,6 +132,7 @@ class Connection : public ObjectWrap { oracle::occi::Environment* m_environment; bool m_autoCommit; int m_prefetchRowCount; + std::string* m_numberStringFormat; }; #endif diff --git a/src/executeBaton.h b/src/executeBaton.h index 451c45b..b9034de 100644 --- a/src/executeBaton.h +++ b/src/executeBaton.h @@ -24,7 +24,8 @@ enum { VALUE_TYPE_TIMESTAMP = 6, VALUE_TYPE_CLOB = 7, VALUE_TYPE_BLOB = 8, - VALUE_TYPE_ARRAY = 9 + VALUE_TYPE_ARRAY = 9, + VALUE_TYPE_INUMBER = 10 }; struct column_t {