T .update( P )

Read(580) Label: update, records,

Description:

Update records in an entity table.

Syntax:

T.update(P)

Note:

The function updates entity table T’s records by matching keys in T and record sequence P; P and T should have same structure. If a key value in P doesn’t exist in T, append or insert the corresponding record in T.

Parameters:

T

A composite table’s entity table

P

A table sequence/record sequence having same structure as T

Options:

@i

Only append or insert non-matching records and ignore the matching ones

@u

Only update the matching records and ignore the non-matching ones

@n

Return records that are updated and inserted

@w

When parameter P is a cursor having same order as the original entity table, update the latter’s fields that P has; only valid for column-wise storage format and no records should be added

Return value:

  An entity table

Example: 

 

A

 

1

=file("emp.ctx")

Generate a composite table file

2

=A1.create@y(#EID,NAME)

Create the composite table’s base table

3

=connect("demo").cursor("select EID,NAME from employee where EID<20")

Return a cursor

4

=A2.append@i(A3)

Append data in A3’s cursor to A2’s base table

5

=A2.attach(table3,SURNAME)

Add attached table table3 that has two fields – EID, which is the key, and SURNAME, to the base table

6

=connect("demo").cursor("select EID,SURNAME from employee where EID< 5")

Return a cursor

7

=A5.append@i(A6)

Append data in A6’s cursor to A5’s pseudo table

8

=A2.cursor().fetch()

View data in the base table:

9

=A5.cursor().fetch()

View data in the attached table:

10

=create(EID,NAME).record([1,"A",21,"B"])

Return a table sequence

11

=A2.update(A10)

Update the base table using A8’s table sequence

12

=A2.cursor().fetch()

View data in the base table again:

13

=create(EID,SURNAME).record([2,"aa",10,"bb"])

Return a table sequence

14

=A5.update@in(A13)

With @i option, only handles insert and ignore records with same key values; the cooperation with @n option makes the function return only the inserted records

15

=A5.cursor().fetch()

View data in the attached table again:

16

=create(EID,SURNAME).record([1,"ss",6,"cc"])

Return a table sequence

17

=A5.update@un(A16)

With @u option, only handles update and ignore records with different key values; the cooperation with @n option makes the function return only the updated records

18

=A5.cursor().fetch()

View data in the attached table: