[glom] libglom: build_sql_select_add_fields_to_get(): Define joins here.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] libglom: build_sql_select_add_fields_to_get(): Define joins here.
- Date: Mon, 24 May 2010 22:27:37 +0000 (UTC)
commit 7918d198352f124396dd7988cb1475cbd0547736
Author: Murray Cumming <murrayc murrayc com>
Date: Tue May 25 00:26:47 2010 +0200
libglom: build_sql_select_add_fields_to_get(): Define joins here.
* glom/libglom/data_structure/layout/usesrelationship.[h|cc]:
Remove add_sql_join_alias_definition(), moving its code into
Utils::build_sql_select_add_fields_to_get() because that was the only code
that called it.
get/set_relationship(), get/set_related_relationship(): const corrections.
* several files: Adapt to const corrections.
ChangeLog | 11 +++++
glom/base_db.cc | 2 +-
.../data_structure/layout/fieldformatting.cc | 4 +-
.../data_structure/layout/fieldformatting.h | 4 +-
.../data_structure/layout/usesrelationship.cc | 46 ++-----------------
.../data_structure/layout/usesrelationship.h | 20 +++------
glom/libglom/document/document.cc | 2 +-
glom/libglom/utils.cc | 40 ++++++++++++++++-
glom/mode_data/box_data_calendar_related.cc | 2 +-
glom/mode_data/datawidget/datawidget.cc | 2 +-
glom/mode_data/flowtablewithfields.cc | 2 +-
.../layout/layout_item_dialogs/box_formatting.cc | 2 +-
glom/print_layout/canvas_print_layout.cc | 2 +-
glom/utility_widgets/db_adddel/db_adddel.cc | 2 +-
14 files changed, 72 insertions(+), 69 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index a635ed6..303e9c0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-05-25 Murray Cumming <murrayc murrayc-x61>
+
+ libglom: build_sql_select_add_fields_to_get(): Define joins here.
+
+ * glom/libglom/data_structure/layout/usesrelationship.[h|cc]:
+ Remove add_sql_join_alias_definition(), moving its code into
+ Utils::build_sql_select_add_fields_to_get() because that was the only code
+ that called it.
+ get/set_relationship(), get/set_related_relationship(): const corrections.
+ * several files: Adapt to const corrections.
+
2010-05-24 Murray Cumming <murrayc murrayc com>
UsesRelationship: Correct use of SqlBuilder for related relationships.
diff --git a/glom/base_db.cc b/glom/base_db.cc
index e983a4a..fefa9c1 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -1944,7 +1944,7 @@ void Base_DB::set_found_set_where_clause_for_portal(FoundSet& found_set, const s
}
- sharedptr<Relationship> relationship = portal->get_relationship();
+ sharedptr<const Relationship> relationship = portal->get_relationship();
// Notice that, in the case that this is a portal to doubly-related records,
// The WHERE clause mentions the first-related table (though by the alias defined in extra_join)
diff --git a/glom/libglom/data_structure/layout/fieldformatting.cc b/glom/libglom/data_structure/layout/fieldformatting.cc
index 4a6e40b..9644914 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.cc
+++ b/glom/libglom/data_structure/layout/fieldformatting.cc
@@ -231,7 +231,7 @@ void FieldFormatting::set_has_related_choices(bool val)
m_choices_related = val;
}
-void FieldFormatting::get_choices(sharedptr<Relationship>& relationship, Glib::ustring& field, Glib::ustring& field_second) const
+void FieldFormatting::get_choices(sharedptr<const Relationship>& relationship, Glib::ustring& field, Glib::ustring& field_second) const
{
relationship = get_relationship();
@@ -241,7 +241,7 @@ void FieldFormatting::get_choices(sharedptr<Relationship>& relationship, Glib::u
//g_warning("FieldFormatting::get_choices, %s, %s, %s", m_choices_related_relationship->c_str(), m_choices_related_field.c_str(), m_choices_related_field_second.c_str());
}
-void FieldFormatting::set_choices(const sharedptr<Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second)
+void FieldFormatting::set_choices(const sharedptr<const Relationship>& relationship, const Glib::ustring& field, const Glib::ustring& field_second)
{
set_relationship(relationship);
diff --git a/glom/libglom/data_structure/layout/fieldformatting.h b/glom/libglom/data_structure/layout/fieldformatting.h
index 7daa702..e709128 100644
--- a/glom/libglom/data_structure/layout/fieldformatting.h
+++ b/glom/libglom/data_structure/layout/fieldformatting.h
@@ -65,8 +65,8 @@ public:
*/
void set_choices_restricted(bool val = true, bool as_radio_buttons = false);
- void get_choices(sharedptr<Relationship>& relationship_name, Glib::ustring& field, Glib::ustring& field_second) const;
- void set_choices(const sharedptr<Relationship>& relationship_name, const Glib::ustring& field, const Glib::ustring& field_second);
+ void get_choices(sharedptr<const Relationship>& relationship_name, Glib::ustring& field, Glib::ustring& field_second) const;
+ void set_choices(const sharedptr<const Relationship>& relationship_name, const Glib::ustring& field, const Glib::ustring& field_second);
/** Get whether the text should be displayed with multiple lines in the
* details view. Text is displayed with a single line in the list view.
diff --git a/glom/libglom/data_structure/layout/usesrelationship.cc b/glom/libglom/data_structure/layout/usesrelationship.cc
index b8569d0..45470bb 100644
--- a/glom/libglom/data_structure/layout/usesrelationship.cc
+++ b/glom/libglom/data_structure/layout/usesrelationship.cc
@@ -86,22 +86,22 @@ Glib::ustring UsesRelationship::get_related_relationship_name() const
return Glib::ustring();
}
-sharedptr<Relationship> UsesRelationship::get_relationship() const
+sharedptr<const Relationship> UsesRelationship::get_relationship() const
{
return m_relationship;
}
-void UsesRelationship::set_relationship(const sharedptr<Relationship>& relationship)
+void UsesRelationship::set_relationship(const sharedptr<const Relationship>& relationship)
{
m_relationship = relationship;
}
-sharedptr<Relationship> UsesRelationship::get_related_relationship() const
+sharedptr<const Relationship> UsesRelationship::get_related_relationship() const
{
return m_related_relationship;
}
-void UsesRelationship::set_related_relationship(const sharedptr<Relationship>& relationship)
+void UsesRelationship::set_related_relationship(const sharedptr<const Relationship>& relationship)
{
m_related_relationship = relationship;
}
@@ -147,7 +147,7 @@ Glib::ustring UsesRelationship::get_title_used(const Glib::ustring& parent_table
Glib::ustring UsesRelationship::get_title_singular_used(const Glib::ustring& parent_table_title) const
{
- sharedptr<Relationship> used = m_related_relationship;
+ sharedptr<const Relationship> used = m_related_relationship;
if(!used)
used = m_relationship;
@@ -218,41 +218,5 @@ Glib::ustring UsesRelationship::get_sql_join_alias_name() const
return result;
}
-void UsesRelationship::add_sql_join_alias_definition(const Glib::RefPtr<Gnome::Gda::SqlBuilder>& builder) const
-{
- // Specify an alias, to avoid ambiguity when using 2 relationships to the same table.
- const Glib::ustring alias_name = get_sql_join_alias_name();
-
- // Add the JOIN:
- if(!get_has_related_relationship_name())
- {
- const guint to_target_id = builder->select_add_target(m_relationship->get_to_table(), alias_name);
-
- builder->select_join_targets(
- builder->select_add_target(m_relationship->get_from_table()),
- to_target_id,
- Gnome::Gda::SQL_SELECT_JOIN_LEFT,
- builder->add_cond(
- Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
- builder->add_id("\"" + m_relationship->get_from_table() + "\".\"" + m_relationship->get_from_field() + "\""),
- builder->add_id("\"" + alias_name + "\".\"" + m_relationship->get_to_field() + "\"") ) );
- }
- else
- {
- UsesRelationship parent_relationship;
- parent_relationship.set_relationship(m_relationship);
-
- const guint to_target_id = builder->select_add_target(m_related_relationship->get_to_table(), alias_name);
-
- builder->select_join_targets(
- builder->select_add_target(m_relationship->get_from_table()), //TODO: Must we use the ID from select_add_target_id()?
- to_target_id,
- Gnome::Gda::SQL_SELECT_JOIN_LEFT,
- builder->add_cond(
- Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
- builder->add_id("\"" + parent_relationship.get_sql_join_alias_name() + "\".\"" + m_related_relationship->get_from_field() + "\""),
- builder->add_id("\"" + alias_name + "\".\"" + m_related_relationship->get_to_field() + "\"") ) );
- }
-}
} //namespace Glom
diff --git a/glom/libglom/data_structure/layout/usesrelationship.h b/glom/libglom/data_structure/layout/usesrelationship.h
index 77a6193..7390994 100644
--- a/glom/libglom/data_structure/layout/usesrelationship.h
+++ b/glom/libglom/data_structure/layout/usesrelationship.h
@@ -24,7 +24,6 @@
#include <libglom/data_structure/numeric_format.h>
#include <libglom/data_structure/relationship.h>
#include <libglom/sharedptr.h>
-#include <libgdamm.h>
namespace Glom
{
@@ -60,17 +59,17 @@ public:
* See also get_has_relationship_name() which can prevent the need for your
* own null sharedptr check.
*/
- sharedptr<Relationship> get_relationship() const;
+ sharedptr<const Relationship> get_relationship() const;
- void set_relationship(const sharedptr<Relationship>& relationship);
+ void set_relationship(const sharedptr<const Relationship>& relationship);
/** Return the related relationship used by this item, if any, or a null sharedptr.
* See also get_has_related_relationship_name() which can prevent the need for your
* own null sharedptr check.
*/
- sharedptr<Relationship> get_related_relationship() const;
+ sharedptr<const Relationship> get_related_relationship() const;
- void set_related_relationship(const sharedptr<Relationship>& relationship);
+ void set_related_relationship(const sharedptr<const Relationship>& relationship);
/** Returns either the @a parent_table, related to table, or doubly-related to-table.
*/
@@ -105,12 +104,7 @@ public:
* This will always be the same string for items that have the same definition.
*/
Glib::ustring get_sql_join_alias_name() const;
-
- /** Define the alias name as returned by
- * get_sql_join_alias_name().
- */
- void add_sql_join_alias_definition(const Glib::RefPtr<Gnome::Gda::SqlBuilder>& builder) const;
-
+
/** Get the item's alias name, if it uses a relationship, or just get its table name.
* @param parent_table The table to which the item (or its relatinoships) belong.
*/
@@ -119,8 +113,8 @@ public:
private:
//This is just cached data, so we don't need to always lookup the relationship details from the document, from the name.
- sharedptr<Relationship> m_relationship;
- sharedptr<Relationship> m_related_relationship; //Rarely used. It is for showing fields from the (related) relationships of related tables.
+ sharedptr<const Relationship> m_relationship;
+ sharedptr<const Relationship> m_related_relationship; //Rarely used. It is for showing fields from the (related) relationships of related tables.
};
} //namespace Glom
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 891fe41..cb6ce3d 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -2981,7 +2981,7 @@ void Document::save_before_layout_item_formatting(xmlpp::Element* nodeItem, cons
set_node_attribute_value_as_bool(nodeItem, GLOM_ATTRIBUTE_FORMAT_CHOICES_RELATED, format.get_has_related_choices() );
- sharedptr<Relationship> choice_relationship;
+ sharedptr<const Relationship> choice_relationship;
Glib::ustring choice_field, choice_second;
format.get_choices(choice_relationship, choice_field, choice_second);
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 1d28349..bf659c9 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -258,7 +258,6 @@ void Utils::build_sql_select_add_fields_to_get(const Glib::RefPtr<Gnome::Gda::Sq
}
-
//LEFT OUTER JOIN will get the field values from the other tables,
//and give us our fields for this table even if there is no corresponding value in the other table.
for(type_list_relationships::const_iterator iter = list_relationships.begin(); iter != list_relationships.end(); ++iter)
@@ -267,7 +266,42 @@ void Utils::build_sql_select_add_fields_to_get(const Glib::RefPtr<Gnome::Gda::Sq
sharedptr<const Relationship> relationship = uses_relationship->get_relationship();
if(relationship->get_has_fields()) //TODO: Handle related_record has_fields.
{
- uses_relationship->add_sql_join_alias_definition(builder);
+ // Define the alias name as returned by get_sql_join_alias_name():
+
+ // Specify an alias, to avoid ambiguity when using 2 relationships to the same table.
+ const Glib::ustring alias_name = uses_relationship->get_sql_join_alias_name();
+
+ // Add the JOIN:
+ if(!uses_relationship->get_has_related_relationship_name())
+ {
+ const guint to_target_id = builder->select_add_target(relationship->get_to_table(), alias_name);
+
+ builder->select_join_targets(
+ builder->select_add_target(relationship->get_from_table()),
+ to_target_id,
+ Gnome::Gda::SQL_SELECT_JOIN_LEFT,
+ builder->add_cond(
+ Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
+ builder->add_id("\"" + relationship->get_from_table() + "\".\"" + relationship->get_from_field() + "\""),
+ builder->add_id("\"" + alias_name + "\".\"" + relationship->get_to_field() + "\"") ) );
+ }
+ else
+ {
+ UsesRelationship parent_relationship;
+ parent_relationship.set_relationship(relationship);
+ sharedptr<const Relationship> related_relationship = uses_relationship->get_related_relationship();
+
+ const guint to_target_id = builder->select_add_target(related_relationship->get_to_table(), alias_name);
+
+ builder->select_join_targets(
+ builder->select_add_target(relationship->get_from_table()), //TODO: Must we use the ID from select_add_target_id()?
+ to_target_id,
+ Gnome::Gda::SQL_SELECT_JOIN_LEFT,
+ builder->add_cond(
+ Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
+ builder->add_id("\"" + parent_relationship.get_sql_join_alias_name() + "\".\"" + related_relationship->get_from_field() + "\""),
+ builder->add_id("\"" + alias_name + "\".\"" + related_relationship->get_to_field() + "\"") ) );
+ }
}
else if(relationship->get_has_to_table())
{
@@ -422,7 +456,7 @@ Utils::type_list_values_with_second Utils::get_choice_values(const sharedptr<con
{
type_list_values_with_second list_values;
- sharedptr<Relationship> choice_relationship;
+ sharedptr<const Relationship> choice_relationship;
Glib::ustring choice_field, choice_second;
field->get_formatting_used().get_choices(choice_relationship, choice_field, choice_second);
if(!choice_relationship)
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index d2103ce..4316bd5 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -154,7 +154,7 @@ bool Box_Data_Calendar_Related::fill_from_database()
Gnome::Gda::Value date_end_value(date_end);
//Add a WHERE clause for this date range:
- sharedptr<Relationship> relationship = m_portal->get_relationship();
+ sharedptr<const Relationship> relationship = m_portal->get_relationship();
Glib::ustring where_clause_to_table_name = relationship->get_to_table();
sharedptr<LayoutItem_CalendarPortal> derived_portal = sharedptr<LayoutItem_CalendarPortal>::cast_dynamic(m_portal);
diff --git a/glom/mode_data/datawidget/datawidget.cc b/glom/mode_data/datawidget/datawidget.cc
index 376d235..63d26de 100644
--- a/glom/mode_data/datawidget/datawidget.cc
+++ b/glom/mode_data/datawidget/datawidget.cc
@@ -127,7 +127,7 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
}
else if(field->get_formatting_used().get_has_related_choices())
{
- sharedptr<Relationship> choice_relationship;
+ sharedptr<const Relationship> choice_relationship;
Glib::ustring choice_field, choice_second;
field->get_formatting_used().get_choices(choice_relationship, choice_field, choice_second);
if(choice_relationship && !choice_field.empty())
diff --git a/glom/mode_data/flowtablewithfields.cc b/glom/mode_data/flowtablewithfields.cc
index c39f5ba..2707d2d 100644
--- a/glom/mode_data/flowtablewithfields.cc
+++ b/glom/mode_data/flowtablewithfields.cc
@@ -884,7 +884,7 @@ FlowTableWithFields::type_portals FlowTableWithFields::get_portals(const sharedp
sharedptr<LayoutItem_Portal> portal = pPortalUI->get_portal();
if(portal)
{
- sharedptr<Relationship> relationship = portal->get_relationship(); //In this case, we only care about the first relationship (not any child relationships), because that's what would trigger a change.
+ sharedptr<const Relationship> relationship = portal->get_relationship(); //In this case, we only care about the first relationship (not any child relationships), because that's what would trigger a change.
if(relationship && (relationship->get_from_field() == from_key_name))
result.push_back(pPortalUI);
}
diff --git a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
index 9bb0651..2ea2f5c 100644
--- a/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/box_formatting.cc
@@ -231,7 +231,7 @@ void Box_Formatting::set_formatting(const FieldFormatting& format, bool show_num
const Document::type_vec_relationships vecRelationships = document->get_relationships(m_table_name);
m_combo_choices_relationship->set_relationships(vecRelationships);
- sharedptr<Relationship> choices_relationship;
+ sharedptr<const Relationship> choices_relationship;
Glib::ustring choices_field, choices_field_second;
format.get_choices(choices_relationship, choices_field, choices_field_second);
diff --git a/glom/print_layout/canvas_print_layout.cc b/glom/print_layout/canvas_print_layout.cc
index 4501b30..1fe9e08 100644
--- a/glom/print_layout/canvas_print_layout.cc
+++ b/glom/print_layout/canvas_print_layout.cc
@@ -611,7 +611,7 @@ void Canvas_PrintLayout::fill_with_data(const Glib::RefPtr<Goocanvas::Group>& ca
if(layoutitem_portal)
{
//Fill the related records table:
- sharedptr<Relationship> relationship = layoutitem_portal->get_relationship();
+ sharedptr<const Relationship> relationship = layoutitem_portal->get_relationship();
if(relationship)
{
sharedptr<Field> from_field = get_fields_for_table_one_field(relationship->get_from_table(), relationship->get_from_field());
diff --git a/glom/utility_widgets/db_adddel/db_adddel.cc b/glom/utility_widgets/db_adddel/db_adddel.cc
index 44a5d66..231660b 100644
--- a/glom/utility_widgets/db_adddel/db_adddel.cc
+++ b/glom/utility_widgets/db_adddel/db_adddel.cc
@@ -844,7 +844,7 @@ Gtk::CellRenderer* DbAddDel::construct_specified_columns_cellrenderer(const shar
}
else if(item_field && item_field->get_formatting_used().get_has_related_choices())
{
- sharedptr<Relationship> choice_relationship;
+ sharedptr<const Relationship> choice_relationship;
Glib::ustring choice_field, choice_second;
item_field->get_formatting_used().get_choices(choice_relationship, choice_field, choice_second);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]