Commit f0c2ed90 authored by Murray Cumming's avatar Murray Cumming
Browse files

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)
parent b5f94ac9
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.
......
......@@ -41,6 +41,7 @@ check_PROGRAMS = \
tests/test_selfhosting_new_from_example_operator \
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_lookup \
tests/test_selfhosting_new_then_choices \
......@@ -78,6 +79,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_lookup \
......@@ -246,6 +248,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)
......
......@@ -1347,7 +1347,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>
......
......@@ -121,8 +121,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.
}
}
......
/* 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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment