Page 1 of 1

Problem to save with tdatabase - Resolved!

Posted: Fri May 24, 2019 5:17 pm
by Silvio.Falconi
I have an array aDataBase

and save it in this mode

Code: Select all

oTariffeBase:= TDatabase():Open( , cDir+"Tariffe", "DBFCDX", .T. )
       oTariffeBase:gotop()


    For n=1 to Len(aDataBase)
        ctipo:="E"   //Elemento
        ntipotar:="N" 

               cIdelemento := alltrim(aDataBase[n][2])
               celemento   := alltrim(aDataBase[n][3])
               csettore    := alltrim(aDataBase[n][4])
               ngiorni     := aDataBase[n][5]
               ncosto      := aDataBase[n][6]
               lbloccato   := aDataBase[n][7]
               cidlistino  := alltrim(aDataBase[n][8])
               nTotale     := aDataBase[n][6]


               oTariffeBase:append()

                     IF oTariffeBase:RLock()
                        oTariffeBase:tipo       :=  ctipo
                        oTariffeBase:idElemento :=  cIdelemento
                        oTariffeBase:elemento   :=  celemento
                        oTariffeBase:settore    :=  csettore
                        oTariffeBase:giorni     :=  ngiorni
                        oTariffeBase:costo      :=  ncosto
                        oTariffeBase:tipotar    :=  ntipotar
                        oTariffeBase:totale     :=  nTotale
                        oTariffeBase:idlistino  :=  cidlistino
                        oTariffeBase:bloccato   :=  lbloccato
                        oTariffeBase:save(.t.)
                       ENDIF



              next
But it create only record blank why ?

Re: Problem to save with tdatabase

Posted: Sat May 25, 2019 8:09 pm
by ukoenig
Silvio,

this test shows the logic
NO rlock, unlock and append for every record needed

Code: Select all

STATIC FUNCTION SAVE_ARRAY( oCust )
LOCAL  aData[3][3] 

aData[1][1] := "A 1"
aData[1][2] := "B 1"
aData[1][3] := CTOD("01/01/2019")

aData[2][1] := "A 2"
aData[2][2] := "B 2"
aData[2][3] := CTOD("02/01/2019")

aData[3][1] := "A 3"
aData[3][2] := "B 3"
aData[3][3] := CTOD("03/01/2019")

oCust:Append( "Last, First, HireDate", aData ) // 3 records apended

RETURN( NIL )
 
Image

regards
Uwe :D

Re: Problem to save with tdatabase

Posted: Sat May 25, 2019 8:40 pm
by Silvio.Falconi
thanks run ok

Re: Problem to save with tdatabase - Resolved!

Posted: Sun May 26, 2019 11:39 am
by nageswaragunupudi
This example shows the 4 ways of appending data

Code: Select all

#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oDbf

   DBCREATE( "TESTAPND", { { "CODE", "C", 3, 0 }, { "NAME", "C", 15, 0 } }, "DBFCDX" )

   oDbf  := TDatabase():Open( nil, "TESTAPND", "DBFCDX", .T. )

//METHOD-1:
   oDbf:Append( "CODE,NAME", { "SUN", "Sunday" } )
   XBROWSER oDbf

//METHOD-2:
   oDbf:Append( "CODE,NAME", { { "MON", "Monday"  }, ;
                               { "TUE", "Tuesday" }  } )
   XBROWSER oDbf

//METHOD-3:
   oDbf:Append()  // appends blank record
   oDbf:Load()    // this line not required in FWH1905
   oDbf:Code   := "WED"
   oDbf:Name   := "Wednesday"
   oDbf:Save()    // do NOT use Locks/Unlocks

   XBROWSER oDbf

//METHOD-4:
   oDbf:Blank()  // Most commonly used
   oDbf:Code   := "THU"
   oDbf:Name   := "Thursday"
   oDbf:Save()

   XBROWSER oDbf

   oDbf:Close()

return nil
 

Re: Problem to save with tdatabase - Resolved!

Posted: Sun May 26, 2019 12:08 pm
by Silvio.Falconi
Thanks Rao, probably tdata class works differently as I wrote above

Re: Problem to save with tdatabase - Resolved!

Posted: Sun May 26, 2019 12:59 pm
by nageswaragunupudi
Silvio.Falconi wrote:Thanks Rao, probably tdata class works differently as I wrote above
Method-4 works for TData also. That is the most used method by TData users, not the method you wrote.