[libgda] Improved Gda-Sql: code cleanups and small bug fixes
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Improved Gda-Sql: code cleanups and small bug fixes
- Date: Sat, 8 Dec 2012 18:49:45 +0000 (UTC)
commit 531f0fd43f4cd0156eb93c5e5bd309d28a5c0cae
Author: Vivien Malerba <malerba gnome-db org>
Date: Sat Dec 8 18:32:02 2012 +0100
Improved Gda-Sql: code cleanups and small bug fixes
configure.ac | 1 +
tools/Makefile.am | 10 +-
tools/browser/Makefile.am | 8 +-
tools/browser/auth-dialog.c | 2 +-
tools/browser/browser-connection.c | 20 +-
tools/browser/browser-virtual-connection.c | 4 +-
tools/browser/canvas/browser-canvas-fkey.c | 6 +-
tools/browser/common/favorites-actions.c | 32 +-
tools/browser/common/favorites-actions.h | 6 +-
tools/browser/common/fk-declare.c | 6 +-
tools/browser/common/ui-formgrid.c | 8 +-
tools/browser/connection-binding-properties.c | 4 +-
tools/browser/data-manager/data-console.c | 12 +-
.../browser/data-manager/data-favorite-selector.c | 16 +-
.../data-manager/data-manager-perspective.c | 2 +-
tools/browser/data-manager/data-source.c | 26 +-
tools/browser/data-manager/xml-spec-editor.c | 6 +-
tools/browser/doc/gda-browser-sections.txt | 32 +-
tools/browser/doc/gda-browser.types | 2 +-
tools/browser/favorites-test.c | 38 +-
.../ldap-browser/ldap-browser-perspective.c | 4 +-
tools/browser/ldap-browser/ldap-classes-page.c | 4 +-
tools/browser/ldap-browser/ldap-entries-page.c | 4 +-
.../browser/ldap-browser/ldap-favorite-selector.c | 22 +-
tools/browser/login-dialog.c | 2 +-
tools/browser/mgr-favorites.c | 26 +-
tools/browser/query-exec/query-console-page.c | 16 +-
tools/browser/query-exec/query-favorite-selector.c | 30 +-
tools/browser/schema-browser/favorite-selector.c | 8 +-
tools/browser/schema-browser/objects-index.c | 2 +-
tools/browser/schema-browser/relations-diagram.c | 26 +-
.../schema-browser/schema-browser-perspective.c | 4 +-
tools/browser/schema-browser/table-columns.c | 6 +-
tools/browser/schema-browser/table-info.c | 4 +-
tools/cmdtool/Makefile.am | 22 +
tools/cmdtool/tool-command.c | 486 +++
tools/cmdtool/tool-command.h | 123 +
tools/{tools-utils.h => cmdtool/tool-decl.h} | 35 +-
tools/{tools-utils.h => cmdtool/tool-defines.h} | 31 +-
tools/{tools-utils.h => cmdtool/tool-errors.c} | 38 +-
tools/{tools-utils.h => cmdtool/tool-errors.h} | 26 +-
tools/cmdtool/tool-help.c | 517 +++
tools/{tools-utils.h => cmdtool/tool-help.h} | 31 +-
tools/cmdtool/tool-input.c | 486 +++
tools/{tools-input.h => cmdtool/tool-input.h} | 14 +-
tools/cmdtool/tool-output.c | 842 +++++
tools/{tools-input.h => cmdtool/tool-output.h} | 34 +-
tools/{tools-input.h => cmdtool/tool.h} | 28 +-
tools/command-exec.c | 749 +----
tools/command-exec.h | 88 +-
tools/config-info.c | 10 +-
tools/gda-sql.c | 3605 ++++++++------------
tools/gda-sql.h | 41 +-
tools/help/C/gda-sql-help.xml | 14 +-
tools/{tools-utils.c => tool-utils.c} | 10 +-
tools/{tools-utils.h => tool-utils.h} | 24 +-
tools/tools-favorites.c | 166 +-
tools/tools-favorites.h | 62 +-
tools/tools-input.c | 330 --
tools/web-server.c | 6 +-
60 files changed, 4425 insertions(+), 3792 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 51382b7..a926ac2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -950,6 +950,7 @@ control-center/Makefile
control-center/data/Makefile
tools/Makefile
tools/gda-sql-5.0.1:tools/gda-sql.1.in
+tools/cmdtool/Makefile
tools/help/Makefile
tools/browser/Makefile
tools/browser/data/Makefile
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 6745e25..50818df 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -6,7 +6,7 @@ if LDAP
ldap_flags=-DHAVE_LDAP
endif
-SUBDIRS = $(BROWSER_DIR) help
+SUBDIRS = cmdtool $(BROWSER_DIR) help
bin_PROGRAMS = \
gda-list-config-5.0 \
@@ -22,6 +22,7 @@ AM_CPPFLAGS = \
-I$(top_builddir)/libgda/sqlite \
-I$(top_srcdir)/libgda \
-I. \
+ -Icmdtool \
$(ldap_flags) \
$(COREDEPS_CFLAGS) \
-DROOT_DIR=\""$(top_srcdir)"\"
@@ -34,18 +35,16 @@ gda_list_config_5_0_LDADD = \
$(COREDEPS_LIBS)
gda_sql_5_0_SOURCES = \
+ tool-utils.h \
+ tool-utils.c \
config-info.h \
config-info.c \
tools-favorites.h \
tools-favorites.c \
- tools-utils.h \
- tools-utils.c \
gda-sql.c \
gda-sql.h \
gda-threader.h \
gda-threader.c \
- tools-input.h \
- tools-input.c \
command-exec.h \
command-exec.c \
$(top_srcdir)/libgda/global.h \
@@ -53,6 +52,7 @@ gda_sql_5_0_SOURCES = \
$(top_srcdir)/libgda/md5c.c
gda_sql_5_0_LDADD = \
+ cmdtool/libcmdtool.la \
$(top_builddir)/libgda/libgda-5.0.la \
$(COREDEPS_LIBS) \
$(READLINE_LIB) \
diff --git a/tools/browser/Makefile.am b/tools/browser/Makefile.am
index 8a5f9f4..2c0fd33 100644
--- a/tools/browser/Makefile.am
+++ b/tools/browser/Makefile.am
@@ -43,8 +43,8 @@ marshal.c: marshal.list $(GLIB_GENMARSHAL) marshal.h
libbrowser_la_SOURCES=\
../config-info.h \
../config-info.c \
- ../tools-utils.h \
- ../tools-utils.c \
+ ../tool-utils.h \
+ ../tool-utils.c \
gdaui-bar.c \
gdaui-bar.h \
marshal.c \
@@ -136,8 +136,8 @@ canvas_example_DEPENDENCIES = \
common/libcommon.la
canvas_example_SOURCES = \
- ../tools-utils.h \
- ../tools-utils.c \
+ ../tool-utils.h \
+ ../tool-utils.c \
canvas-example.c \
dnd.c \
dnd.h
diff --git a/tools/browser/auth-dialog.c b/tools/browser/auth-dialog.c
index 0bab90e..c1f5986 100644
--- a/tools/browser/auth-dialog.c
+++ b/tools/browser/auth-dialog.c
@@ -318,7 +318,7 @@ sub_thread_open_cnc (AuthData *ad, GError **error)
return cnc;
#else /* DUMMY defined */
sleep (5);
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR, "%s", "Dummy error!");
+ g_set_error (error, GDA_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 0ad3993..78a5aad 100644
--- a/tools/browser/browser-connection.c
+++ b/tools/browser/browser-connection.c
@@ -20,7 +20,7 @@
#include <string.h>
#include <glib/gi18n-lib.h>
-#include "../tools-utils.h"
+#include "../tool-utils.h"
#include "browser-connection.h"
#include <libgda/thread-wrapper/gda-thread-wrapper.h>
#include "support.h"
@@ -1265,7 +1265,7 @@ browser_connection_get_favorites (BrowserConnection *bcnc)
{
g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
if (!bcnc->priv->bfav && !BROWSER_IS_VIRTUAL_CONNECTION (bcnc)) {
- bcnc->priv->bfav = tools_favorites_new (gda_connection_get_meta_store (bcnc->priv->cnc));
+ bcnc->priv->bfav = gda_tools_favorites_new (gda_connection_get_meta_store (bcnc->priv->cnc));
g_signal_connect (bcnc->priv->bfav, "favorites-changed",
G_CALLBACK (fav_changed_cb), bcnc);
}
@@ -1365,7 +1365,7 @@ 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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("No detail"));
}
}
@@ -1760,13 +1760,13 @@ meta_store_addons_init (BrowserConnection *bcnc, GError **error)
GdaMetaStore *store;
if (!bcnc->priv->cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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");
@@ -1812,13 +1812,13 @@ 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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
"%s", _("Can't initialize transaction to access favorites"));
gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
return FALSE;
@@ -1899,7 +1899,7 @@ browser_connection_set_table_column_attribute (BrowserConnection *bcnc,
}
if (! gda_connection_commit_transaction (store_cnc, NULL, NULL)) {
- g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
"%s", _("Can't commit transaction to access favorites"));
goto err;
}
@@ -1954,7 +1954,7 @@ 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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
"%s", _("Can't initialize transaction to access favorites"));
return FALSE;
}
@@ -2462,7 +2462,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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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 62e678d..61a1703 100644
--- a/tools/browser/browser-virtual-connection.c
+++ b/tools/browser/browser-virtual-connection.c
@@ -22,7 +22,7 @@
#include "browser-virtual-connection.h"
#include "browser-connection-priv.h"
#include <virtual/libgda-virtual.h>
-#include "../tools-utils.h"
+#include "../tool-utils.h"
/*
* Main static functions
@@ -316,7 +316,7 @@ sub_thread_open_cnc (BrowserVirtualConnectionSpecs *specs, GError **error)
return virtual;
#else /* DUMMY defined */
sleep (5);
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
"%s", "Timeout!!!");
return NULL;
#endif
diff --git a/tools/browser/canvas/browser-canvas-fkey.c b/tools/browser/canvas/browser-canvas-fkey.c
index c53a0ee..d101834 100644
--- a/tools/browser/canvas/browser-canvas-fkey.c
+++ b/tools/browser/canvas/browser-canvas-fkey.c
@@ -28,7 +28,7 @@
#include "browser-canvas-text.h"
#include "browser-canvas-utility.h"
#include "browser-canvas-db-relations.h"
-#include "../../tools-utils.h"
+#include "../../tool-utils.h"
#include "../support.h"
#include "../browser-window.h"
#include "../common/fk-declare.h"
@@ -422,9 +422,9 @@ single_item_enter_notify_event_cb (GooCanvasItem *ci, G_GNUC_UNUSED GooCanvasIte
_("Declared foreign key") : _("Foreign key"),
cc->priv->fk->fk_name,
_("Policy on UPDATE"),
- tools_utils_fk_policy_to_string (GDA_META_TABLE_FOREIGN_KEY_ON_UPDATE_POLICY (cc->priv->fk)),
+ gda_tools_utils_fk_policy_to_string (GDA_META_TABLE_FOREIGN_KEY_ON_UPDATE_POLICY (cc->priv->fk)),
_("Policy on DELETE"),
- tools_utils_fk_policy_to_string (GDA_META_TABLE_FOREIGN_KEY_ON_DELETE_POLICY (cc->priv->fk)));
+ gda_tools_utils_fk_policy_to_string (GDA_META_TABLE_FOREIGN_KEY_ON_DELETE_POLICY (cc->priv->fk)));
gtk_widget_set_tooltip_text (GTK_WIDGET (goo_canvas_item_get_canvas (GOO_CANVAS_ITEM (ci))),
str);
g_free (str);
diff --git a/tools/browser/common/favorites-actions.c b/tools/browser/common/favorites-actions.c
index d602e47..2a3b701 100644
--- a/tools/browser/common/favorites-actions.c
+++ b/tools/browser/common/favorites-actions.c
@@ -30,24 +30,24 @@ actions_sort_func (ToolsFavoriteAction *act1, ToolsFavoriteAction *act2)
}
/**
- * tools_favorites_get_actions
+ * gda_tools_favorites_get_actions
* @bfav: a #ToolsFavorites
* @bcnc: a #BrowserConnection
* @set: a #GdaSet
*
* Get a list of #ToolsFavoriteAction which can be executed with the data in @set.
*
- * Returns: a new list of #ToolsFavoriteAction, free list with tools_favorites_free_actions()
+ * Returns: a new list of #ToolsFavoriteAction, free list with gda_tools_favorites_free_actions()
*/
GSList *
-tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaSet *set)
+gda_tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaSet *set)
{
GSList *fav_list, *list, *retlist = NULL;
- g_return_val_if_fail (TOOLS_IS_FAVORITES (bfav), NULL);
+ g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), NULL);
g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
g_return_val_if_fail (!set || GDA_IS_SET (set), NULL);
- fav_list = tools_favorites_list (bfav, 0, TOOLS_FAVORITES_ACTIONS, -1, NULL);
+ fav_list = gda_tools_favorites_list (bfav, 0, GDA_TOOLS_FAVORITES_ACTIONS, -1, NULL);
if (! fav_list)
return NULL;
@@ -60,7 +60,7 @@ tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaS
fa->contents);
continue;
}
- if (tools_favorites_get (bfav, atoi (fa->contents + 5), &qfa, NULL)) {
+ if (gda_tools_favorites_get (bfav, atoi (fa->contents + 5), &qfa, NULL)) {
GdaSet *params;
GSList *plist;
GdaBatch *batch;
@@ -74,7 +74,7 @@ tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaS
batch = gda_sql_parser_parse_string_as_batch (parser, qfa.contents, &remain, NULL);
g_object_unref (parser);
if (!batch) {
- tools_favorites_reset_attributes (&qfa);
+ gda_tools_favorites_reset_attributes (&qfa);
continue;
}
stmt_list = gda_batch_get_statements (batch);
@@ -88,13 +88,13 @@ tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaS
}
g_object_unref (batch);
if (!stmt || plist) {
- tools_favorites_reset_attributes (&qfa);
+ gda_tools_favorites_reset_attributes (&qfa);
continue;
}
if (! gda_statement_get_parameters (stmt, ¶ms, NULL) || !params) {
g_object_unref (stmt);
- tools_favorites_reset_attributes (&qfa);
+ gda_tools_favorites_reset_attributes (&qfa);
continue;
}
browser_connection_define_ui_plugins_for_stmt (bcnc, stmt, params);
@@ -129,22 +129,22 @@ tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaS
g_object_unref (stmt);
g_object_unref (params);
- tools_favorites_reset_attributes (&qfa);
+ gda_tools_favorites_reset_attributes (&qfa);
}
}
- tools_favorites_free_list (fav_list);
+ gda_tools_favorites_free_list (fav_list);
return retlist;
}
/**
- * tools_favorites_free_action
+ * gda_tools_favorites_free_action
* @action: (allow-none): a #ToolsFavoriteAction, or %NULL
*
* Frees @action
*/
void
-tools_favorites_free_action (ToolsFavoriteAction *action)
+gda_tools_favorites_free_action (ToolsFavoriteAction *action)
{
if (! action)
return;
@@ -157,19 +157,19 @@ tools_favorites_free_action (ToolsFavoriteAction *action)
}
/**
- * tools_favorites_free_actions_list
+ * gda_tools_favorites_free_actions_list
* @actions_list: (allow-none): a list of #ToolsFavoriteAction, or %NULL
*
* Free a list of #ToolsFavoriteAction (frees the list and each #ToolsFavoriteAction)
*/
void
-tools_favorites_free_actions_list (GSList *actions_list)
+gda_tools_favorites_free_actions_list (GSList *actions_list)
{
GSList *list;
if (!actions_list)
return;
for (list = actions_list; list; list = list->next)
- tools_favorites_free_action ((ToolsFavoriteAction*) list->data);
+ gda_tools_favorites_free_action ((ToolsFavoriteAction*) list->data);
g_slist_free (actions_list);
}
diff --git a/tools/browser/common/favorites-actions.h b/tools/browser/common/favorites-actions.h
index 827bd2e..282d71f 100644
--- a/tools/browser/common/favorites-actions.h
+++ b/tools/browser/common/favorites-actions.h
@@ -35,9 +35,9 @@ typedef struct {
* to another GdaHolder */
} ToolsFavoriteAction;
-GSList *tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaSet *set);
-void tools_favorites_free_action (ToolsFavoriteAction *action);
-void tools_favorites_free_actions_list (GSList *actions_list);
+GSList *gda_tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaSet *set);
+void gda_tools_favorites_free_action (ToolsFavoriteAction *action);
+void gda_tools_favorites_free_actions_list (GSList *actions_list);
G_END_DECLS
diff --git a/tools/browser/common/fk-declare.c b/tools/browser/common/fk-declare.c
index b167d5d..94b194a 100644
--- a/tools/browser/common/fk-declare.c
+++ b/tools/browser/common/fk-declare.c
@@ -21,7 +21,7 @@
#include <sql-parser/gda-sql-parser.h>
#include "fk-declare.h"
#include "../support.h"
-#include "../../tools-utils.h"
+#include "../../tool-utils.h"
/*
* Main static functions
@@ -556,7 +556,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing information to declare foreign key"));
return FALSE;
}
@@ -638,7 +638,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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 57f4f6d..672d0cf 100644
--- a/tools/browser/common/ui-formgrid.c
+++ b/tools/browser/common/ui-formgrid.c
@@ -34,7 +34,7 @@
#ifdef HAVE_LDAP
#include "../ldap-browser/ldap-browser-perspective.h"
#endif
-#include "../../tools-utils.h"
+#include "../../tool-utils.h"
static void ui_formgrid_class_init (UiFormGridClass * class);
static void ui_formgrid_init (UiFormGrid *wid);
@@ -498,7 +498,7 @@ form_grid_populate_popup_cb (GtkWidget *wid, GtkMenu *menu, UiFormGrid *formgrid
/* actions */
GSList *actions_list, *list;
- actions_list = tools_favorites_get_actions (browser_connection_get_favorites (bcnc),
+ actions_list = gda_tools_favorites_get_actions (browser_connection_get_favorites (bcnc),
bcnc, GDA_SET (iter));
if (actions_list) {
GtkWidget *mitem, *submenu;
@@ -514,7 +514,7 @@ form_grid_populate_popup_cb (GtkWidget *wid, GtkMenu *menu, UiFormGrid *formgrid
gtk_widget_show (mitem);
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mitem);
g_object_set_data_full (G_OBJECT (mitem), "action", act,
- (GDestroyNotify) tools_favorites_free_action);
+ (GDestroyNotify) gda_tools_favorites_free_action);
g_signal_connect (mitem, "activate",
G_CALLBACK (execute_action_mitem_cb), formgrid);
}
@@ -652,7 +652,7 @@ exec_end_timeout_cb (ActionExecutedData *aed)
}
else {
g_object_unref (obj);
- g_set_error (&error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (&error, GDA_TOOLS_ERROR, GDA_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 9fa6895..34b91b0 100644
--- a/tools/browser/connection-binding-properties.c
+++ b/tools/browser/connection-binding-properties.c
@@ -26,7 +26,7 @@
#include <libgda-ui/libgda-ui.h>
#include <libgda-ui/gdaui-plugin.h>
#include "common/gdaui-entry-import.h"
-#include "../tools-utils.h"
+#include "../tool-utils.h"
/*
* Main static functions
@@ -472,7 +472,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (&error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Invalid schema name"));
return error;
}
diff --git a/tools/browser/data-manager/data-console.c b/tools/browser/data-manager/data-console.c
index 7f6a0d4..2b56292 100644
--- a/tools/browser/data-manager/data-console.c
+++ b/tools/browser/data-manager/data-console.c
@@ -499,7 +499,7 @@ data_console_set_fav_id (DataConsole *dconsole, gint fav_id, GError **error)
ToolsFavoritesAttributes fav;
if ((fav_id >=0) &&
- tools_favorites_get (browser_connection_get_favorites (dconsole->priv->bcnc),
+ gda_tools_favorites_get (browser_connection_get_favorites (dconsole->priv->bcnc),
fav_id, &fav, error)) {
gchar *str, *tmp;
tmp = g_markup_printf_escaped (_("'%s' data manager"), fav.name);
@@ -510,7 +510,7 @@ data_console_set_fav_id (DataConsole *dconsole, gint fav_id, GError **error)
dconsole->priv->fav_id = fav.id;
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
}
else {
gchar *str;
@@ -543,7 +543,7 @@ real_save_clicked_cb (GtkWidget *button, DataConsole *dconsole)
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = dconsole->priv->fav_id;
- fav.type = TOOLS_FAVORITES_DATA_MANAGERS;
+ fav.type = GDA_TOOLS_FAVORITES_DATA_MANAGERS;
fav.name = gtk_editable_get_chars (GTK_EDITABLE (dconsole->priv->name_entry), 0, -1);
if (!*fav.name) {
g_free (fav.name);
@@ -554,7 +554,7 @@ real_save_clicked_cb (GtkWidget *button, DataConsole *dconsole)
gtk_widget_hide (dconsole->priv->popup_container);
bfav = browser_connection_get_favorites (dconsole->priv->bcnc);
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_DATA_MANAGERS, G_MAXINT, &lerror)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_DATA_MANAGERS, G_MAXINT, &lerror)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel (button),
"<b>%s:</b>\n%s",
_("Could not save data manager"),
@@ -593,10 +593,10 @@ save_clicked_cb (GtkWidget *button, DataConsole *dconsole)
dconsole->priv->name_entry = wid;
if (dconsole->priv->fav_id > 0) {
ToolsFavoritesAttributes fav;
- if (tools_favorites_get (browser_connection_get_favorites (dconsole->priv->bcnc),
+ if (gda_tools_favorites_get (browser_connection_get_favorites (dconsole->priv->bcnc),
dconsole->priv->fav_id, &fav, NULL)) {
gtk_entry_set_text (GTK_ENTRY (wid), fav.name);
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
}
}
diff --git a/tools/browser/data-manager/data-favorite-selector.c b/tools/browser/data-manager/data-favorite-selector.c
index 35e4139..d472fd5 100644
--- a/tools/browser/data-manager/data-favorite-selector.c
+++ b/tools/browser/data-manager/data-favorite-selector.c
@@ -195,7 +195,7 @@ key_press_event_cb (GtkTreeView *treeview, GdkEventKey *event, DataFavoriteSelec
gtk_tree_model_get (model, &iter,
COLUMN_ID, &(fav.id), -1);
bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (!tools_favorites_delete (bfav, 0, &fav, NULL)) {
+ if (!gda_tools_favorites_delete (bfav, 0, &fav, NULL)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
_("Could not remove favorite: %s"),
lerror && lerror->message ? lerror->message : _("No detail"));
@@ -241,7 +241,7 @@ prop_save_timeout (DataFavoriteSelector *tsel)
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = tsel->priv->properties_id;
- fav.type = TOOLS_FAVORITES_DATA_MANAGERS;
+ fav.type = GDA_TOOLS_FAVORITES_DATA_MANAGERS;
fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name));
fav.descr = NULL;
@@ -253,7 +253,7 @@ prop_save_timeout (DataFavoriteSelector *tsel)
fav.contents = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_DATA_MANAGERS, tsel->priv->properties_position, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_DATA_MANAGERS, tsel->priv->properties_position, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
@@ -466,7 +466,7 @@ data_favorite_selector_new (BrowserConnection *bcnc)
/* create tree managers */
tsel->priv->tree = gda_tree_new ();
- manager = mgr_favorites_new (bcnc, TOOLS_FAVORITES_DATA_MANAGERS, ORDER_KEY_DATA_MANAGERS);
+ manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_DATA_MANAGERS, ORDER_KEY_DATA_MANAGERS);
gda_tree_add_manager (tsel->priv->tree, manager);
g_object_unref (manager);
@@ -599,12 +599,12 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
gint id;
bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- id = tools_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data),
+ id = gda_tools_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data),
&fav, NULL);
if (id < 0) {
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = -1;
- fav.type = TOOLS_FAVORITES_DATA_MANAGERS;
+ fav.type = GDA_TOOLS_FAVORITES_DATA_MANAGERS;
fav.name = _("Unnamed data manager");
fav.descr = NULL;
fav.contents = (gchar*) gtk_selection_data_get_data (selection_data);
@@ -613,7 +613,7 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
pos = atoi (path);
/*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_DATA_MANAGERS, pos, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_DATA_MANAGERS, pos, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
@@ -623,7 +623,7 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
}
if (id >= 0)
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
return retval;
}
diff --git a/tools/browser/data-manager/data-manager-perspective.c b/tools/browser/data-manager/data-manager-perspective.c
index e0aad6d..b072ac6 100644
--- a/tools/browser/data-manager/data-manager-perspective.c
+++ b/tools/browser/data-manager/data-manager-perspective.c
@@ -239,7 +239,7 @@ fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, ToolsFav
gint current_page, npages, i;
DataConsole *page_to_reuse = NULL;
- if (fav_type != TOOLS_FAVORITES_DATA_MANAGERS)
+ if (fav_type != GDA_TOOLS_FAVORITES_DATA_MANAGERS)
return;
/* change current page if possible */
diff --git a/tools/browser/data-manager/data-source.c b/tools/browser/data-manager/data-source.c
index 865b547..3bd9fab 100644
--- a/tools/browser/data-manager/data-source.c
+++ b/tools/browser/data-manager/data-source.c
@@ -29,7 +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 "../../tool-utils.h"
#include "data-source.h"
#define DEFAULT_DATA_SOURCE_NAME "DataSource"
@@ -400,7 +400,7 @@ data_source_new_from_xml_node (BrowserConnection *bcnc, xmlNodePtr node, GError
init_from_query (source, node);
}
else {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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);
@@ -434,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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
"%s", _("Not ready"));
return NULL;
}
split = gda_sql_identifier_split (table_name);
if (! split) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Malformed table name \"%s\""), table_name);
return NULL;
}
@@ -458,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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("The \"%s\" object is not a table"), table_name);
return NULL;
}
@@ -481,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
/* Translators: Do not translate "name" */
"%s", _("Missing attribute \"name\" for table"));
return FALSE;
@@ -622,12 +622,12 @@ data_source_add_dependency (DataSource *source, const gchar *table,
}
}
if (!fk) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("The fields involved in the foreign key to \"%s\" are not known"),
table);
return FALSE;
@@ -808,7 +808,7 @@ exec_end_timeout_cb (DataSource *source)
}
else {
g_object_unref (obj);
- g_set_error (&source->priv->exec_error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (&source->priv->exec_error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Statement to execute is not a selection statement"));
}
@@ -948,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("No SELECT statement to execute"));
}
@@ -1218,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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Could not build SELECT statement"));
return FALSE;
}
@@ -1285,7 +1285,7 @@ data_source_set_query (DataSource *source, const gchar *sql, GError **warning)
}
if (remain)
- g_set_error (warning, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (warning, GDA_TOOLS_ERROR, GDA_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 cb617fb..b09cb1a 100644
--- a/tools/browser/data-manager/xml-spec-editor.c
+++ b/tools/browser/data-manager/xml-spec-editor.c
@@ -24,7 +24,7 @@
#include "data-source.h"
#include <libgda/libgda.h>
#include "../support.h"
-#include "../../tools-utils.h"
+#include "../../tool-utils.h"
#ifdef HAVE_GTKSOURCEVIEW
#ifdef GTK_DISABLE_SINGLE_INCLUDES
@@ -169,7 +169,7 @@ signal_editor_changed (XmlSpecEditor *sped)
if (!doc) {
TO_IMPLEMENT;
- g_set_error (&lerror, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (&lerror, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Error parsing XML specifications"));
goto out;
}
@@ -183,7 +183,7 @@ signal_editor_changed (XmlSpecEditor *sped)
}
if (strcmp ((gchar*) node->name, "data")) {
- g_set_error (&lerror, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (&lerror, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Expecting <%s> root node"), "data");
xmlFreeDoc (doc);
goto out;
diff --git a/tools/browser/doc/gda-browser-sections.txt b/tools/browser/doc/gda-browser-sections.txt
index e76675c..f7a5129 100644
--- a/tools/browser/doc/gda-browser-sections.txt
+++ b/tools/browser/doc/gda-browser-sections.txt
@@ -124,30 +124,30 @@ BROWSER_CONNECTION_CLASS
<FILE>browser-favorites</FILE>
ToolsFavoritesPrivate
ToolsFavoritesType
-TOOLS_FAVORITES_NB_TYPES
+GDA_TOOLS_FAVORITES_NB_TYPES
ToolsFavoritesAttributes
<TITLE>ToolsFavorites</TITLE>
ToolsFavorites
-tools_favorites_new
-tools_favorites_type_to_string
-tools_favorites_add
-tools_favorites_list
-tools_favorites_delete
-tools_favorites_free_list
-tools_favorites_reset_attributes
-tools_favorites_find
-tools_favorites_get
+gda_tools_favorites_new
+gda_tools_favorites_type_to_string
+gda_tools_favorites_add
+gda_tools_favorites_list
+gda_tools_favorites_delete
+gda_tools_favorites_free_list
+gda_tools_favorites_reset_attributes
+gda_tools_favorites_find
+gda_tools_favorites_get
<SUBSECTION>
ToolsFavoriteAction
-tools_favorites_get_actions
-tools_favorites_free_action
-tools_favorites_free_actions_list
+gda_tools_favorites_get_actions
+gda_tools_favorites_free_action
+gda_tools_favorites_free_actions_list
<SUBSECTION Standard>
-TOOLS_FAVORITES
+GDA_TOOLS_FAVORITES
BROWSER_IS_FAVORITES
BROWSER_TYPE_FAVORITES
-tools_favorites_get_type
-TOOLS_FAVORITES_CLASS
+gda_tools_favorites_get_type
+GDA_TOOLS_FAVORITES_CLASS
</SECTION>
<SECTION>
diff --git a/tools/browser/doc/gda-browser.types b/tools/browser/doc/gda-browser.types
index 01fcdea..dab022d 100644
--- a/tools/browser/doc/gda-browser.types
+++ b/tools/browser/doc/gda-browser.types
@@ -12,7 +12,7 @@
#include <mgr-favorites.h>
browser_core_get_type
browser_connection_get_type
-tools_favorites_get_type
+gda_tools_favorites_get_type
browser_window_get_type
browser_perspective_get_type
browser_page_get_type
diff --git a/tools/browser/favorites-test.c b/tools/browser/favorites-test.c
index 82d2c0e..6aa4e88 100644
--- a/tools/browser/favorites-test.c
+++ b/tools/browser/favorites-test.c
@@ -79,7 +79,7 @@ main (int argc, char *argv[])
error && error->message ? error->message : "No detail");
exit (1);
}
- bfav = tools_favorites_new (gda_connection_get_meta_store (cnc));
+ bfav = gda_tools_favorites_new (gda_connection_get_meta_store (cnc));
test1 (cnc, bfav);
test2 (cnc, bfav);
test3 (cnc, bfav);
@@ -96,12 +96,12 @@ test1 (GdaConnection *cnc, ToolsFavorites *bfav)
gint favid, i;
GError *error = NULL;
ToolsFavoritesAttributes fav_array[]= {
- {-1, TOOLS_FAVORITES_TABLES, "table1", "fav1-descr", "fav1 contents"},
- {-1, TOOLS_FAVORITES_DIAGRAMS, "diagram1", "fav2-descr", "fav2 contents"}
+ {-1, GDA_TOOLS_FAVORITES_TABLES, "table1", "fav1-descr", "fav1 contents"},
+ {-1, GDA_TOOLS_FAVORITES_DIAGRAMS, "diagram1", "fav2-descr", "fav2 contents"}
};
for (i = 0; i < G_N_ELEMENTS (fav_array); i++) {
ToolsFavoritesAttributes *f = (ToolsFavoritesAttributes*) &(fav_array[i]);
- favid = tools_favorites_add (bfav, 0, f, -1, 0, &error);
+ favid = gda_tools_favorites_add (bfav, 0, f, -1, 0, &error);
if (!favid < 0) {
g_print ("Could not create favorite: %s\n",
error && error->message ? error->message : "No detail");
@@ -111,7 +111,7 @@ test1 (GdaConnection *cnc, ToolsFavorites *bfav)
//dump_favorites_in_db (cnc);
GSList *favlist, *list;
- favlist = tools_favorites_list (bfav, 0, TOOLS_FAVORITES_TABLES, -1, &error);
+ favlist = gda_tools_favorites_list (bfav, 0, GDA_TOOLS_FAVORITES_TABLES, -1, &error);
if (!favlist && error) {
g_print ("Could not list favorites: %s\n",
error && error->message ? error->message : "No detail");
@@ -140,7 +140,7 @@ test1 (GdaConnection *cnc, ToolsFavorites *bfav)
g_print ("Wrong number of favorites reported\n");
exit (1);
}
- tools_favorites_free_list (favlist);
+ gda_tools_favorites_free_list (favlist);
}
static void
@@ -149,17 +149,17 @@ test2 (GdaConnection *cnc, ToolsFavorites *bfav)
gint favid, i;
GError *error = NULL;
ToolsFavoritesAttributes fav_array[]= {
- {-1, TOOLS_FAVORITES_TABLES, "table2", "fav1-descr", "fav1 contents SEPARATE"},
- {-1, TOOLS_FAVORITES_DIAGRAMS, "diagram2", "fav2-descr", "fav2 contents SEPARATE"},
- {-1, TOOLS_FAVORITES_TABLES, "table2", "Another description for table2", "fav1 contents SEPARATE"},
+ {-1, GDA_TOOLS_FAVORITES_TABLES, "table2", "fav1-descr", "fav1 contents SEPARATE"},
+ {-1, GDA_TOOLS_FAVORITES_DIAGRAMS, "diagram2", "fav2-descr", "fav2 contents SEPARATE"},
+ {-1, GDA_TOOLS_FAVORITES_TABLES, "table2", "Another description for table2", "fav1 contents SEPARATE"},
};
ToolsFavoritesAttributes res_fav_array[]= {
- {-1, TOOLS_FAVORITES_TABLES, "table2", "Another description for table2", "fav1 contents SEPARATE"},
- {-1, TOOLS_FAVORITES_DIAGRAMS, "diagram2", "fav2-descr", "fav2 contents SEPARATE"},
+ {-1, GDA_TOOLS_FAVORITES_TABLES, "table2", "Another description for table2", "fav1 contents SEPARATE"},
+ {-1, GDA_TOOLS_FAVORITES_DIAGRAMS, "diagram2", "fav2-descr", "fav2 contents SEPARATE"},
};
for (i = 0; i < G_N_ELEMENTS (fav_array); i++) {
ToolsFavoritesAttributes *f = (ToolsFavoritesAttributes*) &(fav_array[i]);
- favid = tools_favorites_add (bfav, 0, f, 1, 0, &error);
+ favid = gda_tools_favorites_add (bfav, 0, f, 1, 0, &error);
if (!favid < 0) {
g_print ("Could not create favorite: %s\n",
error && error->message ? error->message : "No detail");
@@ -169,7 +169,7 @@ test2 (GdaConnection *cnc, ToolsFavorites *bfav)
dump_favorites_in_db (cnc);
GSList *favlist, *list;
- favlist = tools_favorites_list (bfav, 0, TOOLS_FAVORITES_TABLES, 1, &error);
+ favlist = gda_tools_favorites_list (bfav, 0, GDA_TOOLS_FAVORITES_TABLES, 1, &error);
if (!favlist && error) {
g_print ("Could not list favorites: %s\n",
error && error->message ? error->message : "No detail");
@@ -198,7 +198,7 @@ test2 (GdaConnection *cnc, ToolsFavorites *bfav)
g_print ("Wrong number of favorites reported\n");
exit (1);
}
- tools_favorites_free_list (favlist);
+ gda_tools_favorites_free_list (favlist);
}
static void
@@ -207,14 +207,14 @@ test3 (GdaConnection *cnc, ToolsFavorites *bfav)
gint favid, i;
GError *error = NULL;
ToolsFavoritesAttributes fav_array[]= {
- {-1, TOOLS_FAVORITES_DIAGRAMS, "diagram2", "fav2-descr", "fav2 contents SEPARATE"},
+ {-1, GDA_TOOLS_FAVORITES_DIAGRAMS, "diagram2", "fav2-descr", "fav2 contents SEPARATE"},
};
ToolsFavoritesAttributes res_fav_array[]= {
- {-1, TOOLS_FAVORITES_TABLES, "table2", "Another description for table2", "fav1 contents SEPARATE"},
+ {-1, GDA_TOOLS_FAVORITES_TABLES, "table2", "Another description for table2", "fav1 contents SEPARATE"},
};
for (i = 0; i < G_N_ELEMENTS (fav_array); i++) {
ToolsFavoritesAttributes *f = (ToolsFavoritesAttributes*) &(fav_array[i]);
- favid = tools_favorites_delete (bfav, 0, f, &error);
+ favid = gda_tools_favorites_delete (bfav, 0, f, &error);
if (!favid < 0) {
g_print ("Could not delete favorite: %s\n",
error && error->message ? error->message : "No detail");
@@ -224,7 +224,7 @@ test3 (GdaConnection *cnc, ToolsFavorites *bfav)
dump_favorites_in_db (cnc);
GSList *favlist, *list;
- favlist = tools_favorites_list (bfav, 0, TOOLS_FAVORITES_TABLES, 1, &error);
+ favlist = gda_tools_favorites_list (bfav, 0, GDA_TOOLS_FAVORITES_TABLES, 1, &error);
if (!favlist && error) {
g_print ("Could not list favorites: %s\n",
error && error->message ? error->message : "No detail");
@@ -253,5 +253,5 @@ test3 (GdaConnection *cnc, ToolsFavorites *bfav)
g_print ("Wrong number of favorites reported\n");
exit (1);
}
- tools_favorites_free_list (favlist);
+ gda_tools_favorites_free_list (favlist);
}
diff --git a/tools/browser/ldap-browser/ldap-browser-perspective.c b/tools/browser/ldap-browser/ldap-browser-perspective.c
index 78029c0..e360cf8 100644
--- a/tools/browser/ldap-browser/ldap-browser-perspective.c
+++ b/tools/browser/ldap-browser/ldap-browser-perspective.c
@@ -188,10 +188,10 @@ fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED gint fa
ToolsFavoritesType fav_type,
const gchar *selection, LdapBrowserPerspective *bpers)
{
- if (fav_type == TOOLS_FAVORITES_LDAP_DN) {
+ if (fav_type == GDA_TOOLS_FAVORITES_LDAP_DN) {
ldap_browser_perspective_display_ldap_entry (bpers, selection);
}
- if (fav_type == TOOLS_FAVORITES_LDAP_CLASS) {
+ if (fav_type == GDA_TOOLS_FAVORITES_LDAP_CLASS) {
ldap_browser_perspective_display_ldap_class (bpers, selection);
}
#ifdef GDA_DEBUG_NO
diff --git a/tools/browser/ldap-browser/ldap-classes-page.c b/tools/browser/ldap-browser/ldap-classes-page.c
index baed957..1c7c9f3 100644
--- a/tools/browser/ldap-browser/ldap-classes-page.c
+++ b/tools/browser/ldap-browser/ldap-classes-page.c
@@ -419,13 +419,13 @@ action_add_to_fav_cb (G_GNUC_UNUSED GtkAction *action, LdapClassesPage *ebrowser
classes_view_get_current_class (CLASSES_VIEW (ebrowser->priv->classes_view));
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = -1;
- fav.type = TOOLS_FAVORITES_LDAP_CLASS;
+ fav.type = GDA_TOOLS_FAVORITES_LDAP_CLASS;
fav.name = ldap_classes_page_to_selection (ebrowser);
fav.descr = NULL;
fav.contents = ldap_classes_page_to_selection (ebrowser);
bfav = browser_connection_get_favorites (ebrowser->priv->bcnc);
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, G_MAXINT, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, G_MAXINT, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) ebrowser),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
diff --git a/tools/browser/ldap-browser/ldap-entries-page.c b/tools/browser/ldap-browser/ldap-entries-page.c
index 592b9f4..cc543d4 100644
--- a/tools/browser/ldap-browser/ldap-entries-page.c
+++ b/tools/browser/ldap-browser/ldap-entries-page.c
@@ -425,13 +425,13 @@ action_add_to_fav_cb (G_GNUC_UNUSED GtkAction *action, LdapEntriesPage *ebrowser
hierarchy_view_get_current_dn (HIERARCHY_VIEW (ebrowser->priv->entries_view), &cn);
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = -1;
- fav.type = TOOLS_FAVORITES_LDAP_DN;
+ fav.type = GDA_TOOLS_FAVORITES_LDAP_DN;
fav.name = ldap_entries_page_to_selection (ebrowser);
fav.descr = (gchar*) cn;
fav.contents = ldap_entries_page_to_selection (ebrowser);
bfav = browser_connection_get_favorites (ebrowser->priv->bcnc);
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, G_MAXINT, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, G_MAXINT, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) ebrowser),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
diff --git a/tools/browser/ldap-browser/ldap-favorite-selector.c b/tools/browser/ldap-browser/ldap-favorite-selector.c
index 02f84fd..7075d50 100644
--- a/tools/browser/ldap-browser/ldap-favorite-selector.c
+++ b/tools/browser/ldap-browser/ldap-favorite-selector.c
@@ -184,7 +184,7 @@ favorite_delete_selected (LdapFavoriteSelector *fsel)
gtk_tree_model_get (model, &iter,
COLUMN_ID, &(fav.id), -1);
bfav = browser_connection_get_favorites (fsel->priv->bcnc);
- if (!tools_favorites_delete (bfav, 0, &fav, NULL)) {
+ if (!gda_tools_favorites_delete (bfav, 0, &fav, NULL)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)fsel),
_("Could not remove favorite: %s"),
lerror && lerror->message ? lerror->message : _("No detail"));
@@ -240,12 +240,12 @@ prop_save_timeout (LdapFavoriteSelector *fsel)
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = fsel->priv->properties_id;
- fav.type = TOOLS_FAVORITES_LDAP_DN;
+ fav.type = GDA_TOOLS_FAVORITES_LDAP_DN;
fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (fsel->priv->properties_name));
fav.descr = (gchar*) gtk_entry_get_text (GTK_ENTRY (fsel->priv->properties_descr));
fav.contents = (gchar*) gtk_entry_get_text (GTK_ENTRY (fsel->priv->properties_name));
- allok = tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP,
+ allok = gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP,
fsel->priv->properties_position, &error);
if (! allok) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) fsel),
@@ -446,22 +446,22 @@ ldap_favorite_selector_new (BrowserConnection *bcnc)
fsel->priv->bcnc = g_object_ref (bcnc);
signame = g_strdup_printf ("favorites-changed::%s",
- tools_favorites_type_to_string (TOOLS_FAVORITES_LDAP_DN));
+ gda_tools_favorites_type_to_string (GDA_TOOLS_FAVORITES_LDAP_DN));
g_signal_connect (browser_connection_get_favorites (fsel->priv->bcnc), signame,
G_CALLBACK (favorites_changed_cb), fsel);
g_free (signame);
signame = g_strdup_printf ("favorites-changed::%s",
- tools_favorites_type_to_string (TOOLS_FAVORITES_LDAP_CLASS));
+ gda_tools_favorites_type_to_string (GDA_TOOLS_FAVORITES_LDAP_CLASS));
g_signal_connect (browser_connection_get_favorites (fsel->priv->bcnc), signame,
G_CALLBACK (favorites_changed_cb), fsel);
g_free (signame);
/* create tree managers */
fsel->priv->tree = gda_tree_new ();
- manager = mgr_favorites_new (bcnc, TOOLS_FAVORITES_LDAP_DN, ORDER_KEY_LDAP);
+ manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_LDAP_DN, ORDER_KEY_LDAP);
gda_tree_add_manager (fsel->priv->tree, manager);
g_object_unref (manager);
- manager = mgr_favorites_new (bcnc, TOOLS_FAVORITES_LDAP_CLASS, ORDER_KEY_LDAP);
+ manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_LDAP_CLASS, ORDER_KEY_LDAP);
gda_tree_add_manager (fsel->priv->tree, manager);
g_object_unref (manager);
@@ -580,12 +580,12 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
gint id;
bfav = browser_connection_get_favorites (fsel->priv->bcnc);
- id = tools_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_ldap),
+ id = gda_tools_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_ldap),
&fav, NULL);
if (id < 0) {
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = -1;
- fav.type = TOOLS_FAVORITES_LDAP_DN;
+ fav.type = GDA_TOOLS_FAVORITES_LDAP_DN;
fav.name = (gchar*) gtk_selection_data_get_data (selection_ldap);
fav.descr = NULL;
fav.contents = (gchar*) gtk_selection_data_get_data (selection_ldap);
@@ -594,7 +594,7 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
pos = atoi (path);
/*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, pos, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, pos, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) fsel),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
@@ -604,7 +604,7 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
}
if (id >= 0)
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
return retval;
}
diff --git a/tools/browser/login-dialog.c b/tools/browser/login-dialog.c
index d1eaa53..70b55cf 100644
--- a/tools/browser/login-dialog.c
+++ b/tools/browser/login-dialog.c
@@ -290,7 +290,7 @@ sub_thread_open_cnc (GdaDsnInfo *info, GError **error)
return cnc;
#else /* DUMMY defined */
sleep (5);
- g_set_error (error, TOOLS_INTERNAL_COMMAND_ERROR, "%s", "Dummy error!");
+ g_set_error (error, GDA_TOOLS_INTERNAL_COMMAND_ERROR, "%s", "Dummy error!");
return NULL;
#endif
}
diff --git a/tools/browser/mgr-favorites.c b/tools/browser/mgr-favorites.c
index 3ce9200..0f16267 100644
--- a/tools/browser/mgr-favorites.c
+++ b/tools/browser/mgr-favorites.c
@@ -211,7 +211,7 @@ mgr_favorites_get_property (GObject *object,
* mgr_favorites_new
* @bcnc: a #BrowserConnection object
* @type: the type of favorites to handle
- * @order_key: ordering key, see tools_favorites_add()
+ * @order_key: ordering key, see gda_tools_favorites_add()
*
* Creates a new #GdaTreeManager object which will add one tree node for each favorite of the @type type
*
@@ -372,7 +372,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
ehash = hash_for_existing_nodes (children_nodes);
bcnc = mgr->priv->bcnc;
- fav_list = tools_favorites_list (browser_connection_get_favorites (bcnc),
+ fav_list = gda_tools_favorites_list (browser_connection_get_favorites (bcnc),
0, mgr->priv->fav_type,
mgr->priv->order_key, &lerror);
if (fav_list) {
@@ -392,7 +392,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
g_object_ref (G_OBJECT (snode));
}
- if (fav->type == TOOLS_FAVORITES_TABLES) {
+ if (fav->type == GDA_TOOLS_FAVORITES_TABLES) {
if (!snode) {
GdaQuarkList *ql;
const gchar *fname = NULL;
@@ -439,7 +439,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gda_quark_list_free (ql);
}
}
- else if (fav->type == TOOLS_FAVORITES_DIAGRAMS) {
+ else if (fav->type == GDA_TOOLS_FAVORITES_DIAGRAMS) {
if (!snode) {
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -475,7 +475,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gda_tree_node_set_node_attribute (snode, "markup", av, NULL);
gda_value_free (av);
}
- else if (fav->type == TOOLS_FAVORITES_QUERIES) {
+ else if (fav->type == GDA_TOOLS_FAVORITES_QUERIES) {
if (!snode) {
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -496,8 +496,8 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gboolean is_action = FALSE;
GSList *favlist;
GdkPixbuf *pixbuf;
- favlist = tools_favorites_list (browser_connection_get_favorites (bcnc),
- 0, TOOLS_FAVORITES_ACTIONS,
+ favlist = gda_tools_favorites_list (browser_connection_get_favorites (bcnc),
+ 0, GDA_TOOLS_FAVORITES_ACTIONS,
-1, NULL);
if (favlist) {
gchar *tmp;
@@ -512,7 +512,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
}
}
g_free (tmp);
- tools_favorites_free_list (favlist);
+ gda_tools_favorites_free_list (favlist);
}
if (is_action)
pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_ACTION);
@@ -541,7 +541,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
av, NULL);
gda_value_free (av);
}
- else if (fav->type == TOOLS_FAVORITES_DATA_MANAGERS) {
+ else if (fav->type == GDA_TOOLS_FAVORITES_DATA_MANAGERS) {
if (!snode) {
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -585,7 +585,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gda_value_free (av);
}
#ifdef HAVE_LDAP
- else if (fav->type == TOOLS_FAVORITES_LDAP_DN) {
+ else if (fav->type == GDA_TOOLS_FAVORITES_LDAP_DN) {
if (!snode) {
/* favorite ID */
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -675,7 +675,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
av, NULL);
gda_value_free (av);
}
- else if (fav->type == TOOLS_FAVORITES_LDAP_CLASS) {
+ else if (fav->type == GDA_TOOLS_FAVORITES_LDAP_CLASS) {
if (!snode) {
/* favorite ID */
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -743,7 +743,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
if (snode)
nodes_list = g_slist_prepend (nodes_list, snode);
}
- tools_favorites_free_list (fav_list);
+ gda_tools_favorites_free_list (fav_list);
}
else if (lerror) {
if (out_error)
@@ -765,7 +765,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gchar *str;
GValue *value;
- if (mgr->priv->fav_type & TOOLS_FAVORITES_TABLES) {
+ if (mgr->priv->fav_type & GDA_TOOLS_FAVORITES_TABLES) {
str = g_strdup_printf ("<i>%s</i>", _("No favorite:\ndrag item to\ndefine one"));
snode = gda_tree_manager_create_node (manager, node, str);
g_value_take_string ((value = gda_value_new (G_TYPE_STRING)), str);
diff --git a/tools/browser/query-exec/query-console-page.c b/tools/browser/query-exec/query-console-page.c
index d9f6554..d24a66d 100644
--- a/tools/browser/query-exec/query-console-page.c
+++ b/tools/browser/query-exec/query-console-page.c
@@ -715,7 +715,7 @@ sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tcon
bfav = browser_connection_get_favorites (tconsole->priv->bcnc);
if (tconsole->priv->fav_id >= 0) {
ToolsFavoritesAttributes fav;
- if (tools_favorites_get (bfav, tconsole->priv->fav_id, &fav, NULL)) {
+ if (gda_tools_favorites_get (bfav, tconsole->priv->fav_id, &fav, NULL)) {
gchar *str;
str = g_strdup_printf (_("Modify favorite '%s'"), fav.name);
mitem = gtk_menu_item_new_with_label (str);
@@ -728,12 +728,12 @@ sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tcon
GINT_TO_POINTER (tconsole->priv->fav_id));
gtk_widget_show (mitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
}
}
GSList *allfav;
- allfav = tools_favorites_list (bfav, 0, TOOLS_FAVORITES_QUERIES, ORDER_KEY_QUERIES, NULL);
+ allfav = gda_tools_favorites_list (bfav, 0, GDA_TOOLS_FAVORITES_QUERIES, ORDER_KEY_QUERIES, NULL);
if (allfav) {
GtkWidget *submenu;
GSList *list;
@@ -762,7 +762,7 @@ sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tcon
gtk_widget_show (mitem);
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mitem);
}
- tools_favorites_free_list (allfav);
+ gda_tools_favorites_free_list (allfav);
}
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
@@ -805,14 +805,14 @@ sql_favorite_new_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *t
memset (&fav, 0, sizeof (fav));
fav.id = -1;
- fav.type = TOOLS_FAVORITES_QUERIES;
+ fav.type = GDA_TOOLS_FAVORITES_QUERIES;
fav.contents = query_editor_get_all_text (tconsole->priv->editor);
cvalue = gda_set_get_holder_value (set, _("Favorite's name"));
fav.name = (gchar*) g_value_get_string (cvalue);
bfav = browser_connection_get_favorites (tconsole->priv->bcnc);
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
@@ -836,13 +836,13 @@ sql_favorite_modify_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage
memset (&fav, 0, sizeof (fav));
fav.id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (mitem), "favid"));
- fav.type = TOOLS_FAVORITES_QUERIES;
+ fav.type = GDA_TOOLS_FAVORITES_QUERIES;
fav.contents = query_editor_get_all_text (tconsole->priv->editor);
fav.name = g_object_get_data (G_OBJECT (mitem), "favname");
bfav = browser_connection_get_favorites (tconsole->priv->bcnc);
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
diff --git a/tools/browser/query-exec/query-favorite-selector.c b/tools/browser/query-exec/query-favorite-selector.c
index bf88924..bca26ed 100644
--- a/tools/browser/query-exec/query-favorite-selector.c
+++ b/tools/browser/query-exec/query-favorite-selector.c
@@ -185,7 +185,7 @@ favorite_delete_selected (QueryFavoriteSelector *tsel)
gtk_tree_model_get (model, &iter,
COLUMN_ID, &(fav.id), -1);
bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (!tools_favorites_delete (bfav, 0, &fav, NULL)) {
+ if (!gda_tools_favorites_delete (bfav, 0, &fav, NULL)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
_("Could not remove favorite: %s"),
lerror && lerror->message ? lerror->message : _("No detail"));
@@ -197,9 +197,9 @@ favorite_delete_selected (QueryFavoriteSelector *tsel)
gint id;
gchar *tmp;
tmp = g_strdup_printf ("QUERY%d", fav.id);
- id = tools_favorites_find (bfav, 0, tmp, &fav, NULL);
+ id = gda_tools_favorites_find (bfav, 0, tmp, &fav, NULL);
if (id >= 0) {
- tools_favorites_delete (bfav, 0, &fav, NULL);
+ gda_tools_favorites_delete (bfav, 0, &fav, NULL);
/*g_print ("ACTION_DELETED %d: %s\n", fav.id, tmp);*/
}
g_free (tmp);
@@ -253,12 +253,12 @@ prop_save_timeout (QueryFavoriteSelector *tsel)
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = tsel->priv->properties_id;
- fav.type = TOOLS_FAVORITES_QUERIES;
+ fav.type = GDA_TOOLS_FAVORITES_QUERIES;
fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name));
fav.descr = NULL;
fav.contents = query_editor_get_all_text (QUERY_EDITOR (tsel->priv->properties_text));
- allok = tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES,
+ allok = gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES,
tsel->priv->properties_position, &error);
if (! allok) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
@@ -275,11 +275,11 @@ prop_save_timeout (QueryFavoriteSelector *tsel)
is_action = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tsel->priv->properties_action));
if (is_action) {
fav.id = -1;
- fav.type = TOOLS_FAVORITES_ACTIONS;
+ fav.type = GDA_TOOLS_FAVORITES_ACTIONS;
fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name));
fav.descr = NULL;
fav.contents = g_strdup_printf ("QUERY%d", qid);
- allok = tools_favorites_add (bfav, 0, &fav, -1,
+ allok = gda_tools_favorites_add (bfav, 0, &fav, -1,
tsel->priv->properties_position, &error);
if (! allok) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
@@ -300,9 +300,9 @@ prop_save_timeout (QueryFavoriteSelector *tsel)
gint id;
gchar *tmp;
tmp = g_strdup_printf ("QUERY%d", tsel->priv->properties_id);
- id = tools_favorites_find (bfav, 0, tmp, &fav, NULL);
+ id = gda_tools_favorites_find (bfav, 0, tmp, &fav, NULL);
if (id >= 0) {
- tools_favorites_delete (bfav, 0, &fav, NULL);
+ gda_tools_favorites_delete (bfav, 0, &fav, NULL);
/*g_print ("ACTION_DELETED %d: %s\n", fav.id, tmp);*/
}
g_free (tmp);
@@ -438,7 +438,7 @@ properties_activated_cb (GtkMenuItem *mitem, QueryFavoriteSelector *tsel)
ToolsFavoritesAttributes fav;
bfav = browser_connection_get_favorites (tsel->priv->bcnc);
tmp = g_strdup_printf ("QUERY%d", tsel->priv->properties_id);
- id = tools_favorites_find (bfav, 0, tmp, &fav, NULL);
+ id = gda_tools_favorites_find (bfav, 0, tmp, &fav, NULL);
if (id >= 0) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tsel->priv->properties_action),
TRUE);
@@ -547,7 +547,7 @@ query_favorite_selector_new (BrowserConnection *bcnc)
/* create tree managers */
tsel->priv->tree = gda_tree_new ();
- manager = mgr_favorites_new (bcnc, TOOLS_FAVORITES_QUERIES, ORDER_KEY_QUERIES);
+ manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_QUERIES, ORDER_KEY_QUERIES);
gda_tree_add_manager (tsel->priv->tree, manager);
g_object_unref (manager);
@@ -687,12 +687,12 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
gint id;
bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- id = tools_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data),
+ id = gda_tools_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data),
&fav, NULL);
if (id < 0) {
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = -1;
- fav.type = TOOLS_FAVORITES_QUERIES;
+ fav.type = GDA_TOOLS_FAVORITES_QUERIES;
fav.name = _("Unnamed query");
fav.descr = NULL;
fav.contents = (gchar*) gtk_selection_data_get_data (selection_data);
@@ -701,7 +701,7 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
pos = atoi (path);
/*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, pos, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, pos, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
@@ -711,7 +711,7 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
}
if (id >= 0)
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
return retval;
}
diff --git a/tools/browser/schema-browser/favorite-selector.c b/tools/browser/schema-browser/favorite-selector.c
index 9ac3427..c696e87 100644
--- a/tools/browser/schema-browser/favorite-selector.c
+++ b/tools/browser/schema-browser/favorite-selector.c
@@ -164,7 +164,7 @@ key_press_event_cb (GtkTreeView *treeview, GdkEventKey *event, FavoriteSelector
gtk_tree_model_get (model, &iter,
COLUMN_ID, &(fav.id), -1);
bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (!tools_favorites_delete (bfav, 0, &fav, NULL)) {
+ if (!gda_tools_favorites_delete (bfav, 0, &fav, NULL)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
_("Could not remove favorite: %s"),
lerror && lerror->message ? lerror->message : _("No detail"));
@@ -229,7 +229,7 @@ favorite_selector_new (BrowserConnection *bcnc)
/* create tree managers */
tsel->priv->tree = gda_tree_new ();
- manager = mgr_favorites_new (bcnc, TOOLS_FAVORITES_TABLES | TOOLS_FAVORITES_DIAGRAMS,
+ manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_TABLES | GDA_TOOLS_FAVORITES_DIAGRAMS,
ORDER_KEY_SCHEMA);
gda_tree_add_manager (tsel->priv->tree, manager);
g_object_unref (manager);
@@ -337,7 +337,7 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = -1;
- fav.type = TOOLS_FAVORITES_TABLES;
+ fav.type = GDA_TOOLS_FAVORITES_TABLES;
fav.name = NULL;
fav.descr = NULL;
fav.contents = (gchar*) gtk_selection_data_get_data (selection_data);
@@ -346,7 +346,7 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
/*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/
bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, pos, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, pos, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
diff --git a/tools/browser/schema-browser/objects-index.c b/tools/browser/schema-browser/objects-index.c
index 8afb2fc..39bb99c 100644
--- a/tools/browser/schema-browser/objects-index.c
+++ b/tools/browser/schema-browser/objects-index.c
@@ -136,7 +136,7 @@ cloud_object_selected_cb (G_GNUC_UNUSED ObjectsCloud *sel, G_GNUC_UNUSED Objects
{
/* FIXME: adjust with sel->priv->type */
g_signal_emit (index, objects_index_signals [SELECTION_CHANGED], 0,
- TOOLS_FAVORITES_TABLES, sel_contents);
+ GDA_TOOLS_FAVORITES_TABLES, sel_contents);
}
static void
diff --git a/tools/browser/schema-browser/relations-diagram.c b/tools/browser/schema-browser/relations-diagram.c
index 24059aa..f6cde38 100644
--- a/tools/browser/schema-browser/relations-diagram.c
+++ b/tools/browser/schema-browser/relations-diagram.c
@@ -30,7 +30,7 @@
#include "../browser-perspective.h"
#include "../browser-window.h"
#include "../data-manager/data-manager-perspective.h"
-#include "../../tools-utils.h"
+#include "../../tool-utils.h"
struct _RelationsDiagramPrivate {
BrowserConnection *bcnc;
@@ -225,7 +225,7 @@ real_save_clicked_cb (GtkWidget *button, RelationsDiagram *diagram)
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = diagram->priv->fav_id;
- fav.type = TOOLS_FAVORITES_DIAGRAMS;
+ fav.type = GDA_TOOLS_FAVORITES_DIAGRAMS;
fav.name = gtk_editable_get_chars (GTK_EDITABLE (diagram->priv->name_entry), 0, -1);
if (!*fav.name) {
g_free (fav.name);
@@ -236,7 +236,7 @@ real_save_clicked_cb (GtkWidget *button, RelationsDiagram *diagram)
gtk_widget_hide (diagram->priv->popup_container);
bfav = browser_connection_get_favorites (diagram->priv->bcnc);
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, G_MAXINT, &lerror)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, G_MAXINT, &lerror)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel (button),
"<b>%s:</b>\n%s",
_("Could not save diagram"),
@@ -275,10 +275,10 @@ save_clicked_cb (GtkWidget *button, RelationsDiagram *diagram)
diagram->priv->name_entry = wid;
if (diagram->priv->fav_id > 0) {
ToolsFavoritesAttributes fav;
- if (tools_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
+ if (gda_tools_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
diagram->priv->fav_id, &fav, NULL)) {
gtk_entry_set_text (GTK_ENTRY (wid), fav.name);
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
}
}
@@ -361,14 +361,14 @@ relations_diagram_new_with_fav_id (BrowserConnection *bcnc, gint fav_id, GError
ToolsFavoritesAttributes fav;
xmlDocPtr doc = NULL;
- if (! tools_favorites_get (browser_connection_get_favorites (bcnc),
+ if (! gda_tools_favorites_get (browser_connection_get_favorites (bcnc),
fav_id, &fav, error))
return FALSE;
doc = xmlParseDoc (BAD_CAST fav.contents);
if (!doc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Error parsing favorite's contents"));
goto out;
}
@@ -427,7 +427,7 @@ relations_diagram_new_with_fav_id (BrowserConnection *bcnc, gint fav_id, GError
xmlFree (schema);
if (name)
xmlFree (name);
- g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
"%s", _("Missing table attribute in favorite's contents"));
gtk_widget_destroy ((GtkWidget*) diagram);
diagram = NULL;
@@ -437,7 +437,7 @@ relations_diagram_new_with_fav_id (BrowserConnection *bcnc, gint fav_id, GError
}
out:
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
if (doc)
xmlFreeDoc (doc);
return (GtkWidget*) diagram;
@@ -455,7 +455,7 @@ relations_diagram_set_fav_id (RelationsDiagram *diagram, gint fav_id, GError **e
ToolsFavoritesAttributes fav;
if ((fav_id >=0) &&
- tools_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
+ gda_tools_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
fav_id, &fav, error)) {
gchar *str, *tmp;
tmp = g_markup_printf_escaped (_("'%s' diagram"), fav.name);
@@ -466,7 +466,7 @@ relations_diagram_set_fav_id (RelationsDiagram *diagram, gint fav_id, GError **e
diagram->priv->fav_id = fav.id;
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
}
else {
gchar *str;
@@ -556,10 +556,10 @@ relations_diagram_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_b
diagram = RELATIONS_DIAGRAM (page);
if (diagram->priv->fav_id > 0) {
ToolsFavoritesAttributes fav;
- if (tools_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
+ if (gda_tools_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
diagram->priv->fav_id, &fav, NULL)) {
tab_name = g_strdup (fav.name);
- tools_favorites_reset_attributes (&fav);
+ gda_tools_favorites_reset_attributes (&fav);
}
}
if (!tab_name)
diff --git a/tools/browser/schema-browser/schema-browser-perspective.c b/tools/browser/schema-browser/schema-browser-perspective.c
index 6551a10..a9d6a85 100644
--- a/tools/browser/schema-browser/schema-browser-perspective.c
+++ b/tools/browser/schema-browser/schema-browser-perspective.c
@@ -205,7 +205,7 @@ static void
fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, ToolsFavoritesType fav_type,
const gchar *selection, SchemaBrowserPerspective *bpers)
{
- if (fav_type == TOOLS_FAVORITES_TABLES) {
+ if (fav_type == GDA_TOOLS_FAVORITES_TABLES) {
GdaQuarkList *ql;
const gchar *type;
const gchar *schema = NULL, *table = NULL, *short_name = NULL;
@@ -249,7 +249,7 @@ fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, ToolsFav
if (ql)
gda_quark_list_free (ql);
}
- else if (fav_type == TOOLS_FAVORITES_DIAGRAMS) {
+ else if (fav_type == GDA_TOOLS_FAVORITES_DIAGRAMS) {
#ifdef HAVE_GOOCANVAS
schema_browser_perspective_display_diagram (bpers, fav_id);
#else
diff --git a/tools/browser/schema-browser/table-columns.c b/tools/browser/schema-browser/table-columns.c
index c6a2b31..5abfa88 100644
--- a/tools/browser/schema-browser/table-columns.c
+++ b/tools/browser/schema-browser/table-columns.c
@@ -27,7 +27,7 @@
#include "table-info.h"
#include "table-columns.h"
#include <libgda-ui/gdaui-tree-store.h>
-#include "../tools-utils.h"
+#include "../tool-utils.h"
#include "../support.h"
#include "../gdaui-bar.h"
#include "mgr-columns.h"
@@ -356,7 +356,7 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
gtk_text_buffer_insert (tbuffer, ¤t, _("Policy on UPDATE"), -1);
gtk_text_buffer_insert (tbuffer, ¤t, ": ", -1);
gtk_text_buffer_insert (tbuffer, ¤t,
- tools_utils_fk_policy_to_string (policy),
+ gda_tools_utils_fk_policy_to_string (policy),
-1);
}
policy = GDA_META_TABLE_FOREIGN_KEY_ON_DELETE_POLICY (fk);
@@ -366,7 +366,7 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
gtk_text_buffer_insert (tbuffer, ¤t, _("Policy on DELETE"), -1);
gtk_text_buffer_insert (tbuffer, ¤t, ": ", -1);
gtk_text_buffer_insert (tbuffer, ¤t,
- tools_utils_fk_policy_to_string (policy),
+ gda_tools_utils_fk_policy_to_string (policy),
-1);
}
diff --git a/tools/browser/schema-browser/table-info.c b/tools/browser/schema-browser/table-info.c
index 6fba0d5..c68986c 100644
--- a/tools/browser/schema-browser/table-info.c
+++ b/tools/browser/schema-browser/table-info.c
@@ -457,13 +457,13 @@ action_add_to_fav_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
fav.id = -1;
- fav.type = TOOLS_FAVORITES_TABLES;
+ fav.type = GDA_TOOLS_FAVORITES_TABLES;
fav.name = NULL;
fav.descr = NULL;
fav.contents = table_info_to_selection (tinfo);
bfav = browser_connection_get_favorites (tinfo->priv->bcnc);
- if (! tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, G_MAXINT, &error)) {
+ if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, G_MAXINT, &error)) {
browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tinfo),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
diff --git a/tools/cmdtool/Makefile.am b/tools/cmdtool/Makefile.am
new file mode 100644
index 0000000..6fb9e33
--- /dev/null
+++ b/tools/cmdtool/Makefile.am
@@ -0,0 +1,22 @@
+noinst_LTLIBRARIES = libcmdtool.la
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/libgda \
+ $(COREDEPS_CFLAGS) \
+ $(COREDEPS_WFLAGS)
+
+
+libcmdtool_la_SOURCES = \
+ tool.h \
+ tool-decl.h \
+ tool-errors.h \
+ tool-errors.c \
+ tool-input.h \
+ tool-input.c \
+ tool-output.h \
+ tool-output.c \
+ tool-command.h \
+ tool-command.c \
+ tool-help.h \
+ tool-help.c
diff --git a/tools/cmdtool/tool-command.c b/tools/cmdtool/tool-command.c
new file mode 100644
index 0000000..e2c08f8
--- /dev/null
+++ b/tools/cmdtool/tool-command.c
@@ -0,0 +1,486 @@
+/*
+ * Copyright (C) 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
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "tool-command.h"
+#include "tool-help.h"
+#include <glib/gi18n-lib.h>
+
+struct _ToolCommandGroup {
+ GSList *name_ordered;
+ GSList *group_ordered;
+};
+
+/* module error */
+GQuark
+tool_command_error_quark (void)
+{
+ static GQuark quark;
+ if (!quark)
+ quark = g_quark_from_static_string ("tool_command_error");
+ return quark;
+}
+
+
+/**
+ * tool_command_result_new:
+ * @type: a #ToolCommandResultType
+ *
+ * Returns: (transfer full): a new #ToolCommandResult
+ */
+ToolCommandResult *
+tool_command_result_new (GdaConnection *cnc, ToolCommandResultType type)
+{
+ ToolCommandResult *res;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = type;
+ if (cnc) {
+ res->was_in_transaction_before_exec =
+ gda_connection_get_transaction_status (cnc) ? TRUE : FALSE;
+ res->cnc = g_object_ref (cnc);
+ }
+ return res;
+}
+
+/**
+ * tool_command_result_free:
+ * @res: (allow-none): a #ToolCommandResult, or %NULL
+ *
+ * Frees any resource used by @res
+ */
+void
+tool_command_result_free (ToolCommandResult *res)
+{
+ if (!res)
+ return;
+ switch (res->type) {
+ case TOOL_COMMAND_RESULT_DATA_MODEL:
+ if (res->u.model)
+ g_object_unref (res->u.model);
+ if (! res->was_in_transaction_before_exec &&
+ res->cnc &&
+ gda_connection_get_transaction_status (res->cnc))
+ gda_connection_rollback_transaction (res->cnc, NULL, NULL);
+ break;
+ case TOOL_COMMAND_RESULT_SET:
+ if (res->u.set)
+ g_object_unref (res->u.set);
+ break;
+ case TOOL_COMMAND_RESULT_TREE:
+ if (res->u.tree)
+ g_object_unref (res->u.tree);
+ break;
+ case TOOL_COMMAND_RESULT_TXT:
+ case TOOL_COMMAND_RESULT_TXT_STDOUT:
+ if (res->u.txt)
+ g_string_free (res->u.txt, TRUE);
+ break;
+ case TOOL_COMMAND_RESULT_MULTIPLE: {
+ GSList *list;
+
+ for (list = res->u.multiple_results; list; list = list->next)
+ tool_command_result_free ((ToolCommandResult *) list->data);
+ g_slist_free (res->u.multiple_results);
+ break;
+ }
+ default:
+ break;
+ }
+ if (res->cnc)
+ g_object_unref (res->cnc);
+ g_free (res);
+}
+
+/**
+ * tool_command_group_new:
+ *
+ * Returns: (transfer full): a new #ToolCommandGroup structure
+ */
+ToolCommandGroup *
+tool_command_group_new (void)
+{
+ ToolCommandGroup *group;
+ group = g_new0 (ToolCommandGroup, 1);
+ return group;
+}
+
+/**
+ * tool_command_group_free:
+ * @group: (allow-none) (transfer full): a #ToolCommandGroup pointer
+ *
+ * Frees any resource used by @group
+ */
+void
+tool_command_group_free (ToolCommandGroup *group)
+{
+ if (group) {
+ g_slist_free (group->name_ordered);
+ g_slist_free (group->group_ordered);
+ g_free (group);
+ }
+}
+
+static gint
+commands_compare_name (ToolCommand *a, ToolCommand *b)
+{
+ gint cmp, alength, blength;
+ if (!a->name || !b->name) {
+ g_warning (_("Invalid unnamed command"));
+ if (!a->name) {
+ if (b->name)
+ return 1;
+ else
+ return 0;
+ }
+ else
+ return -1;
+ }
+ return strcmp (a->name, b->name);
+}
+
+static gint
+commands_compare_group (ToolCommand *a, ToolCommand *b)
+{
+ gint cmp, alength, blength;
+ if (!a->group || !b->group) {
+ g_warning (_("Invalid unnamed command"));
+ if (!a->group) {
+ if (b->group)
+ return 1;
+ else
+ return 0;
+ }
+ else
+ return -1;
+ }
+ return strcmp (a->group, b->group);
+}
+
+/**
+ * tool_command_group_add:
+ * @group: a #ToolCommandGroup pointer
+ * @cmd: (transfer none): the command to add
+ *
+ * Add @cmd to @group. If a previous command with the same name existed,
+ * it is replaced by the new one.
+ *
+ * @cmd is used as it is (i.e. not copied).
+ */
+void
+tool_command_group_add (ToolCommandGroup *group, ToolCommand *cmd)
+{
+ g_return_if_fail (group);
+ g_return_if_fail (cmd);
+ g_return_if_fail (cmd->name && *cmd->name && g_ascii_isalpha (*cmd->name));
+ g_return_if_fail (cmd->group && *cmd->group);
+ if (cmd->name && !cmd->name_args) {
+ cmd->name_args = cmd->name;
+ gchar *tmp;
+ for (tmp = cmd->name_args; *tmp && !g_ascii_isspace(*tmp); tmp++);
+ cmd->name = g_strndup (cmd->name_args, tmp - cmd->name_args);
+ }
+
+ tool_command_group_remove (group, cmd->name);
+
+ group->name_ordered = g_slist_insert_sorted (group->name_ordered, cmd,
+ (GCompareFunc) commands_compare_name);
+ group->group_ordered = g_slist_insert_sorted (group->group_ordered, cmd,
+ (GCompareFunc) commands_compare_group);
+}
+
+/**
+ * tool_command_group_remove:
+ * @group: a #ToolCommandGroup pointer
+ * @name: the name of the command to remove
+ *
+ * Remove @cmd from @group. If @cmd is not in @group, then nothing is done.
+ */
+void
+tool_command_group_remove (ToolCommandGroup *group, const gchar *name)
+{
+ g_return_if_fail (group);
+
+ GSList *list;
+ for (list = group->name_ordered; list; list = list->next) {
+ ToolCommand *ec;
+ gint cmp;
+ ec = (ToolCommand*) list->data;
+ cmp = strcmp (name, ec->name);
+ if (!cmp) {
+ group->name_ordered = g_slist_remove (group->name_ordered, ec);
+ group->group_ordered = g_slist_remove (group->group_ordered, ec);
+ break;
+ }
+ else if (cmp > 0)
+ break;
+ }
+}
+
+/**
+ * tool_command_group_find:
+ */
+ToolCommand *
+tool_command_group_find (ToolCommandGroup *group, const gchar *name, GError **error)
+{
+ ToolCommand *cmd = NULL;
+ GSList *list;
+ gsize length;
+
+ if (!name)
+ return NULL;
+
+ for (list = group->name_ordered; list; list = list->next) {
+ ToolCommand *command;
+ command = (ToolCommand*) list->data;
+ gint cmp;
+ cmp = strcmp (command->name, name);
+ if (!cmp) {
+ cmd = command;
+ break;
+ }
+ else if (cmp > 0)
+ break;
+ }
+
+ if (! cmd) {
+ /* see if a shortcut version leads to a command */
+ length = strlen (name);
+ guint nmatch = 0;
+ for (list = group->name_ordered; list; list = list->next) {
+ ToolCommand *command;
+ command = (ToolCommand*) list->data;
+ if (!strncmp (command->name, name, MIN (length, strlen (command->name)))) {
+ nmatch ++;
+ cmd = command;
+ }
+ }
+ if (nmatch != 1)
+ cmd = NULL;
+ }
+
+ if (!cmd &&
+ ((*name == 'h') || (*name == 'H')))
+ cmd = tool_command_group_find (group, "?", NULL);
+
+ if (!cmd) {
+ g_set_error (error, TOOL_COMMAND_ERROR,
+ TOOL_COMMAND_COMMAND_NOT_FOUND_ERROR,
+ _("Command '%s' not found"), name);
+ }
+
+ return cmd;
+}
+
+static gchar **
+split_command_string (const gchar *cmde, guint *out_n_args, GError **error)
+{
+ GArray *args;
+ gchar *ptr, *str;
+ g_assert (cmde && *cmde);
+ g_assert (out_n_args);
+
+ *out_n_args = 0;
+ str = g_strdup (cmde);
+ args = g_array_new (TRUE, FALSE, sizeof (gchar*));
+ for (ptr = str; *ptr; ptr++) {
+ gchar *tmp;
+ gboolean inquotes = FALSE;
+
+ for (tmp = ptr; *tmp && g_ascii_isspace (*tmp); tmp++); /* ignore spaces */
+
+ for (; *tmp; tmp++) {
+ if (*tmp == '"')
+ inquotes = !inquotes;
+ else if (*tmp == '\\') {
+ tmp++;
+ if (! *tmp) {
+ g_set_error (error, TOOL_COMMAND_ERROR,
+ TOOL_COMMAND_SYNTAX_ERROR,
+ _("Syntax error after '\\'"));
+ goto onerror;
+ }
+ }
+ else if (!inquotes && g_ascii_isspace (*tmp)) {
+ gchar hold;
+ gchar *dup;
+ hold = *tmp;
+ *tmp = 0;
+ if (*ptr == '"') {
+ gint len;
+ dup = g_strdup (ptr + 1);
+ len = strlen (dup);
+ g_assert (dup [len-1] == '"');
+ dup [len-1] = 0;
+ }
+ else
+ dup = g_strdup (ptr);
+ g_array_append_val (args, dup);
+ *out_n_args += 1;
+ ptr = tmp;
+ *tmp = hold;
+ break;
+ }
+ }
+
+ if (!*tmp) {
+ if (inquotes) {
+ g_set_error (error, TOOL_COMMAND_ERROR,
+ TOOL_COMMAND_SYNTAX_ERROR,
+ _("Unbalanced usage of quotes"));
+ goto onerror;
+ }
+ else {
+ /* last command */
+ gchar *dup;
+ if (*ptr == '"') {
+ gint len;
+ dup = g_strdup (ptr + 1);
+ len = strlen (dup);
+ g_assert (dup [len-1] == '"');
+ dup [len-1] = 0;
+ }
+ else
+ dup = g_strdup (ptr);
+ g_array_append_val (args, dup);
+ *out_n_args += 1;
+ break;
+ }
+ }
+ }
+
+ g_free (str);
+ if (0) {
+ /* debug */
+ guint i;
+ g_print ("split [%s] => %d parts\n", cmde, *out_n_args);
+ for (i = 0; ; i++) {
+ gchar *tmp;
+ tmp = g_array_index (args, gchar*, i);
+ if (!tmp)
+ break;
+ g_print ("\t[%s]\n", tmp);
+ }
+ }
+ return (gchar **) g_array_free (args, FALSE);
+
+ onerror:
+ g_free (str);
+ g_array_free (args, TRUE);
+ *out_n_args = 0;
+ return NULL;
+}
+
+/**
+ * tool_command_group_execute:
+ * @group: a #ToolCommandGroup pointer
+ * @cmde: the command as a string (name + arguments)
+ * @user_data: (allow-none): a pointer
+ * @error: (allow-none): a place to store errors, or %NULL
+ *
+ * Executes @cmde
+ *
+ * Returns: (transfer full): a new #ToolCommandResult result
+ */
+ToolCommandResult *
+tool_command_group_execute (ToolCommandGroup *group, const gchar *cmde,
+ ToolOutputFormat format, gpointer user_data, GError **error)
+{
+ g_return_val_if_fail (group, NULL);
+
+ if (!cmde || !*cmde) {
+ ToolCommandResult *res;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
+ return res;
+ }
+
+ ToolCommand *cmd;
+ gchar **args;
+ guint nargs;
+ args = split_command_string (cmde, &nargs, error);
+ if (!args)
+ return NULL;
+
+ ToolCommandResult *res = NULL;
+ GError *lerror = NULL;
+ cmd = tool_command_group_find (group, args[0], &lerror);
+ if (!cmd) {
+ if (args[0] && ((*args[0] == 'h') || (*args[0] == '?'))) {
+ /* help requested */
+ res = tool_help_get_command_help (group, args [1], format);
+ g_clear_error (&lerror);
+ }
+ else {
+ g_strfreev (args);
+ g_propagate_error (error, lerror);
+ return NULL;
+ }
+ }
+
+ if (!res) {
+ if (cmd->command_func)
+ res = cmd->command_func (cmd, nargs - 1, (const gchar**) args + 1, user_data, error);
+ else
+ g_warning ("Tool command has no associated function to execute");
+ }
+ g_strfreev (args);
+ return res;
+}
+
+/**
+ * tool_command_get_all_commands:
+ * @group: a #ToolCommandGroup group of commands
+ *
+ * Get a list of all the commands (sorted by group) in @group
+ *
+ * Returns: (transfer none): a list of all the #ToolCommand commands
+ */
+GSList *
+tool_command_get_all_commands (ToolCommandGroup *group)
+{
+ g_return_val_if_fail (group, NULL);
+ return group->group_ordered;
+}
+
+/**
+ * tool_command_get_commands:
+ * @group: a #ToolCommandGroup group of commands
+ * @prefix: (allow-none): a prefix
+ *
+ * Get a list of all the commands (sorted by group) in @group, starting by @prefix
+ *
+ * Returns: (transfer container): a list of all the #ToolCommand commands, free using g_slist_free()
+ */
+GSList *
+tool_command_get_commands (ToolCommandGroup *group, const gchar *prefix)
+{
+ g_return_val_if_fail (group, NULL);
+ if (!prefix || !*prefix)
+ return g_slist_copy (group->group_ordered);
+
+ GSList *list, *ret = NULL;
+ gsize len;
+ len = strlen (prefix);
+ for (list = group->group_ordered; list; list = list->next) {
+ ToolCommand *tc;
+ tc = (ToolCommand*) list->data;
+ if (!strncmp (tc->name, prefix, len))
+ ret = g_slist_prepend (ret, tc);
+ }
+
+ return g_slist_reverse (ret);
+}
diff --git a/tools/cmdtool/tool-command.h b/tools/cmdtool/tool-command.h
new file mode 100644
index 0000000..150ee7d
--- /dev/null
+++ b/tools/cmdtool/tool-command.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 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
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __TOOL_COMMAND__
+#define __TOOL_COMMAND__
+
+#include <stdio.h>
+#include <glib.h>
+#include <libgda.h>
+#include "tool-decl.h"
+#include "tool-output.h"
+#include "tool-input.h"
+
+/**
+ * ToolCommandResultType:
+ *
+ * Defines the type of result of a command result
+ */
+typedef enum {
+ TOOL_COMMAND_RESULT_EMPTY,
+ TOOL_COMMAND_RESULT_DATA_MODEL,
+ TOOL_COMMAND_RESULT_SET,
+ TOOL_COMMAND_RESULT_TREE,
+ TOOL_COMMAND_RESULT_TXT,
+ TOOL_COMMAND_RESULT_TXT_STDOUT,
+ TOOL_COMMAND_RESULT_MULTIPLE,
+ TOOL_COMMAND_RESULT_EXIT
+} ToolCommandResultType;
+
+/**
+ * ToolCommandResult:
+ *
+ * Returned value after a command has been executed
+ */
+struct _ToolCommandResult {
+ ToolCommandResultType type;
+ GdaConnection *cnc;
+ gboolean was_in_transaction_before_exec;
+ union {
+ GdaDataModel *model;
+ GdaSet *set;
+ GdaTree *tree;
+ GString *txt;
+ GSList *multiple_results; /* for TOOL_COMMAND_RESULT_MULTIPLE */
+ } u;
+};
+
+ToolCommandResult *tool_command_result_new (GdaConnection *cnc, ToolCommandResultType type);
+void tool_command_result_free (ToolCommandResult *res);
+
+/**
+ * ToolCommandFunc:
+ * @command: the #ToolCommand to execute
+ * @argc: @argv's size
+ * @argv: the arguments (not including the command's name itself)
+ * @user_data: (allow-none): a pointer to some use data, corresponds to the @user_data argument of tool_command_group_execute()
+ * @error: (allow-none): a place to store errors
+ *
+ * Function defining a command's execution code
+ */
+typedef ToolCommandResult *(*ToolCommandFunc) (ToolCommand *command, guint argc, const gchar **argv,
+ gpointer user_data, GError **error);
+
+typedef gchar** (*ToolCommandCompletionFunc) (const gchar *text);
+
+/**
+ * ToolCommand:
+ *
+ * Definition of a command. This can be subclassed to include more specific tools data.
+ */
+struct _ToolCommand {
+ gchar *group;
+ gchar *group_id; /* to be found in the help file */
+ gchar *name; /* without the '\' or '.' */
+ gchar *name_args; /* without the '\' or '.', but with the name included */
+ gchar *description;
+ ToolCommandFunc command_func;
+ ToolCommandCompletionFunc completion_func;
+};
+
+/* error reporting */
+extern GQuark tool_command_error_quark (void);
+#define TOOL_COMMAND_ERROR tool_command_error_quark ()
+
+typedef enum {
+ TOOL_COMMAND_COMMAND_NOT_FOUND_ERROR,
+ TOOL_COMMAND_SYNTAX_ERROR
+} CoolCommandError;
+
+
+/**
+ * ToolCommandGroup:
+ *
+ * A coherent ser of commands
+ */
+ToolCommandGroup *tool_command_group_new (void);
+void tool_command_group_free (ToolCommandGroup *group);
+void tool_command_group_add (ToolCommandGroup *group, ToolCommand *cmd);
+void tool_command_group_remove (ToolCommandGroup *group, const gchar *name);
+ToolCommand *tool_command_group_find (ToolCommandGroup *group, const gchar *name, GError **error);
+GSList *tool_command_get_all_commands (ToolCommandGroup *group);
+GSList *tool_command_get_commands (ToolCommandGroup *group, const gchar *prefix);
+
+ToolCommandResult *tool_command_group_execute (ToolCommandGroup *group, const gchar *cmde,
+ ToolOutputFormat format,
+ gpointer user_data, GError **error);
+
+#endif
diff --git a/tools/tools-utils.h b/tools/cmdtool/tool-decl.h
similarity index 55%
copy from tools/tools-utils.h
copy to tools/cmdtool/tool-decl.h
index 566713b..4fcded5 100644
--- a/tools/tools-utils.h
+++ b/tools/cmdtool/tool-decl.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 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
@@ -16,29 +16,20 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __GDA_TOOLS_UTILS__
-#define __GDA_TOOLS_UTILS__
+#ifndef __TOOL_DECL__
+#define __TOOL_DECL__
-#include <libgda/libgda.h>
+typedef enum {
+ TOOL_OUTPUT_FORMAT_DEFAULT = 1 << 0,
+ TOOL_OUTPUT_FORMAT_HTML = 1 << 1,
+ TOOL_OUTPUT_FORMAT_XML = 1 << 2,
+ TOOL_OUTPUT_FORMAT_CSV = 1 << 3,
-const gchar *tools_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy);
+ TOOL_OUTPUT_FORMAT_COLOR_TERM = 1 << 8
+} ToolOutputFormat;
-/*
- * 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;
+typedef struct _ToolCommand ToolCommand;
+typedef struct _ToolCommandResult ToolCommandResult;
+typedef struct _ToolCommandGroup ToolCommandGroup;
#endif
diff --git a/tools/tools-utils.h b/tools/cmdtool/tool-defines.h
similarity index 54%
copy from tools/tools-utils.h
copy to tools/cmdtool/tool-defines.h
index 566713b..e2235c4 100644
--- a/tools/tools-utils.h
+++ b/tools/cmdtool/tool-defines.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 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
@@ -16,29 +16,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __GDA_TOOLS_UTILS__
-#define __GDA_TOOLS_UTILS__
+#ifndef __TOOL_DEFINES__
+#define __TOOL_DEFINES__
-#include <libgda/libgda.h>
-
-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;
+#define TOOL_NAME "GDA-SQL"
+#define TOOL_HISTORY_ENV_NAME "GDA_SQL_HISTFILE"
+#define TOOL_HISTORY_FILE "gdadsl_history"
+#define TOOL_NO_PAGER "GDA_NO_PAGER"
#endif
diff --git a/tools/tools-utils.h b/tools/cmdtool/tool-errors.c
similarity index 53%
copy from tools/tools-utils.h
copy to tools/cmdtool/tool-errors.c
index 566713b..fc4fc1a 100644
--- a/tools/tools-utils.h
+++ b/tools/cmdtool/tool-errors.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 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
@@ -16,29 +16,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __GDA_TOOLS_UTILS__
-#define __GDA_TOOLS_UTILS__
+#include "tool-errors.h"
+#include <glib/gi18n-lib.h>
-#include <libgda/libgda.h>
-
-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
+/* module error */
+GQuark
+tool_errors_quark (void)
+{
+ static GQuark quark;
+ if (!quark)
+ quark = g_quark_from_static_string ("tool_errors");
+ return quark;
+}
diff --git a/tools/tools-utils.h b/tools/cmdtool/tool-errors.h
similarity index 57%
copy from tools/tools-utils.h
copy to tools/cmdtool/tool-errors.h
index 566713b..4c35586 100644
--- a/tools/tools-utils.h
+++ b/tools/cmdtool/tool-errors.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 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
@@ -16,29 +16,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __GDA_TOOLS_UTILS__
-#define __GDA_TOOLS_UTILS__
+#ifndef __TOOL_ERRORS__
+#define __TOOL_ERRORS__
-#include <libgda/libgda.h>
-
-const gchar *tools_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy);
+#include <glib.h>
/*
* error reporting
*/
-extern GQuark tools_error_quark (void);
-#define TOOLS_ERROR tools_error_quark ()
+extern GQuark tool_errors_quark (void);
+#define TOOL_ERRORS tool_errors_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;
+ TOOL_STORED_DATA_ERROR
+} ToolErrors;
#endif
diff --git a/tools/cmdtool/tool-help.c b/tools/cmdtool/tool-help.c
new file mode 100644
index 0000000..c4844d8
--- /dev/null
+++ b/tools/cmdtool/tool-help.c
@@ -0,0 +1,517 @@
+/*
+ * Copyright (C) 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
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "tool-help.h"
+#include "tool-command.h"
+#include "tool-input.h"
+#include <glib/gi18n-lib.h>
+#include <libgda/binreloc/gda-binreloc.h>
+
+static xmlDocPtr helpdoc = NULL;
+
+/**
+ * tools_help_set_xml_file:
+ *
+ * Returns: %TRUE if file has been loaded
+ */
+gboolean
+tool_help_set_xml_file (const gchar *file)
+{
+ if (helpdoc) {
+ xmlFreeDoc (helpdoc);
+ helpdoc = NULL;
+ }
+ if (file) {
+ helpdoc = xmlParseFile (file);
+ return helpdoc ? TRUE : FALSE;
+ }
+ else
+ return TRUE;
+}
+
+/*
+ * Same as append_to_string but cuts strings which are too long
+ */
+static void
+append_raw_to_string (GString *string, gchar *str, gint width, gint offset)
+{
+ g_assert (string);
+ if (!str)
+ return;
+ if ((width <= 0) && (offset <= 0)) {
+ g_string_append (string, str);
+ return;
+ }
+ if (offset < 0)
+ offset = 0;
+
+ /* start on a fresh line */
+ if ((string->str) && (string->len > 0) &&
+ (string->str[string->len - 1] != '\n'))
+ g_string_append_c (string, '\n');
+
+ gchar *ptr;
+ gboolean startofline = TRUE;
+ for (ptr = str; *ptr; ) {
+ gchar *next, *pnext;
+ if (*ptr == '\n') {
+ g_string_append_c (string, '\n');
+ ptr++;
+ startofline = TRUE;
+ continue;
+ }
+ guint clen = 0;
+ for (next = ptr, pnext = ptr;
+ *next && (*next != '\n');
+ pnext = next + 1, next = g_utf8_next_char (next), clen++) {
+ if (startofline) {
+ if (offset > 0) {
+ gint i;
+ for (i = 0; i < offset; i++)
+ g_string_append_c (string, ' ');
+ }
+ startofline = FALSE;
+ }
+
+ if ((width > 0) && ((gint) clen >= width - offset)) {
+ g_string_append_c (string, '\n');
+ startofline = TRUE;
+ for (; *next && (*next != '\n'); next++);
+ if (*next == '\n')
+ next++;
+ break;
+ }
+ else {
+ for (; pnext <= next; pnext++)
+ g_string_append_c (string, *pnext);
+ }
+ }
+ ptr = next;
+ }
+}
+
+/*
+ * parses @str, and appends to @string lines which are @width large, if @offset is >0, then
+ * leave that amount of spaces. If @width <= 0, then only adds @offset spaces at the beginning of each
+ * new line.
+ */
+static void
+append_to_string (GString *string, gchar *str, gint width, gint offset)
+{
+ g_assert (string);
+ if (!str)
+ return;
+ if ((width <= 0) && (offset <= 0)) {
+ g_string_append (string, str);
+ return;
+ }
+ if (offset < 0)
+ offset = 0;
+
+ /* replace @WORD@ by <WORD> */
+ gchar *ptr;
+ gboolean in = FALSE;
+ for (ptr = str; *ptr; ptr++) {
+ if (*ptr == '@') {
+ if (in) {
+ *ptr = '>';
+ in = FALSE;
+ }
+ else {
+ *ptr = '<';
+ in = TRUE;
+ }
+ }
+ }
+
+ /* actual work */
+ gboolean firstword = TRUE;
+ gint clen = 0;
+ if ((string->str) && (string->len > 0) &&
+ (string->str[string->len - 1] != '\n')) {
+ for (ptr = string->str + (string->len -1); (ptr >= string->str) && (*ptr != '\n'); ptr --)
+ clen++;
+ }
+ if (!strcmp (str, "> ")) {
+ if (offset > 0) {
+ gint i;
+ for (i = 0; i < offset; i++)
+ g_string_append_c (string, ' ');
+ }
+ g_string_append (string, str);
+ return;
+ }
+
+ for (ptr = str; *ptr; ) {
+ /* skip spaces */
+ if ((*ptr == ' ') || (*ptr == '\t') || (*ptr == '\n') || (*ptr == '\r')) {
+ ptr++;
+ continue;
+ }
+
+ /* find end of next word */
+ gchar *next;
+ gint wlen;
+ for (wlen = 0, next = ptr;
+ *next && (*next != ' ') && (*next != '\t') && (*next != '\n') && (*next != '\r');
+ wlen ++, next = g_utf8_next_char (next));
+
+ if (wlen >= width - offset) {
+ const gchar *n2;
+ for (n2 = ptr; n2 < next; n2++) {
+ g_string_append_c (string, *n2);
+ }
+ ptr = next;
+ firstword = FALSE;
+ g_string_append_c (string, '\n');
+ clen = 0;
+ continue;
+ }
+ else if ((width > 0) && ((wlen + clen) >= width)) {
+ /* cut here */
+ g_string_append_c (string, '\n');
+ clen = 0;
+ continue;
+ }
+ else {
+ /* copy word */
+ if (clen == 0) {
+ if (offset > 0) {
+ gint i;
+ for (i = 0; i < offset; i++) {
+ g_string_append_c (string, ' ');
+ clen++;
+ }
+ }
+ }
+ else if (!firstword) {
+ g_string_append_c (string, ' ');
+ clen++;
+ }
+ const gchar *n2;
+ for (n2 = ptr; n2 < next; n2++) {
+ g_string_append_c (string, *n2);
+ clen++;
+ }
+ ptr = next;
+ firstword = FALSE;
+ }
+ }
+}
+
+static gchar *
+help_xml_doc_to_string_command (xmlDocPtr helpdoc, const gchar *command_name, gint width, ToolOutputFormat format)
+{
+ xmlNodePtr node;
+ node = xmlDocGetRootElement (helpdoc);
+ if (!node || !command_name || !*command_name)
+ return NULL;
+ for (node = node->children; node; node = node->next) {
+ if (strcmp ((gchar*) node->name, "command"))
+ continue;
+ xmlChar *prop;
+ prop = xmlGetProp (node, BAD_CAST "name");
+ if (prop && !strcmp ((gchar*) prop, command_name))
+ break;
+ }
+ if (!node)
+ return NULL;
+
+ /* create output string */
+ GString *string;
+ string = g_string_new ("");
+ for (node = node->children; node; node = node->next) {
+ xmlChar *data = NULL;
+ if (!strcmp ((gchar*) node->name, "shortdescription")) {
+ data = xmlNodeGetContent (node);
+ if (data) {
+ append_to_string (string, (gchar*) data, width, 0);
+ g_string_append (string, "\n\n");
+ }
+ }
+ else if (!strcmp ((gchar*) node->name, "usage") || !strcmp ((gchar*) node->name, "example")) {
+ if (!strcmp ((gchar*) node->name, "usage"))
+ append_to_string (string, _("Usage"), width, 0);
+ else
+ append_to_string (string, _("Example"), width, 0);
+ g_string_append (string, ":\n");
+ xmlNodePtr snode;
+ for (snode = node->children; snode; snode = snode->next) {
+ if (!strcmp ((gchar*) snode->name, "synopsis")) {
+ data = xmlNodeGetContent (snode);
+ if (data) {
+ append_to_string (string, "> ", width, 3);
+ gchar *tmp;
+ tmp = g_strdup_printf ("%s%s%s",
+ tool_output_color_s (TOOL_COLOR_BOLD, format),
+ data,
+ tool_output_color_s (TOOL_COLOR_RESET, format));
+ append_to_string (string, tmp, width, 3);
+ g_free (tmp);
+ g_string_append_c (string, '\n');
+ }
+ }
+ else if (!strcmp ((gchar*) snode->name, "comment")) {
+ data = xmlNodeGetContent (snode);
+ if (data) {
+ append_to_string (string, (gchar*) data, width, 6);
+ g_string_append_c (string, '\n');
+ }
+ }
+ else if (!strcmp ((gchar*) snode->name, "raw")) {
+ data = xmlNodeGetContent (snode);
+ if (data) {
+ append_raw_to_string (string, (gchar*) data, width, 6);
+ g_string_append (string, "\n\n");
+ }
+ }
+ if (data)
+ xmlFree (data);
+ data = NULL;
+ }
+ }
+ if (data)
+ xmlFree (data);
+ }
+
+ return g_string_free (string, FALSE);
+}
+
+static gchar *
+help_xml_doc_to_string_section (xmlDocPtr helpdoc, const gchar *section_name, gint width)
+{
+ xmlNodePtr node;
+ node = xmlDocGetRootElement (helpdoc);
+ if (!node || !section_name || !*section_name)
+ return NULL;
+ for (node = node->children; node; node = node->next) {
+ if (strcmp ((gchar*) node->name, "section"))
+ continue;
+ xmlChar *prop;
+ prop = xmlGetProp (node, BAD_CAST "name");
+ if (prop && strstr ((gchar*) prop, section_name))
+ break;
+ }
+ if (!node)
+ return NULL;
+
+ /* create output string */
+ GString *string;
+ string = g_string_new ("");
+ for (node = node->children; node; node = node->next) {
+ xmlChar *data = NULL;
+ if (!strcmp ((gchar*) node->name, "shortdescription")) {
+ data = xmlNodeGetContent (node);
+ if (data) {
+ append_to_string (string, (gchar*) data, width, 0);
+ g_string_append (string, "\n\n");
+ }
+ }
+ else if (!strcmp ((gchar*) node->name, "usage") || !strcmp ((gchar*) node->name, "example")) {
+ if (!strcmp ((gchar*) node->name, "example")) {
+ append_to_string (string, _("Example"), width, 0);
+ g_string_append (string, ":\n");
+ }
+ xmlNodePtr snode;
+ for (snode = node->children; snode; snode = snode->next) {
+ if (!strcmp ((gchar*) snode->name, "synopsis")) {
+ data = xmlNodeGetContent (snode);
+ if (data) {
+ append_to_string (string, "> ", width, 3);
+ append_to_string (string, (gchar*) data, width, 3);
+ g_string_append_c (string, '\n');
+ }
+ }
+ else if (!strcmp ((gchar*) snode->name, "comment")) {
+ data = xmlNodeGetContent (snode);
+ if (data) {
+ append_to_string (string, (gchar*) data, width, 3);
+ g_string_append_c (string, '\n');
+ }
+ }
+ else if (!strcmp ((gchar*) snode->name, "raw")) {
+ data = xmlNodeGetContent (snode);
+ if (data) {
+ append_raw_to_string (string, (gchar*) data, width, 3);
+ g_string_append (string, "\n\n");
+ }
+ }
+ if (data)
+ xmlFree (data);
+ data = NULL;
+ }
+ }
+ if (data)
+ xmlFree (data);
+ }
+
+ return g_string_free (string, FALSE);
+}
+
+/**
+ * load_help_doc:
+ */
+static xmlDocPtr
+load_help_doc (void)
+{
+ xmlDocPtr helpdoc = NULL;
+ const gchar * const *langs = g_get_language_names ();
+ gchar *dirname, *helpfile;
+ gint i;
+ dirname = gda_gbr_get_file_path (GDA_DATA_DIR, "gnome", "help",
+ "gda-sql", NULL);
+ for (i = 0; langs[i]; i++) {
+ helpfile = g_build_filename (dirname, langs[i], "gda-sql-help.xml", NULL);
+ if (g_file_test (helpfile, G_FILE_TEST_EXISTS))
+ helpdoc = xmlParseFile (helpfile);
+ g_free (helpfile);
+ if (helpdoc)
+ break;
+ }
+
+ if (!helpdoc) {
+ /* default to the "C" one */
+ helpfile = g_build_filename (dirname, "C", "gda-sql-help.xml", NULL);
+ if (g_file_test (helpfile, G_FILE_TEST_EXISTS))
+ helpdoc = xmlParseFile (helpfile);
+ g_free (helpfile);
+ }
+ g_free (dirname);
+ return helpdoc;
+}
+
+/**
+ * tools_help_get_command_help:
+ */
+ToolCommandResult *
+tool_help_get_command_help (ToolCommandGroup *group, const gchar *command_name, ToolOutputFormat format)
+{
+ ToolCommandResult *res;
+ GSList *list;
+ gchar *current_group = NULL;
+ GString *string = g_string_new ("");
+#define NAMESIZE 18
+
+ /* get term size */
+ gint width = -1;
+ if (format | TOOL_OUTPUT_FORMAT_DEFAULT)
+ input_get_size (&width, NULL);
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT;
+
+ if (command_name) {
+ ToolCommand *command = NULL;
+ GError *lerror = NULL;
+ if ((*command_name == '.') || (*command_name == '\\'))
+ command_name = command_name + 1;
+ command = tool_command_group_find (group, command_name, &lerror);
+ if (command) {
+ if (!helpdoc)
+ helpdoc = load_help_doc ();
+
+ gboolean done = FALSE;
+ if (helpdoc) {
+ gchar *tmp;
+ tmp = help_xml_doc_to_string_command (helpdoc, command_name, width, format);
+ if (tmp) {
+ g_string_append (string, tmp);
+ g_free (tmp);
+ done = TRUE;
+ }
+ }
+ if (!done) {
+ append_to_string (string, command->description, width, 0);
+ g_string_append_printf (string, "\n\n%s:\n ", _("Usage"));
+ tool_output_color_append_string (TOOL_COLOR_BOLD, format, string, ".");
+ tool_output_color_append_string (TOOL_COLOR_BOLD, format, string, command->name_args);
+ }
+ }
+ else {
+ g_string_append_printf (string, "%s", lerror->message);
+ g_clear_error (&lerror);
+ }
+ }
+ else {
+ GSList *all_commands;
+ all_commands = tool_command_get_all_commands (group);
+ for (list = all_commands; list; list = list->next) {
+ ToolCommand *command = (ToolCommand*) list->data;
+ gint clen;
+
+#ifdef HAVE_LDAP
+ if (g_str_has_prefix (command->name, "ldap") && cnc && !GDA_IS_LDAP_CONNECTION (cnc))
+ continue;
+#endif
+
+ if (!current_group || strcmp (current_group, command->group)) {
+ current_group = command->group;
+ if (list != all_commands)
+ g_string_append_c (string, '\n');
+ if (width > 0) {
+ gint i, nb, remain;
+ nb = (width - g_utf8_strlen (current_group, -1) - 2) / 2;
+ remain = width - (2 * nb + 2 + g_utf8_strlen (current_group, -1));
+ for (i = 0; i < nb; i++)
+ g_string_append_c (string, '=');
+ g_string_append_c (string, ' ');
+ append_to_string (string, current_group, width, 0);
+ g_string_append_c (string, ' ');
+ for (i = 0; i < nb + remain; i++)
+ g_string_append_c (string, '=');
+ g_string_append_c (string, '\n');
+ }
+ else {
+ g_string_append (string, "=== ");
+ append_to_string (string, current_group, width, 0);
+ g_string_append (string, " ===\n");
+ }
+
+ if (!helpdoc)
+ helpdoc = load_help_doc ();
+
+ if (helpdoc && command->group_id) {
+ gchar *tmp;
+ tmp = help_xml_doc_to_string_section (helpdoc, command->group_id, width);
+ if (tmp) {
+ g_string_append (string, tmp);
+ g_free (tmp);
+ g_string_append_c (string, '\n');
+ }
+ }
+ }
+
+ g_string_append (string, " ");
+ tool_output_color_append_string (TOOL_COLOR_BOLD, format, string, ".");
+ tool_output_color_append_string (TOOL_COLOR_BOLD, format, string, command->name);
+ clen = g_utf8_strlen (command->name, -1);
+ if (clen >= NAMESIZE)
+ g_string_append_c (string, '\n');
+ else {
+ gint i, size;
+ size = NAMESIZE - clen - 1;
+ for (i = 0; i < size; i++)
+ g_string_append_c (string, ' ');
+ }
+ append_to_string (string, command->description, width, NAMESIZE + 3);
+ g_string_append_c (string, '\n');
+ }
+ }
+ res->u.txt = string;
+ return res;
+}
diff --git a/tools/tools-utils.h b/tools/cmdtool/tool-help.h
similarity index 54%
copy from tools/tools-utils.h
copy to tools/cmdtool/tool-help.h
index 566713b..71c36d9 100644
--- a/tools/tools-utils.h
+++ b/tools/cmdtool/tool-help.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 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
@@ -16,29 +16,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __GDA_TOOLS_UTILS__
-#define __GDA_TOOLS_UTILS__
+#ifndef __TOOL_HELP__
+#define __TOOL_HELP__
-#include <libgda/libgda.h>
+#include <stdio.h>
+#include <glib.h>
+#include "tool-command.h"
-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;
+gboolean tool_help_set_xml_file (const gchar *file);
+ToolCommandResult *tool_help_get_command_help (ToolCommandGroup *group, const gchar *command_name, ToolOutputFormat format);
#endif
diff --git a/tools/cmdtool/tool-input.c b/tools/cmdtool/tool-input.c
new file mode 100644
index 0000000..f4beffd
--- /dev/null
+++ b/tools/cmdtool/tool-input.c
@@ -0,0 +1,486 @@
+/*
+ * Copyright (C) 2007 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 David King <davidk openismus com>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "tool-errors.h"
+#include "tool-input.h"
+#include "tool-command.h"
+#include <glib/gi18n-lib.h>
+#include <glib/gstdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#ifndef G_OS_WIN32
+#include <sys/ioctl.h>
+#endif
+
+#define TO_IMPLEMENT g_print ("Implementation missing: %s() in %s line %d\n", __FUNCTION__, __FILE__,__LINE__)
+
+#ifdef HAVE_READLINE
+#include <readline/readline.h>
+#endif
+#ifdef HAVE_HISTORY
+#include <readline/history.h>
+#endif
+
+#include "tool-defines.h"
+
+#ifdef HAVE_HISTORY
+static gboolean history_init_done = FALSE;
+gchar *history_file = NULL;
+#endif
+
+static void init_history ();
+
+/**
+ * input_from_stream
+ *
+ * returns: a new string read from @stream
+ */
+gchar *
+input_from_stream (FILE *stream)
+{
+ #define LINE_SIZE 65535
+ gchar line [LINE_SIZE];
+ gchar *result;
+
+ result = fgets (line, LINE_SIZE, stream);
+ if (!result)
+ return NULL;
+ else {
+ gint len = strlen (line);
+ if (line [len - 1] == '\n')
+ line [len - 1] = 0;
+ return g_strdup (line);
+ }
+}
+
+static TreatLineFunc line_cb_func = NULL;
+static gpointer line_cb_func_data = NULL;
+static ComputePromptFunc line_prompt_func = NULL;
+static GIOChannel *ioc = NULL;
+
+static gboolean
+chars_for_readline_cb (G_GNUC_UNUSED GIOChannel *ioc, G_GNUC_UNUSED GIOCondition condition,
+ G_GNUC_UNUSED gpointer data)
+{
+#ifdef HAVE_READLINE
+ rl_callback_read_char ();
+#else
+ gchar *line;
+ gsize tpos;
+ GError *error = NULL;
+ GIOStatus st;
+ st = g_io_channel_read_line (ioc, &line, NULL, &tpos, &error);
+ switch (st) {
+ case G_IO_STATUS_NORMAL:
+ line [tpos] = 0;
+ if (line_cb_func (line, line_cb_func_data) == TRUE) {
+ /* print prompt for next line */
+ g_print ("%s", line_prompt_func ());
+ }
+ g_free (line);
+ break;
+ case G_IO_STATUS_ERROR:
+ g_warning ("Error reading from STDIN: %s\n",
+ error && error->message ? error->message : _("No detail"));
+ if (error)
+ g_error_free (error);
+ break;
+ case G_IO_STATUS_EOF:
+ /* send the Quit command */
+ line_cb_func (".q", line_cb_func_data);
+ return FALSE;
+ break;
+ default:
+ break;
+ }
+#endif
+ return TRUE;
+}
+
+#ifdef HAVE_READLINE
+static void
+line_read_handler (char *line)
+{
+ line_cb_func (line, line_cb_func_data); /* we don't care about the return status */
+ free (line);
+ rl_set_prompt (line_prompt_func ());
+}
+#endif
+
+/**
+ * init_input
+ *
+ * Initializes input
+ */
+void
+init_input (TreatLineFunc treat_line_func, ComputePromptFunc prompt_func, gpointer data)
+{
+ /* init readline related features */
+ line_cb_func = treat_line_func;
+ line_cb_func_data = data;
+ line_prompt_func = prompt_func;
+
+#ifdef HAVE_READLINE
+ rl_catch_signals = 1;
+ rl_set_signals ();
+ rl_readline_name = "gda-sql";
+ rl_callback_handler_install (prompt_func (), line_read_handler);
+#else
+ g_print ("%s", line_prompt_func ());
+#endif
+ if (!ioc) {
+ ioc = g_io_channel_unix_new (STDIN_FILENO);
+ g_io_add_watch (ioc, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, (GIOFunc) chars_for_readline_cb, NULL);
+ }
+
+ /* init history */
+ init_history ();
+
+ /* completion init */
+#ifdef HAVE_READLINE
+ rl_basic_word_break_characters = " \t\n\\'` $><=;|&{(";
+ rl_completer_word_break_characters = " \t\n\\'` $><=;|&{(";
+#endif
+}
+
+/**
+ * end_input
+ *
+ * Releases any data related to the input and allocated during init_input()
+ */
+void
+end_input (void)
+{
+#ifdef HAVE_READLINE
+ rl_callback_handler_remove ();
+#endif
+ if (ioc) {
+ g_io_channel_shutdown (ioc, TRUE, NULL);
+ g_io_channel_unref (ioc);
+ }
+}
+
+static gsize
+determine_max_prefix_len (gchar **array)
+{
+ gsize max;
+ g_assert (array[0]);
+ g_assert (array[1]);
+
+ for (max = 1; ; max++) {
+ gint i;
+ gchar *ref;
+ ref = array[0];
+ for (i = 1; array[i]; i++) {
+ if (strncmp (ref, array[i], max))
+ break;
+ if (!array[i][max]) {
+ max ++;
+ break;
+ }
+ }
+ if (array[i])
+ break;
+ }
+
+ return max - 1;
+}
+
+static ToolCommandGroup *user_defined_completion_group = NULL;
+static CompletionFunc user_defined_completion_func = NULL;
+static gchar *user_defined_chars_to_ignore = NULL;
+
+#ifdef HAVE_READLINE
+static char **
+_tool_completion (const char *text, int start, int end)
+{
+ GArray *array = NULL;
+ gchar *match, *prematch;
+ gboolean treated = FALSE;
+ match = g_strndup (rl_line_buffer + start, end - start);
+ g_assert (!strcmp (text, match));
+ prematch = g_strndup (rl_line_buffer, start);
+ g_strstrip (prematch);
+ g_strstrip (match);
+
+ if (start == 0) {
+ /* user needs to enter a command */
+ if (!user_defined_completion_group)
+ goto out;
+
+ gchar *cmd_match;
+ gchar start_char = 0;
+ cmd_match = match;
+
+ /* maybe ignore some start chars */
+ if (user_defined_chars_to_ignore) {
+ gchar *ptr;
+ for (ptr = user_defined_chars_to_ignore; *ptr; ptr++) {
+ if (*cmd_match == *ptr) {
+ cmd_match ++;
+ start_char = *ptr;
+ break;
+ }
+ }
+ }
+
+ if (!user_defined_chars_to_ignore || (start_char && user_defined_chars_to_ignore)) {
+ GSList *commands;
+ commands = tool_command_get_commands (user_defined_completion_group, cmd_match);
+ if (commands) {
+ array = g_array_new (TRUE, FALSE, sizeof (gchar*));
+ GSList *list;
+ for (list = commands; list; list = list->next) {
+ ToolCommand *tc = (ToolCommand*) list->data;
+ const gchar *tmp;
+ if (start_char)
+ tmp = g_strdup_printf ("%c%s", start_char, tc->name);
+ else
+ tmp = g_strdup (tc->name);
+ g_array_append_val (array, tmp);
+ }
+ g_slist_free (commands);
+ }
+ rl_completion_append_character = ' ';
+ treated = TRUE;
+ }
+ }
+
+ if (!treated && user_defined_completion_func) {
+ gchar **vals;
+ ToolCommand *tc = NULL;
+ if (*prematch && user_defined_completion_group) {
+ gchar *tmp = prematch;
+ if (user_defined_chars_to_ignore) {
+ gchar *ptr;
+ for (ptr = user_defined_chars_to_ignore; *ptr; ptr++) {
+ if (*tmp == *ptr) {
+ tmp ++;
+ break;
+ }
+ }
+ }
+ tc = tool_command_group_find (user_defined_completion_group, tmp, NULL);
+ }
+ if (tc && tc->completion_func)
+ vals = tc->completion_func (text);
+ else
+ vals = user_defined_completion_func (text, rl_line_buffer, start, end);
+
+ if (vals) {
+ guint i;
+ for (i = 0; vals [i]; i++) {
+ if (!array)
+ array = g_array_new (TRUE, FALSE, sizeof (gchar*));
+ gchar *tmp;
+ tmp = vals[i];
+ g_array_append_val (array, tmp);
+ }
+ g_free (vals); /* and not g_strfreev() */
+ rl_completion_append_character = 0;
+ }
+ }
+
+ out:
+ g_free (match);
+ g_free (prematch);
+ if (array) {
+ if (array->len > 1) {
+ /* determine max string in common to all possible completions */
+ gsize len;
+ len = determine_max_prefix_len ((gchar**) array->data);
+ if (len > 0) {
+ gchar *tmp;
+ tmp = g_strndup (g_array_index (array, gchar*, 0), len);
+ g_array_prepend_val (array, tmp);
+ }
+ else {
+ gchar *tmp;
+ tmp = g_strdup ("");
+ g_array_prepend_val (array, tmp);
+ }
+ }
+ return (gchar**) g_array_free (array, FALSE);
+ }
+ else
+ return NULL;
+}
+#endif /* HAVE_READLINE */
+
+/**
+ * tool_input_set_completion_func:
+ * @group: (allow-none): a #ToolCommandGroup, or %NULL
+ * @func: (allow-none): a #CompletionFunc, or %NULL
+ * @start_chars_to_ignore: (allow-none): a list of characters to ignore at the beginning of commands
+ *
+ * Defines the completion function.
+ */
+void
+tool_input_set_completion_func (ToolCommandGroup *group, CompletionFunc func, gchar *start_chars_to_ignore)
+{
+ user_defined_completion_group = group;
+ user_defined_completion_func = func;
+ g_free (user_defined_chars_to_ignore);
+ user_defined_chars_to_ignore = start_chars_to_ignore ? g_strdup (start_chars_to_ignore) : NULL;
+
+#ifdef HAVE_READLINE
+ if (group || func)
+ rl_attempted_completion_function = _tool_completion;
+ else
+ rl_attempted_completion_function = NULL;
+#endif
+}
+
+/*
+ * input_get_size
+ *
+ * Get the size of the input term, if possible, otherwise returns -1
+ */
+void
+input_get_size (gint *width, gint *height)
+{
+ int tty = fileno (stdin);
+ int cols = -1, rows = -1;
+
+#ifdef TIOCGWINSZ
+ struct winsize window_size;
+ if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) {
+ cols = (int) window_size.ws_col;
+ rows = (int) window_size.ws_row;
+ }
+
+ if (cols <= 1)
+ cols = -1;
+ if (rows <= 0)
+ rows = -1;
+#endif
+
+ if (width)
+ *width = cols;
+ if (height)
+ *height = rows;
+
+ /*g_print ("Screen: %dx%d\n", cols, rows);*/
+}
+
+static void
+sanitize_env (gchar *str)
+{
+ gchar *ptr;
+ for (ptr = str; *ptr; ptr++) {
+ if (! g_ascii_isprint (*ptr) || (*ptr == G_DIR_SEPARATOR))
+ *ptr = '_';
+ }
+}
+
+/**
+ * init_history
+ *
+ * Loads the contents of the history file, if supported
+ */
+static void
+init_history ()
+{
+#ifdef HAVE_HISTORY
+ if (history_init_done)
+ return;
+ if (getenv (TOOL_HISTORY_ENV_NAME)) {
+ const gchar *ename;
+ ename = getenv (TOOL_HISTORY_ENV_NAME);
+ if (!ename || !*ename || !strcmp (ename, "NO_HISTORY")) {
+ history_init_done = TRUE;
+ return;
+ }
+ history_file = g_strdup (ename);
+ sanitize_env (history_file);
+ }
+ else {
+ gchar *cache_dir;
+#ifdef LIBGDA_ABI_NAME
+ cache_dir = g_build_filename (g_get_user_cache_dir (), "libgda", NULL);
+#else
+ gchar *tmp;
+ tmp = g_utf8_strdown (TOOL_NAME, -1);
+ cache_dir = g_build_filename (g_get_user_cache_dir (), tmp, NULL);
+ g_free (tmp);
+#endif
+ history_file = g_build_filename (cache_dir, TOOL_HISTORY_FILE, NULL);
+ if (!g_file_test (cache_dir, G_FILE_TEST_EXISTS)) {
+ if (g_mkdir_with_parents (cache_dir, 0700)) {
+ g_free (history_file);
+ history_file = NULL;
+ }
+ }
+ g_free (cache_dir);
+ }
+ if (history_file) {
+ using_history ();
+ read_history (history_file);
+ history_init_done = TRUE;
+ }
+#endif
+}
+
+/**
+ * add_to_history
+ */
+void
+add_to_history (const gchar *txt)
+{
+#ifdef HAVE_HISTORY
+ if (!history_init_done)
+ init_history ();
+ if (!txt || !(*txt))
+ return;
+
+ HIST_ENTRY *current;
+
+ current = history_get (history_length);
+ if (current && current->line && !strcmp (current->line, txt))
+ return;
+ add_history (txt);
+#endif
+}
+
+/**
+ * save_history
+ */
+gboolean
+save_history (const gchar *file, GError **error)
+{
+#ifdef HAVE_HISTORY
+ int res;
+ if (!history_init_done || !history_file)
+ return FALSE;
+ res = append_history (1, file ? file : history_file);
+ if (res == ENOENT)
+ res = write_history (file ? file : history_file);
+ if (res != 0) {
+ g_set_error (error, TOOL_ERRORS, TOOL_STORED_DATA_ERROR,
+ _("Could not save history file to '%s': %s"),
+ file ? file : history_file, strerror (errno));
+ return FALSE;
+ }
+ /*if (res == 0)
+ history_truncate_file (history_file, 500);*/
+#endif
+ return TRUE;
+}
diff --git a/tools/tools-input.h b/tools/cmdtool/tool-input.h
similarity index 81%
copy from tools/tools-input.h
copy to tools/cmdtool/tool-input.h
index 8bb3a8a..8ce6ca4 100644
--- a/tools/tools-input.h
+++ b/tools/cmdtool/tool-input.h
@@ -20,26 +20,28 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __GDA_TOOLS_INPUT__
-#define __GDA_TOOLS_INPUT__
+#ifndef __TOOLS_INPUT__
+#define __TOOLS_INPUT__
#include <stdio.h>
#include <glib.h>
+#ifdef HAVE_READLINE
+#include <readline/readline.h>
+#endif
+#include "tool-decl.h"
-typedef char **(*CompletionFunc) (const char *, int, int);
+typedef char **(*CompletionFunc) (const char *match, const char *line, int start, int end);
typedef gboolean (*TreatLineFunc) (const gchar *, gpointer);
typedef const char *(*ComputePromptFunc) (void);
-gchar *input_from_console (const gchar *prompt);
gchar *input_from_stream (FILE *stream);
void init_input (TreatLineFunc treat_line_func, ComputePromptFunc prompt_func, gpointer data);
void input_get_size (gint *width, gint *height);
void end_input (void);
-void init_history ();
void add_to_history (const gchar *txt);
gboolean save_history (const gchar *file, GError **error);
-void set_completion_func (CompletionFunc func);
+void tool_input_set_completion_func (ToolCommandGroup *group, CompletionFunc func, gchar *start_chars_to_ignore);
#endif
diff --git a/tools/cmdtool/tool-output.c b/tools/cmdtool/tool-output.c
new file mode 100644
index 0000000..1abc87d
--- /dev/null
+++ b/tools/cmdtool/tool-output.c
@@ -0,0 +1,842 @@
+/*
+ * Copyright (C) 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
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "tool-defines.h"
+#include "tool-output.h"
+#include <glib/gi18n-lib.h>
+#include <glib/gstdio.h>
+#include <unistd.h>
+
+#ifndef G_OS_WIN32
+#include <signal.h>
+typedef void (*sighandler_t)(int);
+#include <pwd.h>
+#else
+#include <stdlib.h>
+#include <windows.h>
+#endif
+
+static GdaSet *
+make_options_set_from_string (const gchar *context, GdaSet *options)
+{
+ GdaSet *expopt = NULL;
+ GSList *list, *nlist = NULL;
+ if (options) {
+ for (list = options->holders; list; list = list->next) {
+ GdaHolder *param = GDA_HOLDER (list->data);
+ const GValue *cvalue;
+ cvalue = gda_holder_get_attribute (param, context);
+ if (!cvalue)
+ continue;
+
+ GdaHolder *nparam;
+ const GValue *cvalue2;
+ cvalue2 = gda_holder_get_value (param);
+ nparam = gda_holder_new (G_VALUE_TYPE (cvalue2));
+ g_object_set ((GObject*) nparam, "id", g_value_get_string (cvalue), NULL);
+ g_assert (gda_holder_set_value (nparam, cvalue2, NULL));
+ nlist = g_slist_append (nlist, nparam);
+ }
+ if (nlist) {
+ expopt = gda_set_new (nlist);
+ g_slist_free (nlist);
+ }
+ }
+ return expopt;
+}
+
+static gchar *
+data_model_to_string (GdaDataModel *model, ToolOutputFormat format, FILE *stream, GdaSet *options)
+{
+ static gboolean env_set = FALSE;
+
+ if (!GDA_IS_DATA_MODEL (model))
+ return NULL;
+
+ if (!env_set) {
+ if (! getenv ("GDA_DATA_MODEL_DUMP_TITLE"))
+ g_setenv ("GDA_DATA_MODEL_DUMP_TITLE", "Yes", TRUE);
+ if (! getenv ("GDA_DATA_MODEL_NULL_AS_EMPTY"))
+ g_setenv ("GDA_DATA_MODEL_NULL_AS_EMPTY", "Yes", TRUE);
+ if (! stream || isatty (fileno (stream))) {
+ if (! getenv ("GDA_DATA_MODEL_DUMP_TRUNCATE"))
+ g_setenv ("GDA_DATA_MODEL_DUMP_TRUNCATE", "-1", TRUE);
+ }
+ env_set = TRUE;
+ }
+
+ if (format & TOOL_OUTPUT_FORMAT_DEFAULT) {
+ gchar *tmp;
+ tmp = gda_data_model_dump_as_string (model);
+ if (GDA_IS_DATA_SELECT (model)) {
+ gchar *tmp2, *tmp3;
+ gdouble etime;
+ g_object_get ((GObject*) model, "execution-delay", &etime, NULL);
+ tmp2 = g_strdup_printf ("%s: %.03f s", _("Execution delay"), etime);
+ tmp3 = g_strdup_printf ("%s\n%s", tmp, tmp2);
+ g_free (tmp);
+ g_free (tmp2);
+ return tmp3;
+ }
+ else
+ return tmp;
+ }
+ else if (format & TOOL_OUTPUT_FORMAT_XML)
+ return gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_DATA_ARRAY_XML,
+ NULL, 0,
+ NULL, 0, NULL);
+ else if (format & TOOL_OUTPUT_FORMAT_CSV) {
+ gchar *retval;
+ GdaSet *optexp;
+ optexp = make_options_set_from_string ("csv", options);
+ retval = gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_TEXT_SEPARATED,
+ NULL, 0,
+ NULL, 0, optexp);
+ if (optexp)
+ g_object_unref (optexp);
+ return retval;
+ }
+ else if (format & TOOL_OUTPUT_FORMAT_HTML) {
+ xmlBufferPtr buffer;
+ xmlNodePtr top, div, table, node, row_node, col_node, header, meta;
+ gint ncols, nrows, i, j;
+ gchar *str;
+
+ top = xmlNewNode (NULL, BAD_CAST "html");
+ header = xmlNewChild (top, NULL, BAD_CAST "head", NULL);
+ meta = xmlNewChild (header, NULL, BAD_CAST "meta", NULL);
+ xmlSetProp (meta, BAD_CAST "http-equiv", BAD_CAST "content-type");
+ xmlSetProp (meta, BAD_CAST "content", BAD_CAST "text/html; charset=UTF-8");
+ div = xmlNewChild (top, NULL, BAD_CAST "body", NULL);
+ table = xmlNewChild (div, NULL, BAD_CAST "table", NULL);
+ xmlSetProp (table, BAD_CAST "border", BAD_CAST "1");
+
+ if (g_object_get_data (G_OBJECT (model), "name"))
+ xmlNewTextChild (table, NULL, BAD_CAST "caption", g_object_get_data (G_OBJECT (model), "name"));
+
+ ncols = gda_data_model_get_n_columns (model);
+ nrows = gda_data_model_get_n_rows (model);
+
+ row_node = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
+ for (j = 0; j < ncols; j++) {
+ const gchar *cstr;
+ cstr = gda_data_model_get_column_title (model, j);
+ col_node = xmlNewTextChild (row_node, NULL, BAD_CAST "th", BAD_CAST cstr);
+ xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "center");
+ }
+
+ for (i = 0; i < nrows; i++) {
+ row_node = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
+ xmlSetProp (row_node, BAD_CAST "valign", BAD_CAST "top");
+ for (j = 0; j < ncols; j++) {
+ const GValue *value;
+ value = gda_data_model_get_value_at (model, j, i, NULL);
+ if (!value) {
+ col_node = xmlNewChild (row_node, NULL, BAD_CAST "td", BAD_CAST "ERROR");
+ xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "left");
+ }
+ else {
+ str = gda_value_stringify (value);
+ col_node = xmlNewTextChild (row_node, NULL, BAD_CAST "td", BAD_CAST str);
+ xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "left");
+ g_free (str);
+ }
+ }
+ }
+
+ node = xmlNewChild (div, NULL, BAD_CAST "p", NULL);
+ str = g_strdup_printf (ngettext ("(%d row)", "(%d rows)", nrows), nrows);
+ xmlNodeSetContent (node, BAD_CAST str);
+ g_free (str);
+
+ buffer = xmlBufferCreate ();
+ xmlNodeDump (buffer, NULL, top, 0, 1);
+ str = g_strdup ((gchar *) xmlBufferContent (buffer));
+ xmlBufferFree (buffer);
+ xmlFreeNode (top);
+ return str;
+ }
+ else
+ TO_IMPLEMENT;
+
+ return NULL;
+}
+
+
+/*
+ * REM: if @attr_names is not NULL, then @cols_size will have the same number of items
+ *
+ * - Optionally called once with @out_max_prefix_size not %NULL and @in_string %NULL => compute
+ * cols_size[x] and *out_max_prefix_size
+ * - Called once with @in_string not %NULL and @out_max_prefix_size %NULL
+ */
+static void
+tree_node_to_string (GdaTreeNode *node, gboolean has_parent, gboolean has_next_sibling,
+ const gchar *prefix,
+ gchar **attr_names, guint *cols_size, guint max_prefix_size,
+ guint *out_max_prefix_size, GString *in_string)
+{
+ gchar *pipe = "|";
+ gchar *prefix2 = "|- ";
+ gchar *prefix3 = "`- ";
+
+ pipe = "â";
+ prefix2 = "ââ ";
+ prefix3 = "ââ ";
+#define SEP " "
+ const GValue *cvalue;
+ gchar *p;
+ const gchar *cstr;
+ guint i;
+
+ /* prefix */
+ if (has_next_sibling)
+ p = g_strdup_printf ("%s%s", prefix, prefix2);
+ else
+ p = g_strdup_printf ("%s%s", prefix, prefix3);
+ if (in_string)
+ g_string_append (in_string, p);
+ i = g_utf8_strlen (p, -1);
+ g_free (p);
+
+ /* node name */
+ cvalue = gda_tree_node_get_node_attribute (node, GDA_ATTRIBUTE_NAME);
+ cstr = cvalue && g_value_get_string (cvalue)? g_value_get_string (cvalue) : "???";
+ if (in_string)
+ g_string_append (in_string, cstr);
+
+ /* padding */
+ if (in_string) {
+ for (i = i + g_utf8_strlen (cstr, -1); i < max_prefix_size; i++)
+ g_string_append_c (in_string, ' ');
+ }
+ else {
+ guint size = i;
+ if (g_utf8_validate (cstr, -1, NULL))
+ size += g_utf8_strlen (cstr, -1);
+ else
+ size += strlen (cstr);
+ *out_max_prefix_size = MAX (size, *out_max_prefix_size);
+ }
+
+ /* some node's attributes */
+ if (attr_names) {
+ for (i = 0; attr_names[i] && *attr_names[i]; i++) {
+ guint colsize = 0;
+ if (in_string) {
+ if (cols_size [i] == 0)
+ continue; /* ignore this attribute as it's not set */
+ g_string_append (in_string, SEP);
+ }
+
+ cvalue = gda_tree_node_get_node_attribute (node, attr_names[i]);
+ if (cvalue && (G_VALUE_TYPE (cvalue) != GDA_TYPE_NULL)) {
+ gchar *tmp = NULL;
+ if (G_VALUE_TYPE (cvalue) == G_TYPE_FLOAT)
+ tmp = g_strdup_printf ("%.01f", g_value_get_float (cvalue));
+ else {
+ GdaDataHandler *dh;
+ dh = gda_data_handler_get_default (G_VALUE_TYPE (cvalue));
+ if (dh)
+ tmp = gda_data_handler_get_str_from_value (dh, cvalue);
+ else
+ tmp = gda_value_stringify (cvalue);
+ }
+ if (in_string) {
+ gboolean right = FALSE;
+ if ((G_VALUE_TYPE (cvalue) == G_TYPE_INT) ||
+ (G_VALUE_TYPE (cvalue) == G_TYPE_UINT) ||
+ (G_VALUE_TYPE (cvalue) == G_TYPE_INT64) ||
+ (G_VALUE_TYPE (cvalue) == G_TYPE_UINT64) ||
+ (G_VALUE_TYPE (cvalue) == G_TYPE_FLOAT) ||
+ (G_VALUE_TYPE (cvalue) == G_TYPE_DOUBLE) ||
+ (G_VALUE_TYPE (cvalue) == G_TYPE_CHAR) ||
+ (G_VALUE_TYPE (cvalue) == GDA_TYPE_SHORT) ||
+ (G_VALUE_TYPE (cvalue) == GDA_TYPE_USHORT))
+ right = TRUE;
+
+ if (right) {
+ /* right align */
+ guint j;
+ for (j = tmp ? g_utf8_strlen (tmp, -1) : 0; j < cols_size [i]; j++)
+ g_string_append_c (in_string, ' ');
+
+ if (tmp) {
+ if (g_utf8_strlen (tmp, -1) > cols_size[i])
+ tmp [cols_size [i]] = 0;
+ g_string_append (in_string, tmp);
+ }
+ }
+ else {
+ /* left align */
+ if (tmp) {
+ if (g_utf8_strlen (tmp, -1) > cols_size[i])
+ tmp [cols_size [i]] = 0;
+ g_string_append (in_string, tmp);
+ }
+ guint j;
+ for (j = tmp ? g_utf8_strlen (tmp, -1) : 0; j < cols_size [i]; j++)
+ g_string_append_c (in_string, ' ');
+ }
+ }
+ else {
+ if (tmp) {
+ if (g_utf8_validate (tmp, -1, NULL))
+ colsize += g_utf8_strlen (tmp, -1);
+ else
+ colsize += strlen (tmp);
+ }
+ cols_size [i] = MAX (cols_size [i], colsize);
+ }
+
+ g_free (tmp);
+ }
+ else if (in_string){
+ guint j;
+ for (j = 0; j < cols_size [i]; j++)
+ g_string_append_c (in_string, ' ');
+ }
+ }
+ }
+ if (in_string)
+ g_string_append_c (in_string, '\n');
+
+ /* children */
+ gchar *ch_prefix;
+ if (has_next_sibling)
+ ch_prefix = g_strdup_printf ("%s%s ", prefix, pipe);
+ else
+ ch_prefix = g_strdup_printf ("%s ", prefix);
+
+ GSList *top, *list;
+ top = gda_tree_node_get_children (node);
+ for (list = top; list; list = list->next)
+ tree_node_to_string (GDA_TREE_NODE (list->data), TRUE, list->next ? TRUE : FALSE,
+ ch_prefix, attr_names, cols_size, max_prefix_size,
+ out_max_prefix_size, in_string);
+
+ g_slist_free (top);
+ g_free (ch_prefix);
+}
+
+static gchar *
+tree_to_string_default (GdaTree *tree, FILE *stream, GdaSet *options)
+{
+ GString *string;
+ GSList *top, *list;
+ gchar **attr_names = NULL;
+ guint attr_names_size = 0;
+ guint *cols_size = NULL;
+ guint max_prefix_size = 0;
+
+ g_return_val_if_fail (GDA_IS_TREE (tree), NULL);
+
+ if (options) {
+ const GValue *cvalue;
+ cvalue = gda_set_get_holder_value (options, "GDA_TREE_COLUMN_NAMES");
+ if (cvalue && (G_VALUE_TYPE (cvalue) == G_TYPE_STRING) && g_value_get_string (cvalue)) {
+ attr_names = g_strsplit (g_value_get_string (cvalue), ",", 0);
+ if (attr_names) {
+ guint i;
+ for (i = 0; attr_names [i]; i++)
+ g_strstrip (attr_names [i]);
+ attr_names_size = i;
+ }
+ }
+ }
+
+ string = g_string_new ("");
+ top = gda_tree_get_nodes_in_path (tree, NULL, FALSE);
+ if (attr_names) {
+ /* determine prefix's max size and columns' max size */
+ cols_size = g_new0 (guint, attr_names_size);
+ for (list = top; list; list = list->next) {
+ tree_node_to_string (GDA_TREE_NODE (list->data), FALSE, list->next ? TRUE : FALSE, "",
+ attr_names, cols_size, 0, &max_prefix_size, NULL);
+ }
+
+ guint i, j;
+ for (i = 0; attr_names [i]; i++) {
+ guint size = 0;
+ if (g_utf8_validate (attr_names[i], -1, NULL))
+ size += g_utf8_strlen (attr_names[i], -1);
+ else
+ size += strlen (attr_names[i]);
+ cols_size[i] = MAX (cols_size[i], size);
+ }
+
+ /* output column names */
+ const gchar *title;
+ title = (const gchar*) g_object_get_data ((GObject*) tree, "GDA_TREE_TITLE");
+ if (title) {
+ g_string_append (string, title);
+ for (j = g_utf8_strlen (title, -1); j < max_prefix_size; j++)
+ g_string_append_c (string, ' ');
+ }
+ else {
+ for (j = 0; j < max_prefix_size; j++)
+ g_string_append_c (string, ' ');
+ }
+
+ /* output column values */
+ for (i = 0; attr_names [i]; i++) {
+ if (cols_size[i] == 0)
+ continue;
+ g_string_append (string, SEP);
+ g_string_append (string, attr_names[i]);
+ guint size = 0;
+ if (g_utf8_validate (attr_names[i], -1, NULL))
+ size += g_utf8_strlen (attr_names[i], -1);
+ else
+ size += strlen (attr_names[i]);
+ for (j = size; j < cols_size[i]; j++)
+ g_string_append_c (string, ' ');
+ }
+ g_string_append_c (string, '\n');
+ }
+
+ for (list = top; list; list = list->next)
+ tree_node_to_string (GDA_TREE_NODE (list->data), FALSE, list->next ? TRUE : FALSE, "",
+ attr_names, cols_size, max_prefix_size, NULL, string);
+ g_slist_free (top);
+
+ if (attr_names) {
+ g_strfreev (attr_names);
+ g_free (cols_size);
+ }
+
+ return g_string_free (string, FALSE);
+}
+
+static gchar *
+tree_to_string (GdaTree *tree, ToolOutputFormat format, FILE *stream, GdaSet *options)
+{
+ if (!GDA_IS_TREE (tree))
+ return NULL;
+
+ if (format & TOOL_OUTPUT_FORMAT_DEFAULT)
+ return tree_to_string_default (tree, stream, options);
+ else if (format & TOOL_OUTPUT_FORMAT_XML) {
+ TO_IMPLEMENT;
+ }
+ else if (format & TOOL_OUTPUT_FORMAT_CSV) {
+ TO_IMPLEMENT;
+ }
+ else if (format & TOOL_OUTPUT_FORMAT_HTML) {
+ TO_IMPLEMENT;
+ }
+ else
+ TO_IMPLEMENT;
+
+ return NULL;
+}
+
+
+/**
+ * tool_output_result_to_string:
+ * @res: a #ToolCommandResult
+ * @format: a #ToolOutputFormat format specification
+ * @stream: (allow-none): a stream which the returned string will be put to, or %NULL
+ * @options: (allow-none): a #GdaSet containing options, or %NULL
+ *
+ * Converts @res to a string
+ *
+ * Returns: (transfer full): a new string
+ */
+gchar *
+tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
+ FILE *stream, GdaSet *options)
+{
+ switch (res->type) {
+ case TOOL_COMMAND_RESULT_DATA_MODEL:
+ return data_model_to_string (res->u.model, format, stream, options);
+
+ case TOOL_COMMAND_RESULT_SET: {
+ GSList *list;
+ GString *string;
+ xmlNodePtr node;
+ xmlBufferPtr buffer;
+ gchar *str;
+
+ if (format & TOOL_OUTPUT_FORMAT_DEFAULT) {
+ string = g_string_new ("");
+ for (list = res->u.set->holders; list; list = list->next) {
+ const GValue *value;
+ gchar *tmp;
+ const gchar *cstr;
+ GdaHolder *h;
+ h = GDA_HOLDER (list->data);
+
+ cstr = gda_holder_get_id (h);
+ value = gda_holder_get_value (h);
+ if (!strcmp (cstr, "IMPACTED_ROWS")) {
+ g_string_append_printf (string, "%s: ",
+ _("Number of rows impacted"));
+ tmp = gda_value_stringify (value);
+ g_string_append_printf (string, "%s", tmp);
+ g_free (tmp);
+ }
+ else if (!strcmp (cstr, "EXEC_DELAY")) {
+ g_string_append_printf (string, "%s: ",
+ _("Execution delay"));
+ gdouble etime;
+ etime = g_value_get_double (value);
+ g_string_append_printf (string, "%.03f s", etime);
+ }
+ else {
+ tmp = g_markup_escape_text (cstr, -1);
+ g_string_append_printf (string, "%s: ", tmp);
+ g_free (tmp);
+
+ tmp = gda_value_stringify (value);
+ g_string_append_printf (string, "%s", tmp);
+ g_free (tmp);
+ }
+ g_string_append (string, "\n");
+ }
+ str = string->str;
+ g_string_free (string, FALSE);
+ return str;
+ }
+ else if (format & TOOL_OUTPUT_FORMAT_XML) {
+ buffer = xmlBufferCreate ();
+ node = xmlNewNode (NULL, BAD_CAST "parameters");
+ for (list = res->u.set->holders; list; list = list->next) {
+ const GValue *value;
+ xmlNodePtr pnode, vnode;
+
+ pnode = xmlNewNode (NULL, BAD_CAST "parameter");
+ xmlAddChild (node, pnode);
+ xmlSetProp (pnode, BAD_CAST "name",
+ BAD_CAST gda_holder_get_id (GDA_HOLDER (list->data)));
+ value = gda_holder_get_value (GDA_HOLDER (list->data));
+ vnode = gda_value_to_xml (value);
+ xmlAddChild (pnode, vnode);
+ }
+ xmlNodeDump (buffer, NULL, node, 0, 1);
+ str = g_strdup ((gchar *) xmlBufferContent (buffer));
+ xmlBufferFree (buffer);
+ xmlFreeNode (node);
+ return str;
+ }
+ else if (format & TOOL_OUTPUT_FORMAT_HTML) {
+ buffer = xmlBufferCreate ();
+ node = xmlNewNode (NULL, BAD_CAST "ul");
+ for (list = res->u.set->holders; list; list = list->next) {
+ const GValue *value;
+ xmlNodePtr pnode, vnode;
+
+ pnode = xmlNewNode (NULL, BAD_CAST "li");
+ xmlAddChild (node, pnode);
+ xmlSetProp (pnode, BAD_CAST "name",
+ BAD_CAST gda_holder_get_id (GDA_HOLDER (list->data)));
+ value = gda_holder_get_value (GDA_HOLDER (list->data));
+ vnode = gda_value_to_xml (value);
+ xmlAddChild (pnode, vnode);
+ }
+ xmlNodeDump (buffer, NULL, node, 0, 1);
+ str = g_strdup ((gchar *) xmlBufferContent (buffer));
+ xmlBufferFree (buffer);
+ xmlFreeNode (node);
+ return str;
+ }
+ else if (format & TOOL_OUTPUT_FORMAT_CSV) {
+ string = g_string_new ("");
+ for (list = res->u.set->holders; list; list = list->next) {
+ const GValue *value;
+ gchar *tmp;
+ const gchar *cstr;
+ GdaHolder *h;
+ h = GDA_HOLDER (list->data);
+
+ cstr = gda_holder_get_id (h);
+ value = gda_holder_get_value (h);
+ if (!strcmp (cstr, "IMPACTED_ROWS")) {
+ g_string_append_printf (string, "\"%s\",",
+ _("Number of rows impacted"));
+ tmp = gda_value_stringify (value);
+ g_string_append_printf (string, "\"%s\"", tmp);
+ g_free (tmp);
+ }
+ else if (!strcmp (cstr, "EXEC_DELAY")) {
+ g_string_append_printf (string, "\"%s\",",
+ _("Execution delay"));
+ gdouble etime;
+ etime = g_value_get_double (value);
+ g_string_append_printf (string, "\"%.03f s\"", etime);
+ }
+ else {
+ tmp = g_markup_escape_text (cstr, -1);
+ g_string_append_printf (string, "\"%s\",", tmp);
+ g_free (tmp);
+
+ tmp = gda_value_stringify (value);
+ g_string_append_printf (string, "\"%s\"", tmp);
+ g_free (tmp);
+ }
+ g_string_append (string, "\n");
+ }
+ str = string->str;
+ g_string_free (string, FALSE);
+ return str;
+ }
+ else {
+ TO_IMPLEMENT;
+ return NULL;
+ }
+ }
+
+ case TOOL_COMMAND_RESULT_TREE: {
+ GdaSet *options2, *merge = NULL;
+
+ options2 = g_object_get_data ((GObject*) res->u.tree, "TOOL_OUTPUT_OPTIONS");
+ if (options && options2) {
+ merge = gda_set_copy (options2);
+ gda_set_merge_with_set (merge, options);
+ }
+ gchar *tmp;
+ tmp = tree_to_string (res->u.tree, format, stream, merge ? merge : (options ? options : options2));
+ if (merge)
+ g_object_unref (merge);
+ return tmp;
+ }
+
+ case TOOL_COMMAND_RESULT_TXT: {
+ xmlNodePtr node;
+ xmlBufferPtr buffer;
+ gchar *str;
+
+ if ((format & TOOL_OUTPUT_FORMAT_DEFAULT) ||
+ (format & TOOL_OUTPUT_FORMAT_CSV))
+ return g_strdup (res->u.txt->str);
+ else if (format & TOOL_OUTPUT_FORMAT_XML) {
+ buffer = xmlBufferCreate ();
+ node = xmlNewNode (NULL, BAD_CAST "txt");
+ xmlNodeSetContent (node, BAD_CAST res->u.txt->str);
+ xmlNodeDump (buffer, NULL, node, 0, 1);
+ str = g_strdup ((gchar *) xmlBufferContent (buffer));
+ xmlBufferFree (buffer);
+ xmlFreeNode (node);
+ return str;
+ }
+ else if (format & TOOL_OUTPUT_FORMAT_HTML) {
+ buffer = xmlBufferCreate ();
+ node = xmlNewNode (NULL, BAD_CAST "p");
+ xmlNodeSetContent (node, BAD_CAST res->u.txt->str);
+ xmlNodeDump (buffer, NULL, node, 0, 1);
+ str = g_strdup ((gchar *) xmlBufferContent (buffer));
+ xmlBufferFree (buffer);
+ xmlFreeNode (node);
+ return str;
+ }
+ else {
+ TO_IMPLEMENT;
+ return NULL;
+ }
+ }
+
+ case TOOL_COMMAND_RESULT_EMPTY:
+ return g_strdup ("");
+
+ case TOOL_COMMAND_RESULT_MULTIPLE: {
+ GSList *list;
+ GString *string = NULL;
+ gchar *str;
+
+ for (list = res->u.multiple_results; list; list = list->next) {
+ ToolCommandResult *tres = (ToolCommandResult*) list->data;
+ gchar *tmp;
+
+ tmp = tool_output_result_to_string (tres, format, stream, options);
+ if (!string)
+ string = g_string_new (tmp);
+ else {
+ g_string_append_c (string, '\n');
+ g_string_append (string, tmp);
+ }
+ g_free (tmp);
+ }
+ if (string) {
+ str = string->str;
+ g_string_free (string, FALSE);
+ }
+ else
+ str = g_strdup ("");
+ return str;
+ }
+
+ default:
+ return NULL;
+ }
+}
+
+/*
+ * Check that the @arg string can safely be passed to a shell
+ * to be executed, i.e. it does not contain dangerous things like "rm -rf *"
+ */
+// coverity[ +tainted_string_sanitize_content : arg-0 ]
+static gboolean
+check_shell_argument (const gchar *arg)
+{
+ const gchar *ptr;
+ g_assert (arg);
+
+ /* check for starting spaces */
+ for (ptr = arg; *ptr == ' '; ptr++);
+ if (!*ptr)
+ return FALSE; /* only spaces is not allowed */
+
+ /* check for the rest */
+ for (; *ptr; ptr++) {
+ if (! g_ascii_isalnum (*ptr) && (*ptr != G_DIR_SEPARATOR))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ * tool_output_output_string:
+ * @stream: (allow-none): an outout stream, or %NULL
+ * @str: a string
+ *
+ * "Outputs" @str to @stream, or to stdout if @stream is %NULL
+ */
+void
+tool_output_output_string (FILE *stream, const gchar *str)
+{
+ FILE *to_stream;
+ gboolean append_nl = FALSE;
+ gint length;
+ static gint force_no_pager = -1;
+
+ if (!str)
+ return;
+
+ if (force_no_pager < 0) {
+ /* still unset... */
+ if (getenv (TOOL_NO_PAGER))
+ force_no_pager = 1;
+ else
+ force_no_pager = 0;
+ }
+
+ length = strlen (str);
+ if (*str && (str[length - 1] != '\n'))
+ append_nl = TRUE;
+
+ if (stream)
+ to_stream = stream;
+ else
+ to_stream = stdout;
+
+ if (!force_no_pager && isatty (fileno (to_stream))) {
+ /* use pager */
+ FILE *pipe;
+ const char *pager;
+#ifndef G_OS_WIN32
+ sighandler_t phandler;
+#endif
+ pager = getenv ("PAGER");
+ if (!pager)
+ pager = "more";
+ if (!check_shell_argument (pager)) {
+ g_warning ("Invalid PAGER value: must only contain alphanumeric characters");
+ return;
+ }
+ else
+ pipe = popen (pager, "w");
+#ifndef G_OS_WIN32
+ phandler = signal (SIGPIPE, SIG_IGN);
+#endif
+ if (append_nl)
+ g_fprintf (pipe, "%s\n", str);
+ else
+ g_fprintf (pipe, "%s", str);
+ pclose (pipe);
+#ifndef G_OS_WIN32
+ signal (SIGPIPE, phandler);
+#endif
+ }
+ else {
+ if (append_nl)
+ g_fprintf (to_stream, "%s\n", str);
+ else
+ g_fprintf (to_stream, "%s", str);
+ }
+}
+
+/*
+ * color output handling
+ */
+gchar *
+tool_output_color_string (ToolColor color, ToolOutputFormat format, const char *fmt, ...)
+{
+ va_list argv;
+ gchar *tmp, *res;
+
+ va_start (argv, fmt);
+ tmp = g_strdup_vprintf (fmt, argv);
+ va_end (argv);
+ res = g_strdup_printf ("%s%s%s", tool_output_color_s (color, format), tmp, tool_output_color_s (TOOL_COLOR_RESET, format));
+ g_free (tmp);
+ return res;
+}
+
+void
+tool_output_color_append_string (ToolColor color, ToolOutputFormat format, GString *string, const char *fmt, ...)
+{
+ va_list argv;
+ g_string_append (string, tool_output_color_s (color, format));
+ va_start (argv, fmt);
+ g_string_append_vprintf (string, fmt, argv);
+ va_end (argv);
+ g_string_append (string, tool_output_color_s (TOOL_COLOR_RESET, format));
+}
+
+void
+tool_output_color_print (ToolColor color, ToolOutputFormat format, const char *fmt, ...)
+{
+ va_list argv;
+ g_print ("%s", tool_output_color_s (color, format));
+ va_start (argv, fmt);
+ g_vprintf (fmt, argv);
+ va_end (argv);
+ g_print ("%s", tool_output_color_s (TOOL_COLOR_RESET, format));
+}
+
+const gchar *
+tool_output_color_s (ToolColor color, ToolOutputFormat format)
+{
+#ifndef G_OS_WIN32
+ if (format & TOOL_OUTPUT_FORMAT_COLOR_TERM) {
+ switch (color) {
+ case TOOL_COLOR_NORMAL:
+ return "";
+ case TOOL_COLOR_RESET:
+ return "\033[m";
+ case TOOL_COLOR_BOLD:
+ return "\033[1m";
+ case TOOL_COLOR_RED:
+ return "\033[31m";
+ default:
+ g_assert_not_reached();
+ }
+ }
+#endif
+ return "";
+}
diff --git a/tools/tools-input.h b/tools/cmdtool/tool-output.h
similarity index 56%
copy from tools/tools-input.h
copy to tools/cmdtool/tool-output.h
index 8bb3a8a..cc12486 100644
--- a/tools/tools-input.h
+++ b/tools/cmdtool/tool-output.h
@@ -20,26 +20,32 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __GDA_TOOLS_INPUT__
-#define __GDA_TOOLS_INPUT__
+#ifndef __TOOL_OUTPUT__
+#define __TOOL_OUTPUT__
#include <stdio.h>
#include <glib.h>
-typedef char **(*CompletionFunc) (const char *, int, int);
-typedef gboolean (*TreatLineFunc) (const gchar *, gpointer);
-typedef const char *(*ComputePromptFunc) (void);
+#include "tool-decl.h"
+#include "tool-command.h"
-gchar *input_from_console (const gchar *prompt);
-gchar *input_from_stream (FILE *stream);
+gchar *tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
+ FILE *stream, GdaSet *options);
+void tool_output_output_string (FILE *output_stream, const gchar *str);
-void init_input (TreatLineFunc treat_line_func, ComputePromptFunc prompt_func, gpointer data);
-void input_get_size (gint *width, gint *height);
-void end_input (void);
+/*
+ * color output handling
+ */
+typedef enum {
+ TOOL_COLOR_NORMAL,
+ TOOL_COLOR_RESET,
+ TOOL_COLOR_BOLD,
+ TOOL_COLOR_RED
+} ToolColor;
-void init_history ();
-void add_to_history (const gchar *txt);
-gboolean save_history (const gchar *file, GError **error);
-void set_completion_func (CompletionFunc func);
+void tool_output_color_print (ToolColor color, ToolOutputFormat format, const char *fmt, ...);
+gchar *tool_output_color_string (ToolColor color, ToolOutputFormat format, const char *fmt, ...);
+void tool_output_color_append_string (ToolColor color, ToolOutputFormat format, GString *string, const char *fmt, ...);
+const gchar *tool_output_color_s (ToolColor color, ToolOutputFormat format);
#endif
diff --git a/tools/tools-input.h b/tools/cmdtool/tool.h
similarity index 59%
rename from tools/tools-input.h
rename to tools/cmdtool/tool.h
index 8bb3a8a..eeb1de4 100644
--- a/tools/tools-input.h
+++ b/tools/cmdtool/tool.h
@@ -20,26 +20,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __GDA_TOOLS_INPUT__
-#define __GDA_TOOLS_INPUT__
+#ifndef __TOOL__
+#define __TOOL__
-#include <stdio.h>
-#include <glib.h>
-
-typedef char **(*CompletionFunc) (const char *, int, int);
-typedef gboolean (*TreatLineFunc) (const gchar *, gpointer);
-typedef const char *(*ComputePromptFunc) (void);
-
-gchar *input_from_console (const gchar *prompt);
-gchar *input_from_stream (FILE *stream);
-
-void init_input (TreatLineFunc treat_line_func, ComputePromptFunc prompt_func, gpointer data);
-void input_get_size (gint *width, gint *height);
-void end_input (void);
-
-void init_history ();
-void add_to_history (const gchar *txt);
-gboolean save_history (const gchar *file, GError **error);
-void set_completion_func (CompletionFunc func);
+#include <tool-command.h>
+#include <tool-errors.h>
+#include <tool-input.h>
+#include <tool-output.h>
+#include <tool-defines.h>
+#include <tool-help.h>
#endif
diff --git a/tools/command-exec.c b/tools/command-exec.c
index 5548d98..bb62506 100644
--- a/tools/command-exec.c
+++ b/tools/command-exec.c
@@ -24,12 +24,12 @@
#include <libgda/binreloc/gda-binreloc.h>
#include <glib/gi18n-lib.h>
#include <string.h>
-#include "tools-input.h"
+#include "tool-input.h"
#ifdef HAVE_HISTORY
#include <readline/history.h>
#endif
#include <sql-parser/gda-statement-struct-util.h>
-#include "tools-utils.h"
+#include "tool-utils.h"
#ifdef HAVE_LDAP
#include <virtual/gda-ldap-connection.h>
#endif
@@ -109,51 +109,6 @@ gda_internal_command_arg_remove_quotes (gchar *str)
}
/*
- * gda_internal_command_exec_result_free
- *
- * Clears the memory associated with @res
- */
-void
-gda_internal_command_exec_result_free (GdaInternalCommandResult *res)
-{
- if (!res)
- return;
- switch (res->type) {
- case GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL:
- if (res->u.model)
- g_object_unref (res->u.model);
- if (! res->was_in_transaction_before_exec &&
- res->cnc &&
- gda_connection_get_transaction_status (res->cnc))
- gda_connection_rollback_transaction (res->cnc, NULL, NULL);
-
- break;
- case GDA_INTERNAL_COMMAND_RESULT_SET:
- if (res->u.set)
- g_object_unref (res->u.set);
- break;
- case GDA_INTERNAL_COMMAND_RESULT_TXT:
- case GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT:
- if (res->u.txt)
- g_string_free (res->u.txt, TRUE);
- break;
- case GDA_INTERNAL_COMMAND_RESULT_MULTIPLE: {
- GSList *list;
-
- for (list = res->u.multiple_results; list; list = list->next)
- gda_internal_command_exec_result_free ((GdaInternalCommandResult *) list->data);
- g_slist_free (res->u.multiple_results);
- break;
- }
- default:
- break;
- }
- if (res->cnc)
- g_object_unref (res->cnc);
- g_free (res);
-}
-
-/*
* Small tokenizer
*/
#define T_ILLEGAL 1
@@ -255,500 +210,24 @@ default_gda_internal_commandargs_func (const gchar *string)
return array;
}
-/*
- * Same as append_to_string but cuts strings which are too long
- */
-static void
-append_raw_to_string (GString *string, gchar *str, gint width, gint offset)
-{
- g_assert (string);
- if (!str)
- return;
- if ((width <= 0) && (offset <= 0)) {
- g_string_append (string, str);
- return;
- }
- if (offset < 0)
- offset = 0;
-
- /* start on a fresh line */
- if ((string->str) && (string->len > 0) &&
- (string->str[string->len - 1] != '\n'))
- g_string_append_c (string, '\n');
-
- gchar *ptr;
- gboolean startofline = TRUE;
- for (ptr = str; *ptr; ) {
- gchar *next, *pnext;
- if (*ptr == '\n') {
- g_string_append_c (string, '\n');
- ptr++;
- startofline = TRUE;
- continue;
- }
- guint clen = 0;
- for (next = ptr, pnext = ptr;
- *next && (*next != '\n');
- pnext = next + 1, next = g_utf8_next_char (next), clen++) {
- if (startofline) {
- if (offset > 0) {
- gint i;
- for (i = 0; i < offset; i++)
- g_string_append_c (string, ' ');
- }
- startofline = FALSE;
- }
-
- if ((width > 0) && (clen >= width - offset)) {
- g_string_append_c (string, '\n');
- startofline = TRUE;
- for (; *next && (*next != '\n'); next++);
- if (*next == '\n')
- next++;
- break;
- }
- else {
- for (; pnext <= next; pnext++)
- g_string_append_c (string, *pnext);
- }
- }
- ptr = next;
- }
-}
-
-/*
- * parses @str, and appends to @string lines which are @width large, if @offset is >0, then
- * leave that amount of spaces. If @width <= 0, then only adds @offset spaces at the beginning of each
- * new line.
- */
-static void
-append_to_string (GString *string, gchar *str, gint width, gint offset)
-{
- g_assert (string);
- if (!str)
- return;
- if ((width <= 0) && (offset <= 0)) {
- g_string_append (string, str);
- return;
- }
- if (offset < 0)
- offset = 0;
-
- /* replace @WORD@ by <WORD> */
- gchar *ptr;
- gboolean in = FALSE;
- for (ptr = str; *ptr; ptr++) {
- if (*ptr == '@') {
- if (in) {
- *ptr = '>';
- in = FALSE;
- }
- else {
- *ptr = '<';
- in = TRUE;
- }
- }
- }
-
- /* actual work */
- gboolean firstword = TRUE;
- gint clen = 0;
- if ((string->str) && (string->len > 0) &&
- (string->str[string->len - 1] != '\n')) {
- for (ptr = string->str + (string->len -1); (ptr >= string->str) && (*ptr != '\n'); ptr --)
- clen++;
- }
- if (!strcmp (str, "> ")) {
- if (offset > 0) {
- gint i;
- for (i = 0; i < offset; i++)
- g_string_append_c (string, ' ');
- }
- g_string_append (string, str);
- return;
- }
-
- for (ptr = str; *ptr; ) {
- /* skip spaces */
- if ((*ptr == ' ') || (*ptr == '\t') || (*ptr == '\n') || (*ptr == '\r')) {
- ptr++;
- continue;
- }
-
- /* find end of next word */
- gchar *next;
- gint wlen;
- for (wlen = 0, next = ptr;
- *next && (*next != ' ') && (*next != '\t') && (*next != '\n') && (*next != '\r');
- wlen ++, next = g_utf8_next_char (next));
-
- if (wlen >= width - offset) {
- const gchar *n2;
- for (n2 = ptr; n2 < next; n2++) {
- g_string_append_c (string, *n2);
- }
- ptr = next;
- firstword = FALSE;
- g_string_append_c (string, '\n');
- clen = 0;
- continue;
- }
- else if ((width > 0) && ((wlen + clen) >= width)) {
- /* cut here */
- g_string_append_c (string, '\n');
- clen = 0;
- continue;
- }
- else {
- /* copy word */
- if (clen == 0) {
- if (offset > 0) {
- gint i;
- for (i = 0; i < offset; i++) {
- g_string_append_c (string, ' ');
- clen++;
- }
- }
- }
- else if (!firstword) {
- g_string_append_c (string, ' ');
- clen++;
- }
- const gchar *n2;
- for (n2 = ptr; n2 < next; n2++) {
- g_string_append_c (string, *n2);
- clen++;
- }
- ptr = next;
- firstword = FALSE;
- }
- }
-}
-
-static gchar *
-help_xml_doc_to_string_command (xmlDocPtr helpdoc, const gchar *command_name, gint width)
-{
- xmlNodePtr node;
- node = xmlDocGetRootElement (helpdoc);
- if (!node || !command_name || !*command_name)
- return NULL;
- for (node = node->children; node; node = node->next) {
- if (strcmp ((gchar*) node->name, "command"))
- continue;
- xmlChar *prop;
- prop = xmlGetProp (node, BAD_CAST "name");
- if (prop && !strcmp ((gchar*) prop, command_name))
- break;
- }
- if (!node)
- return NULL;
-
- /* create output string */
- GString *string;
- string = g_string_new ("");
- for (node = node->children; node; node = node->next) {
- xmlChar *data = NULL;
- if (!strcmp ((gchar*) node->name, "shortdescription")) {
- data = xmlNodeGetContent (node);
- if (data) {
- append_to_string (string, (gchar*) data, width, 0);
- g_string_append (string, "\n\n");
- }
- }
- else if (!strcmp ((gchar*) node->name, "usage") || !strcmp ((gchar*) node->name, "example")) {
- if (!strcmp ((gchar*) node->name, "usage"))
- append_to_string (string, _("Usage"), width, 0);
- else
- append_to_string (string, _("Example"), width, 0);
- g_string_append (string, ":\n");
- xmlNodePtr snode;
- for (snode = node->children; snode; snode = snode->next) {
- if (!strcmp ((gchar*) snode->name, "synopsis")) {
- data = xmlNodeGetContent (snode);
- if (data) {
- append_to_string (string, "> ", width, 3);
- append_to_string (string, (gchar*) data, width, 3);
- g_string_append_c (string, '\n');
- }
- }
- else if (!strcmp ((gchar*) snode->name, "comment")) {
- data = xmlNodeGetContent (snode);
- if (data) {
- append_to_string (string, (gchar*) data, width, 6);
- g_string_append_c (string, '\n');
- }
- }
- else if (!strcmp ((gchar*) snode->name, "raw")) {
- data = xmlNodeGetContent (snode);
- if (data) {
- append_raw_to_string (string, (gchar*) data, width, 6);
- g_string_append (string, "\n\n");
- }
- }
- if (data)
- xmlFree (data);
- data = NULL;
- }
- }
- if (data)
- xmlFree (data);
- }
-
- return g_string_free (string, FALSE);
-}
-
-static gchar *
-help_xml_doc_to_string_section (xmlDocPtr helpdoc, const gchar *section_name, gint width)
-{
- xmlNodePtr node;
- node = xmlDocGetRootElement (helpdoc);
- if (!node || !section_name || !*section_name)
- return NULL;
- for (node = node->children; node; node = node->next) {
- if (strcmp ((gchar*) node->name, "section"))
- continue;
- xmlChar *prop;
- prop = xmlGetProp (node, BAD_CAST "name");
- if (prop && strstr ((gchar*) prop, section_name))
- break;
- }
- if (!node)
- return NULL;
-
- /* create output string */
- GString *string;
- string = g_string_new ("");
- for (node = node->children; node; node = node->next) {
- xmlChar *data = NULL;
- if (!strcmp ((gchar*) node->name, "shortdescription")) {
- data = xmlNodeGetContent (node);
- if (data) {
- append_to_string (string, (gchar*) data, width, 0);
- g_string_append (string, "\n\n");
- }
- }
- else if (!strcmp ((gchar*) node->name, "usage") || !strcmp ((gchar*) node->name, "example")) {
- if (!strcmp ((gchar*) node->name, "example")) {
- append_to_string (string, _("Example"), width, 0);
- g_string_append (string, ":\n");
- }
- xmlNodePtr snode;
- for (snode = node->children; snode; snode = snode->next) {
- if (!strcmp ((gchar*) snode->name, "synopsis")) {
- data = xmlNodeGetContent (snode);
- if (data) {
- append_to_string (string, "> ", width, 3);
- append_to_string (string, (gchar*) data, width, 3);
- g_string_append_c (string, '\n');
- }
- }
- else if (!strcmp ((gchar*) snode->name, "comment")) {
- data = xmlNodeGetContent (snode);
- if (data) {
- append_to_string (string, (gchar*) data, width, 3);
- g_string_append_c (string, '\n');
- }
- }
- else if (!strcmp ((gchar*) snode->name, "raw")) {
- data = xmlNodeGetContent (snode);
- if (data) {
- append_raw_to_string (string, (gchar*) data, width, 3);
- g_string_append (string, "\n\n");
- }
- }
- if (data)
- xmlFree (data);
- data = NULL;
- }
- }
- if (data)
- xmlFree (data);
- }
-
- return g_string_free (string, FALSE);
-}
-
-xmlDocPtr
-load_help_doc (void)
-{
- xmlDocPtr helpdoc = NULL;
- const gchar * const *langs = g_get_language_names ();
- gchar *dirname, *helpfile;
- gint i;
- dirname = gda_gbr_get_file_path (GDA_DATA_DIR, "gnome", "help",
- "gda-sql", NULL);
- for (i = 0; langs[i]; i++) {
- helpfile = g_build_filename (dirname, langs[i], "gda-sql-help.xml", NULL);
- if (g_file_test (helpfile, G_FILE_TEST_EXISTS))
- helpdoc = xmlParseFile (helpfile);
- g_free (helpfile);
- if (helpdoc)
- break;
- }
-
- if (!helpdoc) {
- /* default to the "C" one */
- helpfile = g_build_filename (dirname, "C", "gda-sql-help.xml", NULL);
- if (g_file_test (helpfile, G_FILE_TEST_EXISTS))
- helpdoc = xmlParseFile (helpfile);
- g_free (helpfile);
- }
- g_free (dirname);
- return helpdoc;
-}
-
-GdaInternalCommandResult *
-gda_internal_command_help (SqlConsole *console, GdaConnection *cnc,
- const gchar **args, OutputFormat format, G_GNUC_UNUSED GError **error,
- GdaInternalCommandsList *clist)
+ToolCommandResult *
+gda_internal_command_history (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
- GSList *list;
- gchar *current_group = NULL;
- GString *string = g_string_new ("");
- xmlDocPtr helpdoc = NULL;
-#define NAMESIZE 18
-
- /* get term size */
- gint width = -1;
- if (format | OUTPUT_FORMAT_DEFAULT)
- input_get_size (&width, NULL);
-
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
-
- if (args[0] && *args[0]) {
- const gchar *command_name = NULL;
- GdaInternalCommand *command = NULL;
- command_name = args[0];
- if ((*command_name == '.') || (*command_name == '\\'))
- command_name++;
- for (list = clist->group_ordered; list; list = list->next) {
- command = (GdaInternalCommand*) list->data;
- gint clength;
- clength = strlen (command_name);
- if (!g_ascii_strncasecmp (command->name, command_name, clength) &&
- (command->name[clength] == ' '))
- break;
- command = NULL;
- }
- if (!command)
- g_string_append_printf (string, _("Command '%s' not found\n"), command_name);
- else {
- if (!helpdoc)
- helpdoc = load_help_doc ();
-
- gboolean done = FALSE;
- if (helpdoc) {
- gchar *tmp;
- tmp = help_xml_doc_to_string_command (helpdoc, command_name, width);
- if (tmp) {
- g_string_append (string, tmp);
- g_free (tmp);
- done = TRUE;
- }
- }
- if (!done) {
- append_to_string (string, command->description, width, 0);
- g_string_append_printf (string, "\n\n%s:\n ", _("Usage"));
- color_append_string (GDA_SQL_COLOR_BOLD, format, string, ".");
- color_append_string (GDA_SQL_COLOR_BOLD, format, string, command->name);
- }
- }
- }
- else {
- for (list = clist->group_ordered; list; list = list->next) {
- GdaInternalCommand *command = (GdaInternalCommand*) list->data;
- gint clen;
- if (console && command->limit_to_main)
- continue;
-
-#ifdef HAVE_LDAP
- if (g_str_has_prefix (command->name, "ldap") && cnc && !GDA_IS_LDAP_CONNECTION (cnc))
- continue;
-#endif
-
- if (!current_group || strcmp (current_group, command->group)) {
- current_group = command->group;
- if (list != clist->group_ordered)
- g_string_append_c (string, '\n');
- if (width > 0) {
- gint i, nb, remain;
- nb = (width - g_utf8_strlen (current_group, -1) - 2) / 2;
- remain = width - (2 * nb + 2 + g_utf8_strlen (current_group, -1));
- for (i = 0; i < nb; i++)
- g_string_append_c (string, '=');
- g_string_append_c (string, ' ');
- append_to_string (string, current_group, width, 0);
- g_string_append_c (string, ' ');
- for (i = 0; i < nb + remain; i++)
- g_string_append_c (string, '=');
- g_string_append_c (string, '\n');
- }
- else {
- g_string_append (string, "=== ");
- append_to_string (string, current_group, width, 0);
- g_string_append (string, " ===\n");
- }
-
- if (!helpdoc)
- helpdoc = load_help_doc ();
+ ToolCommandResult *res;
- if (helpdoc && command->group_id) {
- gchar *tmp;
- tmp = help_xml_doc_to_string_section (helpdoc, command->group_id, width);
- if (tmp) {
- g_string_append (string, tmp);
- g_free (tmp);
- g_string_append_c (string, '\n');
- }
- }
- }
-
- g_string_append (string, " ");
- color_append_string (GDA_SQL_COLOR_BOLD, format, string, ".");
- color_append_string (GDA_SQL_COLOR_BOLD, format, string, command->name);
- clen = g_utf8_strlen (command->name, -1);
- if (clen >= NAMESIZE)
- g_string_append_c (string, '\n');
- else {
- gint i, size;
- size = NAMESIZE - clen - 1;
- for (i = 0; i < size; i++)
- g_string_append_c (string, ' ');
- }
- append_to_string (string, command->description, width, NAMESIZE + 3);
- g_string_append_c (string, '\n');
- }
- }
- res->u.txt = string;
- return res;
-}
-
-GdaInternalCommandResult *
-gda_internal_command_history (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
-{
- GdaInternalCommandResult *res;
-
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
-
- if (console) {
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- TO_IMPLEMENT;
- return res;
- }
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT;
GString *string;
#ifdef HAVE_HISTORY
- if (args[0]) {
- if (!save_history (args[0], error)) {
+ if (argv[0]) {
+ if (!save_history (argv[0], error)) {
g_free (res);
res = NULL;
}
else
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
else {
HIST_ENTRY **hist_array = history_list ();
@@ -771,36 +250,37 @@ gda_internal_command_history (SqlConsole *console, G_GNUC_UNUSED GdaConnection *
return res;
}
-GdaInternalCommandResult *
-gda_internal_command_dict_sync (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+ToolCommandResult *
+gda_internal_command_dict_sync (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
- if (!cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
GdaMetaContext context;
memset (&context, 0, sizeof (context));
- if (*args[0] == '_')
- context.table_name = (gchar*) args[0];
+ if (*argv[0] == '_')
+ context.table_name = (gchar*) argv[0];
else
- context.table_name = g_strdup_printf ("_%s", args[0]);
- if (!gda_connection_update_meta_store (cnc, &context, error)) {
+ context.table_name = g_strdup_printf ("_%s", argv[0]);
+ if (!gda_connection_update_meta_store (console->current->cnc, &context, error)) {
g_free (res);
res = NULL;
}
- if (*args[0] != '_')
+ if (*argv[0] != '_')
g_free (context.table_name);
}
- else if (!gda_connection_update_meta_store (cnc, NULL, error)) {
+ else if (!gda_connection_update_meta_store (console->current->cnc, NULL, error)) {
g_free (res);
res = NULL;
}
@@ -808,20 +288,21 @@ gda_internal_command_dict_sync (G_GNUC_UNUSED SqlConsole *console, GdaConnection
return res;
}
-GdaInternalCommandResult *
-gda_internal_command_list_tables (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+ToolCommandResult *
+gda_internal_command_list_tables (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
GdaDataModel *model;
- if (!cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
GValue *v;
const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
"table_owner as Owner, table_comments as Description "
@@ -829,9 +310,10 @@ gda_internal_command_list_tables (G_GNUC_UNUSED SqlConsole *console, GdaConnecti
"table_type LIKE '%TABLE%' "
"ORDER BY table_schema, table_name";
- gchar *tmp = gda_sql_identifier_prepare_for_compare (g_strdup (args[0]));
+ gchar *tmp = gda_sql_identifier_prepare_for_compare (g_strdup (argv[0]));
g_value_take_string (v = gda_value_new (G_TYPE_STRING), tmp);
- model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error, "tname", v, NULL);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ sql, error, "tname", v, NULL);
gda_value_free (v);
}
else {
@@ -839,34 +321,36 @@ gda_internal_command_list_tables (G_GNUC_UNUSED SqlConsole *console, GdaConnecti
"table_owner as Owner, table_comments as Description "
"FROM _tables WHERE table_type LIKE '%TABLE%' "
"ORDER BY table_schema, table_name";
- model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ sql, error);
}
if (!model)
return NULL;
g_object_set_data (G_OBJECT (model), "name", _("List of tables"));
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
-GdaInternalCommandResult *
-gda_internal_command_list_views (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+ToolCommandResult *
+gda_internal_command_list_views (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
GdaDataModel *model;
- if (!cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
GValue *v;
const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
"table_owner as Owner, table_comments as Description "
@@ -874,8 +358,9 @@ gda_internal_command_list_views (G_GNUC_UNUSED SqlConsole *console, GdaConnectio
"table_type = 'VIEW' "
"ORDER BY table_schema, table_name";
- g_value_set_string (v = gda_value_new (G_TYPE_STRING), args[0]);
- model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error, "tname", v, NULL);
+ g_value_set_string (v = gda_value_new (G_TYPE_STRING), argv[0]);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ sql, error, "tname", v, NULL);
gda_value_free (v);
}
else {
@@ -883,64 +368,68 @@ gda_internal_command_list_views (G_GNUC_UNUSED SqlConsole *console, GdaConnectio
"table_owner as Owner, table_comments as Description "
"FROM _tables WHERE table_type='VIEW' "
"ORDER BY table_schema, table_name";
- model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ sql, error);
}
if (!model)
return NULL;
g_object_set_data (G_OBJECT (model), "name", _("List of views"));
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
-GdaInternalCommandResult *
-gda_internal_command_list_schemas (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+ToolCommandResult *
+gda_internal_command_list_schemas (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
GdaDataModel *model;
- if (!cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
GValue *v;
const gchar *sql = "SELECT schema_name AS Schema, schema_owner AS Owner, "
"CASE WHEN schema_internal THEN 'yes' ELSE 'no' END AS Internal "
"FROM _schemata WHERE schema_name=##sname::string "
"ORDER BY schema_name";
- g_value_set_string (v = gda_value_new (G_TYPE_STRING), args[0]);
- model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error, "sname", v, NULL);
+ g_value_set_string (v = gda_value_new (G_TYPE_STRING), argv[0]);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ sql, error, "sname", v, NULL);
gda_value_free (v);
}
else {
const gchar *sql = "SELECT schema_name AS Schema, schema_owner AS Owner, "
"CASE WHEN schema_internal THEN 'yes' ELSE 'no' END AS Internal "
"FROM _schemata ORDER BY schema_name";
- model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ sql, error);
}
if (!model)
return NULL;
g_object_set_data (G_OBJECT (model), "name", _("List of schemas"));
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
GdaMetaStruct *
-gda_internal_command_build_meta_struct (GdaConnection *cnc, const gchar **args, GError **error)
+gda_internal_command_build_meta_struct (GdaConnection *cnc, const gchar **argv, GError **error)
{
GdaMetaStruct *mstruct;
gint index;
@@ -951,7 +440,7 @@ gda_internal_command_build_meta_struct (GdaConnection *cnc, const gchar **args,
store = gda_connection_get_meta_store (cnc);
mstruct = gda_meta_struct_new (store, GDA_META_STRUCT_FEATURE_ALL);
- if (!args[0]) {
+ if (!argv[0]) {
GSList *list;
/* use all tables or views visible by default */
if (!gda_meta_struct_complement_default (mstruct, error))
@@ -966,7 +455,7 @@ gda_internal_command_build_meta_struct (GdaConnection *cnc, const gchar **args,
g_slist_free (list);
}
- for (index = 0, arg = args[0]; arg; index++, arg = args[index]) {
+ for (index = 0, arg = argv[0]; arg; index++, arg = argv[index]) {
GValue *v;
g_value_set_string (v = gda_value_new (G_TYPE_STRING), arg);
@@ -1003,7 +492,7 @@ 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, TOOLS_ERROR, TOOLS_OBJECT_NOT_FOUND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_OBJECT_NOT_FOUND_ERROR,
"%s", _("No object found"));
goto onerror;
}
@@ -1031,26 +520,28 @@ meta_table_column_foreach_attribute_func (const gchar *att_name, const GValue *v
}
}
-GdaInternalCommandResult *
-gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+ToolCommandResult *
+gda_internal_command_detail (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
GdaDataModel *model;
- if (!cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
- if (!args[0] || !*args[0]) {
+ if (!argv[0] || !*argv[0]) {
/* FIXME: include indexes and sequences when they are present in the information schema */
/* displays all tables, views, indexes and sequences which are "directly visible" */
const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
"table_owner as Owner FROM _tables WHERE table_short_name = table_name "
"ORDER BY table_schema, table_name";
- model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error, NULL);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ sql, error, NULL);
if (model) {
/* if no row, then return all the objects from all the schemas */
@@ -1059,22 +550,23 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
"table_owner as Owner FROM _tables "
"ORDER BY table_schema, table_name";
- model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error, NULL);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ sql, error, NULL);
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
}
else {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
return res;
}
GdaMetaStruct *mstruct;
GSList *dbo_list, *tmplist;
- mstruct = gda_internal_command_build_meta_struct (cnc, args, error);
+ mstruct = gda_internal_command_build_meta_struct (console->current->cnc, argv, error);
if (!mstruct)
return NULL;
@@ -1129,14 +621,14 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
g_list_foreach (values, (GFunc) gda_value_free, NULL);
g_list_free (values);
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
g_slist_free (tmplist);
return res;
}
else if (nb_objects == 0) {
- g_set_error (error, TOOLS_ERROR, TOOLS_OBJECT_NOT_FOUND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_OBJECT_NOT_FOUND_ERROR,
"%s", _("No object found"));
g_slist_free (tmplist);
return NULL;
@@ -1145,8 +637,8 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
/*
* Information about a single object
*/
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_MULTIPLE;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_MULTIPLE;
res->u.multiple_results = NULL;
GdaMetaDbObject *dbo;
@@ -1161,7 +653,7 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
g_slist_free (tmplist);
if ((dbo->obj_type == GDA_META_DB_VIEW) || (dbo->obj_type == GDA_META_DB_TABLE)) {
- GdaInternalCommandResult *subres;
+ ToolCommandResult *subres;
GdaMetaTable *mt = GDA_META_TABLE (dbo);
if (mt->columns) {
@@ -1210,14 +702,14 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
g_list_free (values);
}
- subres = g_new0 (GdaInternalCommandResult, 1);
- subres->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = TOOL_COMMAND_RESULT_DATA_MODEL;
subres->u.model = model;
res->u.multiple_results = g_slist_append (res->u.multiple_results, subres);
}
else {
- subres = g_new0 (GdaInternalCommandResult, 1);
- subres->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = TOOL_COMMAND_RESULT_TXT;
subres->u.txt = g_string_new ("");
if (dbo->obj_type == GDA_META_DB_VIEW)
g_string_append_printf (subres->u.txt,
@@ -1235,8 +727,8 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
/* VIEW specific */
GdaMetaView *mv = GDA_META_VIEW (dbo);
- subres = g_new0 (GdaInternalCommandResult, 1);
- subres->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = TOOL_COMMAND_RESULT_TXT;
subres->u.txt = g_string_new ("");
g_string_append_printf (subres->u.txt, _("View definition: %s"), mv->view_def);
res->u.multiple_results = g_slist_append (res->u.multiple_results, subres);
@@ -1254,7 +746,8 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
g_value_set_string ((catalog = gda_value_new (G_TYPE_STRING)), dbo->obj_catalog);
g_value_set_string ((schema = gda_value_new (G_TYPE_STRING)), dbo->obj_schema);
g_value_set_string ((name = gda_value_new (G_TYPE_STRING)), dbo->obj_name);
- model = gda_meta_store_extract (gda_connection_get_meta_store (cnc), sql, error,
+ model = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ sql, error,
"tc", catalog, "ts", schema, "tname", name, NULL);
nrows = gda_data_model_get_n_rows (model);
for (i = 0; i < nrows; i++) {
@@ -1264,7 +757,7 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
cvalue = gda_data_model_get_value_at (model, 0, i, error);
if (!cvalue) {
- gda_internal_command_exec_result_free (res);
+ tool_command_result_free (res);
res = NULL;
goto out;
}
@@ -1274,7 +767,7 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
GdaDataModel *cols;
cvalue = gda_data_model_get_value_at (model, 1, i, error);
if (!cvalue) {
- gda_internal_command_exec_result_free (res);
+ tool_command_result_free (res);
res = NULL;
goto out;
}
@@ -1286,7 +779,8 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
"constraint_name = ##cname::string "
"ORDER BY ordinal_position";
- cols = gda_meta_store_extract (gda_connection_get_meta_store (cnc), str, error,
+ cols = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ str, error,
"tc", catalog, "ts", schema, "tname", name, "cname", cvalue,
NULL);
if (cols) {
@@ -1299,7 +793,7 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
g_string_append (string, ", ");
cvalue = gda_data_model_get_value_at (cols, 0, j, error);
if (!cvalue) {
- gda_internal_command_exec_result_free (res);
+ tool_command_result_free (res);
res = NULL;
g_object_unref (cols);
g_string_free (string, TRUE);
@@ -1320,7 +814,7 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
GdaDataModel *cols;
cvalue = gda_data_model_get_value_at (model, 1, i, error);
if (!cvalue) {
- gda_internal_command_exec_result_free (res);
+ tool_command_result_free (res);
res = NULL;
goto out;
}
@@ -1332,7 +826,8 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
"constraint_name = ##cname::string "
"ORDER BY ordinal_position";
- cols = gda_meta_store_extract (gda_connection_get_meta_store (cnc), str, error,
+ cols = gda_meta_store_extract (gda_connection_get_meta_store (console->current->cnc),
+ str, error,
"tc", catalog, "ts", schema, "tname", name, "cname", cvalue,
NULL);
if (cols) {
@@ -1345,7 +840,7 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
g_string_append (string, ", ");
cvalue = gda_data_model_get_value_at (cols, 0, j, error);
if (!cvalue) {
- gda_internal_command_exec_result_free (res);
+ tool_command_result_free (res);
res = NULL;
g_object_unref (cols);
g_string_free (string, TRUE);
@@ -1360,8 +855,8 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
}
if (string) {
- subres = g_new0 (GdaInternalCommandResult, 1);
- subres->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = TOOL_COMMAND_RESULT_TXT;
subres->u.txt = string;
res->u.multiple_results = g_slist_append (res->u.multiple_results, subres);
}
@@ -1415,14 +910,14 @@ gda_internal_command_detail (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
g_string_append (string, "\n ");
g_string_append (string, _("Policy on UPDATE"));
g_string_append (string, ": ");
- g_string_append (string, tools_utils_fk_policy_to_string (GDA_META_TABLE_FOREIGN_KEY_ON_UPDATE_POLICY (fk)));
+ g_string_append (string, gda_tools_utils_fk_policy_to_string (GDA_META_TABLE_FOREIGN_KEY_ON_UPDATE_POLICY (fk)));
g_string_append (string, "\n ");
g_string_append (string, _("Policy on DELETE"));
g_string_append (string, ": ");
- g_string_append (string, tools_utils_fk_policy_to_string (GDA_META_TABLE_FOREIGN_KEY_ON_DELETE_POLICY (fk)));
+ g_string_append (string, gda_tools_utils_fk_policy_to_string (GDA_META_TABLE_FOREIGN_KEY_ON_DELETE_POLICY (fk)));
- subres = g_new0 (GdaInternalCommandResult, 1);
- subres->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = TOOL_COMMAND_RESULT_TXT;
subres->u.txt = string;
res->u.multiple_results = g_slist_append (res->u.multiple_results,
subres);
diff --git a/tools/command-exec.h b/tools/command-exec.h
index b80f7f3..a9a645e 100644
--- a/tools/command-exec.h
+++ b/tools/command-exec.h
@@ -23,85 +23,27 @@
#include <glib.h>
#include <libgda/libgda.h>
#include "gda-sql.h"
-
-/*
- * Command exec result
- */
-typedef enum {
- GDA_INTERNAL_COMMAND_RESULT_EMPTY,
- GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL,
- GDA_INTERNAL_COMMAND_RESULT_SET,
- GDA_INTERNAL_COMMAND_RESULT_TXT,
- GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT,
- GDA_INTERNAL_COMMAND_RESULT_MULTIPLE,
- GDA_INTERNAL_COMMAND_RESULT_EXIT
-} GdaInternalCommandResultType;
-
-typedef struct {
- GdaInternalCommandResultType type;
- GdaConnection *cnc;
- gboolean was_in_transaction_before_exec;
- union {
- GdaDataModel *model;
- GdaSet *set;
- GString *txt;
- GSList *multiple_results; /* for GDA_INTERNAL_COMMAND_RESULT_MULTIPLE */
- } u;
-} GdaInternalCommandResult;
+#include "cmdtool/tool.h"
/*
* Command definition
*/
-typedef GdaInternalCommandResult *(*GdaInternalCommandFunc) (SqlConsole *, GdaConnection *cnc,
- const gchar **, OutputFormat, GError **, gpointer);
-typedef gchar **(*GdaInternalCommandArgsFunc) (const gchar *);
-typedef struct {
- gchar *name;
- gboolean optional;
-} GdaInternalCommandArgument;
-
-typedef struct {
- gchar *group;
- gchar *group_id; /* to be found in the help file */
- gchar *name; /* without the '\' or '.' */
- gchar *description;
- GSList *args; /* list of GdaInternalCommandArgument structures */
- GdaInternalCommandFunc command_func;
- gpointer user_data;
- GdaInternalCommandArgsFunc arguments_delimiter_func;
- gboolean unquote_args;
- gboolean limit_to_main;
-} GdaInternalCommand;
-
-typedef struct {
- GSList *commands;
-
- /* internal usage */
- GSList *name_ordered;
- GSList *group_ordered;
-} GdaInternalCommandsList;
-
-gchar *gda_internal_command_arg_remove_quotes (gchar *str);
-
-/* Commands execution */
-gchar **default_gda_internal_commandargs_func (const gchar *string);
-void gda_internal_command_exec_result_free (GdaInternalCommandResult *res);
+typedef ToolCommandResult *(*GdaInternalCommandFunc) (SqlConsole *, GdaConnection *cnc,
+ const gchar **, ToolOutputFormat, GError **, gpointer);
/* Available commands */
-GdaInternalCommandResult *gda_internal_command_help (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- OutputFormat format, GError **error, GdaInternalCommandsList *clist);
-GdaInternalCommandResult *gda_internal_command_history (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-GdaInternalCommandResult *gda_internal_command_dict_sync (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-GdaInternalCommandResult *gda_internal_command_list_tables (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-GdaInternalCommandResult *gda_internal_command_list_views (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-GdaInternalCommandResult *gda_internal_command_list_schemas (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-GdaInternalCommandResult *gda_internal_command_detail (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- OutputFormat format, GError **error, gpointer data);
+ToolCommandResult *gda_internal_command_history (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+ToolCommandResult *gda_internal_command_dict_sync (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+ToolCommandResult *gda_internal_command_list_tables (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+ToolCommandResult *gda_internal_command_list_views (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+ToolCommandResult *gda_internal_command_list_schemas (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+ToolCommandResult *gda_internal_command_detail (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
/* Misc */
GdaMetaStruct *gda_internal_command_build_meta_struct (GdaConnection *cnc, const gchar **args, GError **error);
diff --git a/tools/config-info.c b/tools/config-info.c
index 2aa24d1..5e7e14f 100644
--- a/tools/config-info.c
+++ b/tools/config-info.c
@@ -17,7 +17,7 @@
*/
#include "config-info.h"
-#include "tools-utils.h"
+#include "tool-utils.h"
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
@@ -105,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, TOOLS_ERROR, TOOLS_PROVIDER_NOT_FOUND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_PROVIDER_NOT_FOUND_ERROR,
_("Could not find provider '%s'"), provider);
return NULL;
}
@@ -274,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, TOOLS_ERROR, TOOLS_DSN_NOT_FOUND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_DSN_NOT_FOUND_ERROR,
_("Could not find data source '%s'"), dsn);
return NULL;
}
@@ -551,7 +551,7 @@ config_info_purge_data_files (const gchar *criteria, GError **error)
}
g_strfreev (array);
if (cri == PURGE_UNKNOWN) {
- g_set_error (error, TOOLS_ERROR, TOOLS_PURGE_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_PURGE_ERROR,
_("Unknown criteria '%s'"), criteria);
return NULL;
}
@@ -631,7 +631,7 @@ config_info_purge_data_files (const gchar *criteria, GError **error)
g_dir_close (dir);
if (errstring) {
- g_set_error (error, TOOLS_ERROR, TOOLS_PURGE_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_PURGE_ERROR,
"%s", errstring->str);
g_string_free (errstring, TRUE);
}
diff --git a/tools/gda-sql.c b/tools/gda-sql.c
index 6df4d8f..b2c84a7 100644
--- a/tools/gda-sql.c
+++ b/tools/gda-sql.c
@@ -21,8 +21,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+#include "tool.h"
+#include "tool-utils.h"
#include "gda-sql.h"
-#include "tools-utils.h"
#include <virtual/libgda-virtual.h>
#include <glib/gi18n-lib.h>
#include <glib/gprintf.h>
@@ -31,7 +32,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <glib/gstdio.h>
-#include "tools-input.h"
+#include "tool-input.h"
+#include "tool-output.h"
#include "config-info.h"
#include "command-exec.h"
#include <unistd.h>
@@ -113,16 +115,15 @@ typedef enum {
} SigintHandlerCode;
static SigintHandlerCode sigint_handler_status = SIGINT_HANDLER_DISABLED;
+
/* structure to hold program's data */
typedef struct {
+ SqlConsole *term_console;
GSList *settings; /* list all the ConnectionSetting */
- ConnectionSetting *current; /* current connection setting to which commands are sent */
- GdaInternalCommandsList *internal_commands;
+ ToolCommandGroup *limit_commands;
+ ToolCommandGroup *all_commands;
FILE *input_stream;
- FILE *output_stream;
- gboolean output_is_pipe;
- OutputFormat output_format;
GString *partial_command;
@@ -142,8 +143,9 @@ GMainLoop *main_loop = NULL;
gboolean exit_requested = FALSE;
static ConnectionSetting *get_current_connection_settings (SqlConsole *console);
-static char **completion_func (const char *text, int start, int end);
-static void compute_prompt (SqlConsole *console, GString *string, gboolean in_command, OutputFormat format);
+static char **completion_func (const char *text, const gchar *line, int start, int end);
+static void compute_prompt (SqlConsole *console, GString *string, gboolean in_command,
+ gboolean for_readline, ToolOutputFormat format);
static gboolean set_output_file (const gchar *file, GError **error);
static gboolean set_input_file (const gchar *file, GError **error);
static gchar *data_model_to_string (SqlConsole *console, GdaDataModel *model);
@@ -161,14 +163,13 @@ static void compute_term_color_attribute (void);
/* commands manipulation */
-static GdaInternalCommandsList *build_internal_commands_list (void);
-static gboolean command_is_complete (const gchar *command);
-static GdaInternalCommandResult *command_execute (SqlConsole *console,
- const gchar *command,
- GdaStatementModelUsage usage, GError **error);
+static void build_commands (MainData *md);
+static gboolean command_is_complete (const gchar *command);
+static ToolCommandResult *command_execute (SqlConsole *console,
+ const gchar *command,
+ GdaStatementModelUsage usage, GError **error);
-static gchar *result_to_string (SqlConsole *console, GdaInternalCommandResult *res, OutputFormat format);
-static void display_result (GdaInternalCommandResult *res);
+static void display_result (ToolCommandResult *res);
int
main (int argc, char *argv[])
@@ -202,7 +203,6 @@ main (int argc, char *argv[])
has_threads = g_thread_supported ();
data = g_new0 (MainData, 1);
- data->output_format = OUTPUT_FORMAT_DEFAULT;
data->options = gda_set_new_inline (3,
"csv_names_on_first_line", G_TYPE_BOOLEAN, FALSE,
"csv_quote", G_TYPE_STRING, "\"",
@@ -248,6 +248,10 @@ main (int argc, char *argv[])
data->mem_data_models = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
main_data = data;
+ /* build internal command s list */
+ build_commands (data);
+ data->term_console = gda_sql_console_new ("TERM");
+ data->term_console->command_group = main_data->all_commands;
compute_term_color_attribute ();
/* output file */
@@ -333,7 +337,7 @@ main (int argc, char *argv[])
}
/* welcome message */
- if (show_welcome && !data->output_stream) {
+ if (show_welcome && !data->term_console->output_stream) {
#ifdef G_OS_WIN32
HANDLE wHnd;
SMALL_RECT windowSize = {0, 0, 139, 49};
@@ -344,18 +348,17 @@ main (int argc, char *argv[])
SetConsoleWindowInfo (wHnd, TRUE, &windowSize);
#endif
gchar *c1, *c2, *c3, *c4;
- color_print (GDA_SQL_COLOR_BOLD, main_data->output_format,
+ tool_output_color_print (TOOL_COLOR_BOLD, main_data->term_console->output_format,
_("Welcome to the GDA SQL console, version " PACKAGE_VERSION));
g_print ("\n\n");
- c1 = color_string (GDA_SQL_COLOR_BOLD, main_data->output_format, ".copyright");
- c2 = color_string (GDA_SQL_COLOR_BOLD, main_data->output_format, ".?");
- c3 = color_string (GDA_SQL_COLOR_BOLD, main_data->output_format, ".h");
- c4 = color_string (GDA_SQL_COLOR_BOLD, main_data->output_format, ".q");
+ c1 = tool_output_color_string (TOOL_COLOR_BOLD, main_data->term_console->output_format, ".copyright");
+ c2 = tool_output_color_string (TOOL_COLOR_BOLD, main_data->term_console->output_format, ".?");
+ c3 = tool_output_color_string (TOOL_COLOR_BOLD, main_data->term_console->output_format, ".help");
+ c4 = tool_output_color_string (TOOL_COLOR_BOLD, main_data->term_console->output_format, ".q");
g_print (_("Type: %s to show usage and distribution terms\n"
" %s or %s for help with internal commands\n"
- " %s (or CTRL-D) to quit\n"
- " (the '.' can be replaced by a '\\')\n"
- " or any query terminated by a semicolon\n\n"), c1, c2, c3, c4);
+ " %s (or CTRL-D) to quit (the '.' can be replaced by a '\\')\n"
+ " or any SQL query terminated by a semicolon\n\n"), c1, c2, c3, c4);
g_free (c1);
g_free (c2);
g_free (c3);
@@ -404,9 +407,9 @@ main (int argc, char *argv[])
str = g_strdup (info->name);
else
str = g_strdup_printf ("c%d", i-1);
- if (!data->output_stream)
+ if (!data->term_console->output_stream)
g_print (_("Opening connection '%s' for: %s\n"), str, argv[i]);
- cs = open_connection (NULL, str, argv[i], &error);
+ cs = open_connection (data->term_console, str, argv[i], &error);
config_info_modify_argv (argv[i]);
g_free (str);
if (!cs) {
@@ -422,10 +425,10 @@ main (int argc, char *argv[])
gchar *str;
const gchar *envstr = getenv ("GDA_SQL_CNC");
str = g_strdup_printf ("c%d", i-1);
- if (!data->output_stream)
+ if (!data->term_console->output_stream)
g_print (_("Opening connection '%s' for: %s (GDA_SQL_CNC environment variable)\n"),
- str, envstr);
- cs = open_connection (NULL, str, envstr, &error);
+ str, envstr);
+ cs = open_connection (data->term_console, str, envstr, &error);
g_free (str);
if (!cs) {
g_print (_("Can't open connection defined by GDA_SQL_CNC: %s\n"),
@@ -435,9 +438,6 @@ main (int argc, char *argv[])
}
}
- /* build internal command s list */
- data->internal_commands = build_internal_commands_list ();
-
#ifdef HAVE_LIBSOUP
/* start HTTP server if requested */
if (http_port > 0) {
@@ -453,7 +453,7 @@ main (int argc, char *argv[])
/* process commands which need to be executed as specified by the command line args */
if (single_command) {
treat_line_func (single_command, NULL);
- if (!data->output_stream)
+ if (!data->term_console->output_stream)
g_print ("\n");
goto cleanup;
}
@@ -475,7 +475,7 @@ main (int argc, char *argv[])
if (interactive && !cmde && isatty (fileno (stdin)))
set_input_file (NULL, NULL);
else {
- if (!data->output_stream)
+ if (!data->term_console->output_stream)
g_print ("\n");
goto cleanup;
}
@@ -487,15 +487,13 @@ main (int argc, char *argv[])
/* set up interactive commands */
setup_sigint_handler ();
init_input ((TreatLineFunc) treat_line_func, prompt_func, NULL);
- set_completion_func (completion_func);
- init_history ();
+ tool_input_set_completion_func (data->term_console->command_group, completion_func, ".\\");
/* run main loop */
main_loop = g_main_loop_new (NULL, TRUE);
g_main_loop_run (main_loop);
g_main_loop_unref (main_loop);
-
cleanup:
/* cleanups */
g_slist_foreach (data->settings, (GFunc) connection_settings_free, NULL);
@@ -512,13 +510,13 @@ static void
compute_term_color_attribute (void)
{
g_assert (main_data);
- main_data->output_format &= ~(OUTPUT_FORMAT_COLOR_TERM);
- if (!main_data->output_stream || isatty (fileno (main_data->output_stream))) {
+ main_data->term_console->output_format &= ~(TOOL_OUTPUT_FORMAT_COLOR_TERM);
+ if (!main_data->term_console->output_stream || isatty (fileno (main_data->term_console->output_stream))) {
const gchar *term;
- main_data->output_format |= OUTPUT_FORMAT_COLOR_TERM;
+ main_data->term_console->output_format |= TOOL_OUTPUT_FORMAT_COLOR_TERM;
term = g_getenv ("TERM");
if (term && !strcmp (term, "dumb"))
- main_data->output_format ^= OUTPUT_FORMAT_COLOR_TERM;
+ main_data->term_console->output_format ^= TOOL_OUTPUT_FORMAT_COLOR_TERM;
}
}
@@ -526,8 +524,9 @@ static const char *
prompt_func (void)
{
/* compute a new prompt */
- compute_prompt (NULL, prompt, main_data->partial_command == NULL ? FALSE : TRUE,
- OUTPUT_FORMAT_DEFAULT | (main_data->output_format & OUTPUT_FORMAT_COLOR_TERM));
+ compute_prompt (NULL, prompt, main_data->partial_command == NULL ? FALSE : TRUE, TRUE,
+ TOOL_OUTPUT_FORMAT_DEFAULT |
+ (main_data->term_console->output_format & TOOL_OUTPUT_FORMAT_COLOR_TERM));
return (char*) prompt->str;
}
@@ -542,8 +541,9 @@ treat_line_func (const gchar *cmde, gboolean *out_cmde_exec_ok)
if (!cmde) {
save_history (NULL, NULL);
- if (!main_data->output_stream)
+ if (!main_data->term_console->output_stream)
g_print ("\n");
+ exit_requested = TRUE;
goto exit;
}
@@ -562,23 +562,24 @@ treat_line_func (const gchar *cmde, gboolean *out_cmde_exec_ok)
}
if (command_is_complete (main_data->partial_command->str)) {
/* execute command */
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
FILE *to_stream;
GError *error = NULL;
if ((*main_data->partial_command->str != '\\') && (*main_data->partial_command->str != '.')) {
- if (main_data->current) {
- if (!main_data->current->query_buffer)
- main_data->current->query_buffer = g_string_new ("");
- g_string_assign (main_data->current->query_buffer, main_data->partial_command->str);
+ if (main_data->term_console->current) {
+ if (!main_data->term_console->current->query_buffer)
+ main_data->term_console->current->query_buffer = g_string_new ("");
+ g_string_assign (main_data->term_console->current->query_buffer,
+ main_data->partial_command->str);
}
}
- if (main_data && main_data->output_stream)
- to_stream = main_data->output_stream;
+ if (main_data->term_console->output_stream)
+ to_stream = main_data->term_console->output_stream;
else
to_stream = stdout;
- res = command_execute (NULL, main_data->partial_command->str,
+ res = command_execute (main_data->term_console, main_data->partial_command->str,
GDA_STATEMENT_MODEL_RANDOM_ACCESS, &error);
if (!res) {
@@ -586,8 +587,8 @@ treat_line_func (const gchar *cmde, gboolean *out_cmde_exec_ok)
(error->domain != GDA_SQL_PARSER_ERROR) ||
(error->code != GDA_SQL_PARSER_EMPTY_SQL_ERROR)) {
g_fprintf (to_stream, "%sERROR:%s ",
- color_s (GDA_SQL_COLOR_RED, main_data->output_format),
- color_s (GDA_SQL_COLOR_RESET, main_data->output_format));
+ tool_output_color_s (TOOL_COLOR_RED, main_data->term_console->output_format),
+ tool_output_color_s (TOOL_COLOR_RESET, main_data->term_console->output_format));
g_fprintf (to_stream,
"%s\n",
error && error->message ? error->message : _("No detail"));
@@ -601,12 +602,12 @@ treat_line_func (const gchar *cmde, gboolean *out_cmde_exec_ok)
}
else {
display_result (res);
- if (res->type == GDA_INTERNAL_COMMAND_RESULT_EXIT) {
- gda_internal_command_exec_result_free (res);
+ if (res->type == TOOL_COMMAND_RESULT_EXIT) {
+ tool_command_result_free (res);
exit_requested = TRUE;
goto exit;
}
- gda_internal_command_exec_result_free (res);
+ tool_command_result_free (res);
}
g_string_free (main_data->partial_command, TRUE);
main_data->partial_command = NULL;
@@ -626,251 +627,36 @@ treat_line_func (const gchar *cmde, gboolean *out_cmde_exec_ok)
}
static void
-display_result (GdaInternalCommandResult *res)
+display_result (ToolCommandResult *res)
{
switch (res->type) {
- case GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT:
+ case TOOL_COMMAND_RESULT_TXT_STDOUT:
g_print ("%s", res->u.txt->str);
if (res->u.txt->str [strlen (res->u.txt->str) - 1] != '\n')
g_print ("\n");
fflush (NULL);
break;
- case GDA_INTERNAL_COMMAND_RESULT_EMPTY:
+ case TOOL_COMMAND_RESULT_EMPTY:
break;
- case GDA_INTERNAL_COMMAND_RESULT_MULTIPLE: {
+ case TOOL_COMMAND_RESULT_MULTIPLE: {
GSList *list;
for (list = res->u.multiple_results; list; list = list->next)
- display_result ((GdaInternalCommandResult *) list->data);
+ display_result ((ToolCommandResult *) list->data);
break;
}
- case GDA_INTERNAL_COMMAND_RESULT_EXIT:
+ case TOOL_COMMAND_RESULT_EXIT:
break;
default: {
gchar *str;
- str = result_to_string (NULL, res, main_data->output_format);
+ str = tool_output_result_to_string (res, main_data->term_console->output_format,
+ main_data->term_console->output_stream,
+ main_data->options);
output_string (str);
g_free (str);
}
}
}
-static gchar *
-result_to_string (SqlConsole *console, GdaInternalCommandResult *res, OutputFormat format)
-{
- OutputFormat of;
- if (console)
- of = console->output_format;
- else
- of = main_data->output_format;
-
- switch (res->type) {
- case GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL:
- return data_model_to_string (console, res->u.model);
-
- case GDA_INTERNAL_COMMAND_RESULT_SET: {
- GSList *list;
- GString *string;
- xmlNodePtr node;
- xmlBufferPtr buffer;
- gchar *str;
-
- if (of & OUTPUT_FORMAT_DEFAULT) {
- string = g_string_new ("");
- for (list = res->u.set->holders; list; list = list->next) {
- const GValue *value;
- gchar *tmp;
- const gchar *cstr;
- GdaHolder *h;
- h = GDA_HOLDER (list->data);
-
- cstr = gda_holder_get_id (h);
- value = gda_holder_get_value (h);
- if (!strcmp (cstr, "IMPACTED_ROWS")) {
- g_string_append_printf (string, "%s: ",
- _("Number of rows impacted"));
- tmp = gda_value_stringify (value);
- g_string_append_printf (string, "%s", tmp);
- g_free (tmp);
- }
- else if (!strcmp (cstr, "EXEC_DELAY")) {
- g_string_append_printf (string, "%s: ",
- _("Execution delay"));
- gdouble etime;
- etime = g_value_get_double (value);
- g_string_append_printf (string, "%.03f s", etime);
- }
- else {
- tmp = g_markup_escape_text (cstr, -1);
- g_string_append_printf (string, "%s: ", tmp);
- g_free (tmp);
-
- tmp = gda_value_stringify (value);
- g_string_append_printf (string, "%s", tmp);
- g_free (tmp);
- }
- g_string_append (string, "\n");
- }
- str = string->str;
- g_string_free (string, FALSE);
- return str;
- }
- else if (of & OUTPUT_FORMAT_XML) {
- buffer = xmlBufferCreate ();
- node = xmlNewNode (NULL, BAD_CAST "parameters");
- for (list = res->u.set->holders; list; list = list->next) {
- const GValue *value;
- xmlNodePtr pnode, vnode;
-
- pnode = xmlNewNode (NULL, BAD_CAST "parameter");
- xmlAddChild (node, pnode);
- xmlSetProp (pnode, BAD_CAST "name",
- BAD_CAST gda_holder_get_id (GDA_HOLDER (list->data)));
- value = gda_holder_get_value (GDA_HOLDER (list->data));
- vnode = gda_value_to_xml (value);
- xmlAddChild (pnode, vnode);
- }
- xmlNodeDump (buffer, NULL, node, 0, 1);
- str = g_strdup ((gchar *) xmlBufferContent (buffer));
- xmlBufferFree (buffer);
- xmlFreeNode (node);
- return str;
- }
- else if (of & OUTPUT_FORMAT_HTML) {
- buffer = xmlBufferCreate ();
- node = xmlNewNode (NULL, BAD_CAST "ul");
- for (list = res->u.set->holders; list; list = list->next) {
- const GValue *value;
- xmlNodePtr pnode, vnode;
-
- pnode = xmlNewNode (NULL, BAD_CAST "li");
- xmlAddChild (node, pnode);
- xmlSetProp (pnode, BAD_CAST "name",
- BAD_CAST gda_holder_get_id (GDA_HOLDER (list->data)));
- value = gda_holder_get_value (GDA_HOLDER (list->data));
- vnode = gda_value_to_xml (value);
- xmlAddChild (pnode, vnode);
- }
- xmlNodeDump (buffer, NULL, node, 0, 1);
- str = g_strdup ((gchar *) xmlBufferContent (buffer));
- xmlBufferFree (buffer);
- xmlFreeNode (node);
- return str;
- }
- else if (of & OUTPUT_FORMAT_CSV) {
- string = g_string_new ("");
- for (list = res->u.set->holders; list; list = list->next) {
- const GValue *value;
- gchar *tmp;
- const gchar *cstr;
- GdaHolder *h;
- h = GDA_HOLDER (list->data);
-
- cstr = gda_holder_get_id (h);
- value = gda_holder_get_value (h);
- if (!strcmp (cstr, "IMPACTED_ROWS")) {
- g_string_append_printf (string, "\"%s\",",
- _("Number of rows impacted"));
- tmp = gda_value_stringify (value);
- g_string_append_printf (string, "\"%s\"", tmp);
- g_free (tmp);
- }
- else if (!strcmp (cstr, "EXEC_DELAY")) {
- g_string_append_printf (string, "\"%s\",",
- _("Execution delay"));
- gdouble etime;
- etime = g_value_get_double (value);
- g_string_append_printf (string, "\"%.03f s\"", etime);
- }
- else {
- tmp = g_markup_escape_text (cstr, -1);
- g_string_append_printf (string, "\"%s\",", tmp);
- g_free (tmp);
-
- tmp = gda_value_stringify (value);
- g_string_append_printf (string, "\"%s\"", tmp);
- g_free (tmp);
- }
- g_string_append (string, "\n");
- }
- str = string->str;
- g_string_free (string, FALSE);
- return str;
- }
- else {
- TO_IMPLEMENT;
- return NULL;
- }
- }
-
- case GDA_INTERNAL_COMMAND_RESULT_TXT: {
- xmlNodePtr node;
- xmlBufferPtr buffer;
- gchar *str;
-
- if ((of & OUTPUT_FORMAT_DEFAULT) ||
- (of & OUTPUT_FORMAT_CSV))
- return g_strdup (res->u.txt->str);
- else if (of & OUTPUT_FORMAT_XML) {
- buffer = xmlBufferCreate ();
- node = xmlNewNode (NULL, BAD_CAST "txt");
- xmlNodeSetContent (node, BAD_CAST res->u.txt->str);
- xmlNodeDump (buffer, NULL, node, 0, 1);
- str = g_strdup ((gchar *) xmlBufferContent (buffer));
- xmlBufferFree (buffer);
- xmlFreeNode (node);
- return str;
- }
- else if (of & OUTPUT_FORMAT_HTML) {
- buffer = xmlBufferCreate ();
- node = xmlNewNode (NULL, BAD_CAST "p");
- xmlNodeSetContent (node, BAD_CAST res->u.txt->str);
- xmlNodeDump (buffer, NULL, node, 0, 1);
- str = g_strdup ((gchar *) xmlBufferContent (buffer));
- xmlBufferFree (buffer);
- xmlFreeNode (node);
- return str;
- }
- else {
- TO_IMPLEMENT;
- return NULL;
- }
- }
-
- case GDA_INTERNAL_COMMAND_RESULT_EMPTY:
- return g_strdup ("");
-
- case GDA_INTERNAL_COMMAND_RESULT_MULTIPLE: {
- GSList *list;
- GString *string = NULL;
- gchar *str;
-
- for (list = res->u.multiple_results; list; list = list->next) {
- GdaInternalCommandResult *tres = (GdaInternalCommandResult*) list->data;
- gchar *tmp;
-
- tmp = result_to_string (console, tres, main_data->output_format);
- if (!string)
- string = g_string_new (tmp);
- else {
- g_string_append_c (string, '\n');
- g_string_append (string, tmp);
- }
- g_free (tmp);
- }
- if (string) {
- str = string->str;
- g_string_free (string, FALSE);
- }
- else
- str = g_strdup ("");
- return str;
- }
-
- default:
- return NULL;
- }
-}
-
/*
* SIGINT handling
*/
@@ -896,11 +682,16 @@ sigint_handler (int sig_num)
if (main_data->partial_command) {
g_string_free (main_data->partial_command, TRUE);
main_data->partial_command = NULL;
+ sigint_handler_status = SIGINT_HANDLER_DISABLED;
}
/* show a new prompt */
- compute_prompt (NULL, prompt, main_data->partial_command == NULL ? FALSE : TRUE,
- OUTPUT_FORMAT_DEFAULT | (main_data->output_format & OUTPUT_FORMAT_COLOR_TERM));
- g_print ("\ng%s", prompt->str);
+ compute_prompt (NULL, prompt, FALSE, FALSE,
+ TOOL_OUTPUT_FORMAT_DEFAULT |
+ (main_data->term_console->output_format & TOOL_OUTPUT_FORMAT_COLOR_TERM));
+ g_print ("\n%s", prompt->str);
+ compute_prompt (NULL, prompt, FALSE, TRUE,
+ TOOL_OUTPUT_FORMAT_DEFAULT |
+ (main_data->term_console->output_format & TOOL_OUTPUT_FORMAT_COLOR_TERM));
fflush (NULL);
}
else {
@@ -951,216 +742,55 @@ command_is_complete (const gchar *command)
/*
* command_execute
*/
-static GdaInternalCommandResult *execute_internal_command (SqlConsole *console, GdaConnection *cnc,
- const gchar *command_str,
- GError **error);
-static GdaInternalCommandResult *execute_external_command (SqlConsole *console, const gchar *command,
- GdaStatementModelUsage usage,
- GError **error);
-static GdaInternalCommandResult *
+static ToolCommandResult *execute_sql_command (SqlConsole *console, const gchar *command,
+ GdaStatementModelUsage usage,
+ GError **error);
+static ToolCommandResult *
command_execute (SqlConsole *console, const gchar *command, GdaStatementModelUsage usage, GError **error)
{
ConnectionSetting *cs;
+ g_assert (console);
cs = get_current_connection_settings (console);
if (!command || !(*command))
return NULL;
- if ((*command == '\\') || (*command == '.')) {
- if (cs)
- return execute_internal_command (console, cs->cnc, command, error);
- else
- return execute_internal_command (console, NULL, command, error);
- }
+ if ((*command == '\\') || (*command == '.'))
+ return tool_command_group_execute (console->command_group, command + 1, console->output_format,
+ console, error);
+
else if (*command == '#') {
/* nothing to do */
- GdaInternalCommandResult *res;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ ToolCommandResult *res;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
else {
if (!cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
if (!gda_connection_is_opened (cs->cnc)) {
- g_set_error (error, TOOLS_ERROR, TOOLS_CONNECTION_CLOSED_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_CONNECTION_CLOSED_ERROR,
"%s", _("Connection closed"));
return NULL;
}
- return execute_external_command (console, command, usage, error);
+ return execute_sql_command (console, command, usage, error);
}
}
-static gint
-commands_compare_name (GdaInternalCommand *a, GdaInternalCommand *b)
-{
- gint cmp, alength, blength;
- if (!a->name || !b->name) {
- g_warning (_("Invalid unnamed command"));
- if (!a->name) {
- if (b->name)
- return 1;
- else
- return 0;
- }
- else
- return -1;
- }
- alength = strlen (a->name);
- blength = strlen (b->name);
- cmp = strncmp (a->name, b->name, MIN (alength, blength));
- if (cmp == 0)
- return blength - alength;
- else
- return cmp;
-}
-
-
-static gint
-commands_compare_group (GdaInternalCommand *a, GdaInternalCommand *b)
-{
- if (!a->group) {
- if (b->group)
- return 1;
- else
- return 0;
- }
- else {
- if (b->group) {
- gint cmp = strcmp (a->group, b->group);
- if (cmp)
- return cmp;
- else
- return commands_compare_name (a, b);
- }
- else
- return -1;
- }
-}
-
-
-static GdaInternalCommand *
-find_command (GdaInternalCommandsList *commands_list, const gchar *command_str, gboolean *command_complete)
-{
- GdaInternalCommand *command = NULL;
- GSList *list;
- gsize length;
-
- if (!command_str || ((*command_str != '\\') && (*command_str != '.')))
- return NULL;
-
- length = strlen (command_str + 1);
- for (list = commands_list->name_ordered; list; list = list->next) {
- command = (GdaInternalCommand*) list->data;
- if (!strncmp (command->name, command_str + 1, MIN (length, strlen (command->name)))) {
- gsize l;
- gchar *ptr;
- for (ptr = command->name, l = 0; *ptr && (*ptr != ' '); ptr++, l++);
-
- if (length == l)
- break;
- else
- command = NULL;
- }
- else
- command = NULL;
- }
-
- if (!command &&
- ((command_str[1] == 'h') || (command_str[1] == 'H')) &&
- ((command_str[2] == ' ') || !command_str[2]))
- command = find_command (commands_list, ".?", command_complete);
-
- /* FIXME */
- if (command_complete)
- *command_complete = TRUE;
-
- return command;
-}
-
-
/*
- * execute_internal_command
- *
- * Executes an internal command (not SQL)
- */
-GdaInternalCommandResult *
-execute_internal_command (SqlConsole *console, GdaConnection *cnc, const gchar *command_str, GError **error)
-{
- GdaInternalCommand *command;
- gboolean command_complete;
- gchar **args;
- GdaInternalCommandResult *res = NULL;
- GdaInternalCommandsList *commands_list = main_data->internal_commands;
-
- if (!commands_list->name_ordered) {
- GSList *list;
-
- for (list = commands_list->commands; list; list = list->next) {
- commands_list->name_ordered =
- g_slist_insert_sorted (commands_list->name_ordered, list->data,
- (GCompareFunc) commands_compare_name);
- commands_list->group_ordered =
- g_slist_insert_sorted (commands_list->group_ordered, list->data,
- (GCompareFunc) commands_compare_group);
- }
- }
-
- args = g_strsplit (command_str, " ", 2);
- command = find_command (commands_list, args[0], &command_complete);
- g_strfreev (args);
- args = NULL;
- if (!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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
- "%s", _("Internal command not correctly defined"));
- goto cleanup;
- }
-
- if (!command_complete) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
- "%s", _("Incomplete internal command"));
- goto cleanup;
- }
-
- if (command->arguments_delimiter_func)
- args = command->arguments_delimiter_func (command_str);
- else
- args = default_gda_internal_commandargs_func (command_str);
- if (command->unquote_args) {
- gint i;
- for (i = 1; args[i]; i++)
- gda_internal_command_arg_remove_quotes (args[i]);
- }
- res = command->command_func (console, cnc, (const gchar **) &(args[1]),
- main_data->output_format, error, command->user_data);
-
- cleanup:
- if (args)
- g_strfreev (args);
-
- return res;
-}
-
-
-/*
- * execute_external_command
+ * execute_sql_command
*
* Executes an SQL statement as understood by the DBMS
*/
-static GdaInternalCommandResult *
-execute_external_command (SqlConsole *console, const gchar *command,
- GdaStatementModelUsage usage, GError **error)
+static ToolCommandResult *
+execute_sql_command (SqlConsole *console, const gchar *command,
+ GdaStatementModelUsage usage, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
GdaBatch *batch;
const GSList *stmt_list;
GdaStatement *stmt;
@@ -1171,7 +801,7 @@ execute_external_command (SqlConsole *console, const gchar *command,
cs = get_current_connection_settings (console);
if (!cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
@@ -1191,7 +821,7 @@ execute_external_command (SqlConsole *console, const gchar *command,
}
if (stmt_list->next) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("More than one SQL statement"));
g_object_unref (batch);
return NULL;
@@ -1237,7 +867,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Could not interpret the '%s' parameter's value"),
gda_holder_get_id (h));
g_free (res);
@@ -1254,7 +884,7 @@ execute_external_command (SqlConsole *console, const gchar *command,
}
else {
if (! gda_holder_is_valid (h)) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("No internal parameter named '%s' required by query"),
gda_holder_get_id (h));
g_free (res);
@@ -1265,7 +895,7 @@ execute_external_command (SqlConsole *console, const gchar *command,
}
}
- res = g_new0 (GdaInternalCommandResult, 1);
+ res = g_new0 (ToolCommandResult, 1);
res->was_in_transaction_before_exec = gda_connection_get_transaction_status (cs->cnc) ? TRUE : FALSE;
res->cnc = g_object_ref (cs->cnc);
obj = gda_connection_statement_execute (cs->cnc, stmt, params, usage, NULL, error);
@@ -1275,11 +905,11 @@ execute_external_command (SqlConsole *console, const gchar *command,
}
else {
if (GDA_IS_DATA_MODEL (obj)) {
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = GDA_DATA_MODEL (obj);
}
else if (GDA_IS_SET (obj)) {
- res->type = GDA_INTERNAL_COMMAND_RESULT_SET;
+ res->type = TOOL_COMMAND_RESULT_SET;
res->u.set = GDA_SET (obj);
}
else
@@ -1297,39 +927,44 @@ execute_external_command (SqlConsole *console, const gchar *command,
static ConnectionSetting *
get_current_connection_settings (SqlConsole *console)
{
- if (console) {
- if (console->current) {
- if (g_slist_find (main_data->settings, console->current))
- return console->current;
- else
- return NULL;
- }
- else
- return NULL;
+ if (console->current) {
+ g_assert (g_slist_find (main_data->settings, console->current));
+ return console->current;
}
else
- return main_data->current;
+ return NULL;
}
+/**
+ * clears and modifies @string to hold a prompt.
+ */
static void
-compute_prompt (SqlConsole *console, GString *string, gboolean in_command, OutputFormat format)
+compute_prompt (SqlConsole *console, GString *string, gboolean in_command, gboolean for_readline, ToolOutputFormat format)
{
gchar *prefix = NULL;
ConnectionSetting *cs;
g_assert (string);
gchar suffix = '>';
+ if (!console)
+ console = main_data->term_console;
g_string_set_size (string, 0);
- if (format & OUTPUT_FORMAT_COLOR_TERM) {
+
+ if (exit_requested)
+ return;
+
+ if (format & TOOL_OUTPUT_FORMAT_COLOR_TERM) {
const gchar *color;
- color = color_s (GDA_SQL_COLOR_BOLD, format);
+ color = tool_output_color_s (TOOL_COLOR_BOLD, format);
if (color && *color) {
#ifdef HAVE_READLINE
- g_string_append_c (string, RL_PROMPT_START_IGNORE);
+ if (for_readline)
+ g_string_append_c (string, RL_PROMPT_START_IGNORE);
#endif
g_string_append (string, color);
#ifdef HAVE_READLINE
- g_string_append_c (string, RL_PROMPT_END_IGNORE);
+ if (for_readline)
+ g_string_append_c (string, RL_PROMPT_END_IGNORE);
#endif
}
}
@@ -1357,16 +992,18 @@ compute_prompt (SqlConsole *console, GString *string, gboolean in_command, Outpu
else
g_string_append_printf (string, "%s%c ", prefix, suffix);
- if (format & OUTPUT_FORMAT_COLOR_TERM) {
+ if (format & TOOL_OUTPUT_FORMAT_COLOR_TERM) {
const gchar *color;
- color = color_s (GDA_SQL_COLOR_RESET, OUTPUT_FORMAT_COLOR_TERM);
+ color = tool_output_color_s (TOOL_COLOR_RESET, TOOL_OUTPUT_FORMAT_COLOR_TERM);
if (color && *color) {
#ifdef HAVE_READLINE
- g_string_append_c (string, RL_PROMPT_START_IGNORE);
+ if (for_readline)
+ g_string_append_c (string, RL_PROMPT_START_IGNORE);
#endif
g_string_append (string, color);
#ifdef HAVE_READLINE
- g_string_append_c (string, RL_PROMPT_END_IGNORE);
+ if (for_readline)
+ g_string_append_c (string, RL_PROMPT_END_IGNORE);
#endif
}
}
@@ -1402,17 +1039,17 @@ check_shell_argument (const gchar *arg)
static gboolean
set_output_file (const gchar *file, GError **error)
{
- if (main_data->output_stream) {
- if (main_data->output_is_pipe) {
- pclose (main_data->output_stream);
+ if (main_data->term_console->output_stream) {
+ if (main_data->term_console->output_is_pipe) {
+ pclose (main_data->term_console->output_stream);
#ifndef G_OS_WIN32
signal (SIGPIPE, SIG_DFL);
#endif
}
else
- fclose (main_data->output_stream);
- main_data->output_stream = NULL;
- main_data->output_is_pipe = FALSE;
+ fclose (main_data->term_console->output_stream);
+ main_data->term_console->output_stream = NULL;
+ main_data->term_console->output_is_pipe = FALSE;
}
if (file) {
@@ -1421,23 +1058,23 @@ set_output_file (const gchar *file, GError **error)
if (*copy != '|') {
/* output to a file */
- main_data->output_stream = g_fopen (copy, "w");
- if (!main_data->output_stream) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ main_data->term_console->output_stream = g_fopen (copy, "w");
+ if (!main_data->term_console->output_stream) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Can't open file '%s' for writing: %s\n"),
copy,
strerror (errno));
g_free (copy);
return FALSE;
}
- main_data->output_is_pipe = FALSE;
+ main_data->term_console->output_is_pipe = FALSE;
}
else {
/* output to a pipe */
if (check_shell_argument (copy+1)) {
- main_data->output_stream = popen (copy+1, "w");
- if (!main_data->output_stream) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ main_data->term_console->output_stream = popen (copy+1, "w");
+ if (!main_data->term_console->output_stream) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Can't open pipe '%s': %s"),
copy,
strerror (errno));
@@ -1446,7 +1083,7 @@ set_output_file (const gchar *file, GError **error)
}
}
else {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Can't open pipe '%s': %s"),
copy + 1,
"program name must only contain alphanumeric characters");
@@ -1456,7 +1093,7 @@ set_output_file (const gchar *file, GError **error)
#ifndef G_OS_WIN32
signal (SIGPIPE, SIG_IGN);
#endif
- main_data->output_is_pipe = TRUE;
+ main_data->term_console->output_is_pipe = TRUE;
}
g_free (copy);
}
@@ -1486,7 +1123,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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Can't open file '%s' for reading: %s\n"),
file,
strerror (errno));
@@ -1535,7 +1172,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 void conn_closed_cb (GdaConnection *cnc, ConnectionSetting *cs);
+static void conn_closed_cb (GdaConnection *cnc, gpointer data);
static gchar* read_hidden_passwd ();
static void user_password_needed (GdaDsnInfo *info, const gchar *real_provider,
@@ -1552,8 +1189,10 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
ConnectionSetting *cs = NULL;
gchar *real_cnc_string;
+ g_assert (console);
+
if (cnc_name && ! connection_name_is_valid (cnc_name)) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Connection name '%s' is invalid"), cnc_name);
return NULL;
}
@@ -1736,10 +1375,7 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
cs->meta_job_id = 0;
main_data->settings = g_slist_append (main_data->settings, cs);
- if (console)
- console->current = cs;
- else
- main_data->current = cs;
+ console->current = cs;
GdaMetaStore *store;
gboolean update_store = FALSE;
@@ -1777,7 +1413,7 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
(GdaThreaderFunc) thread_cancelled_cb_update_meta_store,
&lerror);
if (cs->meta_job_id == 0) {
- if (!main_data->output_stream)
+ if (!console->output_stream)
g_print (_("Error getting meta data in background: %s\n"),
lerror && lerror->message ? lerror->message : _("No detail"));
if (lerror)
@@ -1785,21 +1421,21 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
}
}
else {
- if (!main_data->output_stream) {
+ if (!console->output_stream) {
g_print (_("Getting database schema information for connection '%s', this may take some time... "),
cs->name);
fflush (stdout);
}
if (!gda_connection_update_meta_store (cs->cnc, NULL, &lerror)) {
- if (!main_data->output_stream)
+ if (!console->output_stream)
g_print (_("error: %s\n"),
lerror && lerror->message ? lerror->message : _("No detail"));
if (lerror)
g_error_free (lerror);
}
else
- if (!main_data->output_stream)
+ if (!console->output_stream)
g_print (_("Done.\n"));
}
}
@@ -1810,7 +1446,7 @@ open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_st
if (cs) {
g_signal_connect (cs->cnc, "conn-closed",
- G_CALLBACK (conn_closed_cb), cs);
+ G_CALLBACK (conn_closed_cb), NULL);
}
return cs;
@@ -1873,7 +1509,7 @@ read_hidden_passwd (void)
if (fail)
return NULL;
#else
- #ifdef G_OS_WIN32
+#ifdef G_OS_WIN32
HANDLE t = NULL;
LPDWORD t_orig = NULL;
@@ -1886,7 +1522,7 @@ read_hidden_passwd (void)
/* set to the new mode */
SetConsoleMode (t, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
- #endif
+#endif
#endif
p = fgets (password, sizeof (password) - 1, stdin);
@@ -1895,11 +1531,11 @@ read_hidden_passwd (void)
termio.c_lflag |= ECHO;
tcsetattr (0, TCSANOW, &termio);
#else
- #ifdef G_OS_WIN32
+#ifdef G_OS_WIN32
SetConsoleMode (t, *t_orig);
fflush (stdout);
free (t_orig);
- #endif
+#endif
#endif
if (!p)
@@ -1938,21 +1574,21 @@ thread_ok_cb_update_meta_store (G_GNUC_UNUSED GdaThreader *threader, G_GNUC_UNUS
data->cs->meta_job_id = 0;
if (data->cannot_lock) {
GError *lerror = NULL;
- if (!main_data->output_stream) {
+ if (!main_data->term_console->output_stream) {
g_print (_("Getting database schema information for connection '%s', this may take some time... "),
data->cs->name);
fflush (stdout);
}
if (!gda_connection_update_meta_store (data->cs->cnc, NULL, &lerror)) {
- if (!main_data->output_stream)
+ if (!main_data->term_console->output_stream)
g_print (_("error: %s\n"),
lerror && lerror->message ? lerror->message : _("No detail"));
if (lerror)
g_error_free (lerror);
}
else
- if (!main_data->output_stream)
+ if (!main_data->term_console->output_stream)
g_print (_("Done.\n"));
}
if (data->error)
@@ -1978,7 +1614,7 @@ connection_settings_free (ConnectionSetting *cs)
g_free (cs->name);
if (cs->cnc) {
g_signal_handlers_disconnect_by_func (cs->cnc,
- G_CALLBACK (conn_closed_cb), cs);
+ G_CALLBACK (conn_closed_cb), NULL);
g_object_unref (cs->cnc);
}
if (cs->parser)
@@ -2036,8 +1672,9 @@ static gchar *
data_model_to_string (SqlConsole *console, GdaDataModel *model)
{
static gboolean env_set = FALSE;
- OutputFormat of;
+ ToolOutputFormat of;
+ g_assert (console);
if (!GDA_IS_DATA_MODEL (model))
return NULL;
@@ -2048,19 +1685,15 @@ data_model_to_string (SqlConsole *console, GdaDataModel *model)
g_setenv ("GDA_DATA_MODEL_DUMP_TITLE", "Yes", TRUE);
if (! getenv ("GDA_DATA_MODEL_NULL_AS_EMPTY"))
g_setenv ("GDA_DATA_MODEL_NULL_AS_EMPTY", "Yes", TRUE);
- if (! main_data->output_stream || isatty (fileno (main_data->output_stream))) {
+ if (! console->output_stream || isatty (fileno (console->output_stream))) {
if (! getenv ("GDA_DATA_MODEL_DUMP_TRUNCATE"))
g_setenv ("GDA_DATA_MODEL_DUMP_TRUNCATE", "-1", TRUE);
}
env_set = TRUE;
}
- if (console)
- of = console->output_format;
- else
- of = main_data->output_format;
-
- if (of & OUTPUT_FORMAT_DEFAULT) {
+ of = console->output_format;
+ if (of & TOOL_OUTPUT_FORMAT_DEFAULT) {
gchar *tmp;
tmp = gda_data_model_dump_as_string (model);
if (GDA_IS_DATA_SELECT (model)) {
@@ -2076,11 +1709,11 @@ data_model_to_string (SqlConsole *console, GdaDataModel *model)
else
return tmp;
}
- else if (of & OUTPUT_FORMAT_XML)
+ else if (of & TOOL_OUTPUT_FORMAT_XML)
return gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_DATA_ARRAY_XML,
NULL, 0,
NULL, 0, NULL);
- else if (of & OUTPUT_FORMAT_CSV) {
+ else if (of & TOOL_OUTPUT_FORMAT_CSV) {
gchar *retval;
GdaSet *optexp;
optexp = make_options_set_from_gdasql_options ("csv");
@@ -2091,7 +1724,7 @@ data_model_to_string (SqlConsole *console, GdaDataModel *model)
g_object_unref (optexp);
return retval;
}
- else if (of & OUTPUT_FORMAT_HTML) {
+ else if (of & TOOL_OUTPUT_FORMAT_HTML) {
xmlBufferPtr buffer;
xmlNodePtr top, div, table, node, row_node, col_node, header, meta;
gint ncols, nrows, i, j;
@@ -2170,7 +1803,7 @@ output_string (const gchar *str)
if (force_no_pager < 0) {
/* still unset... */
- if (getenv ("GDA_NO_PAGER"))
+ if (getenv (TOOL_NO_PAGER))
force_no_pager = 1;
else
force_no_pager = 0;
@@ -2180,8 +1813,8 @@ output_string (const gchar *str)
if (*str && (str[length - 1] != '\n'))
append_nl = TRUE;
- if (main_data->output_stream)
- to_stream = main_data->output_stream;
+ if (main_data->term_console->output_stream)
+ to_stream = main_data->term_console->output_stream;
else
to_stream = stdout;
@@ -2221,803 +1854,533 @@ output_string (const gchar *str)
}
}
-static gchar **args_as_string_func (const gchar *str);
-static gchar **args_as_string_set (const gchar *str);
-
-static GdaInternalCommandResult *extra_command_copyright (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_option (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_quit (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_cd (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_set_output (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_set_output_format (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_set_input (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_echo (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_qecho (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_list_dsn (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_create_dsn (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_remove_dsn (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_list_providers (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_manage_cnc (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_close_cnc (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_bind_cnc (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_edit_buffer (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_reset_buffer (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_show_buffer (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_exec_buffer (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_write_buffer (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_query_buffer_to_dict (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_query_buffer_from_dict (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_query_buffer_list_dict (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_query_buffer_delete_dict (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_set (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_unset (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_data_sets_list (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_data_set_move (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_data_set_grep (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_data_set_show (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_data_set_rm (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_data_set_import (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_graph (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
+static ToolCommandResult *extra_command_copyright (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_option (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_quit (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_cd (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_set_output (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_set_output_format (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_set_input (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_echo (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_qecho (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_list_dsn (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_create_dsn (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_remove_dsn (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_list_providers (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static gchar **extra_command_manage_cnc_compl (const gchar *text);
+static ToolCommandResult *extra_command_close_cnc (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_bind_cnc (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_edit_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_reset_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_show_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_exec_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_write_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_query_buffer_to_dict (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_query_buffer_from_dict (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_query_buffer_list_dict (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_query_buffer_delete_dict (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_set (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_unset (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_data_sets_list (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_data_set_move (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_data_set_grep (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_data_set_show (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+
+static ToolCommandResult *extra_command_data_set_rm (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_data_set_import (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+
+static ToolCommandResult *extra_command_graph (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
#ifdef HAVE_LIBSOUP
-static GdaInternalCommandResult *extra_command_httpd (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
+static ToolCommandResult *extra_command_httpd (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
#endif
-
#ifdef NONE
-static GdaInternalCommandResult *extra_command_lo_update (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
+static ToolCommandResult *extra_command_lo_update (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
#endif
-static GdaInternalCommandResult *extra_command_export (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_set2 (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_pivot (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_declare_fk (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
-static GdaInternalCommandResult *extra_command_undeclare_fk (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-
+static ToolCommandResult *extra_command_export (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_set2 (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_pivot (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+
+static ToolCommandResult *extra_command_declare_fk (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+
+static ToolCommandResult *extra_command_undeclare_fk (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
#ifdef HAVE_LDAP
-static GdaInternalCommandResult *extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_ldap_descr (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_ldap_mv (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
-static GdaInternalCommandResult *extra_command_ldap_mod (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- OutputFormat format, GError **error, gpointer data);
+static ToolCommandResult *extra_command_ldap_search (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_ldap_mv (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
+static ToolCommandResult *extra_command_ldap_mod (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error);
#endif
-static GdaInternalCommandsList *
-build_internal_commands_list (void)
+static void
+build_commands (MainData *md)
{
- GdaInternalCommandsList *commands = g_new0 (GdaInternalCommandsList, 1);
- GdaInternalCommand *c;
+ md->limit_commands = tool_command_group_new ();
+ md->all_commands = tool_command_group_new ();
- c = g_new0 (GdaInternalCommand, 1);
+ ToolCommand *c;
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("General");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FILE>]"), "s");
c->description = _("Show commands history, or save it to file");
- c->args = NULL;
- c->command_func = gda_internal_command_history;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) gda_internal_command_history;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
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;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) gda_internal_command_dict_sync;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <fkname> <tableA>(<colA>,...) <tableB>(<colB>,...)"), "fkdeclare");
c->description = _("Declare a new foreign key (not actually in database): tableA references tableB");
- c->args = NULL;
- c->command_func = extra_command_declare_fk;
- c->user_data = NULL;
- c->arguments_delimiter_func = args_as_string_func;
- c->unquote_args = FALSE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_declare_fk;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <fkname> <tableA> <tableB>"), "fkundeclare");
c->description = _("Un-declare a foreign key (not actually in database)");
- c->args = NULL;
- c->command_func = extra_command_undeclare_fk;
- c->user_data = NULL;
- c->arguments_delimiter_func = args_as_string_func;
- c->unquote_args = FALSE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_undeclare_fk;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<TABLE>]"), "dt");
c->description = _("List all tables (or named table)");
- c->args = NULL;
- c->command_func = gda_internal_command_list_tables;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = FALSE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) gda_internal_command_list_tables;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<VIEW>]"), "dv");
c->description = _("List all views (or named view)");
- c->args = NULL;
- c->command_func = gda_internal_command_list_views;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = FALSE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) gda_internal_command_list_views;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<SCHEMA>]"), "dn");
c->description = _("List all schemas (or named schema)");
- c->args = NULL;
- c->command_func = gda_internal_command_list_schemas;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = FALSE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) gda_internal_command_list_schemas;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<OBJ_NAME>|<SCHEMA>.*]"), "d");
c->description = _("Describe object or full list of objects");
- c->args = NULL;
- c->command_func = gda_internal_command_detail;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = FALSE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) gda_internal_command_detail;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<TABLE1> [<TABLE2>...]]"), "graph");
c->description = _("Create a graph of all or the listed tables");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_graph;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = FALSE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_graph;
+ tool_command_group_add (md->all_commands, c);
#ifdef HAVE_LIBSOUP
- c = g_new0 (GdaInternalCommand, 1);
+ c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<port> [<authentication token>]]"), "http");
c->description = _("Start/stop embedded HTTP server (on given port or on 12345 by default)");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_httpd;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_httpd;
+ tool_command_group_add (md->all_commands, c);
#endif
/* specific commands */
- c = g_new0 (GdaInternalCommand, 1);
+ c = g_new0 (ToolCommand, 1);
c->group = _("General");
c->group_id = NULL;
- c->name = g_strdup_printf (_("%s [<CNC_NAME> [<DSN>|<CONNECTION STRING>]]"), "c");
+ c->name = g_strdup_printf (_("%s [[<CNC_NAME>] [<DSN>|<CONNECTION STRING>]]"), "c");
c->description = _("Opens a new connection or lists opened connections");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_manage_cnc;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_manage_cnc;
+ c->completion_func = extra_command_manage_cnc_compl;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("General");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<CNC_NAME>]"), "close");
c->description = _("Close a connection");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_close_cnc;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_close_cnc;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("General");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <CNC NAME> <OBJ NAME> [<OBJ NAME> ...]"), "bind");
c->description = _("Bind connections or datasets (<OBJ NAME>) into a single new one (allowing SQL commands to be executed across multiple connections and/or datasets)");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_bind_cnc;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_bind_cnc;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("DSN (data sources) management");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<DSN>]"), "l");
c->description = _("List all DSN (or named DSN's attributes)");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_list_dsn;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_list_dsn;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("DSN (data sources) management");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <DSN_NAME> <DSN_DEFINITION> [<DESCRIPTION>]"), "lc");
c->description = _("Create (or modify) a DSN");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_create_dsn;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_create_dsn;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("DSN (data sources) management");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <DSN_NAME> [<DSN_NAME>...]"), "lr");
c->description = _("Remove a DSN");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_remove_dsn;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_remove_dsn;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("DSN (data sources) management");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<PROVIDER>]"), "lp");
c->description = _("List all installed database providers (or named one's attributes)");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_list_providers;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_list_providers;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <FILE>"), "i");
c->description = _("Execute commands from file");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_set_input;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_set_input;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FILE>]"), "o");
c->description = _("Send output to a file or |pipe");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_set_output;
- c->user_data = NULL;
- c->arguments_delimiter_func = args_as_string_func;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_set_output;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<TEXT>]"), "echo");
c->description = _("Print TEXT or an empty line to standard output");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_echo;
- c->user_data = NULL;
- c->arguments_delimiter_func = args_as_string_func;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_echo;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<TEXT>]"), "qecho");
c->description = _("Send TEXT or an empty line to current output stream");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_qecho;
- c->user_data = NULL;
- c->arguments_delimiter_func = args_as_string_func;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_qecho;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("General");
c->group_id = NULL;
c->name = "q";
c->description = _("Quit");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_quit;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_quit;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("General");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<DIR>]"), "cd");
c->description = _("Change the current working directory");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_cd;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_cd;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("General");
c->group_id = NULL;
c->name = "copyright";
c->description = _("Show usage and distribution terms");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_copyright;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_copyright;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("General");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<NAME> [<VALUE>]]"), "option");
c->description = _("Set or show an option, or list all options ");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_option;
- c->user_data = NULL;
- c->arguments_delimiter_func = args_as_string_set;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_option;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FILE>]"), "e");
c->description = _("Edit the query buffer (or file) with external editor");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_edit_buffer;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_edit_buffer;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FILE>]"), "qr");
c->description = _("Reset the query buffer (or load file into query buffer)");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_reset_buffer;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_reset_buffer;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = "qp";
c->description = _("Show the contents of the query buffer");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_show_buffer;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_show_buffer;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FAVORITE_NAME>]"), "g");
c->description = _("Execute contents of query buffer, or execute specified query favorite");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_exec_buffer;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_exec_buffer;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <FILE>"), "qw");
c->description = _("Write query buffer to file");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_write_buffer;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_write_buffer;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <FAVORITE_NAME>"), "qs");
c->description = _("Save query buffer as favorite");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_query_buffer_to_dict;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_query_buffer_to_dict;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <FAVORITE_NAME>"), "ql");
c->description = _("Load a query favorite into query buffer");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_query_buffer_from_dict;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_query_buffer_from_dict;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <FAVORITE_NAME>"), "qd");
c->description = _("Delete a query favorite");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_query_buffer_delete_dict;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_query_buffer_delete_dict;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s"), "qa");
c->description = _("List all query favorites");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_query_buffer_list_dict;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_query_buffer_list_dict;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
c->group_id = NULL;
c->name = "H [HTML|XML|CSV|DEFAULT]";
c->description = _("Set output format");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_set_output_format;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_set_output_format;
+ tool_command_group_add (md->all_commands, c);
/*
- c = g_new0 (GdaInternalCommand, 1);
- c->group = _("Query buffer & query favorites");
- c->group_id = NULL;
- c->name = g_strdup_printf (_("%s <FILE> <TABLE> <BLOB_COLUMN> <ROW_CONDITION>"), "lo_update");
- c->description = _("Import a blob into the database");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_lo_update;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
+ c = g_new0 (ToolCommand, 1);
+ c->group = _("Query buffer & query favorites");
+ c->group_id = NULL;
+ c->name = g_strdup_printf (_("%s <FILE> <TABLE> <BLOB_COLUMN> <ROW_CONDITION>"), "lo_update");
+ c->description = _("Import a blob into the database");
+ c->command_func = (ToolCommandFunc) extra_command_lo_update;
+ tool_command_group_add (md->all_commands, c);
*/
- c = g_new0 (GdaInternalCommand, 1);
+ c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<NAME>|<TABLE> <COLUMN> <ROW_CONDITION>] <FILE>"), "export");
c->description = _("Export internal parameter or table's value to the FILE file");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_export;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_export;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Execution context");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<NAME> [<VALUE>|_null_]]"), "set");
c->description = _("Set or show internal parameter, or list all if no parameter specified ");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_set;
- c->user_data = NULL;
- c->arguments_delimiter_func = args_as_string_set;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_set;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Execution context");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<NAME>]"), "unset");
c->description = _("Unset (delete) internal named parameter (or all parameters)");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_unset;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_unset;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Execution context");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <NAME> [<FILE>|<TABLE> <COLUMN> <ROW_CONDITION>]"), "setex");
c->description = _("Set internal parameter as the contents of the FILE file or from an existing table's value");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_set2;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_set2;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Execution context");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <SELECT> <ROW_FIELDS> [<COLUMN_FIELDS> [<DATA_FIELDS> ...]]"), "pivot");
c->description = _("Performs a statistical analysis on the data from SELECT, "
"using ROW_FIELDS and COLUMN_FIELDS criteria and optionally DATA_FIELDS for the data");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_pivot;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_pivot;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
c->group_id = "DATA";
c->name = g_strdup_printf (_("%s"), "ds_list");
c->description = _("Lists all the datasets kept in memory for reference");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_data_sets_list;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_data_sets_list;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
c->group_id = "DATA";
c->name = g_strdup_printf (_("%s <DATASET NAME> <PATTERN>"), "ds_grep");
c->description = _("Show a dataset's contents where lines match a regular expression");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_data_set_grep;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_data_set_grep;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
c->group_id = "DATA";
c->name = g_strdup_printf (_("%s <DATASET NAME> [<COLUMN> [<COLUMN> ...]]"), "ds_show");
c->description = _("Show a dataset's contents, showing only the specified columns if any specified");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_data_set_show;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_data_set_show;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
c->group_id = "DATA";
c->name = g_strdup_printf (_("%s <DATASET NAME> [<DATASET NAME> ...]"), "ds_rm");
c->description = _("Remove one or more datasets");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_data_set_rm;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_data_set_rm;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
c->group_id = "DATA";
c->name = g_strdup_printf (_("%s <DATASET NAME> <DATASET NAME>"), "ds_mv");
c->description = _("Rename a dataset, useful to rename the '_' dataset to keep it");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_data_set_move;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_data_set_move;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
c->group_id = "DATA";
c->name = g_strdup_printf (_("%s CSV <FILE NAME>"), "ds_import");
c->description = _("Import a dataset from a file");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_data_set_import;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_data_set_import;
+ tool_command_group_add (md->limit_commands, c);
+ tool_command_group_add (md->all_commands, c);
#ifdef HAVE_LDAP
- c = g_new0 (GdaInternalCommand, 1);
+ c = g_new0 (ToolCommand, 1);
c->group = _("LDAP");
c->group_id = "LDAP";
c->name = g_strdup_printf (_("%s <filter> [<base|onelevel|subtree> [<base DN>]]"), "ldap_search");
c->description = _("Search LDAP entries");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_ldap_search;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_ldap_search;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("LDAP");
c->group_id = "LDAP";
c->name = g_strdup_printf (_("%s <DN> [\"all\"|\"set\"|\"unset\"]"), "ldap_descr");
@@ -3026,131 +2389,87 @@ build_internal_commands_list (void)
"the \"all\" 2nd parameter is passed, then the unset attributes are "
"also shown, and if the \"unset\" 2nd parameter "
"is passed, then only non set attributes are shown.");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_ldap_descr;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_ldap_descr;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("LDAP");
c->group_id = "LDAP";
c->name = g_strdup_printf (_("%s <DN> <new DN>"), "ldap_mv");
c->description = _("Renames an LDAP entry");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_ldap_mv;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- c = g_new0 (GdaInternalCommand, 1);
+ c->command_func = (ToolCommandFunc) extra_command_ldap_mv;
+ tool_command_group_add (md->all_commands, c);
+
+ c = g_new0 (ToolCommand, 1);
c->group = _("LDAP");
c->group_id = "LDAP";
c->name = g_strdup_printf (_("%s <DN> <OPERATION> [<ATTR>[=<VALUE>]] [<ATTR>=<VALUE> ...]"), "ldap_mod");
c->description = _("Modifies an LDAP entry's attributes; <OPERATION> may be DELETE, REPLACE or ADD");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) extra_command_ldap_mod;
- c->user_data = NULL;
- c->arguments_delimiter_func = NULL;
- c->unquote_args = TRUE;
- c->limit_to_main = TRUE;
- commands->commands = g_slist_prepend (commands->commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_ldap_mod;
+ tool_command_group_add (md->all_commands, c);
#endif
-
- /* comes last */
- c = g_new0 (GdaInternalCommand, 1);
- c->group = _("General");
- c->group_id = NULL;
- c->name = g_strdup_printf (_("%s [command]"), "?");
- c->description = _("List all available commands or give help for the specified command");
- c->args = NULL;
- c->command_func = (GdaInternalCommandFunc) gda_internal_command_help;
- c->user_data = commands;
- c->arguments_delimiter_func = NULL;
- c->limit_to_main = FALSE;
- commands->commands = g_slist_prepend (commands->commands, c);
-
- return commands;
}
-static GdaInternalCommandResult *
-extra_command_set_output (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_set_output (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
- if (set_output_file (args[0], error)) {
- GdaInternalCommandResult *res;
+ g_assert (console);
+ if (set_output_file (argv[0], error)) {
+ ToolCommandResult *res;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
else
return NULL;
}
-static GdaInternalCommandResult *
-extra_command_set_output_format (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, G_GNUC_UNUSED GError **error,
- G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_set_output_format (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *fmt = NULL;
- if (console) {
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- if (args[0] && *args[0])
- fmt = args[0];
+ g_assert (console);
+ if (argv[0] && *argv[0])
+ fmt = argv[0];
- main_data->output_format = OUTPUT_FORMAT_DEFAULT;
+ console->output_format = TOOL_OUTPUT_FORMAT_DEFAULT;
if (fmt) {
if ((*fmt == 'X') || (*fmt == 'x'))
- main_data->output_format = OUTPUT_FORMAT_XML;
+ console->output_format = TOOL_OUTPUT_FORMAT_XML;
else if ((*fmt == 'H') || (*fmt == 'h'))
- main_data->output_format = OUTPUT_FORMAT_HTML;
+ console->output_format = TOOL_OUTPUT_FORMAT_HTML;
else if ((*fmt == 'D') || (*fmt == 'd'))
- main_data->output_format = OUTPUT_FORMAT_DEFAULT;
+ console->output_format = TOOL_OUTPUT_FORMAT_DEFAULT;
else if ((*fmt == 'C') || (*fmt == 'c'))
- main_data->output_format = OUTPUT_FORMAT_CSV;
+ console->output_format = TOOL_OUTPUT_FORMAT_CSV;
else {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Unknown output format: '%s', reset to default"), fmt);
goto out;
}
}
- if (!main_data->output_stream) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT;
+ if (!console->output_stream) {
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
res->u.txt = g_string_new ("");
- switch (main_data->output_format) {
- case OUTPUT_FORMAT_DEFAULT:
+ switch (console->output_format) {
+ case TOOL_OUTPUT_FORMAT_DEFAULT:
g_string_assign (res->u.txt, ("Output format is default\n"));
break;
- case OUTPUT_FORMAT_HTML:
+ case TOOL_OUTPUT_FORMAT_HTML:
g_string_assign (res->u.txt, ("Output format is HTML\n"));
break;
- case OUTPUT_FORMAT_XML:
+ case TOOL_OUTPUT_FORMAT_XML:
g_string_assign (res->u.txt, ("Output format is XML\n"));
break;
- case OUTPUT_FORMAT_CSV:
+ case TOOL_OUTPUT_FORMAT_CSV:
g_string_assign (res->u.txt, ("Output format is CSV\n"));
break;
default:
@@ -3158,8 +2477,8 @@ extra_command_set_output_format (SqlConsole *console, G_GNUC_UNUSED GdaConnectio
}
}
else {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
out:
@@ -3188,91 +2507,75 @@ idle_read_input_stream (G_GNUC_UNUSED gpointer data)
}
stop:
- compute_prompt (NULL, prompt, main_data->partial_command == NULL ? FALSE : TRUE,
- OUTPUT_FORMAT_DEFAULT | (main_data->output_format & OUTPUT_FORMAT_COLOR_TERM));
+ compute_prompt (NULL, prompt, main_data->partial_command == NULL ? FALSE : TRUE, FALSE,
+ TOOL_OUTPUT_FORMAT_DEFAULT |
+ (main_data->term_console->output_format & TOOL_OUTPUT_FORMAT_COLOR_TERM));
g_print ("\n%s", prompt->str);
fflush (NULL);
set_input_file (NULL, NULL);
return FALSE; /* stop calling this function */
}
-static GdaInternalCommandResult *
-extra_command_set_input (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_set_input (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- if (set_input_file (args[0], error)) {
- GdaInternalCommandResult *res;
+ g_assert (console);
+ if (set_input_file (argv[0], error)) {
+ ToolCommandResult *res;
g_idle_add ((GSourceFunc) idle_read_input_stream, NULL);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
else
return NULL;
}
-static GdaInternalCommandResult *
-extra_command_echo (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, G_GNUC_UNUSED GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_echo (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT;
- res->u.txt = g_string_new (args[0]);
- if (args[0][strlen (args[0]) - 1] != '\n')
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
+ res->u.txt = g_string_new (argv[0]);
+ if (argv[0][strlen (argv[0]) - 1] != '\n')
g_string_append_c (res->u.txt, '\n');
return res;
}
-static GdaInternalCommandResult *
-extra_command_qecho (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, G_GNUC_UNUSED GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_qecho (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
- res->u.txt = g_string_new (args[0]);
+ g_assert (console);
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT;
+ res->u.txt = g_string_new (argv[0]);
return res;
}
-static GdaInternalCommandResult *
-extra_command_list_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
- const gchar **args, G_GNUC_UNUSED OutputFormat format, GError **error,
- G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_list_dsn (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
GList *list = NULL;
GdaDataModel *dsn_list = NULL, *model = NULL;
- if (args[0]) {
+ if (argv[0]) {
/* details about a DSN */
GdaDataModel *model;
- model = config_info_detail_dsn (args[0], error);
+ model = config_info_detail_dsn (argv[0], error);
if (model) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
@@ -3317,8 +2620,8 @@ extra_command_list_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConn
g_list_free (list);
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
g_object_unref (dsn_list);
@@ -3335,25 +2638,24 @@ extra_command_list_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConn
return NULL;
}
-static GdaInternalCommandResult *
-extra_command_create_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
- const gchar **args, G_GNUC_UNUSED OutputFormat format,
- GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_create_dsn (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
GdaDsnInfo newdsn;
gchar *real_cnc, *real_provider, *user, *pass;
- if (!args[0] || !args[1]) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (!argv[0] || !argv[1]) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing arguments"));
return NULL;
}
- newdsn.name = (gchar *) args [0];
- gda_connection_string_split ((gchar *) args[1], &real_cnc, &real_provider, &user, &pass);
+ newdsn.name = (gchar *) argv [0];
+ gda_connection_string_split ((gchar *) argv[1], &real_cnc, &real_provider, &user, &pass);
newdsn.provider = real_provider;
- newdsn.description = (gchar*) args[2];
+ newdsn.description = (gchar*) argv[2];
newdsn.cnc_string = real_cnc;
newdsn.auth_string = NULL;
@@ -3366,12 +2668,12 @@ extra_command_create_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
newdsn.is_system = FALSE;
if (!newdsn.provider) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing provider name"));
}
else if (gda_config_define_dsn (&newdsn, error)) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
g_free (real_cnc);
@@ -3382,48 +2684,43 @@ extra_command_create_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
return res;
}
-static GdaInternalCommandResult *
-extra_command_remove_dsn (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
- const gchar **args, G_GNUC_UNUSED OutputFormat format,
- GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_remove_dsn (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
gint i;
- if (!args[0]) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (!argv[0]) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing DSN name"));
return NULL;
}
- for (i = 0; args [i]; i++) {
- if (! gda_config_remove_dsn (args[i], error))
+ for (i = 0; argv [i]; i++) {
+ if (! gda_config_remove_dsn (argv[i], error))
return NULL;
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
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, G_GNUC_UNUSED OutputFormat format,
- GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_list_providers (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
GdaDataModel *model;
- if (args[0])
- model = config_info_detail_provider (args[0], error);
+ if (argv[0])
+ model = config_info_detail_provider (argv[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 = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
@@ -3438,81 +2735,96 @@ vconnection_hub_foreach_cb (G_GNUC_UNUSED GdaConnection *cnc, const gchar *ns, G
g_string_append_printf (string, "namespace %s", ns);
}
+static gchar **
+extra_command_manage_cnc_compl (const gchar *text)
+{
+ GArray *array = NULL;
+ gsize len;
+ gint i, ndsn;
+ len = strlen (text);
+
+ /* complete with DSN list to open connections */
+ ndsn = gda_config_get_nb_dsn ();
+ for (i = 0; i < ndsn; i++) {
+ GdaDsnInfo *info;
+ info = gda_config_get_dsn_info_at_index (i);
+ if (!len || !strncmp (info->name, text, len)) {
+ if (!array)
+ array = g_array_new (TRUE, FALSE, sizeof (gchar*));
+ gchar *tmp;
+ tmp = g_strdup (info->name);
+ g_array_append_val (array, tmp);
+ }
+ }
+
+ /* complete with opened connections */
+ GSList *list;
+ for (list = main_data->settings; list; list = list->next) {
+ ConnectionSetting *cs = (ConnectionSetting *) list->data;
+ if (!len || !strncmp (cs->name, text, len)) {
+ if (!array)
+ array = g_array_new (TRUE, FALSE, sizeof (gchar*));
+ gchar *tmp;
+ tmp = g_strdup (cs->name);
+ g_array_append_val (array, tmp);
+ }
+ }
+
+ if (array)
+ return (gchar**) g_array_free (array, FALSE);
+ else
+ return NULL;
+}
+
static
-GdaInternalCommandResult *
-extra_command_manage_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+ToolCommandResult *
+extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
+ g_assert (console);
+
+ if (argc > 2) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ _("Too many arguments"));
+ return NULL;
+ }
+
/* arguments:
* 0 = connection name
* 1 = DSN or direct string
- * 2 = user
- * 3 = password
*/
- if (args[0]) {
- if (args [1]) {
- /* open a new connection */
- const gchar *user = NULL, *pass = NULL;
+ if (argv[0]) {
+ const gchar *dsn = NULL;
+ if (!argv[1]) {
+ /* try to switch to an existing connection */
ConnectionSetting *cs;
-
- cs = find_connection_from_name (args[0]);
- if (cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("A connection named '%s' already exists"), args[0]);
- return NULL;
- }
- if (args[2]) {
- user = args[2];
- if (args[3])
- pass = args[3];
- }
- cs = open_connection (console, args[0], args[1], error);
+ cs = find_connection_from_name (argv[0]);
if (cs) {
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
- else
- return NULL;
- }
- else {
- /* switch to another already opened connection */
- ConnectionSetting *cs;
-
- cs = find_connection_from_name (args[0]);
- if (cs) {
- GdaInternalCommandResult *res;
-
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- if (console)
- console->current = cs;
- else
- main_data->current = cs;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
+ console->current = cs;
return res;
}
else {
- if (*args [0] == '~') {
+ if (*argv [0] == '~') {
/* find connection for which we want the meta store's connection */
- if (*(args[0] + 1)) {
- cs = find_connection_from_name (args[0] + 1);
+ if (*(argv[0] + 1)) {
+ cs = find_connection_from_name (argv[0] + 1);
if (!cs) {
- g_set_error (error, TOOLS_ERROR,
- TOOLS_NO_CONNECTION_ERROR,
- _("No connection named '%s' found"), args[0] + 1);
+ g_set_error (error, GDA_TOOLS_ERROR,
+ GDA_TOOLS_NO_CONNECTION_ERROR,
+ _("No connection named '%s' found"), argv[0] + 1);
return NULL;
}
}
- else if (console)
- cs = console->current;
else
- cs = main_data->current;
+ cs = console->current;
if (!cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
@@ -3520,7 +2832,7 @@ extra_command_manage_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
/* find if requested connection already exists */
ConnectionSetting *ncs = NULL;
if (* (cs->name) == '~')
- ncs = find_connection_from_name (main_data->current->name + 1);
+ ncs = find_connection_from_name (console->current->name + 1);
else {
gchar *tmp;
tmp = g_strdup_printf ("~%s", cs->name);
@@ -3528,21 +2840,18 @@ extra_command_manage_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
g_free (tmp);
}
if (ncs) {
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- if (console)
- console->current = ncs;
- else
- main_data->current = ncs;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
+ console->current = ncs;
return res;
}
/* open a new connection */
ncs = g_new0 (ConnectionSetting, 1);
GdaMetaStore *store;
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
ncs->name = g_strdup_printf ("~%s", cs->name);
store = gda_connection_get_meta_store (cs->cnc);
@@ -3556,48 +2865,69 @@ extra_command_manage_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
ncs->meta_job_id = 0;
main_data->settings = g_slist_append (main_data->settings, ncs);
- if (console)
- console->current = ncs;
- else
- main_data->current = ncs;
+ console->current = ncs;
GError *lerror = NULL;
- if (!main_data->output_stream) {
+ if (!console->output_stream) {
g_print (_("Getting database schema information, "
"this may take some time... "));
fflush (stdout);
}
if (!gda_connection_update_meta_store (ncs->cnc, NULL, &lerror)) {
- if (!main_data->output_stream)
+ if (!console->output_stream)
g_print (_("error: %s\n"),
lerror && lerror->message ? lerror->message : _("No detail"));
if (lerror)
g_error_free (lerror);
}
else
- if (!main_data->output_stream)
+ if (!console->output_stream)
g_print (_("Done.\n"));
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
- _("No connection named '%s' found"), args[0]);
+ dsn = argv[0];
+ }
+ }
+ else
+ dsn = argv[1];
+
+ if (dsn) {
+ /* open a new connection */
+ ConnectionSetting *cs;
+
+ cs = find_connection_from_name (argv[0]);
+ if (cs) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ _("A connection named '%s' already exists"), argv[0]);
return NULL;
}
+
+ cs = open_connection (console, argv[0], dsn, error);
+ if (cs) {
+ ToolCommandResult *res;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
+ return res;
+ }
+ else
+ return NULL;
}
+ else
+ return NULL;
}
else {
/* list opened connections */
GdaDataModel *model;
GSList *list;
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
if (! main_data->settings) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT;
res->u.txt = g_string_new (_("No opened connection"));
return res;
}
@@ -3662,35 +2992,19 @@ extra_command_manage_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
gda_value_free (value);
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
}
static void
-conn_closed_cb (GdaConnection *cnc, G_GNUC_UNUSED ConnectionSetting *cs)
+handle_close_cnc (SqlConsole *console, ConnectionSetting *cs, GdaConnection *cnc)
{
- extra_command_close_cnc (NULL, cnc, NULL, main_data->output_format, NULL, NULL);
-}
-
-static
-GdaInternalCommandResult *
-extra_command_close_cnc (SqlConsole *console, GdaConnection *cnc, const gchar **args, G_GNUC_UNUSED OutputFormat format,
- GError **error, G_GNUC_UNUSED gpointer data)
-{
- ConnectionSetting *cs = NULL;
- if (args && args[0] && *args[0]) {
- cs = find_connection_from_name (args[0]);
- if (!cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
- _("No connection named '%s' found"), args[0]);
- return NULL;
- }
- }
- else {
- /* close @cnc */
+ g_assert (console);
+ if (!cs) {
+ /* handle closed @cnc */
GSList *list;
for (list = main_data->settings; list; list = list->next) {
if (((ConnectionSetting *) list->data)->cnc == cnc) {
@@ -3698,16 +3012,9 @@ extra_command_close_cnc (SqlConsole *console, GdaConnection *cnc, const gchar **
break;
}
}
-
- if (! cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
- "%s", _("No connection currently opened"));
- return NULL;
- }
}
-
- if ((console && (console->current == cs)) ||
- (!console && (main_data->current == cs))) {
+
+ if (console->current == cs) {
gint index;
ConnectionSetting *ncs = NULL;
index = g_slist_index (main_data->settings, cs);
@@ -3715,57 +3022,87 @@ extra_command_close_cnc (SqlConsole *console, GdaConnection *cnc, const gchar **
ncs = g_slist_nth_data (main_data->settings, index + 1);
else
ncs = g_slist_nth_data (main_data->settings, index - 1);
- if (console)
- console->current = ncs;
- else
- main_data->current = ncs;
+ console->current = ncs;
}
main_data->settings = g_slist_remove (main_data->settings, cs);
connection_settings_free (cs);
+}
+
+static void
+conn_closed_cb (GdaConnection *cnc, G_GNUC_UNUSED gpointer data)
+{
+ handle_close_cnc (NULL, NULL, cnc);
+}
- GdaInternalCommandResult *res;
+static
+ToolCommandResult *
+extra_command_close_cnc (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
+{
+ if (argc == 0) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ _("No connection specified"));
+ return NULL;
+ }
+ else {
+ guint i;
+ for (i = 0; i < argc; i++) {
+ ConnectionSetting *cs = NULL;
+ if (argv[i] && *argv[i])
+ cs = find_connection_from_name (argv[0]);
+ if (!cs) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ _("No connection named '%s' found"), argv[0]);
+ return NULL;
+ }
+
+ handle_close_cnc (console, cs, NULL);
+ }
+ }
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ ToolCommandResult *res;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
-static GdaInternalCommandResult *
-extra_command_bind_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_bind_cnc (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
ConnectionSetting *cs = NULL;
- gint i, nargs = g_strv_length ((gchar **) args);
+ gint i, nargv = g_strv_length ((gchar **) argv);
static GdaVirtualProvider *vprovider = NULL;
GdaConnection *virtual;
GString *string;
- if (nargs < 2) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_assert (console);
+ if (nargv < 2) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing required connection names"));
return NULL;
}
/* check for connections existance */
- cs = find_connection_from_name (args[0]);
+ cs = find_connection_from_name (argv[0]);
if (cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("A connection named '%s' already exists"), args[0]);
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ _("A connection named '%s' already exists"), argv[0]);
return NULL;
}
- if (! connection_name_is_valid (args[0])) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("Connection name '%s' is invalid"), args[0]);
+ if (! connection_name_is_valid (argv[0])) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ _("Connection name '%s' is invalid"), argv[0]);
return NULL;
}
- for (i = 1; i < nargs; i++) {
- cs = find_connection_from_name (args[i]);
+ for (i = 1; i < nargv; i++) {
+ cs = find_connection_from_name (argv[i]);
if (!cs) {
GdaDataModel *src;
- src = g_hash_table_lookup (main_data->mem_data_models, args[i]);
+ src = g_hash_table_lookup (main_data->mem_data_models, argv[i]);
if (!src) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("No connection or dataset named '%s' found"), args[i]);
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ _("No connection or dataset named '%s' found"), argv[i]);
return NULL;
}
}
@@ -3779,7 +3116,7 @@ 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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Could not create virtual connection"));
return NULL;
}
@@ -3788,11 +3125,11 @@ extra_command_bind_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, c
/* add existing connections to virtual connection */
string = g_string_new (_("Bound connections are as:"));
- for (i = 1; i < nargs; i++) {
- cs = find_connection_from_name (args[i]);
+ for (i = 1; i < nargv; i++) {
+ cs = find_connection_from_name (argv[i]);
if (cs) {
if (!gda_vconnection_hub_add (GDA_VCONNECTION_HUB (virtual),
- cs->cnc, args[i], error)) {
+ cs->cnc, argv[i], error)) {
g_object_unref (virtual);
g_string_free (string, TRUE);
return NULL;
@@ -3800,13 +3137,13 @@ extra_command_bind_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, c
g_string_append (string, "\n ");
/* Translators: this string indicates that all the tables in connection named in the
* 1st "%s" will appear in the SQL namespace named as the 2nd "%s" */
- g_string_append_printf (string, _("%s in the '%s' namespace"), args[i], args[i]);
+ g_string_append_printf (string, _("%s in the '%s' namespace"), argv[i], argv[i]);
}
else {
GdaDataModel *src;
- src = g_hash_table_lookup (main_data->mem_data_models, args[i]);
+ src = g_hash_table_lookup (main_data->mem_data_models, argv[i]);
if (! gda_vconnection_data_model_add_model (GDA_VCONNECTION_DATA_MODEL (virtual),
- src, args[i], error)) {
+ src, argv[i], error)) {
g_object_unref (virtual);
g_string_free (string, TRUE);
return NULL;
@@ -3814,13 +3151,13 @@ extra_command_bind_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, c
g_string_append (string, "\n ");
/* Translators: this string indicates that the dataset named in the 1st "%s"
* will appear as the table named as the 2nd "%s" */
- g_string_append_printf (string, _("%s mapped to the %s table"), args[i],
+ g_string_append_printf (string, _("%s mapped to the %s table"), argv[i],
gda_vconnection_data_model_get_table_name (GDA_VCONNECTION_DATA_MODEL (virtual), src));
}
}
cs = g_new0 (ConnectionSetting, 1);
- cs->name = g_strdup (args[0]);
+ cs->name = g_strdup (argv[0]);
cs->cnc = virtual;
cs->parser = gda_connection_create_parser (virtual);
cs->query_buffer = NULL;
@@ -3828,28 +3165,24 @@ extra_command_bind_cnc (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, c
cs->meta_job_id = 0;
main_data->settings = g_slist_append (main_data->settings, cs);
- if (console)
- console->current = cs;
- else
- main_data->current = cs;
+ console->current = cs;
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT;
res->u.txt = string;
return res;
}
-static GdaInternalCommandResult *
-extra_command_copyright (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
- G_GNUC_UNUSED const gchar **args, G_GNUC_UNUSED OutputFormat format,
- G_GNUC_UNUSED GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_copyright (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT;
res->u.txt = g_string_new ("This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
@@ -3861,18 +3194,18 @@ extra_command_copyright (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCon
return res;
}
-static GdaInternalCommandResult *
-extra_command_option (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_option (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *oname = NULL;
const gchar *value = NULL;
- if (args[0] && *args[0]) {
- oname = args[0];
- if (args[1] && *args[1])
- value = args[1];
+ if (argv[0] && *argv[0]) {
+ oname = argv[0];
+ if (argv[1] && *argv[1])
+ value = argv[1];
}
if (oname) {
@@ -3881,18 +3214,18 @@ extra_command_option (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, con
if (value) {
if (! gda_holder_set_value_str (opt, NULL, value, error))
return NULL;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
else {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_SET;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_SET;
res->u.set = gda_set_new (NULL);
gda_set_add_holder (res->u.set, gda_holder_copy (opt));
}
}
else {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("No option named '%s'"), oname);
return NULL;
}
@@ -3927,52 +3260,36 @@ extra_command_option (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, con
gda_data_model_set_value_at (model, 2, row, value, NULL);
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
}
return res;
}
-static GdaInternalCommandResult *
-extra_command_quit (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, G_GNUC_UNUSED const gchar **args,
- G_GNUC_UNUSED OutputFormat format, G_GNUC_UNUSED GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_quit (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EXIT;
+ g_assert (console);
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EXIT;
return res;
}
-static GdaInternalCommandResult *
-extra_command_cd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_cd (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
const gchar *dir = NULL;
#define DIR_LENGTH 256
static char start_dir[DIR_LENGTH];
static gboolean init_done = FALSE;
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
+ g_assert (console);
if (!init_done) {
init_done = TRUE;
memset (start_dir, 0, DIR_LENGTH);
@@ -3986,7 +3303,7 @@ extra_command_cd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const g
pw = getpwuid (geteuid ());
if (!pw) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Could not get home directory: %s"), strerror (errno));
return NULL;
}
@@ -4001,23 +3318,23 @@ extra_command_cd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const g
}
}
- if (args[0])
- dir = args[0];
+ if (argv[0])
+ dir = argv[0];
else
dir = start_dir;
if (dir) {
if (chdir (dir) == 0) {
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
res->u.txt = g_string_new ("");
g_string_append_printf (res->u.txt, _("Working directory is now: %s"), dir);
return res;
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Could not change working directory to '%s': %s"),
dir, strerror (errno));
}
@@ -4025,45 +3342,36 @@ extra_command_cd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const g
return NULL;
}
-static GdaInternalCommandResult *
-extra_command_edit_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_edit_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
gchar *filename = NULL;
static gchar *editor_name = NULL;
- gchar *command = NULL;
+ gchar *edit_command = NULL;
gint systemres;
- GdaInternalCommandResult *res = NULL;
-
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
+ ToolCommandResult *res = NULL;
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
goto end_of_command;
}
- if (!main_data->current->query_buffer)
- main_data->current->query_buffer = g_string_new ("");
+ if (!console->current->query_buffer)
+ console->current->query_buffer = g_string_new ("");
- if (args[0] && *args[0])
- filename = (gchar *) args[0];
+ if (argv[0] && *argv[0])
+ filename = (gchar *) argv[0];
else {
/* use a temp file */
gint fd;
fd = g_file_open_tmp (NULL, &filename, error);
if (fd < 0)
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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ if (write (fd, console->current->query_buffer->str,
+ console->current->query_buffer->len) != (gint)console->current->query_buffer->len) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Could not write to temporary file '%s': %s"),
filename, strerror (errno));
close (fd);
@@ -4092,40 +3400,40 @@ extra_command_edit_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc
#else
#define SYSTEMQUOTE ""
#endif
- command = g_strdup_printf ("%s\"%s\" \"%s\"%s", SYSTEMQUOTE, editor_name, filename, SYSTEMQUOTE);
+ edit_command = g_strdup_printf ("%s\"%s\" \"%s\"%s", SYSTEMQUOTE, editor_name, filename, SYSTEMQUOTE);
#else
- command = g_strdup_printf ("exec %s '%s'", editor_name, filename);
+ edit_command = g_strdup_printf ("exec %s '%s'", editor_name, filename);
#endif
- systemres = system (command);
+ systemres = system (edit_command);
if (systemres == -1) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("could not start editor '%s'"), editor_name);
goto end_of_command;
}
else if (systemres == 127) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Could not start /bin/sh"));
goto end_of_command;
}
else {
- if (! args[0]) {
+ if (! argv[0]) {
gchar *str;
if (!g_file_get_contents (filename, &str, NULL, error))
goto end_of_command;
- g_string_assign (main_data->current->query_buffer, str);
+ g_string_assign (console->current->query_buffer, str);
g_free (str);
}
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
end_of_command:
- g_free (command);
- if (! args[0]) {
+ g_free (edit_command);
+ if (! argv[0]) {
g_unlink (filename);
g_free (filename);
}
@@ -4133,154 +3441,120 @@ extra_command_edit_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc
return res;
}
-static GdaInternalCommandResult *
-extra_command_reset_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_reset_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
-
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
+ ToolCommandResult *res = NULL;
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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 (!console->current->query_buffer)
+ console->current->query_buffer = g_string_new ("");
else
- g_string_assign (main_data->current->query_buffer, "");
+ g_string_assign (console->current->query_buffer, "");
- if (args[0]) {
+ if (argv[0]) {
const gchar *filename = NULL;
gchar *str;
- filename = args[0];
+ filename = argv[0];
if (!g_file_get_contents (filename, &str, NULL, error))
return NULL;
- g_string_assign (main_data->current->query_buffer, str);
+ g_string_assign (console->current->query_buffer, str);
g_free (str);
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
-static GdaInternalCommandResult *
-extra_command_show_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
- G_GNUC_UNUSED const gchar **args, G_GNUC_UNUSED OutputFormat format,
- GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_show_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (!main_data->current->query_buffer)
- main_data->current->query_buffer = g_string_new ("");
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT;
- res->u.txt = g_string_new (main_data->current->query_buffer->str);
+ if (!console->current->query_buffer)
+ console->current->query_buffer = g_string_new ("");
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT;
+ res->u.txt = g_string_new (console->current->query_buffer->str);
return res;
}
-static GdaInternalCommandResult *
-extra_command_exec_buffer (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_exec_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
-
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
+ ToolCommandResult *res = NULL;
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
/* load named query buffer first */
- res = extra_command_query_buffer_from_dict (console, cnc, args, format, error, data);
+ res = extra_command_query_buffer_from_dict (command, argc, argv, console, error);
if (!res)
return NULL;
- gda_internal_command_exec_result_free (res);
+ tool_command_result_free (res);
res = NULL;
}
- if (!main_data->current->query_buffer)
- main_data->current->query_buffer = g_string_new ("");
- if (*main_data->current->query_buffer->str != 0)
- res = command_execute (NULL, main_data->current->query_buffer->str,
+ if (!console->current->query_buffer)
+ console->current->query_buffer = g_string_new ("");
+ if (*console->current->query_buffer->str != 0)
+ res = command_execute (console, console->current->query_buffer->str,
GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
else {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
return res;
}
-static GdaInternalCommandResult *
-extra_command_write_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_write_buffer (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
-
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
+ ToolCommandResult *res = NULL;
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (!console->current->query_buffer)
+ console->current->query_buffer = g_string_new ("");
+ if (!argv[0])
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ if (g_file_set_contents (argv[0], console->current->query_buffer->str, -1, error)) {
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
}
@@ -4288,31 +3562,23 @@ extra_command_write_buffer (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cn
}
#define QUERY_BUFFERS_TABLE_NAME "gda_sql_query_buffers"
-#define QUERY_BUFFERS_TABLE_SELECT \
+#define QUERY_BUFFERS_TABLE_SELECT \
"SELECT name, sql FROM " QUERY_BUFFERS_TABLE_NAME " ORDER BY name"
-#define QUERY_BUFFERS_TABLE_SELECT_ONE \
+#define QUERY_BUFFERS_TABLE_SELECT_ONE \
"SELECT sql FROM " QUERY_BUFFERS_TABLE_NAME " WHERE name = ##name::string"
-#define QUERY_BUFFERS_TABLE_DELETE \
+#define QUERY_BUFFERS_TABLE_DELETE \
"DELETE FROM " QUERY_BUFFERS_TABLE_NAME " WHERE name = ##name::string"
-static GdaInternalCommandResult *
-extra_command_query_buffer_list_dict (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, G_GNUC_UNUSED const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_query_buffer_list_dict (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
GdaDataModel *retmodel;
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
@@ -4324,16 +3590,16 @@ extra_command_query_buffer_list_dict (SqlConsole *console, G_GNUC_UNUSED GdaConn
gda_data_model_set_column_title (retmodel, 2, _("SQL"));
GdaMetaStore *mstore;
- mstore = gda_connection_get_meta_store (main_data->current->cnc);
+ mstore = gda_connection_get_meta_store (console->current->cnc);
/* Use tools favorites */
- if (! main_data->current->favorites)
- main_data->current->favorites = tools_favorites_new (mstore);
+ if (! console->current->favorites)
+ console->current->favorites = gda_tools_favorites_new (mstore);
GSList *favlist, *list;
GError *lerror = NULL;
- favlist = tools_favorites_list (main_data->current->favorites, 0, TOOLS_FAVORITES_QUERIES,
- ORDER_KEY_QUERIES, &lerror);
+ favlist = gda_tools_favorites_list (console->current->favorites, 0, GDA_TOOLS_FAVORITES_QUERIES,
+ ORDER_KEY_QUERIES, &lerror);
if (lerror) {
g_propagate_error (error, lerror);
g_object_unref (retmodel);
@@ -4359,18 +3625,18 @@ extra_command_query_buffer_list_dict (SqlConsole *console, G_GNUC_UNUSED GdaConn
continue;
cleanloop:
gda_value_free (value);
- tools_favorites_free_list (favlist);
+ gda_tools_favorites_free_list (favlist);
g_object_unref (retmodel);
return NULL;
}
if (favlist)
- tools_favorites_free_list (favlist);
+ gda_tools_favorites_free_list (favlist);
/* Use query buffer which used to be stored differently in previous versions of GdaSql:
* in the "gda_sql_query_buffers" table */
GdaStatement *sel_stmt = NULL;
GdaDataModel *model;
- sel_stmt = gda_sql_parser_parse_string (main_data->current->parser,
+ sel_stmt = gda_sql_parser_parse_string (console->current->parser,
QUERY_BUFFERS_TABLE_SELECT, NULL, NULL);
g_assert (sel_stmt);
GdaConnection *store_cnc;
@@ -4399,118 +3665,102 @@ extra_command_query_buffer_list_dict (SqlConsole *console, G_GNUC_UNUSED GdaConn
g_object_unref (model);
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = retmodel;
return res;
}
-static GdaInternalCommandResult *
-extra_command_query_buffer_to_dict (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_query_buffer_to_dict (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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 (!console->current->query_buffer)
+ console->current->query_buffer = g_string_new ("");
- if (*main_data->current->query_buffer->str != 0) {
+ if (*console->current->query_buffer->str != 0) {
/* find a suitable name */
gchar *qname;
- if (args[0] && *args[0])
- qname = g_strdup ((gchar *) args[0]);
+ if (argv[0] && *argv[0])
+ qname = g_strdup ((gchar *) argv[0]);
else {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing query buffer name"));
return NULL;
}
/* Use tools favorites */
GdaMetaStore *mstore;
- mstore = gda_connection_get_meta_store (main_data->current->cnc);
- if (! main_data->current->favorites)
- main_data->current->favorites = tools_favorites_new (mstore);
+ mstore = gda_connection_get_meta_store (console->current->cnc);
+ if (! console->current->favorites)
+ console->current->favorites = gda_tools_favorites_new (mstore);
ToolsFavoritesAttributes att;
att.id = -1;
- att.type = TOOLS_FAVORITES_QUERIES;
+ att.type = GDA_TOOLS_FAVORITES_QUERIES;
att.name = qname;
att.descr = NULL;
- att.contents = main_data->current->query_buffer->str;
+ att.contents = console->current->query_buffer->str;
- if (! tools_favorites_add (main_data->current->favorites, 0,
- &att, ORDER_KEY_QUERIES, G_MAXINT, error)) {
+ if (! gda_tools_favorites_add (console->current->favorites, 0,
+ &att, ORDER_KEY_QUERIES, G_MAXINT, error)) {
g_free (qname);
return NULL;
}
g_free (qname);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Query buffer is empty"));
return res;
}
-static GdaInternalCommandResult *
-extra_command_query_buffer_from_dict (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
- const gchar **args, G_GNUC_UNUSED OutputFormat format,
- GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_query_buffer_from_dict (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
-
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
+ ToolCommandResult *res = NULL;
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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 (!console->current->query_buffer)
+ console->current->query_buffer = g_string_new ("");
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
/* Use tools favorites */
GdaMetaStore *mstore;
- mstore = gda_connection_get_meta_store (main_data->current->cnc);
- if (! main_data->current->favorites)
- main_data->current->favorites = tools_favorites_new (mstore);
+ mstore = gda_connection_get_meta_store (console->current->cnc);
+ if (! console->current->favorites)
+ console->current->favorites = gda_tools_favorites_new (mstore);
ToolsFavoritesAttributes att;
gint favid;
- favid = tools_favorites_find_by_name (main_data->current->favorites, 0, TOOLS_FAVORITES_QUERIES,
- args[0], &att, NULL);
+ favid = gda_tools_favorites_find_by_name (console->current->favorites, 0,
+ GDA_TOOLS_FAVORITES_QUERIES,
+ argv[0], &att, NULL);
if (favid >= 0) {
- g_string_assign (main_data->current->query_buffer, att.contents);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ g_string_assign (console->current->query_buffer, att.contents);
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
else {
/* query retrieval */
@@ -4520,16 +3770,16 @@ extra_command_query_buffer_from_dict (SqlConsole *console, G_GNUC_UNUSED GdaConn
const GValue *cvalue;
GError *lerror = NULL;
- g_set_error (&lerror, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (&lerror, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Could not find favorite"));
if (!sel_stmt) {
- sel_stmt = gda_sql_parser_parse_string (main_data->current->parser,
+ sel_stmt = gda_sql_parser_parse_string (console->current->parser,
QUERY_BUFFERS_TABLE_SELECT_ONE, NULL, NULL);
g_assert (sel_stmt);
g_assert (gda_statement_get_parameters (sel_stmt, &sel_params, NULL));
}
- if (! gda_set_set_holder_value (sel_params, error, "name", args[0])) {
+ if (! gda_set_set_holder_value (sel_params, error, "name", argv[0])) {
g_propagate_error (error, lerror);
return NULL;
}
@@ -4544,73 +3794,64 @@ extra_command_query_buffer_from_dict (SqlConsole *console, G_GNUC_UNUSED GdaConn
if ((gda_data_model_get_n_rows (model) == 1) &&
(cvalue = gda_data_model_get_value_at (model, 0, 0, NULL))) {
- g_string_assign (main_data->current->query_buffer, g_value_get_string (cvalue));
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ g_string_assign (console->current->query_buffer, g_value_get_string (cvalue));
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
g_object_unref (model);
}
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing query buffer name"));
return res;
}
-static GdaInternalCommandResult *
-extra_command_query_buffer_delete_dict (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc,
- const gchar **args, G_GNUC_UNUSED OutputFormat format,
- GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_query_buffer_delete_dict (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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 (!console->current->query_buffer)
+ console->current->query_buffer = g_string_new ("");
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
/* Use tools favorites */
GdaMetaStore *mstore;
- mstore = gda_connection_get_meta_store (main_data->current->cnc);
- if (! main_data->current->favorites)
- main_data->current->favorites = tools_favorites_new (mstore);
+ mstore = gda_connection_get_meta_store (console->current->cnc);
+ if (! console->current->favorites)
+ console->current->favorites = gda_tools_favorites_new (mstore);
ToolsFavoritesAttributes att;
GError *lerror = NULL;
att.id = -1;
- att.type = TOOLS_FAVORITES_QUERIES;
- att.name = (gchar*) args[0];
+ att.type = GDA_TOOLS_FAVORITES_QUERIES;
+ att.name = (gchar*) argv[0];
att.descr = NULL;
att.contents = NULL;
- if (! tools_favorites_delete (main_data->current->favorites, 0,
- &att, &lerror)) {
+ if (! gda_tools_favorites_delete (console->current->favorites, 0,
+ &att, &lerror)) {
/* query retrieval */
static GdaStatement *del_stmt = NULL;
static GdaSet *del_params = NULL;
if (!del_stmt) {
- del_stmt = gda_sql_parser_parse_string (main_data->current->parser,
+ del_stmt = gda_sql_parser_parse_string (console->current->parser,
QUERY_BUFFERS_TABLE_DELETE, NULL, NULL);
g_assert (del_stmt);
g_assert (gda_statement_get_parameters (del_stmt, &del_params, NULL));
}
- if (! gda_set_set_holder_value (del_params, NULL, "name", args[0])) {
+ if (! gda_set_set_holder_value (del_params, NULL, "name", argv[0])) {
g_propagate_error (error, lerror);
return NULL;
}
@@ -4625,29 +3866,36 @@ extra_command_query_buffer_delete_dict (SqlConsole *console, G_GNUC_UNUSED GdaCo
return NULL;
}
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing query buffer name"));
return res;
}
static void foreach_param_set (const gchar *pname, GdaHolder *param, GdaDataModel *model);
-static GdaInternalCommandResult *
-extra_command_set (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_set (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *pname = NULL;
const gchar *value = NULL;
- if (args[0] && *args[0]) {
- pname = args[0];
- if (args[1] && *args[1])
- value = args[1];
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ "%s", _("No current connection"));
+ return NULL;
+ }
+
+ if (argv[0] && *argv[0]) {
+ pname = argv[0];
+ if (argv[1] && *argv[1])
+ value = argv[1];
}
if (pname) {
@@ -4664,20 +3912,21 @@ extra_command_set (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const
GdaDataHandler *dh;
GValue *gvalue;
- prov = gda_connection_get_provider (cnc);
- dh = gda_server_provider_get_data_handler_g_type (prov, cnc,
- gda_holder_get_g_type (param));
+ prov = gda_connection_get_provider (console->current->cnc);
+ dh = gda_server_provider_get_data_handler_g_type (prov,
+ console->current->cnc,
+ gda_holder_get_g_type (param));
gvalue = gda_data_handler_get_value_from_str (dh, value, gda_holder_get_g_type (param));
if (! gda_holder_take_value (param, gvalue, error))
return NULL;
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
else {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_SET;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_SET;
res->u.set = gda_set_new (NULL);
gda_set_add_holder (res->u.set, gda_holder_copy (param));
}
@@ -4689,11 +3938,11 @@ extra_command_set (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const
value = NULL;
param = gda_holder_new_string (pname, value);
g_hash_table_insert (main_data->parameters, g_strdup (pname), param);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("No parameter named '%s' defined"), pname);
}
}
@@ -4707,8 +3956,8 @@ extra_command_set (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const
gda_data_model_set_column_title (model, 1, _("Value"));
g_object_set_data (G_OBJECT (model), "name", _("List of defined parameters"));
g_hash_table_foreach (main_data->parameters, (GHFunc) foreach_param_set, model);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
}
@@ -4734,11 +3983,11 @@ foreach_param_set (const gchar *pname, GdaHolder *param, GdaDataModel *model)
}
static void foreach_data_model (const gchar *name, GdaDataModel *keptmodel, GdaDataModel *model);
-static GdaInternalCommandResult *
-extra_command_data_sets_list (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_data_sets_list (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
GdaDataModel *model;
model = gda_data_model_array_new_with_g_types (2,
G_TYPE_STRING,
@@ -4747,8 +3996,8 @@ extra_command_data_sets_list (G_GNUC_UNUSED SqlConsole *console, GdaConnection *
gda_data_model_set_column_title (model, 1, _("dimensions (columns x rows)"));
g_object_set_data (G_OBJECT (model), "name", _("List of kept data"));
g_hash_table_foreach (main_data->mem_data_models, (GHFunc) foreach_data_model, model);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
@@ -4775,21 +4024,21 @@ foreach_data_model (const gchar *name, GdaDataModel *keptmodel, GdaDataModel *mo
gda_value_free (value);
}
-static GdaInternalCommandResult *
-extra_command_data_set_grep (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_data_set_grep (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *model_name = NULL;
const gchar *pattern = NULL;
- if (args[0] && *args[0]) {
- model_name = args[0];
- if (args[1] && *args[1])
- pattern = args[1];
+ if (argv[0] && *argv[0]) {
+ model_name = argv[0];
+ if (argv[1] && *argv[1])
+ pattern = argv[1];
}
if (!model_name) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing argument"));
return NULL;
}
@@ -4799,7 +4048,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Could not find dataset named '%s'"), model_name);
return NULL;
}
@@ -4891,25 +4140,25 @@ extra_command_data_set_grep (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
}
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
-static GdaInternalCommandResult *
-extra_command_data_set_show (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_data_set_show (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *model_name = NULL;
- if (args[0] && *args[0])
- model_name = args[0];
+ if (argv[0] && *argv[0])
+ model_name = argv[0];
if (!model_name) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing argument"));
return NULL;
}
@@ -4917,17 +4166,17 @@ extra_command_data_set_show (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
GdaDataModel *src;
src = g_hash_table_lookup (main_data->mem_data_models, model_name);
if (!src) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Could not find dataset named '%s'"), model_name);
return NULL;
}
- if (args[1] && *args[1]) {
+ if (argv[1] && *argv[1]) {
GArray *cols;
gint i;
cols = g_array_new (FALSE, FALSE, sizeof (gint));
- for (i = 1; args[i] && *args[i]; i++) {
- const gchar *cname = args[i];
+ for (i = 1; argv[i] && *argv[i]; i++) {
+ const gchar *cname = argv[i];
gint pos;
pos = gda_data_model_get_column_index (src, cname);
if (pos < 0) {
@@ -4938,7 +4187,7 @@ extra_command_data_set_show (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
pos = (gint) li;
}
if (pos < 0) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Could not identify column '%s'"), cname);
g_array_free (cols, TRUE);
return NULL;
@@ -4951,73 +4200,73 @@ extra_command_data_set_show (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
error);
g_array_free (cols, TRUE);
if (model) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
}
else
return NULL;
}
else {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = g_object_ref (src);
}
return res;
}
-static GdaInternalCommandResult *
-extra_command_data_set_rm (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_data_set_rm (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
guint i;
- if (!args[0] || !(*args[0])) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (!argv[0] || !(*argv[0])) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing argument"));
return NULL;
}
- for (i = 0; args[i]; i++) {
+ for (i = 0; argv[i]; i++) {
GdaDataModel *src;
- src = g_hash_table_lookup (main_data->mem_data_models, args[i]);
+ src = g_hash_table_lookup (main_data->mem_data_models, argv[i]);
if (!src) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("Could not find dataset named '%s'"), args[i]);
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ _("Could not find dataset named '%s'"), argv[i]);
return NULL;
}
}
- for (i = 0; args[i]; i++)
- g_hash_table_remove (main_data->mem_data_models, args[i]);
+ for (i = 0; argv[i]; i++)
+ g_hash_table_remove (main_data->mem_data_models, argv[i]);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
-static GdaInternalCommandResult *
-extra_command_data_set_import (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_data_set_import (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *type = NULL, *file_name = NULL;
- if (args[0] && *args[0]) {
- type = args[0];
+ if (argv[0] && *argv[0]) {
+ type = argv[0];
if (g_ascii_strcasecmp (type, "csv")) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("Unknown import format '%s'"), args[0]);
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ _("Unknown import format '%s'"), argv[0]);
return NULL;
}
- if (args[1] && *args[1])
- file_name = args[1];
+ if (argv[1] && *argv[1])
+ file_name = argv[1];
}
if (!type || !file_name) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing argument"));
return NULL;
}
@@ -5029,7 +4278,7 @@ extra_command_data_set_import (G_GNUC_UNUSED SqlConsole *console, GdaConnection
if (impopt)
g_object_unref (impopt);
if (!model) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Could not import file '%s'"), file_name);
return NULL;
}
@@ -5041,27 +4290,27 @@ extra_command_data_set_import (G_GNUC_UNUSED SqlConsole *console, GdaConnection
}
g_hash_table_insert (main_data->mem_data_models, g_strdup (LAST_DATA_MODEL_NAME), model);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
-static GdaInternalCommandResult *
-extra_command_data_set_move (G_GNUC_UNUSED SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_data_set_move (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *old_name = NULL;
const gchar *new_name = NULL;
- if (args[0] && *args[0]) {
- old_name = args[0];
- if (args[1] && *args[1])
- new_name = args[1];
+ if (argv[0] && *argv[0]) {
+ old_name = argv[0];
+ if (argv[1] && *argv[1])
+ new_name = argv[1];
}
if (!old_name || !*old_name || !new_name || !*new_name) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing argument"));
return NULL;
}
@@ -5070,7 +4319,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Could not find dataset named '%s'"), old_name);
return NULL;
}
@@ -5079,8 +4328,8 @@ extra_command_data_set_move (G_GNUC_UNUSED SqlConsole *console, GdaConnection *c
if (strcmp (old_name, LAST_DATA_MODEL_NAME))
g_hash_table_remove (main_data->mem_data_models, old_name);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
@@ -5123,7 +4372,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing foreign key declaration specification"));
return NULL;
}
@@ -5240,7 +4489,7 @@ parse_fk_decl_spec (const gchar *spec, gboolean columns_required, GError **error
onerror:
fk_decl_data_free (decldata);
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Malformed foreign key declaration specification"));
return NULL;
}
@@ -5272,34 +4521,34 @@ fk_decl_analyse_table_name (const gchar *table, GdaMetaStore *mstore,
g_strfreev (id_array);
}
else {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Malformed table name specification '%s'"), table);
return FALSE;
}
return TRUE;
}
-static GdaInternalCommandResult *
-extra_command_declare_fk (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_declare_fk (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
FkDeclData *decldata;
GdaMetaStore *mstore;
gchar *catalog = NULL, *schema = NULL, *table = NULL;
gchar *ref_catalog = NULL, *ref_schema = NULL, *ref_table = NULL;
- mstore = gda_connection_get_meta_store (main_data->current->cnc);
- if (! (decldata = parse_fk_decl_spec (args[0], TRUE, error)))
+ mstore = gda_connection_get_meta_store (console->current->cnc);
+ if (! (decldata = parse_fk_decl_spec (argv[0], TRUE, error)))
return NULL;
/* table name */
@@ -5356,37 +4605,37 @@ extra_command_declare_fk (SqlConsole *console, GdaConnection *cnc,
fk_decl_data_free (decldata);
if (allok) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing foreign key name argument"));
return res;
}
-static GdaInternalCommandResult *
-extra_command_undeclare_fk (SqlConsole *console, GdaConnection *cnc,
- const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_undeclare_fk (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
- if (!main_data->current) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
FkDeclData *decldata;
GdaMetaStore *mstore;
gchar *catalog = NULL, *schema = NULL, *table = NULL;
gchar *ref_catalog = NULL, *ref_schema = NULL, *ref_table = NULL;
- mstore = gda_connection_get_meta_store (main_data->current->cnc);
- if (! (decldata = parse_fk_decl_spec (args[0], FALSE, error)))
+ mstore = gda_connection_get_meta_store (console->current->cnc);
+ if (! (decldata = parse_fk_decl_spec (argv[0], FALSE, error)))
return NULL;
/* table name */
@@ -5431,18 +4680,18 @@ extra_command_undeclare_fk (SqlConsole *console, GdaConnection *cnc,
fk_decl_data_free (decldata);
if (allok) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing foreign key name argument"));
return res;
}
static const GValue *
-get_table_value_at_cell (GdaConnection *cnc, GError **error, G_GNUC_UNUSED MainData *data,
+get_table_value_at_cell (SqlConsole *console, GError **error,
const gchar *table, const gchar *column, const gchar *row_cond,
GdaDataModel **out_model_of_value)
{
@@ -5454,21 +4703,21 @@ get_table_value_at_cell (GdaConnection *cnc, GError **error, G_GNUC_UNUSED MainD
gchar *sql;
gchar *rtable, *rcolumn;
- rtable = gda_sql_identifier_quote (table, cnc, NULL, FALSE, FALSE);
- rcolumn = gda_sql_identifier_quote (column, cnc, NULL, FALSE, FALSE);
+ rtable = gda_sql_identifier_quote (table, console->current->cnc, NULL, FALSE, FALSE);
+ rcolumn = gda_sql_identifier_quote (column, console->current->cnc, NULL, FALSE, FALSE);
sql = g_strdup_printf ("SELECT %s FROM %s WHERE %s", rcolumn, rtable, row_cond);
g_free (rtable);
g_free (rcolumn);
GdaStatement *stmt;
const gchar *remain;
- stmt = gda_sql_parser_parse_string (main_data->current->parser, sql, &remain, error);
+ stmt = gda_sql_parser_parse_string (console->current->parser, sql, &remain, error);
if (!stmt) {
g_free (sql);
return NULL;
}
if (remain) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Wrong row condition"));
g_free (sql);
return NULL;
@@ -5476,13 +4725,13 @@ get_table_value_at_cell (GdaConnection *cnc, GError **error, G_GNUC_UNUSED MainD
g_object_unref (stmt);
/* execute statement */
- GdaInternalCommandResult *tmpres;
- tmpres = execute_external_command (NULL, sql, GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
+ ToolCommandResult *tmpres;
+ tmpres = execute_sql_command (NULL, sql, GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
g_free (sql);
if (!tmpres)
return NULL;
gboolean errorset = FALSE;
- if (tmpres->type == GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL) {
+ if (tmpres->type == TOOL_COMMAND_RESULT_DATA_MODEL) {
GdaDataModel *model;
model = tmpres->u.model;
if (gda_data_model_get_n_rows (model) == 1) {
@@ -5493,70 +4742,62 @@ get_table_value_at_cell (GdaConnection *cnc, GError **error, G_GNUC_UNUSED MainD
*out_model_of_value = g_object_ref (model);
}
}
- gda_internal_command_exec_result_free (tmpres);
+ tool_command_result_free (tmpres);
if (!retval && !errorset)
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("No unique row identified"));
return retval;
}
-static GdaInternalCommandResult *
-extra_command_set2 (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_set2 (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *pname = NULL;
const gchar *filename = NULL;
const gchar *table = NULL;
const gchar *column = NULL;
const gchar *row_cond = NULL;
- gint whichargs = 0;
-
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- if (!cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ gint whichargv = 0;
+
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
- if (args[0] && *args[0]) {
- pname = args[0];
- if (args[1] && *args[1]) {
- if (args[2] && *args[2]) {
- table = args[1];
- column = args[2];
- if (args[3] && *args[3]) {
- row_cond = args[3];
- if (args [4]) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (argv[0] && *argv[0]) {
+ pname = argv[0];
+ if (argv[1] && *argv[1]) {
+ if (argv[2] && *argv[2]) {
+ table = argv[1];
+ column = argv[2];
+ if (argv[3] && *argv[3]) {
+ row_cond = argv[3];
+ if (argv [4]) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Too many arguments"));
return NULL;
}
- whichargs = 1;
+ whichargv = 1;
}
}
else {
- filename = args[1];
- whichargs = 2;
+ filename = argv[1];
+ whichargv = 2;
}
}
}
- if (whichargs == 1) {
+ if (whichargv == 1) {
/* param from an existing blob */
const GValue *value;
GdaDataModel *model = NULL;
- value = get_table_value_at_cell (cnc, error, data, table, column, row_cond, &model);
+ value = get_table_value_at_cell (console, error, table,
+ column, row_cond, &model);
if (value) {
GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
if (param)
@@ -5565,13 +4806,13 @@ extra_command_set2 (SqlConsole *console, GdaConnection *cnc, const gchar **args,
param = gda_holder_new (G_VALUE_TYPE (value));
g_assert (gda_holder_set_value (param, value, NULL));
g_hash_table_insert (main_data->parameters, g_strdup (pname), param);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
if (model)
g_object_unref (model);
}
- else if (whichargs == 2) {
+ else if (whichargv == 2) {
/* param from filename */
GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
GValue *bvalue;
@@ -5582,25 +4823,25 @@ extra_command_set2 (SqlConsole *console, GdaConnection *cnc, const gchar **args,
bvalue = gda_value_new_blob_from_file (filename);
g_assert (gda_holder_take_value (param, bvalue, NULL));
g_hash_table_insert (main_data->parameters, g_strdup (pname), param);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Wrong number of arguments"));
return res;
}
-static GdaInternalCommandResult *
-extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_pivot (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
ConnectionSetting *cs;
cs = get_current_connection_settings (console);
if (!cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
@@ -5609,22 +4850,22 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
const gchar *row_fields = NULL;
const gchar *column_fields = NULL;
- if (args[0] && *args[0]) {
- select = args[0];
- if (args[1] && *args[1]) {
- row_fields = args [1];
- if (args[2] && *args[2])
- column_fields = args[2];
+ if (argv[0] && *argv[0]) {
+ select = argv[0];
+ if (argv[1] && *argv[1]) {
+ row_fields = argv [1];
+ if (argv[2] && *argv[2])
+ column_fields = argv[2];
}
}
if (!select) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing data on which to operate"));
return NULL;
}
if (!row_fields) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing row fields specifications"));
return NULL;
}
@@ -5633,16 +4874,16 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
/* execute SELECT */
gboolean was_in_trans;
- GdaInternalCommandResult *tmpres;
+ ToolCommandResult *tmpres;
was_in_trans = gda_connection_get_transaction_status (cs->cnc) ? TRUE : FALSE;
tmpres = command_execute (console, select, GDA_STATEMENT_MODEL_CURSOR_FORWARD, error);
if (!tmpres)
return NULL;
- if (tmpres->type != GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL) {
- gda_internal_command_exec_result_free (tmpres);
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (tmpres->type != TOOL_COMMAND_RESULT_DATA_MODEL) {
+ tool_command_result_free (tmpres);
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Wrong SELECT argument"));
return NULL;
}
@@ -5651,7 +4892,7 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
gdouble etime = 0.;
//g_object_get ((GObject*) tmpres->u.model, "execution-delay", &etime, NULL);
pivot = (GdaDataPivot*) gda_data_pivot_new (tmpres->u.model);
- gda_internal_command_exec_result_free (tmpres);
+ tool_command_result_free (tmpres);
if (! gda_data_pivot_add_field (pivot, GDA_DATA_PIVOT_FIELD_ROW,
row_fields, NULL, error)) {
@@ -5670,8 +4911,8 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
timer = g_timer_new ();
gint i;
- for (i = 3; args[i] && *args[i]; i++) {
- const gchar *df = args[i];
+ for (i = 3; argv[i] && *argv[i]; i++) {
+ const gchar *df = argv[i];
const gchar *alias = "count";
GdaDataPivotAggregate agg = GDA_DATA_PIVOT_COUNT;
if (*df == '[') {
@@ -5680,7 +4921,7 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
if (!*tmp) {
g_timer_destroy (timer);
g_object_unref (pivot);
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Wrong data field argument"));
return NULL;
}
@@ -5708,7 +4949,7 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
else {
g_timer_destroy (timer);
g_object_unref (pivot);
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Wrong data field argument"));
return NULL;
}
@@ -5735,30 +4976,30 @@ extra_command_pivot (SqlConsole *console, GdaConnection *cnc, const gchar **args
g_timer_destroy (timer);
//g_object_set (pivot, "execution-delay", etime, NULL);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->was_in_transaction_before_exec = was_in_trans;
res->u.model = (GdaDataModel*) pivot;
return res;
}
#ifdef HAVE_LDAP
-static GdaInternalCommandResult *
-extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_ldap_search (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
ConnectionSetting *cs;
GdaDataModel *model, *wrapper;
cs = get_current_connection_settings (console);
if (!cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Connection is not an LDAP connection"));
return NULL;
}
@@ -5769,10 +5010,10 @@ extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc, const gchar
const gchar *base_dn = NULL;
GdaLdapSearchScope lscope = GDA_LDAP_SEARCH_SUBTREE;
- if (args[0] && *args[0]) {
- filter = args[0];
- if (args[1]) {
- scope = args [1];
+ if (argv[0] && *argv[0]) {
+ filter = argv[0];
+ if (argv[1]) {
+ scope = argv [1];
if (!g_ascii_strcasecmp (scope, "base"))
lscope = GDA_LDAP_SEARCH_BASE;
else if (!g_ascii_strcasecmp (scope, "onelevel"))
@@ -5780,17 +5021,17 @@ 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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Unknown search scope '%s'"), scope);
return NULL;
}
- if (args[2])
- base_dn = args[2];
+ if (argv[2])
+ base_dn = argv[2];
}
}
if (!filter) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing filter which to operate"));
return NULL;
}
@@ -5835,28 +5076,27 @@ extra_command_ldap_search (SqlConsole *console, GdaConnection *cnc, const gchar
}
}
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = wrapper;
return res;
}
-static GdaInternalCommandResult *
-extra_command_ldap_mv (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_ldap_mv (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
ConnectionSetting *cs;
- GdaDataModel *model, *wrapper;
cs = get_current_connection_settings (console);
if (!cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Connection is not an LDAP connection"));
return NULL;
}
@@ -5864,21 +5104,21 @@ extra_command_ldap_mv (SqlConsole *console, GdaConnection *cnc, const gchar **ar
const gchar *current_dn = NULL;
const gchar *new_dn = NULL;
- if (args[0] && *args[0]) {
- current_dn = args[0];
- if (args[1])
- new_dn = args [1];
+ if (argv[0] && *argv[0]) {
+ current_dn = argv[0];
+ if (argv[1])
+ new_dn = argv [1];
}
if (!current_dn || !new_dn) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing current DN or new DN specification"));
return NULL;
}
if (gda_ldap_rename_entry (GDA_LDAP_CONNECTION (cs->cnc), current_dn, new_dn, error)) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
else
@@ -5935,22 +5175,21 @@ parse_ldap_attr (const gchar *spec, gboolean value_req,
}
}
-static GdaInternalCommandResult *
-extra_command_ldap_mod (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_ldap_mod (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
ConnectionSetting *cs;
- GdaDataModel *model, *wrapper;
cs = get_current_connection_settings (console);
if (!cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Connection is not an LDAP connection"));
return NULL;
}
@@ -5958,19 +5197,19 @@ extra_command_ldap_mod (SqlConsole *console, GdaConnection *cnc, const gchar **a
const gchar *dn = NULL;
const gchar *op = NULL;
GdaLdapModificationType optype;
- if (args[0] && *args[0]) {
- dn = args[0];
- if (args[1])
- op = args [1];
+ if (argv[0] && *argv[0]) {
+ dn = argv[0];
+ if (argv[1])
+ op = argv [1];
}
if (!dn) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing DN of LDAP entry"));
return NULL;
}
if (!op) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing operation to perform on LDAP entry's attributes"));
return NULL;
}
@@ -5982,7 +5221,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, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
_("Unknown operation '%s' to perform on LDAP entry's attributes"), op);
return NULL;
}
@@ -5991,27 +5230,27 @@ extra_command_ldap_mod (SqlConsole *console, GdaConnection *cnc, const gchar **a
guint i;
entry = gda_ldap_entry_new (dn);
- for (i = 2; args[i]; i++) {
+ for (i = 2; argv[i]; i++) {
gchar *att_name;
GValue *att_value;
gboolean vreq = TRUE;
if (optype == GDA_LDAP_MODIFICATION_ATTR_DEL)
vreq = FALSE;
- if (parse_ldap_attr (args[i], vreq, &att_name, &att_value)) {
+ if (parse_ldap_attr (argv[i], vreq, &att_name, &att_value)) {
gda_ldap_entry_add_attribute (entry, TRUE, att_name, 1, &att_value);
g_free (att_name);
gda_value_free (att_value);
}
else {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("Wrong attribute value specification"), args[i]);
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ _("Wrong attribute value specification '%s'"), argv[i]);
return NULL;
}
}
if (gda_ldap_modify_entry (GDA_LDAP_CONNECTION (cs->cnc), optype, entry, NULL, error)) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
gda_ldap_entry_free (entry);
return res;
@@ -6030,22 +5269,22 @@ att_row_cmp (AttRow *r1, AttRow *r2)
return strcmp (g_value_get_string (r1->attr_name), g_value_get_string (r2->attr_name));
}
-static GdaInternalCommandResult *
-extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
ConnectionSetting *cs;
cs = get_current_connection_settings (console);
if (!cs) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Connection is not an LDAP connection"));
return NULL;
}
@@ -6058,22 +5297,22 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
* 3 => show all set attributes only
*/
- if (!args[0] || !*args[0]) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (!argv[0] || !*argv[0]) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing DN (Distinguished name) argument"));
return NULL;
}
- dn = args[0];
- if (args [1] && *args[1]) {
- if (!g_ascii_strcasecmp (args [1], "all"))
+ dn = argv[0];
+ if (argv [1] && *argv[1]) {
+ if (!g_ascii_strcasecmp (argv [1], "all"))
options = 1;
- else if (!g_ascii_strcasecmp (args [1], "unset"))
+ else if (!g_ascii_strcasecmp (argv [1], "unset"))
options = 2;
- else if (!g_ascii_strcasecmp (args [1], "set"))
+ else if (!g_ascii_strcasecmp (argv [1], "set"))
options = 3;
else {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("Unknown '%s' argument"), args[1]);
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ _("Unknown '%s' argument"), argv[1]);
return NULL;
}
}
@@ -6083,7 +5322,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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("Could not find entry with DN '%s'"), dn);
return NULL;
}
@@ -6165,7 +5404,7 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
continue;
if (attrs_hash && !g_hash_table_lookup (attrs_hash, def->name))
- continue;
+ continue;
AttRow *row;
row = g_hash_table_lookup (rows_hash, def->name);
@@ -6227,8 +5466,8 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
gda_ldap_entry_free (entry);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
@@ -6236,55 +5475,46 @@ extra_command_ldap_descr (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaCo
#endif /* HAVE_LDAP */
-static GdaInternalCommandResult *
-extra_command_export (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_export (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *pname = NULL;
const gchar *table = NULL;
const gchar *column = NULL;
const gchar *filename = NULL;
const gchar *row_cond = NULL;
- gint whichargs = 0;
-
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- if (!cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ gint whichargv = 0;
+
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
- if (args[0] && *args[0]) {
- table = args[0];
- pname = args[0];
- if (args[1] && *args[1]) {
- column = args[1];
- filename = args[1];
- if (args[2] && *args[2]) {
- row_cond = args[2];
- if (args[3] && *args[3]) {
- filename = args[3];
- if (args [4]) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (argv[0] && *argv[0]) {
+ table = argv[0];
+ pname = argv[0];
+ if (argv[1] && *argv[1]) {
+ column = argv[1];
+ filename = argv[1];
+ if (argv[2] && *argv[2]) {
+ row_cond = argv[2];
+ if (argv[3] && *argv[3]) {
+ filename = argv[3];
+ if (argv [4]) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Too many arguments"));
return NULL;
}
else
- whichargs = 1;
+ whichargv = 1;
}
}
else {
- whichargs = 2;
+ whichargv = 2;
}
}
}
@@ -6292,18 +5522,19 @@ extra_command_export (SqlConsole *console, GdaConnection *cnc, const gchar **arg
const GValue *value = NULL;
GdaDataModel *model = NULL;
- if (whichargs == 1)
- value = get_table_value_at_cell (cnc, error, data, table, column, row_cond, &model);
- else if (whichargs == 2) {
+ if (whichargv == 1)
+ value = get_table_value_at_cell (console, error, table, column,
+ row_cond, &model);
+ else if (whichargv == 2) {
GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
if (!pname)
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("No parameter named '%s' defined"), pname);
else
value = gda_holder_get_value (param);
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Wrong number of arguments"));
if (value) {
@@ -6315,7 +5546,7 @@ 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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Could not write file"));
else
done = TRUE;
@@ -6329,7 +5560,7 @@ 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, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Could not write file"));
else
done = TRUE;
@@ -6345,8 +5576,8 @@ extra_command_export (SqlConsole *console, GdaConnection *cnc, const gchar **arg
}
if (done) {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
}
if (model)
@@ -6357,32 +5588,32 @@ extra_command_export (SqlConsole *console, GdaConnection *cnc, const gchar **arg
}
-static GdaInternalCommandResult *
-extra_command_unset (G_GNUC_UNUSED SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_unset (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
+ ToolCommandResult *res = NULL;
const gchar *pname = NULL;
- if (args[0] && *args[0])
- pname = args[0];
+ if (argv[0] && *argv[0])
+ pname = argv[0];
if (pname) {
GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
if (param) {
g_hash_table_remove (main_data->parameters, pname);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
_("No parameter named '%s' defined"), pname);
}
else {
g_hash_table_destroy (main_data->parameters);
main_data->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
}
return res;
@@ -6468,38 +5699,30 @@ create_graph_from_meta_struct (G_GNUC_UNUSED GdaConnection *cnc, GdaMetaStruct *
return result;
}
-static GdaInternalCommandResult *
-extra_command_graph (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_graph (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
gchar *result;
GdaMetaStruct *mstruct;
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
- if (!cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ if (!console->current) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
- mstruct = gda_internal_command_build_meta_struct (cnc, args, error);
+ mstruct = gda_internal_command_build_meta_struct (console->current->cnc, argv, error);
if (!mstruct)
return NULL;
- result = create_graph_from_meta_struct (cnc, mstruct, error);
+ result = create_graph_from_meta_struct (console->current->cnc, mstruct, error);
g_object_unref (mstruct);
if (result) {
- GdaInternalCommandResult *res;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT;
+ ToolCommandResult *res;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
res->u.txt = g_string_new (result);
g_free (result);
return res;
@@ -6511,55 +5734,46 @@ extra_command_graph (SqlConsole *console, GdaConnection *cnc, const gchar **args
#ifdef HAVE_LIBSOUP
-static GdaInternalCommandResult *
-extra_command_httpd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_httpd (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res = NULL;
-
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
+ ToolCommandResult *res = NULL;
if (main_data->server) {
/* stop server */
g_object_unref (main_data->server);
main_data->server = NULL;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
res->u.txt = g_string_new (_("HTTPD server stopped"));
}
else {
/* start new server */
gint port = 12345;
const gchar *auth_token = NULL;
- if (args[0] && *args[0]) {
+ if (argv[0] && *argv[0]) {
gchar *ptr;
- port = (gint) strtol (args[0], &ptr, 10);
+ port = (gint) strtol (argv[0], &ptr, 10);
if (ptr && *ptr)
port = -1;
- if (args[1] && *args[1]) {
- auth_token = args[1];
+ if (argv[1] && *argv[1]) {
+ auth_token = argv[1];
}
}
if (port > 0) {
main_data->server = web_server_new (port, auth_token);
if (!main_data->server)
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Could not start HTTPD server"));
else {
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_TXT_STDOUT;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
res->u.txt = g_string_new (_("HTTPD server started"));
}
}
else
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Invalid port specification"));
}
@@ -6568,42 +5782,33 @@ extra_command_httpd (SqlConsole *console, G_GNUC_UNUSED GdaConnection *cnc, cons
#endif
#ifdef NONE
-static GdaInternalCommandResult *
-extra_command_lo_update (SqlConsole *console, GdaConnection *cnc, const gchar **args,
- G_GNUC_UNUSED OutputFormat format, GError **error, gpointer data)
+static ToolCommandResult *
+extra_command_lo_update (ToolCommand *command, guint argc, const gchar **argv,
+ SqlConsole *console, GError **error)
{
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
const gchar *table = NULL;
const gchar *blob_col = NULL;
const gchar *filename = NULL;
const gchar *row_cond = NULL;
- if (console) {
- GdaInternalCommandResult *res;
-
- TO_IMPLEMENT;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
- return res;
- }
-
if (!cnc) {
- g_set_error (error, TOOLS_ERROR, TOOLS_NO_CONNECTION_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
- if (args[0] && *args[0]) {
- filename = args[0];
- if (args[1] && *args[1]) {
- table = args[1];
- if (args[2] && *args[2]) {
- blob_col = args[2];
- if (args[3] && *args[3]) {
- row_cond = args[3];
- if (args [4]) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (argv[0] && *argv[0]) {
+ filename = argv[0];
+ if (argv[1] && *argv[1]) {
+ table = argv[1];
+ if (argv[2] && *argv[2]) {
+ blob_col = argv[2];
+ if (argv[3] && *argv[3]) {
+ row_cond = argv[3];
+ if (argv [4]) {
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Too many arguments"));
return NULL;
}
@@ -6612,7 +5817,7 @@ extra_command_lo_update (SqlConsole *console, GdaConnection *cnc, const gchar **
}
}
if (!row_cond) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing arguments"));
return NULL;
}
@@ -6635,12 +5840,12 @@ extra_command_lo_update (SqlConsole *console, GdaConnection *cnc, const gchar **
GdaStatement *stmt;
const gchar *remain;
- stmt = gda_sql_parser_parse_string (main_data->current->parser, sql, &remain, error);
+ stmt = gda_sql_parser_parse_string (console->current->parser, sql, &remain, error);
g_free (sql);
if (!stmt)
return NULL;
if (remain) {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Wrong row condition"));
return NULL;
}
@@ -6673,37 +5878,24 @@ extra_command_lo_update (SqlConsole *console, GdaConnection *cnc, const gchar **
if (nrows == -1)
return NULL;
- res = g_new0 (GdaInternalCommandResult, 1);
- res->type = GDA_INTERNAL_COMMAND_RESULT_EMPTY;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = TOOL_COMMAND_RESULT_EMPTY;
return res;
}
#endif
-static gchar **
-args_as_string_func (const gchar *str)
-{
- return g_strsplit (str, " ", 2);
-}
-
-static gchar **
-args_as_string_set (const gchar *str)
-{
- return g_strsplit (str, " ", 3);
-}
-
static char **
-completion_func (G_GNUC_UNUSED const char *text, int start, int end)
+completion_func (G_GNUC_UNUSED const char *text, const gchar *line, int start, int end)
{
-#ifdef HAVE_READLINE
- ConnectionSetting *cs = main_data->current;
+ ConnectionSetting *cs = main_data->term_console->current;
char **array;
gchar **gda_compl;
gint i, nb_compl;
if (!cs)
return NULL;
- gda_compl = gda_completion_list_get (cs->cnc, rl_line_buffer, start, end);
+ gda_compl = gda_completion_list_get (cs->cnc, line, start, end);
if (!gda_compl)
return NULL;
@@ -6724,9 +5916,6 @@ completion_func (G_GNUC_UNUSED const char *text, int start, int end)
array[i] = NULL;
g_strfreev (gda_compl);
return array;
-#else
- return NULL;
-#endif
}
@@ -6745,37 +5934,39 @@ gda_sql_get_connection (const gchar *name)
const ConnectionSetting *
gda_sql_get_current_connection (void)
{
- return main_data->current;
+ return main_data->term_console->current;
}
gchar *
-gda_sql_console_execute (SqlConsole *console, const gchar *command, GError **error, OutputFormat format)
+gda_sql_console_execute (SqlConsole *console, const gchar *command, GError **error, ToolOutputFormat format)
{
gchar *loc_cmde = NULL;
gchar *retstr = NULL;
+ g_assert (console);
loc_cmde = g_strdup (command);
g_strchug (loc_cmde);
if (*loc_cmde) {
if (command_is_complete (loc_cmde)) {
/* execute command */
- GdaInternalCommandResult *res;
+ ToolCommandResult *res;
res = command_execute (console, loc_cmde,
GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
if (res) {
- OutputFormat of = console->output_format;
- if (res->type == GDA_INTERNAL_COMMAND_RESULT_DATA_MODEL)
- console->output_format = OUTPUT_FORMAT_HTML;
+ ToolOutputFormat of = console->output_format;
+ if (res->type == TOOL_COMMAND_RESULT_DATA_MODEL)
+ console->output_format = TOOL_OUTPUT_FORMAT_HTML;
- retstr = result_to_string (console, res, format);
+ retstr = tool_output_result_to_string (res, format, console->output_stream,
+ main_data->options);
console->output_format = of;
- gda_internal_command_exec_result_free (res);
+ tool_command_result_free (res);
}
}
else {
- g_set_error (error, TOOLS_ERROR, TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
"%s", _("Command is incomplete"));
}
}
@@ -6790,10 +5981,13 @@ gda_sql_console_new (const gchar *id)
SqlConsole *c;
c = g_new0 (SqlConsole, 1);
- c->output_format = OUTPUT_FORMAT_DEFAULT;
+ c->output_format = TOOL_OUTPUT_FORMAT_DEFAULT;
if (id)
c->id = g_strdup (id);
- c->current = main_data->current;
+ if (main_data->term_console)
+ c->current = main_data->term_console->current;
+ c->command_group = main_data->limit_commands; /* limit to a subset of all commands */
+ c->output_stream = NULL;
return c;
}
@@ -6805,73 +5999,12 @@ gda_sql_console_free (SqlConsole *console)
}
gchar *
-gda_sql_console_compute_prompt (SqlConsole *console, OutputFormat format)
+gda_sql_console_compute_prompt (SqlConsole *console, ToolOutputFormat format)
{
GString *string;
string = g_string_new ("");
- compute_prompt (console, string, FALSE, format);
+ compute_prompt (console, string, FALSE, TRUE, format);
return g_string_free (string, FALSE);
}
-
-/*
- * color output handling
- */
-gchar *
-color_string (GdaSqlColor color, OutputFormat format, const char *fmt, ...)
-{
- va_list args;
- gchar *tmp, *res;
-
- va_start (args, fmt);
- tmp = g_strdup_vprintf (fmt, args);
- va_end (args);
- res = g_strdup_printf ("%s%s%s", color_s (color, format), tmp, color_s (GDA_SQL_COLOR_RESET, format));
- g_free (tmp);
- return res;
-}
-
-void
-color_append_string (GdaSqlColor color, OutputFormat format, GString *string, const char *fmt, ...)
-{
- va_list args;
- g_string_append (string, color_s (color, format));
- va_start (args, fmt);
- g_string_append_vprintf (string, fmt, args);
- va_end (args);
- g_string_append (string, color_s (GDA_SQL_COLOR_RESET, format));
-}
-
-void
-color_print (GdaSqlColor color, OutputFormat format, const char *fmt, ...)
-{
- va_list args;
- g_print (color_s (color, format));
- va_start (args, fmt);
- g_vprintf (fmt, args);
- va_end (args);
- g_print (color_s (GDA_SQL_COLOR_RESET, format));
-}
-
-const gchar *
-color_s (GdaSqlColor color, OutputFormat format)
-{
-#ifndef G_OS_WIN32
- if (format & OUTPUT_FORMAT_COLOR_TERM) {
- switch (color) {
- case GDA_SQL_COLOR_NORMAL:
- return "";
- case GDA_SQL_COLOR_RESET:
- return "\033[m";
- case GDA_SQL_COLOR_BOLD:
- return "\033[1m";
- case GDA_SQL_COLOR_RED:
- return "\033[31m";
- default:
- g_assert_not_reached();
- }
- }
-#endif
- return "";
-}
diff --git a/tools/gda-sql.h b/tools/gda-sql.h
index e1d9c63..8cb7431 100644
--- a/tools/gda-sql.h
+++ b/tools/gda-sql.h
@@ -27,6 +27,7 @@
#include <tools/gda-threader.h>
#include <sql-parser/gda-sql-parser.h>
#include "tools-favorites.h"
+#include <cmdtool/tool.h>
G_BEGIN_DECLS
@@ -44,20 +45,19 @@ typedef struct {
guint meta_job_id;
} ConnectionSetting;
-typedef enum {
- OUTPUT_FORMAT_DEFAULT = 1 << 0,
- OUTPUT_FORMAT_HTML = 1 << 1,
- OUTPUT_FORMAT_XML = 1 << 2,
- OUTPUT_FORMAT_CSV = 1 << 3,
-
- OUTPUT_FORMAT_COLOR_TERM = 1 << 8
-} OutputFormat;
-
+/*
+ * Structure representing a context using a connection
+ */
typedef struct {
gchar *id;
ConnectionSetting *current;
- OutputFormat output_format;
- GTimeVal last_time_used;
+
+ ToolOutputFormat output_format;
+ FILE *output_stream;
+ gboolean output_is_pipe;
+
+ GTimeVal last_time_used;
+ ToolCommandGroup *command_group;
} SqlConsole;
const GSList *gda_sql_get_all_connections (void);
@@ -67,24 +67,9 @@ const ConnectionSetting *gda_sql_get_current_connection (void);
SqlConsole *gda_sql_console_new (const gchar *id);
void gda_sql_console_free (SqlConsole *console);
gchar *gda_sql_console_execute (SqlConsole *console, const gchar *command,
- GError **error, OutputFormat format);
-
-gchar *gda_sql_console_compute_prompt (SqlConsole *console, OutputFormat format);
-
-/*
- * color output handling
- */
-typedef enum {
- GDA_SQL_COLOR_NORMAL,
- GDA_SQL_COLOR_RESET,
- GDA_SQL_COLOR_BOLD,
- GDA_SQL_COLOR_RED
-} GdaSqlColor;
+ GError **error, ToolOutputFormat format);
-void color_print (GdaSqlColor color, OutputFormat format, const char *fmt, ...);
-gchar *color_string (GdaSqlColor color, OutputFormat format, const char *fmt, ...);
-void color_append_string (GdaSqlColor color, OutputFormat format, GString *string, const char *fmt, ...);
-const gchar *color_s (GdaSqlColor color, OutputFormat format);
+gchar *gda_sql_console_compute_prompt (SqlConsole *console, ToolOutputFormat format);
G_END_DECLS
diff --git a/tools/help/C/gda-sql-help.xml b/tools/help/C/gda-sql-help.xml
index de60e84..02bfff2 100644
--- a/tools/help/C/gda-sql-help.xml
+++ b/tools/help/C/gda-sql-help.xml
@@ -36,20 +36,20 @@
<command name="c">
<shortdescription>Opens a new connection or lists opened connections</shortdescription>
<usage>
- <synopsis>.c [ CNC_NAME@ [ DSN@|@CONNECTION STRING ]]</synopsis>
+ <synopsis>.c [[ CNC_NAME@] [ DSN@|@CONNECTION STRING ]]</synopsis>
<comment>Opens a new connection, named @CNC_NAME@ using either a DSN name (use the ".l" command to list all declared DSN), or a connection string (use the ".lp" command to list database providers and see which argument their connection string accepts).</comment>
<comment>If only a connection name is passed as argument, then the named connection becomes the current active connection. As a side note, using "~" as a connection name will switch to a (new or already opened) connection which contains the meta data for the active connection.</comment>
<comment>If no connection name is specified, then this command lists all the opened connections</comment>
</usage>
<example>
- <synopsis>.c st SalesTest</synopsis>
+ <synopsis>.c SalesTest</synopsis>
<synopsis>.c ht htsql_demo.db</synopsis>
<synopsis>.c</synopsis>
<raw> List of opened connections
-Name | Provider | DSN or connection string | Username
------+----------+--------------------------------------------------+---------
-ht | SQLite | DB_DIR=.;EXTRA_FUNCTIONS=TRUE;DB_NAME=htsql_demo |
-st | SQLite | SalesTest |
+Name | Provider | DSN or connection string | Username
+----------+----------+--------------------------------------------------+---------
+ht | SQLite | DB_DIR=.;EXTRA_FUNCTIONS=TRUE;DB_NAME=htsql_demo |
+SalesTest | SQLite | SalesTest |
(2 rows)</raw>
<comment>This example opens two SQLite connections, named "ht" and "st"</comment>
</example>
@@ -416,4 +416,4 @@ uid=achassin,ou=People,dc=example,dc=gnome-db | Ashley Chassin | achassin
</usage>
</section>
-</gda-sql-help>
\ No newline at end of file
+</gda-sql-help>
diff --git a/tools/tools-utils.c b/tools/tool-utils.c
similarity index 87%
rename from tools/tools-utils.c
rename to tools/tool-utils.c
index 809ad62..7909056 100644
--- a/tools/tools-utils.c
+++ b/tools/tool-utils.c
@@ -16,17 +16,17 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "tools-utils.h"
+#include "tool-utils.h"
#include <glib/gi18n-lib.h>
/**
- * tools_utils_fk_policy_to_string
+ * gda_tools_utils_fk_policy_to_string
* @policy: a #GdaMetaForeignKeyPolicy
*
* Returns: the human readable version of @policy
*/
const gchar *
-tools_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy)
+gda_tools_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy)
{
switch (policy) {
default:
@@ -50,10 +50,10 @@ tools_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy)
/* module error */
GQuark
-tools_error_quark (void)
+gda_tools_error_quark (void)
{
static GQuark quark;
if (!quark)
- quark = g_quark_from_static_string ("tools_error");
+ quark = g_quark_from_static_string ("gda_tools_error");
return quark;
}
diff --git a/tools/tools-utils.h b/tools/tool-utils.h
similarity index 66%
rename from tools/tools-utils.h
rename to tools/tool-utils.h
index 566713b..f8b473b 100644
--- a/tools/tools-utils.h
+++ b/tools/tool-utils.h
@@ -21,24 +21,24 @@
#include <libgda/libgda.h>
-const gchar *tools_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy);
+const gchar *gda_tools_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy);
/*
* error reporting
*/
-extern GQuark tools_error_quark (void);
-#define TOOLS_ERROR tools_error_quark ()
+extern GQuark gda_tools_error_quark (void);
+#define GDA_TOOLS_ERROR gda_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
+ GDA_TOOLS_NO_CONNECTION_ERROR,
+ GDA_TOOLS_CONNECTION_CLOSED_ERROR,
+ GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ GDA_TOOLS_OBJECT_NOT_FOUND_ERROR,
+ GDA_TOOLS_PROVIDER_NOT_FOUND_ERROR,
+ GDA_TOOLS_DSN_NOT_FOUND_ERROR,
+ GDA_TOOLS_STORED_DATA_ERROR,
+ GDA_TOOLS_PURGE_ERROR
} ToolsError;
#endif
diff --git a/tools/tools-favorites.c b/tools/tools-favorites.c
index 259c274..404e0e9 100644
--- a/tools/tools-favorites.c
+++ b/tools/tools-favorites.c
@@ -21,7 +21,7 @@
#include <string.h>
#include <glib/gi18n-lib.h>
#include "tools-favorites.h"
-#include "tools-utils.h"
+#include "tool-utils.h"
#include <libgda/thread-wrapper/gda-thread-wrapper.h>
#include <libgda/gda-sql-builder.h>
#include <sql-parser/gda-sql-parser.h>
@@ -35,9 +35,9 @@ struct _ToolsFavoritesPrivate {
/*
* Main static functions
*/
-static void tools_favorites_class_init (ToolsFavoritesClass *klass);
-static void tools_favorites_init (ToolsFavorites *bfav);
-static void tools_favorites_dispose (GObject *object);
+static void gda_tools_favorites_class_init (ToolsFavoritesClass *klass);
+static void gda_tools_favorites_init (ToolsFavorites *bfav);
+static void gda_tools_favorites_dispose (GObject *object);
/* get a pointer to the parents to be able to call their destructor */
static GObjectClass *parent_class = NULL;
@@ -48,10 +48,10 @@ enum {
LAST_SIGNAL
};
-gint tools_favorites_signals [LAST_SIGNAL] = { 0 };
+gint gda_tools_favorites_signals [LAST_SIGNAL] = { 0 };
GType
-tools_favorites_get_type (void)
+gda_tools_favorites_get_type (void)
{
static GType type = 0;
@@ -61,12 +61,12 @@ tools_favorites_get_type (void)
sizeof (ToolsFavoritesClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
- (GClassInitFunc) tools_favorites_class_init,
+ (GClassInitFunc) gda_tools_favorites_class_init,
NULL,
NULL,
sizeof (ToolsFavorites),
0,
- (GInstanceInitFunc) tools_favorites_init,
+ (GInstanceInitFunc) gda_tools_favorites_init,
0
};
@@ -80,12 +80,12 @@ tools_favorites_get_type (void)
}
static void
-tools_favorites_class_init (ToolsFavoritesClass *klass)
+gda_tools_favorites_class_init (ToolsFavoritesClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
- tools_favorites_signals [FAV_CHANGED] =
+ gda_tools_favorites_signals [FAV_CHANGED] =
g_signal_new ("favorites-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED,
@@ -96,11 +96,11 @@ tools_favorites_class_init (ToolsFavoritesClass *klass)
klass->favorites_changed = NULL;
- object_class->dispose = tools_favorites_dispose;
+ object_class->dispose = gda_tools_favorites_dispose;
}
static void
-tools_favorites_init (ToolsFavorites *bfav)
+gda_tools_favorites_init (ToolsFavorites *bfav)
{
bfav->priv = g_new0 (ToolsFavoritesPrivate, 1);
bfav->priv->store = NULL;
@@ -108,14 +108,14 @@ tools_favorites_init (ToolsFavorites *bfav)
}
static void
-tools_favorites_dispose (GObject *object)
+gda_tools_favorites_dispose (GObject *object)
{
ToolsFavorites *bfav;
g_return_if_fail (object != NULL);
- g_return_if_fail (TOOLS_IS_FAVORITES (object));
+ g_return_if_fail (GDA_TOOLS_IS_FAVORITES (object));
- bfav = TOOLS_FAVORITES (object);
+ bfav = GDA_TOOLS_FAVORITES (object);
if (bfav->priv) {
if (bfav->priv->store)
g_object_unref (bfav->priv->store);
@@ -131,20 +131,20 @@ tools_favorites_dispose (GObject *object)
}
/**
- * tools_favorites_new
+ * gda_tools_favorites_new
*
* Creates a new #ToolsFavorites object
*
* Returns: the new object
*/
ToolsFavorites*
-tools_favorites_new (GdaMetaStore *store)
+gda_tools_favorites_new (GdaMetaStore *store)
{
ToolsFavorites *bfav;
g_return_val_if_fail (GDA_IS_META_STORE (store), NULL);
- bfav = TOOLS_FAVORITES (g_object_new (TOOLS_TYPE_FAVORITES, NULL));
+ bfav = GDA_TOOLS_FAVORITES (g_object_new (GDA_TOOLS_TYPE_FAVORITES, NULL));
bfav->priv->store = g_object_ref (store);
return bfav;
@@ -181,7 +181,7 @@ 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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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");
@@ -190,7 +190,7 @@ 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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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");
@@ -204,28 +204,28 @@ meta_store_addons_init (ToolsFavorites *bfav, GError **error)
}
/**
- * tools_favorites_type_to_string:
+ * gda_tools_favorites_type_to_string:
* @type: a #ToolsFavoritesType
*
* Returns: a string representing @type
*/
const gchar *
-tools_favorites_type_to_string (ToolsFavoritesType type)
+gda_tools_favorites_type_to_string (ToolsFavoritesType type)
{
switch (type) {
- case TOOLS_FAVORITES_TABLES:
+ case GDA_TOOLS_FAVORITES_TABLES:
return "TABLE";
- case TOOLS_FAVORITES_DIAGRAMS:
+ case GDA_TOOLS_FAVORITES_DIAGRAMS:
return "DIAGRAM";
- case TOOLS_FAVORITES_QUERIES:
+ case GDA_TOOLS_FAVORITES_QUERIES:
return "QUERY";
- case TOOLS_FAVORITES_DATA_MANAGERS:
+ case GDA_TOOLS_FAVORITES_DATA_MANAGERS:
return "DATAMAN";
- case TOOLS_FAVORITES_ACTIONS:
+ case GDA_TOOLS_FAVORITES_ACTIONS:
return "ACTION";
- case TOOLS_FAVORITES_LDAP_DN:
+ case GDA_TOOLS_FAVORITES_LDAP_DN:
return "LDAP_DN";
- case TOOLS_FAVORITES_LDAP_CLASS:
+ case GDA_TOOLS_FAVORITES_LDAP_CLASS:
return "LDAP_CLASS";
default:
g_warning ("Unknown type of favorite");
@@ -238,22 +238,22 @@ static ToolsFavoritesType
favorite_string_to_type (const gchar *str)
{
if (*str == 'T')
- return TOOLS_FAVORITES_TABLES;
+ return GDA_TOOLS_FAVORITES_TABLES;
else if (*str == 'D') {
if (str[1] == 'I')
- return TOOLS_FAVORITES_DIAGRAMS;
+ return GDA_TOOLS_FAVORITES_DIAGRAMS;
else
- return TOOLS_FAVORITES_DATA_MANAGERS;
+ return GDA_TOOLS_FAVORITES_DATA_MANAGERS;
}
else if (*str == 'Q')
- return TOOLS_FAVORITES_QUERIES;
+ return GDA_TOOLS_FAVORITES_QUERIES;
else if (*str == 'A')
- return TOOLS_FAVORITES_ACTIONS;
+ return GDA_TOOLS_FAVORITES_ACTIONS;
else if (*str == 'L') {
if (strlen (str) == 7)
- return TOOLS_FAVORITES_LDAP_DN;
+ return GDA_TOOLS_FAVORITES_LDAP_DN;
else
- return TOOLS_FAVORITES_LDAP_CLASS;
+ return GDA_TOOLS_FAVORITES_LDAP_CLASS;
}
else
g_warning ("Unknown type '%s' of favorite", str);
@@ -356,7 +356,7 @@ find_favorite_by_name (ToolsFavorites *bfav, guint session_id, const gchar *name
return -1;
params = gda_set_new_inline (3,
"session", G_TYPE_INT, session_id,
- "type", G_TYPE_STRING, tools_favorites_type_to_string (type),
+ "type", G_TYPE_STRING, gda_tools_favorites_type_to_string (type),
"name", G_TYPE_STRING, name);
model = gda_connection_statement_execute_select (bfav->priv->store_cnc, stmt, params, error);
g_object_unref (stmt);
@@ -394,7 +394,7 @@ find_favorite_by_name (ToolsFavorites *bfav, guint session_id, const gchar *name
*
* Returns: the ID or -1 if not found (and sets ERROR).
*
- * if @out_existing_fav is not %NULL, then its attributes are set, use tools_favorites_reset_attributes()
+ * if @out_existing_fav is not %NULL, then its attributes are set, use gda_tools_favorites_reset_attributes()
* to free.
*/
static gint
@@ -584,7 +584,7 @@ favorites_reorder (ToolsFavorites *bfav, gint order_key, gint id, gint new_pos,
}
/**
- * tools_favorites_add
+ * gda_tools_favorites_add
* @bfav: a #ToolsFavorites object
* @session_id: session ID (0)
* @fav: a pointer to a #ToolsFavoritesAttributes structure
@@ -606,7 +606,7 @@ favorites_reorder (ToolsFavorites *bfav, gint order_key, gint id, gint new_pos,
* if @order_key is negative, then no ordering is done and @pos is ignored.
*/
gboolean
-tools_favorites_add (ToolsFavorites *bfav, guint session_id,
+gda_tools_favorites_add (ToolsFavorites *bfav, guint session_id,
ToolsFavoritesAttributes *fav,
gint order_key, gint pos,
GError **error)
@@ -616,7 +616,7 @@ tools_favorites_add (ToolsFavorites *bfav, guint session_id,
gint favid = -1;
ToolsFavoritesAttributes efav; /* existing favorite */
- g_return_val_if_fail (TOOLS_IS_FAVORITES (bfav), FALSE);
+ g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), FALSE);
g_return_val_if_fail (fav, FALSE);
g_return_val_if_fail (fav->contents, FALSE);
@@ -625,13 +625,13 @@ 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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
"%s", _("Can't initialize transaction to access favorites"));
gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
return FALSE;
@@ -649,7 +649,7 @@ tools_favorites_add (ToolsFavorites *bfav, guint session_id,
params = gda_set_new_inline (8,
"session", G_TYPE_INT, session_id,
"id", G_TYPE_INT, fav->id,
- "type", G_TYPE_STRING, tools_favorites_type_to_string (rtype),
+ "type", G_TYPE_STRING, gda_tools_favorites_type_to_string (rtype),
"name", G_TYPE_STRING, fav->name ? fav->name : efav.name,
"contents", G_TYPE_STRING, fav->contents,
"rank", G_TYPE_INT, pos,
@@ -740,7 +740,7 @@ tools_favorites_add (ToolsFavorites *bfav, guint session_id,
g_object_unref (stmt);
fav->id = favid;
}
- tools_favorites_reset_attributes (&efav);
+ gda_tools_favorites_reset_attributes (&efav);
if (order_key >= 0) {
GdaSqlBuilder *builder;
@@ -804,7 +804,7 @@ tools_favorites_add (ToolsFavorites *bfav, guint session_id,
}
if (! gda_connection_commit_transaction (store_cnc, NULL, NULL)) {
- g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
"%s", _("Can't commit transaction to access favorites"));
goto err;
}
@@ -812,8 +812,8 @@ tools_favorites_add (ToolsFavorites *bfav, guint session_id,
if (params)
g_object_unref (params);
gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
- g_signal_emit (bfav, tools_favorites_signals [FAV_CHANGED],
- g_quark_from_string (tools_favorites_type_to_string (rtype)));
+ g_signal_emit (bfav, gda_tools_favorites_signals [FAV_CHANGED],
+ g_quark_from_string (gda_tools_favorites_type_to_string (rtype)));
return TRUE;
err:
@@ -825,34 +825,34 @@ tools_favorites_add (ToolsFavorites *bfav, guint session_id,
}
/**
- * tools_favorites_free_list
+ * gda_tools_favorites_free_list
* @fav_list: a list of #ToolsFavoritesAttributes
*
* Frees all the #ToolsFavoritesAttributes of the @fav_list list, and frees the list
* itself.
*/
void
-tools_favorites_free_list (GSList *fav_list)
+gda_tools_favorites_free_list (GSList *fav_list)
{
GSList *list;
if (!fav_list)
return;
for (list = fav_list; list; list = list->next) {
ToolsFavoritesAttributes *fav = (ToolsFavoritesAttributes*) list->data;
- tools_favorites_reset_attributes (fav);
+ gda_tools_favorites_reset_attributes (fav);
g_free (fav);
}
g_slist_free (fav_list);
}
/**
- * tools_favorites_reset_attributes
+ * gda_tools_favorites_reset_attributes
* @fav: a pointer to a #ToolsFavoritesAttributes
*
* Resets @fav with empty attributes; it does not free @fav.
*/
void
-tools_favorites_reset_attributes (ToolsFavoritesAttributes *fav)
+gda_tools_favorites_reset_attributes (ToolsFavoritesAttributes *fav)
{
g_free (fav->name);
g_free (fav->descr);
@@ -861,7 +861,7 @@ tools_favorites_reset_attributes (ToolsFavoritesAttributes *fav)
}
/**
- * tools_favorites_list
+ * gda_tools_favorites_list
* @bfav: a #ToolsFavorites
* @session_id: 0 for now
* @type: filter the type of attributes to be listed
@@ -871,10 +871,10 @@ tools_favorites_reset_attributes (ToolsFavoritesAttributes *fav)
* Extract some favorites.
*
* Returns: a new list of #ToolsFavoritesAttributes pointers. The list has to
- * be freed using tools_favorites_free_list()
+ * be freed using gda_tools_favorites_free_list()
*/
GSList *
-tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType type,
+gda_tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType type,
gint order_key, GError **error)
{
GdaSqlBuilder *b;
@@ -886,10 +886,10 @@ tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType
guint and_cond_ids [3];
int and_cond_size = 0;
- guint or_cond_ids [TOOLS_FAVORITES_NB_TYPES];
+ guint or_cond_ids [GDA_TOOLS_FAVORITES_NB_TYPES];
int or_cond_size = 0;
- g_return_val_if_fail (TOOLS_IS_FAVORITES (bfav), NULL);
+ g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), NULL);
g_return_val_if_fail ((type != 0) || (order_key >= 0), NULL);
if (! meta_store_addons_init (bfav, error))
@@ -932,10 +932,10 @@ tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType
gint i;
gint flag;
- for (i = 0, flag = 1; i < TOOLS_FAVORITES_NB_TYPES; i++, flag <<= 1) {
+ for (i = 0, flag = 1; i < GDA_TOOLS_FAVORITES_NB_TYPES; i++, flag <<= 1) {
if (type & flag) {
gchar *str;
- str = g_strdup_printf ("'%s'", tools_favorites_type_to_string (flag));
+ str = g_strdup_printf ("'%s'", gda_tools_favorites_type_to_string (flag));
or_cond_ids [or_cond_size] = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
gda_sql_builder_add_id (b, "fav.type"),
gda_sql_builder_add_id (b, str),
@@ -1011,7 +1011,7 @@ tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType
fav_list = g_slist_prepend (fav_list, fav);
}
else {
- tools_favorites_free_list (fav_list);
+ gda_tools_favorites_free_list (fav_list);
fav_list = NULL;
goto out;
}
@@ -1028,7 +1028,7 @@ tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType
/**
- * tools_favorites_delete
+ * gda_tools_favorites_delete
* @bfav: a #ToolsFavorites
* @session_id: 0 for now
* @fav: a pointer to a #ToolsFavoritesAttributes definning which favorite to delete
@@ -1039,7 +1039,7 @@ tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType
* Returns: %TRUE if no error occurred.
*/
gboolean
-tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
+gda_tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
ToolsFavoritesAttributes *fav, GError **error)
{
GdaSqlBuilder *b;
@@ -1049,7 +1049,7 @@ tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
gint favid = -1;
ToolsFavoritesAttributes efav;
- g_return_val_if_fail (TOOLS_IS_FAVORITES (bfav), FALSE);
+ g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), FALSE);
g_return_val_if_fail (fav, FALSE);
g_return_val_if_fail ((fav->id >= 0) || fav->contents || fav->name , FALSE);
@@ -1058,14 +1058,14 @@ tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
return FALSE;
if (! gda_lockable_trylock (GDA_LOCKABLE (bfav->priv->store_cnc))) {
- g_set_error (error, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
"%s", _("Can't initialize transaction to access favorites"));
gda_lockable_unlock (GDA_LOCKABLE (bfav->priv->store_cnc));
return FALSE;
@@ -1088,7 +1088,7 @@ tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
}
}
if (favid < 0) {
- g_set_error (error, TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
"%s", _("Could not find favorite"));
goto out;
}
@@ -1133,7 +1133,7 @@ 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, TOOLS_ERROR, TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
"%s", _("Can't commit transaction to access favorites"));
goto out;
}
@@ -1145,9 +1145,9 @@ tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
gda_lockable_unlock (GDA_LOCKABLE (bfav->priv->store_cnc));
if (retval)
- g_signal_emit (bfav, tools_favorites_signals [FAV_CHANGED],
- g_quark_from_string (tools_favorites_type_to_string (efav.type)));
- tools_favorites_reset_attributes (&efav);
+ g_signal_emit (bfav, gda_tools_favorites_signals [FAV_CHANGED],
+ g_quark_from_string (gda_tools_favorites_type_to_string (efav.type)));
+ gda_tools_favorites_reset_attributes (&efav);
if (params)
g_object_unref (G_OBJECT (params));
@@ -1155,7 +1155,7 @@ tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
}
/**
- * tools_favorites_find
+ * gda_tools_favorites_find
* @bfav: a #ToolsFavorites
* @session_id: 0 for now
* @contents: the favorite's contents
@@ -1163,15 +1163,15 @@ tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
* @error: a place to store errors, or %NULL
*
* Get all the information about a favorite from its id: fills the @out_fav
- * pointed structure. Use tools_favorites_reset_attributes() to reset @out_fav's contents.
+ * pointed structure. Use gda_tools_favorites_reset_attributes() to reset @out_fav's contents.
*
* Retuns: the requested's favorite ID, or -1 if not found
*/
gint
-tools_favorites_find (ToolsFavorites *bfav, guint session_id, const gchar *contents,
+gda_tools_favorites_find (ToolsFavorites *bfav, guint session_id, const gchar *contents,
ToolsFavoritesAttributes *out_fav, GError **error)
{
- g_return_val_if_fail (TOOLS_IS_FAVORITES (bfav), -1);
+ g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), -1);
g_return_val_if_fail (contents, -1);
if (! meta_store_addons_init (bfav, error))
@@ -1180,7 +1180,7 @@ tools_favorites_find (ToolsFavorites *bfav, guint session_id, const gchar *conte
}
/**
- * tools_favorites_find_by_name:
+ * gda_tools_favorites_find_by_name:
* @bfav: a #ToolsFavorites
* @session_id: 0 for now
* @type: the favorite's type
@@ -1189,15 +1189,15 @@ tools_favorites_find (ToolsFavorites *bfav, guint session_id, const gchar *conte
* @error: a place to store errors, or %NULL
*
* Get all the information about a favorite from its id: fills the @out_fav
- * pointed structure. Use tools_favorites_reset_attributes() to reset @out_fav's contents.
+ * pointed structure. Use gda_tools_favorites_reset_attributes() to reset @out_fav's contents.
*
* Retuns: the requested's favorite ID, or -1 if not found
*/
gint
-tools_favorites_find_by_name (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType type, const gchar *name,
+gda_tools_favorites_find_by_name (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType type, const gchar *name,
ToolsFavoritesAttributes *out_fav, GError **error)
{
- g_return_val_if_fail (TOOLS_IS_FAVORITES (bfav), -1);
+ g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), -1);
g_return_val_if_fail (name, -1);
if (! meta_store_addons_init (bfav, error))
@@ -1208,19 +1208,19 @@ tools_favorites_find_by_name (ToolsFavorites *bfav, guint session_id, ToolsFavor
/**
- * tools_favorites_get
+ * gda_tools_favorites_get
* @bfav: a #ToolsFavorites
* @fav_id: the favorite's ID
* @out_fav: a #ToolsFavoritesAttributes to be filled with the favorite's attributes
* @error: a place to store errors, or %NULL
*
* Get all the information about a favorite from its id: fills the @out_fav
- * pointed structure. Use tools_favorites_reset_attributes() to reset @out_fav's contents.
+ * pointed structure. Use gda_tools_favorites_reset_attributes() to reset @out_fav's contents.
*
* Retuns: %TRUE if no error occurred.
*/
gboolean
-tools_favorites_get (ToolsFavorites *bfav, gint fav_id,
+gda_tools_favorites_get (ToolsFavorites *bfav, gint fav_id,
ToolsFavoritesAttributes *out_fav, GError **error)
{
GdaSqlBuilder *b;
@@ -1229,7 +1229,7 @@ tools_favorites_get (ToolsFavorites *bfav, gint fav_id,
GdaDataModel *model;
gboolean retval = FALSE;
- g_return_val_if_fail (TOOLS_IS_FAVORITES (bfav), FALSE);
+ g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), FALSE);
g_return_val_if_fail (out_fav, FALSE);
g_return_val_if_fail (fav_id >= 0, FALSE);
diff --git a/tools/tools-favorites.h b/tools/tools-favorites.h
index 70b5ecc..277ff6e 100644
--- a/tools/tools-favorites.h
+++ b/tools/tools-favorites.h
@@ -17,17 +17,17 @@
*/
-#ifndef __TOOLS_FAVORITES_H_
-#define __TOOLS_FAVORITES_H_
+#ifndef __GDA_TOOLS_FAVORITES_H_
+#define __GDA_TOOLS_FAVORITES_H_
#include <libgda/libgda.h>
G_BEGIN_DECLS
-#define TOOLS_TYPE_FAVORITES (tools_favorites_get_type())
-#define TOOLS_FAVORITES(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, tools_favorites_get_type(), ToolsFavorites)
-#define TOOLS_FAVORITES_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, tools_favorites_get_type (), ToolsFavoritesClass)
-#define TOOLS_IS_FAVORITES(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, tools_favorites_get_type ())
+#define GDA_TOOLS_TYPE_FAVORITES (gda_tools_favorites_get_type())
+#define GDA_TOOLS_FAVORITES(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, gda_tools_favorites_get_type(), ToolsFavorites)
+#define GDA_TOOLS_FAVORITES_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, gda_tools_favorites_get_type (), ToolsFavoritesClass)
+#define GDA_TOOLS_IS_FAVORITES(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, gda_tools_favorites_get_type ())
typedef struct _ToolsFavorites ToolsFavorites;
typedef struct _ToolsFavoritesClass ToolsFavoritesClass;
@@ -35,24 +35,24 @@ typedef struct _ToolsFavoritesPrivate ToolsFavoritesPrivate;
/**
* ToolsFavoritesType:
- * @TOOLS_FAVORITES_TABLES: a database's table favorite
- * @TOOLS_FAVORITES_DIAGRAMS: a diagram favorite
- * @TOOLS_FAVORITES_QUERIES:
- * @TOOLS_FAVORITES_DATA_MANAGERS:
- * @TOOLS_FAVORITES_ACTIONS:
+ * @GDA_TOOLS_FAVORITES_TABLES: a database's table favorite
+ * @GDA_TOOLS_FAVORITES_DIAGRAMS: a diagram favorite
+ * @GDA_TOOLS_FAVORITES_QUERIES:
+ * @GDA_TOOLS_FAVORITES_DATA_MANAGERS:
+ * @GDA_TOOLS_FAVORITES_ACTIONS:
*
* Enum to identify favorite's types.
*/
typedef enum {
- TOOLS_FAVORITES_TABLES = 1 << 0,
- TOOLS_FAVORITES_DIAGRAMS = 1 << 1,
- TOOLS_FAVORITES_QUERIES = 1 << 2,
- TOOLS_FAVORITES_DATA_MANAGERS = 1 << 3,
- TOOLS_FAVORITES_ACTIONS = 1 << 4,
- TOOLS_FAVORITES_LDAP_DN = 1 << 5,
- TOOLS_FAVORITES_LDAP_CLASS = 1 << 6
+ GDA_TOOLS_FAVORITES_TABLES = 1 << 0,
+ GDA_TOOLS_FAVORITES_DIAGRAMS = 1 << 1,
+ GDA_TOOLS_FAVORITES_QUERIES = 1 << 2,
+ GDA_TOOLS_FAVORITES_DATA_MANAGERS = 1 << 3,
+ GDA_TOOLS_FAVORITES_ACTIONS = 1 << 4,
+ GDA_TOOLS_FAVORITES_LDAP_DN = 1 << 5,
+ GDA_TOOLS_FAVORITES_LDAP_CLASS = 1 << 6
} ToolsFavoritesType;
-#define TOOLS_FAVORITES_NB_TYPES 7
+#define GDA_TOOLS_FAVORITES_NB_TYPES 7
#define ORDER_KEY_SCHEMA 1
#define ORDER_KEY_QUERIES 2
@@ -98,31 +98,31 @@ struct _ToolsFavoritesClass
* @see_also:
*
* Each connection uses a single #ToolsFavorites object to manage its favorites,
- * see tools_connection_get_favorites().
+ * see gda_tools_connection_get_favorites().
*/
-GType tools_favorites_get_type (void) G_GNUC_CONST;
+GType gda_tools_favorites_get_type (void) G_GNUC_CONST;
-ToolsFavorites *tools_favorites_new (GdaMetaStore *store);
-const gchar *tools_favorites_type_to_string (ToolsFavoritesType type);
-gboolean tools_favorites_add (ToolsFavorites *bfav, guint session_id,
+ToolsFavorites *gda_tools_favorites_new (GdaMetaStore *store);
+const gchar *gda_tools_favorites_type_to_string (ToolsFavoritesType type);
+gboolean gda_tools_favorites_add (ToolsFavorites *bfav, guint session_id,
ToolsFavoritesAttributes *fav,
gint order_key, gint pos,
GError **error);
-GSList *tools_favorites_list (ToolsFavorites *bfav, guint session_id,
+GSList *gda_tools_favorites_list (ToolsFavorites *bfav, guint session_id,
ToolsFavoritesType type, gint order_key, GError **error);
-gboolean tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
+gboolean gda_tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
ToolsFavoritesAttributes *fav, GError **error);
-void tools_favorites_free_list (GSList *fav_list);
-void tools_favorites_reset_attributes (ToolsFavoritesAttributes *fav);
+void gda_tools_favorites_free_list (GSList *fav_list);
+void gda_tools_favorites_reset_attributes (ToolsFavoritesAttributes *fav);
-gint tools_favorites_find (ToolsFavorites *bfav, guint session_id, const gchar *contents,
+gint gda_tools_favorites_find (ToolsFavorites *bfav, guint session_id, const gchar *contents,
ToolsFavoritesAttributes *out_fav, GError **error);
-gint tools_favorites_find_by_name (ToolsFavorites *bfav, guint session_id,
+gint gda_tools_favorites_find_by_name (ToolsFavorites *bfav, guint session_id,
ToolsFavoritesType type, const gchar *name,
ToolsFavoritesAttributes *out_fav, GError **error);
-gboolean tools_favorites_get (ToolsFavorites *bfav, gint fav_id,
+gboolean gda_tools_favorites_get (ToolsFavorites *bfav, gint fav_id,
ToolsFavoritesAttributes *out_fav, GError **error);
G_END_DECLS
diff --git a/tools/web-server.c b/tools/web-server.c
index 6cef064..1e01921 100644
--- a/tools/web-server.c
+++ b/tools/web-server.c
@@ -1995,7 +1995,7 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
xmlDocSetRootElement (doc, topnode);
xmlNewChild (topnode, NULL, BAD_CAST "cid", BAD_CAST (console->id));
- tmp = gda_sql_console_compute_prompt (console, OUTPUT_FORMAT_HTML);
+ tmp = gda_sql_console_compute_prompt (console, TOOL_OUTPUT_FORMAT_HTML);
xmlNewChild (topnode, NULL, BAD_CAST "prompt", BAD_CAST tmp);
g_free (tmp);
@@ -2019,7 +2019,7 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
topnode = xmlNewDocNode (doc, NULL, BAD_CAST "result", NULL);
xmlDocSetRootElement (doc, topnode);
- tmp = gda_sql_console_execute (console, cmd, &lerror, OUTPUT_FORMAT_HTML);
+ tmp = gda_sql_console_execute (console, cmd, &lerror, TOOL_OUTPUT_FORMAT_HTML);
if (!tmp)
tmp = g_strdup_printf (_("Error: %s"),
lerror && lerror->message ? lerror->message : _("No detail"));
@@ -2029,7 +2029,7 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
xmlNewChild (topnode, NULL, BAD_CAST "cmde", BAD_CAST tmp);
g_free (tmp);
- tmp = gda_sql_console_compute_prompt (console, OUTPUT_FORMAT_HTML);
+ tmp = gda_sql_console_compute_prompt (console, TOOL_OUTPUT_FORMAT_HTML);
xmlNewChild (topnode, NULL, BAD_CAST "prompt", BAD_CAST tmp);
g_free (tmp);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]