[libgda/LIBGDA_4.2] Tools: allow displaying DNS information
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_4.2] Tools: allow displaying DNS information
- Date: Wed, 11 May 2011 20:26:00 +0000 (UTC)
commit 0dd7d9446f94497c8e30267d602c7316b4e30315
Author: Vivien Malerba <malerba gnome-db org>
Date: Tue May 10 23:14:20 2011 +0200
Tools: allow displaying DNS information
tools/browser/main.c | 17 +++++-
tools/config-info.c | 151 +++++++++++++++++++++++++++++++++++++++++++++++++-
tools/config-info.h | 1 +
tools/gda-sql.c | 78 +++++++++-----------------
4 files changed, 191 insertions(+), 56 deletions(-)
---
diff --git a/tools/browser/main.c b/tools/browser/main.c
index 334d6b6..d2958e0 100644
--- a/tools/browser/main.c
+++ b/tools/browser/main.c
@@ -131,9 +131,20 @@ main (int argc, char *argv[])
if (list_configs) {
gda_init ();
setlocale (LC_ALL, "");
- GdaDataModel *model = config_info_list_all_dsn ();
- output_data_model (model);
- g_object_unref (model);
+ GdaDataModel *model;
+ if (argc == 2)
+ model = config_info_detail_dsn (argv[1], &error);
+ else
+ model = config_info_list_all_dsn ();
+ if (model) {
+ output_data_model (model);
+ g_object_unref (model);
+ }
+ else {
+ g_print (_("Error: %s\n"),
+ error && error->message ? error->message : _("No detail"));
+ g_clear_error (&error);
+ }
return 0;
}
if (list_data_files) {
diff --git a/tools/config-info.c b/tools/config-info.c
index 0606870..914e23e 100644
--- a/tools/config-info.c
+++ b/tools/config-info.c
@@ -78,8 +78,11 @@ config_info_detail_provider (const gchar *provider, GError **error)
{
GdaProviderInfo *pinfo;
pinfo = gda_config_get_provider_info (provider);
- if (! pinfo)
+ if (! pinfo) {
+ g_set_error (error, 0, 0,
+ _("Could not find provider '%s'"), provider);
return NULL;
+ }
GdaDataModel *model;
GValue *tmpvalue = NULL;
@@ -230,6 +233,152 @@ config_info_detail_provider (const gchar *provider, GError **error)
return NULL;
}
+static void
+ql_foreach_cb (const gchar *name, const gchar *value, GString *string)
+{
+ if (*string->str)
+ g_string_append (string, "\n");
+ g_string_append_printf (string, "%s: %s", name, value);
+}
+
+GdaDataModel *
+config_info_detail_dsn (const gchar *dsn, GError **error)
+{
+ GdaDsnInfo *info = NULL;
+ if (dsn && *dsn)
+ info = gda_config_get_dsn_info (dsn);
+ if (!info) {
+ g_set_error (error, 0, 0,
+ _("Could not find data source '%s'"), dsn);
+ return NULL;
+ }
+
+ GdaDataModel *model;
+ GValue *tmpvalue = NULL;
+ gint row;
+
+ /* define data model */
+ model = gda_data_model_array_new_with_g_types (2,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+ gda_data_model_set_column_title (model, 0, _("Attribute"));
+ gda_data_model_set_column_title (model, 1, _("Value"));
+ g_object_set_data_full (G_OBJECT (model), "name",
+ g_strdup_printf (_("DSN '%s' description"), dsn),
+ g_free);
+ /* DSN name */
+ row = 0;
+ if (gda_data_model_append_row (model, error) == -1)
+ goto onerror;
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), _("DSN name"));
+ if (! gda_data_model_set_value_at (model, 0, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), info->name);
+ if (! gda_data_model_set_value_at (model, 1, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ /* provider */
+ row++;
+ if (gda_data_model_append_row (model, error) == -1)
+ goto onerror;
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), _("Provider"));
+ if (! gda_data_model_set_value_at (model, 0, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), info->provider);
+ if (! gda_data_model_set_value_at (model, 1, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ /* description */
+ row++;
+ if (gda_data_model_append_row (model, error) == -1)
+ goto onerror;
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), _("Description"));
+ if (! gda_data_model_set_value_at (model, 0, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), info->description);
+ if (! gda_data_model_set_value_at (model, 1, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ /* CNC prameters */
+ row++;
+ if (gda_data_model_append_row (model, error) == -1)
+ goto onerror;
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), _("Parameters"));
+ if (! gda_data_model_set_value_at (model, 0, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ if (info->cnc_string) {
+ GString *string;
+ GdaQuarkList *ql;
+ string = g_string_new ("");
+ ql = gda_quark_list_new_from_string (info->cnc_string);
+ gda_quark_list_foreach (ql, (GHFunc) ql_foreach_cb, string);
+ gda_quark_list_free (ql);
+
+ g_value_take_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), string->str);
+ g_string_free (string, FALSE);
+ if (! gda_data_model_set_value_at (model, 1, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+ }
+
+ /* authentication */
+ row++;
+ if (gda_data_model_append_row (model, error) == -1)
+ goto onerror;
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), _("Authentication"));
+ if (! gda_data_model_set_value_at (model, 0, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ if (info->auth_string) {
+ GString *string;
+ GdaQuarkList *ql;
+ string = g_string_new ("");
+ ql = gda_quark_list_new_from_string (info->auth_string);
+ gda_quark_list_foreach (ql, (GHFunc) ql_foreach_cb, string);
+ gda_quark_list_free (ql);
+
+ g_value_take_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), string->str);
+ g_string_free (string, FALSE);
+ if (! gda_data_model_set_value_at (model, 1, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+ }
+
+ /* system wide? */
+ row++;
+ if (gda_data_model_append_row (model, error) == -1)
+ goto onerror;
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)), _("System DSN?"));
+ if (! gda_data_model_set_value_at (model, 0, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)),
+ info->is_system ? _("Yes") : _("No"));
+ if (! gda_data_model_set_value_at (model, 1, row, tmpvalue, error))
+ goto onerror;
+ gda_value_free (tmpvalue);
+
+ return model;
+ onerror:
+ if (tmpvalue)
+ gda_value_free (tmpvalue);
+ g_object_unref (model);
+ return NULL;
+}
+
GdaDataModel *
config_info_list_data_files (GError **error)
{
diff --git a/tools/config-info.h b/tools/config-info.h
index c794c86..6f83003 100644
--- a/tools/config-info.h
+++ b/tools/config-info.h
@@ -31,6 +31,7 @@ void config_info_update_meta_store_properties (GdaMetaStore *mstore, Gd
GdaDataModel *config_info_list_all_dsn (void);
GdaDataModel *config_info_list_all_providers (void);
GdaDataModel *config_info_detail_provider (const gchar *provider, GError **error);
+GdaDataModel *config_info_detail_dsn (const gchar *dsn, GError **error);
GdaDataModel *config_info_list_data_files (GError **error);
gchar *config_info_purge_data_files (const gchar *criteria, GError **error);
diff --git a/tools/gda-sql.c b/tools/gda-sql.c
index 9b7d192..63b8d4a 100644
--- a/tools/gda-sql.c
+++ b/tools/gda-sql.c
@@ -216,10 +216,17 @@ main (int argc, char *argv[])
}
}
if (list_configs) {
- GdaDataModel *model = config_info_list_all_dsn ();
- output_data_model (model);
- g_object_unref (model);
- goto cleanup;
+ if (argc == 2) {
+ single_command = g_strdup_printf (".l %s", argv[1]);
+ argc = 1;
+ show_welcome = FALSE;
+ }
+ else {
+ GdaDataModel *model = config_info_list_all_dsn ();
+ output_data_model (model);
+ g_object_unref (model);
+ goto cleanup;
+ }
}
if (list_data_files) {
gchar *confdir;
@@ -2704,61 +2711,28 @@ extra_command_list_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConn
const gchar **args, GError **error, G_GNUC_UNUSED gpointer data)
{
GdaInternalCommandResult *res;
- GdaDataModel *dsn_list, *model = NULL;
- gint i, nrows;
GList *list = NULL;
-
- dsn_list = gda_config_list_dsn ();
- nrows = gda_data_model_get_n_rows (dsn_list);
+ GdaDataModel *dsn_list = NULL, *model = NULL;
if (args[0]) {
/* details about a DSN */
- for (i = 0; i < nrows; i++) {
- const GValue *value;
- value = gda_data_model_get_value_at (dsn_list, 0, i, error);
- if (!value)
- goto onerror;
-
- if (!strcmp (g_value_get_string (value), args[0])) {
- gint j;
- model = gda_data_model_array_new_with_g_types (2,
- G_TYPE_STRING,
- G_TYPE_STRING);
- gda_data_model_set_column_title (model, 0, _("Attribute"));
- gda_data_model_set_column_title (model, 1, _("Value"));
- g_object_set_data_full (G_OBJECT (model), "name",
- g_strdup_printf (_("DSN '%s' description"), args[0]),
- g_free);
-
- for (j = 0; j < 6; j++) {
- GValue *tmpvalue;
- if (gda_data_model_append_row (model, error) == -1)
- goto onerror;
-
- g_value_set_string ((tmpvalue = gda_value_new (G_TYPE_STRING)),
- gda_data_model_get_column_title (dsn_list, j));
- if (! gda_data_model_set_value_at (model, 0, j, tmpvalue, error))
- goto onerror;
- gda_value_free (tmpvalue);
-
- value = gda_data_model_get_value_at (dsn_list, j, i, error);
- if (!value ||
- ! gda_data_model_set_value_at (model, 1, j, value, error))
- goto onerror;
- }
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
- res->u.model = model;
- g_object_unref (dsn_list);
- return res;
- }
+ GdaDataModel *model;
+ model = config_info_detail_dsn (args[0], error);
+ if (model) {
+ res = g_new0 (GdaInternalCommandResult, 1);
+ res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+ return res;
}
- g_object_unref (dsn_list);
- g_set_error (error, 0, 0,
- _("Could not find any DSN named '%s'"), args[0]);
- return NULL;
+ else
+ return NULL;
}
else {
+ gint i, nrows;
+
+ dsn_list = gda_config_list_dsn ();
+ nrows = gda_data_model_get_n_rows (dsn_list);
+
model = gda_data_model_array_new_with_g_types (3,
G_TYPE_STRING,
G_TYPE_STRING,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]