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 39 by tony, Tue May 17 08:14:52 2016 UTC vs.
Revision 118 by tony, Mon Jan 22 13:58:14 2018 UTC

# Line 27 | Line 27
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 - 2015                                                }
30 > {    Associates Ltd 2011 - 2015                                          }
31   {                                                                        }
32   {************************************************************************}
33  
34   unit IBCustomDataSet;
35  
36 {$IF FPC_FULLVERSION >= 20700 }
37 {$codepage UTF8}
38 {$DEFINE HAS_ANSISTRING_CODEPAGE}
39 {$DEFINE NEW_TBOOKMARK}
40 {$ENDIF}
41
36   {$R-}
37  
38 + {$IFDEF FPC}
39   {$Mode Delphi}
40 + {$codepage UTF8}
41 + {$ENDIF}
42  
43   {$IFDEF DELPHI}
44   {$DEFINE TDBDFIELD_IS_BCD}
# Line 55 | Line 52 | uses
52   {$ELSE}
53    unix,
54   {$ENDIF}
55 <  SysUtils, Classes, IBDatabase, IBExternals, IB, IBHeader,  IBSQL, Db,
56 <  IBUtils, IBBlob, IBSQLParser;
55 >  SysUtils, Classes, IBDatabase, IBExternals, IB,  IBSQL, Db,
56 >  IBUtils, IBBlob, IBSQLParser, IBDatabaseInfo;
57  
58   const
59    BufferCacheSize    =  1000;  { Allocate cache in this many record chunks}
# Line 77 | Line 74 | type
74      procedure SetDataSet(ADataSet: TIBCustomDataSet); virtual; abstract;
75      procedure Apply(UpdateKind: TUpdateKind; buff: PChar); virtual; abstract;
76      function GetSQL(UpdateKind: TUpdateKind): TStrings; virtual; abstract;
77 <    procedure InternalSetParams(Query: TIBSQL; buff: PChar);
77 >    procedure InternalSetParams(Params: ISQLParams; buff: PChar); overload;
78 >    procedure InternalSetParams(Query: TIBSQL; buff: PChar); overload;
79 >    procedure UpdateRecordFromQuery(UpdateKind: TUpdateKind; QryResults: IResults; Buffer: PChar);
80      property DataSet: TIBCustomDataSet read GetDataSet write SetDataSet;
81    public
82      constructor Create(AOwner: TComponent); override;
# Line 88 | Line 87 | type
87  
88    TBlobDataArray = array[0..0] of TIBBlobStream;
89    PBlobDataArray = ^TBlobDataArray;
90 +  TIBArrayField = class;
91  
92 <  { TIBCustomDataSet }
93 <  TFieldData = record
94 <    fdDataType: Short;
95 <    fdDataScale: Short;
96 <    fdNullable: Boolean;
97 <    fdIsNull: Boolean;
98 <    fdDataSize: Short;
99 <    fdDataLength: Short;
100 <    fdDataOfs: Integer;
92 >  { TIBArray }
93 >
94 >  {Wrapper class to support array cache in TIBCustomDataset and event handling}
95 >
96 >  TIBArray = class
97 >  private
98 >    FArray: IArray;
99 >    FRecNo: integer;
100 >    FField: TIBArrayField;
101 >    procedure EventHandler(Sender: IArray; Reason: TArrayEventReason);
102 >  public
103 >    constructor Create(aField: TIBArrayField; anArray: IArray);
104 >    destructor Destroy; override;
105 >    property ArrayIntf: IArray read FArray;
106    end;
107 <  PFieldData = ^TFieldData;
107 >
108 >  TArrayDataArray = array [0..0] of TIBArray;
109 >  PArrayDataArray = ^TArrayDataArray;
110 >
111 >  { TIBCustomDataSet }
112  
113    TCachedUpdateStatus = (
114                           cusUnmodified, cusModified, cusInserted,
# Line 110 | Line 119 | type
119    end;
120    PIBDBKey = ^TIBDBKey;
121  
122 +  PFieldData = ^TFieldData;
123 +  TFieldData = record
124 +   fdIsNull: Boolean;
125 +   fdDataLength: Short;
126 + end;
127 +
128 + PColumnData = ^TColumnData;
129 + TColumnData = record
130 +  fdDataType: Short;
131 +  fdDataScale: Short;
132 +  fdNullable: Boolean;
133 +  fdDataSize: Short;
134 +  fdDataOfs: Integer;
135 +  fdCodePage: TSystemCodePage;
136 + end;
137 +
138 + PFieldColumns = ^TFieldColumns;
139 + TFieldColumns =  array[1..1] of TColumnData;
140 +
141    TRecordData = record
142      rdBookmarkFlag: TBookmarkFlag;
143      rdFieldCount: Short;
# Line 122 | Line 150 | type
150    end;
151    PRecordData = ^TRecordData;
152  
153 +  { TIBArrayField }
154 +
155 +  TIBArrayField = class(TField)
156 +  private
157 +    FArrayBounds: TArrayBounds;
158 +    FArrayDimensions: integer;
159 +    FRelationName: string;
160 +    FCacheOffset: word;
161 +    function GetArrayID: TISC_QUAD;
162 +    function GetArrayIntf: IArray;
163 +    procedure SetArrayIntf(AValue: IArray);
164 +  protected
165 +    class procedure CheckTypeSize(AValue: Longint); override;
166 +    function GetAsString: string; override;
167 +    function GetDataSize: Integer; override;
168 +    procedure Bind(Binding: Boolean); override;
169 +  public
170 +    constructor Create(AOwner: TComponent); override;
171 +    function CreateArray: IArray;
172 +    property ArrayID: TISC_QUAD read GetArrayID;
173 +    property ArrayIntf: IArray read GetArrayIntf write SetArrayIntf;
174 +    property ArrayDimensions: integer read FArrayDimensions write FArrayDimensions;
175 +    property ArrayBounds: TArrayBounds read FArrayBounds write FArrayBounds;
176 +  end;
177 +
178    { TIBStringField allows us to have strings longer than 8196 }
179  
180    TIBStringField = class(TStringField)
181    private
182      FCharacterSetName: RawByteString;
183      FCharacterSetSize: integer;
184 +    FAutoFieldSize: boolean;
185 +    FCodePage: TSystemCodePage;
186 +    FDataSize: integer;
187    protected
188 <    function GetDefaultWidth: Longint; override;
188 >    procedure Bind(Binding: Boolean); override;
189 >    function GetDataSize: Integer; override;
190    public
191      constructor Create(aOwner: TComponent); override;
192      class procedure CheckTypeSize(Value: Integer); override;
# Line 139 | Line 196 | type
196      procedure SetAsString(const Value: string); override;
197      property CharacterSetName: RawByteString read FCharacterSetName write FCharacterSetName;
198      property CharacterSetSize: integer read FCharacterSetSize write FCharacterSetSize;
199 <    {$IFDEF HAS_ANSISTRING_CODEPAGE}
200 <    private
201 <      FCodePage: TSystemCodePage;
145 <    public
146 <      property CodePage: TSystemCodePage read FCodePage write FCodePage;
147 <    {$ENDIF}
148 <  end;
149 <
150 <  { TIBWideStringField }
151 <
152 <  TIBWideStringField = class(TWideStringField)
153 <  private
154 <    FCharacterSetName: RawByteString;
155 <    FCharacterSetSize: integer;
156 <  public
157 <    property CharacterSetName: RawByteString read FCharacterSetName write FCharacterSetName;
158 <    property CharacterSetSize: integer read FCharacterSetSize write FCharacterSetSize;
199 >    property CodePage: TSystemCodePage read FCodePage write FCodePage;
200 >  published
201 >    property AutoFieldSize: boolean read FAutoFieldSize write FAutoFieldSize default true;
202    end;
203  
204    { TIBBCDField }
# Line 166 | 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 174 | 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 189 | Line 272 | type
272       FDisplayTextAsClassName: boolean;
273       function GetTruncatedText: string;
274     protected
275 +     procedure Bind(Binding: Boolean); override;
276       function GetAsString: string; override;
277       function GetDefaultWidth: Longint; override;
278       procedure GetText(var AText: string; ADisplayText: Boolean); override;
# Line 200 | Line 284 | type
284     published
285       property DisplayTextAsClassName: boolean read FDisplayTextAsClassName
286                                              write FDisplayTextAsClassName;
203   {$IFDEF HAS_ANSISTRING_CODEPAGE}
287     private
288       FCodePage: TSystemCodePage;
289       FFCodePage: TSystemCodePage;
290     public
291       property CodePage: TSystemCodePage read FFCodePage write FFCodePage;
209   {$ENDIF}
210   end;
211
212   { TIBWideMemoField }
213
214   TIBWideMemoField = class(TWideMemoField)
215   private
216     FCharacterSetName: RawByteString;
217     FCharacterSetSize: integer;
218     FDisplayTextAsClassName: boolean;
219     function GetTruncatedText: string;
220   protected
221     function GetDefaultWidth: Longint; override;
222     procedure GetText(var AText: string; ADisplayText: Boolean); override;
223   public
224     constructor Create(AOwner: TComponent); override;
225     property CharacterSetName: RawByteString read FCharacterSetName write FCharacterSetName;
226     property CharacterSetSize: integer read FCharacterSetSize write FCharacterSetSize;
227   published
228      property DisplayTextAsClassName: boolean read FDisplayTextAsClassName
229                                             write FDisplayTextAsClassName;
292     end;
293  
294    TIBDataLink = class(TDetailDataLink)
# Line 253 | 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 284 | Line 356 | type
356    TIBAutoCommit = (acDisabled, acCommitRetaining);
357  
358    { TIBCustomDataSet }
359 +
360    TIBUpdateAction = (uaFail, uaAbort, uaSkip, uaRetry, uaApply, uaApplied);
361  
362    TIBUpdateErrorEvent = procedure(DataSet: TDataSet; E: EDatabaseError;
# Line 298 | Line 371 | type
371  
372    TOnValidatePost = procedure (Sender: TObject; var CancelPost: boolean) of object;
373  
374 +  TOnDeleteReturning = procedure (Sender: TObject; QryResults: IResults) of object;
375 +
376    TIBCustomDataSet = class(TDataset)
377    private
378 +    FAllowAutoActivateTransaction: Boolean;
379 +    FArrayFieldCount: integer;
380 +    FArrayCacheOffset: integer;
381      FAutoCommit: TIBAutoCommit;
382      FGenerateParamNames: Boolean;
383      FGeneratorField: TIBGenerator;
384      FNeedsRefresh: Boolean;
385      FForcedRefresh: Boolean;
386      FDidActivate: Boolean;
309    FIBLoaded: Boolean;
387      FBase: TIBBase;
388      FBlobCacheOffset: Integer;
389      FBlobStreamList: TList;
390 +    FArrayList: TList;
391      FBufferChunks: Integer;
392      FBufferCache,
393      FOldBufferCache: PChar;
# Line 327 | Line 405 | type
405      FDeletedRecords: Long;
406      FModelBuffer,
407      FOldBuffer: PChar;
408 +    FOnDeleteReturning: TOnDeleteReturning;
409      FOnValidatePost: TOnValidatePost;
410      FOpen: Boolean;
411      FInternalPrepared: Boolean;
# Line 335 | Line 414 | type
414      FQRefresh,
415      FQSelect,
416      FQModify: TIBSQL;
417 +    FDatabaseInfo: TIBDatabaseInfo;
418      FRecordBufferSize: Integer;
419      FRecordCount: Integer;
420      FRecordSize: Integer;
# Line 363 | Line 443 | type
443      FCloseAction: TTransactionAction;
444      FInTransactionEnd: boolean;
445      FIBLinks: TList;
446 <    function GetSelectStmtHandle: TISC_STMT_HANDLE;
446 >    FFieldColumns: PFieldColumns;
447 >    FBufferUpdatedOnQryReturn: boolean;
448 >    procedure ColumnDataToBuffer(QryResults: IResults; ColumnIndex,
449 >      FieldIndex: integer; Buffer: PChar);
450 >    procedure InitModelBuffer(Qry: TIBSQL; Buffer: PChar);
451 >    function GetSelectStmtIntf: IStatement;
452      procedure SetUpdateMode(const Value: TUpdateMode);
453      procedure SetUpdateObject(Value: TIBDataSetUpdateObject);
454  
# Line 375 | Line 460 | type
460      function CanRefresh: Boolean;
461      procedure CheckEditState;
462      procedure ClearBlobCache;
463 +    procedure ClearArrayCache;
464      procedure ClearIBLinks;
465      procedure CopyRecordBuffer(Source, Dest: Pointer);
466      procedure DoBeforeDatabaseDisconnect(Sender: TObject);
# Line 383 | Line 469 | type
469      procedure DoBeforeTransactionEnd(Sender: TObject; Action: TTransactionAction);
470      procedure DoAfterTransactionEnd(Sender: TObject);
471      procedure DoTransactionFree(Sender: TObject);
472 +    procedure DoDeleteReturning(QryResults: IResults);
473      procedure FetchCurrentRecordToBuffer(Qry: TIBSQL; RecordNumber: Integer;
474                                           Buffer: PChar);
475      function GetDatabase: TIBDatabase;
389    function GetDBHandle: PISC_DB_HANDLE;
476      function GetDeleteSQL: TStrings;
477      function GetInsertSQL: TStrings;
478 <    function GetSQLParams: TIBXSQLDA;
478 >    function GetSQLParams: ISQLParams;
479      function GetRefreshSQL: TStrings;
480      function GetSelectSQL: TStrings;
481 <    function GetStatementType: TIBSQLTypes;
481 >    function GetStatementType: TIBSQLStatementTypes;
482      function GetModifySQL: TStrings;
483      function GetTransaction: TIBTransaction;
398    function GetTRHandle: PISC_TR_HANDLE;
484      function GetParser: TSelectSQLParser;
485      procedure InternalDeleteRecord(Qry: TIBSQL; Buff: Pointer); virtual;
486      function InternalLocate(const KeyFields: string; const KeyValues: Variant;
# Line 410 | Line 495 | type
495      procedure SetDatabase(Value: TIBDatabase);
496      procedure SetDeleteSQL(Value: TStrings);
497      procedure SetInsertSQL(Value: TStrings);
498 <    procedure SetInternalSQLParams(Qry: TIBSQL; Buffer: Pointer);
498 >    procedure SetInternalSQLParams(Params: ISQLParams; Buffer: Pointer);
499      procedure SetRefreshSQL(Value: TStrings);
500      procedure SetSelectSQL(Value: TStrings);
501      procedure SetModifySQL(Value: TStrings);
502      procedure SetTransaction(Value: TIBTransaction);
503      procedure SetUpdateRecordTypes(Value: TIBUpdateRecordTypes);
504      procedure SetUniDirectional(Value: Boolean);
505 +    procedure UpdateRecordFromQuery(QryResults: IResults; Buffer: PChar);
506      procedure RefreshParams;
507      function AdjustPosition(FCache: PChar; Offset: DWORD;
508                              Origin: Integer): DWORD;
# Line 450 | Line 536 | type
536      procedure SQLChanging(Sender: TObject); virtual;
537      procedure SQLChanged(Sender: TObject); virtual;
538  
539 < (*    { IProviderSupport }
539 >    { IProviderSupport }
540      procedure PSEndTransaction(Commit: Boolean); override;
541      function PSExecuteStatement(const ASQL: string; AParams: TParams;
542        ResultSet: Pointer = nil): Integer; override;
# Line 463 | Line 549 | type
549      procedure PSStartTransaction; override;
550      procedure PSReset; override;
551      function PSUpdateRecord(UpdateKind: TUpdateKind; Delta: TDataSet): Boolean; override;
552 < *)
552 >
553      { TDataSet support }
554      procedure InternalInsert; override;
555      procedure InitRecord(Buffer: PChar); override;
# Line 527 | Line 613 | type
613    protected
614      {Likely to be made public by descendant classes}
615      property AutoCommit: TIBAutoCommit read FAutoCommit write FAutoCommit default acDisabled;
616 <    property SQLParams: TIBXSQLDA read GetSQLParams;
617 <    property Params: TIBXSQLDA read GetSQLParams;
616 >    property SQLParams: ISQLParams read GetSQLParams;
617 >    property Params: ISQLParams read GetSQLParams;
618      property InternalPrepared: Boolean read FInternalPrepared;
619      property QDelete: TIBSQL read FQDelete;
620      property QInsert: TIBSQL read FQInsert;
621      property QRefresh: TIBSQL read FQRefresh;
622      property QSelect: TIBSQL read FQSelect;
623      property QModify: TIBSQL read FQModify;
624 <    property StatementType: TIBSQLTypes read GetStatementType;
625 <    property SelectStmtHandle: TISC_STMT_HANDLE read GetSelectStmtHandle;
624 >    property StatementType: TIBSQLStatementTypes read GetStatementType;
625 >    property SelectStmtHandle: IStatement read GetSelectStmtIntf;
626  
627      {Likely to be made published by descendant classes}
628      property BufferChunks: Integer read FBufferChunks write SetBufferChunks;
# Line 587 | Line 673 | type
673      function BookmarkValid(Bookmark: TBookmark): Boolean; override;
674      function CompareBookmarks(Bookmark1, Bookmark2: TBookmark): Integer; override;
675      function CreateBlobStream(Field: TField; Mode: TBlobStreamMode): TStream; override;
676 +    function GetArray(Field: TIBArrayField): IArray;
677 +    procedure SetArrayIntf(AnArray: IArray; Field: TIBArrayField);
678      function GetCurrentRecord(Buffer: PChar): Boolean; override;
679      function GetFieldData(Field : TField; Buffer : Pointer) : Boolean; overload; override;
680      function GetFieldData(FieldNo: Integer; Buffer: Pointer): Boolean; overload; (*override;*)
# Line 600 | Line 688 | type
688      function UpdateStatus: TUpdateStatus; override;
689      function IsSequenced: Boolean; override;
690      procedure Post; override;
691 <    function ParamByName(ParamName: String): TIBXSQLVAR;
692 <    property DBHandle: PISC_DB_HANDLE read GetDBHandle;
693 <    property TRHandle: PISC_TR_HANDLE read GetTRHandle;
691 >    function ParamByName(ParamName: String): ISQLParam;
692 >    property ArrayFieldCount: integer read FArrayFieldCount;
693 >    property DatabaseInfo: TIBDatabaseInfo read FDatabaseInfo;
694      property UpdateObject: TIBDataSetUpdateObject read FUpdateObject write SetUpdateObject;
695      property UpdatesPending: Boolean read FUpdatesPending;
696      property UpdateRecordTypes: TIBUpdateRecordTypes read FUpdateRecordTypes
# Line 611 | Line 699 | type
699                 read FDataSetCloseAction write FDataSetCloseAction;
700  
701    published
702 +    property AllowAutoActivateTransaction: Boolean read FAllowAutoActivateTransaction
703 +                 write FAllowAutoActivateTransaction;
704      property Database: TIBDatabase read GetDatabase write SetDatabase;
705      property Transaction: TIBTransaction read GetTransaction
706                                            write SetTransaction;
# Line 645 | Line 735 | type
735                                                   write FOnUpdateError;
736      property OnUpdateRecord: TIBUpdateRecordEvent read FOnUpdateRecord
737                                                     write FOnUpdateRecord;
738 +    property OnDeleteReturning: TOnDeleteReturning read FOnDeleteReturning
739 +                                                   write FOnDeleteReturning;
740    end;
741  
742    TIBParserDataSet = class(TIBCustomDataSet)
# Line 731 | Line 823 | type
823      property OnNewRecord;
824      property OnPostError;
825      property OnValidatePost;
826 +    property OnDeleteReturning;
827    end;
828  
829    { TIBDSBlobStream }
# Line 740 | Line 833 | type
833    protected
834      FField: TField;
835      FBlobStream: TIBBlobStream;
836 +    function  GetSize: Int64; override;
837    public
838      constructor Create(AField: TField; ABlobStream: TIBBlobStream;
839                         Mode: TBlobStreamMode);
# Line 750 | Line 844 | type
844      function Write(const Buffer; Count: Longint): Longint; override;
845    end;
846  
847 +  {Extended Field Def for character set info}
848 +
849 +  { TIBFieldDef }
850 +
851 +  TIBFieldDef = class(TFieldDef)
852 +  private
853 +    FArrayBounds: TArrayBounds;
854 +    FArrayDimensions: integer;
855 +    FCharacterSetName: RawByteString;
856 +    FCharacterSetSize: integer;
857 +    FCodePage: TSystemCodePage;
858 +    FIdentityColumn: boolean;
859 +    FRelationName: string;
860 +    FDataSize: integer;
861 +  published
862 +    property CharacterSetName: RawByteString read FCharacterSetName write FCharacterSetName;
863 +    property CharacterSetSize: integer read FCharacterSetSize write FCharacterSetSize;
864 +    property CodePage: TSystemCodePage read FCodePage write FCodePage;
865 +    property DataSize: integer read FDataSize write FDataSize;
866 +    property RelationName: string read FRelationName write FRelationName;
867 +    property ArrayDimensions: integer read FArrayDimensions write FArrayDimensions;
868 +    property ArrayBounds: TArrayBounds read FArrayBounds write FArrayBounds;
869 +    property IdentityColumn: boolean read FIdentityColumn write FIdentityColumn default false;
870 +  end;
871 +
872   const
873   DefaultFieldClasses: array[TFieldType] of TFieldClass = (
874      nil,                { ftUnknown }
875      TIBStringField,     { ftString }
876 <    TSmallintField,     { ftSmallint }
877 <    TIntegerField,      { ftInteger }
876 >    TIBSmallintField,   { ftSmallint }
877 >    TIBIntegerField,      { ftInteger }
878      TWordField,         { ftWord }
879      TBooleanField,      { ftBoolean }
880      TFloatField,        { ftFloat }
# Line 776 | Line 895 | DefaultFieldClasses: array[TFieldType] o
895      TBlobField,         { ftTypedBinary }
896      nil,                { ftCursor }
897      TStringField,       { ftFixedChar }
898 <    TIBWideStringField,    { ftWideString }
899 <    TLargeIntField,     { ftLargeInt }
898 >    nil,    { ftWideString }
899 >    TIBLargeIntField,     { ftLargeInt }
900      nil,          { ftADT }
901 <    nil,        { ftArray }
901 >    TIBArrayField,        { ftArray }
902      nil,    { ftReference }
903      nil,     { ftDataSet }
904      TBlobField,         { ftOraBlob }
# Line 791 | Line 910 | DefaultFieldClasses: array[TFieldType] o
910      TDateTimeField,    {ftTimestamp}
911      TIBBCDField,       {ftFMTBcd}
912      nil,  {ftFixedWideChar}
913 <    TIBWideMemoField);   {ftWideMemo}
913 >    nil);   {ftWideMemo}
914   (*
915      TADTField,          { ftADT }
916      TArrayField,        { ftArray }
# Line 808 | Line 927 | DefaultFieldClasses: array[TFieldType] o
927  
928   implementation
929  
930 < uses IBIntf, Variants, FmtBCD, LazUTF8;
930 > uses Variants, FmtBCD, LazUTF8, FBMessages, IBQuery;
931  
932   const FILE_BEGIN = 0;
933        FILE_CURRENT = 1;
# Line 821 | Line 940 | type
940      FieldName : String;
941      COMPUTED_BLR : Boolean;
942      DEFAULT_VALUE : boolean;
943 +    IDENTITY_COLUMN : boolean;
944      NextField : TFieldNode;
945    end;
946  
# Line 831 | Line 951 | type
951      NextRelation : TRelationNode;
952    end;
953  
834  {Extended Field Def for character set info}
835
836  { TIBFieldDef }
837
838  TIBFieldDef = class(TFieldDef)
839  private
840    FCharacterSetName: RawByteString;
841    FCharacterSetSize: integer;
842    {$IFDEF HAS_ANSISTRING_CODEPAGE}
843    FCodePage: TSystemCodePage;
844    {$ENDIF}
845  published
846    property CharacterSetName: RawByteString read FCharacterSetName write FCharacterSetName;
847    property CharacterSetSize: integer read FCharacterSetSize write FCharacterSetSize;
848    {$IFDEF HAS_ANSISTRING_CODEPAGE}
849    property CodePage: TSystemCodePage read FCodePage write FCodePage;
850    {$ENDIF}
851  end;
852
954  
955    {  Copied from LCLProc in order to avoid LCL dependency
956  
# Line 892 | Line 993 | type
993      Result := str;
994    end;
995  
996 < { TIBWideMemoField }
996 > { TIBLargeIntField }
997  
998 < function TIBWideMemoField.GetTruncatedText: string;
998 > procedure TIBLargeIntField.Bind(Binding: Boolean);
999   begin
1000 <  Result := GetAsString;
1000 >  inherited Bind(Binding);
1001 >  if Binding and (FieldDef <> nil) then
1002 >     FIdentityColumn := (FieldDef as TIBFieldDef).IdentityColumn;
1003 > end;
1004  
1005 <  if Result <> '' then
1006 <    if DisplayWidth = 0 then
1007 <      Result := TextToSingleLine(Result)
1008 <    else
1009 <    if Length(Result) > DisplayWidth then {Show truncation with elipses}
1010 <      Result := TextToSingleLine(system.copy(Result,1,DisplayWidth-3)) + '...';
1005 > { TIBIntegerField }
1006 >
1007 > procedure TIBIntegerField.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 < function TIBWideMemoField.GetDefaultWidth: Longint;
1014 > { TIBSmallintField }
1015 >
1016 > procedure TIBSmallintField.Bind(Binding: Boolean);
1017   begin
1018 <  Result := 128;
1018 >  inherited Bind(Binding);
1019 >  if Binding and (FieldDef <> nil) then
1020 >     FIdentityColumn := (FieldDef as TIBFieldDef).IdentityColumn;
1021   end;
1022  
1023 < procedure TIBWideMemoField.GetText(var AText: string; ADisplayText: Boolean);
1023 > { TIBArray }
1024 >
1025 > procedure TIBArray.EventHandler(Sender: IArray; Reason: TArrayEventReason);
1026   begin
1027 <  if ADisplayText then
1027 >  case Reason of
1028 >  arChanging:
1029 >    if FRecNo <> FField.Dataset.RecNo then
1030 >      IBError(ibxeNotCurrentArray,[nil]);
1031 >
1032 >  arChanged:
1033 >    FField.DataChanged;
1034 >  end;
1035 > end;
1036 >
1037 > constructor TIBArray.Create(aField: TIBArrayField; anArray: IArray);
1038 > begin
1039 >  inherited Create;
1040 >  FField := aField;
1041 >  FArray := anArray;
1042 >  FRecNo := FField.Dataset.RecNo;
1043 >  FArray.AddEventHandler(EventHandler);
1044 > end;
1045 >
1046 > destructor TIBArray.Destroy;
1047 > begin
1048 >  FArray.RemoveEventHandler(EventHandler);
1049 >  inherited Destroy;
1050 > end;
1051 >
1052 > { TIBArrayField }
1053 >
1054 > function TIBArrayField.GetArrayIntf: IArray;
1055 > begin
1056 >  Result := TIBCustomDataSet(DataSet).GetArray(self);
1057 > end;
1058 >
1059 > function TIBArrayField.GetArrayID: TISC_QUAD;
1060 > begin
1061 >  GetData(@Result);
1062 > end;
1063 >
1064 > procedure TIBArrayField.SetArrayIntf(AValue: IArray);
1065 > begin
1066 >  TIBCustomDataSet(DataSet).SetArrayIntf(AValue,self);
1067 >  DataChanged;
1068 > end;
1069 >
1070 > class procedure TIBArrayField.CheckTypeSize(AValue: Longint);
1071 > begin
1072 >  //Ignore
1073 > end;
1074 >
1075 > function TIBArrayField.GetAsString: string;
1076 > begin
1077 >  Result := '(Array)';
1078 > end;
1079 >
1080 > function TIBArrayField.GetDataSize: Integer;
1081 > begin
1082 >  Result := sizeof(TISC_QUAD);
1083 > end;
1084 >
1085 > procedure TIBArrayField.Bind(Binding: Boolean);
1086 > begin
1087 >  inherited Bind(Binding);
1088 >  if Binding then
1089    begin
1090 <    if not DisplayTextAsClassName and (CharacterSetName<> '') then
1091 <      AText := GetTruncatedText
1092 <    else
1093 <      inherited GetText(AText, ADisplayText);
1094 <  end
1095 <  else
1096 <    AText := GetAsString;
1090 >    FCacheOffset := TIBCustomDataSet(DataSet).ArrayFieldCount;
1091 >    Inc(TIBCustomDataSet(DataSet).FArrayFieldCount);
1092 >    if FieldDef <> nil then
1093 >    begin
1094 >      FRelationName := TIBFieldDef(FieldDef).FRelationName;
1095 >      FArrayDimensions := TIBFieldDef(FieldDef).ArrayDimensions;
1096 >      FArrayBounds :=  TIBFieldDef(FieldDef).ArrayBounds;
1097 >    end;
1098 >  end;
1099   end;
1100  
1101 < constructor TIBWideMemoField.Create(AOwner: TComponent);
1101 > constructor TIBArrayField.Create(AOwner: TComponent);
1102   begin
1103    inherited Create(AOwner);
1104 <  BlobType := ftWideMemo;
1104 >  SetDataType(ftArray);
1105 > end;
1106 >
1107 > function TIBArrayField.CreateArray: IArray;
1108 > begin
1109 > with DataSet as TIBCustomDataSet do
1110 >  Result := Database.Attachment.CreateArray(Transaction.TransactionIntf,FRelationName,FieldName);
1111   end;
1112  
1113   { TIBMemoField }
# Line 949 | Line 1129 | begin
1129         {2: case 2 ignored. This should be handled by TIBWideMemo}
1130  
1131         3, {Assume UNICODE_FSS is really UTF8}
1132 <       4: {Include GB18030 - assuming UTF8 routine work for this codeset}
1132 >       4: {Include GB18030 - assuming UTF8 routines work for this codeset}
1133           if DisplayWidth = 0 then
1134             Result := ValidUTF8String(TextToSingleLine(Result))
1135           else
# Line 959 | Line 1139 | begin
1139     end
1140   end;
1141  
1142 + procedure TIBMemoField.Bind(Binding: Boolean);
1143 + var IBFieldDef: TIBFieldDef;
1144 + begin
1145 +  inherited Bind(Binding);
1146 +  if Binding and (FieldDef <> nil) then
1147 +  begin
1148 +    IBFieldDef := FieldDef as TIBFieldDef;
1149 +    CharacterSetSize := IBFieldDef.CharacterSetSize;
1150 +    CharacterSetName := IBFieldDef.CharacterSetName;
1151 +    CodePage := IBFieldDef.CodePage;
1152 +  end;
1153 + end;
1154 +
1155   function TIBMemoField.GetAsString: string;
1156   var s: RawByteString;
1157   begin
1158    s := inherited GetAsString;
966  {$IFDEF HAS_ANSISTRING_CODEPAGE}
1159    SetCodePage(s,CodePage,false);
1160 <  {$ENDIF}
1160 >  if (CodePage <> CP_NONE) and (CodePage <> CP_UTF8) then
1161 >    SetCodePage(s,CP_UTF8,true);  {LCL only accepts UTF8}
1162    Result := s;
1163   end;
1164  
# Line 994 | Line 1187 | procedure TIBMemoField.SetAsString(const
1187   var s: RawByteString;
1188   begin
1189    s := AValue;
1190 <  {$IFDEF HAS_ANSISTRING_CODEPAGE}
1191 <  if StringCodePage(Value) <> CodePage then
999 <    SetCodePage(s,CodePage,true);
1000 <  {$ENDIF}
1190 >  if StringCodePage(s) <> CodePage then
1191 >    SetCodePage(s,CodePage,CodePage<>CP_NONE);
1192    inherited SetAsString(s);
1193   end;
1194  
# Line 1005 | Line 1196 | constructor TIBMemoField.Create(AOwner:
1196   begin
1197    inherited Create(AOwner);
1198    BlobType := ftMemo;
1008  {$IFDEF HAS_ANSISTRING_CODEPAGE}
1199    FCodePage := CP_NONE;
1010  {$ENDIF}
1200   end;
1201  
1202   { TIBControlLink }
# Line 1041 | Line 1230 | end;
1230  
1231   { TIBStringField}
1232  
1233 < function TIBStringField.GetDefaultWidth: Longint;
1233 > procedure TIBStringField.Bind(Binding: Boolean);
1234 > var IBFieldDef: TIBFieldDef;
1235 > begin
1236 >  inherited Bind(Binding);
1237 >  if Binding and (FieldDef <> nil) then
1238 >  begin
1239 >    IBFieldDef := FieldDef as TIBFieldDef;
1240 >    CharacterSetSize := IBFieldDef.CharacterSetSize;
1241 >    CharacterSetName := IBFieldDef.CharacterSetName;
1242 >    FDataSize := IBFieldDef.DataSize + 1;
1243 >    if AutoFieldSize then
1244 >      Size := IBFieldDef.Size;
1245 >    CodePage := IBFieldDef.CodePage;
1246 >  end;
1247 > end;
1248 >
1249 > function TIBStringField.GetDataSize: Integer;
1250   begin
1251 <  Result := Size div CharacterSetSize;
1251 >  Result := FDataSize;
1252   end;
1253  
1254   constructor TIBStringField.Create(aOwner: TComponent);
1255   begin
1256    inherited Create(aOwner);
1257    FCharacterSetSize := 1;
1053  {$IFDEF HAS_ANSISTRING_CODEPAGE}
1258    FCodePage := CP_NONE;
1259 <  {$ENDIF}
1259 >  FAutoFieldSize := true;
1260   end;
1261  
1262   class procedure TIBStringField.CheckTypeSize(Value: Integer);
# Line 1078 | Line 1282 | var
1282    s: RawByteString;
1283   begin
1284    Buffer := nil;
1285 <  IBAlloc(Buffer, 0, Size + 1);
1285 >  IBAlloc(Buffer, 0, DataSize);
1286    try
1287      Result := GetData(Buffer);
1288      if Result then
1289      begin
1290 <      {$IFDEF HAS_ANSISTRING_CODEPAGE}
1087 <      s := string(Buffer);
1290 >      s := strpas(Buffer);
1291        SetCodePage(s,CodePage,false);
1292 +      if (CodePage <> CP_NONE) and (CodePage <> CP_UTF8) then
1293 +        SetCodePage(s,CP_UTF8,true);  {LCL only accepts UTF8}
1294        Value := s;
1295   //      writeln(FieldName,': ', StringCodePage(Value),', ',Value);
1091      {$ELSE}
1092      Value := string(Buffer);
1093      {$ENDIF}
1296        if Transliterate and (Value <> '') then
1297          DataSet.Translate(PChar(Value), PChar(Value), False);
1298      end
# Line 1105 | Line 1307 | var
1307    s: RawByteString;
1308   begin
1309    Buffer := nil;
1310 <  IBAlloc(Buffer, 0, Size + 1);
1310 >  IBAlloc(Buffer, 0, DataSize);
1311    try
1312      s := Value;
1111    {$IFDEF HAS_ANSISTRING_CODEPAGE}
1313      if StringCodePage(s) <> CodePage then
1314 <      SetCodePage(s,CodePage,true);
1315 <    {$ENDIF}
1115 <    StrLCopy(Buffer, PChar(s), Size);
1314 >      SetCodePage(s,CodePage,CodePage<>CP_NONE);
1315 >    StrLCopy(Buffer, PChar(s), DataSize-1);
1316      if Transliterate then
1317        DataSet.Translate(Buffer, Buffer, True);
1318      SetData(Buffer);
# Line 1131 | Line 1331 | begin
1331    Size := 8;
1332   end;
1333  
1334 + procedure TIBBCDField.Bind(Binding: Boolean);
1335 + begin
1336 +  inherited Bind(Binding);
1337 +  if Binding and (FieldDef <> nil) then
1338 +     FIdentityColumn := (FieldDef as TIBFieldDef).IdentityColumn;
1339 + end;
1340 +
1341   class procedure TIBBCDField.CheckTypeSize(Value: Integer);
1342   begin
1343   { No need to check as the base type is currency, not BCD }
# Line 1215 | Line 1422 | end;
1422   constructor TIBCustomDataSet.Create(AOwner: TComponent);
1423   begin
1424    inherited Create(AOwner);
1218  FIBLoaded := False;
1219  CheckIBLoaded;
1220  FIBLoaded := True;
1425    FBase := TIBBase.Create(Self);
1426 +  FDatabaseInfo := TIBDatabaseInfo.Create(self);
1427    FIBLinks := TList.Create;
1428    FCurrentRecord := -1;
1429    FDeletedRecords := 0;
1430    FUniDirectional := False;
1431    FBufferChunks := BufferCacheSize;
1432    FBlobStreamList := TList.Create;
1433 +  FArrayList := TList.Create;
1434    FGeneratorField := TIBGenerator.Create(self);
1435    FDataLink := TIBDataLink.Create(Self);
1436    FQDelete := TIBSQL.Create(Self);
# Line 1268 | Line 1474 | end;
1474   destructor TIBCustomDataSet.Destroy;
1475   begin
1476    if Active then Active := false;
1477 <  if FIBLoaded then
1478 <  begin
1479 <    if assigned(FGeneratorField) then FGeneratorField.Free;
1480 <    FDataLink.Free;
1481 <    FBase.Free;
1482 <    ClearBlobCache;
1483 <    ClearIBLinks;
1484 <    FIBLinks.Free;
1485 <    FBlobStreamList.Free;
1486 <    FreeMem(FBufferCache);
1487 <    FBufferCache := nil;
1488 <    FreeMem(FOldBufferCache);
1489 <    FOldBufferCache := nil;
1490 <    FCacheSize := 0;
1491 <    FOldCacheSize := 0;
1286 <    FMappedFieldPosition := nil;
1287 <  end;
1477 >  if assigned(FGeneratorField) then FGeneratorField.Free;
1478 >  FDataLink.Free;
1479 >  FBase.Free;
1480 >  ClearBlobCache;
1481 >  ClearIBLinks;
1482 >  FIBLinks.Free;
1483 >  FBlobStreamList.Free;
1484 >  FArrayList.Free;
1485 >  FreeMem(FBufferCache);
1486 >  FBufferCache := nil;
1487 >  FreeMem(FOldBufferCache);
1488 >  FOldBufferCache := nil;
1489 >  FCacheSize := 0;
1490 >  FOldCacheSize := 0;
1491 >  FMappedFieldPosition := nil;
1492    if assigned(FBaseSQLSelect) then FBaseSQLSelect.Free;
1493    if assigned(FParser) then FParser.Free;
1494    inherited Destroy;
# Line 1309 | Line 1513 | begin
1513        Inc(FCurrentRecord);
1514        if (FCurrentRecord = FRecordCount) then
1515        begin
1516 <        if (not FQSelect.EOF) and (FQSelect.Next <> nil) then
1516 >        if (not FQSelect.EOF) and FQSelect.Next  then
1517          begin
1518            FetchCurrentRecordToBuffer(FQSelect, FCurrentRecord, Buffer);
1519            Inc(FRecordCount);
# Line 1328 | Line 1532 | end;
1532  
1533   procedure TIBCustomDataSet.ApplyUpdates;
1534   var
1331  {$IFDEF NEW_TBOOKMARK }
1535    CurBookmark: TBookmark;
1333  {$ELSE}
1334  CurBookmark: string;
1335  {$ENDIF}
1536    Buffer: PRecordData;
1537    CurUpdateTypes: TIBUpdateRecordTypes;
1538    UpdateAction: TIBUpdateAction;
# Line 1563 | Line 1763 | end;
1763   function TIBCustomDataSet.ActivateTransaction: Boolean;
1764   begin
1765    Result := False;
1766 <  if not Assigned(Transaction) then
1567 <    IBError(ibxeTransactionNotAssigned, [nil]);
1568 <  if not Transaction.Active then
1766 >  if AllowAutoActivateTransaction or (csDesigning in ComponentState) then
1767    begin
1768 <    Result := True;
1769 <    Transaction.StartTransaction;
1770 <    FDidActivate := True;
1768 >    if not Assigned(Transaction) then
1769 >      IBError(ibxeTransactionNotAssigned, [nil]);
1770 >    if not Transaction.Active then
1771 >    begin
1772 >      Result := True;
1773 >      Transaction.StartTransaction;
1774 >      FDidActivate := True;
1775 >    end;
1776    end;
1777   end;
1778  
# Line 1694 | Line 1897 | begin
1897    FBlobStreamList.Pack;
1898   end;
1899  
1900 + procedure TIBCustomDataSet.ClearArrayCache;
1901 + var
1902 +  i: Integer;
1903 + begin
1904 +  for i := 0 to FArrayList.Count - 1 do
1905 +  begin
1906 +    TIBArray(FArrayList[i]).Free;
1907 +    FArrayList[i] := nil;
1908 +  end;
1909 +  FArrayList.Pack;
1910 + end;
1911 +
1912   procedure TIBCustomDataSet.CopyRecordBuffer(Source, Dest: Pointer);
1913   begin
1914    Move(Source^, Dest^, FRecordBufferSize);
# Line 1703 | Line 1918 | procedure TIBCustomDataSet.DoBeforeDatab
1918   begin
1919    if Active then
1920      Active := False;
1921 <  FInternalPrepared := False;
1921 >  InternalUnPrepare;
1922    if Assigned(FBeforeDatabaseDisconnect) then
1923      FBeforeDatabaseDisconnect(Sender);
1924   end;
# Line 1741 | Line 1956 | begin
1956      FQModify.FreeHandle;
1957    if FQRefresh <> nil then
1958      FQRefresh.FreeHandle;
1959 +  InternalUnPrepare;
1960    if Assigned(FBeforeTransactionEnd) then
1961      FBeforeTransactionEnd(Sender);
1962   end;
# Line 1757 | Line 1973 | begin
1973      FTransactionFree(Sender);
1974   end;
1975  
1976 < { Read the record from FQSelect.Current into the record buffer
1977 <  Then write the buffer to in memory cache }
1978 < procedure TIBCustomDataSet.FetchCurrentRecordToBuffer(Qry: TIBSQL;
1979 <  RecordNumber: Integer; Buffer: PChar);
1980 < var
1981 <  p: PRecordData;
1982 <  pbd: PBlobDataArray;
1983 <  i, j: Integer;
1984 <  LocalData: Pointer;
1985 <  LocalDate, LocalDouble: Double;
1986 <  LocalInt: Integer;
1771 <  LocalBool: wordBool;
1772 <  LocalInt64: Int64;
1773 <  LocalCurrency: Currency;
1774 <  FieldsLoaded: Integer;
1775 <  temp: TIBXSQLVAR;
1976 > procedure TIBCustomDataSet.DoDeleteReturning(QryResults: IResults);
1977 > begin
1978 >  if assigned(FOnDeleteReturning) then
1979 >     OnDeleteReturning(self,QryResults);
1980 > end;
1981 >
1982 > procedure TIBCustomDataSet.InitModelBuffer(Qry: TIBSQL; Buffer: PChar);
1983 > var i, j: Integer;
1984 >    FieldsLoaded: integer;
1985 >    p: PRecordData;
1986 >    colMetadata: IColumnMetaData;
1987   begin
1988    p := PRecordData(Buffer);
1778  { Make sure blob cache is empty }
1779  pbd := PBlobDataArray(Buffer + FBlobCacheOffset);
1780  if RecordNumber > -1 then
1781    for i := 0 to BlobFieldCount - 1 do
1782      pbd^[i] := nil;
1989    { Get record information }
1990    p^.rdBookmarkFlag := bfCurrent;
1991 <  p^.rdFieldCount := Qry.Current.Count;
1992 <  p^.rdRecordNumber := RecordNumber;
1991 >  p^.rdFieldCount := Qry.FieldCount;
1992 >  p^.rdRecordNumber := -1;
1993    p^.rdUpdateStatus := usUnmodified;
1994    p^.rdCachedUpdateStatus := cusUnmodified;
1995    p^.rdSavedOffset := $FFFFFFFF;
1996  
1997    { Load up the fields }
1998 <  FieldsLoaded := FQSelect.Current.Count;
1998 >  FieldsLoaded := FQSelect.MetaData.Count;
1999    j := 1;
2000 <  for i := 0 to Qry.Current.Count - 1 do
2000 >  for i := 0 to Qry.MetaData.Count - 1 do
2001    begin
2002      if (Qry = FQSelect) then
2003        j := i + 1
2004 <    else begin
2004 >    else
2005 >    begin
2006        if FieldsLoaded = 0 then
2007          break;
2008 <      j := FQSelect.FieldIndex[Qry.Current[i].Name] + 1;
2008 >      j := FQSelect.FieldIndex[Qry[i].Name] + 1;
2009        if j < 1 then
2010          continue
2011        else
2012          Dec(FieldsLoaded);
2013      end;
2014 <    with FQSelect.Current[j - 1].Data^ do
1808 <      if aliasname = 'IBX_INTERNAL_DBKEY' then {do not localize}
1809 <      begin
1810 <        if sqllen <= 8 then
1811 <          p^.rdDBKey := PIBDBKEY(Qry.Current[i].AsPointer)^;
1812 <        continue;
1813 <      end;
1814 <    if j > 0 then with p^ do
2014 >    if j > 0 then
2015      begin
2016 <      rdFields[j].fdDataType :=
2017 <        Qry.Current[i].Data^.sqltype and (not 1);
2018 <      rdFields[j].fdDataScale :=
2019 <        Qry.Current[i].Data^.sqlscale;
2020 <      rdFields[j].fdNullable :=
2021 <        (Qry.Current[i].Data^.sqltype and 1 = 1);
2022 <      rdFields[j].fdIsNull :=
2023 <        (rdFields[j].fdNullable and (Qry.Current[i].Data^.sqlind^ = -1));
2024 <      LocalData := Qry.Current[i].Data^.sqldata;
2025 <      case rdFields[j].fdDataType of
2026 <        SQL_TIMESTAMP:
2016 >      colMetadata := Qry.MetaData[i];
2017 >      with p^.rdFields[j], FFieldColumns^[j] do
2018 >      begin
2019 >        fdDataType := colMetadata.GetSQLType;
2020 >        if fdDataType = SQL_BLOB then
2021 >          fdDataScale := 0
2022 >        else
2023 >          fdDataScale := colMetadata.getScale;
2024 >        fdNullable := colMetadata.getIsNullable;
2025 >        fdIsNull := true;
2026 >        fdDataSize := colMetadata.GetSize;
2027 >        fdDataLength := 0;
2028 >        fdCodePage := CP_NONE;
2029 >
2030 >        case fdDataType of
2031 >        SQL_TIMESTAMP,
2032 >        SQL_TYPE_DATE,
2033 >        SQL_TYPE_TIME:
2034 >          fdDataSize := SizeOf(TDateTime);
2035 >        SQL_SHORT, SQL_LONG:
2036          begin
2037 <          rdFields[j].fdDataSize := SizeOf(TDateTime);
2038 <          if RecordNumber >= 0 then
2039 <            LocalDate := TimeStampToMSecs(DateTimeToTimeStamp(Qry.Current[i].AsDateTime));
2040 <          LocalData := PChar(@LocalDate);
2037 >          if (fdDataScale = 0) then
2038 >            fdDataSize := SizeOf(Integer)
2039 >          else
2040 >          if (fdDataScale >= (-4)) then
2041 >            fdDataSize := SizeOf(Currency)
2042 >          else
2043 >            fdDataSize := SizeOf(Double);
2044          end;
2045 <        SQL_TYPE_DATE:
2045 >        SQL_INT64:
2046          begin
2047 <          rdFields[j].fdDataSize := SizeOf(TDateTime);
2048 <          if RecordNumber >= 0 then
2049 <            LocalInt := DateTimeToTimeStamp(Qry.Current[i].AsDateTime).Date;
2050 <          LocalData := PChar(@LocalInt);
2047 >          if (fdDataScale = 0) then
2048 >            fdDataSize := SizeOf(Int64)
2049 >          else
2050 >          if (fdDataScale >= (-4)) then
2051 >            fdDataSize := SizeOf(Currency)
2052 >          else
2053 >            fdDataSize := SizeOf(Double);
2054          end;
2055 <        SQL_TYPE_TIME:
2055 >        SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT:
2056 >          fdDataSize := SizeOf(Double);
2057 >        SQL_BOOLEAN:
2058 >          fdDataSize := SizeOf(wordBool);
2059 >        SQL_VARYING,
2060 >        SQL_TEXT,
2061 >        SQL_BLOB:
2062 >          fdCodePage := Qry.Metadata[i].getCodePage;
2063 >        end;
2064 >        fdDataOfs := FRecordSize;
2065 >        Inc(FRecordSize, fdDataSize);
2066 >      end;
2067 >    end;
2068 >  end;
2069 > end;
2070 >
2071 > {Update Buffer Fields from Query Results}
2072 >
2073 > procedure TIBCustomDataSet.UpdateRecordFromQuery(QryResults: IResults;
2074 >  Buffer: PChar);
2075 > var i, j: integer;
2076 > begin
2077 >  for i := 0 to QryResults.Count - 1 do
2078 >  begin
2079 >    j := GetFieldPosition(QryResults[i].GetAliasName);
2080 >    if j > 0 then
2081 >    begin
2082 >      ColumnDataToBuffer(QryResults,i,j,Buffer);
2083 >      FBufferUpdatedOnQryReturn := true;
2084 >    end;
2085 >  end;
2086 > end;
2087 >
2088 >
2089 > {Move column data returned from query to row buffer}
2090 >
2091 > procedure TIBCustomDataSet.ColumnDataToBuffer(QryResults: IResults;
2092 >               ColumnIndex, FieldIndex: integer; Buffer: PChar);
2093 > var
2094 >  LocalData: PByte;
2095 >  LocalDate: TDateTime;
2096 >  LocalDouble: Double;
2097 >  LocalInt: Integer;
2098 >  LocalBool: wordBool;
2099 >  LocalInt64: Int64;
2100 >  LocalCurrency: Currency;
2101 >  ColData: ISQLData;
2102 > begin
2103 >  LocalData := nil;
2104 >  with PRecordData(Buffer)^.rdFields[FieldIndex], FFieldColumns^[FieldIndex] do
2105 >  begin
2106 >    QryResults.GetData(ColumnIndex,fdIsNull,fdDataLength,LocalData);
2107 >    if not fdIsNull then
2108 >    begin
2109 >      ColData := QryResults[ColumnIndex];
2110 >      case fdDataType of  {Get Formatted data for column types that need formatting}
2111 >        SQL_TYPE_DATE,
2112 >        SQL_TYPE_TIME,
2113 >        SQL_TIMESTAMP:
2114          begin
2115 <          rdFields[j].fdDataSize := SizeOf(TDateTime);
2116 <          if RecordNumber >= 0 then
2117 <            LocalInt := DateTimeToTimeStamp(Qry.Current[i].AsDateTime).Time;
1845 <          LocalData := PChar(@LocalInt);
2115 >          {This is an IBX native format and not the TDataset approach. See also GetFieldData}
2116 >          LocalDate := ColData.AsDateTime;
2117 >          LocalData := PByte(@LocalDate);
2118          end;
2119          SQL_SHORT, SQL_LONG:
2120          begin
2121 <          if (rdFields[j].fdDataScale = 0) then
2121 >          if (fdDataScale = 0) then
2122            begin
2123 <            rdFields[j].fdDataSize := SizeOf(Integer);
2124 <            if RecordNumber >= 0 then
1853 <              LocalInt := Qry.Current[i].AsLong;
1854 <            LocalData := PChar(@LocalInt);
2123 >            LocalInt := ColData.AsLong;
2124 >            LocalData := PByte(@LocalInt);
2125            end
2126 <          else if (rdFields[j].fdDataScale >= (-4)) then
2127 <               begin
2128 <                 rdFields[j].fdDataSize := SizeOf(Currency);
2129 <                 if RecordNumber >= 0 then
2130 <                   LocalCurrency := Qry.Current[i].AsCurrency;
2131 <                 LocalData := PChar(@LocalCurrency);
2132 <               end
2133 <               else begin
2134 <                 rdFields[j].fdDataSize := SizeOf(Double);
2135 <                 if RecordNumber >= 0 then
2136 <                   LocalDouble := Qry.Current[i].AsDouble;
1867 <                LocalData := PChar(@LocalDouble);
1868 <              end;
2126 >          else
2127 >          if (fdDataScale >= (-4)) then
2128 >          begin
2129 >            LocalCurrency := ColData.AsCurrency;
2130 >            LocalData := PByte(@LocalCurrency);
2131 >          end
2132 >          else
2133 >          begin
2134 >           LocalDouble := ColData.AsDouble;
2135 >           LocalData := PByte(@LocalDouble);
2136 >          end;
2137          end;
2138          SQL_INT64:
2139          begin
2140 <          if (rdFields[j].fdDataScale = 0) then
2140 >          if (fdDataScale = 0) then
2141            begin
2142 <            rdFields[j].fdDataSize := SizeOf(Int64);
2143 <            if RecordNumber >= 0 then
1876 <              LocalInt64 := Qry.Current[i].AsInt64;
1877 <            LocalData := PChar(@LocalInt64);
2142 >            LocalInt64 := ColData.AsInt64;
2143 >            LocalData := PByte(@LocalInt64);
2144            end
2145 <          else if (rdFields[j].fdDataScale >= (-4)) then
2146 <               begin
1881 <                 rdFields[j].fdDataSize := SizeOf(Currency);
1882 <                 if RecordNumber >= 0 then
1883 <                   LocalCurrency := Qry.Current[i].AsCurrency;
1884 <                   LocalData := PChar(@LocalCurrency);
1885 <               end
1886 <               else begin
1887 <                  rdFields[j].fdDataSize := SizeOf(Double);
1888 <                  if RecordNumber >= 0 then
1889 <                    LocalDouble := Qry.Current[i].AsDouble;
1890 <                  LocalData := PChar(@LocalDouble);
1891 <               end
1892 <        end;
1893 <        SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT:
1894 <        begin
1895 <          rdFields[j].fdDataSize := SizeOf(Double);
1896 <          if RecordNumber >= 0 then
1897 <            LocalDouble := Qry.Current[i].AsDouble;
1898 <          LocalData := PChar(@LocalDouble);
1899 <        end;
1900 <        SQL_VARYING:
1901 <        begin
1902 <          rdFields[j].fdDataSize := Qry.Current[i].Data^.sqllen;
1903 <          rdFields[j].fdDataLength := isc_vax_integer(Qry.Current[i].Data^.sqldata, 2);
1904 <          if RecordNumber >= 0 then
2145 >          else
2146 >          if (fdDataScale >= (-4)) then
2147            begin
2148 <            if (rdFields[j].fdDataLength = 0) then
2149 <              LocalData := nil
2148 >            LocalCurrency := ColData.AsCurrency;
2149 >            LocalData := PByte(@LocalCurrency);
2150 >            end
2151              else
2152              begin
2153 <              temp :=  Qry.Current[i];
2154 <              LocalData := @temp.Data^.sqldata[2];
2155 < (*              LocalData := @Qry.Current[i].Data^.sqldata[2];*)
1913 <            end;
1914 <          end;
2153 >              LocalDouble := ColData.AsDouble;
2154 >              LocalData := PByte(@LocalDouble);
2155 >            end
2156          end;
2157 <        SQL_BOOLEAN:
2157 >        SQL_DOUBLE, SQL_FLOAT, SQL_D_FLOAT:
2158          begin
2159 <          LocalBool:= false;
2160 <          rdFields[j].fdDataSize := SizeOf(wordBool);
1920 <          if RecordNumber >= 0 then
1921 <            LocalBool := Qry.Current[i].AsBoolean;
1922 <          LocalData := PChar(@LocalBool);
2159 >          LocalDouble := ColData.AsDouble;
2160 >          LocalData := PByte(@LocalDouble);
2161          end;
2162 <        else { SQL_TEXT, SQL_BLOB, SQL_ARRAY, SQL_QUAD }
2162 >        SQL_BOOLEAN:
2163          begin
2164 <          rdFields[j].fdDataSize := Qry.Current[i].Data^.sqllen;
2165 <          if (rdFields[j].fdDataType = SQL_TEXT) then
1928 <            rdFields[j].fdDataLength := rdFields[j].fdDataSize;
2164 >          LocalBool := ColData.AsBoolean;
2165 >          LocalData := PByte(@LocalBool);
2166          end;
2167        end;
2168 <      if RecordNumber < 0 then
2168 >
2169 >      if fdDataType = SQL_VARYING then
2170 >        Move(LocalData^, Buffer[fdDataOfs], fdDataLength)
2171 >      else
2172 >        Move(LocalData^, Buffer[fdDataOfs], fdDataSize)
2173 >    end
2174 >    else {Null column}
2175 >    if fdDataType = SQL_VARYING then
2176 >      FillChar(Buffer[fdDataOfs],fdDataLength,0)
2177 >    else
2178 >      FillChar(Buffer[fdDataOfs],fdDataSize,0);
2179 >  end;
2180 > end;
2181 >
2182 > { Read the record from FQSelect.Current into the record buffer
2183 >  Then write the buffer to in memory cache }
2184 > procedure TIBCustomDataSet.FetchCurrentRecordToBuffer(Qry: TIBSQL;
2185 >  RecordNumber: Integer; Buffer: PChar);
2186 > var
2187 >  pbd: PBlobDataArray;
2188 >  pda: PArrayDataArray;
2189 >  i, j: Integer;
2190 >  FieldsLoaded: Integer;
2191 >  p: PRecordData;
2192 > begin
2193 >  if RecordNumber = -1 then
2194 >  begin
2195 >    InitModelBuffer(Qry,Buffer);
2196 >    Exit;
2197 >  end;
2198 >  p := PRecordData(Buffer);
2199 >  { Make sure blob cache is empty }
2200 >  pbd := PBlobDataArray(Buffer + FBlobCacheOffset);
2201 >  pda := PArrayDataArray(Buffer + FArrayCacheOffset);
2202 >  for i := 0 to BlobFieldCount - 1 do
2203 >    pbd^[i] := nil;
2204 >  for i := 0 to ArrayFieldCount - 1 do
2205 >    pda^[i] := nil;
2206 >
2207 >  { Get record information }
2208 >  p^.rdBookmarkFlag := bfCurrent;
2209 >  p^.rdFieldCount := Qry.FieldCount;
2210 >  p^.rdRecordNumber := RecordNumber;
2211 >  p^.rdUpdateStatus := usUnmodified;
2212 >  p^.rdCachedUpdateStatus := cusUnmodified;
2213 >  p^.rdSavedOffset := $FFFFFFFF;
2214 >
2215 >  { Load up the fields }
2216 >  FieldsLoaded := FQSelect.MetaData.Count;
2217 >  j := 1;
2218 >  for i := 0 to Qry.FieldCount - 1 do
2219 >  begin
2220 >    if (Qry = FQSelect) then
2221 >      j := i + 1
2222 >    else
2223 >    begin
2224 >      if FieldsLoaded = 0 then
2225 >        break;
2226 >      j := FQSelect.FieldIndex[Qry[i].Name] + 1;
2227 >      if j < 1 then
2228 >        continue
2229 >      else
2230 >        Dec(FieldsLoaded);
2231 >    end;
2232 >    with FQSelect.MetaData[j - 1] do
2233 >      if GetAliasname = 'IBX_INTERNAL_DBKEY' then {do not localize}
2234        begin
2235 <        rdFields[j].fdIsNull := True;
2236 <        rdFields[j].fdDataOfs := FRecordSize;
2237 <        Inc(FRecordSize, rdFields[j].fdDataSize);
1936 <      end
1937 <      else begin
1938 <        if rdFields[j].fdDataType = SQL_VARYING then
1939 <        begin
1940 <          if LocalData <> nil then
1941 <            Move(LocalData^, Buffer[rdFields[j].fdDataOfs], rdFields[j].fdDataLength)
1942 <        end
1943 <        else
1944 <          Move(LocalData^, Buffer[rdFields[j].fdDataOfs], rdFields[j].fdDataSize)
2235 >        if (GetSize <= 8) then
2236 >          p^.rdDBKey := PIBDBKEY(Qry[i].AsPointer)^;
2237 >        continue;
2238        end;
2239 <    end;
2239 >    if j > 0 then
2240 >      ColumnDataToBuffer(Qry.Current,i,j,Buffer);
2241    end;
2242 <  WriteRecordCache(RecordNumber, PChar(p));
2242 >  WriteRecordCache(RecordNumber, Buffer);
2243   end;
2244  
2245   function TIBCustomDataSet.GetActiveBuf: PChar;
# Line 1990 | Line 2284 | begin
2284    result := FBase.Database;
2285   end;
2286  
1993 function TIBCustomDataSet.GetDBHandle: PISC_DB_HANDLE;
1994 begin
1995  result := FBase.DBHandle;
1996 end;
1997
2287   function TIBCustomDataSet.GetDeleteSQL: TStrings;
2288   begin
2289    result := FQDelete.SQL;
# Line 2005 | Line 2294 | begin
2294    result := FQInsert.SQL;
2295   end;
2296  
2297 < function TIBCustomDataSet.GetSQLParams: TIBXSQLDA;
2297 > function TIBCustomDataSet.GetSQLParams: ISQLParams;
2298   begin
2299    if not FInternalPrepared then
2300      InternalPrepare;
# Line 2022 | Line 2311 | begin
2311    result := FQSelect.SQL;
2312   end;
2313  
2314 < function TIBCustomDataSet.GetStatementType: TIBSQLTypes;
2314 > function TIBCustomDataSet.GetStatementType: TIBSQLStatementTypes;
2315   begin
2316 <  result := FQSelect.SQLType;
2316 >  result := FQSelect.SQLStatementType;
2317   end;
2318  
2319   function TIBCustomDataSet.GetModifySQL: TStrings;
# Line 2037 | Line 2326 | begin
2326    result := FBase.Transaction;
2327   end;
2328  
2040 function TIBCustomDataSet.GetTRHandle: PISC_TR_HANDLE;
2041 begin
2042  result := FBase.TRHandle;
2043 end;
2044
2329   procedure TIBCustomDataSet.InternalDeleteRecord(Qry: TIBSQL; Buff: Pointer);
2330   begin
2331    if (Assigned(FUpdateObject) and (FUpdateObject.GetSQL(ukDelete).Text <> '')) then
2332      FUpdateObject.Apply(ukDelete,Buff)
2333    else
2334    begin
2335 <    SetInternalSQLParams(FQDelete, Buff);
2335 >    SetInternalSQLParams(FQDelete.Params, Buff);
2336      FQDelete.ExecQuery;
2337 +    if (FQDelete.FieldCount > 0)  then
2338 +      DoDeleteReturning(FQDelete.Current);
2339    end;
2340    with PRecordData(Buff)^ do
2341    begin
# Line 2063 | Line 2349 | function TIBCustomDataSet.InternalLocate
2349    const KeyValues: Variant; Options: TLocateOptions): Boolean;
2350   var
2351    keyFieldList: TList;
2066  {$IFDEF NEW_TBOOKMARK }
2352    CurBookmark: TBookmark;
2068  {$ELSE}
2069  CurBookmark: string;
2070  {$ENDIF}
2353    fieldValue: Variant;
2354    lookupValues: array of variant;
2355    i, fieldCount: Integer;
# Line 2149 | Line 2431 | end;
2431  
2432   procedure TIBCustomDataSet.InternalPostRecord(Qry: TIBSQL; Buff: Pointer);
2433   var
2434 <  i, j, k: Integer;
2434 >  i, j, k, arr: Integer;
2435    pbd: PBlobDataArray;
2436 +  pda: PArrayDataArray;
2437   begin
2438    pbd := PBlobDataArray(PChar(Buff) + FBlobCacheOffset);
2439 <  j := 0;
2439 >  pda := PArrayDataArray(PChar(Buff) + FArrayCacheOffset);
2440 >  j := 0; arr := 0;
2441    for i := 0 to FieldCount - 1 do
2442      if Fields[i].IsBlob then
2443      begin
# Line 2162 | Line 2446 | begin
2446        begin
2447          pbd^[j].Finalize;
2448          PISC_QUAD(
2449 <          PChar(Buff) + PRecordData(Buff)^.rdFields[k].fdDataOfs)^ :=
2449 >          PChar(Buff) + FFieldColumns^[k].fdDataOfs)^ :=
2450            pbd^[j].BlobID;
2451          PRecordData(Buff)^.rdFields[k].fdIsNull := pbd^[j].Size = 0;
2452 +      end
2453 +      else
2454 +      begin
2455 +        PRecordData(Buff)^.rdFields[k].fdIsNull := true;
2456 +        with PISC_QUAD(PChar(Buff) + FFieldColumns^[k].fdDataOfs)^ do
2457 +        begin
2458 +          gds_quad_high := 0;
2459 +          gds_quad_low := 0;
2460 +        end;
2461        end;
2462        Inc(j);
2463 +    end
2464 +    else
2465 +    if Fields[i] is TIBArrayField then
2466 +    begin
2467 +      if pda^[arr] <> nil then
2468 +      begin
2469 +        k := FMappedFieldPosition[Fields[i].FieldNo -1];
2470 +        PISC_QUAD(
2471 +          PChar(Buff) + FFieldColumns^[k].fdDataOfs)^ :=  pda^[arr].ArrayIntf.GetArrayID;
2472 +        PRecordData(Buff)^.rdFields[k].fdIsNull := pda^[arr].ArrayIntf.IsEmpty;
2473 +      end;
2474 +      Inc(arr);
2475      end;
2476 +  FBufferUpdatedOnQryReturn := false;
2477    if Assigned(FUpdateObject) then
2478    begin
2479      if (Qry = FQDelete) then
# Line 2178 | Line 2484 | begin
2484        FUpdateObject.Apply(ukModify,Buff);
2485    end
2486    else begin
2487 <    SetInternalSQLParams(Qry, Buff);
2487 >    SetInternalSQLParams(Qry.Params, Buff);
2488      Qry.ExecQuery;
2489 +    if Qry.FieldCount > 0 then {Has RETURNING Clause}
2490 +      UpdateRecordFromQuery(Qry.Current,Buff);
2491    end;
2492    PRecordData(Buff)^.rdUpdateStatus := usUnmodified;
2493    PRecordData(Buff)^.rdCachedUpdateStatus := cusUnmodified;
2494    SetModified(False);
2495    WriteRecordCache(PRecordData(Buff)^.rdRecordNumber, Buff);
2496 <  if (FForcedRefresh or FNeedsRefresh) and CanRefresh then
2496 >  if (FForcedRefresh or (FNeedsRefresh and not FBufferUpdatedOnQryReturn)) and CanRefresh then
2497      InternalRefreshRow;
2498   end;
2499  
# Line 2212 | Line 2520 | begin
2520          end
2521          else
2522            Qry := FQRefresh;
2523 <        SetInternalSQLParams(Qry, Buff);
2523 >        SetInternalSQLParams(Qry.Params, Buff);
2524          Qry.ExecQuery;
2525          try
2526 <          if (Qry.SQLType = SQLExecProcedure) or
2219 <             (Qry.Next <> nil) then
2526 >          if (Qry.SQLStatementType = SQLExecProcedure) or Qry.Next then
2527            begin
2528              ofs := PRecordData(Buff)^.rdSavedOffset;
2529              FetchCurrentRecordToBuffer(Qry,
# Line 2309 | Line 2616 | begin
2616   end;
2617  
2618   procedure TIBCustomDataSet.InternalPrepare;
2312 var
2313  DidActivate: Boolean;
2619   begin
2620    if FInternalPrepared then
2621      Exit;
2317  DidActivate := False;
2622    FBase.SetCursor;
2623    try
2624      ActivateConnection;
2625 <    DidActivate := ActivateTransaction;
2625 >    ActivateTransaction;
2626      FBase.CheckDatabase;
2627      FBase.CheckTransaction;
2628      if HasParser and (FParser.SQLText <> FQSelect.SQL.Text) then
# Line 2356 | Line 2660 | begin
2660      end else
2661        IBError(ibxeEmptyQuery, [nil]);
2662    finally
2359    if DidActivate then
2360      DeactivateTransaction;
2663      FBase.RestoreCursor;
2664    end;
2665   end;
# Line 2387 | Line 2689 | var
2689    begin
2690      CopyRecordBuffer(Buffer, OldBuffer);
2691      if BlobFieldCount > 0 then
2692 <      FillChar(PChar(OldBuffer)[FBlobCacheOffset], BlobFieldCount * SizeOf(TIBBlobStream),
2692 >      FillChar(PChar(OldBuffer)[FBlobCacheOffset],
2693 >               BlobFieldCount * SizeOf(TIBBlobStream) + ArrayFieldCount * SizeOf(IArray),
2694                 0);
2695    end;
2696  
# Line 2426 | Line 2729 | end;
2729  
2730   procedure TIBCustomDataSet.SetDatabase(Value: TIBDatabase);
2731   begin
2732 <  if (FBase.Database <> Value) then
2732 >  if (csLoading in ComponentState) or (FBase.Database <> Value) then
2733    begin
2734      CheckDatasetClosed;
2735 +    InternalUnPrepare;
2736      FBase.Database := Value;
2737      FQDelete.Database := Value;
2738      FQInsert.Database := Value;
2739      FQRefresh.Database := Value;
2740      FQSelect.Database := Value;
2741      FQModify.Database := Value;
2742 +    FDatabaseInfo.Database := Value;
2743 +    FGeneratorField.Database := Value;
2744    end;
2745   end;
2746  
# Line 2456 | Line 2762 | begin
2762    end;
2763   end;
2764  
2765 < procedure TIBCustomDataSet.SetInternalSQLParams(Qry: TIBSQL; Buffer: Pointer);
2765 > procedure TIBCustomDataSet.SetInternalSQLParams(Params: ISQLParams; Buffer: Pointer);
2766   var
2767    i, j: Integer;
2768    cr, data: PChar;
2769 <  fn, st: string;
2769 >  fn: string;
2770 >  st: RawByteString;
2771    OldBuffer: Pointer;
2772    ts: TTimeStamp;
2773 +  Param: ISQLParam;
2774   begin
2775    if (Buffer = nil) then
2776      IBError(ibxeBufferNotSet, [nil]);
# Line 2470 | Line 2778 | begin
2778      InternalPrepare;
2779    OldBuffer := nil;
2780    try
2781 <    for i := 0 to Qry.Params.Count - 1 do
2781 >    for i := 0 to Params.GetCount - 1 do
2782      begin
2783 <      fn := Qry.Params[i].Name;
2783 >      Param := Params[i];
2784 >      fn := Param.Name;
2785        if (Pos('OLD_', fn) = 1) then {mbcs ok}
2786        begin
2787          fn := Copy(fn, 5, Length(fn));
# Line 2492 | Line 2801 | begin
2801               cr := Buffer;
2802        j := FQSelect.FieldIndex[fn] + 1;
2803        if (j > 0) then
2804 <        with PRecordData(cr)^ do
2804 >        with PRecordData(cr)^,rdFields[j], FFieldColumns^[j] do
2805          begin
2806 <          if Qry.Params[i].name = 'IBX_INTERNAL_DBKEY' then {do not localize}
2806 >          if Param.name = 'IBX_INTERNAL_DBKEY' then {do not localize}
2807            begin
2808 <            PIBDBKey(Qry.Params[i].AsPointer)^ := rdDBKey;
2808 >            PIBDBKey(Param.AsPointer)^ := rdDBKey;
2809              continue;
2810            end;
2811 <          if rdFields[j].fdIsNull then
2812 <            Qry.Params[i].IsNull := True
2811 >          if fdIsNull then
2812 >            Param.IsNull := True
2813            else begin
2814 <            Qry.Params[i].IsNull := False;
2815 <            data := cr + rdFields[j].fdDataOfs;
2816 <            case rdFields[j].fdDataType of
2814 >            Param.IsNull := False;
2815 >            data := cr + fdDataOfs;
2816 >            case fdDataType of
2817                SQL_TEXT, SQL_VARYING:
2818                begin
2819 <                SetString(st, data, rdFields[j].fdDataLength);
2820 <                Qry.Params[i].AsString := st;
2819 >                SetString(st, data, fdDataLength);
2820 >                SetCodePage(st,fdCodePage,false);
2821 >                Param.AsString := st;
2822                end;
2823              SQL_FLOAT, SQL_DOUBLE, SQL_D_FLOAT:
2824 <              Qry.Params[i].AsDouble := PDouble(data)^;
2824 >              Param.AsDouble := PDouble(data)^;
2825              SQL_SHORT, SQL_LONG:
2826              begin
2827 <              if rdFields[j].fdDataScale = 0 then
2828 <                Qry.Params[i].AsLong := PLong(data)^
2829 <              else if rdFields[j].fdDataScale >= (-4) then
2830 <                Qry.Params[i].AsCurrency := PCurrency(data)^
2827 >              if fdDataScale = 0 then
2828 >                Param.AsLong := PLong(data)^
2829 >              else
2830 >              if fdDataScale >= (-4) then
2831 >                Param.AsCurrency := PCurrency(data)^
2832                else
2833 <                Qry.Params[i].AsDouble := PDouble(data)^;
2833 >                Param.AsDouble := PDouble(data)^;
2834              end;
2835              SQL_INT64:
2836              begin
2837 <              if rdFields[j].fdDataScale = 0 then
2838 <                Qry.Params[i].AsInt64 := PInt64(data)^
2528 <              else if rdFields[j].fdDataScale >= (-4) then
2529 <                Qry.Params[i].AsCurrency := PCurrency(data)^
2837 >              if fdDataScale = 0 then
2838 >                Param.AsInt64 := PInt64(data)^
2839                else
2840 <                Qry.Params[i].AsDouble := PDouble(data)^;
2840 >              if fdDataScale >= (-4) then
2841 >                Param.AsCurrency := PCurrency(data)^
2842 >              else
2843 >                Param.AsDouble := PDouble(data)^;
2844              end;
2845              SQL_BLOB, SQL_ARRAY, SQL_QUAD:
2846 <              Qry.Params[i].AsQuad := PISC_QUAD(data)^;
2847 <            SQL_TYPE_DATE:
2848 <            begin
2537 <              ts.Date := PInt(data)^;
2538 <              ts.Time := 0;
2539 <              Qry.Params[i].AsDate :=
2540 <                TimeStampToDateTime(ts);
2541 <            end;
2542 <            SQL_TYPE_TIME:
2543 <            begin
2544 <              ts.Date := 0;
2545 <              ts.Time := PInt(data)^;
2546 <              Qry.Params[i].AsTime :=
2547 <                TimeStampToDateTime(ts);
2548 <            end;
2846 >              Param.AsQuad := PISC_QUAD(data)^;
2847 >            SQL_TYPE_DATE,
2848 >            SQL_TYPE_TIME,
2849              SQL_TIMESTAMP:
2850 <              Qry.Params[i].AsDateTime :=
2851 <                       TimeStampToDateTime(MSecsToTimeStamp(trunc(PDouble(data)^)));
2850 >            {This is an IBX native format and not the TDataset approach. See also SetFieldData}
2851 >              Param.AsDateTime := PDateTime(data)^;
2852              SQL_BOOLEAN:
2853 <              Qry.Params[i].AsBoolean := PWordBool(data)^;
2853 >              Param.AsBoolean := PWordBool(data)^;
2854            end;
2855          end;
2856        end;
# Line 2599 | Line 2899 | begin
2899      FQRefresh.Transaction := Value;
2900      FQSelect.Transaction := Value;
2901      FQModify.Transaction := Value;
2902 +    FGeneratorField.Transaction := Value;
2903    end;
2904   end;
2905  
# Line 2706 | Line 3007 | begin
3007    Result := Assigned( FQSelect ) and FQSelect.EOF;
3008   end;
3009  
3010 < function TIBCustomDataSet.ParamByName(ParamName: String): TIBXSQLVAR;
3010 > function TIBCustomDataSet.ParamByName(ParamName: String): ISQLParam;
3011   begin
3012    ActivateConnection;
3013    ActivateTransaction;
# Line 2843 | Line 3144 | var
3144    Buff: PChar;
3145    bTr, bDB: Boolean;
3146   begin
3147 +  if (Field = nil) or (Field.DataSet <> self) then
3148 +    IBError(ibxFieldNotinDataSet,[Field.Name,Name]);
3149    Buff := GetActiveBuf;
3150    if Buff = nil then
3151    begin
3152      fs := TIBBlobStream.Create;
3153      fs.Mode := bmReadWrite;
3154 +    fs.Database := Database;
3155 +    fs.Transaction := Transaction;
3156 +    fs.SetField(Field);
3157      FBlobStreamList.Add(Pointer(fs));
3158      result := TIBDSBlobStream.Create(Field, fs, Mode);
3159      exit;
# Line 2862 | Line 3168 | begin
3168      fs.Mode := bmReadWrite;
3169      fs.Database := Database;
3170      fs.Transaction := Transaction;
3171 +    fs.SetField(Field);
3172      fs.BlobID :=
3173 <      PISC_QUAD(@Buff[PRecordData(Buff)^.rdFields[FMappedFieldPosition[Field.FieldNo - 1]].fdDataOfs])^;
3173 >      PISC_QUAD(@Buff[FFieldColumns^[FMappedFieldPosition[Field.FieldNo - 1]].fdDataOfs])^;
3174      if (CachedUpdates) then
3175      begin
3176        bTr := not Transaction.InTransaction;
# Line 2884 | Line 3191 | begin
3191    result := TIBDSBlobStream.Create(Field, fs, Mode);
3192   end;
3193  
3194 + function TIBCustomDataSet.GetArray(Field: TIBArrayField): IArray;
3195 + var Buff: PChar;
3196 +    pda: PArrayDataArray;
3197 +    bTr, bDB: Boolean;
3198 + begin
3199 +  if (Field = nil) or (Field.DataSet <> self) then
3200 +    IBError(ibxFieldNotinDataSet,[Field.Name,Name]);
3201 +  Buff := GetActiveBuf;
3202 +  if Buff = nil then
3203 +    Result := Database.Attachment.CreateArray(Transaction.TransactionIntf,
3204 +                              Field.FRelationName,Field.FieldName)
3205 +  else
3206 +  begin
3207 +    pda := PArrayDataArray(Buff + FArrayCacheOffset);
3208 +    if pda^[Field.FCacheOffset] = nil then
3209 +    begin
3210 +      AdjustRecordOnInsert(Buff);
3211 +      if Field.IsNull then
3212 +        Result := Database.Attachment.CreateArray(Transaction.TransactionIntf,
3213 +                                Field.FRelationName,Field.FieldName)
3214 +      else
3215 +        Result := Database.Attachment.OpenArray(Transaction.TransactionIntf,
3216 +                            Field.FRelationName,Field.FieldName,Field.ArrayID);
3217 +      pda^[Field.FCacheOffset] := TIBArray.Create(Field,Result);
3218 +      FArrayList.Add(pda^[Field.FCacheOffset]);
3219 +      if (CachedUpdates) then
3220 +      begin
3221 +        bTr := not Transaction.InTransaction;
3222 +        bDB := not Database.Connected;
3223 +        if bDB then
3224 +          Database.Open;
3225 +        if bTr then
3226 +          Transaction.StartTransaction;
3227 +         pda^[Field.FCacheOffset].ArrayIntf.PreLoad;
3228 +        if bTr then
3229 +          Transaction.Commit;
3230 +        if bDB then
3231 +          Database.Close;
3232 +      end;
3233 +      WriteRecordCache(PRecordData(Buff)^.rdRecordNumber, Pointer(Buff));
3234 +    end
3235 +    else
3236 +      Result := pda^[Field.FCacheOffset].ArrayIntf;
3237 +  end;
3238 + end;
3239 +
3240 + procedure TIBCustomDataSet.SetArrayIntf(AnArray: IArray; Field: TIBArrayField);
3241 + var Buff: PChar;
3242 +    pda: PArrayDataArray;
3243 + begin
3244 +  if (Field = nil) or (Field.DataSet <> self) then
3245 +    IBError(ibxFieldNotinDataSet,[Field.Name,Name]);
3246 +  Buff := GetActiveBuf;
3247 +  if Buff <> nil then
3248 +  begin
3249 +    AdjustRecordOnInsert(Buff);
3250 +    pda := PArrayDataArray(Buff + FArrayCacheOffset);
3251 +    pda^[Field.FCacheOffset].FArray := AnArray;
3252 +    WriteRecordCache(PRecordData(Buff)^.rdRecordNumber, Pointer(Buff));
3253 +  end;
3254 + end;
3255 +
3256   function TIBCustomDataSet.CompareBookmarks(Bookmark1, Bookmark2: TBookmark): Integer;
3257   const
3258    CMPLess = -1;
# Line 2964 | Line 3333 | end;
3333   procedure TIBCustomDataSet.DoBeforeClose;
3334   begin
3335    inherited DoBeforeClose;
3336 +  if FInTransactionEnd and (FCloseAction = TARollback) then
3337 +     Exit;
3338    if State in [dsInsert,dsEdit] then
3339    begin
2969    if FInTransactionEnd and (FCloseAction = TARollback) then
2970       Exit;
2971
3340      if DataSetCloseAction = dcSaveChanges then
3341        Post;
3342        {Note this can fail with an exception e.g. due to
3343         database validation error. In which case the dataset remains open }
3344    end;
3345 +  if FCachedUpdates and FUpdatesPending and (DataSetCloseAction = dcSaveChanges) then
3346 +    ApplyUpdates;
3347   end;
3348  
3349   procedure TIBCustomDataSet.DoBeforeOpen;
# Line 3005 | Line 3375 | end;
3375  
3376   procedure TIBCustomDataSet.FetchAll;
3377   var
3008  {$IFDEF NEW_TBOOKMARK }
3378    CurBookmark: TBookmark;
3010  {$ELSE}
3011  CurBookmark: string;
3012  {$ENDIF}
3379   begin
3380    FBase.SetCursor;
3381   try
# Line 3120 | Line 3486 | begin
3486      if result and (Buffer <> nil) then
3487        Move(Buff[1], Buffer^, Field.DataSize);
3488    end
3489 <  else if (FMappedFieldPosition[Field.FieldNo - 1] > 0) and
3489 >  else
3490 >  if (FMappedFieldPosition[Field.FieldNo - 1] > 0) and
3491       (FMappedFieldPosition[Field.FieldNo - 1] <= CurrentRecord^.rdFieldCount) then
3492 +  with CurrentRecord^.rdFields[FMappedFieldPosition[Field.FieldNo - 1]],
3493 +                         FFieldColumns^[FMappedFieldPosition[Field.FieldNo - 1]] do
3494    begin
3495 <    result := not CurrentRecord^.rdFields[FMappedFieldPosition[Field.FieldNo - 1]].fdIsNull;
3495 >    result := not fdIsNull;
3496      if result and (Buffer <> nil) then
3128      with CurrentRecord^.rdFields[FMappedFieldPosition[Field.FieldNo - 1]] do
3497        begin
3498 <        Data := Buff + CurrentRecord^.rdFields[FMappedFieldPosition[Field.FieldNo - 1]].fdDataOfs;
3498 >        Data := Buff + fdDataOfs;
3499          if (fdDataType = SQL_VARYING) or (fdDataType = SQL_TEXT) then
3500          begin
3501            if fdDataLength < Field.DataSize then
# Line 3198 | Line 3566 | begin
3566          if FCurrentRecord < FRecordCount then
3567            ReadRecordCache(FCurrentRecord, Buffer, False)
3568          else begin
3569 <          while (not FQSelect.EOF) and
3202 <                (FQSelect.Next <> nil) and
3569 >          while (not FQSelect.EOF) and FQSelect.Next  and
3570                  (FCurrentRecord >= FRecordCount) do begin
3571              FetchCurrentRecordToBuffer(FQSelect, FRecordCount, Buffer);
3572              Inc(FRecordCount);
# Line 3310 | Line 3677 | procedure TIBCustomDataSet.InternalCance
3677   var
3678    Buff: PChar;
3679    CurRec: Integer;
3680 +  pda: PArrayDataArray;
3681 +  i: integer;
3682   begin
3683    inherited InternalCancel;
3684    Buff := GetActiveBuf;
3685 <  if Buff <> nil then begin
3685 >  if Buff <> nil then
3686 >  begin
3687 >    pda := PArrayDataArray(Buff + FArrayCacheOffset);
3688 >    for i := 0 to ArrayFieldCount - 1 do
3689 >      pda^[i].ArrayIntf.CancelChanges;
3690      CurRec := FCurrentRecord;
3691      AdjustRecordOnInsert(Buff);
3692      if (State = dsEdit) then begin
# Line 3336 | Line 3709 | begin
3709      DeactivateTransaction;
3710    FQSelect.Close;
3711    ClearBlobCache;
3712 +  ClearArrayCache;
3713    FreeRecordBuffer(FModelBuffer);
3714    FreeRecordBuffer(FOldBuffer);
3715    FCurrentRecord := -1;
# Line 3351 | Line 3725 | begin
3725    FOBEnd := 0;
3726    FreeMem(FBufferCache);
3727    FBufferCache := nil;
3728 +  FreeMem(FFieldColumns);
3729 +  FFieldColumns := nil;
3730    FreeMem(FOldBufferCache);
3731    FOldBufferCache := nil;
3732    BindFields(False);
# Line 3425 | Line 3801 | const
3801                 'and R.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME '+ {do not localize}
3802                 'and ((not F.RDB$COMPUTED_BLR is NULL) or ' + {do not localize}
3803                 '     (not F.RDB$DEFAULT_VALUE is NULL)) '; {do not localize}
3804 +
3805 +  DefaultSQLODS12 = 'Select F.RDB$COMPUTED_BLR, ' + {do not localize}
3806 +               'F.RDB$DEFAULT_VALUE, R.RDB$FIELD_NAME, R.RDB$IDENTITY_TYPE ' + {do not localize}
3807 +               'from RDB$RELATION_FIELDS R, RDB$FIELDS F ' + {do not localize}
3808 +               'where R.RDB$RELATION_NAME = :RELATION ' +  {do not localize}
3809 +               'and R.RDB$FIELD_SOURCE = F.RDB$FIELD_NAME '+ {do not localize}
3810 +               'and ((not F.RDB$COMPUTED_BLR is NULL) or ' + {do not localize}
3811 +               '     (not F.RDB$DEFAULT_VALUE is NULL) or ' + {do not localize}
3812 +               '     ( not R.RDB$IDENTITY_TYPE is NULL))' ; {do not localize}
3813 +
3814   var
3815    FieldType: TFieldType;
3816    FieldSize: Word;
3817 +  FieldDataSize: integer;
3818    charSetID: short;
3819    CharSetSize: integer;
3820    CharSetName: RawByteString;
3434  {$IFDEF HAS_ANSISTRING_CODEPAGE}
3821    FieldCodePage: TSystemCodePage;
3436  {$ENDIF}
3822    FieldNullable : Boolean;
3823    i, FieldPosition, FieldPrecision: Integer;
3824    FieldAliasName, DBAliasName: string;
3825 <  RelationName, FieldName: string;
3825 >  aRelationName, FieldName: string;
3826    Query : TIBSQL;
3827    FieldIndex: Integer;
3828    FRelationNodes : TRelationNode;
3829 +  aArrayDimensions: integer;
3830 +  aArrayBounds: TArrayBounds;
3831 +  ArrayMetaData: IArrayMetaData;
3832  
3833    function Add_Node(Relation, Field : String) : TRelationNode;
3834    var
# Line 3463 | Line 3851 | var
3851        FField.FieldName := Query.Fields[2].AsString;
3852        FField.DEFAULT_VALUE := not Query.Fields[1].IsNull;
3853        FField.COMPUTED_BLR := not Query.Fields[0].IsNull;
3854 +      FField.IDENTITY_COLUMN := (Query.FieldCount > 3) and not Query.Fields[3].IsNull;
3855        FField.NextField := Result.FieldNodes;
3856        Result.FieldNodes := FField;
3857        Query.Next;
# Line 3516 | Line 3905 | var
3905          FField := Ffield.NextField;
3906    end;
3907  
3908 +  function Is_IDENTITY_COLUMN(Relation, Field : String) : Boolean;
3909 +  var
3910 +    FRelation : TRelationNode;
3911 +    FField : TFieldNode;
3912 +  begin
3913 +    FRelation := FRelationNodes;
3914 +    while Assigned(FRelation) and
3915 +         (FRelation.RelationName <> Relation) do
3916 +      FRelation := FRelation.NextRelation;
3917 +    if not Assigned(FRelation) then
3918 +      FRelation := Add_Node(Relation, Field);
3919 +    Result := false;
3920 +    FField := FRelation.FieldNodes;
3921 +    while Assigned(FField) do
3922 +      if FField.FieldName = Field then
3923 +      begin
3924 +        Result := Ffield.IDENTITY_COLUMN;
3925 +        Exit;
3926 +      end
3927 +      else
3928 +        FField := Ffield.NextField;
3929 +  end;
3930 +
3931    Procedure FreeNodes;
3932    var
3933      FRelation : TRelationNode;
# Line 3538 | Line 3950 | var
3950   begin
3951    FRelationNodes := TRelationNode.Create;
3952    FNeedsRefresh := False;
3953 <  Database.InternalTransaction.StartTransaction;
3953 >  if not Database.InternalTransaction.InTransaction then
3954 >    Database.InternalTransaction.StartTransaction;
3955    Query := TIBSQL.Create(self);
3956    try
3957      Query.Database := DataBase;
# Line 3546 | Line 3959 | begin
3959      FieldDefs.BeginUpdate;
3960      FieldDefs.Clear;
3961      FieldIndex := 0;
3962 <    if (Length(FMappedFieldPosition) < SourceQuery.Current.Count) then
3963 <      SetLength(FMappedFieldPosition, SourceQuery.Current.Count);
3964 <    Query.SQL.Text := DefaultSQL;
3962 >    if (Length(FMappedFieldPosition) < SourceQuery.MetaData.Count) then
3963 >      SetLength(FMappedFieldPosition, SourceQuery.MetaData.Count);
3964 >    if FDatabaseInfo.ODSMajorVersion >= 12 then
3965 >      Query.SQL.Text := DefaultSQLODS12
3966 >    else
3967 >      Query.SQL.Text := DefaultSQL;
3968      Query.Prepare;
3969 <    SetLength(FAliasNameMap, SourceQuery.Current.Count);
3970 <    SetLength(FAliasNameList, SourceQuery.Current.Count);
3971 <    for i := 0 to SourceQuery.Current.Count - 1 do
3972 <      with SourceQuery.Current[i].Data^ do
3969 >    SetLength(FAliasNameMap, SourceQuery.MetaData.Count);
3970 >    SetLength(FAliasNameList, SourceQuery.MetaData.Count);
3971 >    for i := 0 to SourceQuery.MetaData.GetCount - 1 do
3972 >      with SourceQuery.MetaData[i] do
3973        begin
3974          { Get the field name }
3975 <        FieldAliasName := SourceQuery.Current[i].Name;
3976 <        SetString(DBAliasName, aliasname, aliasname_length);
3977 <        SetString(RelationName, relname, relname_length);
3978 <        SetString(FieldName, sqlname, sqlname_length);
3975 >        FieldAliasName := GetName;
3976 >        DBAliasName := GetAliasname;
3977 >        aRelationName := getRelationName;
3978 >        FieldName := getSQLName;
3979          FAliasNameList[i] := DBAliasName;
3980          FieldSize := 0;
3981 +        FieldDataSize := GetSize;
3982          FieldPrecision := 0;
3983 <        FieldNullable := SourceQuery.Current[i].IsNullable;
3983 >        FieldNullable := IsNullable;
3984          CharSetSize := 0;
3985          CharSetName := '';
3569        {$IFDEF HAS_ANSISTRING_CODEPAGE}
3986          FieldCodePage := CP_NONE;
3987 <        {$ENDIF}
3988 <        case sqltype and not 1 of
3987 >        aArrayDimensions := 0;
3988 >        SetLength(aArrayBounds,0);
3989 >        case SQLType of
3990            { All VARCHAR's must be converted to strings before recording
3991             their values }
3992            SQL_VARYING, SQL_TEXT:
3993            begin
3994 <            CharSetSize := FBase.GetCharSetSize(sqlsubtype and $FF);
3995 <            CharSetName := FBase.GetCharSetName(sqlsubtype and $FF);
3996 <            {$IFDEF HAS_ANSISTRING_CODEPAGE}
3997 <            FieldCodePage := FBase.GetCodePage(sqlsubtype and $FF);
3998 <            {$ENDIF}
3999 <            {FieldSize is encoded for strings - see TIBStringField.SetSize for decode}
3583 <            FieldSize := sqllen;
3584 <            if CharSetSize = 2 then
3585 <              FieldType := ftWideString
3586 <            else
3587 <              FieldType := ftString;
3994 >            if not Database.Attachment.CharSetWidth(getCharSetID,CharSetSize) then
3995 >              CharSetSize := 1;
3996 >            CharSetName := Database.Attachment.GetCharsetName(getCharSetID);
3997 >            Database.Attachment.CharSetID2CodePage(getCharSetID,FieldCodePage);
3998 >            FieldSize := FieldDataSize div CharSetSize;
3999 >            FieldType := ftString;
4000            end;
4001            { All Doubles/Floats should be cast to doubles }
4002            SQL_DOUBLE, SQL_FLOAT:
4003              FieldType := ftFloat;
4004            SQL_SHORT:
4005            begin
4006 <            if (sqlscale = 0) then
4006 >            if (getScale = 0) then
4007                FieldType := ftSmallInt
4008              else begin
4009                FieldType := ftBCD;
4010                FieldPrecision := 4;
4011 <              FieldSize := -sqlscale;
4011 >              FieldSize := -getScale;
4012              end;
4013            end;
4014            SQL_LONG:
4015            begin
4016 <            if (sqlscale = 0) then
4016 >            if (getScale = 0) then
4017                FieldType := ftInteger
4018 <            else if (sqlscale >= (-4)) then
4018 >            else if (getScale >= (-4)) then
4019              begin
4020                FieldType := ftBCD;
4021                FieldPrecision := 9;
4022 <              FieldSize := -sqlscale;
4022 >              FieldSize := -getScale;
4023              end
4024              else
4025              if Database.SQLDialect = 1 then
# Line 3619 | Line 4031 | begin
4031              begin
4032                FieldType := ftFMTBCD;
4033                FieldPrecision := 9;
4034 <              FieldSize := -sqlscale;
4034 >              FieldSize := -getScale;
4035              end;
4036            end;
4037  
4038            SQL_INT64:
4039            begin
4040 <            if (sqlscale = 0) then
4040 >            if (getScale = 0) then
4041                FieldType := ftLargeInt
4042 <            else if (sqlscale >= (-4)) then
4042 >            else if (getScale >= (-4)) then
4043              begin
4044                FieldType := ftBCD;
4045                FieldPrecision := 18;
4046 <              FieldSize := -sqlscale;
4046 >              FieldSize := -getScale;
4047              end
4048              else
4049 <              FieldType := ftFloat
4049 >              FieldType := ftFloat;
4050            end;
4051            SQL_TIMESTAMP: FieldType := ftDateTime;
4052            SQL_TYPE_TIME: FieldType := ftTime;
# Line 3642 | Line 4054 | begin
4054            SQL_BLOB:
4055            begin
4056              FieldSize := sizeof (TISC_QUAD);
4057 <            if (sqlsubtype = 1) then
4057 >            if (getSubtype = 1) then
4058              begin
4059 <              if FBase.GetDefaultCharSetName <> '' then
3648 <              begin
3649 <                CharSetSize := FBase.GetDefaultCharSetSize;
3650 <                CharSetName := FBase.GetDefaultCharSetName;
3651 <                {$IFDEF HAS_ANSISTRING_CODEPAGE}
3652 <                FieldCodePage := FBase.GetDefaultCodePage;
3653 <                {$ENDIF}
3654 <              end
3655 <              else
3656 <              if strpas(sqlname) <> '' then
3657 <              begin
3658 <                charSetID := GetBlobCharSetID(Database.Handle,Database.InternalTransaction.Handle,
3659 <                        @relname,@sqlname);
3660 <                CharSetSize := FBase.GetCharSetSize(charSetID);
3661 <                CharSetName := FBase.GetCharSetName(charSetID);
3662 <                {$IFDEF HAS_ANSISTRING_CODEPAGE}
3663 <                FieldCodePage := FBase.GetCodePage(charSetID);
3664 <                {$ENDIF}
3665 <             end
3666 <              else  {Complex SQL with no identifiable column and no connection default}
3667 <              begin
3668 <                CharSetName := '';
4059 >              if not Database.Attachment.CharSetWidth(getCharSetID,CharSetSize) then
4060                  CharSetSize := 1;
4061 <                {$IFDEF HAS_ANSISTRING_CODEPAGE}
4062 <                FieldCodePage := CP_NONE;
4063 <                {$ENDIF}
3673 <              end;
3674 <              if CharSetSize = 2 then
3675 <                FieldType := ftWideMemo
3676 <              else
3677 <                FieldType := ftMemo;
4061 >              CharSetName := Database.Attachment.GetCharsetName(getCharSetID);
4062 >              Database.Attachment.CharSetID2CodePage(getCharSetID,FieldCodePage);
4063 >              FieldType := ftMemo;
4064              end
4065              else
4066                FieldType := ftBlob;
# Line 3682 | Line 4068 | begin
4068            SQL_ARRAY:
4069            begin
4070              FieldSize := sizeof (TISC_QUAD);
4071 <            FieldType := ftUnknown;
4071 >            FieldType := ftArray;
4072 >            ArrayMetaData := GetArrayMetaData;
4073 >            if ArrayMetaData <> nil then
4074 >            begin
4075 >              aArrayDimensions := ArrayMetaData.GetDimensions;
4076 >              aArrayBounds := ArrayMetaData.GetBounds;
4077 >            end;
4078            end;
4079            SQL_BOOLEAN:
4080               FieldType:= ftBoolean;
# Line 3699 | Line 4091 | begin
4091              Name := FieldAliasName;
4092              FAliasNameMap[FieldNo-1] := DBAliasName;
4093              Size := FieldSize;
4094 +            DataSize := FieldDataSize;
4095              Precision := FieldPrecision;
4096              Required := not FieldNullable;
4097 +            RelationName := aRelationName;
4098              InternalCalcField := False;
4099              CharacterSetSize := CharSetSize;
4100              CharacterSetName := CharSetName;
3707            {$IFDEF HAS_ANSISTRING_CODEPAGE}
4101              CodePage := FieldCodePage;
4102 <            {$ENDIF}
4102 >            ArrayDimensions := aArrayDimensions;
4103 >            ArrayBounds := aArrayBounds;
4104              if (FieldName <> '') and (RelationName <> '') then
4105              begin
4106 +              IdentityColumn := Is_IDENTITY_COLUMN(RelationName, FieldName);
4107                if Has_COMPUTED_BLR(RelationName, FieldName) then
4108                begin
4109                  Attributes := [faReadOnly];
# Line 3734 | Line 4129 | begin
4129      FreeNodes;
4130      Database.InternalTransaction.Commit;
4131      FieldDefs.EndUpdate;
4132 +    FieldDefs.Updated := true;
4133    end;
4134   end;
4135  
# Line 3751 | Line 4147 | begin
4147    else begin
4148      Buffer := AllocRecordBuffer;
4149      try
4150 <      while FQSelect.Next <> nil do
4150 >      while FQSelect.Next do
4151        begin
4152          FetchCurrentRecordToBuffer(FQSelect, FRecordCount, Buffer);
4153          Inc(FRecordCount);
# Line 3766 | Line 4162 | end;
4162   procedure TIBCustomDataSet.InternalSetParamsFromCursor;
4163   var
4164    i: Integer;
4165 <  cur_param: TIBXSQLVAR;
4165 >  cur_param: ISQLParam;
4166    cur_field: TField;
4167    s: TStream;
4168   begin
# Line 3774 | Line 4170 | begin
4170      IBError(ibxeEmptyQuery, [nil]);
4171    if not FInternalPrepared then
4172      InternalPrepare;
4173 <  if (SQLParams.Count > 0) and (DataSource <> nil) and (DataSource.DataSet <> nil) then
4173 >  if (SQLParams.GetCount > 0) and (DataSource <> nil) and (DataSource.DataSet <> nil) then
4174    begin
4175 <    for i := 0 to SQLParams.Count - 1 do
4175 >    for i := 0 to SQLParams.GetCount - 1 do
4176      begin
4177        cur_field := DataSource.DataSet.FindField(SQLParams[i].Name);
4178 <      cur_param := SQLParams[i];
4179 <      if (cur_field <> nil) then begin
4178 >      if (cur_field <> nil) then
4179 >      begin
4180 >        cur_param := SQLParams[i];
4181          if (cur_field.IsNull) then
4182            cur_param.IsNull := True
4183 <        else case cur_field.DataType of
4183 >        else
4184 >        case cur_field.DataType of
4185            ftString:
4186              cur_param.AsString := cur_field.AsString;
4187            ftBoolean:
# Line 3793 | Line 4191 | begin
4191            ftInteger:
4192              cur_param.AsLong := cur_field.AsInteger;
4193            ftLargeInt:
4194 <            cur_param.AsInt64 := TLargeIntField(cur_field).AsLargeInt;
4194 >            cur_param.AsInt64 := cur_field.AsLargeInt;
4195            ftFloat, ftCurrency:
4196             cur_param.AsDouble := cur_field.AsFloat;
4197            ftBCD:
# Line 3810 | Line 4208 | begin
4208              try
4209                s := DataSource.DataSet.
4210                       CreateBlobStream(cur_field, bmRead);
4211 <              cur_param.LoadFromStream(s);
4211 >              cur_param.AsBlob := TIBDSBlobStream(s).FBlobStream.Blob;
4212              finally
4213                s.free;
4214              end;
4215            end;
4216 +          ftArray:
4217 +            cur_param.AsArray := TIBArrayField(cur_field).ArrayIntf;
4218            else
4219              IBError(ibxeNotSupported, [nil]);
4220          end;
# Line 3847 | Line 4247 | procedure TIBCustomDataSet.InternalOpen;
4247      result := SizeOf(TRecordData) + ((n - 1) * SizeOf(TFieldData));
4248    end;
4249  
3850  function GetFieldDef(aFieldNo: integer): TIBFieldDef;
3851  var i: integer;
3852  begin
3853    Result := nil;
3854    for i := 0 to FieldDefs.Count - 1 do
3855      if FieldDefs[i].FieldNo = aFieldNo then
3856      begin
3857        Result := TIBFieldDef(FieldDefs[i]);
3858        break;
3859      end;
3860  end;
3861
3862  procedure SetExtendedProperties;
3863  var i: integer;
3864      IBFieldDef: TIBFieldDef;
3865  begin
3866    for i := 0 to Fields.Count - 1 do
3867      if Fields[i].FieldNo > 0 then
3868      begin
3869        if(Fields[i] is TIBStringField) then
3870        with TIBStringField(Fields[i]) do
3871        begin
3872          IBFieldDef := GetFieldDef(FieldNo);
3873          if IBFieldDef <> nil then
3874          begin
3875            CharacterSetSize := IBFieldDef.CharacterSetSize;
3876            CharacterSetName := IBFieldDef.CharacterSetName;
3877            {$IFDEF HAS_ANSISTRING_CODEPAGE}
3878            CodePage := IBFieldDef.CodePage;
3879            {$ENDIF}
3880          end;
3881        end
3882        else
3883        if(Fields[i] is TIBWideStringField) then
3884        with TIBWideStringField(Fields[i]) do
3885        begin
3886          IBFieldDef := GetFieldDef(FieldNo);
3887          if IBFieldDef <> nil then
3888          begin
3889            CharacterSetSize := IBFieldDef.CharacterSetSize;
3890            CharacterSetName := IBFieldDef.CharacterSetName;
3891          end;
3892        end
3893        else
3894        if(Fields[i] is TIBMemoField) then
3895        with TIBMemoField(Fields[i]) do
3896        begin
3897          IBFieldDef := GetFieldDef(FieldNo);
3898          if IBFieldDef <> nil then
3899          begin
3900            CharacterSetSize := IBFieldDef.CharacterSetSize;
3901            CharacterSetName := IBFieldDef.CharacterSetName;
3902            {$IFDEF HAS_ANSISTRING_CODEPAGE}
3903            CodePage := IBFieldDef.CodePage;
3904            {$ENDIF}
3905          end;
3906        end
3907        else
3908        if(Fields[i] is TIBWideMemoField) then
3909        with TIBWideMemoField(Fields[i]) do
3910        begin
3911          IBFieldDef := GetFieldDef(FieldNo);
3912          if IBFieldDef <> nil then
3913          begin
3914            CharacterSetSize := IBFieldDef.CharacterSetSize;
3915            CharacterSetName := IBFieldDef.CharacterSetName;
3916          end;
3917        end
3918      end
3919  end;
3920
4250   begin
4251    FBase.SetCursor;
4252    try
# Line 3927 | Line 4256 | begin
4256        IBError(ibxeEmptyQuery, [nil]);
4257      if not FInternalPrepared then
4258        InternalPrepare;
4259 <   if FQSelect.SQLType = SQLSelect then
4259 >   if FQSelect.SQLStatementType = SQLSelect then
4260     begin
4261        if DefaultFields then
4262          CreateFields;
4263 +      FArrayFieldCount := 0;
4264        BindFields(True);
3935      SetExtendedProperties;
4265        FCurrentRecord := -1;
4266        FQSelect.ExecQuery;
4267        FOpen := FQSelect.Open;
# Line 3943 | Line 4272 | begin
4272          3. After the dummy fetch, FRecordSize will be appropriately
4273             adjusted to reflect the additional "weight" of the field
4274             data.
4275 <        4. Set up the FCalcFieldsOffset, FBlobCacheOffset and FRecordBufferSize.
4275 >        4. Set up the FCalcFieldsOffset, FBlobCacheOffset, FArrayCacheOffset and FRecordBufferSize.
4276          5. Now, with the BufferSize available, allocate memory for chunks of records
4277          6. Re-allocate the model buffer, accounting for the new
4278             FRecordBufferSize.
4279          7. Finally, calls to AllocRecordBuffer will work!.
4280         }
4281        {Step 1}
4282 <      FRecordSize := RecordDataLength(FQSelect.Current.Count);
4282 >      FRecordSize := RecordDataLength(FQSelect.FieldCount);
4283        {Step 2, 3}
4284 +      GetMem(FFieldColumns,sizeof(TFieldColumns) * (FQSelect.FieldCount));
4285        IBAlloc(FModelBuffer, 0, FRecordSize);
4286 <      FetchCurrentRecordToBuffer(FQSelect, -1, FModelBuffer);
4286 >      InitModelBuffer(FQSelect, FModelBuffer);
4287        {Step 4}
4288        FCalcFieldsOffset := FRecordSize;
4289        FBlobCacheOffset := FCalcFieldsOffset + CalcFieldsSize;
4290 <      FRecordBufferSize := (FBlobCacheOffset + (BlobFieldCount * SizeOf(TIBBlobStream)));
4290 >      FArrayCacheOffset := (FBlobCacheOffset + (BlobFieldCount * SizeOf(TIBBlobStream)));
4291 >      FRecordBufferSize := FArrayCacheOffset + (ArrayFieldCount * sizeof(IArray));
4292        {Step 5}
4293        if UniDirectional then
4294          FBufferChunkSize := FRecordBufferSize * UniCache
# Line 3973 | Line 4304 | begin
4304        FCacheSize := FBufferChunkSize;
4305        FOldCacheSize := FBufferChunkSize;
4306        {Step 6}
4307 <      IBAlloc(FModelBuffer, RecordDataLength(FQSelect.Current.Count),
4307 >      IBAlloc(FModelBuffer, RecordDataLength(FQSelect.FieldCount),
4308                               FRecordBufferSize);
4309        {Step 7}
4310        FOldBuffer := AllocRecordBuffer;
# Line 4071 | Line 4402 | end;
4402   function TIBCustomDataSet.Locate(const KeyFields: string; const KeyValues: Variant;
4403                                   Options: TLocateOptions): Boolean;
4404   var
4074  {$IFDEF NEW_TBOOKMARK }
4405    CurBookmark: TBookmark;
4076  {$ELSE}
4077  CurBookmark: string;
4078  {$ENDIF}
4406   begin
4407    DisableControls;
4408    try
# Line 4093 | Line 4420 | function TIBCustomDataSet.Lookup(const K
4420                                   const ResultFields: string): Variant;
4421   var
4422    fl: TList;
4096  {$IFDEF NEW_TBOOKMARK }
4423    CurBookmark: TBookmark;
4098  {$ELSE}
4099  CurBookmark: string;
4100  {$ENDIF}
4424   begin
4425    DisableControls;
4426    fl := TList.Create;
# Line 4170 | Line 4493 | begin
4493        MappedFieldPos := FMappedFieldPosition[Field.FieldNo - 1];
4494        if (MappedFieldPos > 0) and
4495           (MappedFieldPos <= rdFieldCount) then
4496 +      with rdFields[MappedFieldPos], FFieldColumns^[MappedFieldPos] do
4497        begin
4498          Field.Validate(Buffer);
4499          if (Buffer = nil) or
4500             (Field is TIBStringField) and (PChar(Buffer)[0] = #0) then
4501 <          rdFields[MappedFieldPos].fdIsNull := True
4502 <        else begin
4503 <          Move(Buffer^, Buff[rdFields[MappedFieldPos].fdDataOfs],
4504 <                 rdFields[MappedFieldPos].fdDataSize);
4505 <          if (rdFields[MappedFieldPos].fdDataType = SQL_TEXT) or
4506 <             (rdFields[MappedFieldPos].fdDataType = SQL_VARYING) then
4507 <            rdFields[MappedFieldPos].fdDataLength := StrLen(PChar(Buffer));
4184 <          rdFields[MappedFieldPos].fdIsNull := False;
4501 >          fdIsNull := True
4502 >        else
4503 >        begin
4504 >          Move(Buffer^, Buff[fdDataOfs],fdDataSize);
4505 >          if (fdDataType = SQL_TEXT) or (fdDataType = SQL_VARYING) then
4506 >            fdDataLength := StrLen(PChar(Buffer));
4507 >          fdIsNull := False;
4508            if rdUpdateStatus = usUnmodified then
4509            begin
4510              if CachedUpdates then
# Line 4282 | Line 4605 | begin
4605    if FInternalPrepared then
4606    begin
4607      CheckDatasetClosed;
4608 +    if FDidActivate then
4609 +      DeactivateTransaction;
4610      FieldDefs.Clear;
4611      FieldDefs.Updated := false;
4612      FInternalPrepared := False;
# Line 4302 | Line 4627 | begin
4627        IBError(ibxeEmptyQuery, [nil]);
4628      if not FInternalPrepared then
4629        InternalPrepare;
4630 <    if FQSelect.SQLType = SQLSelect then
4630 >    if FQSelect.SQLStatementType = SQLSelect then
4631      begin
4632        IBError(ibxeIsASelectStatement, [nil]);
4633      end
# Line 4315 | Line 4640 | begin
4640    end;
4641   end;
4642  
4643 < function TIBCustomDataSet.GetSelectStmtHandle: TISC_STMT_HANDLE;
4643 > function TIBCustomDataSet.GetSelectStmtIntf: IStatement;
4644   begin
4645 <  Result := FQSelect.Handle;
4645 >  Result := FQSelect.Statement;
4646   end;
4647  
4648   function TIBCustomDataSet.GetParser: TSelectSQLParser;
# Line 4372 | Line 4697 | end;
4697  
4698   { TIBDataSet IProviderSupport }
4699  
4700 < (*procedure TIBCustomDataSet.PSEndTransaction(Commit: Boolean);
4700 > procedure TIBCustomDataSet.PSEndTransaction(Commit: Boolean);
4701   begin
4702    if Commit then
4703      Transaction.Commit else
# Line 4525 | Line 4850 | begin
4850    Transaction.StartTransaction;
4851   end;
4852  
4853 < function TIBCustomDataSet.PSGetTableName: string;
4853 > function TIBCustomDataSet.PsGetTableName: string;
4854   begin
4855   //  if not FInternalPrepared then
4856   //    InternalPrepare;
# Line 4535 | Line 4860 | begin
4860    if not FQSelect.Prepared then
4861      FQSelect.Prepare;
4862    Result := FQSelect.UniqueRelationName;
4863 < end;*)
4863 > end;
4864  
4865   procedure TIBDataSet.BatchInput(InputObject: TIBBatchInput);
4866   begin
# Line 4620 | Line 4945 | end;
4945   function TIBCustomDataSet.GetFieldData(Field: TField; Buffer: Pointer;
4946    NativeFormat: Boolean): Boolean;
4947   begin
4948 <  if (Field.DataType = ftBCD) and not NativeFormat then
4948 >  {These datatypes use IBX conventions and not TDataset conventions}
4949 >  if (Field.DataType in [ftBCD,ftDateTime,ftDate,ftTime]) and not NativeFormat then
4950      Result := InternalGetFieldData(Field, Buffer)
4951    else
4952      Result := inherited GetFieldData(Field, Buffer, NativeFormat);
# Line 4646 | Line 4972 | end;
4972   procedure TIBCustomDataSet.SetFieldData(Field: TField; Buffer: Pointer;
4973    NativeFormat: Boolean);
4974   begin
4975 <  if (not NativeFormat) and (Field.DataType = ftBCD) then
4975 >  {These datatypes use IBX conventions and not TDataset conventions}
4976 >  if (not NativeFormat) and (Field.DataType in [ftBCD,ftDateTime,ftDate,ftTime]) then
4977      InternalSetfieldData(Field, Buffer)
4978    else
4979      inherited SetFieldData(Field, buffer, NativeFormat);
# Line 4666 | Line 4993 | begin
4993    inherited Destroy;
4994   end;
4995  
4996 < procedure TIBDataSetUpdateObject.SetRefreshSQL(Value: TStrings);
4996 > procedure TIBDataSetUpdateObject.SetRefreshSQL(value: TStrings);
4997   begin
4998    FRefreshSQL.Assign(Value);
4999   end;
5000  
5001 + procedure TIBDataSetUpdateObject.InternalSetParams(Params: ISQLParams;
5002 +  buff: PChar);
5003 + begin
5004 +  if not Assigned(DataSet) then Exit;
5005 +  DataSet.SetInternalSQLParams(Params, buff);
5006 + end;
5007 +
5008   procedure TIBDataSetUpdateObject.InternalSetParams(Query: TIBSQL; buff: PChar);
5009   begin
5010 +  InternalSetParams(Query.Params,buff);
5011 + end;
5012 +
5013 + procedure TIBDataSetUpdateObject.UpdateRecordFromQuery(UpdateKind: TUpdateKind;
5014 +  QryResults: IResults; Buffer: PChar);
5015 + begin
5016    if not Assigned(DataSet) then Exit;
5017 <  DataSet.SetInternalSQLParams(Query, buff);
5017 >  case UpdateKind of
5018 >  ukModify, ukInsert:
5019 >    DataSet.UpdateRecordFromQuery(QryResults, Buffer);
5020 >  ukDelete:
5021 >    DataSet.DoDeleteReturning(QryResults);
5022 >  end;
5023 > end;
5024 >
5025 > function TIBDSBlobStream.GetSize: Int64;
5026 > begin
5027 >  Result := FBlobStream.BlobSize;
5028   end;
5029  
5030   { TIBDSBlobStream }
# Line 4685 | Line 5035 | begin
5035    FBlobStream := ABlobStream;
5036    FBlobStream.Seek(0, soFromBeginning);
5037    if (Mode = bmWrite) then
5038 +  begin
5039      FBlobStream.Truncate;
5040 +    TIBCustomDataSet(FField.DataSet).RecordModified(True);
5041 +    TBlobField(FField).Modified := true;
5042 +    FHasWritten := true;
5043 +  end;
5044   end;
5045  
5046   destructor TIBDSBlobStream.Destroy;
# Line 4727 | Line 5082 | end;
5082  
5083   procedure TIBGenerator.SetIncrement(const AValue: integer);
5084   begin
5085 +  if FIncrement = AValue then Exit;
5086    if AValue < 0 then
5087 <     raise Exception.Create('A Generator Increment cannot be negative');
5088 <  FIncrement := AValue
5087 >    IBError(ibxeNegativeGenerator,[]);
5088 >  FIncrement := AValue;
5089 >  SetQuerySQL;
5090   end;
5091  
5092 < function TIBGenerator.GetNextValue(ADatabase: TIBDatabase;
4736 <  ATransaction: TIBTransaction): integer;
5092 > procedure TIBGenerator.SetTransaction(AValue: TIBTransaction);
5093   begin
5094 <  with TIBSQL.Create(nil) do
5095 <  try
5096 <    Database := ADatabase;
5097 <    Transaction := ATransaction;
5098 <    if not assigned(Database) then
5099 <       IBError(ibxeCannotSetDatabase,[]);
5100 <    if not assigned(Transaction) then
5101 <       IBError(ibxeCannotSetTransaction,[]);
5102 <    with Transaction do
5103 <      if not InTransaction then StartTransaction;
5104 <    SQL.Text := Format('Select Gen_ID(%s,%d) as ID From RDB$Database',[FGeneratorName,Increment]);
5105 <    Prepare;
5094 >  FQuery.Transaction := AValue;
5095 > end;
5096 >
5097 > procedure TIBGenerator.SetQuerySQL;
5098 > begin
5099 >  FQuery.SQL.Text := Format('Select Gen_ID(%s,%d) From RDB$Database',[FGeneratorName,Increment]);
5100 > end;
5101 >
5102 > function TIBGenerator.GetDatabase: TIBDatabase;
5103 > begin
5104 >  Result := FQuery.Database;
5105 > end;
5106 >
5107 > function TIBGenerator.GetTransaction: TIBTransaction;
5108 > begin
5109 >  Result := FQuery.Transaction;
5110 > end;
5111 >
5112 > procedure TIBGenerator.SetDatabase(AValue: TIBDatabase);
5113 > begin
5114 >  FQuery.Database := AValue;
5115 > end;
5116 >
5117 > procedure TIBGenerator.SetGeneratorName(AValue: string);
5118 > begin
5119 >  if FGeneratorName = AValue then Exit;
5120 >  FGeneratorName := AValue;
5121 >  SetQuerySQL;
5122 > end;
5123 >
5124 > function TIBGenerator.GetNextValue: integer;
5125 > begin
5126 >  with FQuery do
5127 >  begin
5128 >    Transaction.Active := true;
5129      ExecQuery;
5130      try
5131 <      Result := FieldByName('ID').AsInteger
5131 >      Result := Fields[0].AsInteger
5132      finally
5133        Close
5134      end;
4756  finally
4757    Free
5135    end;
5136   end;
5137  
# Line 4762 | Line 5139 | constructor TIBGenerator.Create(Owner: T
5139   begin
5140    FOwner := Owner;
5141    FIncrement := 1;
5142 +  FQuery := TIBSQL.Create(nil);
5143 + end;
5144 +
5145 + destructor TIBGenerator.Destroy;
5146 + begin
5147 +  if assigned(FQuery) then FQuery.Free;
5148 +  inherited Destroy;
5149   end;
5150  
5151  
5152   procedure TIBGenerator.Apply;
5153   begin
5154 <  if (FGeneratorName <> '') and (FFieldName <> '') and Owner.FieldByName(FFieldName).IsNull then
5155 <    Owner.FieldByName(FFieldName).AsInteger := GetNextValue(Owner.Database,Owner.Transaction);
5154 >  if assigned(Database) and assigned(Transaction) and
5155 >       (FGeneratorName <> '') and (FFieldName <> '') and Owner.FieldByName(FFieldName).IsNull then
5156 >    Owner.FieldByName(FFieldName).AsInteger := GetNextValue;
5157   end;
5158  
5159  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines