table check headers, table check headers silently
THis function checks the table for column headers in a smart way according to specific rules you can provide. If no further options are specified, then just the existence of the headers will be checked. The function table check headers silently suppresses exceptions in case the header check fails and returns appropriate return values instead.
Indirect parameter passing is disabled
Min 2
No. | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 input |
string | Name of existing table | ||||||||||||||||||||
2 input |
table columns | Header names and/or column numbers See table columns as function parameters for general ruling for this parameter.
| ||||||||||||||||||||
Opt. 3 input |
string | Check header option 1 This option affects the header checking rules. See table below for available values. The value n used in the table below stands for number of columns in row 0.
Default value: must exist | ||||||||||||||||||||
Opt. 4, 5, etc. input |
string | Additional option(s) Additional checking options:
|
Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
string | Feedback ok (lower case) is returned if no issues have been identified.
|
Table not found
Various exceptions resulting from issues identified while checking headers
table initialize ( table 1,
{ { Name, Street, Town, Country }, { Miller, "..." } } );
echo("1. Demonstrate 'must not exist':");
echo( table check headers silently( table 1, {"State", "Province"}, must not exist ) ); // OK
echo( table check headers silently( table 1, {"Town", "State"} , must not exist ) ); // Not OK
echo( table check headers silently( table 1, 10, must not exist ) ); // OK
echo( table check headers silently( table 1, -1, must not exist ) ); // Not OK (last column exists)
echo;
echo("2. Demonstrate 'may exist':");
echo( table check headers silently( table 1, {"State", "Province"}, may exist ) ); // Empty and OK
echo( table check headers silently( table 1, {"Town", "Province"}, may exist ) ); // OK
echo( table check headers silently( table 1, {"Town", "State"} , may exist ) ); // OK
echo( table check headers silently( table 1, 10, must not exist ) ); // OK
echo( table check headers silently( table 1, -11, must not exist ) ); // Not OK (range error)
echo;
echo("3. Demonstrate 'create if missing':");
table copy table ( table 1, table 2 );
echo( table check headers silently( table 2, {"State", "City"}, create if missing ) ); // OK
echo( "Header row: ", [table 2: .., 0 ] );
echo;
echo("4. Demonstrate 'must exist':");
echo( table check headers silently( table 1, {"Name", "Town"}, must exist ) ); // OK
echo( table check headers silently( table 1, {"Name", "State"} , must exist ) ); // Not OK
echo( table check headers silently( table 1, 10, must exist ) ); // Not OK
echo( table check headers silently( table 1, -1, must exist ) ); // OK (last column exists)
echo( table check headers silently( table 1, {}, must exist ) ); // Empty and oK
echo;
echo("5. Demonstrate 'unique':");
table initialize ( table 2,
{ { Name, Street, Town, Country, Town }, { Miller, "..." } } );
echo( table check headers silently( table 1, "Town", unique ) ); // OK
echo( table check headers silently( table 2, "Town", unique ) ); // Not OK
echo( table check headers silently( table 2, -1, unique ) ); // Not OK (Also "Town")
echo;
echo("6. Demonstrate 'full match':");
echo( table check headers silently( table 1, { Country, Town, Street, Name }, full match ) ); // OK
echo( table check headers silently( table 1, { 1,3,2,0 }, full match ) ); // OK
echo( table check headers silently( table 1, { Country, Town, Street, Name, Name }, full match ) ); // Not OK
echo;
echo("7. Demonstrate 'sequence':");
echo( table check headers silently( table 1, { Name, Country }, sequence ) ); // OK
echo( table check headers silently( table 1, { Country, Name }, sequence ) ); // Not OK
echo( table check headers silently( table 1, { 0,2,3 }, sequence ) ); // OK
echo( table check headers silently( table 1, { 0,3,2 }, sequence ) ); // Not OK
echo;
echo("8.Demonstrate 'strict sequence':");
echo( table check headers silently( table 1, { Name, Country }, strict sequence ) ); // Not OK
echo( table check headers silently( table 1, { Town, Country }, strict sequence ) ); // OK
echo( table check headers silently( table 1, { 0,1,2 }, strict sequence ) ); // OK
echo( table check headers silently( table 1, { 0,3,3 }, strict sequence ) ); // Not OK
echo;
echo("9. Demonstrate 'identical':");
echo( table check headers silently( table 1, { Name, Street, Town, Country }, identical ) ); // OK
echo( table check headers silently( table 1, { Street, Name, Town, Country }, identical ) ); // Not OK
echo( table check headers silently( table 1, { 0,1,2,3 }, identical) ); // OK
echo( table check headers silently( table 1, { -4,-3,-2,-1 }, identical ) ); // Also OK
echo;
echo("10. Demonstrate 'no repetition':");
echo( table check headers silently( table 1, { Name, Town, Town }, must exist ) ); // OK
echo( table check headers silently( table 1, { Name, Town, Town }, must exist, no repetition ) ); // Not OK
echo;
echo("11. Demonstrate 'no numbers':");
echo( table check headers silently( table 1, { Name, Town }, must exist, no numbers ) ); // OK
echo( table check headers silently( table 1, { Name, 2 }, must exist, no numbers ) ); // Not OK
echo;
echo("12. Demonstrate 'no blanks':");
echo( table check headers silently( table 1, { Name, Town, "" }, must exist, no blanks ) ); // Not OK
echo;
echo("13. Demonstrate 'ignore blanks':");
echo( table check headers silently( table 1, { Name, Town, "" }, must exist, ignore blanks ) ); // OK
echo;
echo("14. Demonstrate 'max 1':");
echo( table check headers silently( table 1, { Name, Town }, must exist, max 1 ) ); // Not OK
echo( table check headers silently( table 1, { Name }, must exist, max 1 ) ); // OK
echo( table check headers silently( table 1, { }, must exist, max 1 ) ); // OK
1. Demonstrate 'must not exist':
ok
already existing
ok
already existing
2. Demonstrate 'may exist':
empty and ok
ok
ok
ok
range error
3. Demonstrate 'create if missing':
ok
Header row: {'Name','Street','Town','Country','State','City'}
4. Demonstrate 'must exist':
ok
not found
range error
ok
empty and ok
5. Demonstrate 'unique':
ok
duplicate
duplicate
6. Demonstrate 'full match':
ok
ok
no full match
7. Demonstrate 'sequence':
ok
incorrect sequence
ok
incorrect sequence
8.Demonstrate 'strict sequence':
incorrect sequence
ok
ok
incorrect sequence
9. Demonstrate 'identical':
ok
incorrect sequence
ok
ok
10. Demonstrate 'no repetition':
ok
repeated
11. Demonstrate 'no numbers':
ok
forbidden number
12. Demonstrate 'no blanks':
forbidden blank
13. Demonstrate 'ignore blanks':
ok
14. Demonstrate 'max 1':
wrong count
ok
empty and ok