Re: [gnome-db] GdaSqlBuilder and WHERE clauses



On Tue, 2010-04-27 at 21:41 +0200, Vivien Malerba wrote:
> On 27 April 2010 18:03, Murray Cumming <murrayc murrayc com> wrote:
> > In Glom, I have several generic functions that combine a fixed SQL query
> > with various WHERE clauses. Imagine something like this
> >
> >  DataModel get_data_from_table(string where_clause)
> >
> > It does this by doing a simple string concatenation.
> >
> > But how can I do this with SqlBuilder, whose gda_sql_builder_add_cond()
> > expects the details of the condition in terms of arguments and
> > operator?:
> > http://library.gnome.org/devel/libgda/unstable/GdaSqlBuilder.html#gda-sql-builder-add-cond
> >
> > Ideally, I think I'd have a GdaSqlBuilderCond object that I could pass
> > around and even AND with another GdaSqlBuilderCond.
> 
> So if I understand you'd like to have a function as:
> DataModel get_data_from_table(GdaSqlBuilderCond where_clause)
> 
> I would prefer to avoid creating a new object just for this case, and
> prefer to add more flexibility to the GdaSqlBuilder by allowing the
> import/export of parts of a statement (as an opaque GdaSqlAnyPart
> pointer):
> 
> GdaSqlAnyPart *gda_sql_builder_export_part (GdaSqlBuilder *b, guint id);

How would I know what id to parse?

> and
> guint gda_sql_builder_import_part (GdaSqlBuilder *b, guint id,
> GdaSqlAnyPart *part);
> 
> With these 2 new calls you can create a
> DataModel get_data_from_table(GdaSqlAnyPart where_clause):
> 
> 1- create a GdaSqlBuilder with the where clause you want

A complete SQL query, part of which I would then ignore after exporting
the WHERE clause?

> 2- export that WHERE clause as a GdaSqlAnyPart, and use it as argument
> to your get_data_from_table() function
> 3- create a new GdaSqlBuilder with the specific SQL you need
> 4- import the GdaSqlAnyPart into that builder object
> 5- get the GdaStatement and execute it.
> 6- discard the unneeded objects
> 
> How does it sound?

I'd be happy to try that out, please.

-- 
murrayc murrayc com
www.murrayc.com
www.openismus.com



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