2
0
Эх сурвалжийг харах

* move validate to newvalue assignment, fixes regression in non fcl-db datasets
caused by r17220. Patch by Luiz Americo, Mantis #19313

git-svn-id: trunk@18872 -

marco 14 жил өмнө
parent
commit
facc124827

+ 6 - 5
packages/fcl-db/src/base/bufdataset.pas

@@ -1859,14 +1859,15 @@ var CurrBuff : pointer;
     NullMask : pbyte;
 
 begin
-  if not (state in [dsEdit, dsInsert, dsFilter, dsCalcFields]) then
-    begin
-    DatabaseErrorFmt(SNotEditing,[Name],self);
-    exit;
-    end;
+  if not (State in dsWriteModes) then
+    DatabaseError(SNotEditing, Self);
   CurrBuff := GetCurrentBuffer;
   If Field.Fieldno > 0 then // If = 0, then calculated field or something
     begin
+    if Field.ReadOnly and not (State in [dsSetKey, dsFilter]) then
+      DatabaseErrorFmt(SReadOnlyField, [Field.DisplayName]);	
+    if State in [dsEdit, dsInsert, dsNewValue] then
+      Field.Validate(Buffer);	
     NullMask := CurrBuff;
 
     inc(CurrBuff,FFieldBufPositions[Field.FieldNo-1]);

+ 0 - 6
packages/fcl-db/src/base/fields.inc

@@ -820,12 +820,6 @@ procedure TField.SetData(Buffer: Pointer; NativeFormat : Boolean);
 begin
   If Not Assigned(FDataset) then
     DatabaseErrorFmt(SNoDataset,[FieldName]);
-  if (FieldNo>0) and not (FDataSet.State in [dsSetKey, dsFilter]) then
-    begin
-    if ReadOnly then 
-      DatabaseErrorFmt(SReadOnlyField, [DisplayName], Self); 
-    Validate(Buffer);
-    end;
   FDataSet.SetFieldData(Self,Buffer, NativeFormat);
 end;
 

+ 2 - 0
packages/fcl-db/src/dbase/dbf.pas

@@ -764,6 +764,8 @@ var
 begin
   if (Field.FieldNo >= 0) then
   begin
+    if State in [dsEdit, dsInsert, dsNewValue] then
+      Field.Validate(Buffer);
     Dst := @PDbfRecord(ActiveBuffer)^.DeletedFlag;
     FDbfFile.SetFieldData(Field.FieldNo - 1, Field.DataType, Buffer, Dst, NativeFormat);
   end else begin    { ***** fkCalculated, fkLookup ***** }

+ 2 - 0
packages/fcl-db/src/memds/memds.pp

@@ -728,6 +728,8 @@ begin
  I:= Field.FieldNo - 1;
  if (I >= 0) and  MDSGetActiveBuffer(DestBuffer) then 
    begin
+   if State in [dsEdit, dsInsert, dsNewValue] then
+      Field.Validate(Buffer);
    if buffer = nil then 
      setfieldisnull(pointer(destbuffer),I)
    else 

+ 6 - 5
packages/fcl-db/src/sdf/sdfdata.pp

@@ -128,7 +128,7 @@ How to Install
 interface
 
 uses
-  DB, Classes, SysUtils;
+  DB, Classes, SysUtils, DBConst;
 
 type
 //-----------------------------------------------------------------------------
@@ -664,16 +664,17 @@ var
   RecBuf, BufEnd: PChar;
   p : Integer;
 begin
-  if not (State in [dsEdit, dsInsert]) then
-    DatabaseError('Dataset not in edit or insert mode', Self);
+  if not (State in dsWriteModes) then
+    DatabaseError(SNotEditing, Self);
   GetActiveRecBuf(RecBuf);
   if Field.FieldNo > 0 then
   begin
     if State = dsCalcFields then
       DatabaseError('Dataset not in edit or insert mode', Self);
     if Field.ReadOnly and not (State in [dsSetKey, dsFilter]) then
-      DatabaseErrorFmt('Field ''%s'' cannot be modified', [Field.DisplayName]);
-    Field.Validate(Buffer);
+      DatabaseErrorFmt(SReadOnlyField, [Field.DisplayName]);
+    if State in [dsEdit, dsInsert, dsNewValue] then
+      Field.Validate(Buffer);
     if Field.FieldKind <> fkInternalCalc then
     begin
       SetFieldPos(RecBuf, Field.FieldNo);