gnomemm r1445 - in libgdamm/branches/libgdamm-3-0: . examples/simple_iter libgda/src tests



Author: murrayc
Date: Tue Apr  8 05:55:58 2008
New Revision: 1445
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1445&view=rev

Log:
2008-04-08  Murray Cumming  <murrayc murrayc com>

* libgda/src/connection.ccg:
* libgda/src/connection.hg: get_schema():
* libgda/src/serverprovider.hg: get_schema(): Do not use refreturn 
with these, to avoid a leak.

* Makefile.am:
* configure.in:
* tests/Makefile.am:
* tests/README:
* tests/test_execute_command.cc:
* tests/test_execute_nonselect_command.cc:
* tests/test_get_schema.cc: Added these tests to help me find leaks.

Added:
   libgdamm/branches/libgdamm-3-0/tests/
   libgdamm/branches/libgdamm-3-0/tests/Makefile.am
   libgdamm/branches/libgdamm-3-0/tests/README
   libgdamm/branches/libgdamm-3-0/tests/test_execute_command.cc
   libgdamm/branches/libgdamm-3-0/tests/test_execute_nonselect_command.cc
   libgdamm/branches/libgdamm-3-0/tests/test_get_schema.cc
Modified:
   libgdamm/branches/libgdamm-3-0/ChangeLog
   libgdamm/branches/libgdamm-3-0/Makefile.am
   libgdamm/branches/libgdamm-3-0/configure.in
   libgdamm/branches/libgdamm-3-0/examples/simple_iter/main.cc
   libgdamm/branches/libgdamm-3-0/libgda/src/connection.ccg
   libgdamm/branches/libgdamm-3-0/libgda/src/connection.hg
   libgdamm/branches/libgdamm-3-0/libgda/src/serverprovider.hg

Modified: libgdamm/branches/libgdamm-3-0/Makefile.am
==============================================================================
--- libgdamm/branches/libgdamm-3-0/Makefile.am	(original)
+++ libgdamm/branches/libgdamm-3-0/Makefile.am	Tue Apr  8 05:55:58 2008
@@ -1,4 +1,4 @@
-SUBDIRS		= tools libgda docs examples
+SUBDIRS		= tools libgda docs examples tests
 DIST_SUBDIRS	= $(SUBDIRS) scripts
 
 EXTRA_DIST	=  \

Modified: libgdamm/branches/libgdamm-3-0/configure.in
==============================================================================
--- libgdamm/branches/libgdamm-3-0/configure.in	(original)
+++ libgdamm/branches/libgdamm-3-0/configure.in	Tue Apr  8 05:55:58 2008
@@ -187,5 +187,7 @@
     examples/introspection/Makefile
     examples/simple/Makefile
     examples/simple_iter/Makefile
+
+  tests/Makefile
 ])
 

Modified: libgdamm/branches/libgdamm-3-0/examples/simple_iter/main.cc
==============================================================================
--- libgdamm/branches/libgdamm-3-0/examples/simple_iter/main.cc	(original)
+++ libgdamm/branches/libgdamm-3-0/examples/simple_iter/main.cc	Tue Apr  8 05:55:58 2008
@@ -38,8 +38,8 @@
     const gchar* connection_provider = "PostgreSQL";
 
     const gchar* connection_host = "localhost";
-    const gchar* connection_table = "glom_musiccollection21";
-    const Glib::ustring connection_string = Glib::ustring("HOST=") + connection_host + ";DB_NAME=" + connection_table;
+    const gchar* connection_table = "glom_musiccollection217";
+    const Glib::ustring connection_string = Glib::ustring("PORT=5433;HOST=") + connection_host + ";DB_NAME=" + connection_table;
 
     const gchar* connection_username = "murrayc";
     const gchar* connection_password = "murraycpw"; 
@@ -70,7 +70,7 @@
       //gda_connection->change_database("murrayc");
 
       //Get data from a table:
-      Gnome::Gda::Command command("SELECT * FROM artists");
+      Gnome::Gda::Command command("SELECT artist_id, picture FROM artists");
 
       //Specify a parameter, to request an iter-only model:
       Glib::RefPtr<Gnome::Gda::ParameterList> params = Gnome::Gda::ParameterList::create();
@@ -131,7 +131,16 @@
           {
             Glib::RefPtr<Gnome::Gda::Parameter> param = iter->get_param_for_column(col);
             Gnome::Gda::Value value_name = param->get_value();
-            std::cout << value_name.to_string() << ", ";
+
+            std::string str = value_name.to_string();
+            try
+            {
+              std::cout << str << ", ";
+            }
+            catch(const Glib::ConvertError& ex)
+            {
+              std::cout << "(INVALID UTF-8), ";
+            }
           }
 
           std::cout << std::endl;   

Modified: libgdamm/branches/libgdamm-3-0/libgda/src/connection.ccg
==============================================================================
--- libgdamm/branches/libgdamm-3-0/libgda/src/connection.ccg	(original)
+++ libgdamm/branches/libgdamm-3-0/libgda/src/connection.ccg	Tue Apr  8 05:55:58 2008
@@ -52,8 +52,6 @@
 {
   GError *gerror = 0;
   Glib::RefPtr<DataModel> retval = Glib::wrap(gda_connection_get_schema(gobj(), ((GdaConnectionSchema)(schema)), 0, &gerror));
-  if(retval)
-    retval->reference();
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror) ::Glib::Error::throw_exception(gerror);

Modified: libgdamm/branches/libgdamm-3-0/libgda/src/connection.hg
==============================================================================
--- libgdamm/branches/libgdamm-3-0/libgda/src/connection.hg	(original)
+++ libgdamm/branches/libgdamm-3-0/libgda/src/connection.hg	Tue Apr  8 05:55:58 2008
@@ -299,10 +299,10 @@
 
   _WRAP_METHOD(bool supports_feature(ConnectionFeature feature) const, gda_connection_supports_feature)
 
-  _WRAP_METHOD(Glib::RefPtr<DataModel> get_schema(ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params), gda_connection_get_schema, errthrow, refreturn)
+  _WRAP_METHOD(Glib::RefPtr<DataModel> get_schema(ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params), gda_connection_get_schema, errthrow)
   // TODO: This is not constversion because the generated code does not pass
   // error to the non-const function if exceptions are disabled.
-  _WRAP_METHOD(Glib::RefPtr<const DataModel> get_schema(ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params) const, gda_connection_get_schema, refreturn, errthrow)
+  _WRAP_METHOD(Glib::RefPtr<const DataModel> get_schema(ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params) const, gda_connection_get_schema, errthrow)
 
   /** Asks the underlying data source for a list of database objects.
    * This is the function that lets applications ask the different providers about all their database objects (tables,

Modified: libgdamm/branches/libgdamm-3-0/libgda/src/serverprovider.hg
==============================================================================
--- libgdamm/branches/libgdamm-3-0/libgda/src/serverprovider.hg	(original)
+++ libgdamm/branches/libgdamm-3-0/libgda/src/serverprovider.hg	Tue Apr  8 05:55:58 2008
@@ -91,7 +91,7 @@
  
  // TODO: This is not constversion because the generated code does not pass
   // error to the non-const function if exceptions are disabled.
-  _WRAP_METHOD(Glib::RefPtr<const DataModel> get_schema(const Glib::RefPtr<Connection>& cnc, ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params) const, gda_server_provider_get_schema, refreturn, errthrow)
+  _WRAP_METHOD(Glib::RefPtr<const DataModel> get_schema(const Glib::RefPtr<Connection>& cnc, ConnectionSchema schema, const Glib::RefPtr<ParameterList>& params) const, gda_server_provider_get_schema, errthrow)
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::RefPtr<DataModel> get_schema(const Glib::RefPtr<Connection>& cnc, ConnectionSchema schema);

Added: libgdamm/branches/libgdamm-3-0/tests/Makefile.am
==============================================================================
--- (empty file)
+++ libgdamm/branches/libgdamm-3-0/tests/Makefile.am	Tue Apr  8 05:55:58 2008
@@ -0,0 +1,11 @@
+include $(top_srcdir)/examples/Makefile.am_fragment
+
+#Build the executable, but don't install it.
+noinst_PROGRAMS = test_execute_command test_execute_nonselect_command test_get_schema
+
+test_execute_command_SOURCES = test_execute_command.cc
+test_execute_nonselect_command_SOURCES = test_execute_nonselect_command.cc
+test_get_schema_SOURCES = test_get_schema.cc
+
+EXTRA_DIST = README
+

Added: libgdamm/branches/libgdamm-3-0/tests/README
==============================================================================
--- (empty file)
+++ libgdamm/branches/libgdamm-3-0/tests/README	Tue Apr  8 05:55:58 2008
@@ -0,0 +1,5 @@
+These are not examples of how to use libgdamm. They are fragments of code to 
+test for regressions and leaks in libgdamm.
+
+See the examples folder for useful example code.
+

Added: libgdamm/branches/libgdamm-3-0/tests/test_execute_command.cc
==============================================================================
--- (empty file)
+++ libgdamm/branches/libgdamm-3-0/tests/test_execute_command.cc	Tue Apr  8 05:55:58 2008
@@ -0,0 +1,92 @@
+/* main.cc
+ *
+ * Copyright (C) 2008 libgdamm Development Team
+ *
+ * This program is free software; you can redistribute it and/or 
+ * modify it under the terms of the GNU General Public License as 
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+
+#include <libgdamm.h>
+#include <iostream>
+
+
+int main (int argc, char** argv)
+{
+  //Initialize libgdamm:
+  Gnome::Gda::init("libgdamm example", "0.1", argc, argv);
+
+#ifndef GLIBMM_EXCEPTIONS_ENABLED
+  std::auto_ptr<Glib::Error> error;
+#endif // !GLIBMM_EXCEPTIONS_ENABLED
+
+  Glib::RefPtr<Gnome::Gda::Client> gda_client = Gnome::Gda::Client::create();
+  if(gda_client)
+  {
+    const gchar* connection_provider = "PostgreSQL";
+
+    const gchar* connection_host = "localhost";
+    const gchar* connection_table = "glom_musiccollection217";
+    const Glib::ustring connection_string = Glib::ustring("PORT=5433;HOST=") + connection_host + ";DB_NAME=" + connection_table;
+
+    const gchar* connection_username = "murrayc";
+    const gchar* connection_password = "murraycpw"; 
+     
+    Glib::RefPtr<Gnome::Gda::Connection> gda_connection;
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    try
+    {
+      gda_connection= gda_client->open_connection_from_string(connection_provider, connection_string, connection_username, connection_password);
+    }
+    catch(const Glib::Exception& ex)
+    {
+      std::cerr << "Exception caught: " << ex.what() << std::endl;
+    }
+#else
+    gda_connection = gda_client->open_connection_from_string(connection_provider, connection_string, connection_username, connection_password, Gnome::Gda::ConnectionOptions(0), error);
+    if(error.get())
+    {
+      std::cerr << "Exception caught: " << error->what() << std::endl;
+    }
+#endif // GLIBMM_EXCEPTIONS_ENABLED
+    
+    if(!gda_connection)
+      std::cerr << "Error: Could not open connection to " << connection_string << std::endl;
+    else
+    {
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try
+      {
+        gda_connection->execute_select_command("SELECT artist_id, picture FROM artists");
+      }
+      catch(const Glib::Exception& ex)
+      {
+       std::cerr << "Exception caught: " << ex.what() << std::endl;
+      }
+#else
+      gda_connection->execute_select_command("SELECT artist_id, picture FROM artists", error);
+      if(error.get())
+      {
+        std::cerr << "Exception caught: " << error->what() << std::endl;
+      }
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  } 
+
+  
+  return 0;
+}
+
+

Added: libgdamm/branches/libgdamm-3-0/tests/test_execute_nonselect_command.cc
==============================================================================
--- (empty file)
+++ libgdamm/branches/libgdamm-3-0/tests/test_execute_nonselect_command.cc	Tue Apr  8 05:55:58 2008
@@ -0,0 +1,92 @@
+/* main.cc
+ *
+ * Copyright (C) 2008 libgdamm Development Team
+ *
+ * This program is free software; you can redistribute it and/or 
+ * modify it under the terms of the GNU General Public License as 
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+
+#include <libgdamm.h>
+#include <iostream>
+
+
+int main (int argc, char** argv)
+{
+  //Initialize libgdamm:
+  Gnome::Gda::init("libgdamm example", "0.1", argc, argv);
+
+#ifndef GLIBMM_EXCEPTIONS_ENABLED
+  std::auto_ptr<Glib::Error> error;
+#endif // !GLIBMM_EXCEPTIONS_ENABLED
+
+  Glib::RefPtr<Gnome::Gda::Client> gda_client = Gnome::Gda::Client::create();
+  if(gda_client)
+  {
+    const gchar* connection_provider = "PostgreSQL";
+
+    const gchar* connection_host = "localhost";
+    const gchar* connection_table = "glom_musiccollection217";
+    const Glib::ustring connection_string = Glib::ustring("PORT=5433;HOST=") + connection_host + ";DB_NAME=" + connection_table;
+
+    const gchar* connection_username = "murrayc";
+    const gchar* connection_password = "murraycpw"; 
+     
+    Glib::RefPtr<Gnome::Gda::Connection> gda_connection;
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    try
+    {
+      gda_connection= gda_client->open_connection_from_string(connection_provider, connection_string, connection_username, connection_password);
+    }
+    catch(const Glib::Exception& ex)
+    {
+      std::cerr << "Exception caught: " << ex.what() << std::endl;
+    }
+#else
+    gda_connection = gda_client->open_connection_from_string(connection_provider, connection_string, connection_username, connection_password, Gnome::Gda::ConnectionOptions(0), error);
+    if(error.get())
+    {
+      std::cerr << "Exception caught: " << error->what() << std::endl;
+    }
+#endif // GLIBMM_EXCEPTIONS_ENABLED
+    
+    if(!gda_connection)
+      std::cerr << "Error: Could not open connection to " << connection_string << std::endl;
+    else
+    {
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try
+      {
+        gda_connection->execute_non_select_command("SET DATESTYLE = 'ISO'");
+      }
+      catch(const Glib::Exception& ex)
+      {
+       std::cerr << "Exception caught: " << ex.what() << std::endl;
+      }
+#else
+      gda_connection->execute_non_select_command("SET DATESTYLE = 'ISO'", error);
+      if(error.get())
+      {
+        std::cerr << "Exception caught: " << error->what() << std::endl;
+      }
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  } 
+
+  
+  return 0;
+}
+
+

Added: libgdamm/branches/libgdamm-3-0/tests/test_get_schema.cc
==============================================================================
--- (empty file)
+++ libgdamm/branches/libgdamm-3-0/tests/test_get_schema.cc	Tue Apr  8 05:55:58 2008
@@ -0,0 +1,92 @@
+/* main.cc
+ *
+ * Copyright (C) 2008 libgdamm Development Team
+ *
+ * This program is free software; you can redistribute it and/or 
+ * modify it under the terms of the GNU General Public License as 
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+
+#include <libgdamm.h>
+#include <iostream>
+
+
+int main (int argc, char** argv)
+{
+  //Initialize libgdamm:
+  Gnome::Gda::init("libgdamm example", "0.1", argc, argv);
+
+#ifndef GLIBMM_EXCEPTIONS_ENABLED
+  std::auto_ptr<Glib::Error> error;
+#endif // !GLIBMM_EXCEPTIONS_ENABLED
+
+  Glib::RefPtr<Gnome::Gda::Client> gda_client = Gnome::Gda::Client::create();
+  if(gda_client)
+  {
+    const gchar* connection_provider = "PostgreSQL";
+
+    const gchar* connection_host = "localhost";
+    const gchar* connection_table = "glom_musiccollection217";
+    const Glib::ustring connection_string = Glib::ustring("PORT=5433;HOST=") + connection_host + ";DB_NAME=" + connection_table;
+
+    const gchar* connection_username = "murrayc";
+    const gchar* connection_password = "murraycpw"; 
+     
+    Glib::RefPtr<Gnome::Gda::Connection> gda_connection;
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+    try
+    {
+      gda_connection= gda_client->open_connection_from_string(connection_provider, connection_string, connection_username, connection_password);
+    }
+    catch(const Glib::Exception& ex)
+    {
+      std::cerr << "Exception caught: " << ex.what() << std::endl;
+    }
+#else
+    gda_connection = gda_client->open_connection_from_string(connection_provider, connection_string, connection_username, connection_password, Gnome::Gda::ConnectionOptions(0), error);
+    if(error.get())
+    {
+      std::cerr << "Exception caught: " << error->what() << std::endl;
+    }
+#endif // GLIBMM_EXCEPTIONS_ENABLED
+    
+    if(!gda_connection)
+      std::cerr << "Error: Could not open connection to " << connection_string << std::endl;
+    else
+    {
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try
+      {
+        Glib::RefPtr<Gnome::Gda::DataModel> data_model_tables = gda_connection->get_schema(Gnome::Gda::CONNECTION_SCHEMA_TYPES);
+      }
+      catch(const Glib::Exception& ex)
+      {
+       std::cerr << "Exception caught: " << ex.what() << std::endl;
+      }
+#else
+      Glib::RefPtr<Gnome::Gda::DataModel> data_model_tables = gda_connection->get_schema(Gnome::Gda::CONNECTION_SCHEMA_TYPES, error);
+      if(error.get())
+      {
+        std::cerr << "Exception caught: " << error->what() << std::endl;
+      }
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  } 
+
+  
+  return 0;
+}
+
+



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