REWRITE

Contents


Rewrite is used to rewrite a given record to a table.

 

Syntaxes

    Rewrite [ class ] [ key ] [ read_mode [ value_key ] ]

 

Parameters

Element

Description

Restrictions

key

Indicates the key for a file in one of the following forms forms:
nom_de_variable
nom_de_variable '(' exp_ind ')'

The key must be defined in an Order By clause or in the table parameters.

exp_ind

Integer expression of the number of parts of the keys used. The whole key is used by default.

0 <=exp_ind<= number of components of the key (8 max).

read_mode

One of the following key-words, or one of the following operators:

key-word

operator

Read mode used

First
Last
Curr
Prev
Next






>=
>
=
<
<=

1st record
Last record
Current record
Previous record
Next record
Key >= value_key
Key > value_key
Key = value_key
Key < value_key
Key <= value_key

value_key

List of expressions separated by ';' matching the values of the sub-keys.

value compatible with type of sub-key.

 

Examples

    # Read a record for modification of the ZONE field
     Trbegin TEST [TEST]
     Readlock [TEST]CLE2(1) = date$
     If [S]fstat
        [TEST]ZONE += 100
       
Rewrite [TEST]
        Unlock [TEST]
        Commit
       Else
        Rollback
     Endif

    # Read, modification of a record and rewrite
     Readlock CLE = [M]CLE  :# Read + lock
     [M] = [F]    :# File transfer to mask
     ...          :# Input zones to be modified
     [F] = [M]    :# Transfer mask to file
    
Rewrite     :# Rewrite current record
     Unlock    :# Unlock

    # Record shifts
    # (record no 2 is written to 1, 3 to 2, etc..)
    # Only works on a non-empty file without unique keys.
     Read [TEST]CLE First
     Read [TEST]CLE Next
     While fstat=0
       
Rewrite [TEST]CLE Prev
        Read [TEST]CLE Next
        Read [TEST]CLE Next
     Wend

 

Description and comments

Rewrite is used to rewrite new values to a record read using the various modes listed in the table above. If no key values are given for modes that require one ( '<', '>', '<=', '>=', '=' ), the current value for class [F] variables for the file is used.

If no read mode is given, Curr mode will be used and the current record (that is, the last read) is modified.

The keys that may be used in Rewrite are :

·         the key defined in the last Order By clause (if there is one);

·         otherwise, one of the keys defined in the file parameters.

The file abbreviation or key name may be omitted from the Rewrite syntax:

·         in the former case, the file used is the first from the list of default tables;

·         in the second case, the key used is the current one. Its number is given by the Adonix system variable currind.

The fstat variable indicates the progress of the write.

fstat

Code

Wr.

Explanation

0

Yes

The rewrite took place correctly.

1

ERLOCK

No

The record is locked.

2

ERECIND

Yes

In read mode <= or >= , indicates that read has taken place, but the key found is < or > the set value.

3

ERDUPCL

No

Attempt to create a duplicate key.

4

ERDEBF

No

Start/End of file

5

ERPALEC

No

No record matches the values requested.

When the rewrite is successful (that is if fstat is either null or has a value ERECIND), the record becomes the current file record.

 

Comment

Until the transaction is complete, the modifications will not be visible to other users.

A link abbreviation may not be used to rewrite a record.

A record must be modified within a transaction.

The record to be rewritten will always be locked and will only be rewritten if this operation is successful, otherwise [S]fstat will be set to 1. Refer to the Readlock documentation for problems relating to record locks.

If there are several records to be updated, the Update instruction may be quicker.

 

Associated errors

Error

Description

MODIN (22)

Read mode incorrect

ERINDI ( 8)

The number of values given or the index indicated, exceeds the number of elements in the key.

PACLE (21)

The key does not exist on this file.

ERCLAS ( 7)

The file class does not exist (file not open).

 

Associated key words

FILE - READLOCK - TRBEGIN - UPDATE - WRITE - FSTAT


CONTENTS


Copyright © Sage 1999 - 2007