Running the example code to return metadata and rows for a db2 table. Trying a database table with the db2.getColumnName() functions which work fine, but when using the db2.fetch to return a table row it just returns the string.
HB.engine.elapsedRunTimeLimit = 120 * 1000 * 1000;
var common = require('common', 'hbutils');
var debugging = require('debugging', 'hbutils');
var writeLog = require('writeWSLog','pyrlutil');
require('JSON', 'hbutils');
var cics = new Cics();
//HB write to MF section
HB.engine.install( "HBR$DJSN" );
var jsonParse = new HB.Json();
HB.engine.install( "HBR$DDB2" );
var db2 = new HB.Db2();
try{
writeln("Loading HB.DB2");
//Create a DB2 object
// SQL statement to be executed.
var sql = "Select * from LFADBA1.GRO_RTE_ADJ_STATE"; //DOIS01P.RTE_RESEQ DOIS01P.RTE_ADJ_STATE LFADBA1.GRO_RTE_ADJ_STATE
// SQL statements must be prepare'd before they can be execute'd
num = db2.prepare( sql );
writeln( "Number of rows from the SQL statment: ", num );
// Open the cursor
db2.open();
//
//
//
writeln( "Number of columns : ", db2.columnCount );
//
// Meta properties of the column
//
writeln( "Name : '", db2.getColumnName( 0 ), "'" );
writeln( "Label : '", db2.getColumnLabel( 0 ), "'" );
writeln( "Type : ", db2.getColumnType( 0 ) );
// Fetch the data for the column
//
// If there were multiple rows returned, you would keep calling fetch
// until an exception was thrown or loop the fetch based on the return
// value from prepare
//
// fetch returns code in JSON or XML?
var str = db2.fetch();
writeln(str);
} catch (e) {
writeln('Error while processing: ' + e);
for(i in e) {
writeln(i," = ", e[i]);
}
}
Release : 8.0
The script using fetch like a property instead of of method.
Change the highlighted lines
var str = db2.fetch();
writeln(str);
to
db2.fetch();
writeln(db2.getColumnData(0));