Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Why RB allways open dataviews

edited August 2007 in General
RB 10.06, BDS2006, Interbase, IBX

I have a Report designed at runtime, with a query assigned by SQL.Text
directly. Well, i have created and event handler, in the application
ppReport for the event BeforeOpenDataPipelines, to assign parameters
before open que query.

Well, i'm doing a trace, and allways before the call to the event, RB
opens all the querys, then i edit the parameters, assign them, and RB
opens the query again.

How can i prevent for not open the querys, because may be a waste of
time opening heavy querys for doing nothing, because the querys has no
parameters.

This is a trace of what RB does before call the event
BeforeOpenDataPipelines, and as you can see all the querys are opened.

14/08/2007 9:55:08
[Application: Test 6.0]
IBTransaction: [Commit (Hard commit)]
14/08/2007 9:55:08
[Application: Test 6.0]
: [Prepare] select *
from peticion
where Fecha >= :Fecha_Consulta

Plan: PLAN (PETICION INDEX (PETICION_IDX0))
14/08/2007 9:55:08
[Application: Test 6.0]
: [Execute] select *
from peticion
where Fecha >= :Fecha_Consulta

FECHA_CONSULTA =
14/08/2007 9:55:08
[Application: Test 6.0]
: [Fetch] select *
from peticion
where Fecha >= :Fecha_Consulta

SEOFReached
14/08/2007 9:55:08
[Application: Test 6.0]
: [Prepare] select *
from peticion
where Fecha >= :Fecha_Consulta

Plan: PLAN (PETICION INDEX (PETICION_IDX0))



--

Comments

  • edited August 2007

    That information is not detailed enough to determine why the dataviews are
    opened.

    Try adding Delphi\Lib\Debug and RBuilder\Source to your Delphi library path.
    Then trace in the debugger and put some stops daIBExpress or ppDBPipeline at
    the point where the datapipeline is opened or the query is set to active.
    When the debugger stops, then examine the call stack.


    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited August 2007
    Nard Moseley (Digital Metaphors) wrote:


    Ok, i have done it and i see where is the problem.

    Before print the report, i want to get the parameters of the query to
    show the end user a form requesting the parameters values, then i get
    the sqlTEXT

    sSQL := TdaIBXQueryDataView(TppDBPipeline( ppInforme.DataPipeline
    ).DataView).SQL.SQLText.Text;

    when i call this code is executed

    function TdaSQL.GetSQLText: TStrings;
    begin

    Result := FSQLText;

    if (csWriting in ComponentState) or (csReading in ComponentState) or
    (csLoading in ComponentState) then Exit;

    if (FSQLOutOfSync) then
    if FEditSQLAsText then
    CreateFieldsFromSQL <=============================

    call to

    TdaSQL.CreateFieldsFromSQL;

    calls to

    TdaSQL.GetFieldsForSQL(aSQL: TStrings; aList: TList): Boolean;

    and calls to

    procedure TdaIBXDataSet.GetFieldsForSQL(aList: TList; aSQL: TStrings);
    var
    lQuery: TIBQuery;
    lQueryField: TField;
    lField: TppField;
    liIndex: Integer;
    begin
    aList.Clear;

    {create a temporary IB query}
    lQuery := TIBQuery.Create(Self);

    try

    {assign databae and SQL properties}
    lQuery.Database := TIBDatabase(Database);
    lQuery.SQL := aSQL;

    {set query to active}
    lQuery.Active := True;

    {create a TppField object for each field in the query}
    for liIndex := 0 to lQuery.FieldCount - 1 do
    begin
    lQueryField := lQuery.Fields[liIndex];

    lField := TppField.Create(nil);

    lField.FieldName := lQueryField.FieldName;
    lField.FieldAlias := lQueryField.DisplayLabel;
    lField.FieldLength := lQueryField.Size;
    lField.DataType := ppConvertFieldType(lQueryField.DataType);
    lField.DisplayWidth := lQueryField.DisplayWidth;

    aList.Add(lField);
    end;

    finally
    lQuery.Free;

    end;

    end; {procedure, GetFieldsForSQL}

    this method, creates a copy of the query, open it and read all fields,
    but i only have tried to get the sqlText, not opening the dataset and
    do all process.

    Because is a copy the beforeopendatapipelines event is not fired.

    Is there anyway to recover the SQL text without having to do this heavy
    process.



    --
  • edited August 2007

    - Open daSQL.pas and find the method, TdaSQL.Loaded

    - Add the following code to the bottom of the TdaSQL.Loaded method...

    if FEditSQLAsText then
    FSQLOutOfSync := False;

    - Test and post a message here with the results. With the above code in
    place, when the DataView loads, it will initializes itself such that the
    CreateFieldsFromSQL code will not be fired.


    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited August 2007
    Nard Moseley (Digital Metaphors) wrote:


    The same problem, because after that event, FSQLOutOfSync is returned
    to true in the event

    TdaSQL.SetSession(aSession: TdaSession);

    that is called from TdaQueryDataView.Loaded;

    and anyway TdaQueryDataView.Loaded, sets FSQLOutOfSync to true again.

    --
  • edited August 2007

    The TdaQueryDataView has an FSQLOutOfSync, but that is not related to
    TdaSQL's FSQLOutOfSync. Two different classes.

    The SetSession, calls Modification. You could try modifying the Modification
    method like this..

    if not FEditSQLAsText then
    FSQLOutOfSync := True;

    I don't know if that will work or not. I reviewd the code more and overall,
    it looks like the TdaSQL class is trying to make sure that it knows when to
    regenerate field info and so there are many places it can set SQLOutOfSync
    to true.

    --
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.