libgda r3144 - in trunk: . libgda providers/postgres tools
- From: vivien svn gnome org
- To: svn-commits-list gnome org
- Subject: libgda r3144 - in trunk: . libgda providers/postgres tools
- Date: Thu, 10 Apr 2008 20:38:07 +0100 (BST)
Author: vivien
Date: Thu Apr 10 20:38:06 2008
New Revision: 3144
URL: http://svn.gnome.org/viewvc/libgda?rev=3144&view=rev
Log:
2008-04-10 Vivien Malerba <malerba gnome-db org>
* libgda/gda-meta-struct.c: crash bug fixed
* providers/postgres/gda-postgres-meta.c: bug fixed
* tools/tools-input.[ch]:
* tools/gda-sql.c: implemented rudinentary command completion, and also tests
if the direct connection string is in fact a DSN when opening the connection
Modified:
trunk/ChangeLog
trunk/libgda/gda-meta-struct.c
trunk/providers/postgres/gda-postgres-meta.c
trunk/tools/gda-sql.c
trunk/tools/tools-input.c
trunk/tools/tools-input.h
Modified: trunk/libgda/gda-meta-struct.c
==============================================================================
--- trunk/libgda/gda-meta-struct.c (original)
+++ trunk/libgda/gda-meta-struct.c Thu Apr 10 20:38:06 2008
@@ -204,8 +204,10 @@
if (sqlst->stmt_type == GDA_SQL_STATEMENT_SELECT) {
GdaSqlStatementSelect *selst;
selst = (GdaSqlStatementSelect*) (sqlst->contents);
- GSList *targets;
- for (targets = selst->from->targets; targets; targets = targets->next) {
+ GSList *targets = NULL;
+ if (selst->from)
+ targets = selst->from->targets;
+ for (; targets; targets = targets->next) {
GdaSqlSelectTarget *t = (GdaSqlSelectTarget *) targets->data;
GValue *catalog, *schema, *name;
GdaMetaDbObject *ref_obj, *tmp_obj;
Modified: trunk/providers/postgres/gda-postgres-meta.c
==============================================================================
--- trunk/providers/postgres/gda-postgres-meta.c (original)
+++ trunk/providers/postgres/gda-postgres-meta.c Thu Apr 10 20:38:06 2008
@@ -481,15 +481,16 @@
GdaDataModel *model;
gboolean retval;
+ gda_holder_set_value (gda_set_get_holder (i_set, "name"), specific_name);
cstr = g_value_get_string (specific_name);
if (*cstr == 'C')
- model = gda_connection_statement_execute_select (cnc, internal_stmt[I_STMT_EL_TYPES_COL], NULL,
+ model = gda_connection_statement_execute_select (cnc, internal_stmt[I_STMT_EL_TYPES_COL], i_set,
error);
else if (*cstr == 'D')
- model = gda_connection_statement_execute_select (cnc, internal_stmt[I_STMT_EL_TYPES_DOM], NULL,
+ model = gda_connection_statement_execute_select (cnc, internal_stmt[I_STMT_EL_TYPES_DOM], i_set,
error);
else if (*cstr == 'U')
- model = gda_connection_statement_execute_select (cnc, internal_stmt[I_STMT_EL_TYPES_UDT], NULL,
+ model = gda_connection_statement_execute_select (cnc, internal_stmt[I_STMT_EL_TYPES_UDT], i_set,
error);
else
TO_IMPLEMENT;
Modified: trunk/tools/gda-sql.c
==============================================================================
--- trunk/tools/gda-sql.c (original)
+++ trunk/tools/gda-sql.c Thu Apr 10 20:38:06 2008
@@ -121,6 +121,7 @@
GString *prompt = NULL;
static gchar *read_a_line (MainData *data);
+static char *completion_func (const char *text, int state);
static void compute_prompt (MainData *data, GString *string, gboolean in_command);
static gboolean set_output_file (MainData *data, const gchar *file, GError **error);
static gboolean set_input_file (MainData *data, const gchar *file, GError **error);
@@ -243,6 +244,7 @@
/* loop over commands */
setup_sigint_handler ();
init_input ();
+ set_completion_func (completion_func);
init_history ();
for (;;) {
gchar *cmde;
@@ -369,7 +371,7 @@
pnode = xmlNewNode (NULL, BAD_CAST "parameter");
xmlAddChild (node, pnode);
xmlSetProp (pnode, BAD_CAST "name",
- gda_holder_get_id (GDA_HOLDER (list->data)));
+ 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);
@@ -390,7 +392,7 @@
pnode = xmlNewNode (NULL, BAD_CAST "li");
xmlAddChild (node, pnode);
xmlSetProp (pnode, BAD_CAST "name",
- gda_holder_get_id (GDA_HOLDER (list->data)));
+ 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);
@@ -432,7 +434,7 @@
case OUTPUT_FORMAT_XML:
buffer = xmlBufferCreate ();
node = xmlNewNode (NULL, BAD_CAST "txt");
- xmlNodeSetContent (node, res->u.txt->str);
+ xmlNodeSetContent (node, BAD_CAST res->u.txt->str);
xmlNodeDump (buffer, NULL, node, 0, 1);
output_string (data, (gchar *) xmlBufferContent (buffer));
xmlBufferFree (buffer);
@@ -441,7 +443,7 @@
case OUTPUT_FORMAT_HTML:
buffer = xmlBufferCreate ();
node = xmlNewNode (NULL, BAD_CAST "p");
- xmlNodeSetContent (node, res->u.txt->str);
+ xmlNodeSetContent (node, BAD_CAST res->u.txt->str);
xmlNodeDump (buffer, NULL, node, 0, 1);
output_string (data, (gchar *) xmlBufferContent (buffer));
xmlBufferFree (buffer);
@@ -826,7 +828,8 @@
* Open a connection
*/
static ConnectionSetting*
-open_connection (MainData *data, const gchar *cnc_name, const gchar *dsn, const gchar *provider, const gchar *direct,
+open_connection (MainData *data, const gchar *cnc_name, const gchar *dsn,
+ const gchar *provider, const gchar *direct,
const gchar *user, const gchar *pass,
GError **error)
{
@@ -856,11 +859,24 @@
_("DSN '%s' is not declared"), dsn);
}
else
- newcnc = gda_connection_open_from_dsn (info->name, auth_string ? auth_string : info->auth_string,
+ newcnc = gda_connection_open_from_dsn (info->name,
+ auth_string ? auth_string : info->auth_string,
0, error);
}
- if (!newcnc && direct)
- newcnc = gda_connection_open_from_string (provider, direct, auth_string, 0, error);
+ if (!newcnc && direct) {
+ /* test if @direct is not in fact a DSN, in which case use it as a DSN */
+ GdaDataSourceInfo *info = NULL;
+ info = gda_config_get_dsn (direct);
+ if (info) {
+ newcnc = gda_connection_open_from_dsn (info->name,
+ auth_string ? auth_string : info->auth_string,
+ 0, error);
+ dsn = direct;
+ direct = NULL;
+ }
+ else
+ newcnc = gda_connection_open_from_string (provider, direct, auth_string, 0, error);
+ }
g_free (auth_string);
if (newcnc) {
@@ -980,7 +996,7 @@
for (j = 0; j < ncols; j++) {
const gchar *cstr;
cstr = gda_data_model_get_column_title (model, j);
- col_node = xmlNewChild (row_node, NULL, BAD_CAST "th", cstr);
+ col_node = xmlNewChild (row_node, NULL, BAD_CAST "th", BAD_CAST cstr);
xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "center");
}
@@ -991,7 +1007,7 @@
const GValue *value;
value = gda_data_model_get_value_at (model, j, i);
str = gda_value_stringify (value);
- col_node = xmlNewChild (row_node, NULL, BAD_CAST "td", str);
+ col_node = xmlNewChild (row_node, NULL, BAD_CAST "td", BAD_CAST str);
xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "left");
g_free (str);
}
@@ -2509,3 +2525,93 @@
{
return g_strsplit (str, " ", 3);
}
+
+static char *
+completion_func (const char *text, int state)
+{
+ static GArray *compl = NULL;
+
+ if (state == 0) {
+ ConnectionSetting *cs = main_data->current;
+ /* clear any previous completion */
+ if (compl) {
+ /* don't free the contents of @array, it is freed by readline */
+ g_array_free (compl, TRUE);
+ compl = NULL;
+ }
+
+ /* compute list of possible completions. It's very simple at the moment */
+ if (!(*text)) {
+ /* no completion possible */
+ }
+ else if (cs) {
+ gchar *copy;
+
+ copy = g_strdup (text);
+ g_strchomp (copy);
+ if (*copy) {
+ const char *start;
+ gint nb_compl = 0;
+ for (start = copy + (strlen (copy) - 1); start > copy; start--)
+ if (g_ascii_isspace (*start)) {
+ start ++;
+ break;
+ }
+ GdaDataModel *model;
+ GdaMetaStore *store;
+ store = gda_connection_get_meta_store (cs->cnc);
+ model = gda_meta_store_extract (store, "SELECT table_schema, table_name FROM "
+ "_tables", NULL);
+ if (model) {
+ gint i, nrows;
+ gint len = strlen (start);
+
+ compl = g_array_new (TRUE, TRUE, sizeof (char *));
+ nrows = gda_data_model_get_n_rows (model);
+ for (i = 0; i < nrows; i++) {
+ const gchar *tname;
+ tname = g_value_get_string (gda_data_model_get_value_at (model, 1, i));
+ if (!strncmp (tname, start, len)) {
+ char *str;
+ str = malloc (sizeof (char) * (strlen (tname) + 1));
+ strcpy (str, tname);
+ g_array_append_val (compl, str);
+ nb_compl++;
+ }
+ }
+ g_object_unref (model);
+ }
+
+ model = gda_meta_store_extract (store, "SELECT schema_name FROM "
+ "_schemata", NULL);
+ if (model) {
+ gint i, nrows;
+ gint len = strlen (start);
+
+ compl = g_array_new (TRUE, TRUE, sizeof (char *));
+ nrows = gda_data_model_get_n_rows (model);
+ for (i = 0; i < nrows; i++) {
+ const gchar *tname;
+ tname = g_value_get_string (gda_data_model_get_value_at (model, 0, i));
+ if (!strncmp (tname, start, len)) {
+ char *str;
+ str = malloc (sizeof (char) * (strlen (tname) + 1));
+ strcpy (str, tname);
+ g_array_append_val (compl, str);
+ nb_compl++;
+ }
+ }
+ g_object_unref (model);
+ }
+ }
+ g_free (copy);
+ }
+
+ if (compl)
+ return g_array_index (compl, char*, 0);
+ else
+ return NULL;
+ }
+ else
+ return g_array_index (compl, char*, state) ;
+}
Modified: trunk/tools/tools-input.c
==============================================================================
--- trunk/tools/tools-input.c (original)
+++ trunk/tools/tools-input.c Thu Apr 10 20:38:06 2008
@@ -95,52 +95,6 @@
}
}
-#ifdef HAVE_READLINE_READLINE_H
-static char *
-completion_generator_func (const char *text, int state)
-{
- static char **compl = NULL;
- if (state == 0) {
- /* clear any previous completion */
- if (compl) {
- /* don't free the contents of @array, it is freed by readline */
- g_free (compl);
- compl = NULL;
- }
-
- /* compute list of possible completions. It's very simple at the moment */
- if (!(*text)) {
- /* no completion possible */
- }
- else {
- gchar *copy;
-
- copy = g_strdup (text);
- g_strchomp (copy);
- if (*copy) {
- const char *start;
- for (start = copy + (strlen (copy) - 1); start >= copy; start--)
- if (g_ascii_isspace (*start)) {
- start ++;
- break;
- }
- compl = g_new0 (char *, 2);
- compl[0] = malloc (sizeof (char) * (strlen (start) + 1));
- strcpy (compl[0], start);
- }
- g_free (copy);
- }
-
- if (compl)
- return compl[0];
- else
- return NULL;
- }
- else
- return compl[state];
-}
-#endif
-
/**
* init_input
*
@@ -152,10 +106,22 @@
#ifdef HAVE_READLINE_READLINE_H
rl_set_signals ();
rl_readline_name = "gda-sql";
- rl_completion_entry_function = completion_generator_func;
#endif
}
+/**
+ * set_completion_func
+ *
+ *
+ */
+void
+set_completion_func (CompletionFunc func)
+{
+#ifdef HAVE_READLINE_READLINE_H
+ rl_completion_entry_function = func;
+#endif
+}
+
/*
* input_get_size
*
Modified: trunk/tools/tools-input.h
==============================================================================
--- trunk/tools/tools-input.h (original)
+++ trunk/tools/tools-input.h Thu Apr 10 20:38:06 2008
@@ -25,6 +25,8 @@
#include <stdio.h>
#include <glib.h>
+typedef char *(*CompletionFunc) (const char *, int);
+
gchar *input_from_console (const gchar *prompt);
gchar *input_from_stream (FILE *stream);
@@ -34,5 +36,6 @@
void init_history ();
void add_to_history (const gchar *txt);
gboolean save_history (const gchar *file, GError **error);
+void set_completion_func (CompletionFunc func);
#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]