home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / usedbf.prg < prev    next >
Text File  |  1993-10-14  |  5KB  |  162 lines

  1. /*
  2.  * File......: USEDBF.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  */
  19.  
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_USEDBF()
  24.  *  $CATEGORY$
  25.  *      Network
  26.  *  $ONELINER$
  27.  *      Open a table
  28.  *  $SYNTAX$
  29.  *      GT_UseDbf( cDbf , aIndex , cAlias , lPack , lReindex , ;
  30.  *                 lExclusive , nTimeOut , lFatal )
  31.  *  $ARGUMENTS$
  32.  *      cDbf       - Database to open
  33.  *      aIndex     - Index to open
  34.  *      cAlias     - Alias to use
  35.  *      lPack      - If .T. we pack the database
  36.  *      lReindex   - If .T. we reindex the database
  37.  *      lExclusive - If .T. open exclusive
  38.  *      nTimeOut   - Number of seconds to retry for
  39.  *      lFatal     - If .T. generate a fatal error on failure
  40.  *  $RETURNS$
  41.  *      .T. if successful
  42.  *      .F. otherwise
  43.  *  $DESCRIPTION$
  44.  *      Opens the table in the required mode.  If it fails, has nTimeOut
  45.  *      retries.
  46.  *      When the table is opened, the indexes are opened, and the table
  47.  *      will hten be packed or reindexed is required.
  48.  *  $EXAMPLES$
  49.  *
  50.  *  $SEEALSO$
  51.  *
  52.  *  $INCLUDE$
  53.  *      GT_LIB.CH
  54.  *  $END$
  55.  */
  56.  
  57. *
  58. #include "GT_LIB.ch"
  59.  
  60. FUNCTION GT_UseDbf( cDbf , aIndex , cAlias , lPack , lReindex , ;
  61.                     lExclusive , nTimeOut , lFatal )
  62.  
  63. /****************************************************************************
  64.  Purpose - Open the given database
  65.  Returns - .T. if successful
  66.  Author  - Martin Colloby
  67.  Created - 23/8/91
  68. ******************************************************************************
  69.  Parameters - cDbf         - Database to open
  70.               aIndex       - Index to open
  71.               cAlias       - Alias to use
  72.               lPack        - If .T. we pack the database
  73.               lReindex     - If .T. we reindex the database
  74.               lExclusive   - If .T. open exclusive
  75.               nTimeOut     - Number of seconds to retry for
  76.               lFatal       - If .T. generate a fatal error on failure
  77.  Locals     - lReturn      - Value to return
  78.  Externals  - cDefaultPath - Default path of .EXE file
  79. ****************************************************************************/
  80.  
  81. LOCAL aActIndex  := { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }
  82. LOCAL cIndex     := ""
  83. LOCAL cTempIndex := ""
  84. LOCAL lReturn    := .F.
  85. LOCAL lForever   := .F.
  86. LOCAL nCount     := 0
  87.  
  88. DEFAULT nTimeOut   TO 0
  89. DEFAULT lFatal     TO .F.
  90. DEFAULT lExclusive TO .F.
  91. DEFAULT lPack      TO .F.
  92. DEFAULT lReindex   TO .F.
  93.  
  94. lForever   := (nTimeOut == 0)
  95. cDbf       := cDefaultPath + "\tables\" + cDbf
  96. cIndex     := ""
  97.  
  98. IF !FILE( cDbf + ".dbf" )
  99.     GT_Warning( { "Cannot find tables " + cDbf } )
  100.     RETURN( .F. )
  101. ENDIF
  102.  
  103. IF LEN( aIndex ) > 0
  104.     FOR nCount := 1 TO LEN( aIndex )
  105.         cTempIndex := cDefaultPath + "\tables\" + aIndex[nCount]
  106.         IF !FILE( cTempIndex + INDEXEXT() )
  107.             GT_Warning( { "Cannot find index  " + cTempIndex } )
  108.             RETURN( .F. )
  109.         ENDIF
  110.  
  111.         aActIndex[nCount] := cTempIndex
  112.  
  113.     NEXT nCount
  114. ENDIF
  115.  
  116. DO WHILE ( lForever .OR. nTimeOut > 0 )
  117.     IF lExclusive
  118.         USE (cDbf) ALIAS (cAlias) NEW EXCLUSIVE
  119.     ELSE
  120.         USE (cDbf) ALIAS (cAlias) NEW SHARED
  121.     ENDIF
  122.  
  123.     IF .NOT. NETERR()
  124.  
  125.         SET INDEX TO ( aActIndex[1] ),;
  126.                      ( aActIndex[2] ),;
  127.                      ( aActIndex[3] ),;
  128.                      ( aActIndex[4] ),;
  129.                      ( aActIndex[5] ),;
  130.                      ( aActIndex[6] ),;
  131.                      ( aActIndex[7] ),;
  132.                      ( aActIndex[8] ),;
  133.                      ( aActIndex[9] ),;
  134.                      ( aActIndex[10] ),;
  135.                      ( aActIndex[11] ),;
  136.                      ( aActIndex[12] ),;
  137.                      ( aActIndex[13] ),;
  138.                      ( aActIndex[14] ),;
  139.                      ( aActIndex[15] )
  140.  
  141.         IF lPack .AND. lExclusive
  142.             SET ORDER TO 0
  143.             PACK
  144.             SET ORDER TO 1
  145.         ENDIF
  146.  
  147.         IF ( lReindex .AND. .NOT. lPack ) .AND. lExclusive
  148.             REINDEX
  149.         ENDIF
  150.  
  151.         RETURN( .T. )
  152.     ENDIF
  153.  
  154.     INKEY( 1 )
  155.     nTimeOut --
  156. ENDDO
  157.  
  158. GT_Warning( "Could not open table " + cDbf )
  159.  
  160. RETURN( .F. )
  161. *
  162.