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 23 by tony, Fri Mar 13 10:26:52 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 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;
122 >    property Params: TParams read FParams write SetParamsList;
123      property UniDirectional default False;
124      property UpdateObject;
125      property Filtered;
# Line 141 | Line 144 | begin
144    TStringList(SQL).OnChange := QueryChanged;
145    FParams := TParams.Create(Self);
146    ParamCheck := True;
144  FGenerateParamNames := False;
147    FRowsAffected := -1;
148   end;
149  
# Line 163 | Line 165 | procedure TIBQuery.InternalOpen;
165   begin
166    ActivateConnection();
167    ActivateTransaction;
168 <  QSelect.GenerateParamNames := FGenerateParamNames;
168 >  QSelect.GenerateParamNames := GenerateParamNames;
169    SetPrepared(True);
170    if DataSource <> nil then
171      SetParamsFromCursor;
# Line 216 | Line 218 | 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);
# Line 261 | Line 272 | begin
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;
# Line 381 | Line 393 | procedure TIBQuery.SetParams;
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 <      SQLParams[i].IsNull := True
403 >      SQLParam.IsNull := True
404      else begin
405 <      SQLParams[i].IsNull := False;
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 <            SQLParams[i].AsPointer := Buffer;
412 >            SQLParam.AsPointer := Buffer;
413            finally
414              FreeMem(Buffer);
415            end;
416          end;
417          ftString:
418 <          SQLParams[i].AsString := Params[i].AsString;
419 <        ftBoolean, ftSmallint, ftWord:
420 <          SQLParams[i].AsShort := Params[i].AsSmallInt;
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 <          SQLParams[i].AsLong := Params[i].AsInteger;
425 < {        ftLargeInt:
426 <          SQLParams[i].AsInt64 := Params[i].AsLargeInt;  }
424 >          SQLParam.AsLong := Params[i].AsInteger;
425 >        ftLargeInt:
426 >          SQLParam.AsInt64 := Params[i].AsLargeInt;
427          ftFloat:
428 <         SQLParams[i].AsDouble := Params[i].AsFloat;
428 >         SQLParam.AsDouble := Params[i].AsFloat;
429          ftBCD, ftCurrency:
430 <          SQLParams[i].AsCurrency := Params[i].AsCurrency;
430 >          SQLParam.AsCurrency := Params[i].AsCurrency;
431          ftDate:
432 <          SQLParams[i].AsDate := Params[i].AsDateTime;
432 >          SQLParam.AsDate := Params[i].AsDateTime;
433          ftTime:
434 <          SQLParams[i].AsTime := Params[i].AsDateTime;
434 >          SQLParam.AsTime := Params[i].AsDateTime;
435          ftDateTime:
436 <          SQLParams[i].AsDateTime := Params[i].AsDateTime;
436 >          SQLParam.AsDateTime := Params[i].AsDateTime;
437          ftBlob, ftMemo:
438 <          SQLParams[i].AsString := Params[i].AsString;
438 >          SQLParam.AsString := Params[i].AsString;
439          else
440            IBError(ibxeNotSupported, [nil]);
441        end;
# Line 429 | Line 445 | end;
445  
446   procedure TIBQuery.PrepareSQL(Value: PChar);
447   begin
448 <  QSelect.GenerateParamNames := FGenerateParamNames;
448 >  QSelect.GenerateParamNames := GenerateParamNames;
449    InternalPrepare;
450   end;
451  
# Line 471 | Line 487 | 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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines