[glom/sqlbuilder2: 117/117] More use of SqlBuilder.



commit 1875860194b44b4cf31c452b60f9419c1d2f469a
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Apr 27 16:43:15 2010 +0200

    More use of SqlBuilder.
    
    * glom/report_builder.cc: report_build_groupby(): Use the new
        SqlBuilder::select_group_by() method to replace another SQL string.

 ChangeLog              |   27 +++++++++++++++++----------
 glom/report_builder.cc |   32 ++++++++++++++++++--------------
 2 files changed, 35 insertions(+), 24 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c69706a..9edf5b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2010-04-27  Murray Cumming  <murrayc murrayc com>
+
+    More use of SqlBuilder.
+
+	* glom/report_builder.cc: report_build_groupby(): Use the new
+    SqlBuilder::select_group_by() method to replace another SQL string.
+
 1.14.1:
 
 2010-04-27  Murray Cumming  <murrayc murrayc com>
@@ -1239,23 +1246,23 @@
 
 	Use Gnome::Gda::SqlBuilder
 
-	* several files: Use Gnome::Gda::SqlBuilder to simplify query building and to 
+	* several files: Use Gnome::Gda::SqlBuilder to simplify query building and to
 	make it safer.
 	Much of this work was actually by Johannes Schmid for Openismus.
-	
+
 2010-02-27  Murray Cumming  <murrayc murrayc com>
 
   Increase required version of libgdamm.
-  
-	* configure.ac: Increase libgdamm dependency to the last one that doesn't 
+
+	* configure.ac: Increase libgdamm dependency to the last one that doesn't
 	need libgda 4.1/4.2. We actually need some API that was not in the older one.
 
 2010-02-27  Murray Cumming  <murrayc murrayc com>
 
   Revert use of SqlBuilder because it requires libgda 4.1,
-  which will not be packaged by the upcoming Ubuntu Lucid, which is an 
+  which will not be packaged by the upcoming Ubuntu Lucid, which is an
   important version of an important distro.
-   
+
 2010-02-27  Murray Cumming  <murrayc murrayc com>
 
 	More uses of SqlBuilder for SELECT statements.
@@ -1263,13 +1270,13 @@
 2010-02-27  Murray Cumming  <murrayc murrayc com>
 
   Fix runtime problems with the use of SqlBuilder.
-  
-	* glom/base_db.[h|cc]: query_execute_select(), query_execute(): Catch more 
+
+	* glom/base_db.[h|cc]: query_execute_select(), query_execute(): Catch more
   errors and output better debug and error text.
-	get_database_preferences(): Don't bother catching exceptions already caught 
+	get_database_preferences(): Don't bother catching exceptions already caught
 	by query_execute*().
 	add_standard_tables(): Fix a typo in the SQL query.
-	insert_example_data(): Work around an inability in GdaSqlBuilder to INSERT 
+	insert_example_data(): Work around an inability in GdaSqlBuilder to INSERT
 	a NULL value. I have asked about it on the mailing list.
 
 2010-02-26  Murray Cumming  <murrayc murrayc-desktop>
diff --git a/glom/report_builder.cc b/glom/report_builder.cc
index 2e59143..f34cec9 100644
--- a/glom/report_builder.cc
+++ b/glom/report_builder.cc
@@ -175,29 +175,33 @@ void ReportBuilder::report_build_groupby(const FoundSet& found_set_parent, xmlpp
     fill_full_field_details(found_set_parent.m_table_name, field_group_by);
 
     //Get the possible group values, ignoring repeats by using GROUP BY.
-    //TODO: Use SqlBuilder:
     const Glib::ustring group_field_table_name = field_group_by->get_table_used(found_set_parent.m_table_name);
-    Glib::ustring sql_query = "SELECT \"" + group_field_table_name + "\".\"" + field_group_by->get_name() + "\""
-      " FROM \"" + group_field_table_name + "\"";
+
+    Glib::RefPtr<Gnome::Gda::SqlBuilder> builder =
+      Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
+    builder->select_add_field(field_group_by->get_name(), group_field_table_name);
+    builder->select_add_target(group_field_table_name);
 
     if(!found_set_parent.m_where_clause.empty())
-      sql_query += " WHERE " + found_set_parent.m_where_clause;
+    {
+      builder->set_where( builder->add_id(found_set_parent.m_where_clause) ); //Is this allowed?
+    }
 
-    sql_query += " GROUP BY " + field_group_by->get_name(); //TODO: And restrict to the current found set.
+    builder->select_group_by( builder->add_id(field_group_by->get_name()) ); //TODO: And restrict to the current found set.
 
-    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(sql_query);
+    Glib::RefPtr<Gnome::Gda::DataModel> datamodel = query_execute_select(builder);
     if(datamodel)
     {
       guint rows_count = datamodel->get_n_rows();
       for(guint row = 0; row < rows_count; ++row)
       {
-#ifdef GLIBMM_EXCEPTIONS_ENABLED      
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
         const Gnome::Gda::Value group_value = datamodel->get_value_at(0 /* col*/, row);
 #else
         std::auto_ptr<Glib::Error> error;
         const Gnome::Gda::Value group_value = datamodel->get_value_at(0 /* col*/, row, error);
-#endif        
-        
+#endif
+
 
         //Add XML node:
         xmlpp::Element* nodeGroupBy = parent_node.add_child(group_by->get_report_part_id());
@@ -278,7 +282,7 @@ void ReportBuilder::report_build_records(const FoundSet& found_set, xmlpp::Eleme
       sharedptr<LayoutItem> layout_item = *iter;
       sharedptr<LayoutItem_Field> layoutitem_field = sharedptr<LayoutItem_Field>::cast_dynamic(layout_item);
 
-      //This adds a field heading (and therefore, column) for fields, or for a vertical group. 
+      //This adds a field heading (and therefore, column) for fields, or for a vertical group.
       xmlpp::Element* nodeFieldHeading = parent_node.add_child("field_heading");
       if(layoutitem_field && layoutitem_field->get_glom_type() == Field::TYPE_NUMERIC)
         nodeFieldHeading->set_attribute("field_type", "numeric"); //TODO: More sophisticated formatting.
@@ -397,23 +401,23 @@ void ReportBuilder::report_build_records_field(const FoundSet& found_set, xmlpp:
     if(!datamodel)
       return;
 
-#ifdef GLIBMM_EXCEPTIONS_ENABLED      
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
     value = datamodel->get_value_at(colField, row);
 #else
     std::auto_ptr<Glib::Error> error;
     value = datamodel->get_value_at(colField, row, error);
-#endif 
+#endif
     colField = 0;
     row = 0;
   }
   else
   {
-#ifdef GLIBMM_EXCEPTIONS_ENABLED      
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
     value = datamodel->get_value_at(colField, row);
 #else
     std::auto_ptr<Glib::Error> error;
     value = datamodel->get_value_at(colField, row, error);
-#endif 
+#endif
   }
 
   nodeField->set_attribute("title", field->get_title_or_name()); //Not always used, but useful.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]