Re: [gnome-db] append row to data model.



2006/1/26, Bas Driessen <bas driessen xobas com>:
>  Hello,
>
>  I see that many gda-data-model-xxxx calls have been changed (again ....
> again losing unproductive hours adapting to something that was already
> working rather than moving forward ... :(  )

I had to change the data model API because the usage of a GdaRow was
not possible with some kind of GdaDataModel I needed to write. It's
still possible to use a GdaRow for the data models based on GdaRow
(which inherit GdaDataModelRow).

>
>  Anyway ... If I look at the function gda_data_model_append_row() for
> instance. This used to have the arguments GdaDataModel and GdaRow. The last
> one containing the values you want to add to the data model and thus the
> database table. In the new situation the GdaRow argument has been removed.

Yes, the idea is to add a row, and then later to set the values of the
row. If you need the "old" behaviour, it is possible to add a
gboolean gda_data_model_row_append_row (GdaDataModel *model, GdaRow *row);
which simply calls the "append_row" virtual function of the
GdaDataModelRow class.
(and rename the static function which already has that name).

I can do it for you if you want.

> This means that this now only can append an empty line. I am using
> PostgreSQL and when executing this function it tries to insert a row into my
> table where all fields are NULL. Well, in most situations this is not
> allowed anyway, so where do we go with this function
> gda_data_model_append_row()? At the moment it is completely useless and
> dangerous for the database backend.

That kind of usage is not the only possible usage of GdaDataModel!

>
>  Btw, there is an error in gda_data_model_row_append_row where GdaRow *row
> is declared, but not initialized. 3 lines further is checks if it is not
> NULL, being not initialized it always exits here. I can provide a patch once
> I get some idea what is happening with the append.

Yes, the gda_data_model_row_append_row creates a new GdaRow which is
initialized with NULL values. This is made on purpose for the new API,
as the values for the new row are to be set after the row has been
added.

>
>  As an alternative then there is a function gda_data_model_append_values ().
> This appears to work for the datamodel itself, since it is appending the row
> with the values, but nothing is done in the database table itself. There is
> no logic at the backend postgres provider, so it is useless at the moment as
> well.

The gda_data_model_append_values() has been added to add an
initialized row like the old gda_data_model_append_row(), but without
using a GdaRow (remember that  some GdaDataModel can't use GdaRow
objects).

>
>  Shouldn't we combine these 2 functions so we get
> gda_data_model_append_row_values (GdaDataModel *model,
> GList *values, GError **error) for instance? Then this logic can link in to
> the existing append_row logic that exists for the backends as postgresql and
> mysql.

I prefer to keep a gda_data_model_append_row() without values as it is
usefull in some cases (obviously not for adding rows to a database!).

>
>  Please advise as I have no way now to append new rows to my database.
>

Here is what I suggest:
* modify the folloging function, which should make the postgres's
recordset work again (I'll commit it to CVS myself).
static gint
gda_data_model_row_append_values (GdaDataModel *model, const GList
*values, GError **error)
{
	GdaRow *row;

	g_return_val_if_fail (GDA_IS_DATA_MODEL_ROW (model), -1);
	g_return_val_if_fail (CLASS (model)->append_values != NULL, -1);

	row = CLASS (model)->append_values (GDA_DATA_MODEL_ROW (model), values, error);
	if (row)
		return gda_row_get_number (row);
	else {
		if (CLASS (model)->append_row) {
			gint retval = -1;

			row = gda_row_new_from_list (model, values);
			if (CLASS (model)->append_row (GDA_DATA_MODEL_ROW (model), row, error))
				retval = gda_row_get_number (row);
			g_object_unref (row);

			return retval;
		}
		else
			return -1;
	}
}

* use the gda_data_model_append_values() function, or write the
gda_data_model_row_append_row() as I suggested above

Tell me if it works OK.

Cheers,

Vivien



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