Under some conditions, you may need to execute some custom code when Stonefield Query Studio opens a project or when the data dictionary is created or updated from a data source. To execute custom code, create a text file called SQCONFIG.SQS in the Data subdirectory of the Stonefield Query program folder. Edit this file using any text editor (not a word processor, such as Microsoft Word, which stores binary files, but an editor such as Notepad that stores text files). This file can contain any code you wish, but it must be Visual FoxPro code. This code must accept three parameters. The first parameter is a string representing the "mode" Stonefield Query Studio is in. The possible values are:

  • STARTUP: this string is passed when Stonefield Query Studio is started.

  • OPENMETADATA: this string is passed when a project is opened. Any code handling this string is executed before the TreeView displays the configuration information for the project.

  • PREFILLCOLLECTIONS: this string is passed just before the table, field, and relation collections are filled when the data dictionary is created or updated from a data source.

  • POSTFILLCOLLECTIONS: this string is passed after the table, field, and relation collections are filled when the data dictionary is created or updated from a data source.

  • BEFOREMODIFYFIELD: this string is passed before any properties of an existing field in the data dictionary are changed to new values read from the database.

  • BEFORESAVEFIELD: this string is passed just before a field is saved in the data dictionary.

  • BEFORESAVETABLE: this string is passed just before a table is saved in the data dictionary.

  • GETTABLENAME: this string is passed when a table name is being read from the database.

The second parameter is a reference to either Stonefield Query Studio engine (in the case of STARTUP or OPENMETADATA) or a Discover object, which is responsible for filling the data dictionary. There are several exposed properties for the Discover object, including:

  • cType: the type of data source; either "ODBC" or "ADO."

  • nHandle: the ODBC connection handle for the data source if cType is "ODBC."

  • oConnection: a reference to the ADO Connection object used to access the data source if cType is "ADO."

  • cDatabase: the name of the database.

  • oData: a reference to an SFDataEngine object, which has oDatabaseCollection, oCursorCollection, oFieldsCollection, and oRelationCollection members.

The third parameter is only passed if the first parameter is "BEFORESAVEFIELD" or "BEFORESAVETABLE." In those cases, this parameter is a reference to a Field (in the case of "BEFORESAVEFIELD") or Table (in the case of "BEFORESAVETABLE") object, which contain information about the field or table.