[libgda/LIBGDA_4.2] Enable GdaDataModel to report global exceptions



commit 7dd3e5665ffd41094ee8925caedf366f8a3c3228
Author: Vivien Malerba <malerba gnome-db org>
Date:   Mon Apr 18 20:53:10 2011 +0200

    Enable GdaDataModel to report global exceptions
    
    * added GdaDataModel::i_get_exceptions
    * modified GdaDataSelect to implement that interface

 doc/C/libgda-sections.txt                       |    2 +
 libgda/gda-data-model.c                         |   48 ++++++++++++++++++++++-
 libgda/gda-data-model.h                         |    9 ++++-
 libgda/gda-data-select.c                        |   48 +++++++++++++++++++++++
 libgda/libgda.symbols                           |    2 +
 libgda/providers-support/gda-data-select-priv.h |    2 +
 6 files changed, 108 insertions(+), 3 deletions(-)
---
diff --git a/doc/C/libgda-sections.txt b/doc/C/libgda-sections.txt
index 7f27079..b683493 100644
--- a/doc/C/libgda-sections.txt
+++ b/doc/C/libgda-sections.txt
@@ -277,6 +277,7 @@ GdaDataModel
 GdaDataModelError
 gda_data_model_get_n_rows
 gda_data_model_get_n_columns
+gda_data_model_get_exceptions
 gda_data_model_describe_column
 gda_data_model_get_column_index
 gda_data_model_get_column_name
@@ -1413,6 +1414,7 @@ gda_data_select_set_modification_statement_sql
 gda_data_select_compute_modification_statements
 gda_data_select_compute_columns_attributes
 gda_data_select_rerun
+gda_data_select_add_exception
 <SUBSECTION Standard>
 GDA_IS_DATA_SELECT
 GDA_DATA_SELECT
diff --git a/libgda/gda-data-model.c b/libgda/gda-data-model.c
index 779bbd3..0218960 100644
--- a/libgda/gda-data-model.c
+++ b/libgda/gda-data-model.c
@@ -996,6 +996,31 @@ gda_data_model_send_hint (GdaDataModel *model, GdaDataModelHint hint, const GVal
 		(GDA_DATA_MODEL_GET_CLASS (model)->i_send_hint) (model, hint, hint_value);
 }
 
+/**
+ * gda_data_model_get_exceptions:
+ * @model: a #GdaDataModel
+ *
+ * Get the global data model exception(s) that occurred when using @model.
+ * This is usefull for example for the LDAP related
+ * data models where some rows may be missing because the LDAP search has reached a limit
+ * imposed by the LDAP server.
+ *
+ * Returns: (transfer none) (element-type GError) (array zero-terminated=1): a pointer to a %NULL terminated array of #GError, or %NULL.
+ *
+ * Since: 4.2.6
+ */
+GError **
+gda_data_model_get_exceptions (GdaDataModel *model)
+{
+	g_return_val_if_fail (GDA_IS_DATA_MODEL (model), NULL);
+
+	if (GDA_DATA_MODEL_GET_CLASS (model)->i_get_exceptions)
+		return (GDA_DATA_MODEL_GET_CLASS (model)->i_get_exceptions) (model);
+	else
+		return NULL;
+}
+
+
 static gchar *export_to_text_separated (GdaDataModel *model, const gint *cols, gint nb_cols, 
 					const gint *rows, gint nb_rows, gchar sep, gchar quote, gboolean field_quotes,
 					gboolean null_as_empty, gboolean invalid_as_null);
@@ -2476,10 +2501,29 @@ real_gda_data_model_dump_as_string (GdaDataModel *model, gboolean dump_attribute
 			g_strfreev (cols_str [i]);
 		g_free (cols_str);
 	}
+
+	/* status message */
+	g_string_append_c (string, '(');
 	if (n_rows > 0)
-		g_string_append_printf (string, ngettext("(%d row)\n", "(%d rows)\n", n_rows), n_rows);
+		g_string_append_printf (string, ngettext("%d row", "%d rows", n_rows), n_rows);
 	else
-		g_string_append_printf (string, _("(0 row)\n"));
+		g_string_append_printf (string, _("0 row"));
+
+	GError **exceptions;
+	exceptions = gda_data_model_get_exceptions (model);
+	if (exceptions) {
+		gint i;
+		for (i = 0; exceptions[i]; i++) {
+			GError *ex;
+			ex = exceptions[i];
+			if (ex && ex->message) {
+				g_string_append (string, ", ");
+				g_string_append (string, ex->message);
+			}
+		}
+	}
+	g_string_append (string, ")\n");
+
 
  out:
 	if (ramodel)
diff --git a/libgda/gda-data-model.h b/libgda/gda-data-model.h
index 2695fdc..2615ec9 100644
--- a/libgda/gda-data-model.h
+++ b/libgda/gda-data-model.h
@@ -75,7 +75,9 @@ typedef enum {
 	GDA_DATA_MODEL_ACCESS_ERROR,
 	GDA_DATA_MODEL_FEATURE_NON_SUPPORTED_ERROR,
 	GDA_DATA_MODEL_FILE_EXIST_ERROR,
-	GDA_DATA_MODEL_XML_FORMAT_ERROR
+	GDA_DATA_MODEL_XML_FORMAT_ERROR,
+
+	GDA_DATA_MODEL_TRUNCATED_ERROR
 } GdaDataModelError;
 
 /* struct for the interface */
@@ -117,6 +119,9 @@ struct _GdaDataModelIface {
 	void                 (* row_removed)        (GdaDataModel *model, gint row);
 	void                 (* changed)            (GdaDataModel *model);
 	void                 (* reset)              (GdaDataModel *model);
+
+	/* getting more information about a data model */
+	GError             **(* i_get_exceptions)   (GdaDataModel *model);
 };
 
 GType               gda_data_model_get_type               (void) G_GNUC_CONST;
@@ -151,6 +156,8 @@ gint                gda_data_model_get_row_from_values    (GdaDataModel *model,
 
 void                gda_data_model_send_hint              (GdaDataModel *model, GdaDataModelHint hint, const GValue *hint_value);
 
+GError            **gda_data_model_get_exceptions         (GdaDataModel *model);
+
 /* contents saving and loading */
 gchar              *gda_data_model_export_to_string       (GdaDataModel *model, GdaDataModelIOFormat format, 
 							   const gint *cols, gint nb_cols, 
diff --git a/libgda/gda-data-select.c b/libgda/gda-data-select.c
index f14357d..92293c3 100644
--- a/libgda/gda-data-select.c
+++ b/libgda/gda-data-select.c
@@ -92,6 +92,7 @@ typedef struct {
 struct _GdaDataSelectPrivate {
 	GdaConnection          *cnc;
         GdaDataModelIter       *iter;
+	GArray                 *exceptions; /* array of #GError pointers */
 	PrivateShareable       *sh;
 	gulong                  ext_params_changed_sig_id;
 };
@@ -174,6 +175,7 @@ static gboolean             gda_data_select_remove_row      (GdaDataModel *model
 
 static void                 gda_data_select_set_notify      (GdaDataModel *model, gboolean do_notify_changes);
 static gboolean             gda_data_select_get_notify      (GdaDataModel *model);
+static GError             **gda_data_select_get_exceptions  (GdaDataModel *model);
 
 static GObjectClass *parent_class = NULL;
 
@@ -313,6 +315,8 @@ gda_data_select_data_model_init (GdaDataModelIface *iface)
 	iface->i_set_notify = gda_data_select_set_notify;
 	iface->i_get_notify = gda_data_select_get_notify;
 	iface->i_send_hint = NULL;
+
+	iface->i_get_exceptions = gda_data_select_get_exceptions;
 }
 
 static void
@@ -322,6 +326,7 @@ gda_data_select_init (GdaDataSelect *model, G_GNUC_UNUSED GdaDataSelectClass *kl
 
 	model->priv = g_new0 (GdaDataSelectPrivate, 1);
 	model->priv->cnc = NULL;
+	model->priv->exceptions = NULL;
 	model->priv->sh = g_new0 (PrivateShareable, 1);
 	model->priv->sh-> notify_changes = TRUE;
 	model->priv->sh->rows = g_array_new (FALSE, FALSE, sizeof (GdaRow *));
@@ -558,6 +563,15 @@ gda_data_select_finalize (GObject *object)
 
 	/* free memory */
 	if (model->priv) {
+		if (model->priv->exceptions) {
+			gint i;
+			for (i = 0; i < model->priv->exceptions->len; i++) {
+				GError *e;
+				e = g_array_index (model->priv->exceptions, GError*, i);
+				g_error_free (e);
+			}
+			g_array_free (model->priv->exceptions, TRUE);
+		}
 		g_free (model->priv);
 		model->priv = NULL;
 	}
@@ -3132,6 +3146,40 @@ gda_data_select_get_notify (GdaDataModel *model)
 	return ((GdaDataSelect *) model)->priv->sh->notify_changes;
 }
 
+static GError **
+gda_data_select_get_exceptions (GdaDataModel *model)
+{
+	GdaDataSelect *sel;
+	sel =  GDA_DATA_SELECT (model);
+	if (sel->priv->exceptions && (sel->priv->exceptions->len > 0))
+		return (GError **) sel->priv->exceptions->data;
+	else
+		return NULL;
+}
+
+/**
+ * gda_data_select_add_exception:
+ * @model: a #GdaDataSelect
+ * @error: (transfer full): an error to add as exception
+ *
+ * Add an exception to @model.
+ *
+ * Since: 4.2.6
+ */
+void
+gda_data_select_add_exception (GdaDataSelect *model, GError *error)
+{
+	GdaDataSelect *sel;
+
+	g_return_if_fail (GDA_IS_DATA_SELECT (model));
+	g_return_if_fail (error);
+	g_return_if_fail (error->message);
+	sel =  GDA_DATA_SELECT (model);
+	if (!sel->priv->exceptions)
+		sel->priv->exceptions = g_array_new (TRUE, FALSE, sizeof (GError*));
+	g_array_append_val (sel->priv->exceptions, error);
+}
+
 /*
  * The following function creates a correspondance between the parameters required to
  * execute the model->one_row_select_stmt statement (GdaHolders named "-<num>", in ), and the GdaHolder
diff --git a/libgda/libgda.symbols b/libgda/libgda.symbols
index ba28244..6d177d3 100644
--- a/libgda/libgda.symbols
+++ b/libgda/libgda.symbols
@@ -233,6 +233,7 @@
 	gda_data_model_get_column_index
 	gda_data_model_get_column_name
 	gda_data_model_get_column_title
+	gda_data_model_get_exceptions
 	gda_data_model_get_n_columns
 	gda_data_model_get_n_rows
 	gda_data_model_get_row_from_values
@@ -311,6 +312,7 @@
 	gda_data_proxy_set_sample_size
 	gda_data_proxy_set_sample_start
 	gda_data_proxy_undelete
+	gda_data_select_add_exception
 	gda_data_select_compute_columns_attributes
 	gda_data_select_compute_modification_statements
 	gda_data_select_compute_row_selection_condition
diff --git a/libgda/providers-support/gda-data-select-priv.h b/libgda/providers-support/gda-data-select-priv.h
index a05501b..d7f61bd 100644
--- a/libgda/providers-support/gda-data-select-priv.h
+++ b/libgda/providers-support/gda-data-select-priv.h
@@ -40,6 +40,8 @@ GdaRow        *gda_data_select_get_stored_row               (GdaDataSelect *mode
 GdaConnection *gda_data_select_get_connection               (GdaDataSelect *model);
 void           gda_data_select_set_columns                  (GdaDataSelect *model, GSList *columns);
 
+void           gda_data_select_add_exception                (GdaDataSelect *model, GError *error);
+
 /* internal API */
 void           _gda_data_select_share_private_data (GdaDataSelect *master, GdaDataSelect *slave);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]