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

Comparing ibx/trunk/runtime/IBCustomDataSet.pas (file contents):
Revision 18 by tony, Sat Dec 28 19:22:24 2013 UTC vs.
Revision 19 by tony, Mon Jul 7 13:00:15 2014 UTC

# Line 198 | Line 198 | type
198  
199    TIBCustomDataSet = class(TDataset)
200    private
201 +    FGenerateParamNames: Boolean;
202      FGeneratorField: TIBGenerator;
203      FNeedsRefresh: Boolean;
204      FForcedRefresh: Boolean;
# Line 250 | Line 251 | type
251      FBeforeTransactionEnd,
252      FAfterTransactionEnd,
253      FTransactionFree: TNotifyEvent;
254 +    FAliasNameMap: array of string;
255  
256      function GetSelectStmtHandle: TISC_STMT_HANDLE;
257      procedure SetUpdateMode(const Value: TUpdateMode);
# Line 321 | Line 323 | type
323      procedure DeactivateTransaction;
324      procedure CheckDatasetClosed;
325      procedure CheckDatasetOpen;
326 +    procedure FieldDefsFromQuery(SourceQuery: TIBSQL);
327      function GetActiveBuf: PChar;
328      procedure InternalBatchInput(InputObject: TIBBatchInput); virtual;
329      procedure InternalBatchOutput(OutputObject: TIBBatchOutput); virtual;
# Line 362 | Line 365 | type
365      function GetBookmarkFlag(Buffer: PChar): TBookmarkFlag; override;
366      function GetCanModify: Boolean; override;
367      function GetDataSource: TDataSource; override;
368 +    function GetDBAliasName(FieldNo: integer): string;
369 +    function GetFieldDefFromAlias(aliasName: string): TFieldDef;
370      function GetFieldClass(FieldType: TFieldType): TFieldClass; override;
371      function GetRecNo: Integer; override;
372      function GetRecord(Buffer: PChar; GetMode: TGetMode;
# Line 390 | Line 395 | type
395      procedure SetBookmarkData(Buffer: PChar; Data: Pointer); override;
396      procedure SetCachedUpdates(Value: Boolean);
397      procedure SetDataSource(Value: TDataSource);
398 +    procedure SetGenerateParamNames(AValue: Boolean); virtual;
399      procedure SetFieldData(Field : TField; Buffer : Pointer); override;
400      procedure SetFieldData(Field : TField; Buffer : Pointer;
401        NativeFormat : Boolean); overload; override;
# Line 456 | Line 462 | type
462      function GetFieldData(FieldNo: Integer; Buffer: Pointer): Boolean; overload; (*override;*)
463      function GetFieldData(Field : TField; Buffer : Pointer;
464        NativeFormat : Boolean) : Boolean; overload; override;
465 +    property GenerateParamNames: Boolean read FGenerateParamNames write SetGenerateParamNames;
466      function Locate(const KeyFields: string; const KeyValues: Variant;
467                      Options: TLocateOptions): Boolean; override;
468      function Lookup(const KeyFields: string; const KeyValues: Variant;
# Line 543 | Line 550 | type
550      property SelectSQL;
551      property ModifySQL;
552      property GeneratorField;
553 +    property GenerateParamNames;
554      property ParamCheck;
555      property UniDirectional;
556      property Filtered;
# Line 859 | Line 867 | begin
867    FQModify.GoToFirstRecordOnExecute := False;
868    FUpdateRecordTypes := [cusUnmodified, cusModified, cusInserted];
869    FParamCheck := True;
870 +  FGenerateParamNames := False;
871    FForcedRefresh := False;
872    {Bookmark Size is Integer for IBX}
873    BookmarkSize := SizeOf(Integer);
# Line 1895 | Line 1904 | begin
1904      begin
1905        if not FQSelect.Prepared then
1906        begin
1907 +        FQSelect.GenerateParamNames := FGenerateParamNames;
1908          FQSelect.ParamCheck := ParamCheck;
1909          FQSelect.Prepare;
1910        end;
1911 +      FQDelete.GenerateParamNames := FGenerateParamNames;
1912        if (Trim(FQDelete.SQL.Text) <> '') and (not FQDelete.Prepared) then
1913          FQDelete.Prepare;
1914 +      FQInsert.GenerateParamNames := FGenerateParamNames;
1915        if (Trim(FQInsert.SQL.Text) <> '') and (not FQInsert.Prepared) then
1916          FQInsert.Prepare;
1917 +      FQRefresh.GenerateParamNames := FGenerateParamNames;
1918        if (Trim(FQRefresh.SQL.Text) <> '') and (not FQRefresh.Prepared) then
1919          FQRefresh.Prepare;
1920 +      FQModify.GenerateParamNames := FGenerateParamNames;
1921        if (Trim(FQModify.SQL.Text) <> '') and (not FQModify.Prepared) then
1922          FQModify.Prepare;
1923        FInternalPrepared := True;
# Line 2197 | Line 2211 | begin
2211      InternalClose;
2212    if FInternalPrepared then
2213      InternalUnPrepare;
2214 +  FieldDefs.Clear;
2215 +  FieldDefs.Updated := false
2216   end;
2217  
2218   { I can "undelete" uninserted records (make them "inserted" again).
# Line 2563 | Line 2579 | begin
2579      result := FDataLink.DataSource;
2580   end;
2581  
2582 + function TIBCustomDataSet.GetDBAliasName(FieldNo: integer): string;
2583 + begin
2584 +  Result := FAliasNameMap[FieldNo-1]
2585 + end;
2586 +
2587 + function TIBCustomDataSet.GetFieldDefFromAlias(aliasName: string): TFieldDef;
2588 + var
2589 +   i: integer;
2590 + begin
2591 +   Result := nil;
2592 +   for i := 0 to Length(FAliasNameMap) - 1 do
2593 +       if FAliasNameMap[i] = aliasName then
2594 +       begin
2595 +         Result := FieldDefs[i+1];
2596 +         Exit
2597 +       end;
2598 + end;
2599 +
2600   function TIBCustomDataSet.GetFieldClass(FieldType: TFieldType): TFieldClass;
2601   begin
2602    Result := DefaultFieldClasses[FieldType];
# Line 2873 | Line 2907 | begin
2907   end;
2908  
2909   procedure TIBCustomDataSet.InternalInitFieldDefs;
2910 + begin
2911 +  if not InternalPrepared then
2912 +  begin
2913 +    InternalPrepare;
2914 +    exit;
2915 +  end;
2916 +   FieldDefsFromQuery(FQSelect);
2917 + end;
2918 +
2919 + procedure TIBCustomDataSet.FieldDefsFromQuery(SourceQuery: TIBSQL);
2920   const
2921    DefaultSQL = 'Select F.RDB$COMPUTED_BLR, ' + {do not localize}
2922                 'F.RDB$DEFAULT_VALUE, R.RDB$FIELD_NAME ' + {do not localize}
# Line 2886 | Line 2930 | var
2930    FieldSize: Word;
2931    FieldNullable : Boolean;
2932    i, FieldPosition, FieldPrecision: Integer;
2933 <  FieldAliasName: string;
2933 >  FieldAliasName, DBAliasName: string;
2934    RelationName, FieldName: string;
2935    Query : TIBSQL;
2936    FieldIndex: Integer;
# Line 2986 | Line 3030 | var
3030    end;
3031  
3032   begin
2989  if not InternalPrepared then
2990  begin
2991    InternalPrepare;
2992    exit;
2993  end;
3033    FRelationNodes := TRelationNode.Create;
3034    FNeedsRefresh := False;
3035    Database.InternalTransaction.StartTransaction;
# Line 3001 | Line 3040 | begin
3040      FieldDefs.BeginUpdate;
3041      FieldDefs.Clear;
3042      FieldIndex := 0;
3043 <    if (Length(FMappedFieldPosition) < FQSelect.Current.Count) then
3044 <      SetLength(FMappedFieldPosition, FQSelect.Current.Count);
3043 >    if (Length(FMappedFieldPosition) < SourceQuery.Current.Count) then
3044 >      SetLength(FMappedFieldPosition, SourceQuery.Current.Count);
3045      Query.SQL.Text := DefaultSQL;
3046      Query.Prepare;
3047 <    for i := 0 to FQSelect.Current.Count - 1 do
3048 <      with FQSelect.Current[i].Data^ do
3047 >    SetLength(FAliasNameMap, SourceQuery.Current.Count);
3048 >    for i := 0 to SourceQuery.Current.Count - 1 do
3049 >      with SourceQuery.Current[i].Data^ do
3050        begin
3051          { Get the field name }
3052 <        SetString(FieldAliasName, aliasname, aliasname_length);
3052 >        FieldAliasName := SourceQuery.Current[i].Name;
3053 >        SetString(DBAliasName, aliasname, aliasname_length);
3054          SetString(RelationName, relname, relname_length);
3055          SetString(FieldName, sqlname, sqlname_length);
3056          FieldSize := 0;
3057          FieldPrecision := 0;
3058 <        FieldNullable := FQSelect.Current[i].IsNullable;
3058 >        FieldNullable := SourceQuery.Current[i].IsNullable;
3059          case sqltype and not 1 of
3060            { All VARCHAR's must be converted to strings before recording
3061             their values }
# Line 3100 | Line 3141 | begin
3141            with FieldDefs.AddFieldDef do
3142            begin
3143              Name := FieldAliasName;
3144 < (*           FieldNo := FieldPosition;*)
3144 >            FAliasNameMap[FieldNo-1] := DBAliasName;
3145              DataType := FieldType;
3146              Size := FieldSize;
3147              Precision := FieldPrecision;
# Line 3589 | Line 3630 | begin
3630    begin
3631      CheckDatasetClosed;
3632      FieldDefs.Clear;
3633 +    FieldDefs.Updated := false;
3634      FInternalPrepared := False;
3635    end;
3636   end;
# Line 3628 | Line 3670 | begin
3670    Result := FQSelect.Handle;
3671   end;
3672  
3673 + procedure TIBCustomDataSet.SetGenerateParamNames(AValue: Boolean);
3674 + begin
3675 +  if FGenerateParamNames = AValue then Exit;
3676 +  FGenerateParamNames := AValue;
3677 +  Disconnect
3678 + end;
3679 +
3680   procedure TIBCustomDataSet.InitRecord(Buffer: PChar);
3681   begin
3682    inherited InitRecord(Buffer);
# Line 4035 | Line 4084 | begin
4084      Owner.FieldByName(FFieldName).AsInteger := GetNextValue(Owner.Database,Owner.Transaction);
4085   end;
4086  
4087 < end.
4087 > end.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines