glom r1881 - in trunk: . glom glom/mode_data
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1881 - in trunk: . glom glom/mode_data
- Date: Fri, 6 Feb 2009 10:36:51 +0000 (UTC)
Author: murrayc
Date: Fri Feb 6 10:36:51 2009
New Revision: 1881
URL: http://svn.gnome.org/viewvc/glom?rev=1881&view=rev
Log:
2009-02-06 Murray Cumming <murrayc murrayc com>
* glom/base_db.cc: get_table_names_from_database(): Comment out the
checks for internal tables, because that is now fixed in libgda.
* glom/mode_data/box_data.[h|cc]:
* glom/base_db_table_data.[h|cc]: Move refresh_related_fields()
(which is virtual) and get_related_fields() down the hierarchy so that
the override is also used by DbAddDel, so related fields are updated
in the view on list views and related records.
This really fixes bug #569722 (Johannes Schmid)
Modified:
trunk/ChangeLog
trunk/glom/base_db.cc
trunk/glom/base_db_table_data.cc
trunk/glom/base_db_table_data.h
trunk/glom/mode_data/box_data.cc
trunk/glom/mode_data/box_data.h
trunk/glom/mode_data/box_data_list_related.cc
Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc (original)
+++ trunk/glom/base_db.cc Fri Feb 6 10:36:51 2009
@@ -426,12 +426,14 @@
continue;
//Ignore the pg_* tables that something (Postgres? libgda?) adds:
- if(table_name.substr(0, 14) == "pg_catalog.pg_")
- continue;
+ //Not needed now that this was fixed again in libgda-4.0.
+ //if(table_name.substr(0, 14) == "pg_catalog.pg_")
+ // continue;
//Ignore the information_schema tables that something (libgda?) adds:
- if(table_name.substr(0, 23) == "information_schema.sql_")
- continue;
+ //Not needed now that this was fixed again in libgda-4.0.
+ //if(table_name.substr(0, 23) == "information_schema.sql_")
+ // continue;
result.push_back(table_name);
}
Modified: trunk/glom/base_db_table_data.cc
==============================================================================
--- trunk/glom/base_db_table_data.cc (original)
+++ trunk/glom/base_db_table_data.cc Fri Feb 6 10:36:51 2009
@@ -470,6 +470,102 @@
return m_signal_record_changed;
}
+
+void Base_DB_Table_Data::refresh_related_fields(const LayoutFieldInRecord& field_in_record_changed, const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& /* field_value */)
+{
+ //std::cout << "DEBUG: Base_DB_Table_Data::refresh_related_fields()" << std::endl;
+
+ if(field_in_record_changed.m_table_name != m_table_name)
+ return; //TODO: Handle these too?
+
+ //Get values for lookup fields, if this field triggers those relationships:
+ //TODO_performance: There is a LOT of iterating and copying here.
+ //const Glib::ustring strFieldName = field_in_record_changed.m_field->get_name();
+ type_vecLayoutFields fieldsToGet = get_related_fields(field_in_record_changed.m_field);
+
+ if(!fieldsToGet.empty())
+ {
+ const Glib::ustring query = Utils::build_sql_select_with_key(field_in_record_changed.m_table_name, fieldsToGet, field_in_record_changed.m_key, field_in_record_changed.m_key_value);
+ //std::cout << "DEBUG: Base_DB_Table_Data::refresh_related_fields(): query=" << query << std::endl;
+
+ Glib::RefPtr<Gnome::Gda::DataModel> result = query_execute_select(query);
+ if(!result)
+ {
+ std::cerr << "Base_DB_Table_Data::refresh_related_fields(): no result." << std::endl;
+ handle_error();
+ }
+ else
+ {
+ //Field contents:
+ if(result->get_n_rows())
+ {
+ type_vecLayoutFields::const_iterator iterFields = fieldsToGet.begin();
+
+ const guint cols_count = result->get_n_columns();
+ if(cols_count <= 0)
+ {
+ std::cerr << "Base_DB_Table_Data::refresh_related_fields(): The result had 0 columns" << std::endl;
+ }
+
+ for(guint uiCol = 0; uiCol < cols_count; uiCol++)
+ {
+ const Gnome::Gda::Value value = result->get_value_at(uiCol, 0 /* row */);
+ sharedptr<LayoutItem_Field> layout_item = *iterFields;
+ if(!layout_item)
+ std::cerr << "Base_DB_Table_Data::refresh_related_fields(): The layout_item was null." << std::endl;
+ else
+ {
+ //std::cout << "DEBUG: Box_Data_List::refresh_related_fields(): field_name=" << layout_item->get_name() << std::endl;
+ //std::cout << " DEBUG: Box_Data_List::refresh_related_fields(): value_as_string=" << value.to_string() << std::endl;
+
+ //m_AddDel.set_value(row, layout_item, value);
+ set_entered_field_data(row, layout_item, value);
+ //g_warning("addedel size=%d", m_AddDel.get_count());
+ }
+
+ ++iterFields;
+ }
+ }
+ else
+ std::cerr << "Base_DB_Table_Data::refresh_related_fields(): no records found." << std::endl;
+ }
+ }
+}
+
+/** Get the shown fields that are in related tables, via a relationship using @a field_name changes.
+ */
+Base_DB_Table_Data::type_vecLayoutFields Base_DB_Table_Data::get_related_fields(const sharedptr<const LayoutItem_Field>& field) const
+{
+ type_vecLayoutFields result;
+
+ const Document_Glom* document = dynamic_cast<const Document_Glom*>(get_document());
+ if(document)
+ {
+ const Glib::ustring field_name = field->get_name(); //At the moment, relationships can not be based on related fields on the from side.
+ for(type_vecLayoutFields::const_iterator iter = m_FieldsShown.begin(); iter != m_FieldsShown.end(); ++iter)
+ {
+ sharedptr<LayoutItem_Field> layout_field = *iter;
+ //Examine each field that looks up its data from a relationship:
+ if(layout_field->get_has_relationship_name())
+ {
+ //Get the relationship information:
+ sharedptr<const Relationship> relationship = document->get_relationship(m_table_name, layout_field->get_relationship_name());
+ if(relationship)
+ {
+ //If the relationship uses the specified field:
+ if(relationship->get_from_field() == field_name)
+ {
+ //Add it:
+ result.push_back(layout_field);
+ }
+ }
+ }
+ }
+ }
+
+ return result;
+}
+
} //namespace Glom
Modified: trunk/glom/base_db_table_data.h
==============================================================================
--- trunk/glom/base_db_table_data.h (original)
+++ trunk/glom/base_db_table_data.h Fri Feb 6 10:36:51 2009
@@ -63,6 +63,12 @@
virtual Gnome::Gda::Value get_primary_key_value_selected() const = 0;
virtual void set_primary_key_value(const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& value) = 0;
virtual Gnome::Gda::Value get_primary_key_value(const Gtk::TreeModel::iterator& row) const = 0;
+
+ virtual void refresh_related_fields(const LayoutFieldInRecord& field_in_record_changed, const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& field_value);
+
+ /** Get the fields that are in related tables, via a relationship using @a field_name changes.
+ */
+ type_vecLayoutFields get_related_fields(const sharedptr<const LayoutItem_Field>& field) const;
/** Ask the user if he really wants to delete the record.
*/
Modified: trunk/glom/mode_data/box_data.cc
==============================================================================
--- trunk/glom/mode_data/box_data.cc (original)
+++ trunk/glom/mode_data/box_data.cc Fri Feb 6 10:36:51 2009
@@ -247,99 +247,6 @@
return type_vecLayoutFields();
}
-/** Get the shown fields that are in related tables, via a relationship using @a field_name changes.
- */
-Box_Data::type_vecLayoutFields Box_Data::get_related_fields(const sharedptr<const LayoutItem_Field>& field) const
-{
- type_vecLayoutFields result;
-
- const Document_Glom* document = dynamic_cast<const Document_Glom*>(get_document());
- if(document)
- {
- const Glib::ustring field_name = field->get_name(); //At the moment, relationships can not be based on related fields on the from side.
- for(type_vecLayoutFields::const_iterator iter = m_FieldsShown.begin(); iter != m_FieldsShown.end(); ++iter)
- {
- sharedptr<LayoutItem_Field> layout_field = *iter;
- //Examine each field that looks up its data from a relationship:
- if(layout_field->get_has_relationship_name())
- {
- //Get the relationship information:
- sharedptr<const Relationship> relationship = document->get_relationship(m_table_name, layout_field->get_relationship_name());
- if(relationship)
- {
- //If the relationship uses the specified field:
- if(relationship->get_from_field() == field_name)
- {
- //Add it:
- result.push_back(layout_field);
- }
- }
- }
- }
- }
-
- return result;
-}
-
-void Box_Data::refresh_related_fields(const LayoutFieldInRecord& field_in_record_changed, const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& /* field_value */)
-{
- if(field_in_record_changed.m_table_name != m_table_name)
- return; //TODO: Handle these too?
-
- //Get values for lookup fields, if this field triggers those relationships:
- //TODO_performance: There is a LOT of iterating and copying here.
- //const Glib::ustring strFieldName = field_in_record_changed.m_field->get_name();
- type_vecLayoutFields fieldsToGet = get_related_fields(field_in_record_changed.m_field);
-
- if(!fieldsToGet.empty())
- {
- const Glib::ustring query = Utils::build_sql_select_with_key(field_in_record_changed.m_table_name, fieldsToGet, field_in_record_changed.m_key, field_in_record_changed.m_key_value);
- std::cout << "DEBUG: Box_Data::refresh_related_fields(): query=" << query << std::endl;
-
- Glib::RefPtr<Gnome::Gda::DataModel> result = query_execute_select(query);
- if(!result)
- {
- std::cerr << "Box_Data_List::refresh_related_fields(): no result." << std::endl;
- handle_error();
- }
- else
- {
- //Field contents:
- if(result->get_n_rows())
- {
- type_vecLayoutFields::const_iterator iterFields = fieldsToGet.begin();
-
- const guint cols_count = result->get_n_columns();
- if(cols_count <= 0)
- {
- std::cerr << "Box_Data_List::refresh_related_fields(): The result had 0 columns" << std::endl;
- }
-
- for(guint uiCol = 0; uiCol < cols_count; uiCol++)
- {
- const Gnome::Gda::Value value = result->get_value_at(uiCol, 0 /* row */);
- sharedptr<LayoutItem_Field> layout_item = *iterFields;
- if(!layout_item)
- std::cerr << "Box_Data_List::refresh_related_fields(): The layout_item was null." << std::endl;
- else
- {
- //std::cout << "DEBUG: Box_Data_List::refresh_related_fields(): field_name=" << layout_item->get_name() << std::endl;
- //std::cout << " DEBUG: Box_Data_List::refresh_related_fields(): value_as_string=" << value.to_string() << std::endl;
-
- //m_AddDel.set_value(row, layout_item, value);
- set_entered_field_data(row, layout_item, value);
- //g_warning("addedel size=%d", m_AddDel.get_count());
- }
-
- ++iterFields;
- }
- }
- else
- std::cerr << "Box_Data_List::refresh_related_fields(): no records found." << std::endl;
- }
- }
-}
-
Document_Glom::type_list_layout_groups Box_Data::get_data_layout_groups(const Glib::ustring& layout_name, const Glib::ustring& layout_platform)
{
Document_Glom::type_list_layout_groups layout_groups;
Modified: trunk/glom/mode_data/box_data.h
==============================================================================
--- trunk/glom/mode_data/box_data.h (original)
+++ trunk/glom/mode_data/box_data.h Fri Feb 6 10:36:51 2009
@@ -97,8 +97,6 @@
///Fill the existing layout with data from the database.
virtual bool fill_from_database(); //override.
- virtual void refresh_related_fields(const LayoutFieldInRecord& field_in_record_changed, const Gtk::TreeModel::iterator& row, const Gnome::Gda::Value& field_value);
-
virtual type_vecLayoutFields get_fields_to_show() const;
type_vecLayoutFields get_table_fields_to_show(const Glib::ustring& table_name) const;
@@ -108,11 +106,6 @@
Document_Glom::type_list_layout_groups get_data_layout_groups(const Glib::ustring& layout_name, const Glib::ustring& layout_platform);
void fill_layout_group_field_info(const sharedptr<LayoutGroup>& group, const Privileges& table_privs);
-
- /** Get the fields that are in related tables, via a relationship using @a field_name changes.
- */
- type_vecLayoutFields get_related_fields(const sharedptr<const LayoutItem_Field>& field) const;
-
void execute_button_script(const sharedptr<const LayoutItem_Button>& layout_item, const Gnome::Gda::Value& primary_key_value);
//Signal handlers:
Modified: trunk/glom/mode_data/box_data_list_related.cc
==============================================================================
--- trunk/glom/mode_data/box_data_list_related.cc (original)
+++ trunk/glom/mode_data/box_data_list_related.cc Fri Feb 6 10:36:51 2009
@@ -240,7 +240,7 @@
//primary_key_value is a new autogenerated or human-entered key for the row.
//It has already been added to the database.
//Gnome::Gda::Value primary_key_value = m_AddDel.get_value_key(row);
- std::cout << "Box_Data_List_Related::on_adddel_record_added(): primary_key_value=" << primary_key_value.to_string() << std::endl;
+ //std::cout << "Box_Data_List_Related::on_adddel_record_added(): primary_key_value=" << primary_key_value.to_string() << std::endl;
if(!row)
@@ -282,7 +282,7 @@
Glib::ustring strQuery = "UPDATE \"" + m_portal->get_table_used(Glib::ustring() /* not relevant */) + "\"";
strQuery += " SET \"" + /* get_table_name() + "." +*/ m_key_field->get_name() + "\" = " + m_key_field->get_gda_holder_string();
strQuery += " WHERE \"" + get_table_name() + "\".\"" + field_primary_key->get_name() + "\" = " + field_primary_key->get_gda_holder_string();
- std::cout << "Box_Data_List_Related::on_adddel_record_added(): setting value in db=" << primary_key_value.to_string() << std::endl;
+ //std::cout << "Box_Data_List_Related::on_adddel_record_added(): setting value in db=" << primary_key_value.to_string() << std::endl;
const bool test = query_execute(strQuery, params);
if(test)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]