gda_data_model_import_from_model ()

View: New views
10 Messages — Rating Filter:   Alert me  

gda_data_model_import_from_model ()

by Massimo Cora' :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----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?

thanks and regards,
Massimo

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpflhAACgkQcfVTgMRILk28HQCfUkBbCL5kdDfIuW9S2Pm0oKwK
nmoAnj3VJwyLRpBSev9ZIhRUQr3uVbRz
=99yU
-----END PGP SIGNATURE-----
_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list

Re: gda_data_model_import_from_model ()

by Vivien Malerba :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



2009/7/16 Massimo Cora' <maxcvs@...>
-----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.

Regards,
Vivien
 


_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list

Re: gda_data_model_import_from_model ()

by Massimo Cora' :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Vivien,

Vivien Malerba wrote:

>
>
> 2009/7/16 Massimo Cora' <maxcvs@... <mailto:maxcvs@...>>
>
>     -----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?

I need all this because I built an iterator on the GdaDataModel and I'd
like to keep the things coherent.

thanks and regards,
Massimo








-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpgoJQACgkQcfVTgMRILk1yFACggVs15uR1+LnBjGRNDLZzy+uz
sqwAniGe94FFp68mlFy7dxMjt+cjMK8A
=Vuju
-----END PGP SIGNATURE-----
_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list

Re: gda_data_model_import_from_model ()

by Vivien Malerba :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



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

Hi Vivien,

Vivien Malerba wrote:
>
>
> 2009/7/16 Massimo Cora' <maxcvs@... <mailto:maxcvs@...>>
>
>     -----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

_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list

Re: gda_data_model_import_from_model ()

by Massimo Cora' :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi Vivien,

Vivien Malerba wrote:

>
>
> 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.


yep, this works good.

>
> 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.
>

this kind of solution was more attracting. I've implemented a
GdaDataModelConcat class, on which you can append more models and access
them by row number. Everything was working until I encountered another
problem: the GdaDataModelIter. In my current application setup I'm using
it to browse the model's records and, being the GdaDataModelIter not an
interface, I'm afraid that I cannot maintain the same naming to iter
through the GdaDataModelConcat records.
More: I don't see a method, analyzing gda-data-model-iter.[c|h], to
switch on the fly the underlying model.

I suppose then that I'll switch to the solution 1. In my particular
situation I have more models composed by at most 1 row, so copying them
in a new bigger model shouldn't have a really bad performance.

thanks and regards,
Massimo

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpjt1oACgkQcfVTgMRILk19/ACfc8PzZNeFBY2pVNEPRtHxM2mI
ZQgAniqPUfW/RHQHCgXbBCz+ybz9PjO5
=KM6a
-----END PGP SIGNATURE-----
_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list

Re: gda_data_model_import_from_model ()

by Vivien Malerba :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



2009/7/20 Massimo Cora' <maxcvs@...>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

hi Vivien,

Vivien Malerba wrote:
>
>
> 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.


yep, this works good.

>
> 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.
>

this kind of solution was more attracting. I've implemented a
GdaDataModelConcat class, on which you can append more models and access
them by row number. Everything was working until I encountered another
problem: the GdaDataModelIter. In my current application setup I'm using
it to browse the model's records and, being the GdaDataModelIter not an
interface, I'm afraid that I cannot maintain the same naming to iter
through the GdaDataModelConcat records.
More: I don't see a method, analyzing gda-data-model-iter.[c|h], to
switch on the fly the underlying model.

There is no reason the default GdaDataModel iter's implementation should not work. Can you send me a standalone version of your code so I can try to figure out what the problem is?

Anyway, even though the GdaDataModelIter is not an interface, you can still subclass it if you need, and then implement the GdaDataModel::i_create_iter method to instanciate your own GdaDataModelIter.

Vivien


_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list

Re: gda_data_model_import_from_model ()

by Massimo Cora' :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Vivien,

Vivien Malerba wrote:

>
>
> There is no reason the default GdaDataModel iter's implementation should
> not work. Can you send me a standalone version of your code so I can try
> to figure out what the problem is?
>
> Anyway, even though the GdaDataModelIter is not an interface, you can
> still subclass it if you need, and then implement the
> GdaDataModel::i_create_iter method to instanciate your own GdaDataModelIter.
>
sure here it is. Just compile and execute with
gcc gda-data-model-concat.c example.c `pkg-config --cflags --libs
libgda-4.0` `pkg-config --cflags --libs glib-2.0` -o example && ./example

As you see from the example, I first try to use the GdaDataModelIter,
unsuccesfully, secondly I just try to query the items directly from the
GdaDataModelConcat, successfully.

Honestly I didn't get why gda-data-model has a virtual method
gda_data_model_iter_at_row, which seems to be implemented in
GdaDataSelect but with too much logic.


thanks and regards,
Massimo

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpkczgACgkQcfVTgMRILk0UIwCfYZB6a6JttYIbrn3IhE9AnpuI
pU4AnidVpMDejtffrdyM9n7FyiGRPPDB
=U+iK
-----END PGP SIGNATURE-----


_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list

libgda-extra.tar.bz2 (7K) Download Attachment

Re: gda_data_model_import_from_model ()

by Vivien Malerba :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



2009/7/20 Massimo Cora' <maxcvs@...>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Vivien,

Vivien Malerba wrote:
>
>
> There is no reason the default GdaDataModel iter's implementation should
> not work. Can you send me a standalone version of your code so I can try
> to figure out what the problem is?
>
> Anyway, even though the GdaDataModelIter is not an interface, you can
> still subclass it if you need, and then implement the
> GdaDataModel::i_create_iter method to instanciate your own GdaDataModelIter.
>

sure here it is. Just compile and execute with
gcc gda-data-model-concat.c example.c `pkg-config --cflags --libs
libgda-4.0` `pkg-config --cflags --libs glib-2.0` -o example && ./example

As you see from the example, I first try to use the GdaDataModelIter,
unsuccesfully, secondly I just try to query the items directly from the
GdaDataModelConcat, successfully.

Honestly I didn't get why gda-data-model has a virtual method
gda_data_model_iter_at_row, which seems to be implemented in
GdaDataSelect but with too much logic.

Here is a slightly modified version of your code, to make it work. Here is what I've modified:
* you don't need to bother about iterators, I've removed all that code
* you _need_ to implement the  i_get_access_flags() virtual method (this is why it failed)
* check that the data models being concatenated support random access mode

If you want to be able to concatenate non random access data models, it's a bit more difficult, but I can help you.

Vivien


_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list

DataModelConcat.tbz (7K) Download Attachment

Re: gda_data_model_import_from_model ()

by Massimo Cora' :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Vivien,

Vivien Malerba wrote:
>
>
> Here is a slightly modified version of your code, to make it work. Here
> is what I've modified:
> * you don't need to bother about iterators, I've removed all that code
> * you _need_ to implement the  i_get_access_flags() virtual method (this
> is why it failed)

oh, it was so simple...

> * check that the data models being concatenated support random access mode
>
> If you want to be able to concatenate non random access data models,
> it's a bit more difficult, but I can help you.
>

random access is perfet! I've added the sources in the Anjuta git repo
under plugins/symbol-db/libgda-extra in case someone needs them

thanks a lot for your help,

Massimo
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpmPBkACgkQcfVTgMRILk1O+gCfRGCDXCwz4UTu5EMcwa/AKps4
1PEAn3cyaTZ+F0setCpI0ZIgBNEDfHe2
=1Ol2
-----END PGP SIGNATURE-----
_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list

Re: gda_data_model_import_from_model ()

by Vivien Malerba :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



2009/7/22 Massimo Cora' <maxcvs@...>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Vivien,

Vivien Malerba wrote:
>
>
> Here is a slightly modified version of your code, to make it work. Here
> is what I've modified:
> * you don't need to bother about iterators, I've removed all that code
> * you _need_ to implement the  i_get_access_flags() virtual method (this
> is why it failed)

oh, it was so simple...

> * check that the data models being concatenated support random access mode
>
> If you want to be able to concatenate non random access data models,
> it's a bit more difficult, but I can help you.
>

random access is perfet! I've added the sources in the Anjuta git repo
under plugins/symbol-db/libgda-extra in case someone needs them

Maybe you should add a few extra tests when adding a data model to concat: make sure the number and type of the added data model's columns are OK, because if not, then unexpected results may happen (the GdaDataModel is expected to have a fixed number of columns, each with a non variable GType).
 


thanks a lot for your help,

You're welcome!

Vivien



_______________________________________________
gnome-db-list mailing list
gnome-db-list@...
http://mail.gnome.org/mailman/listinfo/gnome-db-list