From 8a654e9c0f5244a8f7f46feb6b46e9df12cf97e1 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 22 Jul 2014 12:25:00 +0200 Subject: [PATCH] Add function ag_db_get_chart_list() --- src/ag-db.c | 34 ++++++++++++++++++++++++++++++++++ src/ag-db.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/src/ag-db.c b/src/ag-db.c index 6a92317..42f0b19 100644 --- a/src/ag-db.c +++ b/src/ag-db.c @@ -648,3 +648,37 @@ ag_db_save_chart(AgDb *db, AgDbSave *save_data, GtkWidget *window, GError **err) return FALSE; } + +GList * +ag_db_get_chart_list(AgDb *db, GError **err) +{ + GdaDataModelIter *iter; + GList *ret = NULL; + GdaDataModel *result = ag_db_select( + db, + err, + "SELECT id, name FROM chart ORDER BY name", + NULL + ); + + if (result == NULL) { + return NULL; + } + + iter = gda_data_model_create_iter(result); + + while (gda_data_model_iter_move_next(iter)) { + const GValue *value; + AgDbSave *save_data = g_new0(AgDbSave, 1); + + value = gda_data_model_iter_get_value_at(iter, 0); + save_data->db_id = g_value_get_int(value); + + value = gda_data_model_iter_get_value_at(iter, 1); + save_data->name = g_strdup(g_value_get_string(value)); + + ret = g_list_prepend(ret, save_data); + } + + return g_list_reverse(ret); +} diff --git a/src/ag-db.h b/src/ag-db.h index efe82aa..3ac3447 100644 --- a/src/ag-db.h +++ b/src/ag-db.h @@ -60,6 +60,8 @@ gboolean ag_db_save_chart(AgDb *db, GtkWidget *window, GError **err); +GList *ag_db_get_chart_list(AgDb *db, GError **err); + G_END_DECLS #endif /* __AG_DB_H__ */