2009/6/23 Bas Driessen <[email protected]>

>  Hello,
>
> In V3 there is GdaCommand. I use this to initialize as follows:
>
> *command = gda_command_new(buffer, **GDA_COMMAND_TYPE_TABLE**,
> GDA_COMMAND_OPTION_STOP_ON_ERRORS)*
>
> 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 {
>
>       GDA_COMMAND_TYPE_SQL,
>       GDA_COMMAND_TYPE_XML,
>       GDA_COMMAND_TYPE_PROCEDURE,
>       GDA_COMMAND_TYPE_TABLE,
>       GDA_COMMAND_TYPE_SCHEMA,
>       GDA_COMMAND_TYPE_INVALID
> } 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.

Vivien
_______________________________________________
gnome-db-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gnome-db-list

Reply via email to