Skip to content

setNumberStringFormat introduction #245

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

Open
wants to merge 1 commit 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
32 changes: 29 additions & 3 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void Connection::Init(Handle<Object> 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);

Expand All @@ -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() {
Expand Down Expand Up @@ -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<Connection>(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 {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -623,13 +639,23 @@ Local<Object> Connection::CreateV8ObjectFromRow(ExecuteBaton* baton, vector<colu
delete v;
}
break;
case VALUE_TYPE_NUMBER:
case VALUE_TYPE_INUMBER:
{
oracle::occi::Number* v = (oracle::occi::Number*)val;
obj->Set(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;
Expand Down
3 changes: 3 additions & 0 deletions src/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionTemplate> constructorTemplate;
static void EIO_Execute(uv_work_t* req);
static void EIO_AfterExecute(uv_work_t* req, int status);
Expand All @@ -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
Expand All @@ -130,6 +132,7 @@ class Connection : public ObjectWrap {
oracle::occi::Environment* m_environment;
bool m_autoCommit;
int m_prefetchRowCount;
std::string* m_numberStringFormat;
};

#endif
3 changes: 2 additions & 1 deletion src/executeBaton.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down