attach()

Read(3153) Label: attach,

Here’s how to use attach() functions.

T.attach(T’)

Description:

Retrieve an attached table from a cluster composite table.

Syntax:

T.attach(T’)

Note:

The function retrieves attached table T’, which should already exist, from cluster composite table T.

Parameter:

T

A cluster composite table

T’

An attached table

Return value:

An attached table

Example:

Add an attached table to composite table emp1.ctx:

 

A

 

1

=file("D:\\emp1.ctx")

 

2

=A1.create(#EID,NAME)

Create the composite table’s base table.

3

=demo.cursor("select EID,NAME from employee ")

 

4

=A2.append(A3)

Append records to the base table.

5

=A2.attach(t1, SURNAME,DEPT )

Add attached table t1 to the base table.

6

=demo.cursor("select EID,SURNAME,DEPT from employee")

 

7

=A5.append(A6)

Append records to attached table t1.

8

=A2.attach(t2,GENDER,SALARY)

Add attached table t2 to the base table.

9

=demo.cursor("select EID,GENDER,SALARY from employee ")

 

10

=A8.append(A9)

Append records to attached table t2.

Put emp1.ctx in node 192.168.0.116:8281:

 

A

 

1

=file("emp1.ctx",["192.168.0.116:8281"])

Open a cluster file.

2

=A1.open()

Return a cluster composite table.

3

=A2.attach(t1)

Retrieve attached table t1.

T.attach(T’)

Description:

Open a composite tabl's attached table.

Syntax:

T.attach(T’)

Note:

The function opens composite table T’s attached table T’; can update or modify it.

 

Cannot read an attached table record if its primary key value does not have a primary key match in the base table; will not check the primary key match status between the attached table and the base table when appending data to or updating data in the attached table.

Parameter:

T

Base table

T’

Attached table name

Return value:

Attached table object

Example:

Add an attached table to the base table:

 

A

 

1

=file("D:/ctb.ctx")

 

2

=A1.create(#k1,v1)

Create the composite table’s base table, where k1 is the dimension and v1 is another column.

3

=A2.attach(table2,#k2,v2)

Add an attached table named table2 to the base table A2 returns and specify k1 and k2 as the dimension and v2 as another column.

4

=create(k1,v1).record([1,10,2,20,3,30,4,40,10,100])

Create a table sequence.

5

=create(k1,k2,v2).record([1,1,"a",3,1,"c"])

Create a table sequence.

6

=A2.append(A4.cursor())

Append cursor’s records to the base table.

7

=A3.append(A5.cursor())

Append cursor’s records to attached table table2.

8

>A2.close()

Close the composite table.

Open an attached table:

 

A

 

1

=file("D:/ctb.ctx").open()

 

2

=A1.attach(table2)

Open the entity table’s attached table named table2.

3

=A2.cursor().fetch()

Fetch data from the attached table.

Update an attached table:

 

A

 

1

=file("D:/ctb.ctx").open()

 

2

=A1.attach(table2)

Open the entity table’s attached table named table2.

3

=create(k1,k2,v2).record([4,2,"d"])

 

4

=A2.update(A3)

Update data of table sequence A3 to attached table table2.

5

=A2.cursor().fetch()

Fetch data from the updated attached table.

T.attach(T’,C…)

Description:

Add an attached table to the base table of a composite table.

Synatx:

T.attach(T’,C…)

Note:

The function adds attached table T’ to a composite table’s base table T. A composite table can have one or multiple attached tables. The attached table’s dimensions include dimensions of its base table; its column names should be different from the base table’s column names.

Parameter:

T

A base table

T’

An attached table

C

Attached table column, can be omitted; return an attached table named T’ if it is absent; a C preceded by # is a dimension

Return value:

An attached table

Example:

Add an attached table to the base table:

 

A

 

1

=file("D:/ctb.ctx")

 

2

=A1.create(#k1,v1)

Create the composite table’s base table, where k1 is the dimension and v1 is the base table’s column.

3

=A2.attach(table2,#k2,v2)

Add an attached table named table2 to the base table returned by A2; the attached table’s dimension fields are k1 and k2 and its column is v2.

4

=create(k1,v1).record([1,10,2,20,3,30,4,40,10,100])

Create a table sequence.

5

=create(k1,k2,v2).record([1,1,"a",3,1,"c"])

Create a table sequence.

6

=A2.append(A4.cursor())

Append cursor’s records to A2’s base table.

7

=A3.append(A5.cursor())

Append cursor’s records to A3’s attached table.

8

>A2.close()

Close the composite table.