📄 pfibdataset.pas
字号:
WriteRecordCache(PRecordData(Buff)^.rdRecordNumber, Buff);
if not CachedUpdates then
AutoCommitUpdateTransaction;
if not EmptyStrings(FQRefresh.SQL) and (poRefreshAfterPost in Options)
and (CacheModelOptions.CacheModelKind=cmkStandard)
then
begin
DoBeforeRefresh;
InternalRefreshRow(FQRefresh, Buff);
DoAfterRefresh;
end;
UpdateBlobInfo(Buff,ubiClearOldValue,False,False);
end;
procedure TpFIBDataSet.InternalDeleteRecord(Qry: TFIBQuery; Buff: Pointer);
var
vNeedDeleteFromCache:boolean;
begin
if Qry.SQL.Count > 0 then
if Qry.SQL[0] = SNoAction then
Exit;
AutoStartUpdateTransaction;
ExecUpdateObjects(ukDelete, Buff, oeBeforeDefault);
if not EmptyStrings(Qry.SQL) then
begin
SetQueryParams(Qry, Buff);
Qry.ExecQuery;
if Qry.Open then
Qry.Next;
FHaveUncommitedChanges:=True;
end;
ExecUpdateObjects(ukDelete, Buff, oeAfterDefault);
if poRefreshAfterDelete in Options then
begin
vNeedDeleteFromCache:=not InternalRefreshRow(QRefresh,Buff);
end
else
vNeedDeleteFromCache:=True;
if vNeedDeleteFromCache then
PRecordData(Buff)^.rdFlags := Byte(cusDeletedApplied);
WriteRecordCache(PRecordData(Buff)^.rdRecordNumber, Buff);
if not FCachedUpdates then
AutoCommitUpdateTransaction;
end;
procedure TpFIBDataSet.DoOnDeleteError
(DataSet: TDataSet; E: DB.EDatabaseError; var Action: TDataAction);
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetError(DataSet, deOnDeleteError, E, Action);
if FContainer <> nil then
FContainer.DataSetError(DataSet, deOnDeleteError, E, Action);
if Assigned(vUserOnDeleteError) then
vUserOnDeleteError(DataSet, E, Action);
end;
function TpFIBDataSet.CompareFieldValues(Field:TField;const S1,S2:variant):integer;
var
Compared:boolean;
begin
Compared:=False;
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
Compared:=GlobalContainer.DataSetCompareFieldValues(Self, Field,S1,S2,Result);
if FContainer <> nil then
Compared:=FContainer.DataSetCompareFieldValues(Self, Field,S1,S2,Result);
if not Compared then
Result:= inherited CompareFieldValues(Field,S1,S2);
end;
procedure TpFIBDataSet.DoOnPostError
(DataSet: TDataSet; E: DB.EDatabaseError; var Action: TDataAction);
begin
inherited;
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetError(DataSet, deOnPostError, E, Action);
if FContainer <> nil then
FContainer.DataSetError(DataSet, deOnPostError, E, Action);
if Assigned(vUserOnPostError) then
vUserOnPostError(DataSet, E, Action);
end;
procedure TpFIBDataSet.DoBeforePost;
begin
if (State = dsInsert) and
(FAutoUpdateOptions.WhenGetGenID = wgBeforePost) then
IncGenerator;
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deBeforePost);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deBeforePost);
inherited;
if not CachedUpdates then
AutoGenerateSQLText(State);
end;
procedure TpFIBDataSet.InternalOpen ;
begin
inherited InternalOpen;
UpdateFieldsProps
end;
procedure TpFIBDataSet.InternalPost;
begin
inherited InternalPost;
if State = dsInsert then
FFilteredCacheInfo.NonVisibleRecords.IncValues(GetRealRecno, 1);
end;
procedure TpFIBDataSet.DoAfterPost;
var
ActBuff: PRecordData;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deAfterPost);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deAfterPost);
if (poProtectedEdit in Options) and not CachedUpdates and not (AutoCommit) then
begin
ActBuff := PRecordData(GetActiveBuf);
if ActBuff <> nil then
begin
with ActBuff^ do
rdFlags := Byte(cusModified);
WriteRecordCache(ActBuff^.rdRecordNumber, PChar(ActBuff));
end
end;
inherited;
if AutoCommit and CachedUpdates then
begin
ApplyUpdToBase;
AutoCommitUpdateTransaction;
CommitUpdToCach
end;
if
(dcForceMasterRefresh in FDetailConditions) and not CachedUpdates
then
RefreshMasterDS;
end;
procedure TpFIBDataSet.DoBeforeCancel;
begin
inherited;
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deBeforeCancel);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deBeforeCancel);
end;
procedure TpFIBDataSet.DoAfterCancel;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deAfterCancel);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deAfterCancel);
inherited;
end;
procedure TpFIBDataSet.DoBeforeDelete;
begin
if not CanDelete then
Abort;
{ if not CachedUpdates
and not (FAutoUpdateOptions.UpdateOnlyModifiedFields)
and not (drsInCacheRefresh in FRunState)
then
begin
PrepareQuery(FIBDataSet.skDelete);
if not CanDelete then
Abort;
end;}
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deBeforeDelete);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deBeforeDelete);
inherited;
end;
procedure TpFIBDataSet.DoBeforeInsert;
begin
ForceEndWaitMaster;
if not CanInsert then
Abort;
{ if not CachedUpdates and not (FAutoUpdateOptions.UpdateOnlyModifiedFields)
and not (drsInCacheRefresh in FRunState) then
PrepareQuery(FIBDataSet.skInsert);
if not CanInsert then
Abort; }
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deBeforeInsert);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deBeforeInsert);
if Assigned(BeforeInsert) then
BeforeInsert(Self);
end;
procedure TpFIBDataSet.DoAfterInsert;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deAfterInsert);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deAfterInsert);
inherited;
end;
procedure TpFIBDataSet.DoAfterEdit;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deAfterEdit);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deAfterEdit);
inherited
end;
procedure TpFIBDataSet.DoAfterDelete;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deAfterDelete);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deAfterDelete);
if AutoCommit and CachedUpdates then
begin
ApplyUpdToBase;
AutoCommitUpdateTransaction;
CommitUpdToCach
end;
inherited
end;
procedure TpFIBDataSet.DoAfterScroll;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deAfterScroll);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deAfterScroll);
inherited
end;
procedure TpFIBDataSet.DoBeforeClose;
begin
if DefaultFields and Assigned(FFilterParser) then
FFilterParser.ResetFields;
if DisableCOCount > 0 then
Exit;
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deBeforeClose);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deBeforeClose);
inherited
end;
procedure TpFIBDataSet.DoBeforeRefresh;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deBeforeRefresh);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deBeforeRefresh);
inherited;
end;
procedure TpFIBDataSet.DoAfterRefresh;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deAfterRefresh);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deAfterRefresh);
inherited;
end;
procedure TpFIBDataSet.DoOnApplyDefaultValue(Field:TField; var Applied:boolean);
begin
Applied:=False;
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DoOnApplyDefaultValue(Self,Field, Applied);
if FContainer <> nil then
FContainer.DoOnApplyDefaultValue(Self,Field, Applied);
if Assigned(FOnApplyDefaultValue) then
FOnApplyDefaultValue(Self,Field,Applied);
end;
procedure TpFIBDataSet.DoOnCalcFields;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deOnCalcFields);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deOnCalcFields);
inherited
end;
procedure TpFIBDataSet.DoBeforeScroll;
begin
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deBeforeScroll);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deBeforeScroll);
inherited
end;
procedure TpFIBDataSet.DoOnNewRecord;
var
i: integer;
de: string;
vDifferenceTime: double;
PAR: TFIBXSQLVAR;
DefValueApplied:boolean;
GuidValue:TGUID;
begin
if (FAutoUpdateOptions.WhenGetGenID = wgOnNewRecord) then
IncGenerator
else
if (FAutoUpdateOptions.WhenGetGenID = wgBeforePost) and (KeyField <> nil) then
KeyField.Required := False;
if DataBase is TpFIBDataBase then
vDifferenceTime := TpFIBDataBase(DataBase).DifferenceTime
else
vDifferenceTime := 0;
for i := 0 to Pred(FieldCount) do
with Fields[i] do
begin
if AutoUpdateOptions.SelectGenId and (Fields[i] = KeyField)
then
Continue;
if (Fields[i] is TFIBStringField) and
TFIBStringField(Fields[i]).DefaultValueEmptyString then
asString := ''
else
if (Fields[i] is TFIBGuidField) then
begin
CreateGuid(GuidValue);
TFIBGuidField(Fields[i]).asGuid:=GuidValue;
end
else
begin
if not FDefaultsInited then
begin
if FAutoUpdateOptions.ParamsToFieldsLinks.Count>0 then
PAR :=
Params.FindParam(FAutoUpdateOptions.ParamsToFieldsLinks.Values[Fields[i].FieldName])
else
PAR :=nil;
FParamsForFields[i]:=PAR ;
end
else
PAR := FParamsForFields[i];
if PAR <> nil then
Fields[i].Value := PAR.Value
else
begin
de := FastUpperCase(FastTrim(DefaultExpression));
if de <> '' then
begin
de:=CutQuote(de);
DefValueApplied:=False;
DoOnApplyDefaultValue(Fields[i],DefValueApplied);
if not DefValueApplied then
begin
if de <> 'NULL' then
if Fields[i] is TDateTimeField then
begin
if StringInArray(de, ['NOW','CURRENT_TIME','CURRENT_TIMESTAMP']) then
asDateTime := Now - vDifferenceTime
else
if StringInArray(de, ['TODAY', 'CURRENT_DATE']) then
asDateTime := Trunc(Now - vDifferenceTime)
else
if (de = 'TOMORROW') then
asDateTime := Trunc(Now - vDifferenceTime) + 1
else
if (de = 'YESTERDAY') then
asDateTime := Trunc(Now - vDifferenceTime) - 1
else
asString := DefaultExpression;
end
else
if (Fields[i] is TFIBStringField) then
begin
if StringInArray(de, ['USER', 'CURRENT_USER']) then
begin
asString := DataBase.DBParamByDPB[isc_dpb_user_name]
end
else
if StringInArray(de, ['ROLE', 'CURRENT_ROLE']) then
begin
asString := DataBase.DBParamByDPB[isc_dpb_sql_role_name]
end
else
if(Length(DefaultExpression)>0) and (DefaultExpression[1]='''') then
asString := FastCopy(DefaultExpression,2,Length(DefaultExpression)-2)
else
asString := DefaultExpression;
end
else
asString := DefaultExpression;
end;
end;
end;
end;
end;
if (GlobalContainer<>nil) and (FContainer<>GlobalContainer) then
GlobalContainer.DataSetEvent(Self, deOnNewRecord);
if FContainer <> nil then
FContainer.DataSetEvent(Self, deOnNewRecord);
FDefaultsInited:=True;
inherited DoOnNewRecord
end;
function TpFIBDataSet.WillGenerateSQLs: boolean;
begin
with FAutoUpdateOptions do
Result := UpdateOnlyModifiedFields and
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -