Re: [gnome-db] GdaCommand.

2009/6/23 Bas Driessen <bas driessen xobas com>

In V3 there is GdaCommand. I use this to initialize as follows:


Note the parameter GDA_COMMAND_TYPE_TABLE

This gave me the option to have a database table be represented in a data model and by adding/editing/deleting rows from the data model, the underlying database table is updated as well.

To be complete the list was as follows:

typedef enum {
} GdaCommandType;

How do I use GDA_COMMAND_TYPE_TABLE in V4? Can't find anything in the docs.

You'll have to create a GdaStatement from the "SELECT * FROM table" (which is what was done in V3 BTW). You can do this using a parser object, or by creating the object directly (in 4.2 there will be an API to build statement without using any SQL).

Using a parser, your code would be:
#include <sql-parser/gda-sql-parser.h>
GdaSqlParser *parser = gda_sql_parser_new ();
GdaStatement *stmt;
stmt = gda_sql_parser_parse_string (parser, "SELECT * FROM table", NULL, NULL);
g_object_unref (parser);

Then execute that statement:
GdaDataModel *model;
GError *error = NULL;
model = gda_connection_statement_execute_select (cnc, stmt, NULL, &error);
if (!model)
  // handle error

The returned GdaDataModel is a GdaDataSelect, for which you need to call
gda_data_select_compute_modification_statements (GDA_DATA_SELECT (model), &error)
which should return TRUE if you can modify the data model, and FALSE if not (in which case you'll get the reason why in the error pointer). If it worked, then you can modify the data model like any other data model.

This is a bit more complicated than in V3 but is much more generic and most importantly implemented outside the providers so the behaviour will be the same with all providers (which was not the case in V3).

Further to this, it appears that all the logic that I have added in the past as recordset_append_row (remove and update) have been removed from the various providers..... ???? . So what is the new way of processing record sets?

You have gda_data_model_append_row(), gda_data_model_append_values(), gda_data_model_set_values() and gda_data_model_remove_row() to modify a data model.


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