SetCallback(Module: IMetabaseObjectDescriptor; ForeClass: String);
SetCallback(Module: Prognoz.Platform.Interop.Metabase.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;
Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Db;
Imports Prognoz.Platform.Interop.Metabase;
Public Sub Main(Params: StartParams);
Var
MB: IMetabase;
Cube: IStandardCube;
CubeDataset: IStandardCubeDataset;
Begin
MB := Params.Metabase;
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;
Public Class SQLCallback: ISQLCallback
Public Sub BeforeConstruction(Components: ISQLComponents);
Var
i, l: Integer;
Select_, From_, Where, GroupBy, Aggregation, OrderBy: String;
Begin
System.Diagnostics.Debug.WriteLine("Select_: " + Components.@Select);
System.Diagnostics.Debug.WriteLine("From_: " + Components.From);
System.Diagnostics.Debug.WriteLine("Where: " + Components.Where);
System.Diagnostics.Debug.WriteLine("GroupBy: " + Components.GroupBy);
System.Diagnostics.Debug.WriteLine("Aggregation: " + Components.Aggregation);
System.Diagnostics.Debug.WriteLine("OrderBy: " + Components.OrderBy);
System.Diagnostics.Debug.WriteLine("SubQuery: " + Components.SubQuery.ToString());
System.Diagnostics.Debug.WriteLine("ConditionCount: " + Components.ConditionCount.ToString());
l := Components.ConditionCount - 1;
For i := 0 To l Do
System.Diagnostics.Debug.WriteLine("Condition " + i.ToString() + " : " + Components.Condition[i].Condition);
End For;
System.Diagnostics.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;
Public Sub AfterConstruction(Var SQL: String);
Begin
//If required, modification of final query text in SQL variable
System.Diagnostics.Debug.WriteLine("AFTER: " + SQL);
End Sub;
End Class;
On executing the example, the handler of query generation is set for the first cube data source.
See also: