Copy structure or create new file dbf

Copy structure or create new file dbf

Postby Silvio.Falconi » Tue Jun 07, 2022 11:33 am

to facilitate viewing, since I have too large an archive I decided to create a configuration to create another smaller archive

maybe if I had a smaller database the procedures could work better and faster

i tried inTdatabase

oLotto:CopyTo( cDir+"Integrale")
oLotto:CopyTo( cDir+"Virtuale")

but this makes a physical copy of the dbf, instead I wanted to create at least for the "Virtual" archive only the structure and then through a filtering system insert the selected records in the new archive

How could I do ?

Code: Select all  Expand view


If nTipo=2
    oDbf :=TDatabase():Open( , cDir+"Virtuale", "DBFCDX", .T. )
    oDbf:setorder(1)
    oDbf:Exec( <||
     SET FILTER TO   (  dFirst <= FIELD->DATA .AND.             ;
                        dLast >=  FIELD->DATA )
          return nil
      > )
    oDbf:gobottom()

 else
     oDbf :=TDatabase():Open( , cDir+"Integrale", "DBFCDX", .T. )
     oDbf:setorder(1)
     oDbf:gobottom()
  Endif


If I use
oDbf:Exec( <||
SET FILTER TO ( dFirst <= FIELD->DATA .AND. ;
dLast >= FIELD->DATA )
return nil
> )


then something not run

that's why I thought about creating a new archive by filtering from the full archive
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: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: Copy structure or create new file dbf

Postby nageswaragunupudi » Tue Jun 07, 2022 1:10 pm

Code: Select all  Expand view
USE SOURCEDBF ....
COPY TO NEWDBF FOR <filtercond>
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10620
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Copy structure or create new file dbf

Postby James Bott » Wed Jun 08, 2022 7:51 pm

Using an index with a scope is much faster.

You create the index once when the database is first used, then you automatically open the index whenever the database object is opened. Then you set the scope and then the low and high values you want to see using oDB:setScope(xLow,xHigh). The only records read will be those you want.

I tested a 1 million record DBF file using a scope to filter out about 20,000 records and it takes less than a second! Using a filter instead takes 23 seconds.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Re: Copy structure or create new file dbf

Postby Marc Venken » Wed Jun 08, 2022 8:02 pm

James, This is what you mean ? or a other way ?
Best to have the index set to the index of the field ?

Code: Select all  Expand view

//   oBrw[2]:bChange    := { || Scope("factinfo","document","factart","factart"),oBrw22:refresh() }

function Scope(cParent,cData,cChild,cChildTag)
  LOCAL cZoekdata:= alltrim(upper( (cParent)->&cData))

  (cChild)->(dbsetorder(cChildTag))

  (cChild)->(ORDSCOPE(0, "" ) )  // these 2 lines seems to be best used to clear the scope ?  Is this still needed ?
  (cChild)->(ORDSCOPE(1, "" ) )

  (cChild)->( ORDSCOPE(0, cZoekData ) )
  (cChild)->(ORDSCOPE(1, cZoekData ) )
  (cChild)->(DBGOTOP())

Return NIL
 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Copy structure or create new file dbf

Postby Jimmy » Thu Jun 09, 2022 4:01 am

hi Silvio,

are you sure that you want Dates EXECPT "Filter" :?:

Code: Select all  Expand view
  dFirst <= FIELD->DATA .AND. dLast >= FIELD->DATA

that only work for
Code: Select all  Expand view
  dFirst = FIELD->DATA = dLast


"normal" i want Dates between "Filter"-Top / -End
Code: Select all  Expand view
  dFirst >= FIELD->DATA .AND. dLast <= FIELD->DATA

---
Code: Select all  Expand view

   USE XXX
   COPY STRUCTURE [FIELDS <cFieldname,...>] TO <cFilename>

to create a EMPTY() new DBF
greeting,
Jimmy
User avatar
Jimmy
 
Posts: 1725
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: Copy structure or create new file dbf

Postby Silvio.Falconi » Thu Jun 09, 2022 7:42 am

YesterDay I made as I made on Clipper

Before i create two Database
Create_VirtualeDb(cdir)
Create_IntegraleDb(cDir)

then

oLotto:=TDatabase():Open( , cDir+"lotto", "DBFCDX", .T. )
oLotto:setorder(1)
oLotto:Exec( <||
SET FILTER TO ( dFirst <= FIELD->DATA .AND. ;
dLast >= FIELD->DATA .AND. ;
aCountMesi[ MONTH( FIELD->DATA ) ] .AND. ;
aCountGiorni[ DOW( FIELD->DATA ) ] .AND. ;
aCountDate[ DAY( FIELD->DATA ) ] )
return nil
> )

oLotto:gobottom()

If nTipo=2

atempDbf:= oLotto:DbfToArray()
oVirtuale:=TDatabase():Open( , cDir+"Virtuale", "DBFCDX", .T. )
oVirtuale:SetOrder( 0 )
oVirtuale:ArrayToDBF( atempDbf, , nil, .t., .t. )
oVirtuale:close()
else
oLotto:gobottom()
atempDbf:= oLotto:DbfToArray()
oIntegrale:=TDatabase():Open( , cDir+"Integrale", "DBFCDX", .T. )
oIntegrale:SetOrder( 0 )
oIntegrale:ArrayToDBF( atempDbf, , nil, .t., .t. )
oIntegrale:close()

Endif
oLotto:close()


For Now it seems to run ok
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: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: Copy structure or create new file dbf

Postby Marc Venken » Thu Jun 09, 2022 10:11 am

Silvio,

You have it running... That's mostly the goal ....

But did you try the scope ? I would think it should be faster and less code. A new second filtering (maybe not needed) would also be faster.

Mostly out of interest this question.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1425
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Copy structure or create new file dbf

Postby Silvio.Falconi » Thu Jun 09, 2022 11:42 am

Marc Venken wrote:Silvio,

You have it running... That's mostly the goal ....

But did you try the scope ? I would think it should be faster and less code. A new second filtering (maybe not needed) would also be faster.

Mostly out of interest this question.



I don't really trust the ...scope
then Nages told me to use the filter
also because I have to filter many elements
- the months
- the days of the week
- the numbers of the month
- the monthly indices (which I have not entered for now)

all these data are stored in arrays with .t. or with .f.

so I tried as Nages suggested

Code: Select all  Expand view
oLotto:Exec( <||
     SET FILTER TO   (  dFirst <= FIELD->DATA .AND.             ;
                        dLast >=  FIELD->DATA .AND.             ;
                        aCountMesi[ MONTH( FIELD->DATA ) ]  .AND. ;
                        aCountGiorni[ DOW( FIELD->DATA ) ] .AND. ;
                        aCountDate[ DAY( FIELD->DATA ) ]   )
      return nil
      > )


it seems to be working fine for now
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: 7034
Joined: Thu Oct 18, 2012 7:17 pm

Re: Copy structure or create new file dbf

Postby James Bott » Thu Jun 09, 2022 7:19 pm

Marc,

James, This is what you mean ? or a other way ?
Best to have the index set to the index of the field ?


Yes, but I would do this:

Save the current recno()

If they exist, save the database's state (current index and the top and bottom scopes and the current recordNo()).

set the index and scopes you need to use.

Do a gotop().

Do whatever...

Then at the end of the routine, restore the database's state (the old index and recno() and the old scopes (if they exist).

Another option is to open a new copy of the needed database within your routine. Then you don't have to worry about saving and restoring the database's state. But you do need to close the local copy of the database at the end of your routine.
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 53 guests