Re: [gnome-db] Parameter specification into SQL Query
- From: "Vivien Malerba" <vmalerba gmail com>
- To: "MARZULLO Laurent Ext DF/DCGC" <lmarzullo externe orange-ftgroup com>
- Cc: gnome-db-list gnome org
- Subject: Re: [gnome-db] Parameter specification into SQL Query
- Date: Thu, 26 Oct 2006 11:50:52 +0200
On 10/25/06, MARZULLO Laurent Ext DF/DCGC <lmarzullo externe orange-ftgroup com> wrote:
Hello,
How should I specify 'paramters' in a
Gda::Command ?
I've got the following (in Ruby)
@update_user = Gda::Command.new(
"UPDATE GARGOYLE.GRGL_USERS SET LOGIN=$1, NAME=$2, EMAIL=$3"
, 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 = Gda::Transaction.new( 'toto' ) )
Dsn_connection.execute_single_command(
@update_user,
Gda::ParameterList.new(
Gda::Parameter.new( '$1' , <value to substitute $1 into
@update_user> ),
Gda::Parameter.new( '$2' , <value to substitute $2 into
@update_user> ),
Gda::Parameter.new( '$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).
Regards,
Vivien
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]