Write
Write
allows you to insert a new line in a database table.
WriteWrite [CLASS]
[CLASS]
is an abbreviation of an opened table. By default, the default table as defined by DefaultFile is used. # Extract of a AINSERT "hand written" method on a class : let's create a header and linesTrbegin HEADER [HEAD], LINES [LINE]SetInstance [HEAD] with thisWrite [HEAD]If fstat=0For I=1 to maxtab(this.LINES)If this.LINES(I)<>NullSetInstance [LINE] with this.LINES(I)Write [LINE]Break (fstat<>0)EndifNext IEndifIf fstat=0CommitElseRollbackEndif
Write
allows you to insert a line in the database.
fstat indicates the result of the operation:
Value | Description |
---|---|
0 | The write operation succeeded. |
1 | The table is locked. |
3 | An attempt to create a duplicate key value was done. |
A Write
instruction does not modify the current record. If the current record must be the written one, it is necessary to perform a read operation.
The behavior can be different depending on the database:
Write
are not seen until the transaction ends.It is not possible to use an abbreviation associated with a join by Link to write a line.
The creation of a line must be done in a transaction.
The written line is locked until the transaction ends.
When several lines must be written on a given table, it is best to use the Writeb instruction that performs faster.
If the table is locked by Lock [ABBREV
], the other users cannot insert lines and will get a fstat value equal to 1.
Error code | Description |
---|---|
7 | Class does not exist (no table opened with the corresponding abbreviation). |
27 | A write attempt was done on a [Link](../4gl/link.md) abbreviation. |
44 | No more space to create lines. |
65 | No more space to create lines. |
75 | Database error. |
File, Readlock, Trbegin, Commit, Rollback, Update, Rewrite, Delete, RewriteByKey, DeleteByKey, Writeb, fstat.