Icon View Incident Report

Serious Serious
Reported By: Michael Haralabos
Reported On: 3/13/2002
For: Version 3.07 Build 1
# 1059 Modifying a Field in a Live Result Set that is Used for Another Calculated Field Can Cause NULLs

Example below:

{ This 
doesn't work }

procedure TMainForm.Button1Click(Sender: TObject);
begin
  with MainForm, Query do
  begin

    with Sql do
    begin
      Clear;
      Add('Select 
RECORDID, NAME, ' +
          'EXTRACT(DAY FROM CAST(START AS DATE)) 
AS DAY, START, FINISH,' +
          '((FINISH - START) / 3600000) as 
HOURS');
      // The Start & Finish fields are defined after the "Extract"
      // with the result the "Finish" field not to appear on DBGrid
      Add('From 
Data');
      Add('Where CAST(START AS DATE) Between :StartDate and 
:EndDate');

      Params[0].AsDate := EncodeDate(2002, 3, 1);
      Params[1].AsDate := EncodeDate(2002, 3, 31);
    end;

    DisableControls;
    Open;
    First;

    TFloatField(FieldByName('HOURS')).Precision := 3;
    EnableControls;
  end;
end;

{ This works }

procedure TMainForm.Button2Click(Sender: TObject);
begin
  with MainForm, Query do
  begin

    with Sql do
    begin
      Clear;
      Add('Select 
RECORDID, NAME, START, FINISH, ' +
          'EXTRACT(DAY FROM 
CAST(START AS DATE)) AS DAY, ' +
          '((FINISH - START) / 
3600000) as 
HOURS');
      // The Start & Finish fields are defined BEFORE the "Extract"
      // which gives the correct result with the "Finish" field visible
      // on the DBGrid ... Should i except the same result on the
      // Previous(Button1Click) SQL too ?
      Add('From 
Data');
      Add('Where CAST(START AS DATE) Between :StartDate and 
:EndDate');

      Params[0].AsDate := EncodeDate(2002, 3, 1);
      Params[1].AsDate := EncodeDate(2002, 3, 31);
    end;

    DisableControls;
    Open;
    First;

    TFloatField(FieldByName('HOURS')).Precision := 3;
    EnableControls;
  end;
end;



Resolution Resolution
Fixed Problem on 3/13/2002 in version 3.08 build 1
Image