Page 1 of 1
Copy or paste one record
Posted: Fri Dec 05, 2014 12:53 pm
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.
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 1:48 pm
by karinha
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 4:07 pm
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
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 4:12 pm
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
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 5:24 pm
by FranciscoA
Hi. I do Exactly as Jack do it. The Source and Target dbfs must be identical.
Regards.
Re: Copy or paste one record
Posted: Fri Dec 05, 2014 11:09 pm
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 )
Re: Copy or paste one record
Posted: Sat Dec 06, 2014 8:20 pm
by driessen
Thanks a lot for all your help, guys.
Re: Copy or paste one record
Posted: Sun Jan 04, 2015 8:32 pm
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()
Re: Copy or paste one record
Posted: Mon Jan 05, 2015 1:27 pm
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
Re: Copy or paste one record
Posted: Mon Jan 05, 2015 5:24 pm
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
Re: Copy or paste one record
Posted: Thu Jan 08, 2015 1:58 pm
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.
best regards
Uwe
Re: Copy or paste one record
Posted: Sat Jan 10, 2015 1:04 pm
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 )
best regards
Uwe
Re: Copy or paste one record
Posted: Fri Jan 16, 2015 2:57 am
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 )