laitimes

vfp learns the append from ARRAY command the next day

APPEND FROM ARRAY command

For each row in the array, add a record to the currently selected table and take data from the corresponding array row to add to the record.

APPEND FROM ARRAY ArrayName [FOR lExpression]
  [FIELDS FieldList | FIELDS LIKE Skeleton | FIELDS EXCEPT Skeleton]           

parameter

ArrayName Specifies specifies the name of the array that contains the data to be copied into the new record. The command adds all the rows in the array to the table.

FOR lExpression specifies the conditions for appending records in the array. The target field name must be included in the lExpression condition expression. Before appending rows from the data to records in the table, check that the array elements corresponding to the target fields specified in lExpression meet the conditions in lExpression. If the array element satisfies the condition, the record is appended to the table. If the array element does not meet the condition, the array row is not appended to the table and the next row is checked.

Fields FieldList specifies that only fields in the FieldList list are updated from the array. The first field in the list is updated with the contents of the first element of the array, the second field is updated with the second element, and so on.

Fields LIKE Skeleton specifies that fields that match the field synopsis Skeleton are updated from an array.

Fields EXCEPT Skeleton specifies that all fields that do not match the field outline Skeleton are updated from the array. Field Synopsis Skeleton supports wildcards.

For example, to specify that all fields beginning with the letters A and P are updated from an array, you can use the following statement:

APPEND FROM ARRAY aMyArray FIELDS LIKE A*,P*           

The LIKE clause can be combined with the EXCEPT clause:

APPEND FROM ARRAY aMyArray FIELDS LIKE A*,P* EXCEPT PARTNO*           

The APPEND FROM ARRAY command ignores memo, general-purpose, and large binary object (blob) fields. *NEW

If the table is open and shared, the APPEND FROM ARRAY command locks the table header when appending records.

If the array is one-dimensional, APPEND FROM ARRAY adds only one record to the table. The contents of the first array element are populated into the first field of the newly added record, the contents of the second element are populated into the second field of the record, and so on.

If the number of elements of a one-dimensional array exceeds the number of table fields, more elements than are ignored. If the number of table fields exceeds the number of array elements, the extra fields are initialized to the default null value. The following are the default null values for each field type:

The field type The default value
Character type space
Currency type
Date type Empty date (such as CTOD(""))
Date-time type Empty datetime (such as CTOT(""))
Double type
Floating-point type
Integer
Logical False (.F.)
Remarks type Empty (no content)
Numeric

If the array is two-dimensional, APPEND FROM ARRAY adds a new record to the table for each row in the array. For example, if the array has 4 rows, 4 new records are appended to the table.

The contents of the first column in the array are populated with the first field of the newly added record, the second column is populated with the second field of the newly added record, and so on. For example, if an array has 4 rows and 3 columns, the first column element in the array is filled into the first field of the 4 new records, respectively.

If a two-dimensional array has more columns than the number of fields in the table, more columns than are ignored. If the number of table fields exceeds the number of array columns, the extra fields are initialized to null values.

If the data element data is compatible with the corresponding field data type, APPEND FROM ARRAY is able to populate the field even if the data type of the corresponding array element does not match the field data type. If the data is incompatible, the field is initialized to a null value.

If autoincrement is used in the target table, APPEND FROM ARRAY fails when SET AUTOINCERROR is ON unless the AUTOINC column is omitted from the FIELDS option. Setting AUTOINCERROR to OFF or turning off autoincrement of the target table with CURSORSETPROP( ) allows APPEND FROM ARRAY to succeed. The autoincrementing field of the target table or a field that increments by a specified value, and the value in the source table do not apply. *NEW

This example creates a table and then uses the APPEND FROM ARRAY command to add a record to the new table

LOCAL ARRAY aNewRec(3)

* 创建自由表Test
CREATE TABLE Test FREE  (Object C(10), Color C(16), SqFt n(6,2))
SCATTER TO aNewRec BLANK  && 从表中创建一个新数组
aNewRec[1]="Box"         && 填充数组
aNewRec[2]="Red"
aNewRec[3]=12.5
APPEND FROM ARRAY aNewRec   && 添加包含数组内容的记录
          && 到表中