Skip to content

Commit 2877c8f

Browse files
committed
Add new metaData attribute giving query column names (#6)
1 parent b613bc7 commit 2877c8f

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

examples/select1.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ oracledb.getConnection(
5151
return;
5252
}
5353
console.log(result.rows);
54+
console.log(result.metaData);
5455
});
5556
});

src/njs/src/njsConnection.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,9 @@ void Connection::Async_AfterExecute(uv_work_t *req)
923923
result->Set(String::New("rows"), rowArray, v8::ReadOnly);
924924
result->Set(String::New("outBinds"),Undefined());
925925
result->Set(String::New("rowsAffected"), Undefined());
926+
result->Set(String::New("metaData"), Connection::GetMetaData(
927+
executeBaton->columnNames,
928+
executeBaton->numCols));
926929
break;
927930
case DpiStmtBegin :
928931
case DpiStmtDeclare :
@@ -931,13 +934,15 @@ void Connection::Async_AfterExecute(uv_work_t *req)
931934
result->Set(String::New("outBinds"),Connection::GetOutBinds(executeBaton),
932935
v8::ReadOnly);
933936
result->Set(String::New("rows"), Undefined());
937+
result->Set(String::New("metaData"), Undefined());
934938
break;
935939
default :
936940
result->Set(String::New("rowsAffected"),
937941
Integer::New((unsigned int) executeBaton->rowsAffected),
938942
v8::ReadOnly);
939943
result->Set(String::New("outBinds"),Undefined());
940944
result->Set(String::New("rows"), Undefined());
945+
result->Set(String::New("metaData"), Undefined());
941946
break;
942947
}
943948
argv[1] = result;
@@ -953,6 +958,35 @@ void Connection::Async_AfterExecute(uv_work_t *req)
953958
}
954959
}
955960

961+
/*****************************************************************************/
962+
/*
963+
DESCRIPTION
964+
Method to populate Metadata array
965+
966+
PARAMETERS:
967+
columnNames - Column Names
968+
numCols - number of columns
969+
970+
RETURNS:
971+
MetaData Handle
972+
*/
973+
Handle<Value> Connection::GetMetaData (std::string* columnNames,
974+
unsigned int numCols )
975+
{
976+
HandleScope scope;
977+
Handle<Array> metaArray = v8::Array::New(numCols);
978+
for(unsigned int i=0; i < numCols ; i++)
979+
{
980+
Local<Object> column = Object::New();
981+
column->Set(String::New("name"),
982+
String::New(columnNames[i].c_str(),
983+
(int) columnNames[i].length())
984+
);
985+
metaArray->Set(i, column);
986+
}
987+
return scope.Close(metaArray);
988+
}
989+
956990
/*****************************************************************************/
957991
/*
958992
DESCRIPTION

src/njs/src/njsConnection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ class Connection: public ObjectWrap
229229
static Handle<Value> GetOutBindArray ( std::vector<Bind*> binds, unsigned int outCount);
230230
static Handle<Value> GetOutBindObject (std::vector<Bind*> binds);
231231
static Handle<Value> GetRows (eBaton* executeBaton);
232+
static Handle<Value> GetMetaData (std::string* columnNames,
233+
unsigned int numCols);
232234
static Handle<Value> GetValue (short ind, unsigned short type, void* val,
233235
DPI_BUFLEN_TYPE len);
234236
static void UpdateDateValue ( eBaton *executeBaton );

0 commit comments

Comments
 (0)