Prevent errors when closing databases

This forum is for posting of useful information
Post Reply
Message
Author
User avatar
rdonnay
Site Admin
Posts: 4722
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Prevent errors when closing databases

#1 Post by rdonnay »

Xbase++ can occasionally cause an IDSC if databases are closed incorrectly. This is caused by relations being set. If a parent database has a relation set to a child database and the child database is closed before clearing the relation this can cause an IDSC.

If you use DC_dbCloseArea() as a replacement for dbCloseArea() and DC_dbCloseAll() as a replacement for dbCloseAll() you should prevent these errors.

Code: Select all

FUNCTION DC_DbCloseAll()

LOCAL xValue, bError := ErrorBlock({||TrapError()})
LOCAL aRel[0], i, j

BEGIN SEQUENCE

WorkSpaceEval( {|a|a:=DbRList(),IIF(!Empty(a),AAdd(aRel,{Select(),a}),nil)})

FOR i := 1 TO Len(aRel)
  FOR j := 1 TO Len(aRel[i,2])
    (aRel[i,1])->(dbClearRelation())
  NEXT
NEXT

xValue := dbCloseAll()

END SEQUENCE
ErrorBlock(bError)

RETURN xValue

* ----------------

FUNCTION DC_DbCloseArea()

LOCAL xValue, bError := ErrorBlock({||TrapError()})
LOCAL aRel[0], cAlias, i, j

BEGIN SEQUENCE

cAlias := '_' + Alias()

WorkSpaceEval( {|a|a:=DbRList(),IIF(!Empty(a),AAdd(aRel,{Select(),a}),nil)})

FOR i := 1 TO Len(aRel)
  FOR j := 1 TO Len(aRel[i,2])
    IF cAlias $ aRel[i,2,j]
      (aRel[i,1])->(dbClearRelation())
    ENDIF
  NEXT
NEXT

xValue := dbCloseArea()

END SEQUENCE
ErrorBlock(bError)

RETURN xValue

* ----------------

STATIC FUNCTION TrapError
BREAK
RETURN nil
The eXpress train is coming - and it has more cars.

Post Reply