Here’s how to use reset() function.
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(spl,…).
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:
Description:
Rearrange a composite table file or a homo-name files group to a new one.
Syntax:
f.reset(f’:b;cs) |
Rearrange a composite table file or a homo-name files group to a new composite table file
|
f.reset(f’:b,x;cs) |
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 where update mark is defined for performing update merge; ignore the record in the zone table with the smaller number when same key values appear in two zone tables; Handle the update mark 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 |
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 the update mark:
|
A |
|
1 |
=connect("demo").cursor("select EID,NAME,GENDER from employee") |
|
2 |
=A1.derive(: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 update 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([0,true,,,1,false,"AAA","M",2,true,,])
|
Return a table sequence 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 table sequence A7’s records to zone table 3.er.ctx. |
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 composite table 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 That is: Update Update the record whose EID value is 1 and whose update mark is false (meaning to-be-modified); Won't write the record whose EID value is 2 and whose update mark is true (meaning to-be-deleted) to er_w.ctx; Retain the record whose EID value is 0 and whose update mark is true (to-be-deleted) - the rule is that the record with an update mark and with unique key value will be kept. |
15 |
=A13.open().import() |
Retrieve data from multizone composite table er_w.ctx:
|
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() |
|