[libgda/LIBGDA_4.0] Corrected the "Row out of range..." error message
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Subject: [libgda/LIBGDA_4.0] Corrected the "Row out of range..." error message
- Date: Wed, 8 Jul 2009 19:23:31 +0000 (UTC)
commit 0aa985556be3bb6c35d36cbf49bb95eff10d430c
Author: Vivien Malerba <malerba gnome-db org>
Date: Wed Jul 8 14:25:28 2009 +0200
Corrected the "Row out of range..." error message
when data model is empty, to avoid messages like
"Row 0 out of range (0--1)"
libgda/gda-data-model-array.c | 28 ++++++++++++++++++++--------
libgda/gda-data-model-dir.c | 23 ++++++++++++++++-------
libgda/gda-data-model-dsn-list.c | 13 +++++++++----
libgda/gda-data-proxy.c | 24 +++++++++++++++++-------
libgda/gda-data-select.c | 25 ++++++++++++++++++-------
5 files changed, 80 insertions(+), 33 deletions(-)
---
diff --git a/libgda/gda-data-model-array.c b/libgda/gda-data-model-array.c
index 66050cd..edeb444 100644
--- a/libgda/gda-data-model-array.c
+++ b/libgda/gda-data-model-array.c
@@ -1,5 +1,5 @@
/* GDA library
- * Copyright (C) 1998 - 2008 The GNOME Foundation.
+ * Copyright (C) 1998 - 2009 The GNOME Foundation.
*
* AUTHORS:
* Rodrigo Moya <rodrigo gnome-db org>
@@ -383,9 +383,13 @@ gda_data_model_array_get_row (GdaDataModelArray *model, gint row, GError **error
g_return_val_if_fail (GDA_IS_DATA_MODEL_ARRAY (model), NULL);
if (row >= model->priv->rows->len) {
- g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
- _("Row %d out of range (0-%d)"), row,
- model->priv->rows->len- 1);
+ if (model->priv->rows->len > 0)
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d out of range (0-%d)"), row,
+ model->priv->rows->len - 1);
+ else
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d not found (empty data model)"), row);
return NULL;
}
@@ -526,8 +530,12 @@ gda_data_model_array_get_value_at (GdaDataModel *model, gint col, gint row, GErr
}
if (row >= amodel->priv->rows->len) {
- g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
- _("Row %d out of range (0-%d)"), row, amodel->priv->rows->len - 1);
+ if (amodel->priv->rows->len > 0)
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d out of range (0-%d)"), row, amodel->priv->rows->len - 1);
+ else
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d not found (empty data model)"), row);
return NULL;
}
@@ -609,8 +617,12 @@ gda_data_model_array_set_value_at (GdaDataModel *model, gint col, gint row,
}
if (row > amodel->priv->rows->len) {
- g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_VALUES_LIST_ERROR,
- _("Row %d out of range (0-%d)"), row, amodel->priv->rows->len);
+ if (amodel->priv->rows->len > 0)
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_VALUES_LIST_ERROR,
+ _("Row %d out of range (0-%d)"), row, amodel->priv->rows->len - 1);
+ else
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d not found (empty data model)"), row);
return FALSE;
}
diff --git a/libgda/gda-data-model-dir.c b/libgda/gda-data-model-dir.c
index 6e012c5..2c80cc3 100644
--- a/libgda/gda-data-model-dir.c
+++ b/libgda/gda-data-model-dir.c
@@ -1,5 +1,5 @@
/* GDA common library
- * Copyright (C) 2007 - 2008 The GNOME Foundation
+ * Copyright (C) 2007 - 2009 The GNOME Foundation
*
* AUTHORS:
* Vivien Malerba <malerba gnome-db org>
@@ -799,8 +799,11 @@ gda_data_model_dir_get_value_at (GdaDataModel *model, gint col, gint row, GError
if (row >= imodel->priv->rows->len) {
gchar *str;
- str = g_strdup_printf (_("Row %d out of range (0-%d)"), row,
- imodel->priv->rows->len - 1);
+ if (imodel->priv->rows->len > 0)
+ str = g_strdup_printf (_("Row %d out of range (0-%d)"), row,
+ imodel->priv->rows->len - 1);
+ else
+ str = g_strdup_printf (_("Row %d not found (empty data model)"), row);
add_error (imodel, str);
g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
"%s", str);
@@ -968,8 +971,11 @@ gda_data_model_dir_set_values (GdaDataModel *model, gint row, GList *values, GEr
if (row >= imodel->priv->rows->len) {
gchar *str;
- str = g_strdup_printf (_("Row %d out of range (0-%d)"), row,
- imodel->priv->rows->len - 1);
+ if (imodel->priv->rows->len > 0)
+ str = g_strdup_printf (_("Row %d out of range (0-%d)"), row,
+ imodel->priv->rows->len - 1);
+ else
+ str = g_strdup_printf (_("Row %d not found (empty data model)"), row);
add_error (imodel, str);
g_set_error (error, 0, 0, "%s", str);
g_free (str);
@@ -1315,8 +1321,11 @@ gda_data_model_dir_remove_row (GdaDataModel *model, gint row, GError **error)
if (row >= imodel->priv->rows->len) {
gchar *str;
- str = g_strdup_printf (_("Row %d out of range (0-%d)"), row,
- imodel->priv->rows->len - 1);
+ if (imodel->priv->rows->len > 0)
+ str = g_strdup_printf (_("Row %d out of range (0-%d)"), row,
+ imodel->priv->rows->len - 1);
+ else
+ str = g_strdup_printf (_("Row %d not found (empty data model)"), row);
add_error (imodel, str);
g_set_error (error, 0, 0, "%s", str);
g_free (str);
diff --git a/libgda/gda-data-model-dsn-list.c b/libgda/gda-data-model-dsn-list.c
index f6138ff..3a70617 100644
--- a/libgda/gda-data-model-dsn-list.c
+++ b/libgda/gda-data-model-dsn-list.c
@@ -1,5 +1,5 @@
/* GDA library
- * Copyright (C) 2007 - 2008 The GNOME Foundation.
+ * Copyright (C) 2007 - 2009 The GNOME Foundation.
*
* AUTHORS:
* Vivien Malerba <malerba gnome-db org>
@@ -312,9 +312,14 @@ gda_data_model_dsn_list_get_value_at (GdaDataModel *model, gint col, gint row, G
return NULL;
}
if ((row < 0) || (row >= gda_data_model_dsn_list_get_n_rows (model))) {
- g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
- _("Row %d out of range (0-%d)"), row,
- gda_data_model_dsn_list_get_n_rows (model) - 1);
+ gint n;
+ n = gda_data_model_dsn_list_get_n_rows (model);
+ if (n > 0)
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d out of range (0-%d)"), row, n - 1);
+ else
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d not found (empty data model)"), row);
return NULL;
}
diff --git a/libgda/gda-data-proxy.c b/libgda/gda-data-proxy.c
index b38f248..7d5a946 100644
--- a/libgda/gda-data-proxy.c
+++ b/libgda/gda-data-proxy.c
@@ -1,6 +1,6 @@
/* gda-data-proxy.c
*
- * Copyright (C) 2005 - 2008 Vivien Malerba
+ * Copyright (C) 2005 - 2009 Vivien Malerba
*
* This Library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
@@ -3386,9 +3386,14 @@ gda_data_proxy_get_value_at (GdaDataModel *model, gint column, gint proxy_row, G
}
else {
/* non existing row, return NULL */
- g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
- _("Row %d out of range (0-%d)"), proxy_row,
- gda_data_model_get_n_rows (model) - 1);
+ gint n;
+ n = gda_data_model_get_n_rows (model);
+ if (n > 0)
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d out of range (0-%d)"), proxy_row, n - 1);
+ else
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d not found (empty data model)"), proxy_row);
retval = NULL;
}
}
@@ -3419,9 +3424,14 @@ gda_data_proxy_get_value_at (GdaDataModel *model, gint column, gint proxy_row, G
}
else {
/* non existing row, return NULL */
- g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
- _("Row %d out of range (0-%d)"), proxy_row,
- gda_data_model_get_n_rows (model) - 1);
+ gint n;
+ n = gda_data_model_get_n_rows (model);
+ if (n > 0)
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d out of range (0-%d)"), proxy_row, n - 1);
+ else
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d not found (empty data model)"), proxy_row);
retval = NULL;
}
}
diff --git a/libgda/gda-data-select.c b/libgda/gda-data-select.c
index 54be975..a8949cb 100644
--- a/libgda/gda-data-select.c
+++ b/libgda/gda-data-select.c
@@ -1609,9 +1609,14 @@ external_to_internal_row (GdaDataSelect *model, gint ext_row, GError **error)
nrows = model->advertized_nrows < 0 ? gda_data_select_get_n_rows ((GdaDataModel*) model) :
model->advertized_nrows;
if ((ext_row < 0) || ((nrows >= 0) && (int_row >= nrows))) {
- g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
- _("Row %d out of range (0-%d)"), ext_row,
- gda_data_select_get_n_rows ((GdaDataModel*) model) - 1);
+ gint n;
+ n = gda_data_select_get_n_rows ((GdaDataModel*) model);
+ if (n > 0)
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d out of range (0-%d)"), ext_row, n - 1);
+ else
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d not found (empty data model)"), ext_row);
return -1;
}
@@ -1659,8 +1664,14 @@ gda_data_select_get_value_at (GdaDataModel *model, gint col, gint row, GError **
int_row = external_to_internal_row (imodel, row, NULL);
if (int_row < 0) {
- g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
- _("Row %d out of range (0-%d)"), row, gda_data_select_get_n_rows (model) - 1);
+ gint n;
+ n = gda_data_select_get_n_rows ( model);
+ if (n > 0)
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d out of range (0-%d)"), row, n - 1);
+ else
+ g_set_error (error, GDA_DATA_MODEL_ERROR, GDA_DATA_MODEL_ROW_OUT_OF_RANGE_ERROR,
+ _("Row %d not found (empty data model)"), row);
return NULL;
}
@@ -1969,7 +1980,7 @@ update_iter (GdaDataSelect *imodel, GdaRow *prow)
for (i = 0, plist = GDA_SET (iter)->holders;
plist;
i++, plist = plist->next) {
- const GValue *value;
+ GValue *value;
GError *error = NULL;
value = gda_row_get_value (prow, i);
@@ -3043,7 +3054,7 @@ compute_insert_select_params_mapping (GdaSet *sel_params, GdaSet *ins_values, Gd
}
g_assert (cdata.colid);
if (*(cdata.colid) == '"')
- gda_sql_identifier_remove_quotes (cdata.colid);
+ gda_sql_identifier_remove_quotes ((gchar*) cdata.colid);
/*g_print ("SEL param '%s' <=> column named '%s'\n", cdata.hid, cdata.colid);*/
GSList *ins_list;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]