Views: better checks when adding an existing column to a view
This commit is contained in:
@ -2216,10 +2216,13 @@ int obi_view_add_column(Obiview_p view,
|
||||
obidebug(1, "\nError opening a column to add to a view");
|
||||
return -1;
|
||||
}
|
||||
// Check that the column's line count is at least the view's line count if there's a line selection
|
||||
// TODO rediscuss. This can't be more stringent because when cloning a view, if there's a line selection associated,
|
||||
// Check that, if it's not the first column in the view, the column's line count is at least the view's line count if there's a line selection
|
||||
// Otherwise it should be the same line count
|
||||
// TODO rediscuss. When cloning a view, if there's a line selection associated,
|
||||
// when re-adding the columns to the cloned view, it is normal that the columns have a line count greater than the view's.
|
||||
if ((column->header)->line_count < (view->infos)->line_count)
|
||||
if (((view->infos)->column_count > 0)
|
||||
&& (((view->line_selection != NULL) && ((column->header)->lines_used < (view->infos)->line_count))
|
||||
|| ((view->line_selection == NULL) && ((column->header)->lines_used != (view->infos)->line_count))))
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError adding an existing column to a view: the column's line count (%lld) must be at least the view's (%lld) (when there is a line selection)", (column->header)->line_count, (view->infos)->line_count);
|
||||
@ -2244,6 +2247,10 @@ int obi_view_add_column(Obiview_p view,
|
||||
// Save column alias
|
||||
strcpy((((view->infos)->column_references)[(view->infos)->column_count]).alias, alias);
|
||||
|
||||
// If it's the first column of the view, set the view's line count to the column's line count
|
||||
if ((view->infos)->column_count == 0)
|
||||
(view->infos)->line_count = (column->header)->lines_used;
|
||||
|
||||
// Update column count in view
|
||||
(view->infos)->column_count++;
|
||||
|
||||
@ -2282,24 +2289,19 @@ int obi_view_delete_column(Obiview_p view, const char* column_name)
|
||||
found = false;
|
||||
for (i=0; i<((view->infos)->column_count); i++)
|
||||
{
|
||||
column = *((OBIDMS_column_p*)ll_get(view->columns, i));
|
||||
if (column == NULL)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError getting a column from the linked list of column pointers of a view when deleting a column from a view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((!found) && (!strcmp((((view->infos)->column_references)[i]).alias, column_name)))
|
||||
{
|
||||
obi_close_column(column);
|
||||
view->columns = ll_delete(view->columns, i);
|
||||
if (view->columns != NULL)
|
||||
column = *((OBIDMS_column_p*)ll_get(view->columns, i));
|
||||
if (column == NULL)
|
||||
{
|
||||
obi_set_errno(OBIVIEW_ERROR);
|
||||
obidebug(1, "\nError trying to delete a column: column not found in linked list of column pointers");
|
||||
obidebug(1, "\nError getting a column from the linked list of column pointers of a view when deleting a column from a view");
|
||||
return -1;
|
||||
}
|
||||
|
||||
obi_close_column(column);
|
||||
view->columns = ll_delete(view->columns, i);
|
||||
// TODO how do we check for error? NULL can be empty list
|
||||
found = true;
|
||||
}
|
||||
if (found)
|
||||
|
@ -305,7 +305,7 @@ Obiview_p obi_open_view(OBIDMS_p dms, const char* view_name);
|
||||
* NULL or "" if the default names are to be used ("0;1;2;...;n").
|
||||
* @param indexer_name The name of the indexer if there is one associated with the column.
|
||||
* If NULL or "", the indexer name is set as the column name.
|
||||
* @param comments Optional comments associated with the column.
|
||||
* @param comments Optional comments associated with the column if it is created.
|
||||
* @param create Whether the column should be created (create == true) or opened (create == false).
|
||||
*
|
||||
* @returns A value indicating the success of the operation.
|
||||
|
Reference in New Issue
Block a user