Fixed bugs in the process ensuring that all the columns of a view have

the same line count, fixed a bug when trying to set a value in a view
when a line selection exists, fixed a bug when adding a new column to a
view where line counts would be wrong
This commit is contained in:
Celine Mercier
2016-09-21 17:42:17 +02:00
parent bb25723d99
commit e79507b629

View File

@ -712,9 +712,7 @@ int update_lines(Obiview_p view, index_t line_count)
for (i=0; i<((view->infos)->column_count); i++)
{
while (line_count > (((view->columns)[i])->header)->line_count)
{ // The column needs to be enlarged
// Clone it first if needed
// Clone the column first if needed
if (!(((view->columns)[i])->writable))
{
if (clone_column_in_view(view, (((view->infos)->column_references)[i]).alias) < 0)
@ -723,11 +721,14 @@ int update_lines(Obiview_p view, index_t line_count)
return -1;
}
}
// Enlarge the column
// Enlarge the column if needed
while (line_count > (((view->columns)[i])->header)->line_count)
{
if (obi_enlarge_column(((view->columns)[i])) < 0)
return -1;
(((view->columns)[i])->header)->lines_used = line_count;
}
// Set the number of lines used to the new view line count
(((view->columns)[i])->header)->lines_used = line_count;
}
(view->infos)->line_count = line_count;
@ -815,28 +816,14 @@ int prepare_to_set_value_in_column(Obiview_p view, OBIDMS_column_p* column_pp, i
// Check that the view is not read-only
if (view->read_only)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError trying to set a value in a column in a read-only view");
return -1;
}
/* // If there is a new line selection being created, columns can't be modified // TODO investigate this
if (view->new_line_selection != NULL)
{
obi_set_errno(OBIVIEW_ERROR);
obidebug(1, "\nError trying to set a value in a column in a view with a new line selection being created");
return -1;
}
*/
// If there is a line selection associated with the view or if the column
// is read-only, all columns or this column respectively must be cloned
if ((view->line_selection != NULL) || (!((*column_pp)->writable)))
{
// Get the right line number
if (view->line_selection != NULL)
(*line_nb_p) = *(((index_t*) ((view->line_selection)->data)) + (*line_nb_p));
// Get the name/alias of the column from the pointer
for (i=0; i<((view->infos)->column_count); i++)
{
@ -877,7 +864,7 @@ int prepare_to_get_value_from_column(Obiview_p view, index_t* line_nb_p)
return -1;
}
if (view->line_selection)
if (view->line_selection != NULL)
(*line_nb_p) = *(((index_t*) ((view->line_selection)->data)) + (*line_nb_p));
return 0;
@ -1230,6 +1217,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
free(view);
return NULL;
}
(view->infos)->all_lines = false;
(view->infos)->line_count = 0;
i = 0;
@ -1342,7 +1330,7 @@ Obiview_p obi_new_view(OBIDMS_p dms, const char* view_name, Obiview_p view_to_cl
(((view_to_clone->columns)[i])->header)->version,
(((view_to_clone->infos)->column_references)[i]).alias,
0,
(view->infos)->line_count,
0,
0,
NULL,
NULL,
@ -1490,8 +1478,15 @@ Obiview_infos_p obi_view_map_file(OBIDMS_p dms, const char* view_name)
obiview_file_descriptor = openat(dms->view_dir_fd, file_name, O_RDWR, 0777);
if (obiview_file_descriptor < 0)
{
obi_set_errno(OBIVIEW_ERROR);
if (errno == ENOENT)
{
obidebug(1, "\nError opening an obiview file: View %s does not exist", view_name);
}
else
{
obidebug(1, "\nError opening an obiview file");
}
obi_set_errno(OBIVIEW_ERROR);
free(file_name);
return NULL;
}
@ -1680,7 +1675,7 @@ int obi_view_add_column(Obiview_p view,
else
current_line_selection = view->line_selection;
if (current_line_selection != NULL)
if (create && (current_line_selection != NULL))
{
for (i=0; i<((view->infos)->column_count); i++)
{
@ -1701,7 +1696,6 @@ int obi_view_add_column(Obiview_p view,
obi_close_column(column_buffer);
}
}
}
// Close old line selections
if (view->line_selection != NULL)
@ -1717,20 +1711,27 @@ int obi_view_add_column(Obiview_p view,
obi_close_column(view->new_line_selection);
view->new_line_selection = NULL;
}
}
// Update the line count
// Update the line count if needed
if (create)
{
if ((view->infos)->line_count > nb_lines)
nb_lines = (view->infos)->line_count;
else if (nb_lines > (view->infos)->line_count)
update_lines(view, nb_lines);
}
// Open or create the column
if (create)
{ // Create column
column = obi_create_column(view->dms, column_name, data_type, nb_lines, nb_elements_per_line, elements_names, indexer_name, associated_column_name, associated_column_version, comments);
(column->header)->lines_used = nb_lines;
}
else
{ // Open column
// TODO do we require that the column's line count is equal to the view's line count?
// or do we enlarge the column or the view as needed?
column = obi_open_column(view->dms, column_name, version_number);
}
@ -1750,9 +1751,8 @@ int obi_view_add_column(Obiview_p view,
// Save column alias
strcpy((((view->infos)->column_references)[(view->infos)->column_count]).alias, alias);
// Update column count in view
(view->infos)->column_count++;
if ((view->infos)->column_count == 1) // first column in the view
(view->infos)->line_count = nb_lines;
// Update column references and dictionary
update_column_refs_and_dict(view);
@ -1908,7 +1908,7 @@ int obi_select_line(Obiview_p view, index_t line_nb)
}
}
// If we are already working on a line selection, get the pointed line number
// If there is already a line selection, get the pointed line number
if (view->line_selection)
line_nb = obi_column_get_index(view->line_selection, line_nb);