소스 검색

fcl-db: bufdataset: improves rev.25333; length indicator is saved only for variable length fields

git-svn-id: trunk@25337 -
lacak 12 년 전
부모
커밋
b2e7364ae8
1개의 변경된 파일29개의 추가작업 그리고 12개의 파일을 삭제
  1. 29 12
      packages/fcl-db/src/base/bufdataset.pas

+ 29 - 12
packages/fcl-db/src/base/bufdataset.pas

@@ -386,6 +386,9 @@ type
     const
       FpcBinaryIdent1 = 'BinBufDataset'; // Old version 1; support for transient period;
       FpcBinaryIdent2 = 'BinBufDataSet';
+      StringFieldTypes = [ftString,ftFixedChar,ftWideString,ftFixedWideChar];
+      BlobFieldTypes = [ftBlob,ftMemo,ftWideMemo];
+      VarLenFieldTypes = StringFieldTypes + BlobFieldTypes + [ftBytes,ftVarBytes];
     var
       FVersion: byte;
   public
@@ -3591,14 +3594,22 @@ begin
           begin
           AField := Fields.FieldByNumber(FieldDefs[i].FieldNo);
           if AField=nil then continue;
-          L := Stream.ReadDWord;
-          SetLength(B, L);
-          if L > 0 then
-            Stream.ReadBuffer(B[0], L);
-          if FieldDefs[i].DataType in [ftBlob, ftMemo, ftWideMemo] then
-            RestoreBlobField(ADataset, AField, @B[0], L)
+          if AField.DataType in StringFieldTypes then
+            AField.AsString := Stream.ReadAnsiString
           else
-            AField.SetData(@B[0], False);  // set it to the FilterBuffer
+            begin
+            if AField.DataType in VarLenFieldTypes then
+              L := Stream.ReadDWord
+            else
+              L := AField.DataSize;
+            SetLength(B, L);
+            if L > 0 then
+              Stream.ReadBuffer(B[0], L);
+            if AField.DataType in BlobFieldTypes then
+              RestoreBlobField(ADataset, AField, @B[0], L)
+            else
+              AField.SetData(@B[0], False);  // set it to the FilterBuffer
+            end;
           end;
   end;
 end;
@@ -3624,11 +3635,17 @@ begin
       begin
       AField := Fields.FieldByNumber(FieldDefs[i].FieldNo);
       if AField=nil then continue;
-      B := AField.AsBytes;
-      L := length(B);
-      Stream.WriteDWord(L);
-      if L > 0 then
-        Stream.WriteBuffer(B[0], L);
+      if AField.DataType in StringFieldTypes then
+        Stream.WriteAnsiString(AField.AsString)
+      else
+        begin
+        B := AField.AsBytes;
+        L := length(B);
+        if AField.DataType in VarLenFieldTypes then
+          Stream.WriteDWord(L);
+        if L > 0 then
+          Stream.WriteBuffer(B[0], L);
+        end;
      end;
 end;