[libgda] Gda-sql console improvements



commit 51e51c89ad086f6e0cc2a87e7e6b0b8f5c8845b9
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Apr 28 21:16:07 2009 +0200

    Gda-sql console improvements
    
    	* tools/gda-sql.c:
    	  - allow to specify which kind of meta data to update in the "meta" command
    	  - store the dictionary in a file even for connections not created from a DSN
    	    if GLIB >= 2.16.0, no change otherwise
---
 ChangeLog            |    8 ++++
 tools/command-exec.c |   16 ++++++++-
 tools/gda-sql.c      |   94 ++++++++++++++++++++++++++++++++++++++++---------
 3 files changed, 99 insertions(+), 19 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d5887a5..f22bfe7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-04-28  Vivien Malerba <malerba gnome-db org>
+
+	* libgda.doap: prefixed mail with "mailto:";
+	* tools/gda-sql.c:
+	  - allow to specify which kind of meta data to update in the "meta" command
+	  - store the dictionary in a file even for connections not created from a DSN
+	    if GLIB >= 2.16.0, no change otherwise
+
 2009-04-23  Vivien Malerba <malerba gnome-db org>
 
 	* libgda/gda-config.c: only display a warning if loading a provider fails if the
diff --git a/tools/command-exec.c b/tools/command-exec.c
index 4af937d..388284a 100644
--- a/tools/command-exec.c
+++ b/tools/command-exec.c
@@ -345,7 +345,21 @@ gda_internal_command_dict_sync (SqlConsole *console, GdaConnection *cnc, const g
 	res = g_new0 (GdaInternalCommandResult, 1);
 	res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
 
-	if (!gda_connection_update_meta_store (cnc, NULL, error)) {
+	if (args[0] && *args[0]) {
+		GdaMetaContext context;
+		memset (&context, 0, sizeof (context));
+		if (*args[0] == '_')
+			context.table_name = args[0];
+		else
+			context.table_name = g_strdup_printf ("_%s", args[0]);
+		if (!gda_connection_update_meta_store (cnc, &context, error)) {
+			g_free (res);
+			res = NULL;
+		}
+		if (*args[0] != '_')
+			g_free (context.table_name);
+	}
+	else if (!gda_connection_update_meta_store (cnc, NULL, error)) {
 		g_free (res);
 		res = NULL;
 	}
diff --git a/tools/gda-sql.c b/tools/gda-sql.c
index ad4b3cd..f90caf3 100644
--- a/tools/gda-sql.c
+++ b/tools/gda-sql.c
@@ -1242,6 +1242,7 @@ typedef struct {
 static gpointer thread_start_update_meta_store (MetaUpdateData *data);
 static void thread_ok_cb_update_meta_store (GdaThreader *threader, guint job, MetaUpdateData *data);
 static void thread_cancelled_cb_update_meta_store (GdaThreader *threader, guint job, MetaUpdateData *data);
+static gchar *compute_dict_file_name (GdaDsnInfo *info, const gchar *cnc_string);
 
 /*
  * Open a connection
@@ -1253,6 +1254,7 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
 	ConnectionSetting *cs = NULL;
 	static gint cncindex = 0;
 	gchar *real_cnc_string;
+	gchar *dict_file_name = NULL;
 
 	if (cnc_name && ! connection_name_is_valid (cnc_name)) {
 		g_set_error (error, 0, 0,
@@ -1355,6 +1357,8 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
 		newcnc = gda_connection_open_from_string (NULL, real_cnc_string, real_auth_string,
 							  GDA_CONNECTION_OPTIONS_THREAD_SAFE, error);
 	
+	dict_file_name = compute_dict_file_name (info, real_cnc_string);
+
 	g_free (real_cnc_string);
 	g_free (real_cnc);
 	g_free (user);
@@ -1386,23 +1390,10 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
 		GdaMetaStore *store;
 		gboolean update_store = FALSE;
 
-		if (info) {
-			gchar *filename;
-			gchar *confdir;
-
-			confdir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), "libgda", NULL);
-			if (!g_file_test (confdir, G_FILE_TEST_EXISTS)) {
-				g_free (confdir);
-				confdir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".libgda", NULL);
-			}
-			filename = g_strdup_printf ("%s%sgda-sql-%s.db", 
-						    confdir, G_DIR_SEPARATOR_S,
-						    info->name);
-			g_free (confdir);
-			if (! g_file_test (filename, G_FILE_TEST_EXISTS))
+		if (dict_file_name) {
+			if (! g_file_test (dict_file_name, G_FILE_TEST_EXISTS))
 				update_store = TRUE;
-			store = gda_meta_store_new_with_file (filename);
-			g_free (filename);
+			store = gda_meta_store_new_with_file (dict_file_name);
 		}
 		else {
 			store = gda_meta_store_new (NULL);
@@ -1456,6 +1447,7 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
 		if (store)
 			g_object_unref (store);
 	}
+	g_free (dict_file_name);
 
 	return cs;
 }
@@ -1476,6 +1468,72 @@ thread_start_update_meta_store (MetaUpdateData *data)
 }
 
 static void
+compute_dict_file_name_foreach_cb (const gchar *key, const gchar *value, GSList **list)
+{
+	if (!*list) 
+		*list = g_slist_prepend (NULL, (gpointer) key);
+	else
+		*list = g_slist_insert_sorted (*list, (gpointer) key, (GCompareFunc) strcmp);
+}
+
+static gchar *
+compute_dict_file_name (GdaDsnInfo *info, const gchar *cnc_string)
+{
+	gchar *filename = NULL;
+	gchar *confdir;
+
+	confdir = g_build_path (G_DIR_SEPARATOR_S, g_get_user_data_dir (), "libgda", NULL);
+	if (!g_file_test (confdir, G_FILE_TEST_EXISTS)) {
+		g_free (confdir);
+		confdir = g_build_path (G_DIR_SEPARATOR_S, g_get_home_dir (), ".libgda", NULL);
+	}
+
+	if (info) {		
+		filename = g_strdup_printf ("%s%sgda-sql-%s.db", 
+					    confdir, G_DIR_SEPARATOR_S,
+					    info->name);
+	}
+	else {
+#if GLIB_CHECK_VERSION(2,16,0)
+		GdaQuarkList *ql;
+		GSList *list, *sorted_list = NULL;
+		GString *string = NULL;
+		ql = gda_quark_list_new_from_string (cnc_string);
+
+		gda_quark_list_foreach (ql, (GHFunc) compute_dict_file_name_foreach_cb, &sorted_list);
+		for (list = sorted_list; list; list = list->next) {
+			const gchar *value;
+			gchar *evalue;
+
+			if (!string)
+				string = g_string_new ("");
+			else
+				g_string_append_c (string, ',');
+
+			value = gda_quark_list_find (ql, (gchar *) list->data);
+			evalue = gda_rfc1738_encode (value);
+			g_string_append_printf (string, ",%s=%s", (gchar *) list->data, evalue);
+			g_free (evalue);
+		}
+		gda_quark_list_free (ql);
+
+		if (string) {
+			gchar *chname;
+			chname = g_compute_checksum_for_string (G_CHECKSUM_SHA1, string->str, -1);
+			g_string_free (string, TRUE);
+			filename = g_strdup_printf ("%s%sgda-sql-%s.db", 
+					    confdir, G_DIR_SEPARATOR_S,
+					    chname);
+			g_free (chname);
+		}
+#endif
+	}
+
+	g_free (confdir);
+	return filename;
+}
+
+static void
 thread_ok_cb_update_meta_store (GdaThreader *threader, guint job, MetaUpdateData *data)
 {
 	data->cs->meta_job_id = 0;
@@ -1875,8 +1933,8 @@ build_internal_commands_list (void)
 
 	c = g_new0 (GdaInternalCommand, 1);
 	c->group = _("Information");
-	c->name = "meta";
-	c->description = _("Force reading the database meta data");
+	c->name = g_strdup_printf (_("%s [META DATA TYPE]"), "meta");
+	c->description = _("Force reading the database meta data (or part of the meta data, ex:\"tables\")");
 	c->args = NULL;
 	c->command_func = gda_internal_command_dict_sync;
 	c->user_data = NULL;



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