For performance reasons, you may want a script to create some temporary data the first time it's required. That way, on subsequent requests, the data exists and doesn't have to be recreated. An example is a calculated field that looks up some information in a static table. Since the contents of that table change rarely, better performance is achieved if the table is read from the data source into memory and accessed there.

However, one drawback to this approach is that the user may change data sources if the Allow Multiple Data Sources configuration setting is True. In that case, the temporary data may not be valid for the newly selected data source, and should be recreated the next time it's required. You can close and destroy the temporary data in the DataEngine.AfterDataEnvironmentCleared script.

Parameters
A reference to the Stonefield Query Application object.

Return Value
Any value (Stonefield Query ignores the return value).

Example

Visual FoxPro
Here's an example that closes the _LOOKUPS cursor if it's open (presumably, this cursor was opened by another script). This isn't strictly required because Stonefield Query closes all opened cursors when the data source is changed, but is shown here for completeness.

lparameters toApplication as SQApplication
if used('_LOOKUPS')
  use in _LOOKUPS
endif

VBScript
This example tells Stonefield Query to blank the Application.Categories property when the data source is changed (this property is created and filled with information by another script).

function Main(Application)
XML = "Test"
on error resume next
XML = Application.Categories
on error goto 0
if XML <> "Test" then
  Application.Categories = ""
end if
end function

JavaScript
This example tells Stonefield Query to blank the Application.Categories property when the data source is changed (this property is created and filled with information by another script).

function Main(Application) {
try {
  Application.Categories = '' ;
}
catch(e) {
}
}

C#
This example tells Stonefield Query to blank the SFQApplication.Categories property when the data source is changed (this property is created and filled with information by another script).

Please note that the method in this script must be named DataEngine_AfterDataEnvironmentCleared.

public static void DataEngine_AfterDataEnvironmentCleared(SFQApplication sfqApplication)
{	
  try
  {
    sfqApplication.SetProperty("Categories", "");
  }
  catch(Exception e)
  {
    // If we encounter an exception it probably means that the Property does not exist.
    // In that case we can just continue on

    // Uncomment the line below to see the exception details		
    //MessageBox.Show(e.Message, "Error Occurred");
  }
}

VB.NET
This example tells Stonefield Query to blank the SFQApplication.Categories property when the data source is changed (this property is created and filled with information by another script).

Please note that the method in this script must be named DataEngine_AfterDataEnvironmentCleared.

public shared function DataEngine_AfterDataEnvironmentCleared(sfqApplication as SFQApplication)
  as Boolean
  Try
    sfqApplication.SetProperty("Categories", "")
  Catch e As Exception
    ' If we encounter an exception it probably means that the Property does not exist.
    ' In that case we can just continue on

    ' Uncomment the line below to see the exception details		
    ' MessageBox.Show(e.Message, "Error Occurred")
  End Try
  Return True
End Function

See also

Scripts

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