[libgda] Misc. corrections
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Misc. corrections
- Date: Tue, 19 Jul 2011 20:31:00 +0000 (UTC)
commit 98d52e6b834fb115d71cee4fc5d1f29688885bff
Author: Vivien Malerba <malerba gnome-db org>
Date: Tue Jul 19 22:21:51 2011 +0200
Misc. corrections
libgda-ui/gdaui-raw-form.c | 2 +-
libgda/gda-data-model.c | 32 ++++++++++++++++++++++++++++++--
libgda/gda-data-proxy.c | 30 ++++++++++--------------------
libgda/gda-row.c | 4 ++--
tests/data-model-errors.c | 11 +++++++----
5 files changed, 50 insertions(+), 29 deletions(-)
---
diff --git a/libgda-ui/gdaui-raw-form.c b/libgda-ui/gdaui-raw-form.c
index 0b8f54c..0a86eaa 100644
--- a/libgda-ui/gdaui-raw-form.c
+++ b/libgda-ui/gdaui-raw-form.c
@@ -711,7 +711,7 @@ action_commit_cb (G_GNUC_UNUSED GtkAction *action, GdauiRawForm *form)
}
/* get to a correct selected row */
- for (; !gda_data_model_iter_move_to_row (form->priv->iter, row) && (row >= 0); row--);
+ for (; (row >= 0) &&!gda_data_model_iter_move_to_row (form->priv->iter, row); row--);
}
static void
diff --git a/libgda/gda-data-model.c b/libgda/gda-data-model.c
index f09cd24..0d20057 100644
--- a/libgda/gda-data-model.c
+++ b/libgda/gda-data-model.c
@@ -711,8 +711,14 @@ gda_data_model_get_attributes_at (GdaDataModel *model, gint col, gint row)
if (GDA_DATA_MODEL_GET_CLASS (model)->i_get_attributes_at)
return (GDA_DATA_MODEL_GET_CLASS (model)->i_get_attributes_at) (model, col, row);
- else
- return 0;
+ else {
+ GdaDataModelAccessFlags flags;
+ GdaValueAttribute attrs = GDA_VALUE_ATTR_NO_MODIF;
+ flags = gda_data_model_get_access_flags (model);
+ if (flags & GDA_DATA_MODEL_ACCESS_WRITE)
+ attrs = 0;
+ return attrs;
+ }
}
/**
@@ -770,6 +776,28 @@ gda_data_model_set_values (GdaDataModel *model, gint row, GList *values, GError
if (GDA_DATA_MODEL_GET_CLASS (model)->i_set_values)
return (GDA_DATA_MODEL_GET_CLASS (model)->i_set_values) (model, row, values, error);
+ else if (GDA_DATA_MODEL_GET_CLASS (model)->i_set_value_at) {
+ /* save the values */
+ gint col, ncols;
+ ncols = gda_data_model_get_n_columns (model);
+ if (g_list_length (values) > ncols) {
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_VALUES_LIST_ERROR,
+ "%s", _("Too many values in list"));
+ return FALSE;
+ }
+
+ for (col = 0;
+ (col < ncols) && values;
+ col++, values = values->next) {
+ const GValue *cvalue;
+ cvalue = (const GValue*) values->data;
+ if (!cvalue)
+ continue;
+ if (! gda_data_model_set_value_at (model, col, row, cvalue, error))
+ return FALSE;
+ }
+ return TRUE;
+ }
else {
/* method not supported */
g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_FEATURE_NON_SUPPORTED_ERROR,
diff --git a/libgda/gda-data-proxy.c b/libgda/gda-data-proxy.c
index acf5dac..6e19e66 100644
--- a/libgda/gda-data-proxy.c
+++ b/libgda/gda-data-proxy.c
@@ -1998,50 +1998,40 @@ commit_row_modif (GdaDataProxy *proxy, RowModif *rm, gboolean adjust_display, GE
else {
if (rm->model_row >= 0) {
/* update the row */
- GSList *list;
GList *values = NULL;
gint i;
- gboolean newvalue_found;
- GValue *newvalue;
- GValue **free_val;
g_assert (rm->modify_values);
g_assert (rm->orig_values);
- free_val = g_new0 (GValue *, proxy->priv->model_nb_cols);
for (i=0; i < rm->orig_values_size; i++) {
- newvalue_found = FALSE;
- newvalue = NULL;
+ gboolean newvalue_found = FALSE;
+ GValue *newvalue = NULL;
+ GSList *list;
- list = rm->modify_values;
- while (list && !newvalue_found) {
+ for (list = rm->modify_values; list; list = list->next) {
if (ROW_VALUE (list->data)->model_column == i) {
newvalue_found = TRUE;
if (g_value_get_flags (ROW_VALUE (list->data)->attributes) &
GDA_VALUE_ATTR_IS_DEFAULT)
newvalue = NULL;
else {
- if (! ROW_VALUE (list->data)->value) {
+ if (! ROW_VALUE (list->data)->value)
newvalue = gda_value_new_null ();
- free_val [i] = newvalue;
- }
else
- newvalue = ROW_VALUE (list->data)->value;
+ newvalue = gda_value_copy (ROW_VALUE (list->data)->value);
}
+ break;
}
- list = g_slist_next (list);
}
- if (!newvalue_found)
- newvalue = rm->orig_values[i];
+ if (!newvalue_found && rm->orig_values[i])
+ newvalue = gda_value_copy (rm->orig_values[i]);
values = g_list_append (values, newvalue);
}
err = ! gda_data_model_set_values (proxy->priv->model, rm->model_row,
values, error);
+ g_list_foreach (values, (GFunc) gda_value_free, NULL);
g_list_free (values);
- for (i = 0; i < proxy->priv->model_nb_cols; i++)
- if (free_val [i])
- gda_value_free (free_val [i]);
- g_free (free_val);
}
else {
/* insert a new row */
diff --git a/libgda/gda-row.c b/libgda/gda-row.c
index 040d47e..9fda297 100644
--- a/libgda/gda-row.c
+++ b/libgda/gda-row.c
@@ -252,7 +252,7 @@ void
gda_row_invalidate_value (G_GNUC_UNUSED GdaRow *row, GValue *value)
{
gda_value_set_null (value);
- G_VALUE_TYPE (value) = G_TYPE_NONE;
+ G_VALUE_TYPE (value) = G_TYPE_INVALID;
}
/**
@@ -269,7 +269,7 @@ gda_row_invalidate_value (G_GNUC_UNUSED GdaRow *row, GValue *value)
gboolean
gda_row_value_is_valid (G_GNUC_UNUSED GdaRow *row, GValue *value)
{
- return (G_VALUE_TYPE (value) == G_TYPE_NONE) ? FALSE : TRUE;
+ return (G_VALUE_TYPE (value) == G_TYPE_INVALID) ? FALSE : TRUE;
}
/**
diff --git a/tests/data-model-errors.c b/tests/data-model-errors.c
index aa60ff7..ef15919 100644
--- a/tests/data-model-errors.c
+++ b/tests/data-model-errors.c
@@ -167,7 +167,6 @@ data_model_errors_init (DataModelErrors *model,
}
}
-
g_ptr_array_add (model->priv->rows, row);
}
}
@@ -376,7 +375,7 @@ data_model_errors_get_attributes_at (GdaDataModel *model, gint col, G_GNUC_UNUSE
return 0;
}
- flags = GDA_VALUE_ATTR_NO_MODIF;
+ flags = 0;
return flags;
}
@@ -402,12 +401,16 @@ data_model_errors_set_value_at (GdaDataModel *model, gint col, gint row, const G
drow = g_ptr_array_index (imodel->priv->rows, row);
if (drow) {
GValue *dvalue;
- dvalue = gda_row_get_value (drow, row);
+ dvalue = gda_row_get_value (drow, col);
+ gda_value_reset_with_type (dvalue, G_VALUE_TYPE (value));
g_value_copy (value, dvalue);
+ gda_data_model_row_updated (model, row);
}
- else
+ else {
g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_NOT_FOUND_ERROR,
"%s", "Row not found");
+ retval = FALSE;
+ }
return retval;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]