Cursors > Binding Input Variables > Standard Implementation > The following code extract is taken from the sample file sybproc.cpp and shows how this argument is used:
 
The following code extract is taken from the sample file sybproc.cpp and shows how this argument is used:
{
cout << "Binding parameters: " << endl;
cout << " @intparam" << endl;
if (!request->bindParam("@intparam", IldIntegerType)) {
IldDisplayError("Binding of @intparam failed: ", request);
delete dbms;
return 1;
}
cout << " @sintparam" << endl;
if (!request->bindParam("@sintparam", IldIntegerType,
-1, 0, 0, IlTrue)) {
IldDisplayError("Binding of @sintparam failed: ", request);
delete dbms;
return 1;
}
cout << " @floatparam" << endl;
if (!request->bindParam("@floatparam", IldRealType,
-1, 0, 0, IlTrue)) {
IldDisplayError("Binding of @floatparam failed: ", request);
delete dbms;
return 1;
}
cout << " @charparam" << endl;
if (!request->bindParam("@charparam", IldStringType, 20,
0, 0, IlTrue)) {
IldDisplayError("Binding of @charparam failed: ", request);
delete dbms;
return 1;
}
}
Warning: Rogue Wave DB Link manages the memory allocation for data buffers internally. In case of long strings, as with Oracle VARCHAR or Informix CHAR, the allocated buffer may be too small if the size is not supplied at binding time. If your parameter is longer than 255 characters, pass the actual maximum size as the third argument to the function IldRequest::bindParam.
*The seventh argument is the actual number of values in the array argument. This argument is only used with Oracle for stored procedure calls where array arguments are required.
*The eighth argument is a valid abstract data type descriptor. It is only used with ORDBMSs and is mandatory if the parameter is bound to IldCollectionType or IldObjectType types.
Warning: Despite standardization, Oracle does not support the question mark as a variable identifier.
Overloaded Version
There is an overloaded version of the function IldRequest::bindParam that is reserved for use with Oracle. Its first argument is a character string holding the parameter name the way Oracle expects it, that is, in the format ':'<parameter name>.
Since Oracle also supports the format ':'<parameter number>, the first implementation of the bindParam function can also be used with them, as shown in the following RDBMS example sbinding:
{
cout << "Binding input variable :name of type string" << endl;
if (!request->bindParam((IlUShort)0, IldStringType, 20)) {
IldDisplayError("Variable binding failed:", request);
delete cust;
Ending(dbms, request);
}
cout << "Binding input variable :age of type integer" << endl;
if (!request->bindParam(1, IldIntegerType)) {
IldDisplayError("Variable binding failed:", request);
delete cust;
Ending(dbms, request);
}
}
Setting Parameter Values
Just before calling the function IldRequest::execute, you must supply values for the parameters through the function IldRequest::setParamValue, as shown in the following example:
{
IlInt n = 0;
for (int i = 0; i < 5; i++) {
cout << "Set " << i << "th variable to name: "
<< names[i] << " and age: " << ages[i] << endl;
request->setParamValue(names[i], 0, 0);
request->setParamValue(ages[i], 1, 0);
 
// execute the insertion
cout << "Inserting row" << endl;
if (!request->execute(&n)) {
IldDisplayError("Execution failed: ", request);
delete cust;
Ending(dbms, request);
}
cout << n << "row(s) inserted." << endl;
}
}
Specific Considerations
You must be careful when using variables of Oracle CHAR data type. For this data type, the values in the database are padded with blanks. A common error is to set parameter values for these columns, without padding the values with blanks.
For instance, with table article (name char(10), id char(10)), the query "select name from article where id = '0'" works correctly.
However, when calling parse for query "select name from article where id = :1", you have to fill the bind variable with spaces so that the equality operator retrieves the expected values.

Version 5.8
Copyright © 2014, Rogue Wave Software, Inc. All Rights Reserved.