10.12.2012 Views

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Executing SQL Queries<br />

Executing SQL Queries<br />

You do not need to set the maximum parameter size for fixed length datatypes,<br />

such as Number and Date, or for parameters that use the setDataBuffer<br />

method.<br />

You can retrieve the current maximum parameter size setting by calling the<br />

getMaxParamSize method.<br />

Executing an Iterative Operation<br />

Once you have set the maximum number of iterations and (if necessary) the<br />

maximum parameter size, iterative execution using a parameterized statement is<br />

straightforward, as shown in the following example:<br />

stmt->setSQL(“INSERT INTO basket_tab VALUES(:1, :2)”);<br />

stmt->setString(1, “Apples”); // value for first parameter of first row<br />

stmt->setInt(2, 6); // value for second parameter of first row<br />

stmt->addIteration(); // add the iteration<br />

stmt->setString(1, “Oranges”); // value for first parameter of second row<br />

stmt->setInt(1, 4); // value for second parameter of second row<br />

stmt->executeUpdate(); // execute statement<br />

As shown in the example, you call the addIteration method after each iteration<br />

except the last, after which you invoke executeUpdate method. Of course, if you<br />

did not have a second row to insert, then you would not need to call the<br />

addIteration method or make the subsequent calls to the setxxx methods.<br />

Iterative Execution Usage Notes<br />

■ Iterative execution is designed only for use in INSERT, UPDATE and DELETE<br />

operations that use either standard or parameterized statements. It cannot be<br />

used for callable statements and queries.<br />

■ The datatype cannot be changed between iterations. For example, if you use<br />

setInt for parameter 1, then you cannot use setString for the same<br />

parameter in a later iteration.<br />

SQL query statements allow your applications to request information from a<br />

database based on any constraints specified. A result set is returned as a result of a<br />

query.<br />

Relational Programming 2-13

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!