tdatabase arraytodbf
- Silvio.Falconi
- Posts: 7154
- Joined: Thu Oct 18, 2012 7:17 pm
- Been thanked: 2 times
tdatabase arraytodbf
there is a command to rewrite dbf from array into tdatabase class ^?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Re: tdatabase arraytodbf
tested : read from backup and write to original
1. read backup-data to array
2. zap original dbf
3. write backup-data to original
regards
Uwe
1. read backup-data to array
2. zap original dbf
3. write backup-data to original
Code: Select all | Expand
// ---------------------- restore data from original DBF ( backup )----------
FUNCTION NET_RESTORE3(oBrw)
LOCAL lReturn := .F., aData := {}
PACKZAP_1(2) // zap original dbf
// original data
USE CUST_ORG NEW ALIAS "CUSTNEW" SHARED VIA "DBFCDX"
oCustNew := TDataBase():New( Select( "CUSTNEW" ) )
// Read required data into array
cList := "*,RECNO()"
aData := oCustNew:FW_DbfToArray( @cList )
aNew := Array( oCustNew:FCount() + 1 )
AEval( aNew, { |u,i| aNew[ i ] := uValBlank( oCustNew:FieldGet( i ) ) }, 1, oCustNew:FCount() )
nRecNoCol:= Len( aNew )
aNew[ nRecNoCol ] := 0
// Read done close backup
oCustNew:Close()
// write new data to customer.dbf from backup
WITH OBJECT oBrw:oDbf
oCust:FW_ArrayToDbf( aData )
END
oCust:GoTop()
oBrw:SetoDbf(oCust)
oBrw:Refresh()
MSGINFO("Original data restored !")
RETURN (lReturn)
// -----------------
FUNCTION PACKZAP_1(nStyle)
IF oCust:lShared() = .T.
oCust:Close()
oCust := TCustomers():New(.F.) // exclusive
oCust:use()
// MSGINFO( oCust:lShared(),"Shared")
ENDIF
IF oCust:Used()
IF nStyle = 1
oCust:Pack()
MSGINFO("Done Pack")
ELSE
oCust:Zap()
MSGINFO("Done Zap")
ENDIF
ENDIF
oCust:Close()
oCust := TCustomers():New(.T.) // back to shared
oCust:use()
RETURN( NIL)
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.
i work with FW.
If you have any questions about special functions, maybe i can help.
- Silvio.Falconi
- Posts: 7154
- Joined: Thu Oct 18, 2012 7:17 pm
- Been thanked: 2 times
Re: tdatabase arraytodbf
ukoenig wrote:tested : read from backup and write to original
1. read backup-data to array
2. zap original dbf
3. write backup-data to originalCode: Select all | Expand
// ---------------------- restore data from original DBF ( backup )----------
FUNCTION NET_RESTORE3(oBrw)
LOCAL lReturn := .F., aData := {}
PACKZAP_1(2) // zap original dbf
// original data
USE CUST_ORG NEW ALIAS "CUSTNEW" SHARED VIA "DBFCDX"
oCustNew := TDataBase():New( Select( "CUSTNEW" ) )
// Read required data into array
cList := "*,RECNO()"
aData := oCustNew:FW_DbfToArray( @cList )
aNew := Array( oCustNew:FCount() + 1 )
AEval( aNew, { |u,i| aNew[ i ] := uValBlank( oCustNew:FieldGet( i ) ) }, 1, oCustNew:FCount() )
nRecNoCol:= Len( aNew )
aNew[ nRecNoCol ] := 0
// Read done close backup
oCustNew:Close()
// write new data to customer.dbf from backup
WITH OBJECT oBrw:oDbf
oCust:FW_ArrayToDbf( aData )
END
oCust:GoTop()
oBrw:SetoDbf(oCust)
oBrw:Refresh()
MSGINFO("Original data restored !")
RETURN (lReturn)
// -----------------
FUNCTION PACKZAP_1(nStyle)
IF oCust:lShared() = .T.
oCust:Close()
oCust := TCustomers():New(.F.) // exclusive
oCust:use()
// MSGINFO( oCust:lShared(),"Shared")
ENDIF
IF oCust:Used()
IF nStyle = 1
oCust:Pack()
MSGINFO("Done Pack")
ELSE
oCust:Zap()
MSGINFO("Done Zap")
ENDIF
ENDIF
oCust:Close()
oCust := TCustomers():New(.T.) // back to shared
oCust:use()
RETURN( NIL)
regards
Uwe
1. I must open a dbf with tdatabase on share mode.
2. The index have For !deleted()
3 I cannot make pack and zap
4. I can only delete all records.
My aData atray can be of 450,800, and over records.
It can be too hard to save.
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Re: tdatabase arraytodbf
Silvio,
what happens with deleted records
after deleting records normally You need a pack
or do You want to clear the fields
or keep them marked as deleted adding new data from the array
just delete PACKZAP_1(2) // zap original dbf
and the array-data will be added to the original dbf and keeps the original data
I deleted some records from the original
and added the data as array from the backup ( same like the original )
like You can see there are double data now.
red is deleted and new from the array-import ( added )
just see the recno - number

regards
Uwe
what happens with deleted records

after deleting records normally You need a pack
or do You want to clear the fields
or keep them marked as deleted adding new data from the array

just delete PACKZAP_1(2) // zap original dbf
and the array-data will be added to the original dbf and keeps the original data
I deleted some records from the original
and added the data as array from the backup ( same like the original )
like You can see there are double data now.
red is deleted and new from the array-import ( added )
just see the recno - number
Code: Select all | Expand
3 I cannot make pack and zap
4. I can only delete all records.

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.
i work with FW.
If you have any questions about special functions, maybe i can help.