[glom] Field: Removed deprecated methods.



commit c58b0785f68b659ab53bce5cec69d08eb8f410cf
Author: Murray Cumming <murrayc murrayc com>
Date:   Mon Mar 12 12:08:45 2012 +0100

    Field: Removed deprecated methods.
    
    * glom/libglom/data_structure/field.[h.cc]: Removed the sql()
    overload that takes no connection. sql_find(): Add a connection
    parameter.
    * glom/libglom/data_structure/layout/layoutgroup.h:
    * glom/libglom/utils.cc:
    * glom/mode_data/box_data.cc: Adapted.

 ChangeLog                                        |   11 +++++++++
 glom/libglom/data_structure/field.cc             |   26 +--------------------
 glom/libglom/data_structure/field.h              |    4 +-
 glom/libglom/data_structure/layout/layoutgroup.h |    2 +-
 glom/libglom/utils.cc                            |   10 +++++++-
 glom/mode_data/box_data.cc                       |    9 ++++++-
 6 files changed, 33 insertions(+), 29 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1a7e2ee..5bdc48b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2012-03-12  Murray Cumming  <murrayc murrayc com>
 
+	Field: Removed deprecated methods.
+
+	* glom/libglom/data_structure/field.[h.cc]: Removed the sql()
+	overload that takes no connection. sql_find(): Add a connection
+	parameter.
+	* glom/libglom/data_structure/layout/layoutgroup.h:
+	* glom/libglom/utils.cc:
+	* glom/mode_data/box_data.cc: Adapted.
+
+2012-03-12  Murray Cumming  <murrayc murrayc com>
+
 	LayoutItem_GroupBy: Add get and set methods for members.
 
 	* glom/libglom/data_structure/layout/report_parts/layoutitem_groupby.[h|cc]: 
diff --git a/glom/libglom/data_structure/field.cc b/glom/libglom/data_structure/field.cc
index 2fcb199..dbc9e6e 100644
--- a/glom/libglom/data_structure/field.cc
+++ b/glom/libglom/data_structure/field.cc
@@ -262,28 +262,6 @@ Glib::ustring Field::sql(const Gnome::Gda::Value& value, const Glib::RefPtr<Gnom
   return Glib::ustring();
 }
 
-Glib::ustring Field::sql(const Gnome::Gda::Value& value) const
-{
-  sharedptr<SharedConnection> connection;
-  try
-  {
-    connection = ConnectionPool::get_instance()->connect();
-  }
-  catch (Glom::ExceptionConnection& ex)
-  {
-    //TODO: Do something more useful here
-    std::cerr << "Field::sql, connection failed: " << ex.what() << std::endl;
-  }
-  if(connection)
-  {
-    Glib::RefPtr<Gnome::Gda::Connection> gda_connection = connection->get_gda_connection();
-    if(gda_connection)
-      return sql(value, gda_connection);
-  }
-
-  return Glib::ustring();
-}
-
 #define GLOM_QUOTE_FOR_FILE_FORMAT "\""
 
 Glib::ustring Field::to_file_format(const Gnome::Gda::Value& value) const
@@ -407,7 +385,7 @@ Gnome::Gda::Value Field::from_file_format(const Glib::ustring& str, glom_field_t
   }
 }
 
-Glib::ustring Field::sql_find(const Gnome::Gda::Value& value) const
+Glib::ustring Field::sql_find(const Gnome::Gda::Value& value, const Glib::RefPtr<Gnome::Gda::Connection>& connection) const
 {
   switch(get_glom_type())
   {
@@ -428,7 +406,7 @@ Glib::ustring Field::sql_find(const Gnome::Gda::Value& value) const
     case(TYPE_BOOLEAN):
     default:
     {
-      return sql(value);
+      return sql(value, connection);
       break;
     }
   }
diff --git a/glom/libglom/data_structure/field.h b/glom/libglom/data_structure/field.h
index a7a421e..449f9cc 100644
--- a/glom/libglom/data_structure/field.h
+++ b/glom/libglom/data_structure/field.h
@@ -171,7 +171,7 @@ public:
   /** Escape and quote the value so that it can be used in a SQL command.
    * Uses the sql_format of the current connectionpool backend.
    */
-  Glib::ustring sql(const Gnome::Gda::Value& value) const;
+  //Glib::ustring sql(const Gnome::Gda::Value& value) const;
 
   /** Get the canonical format for a file, for instance for 
    * a default value or for example data.
@@ -194,7 +194,7 @@ public:
 
   /** Escape the value so that it can be used in a SQL command for a find.
    */
-  Glib::ustring sql_find(const Gnome::Gda::Value& value) const;
+  Glib::ustring sql_find(const Gnome::Gda::Value& value, const Glib::RefPtr<Gnome::Gda::Connection>& connection) const;
 
   /** Get a suitable operator to use when finding records.
    * For instance, == for numbers, or LIKE for text.
diff --git a/glom/libglom/data_structure/layout/layoutgroup.h b/glom/libglom/data_structure/layout/layoutgroup.h
index 7288905..52d0bfc 100644
--- a/glom/libglom/data_structure/layout/layoutgroup.h
+++ b/glom/libglom/data_structure/layout/layoutgroup.h
@@ -78,7 +78,7 @@ public:
    */
   void remove_field(const Glib::ustring& parent_table_name, const Glib::ustring& table_name, const Glib::ustring& field_name);
 
-  //TODO: Do these need to be virtual?
+  //These are virtual so that the portal item can do more.
   virtual void change_field_item_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new);
   virtual void change_related_field_item_name(const Glib::ustring& table_name, const Glib::ustring& field_name, const Glib::ustring& field_name_new);
 
diff --git a/glom/libglom/utils.cc b/glom/libglom/utils.cc
index dd74f5d..209c4d5 100644
--- a/glom/libglom/utils.cc
+++ b/glom/libglom/utils.cc
@@ -1126,6 +1126,14 @@ Gnome::Gda::SqlExpr Utils::get_find_where_clause_quick(const Document* document,
     return Gnome::Gda::SqlExpr();
   }
 
+  //We need the connection to generate the correct SQL syntax:
+  Glib::RefPtr<Gnome::Gda::Connection> connection = get_connection();
+  if(!connection)
+  {
+    std::cerr << G_STRFUNC << ": connection was null." << std::endl;
+    return Gnome::Gda::SqlExpr();
+  }
+
   //TODO: Cache the list of all fields, as well as caching (m_Fields) the list of all visible fields:
   const Document::type_vec_fields fields = document->get_table_fields(table_name);
 
@@ -1149,7 +1157,7 @@ Gnome::Gda::SqlExpr Utils::get_find_where_clause_quick(const Document* document,
       //std::cout << "Using field: " << field->get_name() << std::endl;
       const guint eq_id = builder->add_cond(field->sql_find_operator(),
         builder->add_field_id(field->get_name(), table_name),
-        builder->add_expr( field->sql_find(quick_search) )); //sql_find() modifies the value for the operator.
+        builder->add_expr( field->sql_find(quick_search, connection) )); //sql_find() modifies the value for the operator.
 
       if(previous_id)
       {
diff --git a/glom/mode_data/box_data.cc b/glom/mode_data/box_data.cc
index 6c892a4..37fb612 100644
--- a/glom/mode_data/box_data.cc
+++ b/glom/mode_data/box_data.cc
@@ -92,6 +92,13 @@ Gnome::Gda::SqlExpr Box_Data::get_find_where_clause() const
   builder->select_add_target(m_table_name);  //This might not be necessary.
   guint where_cond_id = 0;
 
+  Glib::RefPtr<Gnome::Gda::Connection> connection = get_connection();
+  if(!connection)
+  {
+    std::cerr << G_STRFUNC << ": connection was null." << std::endl;
+    return Gnome::Gda::SqlExpr();
+  }
+
   //Look at each field entry and build e.g. 'Name = "Bob"'
   for(type_vecConstLayoutFields::const_iterator iter = m_FieldsShown.begin(); iter != m_FieldsShown.end(); ++iter)
   {
@@ -113,7 +120,7 @@ Gnome::Gda::SqlExpr Box_Data::get_find_where_clause() const
         {
           const guint cond_id = builder->add_cond(field->sql_find_operator(),
             builder->add_field_id(field->get_name(), m_table_name),
-            builder->add_expr( field->sql_find(data) ));
+            builder->add_expr( field->sql_find(data, connection) ));
 
           //And with previous condition, if any:
           if(where_cond_id)



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