From f7fd6295d09978d734a7b145e565acb0ec7a1198 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 14 Aug 2010 13:21:17 +0200 Subject: [PATCH] Loaded tables and fields. --- src/datasources.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++- src/main.c | 2 +- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/datasources.c b/src/datasources.c index 00b40a0..9efbf8e 100644 --- a/src/datasources.c +++ b/src/datasources.c @@ -56,7 +56,11 @@ enum { COL_ID_DS, COL_NAME_DS, - COL_CNCSTRING_DS + COL_CNCSTRING_DS, + COL_ID_TABLE, + COL_NAME_TABLE, + COL_ID_FIELD, + COL_NAME_FIELD }; typedef struct _DatasourcesPrivate DatasourcesPrivate; @@ -149,6 +153,90 @@ GtkWidget } /* PRIVATE */ +static void +datasources_load_fields (Datasources *datasources, guint id_table, GtkTreeIter *iter_parent) +{ + GtkTreeIter iter; + + gchar *sql; + + GdaStatement *stmt; + GError *error; + GdaDataModel *dm; + + gint rows; + gint row; + + DatasourcesPrivate *priv = DATASOURCES_GET_PRIVATE (datasources); + + sql = g_strdup_printf ("SELECT id, name" + " FROM fields" + " WHERE status <> 'D'" + " AND id_tables = %d" + " ORDER BY name", id_table); + 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); + if (dm != NULL) + { + rows = gda_data_model_get_n_rows (dm); + for (row = 0; row < rows; row++) + { + gtk_tree_store_append (priv->tstore_datasources, &iter, iter_parent); + + gtk_tree_store_set (priv->tstore_datasources, &iter, + COL_ID_FIELD, g_value_get_int (gda_data_model_get_value_at (dm, 0, row, NULL)), + COL_NAME_FIELD, gda_value_stringify (gda_data_model_get_value_at (dm, 1, row, NULL)), + -1); + } + + g_object_unref (dm); + } +} + +static void +datasources_load_tables (Datasources *datasources, guint id_ds, GtkTreeIter *iter_parent) +{ + GtkTreeIter iter; + + gchar *sql; + + GdaStatement *stmt; + GError *error; + GdaDataModel *dm; + + gint rows; + gint row; + + DatasourcesPrivate *priv = DATASOURCES_GET_PRIVATE (datasources); + + sql = g_strdup_printf ("SELECT id, name" + " FROM tables" + " WHERE status <> 'D'" + " AND id_datasources = %d" + " ORDER BY name", id_ds); + 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); + if (dm != NULL) + { + rows = gda_data_model_get_n_rows (dm); + for (row = 0; row < rows; row++) + { + gtk_tree_store_append (priv->tstore_datasources, &iter, iter_parent); + + gtk_tree_store_set (priv->tstore_datasources, &iter, + COL_ID_TABLE, g_value_get_int (gda_data_model_get_value_at (dm, 0, row, NULL)), + COL_NAME_TABLE, gda_value_stringify (gda_data_model_get_value_at (dm, 1, row, NULL)), + -1); + + datasources_load_fields (datasources, g_value_get_int (gda_data_model_get_value_at (dm, 0, row, NULL)), &iter); + } + + g_object_unref (dm); + } +} + static void datasources_load (Datasources *datasources) { @@ -186,6 +274,8 @@ datasources_load (Datasources *datasources) COL_NAME_DS, gda_value_stringify (gda_data_model_get_value_at (dm, 1, row, NULL)), COL_CNCSTRING_DS, g_strdup_printf ("(%s)", gda_value_stringify (gda_data_model_get_value_at (dm, 2, row, NULL))), -1); + + datasources_load_tables (datasources, g_value_get_int (gda_data_model_get_value_at (dm, 0, row, NULL)), &iter); } g_object_unref (dm); diff --git a/src/main.c b/src/main.c index d28ed6d..f0d2dba 100644 --- a/src/main.c +++ b/src/main.c @@ -206,7 +206,7 @@ main (int argc, char *argv[]) if (argc > 0) { - /* try to user the first argument of command line as a cnc_string */ + /* try to use the first argument of command line as a cnc_string */ main_on_ds_opened (NULL, argv[1], NULL); } -- 2.49.0