Restricting fields selected by a query

When looping on a larger set of records by a query, a huge amount of memory may be allocated for each record. At the same time, a dbdict might be mapped to multiple tables on the RDBMS. Service Manager by default fetches the complete records and therefore selects against each of these tables.

In JavaScript implementations, you can use read-only file variables and restrict them to a set of fields only. Using this option will significantly reduce memory consumption, as well as select against tables not containing any of these fields.

Recommended implementation

var file = new SCFile( filename, SCFILE_READONLY);
var query = "true";
var fields = new Array();
fields = [ “number”, “status” ];
file.setFields( fields );

 

var rc = file.doSelect(query);

 

while (RC_SUCCESS == rc)
{
// Do something with file here
rc = file.getNext();
}

When using the setFields() function on a file variable that is not read-only, the query is executed against all fields and this message is written to the log file:

JS W SCFile.setFields called on non readonly SCFile("number", "status")- ignored