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 7 by tony, Sun Aug 5 18:28:19 2012 UTC vs.
Revision 23 by tony, Fri Mar 13 10:26:52 2015 UTC

# Line 1 | Line 1
1 < {************************************************************************}
2 < {                                                                        }
3 < {       Borland Delphi Visual Component Library                          }
4 < {       InterBase Express core components                                }
5 < {                                                                        }
6 < {       Copyright (c) 1998-2000 Inprise Corporation                      }
7 < {                                                                        }
8 < {    InterBase Express is based in part on the product                   }
9 < {    Free IB Components, written by Gregory H. Deatz for                 }
10 < {    Hoagland, Longo, Moran, Dunst & Doukas Company.                     }
11 < {    Free IB Components is used under license.                           }
12 < {                                                                        }
13 < {    The contents of this file are subject to the InterBase              }
14 < {    Public License Version 1.0 (the "License"); you may not             }
15 < {    use this file except in compliance with the License. You            }
16 < {    may obtain a copy of the License at http://www.Inprise.com/IPL.html }
17 < {    Software distributed under the License is distributed on            }
18 < {    an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either              }
19 < {    express or implied. See the License for the specific language       }
20 < {    governing rights and limitations under the License.                 }
21 < {    The Original Code was created by InterBase Software Corporation     }
22 < {       and its successors.                                              }
23 < {    Portions created by Inprise Corporation are Copyright (C) Inprise   }
24 < {       Corporation. All Rights Reserved.                                }
25 < {    Contributor(s): Jeff Overcash                                       }
26 < {                                                                        }
27 < {    IBX For Lazarus (Firebird Express)                                  }
28 < {    Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk }
29 < {    Portions created by MWA Software are copyright McCallum Whyman      }
30 < {    Associates Ltd 2011                                                 }
31 < {                                                                        }
32 < {************************************************************************}
33 <
34 < unit IBQuery;
35 <
36 < interface
37 <
38 < {$Mode Delphi}
39 <
40 < uses
41 < {$IFDEF WINDOWS }
42 <  Windows,
43 < {$ELSE}
44 <  unix,
45 < {$ENDIF}
46 < SysUtils, Graphics, Classes, Controls, Db,
47 <     IBHeader, IB, IBCustomDataSet, IBSQL;
48 <
49 < type
50 <
51 < { TIBQuery }
52 <
53 <  TIBQuery = class(TIBCustomDataSet)
54 <  private
55 <    FSQL: TStrings;
56 <    FPrepared: Boolean;
57 <    FParams: TParams;
58 <    FText: string;
59 <    FRowsAffected: Integer;
60 <    FCheckRowsAffected: Boolean;
61 <    FGenerateParamNames: Boolean;
62 <    function GetRowsAffected: Integer;
63 <    procedure PrepareSQL(Value: PChar);
64 <    procedure QueryChanged(Sender: TObject);
65 <    procedure ReadParamData(Reader: TReader);
66 <    procedure SetQuery(Value: TStrings);
67 <    procedure SetParamsList(Value: TParams);
68 <    procedure SetParams;
69 <    procedure SetParamsFromCursor;
70 <    procedure SetPrepared(Value: Boolean);
71 <    procedure SetPrepare(Value: Boolean);
72 <    procedure WriteParamData(Writer: TWriter);
73 <    function GetStmtHandle: TISC_STMT_HANDLE;
74 <
75 <  protected
76 <    { IProviderSupport }
77 < (*    procedure PSExecute; override;
78 <    function PSGetParams: TParams; override;
79 <    function PSGetTableName: string; override;
80 <    procedure PSSetCommandText(const CommandText: string); override;
81 <    procedure PSSetParams(AParams: TParams); override;  *)
82 <
83 <    procedure DefineProperties(Filer: TFiler); override;
84 <    procedure InitFieldDefs; override;
85 <    procedure InternalOpen; override;
86 <    procedure Disconnect; override;
87 <    function GetParamsCount: Word;
88 <    function GenerateQueryForLiveUpdate : Boolean;
89 <    procedure SetFiltered(Value: Boolean); override;
90 <
91 <  public
92 <    constructor Create(AOwner: TComponent); override;
93 <    destructor Destroy; override;
94 <    procedure BatchInput(InputObject: TIBBatchInput);
95 <    procedure BatchOutput(OutputObject: TIBBatchOutput);
96 <    procedure ExecSQL;
97 <    procedure GetDetailLinkFields(MasterFields, DetailFields: TList);(* override;*)
98 <    function ParamByName(const Value: string): TParam;
99 <    procedure Prepare;
100 <    procedure UnPrepare;
101 <    property Prepared: Boolean read FPrepared write SetPrepare;
102 <    property ParamCount: Word read GetParamsCount;
103 <    property StmtHandle: TISC_STMT_HANDLE read GetStmtHandle;
104 <    property StatementType;
105 <    property Text: string read FText;
106 <    property RowsAffected: Integer read GetRowsAffected;
107 <    property GenerateParamNames: Boolean read FGenerateParamNames write FGenerateParamNames;
108 < //   property Params: TParams read FParams write SetParamsList;
109 <
110 <  published
111 <    property Active;
112 <    property BufferChunks;
113 <    property CachedUpdates;
114 <    property DataSource read GetDataSource write SetDataSource;
115 < //   property Constraints stored ConstraintsStored;
116 <    property GeneratorField;
117 <    property ParamCheck;
118 <    property SQL: TStrings read FSQL write SetQuery;
119 <   property Params: TParams read FParams write SetParamsList;
120 <    property UniDirectional default False;
121 <    property UpdateObject;
122 <    property Filtered;
123 <
124 <    property BeforeDatabaseDisconnect;
125 <    property AfterDatabaseDisconnect;
126 <    property DatabaseFree;
127 <    property BeforeTransactionEnd;
128 <    property AfterTransactionEnd;
129 <    property TransactionFree;
130 <    property OnFilterRecord;
131 < end;
132 <
133 < implementation
134 <
135 < { TIBQuery }
136 <
137 < constructor TIBQuery.Create(AOwner: TComponent);
138 < begin
139 <  inherited Create(AOwner);
140 <  FSQL := TStringList.Create;
141 <  TStringList(SQL).OnChange := QueryChanged;
142 <  FParams := TParams.Create(Self);
143 <  ParamCheck := True;
144 <  FGenerateParamNames := False;
145 <  FRowsAffected := -1;
146 < end;
147 <
148 < destructor TIBQuery.Destroy;
149 < begin
150 <  Destroying;
151 <  Disconnect;
152 <  SQL.Free;
153 <  FParams.Free;
154 <  inherited Destroy;
155 < end;
156 <
157 < procedure TIBQuery.InitFieldDefs;
158 < begin
159 <  inherited InitFieldDefs;
160 < end;
161 <
162 < procedure TIBQuery.InternalOpen;
163 < begin
164 <  ActivateConnection();
165 <  ActivateTransaction;
166 <  QSelect.GenerateParamNames := FGenerateParamNames;
167 <  SetPrepared(True);
168 <  if DataSource <> nil then
169 <    SetParamsFromCursor;
170 <  SetParams;
171 <  inherited InternalOpen;
172 < end;
173 <
174 < procedure TIBQuery.Disconnect;
175 < begin
176 <  Close;
177 <  UnPrepare;
178 < end;
179 <
180 < procedure TIBQuery.SetPrepare(Value: Boolean);
181 < begin
182 <  if Value then
183 <    Prepare
184 <  else
185 <    UnPrepare;
186 < end;
187 <
188 < procedure TIBQuery.Prepare;
189 < begin
190 <  SetPrepared(True);
191 < end;
192 <
193 < procedure TIBQuery.UnPrepare;
194 < begin
195 <  SetPrepared(False);
196 < end;
197 <
198 < procedure TIBQuery.SetQuery(Value: TStrings);
199 < begin
200 <  if SQL.Text <> Value.Text then
201 <  begin
202 <    Disconnect;
203 <    SQL.BeginUpdate;
204 <    try
205 <      SQL.Assign(Value);
206 <    finally
207 <      SQL.EndUpdate;
208 <    end;
209 <  end;
210 < end;
211 <
212 < procedure TIBQuery.QueryChanged(Sender: TObject);
213 < var
214 <  List: TParams;
215 < begin
216 <  if not (csReading in ComponentState) then
217 <  begin
218 <    Disconnect;
219 <    if ParamCheck or (csDesigning in ComponentState) then
220 <    begin
221 <      List := TParams.Create(Self);
222 <      try
223 <        FText := List.ParseSQL(SQL.Text, True);
224 <        List.AssignValues(FParams);
225 <        FParams.Clear;
226 <        FParams.Assign(List);
227 <      finally
228 <        List.Free;
229 <      end;
230 <    end else
231 <      FText := SQL.Text;
232 <    DataEvent(dePropertyChange, 0);
233 <  end else
234 <    FText := FParams.ParseSQL(SQL.Text, true);
235 <  SelectSQL.Assign(SQL);
236 < end;
237 <
238 < procedure TIBQuery.SetParamsList(Value: TParams);
239 < begin
240 <  FParams.AssignValues(Value);
241 < end;
242 <
243 < function TIBQuery.GetParamsCount: Word;
244 < begin
245 <  Result := FParams.Count;
246 < end;
247 <
248 < procedure TIBQuery.DefineProperties(Filer: TFiler);
249 <
250 <  function WriteData: Boolean;
251 <  begin
252 <  {The following results in a stream read error with nested frames. Hence commented out until
253 <   someone fixes the LCL }
254 < {    if Filer.Ancestor <> nil then
255 <      Result := not FParams.IsEqual(TIBQuery(Filer.Ancestor).FParams) else}
256 <      Result := FParams.Count > 0;
257 <  end;
258 <
259 < begin
260 <  inherited DefineProperties(Filer);
261 <  Filer.DefineProperty('ParamData', ReadParamData, WriteParamData, WriteData); {do not localize}
262 < end;
263 <
264 < procedure TIBQuery.ReadParamData(Reader: TReader);
265 < begin
266 <  FParams.Clear;
267 <  Reader.ReadValue;
268 <  Reader.ReadCollection(FParams);
269 < end;
270 <
271 < procedure TIBQuery.WriteParamData(Writer: TWriter);
272 < begin
273 <  Writer.WriteCollection(Params);
274 < end;
275 <
276 < procedure TIBQuery.SetPrepared(Value: Boolean);
277 < begin
278 <  CheckDatasetClosed;
279 <  if Value <> Prepared then
280 <  begin
281 <    if Value then
282 <    begin
283 <      FRowsAffected := -1;
284 <      FCheckRowsAffected := True;
285 <      if Length(Text) > 1 then PrepareSQL(PChar(Text))
286 <      else IBError(ibxeEmptySQLStatement, [nil]);
287 <    end
288 <    else
289 <    begin
290 <      if FCheckRowsAffected then
291 <        FRowsAffected := RowsAffected;
292 <      InternalUnPrepare;
293 <    end;
294 <    FPrepared := Value;
295 <  end;
296 < end;
297 <
298 < procedure TIBQuery.SetParamsFromCursor;
299 < var
300 <  I: Integer;
301 <  DataSet: TDataSet;
302 <  Field: TField;
303 <
304 <  procedure CheckRequiredParams;
305 <  var
306 <    I: Integer;
307 <  begin
308 <    for I := 0 to FParams.Count - 1 do
309 <    with FParams[I] do
310 <      if not Bound then
311 <        IBError(ibxeRequiredParamNotSet, [nil]);
312 <  end;
313 <
314 < begin
315 <  if DataSource <> nil then
316 <  begin
317 <    DataSet := DataSource.DataSet;
318 <    if DataSet <> nil then
319 <    begin
320 <      DataSet.FieldDefs.Update;
321 <      for I := 0 to FParams.Count - 1 do
322 <      if not FParams[I].Bound then
323 <      begin
324 <        Field := DataSet.FindField(FParams[I].Name);
325 <        if assigned(Field) then
326 <        begin
327 <            FParams[I].AssignField(Field);
328 <            FParams[I].Bound := False;
329 <        end;
330 <      end;
331 <    end
332 <    else
333 <      CheckRequiredParams;
334 <  end
335 <  else
336 <    CheckRequiredParams;
337 < end;
338 <
339 <
340 < function TIBQuery.ParamByName(const Value: string): TParam;
341 < begin
342 <  Result := FParams.ParamByName(Value);
343 < end;
344 <
345 < procedure TIBQuery.BatchInput(InputObject: TIBBatchInput);
346 < begin
347 <  InternalBatchInput(InputObject);
348 < end;
349 <
350 < procedure TIBQuery.BatchOutput(OutputObject: TIBBatchOutput);
351 < begin
352 <  InternalBatchOutput(OutputObject);
353 < end;
354 <
355 < procedure TIBQuery.ExecSQL;
356 < var
357 <  DidActivate: Boolean;
358 < begin
359 <  CheckInActive;
360 <  if SQL.Count <= 0 then
361 <  begin
362 <    FCheckRowsAffected := False;
363 <    IBError(ibxeEmptySQLStatement, [nil]);
364 <  end;
365 <  ActivateConnection();
366 <  DidActivate := ActivateTransaction;
367 <  try
368 <    SetPrepared(True);
369 <    if DataSource <> nil then SetParamsFromCursor;
370 <    if FParams.Count > 0 then SetParams;
371 <    InternalExecQuery;
372 <  finally
373 <    if DidActivate then
374 <      DeactivateTransaction;
375 <    FCheckRowsAffected := True;
376 <  end;
377 < end;
378 <
379 < procedure TIBQuery.SetParams;
380 <
381 < var
382 < i : integer;
383 < Buffer: Pointer;
384 <
385 < begin
386 <  for I := 0 to FParams.Count - 1 do
387 <  begin
388 <    if Params[i].IsNull then
389 <      SQLParams[i].IsNull := True
390 <    else begin
391 <      SQLParams[i].IsNull := False;
392 <      case Params[i].DataType of
393 <        ftBytes:
394 <        begin
395 <          GetMem(Buffer,Params[i].GetDataSize);
396 <          try
397 <            Params[i].GetData(Buffer);
398 <            SQLParams[i].AsPointer := Buffer;
399 <          finally
400 <            FreeMem(Buffer);
401 <          end;
402 <        end;
403 <        ftString:
404 <          SQLParams[i].AsString := Params[i].AsString;
405 <        ftBoolean, ftSmallint, ftWord:
406 <          SQLParams[i].AsShort := Params[i].AsSmallInt;
407 <        ftInteger:
408 <          SQLParams[i].AsLong := Params[i].AsInteger;
409 < {        ftLargeInt:
410 <          SQLParams[i].AsInt64 := Params[i].AsLargeInt;  }
411 <        ftFloat:
412 <         SQLParams[i].AsDouble := Params[i].AsFloat;
413 <        ftBCD, ftCurrency:
414 <          SQLParams[i].AsCurrency := Params[i].AsCurrency;
415 <        ftDate:
416 <          SQLParams[i].AsDate := Params[i].AsDateTime;
417 <        ftTime:
418 <          SQLParams[i].AsTime := Params[i].AsDateTime;
419 <        ftDateTime:
420 <          SQLParams[i].AsDateTime := Params[i].AsDateTime;
421 <        ftBlob, ftMemo:
422 <          SQLParams[i].AsString := Params[i].AsString;
423 <        else
424 <          IBError(ibxeNotSupported, [nil]);
425 <      end;
426 <    end;
427 <  end;
428 < end;
429 <
430 < procedure TIBQuery.PrepareSQL(Value: PChar);
431 < begin
432 <  QSelect.GenerateParamNames := FGenerateParamNames;
433 <  InternalPrepare;
434 < end;
435 <
436 <
437 < function TIBQuery.GetRowsAffected: Integer;
438 < begin
439 <  Result := -1;
440 <  if Prepared then
441 <   Result := QSelect.RowsAffected
442 < end;
443 <
444 <
445 < procedure TIBQuery.GetDetailLinkFields(MasterFields, DetailFields: TList);
446 <
447 <  function AddFieldToList(const FieldName: string; DataSet: TDataSet;
448 <    List: TList): Boolean;
449 <  var
450 <    Field: TField;
451 <  begin
452 <    Field := DataSet.FindField(FieldName);
453 <    if (Field <> nil) then
454 <      List.Add(Field);
455 <    Result := Field <> nil;
456 <  end;
457 <
458 < var
459 <  i: Integer;
460 < begin
461 <  MasterFields.Clear;
462 <  DetailFields.Clear;
463 <  if (DataSource <> nil) and (DataSource.DataSet <> nil) then
464 <    for i := 0 to Params.Count - 1 do
465 <      if AddFieldToList(Params[i].Name, DataSource.DataSet, MasterFields) then
466 <        AddFieldToList(Params[i].Name, Self, DetailFields);
467 < end;
468 <
469 < function TIBQuery.GetStmtHandle: TISC_STMT_HANDLE;
470 < begin
471 <  Result := SelectStmtHandle;
472 < end;
473 <
474 < function TIBQuery.GenerateQueryForLiveUpdate : Boolean;
475 < begin
476 <  Result := False;
477 < end;
478 <
479 < procedure TIBQuery.SetFiltered(Value: Boolean);
480 < begin
481 <  if(Filtered <> Value) then
482 <  begin
483 <    inherited SetFiltered(value);
484 <    if Active then
485 <    begin
486 <      Close;
487 <      Open;
488 <    end;
489 <  end
490 <  else
491 <    inherited SetFiltered(value);
492 < end;
493 <
494 < { TIBQuery IProviderSupport }
495 < (*
496 < function TIBQuery.PSGetParams: TParams;
497 < begin
498 <  Result := Params;
499 < end;
500 <
501 < procedure TIBQuery.PSSetParams(AParams: TParams);
502 < begin
503 <  if AParams.Count <> 0 then
504 <    Params.Assign(AParams);
505 <  Close;
506 < end;
507 <
508 < function TIBQuery.PSGetTableName: string;
509 < begin
510 <  Result := inherited PSGetTableName;
511 < end;
512 <
513 < procedure TIBQuery.PSExecute;
514 < begin
515 <  ExecSQL;
516 < end;
517 <
518 < procedure TIBQuery.PSSetCommandText(const CommandText: string);
519 < begin
520 <  if CommandText <> '' then
521 <    SQL.Text := CommandText;
522 < end;
523 < *)
524 < end.
525 <
1 > {************************************************************************}
2 > {                                                                        }
3 > {       Borland Delphi Visual Component Library                          }
4 > {       InterBase Express core components                                }
5 > {                                                                        }
6 > {       Copyright (c) 1998-2000 Inprise Corporation                      }
7 > {                                                                        }
8 > {    InterBase Express is based in part on the product                   }
9 > {    Free IB Components, written by Gregory H. Deatz for                 }
10 > {    Hoagland, Longo, Moran, Dunst & Doukas Company.                     }
11 > {    Free IB Components is used under license.                           }
12 > {                                                                        }
13 > {    The contents of this file are subject to the InterBase              }
14 > {    Public License Version 1.0 (the "License"); you may not             }
15 > {    use this file except in compliance with the License. You            }
16 > {    may obtain a copy of the License at http://www.Inprise.com/IPL.html }
17 > {    Software distributed under the License is distributed on            }
18 > {    an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either              }
19 > {    express or implied. See the License for the specific language       }
20 > {    governing rights and limitations under the License.                 }
21 > {    The Original Code was created by InterBase Software Corporation     }
22 > {       and its successors.                                              }
23 > {    Portions created by Inprise Corporation are Copyright (C) Inprise   }
24 > {       Corporation. All Rights Reserved.                                }
25 > {    Contributor(s): Jeff Overcash                                       }
26 > {                                                                        }
27 > {    IBX For Lazarus (Firebird Express)                                  }
28 > {    Contributor: Tony Whyman, MWA Software http://www.mwasoftware.co.uk }
29 > {    Portions created by MWA Software are copyright McCallum Whyman      }
30 > {    Associates Ltd 2011                                                 }
31 > {                                                                        }
32 > {************************************************************************}
33 >
34 > unit IBQuery;
35 >
36 > interface
37 >
38 > {$Mode Delphi}
39 >
40 > uses
41 > {$IFDEF WINDOWS }
42 >  Windows,
43 > {$ELSE}
44 >  unix,
45 > {$ENDIF}
46 > SysUtils, Graphics, Classes, Controls, Db,
47 >     IBHeader, IB, IBCustomDataSet, IBSQL, IBSQLParser;
48 >
49 > type
50 >
51 > { TIBQuery }
52 >
53 >  TIBQuery = class(TIBParserDataSet)
54 >  private
55 >    FSQL: TStrings;
56 >    FPrepared: Boolean;
57 >    FParams: TParams;
58 >    FText: string;
59 >    FRowsAffected: Integer;
60 >    FCheckRowsAffected: Boolean;
61 >    FSQLUpdating: boolean;
62 >    function GetRowsAffected: Integer;
63 >    procedure PrepareSQL(Value: PChar);
64 >    procedure QueryChanged(Sender: TObject);
65 >    procedure ReadParamData(Reader: TReader);
66 >    procedure SetQuery(Value: TStrings);
67 >    procedure SetParamsList(Value: TParams);
68 >    procedure SetParams;
69 >    procedure SetParamsFromCursor;
70 >    procedure SetPrepared(Value: Boolean);
71 >    procedure SetPrepare(Value: Boolean);
72 >    procedure WriteParamData(Writer: TWriter);
73 >    function GetStmtHandle: TISC_STMT_HANDLE;
74 >
75 >  protected
76 >    { IProviderSupport }
77 > (*    procedure PSExecute; override;
78 >    function PSGetParams: TParams; override;
79 >    function PSGetTableName: string; override;
80 >    procedure PSSetCommandText(const CommandText: string); override;
81 >    procedure PSSetParams(AParams: TParams); override;  *)
82 >
83 >    function CreateParser: TSelectSQLParser; override;
84 >    procedure DefineProperties(Filer: TFiler); override;
85 >    procedure InitFieldDefs; override;
86 >    procedure InternalOpen; override;
87 >    procedure Disconnect; override;
88 >    function GetParamsCount: Word;
89 >    function GenerateQueryForLiveUpdate : Boolean;
90 >    procedure SetFiltered(Value: Boolean); override;
91 >
92 >  public
93 >    constructor Create(AOwner: TComponent); override;
94 >    destructor Destroy; override;
95 >    procedure BatchInput(InputObject: TIBBatchInput);
96 >    procedure BatchOutput(OutputObject: TIBBatchOutput);
97 >    procedure ExecSQL;
98 >    procedure GetDetailLinkFields(MasterFields, DetailFields: TList);(* override;*)
99 >    function ParamByName(const Value: string): TParam;
100 >    procedure Prepare;
101 >    procedure UnPrepare;
102 >    property Prepared: Boolean read FPrepared write SetPrepare;
103 >    property ParamCount: Word read GetParamsCount;
104 >    property StmtHandle: TISC_STMT_HANDLE read GetStmtHandle;
105 >    property StatementType;
106 >    property Text: string read FText;
107 >    property RowsAffected: Integer read GetRowsAffected;
108 > //   property Params: TParams read FParams write SetParamsList;
109 >    property BaseSQLSelect;
110 >
111 >  published
112 >    property Active;
113 >    property AutoCommit;
114 >    property BufferChunks;
115 >    property CachedUpdates;
116 >    property DataSource read GetDataSource write SetDataSource;
117 >    property GenerateParamNames;
118 > //   property Constraints stored ConstraintsStored;
119 >    property GeneratorField;
120 >    property ParamCheck;
121 >    property SQL: TStrings read FSQL write SetQuery;
122 >    property Params: TParams read FParams write SetParamsList;
123 >    property UniDirectional default False;
124 >    property UpdateObject;
125 >    property Filtered;
126 >
127 >    property BeforeDatabaseDisconnect;
128 >    property AfterDatabaseDisconnect;
129 >    property DatabaseFree;
130 >    property BeforeTransactionEnd;
131 >    property AfterTransactionEnd;
132 >    property TransactionFree;
133 >    property OnFilterRecord;
134 > end;
135 >
136 > implementation
137 >
138 > { TIBQuery }
139 >
140 > constructor TIBQuery.Create(AOwner: TComponent);
141 > begin
142 >  inherited Create(AOwner);
143 >  FSQL := TStringList.Create;
144 >  TStringList(SQL).OnChange := QueryChanged;
145 >  FParams := TParams.Create(Self);
146 >  ParamCheck := True;
147 >  FRowsAffected := -1;
148 > end;
149 >
150 > destructor TIBQuery.Destroy;
151 > begin
152 >  Destroying;
153 >  Disconnect;
154 >  SQL.Free;
155 >  FParams.Free;
156 >  inherited Destroy;
157 > end;
158 >
159 > procedure TIBQuery.InitFieldDefs;
160 > begin
161 >  inherited InitFieldDefs;
162 > end;
163 >
164 > procedure TIBQuery.InternalOpen;
165 > begin
166 >  ActivateConnection();
167 >  ActivateTransaction;
168 >  QSelect.GenerateParamNames := GenerateParamNames;
169 >  SetPrepared(True);
170 >  if DataSource <> nil then
171 >    SetParamsFromCursor;
172 >  SetParams;
173 >  inherited InternalOpen;
174 > end;
175 >
176 > procedure TIBQuery.Disconnect;
177 > begin
178 >  Close;
179 >  UnPrepare;
180 > end;
181 >
182 > procedure TIBQuery.SetPrepare(Value: Boolean);
183 > begin
184 >  if Value then
185 >    Prepare
186 >  else
187 >    UnPrepare;
188 > end;
189 >
190 > procedure TIBQuery.Prepare;
191 > begin
192 >  SetPrepared(True);
193 > end;
194 >
195 > procedure TIBQuery.UnPrepare;
196 > begin
197 >  SetPrepared(False);
198 > end;
199 >
200 > procedure TIBQuery.SetQuery(Value: TStrings);
201 > begin
202 >  if SQL.Text <> Value.Text then
203 >  begin
204 >    Disconnect;
205 >    SQL.BeginUpdate;
206 >    try
207 >      SQL.Assign(Value);
208 >    finally
209 >      SQL.EndUpdate;
210 >    end;
211 >  end;
212 > end;
213 >
214 > procedure TIBQuery.QueryChanged(Sender: TObject);
215 > var
216 >  List: TParams;
217 > begin
218 >  if not (csReading in ComponentState) then
219 >  begin
220 >    Disconnect;
221 >    if HasParser and not FSQLUpdating then
222 >    begin
223 >      FSQLUpdating := true;
224 >      try
225 >        SQL.Text := Parser.SQLText;
226 >      finally
227 >        FSQLUpdating := false
228 >      end;
229 >    end;
230 >    if ParamCheck or (csDesigning 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);
238 >      finally
239 >        List.Free;
240 >      end;
241 >    end else
242 >      FText := SQL.Text;
243 >    DataEvent(dePropertyChange, 0);
244 >  end else
245 >    FText := FParams.ParseSQL(SQL.Text, true);
246 >  SelectSQL.Assign(SQL);
247 > end;
248 >
249 > procedure TIBQuery.SetParamsList(Value: TParams);
250 > begin
251 >  FParams.AssignValues(Value);
252 > end;
253 >
254 > function TIBQuery.GetParamsCount: Word;
255 > begin
256 >  Result := FParams.Count;
257 > end;
258 >
259 > procedure TIBQuery.DefineProperties(Filer: TFiler);
260 >
261 >  function WriteData: Boolean;
262 >  begin
263 >  {The following results in a stream read error with nested frames. Hence commented out until
264 >   someone fixes the LCL }
265 > {    if Filer.Ancestor <> nil then
266 >      Result := not FParams.IsEqual(TIBQuery(Filer.Ancestor).FParams) else}
267 >      Result := FParams.Count > 0;
268 >  end;
269 >
270 > begin
271 >  inherited DefineProperties(Filer);
272 >  Filer.DefineProperty('ParamData', ReadParamData, WriteParamData, WriteData); {do not localize}
273 > end;
274 >
275 >
276 > procedure TIBQuery.ReadParamData(Reader: TReader);
277 > begin
278 >  FParams.Clear;
279 >  Reader.ReadValue;
280 >  Reader.ReadCollection(FParams);
281 > end;
282 >
283 > procedure TIBQuery.WriteParamData(Writer: TWriter);
284 > begin
285 >  Writer.WriteCollection(Params);
286 > end;
287 >
288 > procedure TIBQuery.SetPrepared(Value: Boolean);
289 > begin
290 >  CheckDatasetClosed;
291 >  if Value <> Prepared then
292 >  begin
293 >    if Value then
294 >    begin
295 >      FRowsAffected := -1;
296 >      FCheckRowsAffected := True;
297 >      if Length(Text) > 1 then PrepareSQL(PChar(Text))
298 >      else IBError(ibxeEmptySQLStatement, [nil]);
299 >    end
300 >    else
301 >    begin
302 >      if FCheckRowsAffected then
303 >        FRowsAffected := RowsAffected;
304 >      InternalUnPrepare;
305 >    end;
306 >    FPrepared := Value;
307 >  end;
308 > end;
309 >
310 > procedure TIBQuery.SetParamsFromCursor;
311 > var
312 >  I: Integer;
313 >  DataSet: TDataSet;
314 >  Field: TField;
315 >
316 >  procedure CheckRequiredParams;
317 >  var
318 >    I: Integer;
319 >  begin
320 >    for I := 0 to FParams.Count - 1 do
321 >    with FParams[I] do
322 >      if not Bound then
323 >        IBError(ibxeRequiredParamNotSet, [nil]);
324 >  end;
325 >
326 > begin
327 >  if DataSource <> nil then
328 >  begin
329 >    DataSet := DataSource.DataSet;
330 >    if DataSet <> nil then
331 >    begin
332 >      DataSet.FieldDefs.Update;
333 >      for I := 0 to FParams.Count - 1 do
334 >      if not FParams[I].Bound then
335 >      begin
336 >        Field := DataSet.FindField(FParams[I].Name);
337 >        if assigned(Field) then
338 >        begin
339 >            FParams[I].AssignField(Field);
340 >            FParams[I].Bound := False;
341 >        end;
342 >      end;
343 >    end
344 >    else
345 >      CheckRequiredParams;
346 >  end
347 >  else
348 >    CheckRequiredParams;
349 > end;
350 >
351 >
352 > function TIBQuery.ParamByName(const Value: string): TParam;
353 > begin
354 >  Result := FParams.ParamByName(Value);
355 > end;
356 >
357 > procedure TIBQuery.BatchInput(InputObject: TIBBatchInput);
358 > begin
359 >  InternalBatchInput(InputObject);
360 > end;
361 >
362 > procedure TIBQuery.BatchOutput(OutputObject: TIBBatchOutput);
363 > begin
364 >  InternalBatchOutput(OutputObject);
365 > end;
366 >
367 > procedure TIBQuery.ExecSQL;
368 > var
369 >  DidActivate: Boolean;
370 > begin
371 >  CheckInActive;
372 >  if SQL.Count <= 0 then
373 >  begin
374 >    FCheckRowsAffected := False;
375 >    IBError(ibxeEmptySQLStatement, [nil]);
376 >  end;
377 >  ActivateConnection();
378 >  DidActivate := ActivateTransaction;
379 >  try
380 >    SetPrepared(True);
381 >    if DataSource <> nil then SetParamsFromCursor;
382 >    if FParams.Count > 0 then SetParams;
383 >    InternalExecQuery;
384 >  finally
385 >    if DidActivate then
386 >      DeactivateTransaction;
387 >    FCheckRowsAffected := True;
388 >  end;
389 > end;
390 >
391 > procedure TIBQuery.SetParams;
392 >
393 > var
394 > i : integer;
395 > Buffer: Pointer;
396 > SQLParam: TIBXSQLVAR;
397 >
398 > begin
399 >  for I := 0 to FParams.Count - 1 do
400 >  begin
401 >    SQLParam :=  SQLParams.ByName(Params[i].Name);
402 >    if Params[i].IsNull then
403 >      SQLParam.IsNull := True
404 >    else begin
405 >      SQLParam.IsNull := False;
406 >      case Params[i].DataType of
407 >        ftBytes:
408 >        begin
409 >          GetMem(Buffer,Params[i].GetDataSize);
410 >          try
411 >            Params[i].GetData(Buffer);
412 >            SQLParam.AsPointer := Buffer;
413 >          finally
414 >            FreeMem(Buffer);
415 >          end;
416 >        end;
417 >        ftString:
418 >          SQLParam.AsString := Params[i].AsString;
419 >        ftBoolean:
420 >          SQLParam.AsBoolean := Params[i].AsBoolean;
421 >        ftSmallint, ftWord:
422 >          SQLParam.AsShort := Params[i].AsSmallInt;
423 >        ftInteger:
424 >          SQLParam.AsLong := Params[i].AsInteger;
425 >        ftLargeInt:
426 >          SQLParam.AsInt64 := Params[i].AsLargeInt;
427 >        ftFloat:
428 >         SQLParam.AsDouble := Params[i].AsFloat;
429 >        ftBCD, ftCurrency:
430 >          SQLParam.AsCurrency := Params[i].AsCurrency;
431 >        ftDate:
432 >          SQLParam.AsDate := Params[i].AsDateTime;
433 >        ftTime:
434 >          SQLParam.AsTime := Params[i].AsDateTime;
435 >        ftDateTime:
436 >          SQLParam.AsDateTime := Params[i].AsDateTime;
437 >        ftBlob, ftMemo:
438 >          SQLParam.AsString := Params[i].AsString;
439 >        else
440 >          IBError(ibxeNotSupported, [nil]);
441 >      end;
442 >    end;
443 >  end;
444 > end;
445 >
446 > procedure TIBQuery.PrepareSQL(Value: PChar);
447 > begin
448 >  QSelect.GenerateParamNames := GenerateParamNames;
449 >  InternalPrepare;
450 > end;
451 >
452 >
453 > function TIBQuery.GetRowsAffected: Integer;
454 > begin
455 >  Result := -1;
456 >  if Prepared then
457 >   Result := QSelect.RowsAffected
458 > end;
459 >
460 >
461 > procedure TIBQuery.GetDetailLinkFields(MasterFields, DetailFields: TList);
462 >
463 >  function AddFieldToList(const FieldName: string; DataSet: TDataSet;
464 >    List: TList): Boolean;
465 >  var
466 >    Field: TField;
467 >  begin
468 >    Field := DataSet.FindField(FieldName);
469 >    if (Field <> nil) then
470 >      List.Add(Field);
471 >    Result := Field <> nil;
472 >  end;
473 >
474 > var
475 >  i: Integer;
476 > begin
477 >  MasterFields.Clear;
478 >  DetailFields.Clear;
479 >  if (DataSource <> nil) and (DataSource.DataSet <> nil) then
480 >    for i := 0 to Params.Count - 1 do
481 >      if AddFieldToList(Params[i].Name, DataSource.DataSet, MasterFields) then
482 >        AddFieldToList(Params[i].Name, Self, DetailFields);
483 > end;
484 >
485 > function TIBQuery.GetStmtHandle: TISC_STMT_HANDLE;
486 > begin
487 >  Result := SelectStmtHandle;
488 > end;
489 >
490 > function TIBQuery.CreateParser: TSelectSQLParser;
491 > begin
492 >  Result := inherited CreateParser;
493 >  Result.OnSQLChanging := QueryChanged;
494 > end;
495 >
496 > function TIBQuery.GenerateQueryForLiveUpdate : Boolean;
497 > begin
498 >  Result := False;
499 > end;
500 >
501 > procedure TIBQuery.SetFiltered(Value: Boolean);
502 > begin
503 >  if(Filtered <> Value) then
504 >  begin
505 >    inherited SetFiltered(value);
506 >    if Active then
507 >    begin
508 >      Close;
509 >      Open;
510 >    end;
511 >  end
512 >  else
513 >    inherited SetFiltered(value);
514 > end;
515 >
516 > { TIBQuery IProviderSupport }
517 > (*
518 > function TIBQuery.PSGetParams: TParams;
519 > begin
520 >  Result := Params;
521 > end;
522 >
523 > procedure TIBQuery.PSSetParams(AParams: TParams);
524 > begin
525 >  if AParams.Count <> 0 then
526 >    Params.Assign(AParams);
527 >  Close;
528 > end;
529 >
530 > function TIBQuery.PSGetTableName: string;
531 > begin
532 >  Result := inherited PSGetTableName;
533 > end;
534 >
535 > procedure TIBQuery.PSExecute;
536 > begin
537 >  ExecSQL;
538 > end;
539 >
540 > procedure TIBQuery.PSSetCommandText(const CommandText: string);
541 > begin
542 >  if CommandText <> '' then
543 >    SQL.Text := CommandText;
544 > end;
545 > *)
546 > end.
547 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines