Page 1 of 1

Copying of records of open databases in style with pseudonym

Posted: Fri Aug 24, 2012 11:49 am
by Eugene Lutsenko
How to copy all records of one database in another if both of them are open (COPY FILE not to use) in style with pseudonyms? As in this style the functional analog of the program will look:

Code: Select all

        SELECT Abs
        DBGOTOP()
        DO WHILE .NOT. EOF()
           Ar := {}
           FOR j=1 TO FCOUNT()
               AADD(Ar, FIELDGET(j))
           NEXT
           SELECT InfVisio
           APPEND BLANK
           FOR j=1 TO LEN(Ar)
               FIELDPUT(j,Ar[j])
           NEXT
           SELECT Abs
           DBSKIP(1)
        ENDDO
Something such as it?

Code: Select all

        Abs->(DBGOTOP())
        DO WHILE Abs->(.NOT. EOF())
           FOR j=1 TO Abs->(FCOUNT())
               InfVisio->(FIELDPUT(j,Abs->FIELDGET(j)))
           NEXT
           Abs->(DBSKIP(1))
        ENDDO
The given option at compilation gives syntactic errors

Re: Copying of records of open databases in style with pseud

Posted: Fri Aug 24, 2012 7:27 pm
by Cliff Wiernik
Use this inside of a do while loop

Code: Select all

*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
*+
*+    Function LB_CopyRecord(cSource,cTarget)      
*+
*+      // Copy record to another DBF using Scatter/Gather 
*+
*+±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±
*+ 
FUNCTION LB_CopyRecord(cSource,cTarget)      
  LOCAL i
  LOCAL aRpl := {}
  
  SELECT (cSource)      
      
  FOR i := 1 TO (cSource)->(fcount())
     aadd(aRpl,(cSource)->(fieldget(i)))                                        // load array (scatter) with field data
  NEXT

  SELECT (cTarget)
  (cTarget)->(dbappend())
  aeval(aRpl,{|j,i| (cTarget)->(fieldput(i,j)) })                               // put data in new record (gather)
  
  RETURN .T.      

Re: Copying of records of open databases in style with pseud

Posted: Fri Aug 24, 2012 10:27 pm
by Wolfgang Ciriack
Hello,
or take a look at the functions

DC_DbRecord, DC_Dbscatter, DC_Dbgather

Re: Copying of records of open databases in style with pseud

Posted: Sat Aug 25, 2012 12:25 am
by skiman
Hi,

You could use the dc_gather/dc_scatter but this wouldn't speed it up. I'm wondering if you can use ABS as aliasname, because ABS() is an existing function! This is probably the cause of your syntax errors at compile time.

Code: Select all

Absx->(DBGOTOP())
nFields := absx->(fcount())    // fcount() is a slow function
DO WHILE !Absx->(EOF())
      FOR j=1 TO nFields   // this way the fcount isn't executed each time.
          infvisio->(dbappend())     // you need to append a record
          InfVisio->(FIELDPUT(j,Absx->FIELDGET(j)))
      NEXT
      Absx->(DBSKIP(1))
ENDDO
Another way would be to make use of dbeval() but I don't think this would make difference in speed.

Re: Copying of records of open databases in style with pseud

Posted: Sat Aug 25, 2012 5:08 am
by Eugene Lutsenko
As to Abs - very much can be, I will try to understand... Thanks!

Whether and there is something similar Destroy () after DCBROWSE? And I have that one mode with DCBROWSECOL use after one modes or right after start of system works normally, and after others doesn't display base.