]> saetta.ns0.it Git - zakaudit/gui/commitdiff
Loaded tables and fields.
authorAndrea Zagli <azagli@libero.it>
Sat, 14 Aug 2010 11:21:17 +0000 (13:21 +0200)
committerAndrea Zagli <azagli@libero.it>
Sat, 14 Aug 2010 11:21:17 +0000 (13:21 +0200)
src/datasources.c
src/main.c

index 00b40a0ac30993b796438e5dbf167d04f7df21be..9efbf8e25066f5ad36c726d0c7a75106f2a8d73d 100644 (file)
@@ -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);
index d28ed6d9a727f570d6190f79efc0b8adc3d909ef..f0d2dba713020847757bfb192f61851111b8f477 100644 (file)
@@ -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);
                }