table configure

Prev Next

Function Names

table configure

Description

This function applies configuration settings to all tables specified. These configuration settings affect the following cases:

  • Behavior on row not found, e.g. when referencing tables = [ table: Name, Mike, Phone Nr ] where "Mike" is not in the table
  • Behavior on column not found, e.g. when referencing header names
  • Behavior or reading values, i.e. enabling / disabling automatic conversion to numerals, booleans and dates.

Attention: The table configuration settings are retained even if the table is initialized or cleared, but not if new contents are loaded from a file or destination table for table transpose(…) and table copy table (…).. In order restore default configuration, do them with this function call or delete and then re-initialize the table. Available: configuration parameter names:

Configuration Parameter Name Configuration Parameter Values Explanation
row not found Behavior if a table row cannot be found if a table is accessed by a content where the first row with matching content will be used.
Example case: [table : Name, Mike, Phone Nr] is referenced, but no row with "Mike" as name is found.
exception Default value. Exception asserted. Or -1 if row number is retrieved, e.g. in [table : Name, Mike ]
header row Return the header row instead. Exception asserted in case no header row is available.
first row Return the first row instead. Exception asserted if this row is not existing.
last row Return the last row istead. Exception asserted if this row is not existing.
new row Creates a new row. See description further below.
column not found
exception Default value. Exception asserted. E.g. in [table: Last Name, 1 ] where "Last Name" does not exist as a header name.
first column Refer to first column (column 0) instead.
last column Refer to last column at the right instead.
new column Create a new column with the specified name, even when using this option for reading data.
read numerals 'no' or 'yes' Table contents looking like numbers (incl. minus sign, decial point) will be read as numbers
scientific notation 'no' or 'yes' Table contents looking like numbers in scientific notation format will be read as numbers
read booleans 'no' or 'yes' 'true' and 'false' will be converted to boolean values
read dates 'no' or 'yes' Table contents looking like recognizable dates and times will be converted to dates. Only ISO 8601 formats are accepted, i.e. YYYY-MM-DD, hh:mm:ss, or YYYY-MM-DD hh:mm:ss, as only this format avoids any ambiguities.
blank to zero 'no' or 'yes' Blank fields will be read as 0 (zero).

Case on new rows created A new row, with the contents inserted will be created.
Example 1: [ table : last name, Bonaparte, first name ] = Napoleon;
A new row will be created and two fields ('last name' and 'first name' will be written as specified.
Example 2: row number [] = [ table : last name, Bonaparte ];
The row number of the new row, where last name has already been filled in, will be returned.
first name [ ] = [ table, last name, Bonaparte, first name ] returns a blank because these contents in the new row are not yet written

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

3, 5, 7, ...

Parameters

No.TypeDescription
Min. 1
input
set or string Names of existing tables

Use string to specify a single table, or a set or softquoted string (single quotation marks) with names separated by comma to specify multiple tables.

2, 4, ...
input
string Configuration parameter names

Valid names: See table above

3, 5, ...
input
string Configuration parameter values

Valid values: See table above. Different set of values apply for different configuration parameter names.

Examples

               table initialize( a,
               { { Name, Answer, Date,         Time,       Blank, Number, Scientific },
                 { Nic,  TRUE,   '2020-01-03', '15:30:00', '', '123', '1.2E+3' } } );

               for all table columns( a, 0, col[], x[] ) echo( [a:x[],1] , "  (", type( [a:x[],1] ), ")" );

               table configure( a, read dates, yes, read booleans, yes, blank to zero, yes, scientific notation, yes );
               echo;
               for all table columns( a, 0, col[], x[] ) echo( [a:x[],1] , "  (", type( [a:x[],1] ), ")" );

               table append ( a,  { Jim } );

               echo( [a:Name,John] );   // Returns -1 as row number.  When refering to other columsn; Exception
               table configure( a, row not found, header row );
               echo( [a:Name,John] ); // Header row

               table configure( a, column not found, new column );
               [a:Color,1] = green; // Creates an additional header called "Color" instead of asserting an exception
               echo( "Header names: ", [a:..,0]);
               echo( [a:Color,1] );

Output

Nic  (string)
TRUE  (string)
2020-01-03  (string)
15:30:00  (string)
  (string)
123  (numeral)
1.2E+3  (string)

Nic  (string)
true  (boolean)
2020-01-03  (date)
15:30:00  (date)
0  (numeral)
123  (numeral)
1.2E+3  (numeral)
-1
0
Header names: {'Name','Answer','Date','Time','Blank','Number','Scientific','Color'}
green
Try it yourself: Open LIB_Function_table_configure.b4p in B4P_Examples.zip. Decompress before use.