libgnomedb r1746 - in trunk: . extra/demos libgnomedb/plugins samples/SimpleExample testing
- From: vivien svn gnome org
- To: svn-commits-list gnome org
- Subject: libgnomedb r1746 - in trunk: . extra/demos libgnomedb/plugins samples/SimpleExample testing
- Date: Tue, 23 Sep 2008 18:45:07 +0000 (UTC)
Author: vivien
Date: Tue Sep 23 18:45:07 2008
New Revision: 1746
URL: http://svn.gnome.org/viewvc/libgnomedb?rev=1746&view=rev
Log:
2008-09-23 Vivien Malerba <malerba gnome-db org>
* libgnomedb/plugins/gnome-db-data-cell-renderer-pict.c:
* libgnomedb/plugins/gnome-db-entry-pict.c:
* libgnomedb/plugins/common-pict.[ch]: don't use GPOINTER_TO_INT to store pointers!
* modifications due to the removal of the GdaDataModelQuery object
Modified:
trunk/ChangeLog
trunk/extra/demos/form.c
trunk/extra/demos/form_pict.c
trunk/extra/demos/form_rw.c
trunk/extra/demos/grid.c
trunk/extra/demos/grid_pict.c
trunk/extra/demos/grid_rw.c
trunk/extra/demos/linked_grid_form.c
trunk/extra/demos/linked_model_param.c
trunk/libgnomedb/plugins/common-pict.c
trunk/libgnomedb/plugins/common-pict.h
trunk/libgnomedb/plugins/gnome-db-data-cell-renderer-pict.c
trunk/libgnomedb/plugins/gnome-db-entry-pict.c
trunk/samples/SimpleExample/example.c
trunk/testing/test-dyn-widgets.c
Modified: trunk/extra/demos/form.c
==============================================================================
--- trunk/extra/demos/form.c (original)
+++ trunk/extra/demos/form.c Tue Sep 23 18:45:07 2008
@@ -41,7 +41,7 @@
/* Create the demo widget */
stmt = gda_sql_parser_parse_string (demo_parser, "SELECT * FROM products", NULL, NULL);
- model = gda_data_model_query_new (demo_cnc, stmt, NULL);
+ model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
form = gnome_db_form_new (model);
g_object_unref (model);
Modified: trunk/extra/demos/form_pict.c
==============================================================================
--- trunk/extra/demos/form_pict.c (original)
+++ trunk/extra/demos/form_pict.c Tue Sep 23 18:45:07 2008
@@ -47,9 +47,9 @@
/* Create the demo widget */
stmt = gda_sql_parser_parse_string (demo_parser, "SELECT id, pict FROM pictures", NULL, NULL);
- model = gda_data_model_query_new (demo_cnc, stmt, NULL);
+ model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
- gda_data_model_query_compute_modification_statements (GDA_DATA_MODEL_QUERY (model), NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (model), NULL);
form = gnome_db_form_new (model);
g_object_unref (model);
Modified: trunk/extra/demos/form_rw.c
==============================================================================
--- trunk/extra/demos/form_rw.c (original)
+++ trunk/extra/demos/form_rw.c Tue Sep 23 18:45:07 2008
@@ -44,9 +44,12 @@
stmt = gda_sql_parser_parse_string (demo_parser,
"SELECT ref, category, name, price, wh_stored FROM products",
NULL, NULL);
- model = gda_data_model_query_new (demo_cnc, stmt, NULL);
+ model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
- gda_data_model_query_compute_modification_statements (GDA_DATA_MODEL_QUERY (model), NULL);
+ GError *error = NULL;
+ if (!gda_data_select_compute_modification_statements (GDA_DATA_SELECT (model), &error)) {
+ g_print ("===> %s\n", error && error->message ? error->message : "No detail");
+ }
form = gnome_db_form_new (model);
g_object_unref (model);
Modified: trunk/extra/demos/grid.c
==============================================================================
--- trunk/extra/demos/grid.c (original)
+++ trunk/extra/demos/grid.c Tue Sep 23 18:45:07 2008
@@ -41,7 +41,7 @@
/* Create the demo widget */
stmt = gda_sql_parser_parse_string (demo_parser, "SELECT * FROM products", NULL, NULL);
- model = gda_data_model_query_new (demo_cnc, stmt, NULL);
+ model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
grid = gnome_db_grid_new (model);
g_object_unref (model);
Modified: trunk/extra/demos/grid_pict.c
==============================================================================
--- trunk/extra/demos/grid_pict.c (original)
+++ trunk/extra/demos/grid_pict.c Tue Sep 23 18:45:07 2008
@@ -47,9 +47,9 @@
/* Create the demo widget */
stmt = gda_sql_parser_parse_string (demo_parser, "SELECT id, pict FROM pictures", NULL, NULL);
- model = gda_data_model_query_new (demo_cnc, stmt, NULL);
+ model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
- gda_data_model_query_compute_modification_statements (GDA_DATA_MODEL_QUERY (model), NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (model), NULL);
grid = gnome_db_grid_new (model);
g_object_unref (model);
Modified: trunk/extra/demos/grid_rw.c
==============================================================================
--- trunk/extra/demos/grid_rw.c (original)
+++ trunk/extra/demos/grid_rw.c Tue Sep 23 18:45:07 2008
@@ -42,9 +42,9 @@
/* Create the demo widget */
stmt = gda_sql_parser_parse_string (demo_parser, "SELECT ref, category, name, price, wh_stored FROM products", NULL, NULL);
- model = gda_data_model_query_new (demo_cnc, stmt, NULL);
+ model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
- gda_data_model_query_compute_modification_statements (GDA_DATA_MODEL_QUERY (model), NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (model), NULL);
grid = gnome_db_grid_new (model);
g_object_unref (model);
Modified: trunk/extra/demos/linked_grid_form.c
==============================================================================
--- trunk/extra/demos/linked_grid_form.c (original)
+++ trunk/extra/demos/linked_grid_form.c Tue Sep 23 18:45:07 2008
@@ -103,13 +103,13 @@
"SELECT c.id, c.name, c.default_served_by as \"SalesRep\""
"FROM customers c "
"LEFT JOIN salesrep s ON (s.id=c.default_served_by)", NULL, NULL);
- cust_model = gda_data_model_query_new (demo_cnc, stmt, NULL);
+ cust_model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
- gda_data_model_query_compute_modification_statements (GDA_DATA_MODEL_QUERY (cust_model), NULL);
+ gda_data_select_compute_modification_statements (GDA_DATA_SELECT (cust_model), NULL);
/* create a data model for the salesrep */
stmt = gda_sql_parser_parse_string (demo_parser, "SELECT id, name FROM salesrep", NULL, NULL);
- sr_model = gda_data_model_query_new (demo_cnc, stmt, NULL);
+ sr_model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
/* create grid widget */
Modified: trunk/extra/demos/linked_model_param.c
==============================================================================
--- trunk/extra/demos/linked_model_param.c (original)
+++ trunk/extra/demos/linked_model_param.c Tue Sep 23 18:45:07 2008
@@ -49,7 +49,7 @@
/* create a data model for the salesrep */
stmt = gda_sql_parser_parse_string (demo_parser, "SELECT id, name FROM salesrep", NULL, NULL);
- sr_model = (GdaDataModel*) gda_data_model_query_new (demo_cnc, stmt, NULL);
+ sr_model = gda_connection_statement_execute_select (demo_cnc, stmt, NULL, NULL);
g_object_unref (stmt);
/* create a data model for the customers, and get a list of parameters */
@@ -60,7 +60,7 @@
"WHERE s.id = ##/*name:'SalesRep' type:gint descr:'Sales person'*/ "
"OR s.id IS NULL", NULL, NULL);
gda_statement_get_parameters (stmt, ¶ms, NULL);
- cust_model = (GdaDataModel*) gda_data_model_query_new (demo_cnc, stmt, params);
+ cust_model = gda_connection_statement_execute_select (demo_cnc, stmt, params, NULL);
g_object_unref (stmt);
/* restrict the c.default_served_by field in the grid to be within the sr_model */
Modified: trunk/libgnomedb/plugins/common-pict.c
==============================================================================
--- trunk/libgnomedb/plugins/common-pict.c (original)
+++ trunk/libgnomedb/plugins/common-pict.c Tue Sep 23 18:45:07 2008
@@ -25,19 +25,18 @@
/*
* Fills in @bindata->data and @bindata->data_length with the contents of @value.
*
- * REM: @error is used differently here: the domain is always 0, the code must be converted to a stock id
- * using GINT_TO_POINTER, and message is a clear text error message.
- *
* Returns: TRUE if the data has been loaded correctly
*/
gboolean
-common_pict_load_data (PictOptions *options, const GValue *value, PictBinData *bindata, GError **error)
+common_pict_load_data (PictOptions *options, const GValue *value, PictBinData *bindata,
+ const gchar **stock, GError **error)
{
gboolean allok = TRUE;
if (value) {
if (gda_value_is_null ((GValue *) value)) {
- g_set_error (error, 0, GPOINTER_TO_INT (GTK_STOCK_MISSING_IMAGE), _("No data to display"));
+ *stock = GTK_STOCK_MISSING_IMAGE;
+ g_set_error (error, 0, 0, _("No data to display"));
allok = FALSE;
}
else {
@@ -66,7 +65,8 @@
memcpy (bindata->data, bin->data, bin->binary_length);
}
else {
- g_set_error (error, 0, GPOINTER_TO_INT (GTK_STOCK_DIALOG_ERROR),
+ *stock = GTK_STOCK_DIALOG_ERROR;
+ g_set_error (error, 0, 0,
_("No data to display"));
allok = FALSE;
}
@@ -103,18 +103,21 @@
}
}
else {
- g_set_error (error, 0, GPOINTER_TO_INT (GTK_STOCK_MISSING_IMAGE), _("Empty data"));
+ *stock = GTK_STOCK_MISSING_IMAGE;
+ g_set_error (error, 0, 0, _("Empty data"));
allok = FALSE;
}
}
else {
- g_set_error (error, 0, GPOINTER_TO_INT (GTK_STOCK_DIALOG_ERROR), _("Unhandled type of data"));
+ *stock = GTK_STOCK_DIALOG_ERROR;
+ g_set_error (error, 0, 0, _("Unhandled type of data"));
allok = FALSE;
}
}
}
else {
- g_set_error (error, 0, GPOINTER_TO_INT (GTK_STOCK_MISSING_IMAGE), "");
+ *stock = GTK_STOCK_MISSING_IMAGE;
+ g_set_error (error, 0, 0, _("Empty data"));
allok = FALSE;
}
@@ -184,13 +187,10 @@
* Creates a GdkPixbuf from @bindata and @options; returns NULL if an error occured.
*
* if @allocation is %NULL, then the GdaPixbuf will have the real size of the image.
- *
- * REM: @error is used differently here: the domain is always 0, the code must be converted to a stock id
- * using GINT_TO_POINTER, and message is a clear text error message.
- *
*/
GdkPixbuf *
-common_pict_make_pixbuf (PictOptions *options, PictBinData *bindata, PictAllocation *allocation, GError **error)
+common_pict_make_pixbuf (PictOptions *options, PictBinData *bindata, PictAllocation *allocation,
+ const gchar **stock, GError **error)
{
GdkPixbuf *retpixbuf = NULL;
@@ -205,7 +205,8 @@
bindata->data = NULL;
bindata->data_length = 0;
- g_set_error (error, 0, GPOINTER_TO_INT (GTK_STOCK_DIALOG_ERROR),
+ *stock = GTK_STOCK_DIALOG_ERROR;
+ g_set_error (error, 0, 0,
_("Error while deserializing data:\n%s"),
loc_error && loc_error->message ? loc_error->message : _("No detail"));
@@ -214,7 +215,8 @@
else {
retpixbuf = gdk_pixbuf_from_pixdata (&pixdata, FALSE, &loc_error);
if (!retpixbuf) {
- g_set_error (error, 0, GPOINTER_TO_INT (GTK_STOCK_DIALOG_ERROR),
+ *stock = GTK_STOCK_DIALOG_ERROR;
+ g_set_error (error, 0, 0,
_("Error while interpreting data as an image:\n%s"),
loc_error && loc_error->message ? loc_error->message : _("No detail"));
g_error_free (loc_error);
@@ -251,8 +253,7 @@
if (!retpixbuf) {
if (loc_error)
g_propagate_error (error, loc_error);
- if (error && *error)
- (*error)->code = GPOINTER_TO_INT (GTK_STOCK_MISSING_IMAGE);
+ *stock = GTK_STOCK_MISSING_IMAGE;
}
else
g_object_ref (retpixbuf);
@@ -262,7 +263,8 @@
notice_msg = g_strdup_printf (_("Error while interpreting data as an image:\n%s"),
loc_error && loc_error->message ? loc_error->message : _("No detail"));
g_error_free (loc_error);
- g_set_error (error, 0, GPOINTER_TO_INT (GTK_STOCK_DIALOG_WARNING), notice_msg);
+ *stock = GTK_STOCK_DIALOG_WARNING;
+ g_set_error (error, 0, 0, notice_msg);
g_free (notice_msg);
}
@@ -479,9 +481,10 @@
/* export data to another format */
GdkPixbuf *pixbuf;
gchar *format_str;
+ const gchar *stock;
format_str = g_slist_nth_data (pictformat.formats, format - 1);
- pixbuf = common_pict_make_pixbuf (menudata->options, menudata->bindata, NULL, &error);
+ pixbuf = common_pict_make_pixbuf (menudata->options, menudata->bindata, NULL, &stock, &error);
if (pixbuf) {
allok = gdk_pixbuf_save (pixbuf, filename, format_str, &error, NULL);
g_object_unref (pixbuf);
Modified: trunk/libgnomedb/plugins/common-pict.h
==============================================================================
--- trunk/libgnomedb/plugins/common-pict.h (original)
+++ trunk/libgnomedb/plugins/common-pict.h Tue Sep 23 18:45:07 2008
@@ -60,9 +60,11 @@
GdkPixbuf *common_pict_fetch_cached_pixbuf (PictOptions *options, const GValue *value);
void common_pict_clear_pixbuf_cache (PictOptions *options);
-gboolean common_pict_load_data (PictOptions *options, const GValue *value, PictBinData *bindata, GError **error);
+gboolean common_pict_load_data (PictOptions *options, const GValue *value, PictBinData *bindata,
+ const gchar **stock, GError **error);
-GdkPixbuf *common_pict_make_pixbuf (PictOptions *options, PictBinData *bindata, PictAllocation *allocation, GError **error);
+GdkPixbuf *common_pict_make_pixbuf (PictOptions *options, PictBinData *bindata, PictAllocation *allocation,
+ const gchar **stock, GError **error);
void common_pict_create_menu (PictMenu *pictmenu, GtkWidget *attach_to, PictBinData *bindata, PictOptions *options,
PictCallback callback, gpointer data);
Modified: trunk/libgnomedb/plugins/gnome-db-data-cell-renderer-pict.c
==============================================================================
--- trunk/libgnomedb/plugins/gnome-db-data-cell-renderer-pict.c (original)
+++ trunk/libgnomedb/plugins/gnome-db-data-cell-renderer-pict.c Tue Sep 23 18:45:07 2008
@@ -276,7 +276,7 @@
if (value) {
GValue *gval = g_value_get_boxed (value);
GdkPixbuf *pixbuf = NULL;
- gchar *stock = NULL;
+ const gchar *stock = NULL;
GError *error = NULL;
if (cell->priv->bindata.data) {
@@ -286,12 +286,7 @@
}
/* fill in cell->priv->data */
- if (!common_pict_load_data (&(cell->priv->options), gval, &(cell->priv->bindata), &error)) {
- stock = GINT_TO_POINTER (error->code);
- g_error_free (error);
- error = NULL;
- }
- else {
+ if (common_pict_load_data (&(cell->priv->options), gval, &(cell->priv->bindata), &stock, &error)) {
/* try to make a pixbuf */
pixbuf = common_pict_fetch_cached_pixbuf (&(cell->priv->options), gval);
if (pixbuf)
@@ -299,20 +294,13 @@
else {
pixbuf = common_pict_make_pixbuf (&(cell->priv->options),
&(cell->priv->bindata), &(cell->priv->size),
- &error);
+ &stock, &error);
if (pixbuf)
common_pict_add_cached_pixbuf (&(cell->priv->options), gval, pixbuf);
}
- if (!pixbuf) {
- if (error) {
- stock = GINT_TO_POINTER (error->code);
- g_error_free (error);
- error = NULL;
- }
- else
- stock = GTK_STOCK_MISSING_IMAGE;
- }
+ if (!pixbuf && !stock)
+ stock = GTK_STOCK_MISSING_IMAGE;
}
/* display something */
@@ -323,6 +311,8 @@
if (stock)
g_object_set (G_OBJECT (cell), "stock-id", stock, NULL);
+ if (error)
+ g_error_free (error);
cell->priv->value = gval;
}
Modified: trunk/libgnomedb/plugins/gnome-db-entry-pict.c
==============================================================================
--- trunk/libgnomedb/plugins/gnome-db-entry-pict.c (original)
+++ trunk/libgnomedb/plugins/gnome-db-entry-pict.c Tue Sep 23 18:45:07 2008
@@ -362,8 +362,7 @@
}
/* fill in mgpict->priv->data */
- if (!common_pict_load_data (&(mgpict->priv->options), value, &(mgpict->priv->bindata), &error)) {
- stock = GINT_TO_POINTER (error->code);
+ if (!common_pict_load_data (&(mgpict->priv->options), value, &(mgpict->priv->bindata), &stock, &error)) {
notice_msg = g_strdup (error->message ? error->message : "");
g_error_free (error);
}
@@ -376,7 +375,7 @@
static void
display_image (GnomeDbEntryPict *mgpict, const GValue *value, const gchar *error_stock, const gchar *notice)
{
- gchar *stock = (gchar *) error_stock;
+ const gchar *stock = error_stock;
gchar *notice_msg = NULL;
GdkPixbuf *pixbuf;
PictAllocation alloc;
@@ -389,7 +388,8 @@
if (pixbuf)
g_object_ref (pixbuf);
else {
- pixbuf = common_pict_make_pixbuf (&(mgpict->priv->options), &(mgpict->priv->bindata), &alloc, &error);
+ pixbuf = common_pict_make_pixbuf (&(mgpict->priv->options), &(mgpict->priv->bindata), &alloc,
+ &stock, &error);
if (pixbuf)
common_pict_add_cached_pixbuf (&(mgpict->priv->options), value, pixbuf);
}
@@ -400,7 +400,6 @@
}
else {
if (error) {
- stock = GINT_TO_POINTER (error->code);
notice_msg = g_strdup (error->message ? error->message : "");
g_error_free (error);
}
Modified: trunk/samples/SimpleExample/example.c
==============================================================================
--- trunk/samples/SimpleExample/example.c (original)
+++ trunk/samples/SimpleExample/example.c Tue Sep 23 18:45:07 2008
@@ -10,6 +10,7 @@
* Application-Wide data
*/
typedef struct {
+ GdaConnection *cnc;
GtkWidget *main_window;
GdaDataModel *model_cust;
@@ -28,7 +29,6 @@
main (int argc, char *argv[])
{
GError *error = NULL;
- GdaClient *client;
GdaConnection *cnc;
gchar *str;
MainData *data;
@@ -38,22 +38,20 @@
gtk_init (&argc, &argv);
/* open a connection */
- client = gda_client_new ();
str = g_strdup_printf ("DB_DIR=.;DB_NAME=" DB_NAME);
- cnc = gda_client_open_connection_from_string (client, "SQLite", str,
- NULL, NULL,
- 0, &error);
+ cnc = gda_connection_from_from_string (client, "SQLite", str,
+ NULL, GDA_CONNECTION_OPTIONS_NONE, &error);
g_free (str);
if (! cnc)
g_error ("Can't open connection:\n%s\n", error->message);
- gda_dict_set_connection (default_dict, cnc);
/* create application specific data, and setup */
data = g_new0 (MainData, 1);
+ data->cnc = cnc;
data->main_window = create_main_window ();
prepare_main_window (data);
gtk_widget_show (data->main_window);
-
+
gtk_main ();
return 0;
}
@@ -91,7 +89,8 @@
{
GError *error = NULL;
- GdaQuery *query;
+ GdaSqlParser *parser;
+ GdaStatement *stmt;
GtkWidget *table = lookup_widget (data->main_window, "table1");
GdaSet *params;
@@ -113,9 +112,13 @@
#define CONTENTS_DEL_SQL "DELETE FROM order_contents WHERE order_id = ##oid::gint AND product_ref = ##-0::gchararray AND quantity = ##-2::gint AND discount = ##-3::gdouble"
/* Data model for customers */
- query = gda_query_new_from_sql (NULL, CUSTOMERS_SQL, NULL);
- data->model_cust = gda_data_model_query_new (query);
- g_object_unref (query);
+ parser = gda_connection_create_parser (data->cnc);
+ if (!parser)
+ parser = gda_sql_parser_new ();
+ stmt = gda_sql_parser_parse_string (parser, CUSTOMERS_SQL, NULL, NULL);
+ g_assert (stmt);
+ data->model_cust = gda_connection_statement_execute_select (data->cnc, stmt, NULL, NULL);
+ g_object_unref (stmt);
/* Data model for the orders, set the modification queries (as SQL) to make the
* data model writable.
@@ -123,9 +126,10 @@
* The data model is not initially filled because the SELECT SQL query requires a variable to be
* set (the "Customer" variable)
*/
- query = gda_query_new_from_sql (NULL, ORDERS_SQL, NULL);
- data->model_orders = gda_data_model_query_new (query);
- g_object_unref (query);
+ stmt = gda_sql_parser_parse_string (parser, ORDERS_SQL, NULL, NULL);
+ g_assert (stmt);
+ data->model_orders = ;
+ g_object_unref (stmt);
ok = gda_data_model_query_set_modification_query (GDA_DATA_MODEL_QUERY (data->model_orders),
ORDERS_INS_SQL, &error);
Modified: trunk/testing/test-dyn-widgets.c
==============================================================================
--- trunk/testing/test-dyn-widgets.c (original)
+++ trunk/testing/test-dyn-widgets.c Tue Sep 23 18:45:07 2008
@@ -737,7 +737,7 @@
return NULL;
}
- model = (GdaDataModel*) gda_data_model_query_new (config->cnc, stmt, dset);
+ model = (GdaDataModel*) gda_connection_statement_execute_select (config->cnc, stmt, dset, NULL);
}
return model;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]