table add missing row, table write or add missing row
As a first step, the table will be checked if there is a match in the columns specified in the 2nd function parameter with
the data in the 3rd function parameter. The comparison technique to find the corresponding table row is the same as
in the function table find(), including wildcards supported.
If no matching row has been found, then a new row will be added with the columns and values provided in the 2nd and 3rd
function parameters, and, if avaiable, with the 4th and 5th function parameters, too. Header names specified in the
4th function parameter which are still missing in the table will be created in order to include the data in the table.
However, if a matching row has been found, no futher actions happen if the function table add missing row is called,
or table write or add missing row with only 3 parameters is called (i.e. no further data to write).
Otherwise, the further data entries will be written to the table in the identified row.
Indirect parameter passing is disabled
3 or 5
No. | Type | Description |
---|---|---|
1. input |
string | name of new or existing table Table must be existing when using table append... functions. Otherwise, it does not matter. |
2 input |
table columns | Header names and/or column numbers to compare See table columns as function parameters for general ruling for this parameter.
|
3 input |
set or string | Comparison values or patterns The nummber of elements must match with the number of headers (2nd function parameter).
Specify the comparison patterns.
|
Opt. 4. input |
table columns | Further header names and/or column numbers to add See table columns as function parameters for general ruling for this parameter.
|
Opt. 5 input |
set | Further data to add or write All data written to the table must be put into set and passed in this function parameter, even if only one
string value is provided. The number of elements must not exceed the number of table columns specified but may be lower.
If fewer data elements are specified, then the remaining fields will not be overwritten.
|
Type | Description |
---|---|
numeral | Row number accessed Returns row number accessed. If a row has been added, then it is the new row number at the end of the table. |
table initialize ( t,
{ { Animal, leg count, size, intelligence },
{ Worm, 0, very small, low},
{ Worm, 0, very small too, low},
{ Fox, 4, quite small, medium } });
row[] = table write or add missing row( t, { Animal, size }, { Worm, very small too }, intelligence, { negligible } );
echo("Worm updated in row ", row[] );
row[] = table write or add missing row( t, { Animal, size }, { Whale, huge }, intelligence, { quite high } );
echo("Whale added in row ", row[] );
row[] = table write or add missing row( t, Animal, { Fox } ); //
echo("Fox is in row ", row[] );
row[] = table add missing row( t, { Animal, leg count}, { Fox, 4 } ); // Already existing
echo("Fox with 4 legs already exists in in row ", row[] );
row[] = table add missing row( t, { Animal, leg count}, { Fly, 6 }, { size }, { little } ); // Already existing
echo("Fly added in row ", row[] );
echo;
table list ( t );
Worm updated in row 2
Whale added in row 4
Fox is in row 3
Fox with 4 legs already exists in in row 3
Fly added in row 5
0 : Animal | leg count | size | intelligence
1 : Worm | 0 | very small | low
2 : Worm | 0 | very small too | negligible
3 : Fox | 4 | quite small | medium
4 : Whale | | huge | quite high
5 : Fly | 6 | little |