Forum > Databases

access TDataset/TCSVDataset record values as constant array?

(1/1)

msocorcim:
With TCSVDataset, Is there a way to place a complete record into a dynamic array? It seems like that would be generally useful.

I pursued GetCurrentRecord( Buffer: TRecordBuffer ), but couldn't find out how to allocate/initialize memory for a buffer.


The object is to efficiently copy a large number of records to a new CSVDataset something like:

CSVDataSetDst.AppendRecord([NewField1Value, NewField2Value,NewField3Value, SrcRecordArray])

Thanks!

dje:
Other people have asked and as far as I can see, the answer is no.

A search of the FreePascal source code shows, TDataSet.GetCurrentRecord(Buffer: TRecordBuffer): Boolean; is not implemented nor is it overrided by TDataSet derived classes.

ActiveBuffer "looks" promising, but a search of FreePascal source also shows TRecordBuffer is db format specific. ie: a Simple Move() instruction didn't work for me either by using MemSize() or RecordSize.

What you are after might (?) be possible via code like below (which doesnt work as is).


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure DataSetCopy(ASrc, ADst: TDataSet);begin  ASrc.First;  while not ASrc.EOF do begin    ADst.Append;    Move(ASrc.ActiveBuffer^, ADst.ActiveBuffer^, ADst.RecordSize);    ADst.Post;    ASrc.Next;  end;end;
It would seem the problem is, record buffers were never implemented at the TDataSet level, so each derived class implemented it own record buffer system. The code for these caching systems, looks ultra hairy, so I wouldn't even think about a trying to batch copy via TRecordBuffer.

So, no.

cdbc:
Hi
Would this be an option:
{excerpt from TMemDataset}

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Procedure TMemDataset.CopyFromDataset(DataSet : TDataSet; CopyData : Boolean);Var  I  : Integer;  F,F1,F2 : TField;  L1,L2  : TList;  N : String;begin  Clear(True);  // NOT from fielddefs. The data may not be available in buffers !!  for I:= 0 to Dataset.FieldCount-1 do begin    F:= Dataset.Fields[I];    // ææ special case for ftAutoInc fields 16.02.2020 /bc    if F.DataType = ftAutoInc then TFieldDef.Create(FieldDefs,F.FieldName,ftInteger,F.Size,F.Required,F.FieldNo)    else TFieldDef.Create(FieldDefs,F.FieldName,F.DataType,F.Size,F.Required,F.FieldNo);  end;  CreateTable;  if CopyData then begin    Open;    L1:= TList.Create;    try      L2:= TList.Create;      try        for I:= 0 to FieldDefs.Count-1 do begin          N:= FieldDefs[I].Name;          F1:= FieldByName(N);          F2:= DataSet.FieldByName(N);          L1.Add(F1);          L2.Add(F2);        end;        Dataset.DisableControls;        try          Dataset.Open;          while not Dataset.EOF do begin            Append;            for I:= 0 to L1.Count-1 do begin              F1:= TField(L1[i]);              F2:= TField(L2[I]);              case F1.DataType of                ftString   : F1.AsString:= F2.AsString;                ftBoolean  : F1.AsBoolean:= F2.AsBoolean;                ftFloat    : F1.AsFloat:= F2.AsFloat;                ftLargeInt : F1.AsInteger:= F2.AsInteger;                ftSmallInt : F1.AsInteger:= F2.AsInteger;                ftInteger  : F1.AsInteger:= F2.AsInteger;                ftDate     : F1.AsDateTime:= F2.AsDateTime;                ftTime     : F1.AsDateTime:= F2.AsDateTime;                ftDateTime : F1.AsDateTime:= F2.AsDateTime;              end;            end;            try Post; except Cancel; Raise; end;            Dataset.Next;          end;        finally Dataset.EnableControls; end;      finally L2.Free; end;    finally L1.Free; end;  end;end;Regards Benny

Navigation

[0] Message Index

Go to full version