FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Copy structure or create new file dbf
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Copy structure or create new file dbf
Posted: 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 (fw): Select all Collapse
 

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 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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Copy structure or create new file dbf
Posted: Tue Jun 07, 2022 01:10 PM
Code (fw): Select all Collapse
USE SOURCEDBF ....
COPY TO NEWDBF FOR <filtercond>
Regards



G. N. Rao.

Hyderabad, India
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Copy structure or create new file dbf
Posted: Wed Jun 08, 2022 07: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
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Copy structure or create new file dbf
Posted: Wed Jun 08, 2022 08: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 (fw): Select all Collapse
//   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.08 with Harbour
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: Copy structure or create new file dbf
Posted: Thu Jun 09, 2022 04:01 AM
hi Silvio,

are you sure that you want Dates EXECPT "Filter" :-)

Code (fw): Select all Collapse
   dFirst <= FIELD->DATA .AND. dLast >= FIELD->DATA

that only work for
Code (fw): Select all Collapse
   dFirst = FIELD->DATA = dLast


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

---
Code (fw): Select all Collapse
   USE XXX
   COPY STRUCTURE [FIELDS <cFieldname,...>] TO <cFilename>

to create a EMPTY() new DBF
greeting,

Jimmy
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Copy structure or create new file dbf
Posted: Thu Jun 09, 2022 07: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+&quot;lotto&quot;, &quot;DBFCDX&quot;, .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+&quot;Virtuale&quot;, &quot;DBFCDX&quot;, .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 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
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Copy structure or create new file dbf
Posted: 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.08 with Harbour
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Copy structure or create new file dbf
Posted: 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 (fw): Select all Collapse
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 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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Copy structure or create new file dbf
Posted: Thu Jun 09, 2022 07: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

Continue the discussion