"Massimiliano Campagnoli" <maxi@paoloastori.comwrote in message
news:ef9aad37-6f53-4e17-a90b-b55150ac8b69@p39g2000hsb.googlegroups.com...
Quote:
Hy,
I am trying to understand how the prepare statement works.
>
I am using Qt C++ library to access db2:
>
{
...
QSqlQuery cust_query;
>
cust_query.prepare("SELECT CUST_NAME FROM CUSTOMERS WHERE CUST_ID=?");
>
cust_query.addBindValue(1);
cust_query.exec();
>
cust_query.addBindValue(2);
cust_query.exec();
...
}
>
db2 precompiles the select statement first, then binds the parameter
CUST_ID to value 1 and executes the query, then binds the parameter
CUST_ID to value 2 and again executes the query.
>
So far so good.
>
But what happens if prepare is executed a second time against the same
sql statement ?
Do I pay the cost of re-preparing the statement again or it's now
cached into db2 and it's does not matter if prepare is executed more
than once against the same statement ?
>
Thanks for the help.
|
There is a cost in the sense that you have to submit the prepare to DB2 and
get a response back, but if the exact statement has been previously prepared
and is still in package cache memory, then DB2 will used the cached package
(if the statement text is identical).