Re: [gnome-db] GdaCommand.



On Tue, 2009-06-23 at 14:21 +0200, Vivien Malerba wrote:


2009/6/23 Bas Driessen <bas driessen xobas com>
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).

OK, I have implemented this and when I try to remove a row from a data model I get the error: Model does not allow row deletion. If I try to append a row, I get the error: No INSERT statement provided.

Does that mean that this feature is not implemented for this provider, or am I missing something? I am using postgresql 8.3.7.  If it is not implemented for postgresql, for which provider is it implemented?



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.

Correct, these are available, but they don't appear to work for the provider postgresql (unless I am doing something wrong). I don't mind that you have taken out the code I have written, but if it is taken out and there is no (better) replacement code/alternative then obviously I have a problem with that.



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