Table Sequences and Records

Read(200) Label: table sequence, record,

This chapter lists code examples of handling table sequences and records, including Create an empty table sequence, Judge if it is a record or a table sequence, List fields of a record, Access record fields and assign values to them, Get field number and number of fields, Fill members of a sequence into a record as field values, Get field value from a record by field number, Modify field value in a record by field number, Modify data structure of a table sequence, Change field values of a record into fields, and append new records.

Create an empty table sequence

 

A

 

1

=create(fld1,fld2,fld3)

Create an empty table sequence

2

=A1.create()

Create another empty table sequence using the structure of A1

Judge if it is a record or a table sequence

 

A

 

1

[1,2,3]

 

2

=create(fld1).record(A1)

 

3

=ifr(A1(1))

false, Judge if it is a record

4

=ifr(A2(1))

true, Judge if it is a record

5

=ift(A1)

false, Judge if it is a table sequence

6

=ift(A2)

true, Judge if it is a table sequence

 

List fields of a record

 

A

 

1

=r.fname()

All fields in the table sequence in which the record resides

 

Access record fields and assign value s to them

 

A

 

1

=r.Name

Access by field name

2

=r.#2

Access by field number

3

>r.#2="Tom"

Assignment

4

>r.Name="Tom"

Assignment

 

Get field number and number of fields

 

A

 

1

=create(name, gender, job, age)

 

2

=A1.fno(gender)

2, field number

3

=A1.fno()

4, number of fields

 

Fill members of a sequence into a record as field values

 

A

 

1

>r.record([1,2,3])

Fill members into the record in order

 

Get field value from a record by field number

 

A

 

1

=r.field(i)

Get value of the ith field from record r

 

Modify field value in a record by field number

 

A

 

1

>r.field(i, x)

Modify value of the ith field in record r into x

 

Modify data structure of a table sequence

 

A

 

1

=create(number,name,birthday)

 

2

>A1.rename(number:id)

Modify a field name

3

>A1.rename(birthday)

Delete field names

 

Change field values of a record into fields

 

A

 

1

=demo.query("select NAME,EVENT,SCORE from GYMSCORE")

 

2

=A1.group(NAME)

 

3

=A2.new(NAME,~.select@1(EVENT:"BalanceBeam").SCORE:BalanceBeam,~.select@1(EVENT:"Floor").SCORE:Floor)

Turn a record into fields

 

Append new records

 

A

 

1

=create(Athlete,Event,Score)

Create an empty table sequence

2

>A1.insert(0,90:Score,"s1":Athlete,"Vault":Event)

Append one record

3

>A1.insert(0:2,90+#:Score,"s2"+string(#):Athlete,"Floor":Event)

Append multiple records