Re: [gnome-db] Parameter specification into SQL Query

On 10/25/06, MARZULLO Laurent Ext DF/DCGC <lmarzullo externe orange-ftgroup com> wrote:



How should I specify 'paramters' in a Gda::Command ?


I've got the following (in Ruby)



                             , Gda::Command::TYPE_SQL

                             , Gda::Command::OPTION_STOP_ON_ERRORS )


And then, later, I would like to write something like


Dsn_connection.begin_transaction( toto = 'toto' ) )

Dsn_connection.execute_single_command( @update_user,

   '$1' , <value to substitute $1 into @update_user> ),

   '$2' , <value to substitute $2 into @update_user> ),

   '$3' , <value to substitute $3 into @update_user> ) ) )

Dsn_connection.commit_transaction( toto )

I don't know about Ruby (or the status of Ruby bindings) but here is what to do in C, I'm sorry you'll have to adapt it...

The GdaCommand does not accept parameters, it only accepts "raw" SQL. If you want to execute parametrized queries, then use the GdaQuery object like for example
query = gda_query_new_from_sql (dict, "UPDATE GARGOYLE.GRGL_USERS SET LOGIN=##[:name='login' :type='gchararray'], NAME=##[:name='name' :type='gchararray'], EMAIL=##[:name='email' :type='gchararray']", NULL);
to create a GdaQuery object with 3 parameters; note the syntax to specify parameters whic are named and with a defined type.

Then you can get a GdaParameterList object to specify the parameter values using:

params =  gda_query_get_parameter_list(query).

Now you must actually pass the values to the 'params' object using
param =
gda_parameter_list_find_param (params, "login");
gda_parameter_set_value_str (param, <the login value);

Once finished, call gda_query_execute (query, params).



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