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