1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

DBF Plugin

Discussion in 'Plugins' started by Joe Caverly, Jan 5, 2011.

  1. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    Hi,
    Over at http://www.jpsoft.com/forums/showthread.php?t=1805 I wrote a batch file to read a dBASE database file.

    I have modified the batch file to use the DBF Plugin, available from http://sites.google.com/site/jlcprogrammingstuff/home/tcc/dbf-plugin

    The revised batch file is as follows;

    Code:
    ::--------------------------------------------------------------------+
    ::  Open a dBASE database, display the structure,                     |
    ::  and a desired record, using the DBF Plugin                        |
    ::  Joe Caverly                                                       |
    ::  January 2011                                                      |
    ::                                                                    |
    :: USAGE: dbstruct dbfName RecordNumber                               |
    ::                                                                    |
    ::--------------------------------------------------------------------+
    @setlocal
    @echo off
    ::--------------------------------------------------------------------+
    :: Load the DBF Plugin                                                |
    ::--------------------------------------------------------------------+
    if not plugin dbf plugin /l dbf
    ::--------------------------------------------------------------------+
    :: Designate a file to use for this batch                             |
    ::--------------------------------------------------------------------+
    if not exist %1 goto nofile
    set dbfName=%1
    ::--------------------------------------------------------------------+
    :: Display Structure                                                  |
    ::--------------------------------------------------------------------+
    echo Structure for database: %dbfName
    echo Number of data records: %@reccount[%dbfName]
    echo Date of last update   : %@lupdate[%dbfName]
    echo Field  Field Name  Type        Width   Dec
    do FieldNumber=1 to %@FieldCount[%dbfName]
      screen %_row 0 %@format[5,%FieldNumber]
      ::--------------------------------------------------------------------+
      :: Field Name                                                         |
      ::--------------------------------------------------------------------+
      screen %_row 7 %@FieldName[%dbfName,%FieldNumber]
      ::--------------------------------------------------------------------+
      :: Field Type (C, D, L, M, N)                                         |
      ::--------------------------------------------------------------------+
      set FieldType=%@FieldType[%dbfName,%FieldNumber]
      switch %FieldType
        case C
          set TheType=Character
        case D
          set TheType=Date
        case L
          set TheType=Logical
        case M
          set TheType=Memo
        case N
          set TheType=Numeric
      endswitch
      screen %_row 19 %TheType
      ::--------------------------------------------------------------------+
      :: Field Width                                                        |
      ::--------------------------------------------------------------------+
      set FieldWidth=%@FieldWidth[%dbfName,%FieldNumber]
      screen %_row 33 %@format[3,%FieldWidth]
      ::--------------------------------------------------------------------+
      :: Number of decimal places (Numeric fields only)                     |
      ::--------------------------------------------------------------------+
      iff %@FieldType[%dbfName,%FieldNumber] eq N then
        set DecimalPlaces=%@DECIMAL[%dbfName,%FieldNumber]
        iff %DecimalPlaces gt 0 then
          screen %_row 40 %@format[2,%DecimalPlaces]
        endiff
      endiff
      echo.
    enddo
    set TotalWidth=%@recsize[%dbfName]
    screen %_row 0 ** Total **
    screen %_row 31 %@format[5,%TotalWidth]
    echo.
    ::--------------------------------------------------------------------+
    :: Record Number to get                                               |
    ::--------------------------------------------------------------------+
    set ValidInput=N
    if %2 le %@RecCount[%dbfName] set ValidInput=Y
    if %2 gt 0 set ValidInput=Y
    if %ValidInput eq N set Record2Get=1
    if %ValidInput eq Y set Record2Get=%2
    if %Record2Get gt %@RecCount[%dbfName] goto ROOR
    echo.
    echo Record Number: %Record2Get
    ::--------------------------------------------------------------------+
    :: Display the record                                                 |
    ::--------------------------------------------------------------------+
    echo %@Record[%dbfName,%Record2Get]
    goto eoj
    ::--------------------------------------------------------------------+
    :: Problem opening the database                                       |
    ::--------------------------------------------------------------------+
    :abort
    echo Database is in use, or another error occured opening the database.
    goto eoj
    ::--------------------------------------------------------------------+
    :: File does not exist                                                |
    ::--------------------------------------------------------------------+
    :nofile
    echo File does not exist.
    echo USAGE: dbstruct x:\data\mydb.dbf
    goto eoj
    ::--------------------------------------------------------------------+
    :: Record Out Of Range                                                |
    ::--------------------------------------------------------------------+
    :ROOR
    echo Record Out Of Range (Max. %@RecCount[%dbfName])
    ::--------------------------------------------------------------------+
    :: End Of Job                                                         |
    ::--------------------------------------------------------------------+
    :eoj
    if plugin dbf plugin /u dbf
    endlocal
    

    Joe

     
  2. K_Meinhard

    Joined:
    May 20, 2008
    Messages:
    310
    Likes Received:
    0
    Hey Joe,


    Very nice. I've always thought that TCC should be able to work with a database, preferably (by me) dBase.

    I still think adding basic dBase handling would be a great addition to TCC. Indexed database files would probably make handling long lists of data (e.g. directory lists) much faster. And it would be a great feature for marketing the next version :-)

    herzliche Grüße,

    Klaus Meinhard
     
  3. Joe Caverly

    Joined:
    Aug 28, 2009
    Messages:
    680
    Likes Received:
    8
    Hi,
    Here is a batch file to display the field data from a record in a dBase database, using the DBF Plugin. In this case, I have hard-coded record 1.

    Code:
    ::--------------------------------------------------------------------+
    ::  Open a dBASE database, display the field data                     |
    ::  of record number 1                                                |
    ::  Joe Caverly                                                       |
    ::  January 2011                                                      |
    ::                                                                    |
    :: USAGE: flist dbfName                                               |
    ::--------------------------------------------------------------------+
    @setlocal
    @echo off
    ::--------------------------------------------------------------------+
    :: Load the DBF Plugin                                                |
    ::--------------------------------------------------------------------+
    if not plugin dbf plugin /l dbf
    ::--------------------------------------------------------------------+
    :: Designate a file to use for this batch                             |
    ::--------------------------------------------------------------------+
    if not exist %1 goto nofile
    set dbfName=%1
    set therecord=%@record[%dbfName,1]
    do FieldNumber=1 to %@FieldCount[%dbfName]
      set FieldOffset=%@fieldoffset[%dbfname,%FieldNumber]
      set FieldWidth=%@fieldwidth[%dbfname,%FieldNumber]
      echo %@instr[%FieldOffset,%FieldWidth,%therecord]
    enddo
    goto eoj
    ::--------------------------------------------------------------------+
    :: Problem opening the database                                       |
    ::--------------------------------------------------------------------+
    :abort
    echo Database is in use, or another error occured opening the database.
    goto eoj
    ::--------------------------------------------------------------------+
    :: File does not exist                                                |
    ::--------------------------------------------------------------------+
    :nofile
    echo File does not exist.
    echo USAGE: flist x:\data\mydb.dbf
    goto eoj
    ::--------------------------------------------------------------------+
    :: End Of Job                                                         |
    ::--------------------------------------------------------------------+
    :eoj
    if plugin dbf plugin /u dbf
    endlocal
    
    Joe
     

Share This Page