Page 1 of 1
How to copy Data inside one table
Posted: Tue 24 Apr 2007 07:54
by FanderlF
Hey,
I need to build a new row (containing numbers, blobs...) copying an old row and changing some values.
Is there any possibility to do this without using an SQL Query? I tried to use 2 TOraTables on the same table, but then I got a debugger exception (seems not to be considered to be used that way).
Is there an easy way to coyp Data from one row to another?
Thanks in advance,
Florian Fanderl
Posted: Tue 24 Apr 2007 10:19
by jfudickar
Without sitting on my development-system:
Code: Select all
dataset.insert;
dataset.fieldbyname('Field1').AsString := 'A';
dataset.fieldbyname('Field12').AsInteger := 3;
dataset.post;
Greetings
Jens
Posted: Tue 24 Apr 2007 11:10
by FanderlF
Hmmm... I was just wondering if there wasn't a general functionality. But that helps

at least I can copy it by hand, if the table doesnt get too big. Though I'd prefer a more general row copy function, cause dealing with Blobs (Streams) is a bit annoying.
Posted: Tue 24 Apr 2007 12:25
by Plash
There is no procedure that copies data from one row to another in ODAC. You should manually copy each value.
Posted: Wed 25 Apr 2007 06:59
by FanderlF
ok

thank you... then I'll do it that way.
Posted: Wed 25 Apr 2007 20:22
by robert.wachtel
Code: Select all
procedure DuplicateCurrentRecord(aDataSet: TDataSet);
var
Data: array of variant;
aRecord: array of TVarRec;
i: integer;
max: integer;
begin
max := aDataSet.fields.count - 1;
// set the lenghth of the arecord array to be the same as the number of
// elements in the data array
SetLength(arecord, max + 1);
SetLength(data, max + 1);
// set the variant type pointers to the data array
for i := 0 to max do
begin
arecord[i].VType := vtVariant;
arecord[i].VVariant := @data[i];
end;
// Copy the Record to the Array
for i := 0 to max do
Data[i] := aDataSet.fields[i].value;
aDataSet.Insert;
aDataSet.SetFields(aRecord);
end;
Posted: Thu 26 Apr 2007 07:00
by FanderlF
Great

thank you... I'll test it immediately
