Re: [gnome-db] gda_data_model_import_from_model ()





2009/7/17 Massimo Cora' <maxcvs email it>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Vivien,

Vivien Malerba wrote:
>
>
> 2009/7/16 Massimo Cora' <maxcvs email it <mailto:maxcvs email it>>
>
>     -----BEGIN PGP SIGNED MESSAGE-----
>     Hash: SHA1
>
>     Hi,
>
>     I'm using the gda_data_model_import_from_model () function in this way:
>     the *to and *from datamodels are select results.
>     I just want to append the results from the latter to the former, but
>     this error happens: "No INSERT statement provided".
>
>     *to and *from have the same fields, and unfortunately I cannot compute a
>     single query to retrieve both at the same time. (let's say that I cannot
>     have the records ordered by desc/asc, but they must follow another
>     logic).
>     So my question is: how can I create a datamodel and append the records
>     I'd like to?
>
>
> The example in Libgda's sources: samples/TableCopy/table-copy.c,
> function copy_products_2() does exactly what you are trying to do. Maybe
> you can find where the problem is. Otherwise, I'd need a standalone
> example to work on.
>

that example is fine but I'd like to do something different: I'd like to
merge (or better, to concatenate) the results of *to and *from
datamodels but without interacting with database (i.e. without
reflecting changes on a datamodel using INSERT statements).
I understand that to be modifiable the *to datamodel must be changed
with gda_data_select_set_modification_statement_sql (), but isn't there
a possibility to have a 'detached' model so that appending rows can be
done easily?

What you can do is create a new empty GdaDataModel and fill it with the 2 data models you have. To create a new empty data model, use
gda_data_model_array_new() or gda_data_model_array_new_with_g_types() and then
 
gda_data_model_import_from_model (new_model, to);
gda_data_model_import_from_model (new_model, from);

where to and from are your 2 data models you mentionned. This has the drawback of consuming more memory as data is being copied to the new data model.

Another solution is to create a new object which implements the GdaDataModel interface and, for each virtual method to be implemented, calls the same virtual method of the concatenated data models (I suppose they have the same number of columns and column types). This is fairly simple and the most efficient approach as no data is copied. For an example of this kind of approach, look at the gda-data-meta-wrapper.h and gda-data-meta-wrapper.c files which implement a GdaDataModel interface which transforms some values of another data model.

Vivien


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