Note | This command is defined in a header file and will be preprocessed by the X# preprocessor to a function call. If you disable the standard header (-nostddefs) files then this command will not be available. If you tell the compiler to use a different standard header file (-stddef ) then this command may also be not available |
Purpose
Export records to a new database or text file.
Syntax
COPY TO <xcTargetFile> [FIELDS <idFieldList>] [<Scope>]
[WHILE <lCondition>] [FOR <lCondition>]
[SDF] | [DELIMITED [WITH BLANK | <xcDelimiter>]] |
[VIA <cDriver>] [INHERIT FROM <acRDDs>]
Arguments
TO <xcTargetFile> | The name of the target file, including an optional drive, directory, and extension. See SetDefault() and SetPath() for file searching and creation rules. The default extension for database files is determined by the RDD. For text files, it is .TXT. |
| If <xcTargetFile> does not exist, it is created. If it exists, this command attempts to open the file in exclusive mode and, if successful, the file is overwritten without warning or error. If access is denied because, for example, another process is using the file, NetErr() is set to TRUE. |
FIELDS <idFieldList> | The list of fields to append from <xcSourceFile>. The default is all fields. |
| Only fields with the same names and types in both files are appended. If fields with the same name do not match in data type, a runtime error is raised. |
<Scope> | The portion of the current database file to process. The default is all visible records. Scope is one or more clauses of:
[NEXT <NEXT>] Optionally specifies the number of records to process starting
with the first record of the source file.
[RECORD <rec>] An optional record ID If specified, the processing begins
with this data record in the source file.
[<rest:REST>] The option REST specifies whether records are sequentially
searched only from the current up to the last record.
If a condition is specified, the option ALL is the default value.
[ALL] The option ALL specifies that all records from the source file are imported.
This is the default setting. |
WHILE <lCondition> | A condition that each visible record within the scope must meet, starting with the current record. As soon as the while condition fails, the process terminates. If no <Scope> is specified, having a while condition changes the default scope to the rest of the visible records in the file. |
FOR <lCondition> | A condition that each visible record within the scope must meet in order to be processed. If a record does not meet the specified condition, it is ignored and the next visible record is processed. If no <Scope> or WHILE clause is specified, having a for condition changes the default scope to all visible records. |
SDF | A System Data Format file with format specifications as shown in the table below. Records and fields are fixed length.
|
Character fields | Padded with trailing blanks |
Numeric fields | Padded with leading blanks for zeros |
Record separator | Carriage return/linefeed |
End of file marker | 1A hex or Chr(26) |
DELIMITED [WITH <xcDelimiter>] |
| A text file in which character fields are enclosed in double quote marks (the default delimiter) or the specified <xcDelimiter>. Fields and records are variable length, and the format specifications are shown in the table below: |
Character fields | Delimited, with trailing blanks truncated |
Numeric fields | Leading zeros truncated |
Record separator | Carriage return/linefeed |
End of file marker | 1A hex or Chr(26) |
| A text file in which fields are separated by one space and character fields are not enclosed in delimiters. The format specifications are shown in the table below: |
Character fields | Not delimited, trailing blanks truncated |
Numeric fields | Leading zeros truncated |
Field separator | Single blank space |
Record separator | Carriage return/linefeed |
End of file marker | 1A hex or Chr(26) |
| Warning! If the DELIMITED WITH clause is specified on a COPY TO command line, it must be the last clause specified. |
VIA <cDriver> | The name of the RDD that will service the work area. If not specified, the default RDD as determined by RDDSetDefault() is used. |
| A one-dimensional array with the names of RDDs from which the main RDD inherits special functionality. This allows you to use RDDs with special capabilities, like encryption or decryption, in different work areas with different database drivers. These RDDs overlay special functions of the main RDD (specified with the VIA clause). If multiple RDDs (specified with this INHERIT FROM clause) implement the same function, the function associated with the last RDD in the list takes precedence. |
Notes
Deleted records: If SetDeleted() is FALSE, deleted records in the source file are copied to <xcTargetFile> where they retain their deleted status.
Visibility: If SetDeleted() is TRUE, however, deleted records are not visible and are, therefore, not processed. Similarly, filtered records (with DbSetFilter() or a conditional controlling order) are not processed.
Examples
This example demonstrates copying to another database file:
USE sales NEW
COPY TO temp
This example demonstrates the layout of an SDF file with four fields, one for each data type:
USE testdata NEW
COPY NEXT 1 TO temp SDF
TYPE temp.txt
// Result: Character 12.0019890801T
The next example demonstrates the layout of a DELIMITED file:
COPY NEXT 1 TO temp DELIMITED
TYPE temp.txt
// Result: "Character",12.00,19890801,T
Finally, this example demonstrates the layout of a DELIMITED file WITH a different delimiter:
COPY NEXT 1 TO temp DELIMITED WITH '
TYPE temp.txt
// Result: 'Character',12.00,19890801,T
Assembly
XSharp.RT.DLL
See Also
APPEND FROM, COPY FILE, COPY STRUCTURE, DbCopy(), DbCopyDelim(), DbCopySDF(), RDDSetDefault(), SetDefault(), SetPath(), SetDeleted()