Permalink
Browse files

handles nulls

  • Loading branch information...
1 parent 2230bd8 commit 8e333354434cc4b62b540baffafc52218f5af614 @joeferner committed Dec 22, 2011
Showing with 117 additions and 68 deletions.
  1. +76 −68 src/connection.cpp
  2. +41 −0 tests/integration.js
View
@@ -154,30 +154,34 @@ row_t* Connection::CreateRowFromCurrentResultSetRow(oracle::occi::ResultSet* rs,
int colIndex = 1;
for (std::vector<column_t*>::iterator iterator = columns.begin(), end = columns.end(); iterator != end; ++iterator, colIndex++) {
column_t* col = *iterator;
- switch(col->type) {
- case VALUE_TYPE_STRING:
- row->values.push_back(new std::string(rs->getString(colIndex)));
- break;
- case VALUE_TYPE_NUMBER:
- row->values.push_back(new oracle::occi::Number(rs->getNumber(colIndex)));
- break;
- case VALUE_TYPE_DATE:
- row->values.push_back(new oracle::occi::Date(rs->getDate(colIndex)));
- break;
- case VALUE_TYPE_TIMESTAMP:
- row->values.push_back(new oracle::occi::Timestamp(rs->getTimestamp(colIndex)));
- break;
- case VALUE_TYPE_CLOB:
- row->values.push_back(new oracle::occi::Clob(rs->getClob(colIndex)));
- break;
- case VALUE_TYPE_BLOB:
- row->values.push_back(new oracle::occi::Blob(rs->getBlob(colIndex)));
- break;
- default:
- std::ostringstream message;
- message << "CreateRowFromCurrentResultSetRow: Unhandled type: " << col->type;
- throw NodeOracleException(message.str());
- break;
+ if(rs->isNull(colIndex)) {
+ row->values.push_back(NULL);
+ } else {
+ switch(col->type) {
+ case VALUE_TYPE_STRING:
+ row->values.push_back(new std::string(rs->getString(colIndex)));
+ break;
+ case VALUE_TYPE_NUMBER:
+ row->values.push_back(new oracle::occi::Number(rs->getNumber(colIndex)));
+ break;
+ case VALUE_TYPE_DATE:
+ row->values.push_back(new oracle::occi::Date(rs->getDate(colIndex)));
+ break;
+ case VALUE_TYPE_TIMESTAMP:
+ row->values.push_back(new oracle::occi::Timestamp(rs->getTimestamp(colIndex)));
+ break;
+ case VALUE_TYPE_CLOB:
+ row->values.push_back(new oracle::occi::Clob(rs->getClob(colIndex)));
+ break;
+ case VALUE_TYPE_BLOB:
+ row->values.push_back(new oracle::occi::Blob(rs->getBlob(colIndex)));
+ break;
+ default:
+ std::ostringstream message;
+ message << "CreateRowFromCurrentResultSetRow: Unhandled type: " << col->type;
+ throw NodeOracleException(message.str());
+ break;
+ }
}
}
return row;
@@ -267,50 +271,54 @@ Local<Object> Connection::CreateV8ObjectFromRow(ExecuteBaton* baton, row_t* curr
for (std::vector<column_t*>::iterator iterator = baton->columns.begin(), end = baton->columns.end(); iterator != end; ++iterator, colIndex++) {
column_t* col = *iterator;
void* val = currentRow->values[colIndex];
- switch(col->type) {
- case VALUE_TYPE_STRING:
- {
- std::string* v = (std::string*)val;
- obj->Set(String::New(col->name.c_str()), String::New(v->c_str()));
- delete v;
- }
- break;
- case VALUE_TYPE_NUMBER:
- {
- 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_DATE:
- {
- oracle::occi::Date* v = (oracle::occi::Date*)val;
- obj->Set(String::New(col->name.c_str()), OracleDateToV8Date(v));
- }
- break;
- case VALUE_TYPE_TIMESTAMP:
- {
- oracle::occi::Timestamp* v = (oracle::occi::Timestamp*)val;
- obj->Set(String::New(col->name.c_str()), OracleTimestampToV8Date(v));
- }
- break;
- case VALUE_TYPE_CLOB:
- {
- oracle::occi::Clob* v = (oracle::occi::Clob*)val;
- obj->Set(String::New(col->name.c_str()), Null()); // TODO: handle clobs
- }
- break;
- case VALUE_TYPE_BLOB:
- {
- oracle::occi::Blob* v = (oracle::occi::Blob*)val;
- obj->Set(String::New(col->name.c_str()), Null()); // TODO: handle blobs
- }
- break;
- default:
- std::ostringstream message;
- message << "CreateV8ObjectFromRow: Unhandled type: " << col->type;
- throw NodeOracleException(message.str());
- break;
+ if(val == NULL) {
+ obj->Set(String::New(col->name.c_str()), Null());
+ } else {
+ switch(col->type) {
+ case VALUE_TYPE_STRING:
+ {
+ std::string* v = (std::string*)val;
+ obj->Set(String::New(col->name.c_str()), String::New(v->c_str()));
+ delete v;
+ }
+ break;
+ case VALUE_TYPE_NUMBER:
+ {
+ 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_DATE:
+ {
+ oracle::occi::Date* v = (oracle::occi::Date*)val;
+ obj->Set(String::New(col->name.c_str()), OracleDateToV8Date(v));
+ }
+ break;
+ case VALUE_TYPE_TIMESTAMP:
+ {
+ oracle::occi::Timestamp* v = (oracle::occi::Timestamp*)val;
+ obj->Set(String::New(col->name.c_str()), OracleTimestampToV8Date(v));
+ }
+ break;
+ case VALUE_TYPE_CLOB:
+ {
+ oracle::occi::Clob* v = (oracle::occi::Clob*)val;
+ obj->Set(String::New(col->name.c_str()), Null()); // TODO: handle clobs
+ }
+ break;
+ case VALUE_TYPE_BLOB:
+ {
+ oracle::occi::Blob* v = (oracle::occi::Blob*)val;
+ obj->Set(String::New(col->name.c_str()), Null()); // TODO: handle blobs
+ }
+ break;
+ default:
+ std::ostringstream message;
+ message << "CreateV8ObjectFromRow: Unhandled type: " << col->type;
+ throw NodeOracleException(message.str());
+ break;
+ }
}
}
return obj;
View
@@ -134,5 +134,46 @@ exports['IntegrationTest'] = nodeunit.testCase({
test.done();
});
});
+ },
+
+ "datatypes null": function(test) {
+ var self = this;
+ self.connection.execute(
+ "INSERT INTO datatype_test "
+ + "(tvarchar2, tnvarchar2, tchar, tnchar, tnumber, tdate, ttimestamp, tclob, tnclob, tblob) VALUES "
+ + "(:1, :2, :3, :4, :5, :6, :7, :8, :9, :10) RETURNING id INTO :11",
+ [
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ new oracle.OutParam()
+ ],
+ function(err, results) {
+ if(err) { console.error(err); return; }
+ test.ok(results.returnParam > 0);
+
+ self.connection.execute("SELECT * FROM datatype_test", [], function(err, results) {
+ if(err) { console.error(err); return; }
+ test.equal(results.length, 1);
+ test.equal(results[0]['TVARCHAR2'], null);
+ test.equal(results[0]['TNVARCHAR2'], null);
+ test.equal(results[0]['TCHAR'], null);
+ test.equal(results[0]['TNCHAR'], null);
+ test.equal(results[0]['TNUMBER'], null);
+ test.equal(results[0]['TDATE'], null);
+ test.equal(results[0]['TTIMESTAMP'], null);
+ test.equal(results[0]['TCLOB'], null);
+ test.equal(results[0]['TNCLOB'], null);
+ test.equal(results[0]['TBLOB'], null);
+ test.done();
+ });
+ });
}
});

0 comments on commit 8e33335

Please sign in to comment.