[glom] Use SqlBuilder::add_field_id() to avoid ambiguity.



commit c03e888400b5d6d3b983ae08978cd0c768b70121
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Jun 15 22:55:36 2010 +0200

    Use SqlBuilder::add_field_id() to avoid ambiguity.
    
    * glom/base_db.cc:
    * glom/base_db_table_data.cc:
    * glom/libglom/db_utils.cc:
    * glom/libglom/privs.cc:
    * glom/libglom/python_embed/py_glom_record.cc:
    * glom/libglom/python_embed/py_glom_relatedrecord.cc:
    * glom/libglom/utils.cc:
    * glom/mode_data/box_data.cc:
    * glom/mode_data/box_data_calendar_related.cc:
    * glom/mode_data/box_data_portal.cc:
    * glom/mode_design/dialog_database_preferences.cc:
    * glom/mode_design/fields/box_db_table_definition.cc:
    * glom/report_builder.cc: Replace use of add_id() with the new add_field_id(),
    which lets us specify the table too.

 ChangeLog                                          |   19 +++++++++++++++++++
 glom/base_db.cc                                    |   13 +++++++------
 glom/base_db_table_data.cc                         |   11 ++++++-----
 glom/libglom/db_utils.cc                           |   18 +++++++++---------
 glom/libglom/privs.cc                              |    6 +++---
 glom/libglom/python_embed/py_glom_record.cc        |    2 +-
 glom/libglom/python_embed/py_glom_relatedrecord.cc |    4 ++--
 glom/libglom/utils.cc                              |   16 ++++++++--------
 glom/mode_data/box_data.cc                         |    2 +-
 glom/mode_data/box_data_calendar_related.cc        |    8 ++++----
 glom/mode_data/box_data_portal.cc                  |    5 +++--
 glom/mode_design/dialog_database_preferences.cc    |    4 ++--
 glom/mode_design/fields/box_db_table_definition.cc |    2 +-
 glom/report_builder.cc                             |    2 +-
 14 files changed, 67 insertions(+), 45 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fc4a8cf..a636ae5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
 2010-06-15  Murray Cumming  <murrayc murrayc com>
 
+	Use SqlBuilder::add_field_id() to avoid ambiguity.
+
+	* glom/base_db.cc:
+	* glom/base_db_table_data.cc:
+	* glom/libglom/db_utils.cc:
+	* glom/libglom/privs.cc:
+	* glom/libglom/python_embed/py_glom_record.cc:
+	* glom/libglom/python_embed/py_glom_relatedrecord.cc:
+	* glom/libglom/utils.cc:
+	* glom/mode_data/box_data.cc:
+	* glom/mode_data/box_data_calendar_related.cc:
+	* glom/mode_data/box_data_portal.cc:
+	* glom/mode_design/dialog_database_preferences.cc:
+	* glom/mode_design/fields/box_db_table_definition.cc:
+	* glom/report_builder.cc: Replace use of add_id() with the new add_field_id(), 
+	which lets us specify the table too.
+
+2010-06-15  Murray Cumming  <murrayc murrayc com>
+
 	Adapt to latest libgdamm API.
 
 	* glom/base_db.cc:
diff --git a/glom/base_db.cc b/glom/base_db.cc
index dc5c1fd..f7412ea 100644
--- a/glom/base_db.cc
+++ b/glom/base_db.cc
@@ -1228,7 +1228,7 @@ bool Base_DB::set_field_value_in_database(const LayoutFieldInRecord& layoutfield
     builder->add_field_value_as_value(field_in_record.m_field->get_name(), field_value);
     builder->set_where(
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-        builder->add_id(field_in_record.m_key->get_name()),
+        builder->add_field_id(field_in_record.m_key->get_name(), field_in_record.m_table_name),
         builder->add_expr_as_value(field_in_record.m_key_value)));
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -1613,13 +1613,14 @@ Gnome::Gda::Value Base_DB::get_lookup_value(const Glib::ustring& /* table_name *
     //Convert the value, in case the from and to fields have different types:
     const Gnome::Gda::Value value_to_key_field = Conversions::convert_value(key_value, to_key_field->get_glom_type());
 
+    const Glib::ustring target_table = relationship->get_to_table();
     Glib::RefPtr<Gnome::Gda::SqlBuilder> builder =
       Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
-    builder->select_add_field(source_field->get_name(), relationship->get_to_table());
-    builder->select_add_target(relationship->get_to_table());
+    builder->select_add_field(source_field->get_name(), target_table );
+    builder->select_add_target(target_table );
     builder->set_where(
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-        builder->add_id(to_key_field->get_name()), //TODO: It would be nice to specify the table here too.
+        builder->add_field_id(to_key_field->get_name(), target_table),
         builder->add_expr(value_to_key_field)));
 
     Glib::RefPtr<Gnome::Gda::DataModel> data_model = DbUtils::query_execute_select(builder);
@@ -1654,7 +1655,7 @@ bool Base_DB::get_field_value_is_unique(const Glib::ustring& table_name, const s
   builder->select_add_target(table_name_used);
   builder->set_where(
     builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-      builder->add_id(field->get_name()), //TODO: It would be nice to specify the table here too.
+      builder->add_field_id(field->get_name(), table_name_used),
       builder->add_expr(value)));
 
   Glib::RefPtr<const Gnome::Gda::DataModel> data_model = DbUtils::query_execute_select(builder);
@@ -1854,7 +1855,7 @@ bool Base_DB::get_primary_key_is_in_foundset(const FoundSet& found_set, const Gn
   builder->select_add_target(found_set.m_table_name);
 
   const guint eq_id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-        builder->add_id(primary_key->get_name()),
+        builder->add_field_id(primary_key->get_name(), found_set.m_table_name),
         builder->add_expr_as_value(primary_key_value));
   guint cond_id = 0;
   if(found_set.m_where_clause.empty())
diff --git a/glom/base_db_table_data.cc b/glom/base_db_table_data.cc
index 38ceaa2..9944fa6 100644
--- a/glom/base_db_table_data.cc
+++ b/glom/base_db_table_data.cc
@@ -276,7 +276,7 @@ bool Base_DB_Table_Data::get_related_record_exists(const sharedptr<const Relatio
   builder->select_add_target(related_table);
   builder->set_where(
     builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-      builder->add_id(to_field), //TODO: It would be nice to specify the table here too.
+      builder->add_field_id(to_field, related_table),
       builder->add_expr(key_value)));
                                                
   Glib::RefPtr<Gnome::Gda::DataModel> records = DbUtils::query_execute_select(builder);
@@ -410,14 +410,15 @@ bool Base_DB_Table_Data::add_related_record_for_field(const sharedptr<const Layo
             return false;
           }
           else
-          {              
+          {
+            const Glib::ustring target_table = relationship->get_from_table();             
             Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = 
               Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
-            builder->set_table(relationship->get_from_table());
+            builder->set_table(target_table);
             builder->add_field_value_as_value(relationship->get_from_field(), primary_key_value);
             builder->set_where(
               builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-                builder->add_id(parent_primary_key_field->get_name()),
+                builder->add_field_id(parent_primary_key_field->get_name(), target_table),
                 builder->add_expr(parent_primary_key_value)) );
           
             const bool test = DbUtils::query_execute(builder);
@@ -478,7 +479,7 @@ bool Base_DB_Table_Data::record_delete(const Gnome::Gda::Value& primary_key_valu
     builder->set_table(m_table_name);
     builder->set_where(
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-        builder->add_id(field_primary_key->get_name()),
+        builder->add_field_id(field_primary_key->get_name(), m_table_name),
         builder->add_expr(primary_key_value)) );
     return DbUtils::query_execute(builder);
   }
diff --git a/glom/libglom/db_utils.cc b/glom/libglom/db_utils.cc
index d6c1ff5..2bd3852 100644
--- a/glom/libglom/db_utils.cc
+++ b/glom/libglom/db_utils.cc
@@ -479,7 +479,7 @@ void set_database_preferences(Document* document, const SystemPrefs& prefs)
     builder->add_field_value(GLOM_STANDARD_TABLE_PREFS_FIELD_ORG_LOGO, prefs.m_org_logo);
   }
   builder->set_where(builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-                                       builder->add_id(GLOM_STANDARD_TABLE_PREFS_FIELD_ID),
+                                       builder->add_field_id(GLOM_STANDARD_TABLE_PREFS_FIELD_ID, GLOM_STANDARD_TABLE_PREFS_TABLE_NAME),
                                        builder->add_expr(1)));
   const bool test = query_execute(builder);
 
@@ -523,7 +523,7 @@ bool add_standard_tables(Document* document)
           builder->set_table(GLOM_STANDARD_TABLE_PREFS_TABLE_NAME);
           builder->add_field_value(GLOM_STANDARD_TABLE_PREFS_FIELD_NAME, system_name);
           builder->set_where(builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-                                               builder->add_id(GLOM_STANDARD_TABLE_PREFS_FIELD_ID),
+                                               builder->add_field_id(GLOM_STANDARD_TABLE_PREFS_FIELD_ID, GLOM_STANDARD_TABLE_PREFS_TABLE_NAME),
                                                builder->add_expr(1)));
           const bool test = query_execute(builder);
           if(!test)
@@ -1295,10 +1295,10 @@ Gnome::Gda::Value get_next_auto_increment_value(const Glib::ustring& table_name,
   builder->add_field_value_as_value(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_NEXT_VALUE, next_value);
   builder->set_where(builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_AND,
                                        builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-                                                         builder->add_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME),
+                                                         builder->add_field_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME, GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME),
                                                          builder->add_expr(table_name)),
                                        builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-                                                         builder->add_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME),
+                                                         builder->add_field_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME, GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME),
                                                          builder->add_expr(field_name))));
   const bool test = query_execute(builder);
   if(!test)
@@ -1326,10 +1326,10 @@ Gnome::Gda::Value auto_increment_insert_first_if_necessary(const Glib::ustring&
   builder->set_where(
     builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_AND,
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-        builder->add_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME),
+        builder->add_field_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME, GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME),
         builder->add_expr(table_name)),
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-        builder->add_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME),
+        builder->add_field_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME, GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME),
         builder->add_expr(field_name))));
 
   const Glib::RefPtr<const Gnome::Gda::DataModel> datamodel = query_execute_select(builder);
@@ -1384,7 +1384,7 @@ static void recalculate_next_auto_increment_value(const Glib::ustring& table_nam
   //Get the max key value in the database:
   Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
   std::list<guint> args;
-  args.push_back(builder->add_id(table_name + "." + field_name));
+  args.push_back(builder->add_field_id(field_name, table_name));
   builder->add_field_value_id(builder->add_function("MAX", args));
   builder->select_add_target(table_name);
 
@@ -1410,10 +1410,10 @@ static void recalculate_next_auto_increment_value(const Glib::ustring& table_nam
     builder->add_field_value_as_value(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_NEXT_VALUE, next_value);
     builder->set_where(builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_AND,
                                          builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-                                                           builder->add_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME),
+                                                           builder->add_field_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME, GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME),
                                                            builder->add_expr(table_name)),
                                          builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-                                                           builder->add_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME),
+                                                           builder->add_field_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME, GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME),
                                                            builder->add_expr(field_name))));
 
     const bool test = query_execute(builder);
diff --git a/glom/libglom/privs.cc b/glom/libglom/privs.cc
index 622149c..474f846 100644
--- a/glom/libglom/privs.cc
+++ b/glom/libglom/privs.cc
@@ -138,7 +138,7 @@ Privs::type_vec_strings Privs::get_database_users(const Glib::ustring& group_nam
     builder->select_add_target("pg_group");
     builder->set_where(
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-        builder->add_id("groname"), //TODO: It would be nice to specify the table here too.
+        builder->add_field_id("groname", "pg_group"),
         builder->add_expr(group_name)));
     Glib::RefPtr<Gnome::Gda::DataModel> data_model = DbUtils::query_execute_select(builder);
     if(data_model && data_model->get_n_rows())
@@ -168,7 +168,7 @@ Privs::type_vec_strings Privs::get_database_users(const Glib::ustring& group_nam
           builder->select_add_target("pg_user");
           builder->set_where(
             builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-              builder->add_id("usesysid"), //TODO: It would be nice to specify the table here too.
+              builder->add_field_id("usesysid", "pg_user"),
               builder->add_expr(*iter)));
           Glib::RefPtr<Gnome::Gda::DataModel> data_model = DbUtils::query_execute_select(builder);
           if(data_model)
@@ -284,7 +284,7 @@ Privileges Privs::get_table_privileges(const Glib::ustring& group_name, const Gl
   builder->select_add_target("pg_class");
   builder->set_where(
     builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-      builder->add_id("relname"), //TODO: It would be nice to specify the table here too.
+      builder->add_field_id("relname", "pg_class"),
       builder->add_expr(table_name)));
   Glib::RefPtr<Gnome::Gda::DataModel> data_model = DbUtils::query_execute_select(builder);
   if(data_model && data_model->get_n_rows())
diff --git a/glom/libglom/python_embed/py_glom_record.cc b/glom/libglom/python_embed/py_glom_record.cc
index 7cdc826..1ba6454 100644
--- a/glom/libglom/python_embed/py_glom_record.cc
+++ b/glom/libglom/python_embed/py_glom_record.cc
@@ -184,7 +184,7 @@ void PyGlomRecord::setitem(const boost::python::object& key, const boost::python
   builder->add_field_value_as_value(field->get_name(), field_value);
   builder->set_where(
     builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-      builder->add_id(m_key_field->get_name()),
+      builder->add_field_id(m_key_field->get_name(), m_table_name),
       builder->add_expr(m_key_field_value)));
  
   bool updated = false;
diff --git a/glom/libglom/python_embed/py_glom_relatedrecord.cc b/glom/libglom/python_embed/py_glom_relatedrecord.cc
index d29b934..c9da021 100644
--- a/glom/libglom/python_embed/py_glom_relatedrecord.cc
+++ b/glom/libglom/python_embed/py_glom_relatedrecord.cc
@@ -110,7 +110,7 @@ boost::python::object PyGlomRelatedRecord::getitem(const boost::python::object&
     builder->select_add_target(related_table);
     builder->set_where(
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-        builder->add_id(related_key_name), //TODO: It would nice to specify the table name here too.
+        builder->add_field_id(related_key_name, related_table),
         builder->add_expr(m_from_key_value)));
 
     /* TODO: Fix linking problems
@@ -202,7 +202,7 @@ boost::python::object PyGlomRelatedRecord::generic_aggregate(const std::string&
   builder->select_add_target(related_table);
   builder->set_where(
     builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-      builder->add_id(related_key_name), //TODO: It would nice to specify the table name here too.
+      builder->add_field_id(related_key_name, related_table),
       builder->add_expr(m_from_key_value)));
 
 
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index 87f3a13..95328e0 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -269,8 +269,8 @@ static void builder_add_join(const Glib::RefPtr<Gnome::Gda::SqlBuilder>& builder
       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() + "\"") ) );
+        builder->add_field_id(relationship->get_from_field(), relationship->get_from_table()),
+        builder->add_field_id(relationship->get_to_field(), alias_name)));
   }
   else
   {
@@ -286,8 +286,8 @@ static void builder_add_join(const Glib::RefPtr<Gnome::Gda::SqlBuilder>& builder
        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() + "\"") ) );
+         builder->add_field_id(related_relationship->get_from_field(), parent_relationship.get_sql_join_alias_name()),
+         builder->add_field_id(related_relationship->get_to_field(), alias_name) ) );
   }
 }
 
@@ -338,7 +338,7 @@ void Utils::build_sql_select_add_fields_to_get(const Glib::RefPtr<Gnome::Gda::Sq
     {
       const guint id_function = builder->add_function(
         fieldsummary->get_summary_type_sql(),
-        builder->add_id(layout_item->get_sql_name(table_name)) ); //TODO: It would be nice to specify the table here too.
+        builder->add_id(layout_item->get_sql_name(table_name)) ); //TODO: Just use add_field_id()?
       builder->add_field_value_id(id_function);
     }
     else
@@ -399,7 +399,7 @@ Glib::RefPtr<Gnome::Gda::SqlBuilder> Utils::build_sql_select_with_where_clause(c
 
         //TODO: Avoid the need for the "."
         builder->select_order_by(
-          builder->add_id(layout_item->get_sql_table_or_join_alias_name("\"" + table_name) + "\".\"" + layout_item->get_name() + "\""),
+          builder->add_field_id(layout_item->get_name(), layout_item->get_sql_table_or_join_alias_name(table_name)),
           ascending);
       }
     }
@@ -432,7 +432,7 @@ Gnome::Gda::SqlExpr Utils::build_simple_where_expression(const Glib::ustring& ta
   Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
   builder->select_add_target(table_name);  //This might not be necessary.
   const guint id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-    builder->add_id(key_field->get_name()),
+    builder->add_field_id(key_field->get_name(), table_name),
     builder->add_expr(key_value));
   builder->set_where(id); //This might not be necessary.
 
@@ -994,7 +994,7 @@ Gnome::Gda::SqlExpr Utils::get_find_where_clause_quick(Document* document, const
     if(use_this_field)
     {
       const guint eq_id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ, //TODO: Ue field->sql_find_operator().
-        builder->add_id(field->get_name()),
+        builder->add_field_id(field->get_name(), table_name),
         builder->add_expr(quick_search)); //Use  field->sql_find(quick_search);
 
       guint and_id = 0;
diff --git a/glom/mode_data/box_data.cc b/glom/mode_data/box_data.cc
index acd0063..577b7a3 100644
--- a/glom/mode_data/box_data.cc
+++ b/glom/mode_data/box_data.cc
@@ -112,7 +112,7 @@ Gnome::Gda::SqlExpr Box_Data::get_find_where_clause() const
         if(use_this_field)
         {
           const guint cond_id = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ, //TODO: Use field->sql_find_operator()
-            builder->add_id(field->get_name()), //TODO: Specify m_table_name too?
+            builder->add_field_id(field->get_name(), m_table_name),
             builder->add_expr(data));
 
           //And with previous condition, if any:
diff --git a/glom/mode_data/box_data_calendar_related.cc b/glom/mode_data/box_data_calendar_related.cc
index 1942bfd..c812c72 100644
--- a/glom/mode_data/box_data_calendar_related.cc
+++ b/glom/mode_data/box_data_calendar_related.cc
@@ -171,12 +171,11 @@ bool Box_Data_Calendar_Related::fill_from_database()
 
     //Add an AND to the existing where clause, to get only records within these dates, if any:
     sharedptr<const Field> date_field = derived_portal->get_date_field();
-    //TODO: Use a SQL parameter instead of using sql().
 
     Glib::RefPtr<Gnome::Gda::SqlBuilder> builder =
       Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_SELECT);
     const guint cond = builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_BETWEEN,
-       builder->add_id(date_field->get_name()),
+       builder->add_field_id(date_field->get_name(), m_found_set.m_table_name),
        builder->add_expr_as_value(date_start_value),
        builder->add_expr_as_value(date_end_value));
     builder->set_where(cond); //Might be unnecessary.
@@ -300,11 +299,12 @@ void Box_Data_Calendar_Related::on_record_added(const Gnome::Gda::Value& primary
     if(m_key_field && m_portal)
     {
       Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
-      builder->set_table(m_portal->get_table_used(Glib::ustring() /* not relevant */));
+      const Glib::ustring target_table = m_portal->get_table_used(Glib::ustring() /* not relevant */);
+      builder->set_table(target_table);
       builder->add_field_value_as_value(m_key_field->get_name(), m_key_value);
       builder->set_where(
         builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-          builder->add_id(field_primary_key->get_name()),
+          builder->add_field_id(field_primary_key->get_name(), target_table),
           builder->add_expr_as_value(primary_key_value)));
 
       const bool test = DbUtils::query_execute(builder);
diff --git a/glom/mode_data/box_data_portal.cc b/glom/mode_data/box_data_portal.cc
index df041c6..12c8cc6 100644
--- a/glom/mode_data/box_data_portal.cc
+++ b/glom/mode_data/box_data_portal.cc
@@ -109,12 +109,13 @@ void Box_Data_Portal::make_record_related(const Gnome::Gda::Value& related_recor
     std::cerr << "Box_Data_Portal::make_record_related(): m_portal was null." << std::endl;
   }
 
+  const Glib::ustring target_table = m_portal->get_table_used(Glib::ustring() /* not relevant */);
   Glib::RefPtr<Gnome::Gda::SqlBuilder> builder = Gnome::Gda::SqlBuilder::create(Gnome::Gda::SQL_STATEMENT_UPDATE);
-    builder->set_table(m_portal->get_table_used(Glib::ustring() /* not relevant */));
+    builder->set_table(target_table);
     builder->add_field_value_as_value(m_key_field->get_name(), m_key_value);
     builder->set_where(
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-        builder->add_id(field_primary_key->get_name()),
+        builder->add_field_id(field_primary_key->get_name(), target_table),
         builder->add_expr_as_value(related_record_primary_key_value)));
 
   //std::cout << "Box_Data_Portal::make_record_related(): setting value in db=" << primary_key_value.to_string() << std::endl;
diff --git a/glom/mode_design/dialog_database_preferences.cc b/glom/mode_design/dialog_database_preferences.cc
index 28c8dcf..af7ca02 100644
--- a/glom/mode_design/dialog_database_preferences.cc
+++ b/glom/mode_design/dialog_database_preferences.cc
@@ -133,10 +133,10 @@ void Dialog_Database_Preferences::on_treeview_cell_edited_next_value(const Glib:
     builder->set_where(
       builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_AND,
         builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-          builder->add_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME),
+          builder->add_field_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_TABLE_NAME, GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME),
           builder->add_expr(table_name)),
         builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_EQ,
-          builder->add_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME),
+          builder->add_field_id(GLOM_STANDARD_TABLE_AUTOINCREMENTS_FIELD_FIELD_NAME, GLOM_STANDARD_TABLE_AUTOINCREMENTS_TABLE_NAME),
           builder->add_expr(field_name))));
 
     const bool test = DbUtils::query_execute(builder);
diff --git a/glom/mode_design/fields/box_db_table_definition.cc b/glom/mode_design/fields/box_db_table_definition.cc
index b374829..75629f4 100644
--- a/glom/mode_design/fields/box_db_table_definition.cc
+++ b/glom/mode_design/fields/box_db_table_definition.cc
@@ -630,7 +630,7 @@ bool Box_DB_Table_Definition::field_has_null_values(const sharedptr<const Field>
   builder->select_add_target(m_table_name);
   builder->set_where(
     builder->add_cond(Gnome::Gda::SQL_OPERATOR_TYPE_ISNULL,
-      builder->add_id(field->get_name()))); //TODO: It would nice to specify the table name here too.
+      builder->add_field_id(field->get_name(), m_table_name)));
 
   long null_count = 0;
   Glib::RefPtr<Gnome::Gda::DataModel> datamodel = DbUtils::query_execute_select(builder);
diff --git a/glom/report_builder.cc b/glom/report_builder.cc
index 84c43df..2a3a644 100644
--- a/glom/report_builder.cc
+++ b/glom/report_builder.cc
@@ -188,7 +188,7 @@ void ReportBuilder::report_build_groupby(const FoundSet& found_set_parent, xmlpp
       builder->set_where( builder->import_expression(found_set_parent.m_where_clause) );
     }
 
-    builder->select_group_by( builder->add_id(field_group_by->get_name()) ); //TODO: And restrict to the current found set.
+    builder->select_group_by( builder->add_field_id(field_group_by->get_name(), group_field_table_name) ); //TODO: And restrict to the current found set.
 
     Glib::RefPtr<Gnome::Gda::DataModel> datamodel = DbUtils::query_execute_select(builder);
     if(datamodel)



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