Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Writing batch file for .dbf  (Read 32827 times)

0 Members and 1 Guest are viewing this topic.

fireballs



    Apprentice

  • Code:Terminal
  • Thanked: 3
    Re: Writing batch file for .dbf
    « Reply #15 on: August 27, 2008, 04:07:41 PM »
    For every entry in sample.txt this will take the line of text and put it into variable A. this is then set as APPEARID and used in your code. I hope it works but it's far too complex for me to test on my system.

    FB
    Next time google it.

    T-Wave

      Topic Starter


      Rookie

      Re: Writing batch file for .dbf
      « Reply #16 on: August 27, 2008, 04:16:01 PM »
      OH MY GOD, it actually works. Thanks a million, Fireballs. WOW!!!     :o

      fireballs



        Apprentice

      • Code:Terminal
      • Thanked: 3
        Re: Writing batch file for .dbf
        « Reply #17 on: August 27, 2008, 04:17:22 PM »
        :) not a problem come back if you need anything else...

        FB
        Next time google it.

        T-Wave

          Topic Starter


          Rookie

          Re: Writing batch file for .dbf
          « Reply #18 on: August 27, 2008, 04:18:36 PM »
          I'll make sure to do, thanks  :)

          T-Wave

            Topic Starter


            Rookie

            Re: Writing batch file for .dbf
            « Reply #19 on: August 27, 2008, 05:15:38 PM »
            I'm back sooner than I expected.

            I think I rejoiced too quickly. What that batch file does now is simply set the mininmum height of every player in the entire database to 78.

            I guess when it gets to the line below, it simply filters only players with height less than 78.

            "cdbflite.exe" appearance.dbf /case /filter:APPEARID= /filter:HEIGHT{78 /field:HEIGHT=78 /update

            At first I thought it was because of the segment /filter:APPEARID= not being equated to anything.

            I tried changing it to /filter:APPEARID=%%A but I got the error "Invalid filter..." and "Unknown function [4017]".  By the way, 4017 is the first player ID number stored in Wing.txt (See screenshot below)

            I then tried changing it to /filter:APPEARID=A and though I didn't get any error message this time, it made none of the desired changes to the player heights.

            I guess it's back to square one, how to equate each of the numbers in wing.txt to the APPEARID.


            fireballs



              Apprentice

            • Code:Terminal
            • Thanked: 3
              Re: Writing batch file for .dbf
              « Reply #20 on: August 27, 2008, 05:28:08 PM »
              hmm  i may have missed out some % signs along the way how about if you say:

              @echo off
               for /f "tokens=* delims=" %%A in ('type sample.txt') do (
              set APPEARID=%%A

              ECHO.
              ECHO PRESS ANY KEY TO CONTINUE
              pause >nul
              ECHO.
              ECHO FIXING GENERATED ROOKIE HEIGHTS
              ECHO.
              ECHO.

              ECHO Shooting Guards and Small Forwards
              "cdbflite.exe" appearance.dbf /case /filter:%APPEARID%= /filter:HEIGHT{78 /field:HEIGHT=78 /update

              ECHO.
              :end
              ECHO Players.dbf updated
              ECHO PATCH INSTALLED
              ECHO.
              ECHO.
              ECHO Press any key to close this window
              pause >nul
              EXIT
              )

              I can't test the arguments to cdbflite.exe but my code should now word? Get back to us.

              FB
              Next time google it.

              T-Wave

                Topic Starter


                Rookie

                Re: Writing batch file for .dbf
                « Reply #21 on: August 27, 2008, 05:53:23 PM »
                It's still setting the minimum height of every player to 78.

                I'm including a section of the instructions that came with cdbflite. Perhaps it may help?

                3. How to use
                ~~~~~~~~~~~~~
                 CDBFlite <filename.dbf|pattern> <parameter|@filename.lst|+filename.dbf>

                filename.dbf - the  name of .dbf-file, is necessary.  With this file
                          will make defined actions.

                Instead of a  file name is allowed a pattern.  So operations will be
                made  with  each file,  which  satisfy  given pattern.  Possible  to
                indicate several names or patterns before parameters. (3)

                CDBFlite  requires  one  or  more parameters  also.  You  can  place
                parameters into file and call CDBFlite as:
                   CDBFlite filename.dbf @yourfile
                Commands in the file must be written as one command at the one line.
                All blank lines, and lines beginning  with ';' are ignored. The file
                can contain the references to other files.

                You can create  the cdbflite.ini file and write to  it any commands.
                They will  be executed  each time  up to all  commands. You  can set
                commands such as ansi/oem, case, del...

                If  parameter  has  a  kind "+filename.dbf",  CDBFlite  carries  out
                operation APPEND FROM.



                4. Parameters
                ~~~~~~~~~~~~~

                First character of parameter can be '/' or '-'.
                Inside  of  the parameter  the  comma  or  semicolon  is used  as  a
                separator.

                The remark to OS Unix, Linux:
                   In OS Unix character ';' designates the end of  the  command,
                   therefore in the following cases:
                   /select:name,street,house,flat     - is correct
                   /select:name;street;house;flat     - is not correct!
                   "/select:name;street;house;flat" - is correct
                   If CDBFlite read commands from the file, both characters are
                   valid.

                The remark to OS/2 DLL:
                   Sample script -
                   /* */
                   RxFuncAdd("CDBFlite","cdbflite","CDBFlite")
                   call CDBFlite 'c:\path\cdbflite.ini', <filename.dbf> <parameters>
                             |                     
                   full name of ini-file or empty if not used: ''


                Parameters list:

                /version
                   The service parameter, returns a  version number and date of
                   compilation CDBFlite.

                /delete:N1,N2-N3,all
                   To mark on deleting.
                   You can specify  after colon of records number.  They can be
                   listed through a comma, to specify a range through a hyphen,
                   or to indicate the parameter "All". In last case all records
                   will be marked on deleting.  It's possible to use any amount
                   of records number.
                   /delete:10,20   -   delete records #10 and #20
                   /delete:10-20   -   delete records from #10 to #20
                   /delete:all       -   delete all records
                   /delete:10,20,30-35,40   

                /recall:N1,N2-N3,all
                   To remove a mark on deleting.
                   You can specify  after colon of records number.  They can be
                   listed through a comma, to specify a range through a hyphen,
                   or to  indicate the parameter  "All". In last case  from all
                   records will be  removed mark of deleting.  It's possible to
                   use any amount of records number.
                   /recall:10,20   -   remove mark of deleting from records #10 and #20
                   /recall:10-20   -   remove mark of deleting from records from #10 to #20
                   /recall:all   -   remove mark of deleting from all records
                   /recall:10,20,30-35,40   

                /pack[:dbf|memo]
                   To pack the database.
                   Physically  to delete  records,  marked on  deleting. If  to
                   indicate suffix :dbf or :memo , will be packed only .dbf the
                   file or  only file of the  notes. If suffix is  not specify,
                   will  be packed  all. This  parameter may  be combined  with
                   others, for example:
                   /delete:15-100 /pack
                   /pack:dbf

                /zap
                   To delete physically all records in the database.
                   /zap

                /blank
                   To  clear  the  write  buffer.  Is  usually  applied  before
                   addition of records.  At the start of the  program the write
                   buffer is cleared automatically.
                   /blank

                /append:N|blank
                   Append record with current information  in the buffer. If to
                   indicate unessential number - will be added specified number
                   of records. If to indicate a word "blank", will be added one
                   empty record.
                   /append
                   /append:blank
                   /append:100

                /trunc:N
                   Truncate database on specified number of record.
                   /trunc:100

                /make:filename.dbf
                   To create the empty database with the same structure.
                   /make:new.dbf
                   
                /sort:field1;field2;...
                   To sort database  on the indicated fields. The  old copy was
                   saved in  the file  with the .bak  extension. In  process of
                   sorting CDBFlite  will create file with  the .tmp extension.
                   For  successful fulfilment  of sorting  should be  necessary
                   vacant place on the disk.
                   /sort:name
                   /sort:phone
                   /sort:street;house;flat
                   Before  command /sort  command  /clear called  automatically
                   (see below).

                /cdx
                   Clears (set  to zero) byte  with offset 1c in  header, which
                   designates availability .CDX or .MDX of the file.
                   /cdx

                /cpzero[:N]
                   Set to specified value byte  with offset 1d in header, which
                   designates a used code page. Default to zero.
                   /cpzero
                   /cpzero:3

                /check
                   Checks a correctness of header and if necessary corrects it.
                   *.dbf /check

                /struct:file.txt|file.sql|file.dbf|file.prg
                   To show structure of database.
                   If  filename  does  not  specified,  the  information  about
                   structure will be issued on stdout.
                   /struct
                   If filename  with the .txt extension  specified, information
                   about structure will  be added to the indicated  file in the
                   same kind, as previous parameter.
                   /struct:somefile.txt
                   If filename  with the .sql extension  specified, information
                   about  structure will  be  added to  the  indicated file  as
                   command "CREATE TABLE" of SQL language.
                   /struct:somefile.sql
                   If filename  with the .dbf extension  specified, information
                   about structure will be overwritten to the indicated file in
                   a format accepted in FoxPro or Clipper.
                   /struct:somefile.dbf
                   If filename  with the .prg extension  specified, information
                   about  structure will  be  added to  the  indicated file  as
                   command "CREATEDB" of Clipper language.
                   /struct:somefile.prg
                   If filename  with the .fox extension  specified, information
                   about  structure will  be  added to  the  indicated file  as
                   command "CREATE TABLE" of FoxPro language.
                   /struct:somefile.fox

                /select:field1;field2;...|*
                /s:field1;field2;...|*
                   Print to stdout the specified fields of the database.
                   /select:name
                   /select:name;phone
                   /select:name;street;house;flat
                   /select:*

                /order:field1;field2;...
                /o:field1;field2;...
                   Set  order of  records. This  command in  itself has  not of
                   sense. To use follows in a combination with other commands:
                   /order:name  /select:name;phone;street;house;flat
                   If you want to set the  filter, set it before command /order
                   command. /filter command cancels /order command.

                /clear
                   This  command  to  clear earlier  installed  /order,  /sort,
                   /select, /filter.  With help  this command  you can  to make
                   several requests.
                   /order:name /select:name;phone /clear /order:phone /select:phone;name

                /asc
                   Set the order of ascending sort. By default.
                   /asc

                /desc
                   Set the order of descending sort.
                   /desc

                /filter:condition
                /f:condition
                   Installation of the  filter. The filter allows  to select of
                   some records  which satisfying to some  condition. Allowable
                   to use several conditions in one filter and/or some filters.
                   In the latter case they was united as condition 'AND'.
                   For example:
                   /filter:name=Smith       - to select people with name "Smith"
                   /filter:name=Smith&age>30   - to select people with name "Smith"
                                 and age more them 30 year
                   /filter:name=Smith&age{30   - to select people with name "Smith"
                                 and age less them 30 year
                   /filter:name=Smith;name=Gates   - to select people with name "Smith"
                                                     or "Gates"
                   /filter:name=Smith|name=Gates   - to select people with name "Smith"
                                                     or "Gates"
                   /filter:name~uck       - to  select   people,  containing a
                                 substring   "uck".  Thus   will be
                                 selected  "Luck", "Duck" etc. I.e.
                                 not only beginning of field.


                   Here is  required to explain,  that in the command  line you
                   can not use characters '|', '>', '<' - these characters used
                   Operation System  for pipe  of input-output. On  this reason
                   you should  replace in the  command line this  characters as
                   follows:
                   '|'   -->   ';'
                   '>'   -->   '}'
                   '<'   -->   '{'
                   If  the commands  are transmitted  to the  program from  the
                   file,  there  it is  possible  to  use any  characters.  The
                   following logical operations are allowed:
                   =      - equal
                   <> or  ><       - not equal
                   >  or  >>   - more
                   >=       - more or equal
                   <  or  <<   - less
                   <=       - less or equal
                   ~      - entry of a substring (for string fields)
                   If you set several filters, they will incorporated:
                   /filter:name=A /filter:age=30
                   it's same as
                   /filter:name=A&age=30
                   It is necessary  to notice, that in the second  case to work
                   will be  faster, as  the matching  goes for  1 pass,  in the
                   first case 2.
                   If the  compared expression  contains blanks, you  should to
                   conclude expression in quotes.
                   /filter:name="John Smith"
                   /filter command cancels /order command.
                   In the filter expression available following functions
                      ABS, ACOS, ASIN, ATAN, COSH, COS, EXP, LOG10, LOG,
                      POW10, ROUND, SINH, SIN, SQRT, SQR, TANH, TAN, TRUNC
                   for numeric fields.
                   /filter:summa-round(summa)>0.5   
                   In the filter expression available following functions
                      TRIM, LTRIM, RTRIM, SUBSTR, LEFT, RIGHT
                   for Character and Date fields.
                   /filter:substr(date,3,2)=05 /select:*
                   For comparison date-field you should use finction DTOS:
                   /filter:date=dtos(02.05.2001) /select:*

                /ansi
                   In the file the coding ANSI (Windows).

                /OEM
                   In the file the coding OEM (DOS). By default.

                /case[+|-]
                   /case or /case+  = Ignore case of characters.
                   /case-              = Do not ignore case of characters. By default.
                   Is applied together with /sort, /order or /filter.
                   /case /sort:name

                /del[+|-]
                   /del or  /del+ = show tag of deleting in the command /select
                   /del-          = do not show tag of deleting in the command /select.
                          By default.
                   /del /select:*

                /date:dmy|mdy|ymd|asis|char
                   Format of date field.
                   dmy  - Day-Month-Year
                   mdy  - Month-Day-Year
                   ymd  - Year-Month-Day
                   asis - As stored in the database.
                   You can change format somehow frequently:
                   /date:ymd /filter:born=1971 /date:mdy /select:*
                   You can set date separator:
                   /date:-      // 01-28-2001
                   /date:/      // 01/28/2001

                /range:N1,N2-N3|all
                   To select records with concrete records numbers. If database
                   was ordered or  filtered, the records will  select just from
                   among satisfying to the filter  and in the order. The /range
                   parameter has the lowest priority  and should be used by the
                   latter in a  combination with /filter or  /order. The suffix
                   "all" switch off range.
                   /range:1-10
                   /range:11-20
                   /range:1-100,200-500,150
                   /range:all

                /memo[:text]
                   To show state of memo-field /memo
                                   or contents /memo:text

                /field:field1=value;field2=value;...
                /l:field1=value;field2=value;...
                   To set  values of fields in  the buffer of data.  After that
                   you  can write  down them  into database  by the  /append or
                   /update command.
                   /field:name="John Smith";age=30;phone=3-14159265358

                /update
                   To  write  down current  data  from  write buffer  into  the
                   database. The data will write  to all records, which satisfy
                   current /filter  or /range. all  records will be  updated if
                   /filter or /range is not installed.
                   /field:first=100 /update
                   /filter:name=John /field:first=100 /update

                /count
                   Print quantity of records in database.
                   /count

                /name[+|-]
                   /name or /name+   = to show name of the database
                   /name-        = do not show name of the database.
                             By default.
                   Use with commands /count and /select.
                   *.dbf /name /count
                   *.dbf /name /filter:customer="Smith" /select:*

                /calc:condition
                   Calculate specified condition.
                   Available +-/*, and all functions, which described in the
                   /filter manual.
                   /calc:2+2*2
                   /calc:cos(0)

                /trim:left|right|all
                   Management of trimming of leading and trailing spaces from a
                   Character fields.
                   /trim        - without suffix, trimming spaces is off.
                   /trim:left   - Remove leading spaces from a character string.
                   /trim:right  - Remove trailing spaces from a character string.
                   /trim:all    - Remove leading and trailing spaces from a
                             character string.

                /out:file.txt|file.htm|file.dbf|file.sql|file.prg|file.fox|file.csv
                   Type of output of the information by /select command.
                   By default CDBFlite print result of work on the stdout(screen).
                   /out /select:*
                   If filename  with extension .txt specified,  command /select
                   will add information to the indicated file in the same kind,
                   as previous parameter.
                   /out:file.txt /select:*
                   If filename  with extension .csv specified,  command /select
                   will add information to the indicated file in the CSV format
                   /out:file.csv /select:*
                   If filename  with extension .htm specified,  command /select
                   will add information  to the indicated file  as table, using
                   html syntax.
                   /out:file.htm /select:*
                   If filename  with extension .dbf specified,  command /select
                   will  add information  to the  indicated .dbf-file.  If file
                   does not  exists - it will  be created. If the  file exists,
                   CDBFlite adds the information  only in existing fields (same
                   names, as in the source file).
                   /out:file.dbf /select:name;address;phone
                   If  filename  with  the .sql  extension  specified,  command
                   /select  will  add  information  to the  indicated  file  as
                   command "INSERT INTO" of SQL language.
                   /out:file.sql /select:*
                   /struct:dump.sql /out:dump.sql /select:*
                   If  filename  with the  .prg  or  .fox extension  specified,
                   command /select  will add information to  the indicated file
                   as command "REPLACE" of Clipper or FoxPro language.
                   /out:file.prg /select:*
                   /struct:dump.prg /out:dump.prg /select:*

                +filename.dbf
                   The operation  APPEND FROM  - addition  to current  file the
                   records  from other  file. If  the dbf-files  have identical
                   fields  names  and the  types  is  differs -  CDBFlite  will
                   transform expression to the necessary type.
                   cdbflite first.dbf +second.dbf

                /hdr[+|-]
                   Print names of fields in command /select.
                   /hdr+ /select:*

                /browse
                /fields
                   Use with command /select.
                   /fields /select:*

                /deleted[+|-]
                   To show or to hide records marked as deleted.
                   /deleted-

                /cmp:filename.dbf [/filter] [/order] /cmp[:isc]
                   Compares two files and displays the differences between   them.
                   You should set the name of second file:
                   /cmp:filename.dbf
                   Now possible to set the filter and/or the order of records. This
                   settings will work on both files.
                   After that you can execute some command of comparison:
                   /cmp or /cmp:i - to print the common information about databases.
                   /cmp:s         - to compare structures of databases.
                   /cmp:c         - to compare contents of databases.
                   /cmp:isc       - to execute all commands.
                   Designations, used at comparison:
                   -     - the field is absent.
                   <>     - field has same name, but all other parameters are different.
                   ~=     - field has same name and type, but size is different.
                   =     - all parameters of fields same, except offset inside the record.
                   ==     - Complete conformity of fields.
                   cdbflite file1.dbf /cmp:file2.dbf /cmp   
                   cdbflite file1.dbf /cmp:file2.dbf /cmp:s
                   cdbflite file1.dbf /cmp:file2.dbf /f:born}dtos(01.01.1970) /o:name /cmp:ics

                /sum:field1;field2;...|*
                   Print to stdout a sum by specified fields of the database.
                   /sum:salary
                   /sum:payment;discount
                   /sum:*

                /avg:field1;field2;...|*
                   Print to stdout an average value by specified fields of the database.
                   /avg:salary
                   /avg:payment;discount
                   /avg:*

                /encode:password
                   Encode database with the specified password.
                   Cryptographic strength is quite good.
                   /encode:super_secret

                /decode:password
                   Decode database  with the  specified password. You  must use
                   the same password as was used in the command /encode. If you
                   will make a mistake, then data will be lost.
                   /decode:super_secret

                /psw[:password]
                   Set password for input/output oparations.
                   The parameter /psw  without of a password switch off current password
                   /psw:12345 /field:a1=John;a2=Smith;a3=100;a4=05.27.2001 /append
                   /psw:12345 /select:*


                /bak[+|-]
                   Create .bak file when database is changed.
                   /bak+
                   /bak-



                5. Note
                ~~~~~~~~~~~~
                (1)   field types:    
                      Character, Numeric, Float, Date, Logical, Memo
                      General, Currency, Double, Integer, Binary.

                (2)   memo-field types:      
                      dBase III, dBase IV, FoxPro, Visual FoxPro.

                (3)   CDBFlite one.dbf two.dbf /parameter /parameter ...
                   CDBFlite a*.dbf b???.dbf /parameter /parameter ...


                fireballs



                  Apprentice

                • Code:Terminal
                • Thanked: 3
                  Re: Writing batch file for .dbf
                  « Reply #22 on: August 27, 2008, 07:09:06 PM »
                  for /f "tokens=* delims=" %%A in ('type wing.txt') do (
                  set APPEARID=%%A
                  "cdbflite.exe" appearance.dbf /case /filter:APPEARID=%APPEARID%&HEIGHT{78 /field:HEIGHT=78 /update
                  )

                  If that doesn't work then DOS is not expanding the variable when it's passed to the executable....

                  FB
                  Next time google it.

                  T-Wave

                    Topic Starter


                    Rookie

                    Re: Writing batch file for .dbf
                    « Reply #23 on: August 28, 2008, 06:40:50 AM »
                    Hi Fireballs,

                    when I tried it with your last code, I get "Invalid filter" as the error message. I'm guessing there is something wrong with the /filter:APPEARID=%APPEARID% segment of the code.

                    Also, do you think this can perhaps be done using an IF statement instead of a SET

                    fireballs



                      Apprentice

                    • Code:Terminal
                    • Thanked: 3
                      Re: Writing batch file for .dbf
                      « Reply #24 on: August 28, 2008, 06:51:42 AM »
                      Code: [Select]
                      for /f "tokens=* delims=" %%A in ('type wing.txt') do (
                      echo %%A>auth
                      "cdbflite.exe" appearance.dbf /case /filter:APPEARID=<auth /filter:HEIGHT{78 /field:HEIGHT=78 /update
                      )
                      That's my last stab at getting this to work in DOS, There must be a way of doing the whole process just using cdbflite.exe.

                      FB
                      Next time google it.

                      T-Wave

                        Topic Starter


                        Rookie

                        Re: Writing batch file for .dbf
                        « Reply #25 on: August 28, 2008, 07:05:26 AM »
                        Still get the same "Invalid filter" error for every line. Thanks, nevertheless, for all your effort, Fireballs.

                        fireballs



                          Apprentice

                        • Code:Terminal
                        • Thanked: 3
                          Re: Writing batch file for .dbf
                          « Reply #26 on: August 28, 2008, 07:13:40 AM »
                          This is still puzzling. You can definitely pass arguments to executables in the form "%%A", at least I can.

                          Have you tried using only one filter at a time to confirm that it definitely is the /filter:APPEARID= one that's not working? Have you tried using a proper value. e.g.  /filter:APPEARID=4107?

                          FB
                          Next time google it.

                          T-Wave

                            Topic Starter


                            Rookie

                            Re: Writing batch file for .dbf
                            « Reply #27 on: August 28, 2008, 07:22:47 AM »
                            I hadn't before, though I had tried several changes to that segment before and had different results that hinted that was the case.

                            Now that you mentioned it though, I just tried the code with a proper value (/filter:APPEARID=4035 /filter:Height{78) and it worked with only that particular line.  By the way, somehow, I have to use multiple /filter instructions to represent an AND. THe statement /filter:APPEARID=4035&Height{78 returns an error.

                            qinghao



                              Intermediate
                            • Don't think your self special
                              Re: Writing batch file for .dbf
                              « Reply #28 on: August 28, 2008, 07:26:25 AM »
                              Oh ,I should learn  more about the batch command.

                              fireballs



                                Apprentice

                              • Code:Terminal
                              • Thanked: 3
                                Re: Writing batch file for .dbf
                                « Reply #29 on: August 28, 2008, 07:34:22 AM »
                                Hmmm it appears as though DOS isn't expanding the variable before it's passed to the executable. Sorry that's all my advice exhausted. Hope you find a solution somehow!

                                FB
                                Next time google it.