Re: [gnome-db] GdaSqlBuilder and WHERE clauses

Vivien Malerba <[email protected]>
Newsgroups gmane.comp.gnome.db
Message-ID <[email protected]>
On 27 April 2010 18:03, Murray Cumming <[email protected]> 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);
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
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?

Vivien
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.