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.
About tdatabase
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: About tdatabase
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
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: Select all | Expand
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
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
Re: About tdatabase
You can also use this code:
Code: Select all | Expand
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
G. N. Rao.
Hyderabad, India
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: About tdatabase
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
James
Code: Select all | Expand
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
- nageswaragunupudi
- Posts: 10721
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 8 times
- Contact:
- James Bott
- Posts: 4840
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: About tdatabase
Rao,
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
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