| Stonefield Query SDK |
| SQProxy Object |
SQProxy is a lightweight COM object included in SQProxy.EXE (which means, of course, that you need to distribute and register that EXE if you want to use this object on your users' systems). It acts as a manager for the Stonefield Query application so it can be started and kept in memory, without displaying any user interface, meaning the startup tasks are only performed once rather than on every report run.
SQProxy has a single method: LoadProject. After instantiating the SQProxy object, call its LoadProject method to load the specified project. This method accepts four parameters: the path for the project files, the user name, the password, and the name of the data source to query against. The last three parameters are optional. Don't pass the user name and password if you want the user to be able to open the Stonefield Query application at the same time as using SQProxy in your application. If you don't pass the data source name, the data source used last time Stonefield Query was run is used. Once you've called LoadProject, you can reference its SQApplication member, which is an instance of the Stonefield Query Application object, giving you full access to all of its members.
In addition to SQApplication, SQProxy has five other properties:
Here's an example that instantiates SQProxy, loads the Northwind project, and runs the Customers and History reports to a couple of PDF files:
loQuery = createobject('SQProxy.SQProxy')
* Load the project. if we can't, display the error code
* (see the Command-Line Interface topic for a list of error codes).
try
loQuery.LoadProject('\MyProjects\Northwind')
catch
messagebox(loQuery.ErrorCode)
endtry
* If we loaded the project, try to run a couple of reports.
if loQuery.ProjectLoaded
try
llSuccess = loQuery.SQApplication.ReportEngine.RunReportToFile('Customers', ;
'\MyReports\customers.pdf')
if not llSuccess
messagebox(loQuery.SQApplication.ReportEngine.ErrorMessage)
endif
llSuccess = loQuery.SQApplication.ReportEngine.RunReportToFile('History', ;
'\MyReports\history.pdf')
if not llSuccess
messagebox(loQuery.SQApplication.ReportEngine.ErrorMessage)
endif
* An error occurred, so display the error message.
catch
messagebox(loQuery.SQApplication.ErrorMessage)
endtry
endifHere's an example that shows adding an additional filter condition to the report by adding a Filter item to the Parameters collection:
loQuery = createobject('SQProxy.SQProxy')
* Create some XML for the new filter condition and add it as a parameter.
text to lcConditions noshow
<conditions>
<condition>
<field>Customers.Country</field>
<operator>equals</operator>
<value>Germany</value>
</condition>
</conditions>
endtext
loQuery.SQApplication.Parameters.AddItem('filter', lcConditions)
* Load the project. if we can't, display the error code
try
loQuery.LoadProject('\MyProjects\Northwind')
catch
messagebox(loQuery.ErrorCode)
endtry
* If we loaded the project, run a report.
if loQuery.ProjectLoaded
try
loQuery.SQApplication.ReportEngine.RunReportToFile('Customers', ;
'\SomeFolder\customers.pdf')
* An error occurred, so display the error message.
catch
messagebox(loQuery.SQApplication.ErrorMessage)
endtry
endifSee the ReportEngine Object help topic for methods available to run reports.
Note that if an error occurs when running a report using SQProxy, an error is raised in the calling application, so you should use error handing in your applications using SQProxy.
If you want to use SQProxy in .Net applications, see the Using SQProxy in .Net Applications help topic.
| Last Updated: 03/11/10 |