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 17 by tony, Sat Dec 28 19:22:24 2013 UTC vs.
Revision 21 by tony, Thu Feb 26 10:33:34 2015 UTC

# Line 44 | Line 44 | uses
44    unix,
45   {$ENDIF}
46   SysUtils, Graphics, Classes, Controls, Db,
47 <     IBHeader, IB, IBCustomDataSet, IBSQL;
47 >     IBHeader, IB, IBCustomDataSet, IBSQL, IBSQLParser;
48  
49   type
50  
51   { TIBQuery }
52  
53 <  TIBQuery = class(TIBCustomDataSet)
53 >  TIBQuery = class(TIBParserDataSet)
54    private
55      FSQL: TStrings;
56      FPrepared: Boolean;
# Line 58 | Line 58 | type
58      FText: string;
59      FRowsAffected: Integer;
60      FCheckRowsAffected: Boolean;
61 <    FGenerateParamNames: Boolean;
61 >    FSQLUpdating: boolean;
62      function GetRowsAffected: Integer;
63      procedure PrepareSQL(Value: PChar);
64      procedure QueryChanged(Sender: TObject);
# Line 80 | Line 80 | type
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;
# Line 104 | Line 105 | type
105      property StatementType;
106      property Text: string read FText;
107      property RowsAffected: Integer read GetRowsAffected;
107    property GenerateParamNames: Boolean read FGenerateParamNames write FGenerateParamNames;
108   //   property Params: TParams read FParams write SetParamsList;
109 +    property BaseSQLSelect;
110  
111    published
112      property Active;
113      property BufferChunks;
114      property CachedUpdates;
115      property DataSource read GetDataSource write SetDataSource;
116 +    property GenerateParamNames;
117   //   property Constraints stored ConstraintsStored;
118      property GeneratorField;
119      property ParamCheck;
120      property SQL: TStrings read FSQL write SetQuery;
121 <   property Params: TParams read FParams write SetParamsList;
121 >    property Params: TParams read FParams write SetParamsList;
122      property UniDirectional default False;
123      property UpdateObject;
124      property Filtered;
# Line 141 | Line 143 | begin
143    TStringList(SQL).OnChange := QueryChanged;
144    FParams := TParams.Create(Self);
145    ParamCheck := True;
144  FGenerateParamNames := False;
146    FRowsAffected := -1;
147   end;
148  
# Line 163 | Line 164 | procedure TIBQuery.InternalOpen;
164   begin
165    ActivateConnection();
166    ActivateTransaction;
167 <  QSelect.GenerateParamNames := FGenerateParamNames;
167 >  QSelect.GenerateParamNames := GenerateParamNames;
168    SetPrepared(True);
169    if DataSource <> nil then
170      SetParamsFromCursor;
# Line 216 | Line 217 | begin
217    if not (csReading in ComponentState) then
218    begin
219      Disconnect;
220 +    if HasParser and not FSQLUpdating then
221 +    begin
222 +      FSQLUpdating := true;
223 +      try
224 +        SQL.Text := Parser.SQLText;
225 +      finally
226 +        FSQLUpdating := false
227 +      end;
228 +    end;
229      if ParamCheck or (csDesigning in ComponentState) then
230      begin
231        List := TParams.Create(Self);
# Line 261 | Line 271 | begin
271    Filer.DefineProperty('ParamData', ReadParamData, WriteParamData, WriteData); {do not localize}
272   end;
273  
274 +
275   procedure TIBQuery.ReadParamData(Reader: TReader);
276   begin
277    FParams.Clear;
# Line 381 | Line 392 | procedure TIBQuery.SetParams;
392   var
393   i : integer;
394   Buffer: Pointer;
395 + SQLParam: TIBXSQLVAR;
396  
397   begin
398    for I := 0 to FParams.Count - 1 do
399    begin
400 +    SQLParam :=  SQLParams.ByName(Params[i].Name);
401      if Params[i].IsNull then
402 <      SQLParams[i].IsNull := True
402 >      SQLParam.IsNull := True
403      else begin
404 <      SQLParams[i].IsNull := False;
404 >      SQLParam.IsNull := False;
405        case Params[i].DataType of
406          ftBytes:
407          begin
408            GetMem(Buffer,Params[i].GetDataSize);
409            try
410              Params[i].GetData(Buffer);
411 <            SQLParams[i].AsPointer := Buffer;
411 >            SQLParam.AsPointer := Buffer;
412            finally
413              FreeMem(Buffer);
414            end;
415          end;
416          ftString:
417 <          SQLParams[i].AsString := Params[i].AsString;
417 >          SQLParam.AsString := Params[i].AsString;
418          ftBoolean, ftSmallint, ftWord:
419 <          SQLParams[i].AsShort := Params[i].AsSmallInt;
419 >          SQLParam.AsShort := Params[i].AsSmallInt;
420          ftInteger:
421 <          SQLParams[i].AsLong := Params[i].AsInteger;
422 < {        ftLargeInt:
423 <          SQLParams[i].AsInt64 := Params[i].AsLargeInt;  }
421 >          SQLParam.AsLong := Params[i].AsInteger;
422 >        ftLargeInt:
423 >          SQLParam.AsInt64 := Params[i].AsLargeInt;
424          ftFloat:
425 <         SQLParams[i].AsDouble := Params[i].AsFloat;
425 >         SQLParam.AsDouble := Params[i].AsFloat;
426          ftBCD, ftCurrency:
427 <          SQLParams[i].AsCurrency := Params[i].AsCurrency;
427 >          SQLParam.AsCurrency := Params[i].AsCurrency;
428          ftDate:
429 <          SQLParams[i].AsDate := Params[i].AsDateTime;
429 >          SQLParam.AsDate := Params[i].AsDateTime;
430          ftTime:
431 <          SQLParams[i].AsTime := Params[i].AsDateTime;
431 >          SQLParam.AsTime := Params[i].AsDateTime;
432          ftDateTime:
433 <          SQLParams[i].AsDateTime := Params[i].AsDateTime;
433 >          SQLParam.AsDateTime := Params[i].AsDateTime;
434          ftBlob, ftMemo:
435 <          SQLParams[i].AsString := Params[i].AsString;
435 >          SQLParam.AsString := Params[i].AsString;
436          else
437            IBError(ibxeNotSupported, [nil]);
438        end;
# Line 429 | Line 442 | end;
442  
443   procedure TIBQuery.PrepareSQL(Value: PChar);
444   begin
445 <  QSelect.GenerateParamNames := FGenerateParamNames;
445 >  QSelect.GenerateParamNames := GenerateParamNames;
446    InternalPrepare;
447   end;
448  
# Line 471 | Line 484 | begin
484    Result := SelectStmtHandle;
485   end;
486  
487 + function TIBQuery.CreateParser: TSelectSQLParser;
488 + begin
489 +  Result := inherited CreateParser;
490 +  Result.OnSQLChanging := QueryChanged;
491 + end;
492 +
493   function TIBQuery.GenerateQueryForLiveUpdate : Boolean;
494   begin
495    Result := False;
# Line 522 | Line 541 | begin
541   end;
542   *)
543   end.
544 <
544 >

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines