tdatabase arraytodbf

tdatabase arraytodbf

Postby Silvio.Falconi » Sun Feb 03, 2019 9:09 am

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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: tdatabase arraytodbf

Postby ukoenig » Sun Feb 03, 2019 3:53 pm

tested : read from backup and write to original

1. read backup-data to array
2. zap original dbf
3. write backup-data to original

Code: Select all  Expand view  RUN

// ---------------------- 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 :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
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: tdatabase arraytodbf

Postby Silvio.Falconi » Sun Feb 03, 2019 4:13 pm

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 original

Code: Select all  Expand view  RUN

// ---------------------- 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 :D


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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: tdatabase arraytodbf

Postby ukoenig » Sun Feb 03, 2019 4:24 pm

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

Code: Select all  Expand view  RUN
3 I cannot make pack and zap
4. I can only delete all records.


Image

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: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 26 guests