Copy or paste one record

Post Reply
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Copy or paste one record

Post by driessen »

Hello,

Is there a method to copy or/and paste a complete record of a DBF, without knowing its structure?

Thanks a lot in advance for any help.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Copy or paste one record

Post by karinha »

Hello, see this aid program.

Is in Portuguese, but is not difficult.

http://www.pctoledo.com.br/forum/viewto ... =1&t=12062

Download:

http://www.pctoledo.com.br/forum/fileba ... 141&page=1

Regards.
João Santos - São Paulo - Brasil
User avatar
Euclides
Posts: 144
Joined: Wed Mar 28, 2007 1:19 pm

Re: Copy or paste one record

Post by Euclides »

Hello Michel.
To 'copy' and ´paste' database records I use the array-field functions SCATTER & GATHER with option for field checking.
I you want, I can post them here.
HTH & regards, Euclides
Jack
Posts: 249
Joined: Wed Jul 11, 2007 11:06 am

Re: Copy or paste one record

Post by Jack »

Here is my code :

vdata:={}
for a=1 to fcount()
aadd(vdata,fieldget(a))
next
append blank


if rlock()
for e=1 to fcount()
fieldput(e,vdata[e])
next
unlock
skip 0
else
MsgAlert("Lock error !!")
endif
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: Copy or paste one record

Post by FranciscoA »

Hi. I do Exactly as Jack do it. The Source and Target dbfs must be identical.
Regards.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh1204-MySql-TMySql
Gale FORd
Posts: 663
Joined: Mon Dec 05, 2005 11:22 pm
Location: Houston
Contact:

Re: Copy or paste one record

Post by Gale FORd »

These functions work even if the database is not the same. Of coarse the field will not be copied if it does not exist in the other database but no error will occur.
You can also pass a record number so that you can take 1 record and update another record in the same database.
aData := scatter()
// Select other database
// Append blank or lock record
gather( aData )

Code: Select all

function scatter( nRecNo )
   local nFldCount := fcount()
   local nCounter
   local aReturn
   local aValues := array( nFldCount )
   local aNames := array( nFldCount )
   if nRecNo == nil
      nRecNo := recno()
   endif

   goto nRecNo
   for nCounter = 1 to nFldCount
      aValues[ nCounter ] := fieldget( nCounter )
      aNames[ nCounter ] := fieldname( nCounter )
   next
Return( {aValues, aNames } )

function gather( aRecValues, nRecNo )
   local nFldCount := len( aRecValues[1] )
   local nCounter
   if nRecNo == nil
      nRecNo := recno()
   endif
   goto nRecNo
   for nCounter = 1 to nFldCount
      nFieldPos := fieldpos(aRecValues[ 2 ][ nCounter ])
      if nFieldPos > 0
         fieldput( nFieldPos, aRecValues[ 1 ][ nCounter ] )
      endif
   next
Return( Nil )
 
User avatar
driessen
Posts: 1239
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Copy or paste one record

Post by driessen »

Thanks a lot for all your help, guys.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 21.01 - Harbour 3.2.0 (October 2020) - xHarbour Builder (January 2020) - Bcc7
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Copy or paste one record

Post by nageswaragunupudi »

An easy way:

Assume we want to copy Record at No 100 and paste over Record No. 200

Code: Select all

USE CUSTOMER
DATABASE oDbf

oDbf:GoTo( 100 )
CUSTOMER->( DBGOTO( 200 ) )
oDbf:Save()
 
Assume we want to copy Record No: 150 and append the same data as a new record.

Code: Select all

USE CUSTOMER
DATABASE oDbf

oDbf:GoTo( 150 )
CUSTOMER->( DBAPPEND() )
oDbf:Save()
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: Copy or paste one record

Post by Otto »

Dear Mr. Rao,

thank you for this example.
Would you be so kind to explain what exactly this lines are doing:

DATABASE oDbf

CUSTOMER->( DBGOTO( 200 ) )
Why don’t we use here
oDbf:DBGoto(200)

oDbf:Save()

Thanks in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
User avatar
James Bott
Posts: 4654
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA
Contact:

Re: Copy or paste one record

Post by James Bott »

CUSTOMER->( DBGOTO( 200 ) )

This is to prevent the buffer from being reloaded.

Another way you could do it:

oDBF:lBuffer:=.f.
oDBF:goto(200)
oDBF:save()

James
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Copy or paste one record

Post by ukoenig »

Maybe do You want to < RESET or REPLACE > defined vars of the new record ?

A test, using different copy-options for the destination record of types < numeric, logic and date > :
I added a new logic-field in DBF customer, to show how to receive different results.

Added many new options :

1. new copy-field-replacement
2. fieldprotection to replace fields with a new value
3. incremental seek
4. filter 2 - 6 can be a multiple selection fieldtyle N, L and D

The 2. record-copy shows the result of a protected field ( salary 11 ).
All other fields are replaced.

A 0 of the destination get APPENDS arecord
A >0 defines the destination record and replaces the values.

Image

best regards
Uwe :?:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Copy or paste one record

Post by ukoenig »

For the final solution of the COPY-test, I added many options
In case something is still not working or possible to make it better, just give me a answer

Download :
http://www.pflegeplus.com/DOWNLOADS/Reccopy1.zip

Usage :

1. select any field-options for the record-copy
--- ( nothing selected will make a NORMAL copy without replacing something )
2. You can change from index to natural order
3. click on a record, to copy
---The record-number will be displayed in the start-get
4. use checkboxes to enable multiple filters
5. added incremental seek
6. possible to delete double names ( records ) after tests
7. possible to define multiple copys
8. exclude fields from replacing values with defined field-numbers
9. Fieldnumbers added to the xbrowse-header
10. Added a INI, to start with the last selected record
11. You can change the Dlg-background using the included function :
--- color = WD_BACKGRD( oDlg2, 1)
--- gradient = WD_BACKGRD( oDlg2, 2, nDColorF, nDColorB, nDGradPos, lDDirect)
--- brush = WD_BACKGRD( oDlg2, 3, , , , , cDBrush )
12. added a new field < Freelancer > to customer.dbf to handle the filter of logical fields

Destination-get = 0 will append a new record.
Destination-get > 0 will replace a record.

A selected replace-checkbox will auto-switch from .T. to .F. if nesessary,
to avoid double selections.
sample :
date-vars selected : < empty date >
date vars changed to DATE() will reset the checkbox < empty date > selected before to .F.


sample :
2 copies defined and replaced with empty date-fields ( 502, 503 )
2 rows before, 2 normal copys ( 500, 501 )


Image

best regards
Uwe :D
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Copy or paste one record

Post by nageswaragunupudi »

I forgot another simpler way:

Code: Select all

DBGOTO( 100 )
h := FW_RecToHash()
DBGOTO( 200)
FW_HashToRec( h )
 
The function takes care of locking and unlocking automatically.

We can also copy selected fields

Code: Select all

DBGOTO( 100 )
h := FW_RecToHash( "FIRST,CITY,SALARY" )
DBGOTO( 200 )
FW_HashToRec( h )
 
Regards

G. N. Rao.
Hyderabad, India
Post Reply