SetCallback(Module: IMetabaseObjectDescriptor; ForeClass: String);
Module. Description of the unit where the class is implemented that implements methods of the ISQLCallback interface.
ForeClass. Name of the class used for handling data extraction query generation.
The SetCallback method sets a handler of data extraction query generation for a data source.
Specify name of the class that implements methods of the ISQLCallback interface in the ForeClass parameter.
To reset the specified handler, set the Module parameter to Null, and the ForeClass to "".
Executing the example requires that the repository contains a standard cube with STD_CUBE identifier and a unit with the CUBE_CALLBACK identifier. The SQLCallback class is implemented in the unit.
Add links to the Cubes and Metabase system assemblies.
Sub UserProc;
Var
MB: IMetabase;
Cube: IStandardCube;
CubeDataset: IStandardCubeDataset;
Begin
MB := MetabaseClass.Active;
Cube := MB.ItemById("STD_CUBE").Edit As IStandardCube;
CubeDataset := Cube.Destinations.Item(0).Datasets.Item(0);
CubeDataset.SetCallback(MB.ItemById("CUBE_CALLBACK"), "SQLCallback");
(Cube As IMetabaseObject).Save;
End Sub UserProc;
Public Class SQLCallback: Object, ISQLCallback
Sub BeforeConstruction(Components: ISQLComponents);
Var
i: Integer;
Select_, From_, Where, GroupBy, Aggregation, OrderBy: String;
Begin
Debug.WriteLine("Select_: " + Components.Select_);
Debug.WriteLine("From_: " + Components.From_);
Debug.WriteLine("Where: " + Components.Where);
Debug.WriteLine("GroupBy: " + Components.GroupBy);
Debug.WriteLine("Aggregation: " + Components.Aggregation);
Debug.WriteLine("OrderBy: " + Components.OrderBy);
Debug.WriteLine("SubQuery: " + Components.SubQuery.ToString);
Debug.WriteLine("ConditionCount: " + Components.ConditionCount.ToString);
For i := 0 To Components.ConditionCount - 1 Do
Debug.WriteLine("Condition " + i.ToString + " : " + Components.Condition(i).Condition);
End For;
Debug.WriteLine("TableAlias: " + Components.TableAlias);
//---Modified parts of query
//Select_ := Components.Select_;
//...
//...Modification of Select_
//...
//Components.Select_ := Select_;
//From_ := Components.From_;
//...
//...Modification of From_
//...
//Components.From_ := From_;
//Where := Components.Where;
//...
//...Modification of Where
//...
//Components.Where := Where;
//GroupBy := Components.GroupBy;
//...
//...Modification of GroupBy
//...
//Components.GroupBy := GroupBy;
//Aggregation := Components.Aggregation;
//...
//...Modification of Aggregation
//...
//Components.Aggregation := Aggregation;
//OrderBy := Components.OrderBy;
//...
//...Modification of OrderBy
//...
//Components.OrderBy := OrderBy;
End Sub BeforeConstruction;
Sub AfterConstruction(Var SQL: String);
Begin
//If required, modification of final query text in SQL variable
Debug.WriteLine("AFTER: " + SQL);
End Sub AfterConstruction;
End Class SQLCallback;
On executing the example, the handler of query generation is set for the first cube data source.
See also: