{
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;
}
/* 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)
{
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);