UPDATE

UPDATE

Update current database file from another database file

Syntax

      UPDATE FROM <xcAlias>
            ON <expKey> [RANDOM]
            REPLACE <idField> WITH <exp>
            [, <idField2> WITH    <exp2>...]

Arguments

FROM <xcAlias> specifies the alias of the work area used to update records in the current work area. This argument may be specified either as a literal file name or as a character expression enclosed in parentheses.

ON <expKey> specifies the expression that defines matching records in the FROM work area.

REPLACE <idField> specifies a field in the current work area to replace with a new value.

WITH <exp> specifies the value to replace into the current field. You must reference any field contained in the FROM work area with the correct alias.

RANDOM allows records in the FROM database file to be in any order. If this option is specified, the current database file must be indexed on <expKey>.

Description

UPDATE is a database command that replaces fields in the current work area with values from another work area based on the specified key expression. UPDATE is designed to update only current work area records based on a one-to-one or one-to-many relation with the FROM work area. This means that UPDATE can only update records in the current work area with unique key values. When there is more than one instance of a key value, only the first record with the key value is updated. The FROM work area, however, can have duplicate key values.

There are two formulations of the command depending on whether the FROM work area records are sorted or indexed on <expKey> or not. If RANDOM is not specified, both the current work area and the FROM work area must be indexed or sorted in <expKey> order. If RANDOM is specified, the current work area must be indexed by <expKey>, but the FROM work area records can be in any order.

To use UPDATE in a network environment, the current database file must be locked with FLOCK() or USEed EXCLUSIVEly. The FROM database file may be used in any mode. Refer to the “Network Programming” chapter in the Programming and Utilities Guide for more information.

Notes

. Deleted records: If DELETED is OFF, deleted records in both source files are processed. Records in the file being updated retain their deleted status and are not affected by the deleted status of records in the FROM file. If DELETED is ON, however, no deleted records are processed from either source file.

Examples

      .  This example UPDATEs the Customer database file with
         outstanding invoice amounts:

      USE Invoices NEW
      USE Customer INDEX Customer NEW
      UPDATE FROM Invoices ON Last;
         REPLACE Owed WITH Owed + Invoices->Amount RANDOM

Seealso

DBCREATEIND(), INDEX, JOIN, REPLACE, SET UNIQUE*, SORT

STORE

STORE*

Assign a value to one or more variables

Syntax

      STORE <exp> TO <idVar list>
         <idVar> = <exp>
         <idVar> := [ <idVar2> := ...] <exp>

Arguments

<exp> is a value of any data type that is assigned to the specified variables.

TO <idVar list> defines a list of one or more local, static, public, private, or field variables that are assigned the value <exp>. If any <idVar> is not visible or does not exist, a private variable is created and assigned <exp>.

Description

STORE assigns a value to one or more variables of any storage class. The storage classes of Clipper variables are local, static, field, private, and public. STORE is identical to the simple assignment operators (=) and (:=). In fact, a STORE statement is preprocessed into an assignment statement using the inline operator (:=). Like all of the assignment operators, STORE assigns to the most recently declared and visible variable referenced by <idVar>. If, however, the variable reference is ambiguous (i.e., not declared at compile time or not explicitly qualified with an alias), it is assumed to be MEMVAR. At runtime, if no private or public variable exists with the specified name, a private variable is created.

To override a declaration, you can specify the <idVar> prefaced by an alias. If <idVar> is a field variable, use the name of the work area. For private and public variables, you can use the memory variable alias (MEMVAR->). To assign to a field variable in the currently selected work area (as opposed to a particular named work area), you can use the field alias (FIELD->).

As a matter of principle, all variables other than field variables should be declared. Preface field variables with the alias. Use of private and public variables is discouraged since they violate basic principles of modular programming and are much slower than local and static variables.

Note that the STORE command is a compatibility command and not recommended for any assignment operation. Clipper provides assignment operators that supersede the STORE command, including the inline assignment operator (:=), the increment and decrement operators (++) and (–), and the compound assignment operators (+=, -=, *=, /=). Refer to the Operators and Variables sections of the “Basic Concepts” chapter in the Programming and Utilities Guide for more information.

Notes

. Assigning a value to an entire array: In Clipper, neither the STORE command nor the assignment operators can assign a single value to an entire array. Use the AFILL() function for this purpose.

. Memo fields: Assigning a memo field to a variable assigns a character value to that variable.

Examples

      .  These statements create and assign values to undeclared
         private variables:

      STORE "string" TO cVar1, cVar2, cVar3
      cVar1:= "string2"
      cVar2:= MEMVAR->cVar1

      .  These statements assign multiple variables using both STORE
         and the inline assignment operator (:=).  The methods produce
         identical code:

      STORE "value" to cVar1, cVar2, cVar3
      cVar1 := cVar2 := cVar3 := "value"

      .  These statements assign values to the same field referenced
         explicitly with an alias.  The first assignment uses the field alias
         (FIELD->), where the second uses the actual alias name:

      USE Sales NEW
      FIELD->CustBal = 1200.98
      Sales->CustBal = 1200.98

Seealso

AFILL(), LOCAL, PRIVATE, PUBLIC, RELEASE, REPLACE

MemoRead()

MEMOREAD()

Return the text file’s contents as a character string

Syntax

      MEMOREAD( <cFileName> ) --> cString

Arguments

<cFileName> is the filename to read from disk. It must include the file extension. If file to be read lives in another directory, you must include the path.

Returns

Returns the contents of a text file as a character string.

If <cFileName> cannot be found or read MEMOREAD returns an empty string (“”).

Description

MEMOREAD() is a function that reads the content of a text file (till now) from disk (floppy, HD, CD-ROM, etc.) into a memory string. In that way you can manipulate as any character string or assigned to a memo field to be saved in a database.

MEMOREAD() function is used together with MEMOEDIT() and MEMOWRIT() to get from disk text from several sources that would be edited, searched, replaced, displayed, etc.

It is used to import data from other sources to our database.

Note: MEMOREAD() does not use the settings SET DEFAULT or SET PATH to search for <cFileName>. It searches for <cFileName> in the current directory. If the file is not found, then MEMOREAD() searches in the DOS path.

Over a network, MEMOREAD() attempts to open <cFileName> in read-only mode and shared. If the file is used in mode exclusive by another process, the function will returns a null string (“”).

Examples

      *  This example uses MEMOREAD() to assign the contents of a text
      *  file to a character variable for later search

         cFile   := "account.prg"
         cString := MEMOREAD( cFile )
         cCopyright := "Melina"

         IF At( "Melina", cString ) == 0            // check for copyright
            MEMOWRIT( cFile, cCopyright + cString ) // if not, add it!
         ENDIF

Compliance

Clipper

Platforms

All (64K)

Files

Library is rtl

Seealso

MEMOEDIT(), MEMOWRIT(), REPLACE, HB_MEMOREAD()

hb_MemoRead()

HB_MEMOREAD()

Return the text file’s contents as a character string

Syntax

      HB_MEMOREAD( <cFileName> ) --> cString

Arguments

<cFileName> is the filename to read from disk. It must include the file extension. If file to be read lives in another directory, you must include the path.

Returns

Returns the contents of a text file as a character string.

If <cFileName> cannot be found or read HB_MEMOREAD returns an empty string (“”).

Description

HB_MEMOREAD() is a function that reads the content of a text file (till now) from disk (floppy, HD, CD-ROM, etc.) into a memory string. In that way you can manipulate as any character string or assigned to a memo field to be saved in a database.

HB_MEMOREAD() function is used together with MEMOEDIT() and HB_MEMOWRIT() to get from disk text from several sources that would be edited, searched, replaced, displayed, etc.

It is used to import data from other sources to our database.

Note: HB_MEMOREAD() does not use the settings SET DEFAULT or SET PATH to search for <cFileName>. It searches for <cFileName> in the current directory. If the file is not found, then HB_MEMOREAD() searches in the DOS path.

Over a network, HB_MEMOREAD() attempts to open <cFileName> in read-only mode and shared. If the file is used in mode exclusive by another process, the function will returns a null string (“”).

HB_MEMOREAD() vs MEMOREAD(): HB_MEMOREAD() is identical to MEMOREAD() except it won’t truncate the last byte (on non-UNIX compatible systems) if it’s a EOF char.

Examples

      *  This example uses HB_MEMOREAD() to assign the contents of a text
      *  file to a character variable for later search

         cFile   := "account.prg"
         cString := HB_MEMOREAD( cFile )
         cCopyright := "Melina"

         IF At( "Melina", cString ) == 0               // check for copyright
            HB_MEMOWRIT( cFile, cCopyright + cString ) // if not, add it!
         ENDIF

Compliance

Clipper

Platforms

All (64K)

Files

Library is rtl

Seealso

MEMOEDIT(), HB_MEMOWRIT(), REPLACE, MEMOREAD()

SP_SADD_REC

SADD_REC()

  Short:
  ------
  SADD_REC() Attempts to append a blank record

  Returns:
  --------
  <lSuccess> => success

  Syntax:
  -------
  SADD_REC([nTries],[lAskMore],[cAskMessage])

  Description:
  ------------
  Attempts to append a blank record. Tries [nTries]
  times and then allows user to retry or not if [lAskMore] by
  giving message [cAskMessage] and asking YES/NO.

  Examples:
  ---------
   IF SADD_REC(5,.T.,"Unable to ADD,Try again?")

       IF SREC_LOCK(5,.T.,"Unable to lock, Try again?")
         REPLACE XXX WITH YYY, ZZZ WITH BBB
         UNLOCK
       ENDIF
   ENDIF

  Source:
  -------
  S_SADDR.PRG

 

SP_GLOBREP

GLOBREP()

  Short:
  ------
  GLOBREP() Performs global selective replace of a field

  Returns:
  --------
  Nothing

  Syntax:
  -------
  GLOBREP([aFields,aDesc])

  Description:
  ------------
  Allows user to point to a field and then enter a
  replacement value for it. Replacement can be executed for all
  records, query matches, or tagged records.

  [aFields,aDesc] arrays of field names, and field
  descriptions.

  Examples:
  ---------
   If nChoice == 9   // Global replace

     GLOBREP()

   endif

  Warnings:
  ----------
  These changes are, of course, permanent.
  New to 3.5:
  -Preview (view changes before they happen)
  -'Build Formula' replacement option type. Lets user build a
  formula for replacing the target field.

  Source:
  -------
  S_GLOBR.PRG

 

C5_REPLACE

 REPLACE
 Assign new values to field variables
------------------------------------------------------------------------------
 Syntax

     REPLACE <idField> WITH <exp>
        [, <idField2> WITH <exp2>...]
        [<scope>] [WHILE <lCondition>] [FOR <lCondition>]

 Arguments

     <idField> is the name of the field variable to be assigned a new
     value.  If <idField> is prefaced with an alias, the assignment takes
     place in the designated work area.

     WITH <exp> defines the value to assign to <idField>.

     <scope> is the portion of the current database file to REPLACE.  The
     default is the current record, or NEXT 1.  Specifying a condition
     changes the default to ALL records in the current work area.

     WHILE <lCondition> specifies the set of records meeting the
     condition from the current record until the condition fails.

     FOR <lCondition> specifies the conditional set of records to REPLACE
     within the given scope.

 Description

     REPLACE is a database command that assigns new values to the contents of
     one or more field variables in the current record in the specified work
     areas.  The target field variables can be character, date, logical,
     memo, or numeric.  REPLACE performs the same function as the assignment
     operator (:=) except that it assumes that an unaliased reference is to a
     field variable.  This means that you can assign new values to field
     variables using assignment statements provided that the field variable
     references are prefaced with an alias, the FIELD alias, or declared
     using the FIELD declaration statement.

     The default scope of REPLACE is the current record unless a scope or
     condition is specified.  If a scope or condition is specified, the
     replace operation is performed on each record matching the scope and/or
     condition.

     Warning!  When you REPLACE a key field, the index is updated and the
     relative position of the record pointer within the index is changed.
     This means that REPLACEing a key field with a scope or a condition may
     yield an erroneous result.  To update a key field, SET ORDER TO 0 before
     the REPLACE.  This ensures that the record pointer moves sequentially in
     natural order.  All open indexes, however, are updated if the key field
     is REPLACEd.

     In a network environment, REPLACEing the current record requires an
     RLOCK().  REPLACEing with a scope and/or condition requires an FLOCK()
     or EXCLUSIVE USE of the current database file.  If a field is being
     REPLACEd in another work area by specifying its alias, that record must
     also be locked with an RLOCK().  Refer to the "Network Programming"
     chapter in the Programming and Utilities Guide for more information.

 Examples

     .  This example shows a simple use of REPLACE:

        USE Customer NEW
        APPEND BLANK
        USE Invoices NEW
        APPEND BLANK
        //
        REPLACE Charges WITH Customer->Markup * Cost,;
           Custid WITH Customer->Custid,;
           Customer->TranDate WITH DATE()

     .  This example uses assignment statements in place of the
        REPLACE command:

        FIELD->Charges := Customer->Markup * FIELD->Cost
        FIELD->Custid := Customer->Custid
        Customer->TranDate := DATE()

 Files   Library is CLIPPER.LIB.

See Also: COMMIT FLOCK() RLOCK()

 

C5 Commands

 ?|??            Display one or more values to the console
 @...BOX         Draw a box on the screen
 @...CLEAR       Clear a rectangular region of the screen
 @...GET         Create a new Get object and display it
 @...PROMPT      Paint a menu item and define a message
 @...SAY         Display data at a specified screen or printer row and column
 @...TO          Draw a single- or double-line box
 ACCEPT*         Place keyboard input into a memory variable
 APPEND BLANK    Add a new record to the current database file
 APPEND FROM     Import records from a database (.dbf) file or ASCII text file
 AVERAGE         Average numeric expressions in the current work area
 CALL*           Execute a C or Assembler procedure
 CANCEL*         Terminate program processing
 CLEAR ALL*      Close files and release public and private variables
 CLEAR GETS      Release Get objects from the current GetList array
 CLEAR MEMORY    Release all public and private variables
 CLEAR SCREEN    Clear the screen and return the cursor home
 CLEAR TYPEAHEAD Empty the keyboard buffer
 CLOSE           Close a specific set of files
 COMMIT          Perform a solid-disk write for all active work areas
 CONTINUE        Resume a pending LOCATE
 COPY FILE       Copy a file to a new file or to a device
 COPY STRUCTURE  Copy the current .dbf structure to a new database (.dbf) file
 COPY STRU EXTE  Copy field definitions to a .dbf file
 COPY TO         Export records to a database (.dbf) file or ASCII text file
 COUNT           Tally records to a variable
 CREATE          Create an empty structure extended (.dbf) file
 CREATE FROM     Create a new .dbf file from a structure extended file
 DELETE          Mark records for deletion
 DELETE FILE     Remove a file from disk
 DELETE TAG      Delete a tag
 DIR*            Display a listing of files from a specified path
 DISPLAY         Display records to the console
 EJECT           Advance the printhead to top of form
 ERASE           Remove a file from disk
 FIND*           Search an index for a specified key value
 GO              Move the pointer to the specified identity
 INDEX           Create an index file
 INPUT*          Enter the result of an expression into a variable
 JOIN            Create a new database file by merging from two work areas
 KEYBOARD        Stuff a string into the keyboard buffer
 LABEL FORM      Display labels to the console
 LIST            List records to the console
 LOCATE          Search sequentially for a record matching a condition
 MENU TO         Execute a lightbar menu for defined PROMPTs
 NOTE*           Place a single-line comment in a program file
 PACK            Remove deleted records from a database file
 QUIT            Terminate program processing
 READ            Activate full-screen editing mode using Get objects
 RECALL          Restore records marked for deletion
 REINDEX         Rebuild open indexes in the current work area
 RELEASE         Delete public and private memory variables
 RENAME          Change the name of a file
 REPLACE         Assign new values to field variables
 REPORT FORM     Display a report to the console
 RESTORE         Retrieve memory variables from a memory (.mem) file
 RESTORE SCREEN* Display a saved screen
 RUN             Execute a DOS command or program
 SAVE            Save variables to a memory (.mem) file
 SAVE SCREEN*    Save the current screen to a buffer or variable
 SEEK            Search an order for a specified key value
 SELECT          Change the current work area
 SET ALTERNATE   Echo console output to a text file
 SET BELL        Toggle sounding of the bell during full-screen operations
 SET CENTURY     Modify the date format to include or omit century digits
 SET COLOR*      Define screen colors
 SET CONFIRM     Toggle required exit key to terminate GETs
 SET CONSOLE     Toggle console display to the screen
 SET CURSOR      Toggle the screen cursor on or off
 SET DATE        Set the date format for input and display
 SET DECIMALS    Set the number of decimal places to be displayed
 SET DEFAULT     Set the CA-Clipper default drive and directory
 SET DELETED     Toggle filtering of deleted records
 SET DELIMITERS  Toggle or define GET delimiters
 SET DESCENDING  Change the descending flag of the controlling order
 SET DEVICE      Direct @...SAYs to the screen or printer
 SET EPOCH       Control the interpretation of dates with no century digits
 SET ESCAPE      Toggle Esc as a READ exit key
 SET EXACT*      Toggle exact matches for character strings
 SET EXCLUSIVE*  Establish shared or exclusive USE of database files
 SET FILTER      Hide records not meeting a condition
 SET FIXED       Toggle fixing of the number of decimal digits displayed
 SET FORMAT*     Activate a format when READ is executed
 SET FUNCTION    Assign a character string to a function key
 SET INDEX       Open one or more order bags in the current work area
 SET INTENSITY   Toggle enhanced display of GETs and PROMPTs
 SET KEY         Assign a procedure invocation to a key
 SET MARGIN      Set the page offset for all printed output
 SET MEMOBLOCK   Change the block size for memo files
 SET MESSAGE     Set the @...PROMPT message line row
 SET OPTIMIZE    Change the setting that optimizes using open orders
 SET ORDER       Select the controlling order
 SET PATH        Specify the CA-Clipper search path for opening files
 SET PRINTER     Toggle echo of output to printer or set the print destination
 SET PROCEDURE*  Compile procedures and functions into the current object file
 SET RELATION    Relate two work areas by a key value or record number
 SET SCOPE       Change the boundaries for scoping keys in controlling order
 SET SCOPEBOTTOM Change bottom boundary for scoping keys in controlling order
 SET SCOPETOP    Change top boundary for scoping keys in controlling order
 SET SCOREBOARD  Toggle the message display from READ or MEMOEDIT()
 SET SOFTSEEK    Toggle relative seeking
 SET TYPEAHEAD   Set the size of the keyboard buffer
 SET UNIQUE*     Toggle inclusion of non-unique keys into an index
 SET WRAP*       Toggle wrapping of the highlight in menus
 SKIP            Move the record pointer to a new position
 SORT            Copy to a database (.dbf) file in sorted order
 STORE*          Assign a value to one or more variables
 SUM             Sum numeric expressions and assign results to variables
 TEXT*           Display a literal block of text
 TOTAL           Summarize records by key value to a database (.dbf) file
 TYPE            Display the contents of a text file
 UNLOCK          Release file/record locks set by the current user
 UPDATE          Update current database file from another database file
 USE             Open an existing database (.dbf) and its associated files
 WAIT*           Suspend program processing until a key is pressed
 ZAP             Remove all records from the current database file

 

Clipper and Networking

Clipper and Networking

Code blocks, inside and out

 

Code blocks, inside and out