[glom/glom-1-20] Reports: Make summary fields work again.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom/glom-1-20] Reports: Make summary fields work again.
- Date: Mon, 6 Feb 2012 11:36:34 +0000 (UTC)
commit 84bce9c7c0636a2754c67f04f503f1b0a04ed480
Author: Murray Cumming <murrayc murrayc com>
Date: Fri Feb 3 13:01:31 2012 +0100
Reports: Make summary fields work again.
* glom/libglom/report_builder.cc: report_build_summary():
Remove any sort clause (ORDER BY) from the FoundSet because that makes
no sense for a single row with summary fields. It looks like recent versions
of PostgreSQL have become more strict about this, producing this error, for
instance:
column invoices.invoice_id must appear in the GROUP BY clause or be used in an aggregate function
* Makefile_tests.am:
* tests/test_selfhosting_new_then_report_summary.cc: Add a test for this.
This fixes bug #669281 (alien)
ChangeLog | 14 +++
Makefile_tests.am | 6 +
examples/example_smallbusiness.glom | 2 +-
glom/libglom/report_builder.cc | 8 ++-
tests/test_selfhosting_new_then_report_summary.cc | 106 +++++++++++++++++++++
5 files changed, 134 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 20ffcb1..23910cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2012-02-03 Murray Cumming <murrayc murrayc com>
+ Reports: Make summary fields work again.
+
+ * glom/libglom/report_builder.cc: report_build_summary():
+ Remove any sort clause (ORDER BY) from the FoundSet because that makes
+ no sense for a single row with summary fields. It looks like recent versions
+ of PostgreSQL have become more strict about this, producing this error, for
+ instance:
+ column "invoices.invoice_id" must appear in the GROUP BY clause or be used in an aggregate function
+ * Makefile_tests.am:
+ * tests/test_selfhosting_new_then_report_summary.cc: Add a test for this.
+ This fixes bug #669281 (alien)
+
+2012-02-03 Murray Cumming <murrayc murrayc com>
+
Document: Really load the table privileges.
* glom/libglom/db_utils.[h|cc]: add_group(): Take a bool superuser
diff --git a/Makefile_tests.am b/Makefile_tests.am
index 35f67f3..a2090ce 100644
--- a/Makefile_tests.am
+++ b/Makefile_tests.am
@@ -37,6 +37,7 @@ check_PROGRAMS = \
tests/test_selfhosting_new_from_example \
tests/test_selfhosting_new_from_example_strangepath \
tests/test_selfhosting_new_then_report \
+ tests/test_selfhosting_new_then_report_summary \
tests/test_selfhosting_new_then_image \
tests/test_selfhosting_new_then_choices \
tests/test_selfhosting_new_then_backup_restore \
@@ -67,6 +68,7 @@ TESTS = tests/test_document_load \
tests/test_selfhosting_new_from_example_in_locales.sh \
tests/test_selfhosting_new_from_example_strangepath \
tests/test_selfhosting_new_then_report \
+ tests/test_selfhosting_new_then_report_summary \
tests/test_selfhosting_new_then_backup_restore \
tests/test_selfhosting_new_then_image \
tests/test_selfhosting_new_then_choices \
@@ -200,6 +202,10 @@ tests_test_selfhosting_new_then_report_SOURCES = tests/test_selfhosting_new_then
tests_test_selfhosting_new_then_report_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_then_report_CPPFLAGS = $(tests_cppflags)
+tests_test_selfhosting_new_then_report_summary_SOURCES = tests/test_selfhosting_new_then_report_summary.cc $(sources_test_selfhosting_utils)
+tests_test_selfhosting_new_then_report_summary_LDADD = $(tests_ldadd)
+tests_test_selfhosting_new_then_report_summary_CPPFLAGS = $(tests_cppflags)
+
tests_test_selfhosting_new_then_image_SOURCES = tests/test_selfhosting_new_then_image.cc $(sources_test_selfhosting_utils) $(sources_test_utils)
tests_test_selfhosting_new_then_image_LDADD = $(tests_ldadd)
tests_test_selfhosting_new_then_image_CPPFLAGS = $(tests_cppflags) $(glom_test_image_defines)
diff --git a/examples/example_smallbusiness.glom b/examples/example_smallbusiness.glom
index 391450d..72f1c9c 100644
--- a/examples/example_smallbusiness.glom
+++ b/examples/example_smallbusiness.glom
@@ -1151,7 +1151,7 @@ Orientation=portrait
</data_layout>
</data_layouts>
<reports>
- <report name="By Customer" title="By Customer">
+ <report name="by_customer" title="By Customer">
<data_layout_groups>
<data_layout_group>
<data_layout_item_groupby>
diff --git a/glom/libglom/report_builder.cc b/glom/libglom/report_builder.cc
index 27de092..0490e7f 100644
--- a/glom/libglom/report_builder.cc
+++ b/glom/libglom/report_builder.cc
@@ -120,8 +120,14 @@ void ReportBuilder::report_build_summary(const FoundSet& found_set, xmlpp::Eleme
if(!itemsToGet.empty())
{
+ //Make sure that the FoundSet has no ORDER BY, because
+ //a) That makes no sense for a single summary row result.
+ //b) That would require us to mention the ORDER BY field in the GROUP BY clause or in an aggregate function.
+ FoundSet found_set_used = found_set;
+ found_set_used.m_sort_clause.clear();
+
//Rows, with data:
- report_build_records(found_set, *node, itemsToGet);
+ report_build_records(found_set_used, *node, itemsToGet); //TODO: Check for failures.
}
}
diff --git a/tests/test_selfhosting_new_then_report_summary.cc b/tests/test_selfhosting_new_then_report_summary.cc
new file mode 100644
index 0000000..d3f6560
--- /dev/null
+++ b/tests/test_selfhosting_new_then_report_summary.cc
@@ -0,0 +1,106 @@
+/* Glom
+ *
+ * Copyright (C) 2010 Openismus GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+71 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "tests/test_selfhosting_utils.h"
+#include <libglom/init.h>
+#include <libglom/report_builder.h>
+#include <glib.h> //For g_assert()
+#include <iostream>
+#include <cstdlib> //For EXIT_SUCCESS and EXIT_FAILURE
+
+
+static bool test(Glom::Document::HostingMode hosting_mode)
+{
+ Glom::Document document;
+ const bool recreated =
+ test_create_and_selfhost_from_example("example_smallbusiness.glom", document, hosting_mode);
+ if(!recreated)
+ {
+ std::cerr << "Recreation failed." << std::endl;
+ return false;
+ }
+
+ const Glom::sharedptr<const Glom::Report> report =
+ document.get_report("invoices", "by_customer");
+ if(!report)
+ {
+ std::cerr << "The report could not be found." << std::endl;
+ return false;
+ }
+
+ Glom::FoundSet found_set; //TODO: Test a where clause.
+ found_set.m_table_name = "invoices";
+
+ const Glib::ustring locale = ""; /* original locale */
+ Glom::ReportBuilder report_builder(locale);
+ report_builder.set_document(&document);
+ const Glib::ustring html =
+ report_builder.report_build(found_set, report);
+
+ if(html.empty())
+ {
+ std::cerr << "Failed: html was empty." << std::endl;
+ return false;
+ }
+
+ if(html.find("Yodda Yossarian") == std::string::npos)
+ {
+ std::cerr << "Failed: html did not contain the expected text." << std::endl;
+ return false;
+ }
+
+ if(html.find("90.47") == std::string::npos)
+ {
+ std::cerr << "Failed: html did not contain the expected summary number." << std::endl;
+ return false;
+ }
+
+ test_selfhosting_cleanup();
+
+ return true;
+}
+
+int main()
+{
+ Glom::libglom_init();
+
+ //Make sure that we use an en locale,
+ //so we can test for the expected numeric output;
+ setlocale(LC_ALL, "en_US.UTF-8");
+
+
+ if(!test(Glom::Document::HOSTING_MODE_POSTGRES_SELF))
+ {
+ std::cerr << "Failed with PostgreSQL" << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
+ if(!test(Glom::Document::HOSTING_MODE_SQLITE))
+ {
+ std::cerr << "Failed with SQLite" << std::endl;
+ test_selfhosting_cleanup();
+ return EXIT_FAILURE;
+ }
+
+ Glom::libglom_deinit();
+
+ return EXIT_SUCCESS;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]