469,267 Members | 1,094 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,267 developers. It's quick & easy.

dynamic sql - prepare statement

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.
Oct 27 '08 #1
1 5208
"Massimiliano Campagnoli" <ma**@paoloastori.comwrote in message
news:ef**********************************@p39g2000 hsb.googlegroups.com...
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).
Oct 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Arti Potnis | last post: by
1 post views Thread by Who.Really.Really.Cares | last post: by
2 posts views Thread by claus.hirth | last post: by
1 post views Thread by rook | last post: by
3 posts views Thread by aj | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.