FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour About tdatabase
Posts: 332
Joined: Thu Nov 17, 2005 09:11 PM
About tdatabase
Posted: Sat Jun 01, 2013 12:29 PM

Hi,

I work with native tdatabase fivewin, i want to put all value fields from on record in another like this:

oArqCli:GoTop()
Do While ! oArqCli:Eof()
oArqCli:Load()
oCliCli:Blank()
oCliCli:(All fields) := oArqCli:(All fields) <------------------- how?
oCliCli:Append()
oCliCli:Save()
oCliCli:Commit()
oArqCli:Skip(+1)
loop
Enddo

Thanks.

Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: About tdatabase
Posted: Sat Jun 01, 2013 06:43 PM
Wanderson,

Note that all the field data is stored in a buffer array in database objects. Also, of course, both files must have exactly the same structure. Below is an example of how to copy all the field data.

It depends on the situation, but you may want to only do one commit after the ENDDO instead of one after each record save. This would be much faster, but maybe not as safe in a multi-user environment. However, if you are only copying a few records this would only take a few seconds so there isn't much risk.

James

Code (fw): Select all Collapse
oArqCli:GoTop()
Do While ! oArqCli:Eof()
   oArqCli:Load()
   oCliCli:Blank()
   //oCliCli:(All fields) := oArqCli:(All fields) <------------------- how?

   copyAll(oArqCli, oCliCli)

   oCliCli:Append()
   oCliCli:Save()
   oCliCli:Commit()
   oArqCli:Skip(+1)
   loop
Enddo


function copyAll( oDB1, oDB2 )
   Local i:=1
   for i 1 to len(oDB1:aBuffer)
      oDB2:aBuffer[i]:= oDB1:aBuffer[i]
   next
return nil
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: About tdatabase
Posted: Sun Jun 02, 2013 09:01 AM
You can also use this code:
Code (fw): Select all Collapse
   
   oArqCli:lBuffer := .t.  // This is default
   oArqCli:GoTop()
   do while ! oArqCli:Eof()
      oCliCli:Append()
      ACOPY( oArqCli:aBuffer, oCliCli:aBuffer )
      oCliCli:Save()
      oArqCli:Skip()
   enddo
   oCliCli:Close()
Regards



G. N. Rao.

Hyderabad, India
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: About tdatabase
Posted: Mon Jun 03, 2013 01:11 PM
Yes, acopy() would be faster. If you set oArqCli:lBuffer I also suggest saving and restoring its state so as to prevent any possible problems elsewhere.

James

Code (fw): Select all Collapse
   Local lBuffer
   ...
   lBuffer:= oArqCli:lBuffer
   oArqCli:lBuffer := .t.  // this is default
   oArqCli:GoTop()
   do while ! oArqCli:Eof()
      oCliCli:Append()
      ACOPY( oArqCli:aBuffer, oCliCli:aBuffer )
      oCliCli:Save()
      oArqCli:Skip()
   enddo
   oCliCli:Close()
   oArqCli:lBuffer:= lBuffer
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: About tdatabase
Posted: Mon Jun 03, 2013 01:37 PM

For TDatabase, lBuffer is .t. by default.

Regards



G. N. Rao.

Hyderabad, India
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: About tdatabase
Posted: Mon Jun 03, 2013 01:57 PM
Rao,

For TDatabase, lBuffer is .t. by default.


Yes, I understand that. But if you change something like that it is wise to save and restore it's state. It is wise to do as you suggested, set it to true at the start of the routine because you can't depend on it being true already.

As I expect you already know, encapsulation is one of the key principles of OOP. So whenever, you change the state of something you should also restore it. I have found this to be a very useful principle to follow. I can't imagine how many problems I have prevented by using this simple technique.

Regards,
James
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion