/*
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Datasource *c = datasource_new (priv->commons, id);
g_signal_connect (G_OBJECT (c), "updated",
- G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
+ G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
w = datasource_get_widget (c);
gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
else
{
gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_datasources), &iter,
- COL_ID_TABLE, &id,
- -1);
+ COL_ID_TABLE, &id,
+ -1);
if (id != 0)
{
Table *c = table_new (priv->commons, id, 0);
g_signal_connect (G_OBJECT (c), "updated",
- G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
+ G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
w = table_get_widget (c);
gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
GtkTreeIter iter;
guint id_ds;
+ guint depth;
+ GtkTreePath *path;
Datasources *datasources = (Datasources *)user_data;
DatasourcesPrivate *priv = DATASOURCES_GET_PRIVATE (datasources);
if (id_ds == 0)
{
- GtkTreePath *path;
-
path = gtk_tree_model_get_path (GTK_TREE_MODEL (priv->tstore_datasources), &iter);
if (path != NULL)
{
- guint depth;
-
depth = gtk_tree_path_get_depth (path);
if (depth >= 2) gtk_tree_path_up (path);
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->tstore_datasources), &iter, path))
{
gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_datasources), &iter,
- COL_ID_DS, &id_ds,
- -1);
+ COL_ID_DS, &id_ds,
+ -1);
}
}
}
Table *c = table_new (priv->commons, 0, id_ds);
g_signal_connect (G_OBJECT (c), "updated",
- G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
+ G_CALLBACK (datasources_on_datasource_updated), (gpointer)datasources);
w = table_get_widget (c);
gtk_window_set_transient_for (GTK_WINDOW (w), GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")));
else
{
dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- "Select a datasource or a table.");
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Select a datasource or a table.");
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
/*
- * Copyright (C) 2010 Andrea Zagli <azagli@libero.it>
+ * Copyright (C) 2010-2011 Andrea Zagli <azagli@libero.it>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
{
Commons *commons;
+ GdaConnection *gdacon;
+
GtkWidget *w;
GtkListStore *lstore_fields;
g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button6"),
"clicked", G_CALLBACK (table_on_btn_save_clicked), (gpointer *)a);
- table_load_db_tables (a);
-
priv->id = id;
+
if (priv->id == 0)
{
gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label7")), "");
gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label8")), g_strdup_printf ("%d", id_datasources));
+
+ table_load_db_tables (a);
}
else
{
static void
table_load_db_tables (Table *table)
{
+ GtkWidget *dialog;
GError *error;
GdaMetaContext mcontext = {"_tables", 0, NULL, NULL};
+ GdaStatement *stmt;
GdaDataModel *dm;
GtkTreeModel *model;
gchar *table_name;
+ gchar *sql;
+ gchar *cnc;
+
TablePrivate *priv = TABLE_GET_PRIVATE (table);
+ model = gtk_combo_box_get_model (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1")));
+
+ gtk_list_store_clear (GTK_LIST_STORE (model));
+
+ /* open connection to the db to inspect */
+ sql = g_strdup_printf ("SELECT cnc_string"
+ " FROM %sdatasources"
+ " WHERE id = %d AND status <> 'D'",
+ priv->commons->prefix,
+ strtol (gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label8"))), NULL, 10));
+
error = NULL;
- if (!gda_connection_update_meta_store (priv->commons->gdacon, &mcontext, &error))
+ stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, &error);
+ if (stmt == NULL || error != NULL)
{
- GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- "Unable to get tables list.\n\n",
- (error != NULL && error->message != NULL ? error->message : "No details."));
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Unable to get tables list.\n%s",
+ (error != NULL && error->message != NULL ? error->message : "No details."));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return;
}
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1")));
+ error = NULL;
+ dm = gda_connection_statement_execute_select (priv->commons->gdacon, stmt, NULL, &error);
+ g_object_unref (stmt);
+ if (dm != NULL && error == NULL && gda_data_model_get_n_rows (dm) > 0)
+ {
+ cnc = gda_value_stringify (gda_data_model_get_value_at (dm, 0, 0, NULL));
+ g_object_unref (dm);
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Unable to get tables list.\n%s",
+ (error != NULL && error->message != NULL ? error->message : "No details."));
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return;
+ }
- gtk_list_store_clear (GTK_LIST_STORE (model));
+ error = NULL;
+ priv->gdacon = gda_connection_open_from_string (NULL, cnc, NULL,
+ GDA_CONNECTION_OPTIONS_NONE,
+ &error);
+ if (priv->gdacon == NULL || error != NULL)
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Unable to get tables list.\n%s",
+ (error != NULL && error->message != NULL ? error->message : "No details."));
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return;
+ }
error = NULL;
- dm = gda_connection_get_meta_store_data (priv->commons->gdacon,
- GDA_CONNECTION_META_TABLES,
- &error,
- 0);
- if (dm != NULL)
+ if (!gda_connection_update_meta_store (priv->gdacon, &mcontext, &error))
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Unable to get tables list.\n%s",
+ (error != NULL && error->message != NULL ? error->message : "No details."));
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return;
+ }
+
+ error = NULL;
+ dm = gda_connection_get_meta_store_data (priv->gdacon,
+ GDA_CONNECTION_META_TABLES,
+ &error,
+ 0);
+ if (dm != NULL && error == NULL)
{
rows = gda_data_model_get_n_rows (dm);
for (row = 0; row < rows; row++)
{
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
- 0, table_name,
- -1);
+ 0, table_name,
+ -1);
}
}
+ g_object_unref (dm);
+ }
+ else
+ {
+ dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Unable to get tables list.\n%s",
+ (error != NULL && error->message != NULL ? error->message : "No details."));
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ return;
}
}
static void
table_load (Table *table)
{
+ GtkWidget *dialog;
+
TablePrivate *priv = TABLE_GET_PRIVATE (table);
GError *error;
GdaStatement *stmt;
GdaDataModel *dm;
- sql = g_strdup_printf ("SELECT name FROM %stables WHERE id = %d",
+ sql = g_strdup_printf ("SELECT id_datasources, name FROM %stables WHERE id = %d",
priv->commons->prefix,
priv->id);
stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL);
dm = gda_connection_statement_execute_select (priv->commons->gdacon, stmt, NULL, &error);
g_object_unref (stmt);
+ g_free (sql);
if (dm != NULL && gda_data_model_get_n_rows (dm) == 1)
{
- table_set_table (table, gda_value_stringify (gda_data_model_get_value_at (dm, 0, 0, NULL)));
+ gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label8")),
+ g_strdup_printf ("%d", g_value_get_int (gda_data_model_get_value_at (dm, 0, 0, NULL))));
+ table_load_db_tables (table);
+
+ table_set_table (table, gda_value_stringify (gda_data_model_get_value_at (dm, 1, 0, NULL)));
+ g_object_unref (dm);
}
else
{
- GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- "Record %d doesn't exist.", priv->id);
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Record %d doesn't exist.",
+ priv->id);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
else
{
dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- "You must select a table.");
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "You must select a table.");
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return;
error = NULL;
sql = g_strdup_printf ("INSERT INTO %sfields"
" (id, id_tables, name)"
- " VALUES (%d, %d, '%s')",
+ " VALUES (%d, %d, '%s')",
priv->commons->prefix,
- id_field,
+ id_field,
priv->id,
- field_name);
+ field_name);
stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL);
gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error);
if (error != NULL)
error = NULL;
id_saved[strlen (id_saved) - 1] = '\0';
sql = g_strdup_printf ("DELETE FROM %sfields"
- " WHERE id_tables = %d"
- "%s",
- priv->commons->prefix,
- priv->id,
- (g_strcmp0 (id_saved, "") != 0 ? g_strdup_printf (" AND id NOT IN (%s)", id_saved) : ""));
+ " WHERE id_tables = %d"
+ "%s",
+ priv->commons->prefix,
+ priv->id,
+ (g_strcmp0 (id_saved, "") != 0 ? g_strdup_printf (" AND id NOT IN (%s)", id_saved) : ""));
stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL);
gda_connection_statement_execute_non_select (priv->commons->gdacon, stmt, NULL, NULL, &error);
if (error != NULL)
{
g_warning ("Error removing old fields: %s",
- (error->message != NULL ? error->message : "No details."));
+ (error->message != NULL ? error->message : "No details."));
}
g_object_unref (stmt);
g_signal_emit (table, klass->updated_signal_id, 0);
dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_INFO,
- GTK_BUTTONS_OK,
- "Saved with success.");
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ "Saved with success.");
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
}
dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- "Error on saving.\n\n%s",
- (error != NULL && error->message != NULL ? error->message : "No details."));
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Error on saving.\n\n%s",
+ (error != NULL && error->message != NULL ? error->message : "No details."));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
gpointer user_data)
{
GError *error;
+ GtkWidget *dialog;
GdaMetaContext mcontext = {"_columns", 1, NULL, NULL};
+ guint id_tables;
gchar *table_name;
+
GdaDataModel *dm;
GdaStatement *stmt;
GdaDataModel *dm_fields;
return;
}
- gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1"))), &iter, 0, &table_name, -1);
+ gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (gtk_builder_get_object (priv->commons->gtkbuilder, "combobox1"))), &iter,
+ 0, &table_name,
+ -1);
error = NULL;
mcontext.column_names = g_new (gchar *, 1);
mcontext.column_values = g_new (GValue *, 1);
mcontext.column_values[0] = gda_value_new (G_TYPE_STRING);
g_value_take_string (mcontext.column_values[0],
- gda_sql_identifier_quote (table_name, priv->commons->gdacon, NULL, FALSE, FALSE));
- if (!gda_connection_update_meta_store (priv->commons->gdacon, &mcontext, &error))
+ gda_sql_identifier_quote (table_name, priv->gdacon, NULL, FALSE, FALSE));
+ if (!gda_connection_update_meta_store (priv->gdacon, &mcontext, &error))
{
- GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- "Unable to get fields list.\n\n%s",
- (error != NULL && error->message != NULL ? error->message : "No details."));
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ "Unable to get fields list.\n\n%s",
+ (error != NULL && error->message != NULL ? error->message : "No details."));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return;
error = NULL;
gval = gda_value_new (G_TYPE_STRING);
g_value_take_string (gval, table_name);
- dm = gda_connection_get_meta_store_data (priv->commons->gdacon,
+ dm = gda_connection_get_meta_store_data (priv->gdacon,
GDA_CONNECTION_META_FIELDS,
&error,
1,
/* check if field is choosen for libaudit */
error = NULL;
- sql = g_strdup_printf ("SELECT id FROM %sfields WHERE name = '%s' AND status <> 'D'",
+ sql = g_strdup_printf ("SELECT f.id"
+ " FROM %sfields AS f INNER JOIN %stables AS t ON f.id_tables = t.id"
+ " WHERE f.id_tables = %d"
+ " AND t.name = '%s'"
+ " AND f.name = '%s'"
+ " AND f.status <> 'D'",
+ priv->commons->prefix,
priv->commons->prefix,
+ priv->id,
+ table_name,
field_name);
stmt = gda_sql_parser_parse_string (priv->commons->gdaparser, sql, NULL, NULL);
dm_fields = gda_connection_statement_execute_select (priv->commons->gdacon, stmt, NULL, &error);