TDatabase: Using own :append() adds blank records

Post Reply
hua
Posts: 861
Joined: Fri Oct 28, 2005 2:27 am

TDatabase: Using own :append() adds blank records

Post by hua »

Using Harbour+FWH1912, the following sample will at 1st run generates RTE and subsequent runs will see empty records added. Why?

Code: Select all

#include "fivewin.ch"
function main()
  local oDb
  field dref

  if !file("hua.dbf")
     dbCreate("hua.dbf", {{"dref", "c", 12, 0}})
  endif
  oDb := TData():open(, "hua.dbf",,.t.)
  select (oDb:cAlias)
  index on dref to hua temporary

  oDb:append()

  oDb:dref := time()
  oDb:save()
  xbrowse(oDb)
return nil

class TData from TDatabase
  method open(cAlias, cDbf, cDriver, lShared) inline ::super:open(cAlias, cDbf, cDriver, lShared)
  method append() inline (::cAlias)->(myAppend())
endclass

function MyAppend()
  append blank
return nil
 
FWH 11.08/FWH 19.03
xHarbour 1.2.1 (Rev 6406) + BCC
Harbour 3.1 (Rev 17062) + BCC
Harbour 3.2.0dev (r1904111533) + BCC
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: TDatabase: Using own :append() adds blank records

Post by nageswaragunupudi »

Please try this modified program

Code: Select all

#include "fivewin.ch"

function main()
  local oDb
  field dref

  if !file("hua.dbf")
     dbCreate("hua.dbf", {{"DREF", "C", 12, 0}})
  endif
  oDb := TData():open(, "hua.dbf",,.t.)
//  select (oDb:cAlias) // let us not directly handle the alias/area
//  index on dref to hua temporary
  oDb:CreateIndex( nil, "DREF", "DREF", nil, nil, .T. ) // .T. for temporary index

  //
  oDb:Blank()     //oDb:append()
  oDb:dref := time()
  oDb:save()
  XBROWSER oDb

  oDb:Append( { "dref" }, { time() } )
  XBROWSER oDb

  oDb:Blank()
  oDb:dref := time()
  oDb:save()
  XBROWSER oDb

return nil

class TData from TDatabase
  method open(cAlias, cDbf, cDriver, lShared) inline ::super:open(cAlias, cDbf, cDriver, lShared)
//  method append() inline (::cAlias)->(myAppend()) // do not override append()
endclass

/*
function MyAppend()
  append blank
return nil
*/
 
Regards

G. N. Rao.
Hyderabad, India
Post Reply