Basic Techniques
The main operations that can be performed on a row are:
*Insert a row (see IliTable::insertRow)
*Modify a row (see IliTable::updateRow)
*Delete a row (see IliTable::deleteRow)
*Inspect a row (see getValue and rowToBuffer)
These member functions do not give access to the actual row implementation. Instead, they make use of the IliTableBuffer class that can store a copy of the values in a row.
This means that any updates to a table are always carried out on a complete row. The user edits one complete row at a time, therefore avoiding — in the case of IliSQLTable objects — time consuming network activity by validating changes in a complete row.
In addition, it avoids any problems with data coherency that the end user may have. The data in individual columns in a row may apply constraints to each other. For example, having a particular value in one column may limit the values allowed in another column. If the end user must validate a row one column at a time, this problem may occur. When a whole row is validated at one time, the problem is avoided.
A table buffer is created using the IliTable::getBuffer method. The table buffer must be released using the IliTable::releaseBuffer method when it is no longer needed.
Note that rows are identified by their position within the table object. This is represented by an integer, starting with zero for the first row.
The following code sample shows how to insert a new row into the memory table created in the previous example:
IliTableBuffer* buf = tbl->getBuffer();
buf->at(IdColumn).importInteger(1);
buf->at(NameColumn).importString(“Smith”);
buf->at(SalaryColumn).importDouble(255.00);
if (tbl->appendRow(buf) < 0) {
IlvPrint(“Append row failed”);
}
tbl->releaseBuffer(buf);
The at member function returns a reference to an IliValue object that stores the value of the column, whose index is given. The importInteger and importString member functions are then used to assign the id and name to the buffer values. Finally, IliTable::appendRow is called to insert a new row into the table.
The following code sample shows how a row in a table can be modified:
IliTableBuffer* buf = tbl->getBuffer();
IlInt rowno = 10;
if (!buf->rowToBuffer(rowno)) {
IlvPrint(“Invalid row number : %ld”, (long)rowno);
}
IlDouble salary = buf->at(SalaryColumn).asDouble();
buf->at(SalaryColumn).importDouble(salary * 1.1);
if (!tbl->updateRow(rowno, buf)) {
IlvPrint(“Update row failed”);
}
tbl->releaseBuffer(buf);
The rowToBuffer member function copies the row at the specified index into the buffer.
The following code sample shows how a row can be removed from a table by calling the IliTable::deleteRow member function:
IlInt rowno = 15;
tbl->deleteRow(rowno);
Additional member functions are provided in the IliTable class that allow you to move a row in a table, sort a table, or search for a given value in a table. For more information, refer to the moveRow, findRow, findFirstRow, and sortRows member functions in the IliTable class documented in the Views Data Access Reference Manual.
Published date: 05/24/2022
Last modified date: 02/24/2022