ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/public/ibx/trunk/runtime/IBQuery.pas
(Generate patch)

Comparing ibx/trunk/runtime/IBQuery.pas (file contents):
Revision 34 by tony, Sat Jul 18 12:30:52 2015 UTC vs.
Revision 35 by tony, Tue Jan 26 14:38:47 2016 UTC

# Line 59 | Line 59 | type
59      FRowsAffected: Integer;
60      FCheckRowsAffected: Boolean;
61      FSQLUpdating: boolean;
62 +    FInQueryChanged: boolean;
63      function GetRowsAffected: Integer;
64      procedure PrepareSQL;
65      procedure QueryChanged(Sender: TObject);
# Line 71 | Line 72 | type
72      procedure SetPrepare(Value: Boolean);
73      procedure WriteParamData(Writer: TWriter);
74      function GetStmtHandle: TISC_STMT_HANDLE;
75 +    procedure UpdateSQL;
76  
77    protected
78      { IProviderSupport }
# Line 80 | Line 82 | type
82      procedure PSSetCommandText(const CommandText: string); override;
83      procedure PSSetParams(AParams: TParams); override;  *)
84  
83    function CreateParser: TSelectSQLParser; override;
85      procedure DefineProperties(Filer: TFiler); override;
86      procedure InitFieldDefs; override;
87      procedure InternalOpen; override;
# Line 88 | Line 89 | type
89      function GetParamsCount: Word;
90      function GenerateQueryForLiveUpdate : Boolean;
91      procedure SetFiltered(Value: Boolean); override;
92 +    procedure SQLChanged(Sender: TObject); override;
93 +    procedure SQLChanging(Sender: TObject); override;
94  
95    public
96      constructor Create(AOwner: TComponent); override;
# Line 99 | Line 102 | type
102      function ParamByName(const Value: string): TParam;
103      procedure Prepare;
104      procedure UnPrepare;
105 +    procedure ResetParser; override;
106      property Prepared: Boolean read FPrepared write SetPrepare;
107      property ParamCount: Word read GetParamsCount;
108      property StmtHandle: TISC_STMT_HANDLE read GetStmtHandle;
# Line 199 | Line 203 | begin
203    SetPrepared(False);
204   end;
205  
206 + procedure TIBQuery.ResetParser;
207 + begin
208 +  inherited ResetParser;
209 +  UpdateSQL;
210 + end;
211 +
212   procedure TIBQuery.SetQuery(Value: TStrings);
213   begin
214    if SQL.Text <> Value.Text then
# Line 214 | Line 224 | begin
224   end;
225  
226   procedure TIBQuery.QueryChanged(Sender: TObject);
217 var
218  List: TParams;
227   begin
228 <  if not (csReading in ComponentState) then
229 <  begin
230 <    Disconnect;
231 <    if HasParser and not FSQLUpdating then
224 <    begin
225 <      FSQLUpdating := true;
226 <      try
227 <        SQL.Text := Parser.SQLText;
228 <      finally
229 <        FSQLUpdating := false
230 <      end;
231 <    end;
232 <    if ParamCheck or (csDesigning in ComponentState) then
228 >  if FInQueryChanged then Exit;
229 >  FInQueryChanged := true;
230 >  try
231 >    if not (csReading in ComponentState) then
232      begin
233 <      List := TParams.Create(Self);
234 <      try
235 <        FText := List.ParseSQL(SQL.Text, True);
236 <        List.AssignValues(FParams);
237 <        FParams.Clear;
238 <        FParams.Assign(List);
240 <      finally
241 <        List.Free;
242 <      end;
233 >      Disconnect;
234 >      if csDesigning in ComponentState then
235 >        FText := FParams.ParseSQL(SQL.Text, true)
236 >      else
237 >        FText := SQL.Text;
238 >      DataEvent(dePropertyChange, 0);
239      end else
240 <      FText := SQL.Text;
241 <    DataEvent(dePropertyChange, 0);
242 <  end else
243 <    FText := FParams.ParseSQL(SQL.Text, true);
244 <  SelectSQL.Assign(SQL);
240 >      FText := FParams.ParseSQL(SQL.Text, true);
241 >
242 >    if not FSQLUpdating then
243 >    begin
244 >      Prepared := false;
245 >      SelectSQL.Assign(SQL);
246 >    end;
247 >  finally
248 >    FInQueryChanged := false;
249 >  end;
250   end;
251  
252   procedure TIBQuery.SetParamsList(Value: TParams);
# Line 304 | Line 305 | begin
305        if FCheckRowsAffected then
306          FRowsAffected := RowsAffected;
307        InternalUnPrepare;
308 +      FParams.Clear;
309      end;
310      FPrepared := Value;
311    end;
# Line 353 | Line 355 | end;
355  
356   function TIBQuery.ParamByName(const Value: string): TParam;
357   begin
358 +  if not Prepared then
359 +    Prepare;
360    Result := FParams.ParamByName(Value);
361   end;
362  
# Line 446 | Line 450 | begin
450   end;
451  
452   procedure TIBQuery.PrepareSQL;
453 + var List: TParams;
454   begin
455    QSelect.GenerateParamNames := GenerateParamNames;
456    InternalPrepare;
457 +  UpdateSQL;
458 +  if ParamCheck  then
459 +  begin
460 +    List := TParams.Create(Self);
461 +    try
462 +      FText := List.ParseSQL(SQL.Text, True);
463 +      List.AssignValues(FParams);
464 +      FParams.Clear;
465 +      FParams.Assign(List);
466 +    finally
467 +      List.Free;
468 +    end;
469 +  end;
470   end;
471  
472  
# Line 489 | Line 507 | begin
507    Result := SelectStmtHandle;
508   end;
509  
510 < function TIBQuery.CreateParser: TSelectSQLParser;
510 > procedure TIBQuery.UpdateSQL;
511   begin
512 <  Result := inherited CreateParser;
513 <  Result.OnSQLChanging := QueryChanged;
512 >  if not FSQLUpdating and not FInQueryChanged then
513 >  begin
514 >    FSQLUpdating := true;
515 >    try
516 >      SQL.Text := SelectSQL.Text;
517 >    finally
518 >      FSQLUpdating := false
519 >    end;
520 >  end;
521   end;
522  
523   function TIBQuery.GenerateQueryForLiveUpdate : Boolean;
# Line 515 | Line 540 | begin
540      inherited SetFiltered(value);
541   end;
542  
543 + procedure TIBQuery.SQLChanged(Sender: TObject);
544 + begin
545 +  inherited SQLChanged(Sender);
546 +  UpdateSQL;
547 + end;
548 +
549 + procedure TIBQuery.SQLChanging(Sender: TObject);
550 + begin
551 +  inherited SQLChanging(Sender);
552 +  Prepared := false;
553 + end;
554 +
555   { TIBQuery IProviderSupport }
556   (*
557   function TIBQuery.PSGetParams: TParams;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines