[gnome-db] Problems with accents using libgda



Hi people!


Well, I'm developing a program using only the libgda library, but I having a problem wit it:
It isn't showing to me the accents of my database. The database was created with encoding
"latin1".My RDBMS is the PostgreSQL 7.3.2r1-2 and the GDA provider is gda2-postgres 0.11.0-2
(both from Debian SID).

I solved the problem with this statement:

execute_sql_non_query (connection, "SET CLIENT_ENCODING TO 'LATIN1'");

into the db_connect () function. But I don't think it the correct mode to solve it. Another 
problem is I need use the printf () functions instead of g_print () function into
show_table () function, because if I use the g_print () function I get a "Invalid UTF-8" 
with the out of this function.

I hope that you can be understand the problem, because my english is very poor! :)

Regards,

--fx


(The program that I'm using to access the database)



#include <stdio.h>
#include <string.h>
#include <glib.h>
#include <libgda/libgda.h>

#define BUFFER_SIZE	1024


gint
execute_sql_non_query (GdaConnection *connection, const gchar * buffer)
{
	GdaCommand *command;
	gint number;

	command = gda_command_new (buffer, GDA_COMMAND_TYPE_SQL, GDA_COMMAND_OPTION_STOP_ON_ERRORS);
	number  = gda_connection_execute_non_query (connection, command, NULL);
 
	gda_command_free (command);
     
	return (number);
}


void
show_table (GdaDataModel *dm)
{
	GdaValue *value;
	GdaRow *row;
	gint row_id;
	gint col_id;
	gchar *string;

	for (col_id = 0; col_id < gda_data_model_get_n_columns (dm); col_id++)
		g_print ("%s\t\t\t\t", gda_data_model_get_column_title (dm, col_id));
	
	g_print ("\n");

	for (row_id = 0; row_id < gda_data_model_get_n_rows (dm); row_id++) {
		row = (GdaRow*) gda_data_model_get_row (dm, row_id);

		for (col_id = 0; col_id < gda_data_model_get_n_columns (dm); col_id++) {
			value = gda_row_get_value (row, col_id);
			string = gda_value_stringify (value);
			
			printf ("%s\t", string);
			//g_print ("%s\t", string);
			gda_value_free (value);
			g_free (string);
		}

		g_print ("\n");
	}
}



gint
execute_sql_command (GdaConnection *connection, const gchar *buffer)
{
	GdaDataModel *dm;
	GdaCommand *command;
	GList *list;
	GList *node;
	gboolean error = FALSE;

	command = gda_command_new (buffer,
				   GDA_COMMAND_TYPE_SQL,
				   GDA_COMMAND_OPTION_STOP_ON_ERRORS);
	list = gda_connection_execute_command (connection, command, NULL);

	if (list != NULL) {
		for (node = g_list_first (list); node != NULL; node = g_list_next (node)) {
			dm = (GdaDataModel*) node->data;

			if (dm != NULL) {
				show_table (dm);
				g_object_unref (dm);
			}
			else
				error = TRUE;
		}
	}
	else
		error = TRUE;

	gda_command_free (command);

	return error;
}
	

void
db_connect (void)
{
	GdaClient *client;
	GdaConnection *connection;
	gchar *query = "SELECT * from clients";

	client = gda_client_new ();
	connection = gda_client_open_connection (client, "Agenda", NULL, NULL,
						 GDA_CONNECTION_OPTIONS_READ_ONLY);
	execute_sql_non_query (connection, "SET CLIENT_ENCODING TO 'LATIN1'");
	execute_sql_command (connection, query);

	gda_client_close_all_connections (client);
	gda_main_quit ();
}


int
main (int argc, char **argv)
{
	gda_init ("Test", "0.1", argc, argv);

	gda_main_run ((GdaInitFunc) db_connect, (gpointer) NULL);
	
	return 0;
}





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