The DataEngine.BeforeResultSetRetrieved script allows you to perform any necessary tasks just before the result set is retrieved from the database.

You can access the running report object through the global variable Report.

Parameters
A reference to the Stonefield Query Application object and the SQL statement Stonefield Query created for the report.

Return Value
True if the result set retrieval should continue or False if not.

Example
Suppose a report needs an additional calculation done before the result set is retrieved from the database. The result of this calculation could be stored in a property of the Application object that a Select script for a table uses.

Visual FoxPro

lparameters toApplication as SQApplication, tcSelect
local loDatabase as Database, lcSelect, llReturn
loDatabase = toApplication.DataEngine.Databases.GetMainDatabase()
lcSelect = 'select TAXRATE from CONSTANTS'
llReturn = not empty(loDatabase.ExecuteSQLStatement(lcSelect, ;
  '', 'CONSTANTS'))
if llReturn
  toApplication.AddProperty('TaxRate', CONSTANTS.TAXRATE)
endif
return llReturn

VBScript

function Main(Application, SelectStatement)
dim Database, XMLDOM
set Database = Application.DataEngine.Databases.GetMainDatabase()
SelectStmt = "select TAXRATE from CONSTANTS"
Results = Database.ExecuteSQLStatement(SelectStmt)
set XMLDOM = createobject("MSXML.DOMDocument")
XMLDOM.ASync = False
XMLDOM.LoadXML(Results)
TaxRate = XMLDOM.selectSingleNode("/DataSet/_resultset/taxrate").Text
Application.AddProperty("TaxRate", TaxRate)
Main = True
end function

JavaScript

function Main(Application, SelectStatement) {
var Database, SelectStmt, Results, XMLDOM, TaxRate ;
Database = Application.DataEngine.Databases.GetMainDatabase() ;
SelectStmt = 'select TAXRATE from CONSTANTS' ;
Results = Database.ExecuteSQLStatement(SelectStmt) ;
XMLDOM = new ActiveXObject('MSXML.DOMDocument') ;
XMLDOM.ASync = false ;
XMLDOM.LoadXML(Results) ;
TaxRate = XMLDOM.selectSingleNode('/DataSet/_resultset/taxrate').Text ;
Application.AddProperty('TaxRate', TaxRate) ;
return true ;
}

C#

The method in this script must be named DataEngine_BeforeResultSetRetrieved.

public static bool DataEngine_BeforeResultSetRetrieved(SFQApplication sfqApplication, string selectStatement)
{	
  bool result = false;

  Database database = sfqApplication.DataEngine.Databases.GetMainDatabase();
  string selectStmt = "select TAXRATE from CONSTANTS";

  string resultSet = database.ExecuteSQLStatement(selectStmt);

  XmlDocument doc = new XmlDocument();
  doc.LoadXml(resultSet);

  XmlNode node = doc.SelectSingleNode("/DataSet/_resultset/@taxrate");

  if (node != null)
  {
    string taxRate = node.Value;
    sfqApplication.AddProperty("TaxRate", taxRate);

    result = true;
  }

  return result;
}

VB.NET

The method in this script must be named DataEngine_BeforeResultSetRetrieved.

public shared function DataEngine_BeforeResultSetRetrieved(sfqApplication as SFQApplication, selectStatement as string) as Boolean

  Dim result As Boolean = False

  Dim database As Database = sfqApplication.DataEngine.Databases.GetMainDatabase()
  Dim selectStmt As String = "select TAXRATE from CONSTANTS"

  Dim resultSet As String = database.ExecuteSQLStatement(selectStmt)

  Dim doc As XmlDocument = New XmlDocument()
  doc.LoadXml(resultSet)

  Dim node As XmlNode = doc.SelectSingleNode("/DataSet/_resultset/@taxrate")

  If (Not node Is Nothing) Then
    Dim taxRate As String = node.Value
    sfqApplication.AddProperty("TaxRate", taxRate)

    result = True
  End If

  Return result

End Function

See also

DataEngine Object | DataEngine.AfterResultSetRetrieved | Scripts

© Stonefield Software Inc., 2023 • Updated: 06/06/16
Comment or report problem with topic