Re: [gnome-db] 2 issues with GdaConnection

Vivien Malerba wrote:
On Fri, Mar 21, 2008 at 4:44 PM, Mark Johnson <mrj001 shaw ca> wrote:
On page:
 for function gda_connection_open_from_dsn, we find:
 " If a new GdaConnection
 <> is
 created, then the caller will hold a reference on it."
 This seems to imply that if an existing connection was returned from a
 pool of connections, then the caller does not hold a reference on it.
 Therefore, the caller should call g_object_unref only in the case when a
 new connection is created.
 Question: How does one tell if a new connection was created?

 On page:
 We find this statement:
 " Closing the connection can be ordered using gda_connection_close ()
 or is automatically done when the connection object is destroyed (as is
 the case in the example abive when g_object_unref() is called with the
 connection as argument)."

That was from the V3 version where there wer connection pools
(GdaClient object). Now a GdaConnection object is created everytime
gda_connection_open_from...() is called sucessfully. I'll correct the
 When I called g_object_unref on the connection, expecting it to close
 automatically, I found the following in the PostgreSQL log:
 issue513149_dbLOG:  unexpected EOF on client connection
 issue513149_dbLOG:  disconnection: session time: 0:00:00.268
 user=issue513149_user database=issue513149_db host= port=37580

 When I added a call to gda_connection_close prior to the g_object_unref,
 the unexpected EOF message did not appear.  It seems that with
 PostgreSQL, the connection is not automatically closing.

Closing the connection is done automatically when a connection object
is destroted (the same provider's function is called). Are you sure
you did not have 2 references on the connection before calling
g_object_unref()? Otherwise can you send me the piece of code (I'm a
bit lazy...)?
I don't think I have 2 references to the connection. I've attached a current snapshot of my file to let you see it. It's a work in progress for a test case for one of my bugs.


#include <libgda/libgda.h>
#include <sql-parser/gda-sql-parser.h>
#define TABLE_NAME "slots"

int main()
GdaClient *pClient = NULL;
GdaConnection *pConn = NULL;
GError *error = NULL;
GdaSqlParser *pParser = NULL;
GdaStatement *pStmt = NULL;
GdaSet *pParams = NULL;
GdaHolder *pHolder = NULL;
gchar* field_name = NULL;
GValue *pValue = NULL;
gda_init("Issue513149", "1.0", 0, NULL);

// Connect to the server
pConn = gda_connection_open_from_dsn("Issue513149",
         NULL,                       // auth string
if (error != NULL)
   fprintf(stderr, "Error calling gda_connection_open_from_dsn\n");
   fprintf(stderr, error->message);

// Create the SQL statement object
printf("building statement\n");
pParser = gda_sql_parser_new();
pStmt = gda_sql_parser_parse_string(pParser,
         "SELECT * FROM slots WHERE obj_guid = ##the_guid::string",
if (error != NULL)
   fprintf(stderr, "Error calling gda_sql_parser_parse_string\n");
   fprintf(stderr, error->message);
pParser = NULL;

gda_statement_get_parameters(pStmt, &pParams, &error);
if (error != NULL)
   fprintf(stderr, "Error calling gda_statement_get_parameters\n");
   fprintf(stderr, error->message);
pHolder = gda_set_get_holder(pParams, "the_guid");
if (pHolder == NULL)
   fprintf(stderr, "Error calling gda_set_get_holder\n");
pValue = gda_value_new(G_TYPE_STRING);
g_value_set_string(pValue, "4cbf958a005bee408d13aef08914e1c9");
gda_holder_set_value(pHolder, pValue);

// execute query
printf("executing query\n");
// printf("QUERY: %s\n", gda_connection_statement_to_sql(pConn,
//          pStmt,
//          pParams,
//          );
gda_connection_statement_execute_select(pConn, pStmt, pParams, &error);
if (error != NULL)
   fprintf(stderr, "Error calling gda_connection_statement_execute_select\n");
   fprintf(stderr, error->message);
   pParams = NULL;
   pStmt = NULL;

   // close connection
   pConn = NULL;

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