Problem to save with tdatabase - Resolved!

Post Reply
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Problem to save with tdatabase - Resolved!

Post 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 ?
Last edited by Silvio.Falconi on Sat May 25, 2019 9:01 pm, edited 1 time in total.
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Re: Problem to save with tdatabase

Post 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
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem to save with tdatabase

Post by Silvio.Falconi »

thanks run ok
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Problem to save with tdatabase - Resolved!

Post 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
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: Problem to save with tdatabase - Resolved!

Post by Silvio.Falconi »

Thanks Rao, probably tdata class works differently as I wrote above
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: Problem to save with tdatabase - Resolved!

Post 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.
Regards

G. N. Rao.
Hyderabad, India
Post Reply