Re: [gnome-db] 2 issues with GdaConnection



>  >
>  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.

The problem comes from the fact that when you call
g_object_unref(pConn), there is still an object holding a reference on
the pConn object, it is the GdaDataModel returned from the
gda_connection_statement_execute_select() function (which you ignore
in your example but still exists). Here is attached your example,
modified to show the reference count on the pConn object.

Cheers,

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

int main()
{
	GdaConnection *pConn = NULL;
	GError *error = NULL;
	GdaSqlParser *pParser = NULL;
	GdaStatement *pStmt = NULL;
	GdaSet *pParams = NULL;
	GdaHolder *pHolder = 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("pgsales",
					     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);
		}
	g_print ("Ref count: %d\n", G_OBJECT (pConn)->ref_count);

	// Create the SQL statement object
	printf("building statement\n");
	pParser = gda_sql_parser_new();
	pStmt = gda_sql_parser_parse_string(pParser,
					    "SELECT * FROM customers WHERE name = ##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, "lew");
	gda_holder_set_value(pHolder, pValue);

	// execute query
	printf("executing query\n");
	// printf("QUERY: %s\n", gda_connection_statement_to_sql(pConn,
	//          pStmt,
	//          pParams,
	//          );
	GdaDataModel *model;
	model = 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_print ("Ref count: %d\n", G_OBJECT (pConn)->ref_count);
	gda_data_model_dump (model, stdout);
	g_object_unref (model);
	g_print ("Ref count: %d\n", G_OBJECT (pConn)->ref_count);
	g_object_unref(pParams);
	pParams = NULL;
	g_object_unref(pStmt);
	pStmt = NULL;

	// close connection
	//gda_connection_close(pConn);
	g_object_unref(pConn);
	pConn = NULL;

	return 0;
}


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