Re: [gnome-db] 2 issues with GdaConnection
- From: Mark Johnson <mrj001 shaw ca>
- To: Vivien Malerba <vmalerba gmail com>
- Cc: gnome-db list <gnome-db-list gnome org>
- Subject: Re: [gnome-db] 2 issues with GdaConnection
- Date: Fri, 21 Mar 2008 21:33:07 -0600
Vivien Malerba wrote:
On Fri, Mar 21, 2008 at 4:44 PM, Mark Johnson <mrj001 shaw ca> wrote:
On page:
http://library.gnome.org/devel/libgda-4.0/3.99/GdaConnection.html
for function gda_connection_open_from_dsn, we find:
" If a new GdaConnection
<http://library.gnome.org/devel/libgda-4.0/3.99/GdaConnection.html> 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:
http://library.gnome.org/devel/libgda-4.0/3.99/connections.html
We find this statement:
" Closing the connection can be ordered using gda_connection_close ()
<http://library.gnome.org/devel/libgda-4.0/3.99/GdaConnection.html#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
doc.
Thanks.
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=127.0.0.1 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.
Thanks,
Vivien
Mark
#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;
printf("Initializing\n");
g_type_init();
gda_init("Issue513149", "1.0", 0, NULL);
// Connect to the server
printf("Connecting\n");
pConn = gda_connection_open_from_dsn("Issue513149",
NULL, // auth string
GDA_CONNECTION_OPTIONS_NONE,
&error);
if (error != NULL)
{
fprintf(stderr, "Error calling gda_connection_open_from_dsn\n");
fprintf(stderr, error->message);
exit(1);
}
// 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",
NULL,
&error);
if (error != NULL)
{
fprintf(stderr, "Error calling gda_sql_parser_parse_string\n");
fprintf(stderr, error->message);
exit(1);
}
g_object_unref(pParser);
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);
exit(1);
}
pHolder = gda_set_get_holder(pParams, "the_guid");
if (pHolder == NULL)
{
fprintf(stderr, "Error calling gda_set_get_holder\n");
exit(1);
}
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);
exit(1);
}
g_object_unref(pParams);
pParams = NULL;
g_object_unref(pStmt);
pStmt = NULL;
// close connection
gda_connection_close(pConn);
g_object_unref(pConn);
pConn = NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]