Re: [gnome-db] gda_connection_execute_command() result

On 10/21/06, Murray Cumming <murrayc murrayc com> wrote:
On Sat, 2006-10-21 at 15:45 +0200, Vivien Malerba wrote:
> On 10/21/06, Murray Cumming <murrayc murrayc com> wrote:
> > The documentation for gda_connection_execute_command (pasted below) is
> > not clear to me, particularly
> >
> > "The return value is a GList of #GdaDataModel's, and #GdaParameterList".
> >
> > This seems to mean that the GList* contains some GdaDataModels and some
> > GdaParameterLists. If so, what's the sequence or way to identify each
> > element? And what would the GdaParameterList items tell me? Where is
> > this demonstrated in example code?
> You understood correctly. The returned list can hold pointers to
> GdaDataModel or GdaParameterList objects, in the same list.
> Identifying them is easily done using GObject's introspection features

OK. This needs to be mentioned in the documentation.

I'll fix the documentation in this regard, then.

Also, is there ever >1 GdaDataModel or GdaParameterList in that GList?
Does it ever contain both? It would be nice to know what to expect, and

You get as many items in the retunred GList as there are queries
(separated by ";") in the command. For example it the command was made
with "SELECT * FROM mytable; DELETE FROM mytable" then you'd get first
a GdaDataModel for the 1st query and then a GdaParameterList for the
2nd. I'll update the documentation to make this clear.

> A GdaDataModel is returned in the list whenever the SQL was a SELECT
> query (or a query returning a data set), and a GdaParameterList is
> returned whenever the query was something else.
> What the GdaParameterList contains is a list of named values which are
> described in gda_server_provider_execute_command(), the most usefull
> one (and only supported at the moment if I remember) being named
> "IMPACTED_ROWS" which contains the number of rows impacted by the
> query.
> Note that if you know that the command contains a SELECT query, then
> you'd better use gda_connection_execute_select_command() and if you
> know that the command is not as SELECT query, then you should use
> gda_connection_execute_non_select_command().
> These two functions are wrapper around the first one and make things
> easier to use.
> >
> > Please note also that, because it's so odd to have 2 types of element in
> > a GList, people are likely to interpret this text as just meaning that
> > the params parameter is an output parameter. That guess would be
> > reinforced by the missing const for that parameter.
> >
> I know it can seem a bit strange but is it worth creating overhead
> with a structure such as
> struct {
>       gboolean this_is_a_data_model;
>       union {
>              GdaDataModel *model;
>              GdaParameterList *plist;
>       } data;
> }
> and returning a list of these structures.

How about either
- returning two GLists.

We can only return one list because the index in the list of a
GdaDataModel or GdaParameterList corresponds to the query in the
command at the same index.

- Making this function private and just having a execute method for
select and an execute method for parameters?

You cant' always know in advance which query whill return what. For
example a "DESCRIBE" query in MySQL will return a GdaDataModel even
though it does not start with "SELECT".

But if you know in advance what's in your command, then use one of the
other functions I mentioned. I'll also update the documentation in
this regard.



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