4D v14.3

ARRAY TO SELECTION

Home

 
4D v14.3
ARRAY TO SELECTION

ARRAY TO SELECTION 


 

ARRAY TO SELECTION {( array ; aField {; array2 ; aField2 ; ... ; arrayN ; aFieldN}{; *} )} 
Parameter Type   Description
array  Array in Array to copy to the selection
aField  Field in Field to receive the array data
Operator in Await execution

The ARRAY TO SELECTION command copies one or more arrays into a selection of records. All fields listed must belong to the same table.

If a selection exists at the time of the call, the elements of the array are put into the records, based on the order of the array and the order of the records. If there are more elements than records, new records are created. The records, whether new or existing, are automatically saved.

Note: Since it can create new records, this command does not take a table's read-only state (if any) into account (see Record Locking).

All the arrays must have the same number of elements. If the arrays are of different sizes, a syntax error is generated.

This command does the reverse of SELECTION TO ARRAY. However, the ARRAY TO SELECTION command does not allow fields from different tables, including related tables, even when an automatic relation exists.

When you pass the * parameter, 4D does not execute the corresponding statement line immediately but instead stores it in memory; this way you can stack several lines ending with an *. All of these lines awaiting execution are executed by one final ARRAY TO SELECTION statement that does not have the * parameter. For this reason, the command can now be called without any parameters.
As with the QUERY command, this lets you break up a complex statement into a set of lines, which is easier to read and to maintain. You can also insert intermediary statements.

WARNING: Use ARRAY TO SELECTION with caution, because it overwrites information in existing records. If a record is locked by another process during the execution of ARRAY TO SELECTION, that record is not modified. Any locked records are put into the process set called LockedSet. After ARRAY TO SELECTION has executed, you can test the set LockedSet to see if any records were locked.

Note: This command does not take into account the read-only/read-write state of the table containing the field.

4D Server: The command is optimized for 4D Server. Arrays are sent by the client machine to the server, and the records are modified or created on the server machine. As such a request is handled synchronously, the client machine must wait for the operation to be completed successfully. In the multi-user or multi-process environment, any records that are locked will not be overwritten.

In the following example, the two arrays asLastNames and asCompanies place data in the [People] table. The values from the array asLastNames area placed in the field [People]Last Name and the values from the array asCompanies are placed in the field [People]Company:

 ARRAY TO SELECTION(asLastNames;[People]Last Name;asCompanies;[People]Company)

This example duplicates a selection of records:

 ARRAY TEXT(a1;0)
 ARRAY TEXT(a2;0)
 ARRAY TEXT(a3;0)
 ARRAY TEXT(a4;0)
 
 ALL RECORDS([Table_1])
 For($i;1;Get last field number(1))
    $p:=Get pointer("a"+String($i))
    SELECTION TO ARRAY(Field(1;$i)->;$p->;*)
  // Deferred building of arrays
 End for
 SELECTION TO ARRAY //Execution of statements
 
 REDUCE SELECTION([Table_1];0)
 For($i;1;Get last field number(1))
    $p:=Get pointer("a"+String($i))
    ARRAY TO SELECTION($p->;Field(1;$i)->;*)
  // Building selection
 End for
 ARRAY TO SELECTION //Execution of statements

 
PROPERTIES 

Product: 4D
Theme: Arrays
Number: 261

This command modifies the LockedSet system setThe command changes the current selectionDifferent in remote mode

 
HISTORY 

Modified: 4D v11 SQL
Modified: 4D v13

 
SEE ALSO 

SELECTION TO ARRAY
System Variables

 
ARTICLE USAGE

4D Language Reference ( 4D v14 R2)
4D Language Reference ( 4D v14 R3)
4D Language Reference ( 4D v13.5)
4D Language Reference ( 4D v14.3)
4D Language Reference ( 4D v14 R4)

Inherited from : ARRAY TO SELECTION ( 4D v11 SQL Release 6)