56 |
|
FPrepared: Boolean; |
57 |
|
FParams: TParams; |
58 |
|
FText: string; |
59 |
– |
FRowsAffected: Integer; |
60 |
– |
FCheckRowsAffected: Boolean; |
59 |
|
FSQLUpdating: boolean; |
60 |
+ |
FInQueryChanged: boolean; |
61 |
|
function GetRowsAffected: Integer; |
62 |
|
procedure PrepareSQL; |
63 |
|
procedure QueryChanged(Sender: TObject); |
69 |
|
procedure SetPrepared(Value: Boolean); |
70 |
|
procedure SetPrepare(Value: Boolean); |
71 |
|
procedure WriteParamData(Writer: TWriter); |
72 |
< |
function GetStmtHandle: TISC_STMT_HANDLE; |
72 |
> |
function GetStmtHandle: IStatement; |
73 |
> |
procedure UpdateSQL; |
74 |
|
|
75 |
|
protected |
76 |
|
{ IProviderSupport } |
80 |
|
procedure PSSetCommandText(const CommandText: string); override; |
81 |
|
procedure PSSetParams(AParams: TParams); override; *) |
82 |
|
|
83 |
– |
function CreateParser: TSelectSQLParser; override; |
83 |
|
procedure DefineProperties(Filer: TFiler); override; |
84 |
|
procedure InitFieldDefs; override; |
85 |
|
procedure InternalOpen; override; |
87 |
|
function GetParamsCount: Word; |
88 |
|
function GenerateQueryForLiveUpdate : Boolean; |
89 |
|
procedure SetFiltered(Value: Boolean); override; |
90 |
+ |
procedure SQLChanged(Sender: TObject); override; |
91 |
+ |
procedure SQLChanging(Sender: TObject); override; |
92 |
|
|
93 |
|
public |
94 |
|
constructor Create(AOwner: TComponent); override; |
100 |
|
function ParamByName(const Value: string): TParam; |
101 |
|
procedure Prepare; |
102 |
|
procedure UnPrepare; |
103 |
+ |
procedure ResetParser; override; |
104 |
|
property Prepared: Boolean read FPrepared write SetPrepare; |
105 |
|
property ParamCount: Word read GetParamsCount; |
106 |
< |
property StmtHandle: TISC_STMT_HANDLE read GetStmtHandle; |
106 |
> |
property StmtHandle: IStatement read GetStmtHandle; |
107 |
|
property StatementType; |
108 |
|
property Text: string read FText; |
109 |
|
property RowsAffected: Integer read GetRowsAffected; |
139 |
|
|
140 |
|
implementation |
141 |
|
|
142 |
+ |
uses FBMessages; |
143 |
+ |
|
144 |
|
{ TIBQuery } |
145 |
|
|
146 |
|
constructor TIBQuery.Create(AOwner: TComponent); |
150 |
|
TStringList(SQL).OnChange := QueryChanged; |
151 |
|
FParams := TParams.Create(Self); |
152 |
|
ParamCheck := True; |
149 |
– |
FRowsAffected := -1; |
153 |
|
end; |
154 |
|
|
155 |
|
destructor TIBQuery.Destroy; |
202 |
|
SetPrepared(False); |
203 |
|
end; |
204 |
|
|
205 |
+ |
procedure TIBQuery.ResetParser; |
206 |
+ |
begin |
207 |
+ |
inherited ResetParser; |
208 |
+ |
UpdateSQL; |
209 |
+ |
end; |
210 |
+ |
|
211 |
|
procedure TIBQuery.SetQuery(Value: TStrings); |
212 |
|
begin |
213 |
|
if SQL.Text <> Value.Text then |
223 |
|
end; |
224 |
|
|
225 |
|
procedure TIBQuery.QueryChanged(Sender: TObject); |
217 |
– |
var |
218 |
– |
List: TParams; |
226 |
|
begin |
227 |
< |
if not (csReading in ComponentState) then |
228 |
< |
begin |
229 |
< |
Disconnect; |
230 |
< |
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 |
227 |
> |
if FInQueryChanged then Exit; |
228 |
> |
FInQueryChanged := true; |
229 |
> |
try |
230 |
> |
if not (csReading in ComponentState) then |
231 |
|
begin |
232 |
< |
List := TParams.Create(Self); |
233 |
< |
try |
234 |
< |
FText := List.ParseSQL(SQL.Text, True); |
235 |
< |
List.AssignValues(FParams); |
236 |
< |
FParams.Clear; |
237 |
< |
FParams.Assign(List); |
240 |
< |
finally |
241 |
< |
List.Free; |
242 |
< |
end; |
232 |
> |
Disconnect; |
233 |
> |
if csDesigning in ComponentState then |
234 |
> |
FText := FParams.ParseSQL(SQL.Text, true) |
235 |
> |
else |
236 |
> |
FText := SQL.Text; |
237 |
> |
DataEvent(dePropertyChange, 0); |
238 |
|
end else |
239 |
< |
FText := SQL.Text; |
240 |
< |
DataEvent(dePropertyChange, 0); |
241 |
< |
end else |
242 |
< |
FText := FParams.ParseSQL(SQL.Text, true); |
243 |
< |
SelectSQL.Assign(SQL); |
239 |
> |
FText := FParams.ParseSQL(SQL.Text, true); |
240 |
> |
|
241 |
> |
if not FSQLUpdating then |
242 |
> |
begin |
243 |
> |
Prepared := false; |
244 |
> |
SelectSQL.Assign(SQL); |
245 |
> |
end; |
246 |
> |
finally |
247 |
> |
FInQueryChanged := false; |
248 |
> |
end; |
249 |
|
end; |
250 |
|
|
251 |
|
procedure TIBQuery.SetParamsList(Value: TParams); |
294 |
|
begin |
295 |
|
if Value then |
296 |
|
begin |
297 |
– |
FRowsAffected := -1; |
298 |
– |
FCheckRowsAffected := True; |
297 |
|
if Length(Text) > 1 then PrepareSQL |
298 |
|
else IBError(ibxeEmptySQLStatement, [nil]); |
299 |
|
end |
300 |
|
else |
301 |
|
begin |
304 |
– |
if FCheckRowsAffected then |
305 |
– |
FRowsAffected := RowsAffected; |
302 |
|
InternalUnPrepare; |
303 |
+ |
FParams.Clear; |
304 |
|
end; |
305 |
|
FPrepared := Value; |
306 |
|
end; |
350 |
|
|
351 |
|
function TIBQuery.ParamByName(const Value: string): TParam; |
352 |
|
begin |
353 |
+ |
if not Prepared then |
354 |
+ |
Prepare; |
355 |
|
Result := FParams.ParamByName(Value); |
356 |
|
end; |
357 |
|
|
371 |
|
begin |
372 |
|
CheckInActive; |
373 |
|
if SQL.Count <= 0 then |
375 |
– |
begin |
376 |
– |
FCheckRowsAffected := False; |
374 |
|
IBError(ibxeEmptySQLStatement, [nil]); |
375 |
< |
end; |
375 |
> |
|
376 |
|
ActivateConnection(); |
377 |
|
DidActivate := ActivateTransaction; |
378 |
|
try |
383 |
|
finally |
384 |
|
if DidActivate then |
385 |
|
DeactivateTransaction; |
389 |
– |
FCheckRowsAffected := True; |
386 |
|
end; |
387 |
|
end; |
388 |
|
|
391 |
|
var |
392 |
|
i : integer; |
393 |
|
Buffer: Pointer; |
394 |
< |
SQLParam: TIBXSQLVAR; |
394 |
> |
SQLParam: ISQLParam; |
395 |
|
|
396 |
|
begin |
397 |
|
for I := 0 to FParams.Count - 1 do |
442 |
|
end; |
443 |
|
|
444 |
|
procedure TIBQuery.PrepareSQL; |
445 |
+ |
var List: TParams; |
446 |
|
begin |
447 |
|
QSelect.GenerateParamNames := GenerateParamNames; |
448 |
|
InternalPrepare; |
449 |
+ |
UpdateSQL; |
450 |
+ |
if ParamCheck then |
451 |
+ |
begin |
452 |
+ |
List := TParams.Create(Self); |
453 |
+ |
try |
454 |
+ |
FText := List.ParseSQL(SQL.Text, True); |
455 |
+ |
List.AssignValues(FParams); |
456 |
+ |
FParams.Clear; |
457 |
+ |
FParams.Assign(List); |
458 |
+ |
finally |
459 |
+ |
List.Free; |
460 |
+ |
end; |
461 |
+ |
end; |
462 |
|
end; |
463 |
|
|
464 |
|
|
494 |
|
AddFieldToList(Params[i].Name, Self, DetailFields); |
495 |
|
end; |
496 |
|
|
497 |
< |
function TIBQuery.GetStmtHandle: TISC_STMT_HANDLE; |
497 |
> |
function TIBQuery.GetStmtHandle: IStatement; |
498 |
|
begin |
499 |
|
Result := SelectStmtHandle; |
500 |
|
end; |
501 |
|
|
502 |
< |
function TIBQuery.CreateParser: TSelectSQLParser; |
502 |
> |
procedure TIBQuery.UpdateSQL; |
503 |
|
begin |
504 |
< |
Result := inherited CreateParser; |
505 |
< |
Result.OnSQLChanging := QueryChanged; |
504 |
> |
if not FSQLUpdating and not FInQueryChanged and (SQL.Text <> SelectSQL.Text) then |
505 |
> |
begin |
506 |
> |
FSQLUpdating := true; |
507 |
> |
try |
508 |
> |
SQL.Text := SelectSQL.Text; |
509 |
> |
finally |
510 |
> |
FSQLUpdating := false |
511 |
> |
end; |
512 |
> |
end; |
513 |
|
end; |
514 |
|
|
515 |
|
function TIBQuery.GenerateQueryForLiveUpdate : Boolean; |
532 |
|
inherited SetFiltered(value); |
533 |
|
end; |
534 |
|
|
535 |
+ |
procedure TIBQuery.SQLChanged(Sender: TObject); |
536 |
+ |
begin |
537 |
+ |
inherited SQLChanged(Sender); |
538 |
+ |
UpdateSQL; |
539 |
+ |
end; |
540 |
+ |
|
541 |
+ |
procedure TIBQuery.SQLChanging(Sender: TObject); |
542 |
+ |
begin |
543 |
+ |
inherited SQLChanging(Sender); |
544 |
+ |
Prepared := false; |
545 |
+ |
end; |
546 |
+ |
|
547 |
|
{ TIBQuery IProviderSupport } |
548 |
|
(* |
549 |
|
function TIBQuery.PSGetParams: TParams; |