Table table ("some.table"); ROTableRow row (table); // construct TableRow object cout << row.record().description(); // show its description // Get the values in row 17. const TableRecord& record = row.get (17); // column name is "Title", and automatically becomes the record // key for this field of the record: String row17title = record.asString ("Title"); Int row17count = record.asInt ("Count");The simplest constructor will include all columns in the TableRow object (although columns with a non-standard data type will be excluded, because they cannot be represented in a TableRecord). However, it is possible to be more selective and to include only some columns in the TableRow object. The various constructors show how this can be done.
It is possible to have multiple TableRow objects for the same table. They can contain different columns or they can share columns.
On construction an internal TableRecord object is created containing the required fields. The contents of this record will be changed with each get call, but the structure of it is fixed. This means that RORecordFieldPtr objects can be constructed once and used many times. This results in potentially faster access to the record, because it avoids unnecessary name lookups.
// Open the table as readonly and define a row object containing // the given columns. // Note that the function stringToVector is a very convenient // way to construct a Vector<String>. // Show the description of the fields in the row. Table table("Some.table"); ROTableRow row (table, stringToVector("col1,col2,col3")); cout << row.record().description(); // Loop through all rows and get their values. for (uInt i=0; i<table.nrow(); i++) { const TableRecord& values = row.get (i); someString = values.asString ("col1"); somedouble = values.asdouble ("col2"); someArrayInt = values.asArrayInt ("col3"); } // Provided the structure of the record is known, the RecordFieldPtr // objects could be used as follows. // This is faster than the previous method, because it avoids a name // lookup for each iteration. RORecordFieldPtr<String> col1(row.record(), "col1"); RORecordFieldPtr<double> col2(row.record(), "col2"); RORecordFieldPtr<Array<Int> > col3(row.record(), "col3"); for (uInt i=0; i<table.nrow(); i++) { row.get (i); someString = *col1; somedouble = *col2; someArrayInt = *col3; }
Create a ROTableRow object for the given Table.
Its TableRecord will contain all columns except columns with
datatype TpOther (i.e. non-standard data types).
When the flag storedColumnsOnly is True, only the
columns actually stored by a storage manager will be selected.
This is useful when the contents of an entire row has to be copied.
Virtual columns are calculated on-the-fly (often using stored columns),
thus it makes no sense to copy their data.
When the table contains columns with large arrays, it may be better not to use this constructor. Each get will read in all data in the row, thus also the large data array(s). In that case it is better to use the constructor which includes selected columns only.
Create a ROTableRow object for the given Table.
Its TableRecord will contain all columns given in the Vector.
An exception is thrown if an unknown column name is given.
When exclude=True, all columns except the given columns are taken.
In that case an unknown name does not result in an exception.
Copy constructor (copy semantics).
Assignment (copy semantics).
Test if a Table is attached to this object.
Get the Table used for this object.
Get the record containing all fields.
Get the number of the last row read. -1 is returned when no Table is attached or no row has been read yet.
Get a vector consisting of all columns names. This can, for instance, be used to construct a TableRow object with the same columns in another table.
Get the values of all columns used from the given row. When the given row number equals the current one, nothing will be read unless the alwaysRead flag is set to True.
Create the record, column, and field objects for all columns in the table. The writable flag determines if writable or readonly TableColumn objects will be created.
Create the record, column, and field objects for the given columns. The writable flag determines if writable or readonly TableColumn objects will be created.
Put the values found in the internal TableRecord at the given row. This is a helper function for class TableRow.
Put a value in the given field in the TableRecord into the given row and column. This is a helper function for class TableRow.
Set the switch to reread when the current row has been put.
Make a RecordDesc from the table with some excluded column names.
Add a column to the record. When skipOther is True, columns with a non-standard data type will be silently skipped.
Make the required objects. These are the TableRecord and for each column a TableColumn and RecordFieldPtr.
Delete all objects.
put (rownr, tableRecord);can be used to put all values from the given TableRecord, which has to be conforming (i.e. matching order and names). Optionally the conformance is checked. This put function is capable of data type promotion. For instance, if column COL1 is float, the corresponding field in the TableRecord can be Int.
TableRow row (someTable, stringToVector("col1,col2,col3")); RecordFieldPtr<String> col1(row.record(), "col1"); RecordFieldPtr<double> col2(row.record(), "col2"); RecordFieldPtr<Array<Int> > col3(row.record(), "col3"); for (uInt i=0; i<n; i++) { *col1 = someString; *col2 = somedouble; *col3 = someArrayInt; row.put (i); }
putMatchingFields (rownr, tableRecord);can be used to put some fields from the given TableRecord. Only fields having a corresponding name in the TableRow object will be put. Similar to the first way data type promotion will be applied for numeric scalars.
// Open the new table (with 10 rows) and define a row object containing // values from the given column. // Note that the function stringToVector is a very convenient // way to construct a Vector<String>. SetupNewTable newtab(tableDesc, Table::new); Table table(newtab, 10); TableRow row (table, stringToVector("col1,col2,col3,col4")); // Loop through all rows and get their values. for (uInt i=0; i<table.nrow(); i++) { // Some magic filler function returns a filled TableRecord // (with the correct fields in the correct order). TableRecord record = fillerFunction(); row.put (i, record); }
Create a TableRow object for the given Table.
Its TableRecord will contain all columns except columns with
datatype TpOther and columns which are not writable.
When the flag storedColumnsOnly is True, only the
columns actually stored by a storage manager will be selected.
This is useful when the contents of an entire row has to be copied.
Virtual columns are calculated on-the-fly (often using stored columns),
thus it makes no sense to copy their data.
When the table contains columns with large arrays, it may be better not to use this constructor. Each get will read in all data in the row, thus also the large data array(s). In that case it is better to use the next constructor which works selectively.
Create a TableRow object for the given Table.
Its TableRecord will contain all columns given in the Vector.
An exception is thrown if an unknown column name is given
or if a column is given which is not writable.
When exclude=True, all columns except the given columns are taken.
In that case an unknown name does not result in an exception
and non-writable columns are simply skipped.
Copy constructor (copy semantics).
Assignment (copy semantics).
Get non-const access to the TableRecord in this object.
This can be used to change values in it which can thereafter
be put using the function put(rownr).
Put into the last row read. An exception is thrown if no row has been read yet. The values in the TableRecord contained in this object are put. This TableRecord can be accessed and updated using the function record.
Put into the given row. The values in the TableRecord contained in this object are put. This TableRecord can be accessed and updated using the function record.
Put the values found in the TableRecord in the appropriate columns
in the given row.
The names and order of the fields in the TableRecord must conform
those of the description of the TableRow. The data types of numeric
scalars do not need to conform exactly; they can be promoted
(e.g. an Int value in the record may correspond to a float column).
If not conforming, an exception is thrown.
Put the values found in the TableRecord. Only fields with a matching
name in the TableRow object will be put.
This makes it possible to put fields in a selective way.
E.g.: If the TableRow contains columns A and B, and the
record contains fields B and C, only field B will be put.
In principle the data types of the matching fields must match,
but data type promotion of numeric scalars will be applied.