gnomemm r1940 - in libgdamm/trunk: . libgda/src



Author: murrayc
Date: Sat Jan  3 22:26:14 2009
New Revision: 1940
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1940&view=rev

Log:
2009-01-03  Murray Cumming  <murrayc murrayc com>

* libgda/src/connection.hg: open_from_string(): Make the auth_string 
parameter optional because it is not always needed, for instance with 
sqlite.

* libgda/src/datamodelarray.ccg:
* libgda/src/datamodelarray.hg: Added set_column_g_type().

* libgda/src/column.ccg:
* libgda/src/column.hg:
* libgda/src/holder.ccg: set_attribute():  Specify a callback to 
destroy the provided string, because libgda has stupid memory management 
for that.

Modified:
   libgdamm/trunk/ChangeLog
   libgdamm/trunk/libgda/src/column.ccg
   libgdamm/trunk/libgda/src/column.hg
   libgdamm/trunk/libgda/src/connection.hg
   libgdamm/trunk/libgda/src/datamodelarray.ccg
   libgdamm/trunk/libgda/src/datamodelarray.hg
   libgdamm/trunk/libgda/src/holder.ccg

Modified: libgdamm/trunk/libgda/src/column.ccg
==============================================================================
--- libgdamm/trunk/libgda/src/column.ccg	(original)
+++ libgdamm/trunk/libgda/src/column.ccg	Sat Jan  3 22:26:14 2009
@@ -40,13 +40,27 @@
                 get_g_type() == src->get_g_type() &&
                 get_allow_null() == src->get_allow_null() &&
                 get_auto_increment() == src->get_auto_increment() &&
-                get_position() == src->get_position();
-                // FIXME: get_default_value() == src->get_default_value();
+                get_position() == src->get_position() &&
+                get_default_value() == src->get_default_value();
 
   return result;
 }
 
 
+static void on_set_attribute_destroy(gpointer data)
+{
+  g_free((char*)data);
+}
+
+void Column::set_attribute(const Glib::ustring& attribute, const Value& value)
+{
+  //gda_column_set_attribute() has stupid memory management.
+  //See http://bugzilla.gnome.org/show_bug.cgi?id=564402
+  gchar* dup = g_strdup(attribute.c_str());
+  gda_column_set_attribute(gobj(), dup, (value).gobj(), &on_set_attribute_destroy); 
+}
+
+
 } // namespace Gda
 
 } // namespace Gnome

Modified: libgdamm/trunk/libgda/src/column.hg
==============================================================================
--- libgdamm/trunk/libgda/src/column.hg	(original)
+++ libgdamm/trunk/libgda/src/column.hg	Sat Jan  3 22:26:14 2009
@@ -36,6 +36,7 @@
 
 /* possible predefined attribute names for gda_holder_get_attribute() or gda_column_get_attribute() */
 // Keep in sync with libgda
+// TODO: How/When/Why are these used? Where are they documented? murrayc.
 const std::string ATTRIBUTE_DESCRIPTION = "__gda_attr_descr"; /* G_TYPE_STRING */
 const std::string ATTRIBUTE_NAME = "__gda_attr_name"; /* G_TYPE_STRING */
 const std::string ATTRIBUTE_NUMERIC_PRECISION = "__gda_attr_numeric_precision"; /* G_TYPE_INT */
@@ -63,7 +64,7 @@
   _WRAP_METHOD(Glib::ustring get_description() const, gda_column_get_description)
   _WRAP_METHOD(void set_description(const Glib::ustring& title), gda_column_set_description)
 
-  _WRAP_METHOD(void set_attribute(const Glib::ustring& attribute, const Value& value), gda_column_set_attribute_static)
+  void set_attribute(const Glib::ustring& attribute, const Value& value);
   _WRAP_METHOD(Value get_attribute(const Glib::ustring& attribute) const, gda_column_get_attribute)
     
   _WRAP_METHOD(Glib::ustring get_name() const, gda_column_get_name)

Modified: libgdamm/trunk/libgda/src/connection.hg
==============================================================================
--- libgdamm/trunk/libgda/src/connection.hg	(original)
+++ libgdamm/trunk/libgda/src/connection.hg	Sat Jan  3 22:26:14 2009
@@ -75,7 +75,7 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   static Glib::RefPtr<Connection> open_from_string(const Glib::ustring& provider_name,
                                                     const Glib::ustring& cnc_string,
-                                                    const Glib::ustring& auth_string,
+                                                    const Glib::ustring& auth_string = Glib::ustring(),
                                                     ConnectionOptions options = CONNECTION_OPTIONS_NONE);
 #else
   static Glib::RefPtr<Connection> open_from_string(const Glib::ustring& provider_name,

Modified: libgdamm/trunk/libgda/src/datamodelarray.ccg
==============================================================================
--- libgdamm/trunk/libgda/src/datamodelarray.ccg	(original)
+++ libgdamm/trunk/libgda/src/datamodelarray.ccg	Sat Jan  3 22:26:14 2009
@@ -33,6 +33,12 @@
 {
 }
 
+void DataModelArray::set_column_g_type(int col, GType type)
+{
+  //This is based on the code in gda_data_model_array_new_with_g_type():
+  gda_column_set_g_type (gda_data_model_describe_column (GDA_DATA_MODEL(gobj()), col), type);
+}
+
 } /* namespace Gda */
 
 } /* namespace Gnome */

Modified: libgdamm/trunk/libgda/src/datamodelarray.hg
==============================================================================
--- libgdamm/trunk/libgda/src/datamodelarray.hg	(original)
+++ libgdamm/trunk/libgda/src/datamodelarray.hg	Sat Jan  3 22:26:14 2009
@@ -53,6 +53,10 @@
 public:
   _WRAP_CREATE(int cols)
 
+  //This is an equivalent for gda_data_model_array_new_with_g_types().
+  void set_column_g_type(int col, GType type);
+  _IGNORE(gda_data_model_array_new_with_g_types);
+
   _WRAP_METHOD(void set_n_columns(int cols), gda_data_model_array_set_n_columns)
   _WRAP_METHOD(void clear(), gda_data_model_array_clear)
 

Modified: libgdamm/trunk/libgda/src/holder.ccg
==============================================================================
--- libgdamm/trunk/libgda/src/holder.ccg	(original)
+++ libgdamm/trunk/libgda/src/holder.ccg	Sat Jan  3 22:26:14 2009
@@ -35,13 +35,17 @@
 
 }
 
+static void on_set_attribute_destroy(gpointer data)
+{
+  g_free((char*)data);
+}
+
 void Holder::set_attribute(const Glib::ustring& attribute, const Value& value)
 {
   //gda_holder_set_attribute() has stupid memory management.
-  //Leaking is the only way to make sure that the string stays alive.
-  //TODO: Fix gda_holder_set_attribute().
+  //See http://bugzilla.gnome.org/show_bug.cgi?id=564402
   gchar* dup = g_strdup(attribute.c_str());
-  gda_holder_set_attribute_static(gobj(), dup, (value).gobj()); 
+  gda_holder_set_attribute(gobj(), dup, (value).gobj(), &on_set_attribute_destroy); 
 }
   
 } /* namespace Gda */



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