f .export( cs , x : F ,…; s )

Read(450) Label: cursor, write to text file,

Description:

Retrieve data from a cursor and write it to a text file.

Syntax:

f.export(cs,x:F,…;s)

Note:

The function writes data of cursor cs to the file object f as text. If the file does not exist, create it automatically (Note that the directory path cannot be created automatically).

Option:

@t

Export field description, or the headers, as the first row of the file.

@a

Append. If omitted, then overwrite the original file. The option and @t are mutual exclusive. f and cs must be of the same structure, otherwise error will be reported.

@b

Convert into binary file to speed up the processing. It ignores @t and does not support the parameter s.

@c

Use comma as the separator when the parameter s is absent, but the user-defined separator s should take priority when there are both s and @c option.

@z

Force the execution of @b and write the sequence to the binary file f in segment by segment. The sequence won’t be segmented without this option. With this option, the parameter s is the grouping expression ruling that sequence A is ordered by s, if the parameter exists, and perform the segmentation only when s changes. The binary file is used to export a large sequenece in segments with parallel processing, which will make sure records in each segment won’t be split. 

@w

Use Windows-style \r\n line break; by default the line break is specified by the operating system.

@q

Enclose the exported text field values and headers with quotation marks

@o

Use quotation marks as the escape character; need to work with @q. Without it the escape character is the Java-style slash (\)

Parameters:

f

File object.

cs

Cursor whose data to be exported.

x

Fields to be exported. If omitted, then export all fields in the record sequence A that can be textualized. The sign # is used to represent a field with a sequence number.

F

Resulting field name. If omitted, then use the original field name.

s

User-defined separator; the default is tab.

Example:

Write the cursor data to the text file.

 

A

 

 

1

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

 

 

2

=file("D:\\Department1.txt").export(A1)

Tab separator.

 

3

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

 

 

4

=file("D:\\Department2.txt").export(A3;"/")

Specify the separator “/”.

 

5

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

 

 

6

=file("D:\\Department3.txt").export@t(A5)

Write field names in the first row as the titles

 

 

7

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

 

 

8

=file("D:\\Department4.txt").export@t(A7,DEPT:Dept1,DEPT:Dept2;"|")

If x is not omitted, then export the specified fields.

 

9

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

 

 

10

=file("D:\\Department5.txt").export@t(A9,DEPT,MANAGER;"/")

If F is omitted, then use the original field names.

 

11

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

 

 

12

=file("D:\\Department5.txt").export@a(A11 DEPT,MANAGER;"/")

Still the above examlple, append the contents of A12 to the contents of Department5.txt.

 

13

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

 

 

14

=file("D:\\Department6.txt").export@b(A13)

Export data as the binary file to get a higher speed.

 

15

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

 

 

16

=file("D:\\Departmen7.txt").export@c(A15)

Use comma as the separator

 

17

=demo.cursor("select * from EMPLOYEE order by GENDER")

Sort by GENDER.

 

18

=file("D:\\EMPLOYEE1.btx").export@z(A17,EID,NAME,SURNAME,GENDER,SALARY;GENDER)

Export a segmented binary file grouped by GENDER to EMPLOYEE.btx

 

19

=demo.cursor("select * from EMPLOYEE order by GENDER")

 

20

=file("D:\\EMPLOYEE2.txt").export@w(A19)

Use Windows-style \r\n line break.

21

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

 

22

=file("D:\\Department8.txt").export(A21,#1)

#1 represents the first column, so only that column in the cursor is exported

23

=file("D:\\Dep1.txt").export@q(A21)

Both exported field values and headers in the text file are quoted

24

=["12\r34","aa\nbb"].cursor()

Above is the content of the cursor

25

=file("D:\\Dep2.txt").export@q(A24)

26

=file("D:\\Dep3.txt").export@qo(A24)

Use double quotations as the escape character

Related functions: 

f.export()