[libgda] Tools: always set a non zero domain and code



commit cab69450d186e478a9a9abf4185a66ffcfbf9d56
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Jun 26 21:16:53 2012 +0200

    Tools: always set a non zero domain and code

 tools/browser/auth-dialog.c                      |    4 +-
 tools/browser/browser-connection.c               |   28 +-
 tools/browser/browser-virtual-connection.c       |    6 +-
 tools/browser/common/fk-declare.c                |    5 +-
 tools/browser/common/ui-formgrid.c               |    3 +-
 tools/browser/connection-binding-properties.c    |    3 +-
 tools/browser/data-manager/data-source.c         |   25 +-
 tools/browser/data-manager/xml-spec-editor.c     |    5 +-
 tools/browser/login-dialog.c                     |    4 +-
 tools/browser/schema-browser/relations-diagram.c |    5 +-
 tools/command-exec.c                             |   22 +-
 tools/config-info.c                              |   13 +-
 tools/gda-sql.c                                  |  360 ++++++++++++----------
 tools/tools-favorites.c                          |   35 +-
 tools/tools-input.c                              |    3 +-
 tools/tools-utils.c                              |   10 +
 tools/tools-utils.h                              |   18 +
 17 files changed, 310 insertions(+), 239 deletions(-)
---
diff --git a/tools/browser/auth-dialog.c b/tools/browser/auth-dialog.c
index ba612fb..0bab90e 100644
--- a/tools/browser/auth-dialog.c
+++ b/tools/browser/auth-dialog.c
@@ -316,9 +316,9 @@ sub_thread_open_cnc (AuthData *ad, GError **error)
 	}
 #endif
 	return cnc;
-#else
+#else /* DUMMY defined */
 	sleep (5);
-	g_set_error (error, 0, 0, "%s", "Oooo");
+	g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR, "%s", "Dummy error!");
 	return NULL;
 #endif
 }
diff --git a/tools/browser/browser-connection.c b/tools/browser/browser-connection.c
index d2a5af5..00d3581 100644
--- a/tools/browser/browser-connection.c
+++ b/tools/browser/browser-connection.c
@@ -20,6 +20,7 @@
 
 #include <string.h>
 #include <glib/gi18n-lib.h>
+#include "../tools-utils.h"
 #include "browser-connection.h"
 #include <libgda/thread-wrapper/gda-thread-wrapper.h>
 #include "support.h"
@@ -1365,7 +1366,8 @@ wrapper_statement_execute (StmtExecData *data, GError **error)
 		else {
 			g_warning (_("Execution reported an undefined error, please report error to "
 				     "http://bugzilla.gnome.org/ for the \"libgda\" product"));
-			g_set_error (error, 0, 0, "%s", _("No detail"));
+			g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+				     "%s", _("No detail"));
 		}
 	}
 	return obj ? obj : (gpointer) 0x01;
@@ -1759,14 +1761,14 @@ meta_store_addons_init (BrowserConnection *bcnc, GError **error)
 	GdaMetaStore *store;
 
 	if (!bcnc->priv->cnc) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
 			     "%s", _("Connection not yet opened"));
 		return FALSE;
 	}
 	store = gda_connection_get_meta_store (bcnc->priv->cnc);
 	if (!gda_meta_store_schema_add_custom_object (store, DBTABLE_PREFERENCES_TABLE_DESC, &lerror)) {
-                g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize dictionary to store table preferences"));
+                g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize dictionary to store table preferences"));
 		g_warning ("Can't initialize dictionary to store dbtable_preferences :%s",
 			   lerror && lerror->message ? lerror->message : "No detail");
 		if (lerror)
@@ -1811,14 +1813,14 @@ browser_connection_set_table_column_attribute (BrowserConnection *bcnc,
 
 	store_cnc = bcnc->priv->store_cnc;
 	if (! gda_lockable_trylock (GDA_LOCKABLE (store_cnc))) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize transaction to access favorites"));
 		return FALSE;
 	}
 	/* begin a transaction */
 	if (! gda_connection_begin_transaction (store_cnc, NULL, GDA_TRANSACTION_ISOLATION_UNKNOWN, NULL)) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize transaction to access favorites"));
 		gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
                 return FALSE;
 	}
@@ -1898,8 +1900,8 @@ browser_connection_set_table_column_attribute (BrowserConnection *bcnc,
 	}
 
 	if (! gda_connection_commit_transaction (store_cnc, NULL, NULL)) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't commit transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't commit transaction to access favorites"));
 		goto err;
 	}
 
@@ -1953,8 +1955,8 @@ browser_connection_get_table_column_attribute  (BrowserConnection *bcnc,
 
 	store_cnc = bcnc->priv->store_cnc;
 	if (! gda_lockable_trylock (GDA_LOCKABLE (store_cnc))) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize transaction to access favorites"));
 		return FALSE;
 	}
 
@@ -2461,7 +2463,7 @@ wrapper_ldap_search (LdapSearchData *data, GError **error)
 	model = gda_data_model_ldap_new (GDA_CONNECTION (data->cnc), data->base_dn,
 					 data->filter, data->attributes, data->scope);
 	if (!model) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     "%s", _("Could not execute LDAP search"));
 		return (gpointer) 0x01;
 	}
diff --git a/tools/browser/browser-virtual-connection.c b/tools/browser/browser-virtual-connection.c
index 4b2d58d..62e678d 100644
--- a/tools/browser/browser-virtual-connection.c
+++ b/tools/browser/browser-virtual-connection.c
@@ -22,6 +22,7 @@
 #include "browser-virtual-connection.h"
 #include "browser-connection-priv.h"
 #include <virtual/libgda-virtual.h>
+#include "../tools-utils.h"
 
 /* 
  * Main static functions 
@@ -313,9 +314,10 @@ sub_thread_open_cnc (BrowserVirtualConnectionSpecs *specs, GError **error)
 	}
 	
 	return virtual;
-#else
+#else /* DUMMY defined */
         sleep (5);
-        g_set_error (error, 0, 0, "%s", "Timeout!!!");
+        g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+		     "%s", "Timeout!!!");
         return NULL;
 #endif
 }
diff --git a/tools/browser/common/fk-declare.c b/tools/browser/common/fk-declare.c
index 367403d..1a6e52b 100644
--- a/tools/browser/common/fk-declare.c
+++ b/tools/browser/common/fk-declare.c
@@ -21,6 +21,7 @@
 #include <sql-parser/gda-sql-parser.h>
 #include "fk-declare.h"
 #include "../support.h"
+#include "../../tools-utils.h"
 
 /* 
  * Main static functions 
@@ -556,7 +557,7 @@ fk_declare_write (FkDeclare *decl, BrowserWindow *bwin, GError **error)
 	g_return_val_if_fail (!bwin || BROWSER_IS_WINDOW (bwin), FALSE);
 
 	if (! decl->priv->dialog_sensitive) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     "%s", _("Missing information to declare foreign key"));
 		return FALSE;
 	}
@@ -638,7 +639,7 @@ fk_declare_undeclare (GdaMetaStruct *mstruct, BrowserWindow *bwin, GdaMetaTableF
 	    !decl_fk->depend_on->obj_catalog ||
 	    !decl_fk->depend_on->obj_schema ||
 	    !decl_fk->depend_on->obj_name) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     "%s", _("Missing information to undeclare foreign key"));
 		return FALSE;
 	}
diff --git a/tools/browser/common/ui-formgrid.c b/tools/browser/common/ui-formgrid.c
index 01bb6a9..d04e26b 100644
--- a/tools/browser/common/ui-formgrid.c
+++ b/tools/browser/common/ui-formgrid.c
@@ -34,6 +34,7 @@
 #ifdef HAVE_LDAP
 #include "../ldap-browser/ldap-browser-perspective.h"
 #endif
+#include "../../tools-utils.h"
 
 static void ui_formgrid_class_init (UiFormGridClass * class);
 static void ui_formgrid_init (UiFormGrid *wid);
@@ -650,7 +651,7 @@ exec_end_timeout_cb (ActionExecutedData *aed)
                 }
                 else {
 			g_object_unref (obj);
-                        g_set_error (&error, 0, 0,
+                        g_set_error (&error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
                                      "%s", _("Statement to execute is not a selection statement"));
                 }
         }
diff --git a/tools/browser/connection-binding-properties.c b/tools/browser/connection-binding-properties.c
index d078f4b..5e864c1 100644
--- a/tools/browser/connection-binding-properties.c
+++ b/tools/browser/connection-binding-properties.c
@@ -26,6 +26,7 @@
 #include <libgda-ui/libgda-ui.h>
 #include <libgda-ui/gdaui-plugin.h>
 #include "common/gdaui-entry-import.h"
+#include "../tools-utils.h"
 
 /* 
  * Main static functions 
@@ -472,7 +473,7 @@ part_for_cnc_validate_holder_change_cb (G_GNUC_UNUSED GdaSet *set, GdaHolder *ho
 			if (((ptr == str) && ! g_ascii_isalpha (*ptr)) ||
 			    ((ptr != str) && (*ptr != '_') && !g_ascii_isalnum (*ptr))) {
 				GError *error = NULL;
-				g_set_error (&error, 0, 0,
+				g_set_error (&error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 					     "%s", _("Invalid schema name"));
 				return error;
 			}
diff --git a/tools/browser/data-manager/data-source.c b/tools/browser/data-manager/data-source.c
index 9cf8268..865b547 100644
--- a/tools/browser/data-manager/data-source.c
+++ b/tools/browser/data-manager/data-source.c
@@ -29,6 +29,7 @@
 #include <libgda/gda-data-model-extra.h>
 #include <libgda/gda-sql-builder.h>
 #include "../common/ui-formgrid.h"
+#include "../../tools-utils.h"
 
 #include "data-source.h"
 #define DEFAULT_DATA_SOURCE_NAME "DataSource"
@@ -399,7 +400,7 @@ data_source_new_from_xml_node (BrowserConnection *bcnc, xmlNodePtr node, GError
 		init_from_query (source, node);
 	}
 	else {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     /* Translators: Do not translate "table" nor "query" */
 			     _("Node must be \"table\" or \"query\", and is \"%s\""), (gchar*)node->name);
 		g_object_unref (source);
@@ -433,14 +434,14 @@ get_meta_table (DataSource *source, const gchar *table_name, GError **error)
 
 	mstruct = browser_connection_get_meta_struct (source->priv->bcnc);
 	if (! mstruct) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
 			     "%s", _("Not ready"));
 		return NULL;
 	}
 
 	split = gda_sql_identifier_split (table_name);
 	if (! split) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     _("Malformed table name \"%s\""), table_name);
 		return NULL;
 	}
@@ -457,12 +458,12 @@ get_meta_table (DataSource *source, const gchar *table_name, GError **error)
 	if (vname[2]) gda_value_free (vname[2]);
 
 	if (! dbo) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     _("Could not find the \"%s\" table"), table_name);
 		return NULL;
 	}
 	if ((dbo->obj_type != GDA_META_DB_TABLE) && (dbo->obj_type != GDA_META_DB_VIEW)) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     _("The \"%s\" object is not a table"), table_name);
 		return NULL;
 	}
@@ -480,7 +481,7 @@ init_from_table_node (DataSource *source, xmlNodePtr node, GError **error)
 #endif
 	tname = xmlGetProp (node, BAD_CAST "name");
 	if (!tname) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     /* Translators: Do not translate "name" */
 			     "%s", _("Missing attribute \"name\" for table"));
 		return FALSE;
@@ -621,12 +622,12 @@ data_source_add_dependency (DataSource *source, const gchar *table,
 		}
 	}
 	if (!fk) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     _("Could not find any foreign key to \"%s\""), table);
 		return FALSE;
 	}
 	else if (fk->cols_nb <= 0) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     _("The fields involved in the foreign key to \"%s\" are not known"),
 			     table);
 		return FALSE;
@@ -807,7 +808,7 @@ exec_end_timeout_cb (DataSource *source)
 		}
 		else {
 			g_object_unref (obj);
-			g_set_error (&source->priv->exec_error, 0, 0,
+			g_set_error (&source->priv->exec_error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 				     "%s", _("Statement to execute is not a selection statement"));
 		}
 
@@ -947,7 +948,7 @@ data_source_execute (DataSource *source, GError **error)
 		if (source->priv->init_error)
 			g_propagate_error (error, source->priv->init_error);
 		else
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 				     "%s", _("No SELECT statement to execute"));
 	}
 
@@ -1217,7 +1218,7 @@ data_source_set_table (DataSource *source, const gchar *table, GError **error)
 	b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
 	source->priv->builder = b;
 	if (! gda_sql_builder_select_add_target (b, table, NULL)) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     "%s", _("Could not build SELECT statement"));
 		return FALSE;
 	}
@@ -1284,7 +1285,7 @@ data_source_set_query (DataSource *source, const gchar *sql, GError **warning)
 	}
 
 	if (remain)
-		g_set_error (warning, 0, 0,
+		g_set_error (warning, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     "%s", _("Multiple statements detected, only the first will be used"));
 
 	/* try to normalize the statement */
diff --git a/tools/browser/data-manager/xml-spec-editor.c b/tools/browser/data-manager/xml-spec-editor.c
index 420aebc..cb617fb 100644
--- a/tools/browser/data-manager/xml-spec-editor.c
+++ b/tools/browser/data-manager/xml-spec-editor.c
@@ -24,6 +24,7 @@
 #include "data-source.h"
 #include <libgda/libgda.h>
 #include "../support.h"
+#include "../../tools-utils.h"
 
 #ifdef HAVE_GTKSOURCEVIEW
 #ifdef GTK_DISABLE_SINGLE_INCLUDES
@@ -168,7 +169,7 @@ signal_editor_changed (XmlSpecEditor *sped)
 
 	if (!doc) {
 		TO_IMPLEMENT;
-		g_set_error (&lerror, 0, 0,
+		g_set_error (&lerror, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     "%s", _("Error parsing XML specifications"));
 		goto out;
 	}
@@ -182,7 +183,7 @@ signal_editor_changed (XmlSpecEditor *sped)
 	}
 
 	if (strcmp ((gchar*) node->name, "data")) {
-		g_set_error (&lerror, 0, 0,
+		g_set_error (&lerror, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     _("Expecting <%s> root node"), "data");
 		xmlFreeDoc (doc);
 		goto out;
diff --git a/tools/browser/login-dialog.c b/tools/browser/login-dialog.c
index 25dd60b..d1eaa53 100644
--- a/tools/browser/login-dialog.c
+++ b/tools/browser/login-dialog.c
@@ -288,9 +288,9 @@ sub_thread_open_cnc (GdaDsnInfo *info, GError **error)
 						       GDA_CONNECTION_OPTIONS_AUTO_META_DATA,
 						       error);
 	return cnc;
-#else
+#else /* DUMMY defined */
 	sleep (5);
-	g_set_error (error, 0, 0, "%s", "Oooo");
+	g_set_error (error, TOOLS_INTERNAL_COMMAND_ERROR, "%s", "Dummy error!");
 	return NULL;
 #endif
 }
diff --git a/tools/browser/schema-browser/relations-diagram.c b/tools/browser/schema-browser/relations-diagram.c
index 0408161..c4e79e3 100644
--- a/tools/browser/schema-browser/relations-diagram.c
+++ b/tools/browser/schema-browser/relations-diagram.c
@@ -30,6 +30,7 @@
 #include "../browser-perspective.h"
 #include "../browser-window.h"
 #include "../data-manager/data-manager-perspective.h"
+#include "../../tools-utils.h"
 
 struct _RelationsDiagramPrivate {
 	BrowserConnection *bcnc;
@@ -371,7 +372,7 @@ relations_diagram_new_with_fav_id (BrowserConnection *bcnc, gint fav_id, GError
 
 	doc = xmlParseDoc (BAD_CAST fav.contents);
 	if (!doc) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     "%s", _("Error parsing favorite's contents"));
 		goto out;
 	}
@@ -430,7 +431,7 @@ relations_diagram_new_with_fav_id (BrowserConnection *bcnc, gint fav_id, GError
 					xmlFree (schema);
 				if (name)
 					xmlFree (name);
-				g_set_error (error, 0, 0,
+				g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
 					     "%s", _("Missing table attribute in favorite's contents"));
 				gtk_widget_destroy ((GtkWidget*) diagram);
 				diagram = NULL;
diff --git a/tools/command-exec.c b/tools/command-exec.c
index 9440a87..5548d98 100644
--- a/tools/command-exec.c
+++ b/tools/command-exec.c
@@ -778,7 +778,8 @@ gda_internal_command_dict_sync (G_GNUC_UNUSED SqlConsole *console, GdaConnection
 	GdaInternalCommandResult *res;
 
 	if (!cnc) {
-		g_set_error (error, 0, 0, "%s", _("No current connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No current connection"));
 		return NULL;
 	}
 
@@ -815,7 +816,8 @@ gda_internal_command_list_tables (G_GNUC_UNUSED SqlConsole *console, GdaConnecti
 	GdaDataModel *model;
 
 	if (!cnc) {
-		g_set_error (error, 0, 0, "%s", _("No current connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No current connection"));
 		return NULL;
 	}
 
@@ -859,7 +861,8 @@ gda_internal_command_list_views (G_GNUC_UNUSED SqlConsole *console, GdaConnectio
 	GdaDataModel *model;
 
 	if (!cnc) {
-		g_set_error (error, 0, 0, "%s", _("No current connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No current connection"));
 		return NULL;
 	}
 
@@ -902,7 +905,8 @@ gda_internal_command_list_schemas (G_GNUC_UNUSED SqlConsole *console, GdaConnect
 	GdaDataModel *model;
 
 	if (!cnc) {
-		g_set_error (error, 0, 0, "%s", _("No current connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No current connection"));
 		return NULL;
 	}
 
@@ -999,8 +1003,8 @@ gda_internal_command_build_meta_struct (GdaConnection *cnc, const gchar **args,
 
 	objlist = gda_meta_struct_get_all_db_objects (mstruct);
 	if (!objlist) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("No object found"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_OBJECT_NOT_FOUND_ERROR,
+			     "%s", _("No object found"));
 		goto onerror;
 	}
 	g_slist_free (objlist);
@@ -1035,7 +1039,8 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
 	GdaDataModel *model;
 
 	if (!cnc) {
-		g_set_error (error, 0, 0, "%s", _("No current connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No current connection"));
 		return NULL;
 	}
 
@@ -1131,7 +1136,8 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
 		return res;
 	}
 	else if (nb_objects == 0) {
-		g_set_error (error, 0, 0, "%s", _("No object found"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_OBJECT_NOT_FOUND_ERROR,
+			     "%s", _("No object found"));
 		g_slist_free (tmplist);
 		return NULL;
 	}
diff --git a/tools/config-info.c b/tools/config-info.c
index 203020b..2aa24d1 100644
--- a/tools/config-info.c
+++ b/tools/config-info.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2012 Vivien Malerba <malerba gnome-db org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -17,6 +17,7 @@
  */
 
 #include "config-info.h"
+#include "tools-utils.h"
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
@@ -104,7 +105,7 @@ config_info_detail_provider (const gchar *provider, GError **error)
 	GdaProviderInfo *pinfo;
 	pinfo = gda_config_get_provider_info (provider);
 	if (! pinfo) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_PROVIDER_NOT_FOUND_ERROR,
 			     _("Could not find provider '%s'"), provider);
 		return NULL;
 	}
@@ -273,7 +274,7 @@ config_info_detail_dsn (const gchar *dsn, GError **error)
 	if (dsn && *dsn)
 		info = gda_config_get_dsn_info (dsn);
 	if (!info) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_DSN_NOT_FOUND_ERROR,
 			     _("Could not find data source '%s'"), dsn);
 		return NULL;
 	}
@@ -550,7 +551,8 @@ config_info_purge_data_files (const gchar *criteria, GError **error)
 	}
 	g_strfreev (array);
 	if (cri == PURGE_UNKNOWN) {
-		g_set_error (error, 0, 0, "Unknown criteria '%s'", criteria);
+		g_set_error (error, TOOLS_ERROR, TOOLS_PURGE_ERROR,
+			     _("Unknown criteria '%s'"), criteria);
 		return NULL;
 	}
 
@@ -629,7 +631,8 @@ config_info_purge_data_files (const gchar *criteria, GError **error)
 	g_dir_close (dir);
 
 	if (errstring) {
-		g_set_error (error, 0, 0, "%s", errstring->str);
+		g_set_error (error, TOOLS_ERROR, TOOLS_PURGE_ERROR,
+			     "%s", errstring->str);
 		g_string_free (errstring, TRUE);
 	}
 
diff --git a/tools/gda-sql.c b/tools/gda-sql.c
index 8031cd0..e240906 100644
--- a/tools/gda-sql.c
+++ b/tools/gda-sql.c
@@ -22,6 +22,7 @@
  */
 
 #include "gda-sql.h"
+#include "tools-utils.h"
 #include <virtual/libgda-virtual.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gprintf.h>
@@ -979,13 +980,13 @@ command_execute (SqlConsole *console, const gchar *command, GdaStatementModelUsa
 	}
         else {
                 if (!cs) {
-                        g_set_error (error, 0, 0, "%s", 
-                                     _("No connection specified"));
+                        g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+				     "%s", _("No connection specified"));
                         return NULL;
                 }
                 if (!gda_connection_is_opened (cs->cnc)) {
-                        g_set_error (error, 0, 0, "%s", 
-                                     _("Connection closed"));
+                        g_set_error (error, TOOLS_ERROR, TOOLS_CONNECTION_CLOSED_ERROR,
+				     "%s", _("Connection closed"));
                         return NULL;
                 }
 
@@ -1113,20 +1114,20 @@ execute_internal_command (SqlConsole *console, GdaConnection *cnc, const gchar *
 	g_strfreev (args);
 	args = NULL;
 	if (!command) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Unknown internal command"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+			     "%s", _("Unknown internal command"));
 		goto cleanup;
 	}
 
 	if (!command->command_func) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Internal command not correctly defined"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+			     "%s", _("Internal command not correctly defined"));
 		goto cleanup;
 	}
 
 	if (!command_complete) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Incomplete internal command"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+			     "%s", _("Incomplete internal command"));
 		goto cleanup;
 	}
 
@@ -1170,8 +1171,8 @@ execute_external_command (SqlConsole *console, const gchar *command,
 
 	cs = get_current_connection_settings (console);
 	if (!cs) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("No connection specified"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection specified"));
 		return NULL;
 	}
 
@@ -1190,8 +1191,8 @@ execute_external_command (SqlConsole *console, const gchar *command,
 	}
 
 	if (stmt_list->next) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("More than one SQL statement"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("More than one SQL statement"));
 		g_object_unref (batch);
 		return NULL;
 	}
@@ -1236,7 +1237,7 @@ execute_external_command (SqlConsole *console, const gchar *command,
 					value = gda_value_new_from_string (str, gda_holder_get_g_type (h));
 					g_free (str);
 					if (! value) {
-						g_set_error (error, 0, 0,
+						g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 							     _("Could not interpret the '%s' parameter's value"), 
 							     gda_holder_get_id (h));
 						g_free (res);
@@ -1253,7 +1254,7 @@ execute_external_command (SqlConsole *console, const gchar *command,
 			}
 			else {
 				if (! gda_holder_is_valid (h)) {
-					g_set_error (error, 0, 0,
+					g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 						     _("No internal parameter named '%s' required by query"), 
 						     gda_holder_get_id (h));
 					g_free (res);
@@ -1398,7 +1399,7 @@ set_output_file (const gchar *file, GError **error)
 			/* output to a file */
 			main_data->output_stream = g_fopen (copy, "w");
 			if (!main_data->output_stream) {
-				g_set_error (error, 0, 0,
+				g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 					     _("Can't open file '%s' for writing: %s\n"), 
 					     copy,
 					     strerror (errno));
@@ -1411,7 +1412,7 @@ set_output_file (const gchar *file, GError **error)
 			/* output to a pipe */
 			main_data->output_stream = popen (copy+1, "w");
 			if (!main_data->output_stream) {
-				g_set_error (error, 0, 0,
+				g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 					     _("Can't open pipe '%s': %s\n"), 
 					     copy,
 					     strerror (errno));
@@ -1451,7 +1452,7 @@ set_input_file (const gchar *file, GError **error)
 		else
 			main_data->input_stream = g_fopen (file, "r");
 		if (!main_data->input_stream) {
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 				     _("Can't open file '%s' for reading: %s\n"), 
 				     file,
 				     strerror (errno));
@@ -1518,7 +1519,7 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
 	gchar *real_cnc_string;
 
 	if (cnc_name && ! connection_name_is_valid (cnc_name)) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     _("Connection name '%s' is invalid"), cnc_name);
 		return NULL;
 	}
@@ -3090,7 +3091,7 @@ extra_command_set_output_format (SqlConsole *console, G_GNUC_UNUSED GdaConnectio
 		else if ((*fmt == 'C') || (*fmt == 'c'))
 			main_data->output_format = OUTPUT_FORMAT_CSV;
 		else {
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 				     _("Unknown output format: '%s', reset to default"), fmt);
 			goto out;
 		}
@@ -3305,8 +3306,8 @@ extra_command_create_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
 	gchar *real_cnc, *real_provider, *user, *pass;
 
 	if (!args[0] || !args[1]) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Missing arguments"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing arguments"));
 		return NULL;
 	}
 
@@ -3326,8 +3327,8 @@ extra_command_create_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
 	newdsn.is_system = FALSE;
 
 	if (!newdsn.provider) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Missing provider name"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing provider name"));
 	}
 	else if (gda_config_define_dsn (&newdsn, error)) {
 		res = g_new0 (GdaInternalCommandResult, 1);
@@ -3351,8 +3352,8 @@ extra_command_remove_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
 	gint i;
 
 	if (!args[0]) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Missing DSN name"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing DSN name"));
 		return NULL;
 	}
 	for (i = 0; args [i]; i++) {
@@ -3417,7 +3418,7 @@ extra_command_manage_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
 			
 			cs = find_connection_from_name (args[0]);
 			if (cs) {
-				g_set_error (error, 0, 0,
+				g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 					     _("A connection named '%s' already exists"), args[0]);
 				return NULL;
 			}
@@ -3460,7 +3461,8 @@ extra_command_manage_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
 					if (*(args[0] + 1)) {
 						cs = find_connection_from_name (args[0] + 1);
 						if (!cs) {
-							g_set_error (error, 0, 0,
+							g_set_error (error, TOOLS_ERROR,
+								     TOOLS_NO_CONNECTION_ERROR,
 								     _("No connection named '%s' found"), args[0] + 1);
 							return NULL;
 						}
@@ -3471,8 +3473,8 @@ extra_command_manage_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
 						cs = main_data->current;
 
 					if (!cs) {
-						g_set_error (error, 0, 0, "%s", 
-							     _("No current connection"));
+						g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+							     "%s", _("No current connection"));
 						return NULL;
 					}
 
@@ -3542,7 +3544,7 @@ extra_command_manage_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
 					return res;
 				}
 
-				g_set_error (error, 0, 0,
+				g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
 					     _("No connection named '%s' found"), args[0]);
 				return NULL;
 			}
@@ -3643,7 +3645,7 @@ extra_command_close_cnc (SqlConsole *console, GdaConnection *cnc, const gchar **
 	if (args && args[0] && *args[0]) {
 		cs = find_connection_from_name (args[0]);
 		if (!cs) {
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
 				     _("No connection named '%s' found"), args[0]);
 			return NULL;
 		}
@@ -3659,8 +3661,8 @@ extra_command_close_cnc (SqlConsole *console, GdaConnection *cnc, const gchar **
 		}
 
 		if (! cs) {
-			g_set_error (error, 0, 0, "%s", 
-				     _("No connection currently opened"));
+			g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+				     "%s", _("No connection currently opened"));
 			return NULL;
 		}
 	}
@@ -3700,20 +3702,20 @@ extra_command_bind_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, c
 	GString *string;
 
 	if (nargs < 2) {
-		g_set_error (error, 0, 0, "%s", 
-				     _("Missing required connection names"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing required connection names"));
 		return NULL;
 	}
 
 	/* check for connections existance */
 	cs = find_connection_from_name (args[0]);
 	if (cs) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     _("A connection named '%s' already exists"), args[0]);
 		return NULL;
 	}
 	if (! connection_name_is_valid (args[0])) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     _("Connection name '%s' is invalid"), args[0]);
 		return NULL;
 	}
@@ -3723,7 +3725,7 @@ extra_command_bind_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, c
 			GdaDataModel *src;
 			src = g_hash_table_lookup (main_data->mem_data_models, args[i]);
 			if (!src) {
-				g_set_error (error, 0, 0,
+				g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 					     _("No connection or dataset named '%s' found"), args[i]);
 				return NULL;
 			}
@@ -3738,7 +3740,8 @@ extra_command_bind_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, c
 	virtual = gda_virtual_connection_open_extended (vprovider, GDA_CONNECTION_OPTIONS_THREAD_SAFE |
 							GDA_CONNECTION_OPTIONS_AUTO_META_DATA, NULL);
 	if (!virtual) {
-		g_set_error (error, 0, 0, "%s", _("Could not create virtual connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+			     "%s", _("Could not create virtual connection"));
 		return NULL;
 	}
 	g_object_set (G_OBJECT (virtual), "execution-timer", TRUE, NULL);
@@ -3850,7 +3853,7 @@ extra_command_option (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, con
 			}
 		}
 		else {
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 				     _("No option named '%s'"), oname);
 			return NULL;
 		}
@@ -3944,7 +3947,8 @@ extra_command_cd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const g
 			
 			pw = getpwuid (geteuid ());
 			if (!pw) {
-				g_set_error (error, 0, 0, _("Could not get home directory: %s"), strerror (errno));
+				g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+					     _("Could not get home directory: %s"), strerror (errno));
 				return NULL;
 			}
 			else {
@@ -3974,7 +3978,8 @@ extra_command_cd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const g
 			return res;
 		}
 		else
-			g_set_error (error, 0, 0, _("Could not change working directory to '%s': %s"),
+			g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+				     _("Could not change working directory to '%s': %s"),
 				     dir, strerror (errno));
 	}
 
@@ -4001,7 +4006,8 @@ extra_command_edit_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc
 	}
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		goto end_of_command;
 	}
 
@@ -4018,7 +4024,7 @@ extra_command_edit_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc
 			goto end_of_command;
 		if (write (fd, main_data->current->query_buffer->str, 
 			   main_data->current->query_buffer->len) != (gint)main_data->current->query_buffer->len) {
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 				     _("Could not write to temporary file '%s': %s"),
 				     filename, strerror (errno));
 			close (fd);
@@ -4054,12 +4060,12 @@ extra_command_edit_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc
 
 	systemres = system (command);
 	if (systemres == -1) {
-                g_set_error (error, 0, 0,
+                g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     _("could not start editor '%s'"), editor_name);
 		goto end_of_command;
 	}
         else if (systemres == 127) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     "%s", _("Could not start /bin/sh"));
 		goto end_of_command;
 	}
@@ -4104,7 +4110,8 @@ extra_command_reset_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cn
 	}
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
@@ -4148,7 +4155,8 @@ extra_command_show_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc
 	}
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
@@ -4177,7 +4185,8 @@ extra_command_exec_buffer (SqlConsole *console, GdaConnection *cnc, const gchar
 	}
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
@@ -4219,15 +4228,16 @@ extra_command_write_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cn
 	}
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
 	if (!main_data->current->query_buffer) 
 		main_data->current->query_buffer = g_string_new ("");
 	if (!args[0]) 
-		g_set_error (error, 0, 0, "%s",  
-			     _("Missing FILE to write to"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing FILE to write to"));
 	else {
 		if (g_file_set_contents (args[0], main_data->current->query_buffer->str, -1, error)) {
 			res = g_new0 (GdaInternalCommandResult, 1);
@@ -4263,7 +4273,8 @@ extra_command_query_buffer_list_dict (SqlConsole *console, G_GNUC_UNUSED GdaConn
 	}
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
@@ -4372,7 +4383,8 @@ extra_command_query_buffer_to_dict (SqlConsole *console, G_GNUC_UNUSED GdaConnec
 	}
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
@@ -4385,8 +4397,8 @@ extra_command_query_buffer_to_dict (SqlConsole *console, G_GNUC_UNUSED GdaConnec
 		if (args[0] && *args[0]) 
 			qname = g_strdup ((gchar *) args[0]);
 		else {
-			g_set_error (error, 0, 0, "%s", 
-				     _("Missing query buffer name"));
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+				     "%s", _("Missing query buffer name"));
 			return NULL;
 		}
 
@@ -4414,8 +4426,8 @@ extra_command_query_buffer_to_dict (SqlConsole *console, G_GNUC_UNUSED GdaConnec
 		res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
 	}
 	else
-		g_set_error (error, 0, 0, "%s", 
-			     _("Query buffer is empty"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+			     "%s", _("Query buffer is empty"));
 
 	return res;
 }
@@ -4437,7 +4449,8 @@ extra_command_query_buffer_from_dict (SqlConsole *console, G_GNUC_UNUSED GdaConn
 	}
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
@@ -4468,7 +4481,8 @@ extra_command_query_buffer_from_dict (SqlConsole *console, G_GNUC_UNUSED GdaConn
 			const GValue *cvalue;
 			GError *lerror = NULL;
 
-			g_set_error (&lerror, 0, 0, "%s", _("Could not find favorite"));
+			g_set_error (&lerror, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+				     "%s", _("Could not find favorite"));
 			if (!sel_stmt) {
 				sel_stmt = gda_sql_parser_parse_string (main_data->current->parser, 
 									QUERY_BUFFERS_TABLE_SELECT_ONE, NULL, NULL);
@@ -4499,8 +4513,8 @@ extra_command_query_buffer_from_dict (SqlConsole *console, G_GNUC_UNUSED GdaConn
 		}
 	}
 	else
-		g_set_error (error, 0, 0, "%s", 
-			     _("Missing query buffer name"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing query buffer name"));
 		
 	return res;
 }
@@ -4522,7 +4536,8 @@ extra_command_query_buffer_delete_dict (SqlConsole *console, G_GNUC_UNUSED GdaCo
 	}
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
@@ -4575,8 +4590,8 @@ extra_command_query_buffer_delete_dict (SqlConsole *console, G_GNUC_UNUSED GdaCo
 		res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
 	}
 	else
-		g_set_error (error, 0, 0, "%s", 
-			     _("Missing query buffer name"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing query buffer name"));
 		
 	return res;
 }
@@ -4639,7 +4654,7 @@ extra_command_set (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const
 				res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
 			}
 			else 
-				g_set_error (error, 0, 0,
+				g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 					     _("No parameter named '%s' defined"), pname);
 		}
 	}
@@ -4735,8 +4750,8 @@ extra_command_data_set_grep (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
 			pattern = args[1];
 	}
 	if (!model_name) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Missing argument"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing argument"));
 		return NULL;
 	}
 
@@ -4745,7 +4760,7 @@ extra_command_data_set_grep (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
 
 	src = g_hash_table_lookup (main_data->mem_data_models, model_name);
 	if (!src) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     _("Could not find dataset named '%s'"), model_name);
 		return NULL;
 	}
@@ -4855,15 +4870,15 @@ extra_command_data_set_show (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
 		model_name = args[0];
 
 	if (!model_name) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Missing argument"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing argument"));
 		return NULL;
 	}
 
 	GdaDataModel *src;
 	src = g_hash_table_lookup (main_data->mem_data_models, model_name);
 	if (!src) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     _("Could not find dataset named '%s'"), model_name);
 		return NULL;
 	}
@@ -4884,7 +4899,7 @@ extra_command_data_set_show (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
 					pos = (gint) li;
 			}
 			if (pos < 0) {
-				g_set_error (error, 0, 0,
+				g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 					     _("Could not identify column '%s'"), cname);
 				g_array_free (cols, TRUE);
 				return NULL;
@@ -4921,15 +4936,15 @@ extra_command_data_set_rm (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc
 	guint i;
 
 	if (!args[0] ||  !(*args[0])) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Missing argument"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing argument"));
 		return NULL;
 	}
 	for (i = 0; args[i]; i++) {
 		GdaDataModel *src;
 		src = g_hash_table_lookup (main_data->mem_data_models, args[i]);
 		if (!src) {
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 				     _("Could not find dataset named '%s'"), args[i]);
 			return NULL;
 		}
@@ -4954,7 +4969,7 @@ extra_command_data_set_import (G_GNUC_UNUSED SqlConsole *console, GdaConnection
 	if (args[0] && *args[0]) {
 		type = args[0];
 		if (g_ascii_strcasecmp (type, "csv")) {
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 				     _("Unknown import format '%s'"), args[0]);
 			return NULL;
 		}
@@ -4963,8 +4978,8 @@ extra_command_data_set_import (G_GNUC_UNUSED SqlConsole *console, GdaConnection
 	}
 
 	if (!type || !file_name) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Missing argument"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing argument"));
 		return NULL;
 	}
 
@@ -4975,7 +4990,7 @@ extra_command_data_set_import (G_GNUC_UNUSED SqlConsole *console, GdaConnection
 	if (impopt)
 		g_object_unref (impopt);
 	if (!model) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     _("Could not import file '%s'"), file_name);
 		return NULL;
 	}
@@ -5007,8 +5022,8 @@ extra_command_data_set_move (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
 			new_name = args[1];
 	}
 	if (!old_name || !*old_name || !new_name || !*new_name) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Missing argument"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing argument"));
 		return NULL;
 	}
 
@@ -5016,7 +5031,7 @@ extra_command_data_set_move (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
 
 	src = g_hash_table_lookup (main_data->mem_data_models, old_name);
 	if (!src) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     _("Could not find dataset named '%s'"), old_name);
 		return NULL;
 	}
@@ -5069,7 +5084,7 @@ parse_fk_decl_spec (const gchar *spec, gboolean columns_required, GError **error
 	gchar *ptr, *dspec, *start, *subptr, *substart;
 
 	if (!spec || !*spec) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     "%s", _("Missing foreign key declaration specification"));
 		return NULL;
 	}
@@ -5186,7 +5201,7 @@ parse_fk_decl_spec (const gchar *spec, gboolean columns_required, GError **error
 
  onerror:
 	fk_decl_data_free (decldata);
-	g_set_error (error, 0, 0,
+	g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 		     "%s", _("Malformed foreign key declaration specification"));
 	return NULL;
 }
@@ -5218,7 +5233,7 @@ fk_decl_analyse_table_name (const gchar *table, GdaMetaStore *mstore,
 		g_strfreev (id_array);
 	}
 	else {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     _("Malformed table name specification '%s'"), table);
 		return FALSE;
 	}
@@ -5233,7 +5248,8 @@ extra_command_declare_fk (SqlConsole *console, GdaConnection *cnc,
 	GdaInternalCommandResult *res = NULL;
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
@@ -5306,7 +5322,7 @@ extra_command_declare_fk (SqlConsole *console, GdaConnection *cnc,
 		}
 	}
 	else
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     "%s", _("Missing foreign key name argument"));
 	return res;
 }
@@ -5319,7 +5335,8 @@ extra_command_undeclare_fk (SqlConsole *console, GdaConnection *cnc,
 	GdaInternalCommandResult *res = NULL;
 
 	if (!main_data->current) {
-		g_set_error (error, 0, 0, "%s", _("No connection opened"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection opened"));
 		return NULL;
 	}
 
@@ -5380,7 +5397,7 @@ extra_command_undeclare_fk (SqlConsole *console, GdaConnection *cnc,
 		}
 	}
 	else
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     "%s", _("Missing foreign key name argument"));
 	return res;
 }
@@ -5412,8 +5429,8 @@ get_table_value_at_cell (GdaConnection *cnc, GError **error, G_GNUC_UNUSED MainD
 		return NULL;
 	}
 	if (remain) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Wrong row condition"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Wrong row condition"));
 		g_free (sql);
 		return NULL;
 	}
@@ -5440,8 +5457,8 @@ get_table_value_at_cell (GdaConnection *cnc, GError **error, G_GNUC_UNUSED MainD
 	gda_internal_command_exec_result_free (tmpres);
 
 	if (!retval && !errorset)
-		g_set_error (error, 0, 0, "%s", 
-			     _("No unique row identified"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("No unique row identified"));
 
 	return retval;
 }
@@ -5468,7 +5485,8 @@ extra_command_set2 (SqlConsole *console, GdaConnection *cnc, const gchar **args,
 	}
 
 	if (!cnc) {
-                g_set_error (error, 0, 0, "%s", _("No current connection"));
+                g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No current connection"));
                 return NULL;
         }
 
@@ -5481,8 +5499,8 @@ extra_command_set2 (SqlConsole *console, GdaConnection *cnc, const gchar **args,
 				if (args[3] && *args[3]) {
 					row_cond = args[3];
 					if (args [4]) {
-						g_set_error (error, 0, 0, "%s", 
-							     _("Too many arguments"));
+						g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+							     "%s", _("Too many arguments"));
 						return NULL;
 					}
 					whichargs = 1;
@@ -5529,8 +5547,8 @@ extra_command_set2 (SqlConsole *console, GdaConnection *cnc, const gchar **args,
 		res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
 	}
 	else 
-		g_set_error (error, 0, 0, "%s", 
-                             _("Wrong number of arguments"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Wrong number of arguments"));
 
 	return res;
 }
@@ -5543,8 +5561,8 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
 	ConnectionSetting *cs;
 	cs = get_current_connection_settings (console);
 	if (!cs) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("No connection specified"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection specified"));
 		return NULL;
 	}
 
@@ -5562,13 +5580,13 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
         }
 
 	if (!select) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Missing data on which to operate"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing data on which to operate"));
 		return NULL;
 	}
 	if (!row_fields) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Missing row fields specifications"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing row fields specifications"));
 		return NULL;
 	}
 	if (column_fields && !strcmp (column_fields, "-"))
@@ -5585,8 +5603,8 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
 		return NULL;
 	if (tmpres->type != GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL) {
 		gda_internal_command_exec_result_free (tmpres);
-		g_set_error (error, 0, 0, "%s", 
-			     _("Wrong SELECT argument"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Wrong SELECT argument"));
 		return NULL;
 	}
 
@@ -5623,8 +5641,8 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
 			if (!*tmp) {
 				g_timer_destroy (timer);
 				g_object_unref (pivot);
-				g_set_error (error, 0, 0, "%s", 
-					     _("Wrong data field argument"));
+				g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+					     "%s", _("Wrong data field argument"));
 				return NULL;
 			}
 			df++;
@@ -5651,8 +5669,8 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
 			else {
 				g_timer_destroy (timer);
 				g_object_unref (pivot);
-				g_set_error (error, 0, 0, "%s", 
-					     _("Wrong data field argument"));
+				g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+					     "%s", _("Wrong data field argument"));
 				return NULL;
 			}
 			df = tmp+1;
@@ -5695,14 +5713,14 @@ extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc, const gchar
 	GdaDataModel *model, *wrapper;
 	cs = get_current_connection_settings (console);
 	if (!cs) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("No connection specified"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection specified"));
 		return NULL;
 	}
 
 	if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Connection is not an LDAP connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+			     "%s", _("Connection is not an LDAP connection"));
 		return NULL;
 	}
 
@@ -5723,7 +5741,8 @@ extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc, const gchar
 			else if (!g_ascii_strcasecmp (scope, "subtree"))
 				lscope = GDA_LDAP_SEARCH_SUBTREE;
 			else {
-				g_set_error (error, 0, 0, _("Unknown search scope '%s'"), scope);
+				g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+					     _("Unknown search scope '%s'"), scope);
 				return NULL;
 			}
 			if (args[2])
@@ -5732,8 +5751,8 @@ extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc, const gchar
         }
 
 	if (!filter) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Missing filter which to operate"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing filter which to operate"));
 		return NULL;
 	}
 
@@ -5792,14 +5811,14 @@ extra_command_ldap_mv (SqlConsole *console, GdaConnection *cnc, const gchar **ar
 	GdaDataModel *model, *wrapper;
 	cs = get_current_connection_settings (console);
 	if (!cs) {
-		g_set_error (error, 0, 0, "%s",
-			     _("No connection specified"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection specified"));
 		return NULL;
 	}
 
 	if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Connection is not an LDAP connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+			     "%s", _("Connection is not an LDAP connection"));
 		return NULL;
 	}
 
@@ -5813,8 +5832,8 @@ extra_command_ldap_mv (SqlConsole *console, GdaConnection *cnc, const gchar **ar
         }
 
 	if (!current_dn || !new_dn) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Missing current DN or new DN specification"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing current DN or new DN specification"));
 		return NULL;
 	}
 
@@ -5886,14 +5905,14 @@ extra_command_ldap_mod (SqlConsole *console, GdaConnection *cnc, const gchar **a
 	GdaDataModel *model, *wrapper;
 	cs = get_current_connection_settings (console);
 	if (!cs) {
-		g_set_error (error, 0, 0, "%s",
-			     _("No connection specified"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection specified"));
 		return NULL;
 	}
 
 	if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Connection is not an LDAP connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+			     "%s", _("Connection is not an LDAP connection"));
 		return NULL;
 	}
 
@@ -5907,13 +5926,13 @@ extra_command_ldap_mod (SqlConsole *console, GdaConnection *cnc, const gchar **a
         }
 
 	if (!dn) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Missing DN of LDAP entry"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing DN of LDAP entry"));
 		return NULL;
 	}
 	if (!op) {
-		g_set_error (error, 0, 0, "%s",
-			     _("Missing operation to perform on LDAP entry's attributes"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing operation to perform on LDAP entry's attributes"));
 		return NULL;
 	}
 
@@ -5924,7 +5943,7 @@ extra_command_ldap_mod (SqlConsole *console, GdaConnection *cnc, const gchar **a
 	else if (! g_ascii_strncasecmp (op, "ADD", 3))
 		optype = GDA_LDAP_MODIFICATION_ATTR_ADD;
 	else {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 			     _("Unknown operation '%s' to perform on LDAP entry's attributes"), op);
 		return NULL;
 	}
@@ -5945,7 +5964,7 @@ extra_command_ldap_mod (SqlConsole *console, GdaConnection *cnc, const gchar **a
 			gda_value_free (att_value);
 		}
 		else {
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 				     _("Wrong attribute value specification"), args[i]);
 			return NULL;
 		}
@@ -5981,14 +6000,14 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
 	ConnectionSetting *cs;
 	cs = get_current_connection_settings (console);
 	if (!cs) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("No connection specified"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No connection specified"));
 		return NULL;
 	}
 
 	if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Connection is not an LDAP connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+			     "%s", _("Connection is not an LDAP connection"));
 		return NULL;
 	}
 
@@ -6001,8 +6020,8 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
 			   */
 
         if (!args[0] || !*args[0]) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Missing DN (Distinguished name) argument"));		
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing DN (Distinguished name) argument"));		
 		return NULL;
         }
 	dn = args[0];
@@ -6014,7 +6033,7 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
 		else if (!g_ascii_strcasecmp (args [1], "set"))
 			options = 3;
 		else {
-			g_set_error (error, 0, 0, 
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
 				     _("Unknown '%s' argument"), args[1]);
 			return NULL;
 		}
@@ -6025,7 +6044,7 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
 	entry = gda_ldap_describe_entry (GDA_LDAP_CONNECTION (cs->cnc), dn, error);
 	if (!entry) {
 		if (error && !*error)
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 				     _("Could not find entry with DN '%s'"), dn);
 		return NULL;
 	}
@@ -6201,7 +6220,8 @@ extra_command_export (SqlConsole *console, GdaConnection *cnc, const gchar **arg
 	}
 
 	if (!cnc) {
-                g_set_error (error, 0, 0, "%s", _("No current connection"));
+                g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No current connection"));
                 return NULL;
         }
 
@@ -6216,8 +6236,8 @@ extra_command_export (SqlConsole *console, GdaConnection *cnc, const gchar **arg
 				if (args[3] && *args[3]) {
 					filename = args[3];
 					if (args [4]) {
-						g_set_error (error, 0, 0, "%s", 
-							     _("Too many arguments"));
+						g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+							     "%s", _("Too many arguments"));
 						return NULL;
 					}
 					else
@@ -6238,14 +6258,14 @@ extra_command_export (SqlConsole *console, GdaConnection *cnc, const gchar **arg
 	else if (whichargs == 2) {
 		GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
 		if (!pname) 
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 				     _("No parameter named '%s' defined"), pname);
 		else
 			value = gda_holder_get_value (param);
 	}
 	else 
-		g_set_error (error, 0, 0, "%s", 
-                             _("Wrong number of arguments"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Wrong number of arguments"));
 
 	if (value) {
 		/* to file through this blob */
@@ -6256,8 +6276,8 @@ extra_command_export (SqlConsole *console, GdaConnection *cnc, const gchar **arg
 			GdaBlob *tblob = (GdaBlob*) gda_value_get_blob (vblob);
 			const GdaBlob *fblob = gda_value_get_blob (value);
 			if (gda_blob_op_write (tblob->op, (GdaBlob*) fblob, 0) < 0)
-				g_set_error (error, 0, 0, "%s", 
-					     _("Could not write file"));
+				g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+					     "%s", _("Could not write file"));
 			else
 				done = TRUE;
 			gda_value_free (vblob);
@@ -6270,8 +6290,8 @@ extra_command_export (SqlConsole *console, GdaConnection *cnc, const gchar **arg
 			((GdaBinary *) fblob)->data = fbin->data;
 			((GdaBinary *) fblob)->binary_length = fbin->binary_length;
 			if (gda_blob_op_write (tblob->op, (GdaBlob*) fblob, 0) < 0)
-				g_set_error (error, 0, 0, "%s", 
-					     _("Could not write file"));
+				g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+					     "%s", _("Could not write file"));
 			else
 				done = TRUE;
 			g_free (fblob);
@@ -6316,7 +6336,7 @@ extra_command_unset (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnect
 			res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
 		}
 		else 
-			g_set_error (error, 0, 0,
+			g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 				     _("No parameter named '%s' defined"), pname);
 	}
 	else {
@@ -6426,7 +6446,8 @@ extra_command_graph (SqlConsole *console, GdaConnection *cnc, const gchar **args
 	}
 
 	if (!cnc) {
-		g_set_error (error, 0, 0, "%s", _("No current connection"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No current connection"));
 		return NULL;
 	}
 
@@ -6490,8 +6511,8 @@ extra_command_httpd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, cons
 		if (port > 0) {
 			main_data->server = web_server_new (port, auth_token);
 			if (!main_data->server) 
-				g_set_error (error, 0, 0, "%s", 
-					     _("Could not start HTTPD server"));
+				g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+					     "%s", _("Could not start HTTPD server"));
 			else {
 				res = g_new0 (GdaInternalCommandResult, 1);
 				res->type = GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT;
@@ -6499,8 +6520,8 @@ extra_command_httpd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, cons
 			}
 		}
 		else
-			g_set_error (error, 0, 0, "%s", 
-				     _("Invalid port specification"));
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+				     "%s", _("Invalid port specification"));
 	}
 
 	return res;
@@ -6529,7 +6550,8 @@ extra_command_lo_update (SqlConsole *console, GdaConnection *cnc, const gchar **
 	}
 
 	if (!cnc) {
-                g_set_error (error, 0, 0, "%s", _("No current connection"));
+                g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+			     "%s", _("No current connection"));
                 return NULL;
         }
 
@@ -6542,8 +6564,8 @@ extra_command_lo_update (SqlConsole *console, GdaConnection *cnc, const gchar **
 				if (args[3] && *args[3]) {
 					row_cond = args[3];
 					if (args [4]) {
-						g_set_error (error, 0, 0,
-							     _("Too many arguments"));
+						g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+							     "%s", _("Too many arguments"));
 						return NULL;
 					}
 				}
@@ -6551,8 +6573,8 @@ extra_command_lo_update (SqlConsole *console, GdaConnection *cnc, const gchar **
 		}
         }
 	if (!row_cond) {
-		g_set_error (error, 0, 0, "%s", 
-                             _("Missing arguments"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Missing arguments"));
 		return NULL;
 	}
 
@@ -6579,8 +6601,8 @@ extra_command_lo_update (SqlConsole *console, GdaConnection *cnc, const gchar **
 	if (!stmt)
 		return NULL;
 	if (remain) {
-		g_set_error (error, 0, 0, "%s", 
-			     _("Wrong row condition"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+			     "%s", _("Wrong row condition"));
 		return NULL;
 	}
 
@@ -6714,8 +6736,8 @@ gda_sql_console_execute (SqlConsole *console, const gchar *command, GError **err
 			}
 		}
 		else {
-			g_set_error (error, 0, 0,
-				     _("Command is incomplete"));
+			g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+				     "%s", _("Command is incomplete"));
 		}
 	}
 	g_free (loc_cmde);
diff --git a/tools/tools-favorites.c b/tools/tools-favorites.c
index 9f227ac..259c274 100644
--- a/tools/tools-favorites.c
+++ b/tools/tools-favorites.c
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <glib/gi18n-lib.h>
 #include "tools-favorites.h"
+#include "tools-utils.h"
 #include <libgda/thread-wrapper/gda-thread-wrapper.h>
 #include <libgda/gda-sql-builder.h>
 #include <sql-parser/gda-sql-parser.h>
@@ -180,8 +181,8 @@ meta_store_addons_init (ToolsFavorites *bfav, GError **error)
 		return TRUE;
 
 	if (!gda_meta_store_schema_add_custom_object (bfav->priv->store, FAVORITES_TABLE_DESC, &lerror)) {
-                g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize dictionary to store favorites"));
+                g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize dictionary to store favorites"));
 		g_warning ("Can't initialize dictionary to store favorites :%s",
 			   lerror && lerror->message ? lerror->message : "No detail");
 		if (lerror)
@@ -189,8 +190,8 @@ meta_store_addons_init (ToolsFavorites *bfav, GError **error)
                 return FALSE;
         }
 	if (!gda_meta_store_schema_add_custom_object (bfav->priv->store, FAVORDER_TABLE_DESC, &lerror)) {
-                g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize dictionary to store favorites"));
+                g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize dictionary to store favorites"));
 		g_warning ("Can't initialize dictionary to store favorites :%s",
 			   lerror && lerror->message ? lerror->message : "No detail");
 		if (lerror)
@@ -624,14 +625,14 @@ tools_favorites_add (ToolsFavorites *bfav, guint session_id,
 
 	store_cnc = bfav->priv->store_cnc;
 	if (! gda_lockable_trylock (GDA_LOCKABLE (store_cnc))) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize transaction to access favorites"));
 		return FALSE;
 	}
 	/* begin a transaction */
 	if (! gda_connection_begin_transaction (store_cnc, NULL, GDA_TRANSACTION_ISOLATION_UNKNOWN, NULL)) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize transaction to access favorites"));
 		gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
                 return FALSE;
 	}
@@ -803,8 +804,8 @@ tools_favorites_add (ToolsFavorites *bfav, guint session_id,
 	}
 
 	if (! gda_connection_commit_transaction (store_cnc, NULL, NULL)) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't commit transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't commit transaction to access favorites"));
 		goto err;
 	}
 
@@ -1057,15 +1058,15 @@ tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
 		return FALSE;
 
 	if (! gda_lockable_trylock (GDA_LOCKABLE (bfav->priv->store_cnc))) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize transaction to access favorites"));
 		return FALSE;
 	}
 	/* begin a transaction */
 	if (! gda_connection_begin_transaction (bfav->priv->store_cnc, NULL,
 						GDA_TRANSACTION_ISOLATION_UNKNOWN, NULL)) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't initialize transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't initialize transaction to access favorites"));
 		gda_lockable_unlock (GDA_LOCKABLE (bfav->priv->store_cnc));
                 return FALSE;
 	}
@@ -1087,7 +1088,7 @@ tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
 		}
 	}
 	if (favid < 0) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
 			     "%s", _("Could not find favorite"));
 		goto out;
 	}
@@ -1132,8 +1133,8 @@ tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
 	g_object_unref (stmt);
 
 	if (! gda_connection_commit_transaction (bfav->priv->store_cnc, NULL, NULL)) {
-		g_set_error (error, 0, 0, "%s",
-                             _("Can't commit transaction to access favorites"));
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+			     "%s", _("Can't commit transaction to access favorites"));
 		goto out;
 	}
 	retval = TRUE;
diff --git a/tools/tools-input.c b/tools/tools-input.c
index 1d1d354..d7f09e0 100644
--- a/tools/tools-input.c
+++ b/tools/tools-input.c
@@ -18,6 +18,7 @@
  */
 
 #include "tools-input.h"
+#include "tools-utils.h"
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 #include <string.h>
@@ -317,7 +318,7 @@ save_history (const gchar *file, GError **error)
 	if (res == ENOENT)
 		res = write_history (file ? file : history_file);
 	if (res != 0) {
-		g_set_error (error, 0, 0,
+		g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
 			     _("Could not save history file to '%s': %s"), 
 			     file ? file : history_file, strerror (errno));
 		return FALSE;
diff --git a/tools/tools-utils.c b/tools/tools-utils.c
index d37f230..809ad62 100644
--- a/tools/tools-utils.c
+++ b/tools/tools-utils.c
@@ -47,3 +47,13 @@ tools_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy)
 		return _("set to default value");
 	}
 }
+
+/* module error */
+GQuark
+tools_error_quark (void)
+{
+        static GQuark quark;
+        if (!quark)
+                quark = g_quark_from_static_string ("tools_error");
+        return quark;
+}
diff --git a/tools/tools-utils.h b/tools/tools-utils.h
index 3538902..566713b 100644
--- a/tools/tools-utils.h
+++ b/tools/tools-utils.h
@@ -23,4 +23,22 @@
 
 const gchar *tools_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy);
 
+/*
+ * error reporting
+ */
+extern GQuark tools_error_quark (void);
+#define TOOLS_ERROR tools_error_quark ()
+
+typedef enum {
+	TOOLS_NO_CONNECTION_ERROR,
+	TOOLS_CONNECTION_CLOSED_ERROR,
+	TOOLS_INTERNAL_COMMAND_ERROR,
+	TOOLS_COMMAND_ARGUMENTS_ERROR,
+	TOOLS_OBJECT_NOT_FOUND_ERROR,
+	TOOLS_PROVIDER_NOT_FOUND_ERROR,
+	TOOLS_DSN_NOT_FOUND_ERROR,
+	TOOLS_STORED_DATA_ERROR,
+	TOOLS_PURGE_ERROR
+} ToolsError;
+
 #endif



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