From 9c8241a9e618d1d87e0f9b3c9544b8bc75fc2f92 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Tue, 25 Apr 2017 16:10:31 +0200 Subject: [PATCH] Aggiunta la funzione Comuni::get_dm. --- .gitignore | 1 + configure.ac | 20 +++++------ src/comuni.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++--- src/comuni.h | 6 ++-- 4 files changed, 106 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 7896823..1ffab29 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,4 @@ stamp-h1 tests/comune_by_id tests/widget compile +*.rc \ No newline at end of file diff --git a/configure.ac b/configure.ac index 367d34d..f5df983 100644 --- a/configure.ac +++ b/configure.ac @@ -38,16 +38,16 @@ AM_GLIB_GNU_GETTEXT # Checks for libraries. PKG_CHECK_MODULES(TERRITORIO, [gio-2.0 >= 2.36 - libgda-ui-5.0 >= 5.0.0 - libgdaex >= 0.5.0 - libgdaexgrid - libzakconfi >= 0.10.0 - libgtkform >= 0.5.0 - libgtkformui >= 0.5.0 - libzakauthe >= 0.2.0 - libzakautho >= 0.0.5 - libzakutils - libsolipa >= 0.5.0]) + libgda-ui-5.0 >= 5.0.0 + libgdaex >= 0.5.0 + libgdaexgrid + libzakconfi >= 0.10.0 + libgtkform >= 0.5.0 + libgtkformui >= 0.5.0 + libzakauthe >= 0.2.0 + libzakautho >= 0.0.5 + libzakutils + libsolipa >= 0.5.0]) AC_SUBST(TERRITORIO_CFLAGS) AC_SUBST(TERRITORIO_LIBS) diff --git a/src/comuni.c b/src/comuni.c index f5d1988..7047994 100644 --- a/src/comuni.c +++ b/src/comuni.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2016 Andrea Zagli + * Copyright (C) 2010-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -21,6 +21,7 @@ #include #include +#include #include "comuni.h" #include "comune.h" @@ -276,6 +277,92 @@ GtkWidget return priv->widget; } +GdaDataModel +*territorio_comuni_get_dm (TerritorioCommons *commons, gboolean con_provincia, const gchar *where) +{ + GdaDataModel *dm; + + GdaExSqlBuilder *sqlb; + GValue *gval; + + gchar *sql; + + sqlb = gdaex_sql_builder_new (GDA_SQL_STATEMENT_SELECT); + + if (con_provincia) + { + gdaex_sql_builder_from_v (sqlb, + "comuni", "", + "province", "", + NULL); + + gdaex_sql_builder_fields (sqlb, + "comuni", "id", "comuni_id", NULL, + "comuni", "nome", "comuni_nome", NULL, + "comuni", "cod_istat", "comuni_cod_istat", NULL, + "comuni", "cap", "comuni_cap", NULL, + "comuni", "id_province", "comuni_id_province", NULL, + "comuni", "capoluogo", "comuni_capoluogo", NULL, + "comuni", "status", "comuni_status", NULL, + "province", "id", "province_id", NULL, + "province", "nome", "province_nome", NULL, + "province", "cod_istat", "province_cod_istat", NULL, + "province", "sigla", "province_sigla", NULL, + "province", "id_regioni", "province_id_regioni", NULL, + "province", "status", "province_status", NULL, + NULL); + + gdaex_sql_builder_join (sqlb, GDA_SQL_SELECT_JOIN_INNER, + "comuni", "id_province", "", + GDA_SQL_OPERATOR_TYPE_EQ, + "province", "id", "", + NULL); + + gval = zak_utils_gvalue_new_string ("E"); + gdaex_sql_builder_where (sqlb, 0, + "province", "status", "", + GDA_SQL_OPERATOR_TYPE_DIFF, + gval, + NULL); + g_value_unset (gval); + } + else + { + gdaex_sql_builder_from_v (sqlb, + "comuni", "", + NULL); + + gdaex_sql_builder_fields (sqlb, + "comuni", "id", "comuni_id", NULL, + "comuni", "nome", "comuni_nome", NULL, + "comuni", "cod_istat", "comuni_cod_istat", NULL, + "comuni", "cap", "comuni_cap", NULL, + "comuni", "id_province", "comuni_id_province", NULL, + "comuni", "capoluogo", "comuni_capoluogo", NULL, + "comuni", "status", "comuni_status", NULL, + NULL); + } + + gval = zak_utils_gvalue_new_string ("E"); + gdaex_sql_builder_where (sqlb, 0, + "comuni", "status", "comuni_status", + GDA_SQL_OPERATOR_TYPE_DIFF, + gval, + NULL); + g_value_unset (gval); + + sql = g_strdup_printf ("SELECT %s FROM %s WHERE %s%s", + gdaex_sql_builder_get_sql_select (sqlb, NULL, NULL), + gdaex_sql_builder_get_sql_from (sqlb, NULL, NULL), + gdaex_sql_builder_get_sql_where (sqlb, NULL, NULL), + where != NULL ? where : ""); + + dm = gdaex_query (commons->gdaex, sql); + g_free (sql); + + return dm; +} + /* PRIVATE */ static void territorio_comuni_carica (TerritorioComuni *territorio_comuni) @@ -283,7 +370,6 @@ territorio_comuni_carica (TerritorioComuni *territorio_comuni) gchar *sql; gchar *sql_where; - GValue *gvalue; gchar *gcval; gint ival; @@ -339,9 +425,9 @@ territorio_comuni_carica (TerritorioComuni *territorio_comuni) sql_where); gdaex_grid_fill_from_sql (priv->grid, - priv->commons->gdaex, - sql, - NULL); + priv->commons->gdaex, + sql, + NULL); g_free (sql); } diff --git a/src/comuni.h b/src/comuni.h index c86eeb4..204f438 100644 --- a/src/comuni.h +++ b/src/comuni.h @@ -1,5 +1,5 @@ -/* - * Copyright (C) 2010 Andrea Zagli +/* + * Copyright (C) 2010-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -59,6 +59,8 @@ TerritorioComuni *territorio_comuni_new (TerritorioCommons *commons, gboolean se GtkWidget *territorio_comuni_get_widget (TerritorioComuni *territorio_comuni); +GdaDataModel *territorio_comuni_get_dm (TerritorioCommons *commons, gboolean con_provincia, const gchar *where); + G_END_DECLS -- 2.49.0