Re: [gnome-db] parameterized queries
- From: Vivien Malerba <vmalerba gmail com>
- To: Neil Zanella <nzanella gmail com>
- Cc: GNOME-DB List <gnome-db-list gnome org>
- Subject: Re: [gnome-db] parameterized queries
- Date: Tue, 9 Nov 2004 09:12:51 +0100
On Mon, 8 Nov 2004 12:37:34 -0700, Neil Zanella <nzanella gmail com> wrote:
> Hello,
>
> I need to build 'printf style' or similar parameterized queries. My
> understanding is that
> I can do this with:
>
> gint gda_connection_execute_non_query
> (GdaConnection *cnc,
> GdaCommand *cmd,
> GdaParameterList *params);
>
> using the GdaParameterList (instead of setting it to null, maybe I can
> place a list
> of intst, gchar *, etc... or whatever).
>
> Can someone please be so kind to give me an example? (is this really what those
> parameters are for or am I imagining?).
>
If the queries are DML queries, you can use libmergeant (soon this
will be into libgnomedb) like:
MgDict *the_dictionnary;
MgQuery *query;
MgContext *context;
MgParameter *param;
GdaValue *myval;
gchar *str;
the_dictionnary = mg_dict_new ();
query = mg_query_new_from_sql (the_dictionnary, "SELECT * FROM table
where id=##[:type="int4" :name="myparam"]");
context = mg_entity_get_exec_context (MG_ENTITY (query));
param = context->parameters->data; /* first and only parameter */
myval = gda_value_new_integer (1234);
mg_parameter_set_value (param, myval);
gda_value_free (myval);
str = mg_renderer_render_as_sql (MG_RENDERER (query), context, 0, NULL);
/* use str */
g_free (str);
g_object_unref (context);
g_object_unref (query);
g_object_unref (the_dictionnary);
Check the docs for more options and explanations about the different objects.
Cheers,
Vivien
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]