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 80 by tony, Mon Jan 1 11:31:07 2018 UTC vs.
Revision 105 by tony, Thu Jan 18 14:37:32 2018 UTC

# Line 53 | Line 53 | uses
53    unix,
54   {$ENDIF}
55    SysUtils, Classes, IBDatabase, IBExternals, IB,  IBSQL, Db,
56 <  IBUtils, IBBlob, IBSQLParser;
56 >  IBUtils, IBBlob, IBSQLParser, IBDatabaseInfo;
57  
58   const
59    BufferCacheSize    =  1000;  { Allocate cache in this many record chunks}
# Line 76 | Line 76 | type
76      function GetSQL(UpdateKind: TUpdateKind): TStrings; virtual; abstract;
77      procedure InternalSetParams(Params: ISQLParams; buff: PChar); overload;
78      procedure InternalSetParams(Query: TIBSQL; buff: PChar); overload;
79 +    procedure UpdateRecordFromQuery(QryResults: IResults; Buffer: PChar);
80      property DataSet: TIBCustomDataSet read GetDataSet write SetDataSet;
81    public
82      constructor Create(AOwner: TComponent); override;
# Line 208 | Line 209 | type
209       Note: y > 4 will default to Floats
210    }
211    TIBBCDField = class(TBCDField)
212 +  private
213 +    FIdentityColumn: boolean;
214    protected
215 +    procedure Bind(Binding: Boolean); override;
216      class procedure CheckTypeSize(Value: Integer); override;
217      function GetAsCurrency: Currency; override;
218      function GetAsString: string; override;
# Line 216 | Line 220 | type
220      function GetDataSize: Integer; override;
221    public
222      constructor Create(AOwner: TComponent); override;
223 +    property IdentityColumn: boolean read FIdentityColumn;
224    published
225      property Size default 8;
226    end;
227  
228 +  {The following integer field types extend the built in versions to enable IBX appplications
229 +   to check for an Identity column}
230 +
231 +  { TIBSmallintField }
232 +
233 +  TIBSmallintField = class(TSmallintField)
234 +  private
235 +    FIdentityColumn: boolean;
236 +  protected
237 +    procedure Bind(Binding: Boolean); override;
238 +  public
239 +    property IdentityColumn: boolean read FIdentityColumn;
240 +  end;
241 +
242 +  { TIBIntegerField }
243 +
244 +  TIBIntegerField = class(TIntegerField)
245 +  private
246 +    FIdentityColumn: boolean;
247 +  protected
248 +    procedure Bind(Binding: Boolean); override;
249 +  public
250 +    property IdentityColumn: boolean read FIdentityColumn;
251 +  end;
252 +
253 +  { TIBLargeIntField }
254 +
255 +  TIBLargeIntField = class(TLargeIntField)
256 +  private
257 +    FIdentityColumn: boolean;
258 +  protected
259 +    procedure Bind(Binding: Boolean); override;
260 +  public
261 +    property IdentityColumn: boolean read FIdentityColumn;
262 +  end;
263 +
264    {TIBMemoField}
265    {Allows us to show truncated text in DBGrids and anything else that uses
266     DisplayText}
# Line 274 | Line 315 | type
315      FFieldName: string;
316      FGeneratorName: string;
317      FIncrement: integer;
318 +    FQuery: TIBSQL;
319 +    function GetDatabase: TIBDatabase;
320 +    function GetTransaction: TIBTransaction;
321 +    procedure SetDatabase(AValue: TIBDatabase);
322 +    procedure SetGeneratorName(AValue: string);
323      procedure SetIncrement(const AValue: integer);
324 +    procedure SetTransaction(AValue: TIBTransaction);
325 +    procedure SetQuerySQL;
326    protected
327 <    function GetNextValue(ADatabase: TIBDatabase; ATransaction: TIBTransaction): integer;
327 >    function GetNextValue: integer;
328    public
329      constructor Create(Owner: TIBCustomDataSet);
330 +    destructor Destroy; override;
331      procedure Apply;
332      property Owner: TIBCustomDataSet read FOwner;
333 +    property Database: TIBDatabase read GetDatabase write SetDatabase;
334 +    property Transaction: TIBTransaction read GetTransaction write SetTransaction;
335    published
336 <    property Generator: string read FGeneratorName write FGeneratorName;
336 >    property Generator: string read FGeneratorName write SetGeneratorName;
337      property Field: string read FFieldName write FFieldName;
338      property Increment: integer read FIncrement write SetIncrement default 1;
339      property ApplyOnEvent: TIBGeneratorApplyOnEvent read FApplyOnEvent write FApplyOnEvent;
# Line 360 | Line 411 | type
411      FQRefresh,
412      FQSelect,
413      FQModify: TIBSQL;
414 +    FDatabaseInfo: TIBDatabaseInfo;
415      FRecordBufferSize: Integer;
416      FRecordCount: Integer;
417      FRecordSize: Integer;
# Line 389 | Line 441 | type
441      FInTransactionEnd: boolean;
442      FIBLinks: TList;
443      FFieldColumns: PFieldColumns;
444 +    procedure ColumnDataToBuffer(QryResults: IResults; ColumnIndex,
445 +      FieldIndex: integer; Buffer: PChar);
446      procedure InitModelBuffer(Qry: TIBSQL; Buffer: PChar);
447      function GetSelectStmtIntf: IStatement;
448      procedure SetUpdateMode(const Value: TUpdateMode);
# Line 443 | Line 497 | type
497      procedure SetTransaction(Value: TIBTransaction);
498      procedure SetUpdateRecordTypes(Value: TIBUpdateRecordTypes);
499      procedure SetUniDirectional(Value: Boolean);
500 +    procedure UpdateRecordFromQuery(QryResults: IResults; Buffer: PChar);
501      procedure RefreshParams;
502      function AdjustPosition(FCache: PChar; Offset: DWORD;
503                              Origin: Integer): DWORD;
# Line 791 | Line 846 | type
846      FCharacterSetName: RawByteString;
847      FCharacterSetSize: integer;
848      FCodePage: TSystemCodePage;
849 +    FIdentityColumn: boolean;
850      FRelationName: string;
851      FDataSize: integer;
852    published
# Line 801 | Line 857 | type
857      property RelationName: string read FRelationName write FRelationName;
858      property ArrayDimensions: integer read FArrayDimensions write FArrayDimensions;
859      property ArrayBounds: TArrayBounds read FArrayBounds write FArrayBounds;
860 +    property IdentityColumn: boolean read FIdentityColumn write FIdentityColumn default false;
861    end;
862  
863   const
864   DefaultFieldClasses: array[TFieldType] of TFieldClass = (
865      nil,                { ftUnknown }
866      TIBStringField,     { ftString }
867 <    TSmallintField,     { ftSmallint }
868 <    TIntegerField,      { ftInteger }
867 >    TIBSmallintField,   { ftSmallint }
868 >    TIBIntegerField,      { ftInteger }
869      TWordField,         { ftWord }
870      TBooleanField,      { ftBoolean }
871      TFloatField,        { ftFloat }
# Line 830 | Line 887 | DefaultFieldClasses: array[TFieldType] o
887      nil,                { ftCursor }
888      TStringField,       { ftFixedChar }
889      nil,    { ftWideString }
890 <    TLargeIntField,     { ftLargeInt }
890 >    TIBLargeIntField,     { ftLargeInt }
891      nil,          { ftADT }
892      TIBArrayField,        { ftArray }
893      nil,    { ftReference }
# Line 874 | Line 931 | type
931      FieldName : String;
932      COMPUTED_BLR : Boolean;
933      DEFAULT_VALUE : boolean;
934 +    IDENTITY_COLUMN : boolean;
935      NextField : TFieldNode;
936    end;
937  
# Line 926 | Line 984 | type
984      Result := str;
985    end;
986  
987 + { TIBLargeIntField }
988 +
989 + procedure TIBLargeIntField.Bind(Binding: Boolean);
990 + begin
991 +  inherited Bind(Binding);
992 +  if Binding and (FieldDef <> nil) then
993 +     FIdentityColumn := (FieldDef as TIBFieldDef).IdentityColumn;
994 + end;
995 +
996 + { TIBIntegerField }
997 +
998 + procedure TIBIntegerField.Bind(Binding: Boolean);
999 + begin
1000 +  inherited Bind(Binding);
1001 +  if Binding and (FieldDef <> nil) then
1002 +     FIdentityColumn := (FieldDef as TIBFieldDef).IdentityColumn;
1003 + end;
1004 +
1005 + { TIBSmallintField }
1006 +
1007 + procedure TIBSmallintField.Bind(Binding: Boolean);
1008 + begin
1009 +  inherited Bind(Binding);
1010 +  if Binding and (FieldDef <> nil) then
1011 +     FIdentityColumn := (FieldDef as TIBFieldDef).IdentityColumn;
1012 + end;
1013 +
1014   { TIBArray }
1015  
1016   procedure TIBArray.EventHandler(Sender: IArray; Reason: TArrayEventReason);
# Line 1035 | Line 1120 | begin
1120         {2: case 2 ignored. This should be handled by TIBWideMemo}
1121  
1122         3, {Assume UNICODE_FSS is really UTF8}
1123 <       4: {Include GB18030 - assuming UTF8 routine work for this codeset}
1123 >       4: {Include GB18030 - assuming UTF8 routines work for this codeset}
1124           if DisplayWidth = 0 then
1125             Result := ValidUTF8String(TextToSingleLine(Result))
1126           else
# Line 1237 | Line 1322 | begin
1322    Size := 8;
1323   end;
1324  
1325 + procedure TIBBCDField.Bind(Binding: Boolean);
1326 + begin
1327 +  inherited Bind(Binding);
1328 +  if Binding and (FieldDef <> nil) then
1329 +     FIdentityColumn := (FieldDef as TIBFieldDef).IdentityColumn;
1330 + end;
1331 +
1332   class procedure TIBBCDField.CheckTypeSize(Value: Integer);
1333   begin
1334   { No need to check as the base type is currency, not BCD }
# Line 1322 | Line 1414 | constructor TIBCustomDataSet.Create(AOwn
1414   begin
1415    inherited Create(AOwner);
1416    FBase := TIBBase.Create(Self);
1417 +  FDatabaseInfo := TIBDatabaseInfo.Create(self);
1418    FIBLinks := TList.Create;
1419    FCurrentRecord := -1;
1420    FDeletedRecords := 0;
# Line 1960 | Line 2053 | begin
2053    end;
2054   end;
2055  
2056 + {Update Buffer Fields from Query Results}
2057 +
2058 + procedure TIBCustomDataSet.UpdateRecordFromQuery(QryResults: IResults;
2059 +  Buffer: PChar);
2060 + var i, j: integer;
2061 + begin
2062 +  for i := 0 to QryResults.Count - 1 do
2063 +  begin
2064 +    j := GetFieldPosition(QryResults[i].GetAliasName);
2065 +    if j > 0 then
2066 +      ColumnDataToBuffer(QryResults,i,j,Buffer);
2067 +  end;
2068 + end;
2069 +
2070 +
2071 + {Move column data returned from query to row buffer}
2072 +
2073 + procedure TIBCustomDataSet.ColumnDataToBuffer(QryResults: IResults;
2074 +               ColumnIndex, FieldIndex: integer; Buffer: PChar);
2075 + var
2076 +  LocalData: PByte;
2077 +  LocalDate, LocalDouble: Double;
2078 +  LocalInt: Integer;
2079 +  LocalBool: wordBool;
2080 +  LocalInt64: Int64;
2081 +  LocalCurrency: Currency;
2082 +  ColData: ISQLData;
2083 + begin
2084 +  LocalData := nil;
2085 +  with PRecordData(Buffer)^.rdFields[FieldIndex], FFieldColumns^[FieldIndex] do
2086 +  begin
2087 +    QryResults.GetData(ColumnIndex,fdIsNull,fdDataLength,LocalData);
2088 +    if not fdIsNull then
2089 +    begin
2090 +      ColData := QryResults[ColumnIndex];
2091 +      case fdDataType of  {Get Formatted data for column types that need formatting}
2092 +        SQL_TIMESTAMP:
2093 +        begin
2094 +          LocalDate := TimeStampToMSecs(DateTimeToTimeStamp(ColData.AsDateTime));
2095 +          LocalData := PByte(@LocalDate);
2096 +        end;
2097 +        SQL_TYPE_DATE:
2098 +        begin
2099 +          LocalInt := DateTimeToTimeStamp(ColData.AsDateTime).Date;
2100 +          LocalData := PByte(@LocalInt);
2101 +        end;
2102 +        SQL_TYPE_TIME:
2103 +        begin
2104 +          LocalInt := DateTimeToTimeStamp(ColData.AsDateTime).Time;
2105 +          LocalData := PByte(@LocalInt);
2106 +        end;
2107 +        SQL_SHORT, SQL_LONG:
2108 +        begin
2109 +          if (fdDataScale = 0) then
2110 +          begin
2111 +            LocalInt := ColData.AsLong;
2112 +            LocalData := PByte(@LocalInt);
2113 +          end
2114 +          else
2115 +          if (fdDataScale >= (-4)) then
2116 +          begin
2117 +            LocalCurrency := ColData.AsCurrency;
2118 +            LocalData := PByte(@LocalCurrency);
2119 +          end
2120 +          else
2121 +          begin
2122 +           LocalDouble := ColData.AsDouble;
2123 +           LocalData := PByte(@LocalDouble);
2124 +          end;
2125 +        end;
2126 +        SQL_INT64:
2127 +        begin
2128 +          if (fdDataScale = 0) then
2129 +          begin
2130 +            LocalInt64 := ColData.AsInt64;
2131 +            LocalData := PByte(@LocalInt64);
2132 +          end
2133 +          else
2134 +          if (fdDataScale >= (-4)) then
2135 +          begin
2136 +            LocalCurrency := ColData.AsCurrency;
2137 +            LocalData := PByte(@LocalCurrency);
2138 +            end
2139 +            else
2140 +            begin
2141 +              LocalDouble := ColData.AsDouble;
2142 +              LocalData := PByte(@LocalDouble);
2143 +            end
2144 +        end;
2145 +        SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT:
2146 +        begin
2147 +          LocalDouble := ColData.AsDouble;
2148 +          LocalData := PByte(@LocalDouble);
2149 +        end;
2150 +        SQL_BOOLEAN:
2151 +        begin
2152 +          LocalBool := ColData.AsBoolean;
2153 +          LocalData := PByte(@LocalBool);
2154 +        end;
2155 +      end;
2156 +
2157 +      if fdDataType = SQL_VARYING then
2158 +        Move(LocalData^, Buffer[fdDataOfs], fdDataLength)
2159 +      else
2160 +        Move(LocalData^, Buffer[fdDataOfs], fdDataSize)
2161 +    end
2162 +    else {Null column}
2163 +    if fdDataType = SQL_VARYING then
2164 +      FillChar(Buffer[fdDataOfs],fdDataLength,0)
2165 +    else
2166 +      FillChar(Buffer[fdDataOfs],fdDataSize,0);
2167 +  end;
2168 + end;
2169 +
2170   { Read the record from FQSelect.Current into the record buffer
2171    Then write the buffer to in memory cache }
2172   procedure TIBCustomDataSet.FetchCurrentRecordToBuffer(Qry: TIBSQL;
# Line 1968 | Line 2175 | var
2175    pbd: PBlobDataArray;
2176    pda: PArrayDataArray;
2177    i, j: Integer;
1971  LocalData: PByte;
1972  LocalDate, LocalDouble: Double;
1973  LocalInt: Integer;
1974  LocalBool: wordBool;
1975  LocalInt64: Int64;
1976  LocalCurrency: Currency;
2178    FieldsLoaded: Integer;
2179    p: PRecordData;
2180   begin
# Line 2024 | Line 2225 | begin
2225          continue;
2226        end;
2227      if j > 0 then
2228 <    begin
2028 <      LocalData := nil;
2029 <      with p^.rdFields[j], FFieldColumns^[j] do
2030 <      begin
2031 <        Qry.Current.GetData(i,fdIsNull,fdDataLength,LocalData);
2032 <        if not fdIsNull then
2033 <        begin
2034 <          case fdDataType of  {Get Formatted data for column types that need formatting}
2035 <            SQL_TIMESTAMP:
2036 <            begin
2037 <              LocalDate := TimeStampToMSecs(DateTimeToTimeStamp(Qry[i].AsDateTime));
2038 <              LocalData := PByte(@LocalDate);
2039 <            end;
2040 <            SQL_TYPE_DATE:
2041 <            begin
2042 <              LocalInt := DateTimeToTimeStamp(Qry[i].AsDateTime).Date;
2043 <              LocalData := PByte(@LocalInt);
2044 <            end;
2045 <            SQL_TYPE_TIME:
2046 <            begin
2047 <              LocalInt := DateTimeToTimeStamp(Qry[i].AsDateTime).Time;
2048 <              LocalData := PByte(@LocalInt);
2049 <            end;
2050 <            SQL_SHORT, SQL_LONG:
2051 <            begin
2052 <              if (fdDataScale = 0) then
2053 <              begin
2054 <                LocalInt := Qry[i].AsLong;
2055 <                LocalData := PByte(@LocalInt);
2056 <              end
2057 <              else
2058 <              if (fdDataScale >= (-4)) then
2059 <              begin
2060 <                LocalCurrency := Qry[i].AsCurrency;
2061 <                LocalData := PByte(@LocalCurrency);
2062 <              end
2063 <              else
2064 <              begin
2065 <               LocalDouble := Qry[i].AsDouble;
2066 <               LocalData := PByte(@LocalDouble);
2067 <              end;
2068 <            end;
2069 <            SQL_INT64:
2070 <            begin
2071 <              if (fdDataScale = 0) then
2072 <              begin
2073 <                LocalInt64 := Qry[i].AsInt64;
2074 <                LocalData := PByte(@LocalInt64);
2075 <              end
2076 <              else
2077 <              if (fdDataScale >= (-4)) then
2078 <              begin
2079 <                LocalCurrency := Qry[i].AsCurrency;
2080 <                LocalData := PByte(@LocalCurrency);
2081 <                end
2082 <                else
2083 <                begin
2084 <                  LocalDouble := Qry[i].AsDouble;
2085 <                  LocalData := PByte(@LocalDouble);
2086 <                end
2087 <            end;
2088 <            SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT:
2089 <            begin
2090 <              LocalDouble := Qry[i].AsDouble;
2091 <              LocalData := PByte(@LocalDouble);
2092 <            end;
2093 <            SQL_BOOLEAN:
2094 <            begin
2095 <              LocalBool := Qry[i].AsBoolean;
2096 <              LocalData := PByte(@LocalBool);
2097 <            end;
2098 <          end;
2099 <
2100 <          if fdDataType = SQL_VARYING then
2101 <            Move(LocalData^, Buffer[fdDataOfs], fdDataLength)
2102 <          else
2103 <            Move(LocalData^, Buffer[fdDataOfs], fdDataSize)
2104 <        end
2105 <        else {Null column}
2106 <        if fdDataType = SQL_VARYING then
2107 <          FillChar(Buffer[fdDataOfs],fdDataLength,0)
2108 <        else
2109 <          FillChar(Buffer[fdDataOfs],fdDataSize,0);
2110 <      end;
2111 <    end;
2228 >      ColumnDataToBuffer(Qry.Current,i,j,Buffer);
2229    end;
2230    WriteRecordCache(RecordNumber, Buffer);
2231   end;
# Line 2355 | Line 2472 | begin
2472      SetInternalSQLParams(Qry.Params, Buff);
2473      Qry.ExecQuery;
2474    end;
2475 +  if Qry.FieldCount > 0 then {Has RETURNING Clause}
2476 +    UpdateRecordFromQuery(Qry.Current,Buff);
2477    PRecordData(Buff)^.rdUpdateStatus := usUnmodified;
2478    PRecordData(Buff)^.rdCachedUpdateStatus := cusUnmodified;
2479    SetModified(False);
# Line 2605 | Line 2724 | begin
2724      FQRefresh.Database := Value;
2725      FQSelect.Database := Value;
2726      FQModify.Database := Value;
2727 +    FDatabaseInfo.Database := Value;
2728 +    FGeneratorField.Database := Value;
2729    end;
2730   end;
2731  
# Line 2773 | Line 2894 | begin
2894      FQRefresh.Transaction := Value;
2895      FQSelect.Transaction := Value;
2896      FQModify.Transaction := Value;
2897 +    FGeneratorField.Transaction := Value;
2898    end;
2899   end;
2900  
# Line 3674 | Line 3796 | const
3796                 'and R.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME '+ {do not localize}
3797                 'and ((not F.RDB$COMPUTED_BLR is NULL) or ' + {do not localize}
3798                 '     (not F.RDB$DEFAULT_VALUE is NULL)) '; {do not localize}
3799 +
3800 +  DefaultSQLODS12 = 'Select F.RDB$COMPUTED_BLR, ' + {do not localize}
3801 +               'F.RDB$DEFAULT_VALUE, R.RDB$FIELD_NAME, R.RDB$IDENTITY_TYPE ' + {do not localize}
3802 +               'from RDB$RELATION_FIELDS R, RDB$FIELDS F ' + {do not localize}
3803 +               'where R.RDB$RELATION_NAME = :RELATION ' +  {do not localize}
3804 +               'and R.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME '+ {do not localize}
3805 +               'and ((not F.RDB$COMPUTED_BLR is NULL) or ' + {do not localize}
3806 +               '     (not F.RDB$DEFAULT_VALUE is NULL) or ' + {do not localize}
3807 +               '     ( not R.RDB$IDENTITY_TYPE is NULL))' ; {do not localize}
3808 +
3809   var
3810    FieldType: TFieldType;
3811    FieldSize: Word;
# Line 3714 | Line 3846 | var
3846        FField.FieldName := Query.Fields[2].AsString;
3847        FField.DEFAULT_VALUE := not Query.Fields[1].IsNull;
3848        FField.COMPUTED_BLR := not Query.Fields[0].IsNull;
3849 +      FField.IDENTITY_COLUMN := (Query.FieldCount > 3) and not Query.Fields[3].IsNull;
3850        FField.NextField := Result.FieldNodes;
3851        Result.FieldNodes := FField;
3852        Query.Next;
# Line 3767 | Line 3900 | var
3900          FField := Ffield.NextField;
3901    end;
3902  
3903 +  function Is_IDENTITY_COLUMN(Relation, Field : String) : Boolean;
3904 +  var
3905 +    FRelation : TRelationNode;
3906 +    FField : TFieldNode;
3907 +  begin
3908 +    FRelation := FRelationNodes;
3909 +    while Assigned(FRelation) and
3910 +         (FRelation.RelationName <> Relation) do
3911 +      FRelation := FRelation.NextRelation;
3912 +    if not Assigned(FRelation) then
3913 +      FRelation := Add_Node(Relation, Field);
3914 +    Result := false;
3915 +    FField := FRelation.FieldNodes;
3916 +    while Assigned(FField) do
3917 +      if FField.FieldName = Field then
3918 +      begin
3919 +        Result := Ffield.IDENTITY_COLUMN;
3920 +        Exit;
3921 +      end
3922 +      else
3923 +        FField := Ffield.NextField;
3924 +  end;
3925 +
3926    Procedure FreeNodes;
3927    var
3928      FRelation : TRelationNode;
# Line 3800 | Line 3956 | begin
3956      FieldIndex := 0;
3957      if (Length(FMappedFieldPosition) < SourceQuery.MetaData.Count) then
3958        SetLength(FMappedFieldPosition, SourceQuery.MetaData.Count);
3959 <    Query.SQL.Text := DefaultSQL;
3959 >    if FDatabaseInfo.ODSMajorVersion >= 12 then
3960 >      Query.SQL.Text := DefaultSQLODS12
3961 >    else
3962 >      Query.SQL.Text := DefaultSQL;
3963      Query.Prepare;
3964      SetLength(FAliasNameMap, SourceQuery.MetaData.Count);
3965      SetLength(FAliasNameList, SourceQuery.MetaData.Count);
# Line 3939 | Line 4098 | begin
4098              ArrayBounds := aArrayBounds;
4099              if (FieldName <> '') and (RelationName <> '') then
4100              begin
4101 +              IdentityColumn := Is_IDENTITY_COLUMN(RelationName, FieldName);
4102                if Has_COMPUTED_BLR(RelationName, FieldName) then
4103                begin
4104                  Attributes := [faReadOnly];
# Line 4841 | Line 5001 | begin
5001    InternalSetParams(Query.Params,buff);
5002   end;
5003  
5004 + procedure TIBDataSetUpdateObject.UpdateRecordFromQuery(QryResults: IResults;
5005 +  Buffer: PChar);
5006 + begin
5007 +  if not Assigned(DataSet) then Exit;
5008 +  DataSet.UpdateRecordFromQuery(QryResults, Buffer);
5009 + end;
5010 +
5011   function TIBDSBlobStream.GetSize: Int64;
5012   begin
5013    Result := FBlobStream.BlobSize;
# Line 4901 | Line 5068 | end;
5068  
5069   procedure TIBGenerator.SetIncrement(const AValue: integer);
5070   begin
5071 +  if FIncrement = AValue then Exit;
5072    if AValue < 0 then
5073 <     raise Exception.Create('A Generator Increment cannot be negative');
5074 <  FIncrement := AValue
5073 >    IBError(ibxeNegativeGenerator,[]);
5074 >  FIncrement := AValue;
5075 >  SetQuerySQL;
5076   end;
5077  
5078 < function TIBGenerator.GetNextValue(ADatabase: TIBDatabase;
4910 <  ATransaction: TIBTransaction): integer;
5078 > procedure TIBGenerator.SetTransaction(AValue: TIBTransaction);
5079   begin
5080 <  with TIBSQL.Create(nil) do
5081 <  try
5082 <    Database := ADatabase;
5083 <    Transaction := ATransaction;
5084 <    if not assigned(Database) then
5085 <       IBError(ibxeCannotSetDatabase,[]);
5086 <    if not assigned(Transaction) then
5087 <       IBError(ibxeCannotSetTransaction,[]);
5088 <    with Transaction do
5089 <      if not InTransaction then StartTransaction;
5090 <    SQL.Text := Format('Select Gen_ID(%s,%d) as ID From RDB$Database',[FGeneratorName,Increment]);
5091 <    Prepare;
5080 >  FQuery.Transaction := AValue;
5081 > end;
5082 >
5083 > procedure TIBGenerator.SetQuerySQL;
5084 > begin
5085 >  FQuery.SQL.Text := Format('Select Gen_ID(%s,%d) From RDB$Database',[FGeneratorName,Increment]);
5086 > end;
5087 >
5088 > function TIBGenerator.GetDatabase: TIBDatabase;
5089 > begin
5090 >  Result := FQuery.Database;
5091 > end;
5092 >
5093 > function TIBGenerator.GetTransaction: TIBTransaction;
5094 > begin
5095 >  Result := FQuery.Transaction;
5096 > end;
5097 >
5098 > procedure TIBGenerator.SetDatabase(AValue: TIBDatabase);
5099 > begin
5100 >  FQuery.Database := AValue;
5101 > end;
5102 >
5103 > procedure TIBGenerator.SetGeneratorName(AValue: string);
5104 > begin
5105 >  if FGeneratorName = AValue then Exit;
5106 >  FGeneratorName := AValue;
5107 >  SetQuerySQL;
5108 > end;
5109 >
5110 > function TIBGenerator.GetNextValue: integer;
5111 > begin
5112 >  with FQuery do
5113 >  begin
5114 >    Transaction.Active := true;
5115      ExecQuery;
5116      try
5117 <      Result := FieldByName('ID').AsInteger
5117 >      Result := Fields[0].AsInteger
5118      finally
5119        Close
5120      end;
4930  finally
4931    Free
5121    end;
5122   end;
5123  
# Line 4936 | Line 5125 | constructor TIBGenerator.Create(Owner: T
5125   begin
5126    FOwner := Owner;
5127    FIncrement := 1;
5128 +  FQuery := TIBSQL.Create(nil);
5129 + end;
5130 +
5131 + destructor TIBGenerator.Destroy;
5132 + begin
5133 +  if assigned(FQuery) then FQuery.Free;
5134 +  inherited Destroy;
5135   end;
5136  
5137  
5138   procedure TIBGenerator.Apply;
5139   begin
5140 <  if (FGeneratorName <> '') and (FFieldName <> '') and Owner.FieldByName(FFieldName).IsNull then
5141 <    Owner.FieldByName(FFieldName).AsInteger := GetNextValue(Owner.Database,Owner.Transaction);
5140 >  if assigned(Database) and assigned(Transaction) and
5141 >       (FGeneratorName <> '') and (FFieldName <> '') and Owner.FieldByName(FFieldName).IsNull then
5142 >    Owner.FieldByName(FFieldName).AsInteger := GetNextValue;
5143   end;
5144  
5145  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines