Array2Dbf() e Dbf2Array()

Fórum sobre a linguagem CA-Clipper.

Moderador: Moderadores

Dudu_XBase
Membro Master
Membro Master
Mensagens: 1071
Registrado em: 25 Ago 2003 16:55

Array2Dbf() e Dbf2Array()

Mensagem por Dudu_XBase »

:shock: Olhem....sobre o post do dbf para matriz...
// Array2dbf()
// Dbf2Array()

Código: Selecionar todos

FUNCTION Array2Dbf(aArray,lDissimilarRecords)
/*
   Replace record contents with the contents of aArray
   by searching for the fieldname contained in aArray element 2
   and, if found, placing aArray element 1 contents in the field

   Interacts with Dbf2Array().

   Example:

   aCustomer:=CUSTOMER->(Dbf2Array())
   IF INVOICE->(NetAppend())
      INVOICE->(Array2Dbf(aCustomer))
      INVOICE->(DBRUNLOCK())
      INVOICE->(DBCOMMIT())
   ENDIF

   Richard@ClipperSolutions.com
*/
LOCAL i,nArrayLen:=LEN(aArray),nFCount:=FCOUNT(),cFieldName,nPos,nReplaced:=0

DEFAULT lDissimilarRecords:=FALSE
lDissimilarRecords:=IF(nArrayLen#nFCount,TRUE,lDissimilarRecords)

IF nFCount==0 // no table in use in this area
   RETURN(nReplaced)
ENDIF

FOR i:=1 TO nArrayLen
   IF lDissimilarRecords
      cFieldName:=aArray[i,2] // get the fieldname
      IF (nPos:=FIELDPOS(cFieldName))>0 // if the fieldname is found in this table
         IF VALTYPE(aArray[i,1])==VALTYPE(&cFieldName) // and can accept value type
            FIELDPUT(nPos,aArray[i,1])  // put the value in the field
            ++nReplaced                 // and add to number_replaced counter
         ENDIF
      ENDIF
   ELSE
      FIELDPUT(i,aArray[i])
      ++nReplaced
   ENDIF
NEXT
RETURN(nReplaced)

/* ------------------------------------------------------------------------ */
FUNCTION Dbf2Array(lDissimilarRecords)
/*
   Store the current database record to a 2 dimensional array
   with array 1 element = field contents and array 2 element = field name

   Interacts with Array2Dbf().

   Example:

   aCustomer:=CUSTOMER->(Dbf2Array())
   IF INVOICE->(NetAppend())
      INVOICE->(Array2Dbf(aCustomer))
      INVOICE->(DBRUNLOCK())
      INVOICE->(DBCOMMIT())
   ENDIF

   Richard@ClipperSolutions.com
*/
LOCAL aArray:={},nFCount:=FCOUNT(),i

DEFAULT lDissimilarRecords:=FALSE

IF nFCount==0 // no table in use in this area
   RETURN(aArray)
ENDIF

FOR i :=1 TO nFCount
   IF lDissimilarRecords
      AADD(aArray,{FIELDGET(i),FIELDNAME(i)})
   ELSE
      AADD(aArray,FIELDGET(i))
   ENDIF
NEXT
RETURN(aArray)

/* ------------------------------------------------------------------------ */


________________________________________________________________________________________________________
(Aow Saudade) Clipper 5.2e, Blinker 7, RDD SIXNSX, DBFCDX /Xharbour 1.0, Rdd Mediator (Mysql) Free , RDD Sqlrdd (Sql Server) Comercial
(Hoje) C# Python Sql Server e Oracle




Responder