[libgda/gtk3] Gda-sql and gda-browser: better information about config
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/gtk3] Gda-sql and gda-browser: better information about config
- Date: Tue, 7 Dec 2010 20:15:07 +0000 (UTC)
commit bcd549039e98804c321223705933ad280660beeb
Author: Vivien Malerba <malerba gnome-db org>
Date: Mon Dec 6 20:45:03 2010 +0100
Gda-sql and gda-browser: better information about config
po/POTFILES.in | 1 +
tools/Makefile.am | 2 +
tools/README | 28 +++++++
tools/browser/Makefile.am | 1 +
tools/browser/main.c | 37 ++++++++++
tools/config-info.c | 129 +++++++++++++++++++++++++++++++++
tools/config-info.h | 31 ++++++++
tools/gda-sql.c | 176 ++++++--------------------------------------
8 files changed, 253 insertions(+), 152 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 16b2aeb..9157c40 100755
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -288,6 +288,7 @@ tools/browser/schema-browser/table-columns.c
tools/browser/schema-browser/table-info.c
tools/browser/schema-browser/table-preferences.c
tools/command-exec.c
+tools/config-info.c
tools/gda-list-config.c
tools/gda-list-server-op.c
tools/gda-sql.c
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 17da585..74dcb2d 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -28,6 +28,8 @@ gda_list_config_5_0_LDADD = \
$(LIBGDA_LIBS)
gda_sql_5_0_SOURCES = \
+ config-info.h \
+ config-info.c \
gda-sql.c \
gda-sql.h \
gda-threader.h \
diff --git a/tools/README b/tools/README
new file mode 100644
index 0000000..5b31d0b
--- /dev/null
+++ b/tools/README
@@ -0,0 +1,28 @@
+gda-sql-4.0
+-----------
+Console program to open connections to databases and execute SQL commands.
+
+
+gda-list-config-4.0
+-------------------
+Gives a list of installed database providers (along with all the parameters
+they each accept when opening a connection, and a list of the configured DSN
+(data source name).
+
+
+gda-list-server-op-4.0:
+-----------------------
+Gives a list of named parameters expected, for each database provider and for
+each type of server operation.
+
+
+information-schema-doc
+----------------------
+Generates the i_s_doc.xml file from the libgda/information-schema.xml file
+to be included in the documentation, in $topsrcdir/doc/C/.
+
+
+information-schema-types
+------------------------
+Generates the gda-meta-column-types.h file from the libgda/information-schema.xml file
+to be used by database providers, must be moved to $topsrcdir/libgda/providers-support/.
diff --git a/tools/browser/Makefile.am b/tools/browser/Makefile.am
index 25efe65..0c9f43f 100644
--- a/tools/browser/Makefile.am
+++ b/tools/browser/Makefile.am
@@ -31,6 +31,7 @@ marshal.c: marshal.list $(GLIB_GENMARSHAL) marshal.h
$(GLIB_GENMARSHAL) $< --body --prefix=_marshal > $@
libbrowser_la_SOURCES=\
+ ../config-info.c \
cc-gray-bar.c \
cc-gray-bar.h \
marshal.c \
diff --git a/tools/browser/main.c b/tools/browser/main.c
index 321a45d..0241800 100644
--- a/tools/browser/main.c
+++ b/tools/browser/main.c
@@ -30,6 +30,7 @@
#include "login-dialog.h"
#include "auth-dialog.h"
#include "browser-stock-icons.h"
+#include "../config-info.h"
/* Perspectives' factories */
#include "schema-browser/perspective-main.h"
@@ -52,10 +53,14 @@ main_browser_core_init_factories (void)
/* options */
gchar *perspective = NULL;
+gboolean list_configs = FALSE;
+gboolean list_providers = FALSE;
static GOptionEntry entries[] = {
{ "perspective", 'p', 0, G_OPTION_ARG_STRING, &perspective, "Perspective", "default perspective "
"to use when opening windows"},
+ { "list-dsn", 'l', 0, G_OPTION_ARG_NONE, &list_configs, "List configured data sources and exit", NULL },
+ { "list-providers", 'L', 0, G_OPTION_ARG_NONE, &list_providers, "List installed database providers and exit", NULL },
{ NULL, 0, 0, 0, NULL, NULL, NULL }
};
@@ -78,6 +83,38 @@ main (int argc, char *argv[])
}
g_option_context_free (context);
+ /* treat here lists of providers and defined DSN */
+ if (list_providers) {
+ gda_init ();
+ GdaDataModel *model;
+ if (argc == 2)
+ model = config_info_detail_provider (argv[1], &error);
+ else
+ model = config_info_list_all_providers ();
+
+ if (model) {
+ g_setenv ("GDA_DATA_MODEL_DUMP_TITLE", "Yes", TRUE);
+ g_setenv ("GDA_DATA_MODEL_NULL_AS_EMPTY", "Yes", TRUE);
+ gda_data_model_dump (model, NULL);
+ 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_configs) {
+ gda_init ();
+ GdaDataModel *model = config_info_list_all_dsn ();
+ g_setenv ("GDA_DATA_MODEL_DUMP_TITLE", "Yes", TRUE);
+ g_setenv ("GDA_DATA_MODEL_NULL_AS_EMPTY", "Yes", TRUE);
+ gda_data_model_dump (model, NULL);
+ g_object_unref (model);
+ return 0;
+ }
+
gdaui_init ();
gtk_init (&argc, &argv);
#ifdef HAVE_MAC_INTEGRATION
diff --git a/tools/config-info.c b/tools/config-info.c
new file mode 100644
index 0000000..40ff86d
--- /dev/null
+++ b/tools/config-info.c
@@ -0,0 +1,129 @@
+/*
+ * Copyright (C) 2010 The GNOME Foundation.
+ *
+ * AUTHORS:
+ * 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 as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include "config-info.h"
+#include <glib/gi18n-lib.h>
+
+GdaDataModel *
+config_info_list_all_dsn (void)
+{
+ return gda_config_list_dsn ();
+}
+
+GdaDataModel *
+config_info_list_all_providers (void)
+{
+ GdaDataModel *prov_list, *model;
+ gint i, nrows;
+
+ prov_list = gda_config_list_providers ();
+
+ model = gda_data_model_array_new_with_g_types (2,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+ gda_data_model_set_column_title (model, 0, _("Provider"));
+ gda_data_model_set_column_title (model, 1, _("Description"));
+ g_object_set_data (G_OBJECT (model), "name", _("Installed providers list"));
+
+ nrows = gda_data_model_get_n_rows (prov_list);
+ for (i =0; i < nrows; i++) {
+ const GValue *value;
+ GList *list = NULL;
+ value = gda_data_model_get_value_at (prov_list, 0, i, NULL);
+ if (!value)
+ goto onerror;
+ list = g_list_append (list, gda_value_copy (value));
+ value = gda_data_model_get_value_at (prov_list, 1, i, NULL);
+ if (!value)
+ goto onerror;
+ list = g_list_append (list, gda_value_copy (value));
+
+ if (gda_data_model_append_values (model, list, NULL) == -1)
+ goto onerror;
+
+ g_list_foreach (list, (GFunc) gda_value_free, NULL);
+ g_list_free (list);
+ }
+ g_object_unref (prov_list);
+ return model;
+
+ onerror:
+ g_warning ("Could not obtain the list of database providers");
+ g_object_unref (prov_list);
+ g_object_unref (model);
+ return NULL;
+}
+
+GdaDataModel *
+config_info_detail_provider (const gchar *provider, GError **error)
+{
+ GdaDataModel *prov_list, *model = NULL;
+ gint i, nrows;
+
+ prov_list = gda_config_list_providers ();
+ nrows = gda_data_model_get_n_rows (prov_list);
+
+ for (i = 0; i < nrows; i++) {
+ const GValue *value;
+ value = gda_data_model_get_value_at (prov_list, 0, i, error);
+ if (!value)
+ goto onerror;
+
+ if (!strcmp (g_value_get_string (value), provider)) {
+ 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 (_("Provider '%s' description"), provider),
+ g_free);
+
+ for (j = 0; j < 5; 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 (prov_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 (prov_list, j, i, error);
+ if (!value ||
+ ! gda_data_model_set_value_at (model, 1, j, value, error))
+ goto onerror;
+ }
+ g_object_unref (prov_list);
+ return model;
+ }
+ }
+ g_object_unref (prov_list);
+ g_set_error (error, 0, 0,
+ _("Could not find any provider named '%s'"), provider);
+ return model;
+
+ onerror:
+ g_object_unref (prov_list);
+ return NULL;
+}
diff --git a/tools/config-info.h b/tools/config-info.h
new file mode 100644
index 0000000..752847d
--- /dev/null
+++ b/tools/config-info.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2010 The GNOME Foundation.
+ *
+ * AUTHORS:
+ * 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 as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __GDA_CONFIG_INFO__
+#define __GDA_CONFIG_INFO__
+
+#include <libgda/libgda.h>
+
+GdaDataModel *config_info_list_all_dsn (void);
+GdaDataModel *config_info_list_all_providers (void);
+GdaDataModel *config_info_detail_provider (const gchar *provider, GError **error);
+
+#endif
diff --git a/tools/gda-sql.c b/tools/gda-sql.c
index 3faa058..9d43ed1 100644
--- a/tools/gda-sql.c
+++ b/tools/gda-sql.c
@@ -29,6 +29,7 @@
#include <stdlib.h>
#include <glib/gstdio.h>
#include "tools-input.h"
+#include "config-info.h"
#include "command-exec.h"
#include <unistd.h>
#ifdef HAVE_TERMIOS_H
@@ -138,8 +139,6 @@ static void output_string (const gchar *str);
static ConnectionSetting *open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_string,
GError **error);
static void connection_settings_free (ConnectionSetting *cs);
-static GdaDataModel *list_all_dsn (void);
-static GdaDataModel *list_all_providers (void);
static gboolean treat_line_func (const gchar *cmde, gboolean *out_cmde_exec_ok);
static const char *prompt_func (void);
@@ -161,6 +160,7 @@ main (int argc, char *argv[])
GError *error = NULL;
MainData *data;
int exit_status = EXIT_SUCCESS;
+ gboolean show_welcome = TRUE;
prompt = g_string_new ("");
context = g_option_context_new (_("[DSN|connection string]..."));
@@ -197,13 +197,20 @@ main (int argc, char *argv[])
/* treat here lists of providers and defined DSN */
if (list_providers) {
- GdaDataModel *model = list_all_providers ();
- output_data_model (model);
- g_object_unref (model);
- goto cleanup;
+ if (argc == 2) {
+ single_command = g_strdup_printf (".lp %s", argv[1]);
+ argc = 1;
+ show_welcome = FALSE;
+ }
+ else {
+ GdaDataModel *model = config_info_list_all_providers ();
+ output_data_model (model);
+ g_object_unref (model);
+ goto cleanup;
+ }
}
if (list_configs) {
- GdaDataModel *model = list_all_dsn ();
+ GdaDataModel *model = config_info_list_all_dsn ();
output_data_model (model);
g_object_unref (model);
goto cleanup;
@@ -225,7 +232,7 @@ main (int argc, char *argv[])
}
/* welcome message */
- if (!data->output_stream) {
+ if (show_welcome && !data->output_stream) {
#ifdef G_OS_WIN32
HANDLE wHnd;
SMALL_RECT windowSize = {0, 0, 139, 49};
@@ -1827,61 +1834,6 @@ output_string (const gchar *str)
}
}
-/*
- * Lists all the sections in the config files (local to the user and global) in the index page
- */
-static GdaDataModel *
-list_all_dsn (void)
-{
- return gda_config_list_dsn ();
-}
-
-/*
- * make a list of all the providers in the index page
- */
-static GdaDataModel *
-list_all_providers (void)
-{
- GdaDataModel *prov_list, *model;
- gint i, nrows;
-
- prov_list = gda_config_list_providers ();
-
- model = gda_data_model_array_new_with_g_types (2,
- G_TYPE_STRING,
- G_TYPE_STRING);
- gda_data_model_set_column_title (model, 0, _("Provider"));
- gda_data_model_set_column_title (model, 1, _("Description"));
- g_object_set_data (G_OBJECT (model), "name", _("Installed providers list"));
-
- nrows = gda_data_model_get_n_rows (prov_list);
- for (i =0; i < nrows; i++) {
- const GValue *value;
- GList *list = NULL;
- value = gda_data_model_get_value_at (prov_list, 0, i, NULL);
- if (!value)
- goto onerror;
- list = g_list_append (list, gda_value_copy (value));
- value = gda_data_model_get_value_at (prov_list, 1, i, NULL);
- if (!value)
- goto onerror;
- list = g_list_append (list, gda_value_copy (value));
-
- if (gda_data_model_append_values (model, list, NULL) == -1)
- goto onerror;
-
- g_list_foreach (list, (GFunc) gda_value_free, NULL);
- g_list_free (list);
- }
- g_object_unref (prov_list);
- return model;
- onerror:
- g_warning ("Could not obtain the list of database providers");
- g_object_unref (prov_list);
- g_object_unref (model);
- return NULL;
-}
-
static gchar **args_as_string_func (const gchar *str);
static gchar **args_as_string_set (const gchar *str);
@@ -2811,107 +2763,27 @@ extra_command_remove_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
return res;
}
+/*
+ * @console, @cnc and @data are unused here
+ */
static GdaInternalCommandResult *
extra_command_list_providers (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
const gchar **args, GError **error, G_GNUC_UNUSED gpointer data)
{
GdaInternalCommandResult *res;
- GdaDataModel *prov_list, *model = NULL;
- gint i, nrows;
- GList *list = NULL;
-
- prov_list = gda_config_list_providers ();
- nrows = gda_data_model_get_n_rows (prov_list);
-
- if (args[0]) {
- /* details about a provider */
- for (i = 0; i < nrows; i++) {
- const GValue *value;
- value = gda_data_model_get_value_at (prov_list, 0, i, error);
- if (!value)
- goto onerror;
+ GdaDataModel *model;
- 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 (_("Provider '%s' description"), args[0]),
- g_free);
-
- for (j = 0; j < 5; 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 (prov_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 (prov_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 (prov_list);
- return res;
- }
- }
- g_object_unref (prov_list);
- g_set_error (error, 0, 0,
- _("Could not find any provider named '%s'"), args[0]);
- return NULL;
- }
- else {
- model = gda_data_model_array_new_with_g_types (2,
- G_TYPE_STRING,
- G_TYPE_STRING);
- gda_data_model_set_column_title (model, 0, _("Provider"));
- gda_data_model_set_column_title (model, 1, _("Description"));
- g_object_set_data (G_OBJECT (model), "name", _("Installed providers list"));
-
- for (i =0; i < nrows; i++) {
- const GValue *value;
- list = NULL;
- value = gda_data_model_get_value_at (prov_list, 0, i, error);
- if (!value)
- goto onerror;
- list = g_list_append (list, gda_value_copy (value));
- value = gda_data_model_get_value_at (prov_list, 1, i, error);
- if (!value)
- goto onerror;
- list = g_list_append (list, gda_value_copy (value));
-
- if (gda_data_model_append_values (model, list, error) == -1)
- goto onerror;
-
- g_list_foreach (list, (GFunc) gda_value_free, NULL);
- g_list_free (list);
- }
+ if (args[0])
+ model = config_info_detail_provider (args[0], error);
+ else
+ model = config_info_list_all_providers ();
+ if (model) {
res = g_new0 (GdaInternalCommandResult, 1);
res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
- g_object_unref (prov_list);
-
return res;
}
-
- onerror:
- if (list) {
- g_list_foreach (list, (GFunc) gda_value_free, NULL);
- g_list_free (list);
- }
- g_object_unref (prov_list);
- g_object_unref (model);
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]