glom r1536 - in trunk: . docs glom glom/libglom glom/utility_widgets
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1536 - in trunk: . docs glom glom/libglom glom/utility_widgets
- Date: Wed, 9 Apr 2008 10:57:25 +0100 (BST)
Author: murrayc
Date: Wed Apr 9 10:57:24 2008
New Revision: 1536
URL: http://svn.gnome.org/viewvc/glom?rev=1536&view=rev
Log:
2008-04-09 Murray Cumming <murrayc murrayc com>
* glom/utility_widgets/flowtable.cc: Destructor: Remove my hack to
delete child widgets, because it causes double deletes.
Added:
trunk/docs/postgres_test_bigtable.c
Modified:
trunk/ChangeLog
trunk/glom/libglom/test_connectionpool.cc
trunk/glom/main.cc
trunk/glom/utility_widgets/flowtable.cc
trunk/glom/utility_widgets/test_flowtable.cc
Added: trunk/docs/postgres_test_bigtable.c
==============================================================================
--- (empty file)
+++ trunk/docs/postgres_test_bigtable.c Wed Apr 9 10:57:24 2008
@@ -0,0 +1,119 @@
+/*
+ Compile this like so, or similar:
+ gcc postgres_test.c -I /usr/include/postgresql -lpq
+or, on Ubuntu Breezy:
+ gcc postgres_test.c -I /usr/include/postgresql -lpq -I/usr/include/postgresql/8.0/
+ murrayc
+*/
+
+/*
+ * testlibpq.c
+ *
+ * Test the C version of LIBPQ, the POSTGRES frontend library.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include "libpq-fe.h"
+
+static void
+exit_nicely(PGconn *conn)
+{
+ PQfinish(conn);
+ exit(1);
+}
+
+int
+main(int argc, char **argv)
+{
+ const char *conninfo;
+ PGconn *conn;
+ PGresult *res;
+ int nFields;
+ int i,
+ j;
+
+ conninfo = "host=localhost dbname=importtest user=murrayc password=murraycpw port=5433";
+
+ /* Make a connection to the database */
+ conn = PQconnectdb(conninfo);
+
+ /* Check to see that the backend connection was successfully made */
+ if (PQstatus(conn) != CONNECTION_OK)
+ {
+ fprintf(stderr, "Connection to database failed: %s",
+ PQerrorMessage(conn));
+ exit_nicely(conn);
+ }
+
+ /*
+ * Our test case here involves using a cursor, for which we must be
+ * inside a transaction block. We could do the whole thing with a
+ * single PQexec() of "select * from pg_database", but that's too
+ * trivial to make a good example.
+ */
+
+ /* Start a transaction block */
+ res = PQexec(conn, "BEGIN");
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ {
+ fprintf(stderr, "BEGIN command failed: %s", PQerrorMessage(conn));
+ PQclear(res);
+ exit_nicely(conn);
+ }
+
+ /*
+ * Should PQclear PGresult whenever it is no longer needed to avoid
+ * memory leaks
+ */
+ PQclear(res);
+
+ /*
+ * Fetch rows from pg_database, the system catalog of databases
+ */
+ res = PQexec(conn, "DECLARE myportal CURSOR FOR SELECT \"album\".\"id\", \"album\".\"artist\", \"album\".\"name\" FROM \"album\"");
+ if (PQresultStatus(res) != PGRES_COMMAND_OK)
+ {
+ fprintf(stderr, "DECLARE CURSOR failed: %s", PQerrorMessage(conn));
+ PQclear(res);
+ exit_nicely(conn);
+ }
+ PQclear(res);
+
+ res = PQexec(conn, "FETCH ALL in myportal");
+ if (PQresultStatus(res) != PGRES_TUPLES_OK)
+ {
+ fprintf(stderr, "FETCH ALL failed: %s", PQerrorMessage(conn));
+ PQclear(res);
+ exit_nicely(conn);
+ }
+
+ /* first, print out the attribute names */
+ nFields = PQnfields(res);
+ for (i = 0; i < nFields; i++)
+ printf("%-15s", PQfname(res, i));
+ printf("\n\n");
+
+ /* next, print out the rows */
+ for (i = 0; i < PQntuples(res); i++)
+ {
+ for (j = 0; j < nFields; j++)
+ printf("%-15s", PQgetvalue(res, i, j));
+ printf("\n");
+ }
+
+ PQclear(res);
+
+ /* close the portal ... we don't bother to check for errors ... */
+ res = PQexec(conn, "CLOSE myportal");
+ PQclear(res);
+
+ /* end the transaction */
+ res = PQexec(conn, "END");
+ PQclear(res);
+
+ /* close the connection to the database and cleanup */
+ PQfinish(conn);
+
+ return 0;
+}
+
Modified: trunk/glom/libglom/test_connectionpool.cc
==============================================================================
--- trunk/glom/libglom/test_connectionpool.cc (original)
+++ trunk/glom/libglom/test_connectionpool.cc Wed Apr 9 10:57:24 2008
@@ -27,40 +27,48 @@
{
Gnome::Gda::init("test", "0.1", argc, argv);
- //Set the connection details:
- Glom::ConnectionPool* connection_pool = Glom::ConnectionPool::get_instance();
- if(connection_pool)
- {
- //Set the connection details in the ConnectionPool singleton.
- //The ConnectionPool will now use these every time it tries to connect.
-
- connection_pool->set_database("glom_musiccollection217");
- connection_pool->set_host("localhost");
- connection_pool->set_user("murrayc");
- connection_pool->set_password("murraycpw");
+ Glib::RefPtr<Gnome::Gda::Connection> gdaconnection;
- connection_pool->set_port(5433);
- connection_pool->set_try_other_ports(false);
-
- connection_pool->set_ready_to_connect(); //Box_DB::connect_to_server() will now attempt the connection-> Shared instances of m_Connection will also be usable.
+ {
+ //Set the connection details:
+ Glom::ConnectionPool* connection_pool = Glom::ConnectionPool::get_instance();
+ if(connection_pool)
+ {
+ //Set the connection details in the ConnectionPool singleton.
+ //The ConnectionPool will now use these every time it tries to connect.
+
+ connection_pool->set_database("glom_musiccollection217");
+ connection_pool->set_host("localhost");
+ connection_pool->set_user("murrayc");
+ connection_pool->set_password("murraycpw");
+
+ connection_pool->set_port(5433);
+ connection_pool->set_try_other_ports(false);
+
+ connection_pool->set_ready_to_connect(); //Box_DB::connect_to_server() will now attempt the connection-> Shared instances of m_Connection will also be usable.
+ }
+
+ //Connect:
+ Glom::sharedptr<Glom::SharedConnection> connection;
+ #ifdef GLIBMM_EXCEPTIONS_ENABLED
+ connection = Glom::ConnectionPool::get_and_connect();
+ #else
+ std::auto_ptr<ExceptionConnection> error;
+ connection = Glom::ConnectionPool::get_and_connect(error);
+ #endif
+
+ if(connection)
+ std::cout << "Connected" << std::endl;
+ else
+ std::cout << "Connection failed." << std::endl;
+
+ gdaconnection = connection->get_gda_connection();
+ //Cleanup:
+ Glom::ConnectionPool::delete_instance();
}
- //Connect:
- Glom::sharedptr<Glom::SharedConnection> connection;
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
- connection = Glom::ConnectionPool::get_and_connect();
-#else
- std::auto_ptr<ExceptionConnection> error;
- connection = Glom::ConnectionPool::get_and_connect(error);
-#endif
-
- if(connection)
- std::cout << "Connected" << std::endl;
- else
- std::cout << "Connection failed." << std::endl;
+ std::cout << "gdaconnection refcount=" << G_OBJECT(gdaconnection->gobj())->ref_count << std::endl;
- //Cleanup:
- Glom::ConnectionPool::delete_instance();
return 0;
}
Modified: trunk/glom/main.cc
==============================================================================
--- trunk/glom/main.cc (original)
+++ trunk/glom/main.cc Wed Apr 9 10:57:24 2008
@@ -43,6 +43,8 @@
#include "application.h"
#include <glom/libglom/glade_utils.h>
+#include <fontconfig/fontconfig.h> //For cleanup.
+
namespace Glom
{
@@ -303,6 +305,10 @@
//Clean up singletons:
Glom::ConnectionPool::delete_instance();
+ //These fail, probably because of previous things that are causing leaks:
+ //cairo_debug_reset_static_data(); //This crashes with _cairo_hash_table_destroy: Assertion `hash_table->live_entries == 0' failed.
+ //FcFini(); //This crashes with "FcCacheFini: Assertion `fcCacheChains[i] == ((void *)0)' failed."
+
return 0;
}
Modified: trunk/glom/utility_widgets/flowtable.cc
==============================================================================
--- trunk/glom/utility_widgets/flowtable.cc (original)
+++ trunk/glom/utility_widgets/flowtable.cc Wed Apr 9 10:57:24 2008
@@ -37,7 +37,9 @@
#define GLOM_FLOWTABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GLOM_TYPE_FLOWTABLE, GlomFlowtable))
#endif
+#ifndef GLIBMM_VFUNCS_ENABLED
GtkContainerClass* parent_class = NULL;
+#endif
#if 0
struct GlomFlowtableClass
@@ -323,6 +325,33 @@
FlowTable::~FlowTable()
{
+ //Delete managed children.
+ //(For some reason this is not always happening via Gtk::Container:
+ /* Actualy, don't do this because we would then be double-deleting what the
+ * Container base class already deleted. We'll have to really find out if/why some
+ * things are not being deleted. murrayc.
+ bool one_deleted = true;
+ while(!m_children.empty() && one_deleted)
+ {
+ one_deleted = false;
+
+ type_vecChildren::iterator iter = m_children.begin();
+ FlowTableItem& item = *iter;
+
+ //Delete the widgets:
+ if(item.m_first || item.m_second)
+ {
+ if(item.m_first && item.m_first->is_managed_())
+ delete item.m_first;
+
+ if(item.m_second && item.m_second->is_managed_())
+ delete item.m_second;
+
+ m_children.erase(iter);
+ one_deleted = true; //Make sure that we loop again.
+ }
+ }
+ */
}
void FlowTable::set_design_mode(bool value)
@@ -505,7 +534,7 @@
guint i = 0;
for(i = start_widget; i < (start_widget+widget_count); ++i)
{
- FlowTableItem item = m_children[i];
+ const FlowTableItem& item = m_children[i];
int item_height = get_item_requested_height(item);
int item_width_first = 0;
@@ -681,7 +710,7 @@
guint i = start;
while( (height_so_far < height) && (i < m_children.size()))
{
- FlowTableItem item = m_children[i];
+ const FlowTableItem& item = m_children[i];
Gtk::Widget* first = item.m_first;
Gtk::Widget* second = item.m_second;
@@ -790,7 +819,7 @@
{
FlowTableItem& item = m_children[i];
- int item_height = get_item_requested_height(item);
+ const int item_height = get_item_requested_height(item);
//Start a new column if necessary:
int bottom = allocation.get_y() + allocation.get_height();
Modified: trunk/glom/utility_widgets/test_flowtable.cc
==============================================================================
--- trunk/glom/utility_widgets/test_flowtable.cc (original)
+++ trunk/glom/utility_widgets/test_flowtable.cc Wed Apr 9 10:57:24 2008
@@ -47,7 +47,7 @@
flowtable.set_columns_count(2);
flowtable.set_padding(5);
- Gtk::Entry button7; button7.set_text("seven");;
+ Gtk::Entry button7; button7.set_text("seven");
button7.show();
//button7.set_size_request(100, 100);
@@ -56,7 +56,7 @@
button8.show();
//button8.set_size_request(100, 100);
- Gtk::Label button9; button9.set_text("nine");;
+ Gtk::Label button9; button9.set_text("nine"); //TODO: valgrind says that something here is leaked.
button9.show();
//button7.set_size_request(100, 100);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]