Show/Hide Toolbars

XSharp

NoteThis 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

Import records from a database or text file.

Syntax

APPEND FROM <xcSourceFile>
  [FIELDS <idFieldList> | FIELDS LIKE <Skeleton> | FIELDS EXCEPT <Skeleton>]
 [<Scope>] [WHILE <lCondition>] [FOR <lCondition>]
  [[TYPE] [DELIMITED [WITH <Delim> | WITH BLANK | WITH TAB
     | WITH CHARACTER <cDelim>] | DIF | FW2 | MOD | PDOX | RPD |
     SDF | SYLK | WK1 | WK3 | WKS | WR1 | WRK | CSV | XLS | XL5
     [SHEET <cSheetName>] | XL8 [SHEET <cSheetName>]]] [AS <nCodePage>]

Arguments

FROM <xcSourceFile>The name of the source file from which to add records, 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.
This command attempts to open <xcSourceFile> in shared mode.  If the file does not exist, a runtime error is raised.  If the file is successfully opened, the operation proceeds.  If access is denied because, for example, another process has exclusive use of the file, NetErr() is set to TRUE.  

 

FIELDS <idFieldList>The list of fields to process. The default is all fields with the exception of memo fields, unless the command supports the MEMO clause.
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.
FIELDS LIKE <Skeleton>You can specify field names with a wild card, such as FIELDS LIKE *name
FIELDS EXCEPT <Skeleton>You can exclude fields, such as for example the primary keys: FIELDS EXCEPT Id
<Skeleton> supports wildcards (* and ?). For example, to replace all fields that begin with the letters A and P, use:
FIELDS LIKE A*,P*

 

Please note that you can combine FIELDS LIKE and FIELDS EXCEPT but you cannot combine a fields list with the LIKE and EXCEPT clauses.

 

 

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

 

 

DELIMITED WITH <Delim>Indicates that character fields are separated by a character other than the quotation mark.        
DELIMITED WITH BLANK Specifies files that contain fields separated by spaces instead of commas.
DELIMITED WITH TAB Specifies files that contain fields separated by tabs rather than commas.
WITH CHARACTER <cDelim>Specifies files that contain fields all enclosed by the character specified with Delimiter. If Delimiter is a semicolon (the character used in Visual FoxPro to indicate command line continuation), enclose the semicolon in quotation marks. You can also specify the BLANK and TAB keywords for Delimiter.
The WITH Delimiter clause can be combined with the WITH CHARACTER clause.

 

TYPEFrom the various types that FoxPro allows only the following ones are supported in X# at this moment:
SDF        An SDF file is an ASCII text file in which records have a fixed length and end with a carriage return and line feed. Fields are not delimited.
       The file name extension is assumed to be .txt for SDF files.

 
CSV        A comma separated value file. A CSV file has field names as the first line in the file; the field names are ignored when the file is imported.
 The file name extension is assumed to be .csv for CSV files.
OTHER        NOT SUPPORTED AT THIS MOMENT

AS <nCodePage>Specifies the codepage to use for the source file. NOT SUPPORTED AT THIS MOMENT

 

Notes

Deleted records: If SetDeleted() is FALSE, deleted records in <xcSourceFile> are appended to the current database file and retain their deleted status.  If SetDeleted() is TRUE, however, deleted records are not visible and are, therefore, not processed.

 

Unmatched field widths: If a field in the current database file is character type and has a field length greater than the incoming <xcSourceFile> data, APPEND FROM pads the source data with blanks.  If the current field is character data type and its field length is less than the incoming source data, the source data is truncated to fit.  If the current field is numeric type and the incoming source data has more digits than the current field length, a runtime error is raised.

Examples

This example demonstrates an APPEND FROM command using a fields list and a condition:

 

USE sales NEW
APPEND FROM branchfile FIELDS Branch, Salesman, Amount FOR Branch = 100

 

The next example demonstrates how a <Scope> can be specified to import a particular record from another database file:

 

APPEND RECORD 5 FROM temp

Assembly

XSharp.RT.DLL

See Also

COPY TO, DbApp(), DbAppDelim(), DbAppSDF(), RDDSetDefault(), SetDefault(), SetPath(), SetDeleted()