export()

Read(251) Label: export,

Here’s how to use export() function.

A .export()

Description:

Convert a sequence into a string.

Syntax:  

A.export(x:F,…;s)

Note:

The function separates each selected fields x of records in table sequence/record sequence/sequence A with the user-defined separator and returns the result as a string. The name of the resulting field in the string is F. If x isn’t specified, then export all fields. Return a one-field string without a field name if A is a sequence. A serial byte value is stored as an integer.

 If parameters x:F are absent and if A is a sequence of record, then these records should be of same structure.

Parameters:  

A

A table sequence/record sequence/sequence to be exported.

x

Fields to be exported. If omitted, then export all fields of A.

F

Name of the resulting field in the string. If omitted, then use the original field name.

s

User-defined field separator. The default is tab.

Options:  

@t

The column names will be written to the string as the first record.

@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.

@j

Export as json string, with s being ignored.

@w

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

@x

Export as XML string, with s being the starting point which can’t be omitted; the slash / is used to separate multiple levels of data.

<xml>

<table>

        <row>

            <F>v</F>

           

          </row>

       

  </table>

</xml>

@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 backslash (\)

Return value:

String.

Example:

 

A

 

1

=demo.query("select EID,NAME from EMPLOYEE")

 

2

=A1.export()

Parameters x, F, and s are omitted.

3

=A1.export(;"|")

Specify the separator as "|".

4

=A1.export@t(EID:id,NAME:name;",")

Specify to-be-exported fields and the separator; make column names the first record and write it at the beginning of the exported string

5

=A1.export@x(NAME;"employee/name")

Convert the table sequence into an XML string, where employee and name are respectively the first level and second level nodes

6

=A1.export@j()

Convert the table sequence into a JSON string and return it

7

[1,23,34,45]

A sequence

8

=A7.export()

9

=A1.export@c()

With @c option, use default separator comma

10

=A1.export@w()

Use Windows-style \r\n line break.

11

=["12\r34","aa\nbb"]

 

12

=A11.export()

13

=A11.export@q()

With @q option, the exported string is enclosed by double quotations

14

=A11.export@qo()

With @o option, use quotations as the escape character

Note:

Format of the string: Separate the records by space, and the fields by the user-defined separator. The default separator is tab.

Related functions:

f.import()

f.export()

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

Description:

Write a sequence/table sequence/record sequence into a file.

Syntax:

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

Note:

 The function writes sequence/table sequence/record sequence A into file f in the form of text; it will auto-create an f, which is in the text format by default, if the file doesn’t exist (but the path can’t be auto-created). If A contains a serial byte field, the seirial byte values will be written as in the form of integers.

If A is a table sequence or a record sequence, write all fields into the file if parameter x is absent. If the values of a to-be-exported field are referenced records, just write their primary key values into f. The unexportable fields in A can’t be written into f. A one-field file without field name will be generated if A is a sequence and parameter x is absent.

Parameters:

f

A file

A

The record sequence/sequence to be exported

x

The field to be exported. If omitted, all the fields of A that can be textualized will be exported. 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

The user-defined separator used in the text file, and the default separator is tab

Options:

@t

Export the first record to the file as the title

@a

Append. By default, overwrite the original file. The option and @t are mutual exclusive. The appended records and the original records should be of the same structure, otherwise error will be reported

@b

Convert into binary file to speed up the processing; does not support parameter s.

@c

Use comma as the separator when parameter s is absent, but the user-defined separator s should take priority when the parameter is present

@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 by default. In this option, parameter s, when present, is a grouping expression by which A is ordered; perform data segmentation only when s is changed. This option is often used to export a large amount of data to a binary file in segments with parallel processing and it can make sure that each segment will be wholly exported

@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 (\)

Example:

Write a record sequence into a txt file.

 

A

 

 

1

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

 

 

2

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

 

3

=file("D:\\Department.txt").export@t(A1)

Use @t to export the first record as the title

 

 

4

=file("D:\\Department2.txt").export(A1;"|")

 

5

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

 

6

=file("D:\\Department2.txt").export@a(A1)

Still the above example, append the contents from A1 to the contents of the file

 

7

=file("D:\\Department3.txt").export@b(A1)

Export the file content in binary format

 

8

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

If not omitting x, then only export the specified field

 

9

[a,s,d,f]

 

 

10

=file("D:\\myfile.txt").export(A9)

myfile.txt is a one-field file without a field name

 

11

=file("D:\\Department6.txt").export@c(A1)

 

12

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

Sort by GENDER

 

13

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

Group the file by GENDER and export it to EMPLOYEE.btx

 

14

=file("D:\\EMPLOYEE.txt").export@w(A1)

Use Windows-style \r\n line break

15

=demo.query("select * from DEPARTMENT").keys(MANAGER)

 

16

=A12.switch(DEPT,A15:DEPT)

17

=file("D:\\EMPLOYEE1.txt").export@t(A16)

Values of DEPT field in A16 are referenced records; in this case the primary key of the table sequence need to be exported

18

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

19

=file("D:\\Department7.txt").export(A18,#1)

#1 represents the first column, so only that column of data is exported

20

=file("D:\\Dep1.txt").export@q(A18,#1)

21

=["12\r34","aa\nbb"]

22

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

23

=file("D:\\T2.txt").export@qo(A21)

Note:

Format of text file: Separate records by carriage return, and fields by the user-defined separator. The default separator is tab. Here records of table sequence/record sequence/sequence A must be of the same data structure.

Related functions:

f.import()

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

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 the first record to the file as the title.

@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 data to the file with the first record being the title.

 

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()