Skip to content

Commit

Permalink
Merge pull request joeferner#66 from raztus/timestampHandling
Browse files Browse the repository at this point in the history
Handle all Oracle Timestamp types and fix milliseconds
  • Loading branch information
joeferner committed Jul 31, 2013
2 parents 2d1fb22 + 47dbeed commit c00b157
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,10 @@ void Connection::CreateColumnsFromResultSet(oracle::occi::ResultSet* rs, std::ve
case oracle::occi::OCCI_TYPECODE_DATE:
col->type = VALUE_TYPE_DATE;
break;
//Use OCI_TYPECODE from oro.h because occiCommon.h does not re-export these in its TypeCode enum
case OCI_TYPECODE_TIMESTAMP:
case OCI_TYPECODE_TIMESTAMP_TZ: //Timezone
case OCI_TYPECODE_TIMESTAMP_LTZ: //Local Timezone
col->type = VALUE_TYPE_TIMESTAMP;
break;
case oracle::occi::OCCI_TYPECODE_BLOB:
Expand Down Expand Up @@ -485,7 +488,7 @@ Local<Date> OracleDateToV8Date(oracle::occi::Date* d) {
unsigned int month, day, hour, min, sec;
d->getDate(year, month, day, hour, min, sec);
Local<Date> date = Date::Cast(*Date::New(0.0));
CallDateMethod(date, "setUTCMilliSeconds", 0);
CallDateMethod(date, "setUTCMilliseconds", 0);
CallDateMethod(date, "setUTCSeconds", sec);
CallDateMethod(date, "setUTCMinutes", min);
CallDateMethod(date, "setUTCHours", hour);
Expand All @@ -497,12 +500,14 @@ Local<Date> OracleDateToV8Date(oracle::occi::Date* d) {

Local<Date> OracleTimestampToV8Date(oracle::occi::Timestamp* d) {
int year;
unsigned int month, day, hour, min, sec, fs;
unsigned int month, day, hour, min, sec, fs, ms;
d->getDate(year, month, day);
d->getTime(hour, min, sec, fs);
Local<Date> date = Date::Cast(*Date::New(0.0));
//occi always returns nanoseconds, regardless of precision set on timestamp column
ms = (fs / 1000000.0) + 0.5; // add 0.5 to round to nearest millisecond

CallDateMethod(date, "setUTCMilliSeconds", fs);
CallDateMethod(date, "setUTCMilliseconds", ms);
CallDateMethod(date, "setUTCSeconds", sec);
CallDateMethod(date, "setUTCMinutes", min);
CallDateMethod(date, "setUTCHours", hour);
Expand Down

0 comments on commit c00b157

Please sign in to comment.