getValues([Options][, Callback]) Method
Gets an object with the column names and values of the current row.
Parameters
|
Type |
Name |
Description |
|---|---|---|
|
Object |
options |
Specifies the optional object containing the options for defining the representation of rows in the result. |
|
Function |
callback |
Specifies the optional callback function. |
Returns
If the options parameter is specified as {asArray: true}, this method returns an array consisting of all column values for the current row. Otherwise, it returns an object that consists of a set of column names and value pairs for the current row. If multiple columns have the same column name, the property name for the second and subsequent columns with the same column name are "<column-name>:<n>" where <n> is a number starting from 1.
If no callback is specified, then the result is returned.
Remarks
This method can be synchronous or asynchronous. Specify a callback function to use this method asynchronously.
function(err, result){
};
Example
The following example shows how to use the getValue method synchronously:
var hana = require('@sap/hana-client')
var conn = hana.createConnection();
conn.connect("serverNode=myserver:30015;uid=system;pwd=manager");
var stmt = conn.prepare("select * from M_SERVICES");
var resultset = stmt.executeQuery();
var numcolumns = resultset.getColumnCount();
while(resultset.next()) {
var row = resultset.getValues({asArray: true});
for(var i = 0; i < row.length; i++) {
console.log("column %d: ", i+1, row[i]);
}
console.log();
}
resultset.close();
The following example shows how to use the getValue method asynchronously:
var hana = require('@sap/hana-client')
var conn = hana.createConnection();
conn.connect("serverNode=myserver:30015;uid=system;pwd=manager");
var stmt = conn.prepare("select * from M_SERVICES");
var resultset = stmt.executeQuery();
processrows(resultset);
function processrows(resultset) {
resultset.next(function(err, result) {
if(err) {
console.log("next error", err);
} else if(result) {
resultset.getValues({asArray: true}, function(err, row) {
if(err) {
console.log("getValues error", err);
} else {
for(var i = 0; i < row.length; i++) {
console.log("column %d: ", i+1, row[i]);
}
console.log();
processrows(resultset);
}
});
} else {
resultset.close(function(err) {
// done processing the result set
});
}
});
}