Before using the API, the steps below have to be followed to set up the GXquery API.
For .Net
- In the KB where you will use the API, import the GXqueryAPI.xpz file that is located in the API folder (i.e. C:\GXquery40\API).
- In the KB's bin folder (i.e. C:\Models\MyKBName\CSharpModel\Web\bin) copy the files located in the CSharp folder of the API folder where GXquery is installed (i.e. C:\GXquery40\API\CSharp).
- In the Compiler flags property enter this string: /r:bin\Artech.GXquery.API.Common.dll
For Java
- In the KB where you will use the API, import the GXqueryAPI.xpz file that is located in the API folder (i.e. C:\GXquery40\API).
- In the KB's drivers folder (i.e. C:\Models\MyKBName\JavaModel\Web\drivers) copy the files located in the Java folder of the API folder where GXquery is installed (i.e. C:\GXquery40\API\Java).
First of all, to work with the GXquery API we need to establish, only once per web session, a connection with the server where GXquery 4.0 is installed. To do so, in the Start event of the first Web Panel that will be executed in the application, type the following code:
&GXquery.Connection.Host = "Host"
&GXquery.Connection.Port = 80
&GXquery.Connection.BaseUrl = "gxquery40"
&GXquery.Connection.Secure = False
&GXquerySession = &GXquery.StartSession(&RepositoryName, &UserName, &UserPassword, &Errors)
After that, the connection is established, and we are ready to use the API. In addition, you will have indicated the repository to use (if there is only one, as in this example, the variable is empty).
Note: Remember that the availability of the queries contained in the repository metadata depends on the user’s privileges.
It allows you to indicate GXquery the name of the metadata to use. For example:
&GXquerySession.SetMetadata("GXqueryAPI", &Errors)
It indicates that the metadata called "GXqueryAPI" is the one selected in the repository.
It allows you to indicate GXquery the name of the query contained in the metadata to be used. For example:
&GXqueryQuery = &GXquerySession.GetQueryByName("MyQuery", &Errors)
It indicates that the selected query is “MyQuery”.
It allows running the query. For example:
&QueryResult = &GXqueryQuery.Execute(&GXqueryRuntimeParameters, &OutputFormatId, &GXqueryExecuteQueryServiceOptions, &Errors)
If &Errors.Count > 0
Msg(&Errors.Item(1).Message)
Else
QueryViewer1.Visible = True
QueryViewer1.IsExternalQuery = True
QueryViewer1.ExternalQueryResult = &QueryResult
EndIf
The first line executes a query defined in GXquery and stores the result in &QueryResult. If no error occurs &QueryResult is then assigned to the QueryViewer control using the ExternalQueryResult property. Note that since the query is stored in GXquery, IsExternalQuery has to be set to True.
To see a full example, download the KB from TravelAgency (X Evolution 2).
The GXquery API for Java is available as of GXquery 4.0 Upgrade 3.