Board index » delphi » Copy entire record between identical tables?

Copy entire record between identical tables?

I need to be able to copy an entire record between two identical tables -
is there a way of doing this in a single operation rather than field by
field?

JJ.

--
j...@asgard-ltd.co.uk

 

Re:Copy entire record between identical tables?


"Jonathan J Quick" <j...@asgard-ltd.co.uk> wrote:

Quote
>I need to be able to copy an entire record between two identical tables -
>is there a way of doing this in a single operation rather than field by
>field?
>JJ.
>--
>j...@asgard-ltd.co.uk

Jonathan,

I don't know if this is what yoy need but maybe..
I use this for copying one record in the same table.
You only need 2 datasources for the same fysical table.

But it can also with two exactly the same tables.

  Table2.insert;

  for i:=0 to Table1.fieldcount-1 do
    Table2.fields[i].Assign(Table1.Fields[i]);

  Table2.post;

Hans van Spijker
spij...@pi.net
The Netherlands

Re:Copy entire record between identical tables?


Sundial Services <news-re...@sundialservices.com> wrote in article
<news-reply.6348.02F15...@sundialservices.com>...

Quote
> In article <01bcd3ee$e2c3ef20$d1247...@jjquick.dircon.co.uk> "Jonathan J
Quick" <j...@asgard-ltd.co.uk> writes:

> >I need to be able to copy an entire record between two identical tables
-
> >is there a way of doing this in a single operation rather than field by
> >field?

> Take a closer look at the TBatchMove component.

Not really appropriate for record-by-record processing unless I've
misunderstood it; the scenario is to read a record from an input table,
maybe modify it (but maybe not), then write it to the identically
structured output table. It seems you have to move the input record's
individual fields to the output record, although as many kind people have
emailed me, it's easy enough to do this in a simple loop. I'm surprised
there's no property representing an entire record though...

JJ.

--
Email: jjqu...@dircon.co.uk
Homepage: http://www.users.dircon.co.uk/~jjquick/

Re:Copy entire record between identical tables?


In article <01bcd4b3$6c9d1680$e0247...@jjquick.dircon.co.uk>, "Jonathan J

Quote
Quick" <j...@asgard-ltd.co.uk> writes:
>> >I need to be able to copy an entire record between two identical tables
>-
>> >is there a way of doing this in a single operation rather than field by
>> >field?

>> Take a closer look at the TBatchMove component.

>Not really appropriate for record-by-record processing unless I've
>misunderstood it; the scenario is to read a record from an input table,
>maybe modify it (but maybe not), then write it to the identically
>structured output table. It seems you have to move the input record's
>individual fields to the output record, although as many kind people have
>emailed me, it's easy enough to do this in a simple loop. I'm surprised
>there's no property representing an entire record though...

>JJ.

I'd use the Fields property to transfer the info using a simple loop.  Example
for rno:= 0 to Table1.FieldCount - 1 do begin
   Table2.Fields[rno].asString := Table1.Fields[rno].asString;
end;

/js

Re:Copy entire record between identical tables?


In article <61ihv4$...@halley.pi.net>, spij...@pi.net (Hans van Spijker) wrote:

Quote
>"Jonathan J Quick" <j...@asgard-ltd.co.uk> wrote:

>>I need to be able to copy an entire record between two identical tables -
>>is there a way of doing this in a single operation rather than field by
>>field?

>>JJ.

I would do it using SQL:

INSERT INTO TABLE2 (SELECT * FROM TABLE1 WHERE <something>)

This will insert one or more records from table1, depending on what's in
the WHERE clause (if anything at all).

--
|| Bjorn K. Nilssen      // http://home.sn.no/~bjoernk/  // mainly 3D ||

Re:Copy entire record between identical tables?


Quote
Jonathan J Quick wrote:

> I need to be able to copy an entire record between two identical tables
> -
> is there a way of doing this in a single operation rather than field by
> field?

I use : for i := 0 to FieldCount - 1
        do TableNew.Fields[i].Assign(TableOld.Fields[i]);

JP Passama
http://perso.wanadoo.fr/passama

Re:Copy entire record between identical tables?


In article <19971009162901.MAA22...@ladder02.news.aol.com>, JefSummers
<jefsumm...@aol.com> writes

Quote
>In article <01bcd4b3$6c9d1680$e0247...@jjquick.dircon.co.uk>, "Jonathan J
>Quick" <j...@asgard-ltd.co.uk> writes:

>>> >I need to be able to copy an entire record between two identical tables
>>-
>>> >is there a way of doing this in a single operation rather than field by
>>> >field?

>>> Take a closer look at the TBatchMove component.

>>Not really appropriate for record-by-record processing unless I've
>>misunderstood it; the scenario is to read a record from an input table,
>>maybe modify it (but maybe not), then write it to the identically
>>structured output table. It seems you have to move the input record's
>>individual fields to the output record, although as many kind people have
>>emailed me, it's easy enough to do this in a simple loop. I'm surprised
>>there's no property representing an entire record though...

>>JJ.

>I'd use the Fields property to transfer the info using a simple loop.  Example
>for rno:= 0 to Table1.FieldCount - 1 do begin
>   Table2.Fields[rno].asString := Table1.Fields[rno].asString;
>end;

>/js

BatchMove will do individual records if you set RecordCount to 1.
For a loop I would use:

for rno:= 0 to Table1.FieldCount - 1 do begin
   Table2.Fields[rno].assign(Table1.Fields[rno]);

which would handle any type of field.

--
Mark Williams                   M...@polyhedron.co.uk

Polyhedron Software Ltd.        
Programs for Programmers - QA, Compilers, Graphics

************ Visit our Web site on http://www.polyhedron.co.uk/ ************

Other Threads