[gnome-db] Please Check this example
- From: "Daniel Espinosa" <esodan gmail com>
- To: gnome-db-list gnome org
- Subject: [gnome-db] Please Check this example
- Date: Mon, 27 Mar 2006 16:10:04 -0600
After following the steps to connect and access the data to create a
simple example, I make this code, but the GNOME-DB widgets doesn't show
the data; I test the GdaDataModel, accessing the values and it is
valid, then may be is a bug on the Widgets.
Please note that, I use GValue's functions: g_value_transform, to
convert the GdaValue (that it is a GValue) into a String (then the
gda_value_stringify don't needed any more); this is an example for Why
I want to delete most of the API in GdaValue and the Type of GdaValue
it selft.
--
Trabajar, la mejor arma para tu superación
"de grano en grano, se hace la arena" (R) (entrámite, pero para los cuates: LIBRE)
/*
* Initial main.c file generated by Glade. Edit as required.
* Glade will not overwrite this file.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <gnome.h>
#include "interface.h"
#include "support.h"
#include <libgnomedb/libgnomedb.h>
int
main (int argc, char *argv[])
{
GtkWidget *window1;
GtkWidget *logindlg;
#ifdef ENABLE_NLS
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
#endif
gnome_db_init (PACKAGE, VERSION,
argc, argv);
/*
* Create the Main window
*/
window1 = create_window1 ();
/*
Create the Widget to Show the Data:
First: Connect to the Server
*/
logindlg = gnome_db_login_dialog_new("Select the Data Base Provider to Login");
if (gnome_db_login_dialog_run(GNOME_DB_LOGIN_DIALOG(logindlg)))
{
GdaClient *client;
GdaConnection *cnn;
GError *error = NULL;
client = gda_client_new();
cnn = gda_client_open_connection(client,
gnome_db_login_dialog_get_dsn(logindlg),
gnome_db_login_dialog_get_username(logindlg),
gnome_db_login_dialog_get_password(logindlg),
GDA_CONNECTION_OPTIONS_DONT_SHARE,
&error);
if( gda_connection_is_opened (cnn)) {
GdaDict *dict;
GdaQuery *query;
GdaDataModel *data_model;
dict = GDA_DICT (gda_dict_new());
gda_dict_set_connection(dict, cnn);
if (! gda_dict_load (dict, &error)) {
GtkWidget *msgdlg;
msgdlg = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"Couldn't Load the Data Base's Dictionary!");
gtk_dialog_run(GTK_MESSAGE_DIALOG(msgdlg));
gtk_widget_destroy(msgdlg);
}
// Destroy the Login Dialog not used any more
gtk_widget_destroy(logindlg);
/*
Now Set Get the data from the Data Base
*/
query = gda_query_new_from_sql(dict, "SELECT * FROM customers", &error);
if(error)
g_printf("Error: %s\n", error->message);
if(GDA_IS_QUERY(query)) {
GtkWidget *grid;
GtkWidget *vbox;
gchar *sql;
GdaCommand *command;
sql = gda_renderer_render_as_sql(GDA_RENDERER(query), NULL, 0, NULL);
g_printf("COMMAND TEXT: %s\n", sql);
g_printf("QUERY TEXT: %s\n");
//sql = "SELECT * FROM custumers";
command = gda_command_new(sql, GDA_COMMAND_TYPE_SQL,GDA_COMMAND_OPTION_STOP_ON_ERRORS);
data_model = gda_connection_execute_single_command (cnn,
command,
NULL,
&error);
if(!GDA_IS_DATA_MODEL(data_model)) {
g_printf("It isn't a DataModel!\n");
}
else {
GdaValue *value;
gint i, j;
g_printf("It IS a GdaDataModel!\n");
GValue *val = g_new0(GValue, 1);
g_value_init(val, G_TYPE_STRING);
g_printf("VALUES:\n");
for( i = 0; i < gda_data_model_get_n_rows(data_model); i++) {
for( j = 0; j <gda_data_model_get_n_columns(data_model); j++) {
value = gda_data_model_get_value_at(data_model, j, i);
g_value_transform(value, val);
g_printf(" %s | ", g_value_get_string(val));
}
g_printf("\n");
}
}
/*
Now Set up the Widget to Show the Data
*/
grid = gnome_db_form_new(data_model);
vbox = lookup_widget(window1, "vbox");
gtk_box_pack_end_defaults(vbox, grid);
/* Show the Main window*/
gtk_widget_show (window1);
}
}
else {
GtkWidget *msgdlg;
msgdlg = gtk_message_dialog_new(NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_OK,
"Couldn't Connect to the Data Base!");
gtk_dialog_run(GTK_MESSAGE_DIALOG(msgdlg));
gtk_widget_destroy(msgdlg);
}
}
gnome_db_main_run (NULL, NULL);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]