glom r1888 - in trunk: . glom glom/libglom/connectionpool_backends glom/libglom/data_structure



Author: murrayc
Date: Mon Feb  9 17:50:19 2009
New Revision: 1888
URL: http://svn.gnome.org/viewvc/glom?rev=1888&view=rev

Log:
2009-02-09  Murray Cumming  <murrayc murrayc com>

* glom/libglom/data_structure/field.[h|cc]: get_gda_type(): 
Renamed to get_gda_type_name(). Removed get_gda_g_type() because 
we already have a static get_g_type_for_glom_type(). This gets rids of 
the nasty switch block.
* glom/base_db.cc: insert_example_data(), get_lookup_value(),
  get_primary_key_is_in_foundset(): Adapted.

Modified:
   trunk/ChangeLog
   trunk/glom/base_db.cc
   trunk/glom/libglom/connectionpool_backends/sqlite.cc
   trunk/glom/libglom/data_structure/field.cc
   trunk/glom/libglom/data_structure/field.h

Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc	(original)
+++ trunk/glom/base_db.cc	Mon Feb  9 17:50:19 2009
@@ -1578,15 +1578,17 @@
           }
           
           //Add a SQL parameter for the value:
-          unsigned int id;
-          Glib::RefPtr<Gnome::Gda::Holder> holder = Gnome::Gda::Holder::create(vec_fields[i]->get_gda_g_type(),
-                                                                               generator.get_next_name(id));
+          guint id = 0;
+          const Field::glom_type glom_type = vec_fields[i]->get_glom_type();
+          Glib::RefPtr<Gnome::Gda::Holder> holder = 
+            Gnome::Gda::Holder::create( Field::get_gda_type_for_glom_type(glom_type),
+              generator.get_next_name(id));
 
           holder->set_not_null(false);
           holder->set_value_as_value(value);
           params->add_holder(holder);
           
-          strVals += "##" + generator.get_name_from_id(id) + "::" + vec_fields[i]->get_gda_type();
+          strVals += "##" + generator.get_name_from_id(id) + "::" + vec_fields[i]->get_gda_type_name();
         }
 
         //Create and parse the SQL query:
@@ -2821,7 +2823,7 @@
     params->add_holder("key", value_to_key_field);
 
     Glib::ustring strQuery = "SELECT \"" + relationship->get_to_table() + "\".\"" + source_field->get_name() + "\" FROM \"" +  relationship->get_to_table() + "\"";
-    strQuery += " WHERE \"" + to_key_field->get_name() + "\" = ##key::" + to_key_field->get_gda_type();
+    strQuery += " WHERE \"" + to_key_field->get_name() + "\" = ##key::" + to_key_field->get_gda_type_name();
 
     Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(strQuery, params);
     if(data_model && data_model->get_n_rows())
@@ -3052,7 +3054,7 @@
   if(!found_set.m_where_clause.empty())
     where_clause = "(" + found_set.m_where_clause + ") AND ";
 
-  where_clause += "(\"" + primary_key->get_name() + "\" = ##primary_key::" + primary_key->get_gda_type() + ")";
+  where_clause += "(\"" + primary_key->get_name() + "\" = ##primary_key::" + primary_key->get_gda_type_name() + ")";
 
   const Glib::ustring query = Utils::build_sql_select_with_where_clause(found_set.m_table_name, fieldsToGet, where_clause);
   Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute_select(query, params);

Modified: trunk/glom/libglom/connectionpool_backends/sqlite.cc
==============================================================================
--- trunk/glom/libglom/connectionpool_backends/sqlite.cc	(original)
+++ trunk/glom/libglom/connectionpool_backends/sqlite.cc	Mon Feb  9 17:50:19 2009
@@ -56,7 +56,7 @@
   if(db_file->query_file_type() == Gio::FILE_TYPE_REGULAR)
   {
     // Convert URI to path, for GDA connection string
-    std::string database_directory = db_dir->get_path();
+    const std::string database_directory = db_dir->get_path();
 
     const Glib::ustring cnc_string = "DB_DIR=" + database_directory + ";DB_NAME=" + database;
     const Glib::ustring auth_string = Glib::ustring::compose("USERNAME=%1;PASSWORD=%2", username, password);
@@ -95,7 +95,7 @@
 bool Sqlite::create_database(const Glib::ustring& database_name, const Glib::ustring& /* username */, const Glib::ustring& /* password */, std::auto_ptr<Glib::Error>& error)
 {
   Glib::RefPtr<Gio::File> file = Gio::File::create_for_uri(m_database_directory_uri);
-  std::string database_directory = file->get_path(); 
+  const std::string database_directory = file->get_path(); 
   const Glib::ustring cnc_string = Glib::ustring::compose("DB_DIR=%1;DB_NAME=%2", database_directory, database_name);
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED

Modified: trunk/glom/libglom/data_structure/field.cc
==============================================================================
--- trunk/glom/libglom/data_structure/field.cc	(original)
+++ trunk/glom/libglom/data_structure/field.cc	Mon Feb  9 17:50:19 2009
@@ -704,39 +704,16 @@
   }
 }
 
-GType Field::get_gda_g_type() const
+Glib::ustring Field::get_gda_type_name() const
 {
-  // TODO: Can't we just do this here? armin.
-  // return get_field_info()->get_g_type();
-
-  switch(m_glom_type)
-  {
-    case TYPE_NUMERIC:
-      return GDA_TYPE_NUMERIC;
-    case TYPE_TEXT:
-      return G_TYPE_STRING;
-    case TYPE_DATE:
-      return G_TYPE_DATE;
-    case TYPE_TIME:
-      return GDA_TYPE_TIME;
-    case TYPE_BOOLEAN:
-      return G_TYPE_BOOLEAN;
-    case TYPE_IMAGE:
-      return GDA_TYPE_BINARY;
-    default:
-      g_assert_not_reached();
-  }
-}
-
-Glib::ustring Field::get_gda_type() const
-{
-  return g_type_name(get_gda_g_type());
+  return g_type_name( get_gda_type_for_glom_type(m_glom_type) );
 }
 
 Glib::RefPtr<Gnome::Gda::Holder> Field::get_holder(const Gnome::Gda::Value& value, const Glib::ustring& name) const
 {
   const Glib::ustring real_name = name.empty() ? get_name() : name;
-  Glib::RefPtr<Gnome::Gda::Holder> holder = Gnome::Gda::Holder::create(get_gda_g_type(), real_name);
+  const GType gtype = get_gda_type_for_glom_type(m_glom_type);
+  Glib::RefPtr<Gnome::Gda::Holder> holder = Gnome::Gda::Holder::create(gtype, real_name);
   holder->set_value_as_value(value);
   return holder;
 }
@@ -744,7 +721,7 @@
 Glib::ustring Field::get_gda_holder_string(const Glib::ustring& name) const
 {
   const Glib::ustring real_name = name.empty() ? get_name() : name;
-  return "##" + real_name + "::" + get_gda_type();
+  return "##" + real_name + "::" + get_gda_type_name();
 }
 
 /// Ignores any part of FieldAttributes that libgda does not properly fill.

Modified: trunk/glom/libglom/data_structure/field.h
==============================================================================
--- trunk/glom/libglom/data_structure/field.h	(original)
+++ trunk/glom/libglom/data_structure/field.h	Mon Feb  9 17:50:19 2009
@@ -155,8 +155,7 @@
   void set_lookup_field(const Glib::ustring& strField);
 
   Glib::ustring get_sql_type() const;
-  Glib::ustring get_gda_type() const;
-  GType get_gda_g_type() const;
+  Glib::ustring get_gda_type_name() const;
 
   //TODO: Shouldn't this be called get_gda_holder_name()?
   /// A convenience when using parameters with a libgda SQL query.



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