reset()

Read(1714) Label: reset,

Here’s how to use reset() function.

cs.reset()

Description:

Reset a cursor by moving it back to the beginning.

Syntax:

cs.reset()

Note:

The function resets a cursor by moving it back to the beginning when it traverses cursor data to the end.

 

Note: Cursors returned from certain functions are irreversible, including db.cursor@x(), f.cursor@x(), cs.groupx(), cs.sortx(), cs.joinx() and cursor(dfx,…).

Parameter:

cs

A cursor

Return value:

Cursor

Example:

 

A

 

1

=demo.cursor("select * from scores")

Return retrieved data as a cursor.

2

=A1.fetch()

Fetch data from the cursor.

3

=A1.fetch()

Return null because A1’s cursor has come to the end of the data.

4

=A1.reset()

Move the cursor back to the beginning.

5

=A1.fetch()

Fetch data out of the cursor; returned result is the same as A2.

Related function:

cs.skip()

f.reset()

Description:

Rearrange a composite table file or a homo-name files group to a new one.

Syntax:

f.reset(f’:b;cs)

f.reset(f’:b;x;cs)

Rearrange a composite table file or a homo-name files group to a new composite table file

Rearrange a composite table file or a homo-name files group to a new homo-name files group

Note:

The function rearranges composite table or multizone composite table f to a new composite table file or homo-names files group f’.

 

When f is composite table file, f’ can be a composite table file or a homo-name files group; when f’ is a homo-name files group, x is zone table expression and cannot be omitted. When parameter f’ is absent, rearrange f and re-create the index.

 

When f is a homo-names files group, f’ should not be omitted and merge zone tables according to the dimension. Distribution structure of zone tables is changed when f’ is a homo-names files group; and it remains unchanged when parameter x is absent.

 

When parameter cs is present, combine data in cs to f’.

Parameter:

f

A composite table file/homo-name files group.

f’

A composite table file or a homo-name files group.

b

Block size, whose unit is byte; by default, it uses value of “Composite table block size” set in the configuration options; when esProc is integrated into a third-party application, the parameter’s value is by default is blockSize value configure in raqsoftConfig.xml file.

x

Zone table expression.

cs

A cursor/table sequence.

Option:

@u

Write the file as an uncompressed one; perform the write as usual if the parameter is omitted.

@z

Write the file as a compressed one; won’t perform compression if the option is absent.

@r

Write the file by row; perform the write as usual if the parameter is omitted

@c

Write the file by column.

@w

Used on multizone composite tables for performing update merge; ignore the record in the zone table with the smaller number when same key values appear in two zone tables;

Refer to the deletion mark at the same time and won’t write records marked by the deletion mark to the new composite table file; when key value of the record having a deletion mark is unique in its zone table, just retain it.

@q

When parameter f is a homo-name files group and parameter f’ is a composite table file, use this option to perform a simple concatenation instead of a merge while ignoring parameters x and cs.

@y

Force to overwrite the file when the target already exists; by default error will be reported and the file rearrangement fails if the target file exist.

Return value:

Boolean

Example:

When f is a composite table file:

 

A

 

1

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

An existing composite table file.

2

=A1.reset(file("D:\\e1.ctx"))

Rearrange data of composite table file test1.ctx to the composite table file e1.ctx.

3

=A1.reset()

As parameter f’ is absent, clear test1.ctx and re-create index for it.

4

=A1.reset@r(file("D:\\e5.ctx"))

Copy composite table file test1 as a rowwise stored file.

5

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

 

6

=A5.open()

Open A8’s composite table file and data in its base table is as follows:

7

=create(EID,NAME).record([4,"Emily"])

8

=A6.delete(A7)

Delete A7’s record from A6’s composite table

9

=A6.close()

Close the composite table.

10

=A5.reset(file("empNew.ctx"):1048576)

Re-organize composite table file emp12.ctx into empNew.ctx, while setting block size as 1048576 bytes.

 

  When f is a multizone composite table:

 

A

 

1

=file("emp.ctx":[1,2])

Here is an existing homo-name files group; below are contents of files respectively:

Zone table 1.emp.ctx contains data whose GENDER is F, and zone table 2.emp.ctx has data whose GENDER is M

2 

=A1.reset(file("empAll.ctx"))

Merge 1.emp.ctx and 2.emp.ctx, zone tables of the multizone composite table, into composite table file empAll.ctx by dimension.

3

=file("empRe.ctx":[1,2])

Return a homo-name files group object.

4

=A1.reset(A3)

Rearrange data of multizone composite table 1.emp.ctx and 2.emp.ctx and write it to multizone composite table empRe.ctx, and the distribution structure of zone tables remains unchanged; below are contents of the two zone tables:

5

=file("empN.ctx":[1,2])

Return a homo-name files group object.

6

=A1.reset(A5;if(SALARY<10000,1,2))

Re-organize 1.emp.ctx and 2.emp.ctx, zone tables of the multizone composite table, into multizone composite table file empN.ctx, and change the distribution structure of them through zone table expressions, that is, records where SALARY<1000 are written to 1.empN.ctx and other records are written to 2.empN.ctx.

 

When parameter cs is present:

 

A

 

1

=file("apm.ctx")

Here’s an existing composite table file; its content is as follows:

2

=create(EID,NAME).record([5,"Ashley"]).cursor()

Return a cursor, whose content is as follows:

3

=file("re1.ctx")

Return a composite table file object.

4

=A1.reset(A3;A2)

Rearrange data in composite table file apm.ctx and data in cursor A2, and combine them together to re1.ctx

5

=create(EID,NAME).record([10,"Ryan"])

Return a table sequence:

6

=A3.reset(;A5)

Rearrange data in composite table file re1.ctx and combine data in table sequence A5 to it.

7

=A3.open().import()

Import data from re1.ctx and return the following result:

 

Use @q option to concatenate the files group into the composite table file:

 

A

 

1

=file("emr.ctx":[1,2])

An existing files group, where zone table 1.emr.ctx contains records whose GENDER field values are F:

zone table 2.emr.ctx contains records whose GENDER field values are M:

2

=file("empHb.ctx")

 

3

=A1.reset@q(A2)

Use @q option to concatenate the two zone tables into composite table file empHb.ctx whose content is as follows:

 

Use @w option to handle same key value:

 

A

 

1

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

 

2

=A1.derive(false:Defiled)

 

3

=A2.new(EID,Defiled,NAME,GENDER)

Return a cursor whose content is as follows:

4

=file("er.ctx":[1,2])

Define a homo-name files group: 1.er.ctx and 2.er.ctx.

5

=A4.create@yd(#EID,Defiled,NAME,GENDER;if(GENDER=="F",1,2))

Create a multizone composite table, set EID as the key, use @d option to make Defiled the deletion mark field, and put records where GENDER is F to 1.er.ctx and the other records to 2.ed.ctx.

6

=A5.append@ix(A3)

Append cursor A3’s data to the multizone composite table.

7

=create(EID,Defiled,NAME,GENDER).record([1,false,"AAA","M"]).cursor()

Return a cursor whose content is as follows:

8

=file("er.ctx":[3])

 

9

=A8.create@yd(#EID,Defiled,NAME,GENDER;3)

Add a new zone table 3.er.ctx.

10

=A9.append@i(A7)

Append cursor A7’s records to zone table 3.er.ctx; now both 1.er.ctx and 3.er.ctx have the record whose primary key is [1] .

11

=file("er.ctx":[1,2,3])

 

12

=A11.open().import()

Retrieve data from multizone composite table er.ctx:

13

=file("er_w.ctx")

Return a homo-name files group object.

14

=A11.reset@w(A13)

Rearrange data of homo-name files group er.ctx to er_w.ctx and use @w option to perform update merge; now both 1.er.ctx and 3.er.ctx have the record whose primary key is [1] and ignor records of 1.er.ctx.

15

=A13.open().import()

Retrieve data from multizone composite table er_w.ctx:

 

Use @w option to recognize deletion mark:

 

A

 

1

=create(EID,Defiled,NAME,GENDER).record([2,true,,,0,true,,]).cursor()

Return a cursor whose content is as follows:

2

=file("er.ctx":[4])

For content of zone tables 1.er.ctx, 2.er.ctx and 3.er.ctx in multizone table er.ctx, see the above example.

3

=A2.create@yd(#EID,Defiled,NAME,GENDER;4)

Add a new zone table 4.er.ctx and make Defiled the deletion mark field.

4

=A3.append@i(A1)

Append cursor A1’s records to zone table 4.er.ctx; now the deletion mark field value for the record whose primary key field is 2 is true and the record whose primary key value is 0 is new to the original zone table.

5

=file("er.ctx":[1,2,3,4])

 

6

=A5.open().import@x()

Retrieve data from multizone composite table A5 and return the following data:

7

=file("er_w2.ctx")

Return a homo-name files group object.

8

=A5.reset@w(A7)

Rearrange data of homo-name files group er.ctx to er_w2.txt and use @w option to not to write the record whose primary key value is 2 to multizone composite table er_w2.ctx (the record is regarded as deleted because it already exists in the original zone table 1.er.ctx and the record whose primary key value is 2 in zone table 4.er.ctx is marked by deletion mark); the record whose primary key value is 0 does not exist in the original zone table, so it is retained though marked by deletion mark.

9

=A7.open().import@x()

Retrieve data from multizone composite table er_w2.ctx and return data as follows:

T.reset()

Description:

Clear the members of a table sequence.

Syntax:

T.reset()

Note:

The function clears members from table sequence T, but reserves the data structure.

Parameter:

T

A table sequence

Return value:

Empty table sequence

Example:

 

A

 

1

=demo.query("select * from EMPLOYEE")

2

=A1.reset()